Search in sources :

Example 1 with BadTokenException

use of android.view.WindowManager.BadTokenException in project Anki-Android by Ramblurr.

the class Preferences method onSharedPreferenceChanged.

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();
        } else if (key.equals("overrideFont")) {
            ListPreference overrideFontPreference = (ListPreference) getPreferenceScreen().findPreference("overrideFont");
            ListPreference defaultFontPreference = (ListPreference) getPreferenceScreen().findPreference("defaultFont");
            onOverrideFontChange(overrideFontPreference, defaultFontPreference);
        }
        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();
    }
}
Also used : Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) JSONException(org.json.JSONException) Intent(android.content.Intent) ListPreference(android.preference.ListPreference) File(java.io.File) BadTokenException(android.view.WindowManager.BadTokenException)

Example 2 with BadTokenException

use of android.view.WindowManager.BadTokenException in project newsrob by marianokamp.

the class LoginParameters method onError.

private void onError(Exception ex) {
    if (ex != null)
        ex.printStackTrace();
    if (ex instanceof LoginWithCaptchaRequiredException) {
        LoginWithCaptchaRequiredException e = (LoginWithCaptchaRequiredException) ex;
        configureView(e.getCaptchaToken(), e.getCaptchaUrl());
        return;
    }
    configureView(null, null);
    final AlertDialog dialog = new AlertDialog.Builder(LoginActivity.this).create();
    dialog.setIcon(android.R.drawable.ic_dialog_alert);
    dialog.setButton("OK", new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    // i18n
    dialog.setTitle(U.t(LoginActivity.this, R.string.login_error_dialog_title));
    dialog.setMessage(U.t(LoginActivity.this, R.string.login_error_dialog_message) + " " + ex.getMessage() + "/n(" + ex.getClass() + // i18n
    ")");
    try {
        dialog.show();
    } catch (BadTokenException e) {
    //
    }
// mUsername.setError(getString(R.string.screen_login_error));
}
Also used : AlertDialog(android.app.AlertDialog) LoginWithCaptchaRequiredException(com.newsrob.LoginWithCaptchaRequiredException) DialogInterface(android.content.DialogInterface) BadTokenException(android.view.WindowManager.BadTokenException)

Example 3 with BadTokenException

use of android.view.WindowManager.BadTokenException in project newsrob by marianokamp.

the class AccountListActivity method onError.

protected void onError(Exception ex) {
    final AlertDialog dialog = new AlertDialog.Builder(this).create();
    dialog.setIcon(android.R.drawable.ic_dialog_alert);
    dialog.setButton("OK", new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    // i18n
    dialog.setTitle(U.t(this, R.string.login_error_dialog_title));
    String message = null;
    if (ex instanceof IOException)
        message = "Could not reach the Google server. Are you online?";
    else
        message = U.t(this, R.string.login_error_dialog_message) + " " + ex.getMessage();
    // i18n
    dialog.setMessage(message);
    try {
        dialog.show();
    } catch (BadTokenException e) {
    //
    }
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) IOException(java.io.IOException) BadTokenException(android.view.WindowManager.BadTokenException)

Example 4 with BadTokenException

use of android.view.WindowManager.BadTokenException in project android_frameworks_base by ResurrectionRemix.

the class InputMethodService method showWindow.

public void showWindow(boolean showInput) {
    if (DEBUG)
        Log.v(TAG, "Showing window: showInput=" + showInput + " mShowInputRequested=" + mShowInputRequested + " mWindowAdded=" + mWindowAdded + " mWindowCreated=" + mWindowCreated + " mWindowVisible=" + mWindowVisible + " mInputStarted=" + mInputStarted + " mShowInputFlags=" + mShowInputFlags);
    if (mInShowWindow) {
        Log.w(TAG, "Re-entrance in to showWindow");
        return;
    }
    try {
        mWindowWasVisible = mWindowVisible;
        mInShowWindow = true;
        showWindowInner(showInput);
    } catch (BadTokenException e) {
        // while there is a DO_SHOW_SOFT_INPUT message in the IIMethodWrapper queue.
        if (DEBUG)
            Log.v(TAG, "BadTokenException: IME is done.");
        mWindowVisible = false;
        mWindowAdded = false;
        // InputMethodManager#showSoftInputFromInputMethod() should always be used instead.
        throw e;
    } finally {
        // TODO: Is it OK to set true when we get BadTokenException?
        mWindowWasVisible = true;
        mInShowWindow = false;
    }
    IStatusBarService statusbar = getStatusBarService();
    int mKeyboardRotationTimeout = Settings.System.getIntForUser(getContentResolver(), Settings.System.KEYBOARD_ROTATION_TIMEOUT, 0, UserHandle.USER_CURRENT_OR_SELF);
    if (mKeyboardRotationTimeout > 0) {
        mHandler.removeCallbacks(restoreAutoRotation);
        if (!mForcedAutoRotate) {
            boolean isAutoRotate = (Settings.System.getIntForUser(getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT_OR_SELF) == 1);
            if (!isAutoRotate) {
                try {
                    if (statusbar != null) {
                        statusbar.setAutoRotate(true);
                        mForcedAutoRotate = true;
                    }
                } catch (RemoteException e) {
                    mStatusBarService = null;
                }
            }
        }
    }
}
Also used : IStatusBarService(com.android.internal.statusbar.IStatusBarService) RemoteException(android.os.RemoteException) BadTokenException(android.view.WindowManager.BadTokenException)

Aggregations

BadTokenException (android.view.WindowManager.BadTokenException)4 AlertDialog (android.app.AlertDialog)2 DialogInterface (android.content.DialogInterface)2 Intent (android.content.Intent)1 RemoteException (android.os.RemoteException)1 ListPreference (android.preference.ListPreference)1 IStatusBarService (com.android.internal.statusbar.IStatusBarService)1 LoginWithCaptchaRequiredException (com.newsrob.LoginWithCaptchaRequiredException)1 File (java.io.File)1 IOException (java.io.IOException)1 Calendar (java.util.Calendar)1 GregorianCalendar (java.util.GregorianCalendar)1 JSONException (org.json.JSONException)1