void setDayHighlightColor(ColorStateList dayHighlightColor) {
   final int pressedColor =
       dayHighlightColor.getColorForState(
           StateSet.get(StateSet.VIEW_STATE_ENABLED | StateSet.VIEW_STATE_PRESSED), 0);
   mDayHighlightPaint.setColor(pressedColor);
   invalidate();
 }
 void setDaySelectorColor(ColorStateList dayBackgroundColor) {
   final int activatedColor =
       dayBackgroundColor.getColorForState(
           StateSet.get(StateSet.VIEW_STATE_ENABLED | StateSet.VIEW_STATE_ACTIVATED), 0);
   mDaySelectorPaint.setColor(activatedColor);
   invalidate();
 }
 private int keyOfFirstMatchingStateSet(int[] stateSet) {
   int length = mStateSets.size();
   for (int i = 0; i < length; i++) {
     if (StateSet.stateSetMatches(mStateSets.valueAt(i), stateSet)) {
       return mStateSets.keyAt(i);
     }
   }
   return -1;
 }
 private int indexOfStateSet(int[] stateSet) {
   final int[][] stateSets = mStateSets;
   final int N = getChildCount();
   for (int i = 0; i < N; i++) {
     if (StateSet.stateSetMatches(stateSets[i], stateSet)) {
       return i;
     }
   }
   return -1;
 }
