예제 #1
0
 private void updateSeekBarPreference(String key) {
   SeekBarPreference seekpref = (SeekBarPreference) getPreferenceScreen().findPreference(key);
   try {
     if (mListsToUpdate.containsKey(key)) {
       seekpref.setSummary(
           replaceString(mListsToUpdate.get(key), Integer.toString(seekpref.getValue())));
     } else {
       String oldsum = (String) seekpref.getSummary();
       if (oldsum.contains("XXX")) {
         mListsToUpdate.put(key, oldsum);
         seekpref.setSummary(replaceString(oldsum, Integer.toString(seekpref.getValue())));
       } else {
         seekpref.setSummary(Integer.toString(seekpref.getValue()));
       }
     }
   } catch (NullPointerException e) {
     Log.e(AnkiDroidApp.TAG, "Exception when updating seekbar preference: " + e);
   }
 }
예제 #2
0
 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
   try {
     if (key.equals("swipe")) {
       zoomCheckboxPreference.setChecked(false);
       zoomCheckboxPreference.setEnabled(!swipeCheckboxPreference.isChecked());
     } else if (key.equals("timeoutAnswer")) {
       keepScreenOnCheckBoxPreference.setChecked(showAnswerCheckBoxPreference.isChecked());
     } else if (key.equals("language")) {
       closePreferences();
     } else if (key.equals("theme")) {
       String theme = sharedPreferences.getString("theme", "3");
       if (theme.equals("2") || theme.equals("3")) {
         animationsCheckboxPreference.setChecked(false);
         animationsCheckboxPreference.setEnabled(false);
       } else {
         animationsCheckboxPreference.setEnabled(true);
       }
       Themes.loadTheme();
       switch (Integer.parseInt(sharedPreferences.getString("theme", "3"))) {
         case Themes.THEME_ANDROID_DARK:
         case Themes.THEME_ANDROID_LIGHT:
         case Themes.THEME_BLUE:
           sharedPreferences.edit().putString("defaultFont", "").commit();
           break;
         case Themes.THEME_FLAT:
           sharedPreferences.edit().putString("defaultFont", "OpenSans").commit();
           break;
         case Themes.THEME_WHITE:
           sharedPreferences.edit().putString("defaultFont", "OpenSans").commit();
           break;
       }
       Intent intent = this.getIntent();
       setResult(DeckPicker.RESULT_RESTART, intent);
       closePreferences();
     } else if (key.equals("writeAnswers") && sharedPreferences.getBoolean("writeAnswers", true)) {
       showDialog(DIALOG_WRITE_ANSWERS);
     } else if (key.equals("useBackup")) {
       if (lockCheckAction) {
         lockCheckAction = false;
       } else if (!useBackupPreference.isChecked()) {
         lockCheckAction = true;
         useBackupPreference.setChecked(true);
         showDialog(DIALOG_BACKUP);
       }
     } else if (key.equals("asyncMode")) {
       if (lockCheckAction) {
         lockCheckAction = false;
       } else if (asyncModePreference.isChecked()) {
         lockCheckAction = true;
         asyncModePreference.setChecked(false);
         showDialog(DIALOG_ASYNC);
       }
     } else if (key.equals("deckPath")) {
       File decksDirectory = new File(AnkiDroidApp.getCurrentAnkiDroidDirectory());
       if (decksDirectory.exists()) {
         AnkiDroidApp.createNoMediaFileIfMissing(decksDirectory);
       }
     } else if (key.equals("eInkDisplay")) {
       animationsCheckboxPreference.setChecked(false);
       animationsCheckboxPreference.setEnabled(!eInkDisplayPreference.isChecked());
       fadeScrollbars.setChecked(false);
       fadeScrollbars.setEnabled(!eInkDisplayPreference.isChecked());
     } else if (key.equals("convertFenText")) {
       if (convertFenText.isChecked()) {
         ChessFilter.install(AnkiDroidApp.getHooks());
       } else {
         ChessFilter.uninstall(AnkiDroidApp.getHooks());
       }
     } else if (key.equals("fixHebrewText")) {
       if (fixHebrewText.isChecked()) {
         HebrewFixFilter.install(AnkiDroidApp.getHooks());
         showDialog(DIALOG_HEBREW_FONT);
       } else {
         HebrewFixFilter.uninstall(AnkiDroidApp.getHooks());
       }
     } else if (key.equals("showProgress")) {
       mCol.getConf().put("dueCounts", showProgress.isChecked());
       mCol.setMod();
     } else if (key.equals("showEstimates")) {
       mCol.getConf().put("estTimes", showEstimates.isChecked());
       mCol.setMod();
     } else if (key.equals("newSpread")) {
       mCol.getConf().put("newSpread", Integer.parseInt(newSpread.getValue()));
       mCol.setMod();
     } else if (key.equals("timeLimit")) {
       mCol.getConf().put("timeLim", timeLimit.getValue() * 60);
       mCol.setMod();
     } else if (key.equals("learnCutoff")) {
       mCol.getConf().put("collapseTime", learnCutoff.getValue() * 60);
       mCol.setMod();
     } else if (key.equals("useCurrent")) {
       mCol.getConf().put("addToCur", useCurrent.getValue().equals("0") ? true : false);
       mCol.setMod();
     } else if (key.equals("dayOffset")) {
       int hours = dayOffset.getValue();
       Calendar date = (Calendar) mStartDate.clone();
       date.set(Calendar.HOUR_OF_DAY, hours);
       mCol.setCrt(date.getTimeInMillis() / 1000);
       mCol.setMod();
     }
     if (Arrays.asList(mShowValueInSummList).contains(key)) {
       updateListPreference(key);
     } else if (Arrays.asList(mShowValueInSummSeek).contains(key)) {
       updateSeekBarPreference(key);
     } else if (Arrays.asList(mShowValueInSummEditText).contains(key)) {
       updateEditTextPreference(key);
     } else if (Arrays.asList(mShowValueInSummNumRange).contains(key)) {
       updateNumberRangePreference(key);
     }
   } catch (BadTokenException e) {
     Log.e(AnkiDroidApp.TAG, "Preferences: BadTokenException on showDialog: " + e);
   } catch (NumberFormatException e) {
     throw new RuntimeException();
   } catch (JSONException e) {
     throw new RuntimeException();
   }
 }
