1
0
mirror of https://gitee.com/51danju/workclock.git synced 2025-06-28 13:12:48 +08:00

代码重构初始

This commit is contained in:
wushunlian 2019-06-10 18:00:20 +08:00
parent 55f40bd4dc
commit 5d7da6d793
129 changed files with 4643 additions and 1458 deletions

0
CHANGELOG.md Normal file
View File

View File

@ -653,9 +653,9 @@ Also add information on how to contact you by electronic and paper mail.
notice like this when it starts in an interactive mode:
{project} Copyright (C) {year} {fullname}
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This program comes with ABSOLUTELY NO WARRANTY; for details typeCode `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
under certain conditions; typeCode `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands

View File

@ -94,7 +94,7 @@ An Android clock [下载](#直接下载)
其它在设置页设置
<img src="https://raw.githubusercontent.com/socoolby/CoolClock/master/demonstrate.gif" width="320" height="568"/>
<img src="/screenshot/demonstrate.gif" width="320" height="568"/>
6.0系统以下,可以用 近身感应锁屏。 在屏锁状态下无效

View File

@ -20,33 +20,51 @@ android {
productFlavors {
}
compileOptions {
sourceCompatibility = '1.7'
targetCompatibility = '1.7'
sourceCompatibility = '1.7'
targetCompatibility = '1.7'
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.13-beta-2'
implementation 'com.mcxiaoke.volley:library:1.0.19'
implementation 'com.github.razerdp:BasePopup:2.1.8'
implementation 'com.haibin:calendarview:3.5.3'
implementation 'androidx.annotation:annotation:1.0.1'
implementation('com.github.bumptech.glide:glide:4.8.0'){
implementation 'com.github.razerdp:BasePopup:2.2.0'
//BasePopup androidx支持库androidX版本
//implementation 'com.github.razerdp:BasePopup-compat-androidx:2.1.8'
implementation 'com.haibin:calendarview:3.6.2'
implementation 'androidx.annotation:annotation:1.0.2'
implementation('com.github.bumptech.glide:glide:4.8.0') {
exclude group: "com.android.support"
}
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.blankj:utilcode:1.23.4'
implementation 'com.blankj:utilcode:1.23.7'
implementation 'com.larswerkman:HoloColorPicker:1.5'
//implementation 'com.daimajia.easing:library:2.0@aar'
implementation ('com.github.LuckSiege.PictureSelector:picture_library:v2.2.3'){
implementation('com.github.LuckSiege.PictureSelector:picture_library:v2.2.3') {
exclude group: "com.github.bumptech.glide"
}
// ViewModel and LiveData
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
implementation('com.gitee.51danju.e-odbo:e-odbo-jdbc:V1.0-beta.1')
{
exclude(group: 'org.apache.logging.log4j', module: 'log4j-core')
}
implementation 'org.sqldroid:sqldroid:1.1.0-rc1'
implementation "com.github.DeweyReed:UltimateMusicPicker:2.0.4"
}

View File

@ -11,7 +11,8 @@
android:sharedUserId="android.uid.system"
android:name=".ClockApplication"
tools:replace="android:theme"
android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen">
android:theme="@style/Theme.AppCompat.Light.NoActionBar.FullScreen">
<activity android:name=".MainActivity" android:screenOrientation="sensorLandscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

View File

@ -1,7 +1,7 @@
package clock.socoolby.com.clock;
import android.app.Activity;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.widget.TextView;
import clock.socoolby.com.clock.utils.FuncUnit;
@ -11,7 +11,7 @@ import clock.socoolby.com.clock.utils.FuncUnit;
* Created by socoolby on 04/01/2017.
*/
public class AboutActivity extends Activity {
public class AboutActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {

View File

@ -12,6 +12,7 @@ import clock.socoolby.com.clock.protocol.BusinessService;
import clock.socoolby.com.clock.model.DateModel;
import clock.socoolby.com.clock.utils.FileUtils;
import clock.socoolby.com.clock.model.SharePerferenceModel;
import e.odbo.data.dao.EntityManager;
public class ClockApplication extends Application {
@ -23,13 +24,16 @@ public class ClockApplication extends Application {
return sEndzoneBoxApp;
}
SharePerferenceModel model;
EntityManager entityManager;
@Override
public void onCreate() {
super.onCreate();
sEndzoneBoxApp = this;
Utils.init(this);
init();
}
@ -51,9 +55,8 @@ public class ClockApplication extends Application {
Log.d("app","supported permission denied...");
}
}).request();
model = new SharePerferenceModel();
if (!FileUtils.isExistsFile(Constants.SHARE_PERFERENCE_FILE)) {
SharePerferenceModel model = new SharePerferenceModel();
model.setTypeHourPower(Constants.TALKING_HOURS);
DateModel startTimeModel = new DateModel();
startTimeModel.setTime(12, 31);
@ -61,9 +64,8 @@ public class ClockApplication extends Application {
stopTimeModel.setTime(14, 31);
model.setStartHourPowerTime(startTimeModel);
model.setStopHourPowerTime(stopTimeModel);
model.setCity(getString(R.string.shenzhen));
model.save();
}
}else
model.read();
}
public static Context getContext() {
@ -84,4 +86,11 @@ public class ClockApplication extends Application {
return mMainActivity;
}
public SharePerferenceModel getModel() {
return model;
}
public EntityManager getEntityManager(){
return entityManager;
}
}

View File

@ -1,51 +0,0 @@
package clock.socoolby.com.clock;
import android.app.Activity;
import android.os.Handler;
import android.os.Message;
import android.view.MotionEvent;
import android.view.View;
public class CountDownActivity extends Activity implements Handler.Callback, View.OnClickListener, android.view.GestureDetector.OnGestureListener {
@Override
public boolean handleMessage(Message message) {
return false;
}
@Override
public boolean onDown(MotionEvent motionEvent) {
return false;
}
@Override
public void onShowPress(MotionEvent motionEvent) {
}
@Override
public boolean onSingleTapUp(MotionEvent motionEvent) {
return false;
}
@Override
public boolean onScroll(MotionEvent motionEvent, MotionEvent motionEvent1, float v, float v1) {
return false;
}
@Override
public void onLongPress(MotionEvent motionEvent) {
}
@Override
public boolean onFling(MotionEvent motionEvent, MotionEvent motionEvent1, float v, float v1) {
return false;
}
@Override
public void onClick(View view) {
}
}

View File

@ -1,49 +0,0 @@
package clock.socoolby.com.clock;
import android.app.Activity;
import android.os.Handler;
import android.os.Message;
import android.view.MotionEvent;
import android.view.View;
public class CountingActivity extends Activity implements Handler.Callback, View.OnClickListener, android.view.GestureDetector.OnGestureListener{
@Override
public boolean handleMessage(Message message) {
return false;
}
@Override
public boolean onDown(MotionEvent motionEvent) {
return false;
}
@Override
public void onShowPress(MotionEvent motionEvent) {
}
@Override
public boolean onSingleTapUp(MotionEvent motionEvent) {
return false;
}
@Override
public boolean onScroll(MotionEvent motionEvent, MotionEvent motionEvent1, float v, float v1) {
return false;
}
@Override
public void onLongPress(MotionEvent motionEvent) {
}
@Override
public boolean onFling(MotionEvent motionEvent, MotionEvent motionEvent1, float v, float v1) {
return false;
}
@Override
public void onClick(View view) {
}
}

View File

@ -0,0 +1,148 @@
package clock.socoolby.com.clock;
import java.util.ArrayList;
import java.util.List;
import clock.socoolby.com.clock.dao.base.TimeFontStyle;
public class FontManager {
private List<TimeFontStyle> fontStyleList;
private TimeFontStyle currentFontStyle;
private int currentFontIndex;
public FontManager() {
initTimeFontStyle();
currentFontIndex=0;
currentFontStyle=fontStyleList.get(currentFontIndex);
}
private void initTimeFontStyle(){
fontStyleList=new ArrayList<>();
fontStyleList.add(new TimeFontStyle("affair",110,120,130,150));
fontStyleList.add(new TimeFontStyle("agenda",140,150,160,180));
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));
fontStyleList.add(new TimeFontStyle("DK Bergelmir",120,130,140,180));
fontStyleList.add(new TimeFontStyle("ds_digi",140,150,160,200));
fontStyleList.add(new TimeFontStyle("Funk",110,120,130,150));
fontStyleList.add(new TimeFontStyle("GLADYS Regular",110,120,130,150));
fontStyleList.add(new TimeFontStyle("Granite Rock St",110,120,130,170));
fontStyleList.add(new TimeFontStyle("GROOT",120,130,140,170));
fontStyleList.add(new TimeFontStyle("juleslove",110,120,130,150));
fontStyleList.add(new TimeFontStyle("Kingthings Annexx",110,120,150,180));
fontStyleList.add(new TimeFontStyle("Kingthings Willow",110,120,130,150));
fontStyleList.add(new TimeFontStyle("KYLE Regular",110,120,130,150));
fontStyleList.add(new TimeFontStyle("LCD-U",130,140,150,180));
fontStyleList.add(new TimeFontStyle("loong07龙书势如破竹简",110,120,150,170));
fontStyleList.add(new TimeFontStyle("MILKDROP",110,120,130,160));
fontStyleList.add(new TimeFontStyle("Mosaicleaf086",110,120,130,150));
fontStyleList.add(new TimeFontStyle("Pro Display tfb",130,140,150,170));
fontStyleList.add(new TimeFontStyle("SailingJunco",130,140,150,200));
fontStyleList.add(new TimeFontStyle("scoreboard",120,130,140,190));
fontStyleList.add(new TimeFontStyle("SFWasabi-Bold",110,120,130,140));
fontStyleList.add(new TimeFontStyle("Spaghettica",110,120,130,150));
fontStyleList.add(new TimeFontStyle("the_vandor_spot",140,150,160,210));
fontStyleList.add(new TimeFontStyle("Woodplank",120,130,140,180));
fontStyleList.add(new TimeFontStyle("Xtra Power",100,110,120,160));
fontStyleList.add(new TimeFontStyle("海报圆圆",110,120,130,150));
fontStyleList.add(new TimeFontStyle("爱心小兔",110,115,130,140));
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));
fontStyleList.add(new TimeFontStyle("造字工房凌黑",110,120,130,150));
fontStyleList.add(new TimeFontStyle("中国龙新草体",110,120,130,150));
fontStyleList.add(new TimeFontStyle("迷你简剪纸_0",110,120,130,150));
}
public static final TimeFontStyle getDefaultFontSytle=new TimeFontStyle("ds_digi",140,150,160,200);
public int getCurrentFontSize(boolean isFullScreen,boolean isDisplaySecond){
int fontSize=currentFontStyle.displaySecond;
if(isFullScreen){
if(isDisplaySecond) {
fontSize=currentFontStyle.displaySecondOnFull;
}else{
fontSize=currentFontStyle.noDisplaySecondOnFull;
}
}else{
if(isDisplaySecond) {
fontSize=currentFontStyle.displaySecond;
}else{
fontSize=currentFontStyle.noDisplaySecond;
}
}
return fontSize;
}
public int getMaxFontSize(boolean isDisplaySecond){
int fontSize=currentFontStyle.displaySecond;
if(isDisplaySecond) {
fontSize=currentFontStyle.displaySecondOnFull;
}else{
fontSize=currentFontStyle.noDisplaySecondOnFull;
}
return fontSize;
}
public TimeFontStyle getCurrentFontStyle(){
return currentFontStyle;
}
public TimeFontStyle nextFont(){
if(currentFontIndex <fontStyleList.size()-1) {
currentFontIndex++;
}else
currentFontIndex =0;
currentFontStyle=fontStyleList.get(currentFontIndex);
return currentFontStyle;
}
public void setCurrentFontName(String name){
for(TimeFontStyle entry:fontStyleList)
if(entry.name.equalsIgnoreCase(name)){
currentFontStyle=entry;
}
}
public void updateCurrentFontSize(boolean isFullScreen,boolean isDisplaySecond,int newFontSize){
if(isFullScreen){
if(isDisplaySecond) {
currentFontStyle.displaySecondOnFull=newFontSize;
}else{
currentFontStyle.noDisplaySecondOnFull=newFontSize;
}
}else{
if(isDisplaySecond) {
currentFontStyle.displaySecond=newFontSize;
}else{
currentFontStyle.noDisplaySecond=newFontSize;
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,11 @@
package clock.socoolby.com.clock;
import android.app.Activity;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
@ -15,12 +15,12 @@ import android.widget.RadioButton;
import android.widget.RadioGroup;
import clock.socoolby.com.clock.model.DateModel;
import clock.socoolby.com.clock.utils.FuncUnit;
import clock.socoolby.com.clock.model.SharePerferenceModel;
import clock.socoolby.com.clock.utils.FuncUnit;
import clock.socoolby.com.clock.widget.wheelview.WheelView;
import clock.socoolby.com.clock.widget.wheelview.adapters.ArrayWheelAdapter;
public class SettingActivity extends Activity implements View.OnClickListener {
public class SettingActivity extends AppCompatActivity implements View.OnClickListener {
public static final String[] FAMOUS_QUOTES=new String[]{
"人生在勤,不索何获?——张衡",
@ -335,7 +335,6 @@ public class SettingActivity extends Activity implements View.OnClickListener {
reportTimeConfirm();
model.setCity(et_city.getText().toString());
model.setDescription(et_description.getText().toString());
model.save();
setResult(Constants.SUCCESS_CODE);
finish();
}

View File

@ -0,0 +1,718 @@
package clock.socoolby.com.clock;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.TextView;
import androidx.lifecycle.Observer;
import java.util.Timer;
import java.util.TimerTask;
import clock.socoolby.com.clock.dao.base.TimeFontStyle;
import clock.socoolby.com.clock.model.SharePerferenceModel;
import clock.socoolby.com.clock.pop.CalendarPopup;
import clock.socoolby.com.clock.pop.ColorPickerPop;
import clock.socoolby.com.clock.pop.TimeSetupPopup;
import clock.socoolby.com.clock.pop.WeatherPopup;
import clock.socoolby.com.clock.state.ClockInterfaceTypeEnum;
import clock.socoolby.com.clock.state.ClockThemeUITypeEnum;
import clock.socoolby.com.clock.utils.FontUtils;
import clock.socoolby.com.clock.viewmodel.DigitViewModel;
import clock.socoolby.com.clock.viewmodel.GlobalViewModel;
import clock.socoolby.com.clock.viewmodel.SimulateViewModel;
import clock.socoolby.com.clock.viewmodel.ThemeUIViewModel;
import clock.socoolby.com.clock.widget.textview.AutoScrollTextView;
public class ThemeUIManager implements View.OnClickListener {
public static final String TAG = ThemeUIManager.class.getSimpleName();
private View themeRootView = null;
private TextView tv_date;
private TextView tv_day;
private TextView tv_weather;
private AutoScrollTextView tv_descript;
private ImageButton tv_setting;
private ImageButton tv_handup;
private ImageButton tv_hours_system;
private ImageButton tv_background_image_hand;
private ImageButton tv_break;
private ImageButton tv_clock_interface;
//颜色相关
private ImageButton tv_background_color;
private ImageButton tv_foreground_color;
private ImageButton tv_foreground_color1;
private TextView tv_hand_time;
//private boolean hand_time_visable=true;
private ImageButton tv_screen_lock;
private FrameLayout themeUIContainer;
ColorPickerPop colorPickerDialog;
TimeSetupPopup handUpTimePopup;
CalendarPopup calendarPopup;
WeatherPopup weatherPopup;
GlobalViewModel globalViewModel;
DigitViewModel digitViewModel;
SimulateViewModel simulateViewModel;
ThemeUIViewModel themeUIViewModel;
MainActivity mainActivity;
private SharePerferenceModel model;
private boolean autoFullScreen=false;
private int runDelaySecond=10000;
private boolean running=false;
Timer timer=null;
private void autoFullScreenCheck(){
if(!autoFullScreen)
return;
if(timer==null)
timer = new Timer();
if(running){
timer.cancel();
}
running=true;
Log.d("themeUiManager","autoFullScreen task created ...");
timer.schedule(new TimerTask() {
public void run() {
themeUIViewModel.setClockUITypeEnum(ClockThemeUITypeEnum.FULLSCREEN);
this.cancel();
}
}, runDelaySecond);
}
public ThemeUIManager(MainActivity mainActivity, GlobalViewModel globalViewModel, DigitViewModel digitViewModel, SimulateViewModel simulateViewModel, ThemeUIViewModel themeUIViewModel) {
this.themeUIContainer = mainActivity.getThemeUIContainer();
this.globalViewModel = globalViewModel;
this.digitViewModel = digitViewModel;
this.simulateViewModel = simulateViewModel;
this.themeUIViewModel = themeUIViewModel;
this.mainActivity = mainActivity;
this.model = ClockApplication.getInstance().getModel();
bindViewModel();
}
private void bindViewModel() {
themeUIViewModel.getThemeName().observe(mainActivity, new Observer<String>() {
@Override
public void onChanged(String s) {
switchThemeType(s);
}
});
themeUIViewModel.getClockUITypeEnum().observe(mainActivity, new Observer<ClockThemeUITypeEnum>() {
@Override
public void onChanged(ClockThemeUITypeEnum uiTypeEnum) {
switchMode(uiTypeEnum);
}
});
globalViewModel.getHourSystem12().observe(mainActivity, new Observer<Boolean>() {
@Override
public void onChanged(Boolean aBoolean) {
tv_hours_system.setVisibility(aBoolean ? View.VISIBLE : View.GONE);
}
});
globalViewModel.getTime_hour().observe(mainActivity, new Observer<Integer>() {
@Override
public void onChanged(Integer integer) {
tv_hours_system.setImageResource(integer > 12 ? R.drawable.ic_pm : R.drawable.ic_am);
}
});
themeUIViewModel.getDescription().observe(mainActivity, new Observer<String>() {
@Override
public void onChanged(String s) {
setDiscript(s);
}
});
globalViewModel.getForegroundColor().observe(mainActivity, new Observer<Integer>() {
@Override
public void onChanged(Integer integer) {
setForegroundColor(integer);
}
});
themeUIViewModel.getHand_time_visable().observe(mainActivity, new Observer<Boolean>() {
@Override
public void onChanged(Boolean aBoolean) {
tv_hand_time.setVisibility(aBoolean ? View.VISIBLE : View.GONE);
}
});
themeUIViewModel.getWeatherDescription().observe(mainActivity, new Observer<String>() {
@Override
public void onChanged(String s) {
tv_weather.setText(s);
}
});
themeUIViewModel.getWeekDescription().observe(mainActivity, new Observer<String>() {
@Override
public void onChanged(String s) {
tv_date.setText(s);
}
});
themeUIViewModel.getDayDescription().observe(mainActivity, new Observer<String>() {
@Override
public void onChanged(String s) {
tv_day.setText(s);
}
});
}
int currentThemeTypeId = -1;
private void switchThemeType(String themeType) {
switch (themeType) {
case "sample":
//themeBaseLine=-110;
currentThemeTypeId = R.layout.theme_sample;
break;
default:
//themeBaseLine=0;
currentThemeTypeId = R.layout.theme_default;
}
initTheme(mainActivity, currentThemeTypeId);
setForegroundColor(globalViewModel.getForegroundColor().getValue());
setDiscriptForModel();
tv_weather.setText(themeUIViewModel.getWeatherDescription().getValue());
tv_date.setText(themeUIViewModel.getWeekDescription().getValue());
tv_day.setText(themeUIViewModel.getDayDescription().getValue());
updateHourSystem();
updateColorSettingButtunColor();
configThemeUITypeWithNoFullScreen();
autoFullScreenCheck();
}
private void updateColorSettingButtunColor(){
tv_foreground_color.setColorFilter(model.getForegroundColor());
tv_foreground_color1.setColorFilter(model.getForegroundColor1());
}
private void initTheme(final Context context, int themeType) {
if (themeRootView != null) {
themeRootView.setVisibility(View.GONE);
themeUIContainer.removeView(themeRootView);
}
themeRootView = LayoutInflater.from(context).inflate(themeType, null, false);
themeUIContainer.addView(themeRootView);
tv_background_image_hand = themeRootView.findViewById(R.id.tv_background_image_hand);
tv_background_image_hand.setOnClickListener(this);
tv_background_image_hand.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
mainActivity.configBackGroundImage();
return true;
}
});
tv_date = themeRootView.findViewById(R.id.tv_date);
tv_date.setOnClickListener(this);
tv_date.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
if (currentThemeTypeId == R.layout.theme_default)
switchThemeType("sample");
else
switchThemeType("default");
return true;
}
});
tv_day = themeRootView.findViewById(R.id.tv_day);
tv_day.setOnClickListener(this);
tv_day.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
if (isScreenLock())
return true;
model.setHourSystem12(!model.isHourSystem12());
updateHourSystem();
return true;
}
});
tv_weather = themeRootView.findViewById(R.id.tv_weather);
tv_weather.setOnClickListener(this);
tv_descript = themeRootView.findViewById(R.id.tv_descript);
tv_descript.setOnClickListener(this);
tv_descript.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
//changeBackGroundAnimator(ANIMATOR_TEXTLED);
return true;
}
});
tv_break = themeRootView.findViewById(R.id.tv_break);
tv_break.setOnClickListener(this);
tv_break.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
/*if(handUpAbla){
if(showTimeType==ShowTimeType.COUNTING_DOWN)
setCurrentShowTimeType(ShowTimeType.TIME);
else
setCurrentShowTimeType(ShowTimeType.COUNTING_DOWN);
}*/
return true;
}
});
tv_handup = themeRootView.findViewById(R.id.tv_hand);
tv_handup.setOnClickListener(this);
tv_handup.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
if (isScreenLock())
return true;
setupHandUpTime();
return true;
}
});
tv_hand_time = themeRootView.findViewById(R.id.tv_hand_time);
tv_hand_time.setOnClickListener(this);
tv_hand_time.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
//hand_time_visable=false;
tv_hand_time.setVisibility(View.GONE);
return true;
}
});
tv_hours_system = themeRootView.findViewById(R.id.tv_hours_system);
tv_background_color = themeRootView.findViewById(R.id.tv_background_color);
tv_background_color.setOnClickListener(this);
tv_foreground_color = themeRootView.findViewById(R.id.tv_foreground_color);
tv_foreground_color.setOnClickListener(this);
tv_foreground_color.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
if (isScreenLock())
return true;
if (colorPickerDialog == null)
colorPickerDialog = new ColorPickerPop(mainActivity);
colorPickerDialog.setOnColorChangeListenter(new ColorPickerPop.OnColorListener() {
@Override
public void onEnsure(int color) {
model.setForegroundColor(color);
globalViewModel.setForegroundColor(color);
tv_foreground_color.setColorFilter(color);
autoFullScreenCheck();
}
@Override
public void onBack() {
}
});
colorPickerDialog.show(model.getForegroundColor());
return true;
}
});
tv_foreground_color1 = themeRootView.findViewById(R.id.tv_foreground_color1);
tv_foreground_color1.setOnClickListener(this);
tv_foreground_color1.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
if (isScreenLock())
return true;
if (colorPickerDialog == null)
colorPickerDialog = new ColorPickerPop(mainActivity);
colorPickerDialog.setOnColorChangeListenter(new ColorPickerPop.OnColorListener() {
@Override
public void onEnsure(int color) {
model.setForegroundColor1(color);
globalViewModel.setForegroundColor(color);
tv_foreground_color1.setColorFilter(color);
autoFullScreenCheck();
}
@Override
public void onBack() {
}
});
colorPickerDialog.show(model.getForegroundColor1());
return true;
}
});
tv_clock_interface = themeRootView.findViewById(R.id.tv_clock_interface);
tv_clock_interface.setOnClickListener(this);
tv_setting = themeRootView.findViewById(R.id.tv_setting);
tv_setting.setOnClickListener(this);
tv_screen_lock = themeRootView.findViewById(R.id.tv_screen_lock);
tv_screen_lock.setOnClickListener(this);
/*tv_screen_lock.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
if(!isFullScreen()){
screenLock(true);
themeUIViewModel.setClockUITypeEnum(ClockThemeUITypeEnum.FULLSCREEN);
return true;
}
return false;
}
});*/
tv_descript.init(mainActivity, false);
}
private boolean isScreenLock() {
return globalViewModel.getSrceenLock().getValue();
}
private boolean isHandUpAble() {
return globalViewModel.getHandUpAble().getValue();
}
private void updateHourSystem() {
if (model.isHourSystem12())
tv_hours_system.setVisibility(View.VISIBLE);
else
tv_hours_system.setVisibility(View.GONE);
}
//handUp
private void upHandStatic() {
/*if(handUpAbla) {
if(foregroundColor!=null)
this.tv_handup.setColorFilter(foregroundColor);
hand_time_visable=true;
this.tv_hand_time.setVisibility(View.VISIBLE);
}else{
this.tv_handup.setColorFilter(R.color.colorPrimaryDark);
this.tv_hand_time.setVisibility(View.GONE);
if(showTimeType==ShowTimeType.COUNTING_DOWN)
setCurrentShowTimeType(ShowTimeType.TIME);
}*/
}
private void setupHandUpTime() {
/*int saveHandUpTime=model.getHandUpTime();
int hour=0;
int minute=0;
if(handUpTimePopup==null) {
handUpTimePopup = new TimeSetupPopup(this);
handUpTimePopup.setOnSeekBarChangeListener(new TimeSetupPopup.OnTimeChangeListener() {
@Override
public void onChanged(int hour, int minute) {
model.setHandUpTime(hour*60+minute);
handUpAbla=true;
if(hour==0&&minute==0) {
handUpAbla = false;
model.setHandUpTime(-1);
}
saveData();
resetHandUpTime();
upHandStatic();
}
});
}
if(saveHandUpTime>0){
hour=saveHandUpTime/60;
minute=saveHandUpTime-hour*60;
}
handUpTimePopup.init(hour,minute);
handUpTimePopup.showPopupWindow();*/
}
private void setupTempHandUpTime() {
/*handUpAbla=false;
int hour=0;
int minute=0;
if(handUpTimePopup==null) {
handUpTimePopup = new TimeSetupPopup(this);
handUpTimePopup.setOnSeekBarChangeListener(new TimeSetupPopup.OnTimeChangeListener() {
@Override
public void onChanged(int hour, int minute) {
handUpTime=hour*60+minute;
}
});
}
hour=handUpTime/60;
minute=handUpTime-hour*60;
handUpTimePopup.init(hour,minute);
handUpTimePopup.showPopupWindow();
handUpAbla=true;*/
}
private void resetHandUpTime() {
/*this.handUpTime = model.getHandUpTime();
Log.d(TAG,"reset handUp time:"+handUpTime);
setDiscriptForModel();*/
}
//Discript
private void setDiscript(String disp) {
tv_descript.setText(disp);
tv_descript.startScrollIfAble();
}
private void setDiscriptForModel() {
String dis = model.getDescription();
if (dis == null || dis.isEmpty())
dis = SettingActivity.roundFamousQuotes();
setDiscript(dis);
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public void onClick(View view) {
if (isScreenLock() && view.getId() != R.id.tv_screen_lock && view.getId() != R.id.tv_handup_image) {
return;
}
switch (view.getId()) {
case R.id.tv_setting:
mainActivity.setup();
break;
case R.id.tv_hand:
/*if(!handUpAbla&&handUpTime<0) {
setupHandUpTime();
}else{
handUpAbla=!handUpAbla;
upHandStatic();
resetHandUpTime();
switchMode(MODE_NORMAL);
}*/
break;
case R.id.tv_hand_time:
setupTempHandUpTime();
break;
case R.id.tv_day:
digitViewModel.setDisplaySecond(!model.isDisplaySecond());
break;
case R.id.tv_date:
if (calendarPopup == null)
calendarPopup = new CalendarPopup(mainActivity);
calendarPopup.showPopupWindow();
calendarPopup.setCurrentDay();
break;
case R.id.tv_weather:
if (weatherPopup == null)
weatherPopup = new WeatherPopup(mainActivity);
weatherPopup.init(mainActivity.weatherAdape.getWeatherList(), model.getCity() + " PM2.5 : " + mainActivity.weatherAdape.getmPM25());
weatherPopup.showPopupWindow();
break;
case R.id.tv_screen_lock:
/*if(isFullScreen()) {
configThemeUITypeWithNoFullScreen();
}*/
globalViewModel.setSrceenLock(!isScreenLock());
screenLock(!isScreenLock());
break;
case R.id.tv_break:
/*if(showTimeType!= ClockTimeTypeEnum.COUNTING){
setCurrentShowTimeType(ClockTimeTypeEnum.COUNTING);
}else{
setCurrentShowTimeType(ClockTimeTypeEnum.TIME);
}*/
break;
case R.id.tv_descript:
setDiscript(SettingActivity.roundAutoQuotes());
break;
case R.id.tv_background_color:
if (colorPickerDialog == null)
colorPickerDialog = new ColorPickerPop(mainActivity);
colorPickerDialog.setOnColorChangeListenter(new ColorPickerPop.OnColorListener() {
@Override
public void onEnsure(int color) {
globalViewModel.setBackgroundColor(color);
}
@Override
public void onBack() {
}
});
colorPickerDialog.show(model.getBackgroundColor());
break;
case R.id.tv_background_image_hand:
if (globalViewModel.getBackgroundImageUri().getValue() == null)
mainActivity.configBackGroundImage();
else
globalViewModel.setBackgroundImageVisable(!globalViewModel.getBackgroundImageVisable().getValue());
break;
case R.id.tv_foreground_color:
globalViewModel.setForegroundColor(model.getForegroundColor());
break;
case R.id.tv_foreground_color1:
globalViewModel.setForegroundColor(model.getForegroundColor1());
break;
case R.id.tv_clock_interface:
changeClockInterface();
break;
}
autoFullScreenCheck();
}
protected void changeClockInterface() {
ClockInterfaceTypeEnum currentClockInterface = globalViewModel.getClockInterfaceTypeEnum().getValue();
switch (currentClockInterface) {
case Digit:
currentClockInterface = ClockInterfaceTypeEnum.Simulate;
break;
default:
currentClockInterface = ClockInterfaceTypeEnum.Digit;
}
globalViewModel.setClockInterfaceTypeEnum(currentClockInterface);
}
protected void setForegroundColor(Integer color) {
tv_date.setTextColor(color);
tv_day.setTextColor(color);
tv_weather.setTextColor(color);
tv_descript.setTextColor(color);
tv_handup.setColorFilter(color);
tv_screen_lock.setColorFilter(color);
tv_setting.setColorFilter(color);
tv_background_color.setColorFilter(color);
tv_hand_time.setTextColor(color);
tv_hours_system.setColorFilter(color);
tv_background_image_hand.setColorFilter(color);
tv_break.setColorFilter(color);
tv_clock_interface.setColorFilter(color);
}
private void switchMode(ClockThemeUITypeEnum mode) {
Log.d(TAG, "switch mode to:" + mode);
switch (mode) {
case FULLSCREEN:
tv_date.setVisibility(View.GONE);
tv_day.setVisibility(View.GONE);
tv_weather.setVisibility(View.GONE);
tv_descript.setVisibility(View.GONE);
tv_handup.setVisibility(View.GONE);
tv_setting.setVisibility(View.GONE);
tv_background_color.setVisibility(View.GONE);
tv_background_color.setVisibility(View.GONE);
tv_foreground_color.setVisibility(View.GONE);
tv_foreground_color1.setVisibility(View.GONE);
tv_background_image_hand.setVisibility(View.GONE);
tv_break.setVisibility(View.GONE);
tv_clock_interface.setVisibility(View.GONE);
tv_screen_lock.setVisibility(View.GONE);
break;
case NORMAL:
tv_date.setVisibility(View.VISIBLE);
tv_day.setVisibility(View.VISIBLE);
tv_weather.setVisibility(View.VISIBLE);
tv_descript.setVisibility(View.VISIBLE);
tv_handup.setVisibility(View.VISIBLE);
tv_break.setVisibility(View.VISIBLE);
tv_setting.setVisibility(View.GONE);
tv_background_color.setVisibility(View.GONE);
tv_foreground_color.setVisibility(View.GONE);
tv_foreground_color1.setVisibility(View.GONE);
tv_background_image_hand.setVisibility(View.GONE);
tv_clock_interface.setVisibility(View.GONE);
tv_screen_lock.setVisibility(View.VISIBLE);
break;
case SETTING:
tv_date.setVisibility(View.VISIBLE);
tv_day.setVisibility(View.VISIBLE);
tv_weather.setVisibility(View.VISIBLE);
tv_descript.setVisibility(View.VISIBLE);
tv_handup.setVisibility(View.VISIBLE);
tv_break.setVisibility(View.VISIBLE);
tv_setting.setVisibility(View.VISIBLE);
tv_background_color.setVisibility(View.VISIBLE);
tv_foreground_color.setVisibility(View.VISIBLE);
tv_foreground_color1.setVisibility(View.VISIBLE);
tv_background_image_hand.setVisibility(View.VISIBLE);
tv_clock_interface.setVisibility(View.VISIBLE);
tv_screen_lock.setVisibility(View.VISIBLE);
break;
}
}
private boolean isFullScreen(){
return themeUIViewModel.getClockUITypeEnum().getValue()==ClockThemeUITypeEnum.FULLSCREEN;
}
public void configThemeUITypeWithNoFullScreen(){
if(globalViewModel.getClockInterfaceTypeEnum().getValue()==ClockInterfaceTypeEnum.Digit)
themeUIViewModel.setClockUITypeEnum(ClockThemeUITypeEnum.NORMAL);
else
themeUIViewModel.setClockUITypeEnum(ClockThemeUITypeEnum.SETTING);
}
protected void reflushFontStyle(TimeFontStyle fontStyle) {
FontUtils.getInstance().replaceFontFromAsset(tv_date, "fonts/" + fontStyle.name + ".ttf");
}
public void screenLock(boolean locked) {
tv_screen_lock.setImageResource(locked ? R.drawable.ic_screen_lock : R.drawable.ic_screen_unlock);
}
}

