public static void createCircularPreferenceBitmap(Boolean isImage, Preference preference, ImageView imageView, Context context, int color) { Bitmap.Config conf = Bitmap.Config.ARGB_8888; int dimen = (int) context.getResources().getDimension(android.R.dimen.app_icon_size); Bitmap bmp = Bitmap.createBitmap(dimen, dimen, conf); if (isImage) { imageView.setBackground(createRoundedBitmapDrawable(bmp, color, context.getResources())); } else { preference.setIcon(createRoundedBitmapDrawable(bmp, color, context.getResources())); } }
private void setColorIcon(Preference colorPref, String hexColor) { int c = Color.parseColor(hexColor); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { Drawable d1 = getResources().getDrawable(R.drawable.ic_square); d1.mutate().setColorFilter(c, PorterDuff.Mode.MULTIPLY); colorPref.setIcon(d1); } else { Spannable summary = new SpannableString(hexColor); summary.setSpan(new ForegroundColorSpan(c), 0, summary.length(), 0); colorPref.setSummary(summary); } }
public void updateSubtypeEnabler() { if (mSubtypeEnablerPreference != null) { if (mSubtypeEnablerTitleRes != 0) { mSubtypeEnablerPreference.setTitle(mSubtypeEnablerTitleRes); } else if (!TextUtils.isEmpty(mSubtypeEnablerTitle)) { mSubtypeEnablerPreference.setTitle(mSubtypeEnablerTitle); } final String summary = getEnabledSubtypesLabel(mContext, mImm, mImi); if (!TextUtils.isEmpty(summary)) { mSubtypeEnablerPreference.setSummary(summary); } if (mSubtypeEnablerIconRes != 0) { mSubtypeEnablerPreference.setIcon(mSubtypeEnablerIconRes); } else if (mSubtypeEnablerIcon != null) { mSubtypeEnablerPreference.setIcon(mSubtypeEnablerIcon); } } } }
@Override public boolean onPreferenceChange(Preference preference, Object newValue) { String set = (String) newValue; try { int c = Color.parseColor(set); preference.setSummary(set); Drawable d = getResources().getDrawable(R.drawable.ic_square); d.mutate().setColorFilter(c, PorterDuff.Mode.MULTIPLY); preference.setIcon(d); return true; } catch (Exception ex) { Toast.makeText(getApplicationContext(), getString(R.string.error_invalid_color, set), Toast.LENGTH_SHORT).show(); return false; } } };
public void updateSubtypeEnabler() { if (mSubtypeEnablerPreference != null) { if (mSubtypeEnablerTitleRes != 0) { mSubtypeEnablerPreference.setTitle(mSubtypeEnablerTitleRes); } else if (!TextUtils.isEmpty(mSubtypeEnablerTitle)) { mSubtypeEnablerPreference.setTitle(mSubtypeEnablerTitle); } final String summary = getEnabledSubtypesLabel(mContext, mImm, mImi); if (!TextUtils.isEmpty(summary)) { mSubtypeEnablerPreference.setSummary(summary); } if (mSubtypeEnablerIconRes != 0) { mSubtypeEnablerPreference.setIcon(mSubtypeEnablerIconRes); } else if (mSubtypeEnablerIcon != null) { mSubtypeEnablerPreference.setIcon(mSubtypeEnablerIcon); } } } }
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); } } }
static void updateIconPackIcon(Context context) { String iconPackPackage = prefs.prefsGet().getString(ICON_PACK_PREFERENCE, null); Drawable icon; icon = context.getResources().getDrawable(R.drawable.ic_launcher); try { Tools.HangarLog("iconPackPackage: " + iconPackPackage); icon = new BitmapDrawable(context.getResources(), new IconHelper(mContext).cachedResourceIconHelper(iconPackPackage)); } catch (Exception e) { } PrefsFragment mGeneralSettings = (PrefsFragment) mGetFragments.getFragmentByPosition(GENERAL_TAB); mGeneralSettings.icon_pack_preference.setIcon(icon); }
static void updateMoreAppsIcon(Context context) { try { Drawable d = new BitmapDrawable(context.getResources(), new IconHelper(mContext).cachedResourceIconHelper(MORE_APPS_PACKAGE)); PrefsFragment mGeneralSettings = (PrefsFragment) mGetFragments.getFragmentByPosition(GENERAL_TAB); mGeneralSettings.more_apps_icon_preference.setIcon(d); } catch (Exception e) { } }
private void setPreferenceCategoryIcons() { Drawable plusIcon = ApiCompatibilityUtils.getDrawable(getResources(), R.drawable.plus); plusIcon.mutate(); plusIcon.setColorFilter( ApiCompatibilityUtils.getColor(getResources(), R.color.pref_accent_color), PorterDuff.Mode.SRC_IN); findPreference(PREF_AUTOFILL_PROFILES).setIcon(plusIcon); plusIcon = ApiCompatibilityUtils.getDrawable(getResources(), R.drawable.plus); plusIcon.mutate(); plusIcon.setColorFilter( ApiCompatibilityUtils.getColor(getResources(), R.color.pref_accent_color), PorterDuff.Mode.SRC_IN); findPreference(PREF_AUTOFILL_CREDIT_CARDS).setIcon(plusIcon); }
public Preference createAppPreference(final String packageName, final String appName) { Preference app = new Preference(getActivity()); app.setTitle(appName); app.setKey(packageName); app.setIcon(appManager.loadIcon(packageName)); return app; }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mContext = getActivity(); // Themes are 'pre-compiled' in themes-list: get all values // and append them to our newly created PreferenceScreen PreferenceScreen screen = getPreferenceManager().createPreferenceScreen(mContext); final String[] entries = getResources().getStringArray(R.array.theme_entries); final String[] values = getResources().getStringArray(R.array.theme_values); final String[] ids = getResources().getStringArray(R.array.theme_ids); for (int i = 0; i < entries.length; i++) { int[] attrs = decodeValue(values[i]); final Preference pref = new Preference(mContext); pref.setPersistent(false); pref.setOnPreferenceClickListener(this); pref.setTitle(entries[i]); pref.setKey(ids[i]); // preference value of this theme pref.setIcon(generateThemePreview(attrs)); screen.addPreference(pref); } setPreferenceScreen(screen); }
p.setIcon(ContentSettingsResources.getIcon(contentType)); p.setOnPreferenceClickListener(this);
/** * Initializes the Preference based on the state of any policies that may affect it, * e.g. by showing a managed icon or disabling clicks on the preference. * * This should be called once, before the preference is displayed. */ public void initPreference(Preference preference) { if (isPreferenceControlledByPolicy(preference)) { preference.setIcon(ManagedPreferencesUtils.getManagedByEnterpriseIconId()); if (isPreferenceClickDisabledByPolicy(preference)) { // Disable the views and prevent the Preference from mucking with the enabled state. preference.setShouldDisableView(false); // Prevent default click behavior. preference.setFragment(null); preference.setIntent(null); preference.setOnPreferenceClickListener(null); } } }
prefBtDevice.setOnPreferenceClickListener(new onClickListenerDeviceSelect()); prefBtDevice.setKey(device.getMacAddress()); prefBtDevice.setIcon(R.drawable.ic_bluetooth_device_supported); prefBtDevice.setSummary(btDevice.driverName()); Timber.d("Found unsupported device %s", formatDeviceName(device)); prefBtDevice.setIcon(R.drawable.ic_bluetooth_device_not_supported); prefBtDevice.setSummary(R.string.label_bt_device_no_support); prefBtDevice.setEnabled(false);
private void updateMeasurementPreferences() { measurementCategory.removeAll(); List<MeasurementView> measurementViews = MeasurementView.getMeasurementList( getActivity(), MeasurementView.DateTimeOrder.NONE); for (MeasurementView measurement : measurementViews) { Preference preference = new MeasurementOrderPreference( getActivity(), measurementCategory, measurement); preference.setKey(measurement.getSettings().getEnabledKey()); preference.setDefaultValue(measurement.getSettings().isEnabledIgnoringDependencies()); preference.setPersistent(true); preference.setEnabled(measurement.getSettings().areDependenciesEnabled()); Drawable icon = measurement.getIcon(); icon.setColorFilter(measurement.getForegroundColor(), PorterDuff.Mode.SRC_IN); preference.setIcon(icon); preference.setTitle(measurement.getName()); preference.setSummary(measurement.getPreferenceSummary()); measurementCategory.addPreference(preference); } }