protected void showNamespaceSelectDialog() {
    int count = namespaceList.size();
    boolean[] selected = new boolean[count];
    CharSequence[] namespacesArray = new CharSequence[count];

    for (int i = 0; i < count; i++) {
      selected[i] = enabledNamespaces.contains(namespaceList.get(i));
      namespacesArray[i] = namespaceList.get(i);
    }

    DialogInterface.OnMultiChoiceClickListener coloursDialogListener =
        new DialogInterface.OnMultiChoiceClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which, boolean isChecked) {
            synchronized (lockObj) {
              if (isChecked) enabledNamespaces.add(namespaceList.get(which));
              else enabledNamespaces.remove(namespaceList.get(which));
            }
          }
        };

    AlertDialog.Builder builder = new AlertDialog.Builder(serverConnection.getContext());
    builder.setTitle("Select Namespaces");
    builder.setMultiChoiceItems(namespacesArray, selected, coloursDialogListener);
    builder.setNeutralButton("Ok", null);

    AlertDialog dialog = builder.create();
    dialog.show();
  }
  protected void setupMultiChoiceDialog(AlertDialog.Builder builder) {
    final List<ItemT> availableItems = getAvailableItems();

    final ItemPrinter<ItemT> ip = getItemPrinter();
    CharSequence[] items = new CharSequence[availableItems.size()];
    boolean[] checked = new boolean[availableItems.size()];
    for (int i = 0; i < availableItems.size(); ++i) {
      items[i] = ip.itemToString(getItemAt(i));
      if (selectedItems.get(i) != null) {
        checked[i] = true;
      } else {
        checked[i] = false;
      }
    }

    builder.setMultiChoiceItems(
        items,
        checked,
        new DialogInterface.OnMultiChoiceClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which, boolean isChecked) {
            if (isChecked) selectedItems.put(which, getItemAt(which));
            else selectedItems.delete(which);
          }
        });
  }
Exemplo n.º 3
0
  @Override
  protected Dialog onCreateDialog(int id) {
    switch (id) {
      case PREFERENCES_DIALOG:
        // dialog to enable or disable automatic synchronisation
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(getString(R.string.menu_sync_options));
        boolean[] syncStatus = new boolean[] {true};
        if (!automaticSync) {
          syncStatus[0] = false;
        }

        builder.setMultiChoiceItems(
            new String[] {getString(R.string.sync_option)},
            syncStatus,
            new OnMultiChoiceClickListener() {
              // register handler which changes automatic
              // synchronisation preferences
              public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                if (isChecked != automaticSync) {
                  Editor editor = pref.edit();
                  editor.putBoolean(getString(R.string.sync_option), isChecked);
                  editor.commit();
                  automaticSync = isChecked;
                  if (automaticSync) {
                    syncItems();
                  }
                }
              }
            });
        return builder.create();
    }
    return super.onCreateDialog(id);
  }
Exemplo n.º 4
0
 private void click04() {
   final String items[] = {"篮球", "足球", "排球"};
   final boolean selected[] = {true, false, true};
   AlertDialog.Builder builder = new AlertDialog.Builder(this); // 先得到构造器
   builder.setTitle("提示"); // 设置标题
   builder.setIcon(R.drawable.info32); // 设置图标,图片id即可
   builder.setMultiChoiceItems(
       items,
       selected,
       new DialogInterface.OnMultiChoiceClickListener() {
         @Override
         public void onClick(DialogInterface dialog, int which, boolean isChecked) {
           // dialog.dismiss();
           Toast.makeText(DialogShowActivity.this, items[which] + isChecked, Toast.LENGTH_SHORT)
               .show();
         }
       });
   builder.setPositiveButton(
       "确定",
       new DialogInterface.OnClickListener() {
         @Override
         public void onClick(DialogInterface dialog, int which) {
           dialog.dismiss();
           Toast.makeText(DialogShowActivity.this, "确定", Toast.LENGTH_SHORT).show();
           // android会自动根据你选择的改变selected数组的值。
           for (int i = 0; i < selected.length; i++) {
             Log.e("hongliang", "" + selected[i]);
           }
         }
       });
   builder.create().show();
 }
Exemplo n.º 5
0
  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(R.string.settings);

    // Specify the list array, the items to be selected by default (null for none),
    // and the listener through which to receive callbacks when items are selected
    builder.setMultiChoiceItems(
        R.array.settings_array,
        mEnables,
        new DialogInterface.OnMultiChoiceClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which, boolean isChecked) {
            mEnables[which] = isChecked;
          }
        });

    // Set the action buttons
    builder.setPositiveButton(
        R.string.ok,
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int id) {
            mOk = true;
          }
        });
    builder.setNegativeButton(
        R.string.cancel,
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int id) {}
        });

    return builder.create();
  }
 @Override
 public boolean performClick() {
   AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
   builder.setMultiChoiceItems(_items, mSelection, this);
   builder.show();
   return true;
 }
 @Override
 public boolean performClick() {
   AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
   builder.setMultiChoiceItems(_items, mSelection, this);
   _itemsAtStart = getSelectedItemsAsString();
   builder.setPositiveButton(
       "Выбрать",
       new DialogInterface.OnClickListener() {
         @Override
         public void onClick(DialogInterface dialog, int which) {
           System.arraycopy(mSelection, 0, mSelectionAtStart, 0, mSelection.length);
         }
       });
   builder.setNegativeButton(
       "Отмена",
       new DialogInterface.OnClickListener() {
         @Override
         public void onClick(DialogInterface dialog, int which) {
           simple_adapter.clear();
           simple_adapter.add(_itemsAtStart);
           System.arraycopy(mSelectionAtStart, 0, mSelection, 0, mSelectionAtStart.length);
         }
       });
   builder.show();
   return true;
 }