View File

@ -0,0 +1,28 @@
package clock.socoolby.com.clock.alter;
import clock.socoolby.com.clock.model.DateModel;
public class AlterManager {
DateModel startTime;
DateModel stopTime;
public AlterManager(DateModel startTime, DateModel stopTime) {
this.startTime = startTime;
this.stopTime = stopTime;
}
public boolean isReport(int hour, int minute) {
DateModel nowTime = new DateModel();
nowTime.setTime(hour, minute);
if (startTime.getShortTimeString().equals(stopTime.getShortTimeString()))
return true;
long minutes = startTime.minusTime(stopTime);
if (minutes < 0) {//stop>start
if (nowTime.minusTime(startTime) >= 0 && nowTime.minusTime(stopTime) <= 0) {
return false;
}
}
return true;
}
}

View File

@ -0,0 +1,6 @@
package clock.socoolby.com.clock.dao.alter;
public class AlterEntry {
String name;
int type;
}

View File

@ -0,0 +1,4 @@
package clock.socoolby.com.clock.dao.alter;
public class AlterEntryDao {
}

View File

@ -0,0 +1,9 @@
package clock.socoolby.com.clock.dao.alter;
import java.util.Date;
public class AlterEntryHistory {
String alterEntryId;
Date startTime;
Date endTime;
}

