Example usage for android.content.res TypedArray getDrawable

List of usage examples for android.content.res TypedArray getDrawable

Introduction

In this page you can find the example usage for android.content.res TypedArray getDrawable.

Prototype

@Nullable
public Drawable getDrawable(@StyleableRes int index) 

Source Link

Document

Retrieve the Drawable for the attribute at index.

Usage

From source file:com.actionbarsherlock.internal.widget.IcsSpinner.java

/**
 * Construct a new spinner with the given context's theme, the supplied attribute set,
 * and default style.//from   www  .j  a  v a2s.  c  o m
 *
 * @param context The Context the view is running in, through which it can
 *        access the current theme, resources, etc.
 * @param attrs The attributes of the XML tag that is inflating the view.
 * @param defStyle The default style to apply to this view. If 0, no style
 *        will be applied (beyond what is included in the theme). This may
 *        either be an attribute resource, whose value will be retrieved
 *        from the current theme, or an explicit style resource.
 */
public IcsSpinner(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SherlockSpinner, defStyle, 0);

    DropdownPopup popup = new DropdownPopup(context, attrs, defStyle);

    mDropDownWidth = a.getLayoutDimension(R.styleable.SherlockSpinner_android_dropDownWidth,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    popup.setBackgroundDrawable(a.getDrawable(R.styleable.SherlockSpinner_android_popupBackground));
    final int verticalOffset = a
            .getDimensionPixelOffset(R.styleable.SherlockSpinner_android_dropDownVerticalOffset, 0);
    if (verticalOffset != 0) {
        popup.setVerticalOffset(verticalOffset);
    }

    final int horizontalOffset = a
            .getDimensionPixelOffset(R.styleable.SherlockSpinner_android_dropDownHorizontalOffset, 0);
    if (horizontalOffset != 0) {
        popup.setHorizontalOffset(horizontalOffset);
    }

    mPopup = popup;

    mGravity = a.getInt(R.styleable.SherlockSpinner_android_gravity, Gravity.CENTER);

    mPopup.setPromptText(a.getString(R.styleable.SherlockSpinner_android_prompt));

    mDisableChildrenWhenDisabled = true;

    a.recycle();

    // Base constructor can call setAdapter before we initialize mPopup.
    // Finish setting things up if this happened.
    if (mTempAdapter != null) {
        mPopup.setAdapter(mTempAdapter);
        mTempAdapter = null;
    }
}

From source file:com.baiiu.autoloopviewpager.indicator.LinePageIndicator.java

private void init(Context context, AttributeSet attrs) {

    if (isInEditMode())
        return;// w ww.  j a  va 2  s. c o m

    final Resources res = getResources();

    //Load defaults from resources
    final int defaultSelectedColor = Color.parseColor("#FF33B5E5");
    final int defaultUnselectedColor = Color.parseColor("#FFBBBBBB");
    final float defaultLineWidth = 36;
    final float defaultGapWidth = 12;
    final float defaultStrokeWidth = 3;
    final boolean defaultCentered = true;

    //Retrieve styles attributes
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LinePageIndicator);

    mCentered = a.getBoolean(R.styleable.LinePageIndicator_centered, defaultCentered);
    mLineWidth = a.getDimension(R.styleable.LinePageIndicator_lineWidth, defaultLineWidth);
    mGapWidth = a.getDimension(R.styleable.LinePageIndicator_gapWidth, defaultGapWidth);
    setStrokeWidth(a.getDimension(R.styleable.LinePageIndicator_strokeWidth, defaultStrokeWidth));
    mPaintUnselected
            .setColor(a.getColor(R.styleable.LinePageIndicator_unselectedColor, defaultUnselectedColor));
    mPaintSelected.setColor(a.getColor(R.styleable.LinePageIndicator_selectedColor, defaultSelectedColor));

    Drawable background = a.getDrawable(R.styleable.LinePageIndicator_android_background);
    if (background != null) {
        setBackgroundDrawable(background);
    }

    a.recycle();
}

