Beispiel #1
0
  @Override
  protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    super.onLayout(changed, left, top, right, bottom);

    wasLayout = true;
    int opticalInsetLeft = 0;
    int opticalInsetRight = 0;
    if (mThumbDrawable != null) {
      final Rect trackPadding = mTempRect;
      if (mTrackDrawable != null) {
        mTrackDrawable.getPadding(trackPadding);
      } else {
        trackPadding.setEmpty();
      }

      final Insets insets = Insets.NONE;
      opticalInsetLeft = Math.max(0, insets.left - trackPadding.left);
      opticalInsetRight = Math.max(0, insets.right - trackPadding.right);
    }

    final int switchRight;
    final int switchLeft;
    if (LocaleController.isRTL) {
      switchLeft = getPaddingLeft() + opticalInsetLeft;
      switchRight = switchLeft + mSwitchWidth - opticalInsetLeft - opticalInsetRight;
    } else {
      switchRight = getWidth() - getPaddingRight() - opticalInsetRight;
      switchLeft = switchRight - mSwitchWidth + opticalInsetLeft + opticalInsetRight;
    }

    final int switchTop;
    final int switchBottom;
    switch (getGravity() & Gravity.VERTICAL_GRAVITY_MASK) {
      default:
      case Gravity.TOP:
        switchTop = getPaddingTop();
        switchBottom = switchTop + mSwitchHeight;
        break;

      case Gravity.CENTER_VERTICAL:
        switchTop = (getPaddingTop() + getHeight() - getPaddingBottom()) / 2 - mSwitchHeight / 2;
        switchBottom = switchTop + mSwitchHeight;
        break;

      case Gravity.BOTTOM:
        switchBottom = getHeight() - getPaddingBottom();
        switchTop = switchBottom - mSwitchHeight;
        break;
    }

    mSwitchLeft = switchLeft;
    mSwitchTop = switchTop;
    mSwitchBottom = switchBottom;
    mSwitchRight = switchRight;
  }
Beispiel #2
0
  @Override
  protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    super.onLayout(changed, left, top, right, bottom);

    setThumbPosition(isChecked());

    int switchRight;
    int switchLeft;

    switchRight = getWidth() - getPaddingRight();
    switchLeft = switchRight - mSwitchWidth;

    int switchTop = 0;
    int switchBottom = 0;
    switch (getGravity() & Gravity.VERTICAL_GRAVITY_MASK) {
      default:
      case Gravity.TOP:
        switchTop = getPaddingTop();
        switchBottom = switchTop + mSwitchHeight;
        break;

      case Gravity.CENTER_VERTICAL:
        switchTop = (getPaddingTop() + getHeight() - getPaddingBottom()) / 2 - mSwitchHeight / 2;
        switchBottom = switchTop + mSwitchHeight;
        break;

      case Gravity.BOTTOM:
        switchBottom = getHeight() - getPaddingBottom();
        switchTop = switchBottom - mSwitchHeight;
        break;
    }

    mSwitchLeft = switchLeft;
    mSwitchTop = switchTop;
    mSwitchBottom = switchBottom;
    mSwitchRight = switchRight;
  }