Skip to content

Commit

Permalink
update atmospheric
Browse files Browse the repository at this point in the history
  • Loading branch information
AigeStudio's Mac committed Jul 3, 2016
1 parent db2fee2 commit 58b2150
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void run() {
// picker.setIndicatorColor(0xFF3333EE);
// picker.setIndicator(true);
// picker.setCurtain(true);
picker.setCyclic(true);
// picker.setCyclic(true);
// picker.setCurrentItem(3);
// picker.setIndicator(true);
// picker.setCurtainColor(0x88EE3333);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,21 @@ interface IWheelPicker {
*/
void setCurtainColor(int color);

/**
* 设置滚轮是否有空气感
* 开启空气感的滚轮将呈现中间不透明逐渐向两端透明过度的渐变效果
* 注意如果调用{@link #setCurrentItemTextColor(int)}为当前Item设置颜色,那么当前Item的空气感效果将会被设定的颜色值所覆盖
*
* @param hasAtmospheric 是否有空气感
*/
void setAtmospheric(boolean hasAtmospheric);

/**
* 是否有空气感
*
* @return ...
*/
boolean hasAtmospheric();
// /**
// * 设置Item在水平或垂直滚动器上的对齐方式
// * 滚动选择器默认的Item对齐方式为居中对齐{@link WheelCrossPicker#ALIGN_CENTER}
Expand Down Expand Up @@ -284,20 +299,4 @@ interface IWheelPicker {
// */
// boolean isPerspective();
//
// /**
// * 设置滚轮是否有空气感
// * 开启空气感的滚轮将呈现中间不透明逐渐向两端透明过度的渐变效果
// * 注意如果调用{@link #setCurrentItemTextColor(int)}为当前Item设置颜色,那么当前Item的空气感效果将会被设定的颜色值所覆盖
// *
// * @param hasAtmospheric 是否有空气感
// */
// void setAtmospheric(boolean hasAtmospheric);
//
// /**
// * 是否有空气感
// *
// * @return ...
// */
// boolean isAtmospheric();

}
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public class WheelPicker extends View implements IDebug, IWheelPicker, Runnable
private boolean hasSameWidth;
private boolean hasIndicator;
private boolean hasCurtain;
private boolean hasAtmospheric = true;
private boolean isCyclic;
private boolean isDebug;

Expand Down Expand Up @@ -161,7 +162,7 @@ public WheelPicker(Context context, AttributeSet attrs) {
mIndicatorColor = a.getColor(R.styleable.WheelPicker_wheel_indicator_color, 0xFFEE3333);
mIndicatorSize = a.getDimensionPixelSize(R.styleable.WheelPicker_wheel_indicator_size,
getResources().getDimensionPixelSize(R.dimen.WheelIndicatorSize));
hasCurtain = a.getBoolean(R.styleable.WheelPicker_wheel_curtain, true);
hasCurtain = a.getBoolean(R.styleable.WheelPicker_wheel_curtain, false);
mCurtainColor = a.getColor(R.styleable.WheelPicker_wheel_curtain_color, 0x88FFFFFF);
a.recycle();

Expand Down Expand Up @@ -315,9 +316,19 @@ protected void onDraw(Canvas canvas) {
}
mPaint.setColor(mItemTextColor);
mPaint.setStyle(Paint.Style.FILL);
int mDrawnItemCenterY = mDrawnCenterY + (drawnOffsetPos * mItemHeight);
canvas.drawText(data, mDrawnCenterX,
mDrawnItemCenterY + mScrollOffsetY % mItemHeight, mPaint);
int mDrawnItemCenterY = mDrawnCenterY + (drawnOffsetPos * mItemHeight) +
mScrollOffsetY % mItemHeight;
if (isDebug)
Log.i(TAG, "Item " + drawnOffsetPos + "'s draw centerY is" + mDrawnItemCenterY);
if (hasAtmospheric) {
int alpha = (int) ((mDrawnCenterY - Math.abs(mDrawnCenterY - mDrawnItemCenterY)) *
1.0F / mDrawnCenterY * 255);
if (isDebug)
Log.i(TAG, "Item " + drawnOffsetPos + "'s draw alpha is" + alpha);
alpha = alpha < 0 ? 0 : alpha;
mPaint.setAlpha(alpha);
}
canvas.drawText(data, mDrawnCenterX, mDrawnItemCenterY, mPaint);

if (isDebug) {
mPaint.setColor(0xFFEE3333);
Expand Down Expand Up @@ -661,6 +672,17 @@ public void setCurtainColor(int color) {
invalidate();
}

@Override
public void setAtmospheric(boolean hasAtmospheric) {
this.hasAtmospheric = hasAtmospheric;
invalidate();
}

@Override
public boolean hasAtmospheric() {
return hasAtmospheric;
}

/**
* 滚轮选择器Item项被选中时监听接口
*
Expand Down

0 comments on commit 58b2150

Please sign in to comment.