View File

@ -0,0 +1,4 @@
package clock.socoolby.com.clock.dao.alter;
public class AlterEntryHistoryDao {
}

View File

@ -0,0 +1,27 @@
package clock.socoolby.com.clock.dao.base;
public class TimeFontStyle {
public String name;
public int displaySecond;
public int noDisplaySecond;
public int displaySecondOnFull;
public int noDisplaySecondOnFull;
public float secondScale;
public TimeFontStyle(String name, int displaySecond, int noDisplaySecond) {
this(name,displaySecond,noDisplaySecond,displaySecond,noDisplaySecond);
}
public TimeFontStyle(String name, int displaySecond, int noDisplaySecond, int displaySecondOnFull, int noDisplaySecondOnFull) {
this(name,displaySecond,noDisplaySecond,displaySecondOnFull,noDisplaySecondOnFull,1/2);
}
public TimeFontStyle(String name, int displaySecond, int noDisplaySecond, int displaySecondOnFull, int noDisplaySecondOnFull, float second) {
this.name = name;
this.displaySecond = displaySecond;
this.noDisplaySecond = noDisplaySecond;
this.displaySecondOnFull = displaySecondOnFull;
this.noDisplaySecondOnFull = noDisplaySecondOnFull;
this.secondScale = second;
}
}

View File

@ -0,0 +1,4 @@
package clock.socoolby.com.clock.dao.base;
public class TimeFontStyleDao {
}

View File

@ -0,0 +1,6 @@
package clock.socoolby.com.clock.dao.base;
public class UITheme {
String name;
String jsonString;
}

View File

@ -0,0 +1,4 @@
package clock.socoolby.com.clock.dao.base;
public class UIThemeDao {
}

View File

@ -0,0 +1,10 @@
package clock.socoolby.com.clock.dao.work;
public class WorkEntry {
public String name;
public int longTime;
public String ringUrl;
public int dailyTime=0;
}

View File

@ -0,0 +1,4 @@
package clock.socoolby.com.clock.dao.work;
public class WorkEntryDao {
}

View File

@ -0,0 +1,12 @@
package clock.socoolby.com.clock.dao.work;
import java.util.Date;
public class WorkEntryHistory {
String alterRuleHostoryId;
String alterEntryId;
Date startTime;
Date stopTime;
Date endTime;
Date outTime;
}

View File

@ -0,0 +1,4 @@
package clock.socoolby.com.clock.dao.work;
public class WorkEntryHistoryDao {
}

View File

@ -0,0 +1,18 @@
package clock.socoolby.com.clock.dao.work;
import java.util.Date;
import java.util.List;
public class WorkRule {
WorkEntry currentEntry;
List<WorkEntry> entryList;
public String name;
public int ruleLoopType;//这是一个组合
public Date alterDateTime;//只有LoopType为指定时间时有效
}

View File

@ -0,0 +1,4 @@
package clock.socoolby.com.clock.dao.work;
public class WorkRuleDao {
}

View File

@ -0,0 +1,12 @@
package clock.socoolby.com.clock.dao.work;
import java.util.Date;
public class WorkRuleHistory {
Date startTime;
boolean filash;
long entryTimeTotal;
long dailyTimeTotal;
long outTimeTotal;
}

View File

@ -0,0 +1,4 @@
package clock.socoolby.com.clock.dao.work;
public class WorkRuleHistoryDao {
}

View File

@ -0,0 +1,4 @@
package clock.socoolby.com.clock.db;
public class WorkClockDatabase {
}

View File

@ -0,0 +1,82 @@
package clock.socoolby.com.clock.fragment;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import clock.socoolby.com.clock.ClockApplication;
import clock.socoolby.com.clock.R;
import clock.socoolby.com.clock.state.ClockModeEnum;
import clock.socoolby.com.clock.viewmodel.AlterViewModel;
import clock.socoolby.com.clock.viewmodel.GlobalViewModel;
import clock.socoolby.com.clock.viewmodel.ViewModelFactory;
/**
* A simple {@link Fragment} subclass.
* Use the {@link AlterFragment} factory method to
* create an instance of this fragment.
*/
public class AlterFragment extends Fragment {
GlobalViewModel globalViewModel;
AlterViewModel alterViewModel;
private TextView tv_handup_text;
public AlterFragment() {
// Required empty public constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
globalViewModel= ViewModelProviders.of(getActivity(), new ViewModelFactory(ClockApplication.getInstance().getModel(),ClockApplication.getInstance().getEntityManager())).get(GlobalViewModel.class);
alterViewModel=ViewModelProviders.of(getActivity(), new ViewModelFactory(ClockApplication.getInstance().getModel(),ClockApplication.getInstance().getEntityManager())).get(AlterViewModel.class);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view=inflater.inflate(R.layout.fragment_alter, container, false);
tv_handup_text=view.findViewById(R.id.tv_handup_image);
tv_handup_text.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
endHandUp(true);
}
});
bindViewModel();
return view;
}
private void bindViewModel(){
alterViewModel.getHandUpDescription().observe(this, new Observer<String>() {
@Override
public void onChanged(String s) {
tv_handup_text.setText(s);
}
});
globalViewModel.getHandUpTime().observe(this, new Observer<Integer>() {
@Override
public void onChanged(Integer time) {
if(time==0)
endHandUp(false);
}
});
}
private void endHandUp(boolean userCheck){
globalViewModel.getClockModeEnum().setValue(ClockModeEnum.NORMAL);
}
}

View File

@ -0,0 +1,153 @@
package clock.socoolby.com.clock.fragment;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import clock.socoolby.com.clock.ClockApplication;
import clock.socoolby.com.clock.R;
import clock.socoolby.com.clock.dao.base.TimeFontStyle;
import clock.socoolby.com.clock.utils.FontUtils;
import clock.socoolby.com.clock.viewmodel.DigitViewModel;
import clock.socoolby.com.clock.viewmodel.GlobalViewModel;
import clock.socoolby.com.clock.viewmodel.ViewModelFactory;
import clock.socoolby.com.clock.widget.textview.DigitTextView;
import clock.socoolby.com.clock.widget.textview.ShadowTypeEnum;
import clock.socoolby.com.clock.widget.textview.charanimator.CharAnimatorEnum;
/**
* A simple {@link Fragment} subclass.
* Activities that contain this fragment must implement the
* to handle interaction events.
* create an instance of this fragment.
*/
public class DigitClockFragment extends Fragment {
public DigitClockFragment() {
// Required empty public constructor
}
DigitViewModel digitViewModel;
GlobalViewModel globalViewModel;
private DigitTextView tv_time;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
digitViewModel= ViewModelProviders.of(getActivity(), new ViewModelFactory(ClockApplication.getInstance().getModel(),ClockApplication.getInstance().getEntityManager())).get(DigitViewModel.class);
globalViewModel=ViewModelProviders.of(getActivity(), new ViewModelFactory(ClockApplication.getInstance().getModel(),ClockApplication.getInstance().getEntityManager())).get(GlobalViewModel.class);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view=inflater.inflate(R.layout.fragment_digit_clock, container, false);
tv_time=view.findViewById(R.id.tv_time);
bindViewModel();
return view;
}
private void bindViewModel(){
digitViewModel.getTimeFontStyle().observe(this, new Observer<TimeFontStyle>() {
@Override
public void onChanged(TimeFontStyle timeFontStyle) {
reflushFontStyle(timeFontStyle);
}
});
digitViewModel.getTimeFontStyleSize().observe(this, new Observer<Integer>() {
@Override
public void onChanged(Integer integer) {
setFontSize(integer);
}
});
digitViewModel.getBaseLineDown().observe(this, new Observer<Integer>() {
@Override
public void onChanged(Integer integer) {
tv_time.setBaseLineDown(integer);
}
});
digitViewModel.getLinearGradientAble().observe(this, new Observer<Boolean>() {
@Override
public void onChanged(Boolean aBoolean) {
tv_time.setLinearGradientAble(aBoolean);
}
});
digitViewModel.getTimeLinearGradientColorsArray().observe(this, new Observer<Integer[]>() {
@Override
public void onChanged(Integer[] integers) {
if(integers==null) {
tv_time.setLinearGradientAble(false);
return;
}
int[] toInts=new int[integers.length];
for(int i=0;i<integers.length;i++)
toInts[i]=integers[i];
tv_time.setLinearGradient(toInts);
}
});
digitViewModel.getReflectedAble().observe(this, new Observer<Boolean>() {
@Override
public void onChanged(Boolean aBoolean) {
tv_time.setReflectedAble(aBoolean);
}
});
digitViewModel.getShadowType().observe(this, new Observer<ShadowTypeEnum>() {
@Override
public void onChanged(ShadowTypeEnum shadowTypeEnum) {
tv_time.setShadowType(shadowTypeEnum);
}
});
digitViewModel.getTimeText().observe(this, new Observer<String>() {
@Override
public void onChanged(String s) {
tv_time.setText(s);
}
});
digitViewModel.getTimeCharAnimatorType().observe(this, new Observer<CharAnimatorEnum>() {
@Override
public void onChanged(CharAnimatorEnum charAnimatorEnum) {
tv_time.setCurrentCharAnimatorType(charAnimatorEnum);
}
});
globalViewModel.getForegroundColor().observe(this, new Observer<Integer>() {
@Override
public void onChanged(Integer integer) {
tv_time.setTextColor(integer);
}
});
}
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){
FontUtils.getInstance().replaceFontFromAsset(tv_time,"fonts/"+fontStyle.name+".ttf");
}
private void setFontSize(int fontSize){
tv_time.setTextSize(fontSize);
}
}

View File

@ -0,0 +1,150 @@
package clock.socoolby.com.clock.fragment;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import clock.socoolby.com.clock.ClockApplication;
import clock.socoolby.com.clock.R;
import clock.socoolby.com.clock.viewmodel.GlobalViewModel;
import clock.socoolby.com.clock.viewmodel.SimulateViewModel;
import clock.socoolby.com.clock.viewmodel.ViewModelFactory;
import clock.socoolby.com.clock.widget.animatorview.AnimatorView;
import clock.socoolby.com.clock.widget.animatorview.animator.ClockAnimator;
import clock.socoolby.com.clock.widget.animatorview.animator.clockanimator.AbstractClock;
import clock.socoolby.com.clock.widget.animatorview.animator.clockanimator.CircleClock;
import clock.socoolby.com.clock.widget.animatorview.animator.clockanimator.CircleTwoClock;
import clock.socoolby.com.clock.widget.animatorview.animator.clockanimator.ClockFactory;
import clock.socoolby.com.clock.widget.animatorview.animator.clockanimator.HelixClock;
import clock.socoolby.com.clock.widget.animatorview.animator.clockanimator.HexagonalClock;
import clock.socoolby.com.clock.widget.animatorview.animator.clockanimator.OvalClock;
import clock.socoolby.com.clock.widget.animatorview.animator.clockanimator.SquareClock;
import clock.socoolby.com.clock.widget.animatorview.animator.clockanimator.pointer.PointerFactory;
/**
* A simple {@link Fragment} subclass.
* Activities that contain this fragment must implement the
* to handle interaction events.
* create an instance of this fragment.
*/
public class SimulateClockFragment extends Fragment {
public static final String TAG=SimulateClockFragment.class.getSimpleName();
SimulateViewModel simulateViewModel;
GlobalViewModel globalViewModel;
AnimatorView clockView;
public SimulateClockFragment() {
// Required empty public constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
clockAnimator = new ClockAnimator();
simulateViewModel= ViewModelProviders.of(getActivity(), new ViewModelFactory(ClockApplication.getInstance().getModel(),ClockApplication.getInstance().getEntityManager())).get(SimulateViewModel.class);
globalViewModel=ViewModelProviders.of(getActivity(), new ViewModelFactory(ClockApplication.getInstance().getModel(),ClockApplication.getInstance().getEntityManager())).get(GlobalViewModel.class);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view=inflater.inflate(R.layout.fragment_simulate_clock, container, false);
clockView=view.findViewById(R.id.tv_foreground_animatorview);
clockAnimator.init(clockView.getContext(),clockView);
clockView.setAnimator(clockAnimator);
bindViewModel();
return view;
}
@Override
public void onResume() {
super.onResume();
if(clockAnimator!=null){
clockAnimator.start();
}
}
@Override
public void onPause() {
super.onPause();
if(clockAnimator!=null){
clockAnimator.stop();
}
}
private void bindViewModel(){
simulateViewModel.getClockTypeName().observe(this, new Observer<String>() {
@Override
public void onChanged(String s) {
setClockStyle(s);
}
});
simulateViewModel.getPointerTypeName().observe(this, new Observer<String>() {
@Override
public void onChanged(String s) {
setClockPointer(s);
}
});
globalViewModel.getForegroundColor().observe(this, new Observer<Integer>() {
@Override
public void onChanged(Integer integer) {
clockAnimator.setColor(integer);
}
});
}
ClockAnimator clockAnimator=null;
private void changeFullScreenClock(int index) {
Log.d(TAG,"changeFullScreenClock index:"+index);
clockAnimator.setColor(globalViewModel.getForegroundColor().getValue());
switch (index) {
case 1:
clockAnimator.setClock(new SquareClock());
break;
case 2:
clockAnimator.setClock(new OvalClock());
break;
case 3:
clockAnimator.setClock(new CircleTwoClock());
break;
case 4:
clockAnimator.setClock(new HexagonalClock());
break;
case 5:
clockAnimator.setClock(new HelixClock());
break;
default:
clockAnimator.setClock(new CircleClock());
}
clockView.setAnimator(clockAnimator);
}
private void setFullScreenClock(String clockStyle,String pointerStyle){
setClockStyle(clockStyle);
setClockPointer(pointerStyle);
}
private void setClockStyle(String clockStyle){
clockAnimator.setColor(globalViewModel.getForegroundColor().getValue());
AbstractClock clock= ClockFactory.build(clockStyle);
clockAnimator.setClock(clock);
}
private void setClockPointer(String clockPointerStyle){
clockAnimator.setClockPointer(PointerFactory.build(clockPointerStyle));
}
}

View File