Exemplo n.º 8
0
 @Override
 public void onPrepareDialogBuilder(final AlertDialog.Builder builder) {
   super.onPrepareDialogBuilder(builder);
   prefs = getSharedPreferences();
   if (prefs == null) return;
   final int length = mKeys.length;
   for (int i = 0; i < length; i++) {
     mValues[i] = prefs.getBoolean(mKeys[i], mDefaultValues[i]);
   }
   builder.setPositiveButton(android.R.string.ok, this);
   builder.setNegativeButton(android.R.string.cancel, null);
   builder.setMultiChoiceItems(mNames, mValues, this);
   if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.DONUT) {
     new Thread() {
       @Override
       public void run() {
         Dialog dialog = null;
         while (dialog == null) {
           dialog = getDialog();
           if (dialog != null) {
             final Message msg = new Message();
             msg.obj = dialog;
             mDialogWorkaroundHandler.sendMessage(msg);
           }
           try {
             sleep(50L);
           } catch (final InterruptedException e) {
           }
         }
       }
     }.start();
   }
 }
Exemplo n.º 9
0
 protected Dialog onCreateDialog(int id) {
   AlertDialog.Builder adb = new AlertDialog.Builder(this);
   switch (id) {
       // массив
     case DIALOG_ITEMS:
       adb.setTitle(R.string.items);
       adb.setMultiChoiceItems(data, chkd, myItemsMultiClickListener);
       break;
       // курсор
     case DIALOG_CURSOR:
       adb.setTitle(R.string.cursor);
       adb.setMultiChoiceItems(cursor, DB.COLUMN_CHK, DB.COLUMN_TXT, myCursorMultiClickListener);
       break;
   }
   adb.setPositiveButton(R.string.ok, myBtnClickListener);
   return adb.create();
 }
Exemplo n.º 10
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
      case R.id.menu_party_list_activity_add:
        Intent newPartyIntent = new Intent(getActivity(), PartyActivity.class);
        startActivityForResult(newPartyIntent, REQUEST_PARTY_INFO_CHGD);
        break;

      case R.id.menu_party_list_activity_import:
        final List<ImportContacts.Contact> contacts = ImportContacts.getContacts(getActivity());
        final ArrayList<ImportContacts.Contact> importContacts = new ArrayList<>();

        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setTitle(getString(R.string.msg_choose, getString(R.string.str_contact)));
        builder.setNegativeButton(getString(android.R.string.cancel), null);
        builder.setMultiChoiceItems(
            ImportContacts.getNames(contacts),
            null,
            new DialogInterface.OnMultiChoiceClickListener() {
              @Override
              public void onClick(DialogInterface dialogInterface, int i, boolean b) {
                // Add checked contacts into importContacts list
                if (b) importContacts.add(contacts.get(i));
                else importContacts.remove(contacts.get(i));
              }
            });
        builder.setPositiveButton(
            getString(android.R.string.ok),
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialogInterface, int i) {
                new ImportContactsAsync(
                        getActivity(),
                        new ImportContactsAsync.Callback() {

                          @Override
                          public void onFinished() {
                            refreshList();
                          }
                        })
                    .execute(importContacts);
              }
            });
        AlertDialog selectContactsAD = builder.create();
        selectContactsAD.show();
        break;
    }

    return super.onOptionsItemSelected(item);
  }
Exemplo n.º 11
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    tvShow = (TextView) findViewById(R.id.tvShow);
    btnInter = (Button) findViewById(R.id.btnInter);
    btnInter.setOnClickListener(btnInterListener);
    order = new AlertDialog.Builder(this);
    order.setTitle(R.string.show);
    order.setPositiveButton("確認", listener);
    order.setNegativeButton("離開", listener);
    order.setMultiChoiceItems(hamburger, checkedItems, muListener);
  }
  @Override
  protected void onClick() {
    super.onClick();

    AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
    builder.setTitle("Select weekdays");

    final boolean[] selection = stringToArray(selectedValuesString);
    builder.setMultiChoiceItems(
        weekdayNames,
        selection,
        new OnMultiChoiceClickListener() {
          public void onClick(DialogInterface dialog, int which, boolean isChecked) {
            selection[which] = isChecked;
          }
        });

    builder.setPositiveButton(
        "Ok",
        new OnClickListener() {
          public void onClick(DialogInterface dialog, int which) {

            selectedValuesString = arrayToString(selection);

            if (!callChangeListener(selectedValuesString)) {
              return;
            }

            persistString(selectedValuesString);
            notifyChanged();
          }
        });

    builder.setNegativeButton(
        "Cancel",
        new OnClickListener() {
          public void onClick(DialogInterface dialog, int which) {}
        });

    AlertDialog dialog = builder.create();
    dialog.show();
  }
Exemplo n.º 13
0
  /**
   * 复选框对话框
   *
   * @param context
   * @param title
   * @param items
   * @param defaultCheckedItems
   * @param onMultiChoiceClickListener
   * @param onClickListener
   * @return
   */
  public static AlertDialog showMultiChoiceDialog(
      Context context,
      String title,
      String[] items,
      boolean[] defaultCheckedItems,
      DialogInterface.OnMultiChoiceClickListener onMultiChoiceClickListener,
      DialogInterface.OnClickListener onClickListener) {

    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    if (!TextUtils.isEmpty(title)) {
      builder.setTitle(title);
    }
    AlertDialog dialog =
        builder
            .setMultiChoiceItems(items, defaultCheckedItems, onMultiChoiceClickListener)
            .setPositiveButton("确定", null)
            .setNegativeButton("取消", null)
            .show();
    return dialog;
  }
