Esempio n. 1
0
  private void init(Context context, AttributeSet attributeSet) {
    TypedArray attr = getTypedArray(context, attributeSet, R.styleable.MaterialMenuView);

    try {
      int color = attr.getColor(R.styleable.MaterialMenuView_mm_color, DEFAULT_COLOR);
      int scale = attr.getInteger(R.styleable.MaterialMenuView_mm_scale, DEFAULT_SCALE);
      int transformDuration =
          attr.getInteger(
              R.styleable.MaterialMenuView_mm_transformDuration, DEFAULT_TRANSFORM_DURATION);
      int pressedDuration =
          attr.getInteger(
              R.styleable.MaterialMenuView_mm_pressedDuration, DEFAULT_PRESSED_DURATION);
      MaterialMenuDrawable.Stroke stroke =
          MaterialMenuDrawable.Stroke.valueOf(
              attr.getInteger(R.styleable.MaterialMenuView_mm_strokeWidth, 0));
      boolean rtlEnabled = attr.getBoolean(R.styleable.MaterialMenuView_mm_rtlEnabled, false);

      drawable =
          new MaterialMenuDrawable(
              context, color, stroke, scale, transformDuration, pressedDuration);
      drawable.setRTLEnabled(rtlEnabled);
    } finally {
      attr.recycle();
    }

    drawable.setCallback(this);
  }
Esempio n. 2
0
 private void adjustDrawablePadding() {
   if (drawable != null) {
     drawable.setBounds(
         0,
         0,
         drawable.getIntrinsicWidth() + getPaddingLeft() + getPaddingRight(),
         drawable.getIntrinsicHeight() + getPaddingTop() + getPaddingBottom());
   }
 }
Esempio n. 3
0
 @Override
 public void draw(Canvas canvas) {
   super.draw(canvas);
   if (getPaddingLeft() != 0 || getPaddingTop() != 0) {
     int saveCount = canvas.getSaveCount();
     canvas.save();
     canvas.translate(getPaddingLeft(), getPaddingTop());
     drawable.draw(canvas);
     canvas.restoreToCount(saveCount);
   } else {
     drawable.draw(canvas);
   }
 }
Esempio n. 4
0
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int paddingX = getPaddingLeft() + getPaddingRight();
    int paddingY = getPaddingTop() + getPaddingBottom();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
      widthMeasureSpec =
          MeasureSpec.makeMeasureSpec(drawable.getIntrinsicWidth() + paddingX, MeasureSpec.EXACTLY);
      heightMeasureSpec =
          MeasureSpec.makeMeasureSpec(
              drawable.getIntrinsicHeight() + paddingY, MeasureSpec.EXACTLY);
      setMeasuredDimension(widthMeasureSpec, heightMeasureSpec);
    } else {
      setMeasuredDimension(
          drawable.getIntrinsicWidth() + paddingX, drawable.getIntrinsicHeight() + paddingY);
    }
  }
Esempio n. 5
0
 @Override
 public void setTransformationOffset(
     MaterialMenuDrawable.AnimationState animationState, float value) {
   currentState = drawable.setTransformationOffset(animationState, value);
 }
Esempio n. 6
0
 @Override
 public void setInterpolator(Interpolator interpolator) {
   drawable.setInterpolator(interpolator);
 }
Esempio n. 7
0
 @Override
 public void setRTLEnabled(boolean rtlEnabled) {
   drawable.setRTLEnabled(rtlEnabled);
 }
Esempio n. 8
0
 @Override
 public void setTransformationDuration(int duration) {
   drawable.setTransformationDuration(duration);
 }
Esempio n. 9
0
 @Override
 public void setPressedDuration(int duration) {
   drawable.setPressedDuration(duration);
 }
Esempio n. 10
0
 @Override
 public void setColor(int color) {
   drawable.setColor(color);
 }
Esempio n. 11
0
 @Override
 public void animatePressedState(MaterialMenuDrawable.IconState state) {
   currentState = state;
   drawable.animateIconState(state, true);
 }
Esempio n. 12
0
 @Override
 public void animateState(MaterialMenuDrawable.IconState state) {
   currentState = state;
   drawable.animateIconState(state, false);
 }
Esempio n. 13
0
 @Override
 public MaterialMenuDrawable.IconState getState() {
   return drawable.getIconState();
 }
Esempio n. 14
0
 @Override
 public void setState(MaterialMenuDrawable.IconState state) {
   currentState = state;
   drawable.setIconState(state);
 }