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.mci.firstidol.view.ActionSheet.java

private Attributes readAttribute() {
    Attributes attrs = new Attributes(getActivity());
    TypedArray a = getActivity().getTheme().obtainStyledAttributes(null, R.styleable.ActionSheet,
            R.attr.actionSheetStyle, 0);
    Drawable background = a.getDrawable(R.styleable.ActionSheet_actionSheetBackground);
    if (background != null) {
        attrs.background = background;/*from  w w w .j a  v a2s.  c  o m*/
    }
    Drawable cancelButtonBackground = a.getDrawable(R.styleable.ActionSheet_cancelButtonBackground);
    if (cancelButtonBackground != null) {
        attrs.cancelButtonBackground = cancelButtonBackground;
    }
    Drawable otherButtonTopBackground = a.getDrawable(R.styleable.ActionSheet_otherButtonTopBackground);
    if (otherButtonTopBackground != null) {
        attrs.otherButtonTopBackground = otherButtonTopBackground;
    }
    Drawable otherButtonMiddleBackground = a.getDrawable(R.styleable.ActionSheet_otherButtonMiddleBackground);
    if (otherButtonMiddleBackground != null) {
        attrs.otherButtonMiddleBackground = otherButtonMiddleBackground;
    }
    Drawable otherButtonBottomBackground = a.getDrawable(R.styleable.ActionSheet_otherButtonBottomBackground);
    if (otherButtonBottomBackground != null) {
        attrs.otherButtonBottomBackground = otherButtonBottomBackground;
    }
    Drawable otherButtonSingleBackground = a.getDrawable(R.styleable.ActionSheet_otherButtonSingleBackground);
    if (otherButtonSingleBackground != null) {
        attrs.otherButtonSingleBackground = otherButtonSingleBackground;
    }

    Drawable actionSheetTitleBackground = a.getDrawable(R.styleable.ActionSheet_titleTXTBackground);
    if (actionSheetTitleBackground != null) {
        attrs.actionSheetTitleBackground = actionSheetTitleBackground;
    }

    attrs.cancelButtonTextColor = a.getColor(R.styleable.ActionSheet_cancelButtonTextColor,
            attrs.cancelButtonTextColor);
    attrs.otherButtonTextColor = a.getColor(R.styleable.ActionSheet_otherButtonTextColor,
            attrs.otherButtonTextColor);
    attrs.padding = (int) a.getDimension(R.styleable.ActionSheet_actionSheetPadding, attrs.padding);
    attrs.otherButtonSpacing = (int) a.getDimension(R.styleable.ActionSheet_otherButtonSpacing,
            attrs.otherButtonSpacing);
    attrs.cancelButtonMarginTop = (int) a.getDimension(R.styleable.ActionSheet_cancelButtonMarginTop,
            attrs.cancelButtonMarginTop);
    attrs.actionSheetTextSize = a.getDimensionPixelSize(R.styleable.ActionSheet_actionSheetTextSize,
            (int) attrs.actionSheetTextSize);

    a.recycle();
    return attrs;
}

From source file:android.support.v7.app.MediaRouteButton.java

public MediaRouteButton(Context context, AttributeSet attrs, int defStyleAttr) {
    super(MediaRouterThemeHelper.createThemedContext(context, defStyleAttr), attrs, defStyleAttr);
    context = getContext();/*ww  w . j  av a2 s.  c o m*/

    mRouter = MediaRouter.getInstance(context);
    mCallback = new MediaRouterCallback();

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MediaRouteButton, defStyleAttr, 0);
    setRemoteIndicatorDrawable(a.getDrawable(R.styleable.MediaRouteButton_externalRouteEnabledDrawable));
    mMinWidth = a.getDimensionPixelSize(R.styleable.MediaRouteButton_android_minWidth, 0);
    mMinHeight = a.getDimensionPixelSize(R.styleable.MediaRouteButton_android_minHeight, 0);
    a.recycle();

    setClickable(true);
    setLongClickable(true);
}

