Java Code Examples for android.view.ViewGroup#getViewTreeObserver()

The following examples show how to use android.view.ViewGroup#getViewTreeObserver() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ToolbarColorizeHelper.java    From IdeaTrackerPlus with MIT License 6 votes vote down vote up
/**
 * It's important to set overflowDescription atribute in styles, so we can grab the reference
 * to the overflow icon. Check: res/values/styles.xml
 *
 * @param activity
 * @param colorFilter
 */
private static void setOverflowButtonColor(final Activity activity, final PorterDuffColorFilter colorFilter) {
    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
        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.setColorFilter(colorFilter);
            removeOnGlobalLayoutListener(decorView, this);
        }
    });
}
 
Example 2
Source File: ToolbarColorizeHelper.java    From RetroMusicPlayer with GNU General Public License v3.0 6 votes vote down vote up
/**
 * It's important to set overflowDescription atribute in styles, so we can grab the reference
 * to the overflow icon. Check: res/values/styles.xml
 *
 * @param activity
 * @param colorFilter
 */
private static void setOverflowButtonColor(final Activity activity, final PorterDuffColorFilter colorFilter) {
    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
        public void onGlobalLayout() {
            final ArrayList<View> outViews = new ArrayList<View>();
            decorView.findViewsWithText(outViews, overflowDescription,
                    View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION);
            if (outViews.isEmpty()) {
                return;
            }
            final ActionMenuView overflowViewParent = (ActionMenuView) outViews.get(0).getParent();
            overflowViewParent.getOverflowIcon().setColorFilter(colorFilter);
            removeOnGlobalLayoutListener(decorView, this);
        }
    });
}
 
Example 3
Source File: ToolbarContentTintHelper.java    From APlayer with GNU General Public License v3.0 6 votes vote down vote up
public static void setOverflowButtonColor(@NonNull Activity activity,
    final @ColorInt int color) {
  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
    public void onGlobalLayout() {
      final ArrayList<View> outViews = new ArrayList<>();
      decorView.findViewsWithText(outViews, overflowDescription,
          View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION);
      if (outViews.isEmpty()) {
        return;
      }
      final AppCompatImageView overflow = (AppCompatImageView) outViews.get(0);
      overflow.setImageDrawable(TintHelper.createTintedDrawable(overflow.getDrawable(), color));
      decorView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
    }
  });
}
 
Example 4
Source File: ToolbarColorizeHelper.java    From Slide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * It's important to set overflowDescription atribute in styles, so we can grab the reference
 * to the overflow icon. Check: res/values/styles.xml
 *
 * @param activity
 * @param colorFilter
 */
private static void setOverflowButtonColor(final Activity activity, final PorterDuffColorFilter colorFilter) {
    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
        public void onGlobalLayout() {
            final ArrayList<View> outViews = new ArrayList<>();
            decorView.findViewsWithText(outViews, overflowDescription,
                    View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION);
            if (outViews.isEmpty()) {
                return;
            }
            ImageView overflow = (ImageView) outViews.get(0);
            overflow.setColorFilter(colorFilter);
            removeOnGlobalLayoutListener(decorView, this);
        }
    });
}
 
Example 5
Source File: Utils.java    From kolabnotes-android with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void setOverflowButtonColor(final Activity activity, final boolean lightColor){
    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
        public void onGlobalLayout() {
            final ArrayList<View> outViews = new ArrayList<View>();
            decorView.findViewsWithText(outViews, overflowDescription, View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION);

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

            ImageView overflow = (ImageView) outViews.get(0);
            overflow.setColorFilter(lightColor ? android.graphics.Color.WHITE : android.graphics.Color.BLACK);
            decorView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
        }
    });
}
 
Example 6
Source File: MyActionBarActivity.java    From Clip-Stack with MIT License 6 votes vote down vote up
public static void setOverflowButtonColor(final Activity activity, final int imageID) {
    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
        public void onGlobalLayout() {
            final ArrayList<View> outViews = new ArrayList<View>();
            decorView.findViewsWithText(outViews, overflowDescription,
                    View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION);
            if (outViews.isEmpty()) {
                return;
            }
            TintImageView overflow=(TintImageView) outViews.get(0);
            //overflow.setColorFilter(Color.CYAN);
            overflow.setImageResource(imageID);
            removeOnGlobalLayoutListener(decorView, this);
        }
    });
}
 
