diff --git a/README.md b/README.md index d28e9f3..d7b49db 100755 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ An Android clock ### 普通状态 - 左滑:设置 + 左滑:改变背景动画 右滑:改变字本 上滑:增加亮度 下滑:减小亮度 @@ -22,9 +22,14 @@ An Android clock 下面说明条 单击->随机名言 -###定时提醒状态 + 时间 长按-->显示列多功能 + +### 定时提醒状态 倒计时 单击->停止闹铃,返回普通状态 +### 更多功能 + 会出现颜色选择,及设置按键 + ------ 其它在设置页设置 diff --git a/app/build.gradle b/app/build.gradle index c862eb9..98de526 100755 --- a/app/build.gradle +++ b/app/build.gradle @@ -40,4 +40,6 @@ dependencies { implementation 'androidx.cardview:cardview:1.0.0' implementation 'com.blankj:utilcode:1.23.4' + + implementation 'com.larswerkman:HoloColorPicker:1.5' } diff --git a/app/src/main/java/clock/socoolby/com/clock/MainActivity.java b/app/src/main/java/clock/socoolby/com/clock/MainActivity.java index f9c0275..451a2c8 100755 --- a/app/src/main/java/clock/socoolby/com/clock/MainActivity.java +++ b/app/src/main/java/clock/socoolby/com/clock/MainActivity.java @@ -1,15 +1,10 @@ package clock.socoolby.com.clock; -import android.Manifest; + import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.app.Activity; -import android.content.Context; import android.content.Intent; -import android.hardware.Sensor; -import android.hardware.SensorEvent; -import android.hardware.SensorEventListener; -import android.hardware.SensorManager; import android.os.Build; import android.os.Handler; import android.os.Message; @@ -24,6 +19,7 @@ import android.view.MotionEvent; import android.view.View; import android.view.Window; import android.view.WindowManager; +import android.widget.FrameLayout; import android.widget.ImageButton; import android.widget.TextView; import android.widget.Toast; @@ -37,6 +33,7 @@ import java.util.Timer; import java.util.TimerTask; import clock.socoolby.com.clock.pop.CalendarPopup; +import clock.socoolby.com.clock.pop.ColorPickerPop; import clock.socoolby.com.clock.pop.WeatherPopup; import clock.socoolby.com.clock.protocol.WeatherResponse; import clock.socoolby.com.clock.model.DateModel; @@ -46,6 +43,18 @@ import clock.socoolby.com.clock.utils.Player; import clock.socoolby.com.clock.utils.ScreenManager; import clock.socoolby.com.clock.model.SharePerferenceModel; import clock.socoolby.com.clock.pop.TimeSetupPopup; +import clock.socoolby.com.clock.widget.animatorview.AnimatorView; +import clock.socoolby.com.clock.widget.animatorview.I_Animator; +import clock.socoolby.com.clock.widget.animatorview.animator.BubbleAnimator; +import clock.socoolby.com.clock.widget.animatorview.animator.BubbleCollisionAnimator; +import clock.socoolby.com.clock.widget.animatorview.animator.BubbleWhirlPoolAnimator; +import clock.socoolby.com.clock.widget.animatorview.animator.DotsLineAnimator; +import clock.socoolby.com.clock.widget.animatorview.animator.FireworkAnimator; +import clock.socoolby.com.clock.widget.animatorview.animator.FluorescenceAnimator; +import clock.socoolby.com.clock.widget.animatorview.animator.RainAnimator; +import clock.socoolby.com.clock.widget.animatorview.animator.SkyAnimator; +import clock.socoolby.com.clock.widget.animatorview.animator.SnowAnimator; +import clock.socoolby.com.clock.widget.animatorview.animator.StarFallAnimator; import clock.socoolby.com.clock.widget.textview.AutoScrollTextView; @@ -56,7 +65,7 @@ public class MainActivity extends Activity implements Handler.Callback, View.OnC public final static int MODE_NORMAL = 200; public final static int MODE_SETTING_OTHER = 202; public final static int MODE_HANDUP=203; - + clock.socoolby.com.clock.widget.animatorview.AnimatorView view; public final static String[] FONT_NAME_ARRAY={ "cherif", @@ -121,6 +130,20 @@ public class MainActivity extends Activity implements Handler.Callback, View.OnC private Handler handler; private final static int UPDATE_TIME = 100; + //背景动画 + private AnimatorView animatorView; + + private I_Animator backGroundAnimator; + + private int currectAnimatorIndex=0; + + //颜色相关 + private ImageButton tv_background_color; + private ImageButton tv_foreground_color; + private ImageButton tv_foreground_color1; + + ColorPickerPop colorPickerDialog; + // 定义手势检测器实例 GestureDetector detector; @@ -144,6 +167,11 @@ public class MainActivity extends Activity implements Handler.Callback, View.OnC private boolean screenLock=false; private ImageButton tv_screen_lock; + private Integer backgroundColor; + private Integer foregroundColor; + private FrameLayout mainBackground; + + public void setWeather(WeatherResponse weather) { if (weather == null) @@ -161,6 +189,10 @@ public class MainActivity extends Activity implements Handler.Callback, View.OnC super.onCreate(savedInstanceState); //Log.d(TAG,"onCreate..."); setContentView(R.layout.activity_main); + mainBackground=findViewById(R.id.main_background); + + animatorView=findViewById(R.id.tv_background_animatorview); + tv_time = findViewById(R.id.tv_time); tv_date = findViewById(R.id.tv_date); tv_day = findViewById(R.id.tv_day); @@ -179,6 +211,62 @@ public class MainActivity extends Activity implements Handler.Callback, View.OnC } }); + tv_background_color=findViewById(R.id.tv_background_color); + tv_background_color.setOnClickListener(this); + + tv_foreground_color=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 (colorPickerDialog == null) + colorPickerDialog = new ColorPickerPop(MainActivity.this); + + colorPickerDialog.setOnColorChangeListenter(new ColorPickerPop.OnColorListener() { + @Override + public void onEnsure(int color) { + model.setForegroundColor(color); + model.save(); + setForegroundColor(color); + tv_foreground_color.setColorFilter(color); + } + + @Override + public void onBack() { + } + }); + colorPickerDialog.show(model.getForegroundColor()); + return true; + } + }); + + tv_foreground_color1=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 (colorPickerDialog == null) + colorPickerDialog = new ColorPickerPop(MainActivity.this); + + colorPickerDialog.setOnColorChangeListenter(new ColorPickerPop.OnColorListener() { + @Override + public void onEnsure(int color) { + model.setForegroundColor1(color); + model.save(); + setForegroundColor(color); + tv_foreground_color1.setColorFilter(color); + animatorView.setColor(color); + } + + @Override + public void onBack() { + } + }); + colorPickerDialog.show(model.getForegroundColor1()); + return true; + } + }); + tv_handup_image=findViewById(R.id.tv_handup_image); tv_handup_image.setOnClickListener(this); @@ -273,6 +361,15 @@ public class MainActivity extends Activity implements Handler.Callback, View.OnC handUpAbla=model.isHandUpAble(); upHandStatic(); resetHandUpTime(); + resetColorFromModel(); + } + + private void resetColorFromModel(){ + setBackGroundColor(model.getBackgroundColor()); + setForegroundColor(model.getForegroundColor()); + tv_foreground_color.setColorFilter(model.getForegroundColor()); + tv_foreground_color1.setColorFilter(model.getForegroundColor1()); + animatorView.setColor(model.getForegroundColor1()); } //将该Activity上的触碰事件交给GestureDetector处理 @@ -299,6 +396,9 @@ public class MainActivity extends Activity implements Handler.Callback, View.OnC }catch (Exception e){ e.printStackTrace(); } + if(backGroundAnimator!=null) + backGroundAnimator.stop(); + } @@ -310,6 +410,8 @@ public class MainActivity extends Activity implements Handler.Callback, View.OnC getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION); if(!isPowerManagerDisable()) wakeLock.acquire(); + if(backGroundAnimator!=null) + backGroundAnimator.start(); } @Override @@ -318,6 +420,8 @@ public class MainActivity extends Activity implements Handler.Callback, View.OnC //Log.d(TAG,"onPause.."); if(!isPowerManagerDisable()) wakeLock.release(); + if(backGroundAnimator!=null) + backGroundAnimator.stop(); } protected void setFont(int index){ @@ -327,6 +431,31 @@ public class MainActivity extends Activity implements Handler.Callback, View.OnC FontUtils.getInstance().replaceFontFromAsset(tv_date,"fonts/"+FONT_NAME_ARRAY[index]+".ttf"); } + protected void setForegroundColor(Integer color){ + if(foregroundColor!=null&&foregroundColor==color) + return; + foregroundColor=color; + tv_time.setTextColor(color); + tv_date.setTextColor(color); + tv_day.setTextColor(color); + tv_weather .setTextColor(color); + tv_descript.setTextColor(color); + tv_handup_image.setTextColor(color); + + tv_handup.setColorFilter(color); + tv_screen_lock.setColorFilter(color); + tv_setting.setColorFilter(color); + tv_background_color.setColorFilter(color); + } + + protected void setBackGroundColor(Integer color){ + if(backgroundColor!=null&&backgroundColor==color) + return; + backgroundColor=color; + //tv_background_color.setColorFilter(color); + mainBackground.setBackgroundColor(color); + } + CalendarPopup calendarPopup; WeatherPopup weatherPopup; @TargetApi(Build.VERSION_CODES.HONEYCOMB) @@ -372,6 +501,30 @@ public class MainActivity extends Activity implements Handler.Callback, View.OnC case R.id.tv_descript: setDiscript(SettingActivity.roundAutoQuotes()); break; + case R.id.tv_background_color: + if (colorPickerDialog == null) + colorPickerDialog = new ColorPickerPop(MainActivity.this); + + colorPickerDialog.setOnColorChangeListenter(new ColorPickerPop.OnColorListener() { + @Override + public void onEnsure(int color) { + model.setBackgroundColor(color); + model.save(); + setBackGroundColor(color); + //tv_background_color.setColorFilter(color); + } + @Override + public void onBack() { + } + }); + colorPickerDialog.show(model.getBackgroundColor()); + break; + case R.id.tv_foreground_color: + setForegroundColor(model.getForegroundColor()); + break; + case R.id.tv_foreground_color1: + setForegroundColor(model.getForegroundColor1()); + break; } } @@ -383,20 +536,220 @@ public class MainActivity extends Activity implements Handler.Callback, View.OnC tv_time.setVisibility(View.VISIBLE); tv_handup_image.setVisibility(View.GONE); tv_setting.setVisibility(View.GONE); + tv_background_color.setVisibility(View.GONE); + tv_foreground_color.setVisibility(View.GONE); + tv_foreground_color1.setVisibility(View.GONE); break; case MODE_SETTING_OTHER: tv_time.setVisibility(View.VISIBLE); tv_handup_image.setVisibility(View.GONE); tv_setting.setVisibility(View.VISIBLE); + tv_background_color.setVisibility(View.VISIBLE); + tv_foreground_color.setVisibility(View.VISIBLE); + tv_foreground_color1.setVisibility(View.VISIBLE); break; case MODE_HANDUP: - tv_handup_image.setVisibility(View.VISIBLE); tv_time.setVisibility(View.GONE); + tv_handup_image.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); setDiscriptForModel(); } mMode = mode; } + StarFallAnimator starAnimator; + SkyAnimator skyAnimator; + RainAnimator rainAnimator; + SnowAnimator snowAnimator; + BubbleWhirlPoolAnimator bubbleWhirlPoolAnimator; + BubbleAnimator bubbleAnimator; + FluorescenceAnimator fluorescenceAnimator; + BubbleCollisionAnimator bubbleCollisionAnimator; + FireworkAnimator fireworkAnimator; + DotsLineAnimator dotsLineAnimator; + public void changeBackGroundAnimator(int index){ + switch(index){ + case 0: + if(starAnimator==null) { + starAnimator = new StarFallAnimator(); + starAnimator.init(animatorView.getContext(),animatorView); + starAnimator.setColor(foregroundColor); + } + backGroundAnimator=starAnimator; + backGroundAnimator.setRandColor(false); + break; + case 2: + if(skyAnimator==null) { + skyAnimator = new SkyAnimator(); + skyAnimator.init(animatorView.getContext(),animatorView); + skyAnimator.setColor(foregroundColor); + } + backGroundAnimator=skyAnimator; + backGroundAnimator.setRandColor(false); + break; + case 3: + if(rainAnimator==null) { + rainAnimator = new RainAnimator(); + rainAnimator.init(animatorView.getContext(),animatorView); + rainAnimator.setColor(foregroundColor); + } + backGroundAnimator=rainAnimator; + backGroundAnimator.setRandColor(false); + break; + case 4: + if(snowAnimator==null) { + snowAnimator = new SnowAnimator(); + snowAnimator.init(animatorView.getContext(),animatorView); + snowAnimator.setColor(foregroundColor); + } + backGroundAnimator=snowAnimator; + backGroundAnimator.setRandColor(false); + break; + case 5: + if(starAnimator==null) { + starAnimator = new StarFallAnimator(); + starAnimator.init(animatorView.getContext(),animatorView); + starAnimator.setColor(foregroundColor); + } + backGroundAnimator=starAnimator; + backGroundAnimator.setRandColor(true); + break; + case 6: + if(skyAnimator==null) { + skyAnimator = new SkyAnimator(); + skyAnimator.init(animatorView.getContext(),animatorView); + skyAnimator.setColor(foregroundColor); + } + backGroundAnimator=skyAnimator; + backGroundAnimator.setRandColor(true); + break; + case 7: + if(rainAnimator==null) { + rainAnimator = new RainAnimator(); + rainAnimator.init(animatorView.getContext(),animatorView); + rainAnimator.setColor(foregroundColor); + } + backGroundAnimator=rainAnimator; + backGroundAnimator.setRandColor(true); + break; + case 8: + if(snowAnimator==null) { + snowAnimator = new SnowAnimator(); + snowAnimator.init(animatorView.getContext(),animatorView); + snowAnimator.setColor(foregroundColor); + } + backGroundAnimator=snowAnimator; + backGroundAnimator.setRandColor(true); + break; + case 9: + if(bubbleWhirlPoolAnimator ==null) { + bubbleWhirlPoolAnimator = new BubbleWhirlPoolAnimator(); + bubbleWhirlPoolAnimator.init(animatorView.getContext(),animatorView); + bubbleWhirlPoolAnimator.setColor(foregroundColor); + } + backGroundAnimator= bubbleWhirlPoolAnimator; + backGroundAnimator.setRandColor(false); + break; + case 10: + if(bubbleAnimator ==null) { + bubbleAnimator = new BubbleAnimator(); + bubbleAnimator.init(animatorView.getContext(),animatorView); + bubbleAnimator.setColor(foregroundColor); + } + backGroundAnimator= bubbleAnimator; + backGroundAnimator.setRandColor(false); + break; + case 11: + if(bubbleAnimator ==null) { + bubbleAnimator = new BubbleAnimator(); + bubbleAnimator.init(animatorView.getContext(),animatorView); + bubbleAnimator.setColor(foregroundColor); + } + backGroundAnimator= bubbleAnimator; + backGroundAnimator.setRandColor(true); + break; + case 12: + if(bubbleWhirlPoolAnimator ==null) { + bubbleWhirlPoolAnimator = new BubbleWhirlPoolAnimator(); + bubbleWhirlPoolAnimator.init(animatorView.getContext(),animatorView); + bubbleWhirlPoolAnimator.setColor(foregroundColor); + } + backGroundAnimator= bubbleWhirlPoolAnimator; + backGroundAnimator.setRandColor(true); + break; + case 13: + if(fluorescenceAnimator ==null) { + fluorescenceAnimator = new FluorescenceAnimator(); + fluorescenceAnimator.init(animatorView.getContext(),animatorView); + fluorescenceAnimator.setColor(foregroundColor); + } + backGroundAnimator= fluorescenceAnimator; + //backGroundAnimator.setRandColor(true); + break; + case 14: + if(bubbleCollisionAnimator ==null) { + bubbleCollisionAnimator = new BubbleCollisionAnimator(); + bubbleCollisionAnimator.init(animatorView.getContext(),animatorView); + bubbleCollisionAnimator.setColor(foregroundColor); + } + backGroundAnimator= bubbleCollisionAnimator; + backGroundAnimator.setRandColor(false); + break; + case 15: + if(bubbleCollisionAnimator ==null) { + bubbleCollisionAnimator = new BubbleCollisionAnimator(); + bubbleCollisionAnimator.init(animatorView.getContext(),animatorView); + bubbleCollisionAnimator.setColor(foregroundColor); + } + backGroundAnimator= bubbleCollisionAnimator; + backGroundAnimator.setRandColor(true); + break; + case 16: + if(fireworkAnimator ==null) { + fireworkAnimator = new FireworkAnimator(); + fireworkAnimator.init(animatorView.getContext(),animatorView); + fireworkAnimator.setColor(foregroundColor); + } + backGroundAnimator= fireworkAnimator; + backGroundAnimator.setRandColor(true); + break; + case 17: + if(fireworkAnimator ==null) { + fireworkAnimator = new FireworkAnimator(); + fireworkAnimator.init(animatorView.getContext(),animatorView); + fireworkAnimator.setColor(foregroundColor); + } + backGroundAnimator= fireworkAnimator; + backGroundAnimator.setRandColor(false); + break; + case 18: + if(dotsLineAnimator ==null) { + dotsLineAnimator = new DotsLineAnimator(); + dotsLineAnimator.init(animatorView.getContext(),animatorView); + dotsLineAnimator.setColor(foregroundColor); + } + backGroundAnimator= dotsLineAnimator; + backGroundAnimator.setRandColor(false); + break; + case 1: + if(dotsLineAnimator ==null) { + dotsLineAnimator = new DotsLineAnimator(); + dotsLineAnimator.init(animatorView.getContext(),animatorView); + dotsLineAnimator.setColor(foregroundColor); + } + backGroundAnimator= dotsLineAnimator; + backGroundAnimator.setRandColor(true); + break; + default: + currectAnimatorIndex=0; + backGroundAnimator=null; + } + animatorView.setAnimator(backGroundAnimator); + } + private void upHandStatic(){ if(handUpAbla) { this.tv_handup.setColorFilter(0x000); @@ -601,7 +954,6 @@ public class MainActivity extends Activity implements Handler.Callback, View.OnC private void saveData(){ model.setFontIndex(fontIndex); model.setHandUpAble(handUpAbla); - Log.d(TAG,"saveData :"+model); model.save(); } @@ -633,7 +985,10 @@ public class MainActivity extends Activity implements Handler.Callback, View.OnC return; if(!isPowerManagerDisable()) localWakeLock.isHeld(); - switchMode(MODE_SETTING_OTHER); + if(mMode==MODE_SETTING_OTHER) + switchMode(MODE_NORMAL); + else + switchMode(MODE_SETTING_OTHER); } @@ -674,7 +1029,7 @@ public class MainActivity extends Activity implements Handler.Callback, View.OnC this.setFont(fontIndex); return true; } else if (e2.getX() - e1.getX() < -120) { // 从右向左滑动(右进左出) - setup(); + changeBackGroundAnimator(currectAnimatorIndex++); return true; } return false; @@ -714,4 +1069,7 @@ public class MainActivity extends Activity implements Handler.Callback, View.OnC String result = numberFormat.format((float) num1 / (float) num2 * 100); return result+"%"; } + + + } diff --git a/app/src/main/java/clock/socoolby/com/clock/cache/I_TrashCache.java b/app/src/main/java/clock/socoolby/com/clock/cache/I_TrashCache.java new file mode 100644 index 0000000..7d77b19 --- /dev/null +++ b/app/src/main/java/clock/socoolby/com/clock/cache/I_TrashCache.java @@ -0,0 +1,16 @@ +package clock.socoolby.com.clock.cache; + +import java.util.List; + +public interface I_TrashCache{ + + void moveToTrashCache(List objs); + + void moveToTrashCache(Q obj); + + Q revectForTrashCache(); + + int getTrashCacheSize(); + + void clear(); +} diff --git a/app/src/main/java/clock/socoolby/com/clock/cache/MemoryTrashCache.java b/app/src/main/java/clock/socoolby/com/clock/cache/MemoryTrashCache.java new file mode 100644 index 0000000..600c8b9 --- /dev/null +++ b/app/src/main/java/clock/socoolby/com/clock/cache/MemoryTrashCache.java @@ -0,0 +1,41 @@ +package clock.socoolby.com.clock.cache; + + +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; + +public class MemoryTrashCache implements I_TrashCache { + + protected Queue trashCache; + + public MemoryTrashCache() { + trashCache = new LinkedList<>(); + } + + public void moveToTrashCache(List objs){ + for(Q obj:objs) + trashCache.offer(obj); + } + + public void moveToTrashCache(Q obj){ + trashCache.offer(obj); + } + + public Q revectForTrashCache(){ + //Log.d("CacheDifferenceAnimator","revectForTrashCache,current size:"+trashCache.size()); + if(trashCache.size()>0) + return trashCache.poll(); + return null; + } + + public int getTrashCacheSize(){ + return trashCache.size(); + } + + @Override + public void clear() { + trashCache.clear(); + } + +} diff --git a/app/src/main/java/clock/socoolby/com/clock/model/SharePerferenceModel.java b/app/src/main/java/clock/socoolby/com/clock/model/SharePerferenceModel.java index dc764e8..4c0d4ef 100755 --- a/app/src/main/java/clock/socoolby/com/clock/model/SharePerferenceModel.java +++ b/app/src/main/java/clock/socoolby/com/clock/model/SharePerferenceModel.java @@ -1,5 +1,8 @@ package clock.socoolby.com.clock.model; +import android.graphics.Color; +import android.util.Log; + import org.json.JSONException; import org.json.JSONObject; @@ -52,6 +55,15 @@ public class SharePerferenceModel implements Serializable { private final static String KEY_IS_HANDUP_ABLE="key_is_handup_able"; private boolean handUpAble = false; + private final static String KEY_BACKGROUND_COLOR="key_background_color"; + private Integer backgroundColor=Color.rgb(0, 0, 0); + + private final static String KEY_FOREGROUND_COLOR="key_foreground_color"; + private Integer foregroundColor=Color.rgb(255, 255, 255); + + private final static String KEY_FOREGROUND_COLOR1="key_foreground_color1"; + private Integer foregroundColor1=Color.rgb(199,21,133); + public int getTypeHourPower() { return typeHourPower; } @@ -176,12 +188,14 @@ public class SharePerferenceModel implements Serializable { weatherLocation = new JSONObject(jsonObject.getString(KEY_DISPLAYVIEW_WEATHER)); descriptionLocation = new JSONObject(jsonObject.getString(KEY_DISPLAYVIEW_DESCRIPTION)); fontIndex = jsonObject.optInt(KEY_FONT_INDEX,0); - this.handUpAble=jsonObject.optBoolean(KEY_IS_HANDUP_ABLE,false); - this.handUpTime=jsonObject.optInt(KEY_HANDUP_TIME,-1); + handUpAble=jsonObject.optBoolean(KEY_IS_HANDUP_ABLE,false); + handUpTime=jsonObject.optInt(KEY_HANDUP_TIME,-1); + backgroundColor=jsonObject.optInt(KEY_BACKGROUND_COLOR,Color.rgb(0, 0, 0)); + foregroundColor=jsonObject.optInt(KEY_FOREGROUND_COLOR,Color.rgb(255, 255, 255)); + foregroundColor1=jsonObject.optInt(KEY_FOREGROUND_COLOR1,Color.rgb(199,21,133)); } catch (JSONException e) { e.printStackTrace(); } - } private String toJsonString() { @@ -204,6 +218,9 @@ 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_BACKGROUND_COLOR,backgroundColor); + jsonObject.put(KEY_FOREGROUND_COLOR,foregroundColor); + jsonObject.put(KEY_FOREGROUND_COLOR1,foregroundColor1); } catch (JSONException e) { e.printStackTrace(); } @@ -212,11 +229,13 @@ public class SharePerferenceModel implements Serializable { } public void save() { + Log.d("model","saveData :"+toString()); FileUtils.writeObject(Constants.SHARE_PERFERENCE_FILE, toJsonString()); } public void read() { fromJsonString((String) FileUtils.readObject(Constants.SHARE_PERFERENCE_FILE)); + Log.d("model","readData :"+toString()); } @@ -238,6 +257,9 @@ public class SharePerferenceModel implements Serializable { ", fontIndex="+fontIndex+ ", handUpAble="+handUpAble+ ", handUpTime="+handUpTime+ + ", backgroundColor="+backgroundColor+ + ", foregroundColor="+foregroundColor+ + ", foregroundColor1="+foregroundColor1+ '}'; } @@ -264,4 +286,29 @@ public class SharePerferenceModel implements Serializable { public void setHandUpAble(boolean handUpAble) { this.handUpAble = handUpAble; } + + + public Integer getBackgroundColor() { + return backgroundColor; + } + + public void setBackgroundColor(Integer backgroundColor) { + this.backgroundColor = backgroundColor; + } + + public Integer getForegroundColor() { + return foregroundColor; + } + + public void setForegroundColor(Integer foregroundColor) { + this.foregroundColor = foregroundColor; + } + + public Integer getForegroundColor1() { + return foregroundColor1; + } + + public void setForegroundColor1(Integer foregroundColor1) { + this.foregroundColor1 = foregroundColor1; + } } diff --git a/app/src/main/java/clock/socoolby/com/clock/pop/ColorPickerPop.java b/app/src/main/java/clock/socoolby/com/clock/pop/ColorPickerPop.java new file mode 100644 index 0000000..f2da506 --- /dev/null +++ b/app/src/main/java/clock/socoolby/com/clock/pop/ColorPickerPop.java @@ -0,0 +1,121 @@ +package clock.socoolby.com.clock.pop; + +import android.content.Context; +import android.graphics.drawable.ColorDrawable; +import android.view.View; +import android.widget.ImageButton; +import android.widget.TextView; +import com.larswerkman.holocolorpicker.ColorPicker; +import com.larswerkman.holocolorpicker.OpacityBar; +import com.larswerkman.holocolorpicker.SVBar; +import clock.socoolby.com.clock.R; +import razerdp.basepopup.BasePopupWindow; + +/** + * 颜色选择器 + * Created by tianzl on 2017/9/1. + */ + +public class ColorPickerPop extends BasePopupWindow implements View.OnClickListener { + private ImageButton ibBack; + private ImageButton ibEnsure; + private TextView tvTitle; + private ColorPicker colorPicker; + private SVBar svBar; + private OpacityBar opacityBar; + + private int color; + + public ColorPickerPop(Context context) { + super(context); + } + + public View onCreateContentView() { + View content=createPopupById(R.layout.pop_color_picker); + initView(content); + initData(); + initEvent(); + return content; + } + + private void initData() { + colorPicker.addSVBar(svBar); + colorPicker.addOpacityBar(opacityBar); + tvTitle.setText("颜色选择器"); + } + + private void initView(View view) { + ibBack=view.findViewById(R.id.bar_title_left); + ibEnsure=view.findViewById(R.id.bar_title_right); + tvTitle=view.findViewById(R.id.bar_title_title); + colorPicker=view.findViewById(R.id.dialog_color_picker_colorPicker); + svBar=view.findViewById(R.id.dialog_color_picker_svbar); + opacityBar=view.findViewById(R.id.dialog_color_picker_opacity); + + view.findViewById(R.id.default_color_sample).setOnClickListener(this); + view.findViewById(R.id.default_color_sample1).setOnClickListener(this); + view.findViewById(R.id.default_color_sample2).setOnClickListener(this); + view.findViewById(R.id.default_color_sample3).setOnClickListener(this); + view.findViewById(R.id.default_color_sample4).setOnClickListener(this); + view.findViewById(R.id.default_color_sample5).setOnClickListener(this); + view.findViewById(R.id.default_color_sample6).setOnClickListener(this); + view.findViewById(R.id.default_color_sample7).setOnClickListener(this); + view.findViewById(R.id.default_color_sample8).setOnClickListener(this); + view.findViewById(R.id.default_color_sample9).setOnClickListener(this); + view.findViewById(R.id.default_color_sample10).setOnClickListener(this); + view.findViewById(R.id.default_color_sample11).setOnClickListener(this); + view.findViewById(R.id.default_color_sample12).setOnClickListener(this); + view.findViewById(R.id.default_color_sample13).setOnClickListener(this); + view.findViewById(R.id.default_color_sample14).setOnClickListener(this); + + } + + private void initEvent() { + colorPicker.setOnColorChangedListener(new ColorPicker.OnColorChangedListener() { + @Override + public void onColorChanged(int colors) { + tvTitle.setTextColor(colors); + color=colors; + } + }); + ibBack.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + listener.onBack(); + dismiss(); + } + }); + ibEnsure.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + listener.onEnsure(color); + dismiss(); + } + }); + } + + public void show(int initColor) { + colorPicker.setColor(initColor); + color=initColor; + tvTitle.setTextColor(initColor); + this.showPopupWindow(); + } + + @Override + public void onClick(View v) { + ColorDrawable colordDrawable = (ColorDrawable) v.getBackground(); + int colors = colordDrawable.getColor(); + tvTitle.setTextColor(colors); + color=colors; + } + + public interface OnColorListener{ + void onBack(); + void onEnsure(int color); + } + + private OnColorListener listener; + public void setOnColorChangeListenter(OnColorListener listener){ + this.listener=listener; + } +} diff --git a/app/src/main/java/clock/socoolby/com/clock/themeUI/DefaultThemeUI.java b/app/src/main/java/clock/socoolby/com/clock/themeUI/DefaultThemeUI.java new file mode 100644 index 0000000..692cc26 --- /dev/null +++ b/app/src/main/java/clock/socoolby/com/clock/themeUI/DefaultThemeUI.java @@ -0,0 +1,4 @@ +package clock.socoolby.com.clock.themeUI; + +public class DefaultThemeUI { +} diff --git a/app/src/main/java/clock/socoolby/com/clock/themeUI/I_ThemeUI.java b/app/src/main/java/clock/socoolby/com/clock/themeUI/I_ThemeUI.java new file mode 100644 index 0000000..55a7d53 --- /dev/null +++ b/app/src/main/java/clock/socoolby/com/clock/themeUI/I_ThemeUI.java @@ -0,0 +1,4 @@ +package clock.socoolby.com.clock.themeUI; + +public interface I_ThemeUI { +} diff --git a/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/AbstractAnimator.java b/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/AbstractAnimator.java new file mode 100644 index 0000000..c0d01a8 --- /dev/null +++ b/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/AbstractAnimator.java @@ -0,0 +1,220 @@ +package clock.socoolby.com.clock.widget.animatorview; + +import android.animation.ValueAnimator; +import android.content.ContentValues; +import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.Canvas; +import android.graphics.PixelFormat; +import android.graphics.drawable.Drawable; +import android.support.v4.graphics.drawable.DrawableCompat; +import android.util.DisplayMetrics; +import android.util.TypedValue; +import android.view.View; +import android.view.WindowManager; + +import java.util.ArrayList; +import java.util.Random; + +public abstract class AbstractAnimator implements I_Animator{ + protected Random rand=new Random(); + protected boolean isRuning=false; + protected int color=200; + protected View mainView; + protected Context context; + + protected boolean randColor=false; + + //效果场景宽高 + protected int width; + protected int height; + + protected ArrayList list = new ArrayList<>(); + protected ValueAnimator animator; + + @Override + public void init(Context context, final View main) { + mainView=main; + this.context=context; + width=main.getWidth(); + height=main.getHeight(); + } + + @Override + public void start() { + if(animator==null) { + reset(); + //初始化animator + animator = ValueAnimator.ofFloat(0, 1); + animator.setRepeatCount(ValueAnimator.INFINITE); + animator.setDuration(500); + + animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { + @Override + public void onAnimationUpdate(ValueAnimator arg0) { + if(run()) + mainView.invalidate(); + } + }); + } + if(!animator.isRunning()) + animator.start(); + isRuning=true; + } + + public abstract boolean run(); + + public void setRandColor(boolean randColor){ + this.randColor=randColor; + } + + protected void randomColor(){ + if(randColor){ + int alpha = 200; + int r = rand.nextInt(255); + int g = rand.nextInt(255); + int b = rand.nextInt(255); + color = alpha << 24 | r << 16 | g << 8 | b; + } + } + + public void reset(){ + list.clear(); + if(randColor) + randomColor(); + } + + @Override + public void restart() { + pause(); + reset(); + start(); + } + + @Override + public void pause() { + if(animator==null) + return; + //throw new Exception("place start it first.."); + if(animator.isRunning()) + animator.cancel(); + isRuning=false; + } + + @Override + public void stop() { + if(animator==null) + return; + if(animator.isRunning()) + animator.cancel(); + animator.removeAllUpdateListeners(); + animator = null; + isRuning=false; + } + + + @Override + public boolean isRunning() { + return isRuning; + } + + @Override + public void setColor(int color) { + this.color=color; + } + + @Override + public void onSizeChanged(int w, int h, int oldw, int oldh) { + width=w; + height=h; + if(isRuning) + restart(); + } + + @Override + public boolean isColorUseAble() { + return true; + } + + @Override + public boolean isRandColor() { + return randColor; + } + + + public static class Util { + + public static ContentValues videoContentValues = null; + + + public static int roundColor(){ + Random rand=new Random(); + int alpha = 200; + int r = rand.nextInt(255); + int g = rand.nextInt(255); + int b = rand.nextInt(255); + return alpha << 24 | r << 16 | g << 8 | b; + } + /** + * px = dp * (dpi / 160) + * + * @param ctx + * @param dip + * @return + */ + public static int dipToPX(final Context ctx, float dip) { + return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, + dip, ctx.getResources().getDisplayMetrics()); + } + + + public static int getScreenWidth(Context context) { + WindowManager wm = (WindowManager) context + .getSystemService(Context.WINDOW_SERVICE); + DisplayMetrics dm = new DisplayMetrics(); + wm.getDefaultDisplay().getMetrics(dm); + return wm.getDefaultDisplay().getWidth(); + } + + public static int getScreenHeight(Context context) { + WindowManager wm = (WindowManager) context + .getSystemService(Context.WINDOW_SERVICE); + DisplayMetrics dm = new DisplayMetrics(); + wm.getDefaultDisplay().getMetrics(dm); + return dm.heightPixels; + } + + public static Bitmap drawableToBitmap(Drawable drawable) { + + int w = drawable.getIntrinsicWidth(); + int h = drawable.getIntrinsicHeight(); + + + Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 + : Bitmap.Config.RGB_565; + + Bitmap bitmap = Bitmap.createBitmap(w, h, config); + + Canvas canvas = new Canvas(bitmap); + drawable.setBounds(0, 0, w, h); + + drawable.draw(canvas); + return bitmap; + } + + /** + * 重绘Drawable,将drawable颜色着色为color + * @param drawable + * @param color + * @return 重绘后的Drawable + */ + public static Drawable tint(Drawable drawable, int color) + { + final Drawable wrappedDrawable = DrawableCompat.wrap(drawable); + wrappedDrawable.mutate(); + DrawableCompat.setTint(wrappedDrawable, color); + return wrappedDrawable; + } + + } +} diff --git a/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/AbstractCacheAbleAnimator.java b/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/AbstractCacheAbleAnimator.java new file mode 100644 index 0000000..dccde43 --- /dev/null +++ b/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/AbstractCacheAbleAnimator.java @@ -0,0 +1,19 @@ +package clock.socoolby.com.clock.widget.animatorview; + +import clock.socoolby.com.clock.cache.I_TrashCache; + +public abstract class AbstractCacheAbleAnimator extends AbstractCacheDifferenceAnimator { + + public AbstractCacheAbleAnimator() { + } + + public AbstractCacheAbleAnimator(I_TrashCache trashCache) { + super(trashCache); + } + + public void reset() { + if (isCacheAble()) + moveToTrashCache(list); + super.reset(); + } +} diff --git a/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/AbstractCacheDifferenceAnimator.java b/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/AbstractCacheDifferenceAnimator.java new file mode 100644 index 0000000..67a0869 --- /dev/null +++ b/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/AbstractCacheDifferenceAnimator.java @@ -0,0 +1,48 @@ +package clock.socoolby.com.clock.widget.animatorview; + +import java.util.List; +import clock.socoolby.com.clock.cache.I_TrashCache; +import clock.socoolby.com.clock.cache.MemoryTrashCache; + +public abstract class AbstractCacheDifferenceAnimator extends AbstractAnimator{ + + I_TrashCache trashCache; + boolean globalTrashCashe=false; + + public AbstractCacheDifferenceAnimator(){ + super(); + trashCache=new MemoryTrashCache(); + } + + public AbstractCacheDifferenceAnimator(I_TrashCache trashCache){ + super(); + this.trashCache=trashCache; + this.globalTrashCashe=true; + } + + public void stop() { + super.stop(); + if(trashCache!=null&&!globalTrashCashe) + trashCache.clear(); + } + + public boolean isCacheAble(){ + return true; + } + + public void moveToTrashCache(List objs) { + trashCache.moveToTrashCache(objs); + } + + public void moveToTrashCache(Q obj) { + trashCache.moveToTrashCache(obj); + } + + public Q revectForTrashCache() { + return trashCache.revectForTrashCache(); + } + + public int getTrashCacheSize() { + return trashCache.getTrashCacheSize(); + } +} diff --git a/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/AnimatorView.java b/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/AnimatorView.java new file mode 100644 index 0000000..7dde3c1 --- /dev/null +++ b/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/AnimatorView.java @@ -0,0 +1,91 @@ +package clock.socoolby.com.clock.widget.animatorview; + +import android.content.Context; +import android.graphics.Canvas; +import android.util.AttributeSet; +import android.view.View; + +import androidx.annotation.Nullable; + +public class AnimatorView extends View { + + private Context context; + + private I_Animator animator; + private int color=0; + + public AnimatorView(Context context) { + super(context); + this.context = context; + } + + public AnimatorView(Context context, @Nullable AttributeSet attrs) { + super(context, attrs); + } + + public AnimatorView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + + @Override + protected void onSizeChanged(int w, int h, int oldw, int oldh) { + super.onSizeChanged(w, h, oldw, oldh); + // Reset list of droidflakes, then restart it with 8 flakes + if(animator!=null) + animator.onSizeChanged(w,h,oldw,oldh); + } + + @Override + protected void onDraw(Canvas canvas) { + super.onDraw(canvas); + if(animator!=null) + animator.onDraw(canvas); + } + + /** + * 暂停动画 + */ + public void pause() { + if(animator!=null) + animator.pause(); + } + + /** + * 开始动画 + */ + public void start() { + if(animator!=null) + animator.start(); + } + + public void stop(){ + if(animator!=null) + animator.stop(); + } + + public boolean isRunning(){ + if(animator==null){ + return false; + } + return animator.isRunning(); + } + + public void setAnimator(I_Animator newAnimator){ + if(animator!=null) + animator.stop(); + animator=newAnimator; + if(animator!=null) { + animator.setColor(color); + animator.start(); + } + } + + public void setColor(int color){ + this.color=color; + if(animator!=null&&animator.isColorUseAble()&&!animator.isRandColor()) { + animator.setColor(color); + animator.restart(); + } + } +} \ No newline at end of file diff --git a/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/I_Animator.java b/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/I_Animator.java new file mode 100644 index 0000000..00ff52a --- /dev/null +++ b/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/I_Animator.java @@ -0,0 +1,32 @@ +package clock.socoolby.com.clock.widget.animatorview; + +import android.content.Context; +import android.graphics.Canvas; +import android.view.View; + +public interface I_Animator { + + void init(Context context, View main); + + void onDraw(Canvas canvas); + + void start(); + + void pause(); + + void stop(); + + boolean isRunning(); + + void onSizeChanged(int w, int h, int oldw, int oldh); + + void setColor(int color); + + void setRandColor(boolean randColor); + + void restart(); + + boolean isColorUseAble(); + + boolean isRandColor(); +} diff --git a/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/animator/AbstractParticlesAnimator.java b/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/animator/AbstractParticlesAnimator.java new file mode 100644 index 0000000..7fddf0d --- /dev/null +++ b/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/animator/AbstractParticlesAnimator.java @@ -0,0 +1,15 @@ +package clock.socoolby.com.clock.widget.animatorview.animator; + +import clock.socoolby.com.clock.cache.I_TrashCache; +import clock.socoolby.com.clock.widget.animatorview.AbstractCacheAbleAnimator; + +public abstract class AbstractParticlesAnimator extends AbstractCacheAbleAnimator { + + public AbstractParticlesAnimator() { + super(); + } + + public AbstractParticlesAnimator(I_TrashCache trashCache) { + super(trashCache); + } +} diff --git a/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/animator/BubbleAnimator.java b/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/animator/BubbleAnimator.java new file mode 100644 index 0000000..674f960 --- /dev/null +++ b/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/animator/BubbleAnimator.java @@ -0,0 +1,131 @@ +package clock.socoolby.com.clock.widget.animatorview.animator; + +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; +import android.graphics.RectF; + +import java.util.ArrayList; +import java.util.List; + +import clock.socoolby.com.clock.widget.animatorview.AbstractAnimator; + +//引用自:http://www.gcssloop.com/gebug/bubble-sample + +public class BubbleAnimator extends AbstractAnimator { + + private int mBubbleMaxRadius = 30; // 气泡最大半径 px + private int mBubbleMinRadius = 5; // 气泡最小半径 px + private int mBubbleMaxSize = 30; // 气泡数量 + private int mBubbleRefreshTime = 20; // 刷新间隔 + private int mBubbleMaxSpeedY = 5; // 气泡速度 + private int mBubbleAlpha = 128; // 气泡画笔 + + private RectF mContentRectF; // 实际可用内容区域 + + private Paint mBubblePaint; // 气泡画笔 + + @Override + public boolean run() { + tryCreateBubble(); + refreshBubbles(); + return true; + } + + @Override + public void onDraw(Canvas canvas) { + for (Bubble bubble : list) { + if (null == bubble) continue; + mBubblePaint.setColor(bubble.color); + canvas.drawCircle(bubble.x, bubble.y, + bubble.radius, mBubblePaint); + } + } + + @Override + public void reset() { + super.reset(); + mBubblePaint = new Paint(); + mBubblePaint.setColor(Color.WHITE); + mBubblePaint.setAlpha(mBubbleAlpha); + mContentRectF=new RectF(0,0,width,height); + } +//--- 气泡效果 --------------------------------------------------------------------------------- + + public class Bubble { + int radius; // 气泡半径 + float speedY; // 上升速度 + float speedX; // 平移速度 + float x; // 气泡x坐标 + float y; // 气泡y坐标 + int color; // 气泡颜色 + } + + // 尝试创建气泡 + private void tryCreateBubble() { + if (null == mContentRectF) return; + if (list.size() >= mBubbleMaxSize) { + return; + } + if (rand.nextFloat() < 0.95) { + return; + } + Bubble bubble = new Bubble(); + int radius = rand.nextInt(mBubbleMaxRadius - mBubbleMinRadius); + radius += mBubbleMinRadius; + float speedY = rand.nextFloat() * mBubbleMaxSpeedY; + while (speedY < 1) { + speedY = rand.nextFloat() * mBubbleMaxSpeedY; + } + bubble.radius = radius; + bubble.speedY = speedY; + switch (rand.nextInt(10)) { + case 1: + bubble.x = mContentRectF.centerX()/2; + break; + case 2: + bubble.x =mContentRectF.centerX()+mContentRectF.centerX()/2; + break; + case 3: + bubble.x =rand.nextInt(Float.valueOf(mContentRectF.width()).intValue()); + break; + default: + bubble.x = mContentRectF.centerX(); + } + bubble.y = mContentRectF.bottom - radius; + float speedX = rand.nextFloat() - 0.5f; + while (speedX == 0) { + speedX = rand.nextFloat() - 0.5f; + } + bubble.speedX = speedX * 2; + if(randColor) + randomColor(); + bubble.color=color; + list.add(bubble); + } + + // 刷新气泡位置,对于超出区域的气泡进行移除 + private void refreshBubbles() { + List list = new ArrayList<>(this.list); + for (Bubble bubble : list) { + if (bubble.y - bubble.speedY <= mContentRectF.top + bubble.radius) { + this.list.remove(bubble); + } else { + int i = this.list.indexOf(bubble); + if (bubble.x + bubble.speedX <= mContentRectF.left + bubble.radius) { + bubble.x = mContentRectF.left + bubble.radius ; + } else if (bubble.x + bubble.speedX >= mContentRectF.right - bubble.radius ) { + bubble.x = mContentRectF.right - bubble.radius; + } else { + bubble.x = bubble.x + bubble.speedX; + } + bubble.y = bubble.y - bubble.speedY; + this.list.set(i, bubble); + } + } + } + + private float dp2px(float dpValue) { + return Util.dipToPX(context,dpValue); + } +} diff --git a/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/animator/BubbleCollisionAnimator.java b/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/animator/BubbleCollisionAnimator.java new file mode 100644 index 0000000..17d0552 --- /dev/null +++ b/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/animator/BubbleCollisionAnimator.java @@ -0,0 +1,127 @@ +package clock.socoolby.com.clock.widget.animatorview.animator; + + +import android.graphics.Canvas; +import android.graphics.Paint; + +import clock.socoolby.com.clock.widget.animatorview.AbstractAnimator; + +//引用自:https://blog.csdn.net/u010386612/article/details/50580080 +public class BubbleCollisionAnimator extends AbstractAnimator { + + + private int maxRadius; // 小球最大半径 + private int minRadius; // 小球最小半径 + private int minSpeed = 5; // 小球最小移动速度 + private int maxSpeed = 20; // 小球最大移动速度 + + + @Override + public void reset() { + super.reset(); + addBall(20); + } + + public void addBall(int quantity) { + maxRadius = width/12; + minRadius = maxRadius/2; + for (int i = 0; i < quantity;i++) { + Ball mBall=new Ball(); + // 设置画笔 + Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); + if(randColor) + randomColor(); + paint.setColor(color); + paint.setStyle(Paint.Style.FILL); + paint.setAlpha(180); + paint.setStrokeWidth(0); + + // 设置速度 + float speedX = (rand.nextInt(maxSpeed -minSpeed +1)+5)/10f; + float speedY = (rand.nextInt(maxSpeed -minSpeed +1)+5)/10f; + mBall.paint = paint; + mBall.vx = rand.nextBoolean() ? speedX : -speedX; + mBall.vy = rand.nextBoolean() ? speedY : -speedY; + mBall.radius = rand.nextInt(maxRadius+1 - minRadius) +minRadius; + mBall.cx=mBall.cy=0; + if(rand.nextBoolean()) + mBall.cx=rand.nextInt(width); + else + mBall.cy=rand.nextInt(height); + list.add(mBall); + } + } + + @Override + public boolean run() { + // 球碰撞边界 + for (Ball ball:list) { + collisionDetectingAndChangeSpeed(ball); // 碰撞边界的计算 + ball.move(); // 移动 + } + return true; + } + + @Override + public void onDraw(Canvas canvas) { + for (Ball ball:list) { + canvas.drawCircle(ball.cx, ball.cy, ball.radius, ball.paint); + } + } + + + // 判断球是否碰撞碰撞边界 + public void collisionDetectingAndChangeSpeed(Ball ball) { + int left = 0; + int top = 0; + int right = width; + int bottom = height; + + float speedX = ball.vx; + float speedY = ball.vy; + + // 碰撞左右,X的速度取反。 speed的判断是防止重复检测碰撞,然后黏在墙上了=。= + if(ball.left() <= left && speedX < 0) { + ball.vx = -ball.vx; + } else if(ball.top() <= top && speedY < 0) { + ball.vy = -ball.vy; + } else if(ball.right() >= right && speedX >0) { + ball.vx = -ball.vx; + } else if(ball.bottom() >= bottom && speedY >0) { + ball.vy = -ball.vy; + } + } + + + class Ball { + int radius; // 半径 + float cx; // 圆心 + float cy; // 圆心 + float vx; // X轴速度 + float vy; // Y轴速度 + Paint paint; + + // 移动 + void move() { + //向角度的方向移动,偏移圆心 + cx += vx; + cy += vy; + } + + int left() { + return (int) (cx - radius); + } + + int right() { + return (int) (cx +radius); + } + + int bottom() { + return (int) (cy + radius); + } + + int top() { + return (int) (cy - radius); + } + } +} diff --git a/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/animator/BubbleWhirlPoolAnimator.java b/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/animator/BubbleWhirlPoolAnimator.java new file mode 100644 index 0000000..592126f --- /dev/null +++ b/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/animator/BubbleWhirlPoolAnimator.java @@ -0,0 +1,256 @@ +package clock.socoolby.com.clock.widget.animatorview.animator; + +import android.graphics.Canvas; +import android.graphics.Paint; +import clock.socoolby.com.clock.widget.animatorview.AbstractAnimator; + + + +//引用自:https://blog.csdn.net/longyc2010/article/details/44137225 + +public class BubbleWhirlPoolAnimator extends AbstractAnimator { + private static final String TAG = "BubbleWhirlPoolAnimator"; + private static final int NORTH = 0; + private static final int SOUTH = 1; + private static final int EAST = 2; + private static final int WEST = 3; + private static final int NORTH_WEST = 4; + private static final int NORTH_EAST = 5; + private static final int SOUTH_WEST = 6; + private static final int SOUTH_EAST = 7; + + private Paint paint = new Paint(); + private boolean isChangeRunning = false; + private int frequency = 0; + + @Override + public boolean run() { + if (frequency % 5 == 0) { + for (Circle c : list) { + isChangeRunning=rand.nextInt(5)!=1; + if (isChangeRunning) { + c.runBubble(); + } else { + c.increase(); + } + } + } + frequency++; + return true; + } + + + @Override + public void reset() { + super.reset(); + paint.reset(); + addBubble(10); + } + + + public void addBubble(int quantity) { + for (int i = 0; i < quantity;i++) { + if(randColor) + randomColor(); + list.add(new Circle(rand.nextInt(width), rand.nextInt(height), rand.nextInt(30) + 20, rand.nextInt(60) + 40,color)); + } + } + + @Override + public void onDraw(Canvas canvas) { + for (Circle c : list) { + c.draw(canvas, paint); + } + } + + + private class CircleCenterPoint { + private float x; + private float y; + + public CircleCenterPoint(float x, float y) { + this.x = x; + this.y = y; + } + + public float getX() { + return x; + } + + public void setX(float x) { + this.x = x; + } + + public float getY() { + return y; + } + + public void setY(float y) { + this.y = y; + } + + public boolean isOutOfView(float r) { + boolean isOutView = false; + if (x > width - r || x < r || y > height - r || y <= r) { + isOutView = true; + } + + return isOutView; + } + + public boolean isInCenterView(float r, float centerViewR) { + boolean isOutView = false; + if (x > width / 2 - centerViewR && x < width / 2 + centerViewR + && y > height / 2 - centerViewR && y <= height / 2 + centerViewR) { + isOutView = true; + } + return isOutView; + } + } + + public class Circle { + private CircleCenterPoint center; + private float r; + private int a; + private int aMax; + private double distance; + private double minDistance; + private int type = rand.nextInt(100); + private int count = 0; + + private double delta = 0.1f; + private double theta = 0; + + private boolean isInitDistance = false; + private double delta2 = 0.1f; + boolean isShouldDisapear = false; + int circleColor=0; + + public Circle(float x, float y, float r, int a,int color) { + center = new CircleCenterPoint(x, y); + this.r = r; + this.a = a; + minDistance = rand.nextInt(100); + this.circleColor=color; + } + + public void runBubble() { + if (!isInitDistance) { + isInitDistance = true; + float x = center.getX() - width / 2; + float y = center.getY() - height / 2; + + distance = Math.sqrt((double) (x * x + y * y)); + + if (x > 0) { + + theta = Math.atan(y / x); + } else { + + theta = Math.atan(y / x) + Math.PI; + } + + } + theta = theta + 0.1; + distance = getDistance(distance); + center.setY((float) (distance * Math.sin(theta)) + height / 2); + center.setX((float) (distance * Math.cos(theta)) + width / 2); + } + + public void increase() { + if (isInitDistance) { + delta = 0.1f; + isInitDistance = false; + } + changeCenterPoint(center, type); + + if (center.isOutOfView(r) || center.isInCenterView(r, 100f)) { + isShouldDisapear = true; + + } + } + + public void draw(Canvas canvas, Paint paint) { + count++; + if (count % ((type + 8) * 10) == 0) { + type = rand.nextInt(100); + } + if (isShouldDisapear) { + a--; + if (a <= 0) { + isShouldDisapear = false; + center.setX(rand.nextInt(width)); + center.setY(rand.nextInt(height)); + r = rand.nextInt(30) + 20; + aMax = rand.nextInt(60) + 40; + } + + } else { + + if (a <= aMax) { + a++; + } else { + aMax = 0; + } + } + paint.reset(); + paint.setColor(circleColor); + paint.setAlpha(a); + canvas.drawCircle(center.getX(), center.getY(), r, paint); + } + + private double getDistance(double distance) { + + double result = distance; + delta = delta + 0.1; + + result = result - delta * delta; + if (result < minDistance) { + result = minDistance; + } + return result; + } + + } + + private void changeCenterPoint(CircleCenterPoint center, int type) { + + switch (type % 8) { + case NORTH: + center.setX(center.getX()); + center.setY(center.getY() - rand.nextInt(4)); + break; + case SOUTH: + center.setX(center.getX()); + center.setY(center.getY() + rand.nextInt(4)); + break; + case EAST: + center.setX(center.getX() + rand.nextInt(4)); + center.setY(center.getY()); + break; + case WEST: + center.setX(center.getX() - rand.nextInt(4)); + center.setY(center.getY()); + + break; + case NORTH_WEST: + center.setX(center.getX() - rand.nextInt(4)); + center.setY(center.getY() - rand.nextInt(4)); + break; + case NORTH_EAST: + center.setX(center.getX() + rand.nextInt(4)); + center.setY(center.getY() - rand.nextInt(4)); + break; + case SOUTH_WEST: + center.setX(center.getX() + rand.nextInt(4)); + center.setY(center.getY() + rand.nextInt(4)); + break; + case SOUTH_EAST: + center.setX(center.getX() - rand.nextInt(4)); + center.setY(center.getY() + rand.nextInt(4)); + break; + } + } +} + + diff --git a/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/animator/DotsLineAnimator.java b/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/animator/DotsLineAnimator.java new file mode 100644 index 0000000..20b3f60 --- /dev/null +++ b/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/animator/DotsLineAnimator.java @@ -0,0 +1,102 @@ +package clock.socoolby.com.clock.widget.animatorview.animator; + +import android.graphics.Canvas; +import android.graphics.Paint; + +import clock.socoolby.com.clock.widget.animatorview.AbstractAnimator; + +//引用: https://blog.csdn.net/findhappy117/article/details/79491531 + +public class DotsLineAnimator extends AbstractAnimator { + + public static final int SLEEP_TIME=7; + + + @Override + public void reset() { + super.reset(); + paint.reset(); + addDots(60); + } + + int sleepTime=SLEEP_TIME; + @Override + public boolean run() { + if(sleepTime-->0) + return false; + for(Circle circle:list){ + circle.move(width, height); + } + sleepTime=SLEEP_TIME; + return true; + } + + Circle circle; + Paint paint=new Paint(); + + @Override + public void onDraw(Canvas canvas) { + for(int i=0;i 0) ? this._mx : (-this._mx); + this._my = (this.y < h && this.y > 0) ? this._my : (-this._my); + this.x += this._mx / 2; + this.y += this._my / 2; + } + } +} diff --git a/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/animator/DrawableArrayFallAnimator.java b/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/animator/DrawableArrayFallAnimator.java new file mode 100644 index 0000000..54fe12e --- /dev/null +++ b/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/animator/DrawableArrayFallAnimator.java @@ -0,0 +1,210 @@ +package clock.socoolby.com.clock.widget.animatorview.animator; + +import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.Canvas; +import android.graphics.Matrix; +import android.graphics.drawable.Drawable; + +import java.util.HashMap; + +import clock.socoolby.com.clock.widget.animatorview.AbstractAnimator; + +public class DrawableArrayFallAnimator extends AbstractAnimator { + + /** + * 小星星数目的最大值 + */ + public static final int MAX_NUM = 100; + + //小星星图片的资源文件 + int[] picRes ; + + int quantity; + + public DrawableArrayFallAnimator(int[] picRes,int quantity){ + this.picRes=picRes; + this.quantity=quantity; + } + + /** + * 小星星的数目 + */ + private int starNums = 0; + + long startTime, prevTime; + Matrix matrix = new Matrix(); + + @Override + public void onDraw(Canvas canvas) { + //Log.d("123","--------onDraw--------"); + for (int i = 0; i < starNums; ++i) { + Star flake = list.get(i); + matrix.setTranslate(-flake.width/2, -flake.height/2); + matrix.postRotate(flake.rotation); + matrix.postTranslate(flake.width/2 + flake.x, flake.height/2 + flake.y); + canvas.drawBitmap(flake.bitmap, matrix, null); + } + } + + public void onSizeChanged(int w, int h, int oldw, int oldh) { + super.onSizeChanged(w,h,oldw,oldh); + // Reset list of droidflakes, then restart it with 8 flakes + list.clear(); + starNums = 0; + addStars(quantity); + animator.cancel(); + startTime = System.currentTimeMillis(); + prevTime = startTime; + animator.start(); + } + + @Override + public void start() { + startTime = System.currentTimeMillis(); + prevTime = startTime; + if(animator==null) { + reset(); + super.start(); + } + } + + @Override + public void reset() { + super.reset(); + Star.clearCache(); + starNums=0; + addStars(quantity); + } + + @Override + public boolean run() { + //Log.d("123", "--------onAnimationUpdate--------"); + long nowTime = System.currentTimeMillis(); + float secs = (nowTime - prevTime) / 1000f; + prevTime = nowTime; + for (int i = 0; i < starNums; i++) { + Star star = list.get(i); + star.y += (star.speed * secs); + if (star.y > mainView.getHeight()) { + star.y = 0 - star.height; + } + star.rotation = star.rotation + (star.rotationSpeed * secs); + } + return true; + } + + + @Override + public void stop() { + super.stop(); + Star.clearCache(); + } + + /** + * 添加小星星 + * @param quantity + */ + public void addStars(int quantity) { + if(starNums <= MAX_NUM){ + for (int i = 0; i < quantity;i++) { + if(randColor) + randomColor(); + list.add(Star.createStar(mainView.getWidth(),picRes[i%picRes.length],context,color)); + } + starNums += quantity; + } + } + + public static class Star { + + /** + * x坐标、y坐标位置 + */ + float x, y; + /** + * 小星星旋转的角度 + */ + float rotation; + /** + * 小星星下落的速度 + */ + float speed; + /** + * 小星星旋转的速度 + */ + float rotationSpeed; + /** + * 小星星的宽和高 + */ + int width, height; + + /** + * 对应的bitmap + */ + Bitmap bitmap; + + static HashMap bitmapCacheMap = new HashMap(); + + /** + * @param context + * @param xRange 小星星在X方向上的范围 + * @param resId 资源文件Id + * @return + */ + static Star createStar(float xRange,int resId, Context context) { + Star star = new Star(); + //如果十大图片则需要单独处理 + Bitmap originalBitmap = BitmapFactory.decodeResource(context.getResources(), resId); + star.width = originalBitmap.getWidth(); + star.height = originalBitmap.getHeight(); + //初始坐标位置 + star.x = (float)Math.random() * (xRange - star.width); + star.y = 0 - (star.height + (float)Math.random() * Util.getScreenHeight(context)); + //定义下落的速度 + star.speed = Util.dipToPX(context,50) + (float) Math.random() * Util.dipToPX(context,50); + //旋转角度及旋转速度(根据需要修改) + star.rotation = (float) Math.random() * 180 - 90; + star.rotationSpeed = (float) Math.random() * 90 - 45; + //获得bitmap对象 + star.bitmap = bitmapCacheMap.get(resId); + if (star.bitmap == null) { + star.bitmap = Bitmap.createScaledBitmap(originalBitmap, + star.width, star.height, true); + bitmapCacheMap.put(resId, star.bitmap); + } + return star; + } + + static Star createStar(float xRange,int resId, Context context,int color) { + Star star = new Star(); + //如果十大图片则需要单独处理 + Drawable imageDraw=context.getResources().getDrawable(resId); + imageDraw=Util.tint(imageDraw,color); + Bitmap originalBitmap = Util.drawableToBitmap(imageDraw); + star.width = originalBitmap.getWidth(); + star.height = originalBitmap.getHeight(); + //初始坐标位置 + star.x = (float)Math.random() * (xRange - star.width); + star.y = 0 - (star.height + (float)Math.random() * Util.getScreenHeight(context)); + //定义下落的速度 + star.speed = Util.dipToPX(context,50) + (float) Math.random() * Util.dipToPX(context,50); + //旋转角度及旋转速度(根据需要修改) + star.rotation = (float) Math.random() * 180 - 90; + star.rotationSpeed = (float) Math.random() * 90 - 45; + //获得bitmap对象 + star.bitmap = bitmapCacheMap.get(resId); + if (star.bitmap == null) { + star.bitmap = Bitmap.createScaledBitmap(originalBitmap, + star.width, star.height, true); + bitmapCacheMap.put(resId, star.bitmap); + } + return star; + } + + public static void clearCache(){ + bitmapCacheMap.clear(); + } + } +} diff --git a/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/animator/FireworkAnimator.java b/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/animator/FireworkAnimator.java new file mode 100644 index 0000000..8bacadf --- /dev/null +++ b/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/animator/FireworkAnimator.java @@ -0,0 +1,374 @@ +package clock.socoolby.com.clock.widget.animatorview.animator; + +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; +import android.util.Log; +import java.util.ArrayList; +import java.util.Iterator; + +import clock.socoolby.com.clock.widget.animatorview.AbstractCacheDifferenceAnimator; + +//引用自: https://blog.csdn.net/zhuxingchong/article/details/78342562 +public class FireworkAnimator extends AbstractCacheDifferenceAnimator { + + private final String TAG = this.getClass().getSimpleName(); + + private final static int MAX_SIZE = 2; + + @Override + public boolean run() { + Iterator iterator = list.iterator(); + while(iterator.hasNext()){ + Firework firework=iterator.next(); + if(firework.isNeedRemove()) { + firework.stop(); + iterator.remove(); + }else + firework.run(); + } + if(list.size()>=MAX_SIZE) + return true; + int round=rand.nextInt(20); + if(round>15) + lunchFireWork(rand.nextInt(width),rand.nextInt(height),0,STYLE.HEART);//心型 + if(round>10) + lunchFireWork(rand.nextInt(width),rand.nextInt(height),0,STYLE.MAX);//大烟花 + else if(round>5) + lunchFireWork(rand.nextInt(width),rand.nextInt(height),0,STYLE.SMALL);//小烟花 + return true; + } + + @Override + public void onDraw(Canvas canvas) { + for (Firework firework : list) { + firework.draw(canvas); + } + } + + @Override + public void stop() { + for (Firework firework : list) { + firework.stop(); + } + super.stop(); + } + + public void lunchFireWork(float x, float y, int direction, STYLE mode) { + final Firework firework = new Firework(new Location(x, y), direction, mode); + list.add(firework); + } + + + private final static int MAX_DEFAULT_ELEMENT_COUNT = 200;//大烟花爆炸数量 + private int MAX_DEFAULT_DURATION = 30; + private final static int MAX_DEFAULT_LAUNCH_SPEED = 25; + private final static int MAX_DEFAULT_ELEMENT_SIZE = 8; + + private final static int MID_DEFAULT_ELEMENT_SIZE = 5; + private final static int MID_DEFAULT_ELEMENT_COUNT = 40;//中烟花爆炸数量 + + private final static int BIG_DEFAULT_ELEMENT_COUNT = 200;//大烟花爆炸数量 + private int BIG_DEFAULT_DURATION = 20; + private final static float BIG_DEFAULT_LAUNCH_SPEED = 5; + private final static float BIG_DEFAULT_ELEMENT_SIZE = 3; + + private final static int SMALL_DEFAULT_ELEMENT_COUNT = 8;//小星星爆炸数量 + private int SMALL_DEFAULT_DURATION = 10;//烟花引导持续时间 + private final static float SMALL_DEFAULT_LAUNCH_SPEED = 18;//烟花分散速度 + private final static float SMALL_DEFAULT_ELEMENT_SIZE = 8;//烟花颗粒大小 + + private final static float DEFAULT_WIND_SPEED = 6; + private final static float DEFAULT_GRAVITY = 6; + + public class Firework { + final float screenWidthMeasure = 720; + + private Paint mPaint; + private int count; // count of element + private int duration; + private float launchSpeed; + private float windSpeed; + private float gravity; + private int windDirection; // 1 or -1 + private Location location; + private float elementSize; + + //此值在爆炸前为引导时长,在爆炸后为存留时长 + private float animatorValue; + + private ArrayList elements = new ArrayList<>(); + + private STYLE mode = STYLE.SMALL; + + public Firework(Location location, int windDirection, STYLE mode) { + this.location = location; + this.windDirection = windDirection; + this.mode = mode; + gravity = DEFAULT_GRAVITY; + windSpeed = DEFAULT_WIND_SPEED; + + if(rand.nextInt(5)==1){ + count=rand.nextInt(MAX_DEFAULT_ELEMENT_COUNT); + duration = rand.nextInt(MAX_DEFAULT_DURATION); + if((mode == STYLE.MAX)) { + launchSpeed = rand.nextInt(new Float(BIG_DEFAULT_LAUNCH_SPEED).intValue()); + elementSize = rand.nextInt(new Float(MID_DEFAULT_ELEMENT_SIZE).intValue()); + }else{ + launchSpeed = rand.nextInt(MAX_DEFAULT_LAUNCH_SPEED); + elementSize = rand.nextInt(MAX_DEFAULT_ELEMENT_SIZE); + } + }else switch (mode){ + case MAX:// 大烟花 + count = BIG_DEFAULT_ELEMENT_COUNT; + duration = BIG_DEFAULT_DURATION; + launchSpeed = BIG_DEFAULT_LAUNCH_SPEED; + elementSize = BIG_DEFAULT_ELEMENT_SIZE; + break; + case SMALL://小星星爆炸 + count = SMALL_DEFAULT_ELEMENT_COUNT; + duration = SMALL_DEFAULT_DURATION; + launchSpeed = SMALL_DEFAULT_LAUNCH_SPEED; + elementSize = SMALL_DEFAULT_ELEMENT_SIZE; + break; + case HEART: + count = MID_DEFAULT_ELEMENT_COUNT; + duration = BIG_DEFAULT_DURATION; + launchSpeed = BIG_DEFAULT_LAUNCH_SPEED; + elementSize = BIG_DEFAULT_ELEMENT_SIZE; + break; + } + init(); + //Log.d("fireworkAnimator","duration:"+duration); + } + + private void init() { + Element temp=null; + color=Util.roundColor(); + // 给每个火花设定一个随机的方向 0-360 + //Log.d(TAG, "Firework init mode = " + mode + " count = " + count); + switch (mode) { + case MAX: + for (int i = 0; i < count; i++) { + temp=revectForTrashCache(); + if(randColor) + randomColor(); + if(temp==null) + temp=new Element(color, Math.toRadians(rand.nextInt(360)), rand.nextFloat() * launchSpeed,elementSize); + else{ + temp.color=color; + temp.direction=Math.toRadians(rand.nextInt(360)); + temp.speed=rand.nextFloat() * launchSpeed; + temp.r=elementSize; + temp.x=temp.y=0; + } + elements.add(temp); + } + break; + case SMALL: + for (int i = 0; i < count; i++) { + temp=revectForTrashCache(); + if(randColor) + randomColor(); + if(temp==null) + temp=new Element(color, Math.toRadians(rand.nextInt(360)), rand.nextFloat() * launchSpeed,elementSize); + else{ + temp.color=color; + temp.direction=Math.toRadians(rand.nextInt(360)); + temp.speed=rand.nextFloat() * launchSpeed; + temp.r=elementSize; + temp.x=temp.y=0; + } + elements.add(temp); + } + break; + case HEART: + for (int i = 0; i < count; i++) { + temp=revectForTrashCache(); + if(randColor) + randomColor(); + if(temp==null) + temp=new Element(); + temp.color=color; + //temp.direction=-count/2 * (((Math.sin(i)*Math.sqrt(Math.abs(Math.cos(i)))) / (Math.sin(i) + 1.4142)) - 2 * Math.sin(i) + 2); + temp.direction=Math.toRadians(rand.nextInt(360)); + temp.speed=rand.nextFloat() * launchSpeed; + temp.r=elementSize; + temp.x=temp.y=0; + elements.add(temp); + } + break; + } + mPaint = new Paint(); + mPaint.setColor(Color.WHITE); + timeCount = 1; + animatorValue = duration; + } + + private float timeCount = 1; + private final float dif = 0.00816f; + private boolean needRemove = false; + + public boolean isNeedRemove() { + return needRemove; + } + + boolean isStart = false; + Element elementTemp=null; + /* + * 开始烟花爆炸动画 + */ + public void fire() { + //Log.d("zxc55", "onAnimationUpdate animatorValue = " + animatorValue); + // 计算每个火花的位置 + isStart = true; + animatorValue = timeCount; + switch (mode) { + case HEART: + for (int i = 0; i < count; i++) { + elementTemp = elements.get(i); + //产生极坐标点 + int m = i; + double n = -count / 2 * (((Math.sin(i) * Math.sqrt(Math.abs(Math.cos(i)))) / (Math.sin(i) + 1.4142)) - 2 * Math.sin(i) + 2); + //转换为笛卡尔坐标 + elementTemp.x = new Double(n * Math.cos(m) + elementTemp.speed * animatorValue + windSpeed * windDirection).floatValue(); + elementTemp.y = new Double(n * Math.sin(m) - elementTemp.speed * animatorValue + gravity * (1 - animatorValue)).floatValue(); + //Log.d("fireworkAnimator", "element.x:\t" + elementTemp.x + "\telement.y:\t" + elementTemp.y); + } + break; + default: + for (Element element : elements) { + element.x = (float) (element.x + + Math.cos(element.direction) * element.speed + * animatorValue + windSpeed * windDirection); + element.y = (float) (element.y + - Math.sin(element.direction) * element.speed + * animatorValue + gravity * (1 - animatorValue)); + } + } + } + + public void stop(){ + moveToTrashCache(elements); + isStart=false; + needRemove=true; + } + + public void onAnimationEnd() { + //Log.d("zxc118", "onAnimationEnd clear fireworkAnimator"); + needRemove = true; + } + + public void setDuration(int duration) { + this.duration = duration; + } + + public void run(){ + //前一部分为引导 + duration--; + + if(duration>0) + return; + + if(duration==0) { + fire(); + } + /* + * 有些情况小星星动画不能停止,强制结束 + */ + n++; + if (n > maxTime) { + onAnimationEnd(); + } + + /* + * 更新烟花位置 + */ + if (n > 2 && isStart) { + updateLocation(); + } + } + + private final int maxTime = 38; + private int n = 0; + private float fraction=0; + private float startX=0; + private float startY=0; + private float x=0; + private float y=0; + + public void draw(Canvas canvas) { + if(isStart){ + mPaint.setAlpha((int) (225 * animatorValue)); + for (Element element : elements) { + element.draw(canvas,mPaint,location.x,location.y); + } + }else{ + fraction=duration/animatorValue; + startX=width/2; + if(location.y<(height/2)&&rand.nextBoolean()) + startX=rand.nextInt(width); + startY=height; + x=location.x + fraction * (startX-location.x); + y=location.y+fraction * (startY-location.y); + //canvas.drawLine(width/2,height,x,y,mPaint); + canvas.drawCircle(x,y,MID_DEFAULT_ELEMENT_SIZE,mPaint); + canvas.drawCircle(x+SMALL_DEFAULT_ELEMENT_SIZE/2,y,SMALL_DEFAULT_ELEMENT_SIZE,mPaint); + } + } + + public void updateLocation() { + animatorValue -= dif; + if (animatorValue < 0) { + onAnimationEnd(); + } + for (Element element : elements) { + element.x = (float) (element.x + + Math.cos(element.direction) * element.speed + * animatorValue + windSpeed * windDirection); + element.y = (float) (element.y + - Math.sin(element.direction) * element.speed + * animatorValue + gravity * (1 - animatorValue)); + } + } + } + + public enum STYLE{ + MAX,SMALL,HEART; + } + + static class Location { + public float x; + public float y; + + public Location(float x, float y) { + this.x = x; + this.y = y; + } + } + + public class Element { + public int color; + public Double direction; + public float speed; + public float x = 0; + public float y = 0; + public float r=10; + + public Element(){ + + } + + public Element(int color, Double direction, float speed,float r) { + this.color = color; + this.direction = direction; + this.speed = speed; + this.r=r; + } + + public void draw(Canvas canvas, Paint mPaint,float baseX,float baseY) { + mPaint.setColor(color); + canvas.drawCircle(baseX + x, baseY + y,r, mPaint); + } + } +} diff --git a/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/animator/FluorescenceAnimator.java b/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/animator/FluorescenceAnimator.java new file mode 100644 index 0000000..8067081 --- /dev/null +++ b/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/animator/FluorescenceAnimator.java @@ -0,0 +1,171 @@ +package clock.socoolby.com.clock.widget.animatorview.animator; + + +//引用自:https://github.com/YuToo/FluorescenceView/ + +import android.graphics.Canvas; +import android.graphics.Paint; +import android.graphics.PointF; +import android.graphics.RadialGradient; +import android.graphics.Shader; + +import java.util.LinkedList; +import java.util.List; + +import clock.socoolby.com.clock.widget.animatorview.AbstractAnimator; + +public class FluorescenceAnimator extends AbstractAnimator { + + private int mParticleRadius = 15; // 粒子大小基数 + private int mParticleRandomRadius = 50; // 随机范围(基数上范围) + private int mParticleLife = 3000; //生命基数(毫秒) + private int mParticleRandomLife = 8000; //随机范围(基数上范围) + private int mParticleNum = 20; //粒子数量 + private int[] mParticleColors = {0xFF0d4289, 0xff034aa1,0x887b0808, 0xff176bd1, 0xff1f39ff,0x33d4ed00, 0x66ffffff, 0xff777800, 0xff0e2569};//粒子颜色集合 + private Paint mPaint; + + List cache = new LinkedList<>(); + + @Override + public boolean run() { + for(Particle particle : list){ + if(particle.getLife() <= 0){ + cache.add(particle); + } + } + list.removeAll(cache); + for(int i = 0 ; i < mParticleNum - list.size() ; i ++){ + list.add(randomParticle()); + } + cache.clear(); + return true; + } + + @Override + public void onDraw(Canvas canvas) { + for(Particle particle : list){ + PointF point = particle.getPoint(); + if(point == null){ + continue; + } + Shader shader = new RadialGradient(point.x, point.y, particle.getRadius(), particle.getColor(), 0x00000000, Shader.TileMode.CLAMP); + mPaint.setShader(shader); + mPaint.setAlpha((int)(particle.getTranslate() * 255)); + canvas.drawCircle(point.x, point.y, particle.getRadius(), mPaint); + } + } + + @Override + public void reset() { + super.reset(); + mPaint = new Paint(); + mPaint.setStyle(Paint.Style.FILL); + mPaint.setAntiAlias(true); + } + + private Particle randomParticle(){ + Particle particle = new Particle(); + // 随机起始位置 + PointF startP = new PointF(rand.nextInt(width), rand.nextInt(height)); + //随机结束位置 + PointF endP = new PointF(rand.nextInt(width), rand.nextInt(height)); + particle.setStartPointF(startP); + particle.setEndPointF(endP); + // 随机生命 + particle.setLife(mParticleLife + rand.nextInt(mParticleRandomLife)); + // 随机大小 + particle.setRadius(mParticleRadius + rand.nextInt(mParticleRandomRadius)); + // 随机颜色 + particle.setColor(mParticleColors[rand.nextInt(mParticleColors.length)]); + return particle; + } + + /** + * Created by YuToo on 2017/2/28. + * 荧光对象 + */ + public static class Particle { + + private PointF startPointF;//荧光开始坐标 + private PointF endPointF;//荧光结束点坐标 + private float radius;// 荧光半径 + private long startTime;//开始时间 + private int life; //生命 + private int color;//颜色 + + public Particle(){ + startTime = System.currentTimeMillis(); + } + + public PointF getStartPointF() { + return startPointF; + } + + public void setStartPointF(PointF startPointF) { + this.startPointF = startPointF; + } + + public PointF getEndPointF() { + return endPointF; + } + + public void setEndPointF(PointF endPointF) { + this.endPointF = endPointF; + } + + public float getRadius() { + return radius; + } + + public void setRadius(float radius) { + this.radius = radius; + } + + public long getStartTime() { + return startTime; + } + + public void setLife(int life) { + this.life = life; + } + + public int getColor() { + return color; + } + + public void setColor(int color) { + this.color = color; + } + + //获取粒子透明度:先透明再实体再透明(二次函数) + public float getTranslate(){ + // 根据生命计算透明度 + int life = getLife(); + if(life <= 0){ + return 0; + }else{ + // y = 4x - 4x的平方 + float x = (life * 1.0f / this.life); + return 4 * x *(1 - x); + } + } + + // 获取当前位置 + public PointF getPoint(){ + int life = getLife(); + if(life <= 0){ + return null; + }else{ + PointF pointF = new PointF(); + pointF.x = endPointF.x + (endPointF.x - startPointF.x) * (life * 1.0f / this.life); + pointF.y = endPointF.y + (endPointF.y - startPointF.y) * (life * 1.0f / this.life); + return pointF; + } + } + + //获取剩余生命 + public int getLife(){ + return (int)(startTime + life - System.currentTimeMillis()); + } + } +} diff --git a/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/animator/RainAnimator.java b/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/animator/RainAnimator.java new file mode 100644 index 0000000..5acd54d --- /dev/null +++ b/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/animator/RainAnimator.java @@ -0,0 +1,110 @@ +package clock.socoolby.com.clock.widget.animatorview.animator; + +import android.graphics.Canvas; +import android.graphics.Paint; +import android.graphics.Point; +import android.graphics.Rect; +import android.util.Log; + +import clock.socoolby.com.clock.widget.animatorview.AbstractAnimator; + + +//原作者:https://github.com/xianfeng99/Particle + +public class RainAnimator extends AbstractAnimator { + + + @Override + public boolean run() { + for(Rain item : list){ + item.move(); + } + return true; + } + + @Override + public void onDraw(Canvas canvas) { + for(Rain item : list){ + item.draw(canvas,paint); + } + } + + @Override + public void reset() { + super.reset(); + addRains(50); + } + + + public void addRains(int quantity) { + for (int i = 0; i < quantity;i++) { + list.add(new Rain()); + } + } + + private Paint paint = new Paint(); + private final int size = 50; //长度在0-50像素 + + public class Rain{ + private Rect point; //雨点 + private Point speed; //雨点x,y方向速度 + private int rainColor; + + public Rain(){ + point = new Rect(); + speed = new Point(); + reset(); + } + + + public void draw(Canvas canvas,Paint paint){ + paint.setColor(rainColor); + canvas.drawLine(point.left, point.top, point.right, point.bottom, paint); + } + + public void move(){ + point.left += speed.x; + point.top += speed.y; + point.right = point.right + speed.x; + point.bottom = point.bottom + speed.y; + + if(point.left < 0 || point.left > width || point.bottom > height){ + reset(); + } + speed.y += rand.nextBoolean() ? 1 : 0; + } + + private void reset(){ + int x = rand.nextInt(width); + int y = rand.nextInt(height); + int w = rand.nextInt(size / 2); + int h = rand.nextInt(size); + + w = w > h ? h : w; + + point.left = x; + point.top = y; + point.right = x - w; + point.bottom = y + h; + +// int speedX = rand.nextInt(size / 2); +// int speedY = rand.nextInt(size); + int speedX = w; + int speedY = h; + + speedX = speedX == 0 ? 1 : speedX; + speedY = speedY == 0 ? 1 : speedY; + speedX = speedX > speedY ? speedY : speedX; + + speed.x = -speedX; + speed.y = speedY; + if(randColor) + randomColor(); + this.rainColor=color; + } + + public void printPosition(){ + Log.d("rainPoint", "x : " + point.left + " y : " + point.top + " r : " + point.right + " b : " + point.bottom); + } + } +} diff --git a/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/animator/SkyAnimator.java b/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/animator/SkyAnimator.java new file mode 100644 index 0000000..1c94006 --- /dev/null +++ b/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/animator/SkyAnimator.java @@ -0,0 +1,213 @@ +package clock.socoolby.com.clock.widget.animatorview.animator; + +import android.graphics.Canvas; +import android.graphics.Paint; +import android.graphics.Point; + +import clock.socoolby.com.clock.widget.animatorview.AbstractAnimator; + +//原作者:https://github.com/xianfeng99/Particle + +public class SkyAnimator extends AbstractAnimator { + + + @Override + public void onDraw(Canvas canvas) { + for(Star item : list){ + item.draw(canvas); + } + } + + @Override + public void reset() { + super.reset(); + addStars(50); + } + + /** + * 添加小星星 + * @param quantity + */ + public void addStars(int quantity) { + for (int i = 0; i < quantity;i++) { + list.add(new Star()); + } + } + + @Override + public boolean run() { + move(); + return true; + } + + public void move(){ + if(list.size() == 0){ + throw new RuntimeException("请初在initScence的方法中加入效果元素!"); + } + + for(Star item : list){ + item.move(); + } + } + + public class Star { + private final int NORMAL = 0; + private final int LIGHT = 1; + private final int METEOR = 2; + private int state = NORMAL; + + private Paint paint = new Paint(); + private final int size = 20; // 长度在0-size像素 + private int radius; + private Point point; // 星星 + + private int light = 100;// 闪烁 + private int meteor = 10000;// 流星 + + //星星闪烁类型 + private final int LIGHT_FULL = 0; + private final int LIGHT_HALF = 1; + private final int LIGHT_HALF_ALPHA = 2; + private int lightState = 0; + private int lightAlpha = 80; + + //流星移动值 + private int meteorSpeedX; + private int meteorSpeedY; + private int meteorState = 0; + private int meteorAlpha = 255; + private int meteorStep; + + + public Star(){ + point = new Point(); + paint.setColor(0xffffffff); + reset(); + } + + public void draw(Canvas canvas) { + // 变长小于等于8绘制圆形 + switch (state) { + case NORMAL: + canvas.drawCircle(point.x, point.y, radius / 2, paint); + break; + case LIGHT: + canvas.drawCircle(point.x, point.y, radius / 2, paint); + drawLightStar(canvas); + break; + case METEOR: + drawMeteor(canvas); + break; + } + } + + public void move () { + switch (state) { + case NORMAL: + while (point.x < 0 || point.x > width || point.y > height) { + reset(); + } + int mod = rand.nextInt(light + 1) % light; + if (mod == 0) { + // 闪烁 + state = LIGHT; + lightState = rand.nextInt(10) % 3; + return; + } + mod = rand.nextInt(meteor + 1) % meteor; + if (mod == 0) { + // 流星 + state = METEOR; + meteorSpeedY = 1 + rand.nextInt(height / 20); + meteorSpeedX = rand.nextInt(width / 20); + meteorSpeedX *= rand.nextBoolean() ? 1 : -1; + meteorStep = 1; + return; + } + break; + case LIGHT: + lightAlpha -= 20; + if (lightAlpha < 0) { + state = NORMAL; + lightAlpha = 80; + } + break; + case METEOR: + meteorAlpha -= 20; + if (meteorAlpha < 0) { + state = NORMAL; + meteorAlpha = 255; + meteorStep = 1; + return; + } + meteorState = rand.nextInt(10) % 3; + meteorStep++; + break; + } + + } + + private void reset () { + point.x = rand.nextInt(width); + point.y = rand.nextInt(height / 2); + radius = rand.nextInt(size); + if(randColor) + randomColor(); + paint.setColor(color); + } + + private void drawLightStar (Canvas canvas){ + + switch (lightState) { + case LIGHT_HALF: + //左右交叉 + canvas.drawLine(point.x - radius, point.y - radius, point.x + radius, point.y + radius, paint); + canvas.drawLine(point.x - radius, point.y + radius, point.x + radius, point.y - radius, paint); + break; + case LIGHT_FULL: + paint.setAlpha(255 - lightAlpha); + //绘制横竖向 + canvas.drawLine(point.x - 2 * radius, point.y, point.x + 2 * radius, point.y, paint); + canvas.drawLine(point.x, point.y - 2 * radius, point.x, point.y + 2 * radius, paint); + case LIGHT_HALF_ALPHA: + paint.setAlpha(lightAlpha); + //左右交叉 + canvas.drawLine(point.x - radius, point.y - radius, point.x + radius, point.y + radius, paint); + canvas.drawLine(point.x - radius, point.y + radius, point.x + radius, point.y - radius, paint); + paint.setAlpha(255); + break; + } + + } + + private void drawMeteor (Canvas canvas){ + + int trimX = meteorStep * meteorSpeedX; + int trimY = meteorStep * meteorSpeedY; + paint.setAlpha(lightAlpha); + //绘制流行轨迹 + canvas.drawLine(point.x, point.y, trimX + point.x, trimY + point.y, paint); + paint.setAlpha(255); + canvas.drawCircle(trimX + point.x, trimY + point.y, radius / 2, paint); + switch (meteorState) { + case LIGHT_HALF: + //左右交叉 + canvas.drawLine(trimX + point.x - radius, trimY + point.y - radius, trimX + point.x + radius, trimY + point.y + radius, paint); + canvas.drawLine(trimX + point.x - radius, trimY + point.y + radius, trimX + point.x + radius, trimY + point.y - radius, paint); + break; + case LIGHT_FULL: + paint.setAlpha(255 - lightAlpha); + //绘制横竖向 + canvas.drawLine(trimX + point.x - 2 * radius, trimY + point.y, trimX + point.x + 2 * radius, trimY + point.y, paint); + canvas.drawLine(trimX + point.x, trimY + point.y - 2 * radius, trimX + point.x, trimY + point.y + 2 * radius, paint); + case LIGHT_HALF_ALPHA: + paint.setAlpha(lightAlpha); + //左右交叉 + canvas.drawLine(trimX + point.x - radius, trimY + point.y - radius, trimX + point.x + radius, trimY + point.y + radius, paint); + canvas.drawLine(trimX + point.x - radius, trimY + point.y + radius, trimX + point.x + radius, trimY + point.y - radius, paint); + paint.setAlpha(255); + break; + } + } + } +} diff --git a/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/animator/SnowAnimator.java b/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/animator/SnowAnimator.java new file mode 100644 index 0000000..6543359 --- /dev/null +++ b/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/animator/SnowAnimator.java @@ -0,0 +1,244 @@ +package clock.socoolby.com.clock.widget.animatorview.animator; + +import android.graphics.Canvas; +import android.graphics.Paint; +import android.graphics.Point; +import android.graphics.Rect; +import android.util.Log; + +import clock.socoolby.com.clock.widget.animatorview.AbstractAnimator; + +//引用自:https://github.com/xianfeng99/Particle + +public class SnowAnimator extends AbstractAnimator { + + @Override + public boolean run() { + for(SnowPoint item : list){ + item.move(); + } + return true; + } + + Paint paint=new Paint(); + + @Override + public void onDraw(Canvas canvas) { + for(SnowPoint item : list){ + item.draw(canvas,paint); + } + } + + @Override + public void reset() { + super.reset(); + addSnowPoint(50); + } + + public void addSnowPoint(int quantity) { + int round; + for (int i = 0; i < quantity;i++) { + round=rand.nextInt(2); + if(randColor) + randomColor(); + if(round==1) + list.add(new SnowPoint2(color)); + else + list.add(new SnowPoint(color)); + } + } + + public class SnowPoint{ + int color; + protected final int size = 36; // 长度在0-50像素 + private Rect rect; // 雪图 + protected Point point; // 雪点 + protected Point speed; // 雪点x,y方向速度 + + + public SnowPoint(int color) { + rect = new Rect(); + speed = new Point(); + point=new Point(); + reset(); + this.color=color; + } + + public void draw(Canvas canvas,Paint paint) { + paint.setColor(color); + //变长小于等于8绘制圆形 + if(rect.width() <= 8){ + canvas.drawCircle(rect.left, rect.top, rect.width() / 2, paint); + } + else{ + //绘制雪花形状 + drawSknow(canvas,paint); + } + } + + int count = 0; + + public void move() { + point.x += speed.x; + point.y += speed.y; + rect.left += point.x; + rect.top += point.y; + rect.right = rect.right + speed.x; + rect.bottom = rect.bottom + speed.y; + + changeSpeed(); + + if (mustReset()) { + reset(); + } + } + + public void changeSpeed(){ + count++; + if (count > 5) { + count = 0; + speed.x = rand.nextInt(size); + speed.x = speed.x > speed.y ? speed.y : speed.x; + speed.x = rand.nextBoolean() ? -speed.x : speed.x; + speed.y += rand.nextBoolean() ? 1 : 0; + } + } + + + public boolean mustReset(){ + if (rect.left < 0 || rect.bottom > height) { + return true; + } + return false; + } + + public void reset() { + reset(true); + } + + public void reset(boolean resetRect) { + point.x = rand.nextInt(width); + point.y = rand.nextInt(height); + + + //减少出现在下面的机率 + if(point.y>height*2/3&&rand.nextBoolean()) + point.y=point.y-height/2; + + if(resetRect) { + int w = rand.nextInt(size); + int h = rand.nextInt(size); + + if (w > 8) { + //勾3股4弦5(宽是4的倍数,高是3的倍数) + int mod = w % 4; + w += mod; + int mul = w / 4;//倍数 + h = 3 * mul; + rect.left = point.x; + rect.top = point.y; + rect.right = point.x + w; + rect.bottom = point.y + h; + } else { + rect.left = point.x; + rect.top = point.y; + rect.right = point.x + w; + rect.bottom = point.y + w; + } + } + + //修改:速度过快 + int speedX = rand.nextInt(size/2); + int speedY = rand.nextInt(size/2); + + /* + * int speedX = w; int speedY = h; + */ + + speedX = speedX == 0 ? 1 : speedX; + speedY = speedY == 0 ? 1 : speedY; + speedX = speedX > speedY ? speedY : speedX; + + speed.x = speedX; + speed.y = speedY; + } + + + public void drawSknow(Canvas canvas,Paint paint){ + int w = rect.width(); + int h = rect.height(); + int mul = w / 4;//倍数 + float xie = 5 * mul / 2; + float centerY = rect.top + h / 2; + float centerX = rect.left + w / 2; + + canvas.drawLine(rect.left, rect.top, rect.right, rect.bottom, paint); + canvas.drawLine(rect.left, rect.bottom, rect.right, rect.top, paint); + canvas.drawLine(centerX, centerY - xie, centerX, centerY + xie, paint); + + } + + public void printPosition() { + Log.d("SknowPoint", "x : " + rect.left + " y : " + rect.top + " r : " + + rect.right + " b : " + rect.bottom); + } + } + + public class SnowPoint2 extends SnowPoint{ + private int lenSize;// 边长 + private int mul;// 倍数 + + public SnowPoint2(int color) { + super(color); + } + + public void reset() { + super.reset(false); + lenSize = rand.nextInt(size); + lenSize += lenSize % 5; + mul = lenSize / 5; + } + + @Override + public boolean mustReset() { + if (point.x < 0 || point.x > width || point.y > height) { + return true; + } + return false; + } + + public void draw(Canvas canvas,Paint paint) { + paint.setColor(color); + // 变长小于等于10绘制圆形 + if (lenSize <= 10) { + canvas.drawCircle(point.x, point.y, lenSize / 2, paint); + } else { + // 绘制雪花形状 + drawSknow(canvas,paint); + } + } + + public void drawSknow(Canvas canvas, Paint paint) { + int y = mul * 3; + int x = mul * 4; + + if (speed.x > 0) { + // 竖雪花 + canvas.drawLine(point.x, point.y - (float) lenSize / 2, point.x, + point.y + (float) lenSize / 2, paint); + canvas.drawLine(point.x - (float) x / 2, point.y - (float) y / 2, + point.x + (float) x / 2, point.y + (float) y / 2, paint); + canvas.drawLine(point.x - (float) x / 2, point.y + (float) y / 2, + point.x + (float) x / 2, point.y - (float) y / 2, paint); + } else { + // 横雪花 + canvas.drawLine(point.x - (float) lenSize / 2, point.y, point.x + + (float) lenSize / 2, point.y, paint); + canvas.drawLine(point.x - (float) y / 2, point.y - (float) x / 2, + point.x + (float) y / 2, point.y + (float) x / 2, paint); + canvas.drawLine(point.x - (float) y / 2, point.y + (float) x / 2, + point.x + (float) y / 2, point.y - (float) x / 2, paint); + } + } + } +} diff --git a/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/animator/StarFallAnimator.java b/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/animator/StarFallAnimator.java new file mode 100644 index 0000000..d6a0d92 --- /dev/null +++ b/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/animator/StarFallAnimator.java @@ -0,0 +1,22 @@ +package clock.socoolby.com.clock.widget.animatorview.animator; + + +import clock.socoolby.com.clock.R; + +public class StarFallAnimator extends DrawableArrayFallAnimator { + + //小星星图片的资源文件 + static int[] picRes = {R.drawable.ic_star + ,R.drawable.ic_star1 + ,R.drawable.ic_star2 + ,R.drawable.ic_star3 + ,R.drawable.ic_star4 + ,R.drawable.ic_star5 + ,R.drawable.ic_star6 + ,R.drawable.ic_star7 + }; + + public StarFallAnimator() { + super(picRes,10); + } +} diff --git a/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/animator/bean/Particle.java b/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/animator/bean/Particle.java new file mode 100644 index 0000000..9bada0b --- /dev/null +++ b/app/src/main/java/clock/socoolby/com/clock/widget/animatorview/animator/bean/Particle.java @@ -0,0 +1,10 @@ +package clock.socoolby.com.clock.widget.animatorview.animator.bean; + +public class Particle { + public int color; + public Double direction; + public float speed; + public float x = 0; + public float y = 0; + public float r=10; +} diff --git a/app/src/main/java/clock/socoolby/com/clock/widget/textview/AutoScrollTextView.java b/app/src/main/java/clock/socoolby/com/clock/widget/textview/AutoScrollTextView.java index b49f669..012e9ce 100644 --- a/app/src/main/java/clock/socoolby/com/clock/widget/textview/AutoScrollTextView.java +++ b/app/src/main/java/clock/socoolby/com/clock/widget/textview/AutoScrollTextView.java @@ -178,7 +178,11 @@ public class AutoScrollTextView extends android.support.v7.widget.AppCompatTextV stopScroll(); else startScroll(); - } + @Override + public void setTextColor(int color){ + super.setTextColor(color); + paint.setColor(color); + } } diff --git a/app/src/main/res/drawable/ic_background_color.xml b/app/src/main/res/drawable/ic_background_color.xml new file mode 100644 index 0000000..ca49100 --- /dev/null +++ b/app/src/main/res/drawable/ic_background_color.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_check_box_black_24dp.xml b/app/src/main/res/drawable/ic_check_box_black_24dp.xml new file mode 100644 index 0000000..fff2552 --- /dev/null +++ b/app/src/main/res/drawable/ic_check_box_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_foreground_color.xml b/app/src/main/res/drawable/ic_foreground_color.xml new file mode 100644 index 0000000..9a1658d --- /dev/null +++ b/app/src/main/res/drawable/ic_foreground_color.xml @@ -0,0 +1,12 @@ + + + + diff --git a/app/src/main/res/drawable/ic_star.xml b/app/src/main/res/drawable/ic_star.xml new file mode 100644 index 0000000..cacdce5 --- /dev/null +++ b/app/src/main/res/drawable/ic_star.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_star1.xml b/app/src/main/res/drawable/ic_star1.xml new file mode 100644 index 0000000..90a868d --- /dev/null +++ b/app/src/main/res/drawable/ic_star1.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_star2.xml b/app/src/main/res/drawable/ic_star2.xml new file mode 100644 index 0000000..45f4528 --- /dev/null +++ b/app/src/main/res/drawable/ic_star2.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_star3.xml b/app/src/main/res/drawable/ic_star3.xml new file mode 100644 index 0000000..43bcad1 --- /dev/null +++ b/app/src/main/res/drawable/ic_star3.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_star4.xml b/app/src/main/res/drawable/ic_star4.xml new file mode 100644 index 0000000..4841cc9 --- /dev/null +++ b/app/src/main/res/drawable/ic_star4.xml @@ -0,0 +1,15 @@ + + + + + diff --git a/app/src/main/res/drawable/ic_star5.xml b/app/src/main/res/drawable/ic_star5.xml new file mode 100644 index 0000000..68313fe --- /dev/null +++ b/app/src/main/res/drawable/ic_star5.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_star6.xml b/app/src/main/res/drawable/ic_star6.xml new file mode 100644 index 0000000..9362fdc --- /dev/null +++ b/app/src/main/res/drawable/ic_star6.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_star7.xml b/app/src/main/res/drawable/ic_star7.xml new file mode 100644 index 0000000..c864712 --- /dev/null +++ b/app/src/main/res/drawable/ic_star7.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index af3aac3..e001dba 100755 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,12 +1,26 @@ - + + + + @@ -34,6 +49,7 @@ android:layout_alignParentRight="true" android:layout_marginRight="10dp" android:layout_marginTop="10dp" + android:background="#00FFFFFF" android:textColor="#fff" android:textSize="32sp" /> @@ -48,6 +64,45 @@ android:layout_marginTop="10dp" android:src="@drawable/ic_handup" /> + + + + + + - @@ -98,6 +154,7 @@ android:layout_centerHorizontal="true" android:gravity="center" android:textColor="#fff" + android:background="#00FFFFFF" android:layout_weight="8" android:textSize="26sp" /> @@ -114,3 +171,10 @@ android:visibility="gone" /> + + \ No newline at end of file diff --git a/app/src/main/res/layout/pop_color_picker.xml b/app/src/main/res/layout/pop_color_picker.xml new file mode 100644 index 0000000..5ddbeaf --- /dev/null +++ b/app/src/main/res/layout/pop_color_picker.xml @@ -0,0 +1,290 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 63a756b..3bc7a48 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -23,4 +23,8 @@ 自动息屏 手动设置屏显 关闭触发 + 透明度 + 深度 + 对话框标题 + 示列文本 \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c36a434..de38813 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -26,4 +26,8 @@ Except Motto Version: + dialog_folder_title + color_depth + transparency + examples_text