From source file:com.android.inputmethod.latin.suggestions.SuggestionStripView.java

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

    final LayoutInflater inflater = LayoutInflater.from(context);
    inflater.inflate(R.layout.suggestions_strip, this);

    mSuggestionsStrip = (ViewGroup) findViewById(R.id.suggestions_strip);
    mVoiceKey = (ImageButton) findViewById(R.id.suggestions_strip_voice_key);
    mImportantNoticeStrip = findViewById(R.id.important_notice_strip);
    mStripVisibilityGroup = new StripVisibilityGroup(this, mSuggestionsStrip, mImportantNoticeStrip);

    for (int pos = 0; pos < SuggestedWords.MAX_SUGGESTIONS; pos++) {
        final TextView word = new TextView(context, null, R.attr.suggestionWordStyle);
        word.setContentDescription(getResources().getString(R.string.spoken_empty_suggestion));
        word.setOnClickListener(this);
        word.setOnLongClickListener(this);
        mWordViews.add(word);/*  w ww.j a  v a2 s.c o m*/
        final View divider = inflater.inflate(R.layout.suggestion_divider, null);
        mDividerViews.add(divider);
        final TextView info = new TextView(context, null, R.attr.suggestionWordStyle);
        info.setTextColor(Color.WHITE);
        info.setTextSize(TypedValue.COMPLEX_UNIT_DIP, DEBUG_INFO_TEXT_SIZE_IN_DIP);
        mDebugInfoViews.add(info);
    }

    mLayoutHelper = new SuggestionStripLayoutHelper(context, attrs, defStyle, mWordViews, mDividerViews,
            mDebugInfoViews);

    mMoreSuggestionsContainer = inflater.inflate(R.layout.more_suggestions, null);
    mMoreSuggestionsView = (MoreSuggestionsView) mMoreSuggestionsContainer
            .findViewById(R.id.more_suggestions_view);
    mMoreSuggestionsBuilder = new MoreSuggestions.Builder(context, mMoreSuggestionsView);

    final Resources res = context.getResources();
    mMoreSuggestionsModalTolerance = res
            .getDimensionPixelOffset(R.dimen.config_more_suggestions_modal_tolerance);
    mMoreSuggestionsSlidingDetector = new GestureDetector(context, mMoreSuggestionsSlidingListener);

    final TypedArray keyboardAttr = context.obtainStyledAttributes(attrs, R.styleable.Keyboard, defStyle,
            R.style.SuggestionStripView);
    final Drawable iconVoice = keyboardAttr.getDrawable(R.styleable.Keyboard_iconShortcutKey);
    keyboardAttr.recycle();
    mVoiceKey.setImageDrawable(iconVoice);
    mVoiceKey.setOnClickListener(this);
}

From source file:com.github.jorgecastilloprz.FABProgressCircle.java

private void setupInitialAttributes(AttributeSet attrs) {
    if (attrs != null) {
        TypedArray attrArray = getAttributes(attrs);
        try {//from   www .ja va 2 s  .  c o m
            arcColor = attrArray.getColor(R.styleable.FABProgressCircle_arcColor,
                    getResources().getColor(R.color.fab_orange_dark));
            arcWidth = attrArray.getDimensionPixelSize(R.styleable.FABProgressCircle_arcWidth,
                    getResources().getDimensionPixelSize(R.dimen.progress_arc_stroke_width));
            completeIconDrawable = attrArray.getDrawable(R.styleable.FABProgressCircle_finalIcon);
            circleSize = attrArray.getInt(R.styleable.FABProgressCircle_circleSize, 1);
            roundedStroke = attrArray.getBoolean(R.styleable.FABProgressCircle_roundedStroke, false);
            reusable = attrArray.getBoolean(R.styleable.FABProgressCircle_reusable, false);
        } finally {
            attrArray.recycle();
        }
    }
}

From source file:com.rashwan.reactive_popular_movies.common.utilities.ExpandableTextView.java

private void init(AttributeSet attrs) {
    TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.ExpandableTextView);
    mMaxCollapsedLines = typedArray.getInt(R.styleable.ExpandableTextView_maxCollapsedLines,
            MAX_COLLAPSED_LINES);//from   www. j av a  2s  .c o  m
    mAnimationDuration = typedArray.getInt(R.styleable.ExpandableTextView_animDuration, DEFAULT_ANIM_DURATION);
    mExpandDrawable = typedArray.getDrawable(R.styleable.ExpandableTextView_expandDrawable);
    mCollapseDrawable = typedArray.getDrawable(R.styleable.ExpandableTextView_collapseDrawable);

    if (mExpandDrawable == null) {
        mExpandDrawable = getDrawable(getContext(), R.drawable.ic_expand_more_white_12dp);
    }
    if (mCollapseDrawable == null) {
        mCollapseDrawable = getDrawable(getContext(), R.drawable.ic_expand_less_white_12dp);
    }

    typedArray.recycle();

    // enforces vertical orientation
    setOrientation(LinearLayout.VERTICAL);

    // default visibility is gone
    setVisibility(GONE);
}

