List of usage examples for android.view View removeOnLayoutChangeListener
public void removeOnLayoutChangeListener(OnLayoutChangeListener listener)
From source file:Main.java
private static void setupChangeAnimationOneTime(final View view) { ObjectAnimator objectAnimator = sMapAnimators.get(view); if (objectAnimator != null) { objectAnimator.cancel();//from w w w.jav a 2 s. c o m sMapAnimators.remove(objectAnimator); } OnLayoutChangeListener listener = sMapListeners.get(view); if (listener != null) { view.removeOnLayoutChangeListener(listener); sMapListeners.remove(view); } final OnLayoutChangeListener onLayoutChangeListener = new OnLayoutChangeListener() { @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { ObjectAnimator objectAnimator = sMapAnimators.get(view); if (objectAnimator != null) { objectAnimator.cancel(); sMapAnimators.remove(objectAnimator); } final ObjectAnimator changeAnimator = getChangeAnimator(v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom); sMapAnimators.put(view, changeAnimator); if (left != oldLeft || top != oldTop || right != oldRight || bottom != oldBottom) { Animator.AnimatorListener animatorListener = new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { if (sAnimatorListener != null) { sAnimatorListener.onAnimationStart(animation); } } @Override public void onAnimationRepeat(Animator animation) { if (sAnimatorListener != null) { sAnimatorListener.onAnimationRepeat(animation); } } @Override public void onAnimationEnd(Animator animation) { sMapAnimators.remove(view); if (sAnimatorListener != null) { sAnimatorListener.onAnimationEnd(animation); } } @Override public void onAnimationCancel(Animator animation) { if (sAnimatorListener != null) { sAnimatorListener.onAnimationCancel(animation); } } }; changeAnimator.addListener(animatorListener); changeAnimator.start(); } else { sMapAnimators.remove(view); if (sAnimatorListener != null) { sAnimatorListener.onAnimationEnd(changeAnimator); } } } }; view.addOnLayoutChangeListener(onLayoutChangeListener); sMapListeners.put(view, onLayoutChangeListener); }
From source file:despotoski.nikola.github.com.bottomnavigationlayout.Util.java
public static void runOnAttachedToLayout(View v, final Runnable runnable) { if (ViewCompat.isLaidOut(v)) runnable.run();//from www.ja v a2 s. c om else { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { v.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { @TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { runnable.run(); v.removeOnLayoutChangeListener(this); } }); return; } final ViewTreeObserver viewTreeObserver = v.getViewTreeObserver(); if (viewTreeObserver != null && viewTreeObserver.isAlive()) { viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { runnable.run(); if (viewTreeObserver.isAlive()) //noinspection deprecation viewTreeObserver.removeGlobalOnLayoutListener(this); } }); } } }
From source file:tech.salroid.filmy.fragment.FullReadFragment.java
@Nullable @Override/*from www . j a va 2 s . co m*/ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.read_full_layout, container, false); ButterKnife.bind(this, view); crossButton.setOnClickListener(this); // To run the animation as soon as the view is layout in the view hierarchy we add this // listener and remove it // as soon as it runs to prevent multiple animations if the view changes bounds view.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { v.removeOnLayoutChangeListener(this); int cx = getArguments().getInt("cx"); int cy = getArguments().getInt("cy"); // get the hypothenuse so the radius is from one corner to the other int radius = (int) Math.hypot(right, bottom); Animator reveal; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { reveal = ViewAnimationUtils.createCircularReveal(v, cx, cy, 0, radius); reveal.setInterpolator(new DecelerateInterpolator(2f)); reveal.setDuration(1000); reveal.start(); } } }); return view; }
From source file:com.chrynan.guitartuner.PitchFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) { player = new PitchPlayer(); player.play(note);// ww w.ja v a2 s .com viewRoot = inflater.inflate(R.layout.pitch_fragment, parent, false); text = (TextView) viewRoot.findViewById(R.id.note); if (note != null) { text.setText(note.getNote()); } viewRoot.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { v.removeOnLayoutChangeListener(this); circularReveal(x, y); } }); viewRoot.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (getActivity() instanceof TunerActivity) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { ((TunerActivity) getActivity()) .transitionBackToTunerFragment(unreveal(event.getX(), event.getY())); } else { ((TunerActivity) getActivity()).transitionBackToTunerFragment(null); } player.stop(); } return true; } }); return viewRoot; }
From source file:tech.salroid.filmy.fragment.AllTrailerFragment.java
@Nullable @Override/*from w w w . ja v a 2s . c om*/ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity()); nightMode = sp.getBoolean("dark", false); View view = inflater.inflate(R.layout.all_trailer_layout, container, false); ButterKnife.bind(this, view); if (!nightMode) allThemeLogic(); else { nightModeLogic(); } crossButton.setOnClickListener(this); // To run the animation as soon as the view is layout in the view hierarchy we add this // listener and remove it // as soon as it runs to prevent multiple animations if the view changes bounds view.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { v.removeOnLayoutChangeListener(this); int cx = getArguments().getInt("cx"); int cy = getArguments().getInt("cy"); // get the hypothenuse so the radius is from one corner to the other int radius = (int) Math.hypot(right, bottom); Animator reveal; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { reveal = ViewAnimationUtils.createCircularReveal(v, cx, cy, 0, radius); reveal.setInterpolator(new DecelerateInterpolator(2f)); reveal.setDuration(1000); reveal.start(); } } }); init(view); return view; }
From source file:com.brettyin.cardshelper.fragment.SignInFragment.java
@Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { final View contentView = inflater.inflate(R.layout.fragment_sign_in, container, false); contentView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { @Override//from w ww .ja v a2s. c o m public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { v.removeOnLayoutChangeListener(this); setUpGridView(getView()); } }); return contentView; }
From source file:app.philm.in.fragments.base.BasePhilmTabFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_viewpager, container, false); mAdapter = new TabPagerAdapter(getChildFragmentManager()); mViewPager = (ViewPager) view.findViewById(R.id.viewpager); mViewPager.setAdapter(mAdapter);/*from ww w. j a va 2s . c o m*/ mViewPager.setPageMargin(getResources().getDimensionPixelSize(R.dimen.spacing_minor)); mSlidingTabStrip = (SlidingTabLayout) view.findViewById(R.id.viewpager_tabs); mSlidingTabStrip.setViewPager(mViewPager); mSlidingTabStrip.setTabListener(new SlidingTabLayout.TabListener() { @Override public void onTabSelected(int pos) { // NO-OP } @Override public void onTabReSelected(int pos) { final Fragment fragment = mAdapter.getItem(pos); if (fragment instanceof ListFragment) { ((ListFragment) fragment).smoothScrollTo(0); } } }); mSlidingTabStrip.setSelectedIndicatorColors(getResources().getColor(R.color.primary_accent_color)); mSlidingTabStrip.setDividerColors(getResources().getColor(R.color.primary_accent_color_dark_10)); mSlidingTabStrip.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { final int h = bottom - top; mChildrenInsets.top = h; propogateAdditionalInsetsToChildren(mChildrenInsets); if (h > 0) { v.removeOnLayoutChangeListener(this); } } }); if (savedInstanceState != null) { mCurrentItem = savedInstanceState.getInt(SAVE_SELECTED_TAB); } return view; }
From source file:com.eugene.fithealthmaingit.UI.NavFragments.FragmentSearch.java
private void InitiateSearch() { card_search.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { @TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override// ww w . j av a 2 s . c o m public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { v.removeOnLayoutChangeListener(this); InitiateSearch.handleToolBar(getActivity(), card_search, view_search, listView, edit_text_search, line_divider); } }); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { LogQuickSearch logQuickSearch = logQuickSearchAdapter.getItem(position); edit_text_search.setText(logQuickSearch.getName()); listView.setVisibility(View.GONE); ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE)) .hideSoftInputFromWindow(edit_text_search.getWindowToken(), 0); searchFood(logQuickSearch.getName(), 0); } }); edit_text_search.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { if (edit_text_search.getText().toString().length() == 0) { logQuickSearchAdapter = new LogQuickSearchAdapter(getActivity(), 0, LogQuickSearch.all()); listView.setAdapter(logQuickSearchAdapter); clearSearch.setImageResource(R.mipmap.ic_keyboard_voice); IsAdapterEmpty(); } else { logQuickSearchAdapter = new LogQuickSearchAdapter(getActivity(), 0, LogQuickSearch.FilterByName(edit_text_search.getText().toString())); listView.setAdapter(logQuickSearchAdapter); clearSearch.setImageResource(R.mipmap.ic_close); IsAdapterEmpty(); } } @Override public void afterTextChanged(Editable s) { } }); clearSearch.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (edit_text_search.getText().toString().length() != 0) { edit_text_search.setText(""); searchBack.setVisibility(View.GONE); listView.setVisibility(View.VISIBLE); clearItems(); ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE)) .toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY); IsAdapterEmpty(); } else { promptSpeechInput(edit_text_search); } } }); }
From source file:net.simonvt.cathode.ui.fragment.EpisodeFragment.java
@Override public void onViewCreated(View view, Bundle inState) { super.onViewCreated(view, inState); ButterKnife.inject(this, view); if (!isTablet) { toolbar.setNavigationIcon(R.drawable.ic_arrow_back); }//from w w w .j a v a 2 s .com toolbar.setNavigationOnClickListener(navigationClickListener); createMenu(toolbar); toolbar.setOnMenuItemClickListener(menuClickListener); updateTitle(); wait = true; view.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { v.removeOnLayoutChangeListener(this); wait = false; if (currentState == STATE_CONTENT_VISIBLE) { content.setAlpha(1.0f); content.setVisibility(View.VISIBLE); progress.setVisibility(View.GONE); } else { content.setVisibility(View.GONE); progress.setAlpha(1.0f); progress.setVisibility(View.VISIBLE); } if (!isTablet && getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { content.setScrollY(screenshot.getHeight() / 2); } } }); rating.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { RatingDialog.newInstance(RatingDialog.Type.EPISODE, episodeId, currentRating) .show(getFragmentManager(), DIALOG_RATING); } }); if (!isTablet) { content.setListener(new ObservableScrollView.ScrollListener() { @Override public void onScrollChanged(int l, int t) { final int offset = (int) (t / 2.0f); screenshot.setTranslationY(offset); } }); } }
From source file:co.carlosjimenez.android.currencyalerts.app.MainActivityFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main, container, false); ButterKnife.bind(this, rootView); mContext = (AppCompatActivity) getActivity(); mFirebaseAnalytics = FirebaseAnalytics.getInstance(mContext); mContext.setSupportActionBar(mToolbar); mContext.getSupportActionBar().setDisplayShowHomeEnabled(true); mContext.getSupportActionBar().setDisplayShowTitleEnabled(true); mMainCurrency = Utility.getMainCurrency(mContext); // Set the layout manager mRecyclerView.setLayoutManager(new LinearLayoutManager(mContext)); // use this setting to improve performance if you know that changes // in content do not change the layout size of the RecyclerView mRecyclerView.setHasFixedSize(true); // The ForecastAdapter will take data from a source and // use it to populate the RecyclerView it's attached to. mForexAdapter = new ForexAdapter(mContext, new ForexAdapter.ForexAdapterOnClickHandler() { @Override//from w w w . java 2 s. c o m public void onClick(String currencyId, String currencyName, ForexAdapter.ForexAdapterViewHolder vh) { String[] currencies = { mMainCurrency.getId(), currencyId }; sendHitToAnalytics(currencyId, currencyName); double value = Double.parseDouble(mCurrencyEditText.getText().toString()); ((Callback) getActivity()).onItemSelected( ForexContract.RateEntry.buildCurrencyRateWithValue(currencies, value), mImageView, vh); } }, mTvEmptyView); // specify an adapter (see also next example) mRecyclerView.setAdapter(mForexAdapter); getCalculateButton(); loadMainCurrencyDetails(); mCoordinatorLayout.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { v.removeOnLayoutChangeListener(this); addFloatingActionButton(); } }); new LoadCurrencyTask(mContext).execute(); ForexSyncAdapter.initializeSyncAdapter(mContext); // Ad is delayed some seconds as this affects the performance mHandler.postDelayed(new Runnable() { @Override public void run() { loadAd(); } }, AD_DELAY_MILLISECONDS); return rootView; }