@Override protected void onCreate(Bundle icicle) { // 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(icicle); mCol = AnkiDroidApp.getCol(); if (mCol == null) { finish(); return; } mDeck = mCol.getDecks().current(); registerExternalStorageListener(); if (mCol == null) { Log.i(AnkiDroidApp.TAG, "DeckOptions - No Collection loaded"); finish(); return; } else { mPref = new DeckPreferenceHack(); mPref.registerOnSharedPreferenceChangeListener(this); this.addPreferencesFromResource(R.xml.deck_options); this.buildLists(); this.updateSummaries(); } }
public static boolean repairDeck(String deckPath) { File deckFile = new File(deckPath); Collection col = AnkiDroidApp.getCol(); if (col != null) { col.close(); } AnkiDatabaseManager.closeDatabase(deckPath); // repair file String execString = "sqlite3 " + deckPath + " .dump | sqlite3 " + deckPath + ".tmp"; Log.i(AnkiDroidApp.TAG, "repairDeck - Execute: " + execString); try { String[] cmd = {"/system/bin/sh", "-c", execString}; Process process = Runtime.getRuntime().exec(cmd); process.waitFor(); if (!new File(deckPath + ".tmp").exists()) { return false; } if (!moveDatabaseToBrokenFolder(deckPath, false)) { return false; } Log.i(AnkiDroidApp.TAG, "repairDeck - moved corrupt file to broken folder"); File repairedFile = new File(deckPath + ".tmp"); if (!repairedFile.renameTo(deckFile)) { return false; } return true; } catch (IOException e) { Log.e("AnkiDroidApp.TAG", "repairCollection - error: " + e); } catch (InterruptedException e) { Log.e("AnkiDroidApp.TAG", "repairCollection - error: " + e); } return false; }
@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); } }
public Collection getCol() { return AnkiDroidApp.getCol(); }