From source file:com.nextgis.maplibui.fragment.LayersListAdapter.java

private View getStandardLayerView(final ILayer layer, View view) {
    LayoutInflater inflater = LayoutInflater.from(mContext);
    View v = view;//from w  w  w .  j av a 2 s . c o m
    if (v == null || v.getId() == R.id.empty_row)
        v = inflater.inflate(R.layout.row_layer, null);

    if (layer instanceof NGWLookupTable || layer instanceof NGWTrackLayer)
        return inflater.inflate(R.layout.row_empty, null);

    final ILayerUI layerui;
    if (layer == null) {
        return v;
    } else if (layer instanceof ILayerUI) {
        layerui = (ILayerUI) layer;
    } else {
        layerui = null;
    }

    ImageView ivIcon = (ImageView) v.findViewById(R.id.ivIcon);
    ivIcon.setImageDrawable(layerui != null ? layerui.getIcon(mContext) : null);

    TextView tvPaneName = (TextView) v.findViewById(R.id.tvLayerName);
    tvPaneName.setText(layer.getName());
    //final int id = layer.getId();

    final ImageButton btMore = (ImageButton) v.findViewById(R.id.btMore);
    ImageButton btShow = (ImageButton) v.findViewById(R.id.btShow);
    ImageView ivEdited = (ImageView) v.findViewById(R.id.ivEdited);

    boolean hide = layerui instanceof VectorLayer && ((VectorLayer) layerui).isLocked();
    btMore.setVisibility(hide ? View.GONE : View.VISIBLE);
    btShow.setVisibility(hide ? View.GONE : View.VISIBLE);
    ivEdited.setVisibility(hide ? View.VISIBLE : View.GONE);
    if (mOnPencilClickListener != null)
        ivEdited.setOnClickListener(mOnPencilClickListener);

    int[] attrs = new int[] { R.attr.ic_action_visibility_on, R.attr.ic_action_visibility_off };
    TypedArray ta = mContext.obtainStyledAttributes(attrs);
    Drawable visibilityOn = ta.getDrawable(0);
    Drawable visibilityOff = ta.getDrawable(1);

    if (layer instanceof Layer) {
        btShow.setImageDrawable(//setImageResource(
                ((Layer) layer).isVisible() ? visibilityOn : visibilityOff);
        //btShow.refreshDrawableState();
        btShow.setOnClickListener(new View.OnClickListener() {
            public void onClick(View arg0) {
                //Layer layer = mMap.getLayerById(id);
                ((Layer) layer).setVisible(!((Layer) layer).isVisible());
                layer.save();
            }
        });
    }
    ta.recycle();

    btMore.setOnClickListener(new View.OnClickListener() {
        public void onClick(View arg0) {
            PopupMenu popup = new PopupMenu(mContext, btMore);
            popup.getMenuInflater().inflate(R.menu.layer_popup, popup.getMenu());

            if (layerui == null) {
                popup.getMenu().findItem(R.id.menu_settings).setEnabled(false);
                popup.getMenu().findItem(R.id.menu_share).setEnabled(false);
            }

            if (layer instanceof VectorLayerUI)
                popup.getMenu().findItem(R.id.menu_send_to_ngw).setVisible(true);

            if (layerui instanceof TrackLayer) {
                popup.getMenu().findItem(R.id.menu_delete).setVisible(false);
                popup.getMenu().findItem(R.id.menu_settings).setTitle(R.string.track_list);

                List<ILayer> tracks = new ArrayList<>();
                LayerGroup.getLayersByType(mMap, LAYERTYPE_NGW_TRACKS, tracks);
                popup.getMenu().findItem(R.id.menu_share).setVisible(true);
                mTracksSyncEnabled = tracks.size() > 0;
                int title = mTracksSyncEnabled ? R.string.sync_disable : R.string.sync;
                popup.getMenu().findItem(R.id.menu_share).setTitle(title);
            } else if (layerui instanceof VectorLayer) {
                popup.getMenu().findItem(R.id.menu_edit).setVisible(true);
                popup.getMenu().findItem(R.id.menu_share).setVisible(true);
                popup.getMenu().findItem(R.id.menu_zoom_extent).setVisible(true);
                popup.getMenu().findItem(R.id.menu_download_tiles).setVisible(true);
                popup.getMenu().findItem(R.id.menu_download_tiles).setTitle(R.string.attributes);
            } else if (layerui instanceof LocalTMSLayer) {
                popup.getMenu().findItem(R.id.menu_zoom_extent).setVisible(true);
            } else if (layerui instanceof NGWRasterLayer) {
                popup.getMenu().findItem(R.id.menu_zoom_extent).setVisible(true);
                popup.getMenu().findItem(R.id.menu_download_tiles).setVisible(true);
            } else if (layerui instanceof RemoteTMSLayer) {
                popup.getMenu().findItem(R.id.menu_download_tiles).setVisible(true);
            }

            if (layerui instanceof NGWWebMapLayerUI) {
                popup.getMenu().findItem(R.id.menu_zoom_extent).setVisible(false);
                popup.getMenu().findItem(R.id.menu_edit).setVisible(true);
                popup.getMenu().findItem(R.id.menu_edit).setTitle(R.string.sync_layers);
            }

            popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                public boolean onMenuItemClick(MenuItem item) {
                    int i = item.getItemId();
                    if (i == R.id.menu_settings) {
                        assert layerui != null;
                        layerui.changeProperties(mContext);
                    } else if (i == R.id.menu_share) {
                        assert layerui != null;

                        if (layerui instanceof TrackLayerUI) {
                            //                                                handleTrackSync();
                            Toast.makeText(mContext, R.string.commercial, Toast.LENGTH_SHORT).show();
                            return true;
                        } else if (layerui instanceof VectorLayer) {
                            VectorLayer vectorLayer = (VectorLayer) layerui;
                            LayerUtil.shareLayerAsGeoJSON(mActivity, vectorLayer);
                        }
                    } else if (i == R.id.menu_edit) {
                        if (layerui instanceof NGWWebMapLayerUI)
                            ((NGWWebMapLayerUI) layerui).showLayersDialog(mMapView, mActivity);
                        else if (mEditListener != null)
                            mEditListener.onLayerEdit(layer);
                    } else if (i == R.id.menu_delete) {
                        return deleteLayer(layer);
                    } else if (i == R.id.menu_zoom_extent) {
                        mMap.zoomToExtent(layer.getExtents());
                    } else if (i == R.id.menu_download_tiles) {
                        GeoEnvelope env = mMap.getCurrentBounds();

                        if (layer instanceof RemoteTMSLayerUI) {
                            RemoteTMSLayerUI remoteTMSLayer = (RemoteTMSLayerUI) layer;
                            remoteTMSLayer.downloadTiles(mContext, env);
                        } else if (layer instanceof NGWRasterLayerUI) {
                            NGWRasterLayerUI remoteTMSLayer = (NGWRasterLayerUI) layer;
                            remoteTMSLayer.downloadTiles(mContext, env);
                        } else if (layer instanceof NGWWebMapLayerUI) {
                            NGWWebMapLayerUI remoteTMSLayer = (NGWWebMapLayerUI) layer;
                            remoteTMSLayer.downloadTiles(mContext, env);
                        } else if (layer instanceof IVectorLayerUI) {
                            IVectorLayerUI vectorLayerUI = (IVectorLayerUI) layer;
                            vectorLayerUI.showAttributes();
                        }
                    } else if (i == R.id.menu_send_to_ngw) {
                        if (layer instanceof VectorLayerUI)
                            ((VectorLayerUI) layer).sendToNGW(mActivity);
                    }

                    if (mDrawer != null)
                        mDrawer.closeDrawers();

                    return true;
                }
            });

            popup.show();
        }
    });

    return v;
}

