Example usage for android.view ViewGroup findViewsWithText

List of usage examples for android.view ViewGroup findViewsWithText

Introduction

In this page you can find the example usage for android.view ViewGroup findViewsWithText.

Prototype

@Override
    public void findViewsWithText(ArrayList<View> outViews, CharSequence text, int flags) 

Source Link

Usage

From source file:com.cairoconfessions.MainActivity.java

public void addItem(View view) {
    // Instantiate a new "row" view.
    final ViewGroup mFilter = (ViewGroup) findViewById(R.id.filter_cat);
    final ViewGroup mFilterLoc = (ViewGroup) findViewById(R.id.filter_loc);
    final ViewGroup mFilterMain = (ViewGroup) findViewById(R.id.filter_main);
    final ViewGroup newView = (ViewGroup) LayoutInflater.from(this).inflate(R.layout.list_item_example, null);
    final ViewGroup newViewLoc = (ViewGroup) LayoutInflater.from(this).inflate(R.layout.list_item_example,
            null);/*from  w  w  w .  java2s.c o  m*/
    final ViewGroup newViewMain = (ViewGroup) LayoutInflater.from(this).inflate(R.layout.list_item_example,
            null);
    ArrayList<View> presentView = new ArrayList<View>();

    mFilter.findViewsWithText(presentView, ((TextView) view).getText(), 1);
    if (presentView.size() == 0) {
        final String filterName = ((TextView) view).getText().toString();
        switch (((LinearLayout) view.getParent()).getId()) {
        case R.id.cat_filter_list:
            Categories.add(filterName);
            break;
        case R.id.locations:
            Cities.add(filterName);
            break;
        }
        if (filterName.equals("Love")) {
            newView.getChildAt(0).setBackgroundResource(R.color.love);
            newViewLoc.getChildAt(0).setBackgroundResource(R.color.love);
            newViewMain.getChildAt(0).setBackgroundResource(R.color.love);
        }
        if (filterName.equals("Pain")) {
            newView.getChildAt(0).setBackgroundResource(R.color.pain);
            newViewLoc.getChildAt(0).setBackgroundResource(R.color.pain);
            newViewMain.getChildAt(0).setBackgroundResource(R.color.pain);
        }
        if (filterName.equals("Guilt")) {
            newView.getChildAt(0).setBackgroundResource(R.color.guilt);
            newViewLoc.getChildAt(0).setBackgroundResource(R.color.guilt);
            newViewMain.getChildAt(0).setBackgroundResource(R.color.guilt);
        }
        if (filterName.equals("Fantasy")) {
            newView.getChildAt(0).setBackgroundResource(R.color.fantasy);
            newViewLoc.getChildAt(0).setBackgroundResource(R.color.fantasy);
            newViewMain.getChildAt(0).setBackgroundResource(R.color.fantasy);
        }
        if (filterName.equals("Dream")) {
            newView.getChildAt(0).setBackgroundResource(R.color.dream);
            newViewLoc.getChildAt(0).setBackgroundResource(R.color.dream);
            newViewMain.getChildAt(0).setBackgroundResource(R.color.dream);
        }
        ((TextView) newView.findViewById(android.R.id.text1)).setText(filterName);
        ((TextView) newViewLoc.findViewById(android.R.id.text1)).setText(filterName);
        ((TextView) newViewMain.findViewById(android.R.id.text1)).setText(filterName);
        // Set a click listener for the "X" button in the row that will
        // remove the row.

        newView.findViewById(R.id.delete_button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mFilter.removeView(newView);
                mFilterLoc.removeView(newViewLoc);
                mFilterMain.removeView(newViewMain);
                if (mFilter.getChildCount() == 0) {
                    findViewById(R.id.content_loc).setVisibility(View.GONE);
                    findViewById(R.id.content_cat).setVisibility(View.GONE);
                    findViewById(R.id.content_main).setVisibility(View.GONE);
                }
                if (Categories.contains(filterName))
                    while (Categories.remove(filterName))
                        ;
                if (Cities.contains(filterName))
                    while (Cities.remove(filterName))
                        ;
                updateFilters();
            }
        });
        newViewLoc.findViewById(R.id.delete_button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mFilterLoc.removeView(newViewLoc);
                mFilter.removeView(newView);
                mFilterMain.removeView(newViewMain);
                if (mFilterLoc.getChildCount() == 0) {
                    findViewById(R.id.content_loc).setVisibility(View.GONE);
                    findViewById(R.id.content_cat).setVisibility(View.GONE);
                    findViewById(R.id.content_main).setVisibility(View.GONE);
                }
                if (Categories.contains(filterName))
                    while (Categories.remove(filterName))
                        ;
                if (Cities.contains(filterName))
                    while (Cities.remove(filterName))
                        ;
                updateFilters();
            }

        });
        newViewMain.findViewById(R.id.delete_button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mFilterLoc.removeView(newViewLoc);
                mFilter.removeView(newView);
                mFilterMain.removeView(newViewMain);
                if (mFilterMain.getChildCount() == 0) {
                    findViewById(R.id.content_loc).setVisibility(View.GONE);
                    findViewById(R.id.content_cat).setVisibility(View.GONE);
                    findViewById(R.id.content_main).setVisibility(View.GONE);
                }
                if (Categories.contains(filterName))
                    while (Categories.remove(filterName))
                        ;
                if (Cities.contains(filterName))
                    while (Cities.remove(filterName))
                        ;
                updateFilters();
            }

        });

        // Because mFilter has android:animateLayoutChanges set to true,
        // adding this view is automatically animated.
        // mFilterCat.addView(newViewCat);
        mFilter.addView(newView, 0);
        mFilterLoc.addView(newViewLoc, 0);
        mFilterMain.addView(newViewMain, 0);
        findViewById(R.id.content_loc).setVisibility(View.VISIBLE);
        findViewById(R.id.content_cat).setVisibility(View.VISIBLE);
        findViewById(R.id.content_main).setVisibility(View.VISIBLE);
        updateFilters();
        Toast.makeText(this, filterName + " filter added!", Toast.LENGTH_LONG).show();
    } else
        Toast.makeText(this, "Already added!", Toast.LENGTH_LONG).show();
}

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//  w w w  . ja  va  2 s .co  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);

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

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//from   w  ww  .j ava  2  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: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 ww w  .  j  a v  a2s  . 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);
            }
        }
    });
}