コード例 #1
0
 private void initLanguageMap() {
   mLanguageMap = new HashMap<String, CellBroadcastLanguage>();
   for (int i = 0; i < LANGUAGE_NUM; i++) {
     CellBroadcastLanguage language = mLanguageList.get(i);
     if (language != null) {
       int id = language.getLanguageId();
       mLanguageMap.put(String.valueOf(id), language);
     }
   }
 }
コード例 #2
0
 private void updateLanguagesWithSingleConfig(SmsBroadcastConfigInfo info) {
   int languageBeginIndex = info.getFromCodeScheme();
   int languageEndIndex = info.getToCodeScheme();
   if (languageBeginIndex != -1 && languageBeginIndex != -2) {
     for (int j = languageBeginIndex; j <= languageEndIndex; j++) {
       if (mCellBroadcastAsyncTask.isCancelled()) {
         break;
       }
       CellBroadcastLanguage language = getLanguageObjectFromKey(String.valueOf(j));
       if (language != null) {
         language.setLanguageState(info.isSelected());
       }
     }
   } else {
     MmsLog.d(LOG_TAG, "Select all language!");
     if (languageBeginIndex == -2 && languageEndIndex == -2) {
       for (int i = 0; i < mLanguageList.size(); i++) {
         if (mCellBroadcastAsyncTask.isCancelled()) {
           break;
         }
         CellBroadcastLanguage language = (CellBroadcastLanguage) mLanguageList.get(i);
         CellBroadcastLanguage lang =
             getLanguageObjectFromKey(String.valueOf(language.getLanguageId()));
         if (lang != null) {
           lang.setLanguageState(true);
         }
       }
     }
   }
 }
コード例 #3
0
  // convert selection info to SmsBroadcastConfigInfo[],and send to the system
  private SmsBroadcastConfigInfo[] makeLanguageConfigArray() {
    ArrayList<SmsBroadcastConfigInfo> list = new ArrayList<SmsBroadcastConfigInfo>();

    if (mLanguageList.get(0).getLanguageState()) {
      SmsBroadcastConfigInfo cBConfig = new SmsBroadcastConfigInfo(-1, -1, -2, -2, true);
      list.add(cBConfig);
    } else {
      int beginId = mLanguageList.get(1).getLanguageId();
      int endId = beginId;
      boolean beginState = mLanguageList.get(1).getLanguageState();
      int i = 2;
      int tSize = mLanguageList.size();
      for (i = 2; i < tSize; i++) {
        CellBroadcastLanguage tLanguage = mLanguageList.get(i);
        int tempId = tLanguage.getLanguageId();
        boolean tempState = tLanguage.getLanguageState();
        if ((tempId == endId + 1) && (beginState == tempState)) {
          endId = tempId;
        } else {
          SmsBroadcastConfigInfo cBConfig =
              new SmsBroadcastConfigInfo(-1, -1, beginId, endId, beginState);
          list.add(cBConfig);
          beginId = tempId;
          endId = tempId;
          beginState = tempState;
        }
      }

      if (i == mLanguageList.size()) {
        endId = mLanguageList.get(i - 1).getLanguageId();
        SmsBroadcastConfigInfo cBConfig =
            new SmsBroadcastConfigInfo(-1, -1, beginId, endId, beginState);
        list.add(cBConfig);
      }
    }

    return list.toArray(new SmsBroadcastConfigInfo[list.size()]);
  }
コード例 #4
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();
    }
  }