public void hideSearchBar(boolean shiftView) { if (shiftView) { mSearchViewContainer.animate().cancel(); mSearchViewContainer.setAlpha(1); mSearchViewContainer.setTranslationY(0); mSearchViewContainer .animate() .withLayer() .alpha(0) .translationY(-mSearchView.getHeight()) .setDuration(200) .setListener(mHideListener); mFragmentsFrame .animate() .withLayer() .translationY(-mSearchViewContainer.getHeight()) .setDuration(200) .setListener( new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mBottomPaddingView.setVisibility(View.VISIBLE); mFragmentsFrame.setTranslationY(0); mActionBar.setVisibility(View.INVISIBLE); } }); } else { mSearchViewContainer.setTranslationY(-mSearchView.getHeight()); mActionBar.setVisibility(View.INVISIBLE); } }
public void showSearchBar() { mSearchViewContainer.animate().cancel(); mSearchViewContainer.setAlpha(0); mSearchViewContainer.setTranslationY(-mSearchViewContainer.getHeight()); mSearchViewContainer .animate() .withLayer() .alpha(1) .translationY(0) .setDuration(200) .setListener( new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { mSearchViewContainer.setVisibility(View.VISIBLE); mActionBar.setVisibility(View.VISIBLE); } }); mFragmentsFrame.setTranslationY(-mSearchViewContainer.getHeight()); mFragmentsFrame .animate() .withLayer() .translationY(0) .setDuration(200) .setListener( new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { mBottomPaddingView.setVisibility(View.GONE); } }); }
@Override public void onScrollChanged(int deltaX, int deltaY) { // Reposition the header bar -- it's normally anchored to the top of the content, // but locks to the top of the screen on scroll int scrollY = mScrollView.getScrollY(); float newTop = Math.max(mPhotoHeightPixels, scrollY); mHeaderBox.setTranslationY(newTop); mAddScheduleButtonContainer.setTranslationY( newTop + mHeaderHeightPixels - mAddScheduleButtonContainerHeightPixels / 2); float gapFillProgress = 1; if (mPhotoHeightPixels != 0) { gapFillProgress = Math.min(Math.max(UIUtils.getProgress(scrollY, 0, mPhotoHeightPixels), 0), 1); } ViewCompat.setElevation(mHeaderBox, gapFillProgress * mMaxHeaderElevation); ViewCompat.setElevation( mAddScheduleButtonContainer, gapFillProgress * mMaxHeaderElevation + mFABElevation); ViewCompat.setElevation( mAddScheduleButton, gapFillProgress * mMaxHeaderElevation + mFABElevation); // Move background photo (parallax effect) mPhotoViewContainer.setTranslationY(scrollY * 0.5f); }
public void setTranslationY(float translationY) { if (NEEDS_PROXY) { wrap(this).setTranslationY(translationY); } else { super.setTranslationY(translationY); } }
@Override public boolean onDependentViewChanged(CoordinatorLayout parent, View child, View dependency) { if (DEBUG) Timber.d("onDependentViewChanged"); float translationY = Math.min(0, dependency.getTranslationY() - dependency.getHeight()); child.setTranslationY(translationY); return true; }
private void setTranslation(View v, float translate) { if (mSwipeDirection == X) { v.setTranslationX(translate); } else { v.setTranslationY(translate); } }
@Override protected void onFinishInflate() { super.onFinishInflate(); // Get the individual components mDropTargetBar = findViewById(R.id.drag_target_bar); mInfoDropTarget = (ButtonDropTarget) mDropTargetBar.findViewById(R.id.info_target_text); mDeleteDropTarget = (ButtonDropTarget) mDropTargetBar.findViewById(R.id.delete_target_text); mInfoDropTarget.setSearchDropTargetBar(this); mDeleteDropTarget.setSearchDropTargetBar(this); mEnableDropDownDropTargets = getResources().getBoolean(R.bool.config_useDropTargetDownTransition); // Create the various fade animations if (mEnableDropDownDropTargets) { LauncherAppState app = LauncherAppState.getInstance(); DeviceProfile grid = app.getDynamicGrid().getDeviceProfile(); mBarHeight = grid.searchBarSpaceHeightPx; mDropTargetBar.setTranslationY(-mBarHeight); mDropTargetBarAnim = LauncherAnimUtils.ofFloat(mDropTargetBar, "translationY", -mBarHeight, 0f); } else { mDropTargetBar.setAlpha(0f); mDropTargetBarAnim = LauncherAnimUtils.ofFloat(mDropTargetBar, "alpha", 0f, 1f); } setupAnimation(mDropTargetBarAnim, mDropTargetBar); }
@SuppressLint("NewApi") @Override public void setTranslationY(float translationY) { if (proxy != null) { proxy.setTranslationY(translationY); } super.setTranslationY(translationY); }
@SuppressLint("NewApi") private void setTranslation(View v, float translate) { if (mSwipeDirection == X) { v.setTranslationX(translate); } else { v.setTranslationY(translate); } }
public static void setActionBarTranslation(Activity activity, float y) { ViewGroup vg = (ViewGroup) activity.findViewById(android.R.id.content).getParent(); int count = vg.getChildCount(); if (DEBUG) { Log.d(TAG, "=========================="); } // Get the class of action bar Class<?> actionBarContainer = null; Field isSplit = null; try { actionBarContainer = Class.forName("com.android.internal.widget.ActionBarContainer"); isSplit = actionBarContainer.getDeclaredField("mIsSplit"); isSplit.setAccessible(true); } catch (Exception e) { if (DEBUG) { Log.e(TAG, Log.getStackTraceString(e)); } } for (int i = 0; i < count; i++) { View v = vg.getChildAt(i); if (v.getId() != android.R.id.content) { if (DEBUG) { Log.d(TAG, "Found View: " + v.getClass().getName()); } try { if (actionBarContainer.isInstance(v)) { if (DEBUG) { Log.d(TAG, "Found ActionBarContainer"); } if (isSplit.getBoolean(v)) { if (DEBUG) { Log.d(TAG, "Found Split Action Bar"); } continue; } } } catch (Exception e) { if (DEBUG) { Log.e(TAG, Log.getStackTraceString(e)); } } v.setTranslationY(y); } } if (DEBUG) { Log.d(TAG, "=========================="); } }
public void removeChild(View v) { addToRecycledViews(v); mLinearLayout.removeView(v); mCallback.removeTaskDescription(v); // Restore the alpha/translation parameters to what they were before swiping // (for when these items are recycled) View contentView = getChildContentView(v); contentView.setAlpha(1f); contentView.setTranslationY(0); }
@Override private void start(View view, long l, float f, float f2, float f3, float f4, float f5, float f6) { view.setScaleX(f); view.setScaleY(f); view.setTranslationX(f3); view.setTranslationY(f4); ViewPropertyAnimator viewPropertyAnimator = view.animate().translationX(f5).translationY(f6).scaleX(f2).scaleY(f2).setDuration(l); viewPropertyAnimator.start(); }
@Override public void transformPage(View view, float position) { int pageWidth = view.getWidth(); View mask = view.findViewById(R.id.mask); if (position < -1) { // [-Infinity,-1) // This page is way off-screen to the left. view.setAlpha(0); } else if (position <= 0) { // [-1,0] view.setAlpha(1); mask.setAlpha(0); // Counteract the default slide transition view.setTranslationX(pageWidth * -position); // set Y position to swipe in from top float yPosition = position * view.getHeight(); view.setTranslationY(yPosition); } else if (position <= 1) { // [0,1] // Fade the page out. view.setAlpha(1); mask.setAlpha(position); // Counteract the default slide transition view.setTranslationX(pageWidth * -position); view.setTranslationY(0); // Scale the page down (between MIN_SCALE and 1) /* float scaleFactor = MIN_SCALE + (1 - MIN_SCALE) * (1 - Math.abs(position)); view.setScaleX(scaleFactor); view.setScaleY(scaleFactor); */ } else { // (1,+Infinity] // This page is way off-screen to the right. view.setAlpha(0); } }
@SuppressLint("NewApi") public void setOffset(float offset) { View view = this.view.get(); if (view != null) { if (isAPI11) { view.setTranslationY(offset); } else { translatePreICS(view, offset); } } }
@SuppressLint("NewApi") private void setTranslationY(View v, int y) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { v.setTranslationY(y); } else { TranslateAnimation anim = new TranslateAnimation(0, 0, y, y); anim.setFillAfter(true); anim.setDuration(0); v.startAnimation(anim); } }
/** Update the parallax based on the current slide offset. */ @SuppressLint("NewApi") private void applyParallaxForCurrentSlideOffset() { if (mParallaxOffset > 0) { int mainViewOffset = getCurrentParalaxOffset(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { mMainView.setTranslationY(mainViewOffset); } else { AnimatorProxy.wrap(mMainView).setTranslationY(mainViewOffset); } } }
@SuppressLint("NewApi") private void moveHandlebar(final float where) { float move = where; if (move < mScrollbarMargin) move = mScrollbarMargin; else if (move > getHeight() - mHandlebar.getHeight() - mScrollbarMargin) move = getHeight() - mHandlebar.getHeight() - mScrollbarMargin; if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) mHandlebar.startAnimation(moveCompat(move)); else mHandlebar.setTranslationY(move); }
/** * reset the view to default status * * @param target the target */ public void reset(View target) { target.setAlpha(1); target.setScaleX(1); target.setScaleY(1); target.setTranslationX(0); target.setTranslationY(0); target.setRotation(0); target.setRotationY(0); target.setRotationX(0); target.setPivotX(target.getMeasuredWidth() / 2.0f); target.setPivotY(target.getMeasuredHeight() / 2.0f); }
// Wrapper around setting the header offset in different ways depending on // the API version @SuppressLint("NewApi") private void setHeaderOffet(int offset) { if (mHeaderOffset == null || mHeaderOffset != offset) { mHeaderOffset = offset; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { mHeader.setTranslationY(mHeaderOffset); } else { MarginLayoutParams params = (MarginLayoutParams) mHeader.getLayoutParams(); params.topMargin = mHeaderOffset; mHeader.setLayoutParams(params); } } }
@Override public void doFrame(long frameTimeNanos) { if (isInitialized) { int oldX = location[0]; int oldY = location[1]; injectLocation(); view.setTranslationX(oldX - location[0]); view.setTranslationY(oldY - location[1]); } else { injectLocation(); isInitialized = true; } choreographer.postFrameCallback(this); }
/** Positions the media view using the given offset (on the y axis) */ private void offsetMediaView(boolean viewerVisible, float offset) { if (viewerVisible) { // finally position the viewer viewer.setTranslationY(-offset); viewer.setVisibility(View.VISIBLE); // position the repost badge, if it is visible if (repostHint.getVisibility() == View.VISIBLE) { repostHint.setTranslationY(viewer.getPaddingTop() - repostHint.getPivotY() - offset); } } else { viewer.setVisibility(View.INVISIBLE); } }
public void initDot(View dot, boolean normalColor) { dot.setTranslationX(0); dot.setTranslationY(0); if (normalColor) { GradientDrawable dotBg = (GradientDrawable) dot.getBackground(); dotBg.setColor(getResources().getColor(R.color.dot_normal)); dotBg.setStroke( (int) getResources().getDimension(R.dimen.loading_dot_stroke_width), getResources().getColor(R.color.dot_active)); } else { GradientDrawable dotBg = (GradientDrawable) dot.getBackground(); dotBg.setColor(getResources().getColor(R.color.dot_active)); } }
public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = createView(parent); } ViewHolder holder = (ViewHolder) convertView.getTag(); // index is reverse since most recent appears at the bottom... final int index = position; final TaskDescription td = mRecentTaskDescriptions.get(index); // holder.thumbnailView.setContentDescription(td.getLabel()); holder.loadedThumbnailAndIcon = td.isLoaded(); if (td.isLoaded()) { updateIcon(holder, td.getIcon(), true, false); } if (index == 0) { if (mAnimateIconOfFirstTask) { if (mItemToAnimateInWhenWindowAnimationIsFinished != null) { holder.iconView.setAlpha(1f); holder.iconView.setTranslationX(0f); holder.iconView.setTranslationY(0f); } mItemToAnimateInWhenWindowAnimationIsFinished = holder; final int translation = -getResources() .getDimensionPixelSize(R.dimen.status_bar_recents_app_icon_translate_distance); final Configuration config = getResources().getConfiguration(); if (config.orientation == Configuration.ORIENTATION_PORTRAIT) { holder.iconView.setAlpha(0f); holder.iconView.setTranslationX(translation); } else { holder.iconView.setAlpha(0f); holder.iconView.setTranslationY(translation); } if (!mWaitingForWindowAnimation) { animateInIconOfFirstTask(); } } } holder.taskDescription = td; holder.position = index; RecentsScrollView scrollView = (RecentsScrollView) mRecentsContainer; final View animView = scrollView.getChildContentView(convertView); animView.setAlpha(1f); animView.setTranslationY(0f); return convertView; }
private void runEnterAnimation(View view, int position) { if (!animateItems || position >= ANIMATED_ITEMS_COUNT - 1) { return; } if (position > lastAnimatedPosition) { lastAnimatedPosition = position; view.setTranslationY(Utils.getScreenHeight(context)); view.animate() .translationY(0) .setInterpolator(new DecelerateInterpolator(3.f)) .setDuration(700) .start(); } }
public void hideSearchBar(boolean animated) { boolean needToCancelOngoingAnimation = mQSBSearchBarAnim.isRunning() && !animated; if (mIsSearchBarHidden && !needToCancelOngoingAnimation) return; if (animated) { prepareStartAnimation(mQSBSearchBar); mQSBSearchBarAnim.start(); } else { mQSBSearchBarAnim.cancel(); if (mEnableDropDownDropTargets) { mQSBSearchBar.setTranslationY(-mBarHeight); } else { mQSBSearchBar.setAlpha(0f); } } mIsSearchBarHidden = true; }
/* * Shows and hides the search bar. */ public void showSearchBar(boolean animated) { boolean needToCancelOngoingAnimation = mQSBSearchBarAnim.isRunning() && !animated; if (!mIsSearchBarHidden && !needToCancelOngoingAnimation) return; if (animated) { prepareStartAnimation(mQSBSearchBar); mQSBSearchBarAnim.reverse(); } else { mQSBSearchBarAnim.cancel(); if (mEnableDropDownDropTargets) { mQSBSearchBar.setTranslationY(0); } else { mQSBSearchBar.setAlpha(1f); } } mIsSearchBarHidden = false; }
private void interpolate(View view1, View view2, float interpolation) { getOnScreenRect(mRect1, view1); getOnScreenRect(mRect2, view2); float scaleX = 1.0F + interpolation * (mRect2.width() / mRect1.width() - 1.0F); float scaleY = 1.0F + interpolation * (mRect2.height() / mRect1.height() - 1.0F); float translationX = 0.5F * (interpolation * (mRect2.left + mRect2.right - mRect1.left - mRect1.right)); float translationY = 0.5F * (interpolation * (mRect2.top + mRect2.bottom - mRect1.top - mRect1.bottom)); view1.setTranslationX(translationX); view1.setTranslationY(translationY - mHeader.getTranslationY()); view1.setScaleX(scaleX); view1.setScaleY(scaleY); }
private void showAnim() { int y = getIntent().getIntExtra("y", 0); int[] loc = new int[2]; layout_task.getLocationOnScreen(loc); L.d("y:" + y + "," + loc[1]); layout_task.setVisibility(View.VISIBLE); layout_task.setTranslationY(y - loc[1]); layout_task.animate().translationY(0).setDuration(400).start(); iv_sort.animate().alpha(0).setDuration(400).start(); iv_search.animate().alpha(0).setDuration(400).start(); iv_home_bg.animate().alpha(1).setDuration(400).start(); title_bg.animate().alpha(0).setDuration(400).start(); ll_bottom.animate().alpha(1).setDuration(400).start(); materialMenu.animateState(MaterialMenuDrawable.IconState.ARROW); String path = task.getAudioUrl(); if (path != null) { ll_audio.animate().alpha(1).setDuration(300).start(); } }
private Animator createShowItemAnimator(View item) { float dx = centerItem.getX() - item.getX(); float dy = centerItem.getY() - item.getY(); item.setScaleX(0f); item.setScaleY(0f); item.setTranslationX(dx); item.setTranslationY(dy); Animator anim = ObjectAnimator.ofPropertyValuesHolder( item, AnimatorUtils.scaleX(0f, 1f), AnimatorUtils.scaleY(0f, 1f), AnimatorUtils.translationX(dx, 0f), AnimatorUtils.translationY(dy, 0f)); anim.setInterpolator(new DecelerateInterpolator()); anim.setDuration(50); return anim; }
@Override protected void onPostExecute(Void v) { mPager.setAdapter(mPagerAdapter); mPagerAdapter.notifyDataSetChanged(); mPager.setCurrentItem(sFavoriteIndex); if (PrefHelper.subtitleEnabled() && MainActivity.sCurrentFragment == R.id.nav_favorites) { mActionBar.setSubtitle(String.valueOf(sFavorites[sFavoriteIndex])); } Toolbar toolbar = ((MainActivity) getActivity()).toolbar; if (toolbar.getAlpha() == 0) { toolbar.setTranslationY(-300); toolbar.animate().setDuration(300).translationY(0).alpha(1); View view; for (int i = 0; i < toolbar.getChildCount(); i++) { view = toolbar.getChildAt(i); view.setTranslationY(-300); view.animate().setStartDelay(50 * (i + 1)).setDuration(70 * (i + 1)).translationY(0); } } }