Android Open Source - cosmic_hub Icon Preference Screen

From Project

Back to project page cosmic_hub.


The source code is released under:

GNU General Public License

If you think the Android project cosmic_hub listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.cosmic.mods;
/*from w w  w  . j a  v a  2  s .  c o  m*/
import com.cosmic.mods.R;

import android.content.Context;
import android.content.res.TypedArray;
import android.preference.Preference;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;

public class IconPreferenceScreen extends Preference {

    private Drawable mIcon;

    public IconPreferenceScreen(Context context, AttributeSet attrs) {
        this(context, attrs, 0);

    public IconPreferenceScreen(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        TypedArray a = context.obtainStyledAttributes(attrs,
                R.styleable.IconPreferenceScreen, defStyle, 0);
        mIcon = a.getDrawable(R.styleable.IconPreferenceScreen_icon1);

    public void onBindView(View view) {
        ImageView imageView = (ImageView) view.findViewById(;
        if (imageView != null && mIcon != null) {

    public void setIcon(Drawable icon) {
        if ((icon == null && mIcon != null) || (icon != null && !icon.equals(mIcon))) {
            mIcon = icon;

    public Drawable getIcon() {
        return mIcon;

Java Source Code List