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

The following examples show how to use android.preference.Preference#setIcon() . 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: ManagedPreferenceDelegate.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
        }
    }
}
 
Example 2
Source File: ManagedPreferenceDelegate.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
        }
    }
}
 
Example 3
Source File: UsbChooserPreferences.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private void resetList() {
    getPreferenceScreen().removeAll();
    addPreferencesFromResource(R.xml.usb_chooser_preferences);

    if (mPermissionsByObject.isEmpty() && mSearch.isEmpty() && mEmptyView != null) {
        mEmptyView.setText(R.string.website_settings_usb_no_devices);
    }

    for (Pair<ArrayList<UsbInfo>, ArrayList<Website>> entry : mPermissionsByObject.values()) {
        Preference preference = new Preference(getActivity());
        Bundle extras = preference.getExtras();
        extras.putInt(UsbDevicePreferences.EXTRA_CATEGORY, mCategory.toContentSettingsType());
        extras.putString(
                SingleCategoryPreferences.EXTRA_TITLE, getActivity().getTitle().toString());
        extras.putSerializable(UsbDevicePreferences.EXTRA_USB_INFOS, entry.first);
        extras.putSerializable(UsbDevicePreferences.EXTRA_SITES, entry.second);
        preference.setIcon(R.drawable.settings_usb);
        preference.setTitle(entry.first.get(0).getName());
        preference.setFragment(UsbDevicePreferences.class.getCanonicalName());
        getPreferenceScreen().addPreference(preference);
    }
}
 
Example 4
Source File: ChansFragment.java    From Dashchan with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);

	ChanManager manager = ChanManager.getInstance();
	int color = ResourceUtils.getColor(getActivity(), R.attr.drawerIconColor);
	for (String chanName : manager.getAvailableChanNames()) {
		Preference preference = makeButton(null, ChanConfiguration.get(chanName).getTitle(), null, false);
		Drawable drawable = manager.getIcon(chanName, color);
		if (drawable != null) {
			preference.setIcon(drawable);
		}
		Intent intent = new Intent(getActivity(), PreferencesActivity.class);
		intent.putExtra(PreferencesActivity.EXTRA_SHOW_FRAGMENT, ChanFragment.class.getName());
		intent.putExtra(PreferencesActivity.EXTRA_NO_HEADERS, true);
		intent.putExtra(C.EXTRA_CHAN_NAME, chanName);
		preference.setIntent(intent);
	}
}
 
Example 5
Source File: ManagedPreferenceDelegate.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * 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());
    } else if (isPreferenceControlledByCustodian(preference)) {
        preference.setIcon(R.drawable.ic_account_child_grey600_36dp);
    }

    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);
    }
}
 
Example 6
Source File: UsbChooserPreferences.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private void resetList() {
    getPreferenceScreen().removeAll();
    addPreferencesFromResource(R.xml.usb_chooser_preferences);

    if (mPermissionsByObject.isEmpty() && mSearch.isEmpty() && mEmptyView != null) {
        mEmptyView.setText(R.string.website_settings_usb_no_devices);
    }

    for (Pair<ArrayList<UsbInfo>, ArrayList<Website>> entry : mPermissionsByObject.values()) {
        Preference preference = new Preference(getActivity());
        Bundle extras = preference.getExtras();
        extras.putInt(UsbDevicePreferences.EXTRA_CATEGORY, mCategory.toContentSettingsType());
        extras.putString(
                SingleCategoryPreferences.EXTRA_TITLE, getActivity().getTitle().toString());
        extras.putSerializable(UsbDevicePreferences.EXTRA_USB_INFOS, entry.first);
        extras.putSerializable(UsbDevicePreferences.EXTRA_SITES, entry.second);
        preference.setIcon(R.drawable.settings_usb);
        preference.setTitle(entry.first.get(0).getName());
        preference.setFragment(UsbDevicePreferences.class.getCanonicalName());
        getPreferenceScreen().addPreference(preference);
    }
}
 
Example 7
Source File: ThemePreference.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
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()));

        }
    }
 
Example 8
Source File: PickServerFragment.java    From android-vlc-remote with GNU General Public License v3.0 5 votes vote down vote up
private Preference createServerPreference(Server server) {
    Preference preference = new Preference(getActivity());
    preference.setKey(server.toKey());
    preference.setTitle(server.getNickname().isEmpty() ? server.getHostAndPort() : server.getNickname());
    preference.setPersistent(false);
    String authority = server.getUri().getAuthority();
    if(mRemembered.containsKey(authority) && authority.equals(Preferences.get(getActivity()).getAuthority())) {
        preference.setWidgetLayoutResource(R.layout.tick_image);
    }
    switch (server.getResponseCode()) {
        case HttpURLConnection.HTTP_UNAUTHORIZED:
            preference.setSummary(R.string.summary_unauthorized);
            preference.setIcon(R.drawable.ic_vlc_server_auth);
            break;
        case HttpURLConnection.HTTP_FORBIDDEN:
            preference.setSummary(R.string.summary_forbidden);
            preference.setIcon(R.drawable.ic_vlc_server_forbidden);
            break;
        default:
            if(server.hasUserInfo()) {
                preference.setIcon(R.drawable.ic_vlc_server_auth);
            } else {
                preference.setIcon(R.drawable.ic_vlc_server);
            }
    }
    return preference;
}
 
Example 9
Source File: OptionsActivity.java    From trackworktime with GNU General Public License v3.0 5 votes vote down vote up
private void showTimestampPrefIcon(final Preference timestampPref, final String dateLocalStr, final String dateBackupStr) {
	if (dateLocalStr.equals(dateBackupStr)) {
		timestampPref.setIcon(R.drawable.backup_ok);
	} else {
		timestampPref.setIcon(R.drawable.backup_not_ok);
	}
}
 