예제 #3
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    // Workaround for bug 4611: http://code.google.com/p/android/issues/detail?id=4611
    if (AnkiDroidApp.SDK_VERSION >= 7 && AnkiDroidApp.SDK_VERSION <= 10) {
      Themes.applyTheme(this, Themes.THEME_ANDROID_DARK);
    }
    super.onCreate(savedInstanceState);

    mCol = AnkiDroidApp.getCol();
    mPrefMan = getPreferenceManager();
    mPrefMan.setSharedPreferencesName(AnkiDroidApp.SHARED_PREFS_NAME);

    addPreferencesFromResource(R.xml.preferences);

    swipeCheckboxPreference = (CheckBoxPreference) getPreferenceScreen().findPreference("swipe");
    zoomCheckboxPreference = (CheckBoxPreference) getPreferenceScreen().findPreference("zoom");
    keepScreenOnCheckBoxPreference =
        (CheckBoxPreference) getPreferenceScreen().findPreference("keepScreenOn");
    showAnswerCheckBoxPreference =
        (CheckBoxPreference) getPreferenceScreen().findPreference("timeoutAnswer");
    animationsCheckboxPreference =
        (CheckBoxPreference) getPreferenceScreen().findPreference("themeAnimations");
    useBackupPreference = (CheckBoxPreference) getPreferenceScreen().findPreference("useBackup");
    asyncModePreference = (CheckBoxPreference) getPreferenceScreen().findPreference("asyncMode");
    eInkDisplayPreference =
        (CheckBoxPreference) getPreferenceScreen().findPreference("eInkDisplay");
    fadeScrollbars = (CheckBoxPreference) getPreferenceScreen().findPreference("fadeScrollbars");
    //        ListPreference listpref = (ListPreference)
    // getPreferenceScreen().findPreference("theme");
    convertFenText = (CheckBoxPreference) getPreferenceScreen().findPreference("convertFenText");
    fixHebrewText = (CheckBoxPreference) getPreferenceScreen().findPreference("fixHebrewText");
    syncAccount = (Preference) getPreferenceScreen().findPreference("syncAccount");
    showEstimates = (CheckBoxPreference) getPreferenceScreen().findPreference("showEstimates");
    showProgress = (CheckBoxPreference) getPreferenceScreen().findPreference("showProgress");
    learnCutoff = (NumberRangePreference) getPreferenceScreen().findPreference("learnCutoff");
    timeLimit = (NumberRangePreference) getPreferenceScreen().findPreference("timeLimit");
    useCurrent = (ListPreference) getPreferenceScreen().findPreference("useCurrent");
    newSpread = (ListPreference) getPreferenceScreen().findPreference("newSpread");
    dayOffset = (SeekBarPreference) getPreferenceScreen().findPreference("dayOffset");
    //        String theme = listpref.getValue();
    //        animationsCheckboxPreference.setEnabled(theme.equals("2") || theme.equals("3"));
    zoomCheckboxPreference.setEnabled(!swipeCheckboxPreference.isChecked());

    initializeLanguageDialog();
    initializeCustomFontsDialog();

    if (mCol != null) {
      // For collection preferences, we need to fetch the correct values from the collection
      mStartDate = GregorianCalendar.getInstance();
      Timestamp timestamp = new Timestamp(mCol.getCrt() * 1000);
      mStartDate.setTimeInMillis(timestamp.getTime());
      dayOffset.setValue(mStartDate.get(Calendar.HOUR_OF_DAY));
      try {
        JSONObject conf = mCol.getConf();
        learnCutoff.setValue(conf.getInt("collapseTime") / 60);
        timeLimit.setValue(conf.getInt("timeLim") / 60);
        showEstimates.setChecked(conf.getBoolean("estTimes"));
        showProgress.setChecked(conf.getBoolean("dueCounts"));
        newSpread.setValueIndex(conf.getInt("newSpread"));
        useCurrent.setValueIndex(conf.getBoolean("addToCur") ? 0 : 1);
      } catch (JSONException e) {
        throw new RuntimeException();
      } catch (NumberFormatException e) {
        throw new RuntimeException();
      }
    } else {
      // It's possible to open the preferences from the loading screen if no SD card is found.
      // In that case, there will be no collection loaded, so we need to disable the settings
      // that read from and write to the collection.
      dayOffset.setEnabled(false);
      learnCutoff.setEnabled(false);
      timeLimit.setEnabled(false);
      showEstimates.setEnabled(false);
      showProgress.setEnabled(false);
      newSpread.setEnabled(false);
      useCurrent.setEnabled(false);
    }

    for (String key : mShowValueInSummList) {
      updateListPreference(key);
    }
    for (String key : mShowValueInSummSeek) {
      updateSeekBarPreference(key);
    }
    for (String key : mShowValueInSummEditText) {
      updateEditTextPreference(key);
    }
    for (String key : mShowValueInSummNumRange) {
      updateNumberRangePreference(key);
    }

    if (AnkiDroidApp.SDK_VERSION <= 4) {
      fadeScrollbars.setChecked(false);
      fadeScrollbars.setEnabled(false);
    }
  }