@TargetApi(Build.VERSION_CODES.LOLLIPOP)
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_movie);
    ButterKnife.bind(this);

    if (toolbar != null) {
      ViewCompat.setElevation(toolbar, 8);
      toolbar.setNavigationOnClickListener(view -> finish());

      ActionBar ab = getSupportActionBar();
      if (ab != null) {
        ab.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);
        ab.setDisplayHomeAsUpEnabled(true);
        ab.setDisplayShowHomeEnabled(true);
      }
    }
    Movie movie = getIntent().getParcelableExtra(EXTRA_MOVIE);

    ViewCompat.setTransitionName(movieDetailsContainer, TRANSITION_SHARED_ELEMENT);
    if (savedInstanceState == null) {
      MovieFragment fragment = MovieFragment.newInstance(movie);
      getSupportFragmentManager()
          .beginTransaction()
          .replace(R.id.movie_details_container, fragment, MOVIE_FRAGMENT_TAG)
          .commit();
    }
  }
  public void setError(@Nullable CharSequence error) {
    if (!isErrorEnabled() && TextUtils.isEmpty(error)) {
      return;
    }

    if (!TextUtils.isEmpty(error)) {
      ViewCompat.setAlpha(this.error, 0f);
      setErrorEnabled(true);
      this.error.setText(error);

      ViewCompat.animate(this.error)
          .alpha(1f)
          .setDuration(200)
          .setInterpolator(ScopeStealing.INTERPOLATOR)
          .start();
    } else {
      if (isErrorEnabled()) {
        ViewCompat.animate(this.error)
            .alpha(1f)
            .setDuration(200)
            .setInterpolator(ScopeStealing.INTERPOLATOR)
            .setListener(
                new ViewPropertyAnimatorListenerAdapter() {
                  @Override
                  public void onAnimationEnd(View view) {
                    setErrorEnabled(false);
                  }
                })
            .start();
      }
    }
  }
 private void animateChangeImpl(DefaultItemAnimator.ChangeInfo paramChangeInfo)
 {
   View localView = null;
   Object localObject = oldHolder;
   if (localObject == null) {}
   for (localObject = null;; localObject = itemView)
   {
     RecyclerView.ViewHolder localViewHolder = newHolder;
     if (localViewHolder != null) {
       localView = itemView;
     }
     if (localObject != null)
     {
       localObject = ViewCompat.animate((View)localObject).setDuration(getChangeDuration());
       mChangeAnimations.add(oldHolder);
       ((ViewPropertyAnimatorCompat)localObject).translationX(toX - fromX);
       ((ViewPropertyAnimatorCompat)localObject).translationY(toY - fromY);
       ((ViewPropertyAnimatorCompat)localObject).alpha(0.0F).setListener(new DefaultItemAnimator.7(this, paramChangeInfo, (ViewPropertyAnimatorCompat)localObject)).start();
     }
     if (localView != null)
     {
       localObject = ViewCompat.animate(localView);
       mChangeAnimations.add(newHolder);
       ((ViewPropertyAnimatorCompat)localObject).translationX(0.0F).translationY(0.0F).setDuration(getChangeDuration()).alpha(1.0F).setListener(new DefaultItemAnimator.8(this, paramChangeInfo, (ViewPropertyAnimatorCompat)localObject, localView)).start();
     }
     return;
   }
 }
  private void updateSwapTargetTranslation(
      RecyclerView.ViewHolder draggingItem,
      RecyclerView.ViewHolder swapTargetItem,
      float translationPhase) {
    final View swapItemView = swapTargetItem.itemView;

    final int pos1 = draggingItem.getLayoutPosition();
    final int pos2 = swapTargetItem.getLayoutPosition();

    final Rect m1 = mDraggingItemMargins;
    final Rect d1 = mDraggingItemDecorationOffsets;
    final int h1 = mDraggingItemHeight + m1.top + m1.bottom + d1.top + d1.bottom;

    if (mSwapTargetTranslationInterpolator != null) {
      translationPhase = mSwapTargetTranslationInterpolator.getInterpolation(translationPhase);
    }

    if (pos1 > pos2) {
      // dragging item moving to upward
      ViewCompat.setTranslationY(swapItemView, translationPhase * h1);
    } else {
      // dragging item moving to downward
      ViewCompat.setTranslationY(swapItemView, (translationPhase - 1.0f) * h1);
    }
  }
  public CircleImageViewSupport(Context context, int color, final float radius) {
    super(context);
    final float density = getContext().getResources().getDisplayMetrics().density;
    final int diameter = (int) (radius * density * 2);
    final int shadowYOffset = (int) (density * Y_OFFSET);
    final int shadowXOffset = (int) (density * X_OFFSET);

    mShadowRadius = (int) (density * SHADOW_RADIUS);

    ShapeDrawable circle;
    if (elevationSupported()) {
      circle = new ShapeDrawable(new OvalShape());
      ViewCompat.setElevation(this, SHADOW_ELEVATION * density);
    } else {
      OvalShape oval = new OvalShadow(mShadowRadius, diameter);
      circle = new ShapeDrawable(oval);
      ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, circle.getPaint());
      circle
          .getPaint()
          .setShadowLayer(mShadowRadius, shadowXOffset, shadowYOffset, KEY_SHADOW_COLOR);
      final int padding = mShadowRadius;
      // set padding so the inner image sits correctly within the shadow.
      setPadding(padding, padding, padding, padding);
    }
    circle.getPaint().setColor(color);
    setBackgroundDrawable(circle);
  }
    @Override
    public void onAnimationEnd(View view) {
      mAnimator.setListener(null);
      // [WORKAROUND]
      // Issue 189686: NPE can be occurred when using the ViewPropertyAnimatorCompat
      // https://code.google.com/p/android/issues/detail?id=189686
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        InternalHelperKK.clearViewPropertyAnimatorUpdateListener(view);
      } else {
        mAnimator.setUpdateListener(null);
      }

      ViewCompat.setTranslationX(view, mToX);
      ViewCompat.setTranslationY(view, mToY);

      mActive.remove(mViewHolder);

      // [WORKAROUND]
      // issue #152 - bug:Samsung S3 4.1.1(Genymotion) with swipe left
      ViewParent itemParentView = mViewHolder.itemView.getParent();
      if (itemParentView != null) {
        ViewCompat.postInvalidateOnAnimation((View) itemParentView);
      }

      if (mSwipeFinish != null) {
        mSwipeFinish.resultAction.slideAnimationEnd();
      }

      // clean up
      mActive = null;
      mAnimator = null;
      mViewHolder = null;
      mAdapter = null;
    }
 @Override
 protected void onRemoveCanceled(ViewHolder holder) {
   ViewCompat.setRotationY(holder.itemView, 0);
   ViewCompat.setTranslationX(holder.itemView, 0);
   ViewCompat.setScaleX(holder.itemView, 1);
   ViewCompat.setScaleY(holder.itemView, 1);
 }
