List of usage examples for android.view ViewTreeObserver isAlive
public boolean isAlive()
From source file:com.google.samples.apps.iosched.session.SessionDetailFragment.java
private void initViews() { mFABElevation = getResources().getDimensionPixelSize(R.dimen.fab_elevation); mMaxHeaderElevation = getResources().getDimensionPixelSize(R.dimen.session_detail_max_header_elevation); mScrollView = (ObservableScrollView) getActivity().findViewById(R.id.scroll_view); mScrollView.addCallbacks(this); ViewTreeObserver vto = mScrollView.getViewTreeObserver(); if (vto.isAlive()) { vto.addOnGlobalLayoutListener(mGlobalLayoutListener); }//from ww w. ja v a2 s.c o m mScrollViewChild = getActivity().findViewById(R.id.scroll_view_child); mScrollViewChild.setVisibility(View.INVISIBLE); mDetailsContainer = getActivity().findViewById(R.id.details_container); mHeaderBox = getActivity().findViewById(R.id.header_session); mTitle = (TextView) getActivity().findViewById(R.id.session_title); mSubtitle = (TextView) getActivity().findViewById(R.id.session_subtitle); mPhotoViewContainer = getActivity().findViewById(R.id.session_photo_container); mPhotoView = (ImageView) getActivity().findViewById(R.id.session_photo); mAbstract = (TextView) getActivity().findViewById(R.id.session_abstract); mPlusOneIcon = (ImageView) getActivity().findViewById(R.id.gplus_icon_box); mTwitterIcon = (ImageView) getActivity().findViewById(R.id.twitter_icon_box); //Find view that shows a Videocam icon if the session is being live streamed. mLiveStreamVideocamIconAndText = (TextView) getActivity() .findViewById(R.id.live_stream_videocam_icon_and_text); // Find view that shows a play button and some text for the user to watch the session live stream. mLiveStreamPlayIconAndText = (TextView) getActivity().findViewById(R.id.live_stream_play_icon_and_text); mRequirements = (TextView) getActivity().findViewById(R.id.session_requirements); mTags = (LinearLayout) getActivity().findViewById(R.id.session_tags); mTagsContainer = (ViewGroup) getActivity().findViewById(R.id.session_tags_container); ViewCompat.setTransitionName(mPhotoView, SessionDetailConstants.TRANSITION_NAME_PHOTO); mAddScheduleButtonContainer = getActivity().findViewById(R.id.add_schedule_button_container); mAddScheduleButton = (CheckableFloatingActionButton) getActivity().findViewById(R.id.add_schedule_button); mNoPlaceholderImageLoader = new ImageLoader(getContext()); mSpeakersImageLoader = new ImageLoader(getContext(), R.drawable.person_image_empty); }
From source file:ca.zadrox.dota2esportticker.ui.MatchDetailActivity.java
@Override protected void onDestroy() { super.onDestroy(); if (mScrollView == null) { return;//from ww w.j av a 2 s . c o m } ViewTreeObserver vto = mScrollView.getViewTreeObserver(); if (vto.isAlive()) { vto.removeOnGlobalLayoutListener(mGlobalLayoutListener); } }
From source file:ca.zadrox.dota2esportticker.ui.MatchDetailActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_matches_detail); final Toolbar toolbar = getActionBarToolbar(); toolbar.setNavigationIcon(R.drawable.ic_up); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override//from w w w . j a v a 2 s . com public void onClick(View v) { onBackPressed(); } }); mHandler.post(new Runnable() { @Override public void run() { toolbar.setTitle(""); } }); //setmUrl(); mFABElevation = getResources().getDimensionPixelSize(R.dimen.fab_elevation); mMaxHeaderElevation = getResources().getDimensionPixelSize(R.dimen.session_detail_max_header_elevation); 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 = (ViewGroup) findViewById(R.id.details_container); mDetailsContainer.setY(2000); mHeaderBox = findViewById(R.id.header_match); mTitle = (TextView) findViewById(R.id.header_title); mSubtitle = (TextView) findViewById(R.id.header_subtitle); mMatchViewContainer = findViewById(R.id.match_photo_container); //mMatchViewContainer.setVisibility(View.INVISIBLE); mMatchTeamOneImageView = (ImageView) findViewById(R.id.match_team_one_photo); mMatchTeamTwoImageView = (ImageView) findViewById(R.id.match_team_two_photo); mMatchImageView = (ImageView) findViewById(R.id.match_photo); mMatchScoreView = (TextView) findViewById(R.id.match_score_view); mBestOfView = (TextView) findViewById(R.id.match_bo); mAddReminderButton = (CheckableFrameLayout) findViewById(R.id.add_schedule_button); mAddReminderButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { boolean starred = !mStarred; showStarred(starred, true); setSessionStarred(starred); } }); mGGnetMatchId = getIntent().getLongExtra(ARGS_GG_MATCH_ID, 0); mMatchImageView.setColorFilter(Color.rgb(123, 123, 123), android.graphics.PorterDuff.Mode.MULTIPLY); DisplayMetrics displayMetrics = getResources().getDisplayMetrics(); final int dWidth = displayMetrics.widthPixels * 2 / 3; Picasso.with(this).load(R.drawable.drawable_dota_bg_dire_ancient).config(Bitmap.Config.ARGB_8888) .resize(Math.round(dWidth * PHOTO_ASPECT_RATIO), dWidth) .transform(new CropImageTransform(displayMetrics.heightPixels, displayMetrics.widthPixels)) .into(mMatchImageView); LoaderManager manager = getLoaderManager(); mHasPhoto = true; manager.initLoader(DB_LOADER, null, mCursorCallbacks); }
From source file:org.ciasaboark.tacere.activity.fragment.EventsFragment.java
private void showFirstRunWizardIfNeeded() { if (prefs.isFirstRun()) { prefs.disableFirstRun();/*from www . j ava 2s. c o m*/ final ViewTreeObserver viewTreeObserver = ((Activity) context).getWindow().getDecorView() .getViewTreeObserver(); viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { if (!showingTutorial) { showingTutorial = true; startActivity(new Intent(context.getApplicationContext(), TutorialActivity.class)); } if (viewTreeObserver.isAlive()) { if (Build.VERSION.SDK_INT >= 16) { viewTreeObserver.removeOnGlobalLayoutListener(this); } else { viewTreeObserver.removeGlobalOnLayoutListener(this); } } } }); } }
From source file:com.andrada.sitracker.ui.fragment.PublicationInfoFragment.java
private void setupCustomScrolling() { mScrollView.addCallbacks(this); ViewTreeObserver vto = mScrollView.getViewTreeObserver(); if (vto.isAlive()) { vto.addOnGlobalLayoutListener(mGlobalLayoutListener); }//from www. j av a 2 s. c om }
From source file:com.andrada.sitracker.ui.fragment.PublicationInfoFragment.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) @Override//from ww w . j a va 2s . com public void onDestroyView() { super.onDestroyView(); if (mScrollView == null) { return; } ViewTreeObserver vto = mScrollView.getViewTreeObserver(); if (vto.isAlive()) { //noinspection deprecation if (UIUtils.hasJellyBean()) { vto.removeOnGlobalLayoutListener(mGlobalLayoutListener); } else { vto.removeGlobalOnLayoutListener(mGlobalLayoutListener); } } }
From source file:com.androidinspain.deskclock.timer.TimerFragment.java
/** * @param toView one of {@link #mTimersView} or {@link #mCreateTimerView} * @param timerToRemove the timer to be removed during the animation; {@code null} if no timer * should be removed//from w ww. j a v a 2s. c o m * @param animateDown {@code true} if the views should animate upwards, otherwise downwards */ private void animateToView(final View toView, final Timer timerToRemove, final boolean animateDown) { if (mCurrentView == toView) { return; } final boolean toTimers = toView == mTimersView; if (toTimers) { mTimersView.setVisibility(VISIBLE); } else { mCreateTimerView.setVisibility(VISIBLE); } // Avoid double-taps by enabling/disabling the set of buttons active on the new view. updateFab(BUTTONS_DISABLE); final long animationDuration = UiDataModel.getUiDataModel().getLongAnimationDuration(); final ViewTreeObserver viewTreeObserver = toView.getViewTreeObserver(); viewTreeObserver.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { if (viewTreeObserver.isAlive()) { viewTreeObserver.removeOnPreDrawListener(this); } final View view = mTimersView.findViewById(com.androidinspain.deskclock.R.id.timer_time); final float distanceY = view != null ? view.getHeight() + view.getY() : 0; final float translationDistance = animateDown ? distanceY : -distanceY; toView.setTranslationY(-translationDistance); mCurrentView.setTranslationY(0f); toView.setAlpha(0f); mCurrentView.setAlpha(1f); final Animator translateCurrent = ObjectAnimator.ofFloat(mCurrentView, TRANSLATION_Y, translationDistance); final Animator translateNew = ObjectAnimator.ofFloat(toView, TRANSLATION_Y, 0f); final AnimatorSet translationAnimatorSet = new AnimatorSet(); translationAnimatorSet.playTogether(translateCurrent, translateNew); translationAnimatorSet.setDuration(animationDuration); translationAnimatorSet.setInterpolator(AnimatorUtils.INTERPOLATOR_FAST_OUT_SLOW_IN); final Animator fadeOutAnimator = ObjectAnimator.ofFloat(mCurrentView, ALPHA, 0f); fadeOutAnimator.setDuration(animationDuration / 2); fadeOutAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { super.onAnimationStart(animation); // The fade-out animation and fab-shrinking animation should run together. updateFab(FAB_AND_BUTTONS_SHRINK); } @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); if (toTimers) { showTimersView(FAB_AND_BUTTONS_EXPAND); // Reset the state of the create view. mCreateTimerView.reset(); } else { showCreateTimerView(FAB_AND_BUTTONS_EXPAND); } if (timerToRemove != null) { DataModel.getDataModel().removeTimer(timerToRemove); Events.sendTimerEvent(com.androidinspain.deskclock.R.string.action_delete, com.androidinspain.deskclock.R.string.label_deskclock); } // Update the fab and button states now that the correct view is visible and // before the animation to expand the fab and buttons starts. updateFab(FAB_AND_BUTTONS_IMMEDIATE); } }); final Animator fadeInAnimator = ObjectAnimator.ofFloat(toView, ALPHA, 1f); fadeInAnimator.setDuration(animationDuration / 2); fadeInAnimator.setStartDelay(animationDuration / 2); final AnimatorSet animatorSet = new AnimatorSet(); animatorSet.playTogether(fadeOutAnimator, fadeInAnimator, translationAnimatorSet); animatorSet.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); mTimersView.setTranslationY(0f); mCreateTimerView.setTranslationY(0f); mTimersView.setAlpha(1f); mCreateTimerView.setAlpha(1f); } }); animatorSet.start(); return true; } }); }
From source file:com.velli.passwordmanager.FragmentPasswordDetails.java
@SuppressLint("NewApi") @Override/*w w w .j a v a 2 s.com*/ public View onCreateView(LayoutInflater inflater, ViewGroup root, Bundle savedInstanceState) { final View v; final Bundle bundle = savedInstanceState != null ? savedInstanceState : getArguments(); if (bundle != null) { mIsPassword = bundle.getInt(BUNDLE_KEY_TYPE, TYPE_PASSWORD) == TYPE_PASSWORD; mEntryId = bundle.getInt(BUNDLE_KEY_ENTRY_ID, -1); } v = inflater.inflate( mIsPassword ? R.layout.fragment_layout_details : R.layout.fragment_layout_details_credit_card, root, false); mBottomToolbar = (Toolbar) v.findViewById(R.id.details_view_bottom_toolbar); mBottomBarDivider = v.findViewById(R.id.details_view_toolbar_divider); mTitle = (RobotoTextView) v.findViewById(R.id.details_view_description); mLoginType = (RobotoTextView) v.findViewById(R.id.details_view_login_type); mUrl = (RobotoTextView) v.findViewById(R.id.details_view_url); mUrlTitle = (RobotoTextView) v.findViewById(R.id.details_view_url_title); mUsername = (RobotoTextView) v.findViewById(R.id.details_view_username); mUsernameTitle = (RobotoTextView) v.findViewById(R.id.details_view_username_title); mPassword = (RobotoTextView) v.findViewById(R.id.details_view_password); mNotes = (RobotoTextView) v.findViewById(R.id.details_view_notes); mNotesTitle = (RobotoTextView) v.findViewById(R.id.details_view_notes_title); mGroup = (RobotoTextView) v.findViewById(R.id.details_view_group); mGroupTitle = (RobotoTextView) v.findViewById(R.id.details_view_group_title); mLoginIcon = (ImageView) v.findViewById(R.id.details_view_login_icon); mInfoContainer = (LinearLayout) v.findViewById(R.id.details_info_container); mCardType = (RobotoTextView) v.findViewById(R.id.details_view_card_type); mCardNumber = (RobotoTextView) v.findViewById(R.id.details_view_card_number); mCardExpDate = (RobotoTextView) v.findViewById(R.id.details_view_card_exp_date); mCardCSV = (RobotoTextView) v.findViewById(R.id.details_view_card_csv); mWifiSecurity = (RobotoTextView) v.findViewById(R.id.details_view_wifi_security); mWifiSecurityTitle = (RobotoTextView) v.findViewById(R.id.details_view_wifi_security_title); mWifiSSID = (RobotoTextView) v.findViewById(R.id.details_view_wifi_ssid); mWifiSSIDTitle = (RobotoTextView) v.findViewById(R.id.details_view_wifi_ssid_title); mViewsSet = true; if (mEntry != null) { onGetPassword(mEntry); } if (bundle != null && !mAnimated) { final int titleY = bundle.getInt(BUNDLE_KEY_TITLE_Y_POS, -1); final int titleX = bundle.getInt(BUNDLE_KEY_TITLE_X_POS, -1); final int iconY = bundle.getInt(BUNDLE_KEY_ICON_Y_POS, -1); final int iconX = bundle.getInt(BUNDLE_KEY_ICON_X_POS, -1); mIsGridLayoutManager = bundle.getBoolean(BUNDLE_KEY_IS_GRID_LAYOUT_MANAGER, false); if (titleY != -1 && titleX != -1 && iconY != -1 && iconX != -1) { final ViewTreeObserver viewTreeObserver = getActivity().getWindow().getDecorView() .getViewTreeObserver(); viewTreeObserver.addOnPreDrawListener(new OnPreDrawListener() { @SuppressLint("NewApi") @Override public boolean onPreDraw() { if (viewTreeObserver.isAlive()) { viewTreeObserver.removeOnPreDrawListener(this); } if (mTitleAnimator == null) { mTitleAnimator = new DetailsTitleAnimator(); } mTitleAnimator.animate(titleY, titleX, iconY, iconX, v.getHeight()); return false; } }); } else if (mBottomToolbar != null) { mBottomToolbar.setVisibility(View.VISIBLE); } } else if (mBottomToolbar != null) { mBottomToolbar.setVisibility(View.VISIBLE); } return v; }
From source file:suntai.ditudome.utils.photoview.PhotoViewAttacher.java
public void cleanup() { if (null == mImageView) { return; // cleanup already done }//from w w w . j av a 2s. c o m final ImageView imageView = mImageView.get(); if (null != imageView) { // Remove this as a global layout listener ViewTreeObserver observer = imageView.getViewTreeObserver(); if (null != observer && observer.isAlive()) { observer.removeGlobalOnLayoutListener(this); } // Remove the ImageView's reference to this imageView.setOnTouchListener(null); // make sure a pending fling runnable won't be run cancelFling(); } if (null != mGestureDetector) { mGestureDetector.setOnDoubleTapListener(null); } // Clear listeners too mMatrixChangeListener = null; mPhotoTapListener = null; mViewTapListener = null; // Finally, clear ImageView mImageView = null; }
From source file:com.cylan.jiafeigou.support.photoview.PhotoViewAttacher.java
/** * Clean-up the resources attached to this object. This needs to be called when the ImageView is * no longer used. A good example is from {@link View#onDetachedFromWindow()} or * from {@link android.app.Activity#onDestroy()}. This is automatically called if you are using * {@link PhotoView}./*from w w w. j a v a 2 s . c o m*/ */ @SuppressWarnings("deprecation") public void cleanup() { if (null == mImageView) { return; // cleanup already done } final ImageView imageView = mImageView.get(); if (null != imageView) { // Remove this as a global layout listener ViewTreeObserver observer = imageView.getViewTreeObserver(); if (null != observer && observer.isAlive()) { observer.removeGlobalOnLayoutListener(this); } // Remove the ImageView'account reference to this imageView.setOnTouchListener(null); // make sure a pending fling runnable won't be run cancelFling(); } if (null != mGestureDetector) { mGestureDetector.setOnDoubleTapListener(null); } // Clear listeners too mMatrixChangeListener = null; mPhotoTapListener = null; mViewTapListener = null; // Finally, clearLocal ImageView mImageView = null; }