Example usage for android.util TypedValue TypedValue

List of usage examples for android.util TypedValue TypedValue

Introduction

In this page you can find the example usage for android.util TypedValue TypedValue.

Prototype

TypedValue

Source Link

Usage

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

private boolean initializePanelMenu(final PanelFeatureState st) {
    Context context = mContext;// ww w.j a v a  2  s  .  co m

    // If we have an action bar, initialize the menu with the right theme.
    if ((st.featureId == FEATURE_OPTIONS_PANEL || st.featureId == FEATURE_ACTION_BAR)
            && mDecorContentParent != null) {
        final TypedValue outValue = new TypedValue();
        final Resources.Theme baseTheme = context.getTheme();
        baseTheme.resolveAttribute(R.attr.actionBarTheme, outValue, true);

        Resources.Theme widgetTheme = null;
        if (outValue.resourceId != 0) {
            widgetTheme = context.getResources().newTheme();
            widgetTheme.setTo(baseTheme);
            widgetTheme.applyStyle(outValue.resourceId, true);
            widgetTheme.resolveAttribute(R.attr.actionBarWidgetTheme, outValue, true);
        } else {
            baseTheme.resolveAttribute(R.attr.actionBarWidgetTheme, outValue, true);
        }

        if (outValue.resourceId != 0) {
            if (widgetTheme == null) {
                widgetTheme = context.getResources().newTheme();
                widgetTheme.setTo(baseTheme);
            }
            widgetTheme.applyStyle(outValue.resourceId, true);
        }

        if (widgetTheme != null) {
            context = new ContextThemeWrapper(context, 0);
            context.getTheme().setTo(widgetTheme);
        }
    }

    final MenuBuilder menu = new MenuBuilder(context);
    menu.setCallback(this);
    st.setMenu(menu);

    return true;
}

From source file:cm.aptoide.com.actionbarsherlock.widget.SearchView.java

/**
 * For a given suggestion and a given cursor row, get the action message. If
 * not provided by the specific row/column, also check for a single
 * definition (for the action key).//from w ww. ja  v  a  2s  . c  o m
 *
 * @param c The cursor providing suggestions
 * @param actionKey The actionkey record being examined
 *
 * @return Returns a string, or null if no action key message for this
 *         suggestion
 */
// TODO private static String getActionKeyMessage(Cursor c, SearchableInfo.ActionKeyInfo actionKey) {
// TODO     String result = null;
// TODO     // check first in the cursor data, for a suggestion-specific message
// TODO     final String column = actionKey.getSuggestActionMsgColumn();
// TODO     if (column != null) {
// TODO         result = SuggestionsAdapter.getColumnString(c, column);
// TODO     }
// TODO     // If the cursor didn't give us a message, see if there's a single
// TODO     // message defined
// TODO     // for the actionkey (for all suggestions)
// TODO     if (result == null) {
// TODO         result = actionKey.getSuggestActionMsg();
// TODO     }
// TODO     return result;
// TODO }

private int getSearchIconId() {
    TypedValue outValue = new TypedValue();
    getContext().getTheme().resolveAttribute(R.attr.searchViewSearchIcon, outValue, true);
    return outValue.resourceId;
}

From source file:android.support.v7ox.app.AppCompatDelegateImplV7.java

private boolean initializePanelMenu(final PanelFeatureState st) {
    Context context = mContext;/*from   w  w w  .j a v a2 s .  c om*/

    // If we have an action bar, initialize the menu with the right theme.
    if ((st.featureId == FEATURE_OPTIONS_PANEL || st.featureId == FEATURE_SUPPORT_ACTION_BAR)
            && mDecorContentParent != null) {
        final TypedValue outValue = new TypedValue();
        final Resources.Theme baseTheme = context.getTheme();
        baseTheme.resolveAttribute(R.attr.actionBarTheme_ox, outValue, true);

        Resources.Theme widgetTheme = null;
        if (outValue.resourceId != 0) {
            widgetTheme = context.getResources().newTheme();
            widgetTheme.setTo(baseTheme);
            widgetTheme.applyStyle(outValue.resourceId, true);
            widgetTheme.resolveAttribute(R.attr.actionBarWidgetTheme_ox, outValue, true);
        } else {
            baseTheme.resolveAttribute(R.attr.actionBarWidgetTheme_ox, outValue, true);
        }

        if (outValue.resourceId != 0) {
            if (widgetTheme == null) {
                widgetTheme = context.getResources().newTheme();
                widgetTheme.setTo(baseTheme);
            }
            widgetTheme.applyStyle(outValue.resourceId, true);
        }

        if (widgetTheme != null) {
            context = new ContextThemeWrapper(context, 0);
            context.getTheme().setTo(widgetTheme);
        }
    }

    final MenuBuilder menu = new MenuBuilder(context);
    menu.setCallback(this);
    st.setMenu(menu);

    return true;
}