From source file:com.espiandev.redux.cast.mediarouterplus.MediaRouteButtonPlus.java

public MediaRouteButtonPlus(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    mCallback = new MediaRouterCallback();

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MediaRouteButtonPlus, defStyleAttr, 0);
    setRemoteIndicatorDrawable(//from www  .  j  a va  2  s  .com
            a.getDrawable(R.styleable.MediaRouteButtonPlus_mrp_externalRouteEnabledDrawable));
    mMinWidth = a.getDimensionPixelSize(R.styleable.MediaRouteButtonPlus_android_minWidth, 0);
    mMinHeight = a.getDimensionPixelSize(R.styleable.MediaRouteButtonPlus_android_minHeight, 0);
    a.recycle();

    setClickable(true);
    setLongClickable(true);
}

From source file:com.astuetz.viewpager.extensions.FixedTabsView.java

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

    this.mContext = context;

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

    mDividerColor = a.getColor(R.styleable.ViewPagerExtensions_dividerColor, mDividerColor);

    mDividerMarginTop = a.getDimensionPixelSize(R.styleable.ViewPagerExtensions_dividerMarginTop,
            mDividerMarginTop);//from ww w  .j  av a2  s  . com
    mDividerMarginBottom = a.getDimensionPixelSize(R.styleable.ViewPagerExtensions_dividerMarginBottom,
            mDividerMarginBottom);

    mDividerDrawable = a.getDrawable(R.styleable.ViewPagerExtensions_dividerDrawable);

    a.recycle();

    this.setOrientation(LinearLayout.HORIZONTAL);
}