Exemplo n.º 14
0
  private void showCardFieldMultipleChoiceAlertDialog(
      final EnumSet<CardField> selectedFields, final int titleStringId) {
    // Create a AlertDialog for user to select fields in field 1 (the question part).
    boolean[] fieldSelection = new boolean[CardField.values().length];
    int i = 0;
    for (CardField field : CardField.values()) {
      if (selectedFields.contains(field)) {
        fieldSelection[i] = true;
      } else {
        fieldSelection[i] = false;
      }
      i++;
    }
    final String[] fieldText = getResources().getStringArray(R.array.card_field_list);

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(titleStringId);
    builder.setMultiChoiceItems(
        fieldText,
        fieldSelection,
        new DialogInterface.OnMultiChoiceClickListener() {
          public void onClick(DialogInterface dialog, int which, boolean isChecked) {
            if (isChecked) {
              selectedFields.add(CardField.values()[which]);
            } else {
              selectedFields.remove(CardField.values()[which]);
            }
          }
        });
    builder.setPositiveButton(
        getString(R.string.ok_text),
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {}
        });
    builder.show();
  }
  private Dialog getVCardFileSelectDialog(boolean multipleSelect) {
    final int size = mAllVCardFileList.size();
    final VCardSelectedListener listener = new VCardSelectedListener(multipleSelect);
    final AlertDialog.Builder builder =
        new AlertDialog.Builder(this)
            .setTitle(R.string.select_vcard_title)
            .setPositiveButton(android.R.string.ok, listener)
            .setOnCancelListener(mCancelListener)
            .setNegativeButton(android.R.string.cancel, mCancelListener);

    CharSequence[] items = new CharSequence[size];
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    for (int i = 0; i < size; i++) {
      VCardFile vcardFile = mAllVCardFileList.get(i);
      SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
      stringBuilder.append(vcardFile.getName());
      stringBuilder.append('\n');
      int indexToBeSpanned = stringBuilder.length();
      // Smaller date text looks better, since each file name becomes easier to read.
      // The value set to RelativeSizeSpan is arbitrary. You can change it to any other
      // value (but the value bigger than 1.0f would not make nice appearance :)
      stringBuilder.append("(" + dateFormat.format(new Date(vcardFile.getLastModified())) + ")");
      stringBuilder.setSpan(
          new RelativeSizeSpan(0.7f),
          indexToBeSpanned,
          stringBuilder.length(),
          Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
      items[i] = stringBuilder;
    }
    if (multipleSelect) {
      builder.setMultiChoiceItems(items, (boolean[]) null, listener);
    } else {
      builder.setSingleChoiceItems(items, 0, listener);
    }
    return builder.create();
  }
  @Override
  public void onClick(View v) {
    if (v == mVoteBtnView) {
      final HashMap<String, String> map = new HashMap<String, String>();
      AlertDialog.Builder builder = new AlertDialog.Builder(VoteViewActivity.this);
      builder.setTitle(mVoteitem.getmTitle());
      if (mVoteitem.getmIsVoted()) {
        CaculatorRate();
        ListAdapter list = new ListAdapter(mContext, mVoteitem.getmVoteOptions());
        builder.setAdapter(list, null);
        builder.setPositiveButton(R.string.ok, null);
      } else {
        String items[] = new String[mVoteitem.getmVoteOptions().size()];
        final boolean chectitem[] = new boolean[mVoteitem.getmVoteOptions().size()];
        for (int i = 0; i < mVoteitem.getmVoteOptions().size(); i++) {
          items[i] = mVoteitem.getmVoteOptions().get(i).getDesc();
          Log.i(TAG, "items[i] === " + items[i]);
        }
        if (mVoteitem.getmType().equals("0")) {
          builder.setSingleChoiceItems(
              items,
              -1,
              new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                  map.put("optionid", mVoteitem.getmVoteOptions().get(which).getId());
                }
              });
          builder.setPositiveButton(
              R.string.ok,
              new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface arg0, int arg1) {
                  String url =
                      ReadConfigFile.getServerAddress(mContext)
                          + "index.php?controller=vote&action=count";
                  map.put("voteid", mVoteitem.getmId());
                  SharedPreferences userpref = mContext.getSharedPreferences("user", MODE_PRIVATE);
                  String user_name = userpref.getString("user_name", "");
                  map.put("username", user_name);
                  Log.i(TAG, "map ==" + map.toString());
                  HttpConnectionUtil connect = new HttpConnectionUtil(getApplicationContext());
                  ConnectWebResult(connect, url, map);
                }
              });
        } else {
          if ((items == null) || (items.length == 0)) {
            return;
          }
          builder.setMultiChoiceItems(
              items,
              chectitem,
              new DialogInterface.OnMultiChoiceClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                  chectitem[which] = isChecked;
                }
              });
          builder.setPositiveButton(
              R.string.ok,
              new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface arg0, int arg1) {
                  String idstr = null;

                  for (int i = 0; i < chectitem.length; i++) {
                    if (chectitem[i]) {
                      if (idstr == null) {
                        idstr = mVoteitem.getmVoteOptions().get(i).getId();
                      } else {
                        idstr += "," + mVoteitem.getmVoteOptions().get(i).getId();
                      }
                    }
                  }
                  String url =
                      ReadConfigFile.getServerAddress(mContext)
                          + "index.php?controller=vote&action=count";
                  map.put("optionid", idstr);
                  Log.i(TAG, "select idstr == " + idstr);
                  map.put("voteid", mVoteitem.getmId());
                  SharedPreferences userpref = mContext.getSharedPreferences("user", MODE_PRIVATE);
                  String user_name = userpref.getString("user_name", "");
                  map.put("username", user_name);
                  HttpConnectionUtil connect = new HttpConnectionUtil(getApplicationContext());
                  ConnectWebResult(connect, url, map);
                }
              });
        }
      }

      builder.create().show();
    }
  }
