List of usage examples for android.view ViewTreeObserver addOnGlobalLayoutListener
public void addOnGlobalLayoutListener(OnGlobalLayoutListener listener)
From source file:cn.golden.pinchzoomcanvasview.PinchZoomCanvasViewAttacher.java
public PinchZoomCanvasViewAttacher(ImageView imageView, boolean zoomable) { mImageView = new WeakReference<>(imageView); imageView.setDrawingCacheEnabled(true); imageView.setOnTouchListener(this); ViewTreeObserver observer = imageView.getViewTreeObserver(); if (null != observer) observer.addOnGlobalLayoutListener(this); // Make sure we using MATRIX Scale Type setImageViewScaleTypeMatrix(imageView); if (imageView.isInEditMode()) { return;//from www . ja va2 s. c o m } // Create Gesture Detectors... mScaleDragDetector = VersionedGestureDetector.newInstance(imageView.getContext(), this); mGestureDetector = new GestureDetector(imageView.getContext(), new GestureDetector.SimpleOnGestureListener() { // forward long click listener @Override public void onLongPress(MotionEvent e) { if (null != mLongClickListener) { mLongClickListener.onLongClick(getImageView()); } } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { if (mSingleFlingListener != null) { if (getScale() > DEFAULT_MIN_SCALE) { return false; } if (MotionEventCompat.getPointerCount(e1) > SINGLE_TOUCH || MotionEventCompat.getPointerCount(e2) > SINGLE_TOUCH) { return false; } return mSingleFlingListener.onFling(e1, e2, velocityX, velocityY); } return false; } }); // mGestureDetector.setOnDoubleTapListener(new DefaultOnDoubleTapListener(this)); mBaseRotation = 0.0f; // Finally, update the UI so that we're zoomable setZoomable(zoomable); }
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 ww w . ja va 2s . com 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 w w . j av a 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); 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.example.g40_70m.framedemo.view.photoview.PhotoViewAttacher.java
public PhotoViewAttacher(ImageView imageView, boolean zoomable) { mImageView = new WeakReference<>(imageView); imageView.setDrawingCacheEnabled(true); imageView.setOnTouchListener(this); ViewTreeObserver observer = imageView.getViewTreeObserver(); if (null != observer) observer.addOnGlobalLayoutListener(this); // Make sure we using MATRIX Scale Type setImageViewScaleTypeMatrix(imageView); if (imageView.isInEditMode()) { return;//from w w w .ja v a 2s . c o m } // Create Gesture Detectors... mScaleDragDetector = VersionedGestureDetector.newInstance(imageView.getContext(), this); mGestureDetector = new GestureDetector(imageView.getContext().getApplicationContext(), new GestureDetector.SimpleOnGestureListener() { @Override public boolean onDown(MotionEvent e) { downTime = System.currentTimeMillis(); singeClick = !singeClick; return super.onDown(e); } @Override public boolean onSingleTapUp(MotionEvent e) { if (System.currentTimeMillis() - downTime < 200) { getImageView().postDelayed(new Runnable() {//300? ? @Override public void run() { if (singeClick) { onClickListener.onClick(getImageView()); } } }, 300); } downTime = 0; return super.onSingleTapUp(e); } // forward long click listener @Override public void onLongPress(MotionEvent e) { singeClick = false; if (null != mLongClickListener) { mLongClickListener.onLongClick(getImageView()); } } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { if (mSingleFlingListener != null) { if (getScale() > DEFAULT_MIN_SCALE) { return false; } if (MotionEventCompat.getPointerCount(e1) > SINGLE_TOUCH || MotionEventCompat.getPointerCount(e2) > SINGLE_TOUCH) { return false; } return mSingleFlingListener.onFling(e1, e2, velocityX, velocityY); } return false; } }); mGestureDetector.setOnDoubleTapListener(new DefaultOnDoubleTapListener(this)); mBaseRotation = 0.0f; // Finally, update the UI so that we're zoomable setZoomable(zoomable); }
From source file:baizhuan.hangzhou.com.gankcopy.view.customview.photoview.PhotoViewAttacher.java
public PhotoViewAttacher(ImageView imageView, boolean zoomable) { mImageView = new WeakReference<>(imageView); imageView.setDrawingCacheEnabled(true); imageView.setOnTouchListener(this); ViewTreeObserver observer = imageView.getViewTreeObserver(); if (null != observer) observer.addOnGlobalLayoutListener(this); // Make sure we using MATRIX Scale Type setImageViewScaleTypeMatrix(imageView); if (imageView.isInEditMode()) { return;// w w w .ja va 2s. c o m } // Create Gesture Detectors... mScaleDragDetector = VersionedGestureDetector.newInstance(imageView.getContext(), this); mGestureDetector = new GestureDetector(imageView.getContext(), new GestureDetector.SimpleOnGestureListener() { // forward long click listener @Override public void onLongPress(MotionEvent e) { if (null != mLongClickListener) { mLongClickListener.onLongClick(getImageView()); } } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { if (mSingleFlingListener != null) { if (getScale() > DEFAULT_MIN_SCALE) { return false; } if (MotionEventCompat.getPointerCount(e1) > SINGLE_TOUCH || MotionEventCompat.getPointerCount(e2) > SINGLE_TOUCH) { return false; } return mSingleFlingListener.onFling(e1, e2, velocityX, velocityY); } return false; } }); mGestureDetector.setOnDoubleTapListener(new DefaultOnDoubleTapListener(this)); mBaseRotation = 0.0f; // Finally, update the UI so that we're zoomable setZoomable(zoomable); }
From source file:com.biggun.drawbitmapmesh.photoview.PhotoViewAttacher.java
public PhotoViewAttacher(ImageView imageView, boolean zoomable) { mImageView = new WeakReference<>(imageView); imageView.setDrawingCacheEnabled(true); imageView.setOnTouchListener(this); ViewTreeObserver observer = imageView.getViewTreeObserver(); if (null != observer) observer.addOnGlobalLayoutListener(this); // Make sure we using MATRIX Scale Type setImageViewScaleTypeMatrix(imageView); if (imageView.isInEditMode()) { return;/*w ww . java 2 s .c om*/ } // Create Gesture Detectors... mScaleDragDetector = VersionedGestureDetector.newInstance(imageView.getContext(), this); mGestureDetector = new GestureDetector(imageView.getContext(), new GestureDetector.SimpleOnGestureListener() { // forward long click listener @Override public void onLongPress(MotionEvent e) { if (null != mLongClickListener) { mLongClickListener.onLongClick(getImageView()); } } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { if (mSingleFlingListener != null) { if (getScale() > DEFAULT_MIN_SCALE) { return false; } if (MotionEventCompat.getPointerCount(e1) > SINGLE_TOUCH || MotionEventCompat.getPointerCount(e2) > SINGLE_TOUCH) { return false; } return mSingleFlingListener.onFling(e1, e2, velocityX, velocityY); } return false; } }); mGestureDetector.setOnDoubleTapListener(new DefaultOnDoubleTapListener(this)); mBaseRotation = 0.0f; // Finally, update the UI so that we're zoomable setZoomable(zoomable); }
From source file:com.mooc.viewpage_photoview_circleindicator.photoview.PhotoViewAttacher.java
public PhotoViewAttacher(ImageView imageView, boolean zoomable) { //?//from w ww . j av a2 s . com mImageView = new WeakReference<>(imageView); imageView.setDrawingCacheEnabled(true);//???bitmap?? imageView.setOnTouchListener(this); ViewTreeObserver observer = imageView.getViewTreeObserver(); if (null != observer) observer.addOnGlobalLayoutListener(this); // Make sure we using MATRIX Scale Type setImageViewScaleTypeMatrix(imageView); // if (imageView.isInEditMode()) { return; } // Create Gesture Detectors... mScaleDragDetector = VersionedGestureDetector.newInstance(imageView.getContext(), this); mGestureDetector = new GestureDetector(imageView.getContext(), new GestureDetector.SimpleOnGestureListener() { // forward long click listener @Override public void onLongPress(MotionEvent e) { if (null != mLongClickListener) { mLongClickListener.onLongClick(getImageView()); } } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { if (mSingleFlingListener != null) { if (getScale() > DEFAULT_MIN_SCALE) { return false; } if (MotionEventCompat.getPointerCount(e1) > SINGLE_TOUCH || MotionEventCompat.getPointerCount(e2) > SINGLE_TOUCH) { return false; } return mSingleFlingListener.onFling(e1, e2, velocityX, velocityY); } return false; } }); mGestureDetector.setOnDoubleTapListener(new DefaultOnDoubleTapListener(this)); mBaseRotation = 0.0f; // Finally, update the UI so that we're zoomable setZoomable(zoomable); }
From source file:com.google.samples.apps.iosched.ui.SessionDetailFragment.java
private void setupCustomScrolling(View rootView) { mScrollView = (ObservableScrollView) rootView.findViewById(R.id.scroll_view); mScrollView.addCallbacks(this); ViewTreeObserver vto = mScrollView.getViewTreeObserver(); if (vto.isAlive()) { vto.addOnGlobalLayoutListener(mGlobalLayoutListener); }//from w ww . ja v a 2 s .co m }
From source file:com.google.samples.apps.iosched.ui.SessionDetailActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { UIUtils.tryTranslateHttpIntent(this); BeamUtils.tryUpdateIntentFromBeam(this); boolean shouldBeFloatingWindow = shouldBeFloatingWindow(); if (shouldBeFloatingWindow) { setupFloatingWindow();//from w ww . j ava 2 s.c o m } super.onCreate(savedInstanceState); setContentView(R.layout.activity_session_detail); final Toolbar toolbar = getActionBarToolbar(); toolbar.setNavigationIcon(shouldBeFloatingWindow ? R.drawable.ic_ab_close : R.drawable.ic_up); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { finish(); } }); mHandler.post(new Runnable() { @Override public void run() { toolbar.setTitle(""); } }); if (savedInstanceState == null) { Uri sessionUri = getIntent().getData(); BeamUtils.setBeamSessionUri(this, sessionUri); } mSessionUri = getIntent().getData(); if (mSessionUri == null) { return; } mSessionId = ScheduleContract.Sessions.getSessionId(mSessionUri); mFABElevation = getResources().getDimensionPixelSize(R.dimen.fab_elevation); mMaxHeaderElevation = getResources().getDimensionPixelSize(R.dimen.session_detail_max_header_elevation); mTagColorDotSize = getResources().getDimensionPixelSize(R.dimen.tag_color_dot_size); mHandler = new Handler(); if (mSpeakersImageLoader == null) { mSpeakersImageLoader = new ImageLoader(this, R.drawable.person_image_empty); } if (mNoPlaceholderImageLoader == null) { mNoPlaceholderImageLoader = new ImageLoader(this); } mScrollView = (ObservableScrollView) findViewById(R.id.scroll_view); mScrollView.addCallbacks(this); ViewTreeObserver vto = mScrollView.getViewTreeObserver(); if (vto.isAlive()) { vto.addOnGlobalLayoutListener(mGlobalLayoutListener); } mScrollViewChild = findViewById(R.id.scroll_view_child); mScrollViewChild.setVisibility(View.INVISIBLE); mDetailsContainer = findViewById(R.id.details_container); mHeaderBox = findViewById(R.id.header_session); mTitle = (TextView) findViewById(R.id.session_title); mSubtitle = (TextView) findViewById(R.id.session_subtitle); mPhotoViewContainer = findViewById(R.id.session_photo_container); mPhotoView = (ImageView) findViewById(R.id.session_photo); mPlusOneButton = (PlusOneButton) findViewById(R.id.plus_one_button); mAbstract = (TextView) findViewById(R.id.session_abstract); mRequirements = (TextView) findViewById(R.id.session_requirements); mTags = (LinearLayout) findViewById(R.id.session_tags); mTagsContainer = (ViewGroup) findViewById(R.id.session_tags_container); mAddScheduleButton = (CheckableFrameLayout) findViewById(R.id.add_schedule_button); mAddScheduleButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { boolean starred = !mStarred; SessionsHelper helper = new SessionsHelper(SessionDetailActivity.this); showStarred(starred, true); helper.setSessionStarred(mSessionUri, starred, mTitleString); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { mAddScheduleButton.announceForAccessibility( starred ? getString(R.string.session_details_a11y_session_added) : getString(R.string.session_details_a11y_session_removed)); } /* [ANALYTICS:EVENT] * TRIGGER: Add or remove a session from My Schedule. * CATEGORY: 'Session' * ACTION: 'Starred' or 'Unstarred' * LABEL: Session title/subtitle. * [/ANALYTICS] */ AnalyticsManager.sendEvent("Session", starred ? "Starred" : "Unstarred", mTitleString, 0L); } }); ViewCompat.setTransitionName(mPhotoView, TRANSITION_NAME_PHOTO); LoaderManager manager = getLoaderManager(); manager.initLoader(SessionsQuery._TOKEN, null, this); manager.initLoader(SpeakersQuery._TOKEN, null, this); manager.initLoader(TAG_METADATA_TOKEN, null, this); }
From source file:com.ncode.android.apps.schedo.ui.EventDetailActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { UIUtils.tryTranslateHttpIntent(this); BeamUtils.tryUpdateIntentFromBeam(this); boolean shouldBeFloatingWindow = shouldBeFloatingWindow(); if (shouldBeFloatingWindow) { setupFloatingWindow();/* www . j a v a2s . c o m*/ } super.onCreate(savedInstanceState); setContentView(R.layout.activity_session_detail); final Toolbar toolbar = getActionBarToolbar(); toolbar.setNavigationIcon(shouldBeFloatingWindow ? R.drawable.ic_ab_close : R.drawable.ic_up); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { finish(); } }); mHandler.post(new Runnable() { @Override public void run() { toolbar.setTitle(""); } }); if (savedInstanceState == null) { Uri sessionUri = getIntent().getData(); BeamUtils.setBeamSessionUri(this, sessionUri); } mSessionUri = getIntent().getData(); if (mSessionUri == null) { return; } mSessionId = ScheduleContract.Sessions.getSessionId(mSessionUri); mFABElevation = getResources().getDimensionPixelSize(R.dimen.fab_elevation); mMaxHeaderElevation = getResources().getDimensionPixelSize(R.dimen.session_detail_max_header_elevation); mTagColorDotSize = getResources().getDimensionPixelSize(R.dimen.tag_color_dot_size); mHandler = new Handler(); if (mSpeakersImageLoader == null) { mSpeakersImageLoader = new ImageLoader(this, R.drawable.person_image_empty); } if (mNoPlaceholderImageLoader == null) { mNoPlaceholderImageLoader = new ImageLoader(this); } mScrollView = (ObservableScrollView) findViewById(R.id.scroll_view); mScrollView.addCallbacks(this); ViewTreeObserver vto = mScrollView.getViewTreeObserver(); if (vto.isAlive()) { vto.addOnGlobalLayoutListener(mGlobalLayoutListener); } mScrollViewChild = findViewById(R.id.scroll_view_child); mScrollViewChild.setVisibility(View.INVISIBLE); mDetailsContainer = findViewById(R.id.details_container); mHeaderBox = findViewById(R.id.header_session); mTitle = (TextView) findViewById(R.id.session_title); mSubtitle = (TextView) findViewById(R.id.session_subtitle); mPhotoViewContainer = findViewById(R.id.session_photo_container); mPhotoView = (ImageView) findViewById(R.id.session_photo); mPlusOneButton = (PlusOneButton) findViewById(R.id.plus_one_button); mAbstract = (TextView) findViewById(R.id.session_abstract); mRequirements = (TextView) findViewById(R.id.session_requirements); mTags = (LinearLayout) findViewById(R.id.session_tags); mTagsContainer = (ViewGroup) findViewById(R.id.session_tags_container); mAddScheduleButton = (CheckableFrameLayout) findViewById(R.id.add_schedule_button); mAddScheduleButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { boolean starred = !mStarred; SessionsHelper helper = new SessionsHelper(EventDetailActivity.this); showStarred(starred, true); helper.setSessionStarred(mSessionUri, starred, mTitleString); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { mAddScheduleButton.announceForAccessibility( starred ? getString(R.string.session_details_a11y_session_added) : getString(R.string.session_details_a11y_session_removed)); } /* [ANALYTICS:EVENT] * TRIGGER: Add or remove a session from My Schedule. * CATEGORY: 'Session' * ACTION: 'Starred' or 'Unstarred' * LABEL: Session title/subtitle. * [/ANALYTICS] */ AnalyticsManager.sendEvent("Session", starred ? "Starred" : "Unstarred", mTitleString, 0L); } }); ViewCompat.setTransitionName(mPhotoView, TRANSITION_NAME_PHOTO); LoaderManager manager = getLoaderManager(); manager.initLoader(SessionsQuery._TOKEN, null, this); manager.initLoader(SpeakersQuery._TOKEN, null, this); manager.initLoader(TAG_METADATA_TOKEN, null, this); }