/**
  * Enable a hardware layer for the view.
  *
  * @param v
  * @param drawWithLayer
  */
 private void setDrawWithLayer(View v, boolean drawWithLayer) {
   if (v.getLayerType() != LAYER_TYPE_HARDWARE && drawWithLayer) {
     v.setLayerType(LAYER_TYPE_HARDWARE, null);
   } else if (v.getLayerType() != LAYER_TYPE_NONE && !drawWithLayer) {
     v.setLayerType(LAYER_TYPE_NONE, null);
   }
 }
 @TargetApi(Build.VERSION_CODES.HONEYCOMB)
 private void disableHardwareLayer() {
   if (!API_11) return;
   View v;
   for (int i = 0; i < getChildCount(); i++) {
     v = getChildAt(i);
     if (v.getLayerType() != View.LAYER_TYPE_NONE) v.setLayerType(View.LAYER_TYPE_NONE, null);
   }
 }
Exemple #3
0
  /**
   * The View associated with this ViewPropertyAnimator will have its {@link View#setLayerType(int,
   * android.graphics.Paint) layer type} set to {@link View#LAYER_TYPE_HARDWARE} for the duration of
   * the next animation. As stated in the documentation for {@link View#LAYER_TYPE_HARDWARE}, the
   * actual type of layer used internally depends on the runtime situation of the view. If the
   * activity and this view are hardware-accelerated, then the layer will be accelerated as well. If
   * the activity or the view is not accelerated, then the layer will effectively be the same as
   * {@link View#LAYER_TYPE_SOFTWARE}.
   *
   * <p>This state is not persistent, either on the View or on this ViewPropertyAnimator: the layer
   * type of the View will be restored when the animation ends to what it was when this method was
   * called, and this setting on ViewPropertyAnimator is only valid for the next animation. Note
   * that calling this method and then independently setting the layer type of the View (by a direct
   * call to {@link View#setLayerType(int, android.graphics.Paint)}) will result in some
   * inconsistency, including having the layer type restored to its pre-withLayer() value when the
   * animation ends.
   *
   * @see View#setLayerType(int, android.graphics.Paint)
   * @return This object, allowing calls to methods in this class to be chained.
   */
  public ViewPropertyAnimator withLayer() {
    mPendingSetupAction =
        new Runnable() {
          @Override
          public void run() {
            mView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
            if (mView.isAttachedToWindow()) {
              mView.buildLayer();
            }
          }
        };

    /// M: If app call withLayer twice, it should use original layer type instead of current one.
    final int currentLayerType;
    if (mOldLayerType == -1) {
      currentLayerType = mView.getLayerType();
      mOldLayerType = currentLayerType;
    } else {
      currentLayerType = mOldLayerType;
    }

    mPendingCleanupAction =
        new Runnable() {
          @Override
          public void run() {
            mView.setLayerType(currentLayerType, null);
            /// M : reset old layer type
            mOldLayerType = -1;
          }
        };
    if (mAnimatorSetupMap == null) {
      mAnimatorSetupMap = new HashMap<Animator, Runnable>();
    }
    if (mAnimatorCleanupMap == null) {
      mAnimatorCleanupMap = new HashMap<Animator, Runnable>();
    }

    return this;
  }
 @TargetApi(Build.VERSION_CODES.HONEYCOMB)
 private void manageLayer(View v, boolean enableHardware) {
   if (!API_11) return;
   int layerType = enableHardware ? View.LAYER_TYPE_HARDWARE : View.LAYER_TYPE_NONE;
   if (layerType != v.getLayerType()) v.setLayerType(layerType, null);
 }
 public static int getLayerType(View view) {
   return view.getLayerType();
 }
 public static int b(View paramView) {
   return paramView.getLayerType();
 }