Exemplo n.º 17
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case CHOICES_MENU_ID:
        final String[] possibleChoices = getResources().getStringArray(R.array.guessesList);

        // create a new AlertDialog Builder and set its title
        AlertDialog.Builder choicesBuilder = new AlertDialog.Builder(this);
        choicesBuilder.setTitle(R.string.choices);

        // add possibleChoices's items to the Dialog and set the
        // behavior when one of the items is clicked
        choicesBuilder.setItems(
            R.array.guessesList,
            new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int item) {
                // update guessRows to match the user's choice
                guessRows = Integer.parseInt(possibleChoices[item].toString()) / 3;
                resetQuiz(); // reset the quiz
              } // end method onClick
            } // end anonymous inner class
            ); // end call to setItems

        // create an AlertDialog from the Builder
        AlertDialog choicesDialog = choicesBuilder.create();
        choicesDialog.show(); // show the Dialog
        return true;

      case REGIONS_MENU_ID:
        // get array of world regions
        final String[] regionNames = regionsMap.keySet().toArray(new String[regionsMap.size()]);

        // boolean array representing whether each region is enabled
        boolean[] regionsEnabled = new boolean[regionsMap.size()];
        for (int i = 0; i < regionsEnabled.length; ++i)
          regionsEnabled[i] = regionsMap.get(regionNames[i]);

        // create an AlertDialog Builder and set the dialog's title
        AlertDialog.Builder regionsBuilder = new AlertDialog.Builder(this);
        regionsBuilder.setTitle(R.string.regions);

        // replace _ with space in region names for display purposes
        String[] displayNames = new String[regionNames.length];
        for (int i = 0; i < regionNames.length; ++i)
          displayNames[i] = regionNames[i].replace('_', ' ');

        // add displayNames to the Dialog and set the behavior
        // when one of the items is clicked
        regionsBuilder.setMultiChoiceItems(
            displayNames,
            regionsEnabled,
            new DialogInterface.OnMultiChoiceClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                // include or exclude the clicked region
                // depending on whether or not it's checked
                regionsMap.put(regionNames[which].toString(), isChecked);
              } // end method onClick
            } // end anonymous inner class
            ); // end call to setMultiChoiceItems

        // resets quiz when user presses the "Reset Quiz" Button
        regionsBuilder.setPositiveButton(
            R.string.reset_quiz,
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int button) {
                resetQuiz(); // reset the quiz
              } // end method onClick
            } // end anonymous inner class
            ); // end call to method setPositiveButton

        // create a dialog from the Builder
        AlertDialog regionsDialog = regionsBuilder.create();
        regionsDialog.show(); // display the Dialog
        return true;
    } // end switch

    return super.onOptionsItemSelected(item);
  }
Exemplo n.º 18
0
  /** Add participants to be invited in the session */
  private void addParticipants() {
    /* Build list of available contacts not already in the conference */
    Set<ContactId> availableParticipants = new HashSet<>();
    try {
      Set<RcsContact> contacts = getContactApi().getRcsContacts();
      for (RcsContact rcsContact : contacts) {
        ContactId contact = rcsContact.getContactId();
        if (mGroupChat.isAllowedToInviteParticipant(contact)) {
          availableParticipants.add(contact);
        }
      }
    } catch (RcsServiceException e) {
      showException(e);
      return;
    }
    /* Check if some participants are available */
    if (availableParticipants.size() == 0) {
      showMessage(R.string.label_no_participant_found);
      return;
    }
    /* Display contacts */
    final List<String> selectedParticipants = new ArrayList<>();
    final CharSequence[] items = new CharSequence[availableParticipants.size()];
    int i = 0;
    for (ContactId contact : availableParticipants) {
      items[i++] = contact.toString();
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.label_select_contacts);
    builder.setCancelable(true);
    builder.setMultiChoiceItems(
        items,
        null,
        new DialogInterface.OnMultiChoiceClickListener() {
          public void onClick(DialogInterface dialog, int which, boolean isChecked) {
            String c = (String) items[which];
            if (isChecked) {
              selectedParticipants.add(c);
            } else {
              selectedParticipants.remove(c);
            }
          }
        });
    builder.setNegativeButton(R.string.label_cancel, null);
    builder.setPositiveButton(
        R.string.label_ok,
        new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int position) {
            /* Add new participants in the session in background */
            try {
              int max = mGroupChat.getMaxParticipants() - 1;
              int connected = mGroupChat.getParticipants().size();
              int limit = max - connected;
              if (selectedParticipants.size() > limit) {
                showMessage(R.string.label_max_participants);
                return;
              }
              Set<ContactId> contacts = new HashSet<>();
              ContactUtil contactUtils = ContactUtil.getInstance(GroupChatView.this);
              for (String participant : selectedParticipants) {
                contacts.add(contactUtils.formatContact(participant));
              }
              /* Add participants */
              mGroupChat.inviteParticipants(contacts);

            } catch (RcsServiceException e) {
              showException(e);
            }
          }
        });
    registerDialog(builder.show());
  }