From source file:android.support.v17.leanback.app.GuidedStepFragment.java

/**
 * {@inheritDoc}//from   w w  w .  j  a v a 2s  .  c  o  m
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (DEBUG)
        Log.v(TAG, "onCreateView");

    resolveTheme();
    inflater = getThemeInflater(inflater);

    GuidedStepRootLayout root = (GuidedStepRootLayout) inflater.inflate(R.layout.lb_guidedstep_fragment,
            container, false);

    root.setFocusOutStart(isFocusOutStartAllowed());
    root.setFocusOutEnd(isFocusOutEndAllowed());

    ViewGroup guidanceContainer = (ViewGroup) root.findViewById(R.id.content_fragment);
    ViewGroup actionContainer = (ViewGroup) root.findViewById(R.id.action_fragment);

    Guidance guidance = onCreateGuidance(savedInstanceState);
    View guidanceView = mGuidanceStylist.onCreateView(inflater, guidanceContainer, guidance);
    guidanceContainer.addView(guidanceView);

    View actionsView = mActionsStylist.onCreateView(inflater, actionContainer);
    actionContainer.addView(actionsView);

    View buttonActionsView = mButtonActionsStylist.onCreateView(inflater, actionContainer);
    actionContainer.addView(buttonActionsView);

    GuidedActionAdapter.EditListener editListener = new GuidedActionAdapter.EditListener() {

        @Override
        public void onImeOpen() {
            runImeAnimations(true);
        }

        @Override
        public void onImeClose() {
            runImeAnimations(false);
        }

        @Override
        public long onGuidedActionEditedAndProceed(GuidedAction action) {
            return GuidedStepFragment.this.onGuidedActionEditedAndProceed(action);
        }

        @Override
        public void onGuidedActionEditCanceled(GuidedAction action) {
            GuidedStepFragment.this.onGuidedActionEditCanceled(action);
        }
    };

    mAdapter = new GuidedActionAdapter(mActions, new GuidedActionAdapter.ClickListener() {
        @Override
        public void onGuidedActionClicked(GuidedAction action) {
            GuidedStepFragment.this.onGuidedActionClicked(action);
            if (isSubActionsExpanded()) {
                collapseSubActions();
            } else if (action.hasSubActions()) {
                expandSubActions(action);
            }
        }
    }, this, mActionsStylist, false);
    mButtonAdapter = new GuidedActionAdapter(mButtonActions, new GuidedActionAdapter.ClickListener() {
        @Override
        public void onGuidedActionClicked(GuidedAction action) {
            GuidedStepFragment.this.onGuidedActionClicked(action);
        }
    }, this, mButtonActionsStylist, false);
    mSubAdapter = new GuidedActionAdapter(null, new GuidedActionAdapter.ClickListener() {
        @Override
        public void onGuidedActionClicked(GuidedAction action) {
            if (mActionsStylist.isInExpandTransition()) {
                return;
            }
            if (GuidedStepFragment.this.onSubGuidedActionClicked(action)) {
                collapseSubActions();
            }
        }
    }, this, mActionsStylist, true);
    mAdapterGroup = new GuidedActionAdapterGroup();
    mAdapterGroup.addAdpter(mAdapter, mButtonAdapter);
    mAdapterGroup.addAdpter(mSubAdapter, null);
    mAdapterGroup.setEditListener(editListener);
    mActionsStylist.setEditListener(editListener);

    mActionsStylist.getActionsGridView().setAdapter(mAdapter);
    if (mActionsStylist.getSubActionsGridView() != null) {
        mActionsStylist.getSubActionsGridView().setAdapter(mSubAdapter);
    }
    mButtonActionsStylist.getActionsGridView().setAdapter(mButtonAdapter);
    if (mButtonActions.size() == 0) {
        // when there is no button actions, we dont need show the second panel, but keep
        // the width zero to run ChangeBounds transition.
        LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) buttonActionsView.getLayoutParams();
        lp.weight = 0;
        buttonActionsView.setLayoutParams(lp);
    } else {
        // when there are two actions panel, we need adjust the weight of action to
        // guidedActionContentWidthWeightTwoPanels.
        Context ctx = mThemeWrapper != null ? mThemeWrapper : getActivity();
        TypedValue typedValue = new TypedValue();
        if (ctx.getTheme().resolveAttribute(R.attr.guidedActionContentWidthWeightTwoPanels, typedValue, true)) {
            View actionsRoot = root.findViewById(R.id.action_fragment_root);
            float weight = typedValue.getFloat();
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) actionsRoot.getLayoutParams();
            lp.weight = weight;
            actionsRoot.setLayoutParams(lp);
        }
    }

    int pos = (mSelectedIndex >= 0 && mSelectedIndex < mActions.size()) ? mSelectedIndex
            : getFirstCheckedAction();
    setSelectedActionPosition(pos);

    setSelectedButtonActionPosition(0);

    // Add the background view.
    View backgroundView = onCreateBackgroundView(inflater, root, savedInstanceState);
    if (backgroundView != null) {
        FrameLayout backgroundViewRoot = (FrameLayout) root.findViewById(R.id.guidedstep_background_view_root);
        backgroundViewRoot.addView(backgroundView, 0);
    }
    return root;
}

From source file:com.example.ray.firstapp.bottombar.BottomBar.java

private static void navBarMagic(Activity activity, final BottomBar bottomBar) {
    Resources res = activity.getResources();
    int softMenuIdentifier = res.getIdentifier("config_showNavigationBar", "bool", "android");
    int navBarIdentifier = res.getIdentifier("navigation_bar_height", "dimen", "android");
    int navBarHeight = 0;

    if (navBarIdentifier > 0) {
        navBarHeight = res.getDimensionPixelSize(navBarIdentifier);
    }//from   w w w.j  av a  2 s  .c  o m

    if (!bottomBar.drawBehindNavBar() || navBarHeight == 0
            || (!(softMenuIdentifier > 0 && res.getBoolean(softMenuIdentifier)))) {
        return;
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH
            && ViewConfiguration.get(activity).hasPermanentMenuKey()) {
        return;
    }

    /**
     * Copy-paste coding made possible by:
     * http://stackoverflow.com/a/14871974/940036
     */
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        Display d = activity.getWindowManager().getDefaultDisplay();

        DisplayMetrics realDisplayMetrics = new DisplayMetrics();
        d.getRealMetrics(realDisplayMetrics);

        int realHeight = realDisplayMetrics.heightPixels;
        int realWidth = realDisplayMetrics.widthPixels;

        DisplayMetrics displayMetrics = new DisplayMetrics();
        d.getMetrics(displayMetrics);

        int displayHeight = displayMetrics.heightPixels;
        int displayWidth = displayMetrics.widthPixels;

        boolean hasSoftwareKeys = (realWidth - displayWidth) > 0 || (realHeight - displayHeight) > 0;

        if (!hasSoftwareKeys) {
            return;
        }
    }
    /**
     * End of delicious copy-paste code
     */

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT
            && res.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
        activity.getWindow().getAttributes().flags |= WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION;

        if (bottomBar.useTopOffset()) {
            int offset;
            int statusBarResource = res.getIdentifier("status_bar_height", "dimen", "android");

            if (statusBarResource > 0) {
                offset = res.getDimensionPixelSize(statusBarResource);
            } else {
                offset = MiscUtils.dpToPixel(activity, 25);
            }

            if (!bottomBar.useOnlyStatusbarOffset()) {
                TypedValue tv = new TypedValue();
                if (activity.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
                    offset += TypedValue.complexToDimensionPixelSize(tv.data, res.getDisplayMetrics());
                } else {
                    offset += MiscUtils.dpToPixel(activity, 56);
                }
            }

            bottomBar.getUserContainer().setPadding(0, offset, 0, 0);
        }

        final View outerContainer = bottomBar.getOuterContainer();
        final int navBarHeightCopy = navBarHeight;
        bottomBar.getViewTreeObserver()
                .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                    @SuppressWarnings("deprecation")
                    @Override
                    public void onGlobalLayout() {
                        bottomBar.shyHeightAlreadyCalculated();

                        int newHeight = outerContainer.getHeight() + navBarHeightCopy;
                        outerContainer.getLayoutParams().height = newHeight;

                        if (bottomBar.isShy()) {
                            int defaultOffset = bottomBar.useExtraOffset() ? navBarHeightCopy : 0;
                            bottomBar.setTranslationY(defaultOffset);
                            ((CoordinatorLayout.LayoutParams) bottomBar.getLayoutParams())
                                    .setBehavior(new BottomNavigationBehavior(newHeight, defaultOffset));
                        }

                        ViewTreeObserver obs = outerContainer.getViewTreeObserver();

                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                            obs.removeOnGlobalLayoutListener(this);
                        } else {
                            obs.removeGlobalOnLayoutListener(this);
                        }
                    }
                });
    }
}