Beispiel #8
0
 /*
  * Enabled aggressive block sorting
  */
 private void dimChildView(View object, float f, int n) {
     LayoutParams layoutParams = (LayoutParams)object.getLayoutParams();
     if (f > 0.0f && n != 0) {
         int n2 = (int)((float)((-16777216 & n) >>> 24) * f);
         if (layoutParams.dimPaint == null) {
             layoutParams.dimPaint = new Paint();
         }
         layoutParams.dimPaint.setColorFilter(new PorterDuffColorFilter(n2 << 24 | 16777215 & n, PorterDuff.Mode.SRC_OVER));
         if (ViewCompat.getLayerType((View)object) != 2) {
             ViewCompat.setLayerType((View)object, 2, layoutParams.dimPaint);
         }
         this.invalidateChildRegion((View)object);
         return;
     } else {
         if (ViewCompat.getLayerType((View)object) == 0) return;
         {
             if (layoutParams.dimPaint != null) {
                 layoutParams.dimPaint.setColorFilter(null);
             }
             object = new DisableLayerRunnable((View)object);
             this.mPostedRunnables.add((DisableLayerRunnable)object);
             ViewCompat.postOnAnimation(this, (Runnable)object);
             return;
         }
     }
 }
Beispiel #9
0
 void getSize(SizeReadyCallback cb) {
   int currentWidth = getViewWidthOrParam();
   int currentHeight = getViewHeightOrParam();
   if (isSizeValid(currentWidth) && isSizeValid(currentHeight)) {
     int paddingAdjustedWidth =
         currentWidth == WindowManager.LayoutParams.WRAP_CONTENT
             ? currentWidth
             : currentWidth - ViewCompat.getPaddingStart(view) - ViewCompat.getPaddingEnd(view);
     int paddingAdjustedHeight =
         currentHeight == LayoutParams.WRAP_CONTENT
             ? currentHeight
             : currentHeight - view.getPaddingTop() - view.getPaddingBottom();
     cb.onSizeReady(paddingAdjustedWidth, paddingAdjustedHeight);
   } else {
     // We want to notify callbacks in the order they were added and we only expect one or two
     // callbacks to
     // be added a time, so a List is a reasonable choice.
     if (!cbs.contains(cb)) {
       cbs.add(cb);
     }
     if (layoutListener == null) {
       final ViewTreeObserver observer = view.getViewTreeObserver();
       layoutListener = new SizeDeterminerLayoutListener(this);
       observer.addOnPreDrawListener(layoutListener);
     }
   }
 }
  @Override
  public void transformPage(View view, float position) {
    int pageWidth = view.getWidth();

    if (position < -1) { // [-Infinity,-1)
      // This page is way off-screen to the left.
      ViewCompat.setAlpha(view, 0);

    } else if (position <= 0) { // [-1,0]
      // Use the default slide transition when moving to the left page
      ViewCompat.setAlpha(view, 1);
      ViewCompat.setTranslationX(view, 0);
      ViewCompat.setScaleX(view, 1);
      ViewCompat.setScaleY(view, 1);

    } else if (position <= 1) { // (0,1]
      // Fade the page out.
      ViewCompat.setAlpha(view, 1 - position);

      // Counteract the default slide transition
      ViewCompat.setTranslationX(view, pageWidth * -position);

      // Scale the page down (between MIN_SCALE and 1)
      float scaleFactor = MIN_SCALE + (1 - MIN_SCALE) * (1 - Math.abs(position));
      ViewCompat.setScaleX(view, scaleFactor);
      ViewCompat.setScaleY(view, scaleFactor);

    } else { // (1,+Infinity]
      // This page is way off-screen to the right.
      ViewCompat.setAlpha(view, 0);
    }
  }
  @Override
  public void animateToVisibility(int visibility) {
    if (visibility == View.GONE) {
      ViewCompat.animate(mToolbar)
          .alpha(0)
          .setListener(
              new ViewPropertyAnimatorListenerAdapter() {
                private boolean mCanceled = false;

                @Override
                public void onAnimationEnd(View view) {
                  if (!mCanceled) {
                    mToolbar.setVisibility(View.GONE);
                  }
                }

                @Override
                public void onAnimationCancel(View view) {
                  mCanceled = true;
                }
              });
    } else if (visibility == View.VISIBLE) {
      ViewCompat.animate(mToolbar)
          .alpha(1)
          .setListener(
              new ViewPropertyAnimatorListenerAdapter() {
                @Override
                public void onAnimationStart(View view) {
                  mToolbar.setVisibility(View.VISIBLE);
                }
              });
    }
  }
  @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);
  }
  @Override
  protected Rect getDividerBound(int position, RecyclerView parent, View child) {
    Rect bounds = new Rect(0, 0, 0, 0);
    int transitionX = (int) ViewCompat.getTranslationX(child);
    int transitionY = (int) ViewCompat.getTranslationY(child);
    RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
    bounds.top =
        parent.getPaddingTop() + mMarginProvider.dividerTopMargin(position, parent) + transitionY;
    bounds.bottom =
        parent.getHeight()
            - parent.getPaddingBottom()
            - mMarginProvider.dividerBottomMargin(position, parent)
            + transitionY;

    int dividerSize = getDividerSize(position, parent);
    if (mDividerType == DividerType.DRAWABLE) {
      bounds.left = child.getRight() + params.leftMargin + transitionX;
      bounds.right = bounds.left + dividerSize;
    } else {
      bounds.left = child.getRight() + params.leftMargin + dividerSize / 2 + transitionX;
      bounds.right = bounds.left;
    }

    return bounds;
  }
 private void setAnimationProgress(float progress) {
   if (isAlphaUsedForScale()) {
     setColorViewAlpha((int) (progress * 255.0F));
   } else {
     ViewCompat.setScaleX(this.mCircleView, progress);
     ViewCompat.setScaleY(this.mCircleView, progress);
   }
 }
 @Override
 protected void setViewPageData() {
   super.setViewPageData();
   viewPager.setAdapter(new MyDetailPagerAdapter(this, getSupportFragmentManager()));
   tabs.setViewPager(viewPager);
   ViewCompat.setElevation(tabs, 0);
   ViewCompat.setElevation(findViewById(R.id.appbarLayout), 0);
 }
 @Override
 protected void preAnimateAddImpl(RecyclerView.ViewHolder holder) {
   // @TODO https://code.google.com/p/android/issues/detail?id=80863
   //        ViewCompat.setPivotY(holder.itemView, holder.itemView.getHeight());
   holder.itemView.setPivotY(holder.itemView.getHeight());
   ViewCompat.setScaleX(holder.itemView, 0);
   ViewCompat.setScaleY(holder.itemView, 0);
 }
  public void invalidateDraggingItem() {
    if (mDraggingItemViewHolder != null) {
      ViewCompat.setTranslationX(mDraggingItemViewHolder.itemView, 0);
      ViewCompat.setTranslationY(mDraggingItemViewHolder.itemView, 0);
      mDraggingItemViewHolder.itemView.setVisibility(View.VISIBLE);
    }

    mDraggingItemViewHolder = null;
  }
    @Override
    public void onAnimationUpdate(View view) {
      float translation =
          mHorizontal ? ViewCompat.getTranslationX(view) : ViewCompat.getTranslationY(view);
      float amount = translation * mInvSize;

      mAdapter.onUpdateSlideAmount(
          mViewHolder, mViewHolder.getLayoutPosition(), amount, true, mHorizontal, false);
    }
 @Override
 public boolean animateChange(
     RecyclerView.ViewHolder oldHolder,
     RecyclerView.ViewHolder newHolder,
     int fromX,
     int fromY,
     int toX,
     int toY) {
   if (oldHolder == newHolder) {
     // Don't know how to run change animations when the same view holder is re-used.
     // run a move animation to handle position changes.
     return animateMove(oldHolder, fromX, fromY, toX, toY);
   }
   final float prevTranslationX = ViewCompat.getTranslationX(oldHolder.itemView);
   final float prevTranslationY = ViewCompat.getTranslationY(oldHolder.itemView);
   final float prevAlpha = ViewCompat.getAlpha(oldHolder.itemView);
   resetAnimation(oldHolder);
   int deltaX = (int) (toX - fromX - prevTranslationX);
   int deltaY = (int) (toY - fromY - prevTranslationY);
   // recover prev translation state after ending animation
   ViewCompat.setTranslationX(oldHolder.itemView, prevTranslationX);
   ViewCompat.setTranslationY(oldHolder.itemView, prevTranslationY);
   ViewCompat.setAlpha(oldHolder.itemView, prevAlpha);
   if (newHolder != null) {
     // carry over translation values
     resetAnimation(newHolder);
     ViewCompat.setTranslationX(newHolder.itemView, -deltaX);
     ViewCompat.setTranslationY(newHolder.itemView, -deltaY);
     ViewCompat.setAlpha(newHolder.itemView, 0);
   }
   mPendingChanges.add(new ChangeInfo(oldHolder, newHolder, fromX, fromY, toX, toY));
   return true;
 }