Exemplo n.º 19
0
  private void showLanguageSelectDialog() {
    final boolean[] temp = new boolean[LANGUAGE_NUM];
    final boolean[] temp2 = new boolean[LANGUAGE_NUM];
    boolean allLanguagesFlag = true;
    for (int i = 1; i < temp.length; i++) {
      CellBroadcastLanguage tLanguage = mLanguageList.get(i);
      if (tLanguage != null) {
        MmsLog.d(LOG_TAG, "language status " + tLanguage.getLanguageState());
        temp[i] = tLanguage.getLanguageState();
        temp2[i] = tLanguage.getLanguageState();
      } else {
        MmsLog.i(LOG_TAG, "showLanguageSelectDialog() init the language list failed when i=" + i);
      }
      if (!temp[i]) {
        allLanguagesFlag = false; // not select all languages
      }
    }
    // init "All Languages" selection
    MmsLog.d(LOG_TAG, "All language status " + allLanguagesFlag);
    mLanguageList.get(0).setLanguageState(allLanguagesFlag);
    temp[0] = allLanguagesFlag;
    temp2[0] = allLanguagesFlag;
    final AlertDialog.Builder dlgBuilder = new AlertDialog.Builder(this);
    dlgBuilder.setTitle(getString(R.string.cb_dialog_title_language_choice));
    dlgBuilder.setPositiveButton(
        R.string.ok,
        new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int whichButton) {
            int tLength = temp.length;
            // if select "all languages"
            if (temp[0]) {
              for (int i = 0; i < tLength; i++) {
                temp[i] = true;
              }
            }
            // select a language at least
            boolean flag = false;
            for (int i = 0; i < tLength; i++) {
              mLanguageList.get(i).setLanguageState(temp[i]);
              if (temp[i]) {
                flag = true;
              }
            }

            if (flag) {
              SmsBroadcastConfigInfo[] langList = makeLanguageConfigArray();
              setCellBroadcastConfig(langList);
            } else {
              displayMessage(R.string.cb_error_language_select);
              for (int i = 0; i < tLength; i++) {
                mLanguageList.get(i).setLanguageState(temp2[i]);
              }
            }
          }
        });
    dlgBuilder.setNegativeButton(R.string.cancel, null);
    DialogInterface.OnMultiChoiceClickListener multiChoiceListener =
        new DialogInterface.OnMultiChoiceClickListener() {
          public void onClick(DialogInterface dialog, int whichButton, boolean isChecked) {
            temp[whichButton] = isChecked;
            AlertDialog languageDialog = null;
            if (dialog instanceof AlertDialog) {
              languageDialog = (AlertDialog) dialog;
            }
            if (whichButton == 0) {
              if (languageDialog != null) {
                for (int i = 1; i < temp.length; ++i) {
                  ListView items = languageDialog.getListView();
                  items.setItemChecked(i, isChecked);
                  temp[i] = isChecked;
                }
              }
            } else {
              if ((!isChecked) && (languageDialog != null)) {
                ListView items = languageDialog.getListView();
                items.setItemChecked(0, isChecked);
                temp[0] = false;
              } else if (isChecked && (languageDialog != null)) {
                /// M: ALPS00641361 @{
                // if select all language, the first item should be checked
                //
                // MTK add
                setCheckedAlllanguageItem(temp, isChecked, languageDialog);
                /// @}
              }
            }
          }
        };
    dlgBuilder.setMultiChoiceItems(R.array.language_list_values, temp, multiChoiceListener);
    AlertDialog languageDialog = dlgBuilder.create();
    if (languageDialog != null) {
      languageDialog.show();
    }
  }
  protected static void installFileDialog(final Context ctx, final File file) {
    Resources r = ctx.getResources();
    String[] installOpts = r.getStringArray(R.array.install_options);
    final boolean[] selectedOpts = new boolean[installOpts.length];
    selectedOpts[selectedOpts.length - 1] = true;

    AlertDialog.Builder alert = new AlertDialog.Builder(ctx);
    alert.setTitle(R.string.alert_install_title);
    //        alert.setMessage(R.string.alert_install_message);
    if (android.os.Build.DEVICE
        .toLowerCase()
        .equals("gt-n7000")) { // can't flash programmatically, must flash manually
      alert.setMessage(ctx.getString(R.string.alert_noinstall_message, file.getAbsolutePath()));
      alert.setNeutralButton(
          R.string.alert_ok,
          new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
              dialog.dismiss();
            }
          });
    } else {
      alert.setMultiChoiceItems(
          installOpts,
          selectedOpts,
          new DialogInterface.OnMultiChoiceClickListener() {
            public void onClick(DialogInterface dialog, int which, boolean isChecked) {
              selectedOpts[which] = isChecked;
            }
          });
      alert.setPositiveButton(
          R.string.alert_install,
          new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
              dialog.dismiss();

              AlertDialog.Builder alert = new AlertDialog.Builder(ctx);
              alert.setTitle(R.string.alert_install_title);
              alert.setMessage(R.string.alert_install_message);
              alert.setPositiveButton(
                  R.string.alert_install,
                  new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                      try {
                        String name = file.getName();

                        Process p = Runtime.getRuntime().exec("su");
                        DataOutputStream os = new DataOutputStream(p.getOutputStream());
                        os.writeBytes("rm -f /cache/recovery/command\n");
                        os.writeBytes("rm -f /cache/recovery/extendedcommand\n");
                        //                                if (selectedOpts[0]) {
                        //                                    os.writeBytes("echo 'backup_rom
                        // /sdcard/clockwordmod/backup/" +
                        //                                            new
                        // SimpleDateFormat("yyyy-MM-dd_HH.mm").format(new Date()) +
                        //                                            "' >>
                        // /cache/recovery/extendedcommand\n");
                        //                                }
                        if (selectedOpts[0]) {
                          os.writeBytes("echo '--wipe_data' >> /cache/recovery/command\n");
                        }
                        if (selectedOpts[1]) {
                          os.writeBytes("echo '--wipe_cache' >> /cache/recovery/command\n");
                        }

                        os.writeBytes(
                            "echo '--update_package=/"
                                + Utils.getRcvrySdPath()
                                + "/OTA-Updater/download/"
                                + name
                                + "' >> /cache/recovery/command\n");

                        if (!android.os.Build.DEVICE.toLowerCase().equals("gt-i9100")) {
                          os.writeBytes("reboot recovery\n");
                        }

                        os.writeBytes("exit\n");
                        os.flush();
                        p.waitFor();
                        ((PowerManager) ctx.getSystemService(POWER_SERVICE)).reboot("recovery");
                      } catch (Exception e) {
                        e.printStackTrace();
                      }
                    }
                  });
              alert.setNegativeButton(
                  R.string.alert_cancel,
                  new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                      dialog.dismiss();
                    }
                  });
              alert.create().show();
            }
          });
      alert.setNegativeButton(
          R.string.alert_cancel,
          new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
              dialog.dismiss();
            }
          });
    }
    alert.create().show();
  }
  private void createDialog(BluetoothDevice device, int state, int startId) {
    if (mDialog != null) {
      // Shouldn't normally happen
      mDialog.dismiss();
      mDialog = null;
    }
    mDevice = device;
    switch (state) {
      case Intent.EXTRA_DOCK_STATE_CAR:
      case Intent.EXTRA_DOCK_STATE_DESK:
      case Intent.EXTRA_DOCK_STATE_LE_DESK:
      case Intent.EXTRA_DOCK_STATE_HE_DESK:
        break;
      default:
        return;
    }

    startForeground(0, new Notification());

    final AlertDialog.Builder ab = new AlertDialog.Builder(this);
    View view;
    LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);

    mAudioMediaCheckbox = null;

    if (device != null) {
      // Device in a new dock.
      boolean firstTime =
          !LocalBluetoothPreferences.hasDockAutoConnectSetting(this, device.getAddress());

      CharSequence[] items = initBtSettings(device, state, firstTime);

      ab.setTitle(getString(R.string.bluetooth_dock_settings_title));

      // Profiles
      ab.setMultiChoiceItems(items, mCheckedItems, mMultiClickListener);

      // Remember this settings
      view = inflater.inflate(R.layout.remember_dock_setting, null);
      CheckBox rememberCheckbox = (CheckBox) view.findViewById(R.id.remember);

      // check "Remember setting" by default if no value was saved
      boolean checked =
          firstTime
              || LocalBluetoothPreferences.getDockAutoConnectSetting(this, device.getAddress());
      rememberCheckbox.setChecked(checked);
      rememberCheckbox.setOnCheckedChangeListener(mCheckedChangeListener);
      if (DEBUG) {
        Log.d(
            TAG,
            "Auto connect = "
                + LocalBluetoothPreferences.getDockAutoConnectSetting(this, device.getAddress()));
      }
    } else {
      ab.setTitle(getString(R.string.bluetooth_dock_settings_title));

      view = inflater.inflate(R.layout.dock_audio_media_enable_dialog, null);
      mAudioMediaCheckbox = (CheckBox) view.findViewById(R.id.dock_audio_media_enable_cb);

      boolean checked =
          Settings.Global.getInt(getContentResolver(), Settings.Global.DOCK_AUDIO_MEDIA_ENABLED, 0)
              == 1;

      mAudioMediaCheckbox.setChecked(checked);
      mAudioMediaCheckbox.setOnCheckedChangeListener(mCheckedChangeListener);
    }

    float pixelScaleFactor = getResources().getDisplayMetrics().density;
    int viewSpacingLeft = (int) (14 * pixelScaleFactor);
    int viewSpacingRight = (int) (14 * pixelScaleFactor);
    ab.setView(view, viewSpacingLeft, 0 /* top */, viewSpacingRight, 0 /* bottom */);

    // Ok Button
    ab.setPositiveButton(getString(android.R.string.ok), mClickListener);

    mStartIdAssociatedWithDialog = startId;
    mDialog = ab.create();
    mDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
    mDialog.setOnDismissListener(mDismissListener);
    mDialog.show();
  }