From source file:com.shenzhen.elson.selectordialoglib.SelectorDialog.java

private Attributes readAttribute() {
    Attributes attrs = new Attributes(getActivity());
    TypedArray a = getActivity().getTheme().obtainStyledAttributes(null, R.styleable.SelectorDialog,
            R.attr.selectorDialogStyle, 0);
    Drawable background = a.getDrawable(R.styleable.SelectorDialog_selectorDialogBackground);
    if (background != null) {
        attrs.background = background;//from  w  w w. jav a  2  s  .c  om
    }
    Drawable cancelButtonBackground = a.getDrawable(R.styleable.SelectorDialog_cancelButtonBackground);
    if (cancelButtonBackground != null) {
        attrs.cancelButtonBackground = cancelButtonBackground;
    }
    Drawable otherButtonTopBackground = a.getDrawable(R.styleable.SelectorDialog_otherButtonTopBackground);
    if (otherButtonTopBackground != null) {
        attrs.otherButtonTopBackground = otherButtonTopBackground;
    }
    Drawable otherButtonMiddleBackground = a
            .getDrawable(R.styleable.SelectorDialog_otherButtonMiddleBackground);
    if (otherButtonMiddleBackground != null) {
        attrs.otherButtonMiddleBackground = otherButtonMiddleBackground;
    }
    Drawable otherButtonBottomBackground = a
            .getDrawable(R.styleable.SelectorDialog_otherButtonBottomBackground);
    if (otherButtonBottomBackground != null) {
        attrs.otherButtonBottomBackground = otherButtonBottomBackground;
    }
    Drawable otherButtonSingleBackground = a
            .getDrawable(R.styleable.SelectorDialog_otherButtonSingleBackground);
    if (otherButtonSingleBackground != null) {
        attrs.otherButtonSingleBackground = otherButtonSingleBackground;
    }
    attrs.cancelButtonTextColor = a.getColor(R.styleable.SelectorDialog_cancelButtonTextColor,
            attrs.cancelButtonTextColor);
    attrs.otherButtonTextColor = a.getColor(R.styleable.SelectorDialog_otherButtonTextColor,
            attrs.otherButtonTextColor);
    attrs.padding = (int) a.getDimension(R.styleable.SelectorDialog_selectorDialogPadding, attrs.padding);
    attrs.otherButtonSpacing = (int) a.getDimension(R.styleable.SelectorDialog_otherButtonSpacing,
            attrs.otherButtonSpacing);
    attrs.cancelButtonMarginTop = (int) a.getDimension(R.styleable.SelectorDialog_cancelButtonMarginTop,
            attrs.cancelButtonMarginTop);
    attrs.SelectorDialogTextSize = a.getDimensionPixelSize(R.styleable.SelectorDialog_selectorDialogTextSize,
            (int) attrs.SelectorDialogTextSize);

    a.recycle();
    return attrs;
}

From source file:com.heinrichreimersoftware.singleinputform.SingleInputFormActivity.java

private void loadTheme() {
    /* Default values */
    mButtonNextIcon = getResources().getDrawable(R.drawable.ic_action_next_item);
    mButtonFinishIcon = getResources().getDrawable(R.drawable.ic_action_accept);

    /* Custom values */
    int[] attrs = { R.attr.colorPrimary, R.attr.colorPrimaryDark, android.R.attr.textColorPrimary,
            android.R.attr.textColorSecondary, R.attr.sifNextIcon, R.attr.sifFinishIcon };
    TypedArray array = obtainStyledAttributes(attrs);

    mTextFieldBackgroundColor = array.getColor(0, 0);
    mProgressBackgroundColor = array.getColor(1, 0);
    mTitleTextColor = mErrorTextColor = array.getColor(2, 0);
    mDetailsTextColor = array.getColor(3, 0);

    Drawable buttonNextIcon = array.getDrawable(4);
    if (buttonNextIcon != null) {
        mButtonNextIcon = buttonNextIcon;
    }/*from   w  ww .j  av  a  2 s . c  o  m*/

    Drawable buttonFinishIcon = array.getDrawable(5);
    if (buttonFinishIcon != null) {
        mButtonFinishIcon = buttonFinishIcon;
    }

    array.recycle();
}