From source file:android.support.v7.preference.PreferenceFragmentCompat.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    TypedArray a = mStyledContext.obtainStyledAttributes(null, R.styleable.PreferenceFragmentCompat,
            R.attr.preferenceFragmentCompatStyle, 0);

    mLayoutResId = a.getResourceId(R.styleable.PreferenceFragmentCompat_android_layout, mLayoutResId);

    final Drawable divider = a.getDrawable(R.styleable.PreferenceFragmentCompat_android_divider);
    final int dividerHeight = a
            .getDimensionPixelSize(R.styleable.PreferenceFragmentCompat_android_dividerHeight, -1);

    a.recycle();/* w ww .  java  2  s  . co m*/

    // Need to theme the inflater to pick up the preferenceFragmentListStyle
    final TypedValue tv = new TypedValue();
    getActivity().getTheme().resolveAttribute(R.attr.preferenceTheme, tv, true);
    final int theme = tv.resourceId;

    final Context themedContext = new ContextThemeWrapper(inflater.getContext(), theme);
    final LayoutInflater themedInflater = inflater.cloneInContext(themedContext);

    final View view = themedInflater.inflate(mLayoutResId, container, false);

    final View rawListContainer = view.findViewById(AndroidResources.ANDROID_R_LIST_CONTAINER);
    if (!(rawListContainer instanceof ViewGroup)) {
        throw new RuntimeException("Content has view with id attribute "
                + "'android.R.id.list_container' that is not a ViewGroup class");
    }

    final ViewGroup listContainer = (ViewGroup) rawListContainer;

    final RecyclerView listView = onCreateRecyclerView(themedInflater, listContainer, savedInstanceState);
    if (listView == null) {
        throw new RuntimeException("Could not create RecyclerView");
    }

    mList = listView;

    listView.addItemDecoration(mDividerDecoration);
    setDivider(divider);
    if (dividerHeight != -1) {
        setDividerHeight(dividerHeight);
    }

    listContainer.addView(mList);
    mHandler.post(mRequestFocus);

    return view;
}

From source file:com.saulcintero.moveon.fragments.Summary1.java