Exemplo n.º 22
0
  @Override
  protected Dialog onCreateDialog(int id) {
    // TODO Auto-generated method stub
    if (id == 0) {
      AlertDialog.Builder builder = new AlertDialog.Builder(this);
      builder.setMessage("您确定要退出么");
      builder.setPositiveButton(
          "确定",
          new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
              // TODO Auto-generated method stub
              System.exit(0);
            }
          });
      builder.setNegativeButton(
          "取消",
          new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
              // TODO Auto-generated method stub
              return;
            }
          });
      return builder.create();
    }
    if (id == 1) {
      AlertDialog.Builder builder = new AlertDialog.Builder(this);
      builder.setItems(
          R.array.hobby,
          new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
              // TODO Auto-generated method stub
              Toast.makeText(
                      MyDialogActivity.this,
                      getResources().getStringArray(R.array.hobby)[which],
                      1000)
                  .show();
            }
          });
      return builder.create();
    }
    if (id == 2) {
      AlertDialog.Builder builder = new AlertDialog.Builder(this);
      builder.setSingleChoiceItems(
          R.array.hobby,
          0,
          new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
              // TODO Auto-generated method stub
              Toast.makeText(
                      MyDialogActivity.this,
                      getResources().getStringArray(R.array.hobby)[which],
                      1000)
                  .show();
            }
          });
      builder.setPositiveButton(
          "确定",
          new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
              // TODO Auto-generated method stub
              return;
            }
          });
      return builder.create();
    }
    if (id == 3) {
      AlertDialog.Builder builder = new AlertDialog.Builder(this);
      boolean[] checked = {true, true, false, false, false};
      builder.setMultiChoiceItems(
          R.array.hobby,
          checked,
          new DialogInterface.OnMultiChoiceClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which, boolean isChecked) {
              // TODO Auto-generated method stub
              Toast.makeText(
                      MyDialogActivity.this,
                      getResources().getStringArray(R.array.hobby)[which],
                      1000)
                  .show();
            }
          });
      builder.setPositiveButton(
          "确定",
          new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
              // TODO Auto-generated method stub
              return;
            }
          });
      return builder.create();
    }
    if (id == 4) {
      Calendar cal = Calendar.getInstance();
      DatePickerDialog dialog =
          new DatePickerDialog(
              MyDialogActivity.this,
              new DatePickerDialog.OnDateSetListener() {

                @Override
                public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                  // TODO Auto-generated method stub
                  Toast.makeText(
                          MyDialogActivity.this,
                          "您选择了" + year + "年" + (monthOfYear + 1) + "月",
                          1000)
                      .show();
                }
              },
              cal.get(Calendar.YEAR),
              cal.get(Calendar.MONTH),
              cal.get(Calendar.DAY_OF_MONTH));
      return dialog;
    }
    if (id == 5) {
      Calendar cal = Calendar.getInstance();
      TimePickerDialog dialog =
          new TimePickerDialog(
              MyDialogActivity.this,
              new TimePickerDialog.OnTimeSetListener() {

                @Override
                public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                  // TODO Auto-generated method stub
                  Toast.makeText(
                          MyDialogActivity.this, "您选择了" + hourOfDay + "点" + (minute) + "分", 1000)
                      .show();
                }
              },
              cal.get(Calendar.HOUR_OF_DAY),
              cal.get(Calendar.MINUTE),
              true);
      return dialog;
    }
    return super.onCreateDialog(id);
  }
  protected void chooseFromMultipleItems(
      List<ContactResult.ResultItem> items, CheckBox checkbox, String id) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    ArrayList<String> itemLabels = new ArrayList<String>(items.size());

    for (ResultItem resultItem : items) {
      itemLabels.add(resultItem.getResult());
    }

    class ClickListener implements OnCancelListener, OnClickListener, OnMultiChoiceClickListener {
      private List<ContactResult.ResultItem> items;
      private CheckBox checkbox;
      private String id;
      private boolean[] checked;

      public ClickListener(List<ContactResult.ResultItem> items, CheckBox checkbox, String id) {
        this.items = items;
        this.checkbox = checkbox;
        this.id = id;
        checked = new boolean[items.size()];
      }

      @Override
      public void onClick(DialogInterface dialog, int which) {
        finish();
      }

      @Override
      public void onClick(DialogInterface arg0, int which, boolean isChecked) {
        checked[which] = isChecked;
      }

      private void finish() {
        ArrayList<ContactResult.ResultItem> result =
            new ArrayList<ContactResult.ResultItem>(items.size());
        for (int i = 0; i < items.size(); ++i) {
          if (checked[i]) {
            result.add(items.get(i));
          }
        }
        if (result.size() == 0) {
          checkbox.setChecked(false);
        } else {
          results.put(id, new ContactResult(id, result));
        }
      }

      @Override
      public void onCancel(DialogInterface dialog) {
        finish();
      }
    }

    ClickListener clickListener = new ClickListener(items, checkbox, id);

    builder
        .setMultiChoiceItems(itemLabels.toArray(new String[0]), null, clickListener)
        .setOnCancelListener(clickListener)
        .setPositiveButton(android.R.string.ok, clickListener)
        .show();
  }