Beispiel #20
0
 public SlidingPaneLayout(Context context, AttributeSet attributeSet, int n) {
     super(context, attributeSet, n);
     float f = context.getResources().getDisplayMetrics().density;
     this.mOverhangSize = (int)(32.0f * f + 0.5f);
     ViewConfiguration.get(context);
     this.setWillNotDraw(false);
     ViewCompat.setAccessibilityDelegate(this, new AccessibilityDelegate());
     ViewCompat.setImportantForAccessibility(this, 1);
     this.mDragHelper = ViewDragHelper.create(this, 0.5f, new DragHelperCallback());
     this.mDragHelper.setMinVelocity(400.0f * f);
 }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.conversations);

    gcm = Gcm.getInstance(getApplicationContext());
    billing = Billing.getInstance(getApplicationContext());
    database = Database.getInstance(getApplicationContext());
    preferences = Preferences.getInstance(getApplicationContext());

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    ViewCompat.setElevation(toolbar, getResources().getDimension(R.dimen.toolbar_elevation));
    setSupportActionBar(toolbar);

    LinearLayoutManager layoutManager = new LinearLayoutManager(this);
    layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    adapter = new ConversationsRecyclerViewAdapter(this, layoutManager);
    recyclerView = (RecyclerView) findViewById(R.id.list);
    recyclerView.setHasFixedSize(true);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setAdapter(adapter);

    actionMode = null;
    actionModeEnabled = false;

    SwipeRefreshLayout swipeRefreshLayout =
        (SwipeRefreshLayout) findViewById(R.id.swipe_refresh_layout);
    swipeRefreshLayout.setOnRefreshListener(
        new SwipeRefreshLayout.OnRefreshListener() {
          @Override
          public void onRefresh() {
            preFullUpdate();
          }
        });
    swipeRefreshLayout.setColorSchemeResources(R.color.accent);

    ImageButton button = (ImageButton) findViewById(R.id.new_button);
    ViewCompat.setElevation(button, getResources().getDimension(R.dimen.fab_elevation));
    button.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            if (!preferences.getEmail().equals("")
                && !preferences.getPassword().equals("")
                && !preferences.getDid().equals("")) {
              Intent intent = new Intent(conversationsActivity, NewConversationActivity.class);
              startActivity(intent);
            }
          }
        });

    SynchronizationIntervalReceiver.setupSynchronizationInterval(getApplicationContext());
  }
  @Override
  public boolean onCheckCanStartDrag(MyViewHolder holder, int position, int x, int y) {
    // x, y --- relative from the itemView's top-left
    final View containerView = holder.mContainer;
    final View dragHandleView = holder.mDragHandle;

    final int offsetX =
        containerView.getLeft() + (int) (ViewCompat.getTranslationX(containerView) + 0.5f);
    final int offsetY =
        containerView.getTop() + (int) (ViewCompat.getTranslationY(containerView) + 0.5f);

    return ViewUtils.hitTest(dragHandleView, x - offsetX, y - offsetY);
  }
  private void updateOffsets() {
    ViewCompat.offsetTopAndBottom(mView, mOffsetTop - (mView.getTop() - mLayoutTop));
    ViewCompat.offsetLeftAndRight(mView, mOffsetLeft - (mView.getLeft() - mLayoutLeft));

    // Manually invalidate the view and parent to make sure we get drawn pre-M
    if (Build.VERSION.SDK_INT < 23) {
      tickleInvalidationFlag(mView);
      final ViewParent vp = mView.getParent();
      if (vp instanceof View) {
        tickleInvalidationFlag((View) vp);
      }
    }
  }
  public static void setStatusBarColor(Activity activity, int statusColor) {
    Window window = activity.getWindow();
    ViewGroup mContentView = (ViewGroup) activity.findViewById(Window.ID_ANDROID_CONTENT);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
      // First translucent status bar.
      window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        // After LOLLIPOP not translucent status bar
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        // Then call setStatusBarColor.
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(statusColor);
        // set child View not fill the system window
        View mChildView = mContentView.getChildAt(0);
        if (mChildView != null) {
          ViewCompat.setFitsSystemWindows(mChildView, true);
        }
      } else {
        int statusBarHeight = getStatusBarHeight(activity);

        View mChildView = mContentView.getChildAt(0);
        if (mChildView != null) {
          FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mChildView.getLayoutParams();
          // if margin top has already set, just skip.
          if (lp != null && lp.topMargin < statusBarHeight && lp.height != statusBarHeight) {
            // do not use fitsSystemWindows
            ViewCompat.setFitsSystemWindows(mChildView, false);
            // add margin to content
            lp.topMargin += statusBarHeight;
            mChildView.setLayoutParams(lp);
          }
        }

        // Before LOLLIPOP create a fake status bar View.
        View statusBarView = mContentView.getChildAt(0);
        if (statusBarView != null
            && statusBarView.getLayoutParams() != null
            && statusBarView.getLayoutParams().height == statusBarHeight) {
          // if fake status bar view exist, we can setBackgroundColor and return.
          statusBarView.setBackgroundColor(statusColor);
          return;
        }
        statusBarView = new View(activity);
        ViewGroup.LayoutParams lp =
            new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, statusBarHeight);
        statusBarView.setBackgroundColor(statusColor);
        mContentView.addView(statusBarView, 0, lp);
      }
    }
  }