@SuppressLint("Recycle")
@Override/*  www  .j a  va 2 s  .c o m*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    LinearLayout fragmentView = (LinearLayout) inflater.inflate(R.layout.summary1, container, false);
    layout1 = (LinearLayout) fragmentView.findViewById(R.id.linearLayout1);

    act = getActivity();
    mContext = act.getApplicationContext();
    res = getResources();

    prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
    editor = prefs.edit();

    id = prefs.getInt("selected_practice", 0);

    isMetric = FunctionUtils.checkIfUnitsAreMetric(mContext);

    check1 = (CheckBox) fragmentView.findViewById(R.id.checkBox1);
    check2 = (CheckBox) fragmentView.findViewById(R.id.checkBox2);
    check3 = (CheckBox) fragmentView.findViewById(R.id.checkBox3);
    full_mapview = (ImageButton) fragmentView.findViewById(R.id.summary_mapview_fullscreen);
    label1 = (TextView) fragmentView.findViewById(R.id.summary_label_one);
    label2 = (TextView) fragmentView.findViewById(R.id.summary_label_two);
    label3 = (TextView) fragmentView.findViewById(R.id.summary_label_three);
    label4 = (TextView) fragmentView.findViewById(R.id.summary_label_four);
    label5 = (TextView) fragmentView.findViewById(R.id.summary_label_five);
    label6 = (TextView) fragmentView.findViewById(R.id.summary_label_six);
    label7 = (TextView) fragmentView.findViewById(R.id.summary_label_seven);
    label8 = (TextView) fragmentView.findViewById(R.id.summary_label_eight);
    label9 = (TextView) fragmentView.findViewById(R.id.summary_label_nine);
    label10 = (TextView) fragmentView.findViewById(R.id.summary_label_ten);
    label11 = (TextView) fragmentView.findViewById(R.id.summary_label_eleven);
    label12 = (TextView) fragmentView.findViewById(R.id.summary_label_twelve);
    label13 = (TextView) fragmentView.findViewById(R.id.summary_label_thirteen);
    label14 = (TextView) fragmentView.findViewById(R.id.summary_label_fourteen);
    label15 = (TextView) fragmentView.findViewById(R.id.summary_label_fifteen);
    label16 = (TextView) fragmentView.findViewById(R.id.summary_label_sixteen);
    label17 = (TextView) fragmentView.findViewById(R.id.summary_label_seventeen);
    text1 = (TextView) fragmentView.findViewById(R.id.summary_date);
    text2 = (TextView) fragmentView.findViewById(R.id.summary_text_one);
    text3 = (TextView) fragmentView.findViewById(R.id.summary_text_two);
    text4 = (TextView) fragmentView.findViewById(R.id.summary_text_three);
    text5 = (TextView) fragmentView.findViewById(R.id.summary_text_four);
    text6 = (TextView) fragmentView.findViewById(R.id.summary_text_five);
    text7 = (TextView) fragmentView.findViewById(R.id.summary_text_six);
    text8 = (TextView) fragmentView.findViewById(R.id.summary_text_seven);
    text9 = (TextView) fragmentView.findViewById(R.id.summary_text_eight);
    text10 = (TextView) fragmentView.findViewById(R.id.summary_text_nine);
    text11 = (TextView) fragmentView.findViewById(R.id.summary_text_ten);
    text12 = (TextView) fragmentView.findViewById(R.id.summary_text_eleven);
    text13 = (TextView) fragmentView.findViewById(R.id.summary_text_twelve);
    text14 = (TextView) fragmentView.findViewById(R.id.summary_text_thirteen);
    text15 = (TextView) fragmentView.findViewById(R.id.summary_text_fourteen);
    text16 = (TextView) fragmentView.findViewById(R.id.summary_text_fifteen);
    text17 = (TextView) fragmentView.findViewById(R.id.summary_text_sixteen);
    text18 = (TextView) fragmentView.findViewById(R.id.summary_text_seventeen);

    activity_image = (ImageView) fragmentView.findViewById(R.id.summary_activity);

    mGallery = (Gallery) fragmentView.findViewById(R.id.gallery);

    // set gallery to left side
    DisplayMetrics metrics = new DisplayMetrics();
    act.getWindowManager().getDefaultDisplay().getMetrics(metrics);
    MarginLayoutParams mlp = (MarginLayoutParams) mGallery.getLayoutParams();
    mlp.setMargins(-(metrics.widthPixels / 2 + 75), mlp.topMargin, mlp.rightMargin, mlp.bottomMargin);

    String[] data = DataFunctionUtils.getRouteData(mContext, id, isMetric);

    label1.setText(getString(R.string.time_label).toUpperCase(Locale.getDefault()));
    label2.setText(getString(R.string.distance_label).toUpperCase(Locale.getDefault()));
    label3.setText(getString(R.string.avg_label).toUpperCase(Locale.getDefault()));
    label4.setText(getString(R.string.ritm_label).toUpperCase(Locale.getDefault()));
    label5.setText(getString(R.string.max_speed_label).toUpperCase(Locale.getDefault()));
    label6.setText(getString(R.string.max_altitude_label).toUpperCase(Locale.getDefault()));
    label7.setText(getString(R.string.min_altitude_label).toUpperCase(Locale.getDefault()));
    label8.setText(getString(R.string.calories_label).toUpperCase(Locale.getDefault()));
    label9.setText(getString(R.string.steps_label).toUpperCase(Locale.getDefault()));
    label10.setText(getString(R.string.beats_avg_label).toUpperCase(Locale.getDefault()));
    label11.setText(getString(R.string.max_beats_label).toUpperCase(Locale.getDefault()));
    label12.setText(getString(R.string.shoe).toUpperCase(Locale.getDefault()));
    label13.setText(getString(R.string.comments).toUpperCase(Locale.getDefault()));
    label14.setText(getString(R.string.accum_ascent).toUpperCase(Locale.getDefault()));
    label15.setText(getString(R.string.accum_descent).toUpperCase(Locale.getDefault()));
    label16.setText(getString(R.string.avg_cadence).toUpperCase(Locale.getDefault()));
    label17.setText(getString(R.string.max_cadence).toUpperCase(Locale.getDefault()));

    TypedArray activities_icons = res.obtainTypedArray(R.array.activities_icons);
    activity_image.setImageDrawable(activities_icons.getDrawable(Integer.valueOf(data[0]) - 1));

    metric_text1 = (isMetric ? getString(R.string.long_unit1_detail_1)
            : getString(R.string.long_unit2_detail_1));
    metric_text2 = (isMetric ? getString(R.string.long_unit1_detail_2)
            : getString(R.string.long_unit2_detail_2));
    metric_text3 = (isMetric ? getString(R.string.long_unit1_detail_3)
            : getString(R.string.long_unit2_detail_3));
    metric_text4 = (isMetric ? getString(R.string.long_unit1_detail_4)
            : getString(R.string.long_unit2_detail_4));

    text1.setText(data[1]);
    text2.setText(data[2]);
    text3.setText(FunctionUtils.customizedRound(Float.valueOf(data[3]), 2) + " " + metric_text1);
    text4.setText(FunctionUtils.customizedRound(Float.valueOf(data[4]), 2) + " " + metric_text2);
    text5.setText(data[5] + " " + metric_text3);
    text6.setText(data[6] + " " + metric_text2);
    text7.setText(data[7] + " " + metric_text4);
    text8.setText(data[8] + " " + metric_text4);
    text9.setText(data[9] + " " + getString(R.string.tell_calories_setting_details));
    text10.setText(data[10]);
    text11.setText(data[13] + " " + getString(R.string.beats_per_minute));
    text12.setText(data[14] + " " + getString(R.string.beats_per_minute));
    text13.setText(data[12]);
    text14.setText(data[11]);
    text15.setText(data[20] + " " + metric_text4);
    text16.setText(data[21] + " " + metric_text4);
    text17.setText(data[23] + " " + getString(R.string.revolutions_per_minute));
    text18.setText(data[24] + " " + getString(R.string.revolutions_per_minute));

    check1.setOnClickListener(this);
    check2.setOnClickListener(this);
    check3.setOnClickListener(this);

    checkboxStatus();

    populatesMap(fragmentView);

    intentFilter = new IntentFilter("android.intent.action.EXPAND_OR_RESTART_SUMMARY_MAPVIEW");
    intentFilter2 = new IntentFilter("android.intent.action.SUMMARY_GALLERY_SELECTED_IMAGE");
    act.registerReceiver(mReceiverExpandRestartMapview, intentFilter);
    act.registerReceiver(mReceiverSelectedPicture, intentFilter2);

    readImages();
    changeLayout1Margins();

    mGallery.setAdapter(new ImageAdapter(mContext));

    mGallery.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            position = arg2;

            if (folder.isDirectory()) {
                launchPhoto();
            } else {
                UIFunctionUtils.showMessage(mContext, true,
                        mContext.getString(R.string.image_resource_missing));
            }
        }
    });

    mGallery.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapter, View view, int position, long id) {
            markChosenPicturePosition = position;
            markChosenPicture(position);
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapter) {
        }
    });

    return fragmentView;
}

From source file:com.mikecorrigan.trainscorekeeper.Players.java

@SuppressLint("NewApi")
public Players(final Activity context, ViewGroup viewGroup, final JSONArray jsonPlayers) {
    Log.vc(VERBOSE, TAG,/*  w w  w  .  jav  a2 s .  c  o m*/
            "ctor: context=" + context + ", viewGroup=" + viewGroup + ", jsonPlayers=" + jsonPlayers);

    viewGroup.removeAllViews();

    Resources resources = context.getResources();

    String[] playerNames = resources.getStringArray(R.array.playerNames);

    TypedArray drawablesArray = resources.obtainTypedArray(R.array.playerDrawables);

    TypedArray colorIdsArray = resources.obtainTypedArray(R.array.playerTextColors);
    int[] colorIds = new int[colorIdsArray.length()];
    for (int i = 0; i < colorIdsArray.length(); i++) {
        colorIds[i] = colorIdsArray.getResourceId(i, -1);
    }

    listeners = new HashSet<Listener>();
    players = new SparseArray<Player>();

    for (int i = 0; i < playerNames.length; i++) {
        PlayerButton toggleButton = new PlayerButton(context);
        toggleButton.setPlayerId(i);
        LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT, 1f);
        toggleButton.setLayoutParams(layoutParams);
        Drawable drawable = drawablesArray.getDrawable(i);
        int sdk = android.os.Build.VERSION.SDK_INT;
        if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
            toggleButton.setBackgroundDrawable(drawable);
        } else {
            toggleButton.setBackground(drawable);
        }
        toggleButton.setPadding(10, 10, 10, 10);
        toggleButton.setTextColor(resources.getColor(colorIds[i]));
        toggleButton.setOnClickListener(onSelect);

        viewGroup.addView(toggleButton);

        final String name = playerNames[i];

        boolean enabled = true;

        // If the players configuration is available, determine which players are enabled.
        if (jsonPlayers != null) {
            enabled = false;
            for (int j = 0; j < jsonPlayers.length(); j++) {
                String jsonName = jsonPlayers.optString(j, "");
                if (jsonName.equalsIgnoreCase(name)) {
                    enabled = true;
                    break;
                }
            }
        }

        Player player = new Player(toggleButton, i, name, enabled);
        players.put(i, player);
    }

    setSelection(-1);

    drawablesArray.recycle();
    colorIdsArray.recycle();
}