Exemplo n.º 24
0
  private void showAvailableBleDevices() {
    String title = getResources().getString(R.string.dialog_title_select_devices);
    final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(MainActivity.this);
    dialogBuilder.setTitle(title);

    // ArrayList to keep the selected devices
    final ArrayList<Integer> selectedItems = new ArrayList<>();
    ArrayList<String> devicesList = new ArrayList<>();

    // Get the list of available devices
    for (int i = 0; i < mMultiBleService.getBluetoothDevices().size(); i++) {
      BluetoothDevice device = mMultiBleService.getBluetoothDevices().valueAt(i);
      devicesList.add(String.format("%s %s", device.getName(), device.getAddress()));
    }
    CharSequence[] devicesArray = devicesList.toArray(new CharSequence[devicesList.size()]);

    // Create alert dialog with multi-choice items
    dialogBuilder
        .setMultiChoiceItems(
            devicesArray,
            null,
            new DialogInterface.OnMultiChoiceClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int indexSelected, boolean isChecked) {
                if (isChecked) {
                  // If the user checked the item, add it to the selected items
                  selectedItems.add(indexSelected);
                } else if (selectedItems.contains(indexSelected)) {
                  // Else, if the item is already in the array, remove it
                  selectedItems.remove(Integer.valueOf(indexSelected));
                }
              }
            })
        .setPositiveButton(
            getString(R.string.action_connect),
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int id) {
                // Save the selected items' references
                ArrayList<BluetoothDevice> selectedDevices = new ArrayList<>();
                for (int i = 0; i < selectedItems.size(); i++) {
                  selectedDevices.add(
                      mMultiBleService.getBluetoothDevices().valueAt(selectedItems.get(i)));
                }
                Log.i(TAG, String.format("Selected devices: %s", selectedDevices.toString()));

                // Connect with the devices
                mMultiBleService.connectToDevices(selectedDevices);
                mButtonScan.setEnabled(false);
                mButtonDisconnect.setEnabled(true);
                dialog.dismiss();
              }
            })
        .setNegativeButton(
            "Cancel",
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int id) {
                dialog.dismiss();
              }
            })
        .create();
    dialogBuilder.show();
  }
  private void openWidgetsToggleDialog() {
    final List<WidgetBase> widgets = mCapabilities.getWidgets();
    List<String> widgetsName = new ArrayList<String>();

    // Construct a list of widgets
    for (WidgetBase widget : widgets) {
      if (widget.getClass().getName().contains("SettingsWidget")) continue;
      widgetsName.add(widget.getToggleButton().getHintText());
    }

    CharSequence[] items = widgetsName.toArray(new CharSequence[widgetsName.size()]);

    AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
    builder.setTitle(mContext.getString(R.string.widget_settings_choose_widgets));
    builder
        .setMultiChoiceItems(
            items,
            null,
            new DialogInterface.OnMultiChoiceClickListener() {
              // indexSelected contains the index of item (of which checkbox checked)
              @Override
              public void onClick(DialogInterface dialog, int indexSelected, boolean isChecked) {
                widgets.get(indexSelected).setHidden(!isChecked);
              }
            })
        // Set the action buttons
        .setPositiveButton(
            "OK",
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int id) {
                // Store the widget visibility status in SharedPreferences, using the
                // widget class name as key
                for (WidgetBase widget : widgets) {
                  if (widget.getClass().getName().contains("SettingsWidget")) {
                    continue;
                  }

                  SettingsStorage.storeVisibilitySetting(
                      mContext, widget.getClass().getName(), !widget.isHidden());
                }
              }
            })
        .setNegativeButton(
            "Cancel",
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int id) {
                // Restore visibility status from storage
                for (WidgetBase widget : widgets) {
                  if (widget.getClass().getName().contains("SettingsWidget")) {
                    continue;
                  }

                  widget.setHidden(
                      !SettingsStorage.getVisibilitySetting(mContext, widget.getClass().getName()));
                }
              }
            });

    mWidgetsDialog = builder.create();
    mWidgetsDialog.show();
    for (int i = 0; i < widgets.size(); i++) {
      mWidgetsDialog.getListView().setItemChecked(i, !widgets.get(i).isHidden());
    }
    ((ViewGroup) mWidgetsDialog.getListView().getParent().getParent().getParent())
        .animate()
        .rotation(mOrientation)
        .setDuration(300)
        .start();
  }
    @Override
    public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
      if (preference == mEnabledToggles) {
        AlertDialog.Builder builder = new AlertDialog.Builder(StatusBarToggles.this);

        TelephonyManager telephony =
            (TelephonyManager) getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);

        final boolean isCdma = (telephony.getCurrentPhoneType() == Phone.PHONE_TYPE_CDMA);

        ArrayList<String> enabledToggles =
            TogglesLayout.getTogglesStringArray(getApplicationContext());

        boolean checkedToggles[] =
            new boolean[isCdma ? availableCdmaToggles.length : availableGsmToggles.length];

        for (int i = 0; i < checkedToggles.length; i++) {
          if (isCdma && enabledToggles.contains(availableCdmaToggles[i])) {
            checkedToggles[i] = true;
          } else if (!isCdma && enabledToggles.contains(availableGsmToggles[i])) {
            checkedToggles[i] = true;
          }
        }

        builder.setTitle("Choose which toggles to use");
        builder.setCancelable(false);
        builder.setPositiveButton(
            "Close",
            new DialogInterface.OnClickListener() {

              @Override
              public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
              }
            });
        builder.setMultiChoiceItems(
            isCdma ? availableCdmaToggles : availableGsmToggles,
            checkedToggles,
            new OnMultiChoiceClickListener() {

              @Override
              public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                String toggleKey =
                    (isCdma ? availableCdmaToggles[which] : availableGsmToggles[which]);

                if (isChecked) addToggle(getApplicationContext(), toggleKey);
                else removeToggle(getApplicationContext(), toggleKey);
              }
            });

        AlertDialog d = builder.create();

        d.show();

        return true;
      } else if (preference == mAlternateButtonLayout) {

        Settings.System.putInt(
            getContentResolver(),
            Settings.System.STATUSBAR_TOGGLES_USE_BUTTONS,
            ((CheckBoxPreference) preference).isChecked() ? 1 : 0);
        return true;
      }
      return super.onPreferenceTreeClick(preferenceScreen, preference);
    }