Example usage for android.view View FIND_VIEWS_WITH_CONTENT_DESCRIPTION

List of usage examples for android.view View FIND_VIEWS_WITH_CONTENT_DESCRIPTION

Introduction

In this page you can find the example usage for android.view View FIND_VIEWS_WITH_CONTENT_DESCRIPTION.

Prototype

int FIND_VIEWS_WITH_CONTENT_DESCRIPTION

To view the source code for android.view View FIND_VIEWS_WITH_CONTENT_DESCRIPTION.

Click Source Link

Document

Find find views that contain the specified content description.

Usage

From source file:net.tjado.passwdsafe.PasswdSafeOpenFileFragment.java

public void setOverflowButton(final Activity activity) {
    final String overflowDescription = activity.getString(R.string.abc_action_menu_overflow_description);
    final ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
    final ViewTreeObserver viewTreeObserver = decorView.getViewTreeObserver();
    viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override//  w  w  w.j a  va2  s .c o  m
        public void onGlobalLayout() {
            final ArrayList<View> outViews = new ArrayList<View>();
            decorView.findViewsWithText(outViews, overflowDescription,
                    View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION);
            if (outViews.isEmpty()) {
                return;
            }
            AppCompatImageView overflow = (AppCompatImageView) outViews.get(0);

            itsOriginalDrawable = overflow.getDrawable();

            overflow.setImageDrawable(PasswdSafeUtil.scaleImage(
                    activity.getResources().getDrawable(R.drawable.icon_yubico), 0.09f, getResources()));
            overflow.setColorFilter(activity.getResources().getColor(R.color.menu_icon_color));
            removeOnGlobalLayoutListener(decorView, this);
        }
    });
}

From source file:net.tjado.passwdsafe.PasswdSafeOpenFileFragment.java

public void resetOverflowButton(final Activity activity) {
    final String overflowDescription = activity.getString(R.string.abc_action_menu_overflow_description);
    final ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
    final ViewTreeObserver viewTreeObserver = decorView.getViewTreeObserver();
    viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override/*from   w w w .  ja  v  a2s . c om*/
        public void onGlobalLayout() {
            final ArrayList<View> outViews = new ArrayList<View>();
            decorView.findViewsWithText(outViews, overflowDescription,
                    View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION);
            if (outViews.isEmpty()) {
                return;
            }
            AppCompatImageView overflow = (AppCompatImageView) outViews.get(0);

            overflow.setImageDrawable(itsOriginalDrawable);
            removeOnGlobalLayoutListener(decorView, this);
        }
    });
}

From source file:com.jins_meme.bridge.MainActivity.java

void changeSettingButton(final boolean isRev) {
    final String overflowDesc = getString(R.string.accessibility_overflow);

    final ViewGroup decor = (ViewGroup) getWindow().getDecorView();

    decor.post(new Runnable() {
        @Override//from   w w  w.  j a  v  a 2s  . c om
        public void run() {
            final ArrayList<View> outViews = new ArrayList<>();

            decor.findViewsWithText(outViews, overflowDesc, View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION);

            if (outViews.isEmpty()) {
                return;
            }

            ImageView overflow = (ImageView) outViews.get(0);
            if (isRev) {
                overflow.setImageResource(R.mipmap.ic_setting_rev);
            } else {
                overflow.setImageResource(R.mipmap.ic_setting);
            }
        }
    });
}