From source file:android.support.v17.leanback.app.GuidedStepSupportFragment.java

/**
 * {@inheritDoc}//from  www . ja v  a 2 s  . co m
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (DEBUG)
        Log.v(TAG, "onCreateView");

    resolveTheme();
    inflater = getThemeInflater(inflater);

    GuidedStepRootLayout root = (GuidedStepRootLayout) inflater.inflate(R.layout.lb_guidedstep_fragment,
            container, false);

    root.setFocusOutStart(isFocusOutStartAllowed());
    root.setFocusOutEnd(isFocusOutEndAllowed());

    ViewGroup guidanceContainer = (ViewGroup) root.findViewById(R.id.content_fragment);
    ViewGroup actionContainer = (ViewGroup) root.findViewById(R.id.action_fragment);

    Guidance guidance = onCreateGuidance(savedInstanceState);
    View guidanceView = mGuidanceStylist.onCreateView(inflater, guidanceContainer, guidance);
    guidanceContainer.addView(guidanceView);

    View actionsView = mActionsStylist.onCreateView(inflater, actionContainer);
    actionContainer.addView(actionsView);

    View buttonActionsView = mButtonActionsStylist.onCreateView(inflater, actionContainer);
    actionContainer.addView(buttonActionsView);

    GuidedActionAdapter.EditListener editListener = new GuidedActionAdapter.EditListener() {

        @Override
        public void onImeOpen() {
            runImeAnimations(true);
        }

        @Override
        public void onImeClose() {
            runImeAnimations(false);
        }

        @Override
        public long onGuidedActionEditedAndProceed(GuidedAction action) {
            return GuidedStepSupportFragment.this.onGuidedActionEditedAndProceed(action);
        }

        @Override
        public void onGuidedActionEditCanceled(GuidedAction action) {
            GuidedStepSupportFragment.this.onGuidedActionEditCanceled(action);
        }
    };

    mAdapter = new GuidedActionAdapter(mActions, new GuidedActionAdapter.ClickListener() {
        @Override
        public void onGuidedActionClicked(GuidedAction action) {
            GuidedStepSupportFragment.this.onGuidedActionClicked(action);
            if (isSubActionsExpanded()) {
                collapseSubActions();
            } else if (action.hasSubActions()) {
                expandSubActions(action);
            }
        }
    }, this, mActionsStylist, false);
    mButtonAdapter = new GuidedActionAdapter(mButtonActions, new GuidedActionAdapter.ClickListener() {
        @Override
        public void onGuidedActionClicked(GuidedAction action) {
            GuidedStepSupportFragment.this.onGuidedActionClicked(action);
        }
    }, this, mButtonActionsStylist, false);
    mSubAdapter = new GuidedActionAdapter(null, new GuidedActionAdapter.ClickListener() {
        @Override
        public void onGuidedActionClicked(GuidedAction action) {
            if (mActionsStylist.isInExpandTransition()) {
                return;
            }
            if (GuidedStepSupportFragment.this.onSubGuidedActionClicked(action)) {
                collapseSubActions();
            }
        }
    }, this, mActionsStylist, true);
    mAdapterGroup = new GuidedActionAdapterGroup();
    mAdapterGroup.addAdpter(mAdapter, mButtonAdapter);
    mAdapterGroup.addAdpter(mSubAdapter, null);
    mAdapterGroup.setEditListener(editListener);
    mActionsStylist.setEditListener(editListener);

    mActionsStylist.getActionsGridView().setAdapter(mAdapter);
    if (mActionsStylist.getSubActionsGridView() != null) {
        mActionsStylist.getSubActionsGridView().setAdapter(mSubAdapter);
    }
    mButtonActionsStylist.getActionsGridView().setAdapter(mButtonAdapter);
    if (mButtonActions.size() == 0) {
        // when there is no button actions, we dont need show the second panel, but keep
        // the width zero to run ChangeBounds transition.
        LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) buttonActionsView.getLayoutParams();
        lp.weight = 0;
        buttonActionsView.setLayoutParams(lp);
    } else {
        // when there are two actions panel, we need adjust the weight of action to
        // guidedActionContentWidthWeightTwoPanels.
        Context ctx = mThemeWrapper != null ? mThemeWrapper : getActivity();
        TypedValue typedValue = new TypedValue();
        if (ctx.getTheme().resolveAttribute(R.attr.guidedActionContentWidthWeightTwoPanels, typedValue, true)) {
            View actionsRoot = root.findViewById(R.id.action_fragment_root);
            float weight = typedValue.getFloat();
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) actionsRoot.getLayoutParams();
            lp.weight = weight;
            actionsRoot.setLayoutParams(lp);
        }
    }

    int pos = (mSelectedIndex >= 0 && mSelectedIndex < mActions.size()) ? mSelectedIndex
            : getFirstCheckedAction();
    setSelectedActionPosition(pos);

    setSelectedButtonActionPosition(0);

    // Add the background view.
    View backgroundView = onCreateBackgroundView(inflater, root, savedInstanceState);
    if (backgroundView != null) {
        FrameLayout backgroundViewRoot = (FrameLayout) root.findViewById(R.id.guidedstep_background_view_root);
        backgroundViewRoot.addView(backgroundView, 0);
    }
    return root;
}

From source file:com.harlan.jxust.ui.view.bottombar.BottomBar.java

private static void navBarMagic(Activity activity, final BottomBar bottomBar) {
    Resources res = activity.getResources();
    int softMenuIdentifier = res.getIdentifier("config_showNavigationBar", "bool", "android");
    int navBarIdentifier = res.getIdentifier("navigation_bar_height", "dimen", "android");
    int navBarHeight = 0;

    if (navBarIdentifier > 0) {
        navBarHeight = res.getDimensionPixelSize(navBarIdentifier);
    }/*www.  jav  a  2  s . c om*/

    if (!bottomBar.drawBehindNavBar() || navBarHeight == 0
            || (!(softMenuIdentifier > 0 && res.getBoolean(softMenuIdentifier)))) {
        return;
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH
            && ViewConfiguration.get(activity).hasPermanentMenuKey()) {
        return;
    }

    /**
     * Copy-paste coding made possible by:
     * http://stackoverflow.com/a/14871974/940036
     */
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        Display d = activity.getWindowManager().getDefaultDisplay();

        DisplayMetrics realDisplayMetrics = new DisplayMetrics();
        d.getRealMetrics(realDisplayMetrics);

        int realHeight = realDisplayMetrics.heightPixels;
        int realWidth = realDisplayMetrics.widthPixels;

        DisplayMetrics displayMetrics = new DisplayMetrics();
        d.getMetrics(displayMetrics);

        int displayHeight = displayMetrics.heightPixels;
        int displayWidth = displayMetrics.widthPixels;

        boolean hasSoftwareKeys = (realWidth - displayWidth) > 0 || (realHeight - displayHeight) > 0;

        if (!hasSoftwareKeys) {
            return;
        }
    }
    /**
     * End of delicious copy-paste code
     */

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT
            && res.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
        activity.getWindow().getAttributes().flags |= WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION;

        if (bottomBar.useTopOffset()) {
            int offset;
            int statusBarResource = res.getIdentifier("status_bar_height", "dimen", "android");

            if (statusBarResource > 0) {
                offset = res.getDimensionPixelSize(statusBarResource);
            } else {
                offset = MiscUtils.dpToPixel(activity, 25);
            }

            if (!bottomBar.useOnlyStatusbarOffset()) {
                TypedValue tv = new TypedValue();
                if (activity.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
                    offset += TypedValue.complexToDimensionPixelSize(tv.data, res.getDisplayMetrics());
                } else {
                    offset += MiscUtils.dpToPixel(activity, 56);
                }
            }

            bottomBar.getUserContainer().setPadding(0, offset, 0, 0);
        }

        final View outerContainer = bottomBar.getOuterContainer();
        final int navBarHeightCopy = navBarHeight;
        bottomBar.getViewTreeObserver()
                .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                    @SuppressWarnings("deprecation")
                    @Override
                    public void onGlobalLayout() {
                        bottomBar.shyHeightAlreadyCalculated();

                        int newHeight = outerContainer.getHeight() + navBarHeightCopy;
                        outerContainer.getLayoutParams().height = newHeight;

                        if (bottomBar.isShy()) {
                            int defaultOffset = bottomBar.useExtraOffset() ? navBarHeightCopy : 0;
                            bottomBar.setTranslationY(defaultOffset);
                            ((CoordinatorLayout.LayoutParams) bottomBar.getLayoutParams())
                                    .setBehavior(new BottomNavigationBehavior(newHeight, defaultOffset,
                                            bottomBar.isShy(), bottomBar.mIsTabletMode));
                        }

                        ViewTreeObserver obs = outerContainer.getViewTreeObserver();

                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                            obs.removeOnGlobalLayoutListener(this);
                        } else {
                            obs.removeGlobalOnLayoutListener(this);
                        }
                    }
                });
    }
}