Example 7
Source File: PadActivity.java    From Bluefruit_LE_Connect_Android with MIT License 6 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();

    if (!kIsImmersiveModeEnabled) {
        final ViewGroup rootLayout = (ViewGroup) findViewById(R.id.rootLayout);
        ViewTreeObserver observer = rootLayout.getViewTreeObserver();
        observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                adjustAspectRatio();

                rootLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            }
        });
    }

    // Setup listeners
    mBleManager.setBleListener(this);

    // Refresh timer
    isUITimerRunning = true;
    mUIRefreshTimerHandler.postDelayed(mUIRefreshTimerRunnable, 0);

}
 
Example 8
Source File: ModeViewAdapter.java    From mapwize-ui-android with MIT License 5 votes vote down vote up
@Override
@NonNull
public ModeItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(parent.getContext())
            .inflate(R.layout.mapwize_mode_item, parent, false);
    ViewTreeObserver vto = parent.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(() -> {
        int width  = parent.getMeasuredWidth();
        ViewGroup.LayoutParams params = view.getLayoutParams();
        int divider = modes.size() < 5 ? modes.size() : 4;
        params.width = (width / divider);
        view.setLayoutParams(params);
    });
    return new ModeItemViewHolder(view);
}
 
Example 9
Source File: ReviewAndConfirmActivity.java    From px-android with MIT License 4 votes vote down vote up
private void configureScrollLayoutListener(final View floatingConfirmLayout, final ViewGroup scrollView) {
    final ViewTreeObserver viewTreeObserver = scrollView.getViewTreeObserver();
    viewTreeObserver.addOnGlobalLayoutListener(
        () -> resolveFloatingButtonElevationVisibility(floatingConfirmLayout, scrollView));
}
 
Example 10
Source File: ReviewAndConfirmActivity.java    From px-android with MIT License 4 votes vote down vote up
private void addScrollListener(final View floatingConfirmLayout, final ViewGroup scrollView) {
    final ViewTreeObserver viewTreeObserver = scrollView.getViewTreeObserver();
    viewTreeObserver.addOnScrollChangedListener(
        () -> resolveFloatingButtonElevationVisibility(floatingConfirmLayout, scrollView));
}
 
Example 11
Source File: LocationInformation.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mRootView = (ViewGroup) inflater.inflate(R.layout.fragment_location_information, container, false);

    mSwitchOffButton = mRootView.findViewById(R.id.switchOffButton);
    mSwitchOffButton.setOnClickListener(v -> mMapHolder.disableLocations());
    ImageButton shareButton = mRootView.findViewById(R.id.shareButton);
    shareButton.setOnClickListener(v -> mMapHolder.shareLocation(new GeoPoint(mLatitude, mLongitude), null));
    ImageButton inputButton = mRootView.findViewById(R.id.inputButton);
    inputButton.setOnClickListener(v -> {
        TextInputDialogFragment.Builder builder = new TextInputDialogFragment.Builder();
        mTextInputDialog = builder.setCallbacks(LocationInformation.this)
                .setHint(getContext().getString(R.string.coordinates))
                .setShowPasteButton(true)
                .create();
        mTextInputDialog.show(getFragmentManager(), "coordinatesInput");
    });

    mCoordinateDegree = mRootView.findViewById(R.id.coordinate_degree);
    mCoordinateDegMin = mRootView.findViewById(R.id.coordinate_degmin);
    mCoordinateDegMinSec = mRootView.findViewById(R.id.coordinate_degminsec);
    mCoordinateUtmUps = mRootView.findViewById(R.id.coordinate_utmups);
    mCoordinateMgrs = mRootView.findViewById(R.id.coordinate_mgrs);
    mSunriseTitle = mRootView.findViewById(R.id.sunriseTitle);
    mSunsetTitle = mRootView.findViewById(R.id.sunsetTitle);
    mSunrise = mRootView.findViewById(R.id.sunrise);
    mSunset = mRootView.findViewById(R.id.sunset);
    mOffset = mRootView.findViewById(R.id.offset);
    mDeclination = mRootView.findViewById(R.id.declination);

    if (BuildConfig.FULL_VERSION) {
        mRootView.findViewById(R.id.extendTable).setVisibility(View.VISIBLE);
    }

    if (HelperUtils.needsTargetedAdvice(Configuration.ADVICE_SUNRISE_SUNSET)) {
        ViewTreeObserver vto = mRootView.getViewTreeObserver();
        vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                mRootView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                if (BuildConfig.FULL_VERSION) {
                    View view = mSunrise.getVisibility() == View.VISIBLE ? mSunrise : mSunset;
                    HelperUtils.showTargetedAdvice(getActivity(), Configuration.ADVICE_SUNRISE_SUNSET, R.string.advice_sunrise_sunset, view, true);
                }
            }
        });
    }

    return mRootView;
}