Java Code Examples for android.preference.Preference#getContext()

The following examples show how to use android.preference.Preference#getContext() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ControlYourDeviceActivity.java    From AdminControl with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object o) {
    ControlYourDeviceActivity mainPrefActivity =
        ((ControlYourDeviceActivity)preference.getContext());
    if  (! mainPrefActivity.hasDeviceAdmin()) {
        mainPrefActivity.showPermissionExplanation();
    }

    DevicePolicyManager dpm = mainPrefActivity.getDPM();
    ComponentName deviceOwnerComponent = mainPrefActivity.getDeviceOwnerComponent();
    boolean bValue = (Boolean)o;
    int keyguardDisabledFeatures =
            KeyguardFeatures.setFingerprintDisabled(
                    dpm.getKeyguardDisabledFeatures(deviceOwnerComponent), bValue);
    try {
        dpm.setKeyguardDisabledFeatures(deviceOwnerComponent, keyguardDisabledFeatures);
    } catch (SecurityException s) {
        return false;
    }
    return true;
}
 
Example 2
Source File: ThemeSettingsFragment.java    From openboard with GNU General Public License v3.0 5 votes vote down vote up
static void updateKeyboardThemeSummary(final Preference pref) {
    final Context context = pref.getContext();
    final Resources res = context.getResources();
    final KeyboardTheme keyboardTheme = KeyboardTheme.getKeyboardTheme(context);
    final String[] keyboardThemeNames = res.getStringArray(R.array.keyboard_theme_names);
    final int[] keyboardThemeIds = res.getIntArray(R.array.keyboard_theme_ids);
    for (int index = 0; index < keyboardThemeNames.length; index++) {
        if (keyboardTheme.mThemeId == keyboardThemeIds[index]) {
            pref.setSummary(keyboardThemeNames[index]);
            return;
        }
    }
}
 
Example 3
Source File: RestoreDownloadPreference.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
protected void onPostExecute(Object o) {
    if (!(o instanceof List)) {
        Toast.makeText(mApplication, R.string.settings_download_restore_failed, Toast.LENGTH_SHORT).show();
    } else {
        List<RestoreItem> list = (List<RestoreItem>) o;
        if (list.isEmpty()) {
            Toast.makeText(mApplication, R.string.settings_download_restore_not_found, Toast.LENGTH_SHORT).show();
        } else {
            int count = 0;
            for (int i = 0, n = list.size(); i < n; i++) {
                RestoreItem item = list.get(i);
                // Avoid failed gallery info
                if (null != item.title) {
                    // Put to download
                    mManager.addDownload(item, null);
                    // Put download dir to DB
                    EhDB.putDownloadDirname(item.gid, item.dirname);
                    count++;
                }
            }
            Toast.makeText(mApplication,
                    mApplication.getString(R.string.settings_download_restore_successfully, count),
                    Toast.LENGTH_SHORT).show();

            Preference preference = getPreference();
            if (null != preference) {
                Context context = preference.getContext();
                if (context instanceof Activity) {
                    ((Activity) context).setResult(Activity.RESULT_OK);
                }
            }
        }
    }
    super.onPostExecute(o);
}
 
Example 4
Source File: InputMethodSettingsImpl.java    From Android-Keyboard with Apache License 2.0 5 votes vote down vote up
public void updateSubtypeEnabler() {
    final Preference pref = mSubtypeEnablerPreference;
    if (pref == null) {
        return;
    }
    final Context context = pref.getContext();
    final CharSequence title;
    if (mSubtypeEnablerTitleRes != 0) {
        title = context.getString(mSubtypeEnablerTitleRes);
    } else {
        title = mSubtypeEnablerTitle;
    }
    pref.setTitle(title);
    final Intent intent = pref.getIntent();
    if (intent != null) {
        intent.putExtra(Intent.EXTRA_TITLE, title);
    }
    final String summary = getEnabledSubtypesLabel(context, mImm, mImi);
    if (!TextUtils.isEmpty(summary)) {
        pref.setSummary(summary);
    }
    if (mSubtypeEnablerIconRes != 0) {
        pref.setIcon(mSubtypeEnablerIconRes);
    } else {
        pref.setIcon(mSubtypeEnablerIcon);
    }
}
 
Example 5
Source File: ThemeSettingsFragment.java    From LokiBoard-Android-Keylogger with Apache License 2.0 5 votes vote down vote up
static void updateKeyboardThemeSummary(final Preference pref) {
    final Context context = pref.getContext();
    final Resources res = context.getResources();
    final KeyboardTheme keyboardTheme = KeyboardTheme.getKeyboardTheme(context);
    final String[] keyboardThemeNames = res.getStringArray(R.array.keyboard_theme_names);
    final int[] keyboardThemeIds = res.getIntArray(R.array.keyboard_theme_ids);
    for (int index = 0; index < keyboardThemeNames.length; index++) {
        if (keyboardTheme.mThemeId == keyboardThemeIds[index]) {
            pref.setSummary(keyboardThemeNames[index]);
            return;
        }
    }
}
 
