mirror of
https://gitee.com/51danju/workclock.git
synced 2025-06-08 03:44:05 +08:00
可以进入全屏模拟走钟样式,及更多背景动画
This commit is contained in:
parent
cac96e3f43
commit
69beeb73d8
@ -133,7 +133,7 @@ public class MainActivity extends Activity implements Handler.Callback, View.OnC
|
||||
fontStyleList.add(new TimeFontStyle("affair",110,120,130,150));
|
||||
fontStyleList.add(new TimeFontStyle("agenda",140,150,160,180));
|
||||
|
||||
fontStyleList.add(new TimeFontStyle("cheapfire",110,120,130,150));
|
||||
fontStyleList.add(new TimeFontStyle("cheapfire",140,150,160,180));
|
||||
fontStyleList.add(new TimeFontStyle("cherif",80,100,110,140));
|
||||
fontStyleList.add(new TimeFontStyle("Cigar Box Guitar",120,130,140,150));
|
||||
fontStyleList.add(new TimeFontStyle("Ciung Wanara Sejati",110,120,130,150));
|
||||
@ -176,9 +176,9 @@ public class MainActivity extends Activity implements Handler.Callback, View.OnC
|
||||
fontStyleList.add(new TimeFontStyle("Xtra Power",100,110,120,160));
|
||||
|
||||
fontStyleList.add(new TimeFontStyle("海报圆圆",110,120,130,150));
|
||||
fontStyleList.add(new TimeFontStyle("爱心小兔",80,100,110,140));
|
||||
fontStyleList.add(new TimeFontStyle("爱心小兔",110,115,130,140));
|
||||
fontStyleList.add(new TimeFontStyle("王漢宗海報體一半天水",110,120,130,150));
|
||||
fontStyleList.add(new TimeFontStyle("立体铁山硬笔行楷简",110,120,130,150));
|
||||
fontStyleList.add(new TimeFontStyle("立体铁山硬笔行楷简",120,130,140,180));
|
||||
fontStyleList.add(new TimeFontStyle("腾祥倩心简",110,120,130,150));
|
||||
fontStyleList.add(new TimeFontStyle("苏新诗毛糙体简",110,120,130,150));
|
||||
fontStyleList.add(new TimeFontStyle("谁能许我扶桑花期",110,120,130,150));
|
||||
@ -238,12 +238,11 @@ public class MainActivity extends Activity implements Handler.Callback, View.OnC
|
||||
}
|
||||
|
||||
private void setFontSize(int fontSize){
|
||||
tv_time.setText("", TextView.BufferType.NORMAL);
|
||||
tv_time.setTextSize(fontSize);
|
||||
}
|
||||
|
||||
|
||||
private TextView tv_time;
|
||||
private DigitTextView tv_time;
|
||||
private TextView tv_date;
|
||||
private TextView tv_day;
|
||||
private TextView tv_weather;
|
||||
@ -1206,26 +1205,26 @@ public class MainActivity extends Activity implements Handler.Callback, View.OnC
|
||||
clockAnimator = new ClockAnimator();
|
||||
clockAnimator.init(clockView.getContext(),clockView);
|
||||
clockAnimator.setColor(foregroundColor);
|
||||
if(index>5)
|
||||
if(index>4)
|
||||
currentClockAnimatorIndex=index=0;
|
||||
|
||||
switch (index) {
|
||||
case 0:
|
||||
clockAnimator.setClock(new CircleClock());
|
||||
break;
|
||||
case 3:
|
||||
case 2:
|
||||
clockAnimator.setClock(new OvalClock());
|
||||
break;
|
||||
case 2:
|
||||
case 1:
|
||||
clockAnimator.setClock(new SquareClock());
|
||||
break;
|
||||
case 1:
|
||||
clockAnimator.setClock(new OctagonalClock());
|
||||
break;
|
||||
case 4:
|
||||
//case 3:
|
||||
// clockAnimator.setClock(new OctagonalClock());
|
||||
// break;
|
||||
case 3:
|
||||
clockAnimator.setClock(new HexagonalClock());
|
||||
break;
|
||||
case 5:
|
||||
case 4:
|
||||
clockAnimator.setClock(new HelixClock());
|
||||
break;
|
||||
default:
|
||||
@ -1371,42 +1370,19 @@ public class MainActivity extends Activity implements Handler.Callback, View.OnC
|
||||
}
|
||||
}
|
||||
|
||||
DigitTextView.DigitSpan digitSpan,digitSpan1;
|
||||
DigitTextView.DigitSmallSpan digitSpan2;
|
||||
SpannableString spannable;
|
||||
DigitTextView.DigitFlagSpan digitFlagSpan;
|
||||
|
||||
private void setCurrentTimeToView(String timeString){
|
||||
if(isArtificialHiddle)
|
||||
return;
|
||||
spannable = new SpannableString(timeString);
|
||||
if(digitSpan==null) {
|
||||
digitSpan = new DigitTextView.DigitSpan();
|
||||
digitSpan1 = new DigitTextView.DigitSpan();
|
||||
digitSpan2 = new DigitTextView.DigitSmallSpan();
|
||||
digitFlagSpan=new DigitTextView.DigitFlagSpan();
|
||||
}
|
||||
if(isFullScreen){
|
||||
digitSpan.setBeseLineDown(0);
|
||||
digitSpan1.setBeseLineDown(0);
|
||||
digitFlagSpan.setBeseLineDown(0);
|
||||
digitSpan2.setBeseLineDown(0);
|
||||
tv_time.setBaseLineDown(0);
|
||||
}else{
|
||||
float baseLineDown=tv_date.getHeight()/2;
|
||||
digitSpan.setBeseLineDown(baseLineDown);
|
||||
digitSpan1.setBeseLineDown(baseLineDown);
|
||||
digitFlagSpan.setBeseLineDown(baseLineDown);
|
||||
digitSpan2.setBeseLineDown(baseLineDown);
|
||||
tv_time.setBaseLineDown(tv_day.getHeight()/2);
|
||||
}
|
||||
spannable.setSpan(digitSpan,0,2,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
spannable.setSpan(digitFlagSpan,2,3,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
spannable.setSpan(digitSpan1,3,5,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
if(timeString.length()>5)
|
||||
spannable.setSpan(digitSpan2,5,8,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
//tv_time.setText(spannable, TextView.BufferType.SPANNABLE);
|
||||
tv_time.setText(spannable, TextView.BufferType.NORMAL);
|
||||
//tv_time.setText(timeString);
|
||||
tv_time.setText(timeString);
|
||||
}
|
||||
|
||||
|
||||
boolean heartbeat=false;
|
||||
private void updateTime() {
|
||||
heartbeat=!heartbeat;
|
||||
|
@ -1,21 +1,19 @@
|
||||
package clock.socoolby.com.clock.widget.textview;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.os.Build;
|
||||
import android.text.TextPaint;
|
||||
import android.text.style.ReplacementSpan;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.RequiresApi;
|
||||
|
||||
@SuppressLint("AppCompatCustomView")
|
||||
public class DigitTextView extends TextView {
|
||||
public class DigitTextView extends android.support.v7.widget.AppCompatTextView {
|
||||
public static final String Tag=DigitTextView.class.getSimpleName();
|
||||
|
||||
float baseLineDown=0;
|
||||
|
||||
public DigitTextView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
@ -28,9 +26,69 @@ public class DigitTextView extends TextView {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||
public DigitTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
public void setBaseLineDown(float baseLineDown) {
|
||||
this.baseLineDown = baseLineDown;
|
||||
}
|
||||
|
||||
protected void onDraw(Canvas canvas) {
|
||||
int color = getCurrentTextColor();
|
||||
|
||||
Paint mTextPaint=getPaint();
|
||||
|
||||
mTextPaint.setColor(color);
|
||||
|
||||
CharSequence textToDraw=getText();
|
||||
|
||||
Paint.FontMetricsInt fm=mTextPaint.getFontMetricsInt();
|
||||
|
||||
int baseCharWidth= getCharWidth("8",mTextPaint);
|
||||
int flagCharwidth=getCharWidth(":",mTextPaint);
|
||||
int textHight=-fm.descent - fm.ascent;
|
||||
int smallTextHight=0;
|
||||
int smallCharWidth=0;
|
||||
Paint smallCharPaint=null;
|
||||
|
||||
int textLength=textToDraw.length();
|
||||
int textWidth=0;
|
||||
int textSmallSpan=0;
|
||||
|
||||
|
||||
if(textLength>4){
|
||||
textWidth=baseCharWidth*4+flagCharwidth;
|
||||
}
|
||||
if(textLength>7){
|
||||
float fontScale = getResources().getDisplayMetrics().scaledDensity;
|
||||
smallCharPaint = getCustomTextPaint(mTextPaint,mTextPaint.getTextSize()/fontScale*4/5);
|
||||
smallCharWidth=getCharWidth("8",smallCharPaint);
|
||||
fm=smallCharPaint.getFontMetricsInt();
|
||||
smallTextHight=-fm.descent - fm.ascent;
|
||||
textSmallSpan=smallCharWidth*2;
|
||||
}
|
||||
|
||||
float startX=(getWidth()-textWidth-textSmallSpan)/2;
|
||||
float startY=(getHeight()+textHight)/2;
|
||||
|
||||
for(int i=0;i<textLength;i++){
|
||||
String c=String.valueOf(textToDraw.charAt(i));
|
||||
int charWidth= getCharWidth("8",mTextPaint);
|
||||
if(i<5){
|
||||
if(i==2){
|
||||
canvas.drawText(c, startX, startY+baseLineDown, mTextPaint);
|
||||
startX+=flagCharwidth;
|
||||
}else{
|
||||
canvas.drawText(c, startX+(baseCharWidth-charWidth)/2, startY+baseLineDown, mTextPaint);
|
||||
startX+=baseCharWidth;
|
||||
}
|
||||
}else if(i==5) {
|
||||
startX+=smallCharWidth/2;
|
||||
} else {
|
||||
float centerY=(getHeight()+smallTextHight)/2;
|
||||
centerY=centerY+(startY-centerY)/2+smallCharPaint.getFontMetrics().descent;
|
||||
canvas.drawText(c, startX, centerY+baseLineDown, smallCharPaint);
|
||||
startX+=smallCharWidth;
|
||||
Log.d(Tag,"view hight:"+getHeight()+"\t startY:"+startY+"\t text hight:"+textHight+"small text hight:"+smallTextHight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -118,7 +176,7 @@ public class DigitTextView extends TextView {
|
||||
String text1 = text.subSequence(start, end).toString();
|
||||
//Log.d("DigitSpan","getSize text:"+text+"\tstart:"+start+"\tend:"+end+"\tsubStr:"+text1);
|
||||
fontSizeSp=paint.getTextSize()/2;
|
||||
Paint p = getCustomTextPaint(paint);
|
||||
Paint p = getCustomTextPaint(paint,fontSizeSp);
|
||||
return (int) getCharWidth("8",p)*text1.length();
|
||||
}
|
||||
|
||||
@ -131,7 +189,7 @@ public class DigitTextView extends TextView {
|
||||
return;
|
||||
//Log.d("DigitSpan","draw text:"+text+"\tstart:"+start+"\tend:"+end+"\tsubStr:"+text1);
|
||||
Paint.FontMetricsInt fmBefor=paint.getFontMetricsInt();
|
||||
Paint p = getCustomTextPaint(paint);
|
||||
Paint p = getCustomTextPaint(paint,fontSizeSp);
|
||||
Paint.FontMetricsInt fm = p.getFontMetricsInt();
|
||||
int baseCharWitch= getCharWidth("8",p);
|
||||
for(int i=1;i<text1.length();i++) {
|
||||
@ -143,17 +201,18 @@ public class DigitTextView extends TextView {
|
||||
}
|
||||
}
|
||||
|
||||
private TextPaint getCustomTextPaint(Paint srcPaint) {
|
||||
TextPaint paint = new TextPaint(srcPaint);
|
||||
paint.setTextSize(fontSizeSp); //设定字体大小, sp转换为px
|
||||
return paint;
|
||||
}
|
||||
|
||||
public void setBeseLineDown(float beseLineDown){
|
||||
this.beseLineDown=beseLineDown;
|
||||
}
|
||||
}
|
||||
|
||||
private static TextPaint getCustomTextPaint(Paint srcPaint,float fontSizeSp) {
|
||||
TextPaint paint = new TextPaint(srcPaint);
|
||||
paint.setTextSize(fontSizeSp); //设定字体大小, sp转换为px
|
||||
return paint;
|
||||
}
|
||||
|
||||
|
||||
public static class SuperSubSpan extends ReplacementSpan
|
||||
{
|
||||
|
@ -213,14 +213,13 @@ public class SmashAnimator {
|
||||
public void startRandomAnimator(){
|
||||
Random random=new Random();
|
||||
mStyle=random.nextInt(STYLE_MAX_ID);
|
||||
//if(mStyle<=0)
|
||||
// mStyle=1;
|
||||
if(mStyle<RANDOM_EFFECT_TYPE_SQUARE)
|
||||
mStyle=RANDOM_EFFECT_TYPE_SQUARE+random.nextInt(3);
|
||||
if(mStyle<=0)
|
||||
mStyle=1;
|
||||
//if(mStyle<RANDOM_EFFECT_TYPE_SQUARE)
|
||||
// mStyle=RANDOM_EFFECT_TYPE_SQUARE+random.nextInt(3);
|
||||
if(mStyle>= RANDOM_EFFECT_TYPE_SQUARE){
|
||||
mEndValue=1.0f;
|
||||
mStartDelay=0;
|
||||
//mDuration=mDuration*2;
|
||||
mValueAnimator.setFloatValues(0F, mEndValue);
|
||||
initCurtainEffect(mStyle);
|
||||
mAnimatorView.setVisibility(View.GONE);
|
||||
|
@ -31,15 +31,6 @@
|
||||
android:background="#00FFFFFF"
|
||||
>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_time"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_centerInParent="true"
|
||||
android:gravity="center"
|
||||
android:textColor="#fff"
|
||||
android:textSize="180sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_handup_image"
|
||||
android:layout_width="match_parent"
|
||||
@ -222,7 +213,17 @@
|
||||
android:src="@drawable/ic_settings_black_24dp"
|
||||
android:visibility="gone" />
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
||||
</RelativeLayout>
|
||||
|
||||
<clock.socoolby.com.clock.widget.textview.DigitTextView
|
||||
android:id="@+id/tv_time"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:textColor="#fff"
|
||||
/>
|
||||
|
||||
|
||||
<clock.socoolby.com.clock.widget.animatorview.AnimatorView
|
||||
android:id="@+id/tv_foreground_animatorview"
|
||||
android:layout_width="match_parent"
|
||||
|
BIN
workclock.apk
BIN
workclock.apk
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user