From source file:com.example.anumbrella.viewpager.UnderlinePagerIndicator.java

public UnderlinePagerIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    ////w w w .ja  v a2  s  . c om
    if (isInEditMode()) {
        return;
    }

    //??
    final Resources res = getResources();

    //
    //?
    final boolean defaultFades = res.getBoolean(R.bool.default_underline_indicator_fades);
    //
    final int defaultFadeDelay = res.getInteger(R.integer.default_underline_indicator_fade_delay);
    //
    final int defaultFadeLength = res.getInteger(R.integer.default_underline_indicator_fade_length);
    //??
    final int defaultSelectedColor = res.getColor(R.color.default_underline_indicator_selected_color);

    //?xml
    TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.UnderlinePagerIndicator, defStyle, 0);

    setFades(array.getBoolean(R.styleable.UnderlinePagerIndicator_fades, defaultFades));
    setSelectedColor(array.getColor(R.styleable.UnderlinePagerIndicator_selectedColor, defaultSelectedColor));
    setFadeDelay(array.getInteger(R.styleable.UnderlinePagerIndicator_fadeDelay, defaultFadeDelay));
    setFadeLength(array.getInteger(R.styleable.UnderlinePagerIndicator_fadeLength, defaultFadeLength));

    Drawable background = array.getDrawable(R.styleable.UnderlinePagerIndicator_android_background);
    if (background != null) {
        setBackgroundDrawable(background);
    }
    array.recycle();

    final ViewConfiguration configuration = ViewConfiguration.get(context);
    //????(?????)
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
}