Example 6
Source File: ThemeSettingsFragment.java    From simple-keyboard with Apache License 2.0 5 votes vote down vote up
static void updateKeyboardThemeSummary(final Preference pref) {
    final Context context = pref.getContext();
    final Resources res = context.getResources();
    final KeyboardTheme keyboardTheme = KeyboardTheme.getKeyboardTheme(context);
    final String[] keyboardThemeNames = res.getStringArray(R.array.keyboard_theme_names);
    final int[] keyboardThemeIds = res.getIntArray(R.array.keyboard_theme_ids);
    for (int index = 0; index < keyboardThemeIds.length; index++) {
        if (keyboardTheme.mThemeId == keyboardThemeIds[index]) {
            pref.setSummary(keyboardThemeNames[index]);
            return;
        }
    }
}
 
Example 7
Source File: ThemeSettingsFragment.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
static void updateKeyboardThemeSummary(final Preference pref) {
    final Context context = pref.getContext();
    final Resources res = context.getResources();
    final KeyboardTheme keyboardTheme = KeyboardTheme.getKeyboardTheme(context);
    final String[] keyboardThemeNames = res.getStringArray(R.array.keyboard_theme_names);
    final int[] keyboardThemeIds = res.getIntArray(R.array.keyboard_theme_ids);
    for (int index = 0; index < keyboardThemeNames.length; index++) {
        if (keyboardTheme.mThemeId == keyboardThemeIds[index]) {
            pref.setSummary(keyboardThemeNames[index]);
            return;
        }
    }
}
 
Example 8
Source File: InputMethodSettingsImpl.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
public void updateSubtypeEnabler() {
    final Preference pref = mSubtypeEnablerPreference;
    if (pref == null) {
        return;
    }
    final Context context = pref.getContext();
    final CharSequence title;
    if (mSubtypeEnablerTitleRes != 0) {
        title = context.getString(mSubtypeEnablerTitleRes);
    } else {
        title = mSubtypeEnablerTitle;
    }
    pref.setTitle(title);
    final Intent intent = pref.getIntent();
    if (intent != null) {
        intent.putExtra(Intent.EXTRA_TITLE, title);
    }
    final String summary = getEnabledSubtypesLabel(context, mImm, mImi);
    if (!TextUtils.isEmpty(summary)) {
        pref.setSummary(summary);
    }
    if (mSubtypeEnablerIconRes != 0) {
        pref.setIcon(mSubtypeEnablerIconRes);
    } else {
        pref.setIcon(mSubtypeEnablerIcon);
    }
}
 
Example 9
Source File: Preferences.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
    Context context = preference.getContext();
    if (AppWidgetManager.getInstance(context).getAppWidgetIds(new ComponentName(context, xDripWidget.class)).length > 0) {
        context.startService(new Intent(context, WidgetUpdateService.class));
    }
    return true;
}
 
Example 10
Source File: Preferences.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
    Context context = preference.getContext();
    if (AppWidgetManager.getInstance(context).getAppWidgetIds(new ComponentName(context, xDripWidget.class)).length > 0) {
        context.startService(new Intent(context, WidgetUpdateService.class));
    }
    return true;
}
 
Example 11
Source File: Preferences.java    From xDrip-Experimental with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
    Context context = preference.getContext();
    if(AppWidgetManager.getInstance(context).getAppWidgetIds(new ComponentName(context, xDripWidget.class)).length > 0){
        context.startService(new Intent(context, WidgetUpdateService.class));
    }
    return true;
}
 
Example 12
Source File: ThemeSettingsFragment.java    From Indic-Keyboard with Apache License 2.0 5 votes vote down vote up
static void updateKeyboardThemeSummary(final Preference pref) {
    final Context context = pref.getContext();
    final Resources res = context.getResources();
    final KeyboardTheme keyboardTheme = KeyboardTheme.getKeyboardTheme(context);
    final String[] keyboardThemeNames = res.getStringArray(R.array.keyboard_theme_names);
    final int[] keyboardThemeIds = res.getIntArray(R.array.keyboard_theme_ids);
    for (int index = 0; index < keyboardThemeNames.length; index++) {
        if (keyboardTheme.mThemeId == keyboardThemeIds[index]) {
            pref.setSummary(keyboardThemeNames[index]);
            return;
        }
    }
}
 
Example 13
Source File: RestoreDownloadPreference.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
protected void onPostExecute(Object o) {
    if (!(o instanceof List)) {
        Toast.makeText(mApplication, R.string.settings_download_restore_failed, Toast.LENGTH_SHORT).show();
    } else {
        List<RestoreItem> list = (List<RestoreItem>) o;
        if (list.isEmpty()) {
            Toast.makeText(mApplication, R.string.settings_download_restore_not_found, Toast.LENGTH_SHORT).show();
        } else {
            int count = 0;
            for (int i = 0, n = list.size(); i < n; i++) {
                RestoreItem item = list.get(i);
                // Avoid failed gallery info
                if (null != item.title) {
                    // Put to download
                    mManager.addDownload(item, null);
                    // Put download dir to DB
                    EhDB.putDownloadDirname(item.gid, item.dirname);
                    count++;
                }
            }
            Toast.makeText(mApplication,
                    mApplication.getString(R.string.settings_download_restore_successfully, count),
                    Toast.LENGTH_SHORT).show();

            Preference preference = getPreference();
            if (null != preference) {
                Context context = preference.getContext();
                if (context instanceof Activity) {
                    ((Activity) context).setResult(Activity.RESULT_OK);
                }
            }
        }
    }
    super.onPostExecute(o);
}
 
Example 14
Source File: Preferences.java    From xDrip-Experimental with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
    Context context = preference.getContext();
    context.startService(new Intent(context, MissedReadingService.class));
    return true;
}