From source file:android.support.v17.leanback.app.GuidedStepFragment.java

private static boolean isGuidedStepTheme(Context context) {
    int resId = R.attr.guidedStepThemeFlag;
    TypedValue typedValue = new TypedValue();
    boolean found = context.getTheme().resolveAttribute(resId, typedValue, true);
    if (DEBUG)//from  www.j  a va 2 s .  c  om
        Log.v(TAG, "Found guided step theme flag? " + found);
    return found && typedValue.type == TypedValue.TYPE_INT_BOOLEAN && typedValue.data != 0;
}

From source file:com.android.contacts.list.ContactListItemView.java

/**
 * Returns the {@link AppCompatImageButton} delete button, creating it if necessary.
 *//*www .jav  a2 s  .  c  o m*/
public AppCompatImageButton getDeleteImageButton(
        final MultiSelectEntryContactListAdapter.DeleteContactListener listener, final int position) {
    if (mDeleteImageButton == null) {
        mDeleteImageButton = new AppCompatImageButton(getContext());
        mDeleteImageButton.setImageResource(R.drawable.quantum_ic_cancel_vd_theme_24);
        mDeleteImageButton.setScaleType(ScaleType.CENTER);
        mDeleteImageButton.setBackgroundColor(Color.TRANSPARENT);
        mDeleteImageButton.setContentDescription(getResources().getString(R.string.description_delete_contact));
        if (CompatUtils.isLollipopCompatible()) {
            final TypedValue typedValue = new TypedValue();
            getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackgroundBorderless,
                    typedValue, true);
            mDeleteImageButton.setBackgroundResource(typedValue.resourceId);
        }
        addView(mDeleteImageButton);
    }
    // Reset onClickListener because after reloading the view, position might be changed.
    mDeleteImageButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // Inform the adapter that delete icon was clicked.
            if (listener != null) {
                listener.onContactDeleteClicked(position);
            }
        }
    });
    return mDeleteImageButton;
}

From source file:android.support.v17.leanback.widget.GuidedActionsStylist.java

private static Animator createAnimator(View v, int attrId) {
    Context ctx = v.getContext();
    TypedValue typedValue = new TypedValue();
    ctx.getTheme().resolveAttribute(attrId, typedValue, true);
    Animator animator = AnimatorInflater.loadAnimator(ctx, typedValue.resourceId);
    animator.setTarget(v);// w ww. ja  v a2s. c  o  m
    return animator;
}