From source file:android.support.v7.preference.PreferenceController.java

@Override
@NonNull//w  ww . j ava 2s .  co m
public View onCreateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    mInitDone = false;
    mHavePrefs = false;

    final TypedValue tv = new TypedValue();
    getActivity().getTheme().resolveAttribute(R.attr.preferenceTheme, tv, true);
    final int theme = tv.resourceId;
    if (theme == 0) {
        throw new IllegalStateException("Must specify preferenceTheme in theme");
    }
    mStyledContext = new ContextThemeWrapper(getActivity(), theme);

    mPreferenceManager = new PreferenceManager(mStyledContext);
    final String rootKey = getArgs().getString(ARG_PREFERENCE_ROOT);
    onCreatePreferences(savedInstanceState, rootKey);

    TypedArray a = mStyledContext.obtainStyledAttributes(null, R.styleable.PreferenceFragmentCompat,
            R.attr.preferenceFragmentCompatStyle, 0);

    mLayoutResId = a.getResourceId(R.styleable.PreferenceFragmentCompat_android_layout, mLayoutResId);

    mDividerDecoration = new DividerDecoration();
    final Drawable divider = a.getDrawable(R.styleable.PreferenceFragmentCompat_android_divider);
    final int dividerHeight = a
            .getDimensionPixelSize(R.styleable.PreferenceFragmentCompat_android_dividerHeight, -1);
    final boolean allowDividerAfterLastItem = a
            .getBoolean(R.styleable.PreferenceFragmentCompat_allowDividerAfterLastItem, true);

    a.recycle();

    final Context themedContext = new ContextThemeWrapper(inflater.getContext(), theme);
    final LayoutInflater themedInflater = inflater.cloneInContext(themedContext);

    final View view = themedInflater.inflate(mLayoutResId, container, false);

    final View rawListContainer = view.findViewById(AndroidResources.ANDROID_R_LIST_CONTAINER);
    if (!(rawListContainer instanceof ViewGroup)) {
        throw new RuntimeException("Content has view with id attribute "
                + "'android.R.id.list_container' that is not a ViewGroup class");
    }

    final ViewGroup listContainer = (ViewGroup) rawListContainer;

    final RecyclerView listView = onCreateRecyclerView(themedInflater, listContainer, savedInstanceState);
    if (listView == null) {
        throw new RuntimeException("Could not create RecyclerView");
    }

    mList = listView;

    listView.addItemDecoration(mDividerDecoration);
    setDivider(divider);
    if (dividerHeight != -1) {
        setDividerHeight(dividerHeight);
    }
    mDividerDecoration.setAllowDividerAfterLastItem(allowDividerAfterLastItem);

    listContainer.addView(mList);
    mHandler.post(mRequestFocus);

    onViewCreated(view, savedInstanceState);

    return view;
}