Beispiel #25
0
  public MonthView(Context context, AttributeSet attr, DatePickerController controller) {
    super(context, attr);
    mController = controller;
    Resources res = context.getResources();

    mDayLabelCalendar = Calendar.getInstance();
    mCalendar = Calendar.getInstance();

    mDayOfWeekTypeface = res.getString(R.string.mdtp_day_of_week_label_typeface);
    mMonthTitleTypeface = res.getString(R.string.mdtp_sans_serif);

    boolean darkTheme = mController != null && mController.isThemeDark();
    if (darkTheme) {
      mDayTextColor = res.getColor(R.color.mdtp_date_picker_text_normal_dark_theme);
      mMonthDayTextColor = res.getColor(R.color.mdtp_date_picker_month_day_dark_theme);
      mDisabledDayTextColor = res.getColor(R.color.mdtp_date_picker_text_disabled_dark_theme);
      mHighlightedDayTextColor = res.getColor(R.color.mdtp_date_picker_text_highlighted_dark_theme);
    } else {
      mDayTextColor = res.getColor(R.color.mdtp_date_picker_text_normal);
      mMonthDayTextColor = res.getColor(R.color.mdtp_date_picker_month_day);
      mDisabledDayTextColor = res.getColor(R.color.mdtp_date_picker_text_disabled);
      mHighlightedDayTextColor = res.getColor(R.color.mdtp_date_picker_text_highlighted);
    }
    mSelectedDayTextColor = res.getColor(R.color.mdtp_white);
    mTodayNumberColor = mController.getAccentColor();
    mMonthTitleColor = res.getColor(R.color.mdtp_white);

    mStringBuilder = new StringBuilder(50);
    mFormatter = new Formatter(mStringBuilder, Locale.getDefault());

    MINI_DAY_NUMBER_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.mdtp_day_number_size);
    MONTH_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.mdtp_month_label_size);
    MONTH_DAY_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.mdtp_month_day_label_text_size);
    MONTH_HEADER_SIZE = res.getDimensionPixelOffset(R.dimen.mdtp_month_list_item_header_height);
    DAY_SELECTED_CIRCLE_SIZE =
        res.getDimensionPixelSize(R.dimen.mdtp_day_number_select_circle_radius);

    mRowHeight =
        (res.getDimensionPixelOffset(R.dimen.mdtp_date_picker_view_animator_height)
                - getMonthHeaderSize())
            / MAX_NUM_ROWS;

    // Set up accessibility components.
    mTouchHelper = getMonthViewTouchHelper();
    ViewCompat.setAccessibilityDelegate(this, mTouchHelper);
    ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    mLockAccessibilityDelegate = true;

    // Sets up any standard paints that will be used
    initView();
  }
 /**
  * @return Whether it is possible for the child view of this layout to scroll up. Override this if
  *     the child view is a custom view.
  */
 public boolean canChildScrollUp() {
   if (android.os.Build.VERSION.SDK_INT < 14) {
     if (mTarget instanceof AbsListView) {
       final AbsListView absListView = (AbsListView) mTarget;
       return absListView.getChildCount() > 0
           && (absListView.getFirstVisiblePosition() > 0
               || absListView.getChildAt(0).getTop() < absListView.getPaddingTop());
     } else {
       return ViewCompat.canScrollVertically(mTarget, -1) || mTarget.getScrollY() > 0;
     }
   } else {
     return ViewCompat.canScrollVertically(mTarget, -1);
   }
 }
  private static void slideInternal(
      final RecyclerView.ViewHolder holder,
      boolean horizontal,
      int translationX,
      int translationY) {
    if (!(holder instanceof SwipeableItemViewHolder)) {
      return;
    }

    final View containerView = ((SwipeableItemViewHolder) holder).getSwipeableContainerView();
    ViewCompat.animate(containerView).cancel();
    ViewCompat.setTranslationX(containerView, translationX);
    ViewCompat.setTranslationY(containerView, translationY);
  }