예제 #5
0
 @Override
 protected boolean onStateChange(int[] state) {
   boolean active =
       StateSet.stateSetMatches(STATE_SELECTED, state)
           | StateSet.stateSetMatches(STATE_PRESSED, state);
   if (active != mActive) {
     mActive = active;
     //				Log.d("FolderTransitionDrawable", "onStateChange " + StateSet.dump(state) + " " +
     // active);
     if (!active) {
       unscheduleSelf(this);
       if (mAlpha != 255) {
         startTransition(false);
       }
     } else {
       scheduleSelf(this, SystemClock.uptimeMillis() + 500);
     }
     return true;
   }
   return false;
 }
 private int keyOfBestMatchingStateSet(int[] stateSet) {
   int length = mStateSets.size();
   int bestSize = 0;
   int result = -1;
   for (int i = 0; i < length; i++) {
     int[] matchingStateSet = mStateSets.valueAt(i);
     if (StateSet.stateSetMatches(matchingStateSet, stateSet)
         && matchingStateSet.length > bestSize) {
       bestSize = matchingStateSet.length;
       result = mStateSets.keyAt(i);
     }
   }
   return result;
 }
 @DSComment("Private Method")
 @DSBan(DSCat.PRIVATE_METHOD)
 @DSGenerator(
     tool_name = "Doppelganger",
     tool_version = "2.0",
     generated_on = "2013-12-30 12:34:11.141 -0500",
     hash_original_method = "A182AEBDD3B8E6EFB499434DA2A68669",
     hash_generated_method = "D64FD17DD7405A33F3CB0F78E5709DE5")
 private int indexOfStateSet(int[] stateSet) {
   final int[][] stateSets = mStateSets;
   final int N = getChildCount();
   for (int i = 0; i < N; i++) {
     if (StateSet.stateSetMatches(stateSets[i], stateSet)) {
       return i;
     }
   }
   return -1;
 }
  @DSComment("From safe class list")
  @DSSafe(DSCat.SAFE_LIST)
  @DSGenerator(
      tool_name = "Doppelganger",
      tool_version = "2.0",
      generated_on = "2013-12-30 12:34:11.117 -0500",
      hash_original_method = "60A0EEC92FC73D4C3C226304BAFE6ED2",
      hash_generated_method = "881AEE96865DF1F601FB754CA0BA5763")
  @Override
  public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs)
      throws XmlPullParserException, IOException {

    TypedArray a = r.obtainAttributes(attrs, com.android.internal.R.styleable.StateListDrawable);

    super.inflateWithAttributes(
        r, parser, a, com.android.internal.R.styleable.StateListDrawable_visible);

    mStateListState.setVariablePadding(
        a.getBoolean(com.android.internal.R.styleable.StateListDrawable_variablePadding, false));
    mStateListState.setConstantSize(
        a.getBoolean(com.android.internal.R.styleable.StateListDrawable_constantSize, false));
    mStateListState.setEnterFadeDuration(
        a.getInt(com.android.internal.R.styleable.StateListDrawable_enterFadeDuration, 0));
    mStateListState.setExitFadeDuration(
        a.getInt(com.android.internal.R.styleable.StateListDrawable_exitFadeDuration, 0));

    setDither(
        a.getBoolean(com.android.internal.R.styleable.StateListDrawable_dither, DEFAULT_DITHER));

    a.recycle();

    int type;

    final int innerDepth = parser.getDepth() + 1;
    int depth;
    while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
        && ((depth = parser.getDepth()) >= innerDepth || type != XmlPullParser.END_TAG)) {
      if (type != XmlPullParser.START_TAG) {
        continue;
      }

      if (depth > innerDepth || !parser.getName().equals("item")) {
        continue;
      }

      int drawableRes = 0;

      int i;
      int j = 0;
      final int numAttrs = attrs.getAttributeCount();
      int[] states = new int[numAttrs];
      for (i = 0; i < numAttrs; i++) {
        final int stateResId = attrs.getAttributeNameResource(i);
        if (stateResId == 0) break;
        if (stateResId == com.android.internal.R.attr.drawable) {
          drawableRes = attrs.getAttributeResourceValue(i, 0);
        } else {
          states[j++] = attrs.getAttributeBooleanValue(i, false) ? stateResId : -stateResId;
        }
      }
      states = StateSet.trimStateSet(states, j);

      Drawable dr;
      if (drawableRes != 0) {
        dr = r.getDrawable(drawableRes);
      } else {
        while ((type = parser.next()) == XmlPullParser.TEXT) {}
        if (type != XmlPullParser.START_TAG) {
          throw new XmlPullParserException(
              parser.getPositionDescription()
                  + ": <item> tag requires a 'drawable' attribute or "
                  + "child tag defining a drawable");
        }
        dr = Drawable.createFromXmlInner(r, parser, attrs);
      }

      mStateListState.addStateSet(states, dr);
    }

    onStateChange(getState());
  }
  @Override
  public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs)
      throws XmlPullParserException, IOException {

    TypedArray a = r.obtainAttributes(attrs, com.android.internal.R.styleable.StateListDrawable);

    super.inflateWithAttributes(
        r, parser, a, com.android.internal.R.styleable.StateListDrawable_visible);

    mStateListState.setVariablePadding(
        a.getBoolean(com.android.internal.R.styleable.StateListDrawable_variablePadding, false));
    mStateListState.setConstantSize(
        a.getBoolean(com.android.internal.R.styleable.StateListDrawable_constantSize, false));

    setDither(
        a.getBoolean(com.android.internal.R.styleable.StateListDrawable_dither, DEFAULT_DITHER));

    a.recycle();

    int type;

    final int innerDepth = parser.getDepth() + 1;
    int depth;
    while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
        && ((depth = parser.getDepth()) >= innerDepth || type != XmlPullParser.END_TAG)) {
      if (type != XmlPullParser.START_TAG) {
        continue;
      }

      if (depth > innerDepth || !parser.getName().equals("item")) {
        continue;
      }

      int drawableRes = 0;

      int i;
      int j = 0;
      final int numAttrs = attrs.getAttributeCount();
      int[] states = new int[numAttrs];
      for (i = 0; i < numAttrs; i++) {
        final int stateResId = attrs.getAttributeNameResource(i);
        if (stateResId == 0) break;
        if (stateResId == com.android.internal.R.attr.drawable) {
          drawableRes = attrs.getAttributeResourceValue(i, 0);
        } else {
          states[j++] = attrs.getAttributeBooleanValue(i, false) ? stateResId : -stateResId;
        }
      }
      states = StateSet.trimStateSet(states, j);

      Drawable dr;
      if (drawableRes != 0) {
        dr = r.getDrawable(drawableRes);
      } else {
        while ((type = parser.next()) == XmlPullParser.TEXT) {}
        if (type != XmlPullParser.START_TAG) {
          throw new XmlPullParserException(
              parser.getPositionDescription()
                  + ": <item> tag requires a 'drawable' attribute or "
                  + "child tag defining a drawable");
        }
        dr = Drawable.createFromXmlInner(r, parser, attrs);
      }
      if (dr == null) {
        continue;
      }
      mStateListState.addStateSet(states, dr);
    }

    onStateChange(getState());
  }
  /** Draws the month days. */
  private void drawDays(Canvas canvas) {
    final TextPaint p = mDayPaint;
    final int headerHeight = mMonthHeight + mDayOfWeekHeight;
    final int rowHeight = mDayHeight;
    final int colWidth = mCellWidth;

    // Text is vertically centered within the row height.
    final float halfLineHeight = (p.ascent() + p.descent()) / 2f;
    int rowCenter = headerHeight + rowHeight / 2;

    for (int day = 1, col = findDayOffset(); day <= mDaysInMonth; day++) {
      final int colCenter = colWidth * col + colWidth / 2;
      final int colCenterRtl;
      if (isLayoutRtl()) {
        colCenterRtl = mPaddedWidth - colCenter;
      } else {
        colCenterRtl = colCenter;
      }

      int stateMask = 0;

      final boolean isDayEnabled = isDayEnabled(day);
      if (isDayEnabled) {
        stateMask |= StateSet.VIEW_STATE_ENABLED;
      }

      final boolean isDayActivated = mActivatedDay == day;
      if (isDayActivated) {
        stateMask |= StateSet.VIEW_STATE_ACTIVATED;

        // Adjust the circle to be centered on the row.
        canvas.drawCircle(colCenterRtl, rowCenter, mDaySelectorRadius, mDaySelectorPaint);
      } else if (mTouchedItem == day) {
        stateMask |= StateSet.VIEW_STATE_PRESSED;

        if (isDayEnabled) {
          // Adjust the circle to be centered on the row.
          canvas.drawCircle(colCenterRtl, rowCenter, mDaySelectorRadius, mDayHighlightPaint);
        }
      }

      final boolean isDayToday = mToday == day;
      final int dayTextColor;
      if (isDayToday && !isDayActivated) {
        dayTextColor = mDaySelectorPaint.getColor();
      } else {
        final int[] stateSet = StateSet.get(stateMask);
        dayTextColor = mDayTextColor.getColorForState(stateSet, 0);
      }
      p.setColor(dayTextColor);

      canvas.drawText(mDayFormatter.format(day), colCenterRtl, rowCenter - halfLineHeight, p);

      col++;

      if (col == DAYS_IN_WEEK) {
        col = 0;
        rowCenter += rowHeight;
      }
    }
  }