From source file:com.maedi.user.godok.v1.viewpagerindicator.UnderlinePageIndicator.java

@SuppressWarnings("deprecation")
public UnderlinePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;/*from   w ww  .jav a2s . c  o  m*/

    final Resources res = getResources();

    //Load defaults from resources
    final boolean defaultFades = res
            .getBoolean(com.viewpagerindicator.R.bool.default_underline_indicator_fades);
    final int defaultFadeDelay = res
            .getInteger(com.viewpagerindicator.R.integer.default_underline_indicator_fade_delay);
    final int defaultFadeLength = res
            .getInteger(com.viewpagerindicator.R.integer.default_underline_indicator_fade_length);
    final int defaultSelectedColor = res
            .getColor(com.viewpagerindicator.R.color.default_underline_indicator_selected_color);

    //Retrieve styles attributes
    TypedArray a = context.obtainStyledAttributes(attrs,
            com.viewpagerindicator.R.styleable.UnderlinePageIndicator, defStyle, 0);

    setFades(a.getBoolean(com.viewpagerindicator.R.styleable.UnderlinePageIndicator_fades, defaultFades));
    setSelectedColor(a.getColor(com.viewpagerindicator.R.styleable.UnderlinePageIndicator_selectedColor,
            defaultSelectedColor));
    setFadeDelay(a.getInteger(com.viewpagerindicator.R.styleable.UnderlinePageIndicator_fadeDelay,
            defaultFadeDelay));
    setFadeLength(a.getInteger(com.viewpagerindicator.R.styleable.UnderlinePageIndicator_fadeLength,
            defaultFadeLength));

    Drawable background = a
            .getDrawable(com.viewpagerindicator.R.styleable.UnderlinePageIndicator_android_background);
    if (background != null) {
        setBackgroundDrawable(background);
    }

    a.recycle();

    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
}

From source file:com.lovebridge.library.view.viewpagerindicator.LinePageIndicator.java

public LinePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;//from ww w  .  j  a  va 2  s  .  com
    final Resources res = getResources();
    // Load defaults from resources
    final int defaultSelectedColor = res.getColor(R.color.default_line_indicator_selected_color);
    final int defaultUnselectedColor = res.getColor(R.color.default_line_indicator_unselected_color);
    final float defaultLineWidth = res.getDimension(R.dimen.default_line_indicator_line_width);
    final float defaultGapWidth = res.getDimension(R.dimen.default_line_indicator_gap_width);
    final float defaultStrokeWidth = res.getDimension(R.dimen.default_line_indicator_stroke_width);
    final boolean defaultCentered = res.getBoolean(R.bool.default_line_indicator_centered);
    // Retrieve styles attributes
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LinePageIndicator, defStyle, 0);
    mCentered = a.getBoolean(R.styleable.LinePageIndicator_centered, defaultCentered);
    mLineWidth = a.getDimension(R.styleable.LinePageIndicator_lineWidth, defaultLineWidth);
    mGapWidth = a.getDimension(R.styleable.LinePageIndicator_gapWidth, defaultGapWidth);
    setStrokeWidth(a.getDimension(R.styleable.LinePageIndicator_strokeWidth, defaultStrokeWidth));
    mPaintUnselected
            .setColor(a.getColor(R.styleable.LinePageIndicator_unselectedColor, defaultUnselectedColor));
    mPaintSelected.setColor(a.getColor(R.styleable.LinePageIndicator_selectedColor, defaultSelectedColor));
    Drawable background = a.getDrawable(R.styleable.LinePageIndicator_android_background);
    if (background != null) {
        setBackgroundDrawable(background);
    }
    a.recycle();
    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
}

From source file:com.example.FilteredActivityChooserView.java

/**
 * Create a new instance.//from ww  w .  ja va2 s  . co  m
 *
 * @param context The application environment.
 * @param attrs A collection of attributes.
 * @param defStyle The default style to apply to this view.
 */
public FilteredActivityChooserView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    TypedArray attributesArray = context.obtainStyledAttributes(attrs, R.styleable.ActivityChooserView,
            defStyle, 0);

    mInitialActivityCount = attributesArray.getInt(R.styleable.ActivityChooserView_initialActivityCount,
            ActivityChooserViewAdapter.MAX_ACTIVITY_COUNT_DEFAULT);

    Drawable expandActivityOverflowButtonDrawable = attributesArray
            .getDrawable(R.styleable.ActivityChooserView_expandActivityOverflowButtonDrawable);

    attributesArray.recycle();

    LayoutInflater inflater = LayoutInflater.from(getContext());
    inflater.inflate(R.layout.abc_activity_chooser_view, this, true);

    mCallbacks = new Callbacks();

    mActivityChooserContent = (LinearLayout) findViewById(R.id.activity_chooser_view_content);
    mActivityChooserContentBackground = mActivityChooserContent.getBackground();

    mDefaultActivityButton = (FrameLayout) findViewById(R.id.default_activity_button);
    mDefaultActivityButton.setOnClickListener(mCallbacks);
    mDefaultActivityButton.setOnLongClickListener(mCallbacks);
    mDefaultActivityButtonImage = (ImageView) mDefaultActivityButton.findViewById(R.id.image);

    mExpandActivityOverflowButton = (FrameLayout) findViewById(R.id.expand_activities_button);
    mExpandActivityOverflowButton.setOnClickListener(mCallbacks);
    mExpandActivityOverflowButtonImage = (ImageView) mExpandActivityOverflowButton.findViewById(R.id.image);
    mExpandActivityOverflowButtonImage.setImageDrawable(expandActivityOverflowButtonDrawable);

    mAdapter = new ActivityChooserViewAdapter();
    mAdapter.registerDataSetObserver(new DataSetObserver() {
        @Override
        public void onChanged() {
            super.onChanged();
            updateAppearance();
        }
    });

    Resources resources = context.getResources();
    mListPopupMaxWidth = Math.max(resources.getDisplayMetrics().widthPixels / 2,
            resources.getDimensionPixelSize(R.dimen.abc_config_prefDialogWidth));
}