Beispiel #28
0
 @Override
 public void onScroll(int l, int t, int oldl, int oldt) {
   int height = mHeader.getMeasuredHeight() - mToolbar.getMeasuredHeight();
   Drawable drawable = mToolbarContainer.getBackground();
   int alpha = 255 * (Math.min(Math.max(t, 0), height)) / height;
   drawable.setAlpha(alpha);
   if (alpha >= 255) {
     ViewCompat.setElevation(mToolbarContainer, mElevation);
     ViewCompat.setElevation(mHeader, 0);
   } else {
     ViewCompat.setElevation(mToolbarContainer, 0);
     ViewCompat.setElevation(mHeader, mElevation);
   }
 }
  public boolean canChildScrollUp() {
    if (Build.VERSION.SDK_INT < 14) {
      if ((this.mTarget instanceof AbsListView)) {
        AbsListView absListView = (AbsListView) this.mTarget;
        return (absListView.getChildCount() > 0)
            && ((absListView.getFirstVisiblePosition() > 0)
                || (absListView.getChildAt(0).getTop() < absListView.getPaddingTop()));
      }

      return (ViewCompat.canScrollVertically(this.mTarget, -1)) || (this.mTarget.getScrollY() > 0);
    }

    return ViewCompat.canScrollVertically(this.mTarget, -1);
  }
  private void animateAddImpl(final ViewHolder holder) {
    final View view = holder.itemView;
    final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view);
    mAddAnimations.add(holder);
    float startX, startY;

    int position = (int) view.getTag();

    if (position % 2 == 0) {
      startY = -100;
      startX = -width;
    } else {
      startY = 100;
      startX = width;
    }
    Log.d("test", String.valueOf(holder.getLayoutPosition()));
    ViewCompat.setTranslationX(view, startX);
    // 应该是相对偏移
    ViewCompat.setTranslationY(view, startY);
    ViewCompat.setAlpha(view, 0);
    animation.setInterpolator(new OvershootInterpolator());
    animation
        .alpha(1)
        .translationX(0)
        .translationY(0)
        .setDuration(getAddDuration())
        .setListener(
            new VpaListenerAdapter() {
              @Override
              public void onAnimationStart(View view) {
                dispatchAddStarting(holder);
              }

              @Override
              public void onAnimationCancel(View view) {
                ViewCompat.setAlpha(view, 1);
              }

              @Override
              public void onAnimationEnd(View view) {
                animation.setListener(null);
                dispatchAddFinished(holder);
                mAddAnimations.remove(holder);
                dispatchFinishedWhenDone();
                // 使用这个来复原
                ViewCompat.setTranslationY(view, 0);
              }
            })
        .start();
  }