Example 10
Source File: OpenFitActivity.java    From OpenFit with MIT License 5 votes vote down vote up
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;
}
 
Example 11
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 12
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 13
Source File: CompatibilityImpl.java    From Overchan-Android with GNU General Public License v3.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static void setIcon(Preference preference, int iconResId) {
    preference.setIcon(iconResId);
}
 
Example 14
Source File: CompatibilityImpl.java    From Overchan-Android with GNU General Public License v3.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static void setIcon(Preference preference, Drawable icon) {
    preference.setIcon(icon);
}
 
Example 15
Source File: AccountManagementFragment.java    From 365browser with Apache License 2.0 4 votes vote down vote up
private void configureChildAccountPreferences() {
    Preference parentAccounts = findPreference(PREF_PARENT_ACCOUNTS);
    Preference childContent = findPreference(PREF_CHILD_CONTENT);
    if (mProfile.isChild()) {
        Resources res = getActivity().getResources();
        PrefServiceBridge prefService = PrefServiceBridge.getInstance();

        String firstParent = prefService.getSupervisedUserCustodianEmail();
        String secondParent = prefService.getSupervisedUserSecondCustodianEmail();
        String parentText;

        if (!secondParent.isEmpty()) {
            parentText = res.getString(R.string.account_management_two_parent_names,
                    firstParent, secondParent);
        } else if (!firstParent.isEmpty()) {
            parentText = res.getString(R.string.account_management_one_parent_name,
                    firstParent);
        } else {
            parentText = res.getString(R.string.account_management_no_parental_data);
        }
        parentAccounts.setSummary(parentText);
        parentAccounts.setSelectable(false);
        ((ChromeBasePreference) parentAccounts).setUseReducedPadding(true);

        final int childContentSummary;
        int defaultBehavior = prefService.getDefaultSupervisedUserFilteringBehavior();
        if (defaultBehavior == PrefServiceBridge.SUPERVISED_USER_FILTERING_BLOCK) {
            childContentSummary = R.string.account_management_child_content_approved;
        } else if (prefService.isSupervisedUserSafeSitesEnabled()) {
            childContentSummary = R.string.account_management_child_content_filter_mature;
        } else {
            childContentSummary = R.string.account_management_child_content_all;
        }
        childContent.setSummary(childContentSummary);
        // TODO(dgn): made selectable to show the dividers. Find a way to avoid this. A side
        // effect is that it shows a tap ripple on an item that is not interactive.
        // childContent.setSelectable(false);

        Drawable newIcon = ApiCompatibilityUtils.getDrawable(
                getResources(), R.drawable.ic_drive_site_white_24dp);
        newIcon.mutate().setColorFilter(
                ApiCompatibilityUtils.getColor(getResources(), R.color.google_grey_600),
                PorterDuff.Mode.SRC_IN);
        childContent.setIcon(newIcon);
    } else {
        PreferenceScreen prefScreen = getPreferenceScreen();
        prefScreen.removePreference(findPreference(PREF_PARENTAL_SETTINGS));
        prefScreen.removePreference(parentAccounts);
        prefScreen.removePreference(childContent);
    }
}
 
Example 16
Source File: infos.java    From android-kernel-tweaker with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	addPreferencesFromResource(R.xml.infos);

	mDsht = (Preference) findPreference(KEY_DSHT);
	mCesco = (Preference) findPreference(KEY_CESCO);
	mSollyx = (Preference) findPreference(KEY_SOLLYX);
	mAokp = (Preference) findPreference(KEY_AOKP);
	mOmni = (Preference) findPreference(KEY_OMNI);
	mDu = (Preference) findPreference(KEY_DU);
	mSlidingMenu = (Preference) findPreference(KEY_SLIDINGMENU);

	PackageInfo pInfo = null;
	try {
		pInfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0);
	} catch (NameNotFoundException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	String version = pInfo.versionName;

	mDsht.setTitle(R.string.app_name);
	mDsht.setIcon(R.drawable.ic_launcher);
	mDsht.setSummary("Version: "+version);

	mCesco.setIcon(R.drawable.cesco);
	mSollyx.setIcon(R.drawable.sollyx_google);

	/*	
    mAokp.setIcon(R.drawable.aokp);
	mOmni.setIcon(R.drawable.omni);
	mDu.setIcon(R.drawable.du); 
	*/

	mSlidingMenu.setIcon(R.drawable.github);

	mDsht.setOnPreferenceClickListener(this);
	mCesco.setOnPreferenceClickListener(this);
	mSollyx.setOnPreferenceClickListener(this);
	//mAokp.setOnPreferenceClickListener(this);
	//mOmni.setOnPreferenceClickListener(this);
	//mDu.setOnPreferenceClickListener(this);
	mSlidingMenu.setOnPreferenceClickListener(this);

	if(MainActivity.menu.isMenuShowing()) {
		MainActivity.menu.toggle(true);
	}
}
 
Example 17
Source File: PickServerFragment.java    From android-vlc-remote with GNU General Public License v3.0 4 votes vote down vote up
private void setButtonIcon(Preference preference, String button) {
    preference.setIcon(Buttons.getButton(preference.getKey(), button).getIconId());
}
 
Example 18
Source File: paletteUtils.java    From Color-picker-library with GNU General Public License v3.0 3 votes vote down vote up
static void createCircularPreferenceBitmap(Preference preference, Activity activity, Resources resources, int color, int viewColor) {

        Bitmap.Config conf = Bitmap.Config.ARGB_8888;
        Bitmap bmp = Bitmap.createBitmap(SpToPixels(activity, 50), SpToPixels(activity, 50), conf);

        preference.setIcon(createRoundedBitmapDrawableWithBorder(activity, bmp, color, viewColor, resources));

    }