1
0
mirror of https://gitee.com/51danju/workclock.git synced 2025-06-07 19:34:05 +08:00

修改翻页时的字体位置比配,增加时间文字的位移设置

This commit is contained in:
wushunlian 2019-07-03 18:24:32 +08:00
parent ec64ecb921
commit 6736591324
17 changed files with 414 additions and 90 deletions

View File

@ -76,4 +76,6 @@ dependencies {
implementation 'com.jakewharton:butterknife:10.1.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'
implementation 'com.github.Jay-Goo:RangeSeekBar:v3.0.0'
}

View File

@ -243,9 +243,9 @@ public class MainActivity extends AppCompatActivity implements android.view.Ges
globalViewModel.getHourAlterTypeName().setValue(FishAnimator.NAME);
/*globalViewModel.getHandUpTypeName().setValue(HandUpSelect123Fragment.NAME);
//globalViewModel.getHandUpTypeName().setValue(HandUpSelect123Fragment.NAME);
Observer<Boolean> timeChange= new Observer<Boolean>() {
/*Observer<Boolean> timeChange= new Observer<Boolean>() {
@Override
public void onChanged(Boolean aBoolean) {
daily--;
@ -660,7 +660,7 @@ public class MainActivity extends AppCompatActivity implements android.view.Ges
return true;
Log.d(TAG,"onFling");
int brightness=globalViewModel.getBrightness().getValue();
if (e2.getY() - e1.getY() < -100) { // 从上至下
if (e2.getY() - e1.getY() < -200) { // 从上至下
Log.d(TAG, "change brightness +10");
brightness = brightness + 10;
if (brightness >= 255){
@ -669,7 +669,7 @@ public class MainActivity extends AppCompatActivity implements android.view.Ges
}
globalViewModel.getBrightness().setValue(brightness);
return true;
}else if (e2.getY() - e1.getY() >100) { // 从下至上
}else if (e2.getY() - e1.getY() >200) { // 从下至上
Log.d(TAG,"change brightness -10");
brightness=brightness-10;
if(brightness<=0) {
@ -678,8 +678,7 @@ public class MainActivity extends AppCompatActivity implements android.view.Ges
}
globalViewModel.getBrightness().setValue(brightness);
return true;
}
if (e2.getX() - e1.getX() > 120) { // 从左向右滑动左进右出
}else if (e2.getX() - e1.getX() > 200) { // 从左向右滑动左进右出
Log.d(TAG,"left->right");
if(globalViewModel.getClockInterfaceTypeEnum().getValue()== ClockInterfaceTypeEnum.Simulate){
simulateViewModel.setClockTypeName(ClockFactory.nextSimulateClockName(simulateViewModel.getClockTypeName().getValue()));
@ -687,7 +686,7 @@ public class MainActivity extends AppCompatActivity implements android.view.Ges
}
digitViewModel.setTimeFontStyle(fontManager.nextFont());
return true;
} else if (e2.getX() - e1.getX() < -120) { // 从右向左滑动右进左出
} else if (e2.getX() - e1.getX() < -200) { // 从右向左滑动右进左出
nextBackGroundAnimator();
return true;
}

View File

@ -16,6 +16,9 @@ import android.widget.Toast;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProviders;
import com.jaygoo.widget.OnRangeChangedListener;
import com.jaygoo.widget.RangeSeekBar;
import com.jaygoo.widget.VerticalRangeSeekBar;
import com.openbravo.data.basic.BasicException;
import java.util.Random;
@ -124,6 +127,10 @@ public class DigitClockConfigFragment extends Fragment {
CheckBox tvTextStyleBorder;
@BindView(R.id.tv_textStyle_border_color)
Button tvTextStyleBorderColor;
@BindView(R.id.tv_time_text_basline_down)
VerticalRangeSeekBar tvTimeTextBaslineDown;
@BindView(R.id.tv_textStyle_border_divider_color)
Button tvTextStyleBorderDividerColor;
public DigitClockConfigFragment(ThemeUIManager themeUIManager) {
this.themeUIManager = themeUIManager;
@ -148,6 +155,8 @@ public class DigitClockConfigFragment extends Fragment {
unbinder = ButterKnife.bind(this, view);
tvTimeTextBaslineDown.setTickMarkTextArray(new CharSequence[]{"100", "位移", "100"});
loadForViewModel();
tvHourSystemGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@ -285,10 +294,9 @@ public class DigitClockConfigFragment extends Fragment {
tvTextStyleBorder.setOnCheckedChangeListener((group, checkedId) -> {
digitViewModel.setCharBackgroundBorder(tvTextStyleBorder.isChecked());
tvTextStyleBorderColor.setClickable(tvTextStyleBorder.isChecked());
});
tvTextStyleBorderColor.setOnClickListener(v->{
tvTextStyleBorderColor.setOnClickListener(v -> {
if (colorPickerDialog == null)
colorPickerDialog = new ColorPickerPop(getActivity());
@ -306,6 +314,41 @@ public class DigitClockConfigFragment extends Fragment {
colorPickerDialog.show(digitViewModel.getCharBackgroundBorderColor().getValue());
});
tvTextStyleBorderDividerColor.setOnClickListener(v -> {
if (colorPickerDialog == null)
colorPickerDialog = new ColorPickerPop(getActivity());
colorPickerDialog.setOnColorChangeListenter(new ColorPickerPop.OnColorListener() {
@Override
public void onEnsure(int color) {
digitViewModel.setCharBackgroundBorderDividerColor(color);
tvTextStyleBorderDividerColor.setBackgroundColor(color);
}
@Override
public void onBack() {
}
});
colorPickerDialog.show(digitViewModel.getCharBackgroundBorderColor().getValue());
});
tvTimeTextBaslineDown.setOnRangeChangedListener(new OnRangeChangedListener() {
@Override
public void onRangeChanged(RangeSeekBar view, float leftValue, float rightValue, boolean isFromUser) {
digitViewModel.setBaseLineDown(new Float(leftValue - 100).intValue());
}
@Override
public void onStartTrackingTouch(RangeSeekBar view, boolean isLeft) {
}
@Override
public void onStopTrackingTouch(RangeSeekBar view, boolean isLeft) {
}
});
return view;
}
@ -451,7 +494,19 @@ public class DigitClockConfigFragment extends Fragment {
tvTextStyleBorder.setChecked(digitViewModel.getCharBackgroundBorder().getValue());
tvTextStyleBorderColor.setBackgroundColor(digitViewModel.getCharBackgroundBorderColor().getValue());
tvTextStyleBorderColor.setClickable(digitViewModel.getCharBackgroundBorder().getValue());
tvTextStyleBorderDividerColor.setBackgroundColor(digitViewModel.getCharBackgroundBorderDividerColor().getValue());
float baseLineDown = 100f + digitViewModel.getBaseLineDown().getValue();
if (baseLineDown > 200)
baseLineDown = 200;
else if (baseLineDown < 0)
baseLineDown = 100;
tvTimeTextBaslineDown.setProgress(baseLineDown);
digitViewModel.getCharBackgroundBorder().observe(this,(able)->{
tvTextStyleBorderColor.setClickable(able);
tvTextStyleBorderDividerColor.setClickable(able);
});
}
private void setTextColor(int color) {
@ -494,6 +549,10 @@ public class DigitClockConfigFragment extends Fragment {
tvTextStyleBorder.setTextColor(color);
tvTextStyleBorderColor.setTextColor(color);
tvTextStyleBorderDividerColor.setTextColor(color);
tvTimeTextBaslineDown.setTickMarkTextColor(color);
}
static Random rand = new Random();

View File

@ -137,16 +137,14 @@ public class DigitClockFragment extends Fragment {
digitViewModel.getCharBackgroundBorder().observe(this,able->tv_time.setCharBackgroundBorder(able));
digitViewModel.getCharBackgroundBorderColor().observe(this,color->tv_time.setCharBackgroundBorderColor(color));
//globalViewModel.getBackgroundColor().observe(this,color->tv_time.setBackgroundBorderDividerColor(color));
digitViewModel.getCharBackgroundBorderDividerColor().observe(this,color->tv_time.setBackgroundBorderDividerColor(color));
digitViewModel.getCharBackgroundBorderDividerWidth().observe(this,width->tv_time.setBackgroundBorderDividerWidth(width));
}
private void updateBaseLine(boolean isFullScreen){
if(isFullScreen){
tv_time.setBaseLineDown(0);
}else{
//tv_time.setBaseLineDown(themeBaseLine+tv_day.getHeight()/2);
tv_time.setBaseLineDown(digitViewModel.getBaseLineDown().getValue()+30);
}
}
protected void reflushFontStyle(TimeFontStyle fontStyle){

View File

@ -34,7 +34,18 @@ public class DigitPerferenceModel {
protected boolean charBackgroundBorder = false;
protected final static String KEY_IS_CHAR_BACKGROUND_BORDER_COLOR = "key_is_char_background_border_color";
protected Integer charBackgroundBorderColor=0;
protected Integer charBackgroundBorderColor=Color.BLACK;
protected final static String KEY_IS_CHAR_BACKGROUND_BORDER_DIVIDER_COLOR = "key_is_char_background_border_divider_color";
protected Integer charBackgroundBorderDividerColor=Color.BLACK;
protected final static String KEY_IS_CHAR_BACKGROUND_BORDER_DIVIDER_STROKE_WIDTH = "key_is_char_background_border_divider_stroke_width";
protected Integer charBackgroundBorderDividerStrokeWidth=10;
protected final static String KEY_TIME_TEXT_BASELINE_DOWN= "key_time_text_baseline_down";
protected Integer baseLineDown=0;
public void fromJsonString(JSONObject jsonObject) throws JSONException {
linearGradientAble=jsonObject.optBoolean(KEY_IS_LINEARGRADIENT_ABLE,false);
@ -47,6 +58,9 @@ public class DigitPerferenceModel {
timeTextSecondSubscript=jsonObject.optBoolean(KEY_IS_DISPLAY_SECOND_SUBSCRIPT,true);
charBackgroundBorder=jsonObject.optBoolean(KEY_IS_CHAR_BACKGROUND_BORDER,false);
charBackgroundBorderColor=jsonObject.optInt(KEY_IS_CHAR_BACKGROUND_BORDER_COLOR, Color.BLACK);
baseLineDown=jsonObject.optInt(KEY_TIME_TEXT_BASELINE_DOWN,0);
charBackgroundBorderDividerColor=jsonObject.optInt(KEY_IS_CHAR_BACKGROUND_BORDER_DIVIDER_COLOR, Color.BLACK);
charBackgroundBorderDividerStrokeWidth=jsonObject.optInt(KEY_IS_CHAR_BACKGROUND_BORDER_DIVIDER_STROKE_WIDTH, 10);
}
@ -61,6 +75,10 @@ public class DigitPerferenceModel {
jsonObject.put(KEY_IS_DISPLAY_SECOND_SUBSCRIPT,timeTextSecondSubscript);
jsonObject.put(KEY_IS_CHAR_BACKGROUND_BORDER,charBackgroundBorder);
jsonObject.put(KEY_IS_CHAR_BACKGROUND_BORDER_COLOR,charBackgroundBorderColor);
jsonObject.put(KEY_TIME_TEXT_BASELINE_DOWN,baseLineDown);
jsonObject.put(KEY_IS_CHAR_BACKGROUND_BORDER_DIVIDER_COLOR,charBackgroundBorderDividerColor);
jsonObject.put(KEY_IS_CHAR_BACKGROUND_BORDER_DIVIDER_STROKE_WIDTH,charBackgroundBorderDividerStrokeWidth);
}
public static String integerArrayToString(Integer[] fromArrays){
@ -165,4 +183,28 @@ public class DigitPerferenceModel {
public void setCharBackgroundBorderColor(Integer charBackgroundBorderColor) {
this.charBackgroundBorderColor = charBackgroundBorderColor;
}
public Integer getBaseLineDown() {
return baseLineDown;
}
public void setBaseLineDown(Integer baseLineDown) {
this.baseLineDown = baseLineDown;
}
public Integer getCharBackgroundBorderDividerColor() {
return charBackgroundBorderDividerColor;
}
public void setCharBackgroundBorderDividerColor(Integer charBackgroundBorderDividerColor) {
this.charBackgroundBorderDividerColor = charBackgroundBorderDividerColor;
}
public Integer getCharBackgroundBorderDividerStrokeWidth() {
return charBackgroundBorderDividerStrokeWidth;
}
public void setCharBackgroundBorderDividerStrokeWidth(Integer charBackgroundBorderDividerStrokeWidth) {
this.charBackgroundBorderDividerStrokeWidth = charBackgroundBorderDividerStrokeWidth;
}
}

View File

@ -717,4 +717,31 @@ public class SharePerferenceModel implements Serializable {
dirtySave();
}
public Integer getBaseLineDown() {
return digitPerferenceModel.getBaseLineDown();
}
public void setBaseLineDown(Integer baseLineDown) {
digitPerferenceModel.setBaseLineDown(baseLineDown);
dirtySave();
}
public Integer getCharBackgroundBorderDividerColor() {
return digitPerferenceModel.getCharBackgroundBorderDividerColor();
}
public void setCharBackgroundBorderDividerColor(Integer charBackgroundBorderDividerColor) {
digitPerferenceModel.setCharBackgroundBorderDividerColor(charBackgroundBorderDividerColor);
dirtySave();
}
public Integer getCharBackgroundBorderDividerStrokeWidth() {
return digitPerferenceModel.getCharBackgroundBorderDividerStrokeWidth();
}
public void setCharBackgroundBorderDividerStrokeWidth(Integer charBackgroundBorderDividerStrokeWidth) {
digitPerferenceModel.setCharBackgroundBorderDividerStrokeWidth(charBackgroundBorderDividerStrokeWidth);
dirtySave();
}
}

View File

@ -106,6 +106,7 @@ public class ClockStateMachine implements Handler.Callback{
return;
case DELAY:
stopHandUpDelay();
countingDateTimeBase=null;
return;
}
this.showTimeType=type;

View File

@ -38,6 +38,10 @@ public class DigitViewModel extends ViewModel {
private MutableLiveData<Integer> charBackgroundBorderColor=new MutableLiveData<>();
private MutableLiveData<Integer> charBackgroundBorderDividerColor=new MutableLiveData<>();
private MutableLiveData<Integer> charBackgroundBorderDividerWidth=new MutableLiveData<>();
SharePerferenceModel model;
public DigitViewModel(SharePerferenceModel model) {
@ -52,12 +56,14 @@ public class DigitViewModel extends ViewModel {
reflectedAble.setValue(model.isReflectedAble());
shadowType.setValue(ShadowTypeEnum.valueOf(model.getShadowType()));
timeCharAnimatorType.setValue(CharAnimatorEnum.valueOf(model.getTimeTextCharAnimatorType()));
baseLineDown.setValue(0);
baseLineDown.setValue(model.getBaseLineDown());
timeFontStyleSize.setValue(100);
timeFontName.setValue(model.getFontName());
secondSubscript.setValue(model.isTimeTextSecondSubscript());
charBackgroundBorder.setValue(model.isCharBackgroundBorder());
charBackgroundBorderColor.setValue(model.getCharBackgroundBorderColor());
charBackgroundBorderDividerColor.setValue(model.getCharBackgroundBorderDividerColor());
charBackgroundBorderDividerWidth.setValue(model.getCharBackgroundBorderDividerStrokeWidth());
}
public MutableLiveData<Boolean> getDisplaySecond() {
@ -146,6 +152,7 @@ public class DigitViewModel extends ViewModel {
public void setBaseLineDown(Integer baseLineDown) {
this.baseLineDown.setValue(baseLineDown);
model.setBaseLineDown(baseLineDown);
}
public MutableLiveData<String> getTimeFontName() {
@ -178,4 +185,22 @@ public class DigitViewModel extends ViewModel {
this.charBackgroundBorderColor.setValue(charBackgroundBorderColor);
model.setCharBackgroundBorderColor(charBackgroundBorderColor);
}
public MutableLiveData<Integer> getCharBackgroundBorderDividerColor() {
return charBackgroundBorderDividerColor;
}
public void setCharBackgroundBorderDividerColor(Integer charBackgroundBorderDividerColor) {
this.charBackgroundBorderDividerColor.setValue(charBackgroundBorderDividerColor);
model.setCharBackgroundBorderDividerColor(charBackgroundBorderDividerColor);
}
public MutableLiveData<Integer> getCharBackgroundBorderDividerWidth() {
return charBackgroundBorderDividerWidth;
}
public void setCharBackgroundBorderDividerWidth(Integer charBackgroundBorderDividerWidth) {
this.charBackgroundBorderDividerWidth.setValue(charBackgroundBorderDividerWidth);
model.setCharBackgroundBorderDividerStrokeWidth(charBackgroundBorderDividerWidth);
}
}

View File

@ -19,14 +19,6 @@ public class FishAnimator extends AbstractAnimator<FishAnimator.Fish> {
public static final String NAME = "Jcs_Fishsss";
private static final float HEAD_RADIUS = 50;
protected static final float BODY_LENGHT = HEAD_RADIUS * 3.2f; //第一节身体长度
private static final int BODY_ALPHA = 220;
private static final int OTHER_ALPHA = 160;
private static final int FINS_ALPHA = 100;
private static final int FINS_LEFT = 1;//左鱼鳍
private static final int FINS_RIGHT = -1;
private static final float FINS_LENGTH = HEAD_RADIUS * 1.3f;
public static final float TOTAL_LENGTH = 6.79f * HEAD_RADIUS;
public FishAnimator(int entryQuantity) {
super(entryQuantity);
@ -34,10 +26,27 @@ public class FishAnimator extends AbstractAnimator<FishAnimator.Fish> {
@Override
public Fish createNewEntry() {
return new Fish(rand.nextInt(width),rand.nextInt(height),0);
int fishHeadRadius=rand.nextInt(new Double(HEAD_RADIUS*1.5).intValue());
if(fishHeadRadius<15)
fishHeadRadius+=15;
int h=rand.nextInt(height);
if(h<=fishHeadRadius*2)
h+=height/2;
else if(h+fishHeadRadius*2>=height)
h-=height/2;
return new Fish(rand.nextInt(width),h,0,fishHeadRadius);
}
public class Fish implements I_AnimatorEntry {
protected float BODY_LENGHT ; //第一节身体长度
private int BODY_ALPHA = 220;
private int OTHER_ALPHA = 160;
private int FINS_ALPHA = 100;
private int FINS_LEFT = 1;//左鱼鳍
private int FINS_RIGHT = -1;
private float FINS_LENGTH ;
public float TOTAL_LENGTH ;
private Paint mPaint;
//控制区域
private int currentValue = 0;//全局控制标志
@ -53,11 +62,17 @@ public class FishAnimator extends AbstractAnimator<FishAnimator.Fish> {
private int startX,startY;
public Fish(int startX,int startY,float mainAngle) {
init();
private float headRadius;
public Fish(int startX,int startY,float mainAngle, float headRadius) {
this.startX=startX;
this.startY=startY;
this.mainAngle=mainAngle;
this.headRadius=headRadius;
BODY_LENGHT = headRadius * 3.2f; //第一节身体长度
FINS_LENGTH = headRadius * 1.3f;
TOTAL_LENGTH = 6.79f * headRadius;
init();
}
private void init() {
@ -76,7 +91,7 @@ public class FishAnimator extends AbstractAnimator<FishAnimator.Fish> {
bodyPaint.setStyle(Paint.Style.FILL);
bodyPaint.setDither(true);//防抖
bodyPaint.setColor(Color.argb(OTHER_ALPHA + 5, 244, 92, 71));
middlePoint = new PointF(4.18f * HEAD_RADIUS, 4.18f * HEAD_RADIUS);
middlePoint = new PointF(4.18f * headRadius, 4.18f * headRadius);
//鱼鳍灵动动画
//finsAnimator = ObjectAnimator.ofFloat(this, "finsAngle", 0f, 1f, 0f);
@ -154,7 +169,7 @@ public class FishAnimator extends AbstractAnimator<FishAnimator.Fish> {
//生成一个半透明图层否则与背景白色形成干扰,尺寸必须与view的大小一致否则鱼显示不全
canvas.saveLayerAlpha(0, 0, canvas.getWidth(), canvas.getHeight(), 240, Canvas.ALL_SAVE_FLAG);
makeBody(canvas, HEAD_RADIUS);
makeBody(canvas, headRadius);
canvas.restore();
mPath.reset();
mPaint.setColor(Color.argb(OTHER_ALPHA, 244, 92, 71));
@ -181,7 +196,7 @@ public class FishAnimator extends AbstractAnimator<FishAnimator.Fish> {
headPoint.y=headPoint.y+startY;
//画头
canvas.drawCircle(headPoint.x, headPoint.y, HEAD_RADIUS, mPaint);
canvas.drawCircle(headPoint.x, headPoint.y, headRadius, mPaint);
//右鳍 起点
PointF pointFinsRight = calculatPoint(headPoint, headRadius * 0.9f, angle -110);
makeFins(canvas, pointFinsRight, FINS_RIGHT, angle);
@ -312,7 +327,7 @@ public class FishAnimator extends AbstractAnimator<FishAnimator.Fish> {
* @param maxWidth
*/
private void makeTail(Canvas canvas, PointF mainPoint, float length, float maxWidth, float angle) {
float newWidth = (float) Math.abs(Math.sin(Math.toRadians(currentValue * 1.7 * waveFrequence)) * maxWidth + HEAD_RADIUS/5*3);
float newWidth = (float) Math.abs(Math.sin(Math.toRadians(currentValue * 1.7 * waveFrequence)) * maxWidth + headRadius/5*3);
//endPoint为三角形底边中点
PointF endPoint = calculatPoint(mainPoint, length, angle-180);
PointF endPoint2 = calculatPoint(mainPoint, length - 10, angle-180);
@ -370,12 +385,12 @@ public class FishAnimator extends AbstractAnimator<FishAnimator.Fish> {
*/
public int getIntrinsicHeight() {
return (int) (8.38f * HEAD_RADIUS);
return (int) (8.38f * headRadius);
}
public int getIntrinsicWidth() {
return (int) (8.38f * HEAD_RADIUS);
return (int) (8.38f * headRadius);
}
@Override

View File

@ -11,11 +11,11 @@ import android.graphics.Shader;
import android.graphics.Typeface;
import android.text.TextPaint;
import android.util.AttributeSet;
import android.util.Log;
import androidx.annotation.Nullable;
import java.util.Date;
import com.xenione.digit.TabConfig;
import java.util.HashMap;
import java.util.Random;
@ -48,8 +48,8 @@ public class DigitTextView extends androidx.appcompat.widget.AppCompatTextView {
private int charBackgroundBorderColor = Color.BLACK;
private int textWidth = 0;
private int textHight;
private int textfontHight;
private int textBodyHight;
private int textFontHight;
private int baseCharWidth;
private int flagCharwidth;
private int smallTextHight;
@ -106,14 +106,15 @@ public class DigitTextView extends androidx.appcompat.widget.AppCompatTextView {
mDividerPaint.setAntiAlias(true);
mDividerPaint.setStyle(Paint.Style.FILL_AND_STROKE);
mDividerPaint.setColor(Color.WHITE);
mDividerPaint.setStrokeWidth(2);
mDividerPaint.setStrokeWidth(10);
mBackgroundPaint = new Paint();
mBackgroundPaint.setAntiAlias(true);
}
public void setBaseLineDown(float baseLineDown) {
this.baseLineDown = baseLineDown;
this.baseLineDown =getHeight()/2*(-baseLineDown/100);
layoutReflushAble=true;
}
@ -230,10 +231,10 @@ public class DigitTextView extends androidx.appcompat.widget.AppCompatTextView {
//baseCharWidth+=padding;
flagCharwidth = getCharWidth(":", mTextPaint);
textfontHight = (int) getFontHeight(mTextPaint);
textHight = -fm.descent - fm.ascent;
textFontHight = (int) getFontHeight(mTextPaint);
textBodyHight =(int)getFontBodyHeight(mTextPaint);
smallTextHight = textHight;
smallTextHight = textFontHight;
smallCharWidth = baseCharWidth;
textLength = textToDraw.length();
@ -249,7 +250,7 @@ public class DigitTextView extends androidx.appcompat.widget.AppCompatTextView {
smallCharPaint = getCustomTextPaint(mTextPaint, mTextPaint.getTextSize() / fontScale * 4 / 5);
smallCharWidth = getCharWidth("8", smallCharPaint);
fm = smallCharPaint.getFontMetricsInt();
smallTextHight = -fm.descent - fm.ascent;
smallTextHight =(int) getFontHeight(smallCharPaint);
} else
textSmallSpan = textSmallSpan + flagCharwidth;
textSmallSpan = textSmallSpan + smallCharWidth * 2;
@ -277,7 +278,7 @@ public class DigitTextView extends androidx.appcompat.widget.AppCompatTextView {
layoutReflush(textToDraw);
startX = (getWidth() - textWidth - textSmallSpan) / 2;
startY = (getHeight() + textHight) / 2;
startY = (getHeight() + textBodyHight) / 2+baseLineDown;
if (linearGradientReCreate)
linearGradientReflush();
@ -286,7 +287,7 @@ public class DigitTextView extends androidx.appcompat.widget.AppCompatTextView {
charStr = String.valueOf(textToDraw.charAt(i));
if (i < 5) {
if (i == 2) {
canvas.drawText(charStr, startX, startY + baseLineDown, mTextPaint);
canvas.drawText(charStr, startX, startY, mTextPaint);
startX += flagCharwidth;
} else {
drawCharWithAnaimatorCheck(canvas, i, charStr, startX, startY, mTextPaint);
@ -296,22 +297,23 @@ public class DigitTextView extends androidx.appcompat.widget.AppCompatTextView {
if (secondSubscript)
startX += smallCharWidth / 2;
else {
canvas.drawText(charStr, startX, startY + baseLineDown, mTextPaint);
canvas.drawText(charStr, startX, startY , mTextPaint);
startX += flagCharwidth;
}
} else {
if (secondSubscript) {
centerY = (getHeight() + smallTextHight) / 2;
centerY = centerY + (startY - centerY) / 2 + smallCharPaint.getFontMetrics().descent;
smallCharPaint.setColor(getCurrentTextColor());
if (charBackgroundBorder)
drawBackground(canvas, startX, startY + baseLineDown - smallTextHight, smallCharWidth, smallTextHight, mBackgroundPaint);
drawChar(canvas, charStr, startX, centerY + baseLineDown, smallCharPaint);
drawBackground(canvas, startX, centerY - smallTextHight, smallCharWidth, smallTextHight, mBackgroundPaint);
drawChar(canvas, charStr, startX, centerY, smallCharPaint);
} else {
drawCharWithAnaimatorCheck(canvas, i, charStr, startX, startY, mTextPaint);
startX += padding;
}
startX += smallCharWidth;
//Log.d(Tag,"view hight:"+getHeight()+"\t startY:"+startY+"\t text hight:"+textHight+"small text hight:"+smallTextHight);
//Log.d(Tag,"view hight:"+getHeight()+"\t startY:"+startY+"\t text hight:"+textBodyHight+"small text hight:"+smallTextHight);
}
}
preString = textToDraw;
@ -321,11 +323,16 @@ public class DigitTextView extends androidx.appcompat.widget.AppCompatTextView {
private void drawBackground(Canvas canvas, float startX, float startY, int width, int height, Paint mBackgroundPaint) {
mBackgroundPaint.setColor(charBackgroundBorderColor);
canvas.drawRoundRect(new RectF(startX, startY, startX + width, startY + height), 10, 10, mBackgroundPaint);
//canvas.drawRoundRect(new RectF(startX, startY, startX + width, startY + height), 10, 10, mBackgroundPaint);
canvas.drawRoundRect(new RectF(startX, startY, startX + width, startY + height/2-mDividerPaint.getStrokeWidth()/2), 10, 10, mBackgroundPaint);
canvas.drawRoundRect(new RectF(startX, startY+ height/2+mDividerPaint.getStrokeWidth()/2, startX + width, startY + height), 10, 10, mBackgroundPaint);
}
private void drawDivider(Canvas canvas, float startX, float startY, int width, int height, Paint mDividerPaint) {
//canvas.drawLine(startX, startY+height/2, startX+width, startY+height/2, mDividerPaint);
canvas.drawLine(startX+mDividerPaint.getStrokeWidth(), startY+height/2, startX+width-mDividerPaint.getStrokeWidth(), startY+height/2, mDividerPaint);
//canvas.drawRoundRect(new RectF(startX, startY+height/2, startX+width, startY+height/2), 3, 3, mDividerPaint);
//canvas.drawCircle(startX, startY+height/2,mDividerPaint.getStrokeWidth() , mBackgroundPaint);
//canvas.drawCircle(startX+width, startY+height/2,mDividerPaint.getStrokeWidth() , mBackgroundPaint);
}
private void drawChar(Canvas canvas, String c, float startX, float startY, Paint mTextPaint) {
@ -336,9 +343,9 @@ public class DigitTextView extends androidx.appcompat.widget.AppCompatTextView {
private void drawCharWithAnaimatorCheck(Canvas canvas, int i, String charStr, float startX, float startY, Paint mTextPaint) {
charWidth = getCharWidth(charStr, mTextPaint);
//Log.d(Tag,"view width:"+getWidth()+"\t heitht:"+getHeight()+"\t startx:"+startX+"\t startY:"+startY+"\t baseCharWidth:"+baseCharWidth+"\t text hight:"+textHight+"\t text font hight:"+textfontHight);
//Log.d(Tag,"view width:"+getWidth()+"\t heitht:"+getHeight()+"\t startx:"+startX+"\t startY:"+startY+"\t baseCharWidth:"+baseCharWidth+"\t text hight:"+textBodyHight+"\t text font hight:"+textFontHight);
if (charBackgroundBorder)
drawBackground(canvas, startX, startY + baseLineDown - textfontHight + (textfontHight - textHight) / 4, baseCharWidth, textfontHight, mBackgroundPaint);
drawBackground(canvas, startX, startY-textFontHight+mTextPaint.getFontMetrics().bottom, baseCharWidth, textFontHight, mBackgroundPaint);
if (currentCharAnimatorType != CharAnimatorEnum.NOSETUP) {
charAnimator = charAnimatorHashMap.get(i);
if (charAnimator != null && !charAnimator.isCharAnimatorRuning()) {
@ -350,18 +357,19 @@ public class DigitTextView extends androidx.appcompat.widget.AppCompatTextView {
charAnimatorHashMap.put(i, charAnimator);
}
if (charAnimator != null) {
charAnimator.drawCharAnimator(canvas, startX + (baseCharWidth - charWidth) / 2, startY + baseLineDown, mTextPaint);
//charAnimator.drawCharAnimator(canvas, startX + (baseCharWidth - charWidth) / 2, startY , mTextPaint);
charAnimator.drawCharAnimator(canvas, startX, startY , mTextPaint);
//Log.d(Tag,"charAnimator index i:"+i+"\tanimator percent:");
invalidate();
} else {
drawChar(canvas, charStr, startX + (baseCharWidth - charWidth) / 2, startY + baseLineDown, mTextPaint);
drawChar(canvas, charStr, startX + (baseCharWidth - charWidth) / 2, startY, mTextPaint);
if (charBackgroundBorder)
drawDivider(canvas, startX, startY + baseLineDown - textfontHight + (textfontHight - textHight) / 4, baseCharWidth, textfontHight, mDividerPaint);
drawDivider(canvas, startX, startY - textFontHight+mTextPaint.getFontMetrics().bottom, baseCharWidth, textFontHight, mDividerPaint);
}
} else {
drawChar(canvas, charStr, startX + (baseCharWidth - charWidth) / 2, startY + baseLineDown, mTextPaint);
drawChar(canvas, charStr, startX + (baseCharWidth - charWidth) / 2, startY , mTextPaint);
if (charBackgroundBorder)
drawDivider(canvas, startX, startY + baseLineDown - textfontHight + (textfontHight - textHight) / 4, baseCharWidth, textfontHight, mDividerPaint);
drawDivider(canvas, startX, startY - textFontHight+mTextPaint.getFontMetrics().bottom , baseCharWidth, textFontHight, mDividerPaint);
}
}
@ -374,7 +382,7 @@ public class DigitTextView extends androidx.appcompat.widget.AppCompatTextView {
reflectedPaint = new Paint(mTextPaint);
reflectedShader = new LinearGradient(startX,
-startY, startX,
-startY - textHight * 6 / 5,
-startY - textBodyHight * 6 / 5,
Color.BLACK, 0x00ffffff, Shader.TileMode.MIRROR);// 创建线性渐变LinearGradient对象
matrix = new Matrix();
matrix.preScale(1, -1); // 实现图片的反转
@ -401,7 +409,7 @@ public class DigitTextView extends androidx.appcompat.widget.AppCompatTextView {
charAnimator = new Marquee3DCharAnimator(preString, currentString, Marquee3DCharAnimator.U2D);
break;
case TabDigit:
charAnimator = new TabDigitCharAnimator(preString, currentString, true);
charAnimator = new TabDigitCharAnimator(preString, currentString, true,true,new TabConfig(charBackgroundBorder,charBackgroundBorderColor,mDividerPaint.getColor(),(int)mDividerPaint.getStrokeWidth()));
break;
}
return charAnimator;
@ -427,9 +435,14 @@ public class DigitTextView extends androidx.appcompat.widget.AppCompatTextView {
return (int) paint.measureText(str);
}
public float getFontHeight(Paint paint) {
public static float getFontHeight(Paint paint) {
Paint.FontMetrics fm = paint.getFontMetrics();
return ((int) Math.ceil(fm.descent - fm.top) + 2);
return fm.bottom - fm.top;
}
public static float getFontBodyHeight(Paint paint) {
Paint.FontMetrics fm = paint.getFontMetrics();
return fm.descent - fm.ascent;
}
public boolean isCharBackgroundBorder() {
@ -447,4 +460,12 @@ public class DigitTextView extends androidx.appcompat.widget.AppCompatTextView {
public void setCharBackgroundBorderColor(int charBackgroundBorderColor) {
this.charBackgroundBorderColor = charBackgroundBorderColor;
}
public void setBackgroundBorderDividerColor(int color){
mDividerPaint.setColor(color);
}
public void setBackgroundBorderDividerWidth(int width){
mDividerPaint.setStrokeWidth(width);
}
}

View File

@ -3,15 +3,16 @@ package clock.socoolby.com.clock.widget.textview.charanimator;
import android.graphics.Canvas;
import android.graphics.Paint;
import com.xenione.digit.TabConfig;
import com.xenione.digit.TabDigit;
public class TabDigitCharAnimator extends AbstractCharAnimator {
TabDigit tabDigit;
public TabDigitCharAnimator(String preString, String currentString,boolean up) {
public TabDigitCharAnimator(String preString, String currentString, boolean up, boolean charDrawCenter, TabConfig tabConfig) {
super(preString, currentString);
tabDigit=new TabDigit(preString,currentString,up);
tabDigit=new TabDigit(preString,currentString,up,charDrawCenter,tabConfig);
tabDigit.start();
}
@ -23,7 +24,8 @@ public class TabDigitCharAnimator extends AbstractCharAnimator {
@Override
public void drawCharCurrent(Canvas canvas, String strToDraw, float startX, float startY, Paint mTextPaint, float percent) {
canvas.save();
canvas.translate(startX,startY-getFontHeight(mTextPaint));
canvas.translate(startX,startY-getFontHeight(mTextPaint)+mTextPaint.getFontMetrics().bottom);
if(percent==0)
tabDigit.setmNumberPaint(mTextPaint);
tabDigit.onDraw(canvas);
canvas.restore();
@ -41,8 +43,13 @@ public class TabDigitCharAnimator extends AbstractCharAnimator {
return tabDigit.isRunning();
}
public float getFontHeight(Paint paint) {
public static float getFontHeight(Paint paint) {
Paint.FontMetrics fm = paint.getFontMetrics();
return ((int) Math.ceil(fm.descent - fm.top) + 2) + fm.ascent/4 ;
return fm.bottom-fm.top;
}
public static float getFontBodyHeight(Paint paint) {
Paint.FontMetrics fm = paint.getFontMetrics();
return fm.descent - fm.ascent;
}
}

View File

@ -13,7 +13,7 @@ public abstract class AbstractTabAnimation {
protected int state;
protected int mAlpha = 0;
protected long mTime = -1;
protected float mElapsedTime = 1000.0f;
protected float mElapsedTime = 950.0f;
public AbstractTabAnimation(TabDigitEntity mTopTab, TabDigitEntity mBottomTab, TabDigitEntity mMiddleTab) {
this.mTopTab = mTopTab;

View File

@ -52,7 +52,6 @@ public final class TabAnimationUp extends AbstractTabAnimation {
mAlpha = (int) (180 * (1 - (1 * mElapsedTime - delta) / (1 * mElapsedTime)));
mMiddleTab.rotate(mAlpha);
}
}
@Override

View File

@ -0,0 +1,50 @@
package com.xenione.digit;
public class TabConfig{
private Boolean charBackgroundBorder;
private Integer charBackgroundBorderColor;
private Integer charBackgroundBorderDividerColor;
private Integer charBackgroundBorderDividerWidth;
public TabConfig(Boolean charBackgroundBorder, Integer charBackgroundBorderColor, Integer charBackgroundBorderDividerColor, Integer charBackgroundBorderDividerWidth) {
this.charBackgroundBorder = charBackgroundBorder;
this.charBackgroundBorderColor = charBackgroundBorderColor;
this.charBackgroundBorderDividerColor = charBackgroundBorderDividerColor;
this.charBackgroundBorderDividerWidth = charBackgroundBorderDividerWidth;
}
public Boolean getCharBackgroundBorder() {
return charBackgroundBorder;
}
public void setCharBackgroundBorder(Boolean charBackgroundBorder) {
this.charBackgroundBorder = charBackgroundBorder;
}
public Integer getCharBackgroundBorderColor() {
return charBackgroundBorderColor;
}
public void setCharBackgroundBorderColor(Integer charBackgroundBorderColor) {
this.charBackgroundBorderColor = charBackgroundBorderColor;
}
public Integer getCharBackgroundBorderDividerColor() {
return charBackgroundBorderDividerColor;
}
public void setCharBackgroundBorderDividerColor(Integer charBackgroundBorderDividerColor) {
this.charBackgroundBorderDividerColor = charBackgroundBorderDividerColor;
}
public Integer getCharBackgroundBorderDividerWidth() {
return charBackgroundBorderDividerWidth;
}
public void setCharBackgroundBorderDividerWidth(Integer charBackgroundBorderDividerWidth) {
this.charBackgroundBorderDividerWidth = charBackgroundBorderDividerWidth;
}
}

View File

@ -47,8 +47,22 @@ public class TabDigit {
private int width,hight;
private boolean charDrawCenter;
private TabConfig tabConfig;
public TabDigit(String currentChar, String nextChar,boolean mReverseRotation) {
this(currentChar,nextChar,mReverseRotation,false);
}
public TabDigit(String currentChar, String nextChar,boolean mReverseRotation,boolean charDrawCenter) {
this(currentChar,nextChar,mReverseRotation,charDrawCenter,new TabConfig(false,Color.BLACK,Color.BLACK,3));
}
public TabDigit(String currentChar, String nextChar,boolean mReverseRotation,boolean charDrawCenter,TabConfig tabConfig) {
this.mReverseRotation = mReverseRotation;
this.charDrawCenter=charDrawCenter;
this.tabConfig=tabConfig;
init(currentChar,nextChar);
}
@ -70,31 +84,31 @@ public class TabDigit {
mNumberPaint = new Paint();
mNumberPaint.setAntiAlias(true);
mNumberPaint.setStyle(Paint.Style.FILL_AND_STROKE);
mNumberPaint.setColor(Color.WHITE);
mNumberPaint.setColor(Color.BLACK);
mDividerPaint = new Paint();
mDividerPaint.setAntiAlias(true);
mDividerPaint.setStyle(Paint.Style.FILL_AND_STROKE);
mDividerPaint.setColor(Color.WHITE);
mDividerPaint.setStrokeWidth(1);
mDividerPaint.setColor(tabConfig.getCharBackgroundBorderDividerColor());
mDividerPaint.setStrokeWidth(tabConfig.getCharBackgroundBorderDividerWidth());
mBackgroundPaint = new Paint();
mBackgroundPaint.setAntiAlias(true);
mBackgroundPaint.setColor(Color.BLACK);
mBackgroundPaint.setColor(tabConfig.getCharBackgroundBorderColor());
}
private void initTabs() {
// top Tab
mTopTab = new TabDigitEntity(currentChar,nextChar,mProjectionMatrix,mCornerSize);
mTopTab = new TabDigitEntity(currentChar,nextChar,mProjectionMatrix,mCornerSize,charDrawCenter);
mTopTab.rotate(180);
tabs.add(mTopTab);
// bottom Tab
mBottomTab = new TabDigitEntity(currentChar,nextChar,mProjectionMatrix,mCornerSize);
mBottomTab = new TabDigitEntity(currentChar,nextChar,mProjectionMatrix,mCornerSize,charDrawCenter);
tabs.add(mBottomTab);
// middle Tab
mMiddleTab = new TabDigitEntity(currentChar,nextChar,mProjectionMatrix,mCornerSize);
mMiddleTab = new TabDigitEntity(currentChar,nextChar,mProjectionMatrix,mCornerSize,charDrawCenter);
tabs.add(mMiddleTab);
tabAnimation = mReverseRotation ? new TabAnimationDown(mTopTab, mBottomTab, mMiddleTab) : new TabAnimationUp(mTopTab, mBottomTab, mMiddleTab);
@ -106,6 +120,10 @@ public class TabDigit {
public void setmNumberPaint(Paint mNumberPaint){
this.mNumberPaint=mNumberPaint;
calculateTextMeasured();
}
public void calculateTextMeasured(){
calculateTextSize(mTextMeasured);
width=mTextMeasured.width();
hight=mTextMeasured.height();
@ -134,7 +152,7 @@ public class TabDigit {
private void drawTabs(Canvas canvas) {
for (TabDigitEntity tab : tabs) {
tab.draw(canvas,mTextMeasured,mNumberPaint,mBackgroundPaint);
tab.draw(canvas,mTextMeasured,mNumberPaint,tabConfig.getCharBackgroundBorder()?mBackgroundPaint:null,(int)mDividerPaint.getStrokeWidth());
}
}
@ -142,12 +160,21 @@ public class TabDigit {
canvas.save();
canvas.concat(mProjectionMatrix);
//canvas.drawLine(-canvas.getWidth() / 2, 0, canvas.getWidth() / 2, 0, mDividerPaint);
canvas.drawLine(-width / 2, 0, width / 2, 0, mDividerPaint);
//canvas.drawLine(-width / 2, 0, width / 2, 0, mDividerPaint);
canvas.drawLine(-width / 2+mDividerPaint.getStrokeWidth(), 0, width / 2-mDividerPaint.getStrokeWidth(), 0, mDividerPaint);
canvas.restore();
}
private void calculateTextSize(Rect rect) {
mNumberPaint.getTextBounds("8", 0, 1, rect);
//System.out.println("rect left:"+rect.left+"\ttop:"+rect.top+"\tright:"+rect.right+"\t bottom:"+rect.bottom);
int width=getCharWidth("8",mNumberPaint);
int hight=(int)getFontHeight(mNumberPaint);
int left=rect.left-(width-rect.width())/2;
int right=rect.right+(width-rect.width())/2;
int top=rect.top-(hight-rect.height())/2;
int bottom=rect.bottom+(hight-rect.height())/2;
rect.set(left,top,right,bottom);
}
public void setTextSize(int size) {
@ -200,7 +227,8 @@ public class TabDigit {
public void onDraw(Canvas canvas) {
drawTabs(canvas);
//drawDivider(canvas);
if(tabConfig.getCharBackgroundBorder())
drawDivider(canvas);
}
public void run() {
@ -215,4 +243,13 @@ public class TabDigit {
return tabAnimation.isRunning();
}
public static int getCharWidth(String str, Paint paint) {
return (int) paint.measureText(str);
}
public static float getFontHeight(Paint paint) {
Paint.FontMetrics fm = paint.getFontMetrics();
return fm.bottom - fm.top;
}
}

View File

@ -30,13 +30,18 @@ public class TabDigitEntity {
private int mCornerSize;
private boolean charDrawCenter;
public TabDigitEntity(String currentChar, String nextChar,Matrix mProjectionMatrix,int mCornerSize) {
private int startX;
public TabDigitEntity(String currentChar, String nextChar,Matrix mProjectionMatrix,int mCornerSize,boolean charDrawCenter) {
this.currentChar = currentChar;
this.beforChar=currentChar;
this.nextChar = nextChar;
this.mProjectionMatrix=mProjectionMatrix;
this.mCornerSize=mCornerSize;
this.charDrawCenter=charDrawCenter;
}
public void measure(int width, int height) {
@ -81,12 +86,13 @@ public class TabDigitEntity {
MatrixHelper.rotateX(mRotationModelViewMatrix, alpha);
}
public void draw(Canvas canvas, Rect mTextMeasured,Paint mNumberPaint,Paint mBackgroundPaint) {
//drawBackground(canvas,mBackgroundPaint);
public void draw(Canvas canvas, Rect mTextMeasured,Paint mNumberPaint,Paint mBackgroundPaint,int dividerStrokeWidth) {
if(mBackgroundPaint!=null)
drawBackground(canvas,mBackgroundPaint,dividerStrokeWidth);
drawText(canvas, mTextMeasured, mNumberPaint);
}
private void drawBackground(Canvas canvas,Paint mBackgroundPaint) {
private void drawBackground(Canvas canvas,Paint mBackgroundPaint,int dividerStrokeWidth) {
canvas.save();
mModelViewMatrix.set(mRotationModelViewMatrix);
applyTransformation(canvas, mModelViewMatrix);
@ -104,7 +110,10 @@ public class TabDigitEntity {
}
applyTransformation(canvas, mModelViewMatrix);
canvas.clipRect(clip);
canvas.drawText(currentChar, 0, 1, -mTextMeasured.centerX(), -mTextMeasured.centerY(), mNumberPaint);
startX=-mTextMeasured.centerX();
if(charDrawCenter)
startX+=(mTextMeasured.width()-getCharWidth(currentChar,mNumberPaint))/2;
canvas.drawText(currentChar, 0, 1,startX , -mTextMeasured.centerY(), mNumberPaint);
canvas.restore();
}
@ -113,4 +122,9 @@ public class TabDigitEntity {
mModelViewProjectionMatrix.setConcat(mProjectionMatrix, matrix);
canvas.concat(mModelViewProjectionMatrix);
}
public static int getCharWidth(String str, Paint paint) {
return (int) paint.measureText(str);
}
}

View File

@ -73,7 +73,7 @@
android:id="@+id/text_style_group2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginTop="3dp"
android:layout_below="@id/text_style_group1"
android:orientation="horizontal">
@ -136,6 +136,13 @@
android:layout_weight="1"
android:text="底框色" />
<Button
android:id="@+id/tv_textStyle_border_divider_color"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="分割线" />
</LinearLayout>
<LinearLayout
@ -304,4 +311,25 @@
android:text="主题4" />
</LinearLayout>
<com.jaygoo.widget.VerticalRangeSeekBar
android:id="@+id/tv_time_text_basline_down"
android:layout_width="60dp"
android:layout_height="match_parent"
android:layout_above="@id/text_style_group4"
android:layout_below="@id/text_style_group2"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="30dp"
app:rsb_mode="single"
app:rsb_gravity="center"
app:rsb_progress_radius="4dp"
app:rsb_thumb_width="40dp"
app:rsb_thumb_height="40dp"
app:rsb_tick_mark_mode="other"
app:rsb_tick_mark_gravity="center"
app:rsb_min="0"
app:rsb_max="200"
app:rsb_min_interval="5"
/>
</RelativeLayout>