@ -7,12 +7,18 @@ import org.json.JSONException;
import org.json.JSONObject;
import java.io.Serializable;
import java.util.Timer;
import java.util.TimerTask;
import clock.socoolby.com.clock.ClockApplication;
import clock.socoolby.com.clock.Constants;
import clock.socoolby.com.clock.R;
import clock.socoolby.com.clock.utils.FileUtils;
public class SharePerferenceModel implements Serializable {
private boolean dirty=false;
protected int typeHourPower = Constants.TALKING_HALF_AN_HOUR;
protected final static String KEY_TYPE_HOUR_POWER = "key_type_hour_power";
@ -21,11 +27,11 @@ public class SharePerferenceModel implements Serializable {
protected DateModel stopHourPowerTime = null;
protected final static String KEY_STOP_POWER = "key_stop_power";
protected boolean isDisplaySecond = true;
protected boolean displaySecond = true;
protected final static String KEY_IS_DISPLAY_SECOND = "key_is_display_second";
protected boolean isTickSound = false;
protected boolean tickSound = false;
protected final static String KEY_IS_TICK_SOUND = "key_is_tick_sound";
protected boolean isTriggerScreen = true;
protected boolean triggerScreen = true;
protected final static String KEY_IS_TRIGGER_SCREEN = "key_is_trigger_screen";
protected boolean hourSystem12 = false;
@ -38,8 +44,6 @@ public class SharePerferenceModel implements Serializable {
protected final static String KEY_DESCRPTION = "key_description";
protected String mDescription;
protected final static String KEY_FONT_INDEX = "key_font_index";
protected Integer fontIndex;
protected final static String KEY_DISPLAYVIEW_TIME = "key_displayview_time";
protected final static String KEY_DISPLAYVIEW_DATE = "key_dsplayview_date";
@ -58,21 +62,104 @@ public class SharePerferenceModel implements Serializable {
protected final static String KEY_IS_HANDUP_ABLE="key_is_handup_able";
protected boolean handUpAble = false;
protected final static String KEY_HANDUP_MUSIC ="key_handup_music";
protected String handUpMusic = "";
protected final static String KEY_BACKGROUND_COLOR="key_background_color";
protected Integer backgroundColor=Color.rgb(0, 0, 0);
protected final static String KEY_BACKGROUND_IMAGE="key_background_image";
protected String backgroundImage="";
protected final static String KEY_BACKGROUND_ANIMATOR="key_background_animator";
protected String backgroundAnimatorName="";
protected final static String KEY_BACKGROUND_ANIMATOR_RANDOM_COLOR="key_background_animator_random_color";
protected boolean backgroundAnimatorRandomColor=false;
protected final static String KEY_FOREGROUND_COLOR="key_foreground_color";
protected Integer foregroundColor=Color.rgb(255, 255, 255);
protected final static String KEY_FOREGROUND_COLOR1="key_foreground_color1";
protected Integer foregroundColor1=Color.rgb(199,21,133);
protected final static String KEY_FONT_INDEX = "key_font_index";
protected Integer fontIndex;
//数字时钟 time text style
protected final static String KEY_FONT_NAME = "key_font_name";
protected String fontName;
protected final static String KEY_IS_LINEARGRADIENT_ABLE="key_time_text_is_linearGradient_able";
protected boolean linearGradientAble = false;
protected final static String KEY_FOREGROUND_TIME_COLORS_ARRAY="key_time_text_foreground_time_colors_array";
protected Integer[] timeColorsArray=null;
protected final static String KEY_IS_REFLECTED_ABLE="key_time_text_is_reflectedAble_able";
protected boolean reflectedAble = false;
protected final static String KEY_TIME_TEXT_SHADOW_TYPE="key_time_text_shadowType";
protected Integer shadowType=0;
protected final static String KEY_TIME_TEXT_CHAR_ANIMATOR_TYPE="key_time_text_charAnimatorType";
protected Integer timeTextCharAnimatorType=0;
//模拟时钟
protected final static String KEY_SIMULATE_CLOCK_TYPE_NAME="key_simulate_clock_type_name";
protected String simulateClockTypeName;
protected final static String KEY_SIMULATE_CLOCK_POINTER_TYPE_NAME="key_simulate_clock_pointer_type_name";
protected String simulateClockPointerTypeName;
//ui
protected final static String KEY_UI_CLOCK_INTERFACE_TYPE ="key_ui_clock_interface_type";
protected int clockInterfaceType;
protected final static String KEY_UI_AUTO_FULLSCREEN ="key_ui_auto_fullscreen";
protected boolean autoFullscreen=false;
//theme ui
protected final static String KEY_THEME_UI_NAME="key_theme_ui_name";
protected String themeName;
protected final static String KEY_THEME_UI_TYPE="key_theme_ui_type";
protected int themeUIType;
private int dirtyDelaySecond=10000;
private boolean dirtySaving=false;
Timer timer=null;
private void dirtySave(){
Log.d("model","comming in dirty save task...");
if(dirtySaving)
return;
dirtySaving=true;
if(timer==null)
timer = new Timer();
Log.d("model","dirty task created ...");
timer.schedule(new TimerTask() {
public void run() {
Log.d("model","dirty task running...");
save();
dirtySaving=false;
this.cancel();
}
}, dirtyDelaySecond);
}
public int getTypeHourPower() {
return typeHourPower;
}
public void setTypeHourPower(int typeHourPower) {
this.typeHourPower = typeHourPower;
dirtySave();
}
public DateModel getStartHourPowerTime() {
@ -82,6 +169,7 @@ public class SharePerferenceModel implements Serializable {
public void setStartHourPowerTime(DateModel startHourPowerTime) {
this.startHourPowerTime = startHourPowerTime;
dirtySave();
}
public DateModel getStopHourPowerTime() {
@ -90,30 +178,34 @@ public class SharePerferenceModel implements Serializable {
public void setStopHourPowerTime(DateModel stopHourPowerTime) {
this.stopHourPowerTime = stopHourPowerTime;
dirtySave();
}
public boolean isDisplaySecond() {
return isDisplaySecond;
return displaySecond;
}
public void setDisplaySecond(boolean displaySecond) {
isDisplaySecond = displaySecond;
this.displaySecond = displaySecond;
dirtySave();
}
public boolean isTickSound() {
return isTickSound;
return tickSound;
}
public void setTickSound(boolean tickSound) {
isTickSound = tickSound;
this.tickSound = tickSound;
dirtySave();
}
public boolean isTriggerScreen() {
return isTriggerScreen;
return triggerScreen;
}
public void setTriggerScreen(boolean triggerScreen) {
isTriggerScreen = triggerScreen;
this.triggerScreen = triggerScreen;
dirtySave();
}
public String getCity() {
@ -122,6 +214,7 @@ public class SharePerferenceModel implements Serializable {
public void setCity(String city) {
this.mCity = city;
dirtySave();
}
public String getDescription() {
@ -130,26 +223,32 @@ public class SharePerferenceModel implements Serializable {
public void setDescription(String mDescription) {
this.mDescription = mDescription;
dirtySave();
}
public void setTimeLocation(JSONObject timeLocation) {
this.timeLocation = timeLocation;
dirtySave();
}
public void setDateLocation(JSONObject dateLocation) {
this.dateLocation = dateLocation;
dirtySave();
}
public void setDayLocation(JSONObject dayLocation) {
this.dayLocation = dayLocation;
dirtySave();
}
public void setWeatherLocation(JSONObject weatherLocation) {
this.weatherLocation = weatherLocation;
dirtySave();
}
public void setDescriptionLocation(JSONObject descriptionLocation) {
this.descriptionLocation = descriptionLocation;
dirtySave();
}
public JSONObject getTimeLocation() {
@ -176,10 +275,10 @@ public class SharePerferenceModel implements Serializable {
try {
JSONObject jsonObject = new JSONObject(jsonString);
typeHourPower = jsonObject.getInt(KEY_TYPE_HOUR_POWER);
isDisplaySecond = jsonObject.getBoolean(KEY_IS_DISPLAY_SECOND);
isTickSound = jsonObject.getBoolean(KEY_IS_TICK_SOUND);
isTriggerScreen =jsonObject.optBoolean(KEY_IS_TRIGGER_SCREEN,true);
mCity = jsonObject.getString(KEY_CITY);
displaySecond = jsonObject.getBoolean(KEY_IS_DISPLAY_SECOND);
tickSound = jsonObject.getBoolean(KEY_IS_TICK_SOUND);
triggerScreen =jsonObject.optBoolean(KEY_IS_TRIGGER_SCREEN,true);
mCity = jsonObject.optString(KEY_CITY,"jinhua");
mDescription = jsonObject.optString(KEY_DESCRPTION, ClockApplication.getContext().getResources().getString(R.string.always_zuo_never_die));
startHourPowerTime = new DateModel();
startHourPowerTime.setDataString(jsonObject.getString(KEY_START_POWER));
@ -193,10 +292,37 @@ public class SharePerferenceModel implements Serializable {
fontIndex = jsonObject.optInt(KEY_FONT_INDEX,0);
handUpAble=jsonObject.optBoolean(KEY_IS_HANDUP_ABLE,false);
handUpTime=jsonObject.optInt(KEY_HANDUP_TIME,-1);
handUpMusic=jsonObject.optString(KEY_HANDUP_MUSIC,"");
backgroundColor=jsonObject.optInt(KEY_BACKGROUND_COLOR,Color.rgb(0, 0, 0));
backgroundImage=jsonObject.optString(KEY_BACKGROUND_IMAGE,"");
backgroundAnimatorName=jsonObject.optString(KEY_BACKGROUND_ANIMATOR,"");
backgroundAnimatorRandomColor=jsonObject.optBoolean(KEY_BACKGROUND_ANIMATOR_RANDOM_COLOR,false);
foregroundColor=jsonObject.optInt(KEY_FOREGROUND_COLOR,Color.rgb(255, 255, 255));
foregroundColor1=jsonObject.optInt(KEY_FOREGROUND_COLOR1,Color.rgb(199,21,133));
hourSystem12=jsonObject.optBoolean(KEY_IS_HOUR_SYSTEM_12,false);
linearGradientAble=jsonObject.optBoolean(KEY_IS_LINEARGRADIENT_ABLE,false);
timeColorsArray=stringToIntegerArray(jsonObject.optString(KEY_FOREGROUND_TIME_COLORS_ARRAY,null));
reflectedAble=jsonObject.optBoolean(KEY_IS_REFLECTED_ABLE);
shadowType=jsonObject.optInt(KEY_TIME_TEXT_SHADOW_TYPE,0);
timeTextCharAnimatorType=jsonObject.optInt(KEY_TIME_TEXT_CHAR_ANIMATOR_TYPE,0);
fontName=jsonObject.optString(KEY_FONT_NAME,"default");
simulateClockTypeName=jsonObject.optString(KEY_SIMULATE_CLOCK_TYPE_NAME,"default");
simulateClockPointerTypeName=jsonObject.optString(KEY_SIMULATE_CLOCK_POINTER_TYPE_NAME,"default");
themeName=jsonObject.optString(KEY_THEME_UI_NAME,"default");
clockInterfaceType =jsonObject.optInt(KEY_UI_CLOCK_INTERFACE_TYPE,0);
autoFullscreen=jsonObject.optBoolean(KEY_UI_AUTO_FULLSCREEN,false);
themeUIType=jsonObject.optInt(KEY_THEME_UI_TYPE,1);
} catch (JSONException e) {
e.printStackTrace();
}
@ -206,14 +332,13 @@ public class SharePerferenceModel implements Serializable {
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put(KEY_TYPE_HOUR_POWER, typeHourPower);
jsonObject.put(KEY_IS_DISPLAY_SECOND, isDisplaySecond);
jsonObject.put(KEY_IS_TICK_SOUND, isTickSound);
jsonObject.put(KEY_IS_TRIGGER_SCREEN, isTriggerScreen);
jsonObject.put(KEY_IS_DISPLAY_SECOND, displaySecond);
jsonObject.put(KEY_IS_TICK_SOUND, tickSound);
jsonObject.put(KEY_IS_TRIGGER_SCREEN, triggerScreen);
jsonObject.put(KEY_CITY, mCity);
jsonObject.put(KEY_DESCRPTION, mDescription);
jsonObject.put(KEY_START_POWER, startHourPowerTime.getTime());
jsonObject.put(KEY_STOP_POWER, stopHourPowerTime.getTime());
jsonObject.put(KEY_DISPLAYVIEW_TIME, timeLocation.toString());
jsonObject.put(KEY_DISPLAYVIEW_DATE, dateLocation.toString());
jsonObject.put(KEY_DISPLAYVIEW_DAY, dayLocation.toString());
@ -222,10 +347,33 @@ public class SharePerferenceModel implements Serializable {
jsonObject.put(KEY_FONT_INDEX, fontIndex);
jsonObject.put(KEY_HANDUP_TIME,handUpTime);
jsonObject.put(KEY_IS_HANDUP_ABLE,handUpAble);
jsonObject.put(KEY_HANDUP_MUSIC,handUpMusic);
jsonObject.put(KEY_BACKGROUND_COLOR,backgroundColor);
jsonObject.put(KEY_BACKGROUND_IMAGE,backgroundImage);
jsonObject.put(KEY_BACKGROUND_ANIMATOR,backgroundAnimatorName);
jsonObject.put(KEY_BACKGROUND_ANIMATOR_RANDOM_COLOR,backgroundAnimatorRandomColor);
jsonObject.put(KEY_FOREGROUND_COLOR,foregroundColor);
jsonObject.put(KEY_FOREGROUND_COLOR1,foregroundColor1);
jsonObject.put(KEY_IS_HOUR_SYSTEM_12,hourSystem12);
jsonObject.put(KEY_IS_LINEARGRADIENT_ABLE,linearGradientAble);
jsonObject.put(KEY_FOREGROUND_TIME_COLORS_ARRAY,integerArrayToString(timeColorsArray));
jsonObject.put(KEY_IS_REFLECTED_ABLE,reflectedAble);
jsonObject.put(KEY_TIME_TEXT_SHADOW_TYPE,shadowType);
jsonObject.put(KEY_TIME_TEXT_CHAR_ANIMATOR_TYPE,timeTextCharAnimatorType);
jsonObject.put(KEY_FONT_NAME,fontName);
jsonObject.put(KEY_SIMULATE_CLOCK_TYPE_NAME,simulateClockTypeName);
jsonObject.put(KEY_SIMULATE_CLOCK_POINTER_TYPE_NAME,simulateClockPointerTypeName);
jsonObject.put(KEY_THEME_UI_NAME,themeName);
jsonObject.put(KEY_UI_CLOCK_INTERFACE_TYPE, clockInterfaceType);
jsonObject.put(KEY_UI_AUTO_FULLSCREEN,autoFullscreen);
jsonObject.put(KEY_THEME_UI_TYPE,themeUIType);
} catch (JSONException e) {
e.printStackTrace();
}
@ -233,6 +381,29 @@ public class SharePerferenceModel implements Serializable {
}
public static String integerArrayToString(Integer[] fromArrays){
if(fromArrays==null)
return "";
StringBuffer sb = new StringBuffer();
for(int i=0;i<fromArrays.length;i++){
if(i<fromArrays.length-1)
sb.append(fromArrays[i]+",");
else
sb.append(fromArrays[i]);
}
return sb.toString();
}
public static Integer[] stringToIntegerArray(String fromString){
if(fromString==null||fromString.isEmpty())
return null;
String[] temp=fromString.split(",");
Integer[] ret=new Integer[temp.length];
for(int i=0;i<temp.length;i++)
ret[i]=Integer.valueOf(temp[i]);
return ret;
}
public void save() {
save(Constants.SHARE_PERFERENCE_FILE,this);
@ -256,31 +427,12 @@ public class SharePerferenceModel implements Serializable {
@Override
public String toString() {
return "SharePerferenceModel{" +
"typeHourPower=" + typeHourPower +
", startHourPowerTime=" + startHourPowerTime +
", stopHourPowerTime=" + stopHourPowerTime +
", isDisplaySecond=" + isDisplaySecond +
", isTickSound=" + isTickSound +
", mCity='" + mCity + '\'' +
", mDescription='" + mDescription + '\'' +
", timeLocation=" + timeLocation +
", dateLocation=" + dateLocation +
", dayLocation=" + dayLocation +
", weatherLocation=" + weatherLocation +
", descriptionLocation=" + descriptionLocation +
", fontIndex="+fontIndex+
", handUpAble="+handUpAble+
", handUpTime="+handUpTime+
", backgroundColor="+backgroundColor+
", foregroundColor="+foregroundColor+
", foregroundColor1="+foregroundColor1+
", hourSystem12="+hourSystem12+
'}';
return toJsonString();
}
public void setFontIndex(int font_index) {
fontIndex=font_index;
dirtySave();
}
public Integer getFontIndex(){
@ -297,10 +449,12 @@ public class SharePerferenceModel implements Serializable {
public void setHandUpTime(Integer handUpTime) {
this.handUpTime = handUpTime;
dirtySave();
}
public void setHandUpAble(boolean handUpAble) {
this.handUpAble = handUpAble;
dirtySave();
}
@ -310,6 +464,7 @@ public class SharePerferenceModel implements Serializable {
public void setBackgroundColor(Integer backgroundColor) {
this.backgroundColor = backgroundColor;
dirtySave();
}
public Integer getForegroundColor() {
@ -318,6 +473,7 @@ public class SharePerferenceModel implements Serializable {
public void setForegroundColor(Integer foregroundColor) {
this.foregroundColor = foregroundColor;
dirtySave();
}
public Integer getForegroundColor1() {
@ -326,6 +482,7 @@ public class SharePerferenceModel implements Serializable {
public void setForegroundColor1(Integer foregroundColor1) {
this.foregroundColor1 = foregroundColor1;
dirtySave();
}
public boolean isHourSystem12() {
@ -334,5 +491,175 @@ public class SharePerferenceModel implements Serializable {
public void setHourSystem12(boolean hourSystem12) {
this.hourSystem12 = hourSystem12;
dirtySave();
}
public String getmCity() {
return mCity;
}
public void setmCity(String mCity) {
this.mCity = mCity;
dirtySave();
}
public String getmDescription() {
return mDescription;
}
public void setmDescription(String mDescription) {
this.mDescription = mDescription;
dirtySave();
}
public void setFontIndex(Integer fontIndex) {
this.fontIndex = fontIndex;
dirtySave();
}
public String getHandUpMusic() {
return handUpMusic;
}
public void setHandUpMusic(String handUpMusic) {
this.handUpMusic = handUpMusic;
dirtySave();
}
public String getBackgroundImage() {
return backgroundImage;
}
public void setBackgroundImage(String backgroundImage) {
this.backgroundImage = backgroundImage;
dirtySave();
}
public String getBackgroundAnimatorName() {
return backgroundAnimatorName;
}
public void setBackgroundAnimatorName(String backgroundAnimatorName) {
this.backgroundAnimatorName = backgroundAnimatorName;
dirtySave();
}
public Integer[] getTimeColorsArray() {
return timeColorsArray;
}
public void setTimeColorsArray(Integer[] timeColorsArray) {
this.timeColorsArray = timeColorsArray;
dirtySave();
}
public boolean isBackgroundAnimatorRandomColor() {
return backgroundAnimatorRandomColor;
}
public void setBackgroundAnimatorRandomColor(boolean backgroundAnimatorRandomColor) {
this.backgroundAnimatorRandomColor = backgroundAnimatorRandomColor;
dirtySave();
}
public boolean isLinearGradientAble() {
return linearGradientAble;
}
public void setLinearGradientAble(boolean linearGradientAble) {
this.linearGradientAble = linearGradientAble;
dirtySave();
}
public boolean isReflectedAble() {
return reflectedAble;
}
public void setReflectedAble(boolean reflectedAble) {
this.reflectedAble = reflectedAble;
dirtySave();
}
public Integer getShadowType() {
return shadowType;
}
public void setShadowType(Integer shadowType) {
this.shadowType = shadowType;
dirtySave();
}
public int getClockInterfaceType() {
return clockInterfaceType;
}
public void setClockInterfaceType(int clockInterfaceType) {
this.clockInterfaceType = clockInterfaceType;
dirtySave();
}
public String getThemeName() {
return themeName;
}
public void setThemeName(String themeName) {
this.themeName = themeName;
dirtySave();
}
public int getThemeUIType() {
return themeUIType;
}
public void setThemeUIType(int themeUIType) {
this.themeUIType = themeUIType;
dirtySave();
}
public Integer getTimeTextCharAnimatorType() {
return timeTextCharAnimatorType;
}
public void setTimeTextCharAnimatorType(Integer timeTextCharAnimatorType) {
this.timeTextCharAnimatorType = timeTextCharAnimatorType;
dirtySave();
}
public String getSimulateClockTypeName() {
return simulateClockTypeName;
}
public void setSimulateClockTypeName(String simulateClockTypeName) {
this.simulateClockTypeName = simulateClockTypeName;
dirtySave();
}
public String getSimulateClockPointerTypeName() {
return simulateClockPointerTypeName;
}
public void setSimulateClockPointerTypeName(String simulateClockPointerTypeName) {
this.simulateClockPointerTypeName = simulateClockPointerTypeName;
dirtySave();
}
public String getFontName() {
return fontName;
}
public void setFontName(String fontName) {
this.fontName = fontName;
dirtySave();
}
public boolean isAutoFullscreen() {
return autoFullscreen;
}
public void setAutoFullscreen(boolean autoFullscreen) {
this.autoFullscreen = autoFullscreen;
dirtySave();
}
}

View File

@ -1,22 +0,0 @@
package clock.socoolby.com.clock.model;
public class UIThemePerferenceModel extends SharePerferenceModel{
protected final static String KEY_FOREGROUND_TIME_COLORS_ARRAY="key_foreground_time_colors_array";
protected int[] timeColorsArray;
protected final static String KEY_FOREGROUND_TIME_FONT_SIZE="key_foreground_time_font_size";
protected int timeFontSize;
@Override
protected void fromJsonString(String jsonString) {
super.fromJsonString(jsonString);
}
@Override
protected String toJsonString() {
return super.toJsonString();
}
}

View File

@ -0,0 +1,22 @@
package clock.socoolby.com.clock.pop;
import android.content.Context;
import android.view.View;
import razerdp.basepopup.BasePopupWindow;
public class RingPopup extends BasePopupWindow implements View.OnClickListener{
public RingPopup(Context context) {
super(context);
}
@Override
public void onClick(View v) {
}
@Override
public View onCreateContentView() {
return null;
}
}

View File

@ -0,0 +1,21 @@
package clock.socoolby.com.clock.state;
public enum ClockInterfaceTypeEnum {
Digit(0),Simulate(1);
public int code;
ClockInterfaceTypeEnum(int code) {
this.code = code;
}
public static ClockInterfaceTypeEnum valueOf(int code){
switch (code){
case 1:
return Simulate;
}
return Digit;
}
}

View File

@ -0,0 +1,22 @@
package clock.socoolby.com.clock.state;
public enum ClockModeEnum {
NORMAL(0),HANDUP(1),DELAY(2);
public int code;
ClockModeEnum(int code) {
this.code = code;
}
public static ClockModeEnum valueOf(int code){
switch (code){
case 1:
return HANDUP;
case 2:
return DELAY;
default:
return NORMAL;
}
}
}

View File

@ -0,0 +1,227 @@
package clock.socoolby.com.clock.state;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import com.haibin.calendarview.LunarCalendarManager;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import clock.socoolby.com.clock.ClockApplication;
import clock.socoolby.com.clock.Constants;
import clock.socoolby.com.clock.R;
import clock.socoolby.com.clock.alter.AlterManager;
import clock.socoolby.com.clock.model.DateModel;
import clock.socoolby.com.clock.model.SharePerferenceModel;
import clock.socoolby.com.clock.utils.Player;
import clock.socoolby.com.clock.utils.ScreenManager;
import clock.socoolby.com.clock.viewmodel.DigitViewModel;
import clock.socoolby.com.clock.viewmodel.GlobalViewModel;
import clock.socoolby.com.clock.viewmodel.SimulateViewModel;
import clock.socoolby.com.clock.viewmodel.ThemeUIViewModel;
public class ClockStateMachine implements Handler.Callback{
public static final String TAG=ClockStateMachine.class.getSimpleName();
GlobalViewModel globalViewModel;
DigitViewModel digitViewModel;
SimulateViewModel simulateViewModel;
ThemeUIViewModel themeUIViewModel;
private Timer timer;
private Handler handler;
private final static int UPDATE_TIME = 100;
private TimerTask timerTask;
private Date countingDateTimeBase =null;
private AlterManager alterManager;
SharePerferenceModel model;
boolean heartbeat=false;
ClockTimeTypeEnum showTimeType=ClockTimeTypeEnum.TIME;
public ClockStateMachine(AlterManager alterManager,GlobalViewModel globalViewModel, DigitViewModel digitViewModel, SimulateViewModel simulateViewModel,ThemeUIViewModel themeUIViewModel) {
this.globalViewModel = globalViewModel;
this.digitViewModel = digitViewModel;
this.simulateViewModel = simulateViewModel;
this.alterManager = alterManager;
this.themeUIViewModel=themeUIViewModel;
}
public void start(){
LunarCalendarManager.init(ClockApplication.getContext());
model=ClockApplication.getInstance().getModel();
//Log.d(TAG,"create timer and timerTask.................................");
timer = new Timer();
handler = new Handler(this);
timerTask = new TimerTask() {
@Override
public void run() {
//Log.d(TAG, "timerTask move...");
if (!ScreenManager.isScreenOn())
return;
handler.sendEmptyMessage(UPDATE_TIME);
}
};
timer.schedule(timerTask, 1000, 1000);
}
@Override
public boolean handleMessage(Message msg) {
switch (msg.what) {
case UPDATE_TIME:
updateTime();
checkHandUp();
break;
}
return true;
}
public void setCurrentShowTimeType(ClockTimeTypeEnum type){
switch (type){
case COUNTING:
countingDateTimeBase =new Date();
}
}
private int handUPDialy=60;
private void checkHandUp(){
/*if(!handUpAbla) {
return;
}
//Log.d(TAG,"checkHandUp..\thandUPDialy:"+handUPDialy+" \thandUpTime:"+handUpTime+"\thandUpAble:"+handUpAbla);
if(mMode==MODE_HANDUP) {
tv_handup_image.setText("hand up:"+handUPDialy);
handUPDialy--;
if(handUPDialy==0) {
switchMode(MODE_NORMAL);
if(!isArtificialHiddle&&showTimeType==ShowTimeType.TIME){
setCurrentShowTimeType(ShowTimeType.COUNTING);
}
}else
Player.valueOf().playHandUp(this);
return;
}
handUpTime--;
if(hand_time_visable)
tv_hand_time.setText(DateModel.getTime(handUpTime));
if (handUpTime <= 10&&handUpTime > 0)
setDiscript("提醒时间倒计时: " + handUpTime);
if (handUpTime == 0) {
handUPDialy = 60;
resetHandUpTime();
switchMode(MODE_HANDUP);
}*/
}
private void updateTime() {
heartbeat=!heartbeat;
DateModel date = new DateModel();
String timeString=null;
switch (globalViewModel.getClockModeEnum().getValue()){
case NORMAL:
switch (showTimeType){
case COUNTING:
DateModel temp=new DateModel(countingDateTimeBase);
timeString=temp.getTimeString(false);
if (!model.isTickSound()) {
Player.getInstance().playTick(ClockApplication.getContext(), R.raw.tick2);
}
break;
case COUNTING_DOWN:
//timeString=DateModel.getTimeFull(handUpTime);
break;
default:
timeString = model.isDisplaySecond() ? date.getTimeString(model.isHourSystem12()) : date.getShortTimeString(heartbeat,model.isHourSystem12());
break;
}
digitViewModel.getTimeText().setValue(timeString);
break;
case HANDUP:
break;
case DELAY:
break;
}
reportTime(date);
updateDay(date);
updateHourSytemStyle(date);
}
int beforeHourForUpdateSystem=-1;
private void updateHourSytemStyle(DateModel date){
if(beforeHourForUpdateSystem!=date.getHour()) {
beforeHourForUpdateSystem=date.getHour();
globalViewModel.getTime_hour().setValue(date.getHour());
}
}
DateModel currentDate=null;
private void updateDay(DateModel date){
if(currentDate==null||currentDate.getDay()!=date.getDay()) {
Log.d(TAG,"updateDay."+date);
currentDate=date;
String dayString = date.getToday();
String dateString = date.getDateString();
String calendarFestival=getCalendarFestival(date);
if(calendarFestival!=null&&!calendarFestival.isEmpty())
dayString=calendarFestival+" "+dayString;
themeUIViewModel.getDayDescription().setValue(dayString);
themeUIViewModel.getWeekDescription().setValue(dateString);
ClockApplication.getInstance().getBusinessService().getWeather(model.getCity());
}
}
private String getCalendarFestival(DateModel dateModel){
String festival=LunarCalendarManager.gregorianFestival(dateModel.getMonth(),dateModel.getDay());
String ret=LunarCalendarManager.getTraditionFestival(dateModel.getYear(),dateModel.getMonth(),dateModel.getDay());
if(ret==null&&festival==null)
return null;
if(ret==null||ret.isEmpty())
return festival;
if(festival==null||festival.isEmpty())
return ret;
return festival+" "+ret;
}
private void reportTime(DateModel date) {
if (globalViewModel.isTickSound()&&globalViewModel.getClockModeEnum().getValue()!=ClockModeEnum.HANDUP) {
Player.getInstance().playTick(ClockApplication.getContext(),R.raw.tick2);
}
int year = date.getYear();
int month = date.getMonth();
int day = date.getDay();
int hour = date.getHour();
int minute = date.getMinute();
int second = date.getSecond();
int today = date.getWeek();
if (model.getTypeHourPower() != Constants.TALKING_NO_REPORT) {
if ((minute == 30 || minute == 0) && model.getTypeHourPower() == Constants.TALKING_HALF_AN_HOUR && second == 0) {
Log.d(TAG, String.format("reportTime Year:%d Month:%d Day:%d Hour:%d Minute:%d Today:%d", year, month, day, hour, minute, today));
if (alterManager.isReport(hour, minute))
Player.getInstance().reportTime(ClockApplication.getContext(), year, month, day, hour, minute, today);
} else if (model.getTypeHourPower() == Constants.TALKING_HOURS && minute == 0 && second == 0) {
if (alterManager.isReport(hour, minute))
Player.getInstance().reportTime(ClockApplication.getContext(), year, month, day, hour, minute, today);
}
}
}
public void onDestory() {
timer.cancel();
}
}

View File

@ -0,0 +1,21 @@
package clock.socoolby.com.clock.state;
public enum ClockThemeUITypeEnum {
NORMAL(0),SETTING(1),FULLSCREEN(2);
public int code;
ClockThemeUITypeEnum(int code) {
this.code = code;
}
public static ClockThemeUITypeEnum valueOf(int code){
switch (code){
case 1:
return SETTING;
case 2:
return FULLSCREEN;
}
return NORMAL;
}
}

View File

@ -0,0 +1,22 @@
package clock.socoolby.com.clock.state;
public enum ClockTimeTypeEnum {
TIME(0),COUNTING_DOWN(1),COUNTING(2);
public int code;
ClockTimeTypeEnum(int code) {
this.code = code;
}
public static ClockTimeTypeEnum valueOf(int code){
switch (code){
case 1:
return COUNTING_DOWN;
case 2:
return COUNTING;
default:
return TIME;
}
}
}

View File

@ -1,4 +0,0 @@
package clock.socoolby.com.clock.themeUI;
public class DefaultThemeUI {
}

View File

@ -1,4 +0,0 @@
package clock.socoolby.com.clock.themeUI;
public interface I_ThemeUI {
}

View File

@ -1,36 +1,35 @@
package clock.socoolby.com.clock.utils;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.PowerManager;
import android.os.SystemClock;
import androidx.appcompat.app.AppCompatActivity;
import android.view.Window;
import android.view.WindowManager;
import java.util.List;
import clock.socoolby.com.clock.ClockApplication;
import clock.socoolby.com.clock.ActivateAdmin;
import clock.socoolby.com.clock.ClockApplication;
public class ScreenManager {
public static boolean isScreenOn() {
PowerManager pm = (PowerManager) ClockApplication.getContext().getSystemService(Activity.POWER_SERVICE);
PowerManager pm = (PowerManager) ClockApplication.getContext().getSystemService(AppCompatActivity.POWER_SERVICE);
return pm.isScreenOn();
}
public static void turnScreenOff() {
PowerManager pm = (PowerManager) ClockApplication.getContext().getSystemService(Activity.POWER_SERVICE);
PowerManager pm = (PowerManager) ClockApplication.getContext().getSystemService(AppCompatActivity.POWER_SERVICE);
//pm.goToSleep(SystemClock.uptimeMillis());
}
public static void systemLock(Activity context) {
public static void systemLock(AppCompatActivity context) {
DevicePolicyManager policyManager;
ComponentName componentName;
policyManager = (DevicePolicyManager) context.getSystemService(Activity.DEVICE_POLICY_SERVICE);
policyManager = (DevicePolicyManager) context.getSystemService(AppCompatActivity.DEVICE_POLICY_SERVICE);
componentName = new ComponentName(context, ActivateAdmin.class);
@ -50,7 +49,7 @@ public class ScreenManager {
}
public static void systemUnLock() {
PowerManager pm = (PowerManager) ClockApplication.getContext().getSystemService(Activity.POWER_SERVICE);
PowerManager pm = (PowerManager) ClockApplication.getContext().getSystemService(AppCompatActivity.POWER_SERVICE);
//PowerManager.WakeLock mWakelock = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.FULL_WAKE_LOCK, "SimpleTimer");
//mWakelock.acquire();
}

View File

@ -0,0 +1,45 @@
package clock.socoolby.com.clock.viewmodel;
import android.net.Uri;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;
import clock.socoolby.com.clock.model.SharePerferenceModel;
public class AlterViewModel extends ViewModel {
private MutableLiveData<Uri> handUpMusic=new MutableLiveData<>();
private MutableLiveData<Integer> handUPDialy=new MutableLiveData<>();
//alter handUp UI
private MutableLiveData<String> handUpDescription=new MutableLiveData<>();
SharePerferenceModel model;
public AlterViewModel(SharePerferenceModel model) {
this.model = model;
loadFromModel();
}
public void loadFromModel(){
String handUpMusicString=model.getHandUpMusic();
Uri musicUri=handUpMusicString.isEmpty()?null:Uri.parse(handUpMusicString);
handUpMusic.setValue(musicUri);
}
public MutableLiveData<Uri> getHandUpMusic() {
return handUpMusic;
}
public MutableLiveData<String> getHandUpDescription() {
return handUpDescription;
}
public MutableLiveData<Integer> getHandUPDialy() {
return handUPDialy;
}
}

View File

@ -0,0 +1,137 @@
package clock.socoolby.com.clock.viewmodel;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;
import clock.socoolby.com.clock.dao.base.TimeFontStyle;
import clock.socoolby.com.clock.model.SharePerferenceModel;
import clock.socoolby.com.clock.widget.textview.ShadowTypeEnum;
import clock.socoolby.com.clock.widget.textview.charanimator.CharAnimatorEnum;
public class DigitViewModel extends ViewModel {
private MutableLiveData<Boolean> displaySecond=new MutableLiveData<>();
private MutableLiveData<TimeFontStyle> timeFontStyle =new MutableLiveData<>();
private MutableLiveData<String> timeText =new MutableLiveData<>();
private MutableLiveData<Boolean> linearGradientAble=new MutableLiveData<>();
private MutableLiveData<Integer[]> timeLinearGradientColorsArray=new MutableLiveData<>();
private MutableLiveData<Boolean> reflectedAble=new MutableLiveData<>();//倒影
private MutableLiveData<Integer> timeFontStyleSize=new MutableLiveData<>();
private MutableLiveData<ShadowTypeEnum> shadowType=new MutableLiveData<>();//0:不设置1阴影2:浮雕
private MutableLiveData<CharAnimatorEnum> timeCharAnimatorType=new MutableLiveData<>();
private MutableLiveData<Integer> baseLineDown=new MutableLiveData<>();
SharePerferenceModel model;
public DigitViewModel(SharePerferenceModel model) {
this.model = model;
loadFromModel();
}
private void loadFromModel(){
displaySecond.setValue(model.isDisplaySecond());
linearGradientAble.setValue(model.isLinearGradientAble());
timeLinearGradientColorsArray.setValue(model.getTimeColorsArray());
reflectedAble.setValue(model.isReflectedAble());
shadowType.setValue(ShadowTypeEnum.valueOf(model.getShadowType()));
timeCharAnimatorType.setValue(CharAnimatorEnum.valueOf(model.getTimeTextCharAnimatorType()));
baseLineDown.setValue(0);
timeFontStyleSize.setValue(100);
}
public MutableLiveData<Boolean> getDisplaySecond() {
return displaySecond;
}
public MutableLiveData<TimeFontStyle> getTimeFontStyle() {
return timeFontStyle;
}
public MutableLiveData<String> getTimeText() {
return timeText;
}
public MutableLiveData<Boolean> getLinearGradientAble() {
return linearGradientAble;
}
public MutableLiveData<Integer[]> getTimeLinearGradientColorsArray() {
return timeLinearGradientColorsArray;
}
public MutableLiveData<Boolean> getReflectedAble() {
return reflectedAble;
}
public MutableLiveData<Integer> getTimeFontStyleSize() {
return timeFontStyleSize;
}
public MutableLiveData<ShadowTypeEnum> getShadowType() {
return shadowType;
}
public MutableLiveData<CharAnimatorEnum> getTimeCharAnimatorType() {
return timeCharAnimatorType;
}
public MutableLiveData<Integer> getBaseLineDown() {
return baseLineDown;
}
public void setDisplaySecond(Boolean displaySecond) {
this.displaySecond.setValue(displaySecond);
model.setDisplaySecond(displaySecond);
}
public void setTimeFontStyle(TimeFontStyle timeFontStyle) {
this.timeFontStyle.setValue(timeFontStyle);
model.setFontName(timeFontStyle.name);
}
public void setTimeText(String timeText) {
this.timeText.setValue(timeText);
}
public void setLinearGradientAble(Boolean linearGradientAble) {
this.linearGradientAble.setValue(linearGradientAble);
model.setLinearGradientAble(linearGradientAble);
}
public void setTimeLinearGradientColorsArray(Integer[] timeLinearGradientColorsArray) {
this.timeLinearGradientColorsArray.setValue(timeLinearGradientColorsArray);
model.setTimeColorsArray(timeLinearGradientColorsArray);
}
public void setReflectedAble(MutableLiveData<Boolean> reflectedAble) {
this.reflectedAble = reflectedAble;
}
public void setTimeFontStyleSize(Integer timeFontStyleSize) {
this.timeFontStyleSize.setValue(timeFontStyleSize);
}
public void setShadowType(ShadowTypeEnum shadowType) {
this.shadowType.setValue(shadowType);
model.setShadowType(shadowType.getTypeCode());
}
public void setTimeCharAnimatorType(CharAnimatorEnum timeCharAnimatorType) {
this.timeCharAnimatorType.setValue(timeCharAnimatorType);
model.setTimeTextCharAnimatorType(timeCharAnimatorType.getStyleCode());
}
public void setBaseLineDown(Integer baseLineDown) {
this.baseLineDown.setValue(baseLineDown);
}
}

View File

@ -0,0 +1,256 @@
package clock.socoolby.com.clock.viewmodel;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;
import android.net.Uri;
import java.util.Date;
import clock.socoolby.com.clock.model.SharePerferenceModel;
import clock.socoolby.com.clock.state.ClockModeEnum;
import clock.socoolby.com.clock.state.ClockInterfaceTypeEnum;
public class GlobalViewModel extends ViewModel {
//ui
private MutableLiveData<Integer> backgroundColor=new MutableLiveData<>();
private MutableLiveData<Integer> foregroundColor=new MutableLiveData<>();
private MutableLiveData<Uri> backgroundImageUri=new MutableLiveData<>();
private MutableLiveData<String> backgroundAnimatorName=new MutableLiveData<>();
private MutableLiveData<Integer> backgroundAnimatorColor=new MutableLiveData<>();
private Boolean backgroundAnimatorRandomColor=false;
private MutableLiveData<ClockInterfaceTypeEnum> clockInterfaceTypeEnum =new MutableLiveData<>();
private MutableLiveData<Boolean> srceenLock=new MutableLiveData<>();
private MutableLiveData<Boolean> backgroundImageVisable=new MutableLiveData<>();
private MutableLiveData<Boolean> autoFullScreen=new MutableLiveData<>();
//system
private Boolean tickSound=false;
private MutableLiveData<String> mCity=new MutableLiveData<>();
private MutableLiveData<Integer> brightness=new MutableLiveData<>();
//alter handUp
private MutableLiveData<Integer> handUpTime=new MutableLiveData<>();
private MutableLiveData<Boolean> handUpAble=new MutableLiveData<>();
//state
private MutableLiveData<ClockModeEnum> clockModeEnum=new MutableLiveData<>();
private MutableLiveData<Boolean> hourSystem12=new MutableLiveData<>();
private MutableLiveData<Integer> time_hour=new MutableLiveData<>();
private MutableLiveData<Date> time_day=new MutableLiveData<>();
SharePerferenceModel model;
public GlobalViewModel(SharePerferenceModel model) {
this.model = model;
loadFromModel();
}
public void loadFromModel(){
srceenLock.setValue(false);
brightness.setValue(100);
mCity.setValue(model.getCity());
backgroundColor.setValue(model.getBackgroundColor());
foregroundColor.setValue(model.getForegroundColor());
String backgroundImage=model.getBackgroundImage();
Uri imageUri=backgroundImage.isEmpty()?null:Uri.parse(backgroundImage);
backgroundImageUri.setValue(imageUri);
tickSound=model.isTickSound();
backgroundAnimatorName.setValue(model.getBackgroundAnimatorName());
backgroundAnimatorColor.setValue(model.getForegroundColor1());
backgroundAnimatorRandomColor=model.isBackgroundAnimatorRandomColor();
clockInterfaceTypeEnum.setValue(ClockInterfaceTypeEnum.valueOf(model.getClockInterfaceType()));
autoFullScreen.setValue(model.isAutoFullscreen());
clockModeEnum.setValue(ClockModeEnum.NORMAL);
handUpAble.setValue(model.isHandUpAble());
handUpTime.setValue(model.getHandUpTime());
}
public MutableLiveData<String> getCity() {
return mCity;
}
public MutableLiveData<Integer> getBackgroundColor() {
return backgroundColor;
}
public MutableLiveData<Integer> getForegroundColor() {
return foregroundColor;
}
public MutableLiveData<Uri> getBackgroundImageUri() {
return backgroundImageUri;
}
public Boolean isTickSound() {
return tickSound;
}
public MutableLiveData<String> getBackgroundAnimatorName() {
return backgroundAnimatorName;
}
public Boolean getBackgroundAnimatorRandomColor() {
return backgroundAnimatorRandomColor;
}
public MutableLiveData<Boolean> getSrceenLock() {
return srceenLock;
}
public MutableLiveData<Integer> getBrightness() {
return brightness;
}
public MutableLiveData<ClockInterfaceTypeEnum> getClockInterfaceTypeEnum() {
return clockInterfaceTypeEnum;
}
public MutableLiveData<ClockModeEnum> getClockModeEnum() {
return clockModeEnum;
}
public MutableLiveData<Boolean> getBackgroundImageVisable() {
return backgroundImageVisable;
}
public MutableLiveData<Boolean> getHourSystem12() {
return hourSystem12;
}
public MutableLiveData<Integer> getTime_hour() {
return time_hour;
}
public MutableLiveData<Date> getTime_day() {
return time_day;
}
public Boolean getTickSound() {
return tickSound;
}
public MutableLiveData<Integer> getBackgroundAnimatorColor() {
return backgroundAnimatorColor;
}
public MutableLiveData<Integer> getHandUpTime() {
return handUpTime;
}
public MutableLiveData<Boolean> getHandUpAble() {
return handUpAble;
}
public void setCity(String mCity) {
this.mCity.setValue(mCity);
model.setCity(mCity);
}
public void setBackgroundColor(Integer backgroundColor) {
this.backgroundColor.setValue(backgroundColor);
model.setBackgroundColor(backgroundColor);
}
public void setForegroundColor(Integer foregroundColor) {
this.foregroundColor.setValue(foregroundColor);
}
public void setBackgroundImageUri(Uri backgroundImageUri) {
this.backgroundImageUri.setValue(backgroundImageUri);
}
public void setBackgroundAnimatorName(String backgroundAnimatorName) {
this.backgroundAnimatorName.setValue(backgroundAnimatorName);
model.setBackgroundAnimatorName(backgroundAnimatorName);
}
public void setBackgroundAnimatorColor(Integer backgroundAnimatorColor) {
this.backgroundAnimatorColor.setValue(backgroundAnimatorColor);
}
public void setBackgroundAnimatorRandomColor(Boolean backgroundAnimatorRandomColor) {
this.backgroundAnimatorRandomColor=backgroundAnimatorRandomColor;
}
public void setClockInterfaceTypeEnum(ClockInterfaceTypeEnum clockInterfaceTypeEnum) {
this.clockInterfaceTypeEnum.setValue(clockInterfaceTypeEnum);
model.setClockInterfaceType(clockInterfaceTypeEnum.code);
}
public void setSrceenLock(Boolean srceenLock) {
this.srceenLock.setValue(srceenLock);
}
public void setBackgroundImageVisable(Boolean backgroundImageVisable) {
this.backgroundImageVisable.setValue(backgroundImageVisable);
}
public void setTickSound(Boolean tickSound) {
this.tickSound = tickSound;
model.setTickSound(tickSound);
}
public void setBrightness(Integer brightness) {
this.brightness.setValue(brightness);
}
public void setClockModeEnum(ClockModeEnum clockModeEnum) {
this.clockModeEnum.setValue(clockModeEnum);
}
public void setHourSystem12(Boolean hourSystem12) {
this.hourSystem12.setValue(hourSystem12);
model.setHourSystem12(hourSystem12);
}
public void setTime_hour(Integer time_hour) {
this.time_hour.setValue(time_hour);
}
public void setTime_day(Date time_day) {
this.time_day.setValue(time_day);
}
public MutableLiveData<Boolean> getAutoFullScreen() {
return autoFullScreen;
}
public void setAutoFullScreen(Boolean autoFullScreen) {
this.autoFullScreen.setValue(autoFullScreen);
model.setAutoFullscreen(autoFullScreen);
}
public void setHandUpTime(Integer handUpTime) {
this.handUpTime.setValue(handUpTime);
model.setHandUpTime(handUpTime);
}
public void setHandUpAble(Boolean handUpAble) {
this.handUpAble.setValue(handUpAble);
model.setHandUpAble(handUpAble);
}
}

View File

@ -0,0 +1,43 @@
package clock.socoolby.com.clock.viewmodel;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;
import clock.socoolby.com.clock.model.SharePerferenceModel;
public class SimulateViewModel extends ViewModel {
private MutableLiveData<String> clockTypeName=new MutableLiveData<>();
private MutableLiveData<String> pointerTypeName=new MutableLiveData<>();
SharePerferenceModel model;
public SimulateViewModel(SharePerferenceModel model) {
this.model = model;
loadFromModel();
}
private void loadFromModel(){
clockTypeName.setValue(model.getSimulateClockTypeName());
pointerTypeName.setValue(model.getSimulateClockPointerTypeName());
}
public MutableLiveData<String> getClockTypeName() {
return clockTypeName;
}
public MutableLiveData<String> getPointerTypeName() {
return pointerTypeName;
}
public void setClockTypeName(String clockTypeName) {
this.clockTypeName.setValue(clockTypeName);
model.setSimulateClockTypeName(clockTypeName);
}
public void setPointerTypeName(String pointerTypeName) {
this.pointerTypeName.setValue(pointerTypeName);
model.setSimulateClockPointerTypeName(pointerTypeName);
}
}

View File

@ -0,0 +1,99 @@
package clock.socoolby.com.clock.viewmodel;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;
import clock.socoolby.com.clock.model.SharePerferenceModel;
import clock.socoolby.com.clock.state.ClockThemeUITypeEnum;
public class ThemeUIViewModel extends ViewModel {
//Theme UI部分
private MutableLiveData<String> description=new MutableLiveData<>();
private MutableLiveData<ClockThemeUITypeEnum> clockUITypeEnum=new MutableLiveData<>();
private MutableLiveData<String> weatherDescription=new MutableLiveData<>();
private MutableLiveData<String> dayDescription=new MutableLiveData<>();
private MutableLiveData<String> weekDescription=new MutableLiveData<>();
private MutableLiveData<Boolean> hand_time_visable=new MutableLiveData<>();
private MutableLiveData<String> themeName=new MutableLiveData<>();
SharePerferenceModel model;
public ThemeUIViewModel(SharePerferenceModel model) {
this.model = model;
loadFromModel();
}
private void loadFromModel(){
description.setValue(model.getDescription());
themeName.setValue(model.getThemeName());
clockUITypeEnum.setValue(ClockThemeUITypeEnum.valueOf(model.getThemeUIType()));
}
public MutableLiveData<String> getDescription() {
return description;
}
public MutableLiveData<ClockThemeUITypeEnum> getClockUITypeEnum() {
return clockUITypeEnum;
}
public MutableLiveData<String> getWeatherDescription() {
return weatherDescription;
}
public MutableLiveData<String> getDayDescription() {
return dayDescription;
}
public MutableLiveData<String> getWeekDescription() {
return weekDescription;
}
public MutableLiveData<Boolean> getHand_time_visable() {
return hand_time_visable;
}
public MutableLiveData<String> getThemeName() {
return themeName;
}
public void setDescription(String description) {
this.description.setValue(description);
}
public void setClockUITypeEnum(ClockThemeUITypeEnum clockUITypeEnum) {
this.clockUITypeEnum.setValue(clockUITypeEnum);
model.setThemeUIType(clockUITypeEnum.code);
}
public void setWeatherDescription(String weatherDescription) {
this.weatherDescription.setValue(weatherDescription);
}
public void setDayDescription(String dayDescription) {
this.dayDescription.setValue(dayDescription);
}
public void setWeekDescription(String weekDescription) {
this.weekDescription.setValue(weekDescription);
}
public void setHand_time_visable(Boolean hand_time_visable) {
this.hand_time_visable.setValue(hand_time_visable);
}
public void setThemeName(String themeName) {
this.themeName.setValue(themeName);
model.setThemeName(themeName);
}
}

View File

@ -0,0 +1,35 @@
package clock.socoolby.com.clock.viewmodel;
import androidx.lifecycle.ViewModel;
import androidx.lifecycle.ViewModelProvider;
import androidx.annotation.NonNull;
import clock.socoolby.com.clock.model.SharePerferenceModel;
import e.odbo.data.dao.EntityManager;
public class ViewModelFactory extends ViewModelProvider.NewInstanceFactory{
SharePerferenceModel model;
EntityManager entityManager;
public ViewModelFactory(SharePerferenceModel model, EntityManager entityManager) {
this.model = model;
this.entityManager = entityManager;
}
@NonNull
@Override
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
if(GlobalViewModel.class.isAssignableFrom(modelClass))
return (T)new GlobalViewModel(model);
if(SimulateViewModel.class.isAssignableFrom(modelClass))
return (T)new SimulateViewModel(model);
if(DigitViewModel.class.isAssignableFrom(modelClass))
return (T)new DigitViewModel(model);
if(ThemeUIViewModel.class.isAssignableFrom(modelClass))
return (T)new ThemeUIViewModel(model);
if(AlterViewModel.class.isAssignableFrom(modelClass))
return (T)new AlterViewModel(model);
return super.create(modelClass);
}
}

View File

@ -4,11 +4,13 @@ import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.graphics.drawable.Drawable;
import android.support.v4.graphics.drawable.DrawableCompat;
import androidx.core.graphics.drawable.DrawableCompat;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;
import android.view.WindowManager;
@ -19,7 +21,9 @@ import java.util.Random;
public abstract class AbstractAnimator<T extends I_AnimatorEntry> implements I_Animator{
protected Random rand=new Random();
protected boolean isRuning=false;
protected int color=200;
protected int color= Color.BLACK;
protected View mainView;
protected Context context;
@ -74,7 +78,8 @@ public abstract class AbstractAnimator<T extends I_AnimatorEntry> implements I_A
protected void init(){
initPaint(mPaint);
initEntryList();
if(entryQuantity!=DYNAMIC_QUANTITY)
initEntryList();
}
protected void initEntryList(){
@ -119,14 +124,13 @@ public abstract class AbstractAnimator<T extends I_AnimatorEntry> implements I_A
}
protected void initPaint(Paint mPaint){
mPaint.reset();
mPaint.setColor(color);
}
protected void beforeRemoveAnimatorEntry(T entry){
}
public void reset(){
if(entryQuantity!=DYNAMIC_QUANTITY) {
for (T entry : list)
@ -173,11 +177,17 @@ public abstract class AbstractAnimator<T extends I_AnimatorEntry> implements I_A
@Override
public void setColor(int color) {
if(!isColorUseAble())
return;
this.color=color;
mPaint.setColor(color);
for(T entry:list)
entry.setAnimatorEntryColor(color);
}
@Override
public void onSizeChanged(int w, int h, int oldw, int oldh) {
Log.d("animator","onSizeChanged w:"+w+"h:"+h+"oldw:"+oldw+"oldh:"+oldh);
width=w;
height=h;
if(isRuning)

View File

@ -2,6 +2,7 @@ package clock.socoolby.com.clock.widget.animatorview;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.View;
@ -12,7 +13,7 @@ public class AnimatorView extends View {
private Context context;
private I_Animator animator;
private int color=0;
private int color= Color.BLACK;
public AnimatorView(Context context) {
super(context);
@ -85,7 +86,6 @@ public class AnimatorView extends View {
this.color=color;
if(animator!=null&&animator.isColorUseAble()&&!animator.isRandColor()) {
animator.setColor(color);
animator.restart();
}
}
}

View File

@ -8,4 +8,6 @@ public interface I_AnimatorEntry {
void move(int maxWidth, int maxHight);
void onDraw(Canvas canvas, Paint mPaint);
void setAnimatorEntryColor(int color);
}

View File

@ -0,0 +1,95 @@
package clock.socoolby.com.clock.widget.animatorview.animator;
import java.util.HashMap;
import java.util.Map;
import clock.socoolby.com.clock.widget.animatorview.AbstractAnimator;
import clock.socoolby.com.clock.widget.animatorview.animator.textanimator.EZLedAnimator;
import clock.socoolby.com.clock.widget.animatorview.animator.textanimator.EvaporateTextAnimator;
public class AnimatorFactory {
public static Map<String,AnimatorEntry> entryMap=new HashMap<>();
public static Class[] animatorClassArray = new Class[]{
StarFallAnimator.class,
SkyAnimator.class,
RainAnimator.class,
SnowAnimator.class,
BubbleWhirlPoolAnimator.class,
BubbleAnimator.class,
FluorescenceAnimator.class,
BubbleCollisionAnimator.class,
FireworkAnimator.class,
DotsLineAnimator.class,
WaterAnimator.class,
FireAnimator.class,
SawtoothAnimator.class,
WindmillAnimator.class,
VorolayAnimator.class,
EZLedAnimator.class,
EvaporateTextAnimator.class,
PhaserBallAnimator.class,
CarrouselAnimator.class,
Wave3DAnimator.class,
MagicLineAnimator.class
};
static {
for(Class c:animatorClassArray)
addAnimatorEntryToMap(c);
}
public static void addAnimatorEntryToMap(Class animatorClass){
addAnimatorEntryToMap(getInstance(animatorClass));
}
public static void addAnimatorEntryToMap(Class animatorClass,boolean randomColorAble){
addAnimatorEntryToMap(getInstance(animatorClass,randomColorAble));
}
public static void addAnimatorEntryToMap(AnimatorEntry animatorEntry){
entryMap.put(animatorEntry.type,animatorEntry);
}
public static AnimatorEntry getInstance(Class animatorClass){
return getInstance(animatorClass,true);
}
public static AnimatorEntry getInstance(Class animatorClass,boolean randomColorAble){
return new AnimatorEntry(animatorClass,randomColorAble);
}
public static class AnimatorEntry{
String type;
Class animatorClass;
boolean randomColorAble;
public AnimatorEntry(Class animatorClass) {
this.animatorClass = animatorClass;
this.type=animatorClass.getSimpleName();
randomColorAble=true;
}
public AnimatorEntry(Class animatorClass, boolean randomColorAble) {
this.animatorClass = animatorClass;
this.randomColorAble = randomColorAble;
this.type=animatorClass.getSimpleName();
}
}
public static AbstractAnimator build(String name){
AnimatorEntry entry=entryMap.get(name);
if(entry==null)
return null;
AbstractAnimator ret=null;
try {
ret= (AbstractAnimator) entry.animatorClass.newInstance();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
}
return ret;
}
}

View File

@ -109,6 +109,11 @@ public class BubbleAnimator extends AbstractAnimator<BubbleAnimator.Bubble> {
mPaint.setColor(color);
canvas.drawCircle(x, y,radius, mPaint);
}
@Override
public void setAnimatorEntryColor(int color) {
this.color=color;
}
}
// 尝试创建气泡

View File

@ -127,5 +127,12 @@ public class BubbleCollisionAnimator extends AbstractAnimator<BubbleCollisionAni
mPaint.setColor(color);
canvas.drawCircle(cx, cy, radius, mPaint);
}
@Override
public void setAnimatorEntryColor(int color) {
this.color=color;
}
}
}

View File

@ -215,6 +215,12 @@ public class BubbleWhirlPoolAnimator extends AbstractAnimator<BubbleWhirlPoolAni
mPaint.setAlpha(a);
canvas.drawCircle(center.getX(), center.getY(), r, mPaint);
}
@Override
public void setAnimatorEntryColor(int color) {
this.circleColor=color;
}
}
private void changeCenterPoint(CircleCenterPoint center, int type) {

View File

@ -158,6 +158,13 @@ public class CarrouselAnimator extends AbstractAnimator<CarrouselAnimator.Carrou
}
}
@Override
public void setAnimatorEntryColor(int color) {
for(PointCicle pointCicle:mCarrouselViews){
pointCicle.color=color;
}
}
/**
* 通过角度计算是第几个item
*

View File

@ -1,8 +1,12 @@
package clock.socoolby.com.clock.widget.animatorview.animator;
import android.graphics.Color;
import android.util.Log;
import clock.socoolby.com.clock.widget.animatorview.AbstractAnimator;
import clock.socoolby.com.clock.widget.animatorview.animator.clockanimator.AbstractClock;
import clock.socoolby.com.clock.widget.animatorview.animator.clockanimator.I_Pointer;
import clock.socoolby.com.clock.widget.animatorview.animator.clockanimator.pointer.DefaultPointer;
import clock.socoolby.com.clock.widget.animatorview.animator.clockanimator.pointer.LeafPointer;
import clock.socoolby.com.clock.widget.animatorview.animator.clockanimator.pointer.LeafTwoPointer;
@ -28,6 +32,7 @@ public class ClockAnimator extends AbstractAnimator<AbstractClock> {
@Override
public boolean run() {
//Log.d("clock","animator is running: "+(clock!=null));
if(clock==null)
return false;
return super.run();
@ -36,11 +41,24 @@ public class ClockAnimator extends AbstractAnimator<AbstractClock> {
public void setClock(AbstractClock clock1){
list.clear();
this.clock=clock1;
int textColor=color;
randomColorIfAble();
int minHigh=Math.min(width,height);
clock.init(width,height,width/2,height/2,minHigh/2,color,textColor);
clock.init(width,height,width/2,height/2,minHigh/2,color,color);
list.add(clock);
Log.d("clock","set clock type: "+clock1.typeName()+"\t color:"+ color);
}
public void setClockPointer(I_Pointer pointer){
clock.setPointer(pointer);
}
@Override
public void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
if(clock!=null) {
int minHigh=Math.min(width,height);
clock.init(width, height, width / 2, height / 2, minHigh / 2, color, color);
}
}
int randPointerIndex=1;

View File

@ -100,5 +100,10 @@ public class DotsLineAnimator extends AbstractAnimator<DotsLineAnimator.Circle>
public void onDraw(Canvas canvas, Paint mPaint) {
drawCircle(canvas,mPaint);
}
@Override
public void setAnimatorEntryColor(int color) {
this.color=color;
}
}
}

View File

@ -133,6 +133,11 @@ public class DrawableArrayFallAnimator extends AbstractAnimator<DrawableArrayFa
matrix.postTranslate(width/2 + x, height/2 + y);
canvas.drawBitmap(bitmap, matrix, null);
}
@Override
public void setAnimatorEntryColor(int color) {
}
}
static HashMap<Integer, Bitmap> bitmapCacheMap = new HashMap<Integer, Bitmap>();

View File

@ -12,12 +12,10 @@ import clock.socoolby.com.clock.widget.animatorview.I_AnimatorEntry;
//参考: https://www.jianshu.com/p/0d4ab16a6b7b
public class FireAnimator extends AbstractCacheDifferenceAnimator<FireAnimator.ParticleSystem, FireAnimator.Particle> {
public FireAnimator() {
super(1);
}
int high=0;
int fireWidth=0;
int particlesCount;
@ -26,10 +24,11 @@ public class FireAnimator extends AbstractCacheDifferenceAnimator<FireAnimator.P
high=rand.nextInt(height);
if(high<=height/3)
high=high+height/2;
randomColorIfAble();
fireWidth=rand.nextInt(width/2);
particlesCount=rand.nextInt(300);
particlesCount=particlesCount>150?particlesCount:particlesCount+150;
return new ParticleSystem(width/2,height,high,fireWidth,particlesCount,rand.nextInt(30));
return new ParticleSystem(width/2,height,high,fireWidth,particlesCount,rand.nextInt(30),color);
}
@ -37,11 +36,10 @@ public class FireAnimator extends AbstractCacheDifferenceAnimator<FireAnimator.P
private List<Particle> particles = new ArrayList<>();
private int fire_width = 20;
private int particle_width=20;
private Paint paint = new Paint();
private int x,y,high;
private int color;
public ParticleSystem(int x,int y,int high,int fire_width,int particlesCount,int particle_width) {
public ParticleSystem(int x,int y,int high,int fire_width,int particlesCount,int particle_width,int color) {
this.x=x;
this.y=y;
this.high=high;
@ -49,11 +47,7 @@ public class FireAnimator extends AbstractCacheDifferenceAnimator<FireAnimator.P
this.particle_width=particle_width;
if(particle_width<10)
this.particle_width=10;
if(randColor) {
randomColorIfAble();
paint.setColor(color);
}else
paint.setColor(Color.RED);
this.color=color;
for (int i = 0; i < particlesCount; i++) {
particles.add(newParticle());
}
@ -126,11 +120,16 @@ public class FireAnimator extends AbstractCacheDifferenceAnimator<FireAnimator.P
@Override
public void onDraw(Canvas canvas, Paint mPaint) {
mPaint.setColor(color);
for (int i = 0; i < particles.size(); i++) {
Particle particle = particles.get(i);
paint.setAlpha(particle.alpha);
canvas.drawRect(particle.getX(), particle.getY(), particle.getX() + particle_width, particle.getY() + particle_width, paint);
}
mPaint.setAlpha(particle.alpha);
canvas.drawRect(particle.getX(), particle.getY(), particle.getX() + particle_width, particle.getY() + particle_width, mPaint); }
}
@Override
public void setAnimatorEntryColor(int color) {
this.color=color;
}
}

View File

@ -343,6 +343,11 @@ public class FireworkAnimator extends AbstractCacheDifferenceAnimator<FireworkAn
canvas.drawCircle(x+SMALL_DEFAULT_ELEMENT_SIZE/2,y,SMALL_DEFAULT_ELEMENT_SIZE,mPaint);
}
}
@Override
public void setAnimatorEntryColor(int color) {
}
}
public enum STYLE{

View File

@ -23,7 +23,6 @@ public class FluorescenceAnimator extends AbstractAnimator<FluorescenceAnimator.
private int mParticleRandomLife = 8000; //随机范围基数上范围
private int mParticleNum = 20; //粒子数量
private int[] mParticleColors = {0xFF0d4289, 0xff034aa1,0x887b0808, 0xff176bd1, 0xff1f39ff,0x33d4ed00, 0x66ffffff, 0xff777800, 0xff0e2569};//粒子颜色集合
private Paint mPaint;
List<Particle> cache = new LinkedList<>();
@ -180,5 +179,10 @@ public class FluorescenceAnimator extends AbstractAnimator<FluorescenceAnimator.
mPaint.setAlpha((int)(getTranslate() * 255));
canvas.drawCircle(point.x, point.y, getRadius(), mPaint);
}
@Override
public void setAnimatorEntryColor(int color) {
this.color=color;
}
}
}

View File

@ -35,6 +35,15 @@ public class MagicLineAnimator extends AbstractCacheDifferenceAnimator<MagicLine
{200, 500, 0.4f, 500, 200, 0.4f}
};
@Override
protected void initPaint(Paint mPaint) {
super.initPaint(mPaint);
mPaint.setAntiAlias(true);
mPaint.setStrokeWidth(2);
mPaint.setStyle(Paint.Style.FILL);
mPaint.setAlpha(50);
}
public class MagicLine implements I_AnimatorEntry {
//起点在xy移动范围
@ -42,7 +51,6 @@ public class MagicLineAnimator extends AbstractCacheDifferenceAnimator<MagicLine
private float p2XLength = 20, p2YLength = 400, speedP2 = 0.05f;
private double angleP1 = 0, angleP2 = 0;
private int viewWidth, viewHeight;
private Paint paint;
//记录移动过的所有点的数据
private List<CorrdinateData> corrDatas;
//动画绘制的时间
@ -68,18 +76,18 @@ public class MagicLineAnimator extends AbstractCacheDifferenceAnimator<MagicLine
public void onDraw(Canvas canvas, Paint mPaint) {
for (int i = 0; i < corrDatas.size(); i++) {
CorrdinateData cd = corrDatas.get(i);
paint.setColor(cd.color);
canvas.drawLine(cd.p1X, cd.p1Y, cd.p2X, cd.p2Y, paint);
mPaint.setColor(cd.color);
canvas.drawLine(cd.p1X, cd.p1Y, cd.p2X, cd.p2Y, mPaint);
}
}
@Override
public void setAnimatorEntryColor(int color) {
for(CorrdinateData entry:corrDatas)
entry.color=color;
}
private void init() {
paint = new Paint();
paint.setAntiAlias(true);
paint.setStrokeWidth(2);
paint.setStyle(Paint.Style.FILL);
//paint.setColor(Color.WHITE);
paint.setAlpha(50);
// Shader shader = new LinearGradient(cd.p1X, cd.p1Y, cd.p2X, cd.p2Y, colors, null, Shader.TileMode.MIRROR);
// paint.setShader(shader);
corrDatas = new ArrayList<>();

View File

@ -135,5 +135,10 @@ public class PhaserBallAnimator extends AbstractAnimator<PhaserBallAnimator.Phas
mPaint.setColor(color);
canvas.drawCircle(currentX,currentY,r,mPaint);
}
@Override
public void setAnimatorEntryColor(int color) {
this.color=color;
}
}
}

View File

@ -28,7 +28,6 @@ public class RainAnimator extends AbstractAnimator<RainAnimator.Rain> {
return new Rain();
}
private final int size = 50; //长度在0-50像素
public class Rain implements I_AnimatorEntry {
@ -42,7 +41,6 @@ public class RainAnimator extends AbstractAnimator<RainAnimator.Rain> {
reset();
}
private void reset(){
int x = rand.nextInt(width);
int y = rand.nextInt(height);
@ -94,5 +92,10 @@ public class RainAnimator extends AbstractAnimator<RainAnimator.Rain> {
mPaint.setColor(rainColor);
canvas.drawLine(point.left, point.top, point.right, point.bottom, mPaint);
}
@Override
public void setAnimatorEntryColor(int color) {
this.rainColor=color;
}
}
}

View File

@ -24,7 +24,6 @@ public class RippleAnimator extends AbstractAnimator<RippleAnimator.Ripple> {
list.add(createNewEntry());
}
@Override
public Ripple createNewEntry() {
Style style;
@ -38,6 +37,12 @@ public class RippleAnimator extends AbstractAnimator<RippleAnimator.Ripple> {
return new Ripple(width,height,color,style);
}
@Override
protected void initPaint(Paint mPaint) {
super.initPaint(mPaint);
}
public enum Style{
IN,OUT,BREATH;
}
@ -75,7 +80,6 @@ public class RippleAnimator extends AbstractAnimator<RippleAnimator.Ripple> {
Style style;
public Ripple(float mWidth, float mHeight, int mColor,Style style) {
this.mWidth = mWidth;
this.mHeight = mHeight;
@ -326,6 +330,11 @@ public class RippleAnimator extends AbstractAnimator<RippleAnimator.Ripple> {
drawInCircle(canvas);
}
}
@Override
public void setAnimatorEntryColor(int color) {
}
}

View File

@ -113,6 +113,7 @@ public class SawtoothAnimator extends AbstractAnimator<SawtoothAnimator.Sawtooth
int paddingBottom = 0;
// 横向有效宽度
int validWidth = width - paddingLeft - paddingRight;
// 纵向有效高度
@ -303,6 +304,12 @@ public class SawtoothAnimator extends AbstractAnimator<SawtoothAnimator.Sawtooth
mBeltPaint);
}
@Override
public void setAnimatorEntryColor(int color) {
mDarkRedPaint.setColor(color);
mTransitionPaint.setColor(color);
}
@Override
public void move(int maxWidth, int maxHight) {
mCurProgress +=0.1f;

View File

@ -93,6 +93,11 @@ public class ScrollingImageAnimator extends AbstractAnimator<ScrollingImageAnima
public void onDraw(Canvas canvas, Paint mPaint) {
canvas.drawBitmap(bitmap, offset, startY, null);
}
@Override
public void setAnimatorEntryColor(int color) {
}
}

View File

@ -32,7 +32,7 @@ public class SkyAnimator extends AbstractAnimator<SkyAnimator.Star> {
private final int METEOR = 2;
private int state = NORMAL;
private Paint paint = new Paint();
private Paint paint;
private final int size = 20; // 长度在0-size像素
private int radius;
private Point point; // 星星
@ -57,6 +57,7 @@ public class SkyAnimator extends AbstractAnimator<SkyAnimator.Star> {
public Star(){
point = new Point();
paint=new Paint();
paint.setColor(0xffffffff);
reset();
}
@ -71,7 +72,7 @@ public class SkyAnimator extends AbstractAnimator<SkyAnimator.Star> {
paint.setColor(color);
}
private void drawLightStar (Canvas canvas){
private void drawLightStar (Canvas canvas){
switch (lightState) {
case LIGHT_HALF:
@ -187,5 +188,10 @@ public class SkyAnimator extends AbstractAnimator<SkyAnimator.Star> {
break;
}
}
@Override
public void setAnimatorEntryColor(int color) {
paint.setColor(color);
}
}
}

View File

@ -169,6 +169,11 @@ public class SnowAnimator extends AbstractAnimator<SnowAnimator.SnowPoint> {
drawSknow(canvas,mPaint);
}
}
@Override
public void setAnimatorEntryColor(int color) {
this.color=color;
}
}
public class SnowPoint2 extends SnowPoint{

View File

@ -285,5 +285,10 @@ public class VorolayAnimator extends AbstractAnimator<VorolayAnimator.Vorolay> {
// canvas.drawBorder((float)region.site.x, (float)region.site.y, 10, p);
}
}
@Override
public void setAnimatorEntryColor(int color) {
p.setColor(color);
}
}
}

View File

@ -31,7 +31,8 @@ public class WaterAnimator extends AbstractAnimator<WaterAnimator.Water> {
class Water implements I_AnimatorEntry {
private Path mAbovePath, mBelowWavePath;
private Paint mAboveWavePaint, mBelowWavePaint;
private Paint mAboveWavePaint;
//private Paint mBelowWavePaint;
private DrawFilter mDrawFilter;
@ -62,11 +63,11 @@ public class WaterAnimator extends AbstractAnimator<WaterAnimator.Water> {
mAboveWavePaint.setStyle(Paint.Style.FILL);
mAboveWavePaint.setColor(Color.BLUE);
//下方波浪
mBelowWavePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
/*mBelowWavePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mBelowWavePaint.setAntiAlias(true);
mBelowWavePaint.setStyle(Paint.Style.FILL);
mBelowWavePaint.setColor(Color.BLUE);
mBelowWavePaint.setAlpha(60);
mBelowWavePaint.setAlpha(60);*/
//画布抗锯齿
mDrawFilter = new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
@ -112,6 +113,11 @@ public class WaterAnimator extends AbstractAnimator<WaterAnimator.Water> {
canvas.drawPath(mAbovePath, mAboveWavePaint);
// canvas.drawPath(mBelowWavePath, mBelowWavePaint);
}
@Override
public void setAnimatorEntryColor(int color) {
mAboveWavePaint.setColor(color);
}
}
}

View File

@ -103,6 +103,13 @@ public class Wave3DAnimator extends AbstractAnimator<Wave3DAnimator.Wave> {
}
}
@Override
public void setAnimatorEntryColor(int color) {
for(PointCicle point:datas){
point.color=color;
}
}
}
public class PointCicle{

View File

@ -128,5 +128,11 @@ public class WindmillAnimator extends AbstractAnimator<WindmillAnimator.Windmill
drawLines(canvas);
drawWindMills(canvas);
}
@Override
public void setAnimatorEntryColor(int color) {
mPaint.setColor(color);
this.color=color;
}
}
}

View File

@ -2,6 +2,7 @@ package clock.socoolby.com.clock.widget.animatorview.animator.clockanimator;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.Log;
import java.util.Calendar;
@ -43,7 +44,12 @@ public abstract class AbstractClock implements I_AnimatorEntry {
this.textColor=textColor;
initScaleLength();
init();
setPointer(new DefaultPointer());
if(pointer==null)
setPointer(new DefaultPointer());
else
pointer.init(mRadius,mClockColor);
Log.d("clock","init type:"+typeName()+" \tw:"+width+"\th:"+hight+"\tcX:"+mCenterX+"\tcY:"+mCenterY);
}
private void init() {
@ -86,6 +92,12 @@ public abstract class AbstractClock implements I_AnimatorEntry {
pointer.init(mRadius,mClockColor);
}
@Override
public void setAnimatorEntryColor(int color) {
mClockColor=color;
pointer.init(mRadius,mClockColor);
}
/**
* 获取当前系统时间
*/
@ -216,4 +228,6 @@ public abstract class AbstractClock implements I_AnimatorEntry {
public void move(int maxWidth, int maxHight) {
getTime();
}
public abstract String typeName();
}

View File

@ -1,12 +1,9 @@
package clock.socoolby.com.clock.widget.animatorview.animator.clockanimator;
import android.graphics.Canvas;
import android.graphics.Paint;
public class CircleClock extends AbstractClock {
/**
* 绘制时钟的圆形和刻度
*/
@ -39,5 +36,12 @@ public class CircleClock extends AbstractClock {
canvas.restore();
}
@Override
public String typeName() {
return TYPE_CIRCLE;
}
public static final String TYPE_CIRCLE="circle";
}

View File

@ -4,8 +4,6 @@ import android.graphics.Canvas;
public class CircleTwoClock extends AbstractClock {
/**
* 绘制时钟的圆形和刻度
*/
@ -39,5 +37,10 @@ public class CircleTwoClock extends AbstractClock {
canvas.restore();
}
@Override
public String typeName() {
return TYPE_CIRCLE_TWO;
}
public static final String TYPE_CIRCLE_TWO="circleTWO";
}

View File

@ -0,0 +1,34 @@
package clock.socoolby.com.clock.widget.animatorview.animator.clockanimator;
public class ClockFactory {
public static AbstractClock build(String type){
AbstractClock clock=null;
switch (type){
case CircleClock.TYPE_CIRCLE:
clock=new CircleClock();
break;
case CircleTwoClock.TYPE_CIRCLE_TWO:
clock=new CircleTwoClock();
break;
case HelixClock.TYPE_HELIX:
clock=new HelixClock();
break;
case HexagonalClock.TYPE_HEXAGONAL:
clock=new HexagonalClock();
break;
case OctagonalClock.TYPE_OCTAGONAL:
clock=new OctagonalClock();
break;
case OvalClock.TYPE_OVAL:
clock=new OvalClock();
break;
case SquareClock.TYPE_SQUARE:
clock=new SquareClock();
break;
default:
clock=new CircleClock();
}
return clock;
}
}

View File

@ -41,4 +41,12 @@ public class HelixClock extends AbstractClock {
}
@Override
public String typeName() {
return TYPE_HELIX;
}
public static final String TYPE_HELIX="helix";
}

View File

@ -61,5 +61,11 @@ public class HexagonalClock extends AbstractClock {
canvas.restore();
}
@Override
public String typeName() {
return TYPE_HEXAGONAL;
}
public static final String TYPE_HEXAGONAL="hexagonal";
}

View File

@ -7,6 +7,7 @@ public interface I_Pointer {
void init(float mRadius,int mClockColor);
void drawPointer(Canvas canvas, int mH,int mM,int mS, Paint mPointerPaint);
void drawPointer(Canvas canvas, int mH,int mM,int mS, Paint mPointerPaint);
String typeName();
}

View File

@ -130,4 +130,11 @@ public class OctagonalClock extends AbstractClock {
}
@Override
public String typeName() {
return TYPE_OCTAGONAL;
}
public static final String TYPE_OCTAGONAL="octagonal";
}

View File

@ -39,6 +39,11 @@ public class OvalClock extends AbstractClock {
canvas.restore();
}
@Override
public String typeName() {
return TYPE_OVAL;
}
public static final String TYPE_OVAL="oval";
}

View File

@ -121,5 +121,10 @@ public class SquareClock extends AbstractClock {
return points;
}
@Override
public String typeName() {
return TYPE_SQUARE;
}
public static final String TYPE_SQUARE="square";
}

View File

@ -38,7 +38,10 @@ public abstract class AbstractPointer implements I_Pointer {
mPointerPaint.setColor(mClockColor);
}
public void setmPointerColor(int color){
this.mClockColor=color;
mPointerPaint.setColor(mClockColor);
}
public void initPointerLength(float mRadius){

View File

@ -1,5 +1,11 @@
package clock.socoolby.com.clock.widget.animatorview.animator.clockanimator.pointer;
public class DefaultPointer extends AbstractPointer {
public static final String TYPE_NAME="default";
@Override
public String typeName() {
return TYPE_NAME;
}
}

View File

@ -70,4 +70,13 @@ public class LeafPointer extends SecondTailPointer {
canvas.drawPath(path, mPointerPaint);
}
public static final String TYPE_LEAF="Leaf";
@Override
public String typeName() {
return TYPE_LEAF;
}
}

View File

@ -69,4 +69,13 @@ public class LeafTwoPointer extends SecondTailPointer {
canvas.drawPath(path, mPointerPaint);
}
public static final String TYPE_LEAF_TWO="leafTwo";
@Override
public String typeName() {
return TYPE_LEAF_TWO;
}
}

View File

@ -0,0 +1,32 @@
package clock.socoolby.com.clock.widget.animatorview.animator.clockanimator.pointer;
public class PointerFactory {
public static AbstractPointer build(String name){
AbstractPointer pointer=null;
switch (name){
case LeafPointer.TYPE_LEAF:
pointer=new LeafPointer();
break;
case LeafTwoPointer.TYPE_LEAF_TWO:
pointer=new LeafTwoPointer();
break;
case SecondTailPointer.TYPE_SECOND_TAIL:
pointer=new SecondTailPointer();
break;
case SwordPointer.TYPE_SWORD_POINTER:
pointer=new SwordPointer();
break;
case TrianglePointer.TYPE_TRIANGLE_POINTER:
pointer=new TrianglePointer();
break;
case TwoStepPointer.TYPE_TWO_STEP_POINTER:
pointer=new TwoStepPointer();
break;
default:
pointer= new DefaultPointer();
}
return pointer;
}
}

View File

@ -37,4 +37,12 @@ public class SecondTailPointer extends AbstractPointer{
canvas.drawCircle(0,0,mSecondPointerWidth*2,mPointerPaint);
}
public static final String TYPE_SECOND_TAIL="secondTail";
@Override
public String typeName() {
return TYPE_SECOND_TAIL;
}
}

View File

@ -96,4 +96,12 @@ public class SwordPointer extends SecondTailPointer{
canvas.drawPath(path,mPointerPaint);
}
public static final String TYPE_SWORD_POINTER="SwordPointer";
@Override
public String typeName() {
return TYPE_SWORD_POINTER;
}
}

View File

@ -68,4 +68,12 @@ public class TrianglePointer extends SecondTailPointer{
canvas.drawPath(path,mPointerPaint);
}
public static final String TYPE_TRIANGLE_POINTER="trianglePointer";
@Override
public String typeName() {
return TYPE_TRIANGLE_POINTER;
}
}

View File

@ -53,4 +53,12 @@ public class TwoStepPointer extends SecondTailPointer{
mPointerPaint.setStrokeWidth(mMinutePointerWidth/4);
canvas.drawLine(0,0,x1, y1, mPointerPaint);
}
public static final String TYPE_TWO_STEP_POINTER="twoStepPointer";
@Override
public String typeName() {
return TYPE_TWO_STEP_POINTER;
}
}

View File

@ -38,7 +38,13 @@ public class Particle implements I_AnimatorEntry {
@Override
public void onDraw(Canvas canvas, Paint mPaint) {
mPaint.setColor(color);
if(style!=null)
style.draw(canvas,this,mPaint);
}
@Override
public void setAnimatorEntryColor(int color) {
this.color=color;
}
}

View File

@ -266,6 +266,12 @@ public class EZLedAnimator extends AbstractAnimator<EZLedAnimator.EZLed> {
}
}
@Override
public void setAnimatorEntryColor(int color) {
this.ledColor=color;
paint.setColor(ledColor);
}
/**
* Transform text to bitmap

View File

@ -146,6 +146,11 @@ public class EvaporateTextAnimator extends AbstractAnimator<EvaporateTextAnimato
}
}
@Override
public void setAnimatorEntryColor(int color) {
}
public void setProgress(float progress) {
this.progress = progress;
}

View File

@ -124,6 +124,11 @@ public class PathEffectTextAnimator extends AbstractAnimator<PathEffectTextAnima
//}
}
@Override
public void setAnimatorEntryColor(int color) {
setTextColor(color);
}
private void updatePathsPhaseLocked() {
mPaths.clear();

Some files were not shown because too many files have changed in this diff Show More