diff --git a/app/src/main/java/clock/socoolby/com/clock/Constants.java b/app/src/main/java/clock/socoolby/com/clock/Constants.java index 2d4b0aa..ee4a354 100644 --- a/app/src/main/java/clock/socoolby/com/clock/Constants.java +++ b/app/src/main/java/clock/socoolby/com/clock/Constants.java @@ -6,6 +6,8 @@ public class Constants { public final static int TALKING_HOURS=2; public final static int TALKING_NO_REPORT=3; public final static String SHARE_PERFERENCE_FILE="share_perference.conf"; + public final static String SHARE_PERFERENCE_FILE1="share_perference1.conf"; + public final static String SHARE_PERFERENCE_FILE2="share_perference2.conf"; public final static int SUCCESS_CODE=0; public final static int FAIL_CODE=-1; public final static int TYPE_TRIGGER_AUTO_OFF=4; 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 096e138..d018ba2 100755 --- a/app/src/main/java/clock/socoolby/com/clock/MainActivity.java +++ b/app/src/main/java/clock/socoolby/com/clock/MainActivity.java @@ -4,7 +4,9 @@ package clock.socoolby.com.clock; import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.app.Activity; +import android.content.Context; import android.content.Intent; +import android.graphics.Color; import android.os.Build; import android.os.Handler; import android.os.Message; @@ -15,9 +17,11 @@ import android.support.v4.app.ActivityCompat; import android.util.Log; import android.view.GestureDetector; import android.view.KeyEvent; +import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.ScaleGestureDetector; import android.view.View; +import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager; import android.widget.FrameLayout; @@ -337,7 +341,80 @@ public class MainActivity extends Activity implements Handler.Callback, View.OnC setContentView(R.layout.activity_main); mainBackground=findViewById(R.id.main_background); tv_background_image=findViewById(R.id.tv_background_image); - tv_background_image_hand=findViewById(R.id.tv_background_image_hand); + + animatorView=findViewById(R.id.tv_background_animatorview); + + clockView=findViewById(R.id.tv_foreground_animatorview); + + tv_time = findViewById(R.id.tv_time); + //tv_time.setOnClickListener(this); + + handler = new Handler(this); + + if(PermissionUtils.isGranted("android.permission.WAKE_LOCK","android.permission.DEVICE_POWER")) { + PowerManager powerManager = (PowerManager) this.getSystemService(POWER_SERVICE); + wakeLock = powerManager.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.FULL_WAKE_LOCK |powerManager.ON_AFTER_RELEASE, "Clock"); + localWakeLock = powerManager.newWakeLock(32, "MyPower"); + }else + getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + + + //创建手势检测器 + detector = new GestureDetector(this, this); + detector.setOnDoubleTapListener(this); + + scaleGestureDetector=new ScaleGestureDetector(this,this); + + init(); + + switchThemeType(currentThemeTypeId); + + initUI(); + + ClockApplication.getInstance().setMainActivity(this); + + //Log.d(TAG,"create timer and timerTask................................."); + timer = new Timer(); + timerTask = new TimerTask() { + @Override + public void run() { + //Log.d(TAG, "timerTask move..."); + if (!ScreenManager.isScreenOn()) + return; + handler.sendEmptyMessage(UPDATE_TIME); + } + }; + timer.schedule(timerTask, 1000, 1000); + //ClockApplication.getInstance().getBusinessService().checkUpdate(); + } + + private int currentThemeTypeId=R.layout.theme_sample; + private float themeBaseLine=0; + private View themeRoot=null; + private void switchThemeType(int themeType){ + currentThemeTypeId=themeType; + switch (themeType){ + case R.layout.theme_sample: + themeBaseLine=-110; + break; + default: + themeBaseLine=0; + } + initTheme(this,themeType); + currentDate=null; + setWeather(weatherAdape); + resetThemeUI(); + } + + private void initTheme(Context context, int themeType){ + if(themeRoot!=null) { + themeRoot.setVisibility(View.GONE); + mainBackground.removeView(themeRoot); + } + themeRoot = LayoutInflater.from(context).inflate(themeType,null,false); + mainBackground.addView(themeRoot); + + tv_background_image_hand=themeRoot.findViewById(R.id.tv_background_image_hand); tv_background_image_hand.setOnClickListener(this); tv_background_image_hand.setOnLongClickListener(new View.OnLongClickListener() { @Override @@ -347,18 +424,20 @@ public class MainActivity extends Activity implements Handler.Callback, View.OnC } }); - animatorView=findViewById(R.id.tv_background_animatorview); - - clockView=findViewById(R.id.tv_foreground_animatorview); - - tv_time = findViewById(R.id.tv_time); - //tv_time.setOnClickListener(this); - - tv_date = findViewById(R.id.tv_date); + tv_date = themeRoot.findViewById(R.id.tv_date); tv_date.setOnClickListener(this); + tv_date.setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + if(currentThemeTypeId==R.layout.theme_default) + switchThemeType(R.layout.theme_sample); + else + switchThemeType(R.layout.theme_default); + return true; + } + }); - - tv_day = findViewById(R.id.tv_day); + tv_day = themeRoot.findViewById(R.id.tv_day); tv_day.setOnClickListener(this); tv_day.setOnLongClickListener(new View.OnLongClickListener() { @Override @@ -372,7 +451,7 @@ public class MainActivity extends Activity implements Handler.Callback, View.OnC } }); - tv_weather = findViewById(R.id.tv_weather); + tv_weather = themeRoot.findViewById(R.id.tv_weather); tv_weather.setOnClickListener(this); tv_descript = findViewById(R.id.tv_descript); tv_descript.setOnClickListener(this); @@ -384,7 +463,7 @@ public class MainActivity extends Activity implements Handler.Callback, View.OnC } }); - tv_break=findViewById(R.id.tv_break); + tv_break=themeRoot.findViewById(R.id.tv_break); tv_break.setOnClickListener(this); tv_break.setOnLongClickListener(new View.OnLongClickListener() { @Override @@ -399,7 +478,7 @@ public class MainActivity extends Activity implements Handler.Callback, View.OnC } }); - tv_handup=findViewById(R.id.tv_hand); + tv_handup=themeRoot.findViewById(R.id.tv_hand); tv_handup.setOnClickListener(this); tv_handup.setOnLongClickListener(new View.OnLongClickListener() { @Override @@ -410,7 +489,7 @@ public class MainActivity extends Activity implements Handler.Callback, View.OnC return true; } }); - tv_hand_time=findViewById(R.id.tv_hand_time); + tv_hand_time=themeRoot.findViewById(R.id.tv_hand_time); tv_hand_time.setOnClickListener(this); tv_hand_time.setOnLongClickListener(new View.OnLongClickListener() { @Override @@ -421,12 +500,12 @@ public class MainActivity extends Activity implements Handler.Callback, View.OnC } }); - tv_hours_system=findViewById(R.id.tv_hours_system); + tv_hours_system=themeRoot.findViewById(R.id.tv_hours_system); - tv_background_color=findViewById(R.id.tv_background_color); + tv_background_color=themeRoot.findViewById(R.id.tv_background_color); tv_background_color.setOnClickListener(this); - tv_foreground_color=findViewById(R.id.tv_foreground_color); + tv_foreground_color=themeRoot.findViewById(R.id.tv_foreground_color); tv_foreground_color.setOnClickListener(this); tv_foreground_color.setOnLongClickListener(new View.OnLongClickListener() { @Override @@ -455,7 +534,7 @@ public class MainActivity extends Activity implements Handler.Callback, View.OnC } }); - tv_foreground_color1=findViewById(R.id.tv_foreground_color1); + tv_foreground_color1=themeRoot.findViewById(R.id.tv_foreground_color1); tv_foreground_color1.setOnClickListener(this); tv_foreground_color1.setOnLongClickListener(new View.OnLongClickListener() { @Override @@ -484,59 +563,28 @@ public class MainActivity extends Activity implements Handler.Callback, View.OnC } }); - tv_handup_image=findViewById(R.id.tv_handup_image); + tv_handup_image=themeRoot.findViewById(R.id.tv_handup_image); tv_handup_image.setOnClickListener(this); - - handler = new Handler(this); - tv_setting = findViewById(R.id.tv_setting); + tv_setting = themeRoot.findViewById(R.id.tv_setting); tv_setting.setOnClickListener(this); //RelativeLayout rel_main = (RelativeLayout) findViewById(R.id.rel_main); //rel_main.setOnClickListener(this); - tv_screen_lock =findViewById(R.id.tv_screen_lock); + tv_screen_lock =themeRoot.findViewById(R.id.tv_screen_lock); tv_screen_lock.setOnClickListener(this); tv_screen_lock.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { - screenLock(true); - switchMode(MODE_FULLSCREEN); - return true; + if(mMode!=MODE_FULLSCREEN) { + screenLock(true); + switchMode(MODE_FULLSCREEN); + return true; + } + return false; } }); - - - if(PermissionUtils.isGranted("android.permission.WAKE_LOCK","android.permission.DEVICE_POWER")) { - PowerManager powerManager = (PowerManager) this.getSystemService(POWER_SERVICE); - wakeLock = powerManager.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.FULL_WAKE_LOCK |powerManager.ON_AFTER_RELEASE, "Clock"); - localWakeLock = powerManager.newWakeLock(32, "MyPower"); - }else - getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); - - - //创建手势检测器 - detector = new GestureDetector(this, this); - detector.setOnDoubleTapListener(this); - - scaleGestureDetector=new ScaleGestureDetector(this,this); - - init(); - ClockApplication.getInstance().setMainActivity(this); - - //Log.d(TAG,"create timer and timerTask................................."); - timer = new Timer(); - timerTask = new TimerTask() { - @Override - public void run() { - //Log.d(TAG, "timerTask move..."); - if (!ScreenManager.isScreenOn()) - return; - handler.sendEmptyMessage(UPDATE_TIME); - } - }; - timer.schedule(timerTask, 1000, 1000); - //ClockApplication.getInstance().getBusinessService().checkUpdate(); } @@ -582,17 +630,29 @@ public class MainActivity extends Activity implements Handler.Callback, View.OnC model.read(); initTimeFontStyle(); Log.d(TAG, "init model:" + model.toString()); - setDiscriptForModel(); + proximityServiceIntent = new Intent(this, ProximityService.class); setUpProximityService(); brightness=getSystemBrightness(); handUpAbla=model.isHandUpAble(); - resetColorFromModel(); - setFont(model.getFontIndex()==null?0:model.getFontIndex()); + } + + private void initUI(){ upHandStatic(); resetHandUpTime(); updateHourSystem(); + resetColorFromModel(); + } + + private void resetThemeUI(){ + setDiscriptForModel(); + setFont(model.getFontIndex()==null?0:model.getFontIndex()); + Integer backUp=foregroundColor; + if(foregroundColor!=null) { + foregroundColor=null; + setForegroundColor(backUp); + } } private void resetColorFromModel(){ @@ -712,7 +772,7 @@ public class MainActivity extends Activity implements Handler.Callback, View.OnC tv_time.setTextColor(color); tv_date.setTextColor(color); tv_day.setTextColor(color); - tv_weather .setTextColor(color); + tv_weather.setTextColor(color); tv_descript.setTextColor(color); tv_handup_image.setTextColor(color); @@ -921,7 +981,6 @@ public class MainActivity extends Activity implements Handler.Callback, View.OnC tv_break.setVisibility(View.GONE); }else{ if(clockView.isRunning()) { - //clockView.setAnimator(null); clockView.stop(); } clockView.setVisibility(View.GONE); @@ -1442,7 +1501,7 @@ public class MainActivity extends Activity implements Handler.Callback, View.OnC if(isFullScreen){ tv_time.setBaseLineDown(0); }else{ - tv_time.setBaseLineDown(tv_day.getHeight()/2); + tv_time.setBaseLineDown(themeBaseLine+tv_day.getHeight()/2); } tv_time.setText(timeString); } @@ -1457,6 +1516,9 @@ public class MainActivity extends Activity implements Handler.Callback, View.OnC case COUNTING: DateModel temp=new DateModel(countingDateTimeBase); timeString=temp.getTimeString(false); + if (!model.isTickSound()&&mMode!=MODE_HANDUP) { + Player.getInstance().playTick(this,R.raw.tick2); + } break; case COUNTING_DOWN: timeString=DateModel.getTimeFull(handUpTime); @@ -1530,8 +1592,8 @@ public class MainActivity extends Activity implements Handler.Callback, View.OnC } private void reportTime(DateModel date) { - if (model.isTickSound()) { - Player.getInstance().playTick(this); + if (model.isTickSound()&&mMode!=MODE_HANDUP) { + Player.getInstance().playTick(this,R.raw.tick2); } int year = date.getYear(); int month = date.getMonth(); @@ -1723,12 +1785,12 @@ public class MainActivity extends Activity implements Handler.Callback, View.OnC int currentFontSize=new Float(tv_time.getTextSize()/fontScale).intValue(); currentFontSize=currentFontSize+step; Log.d(TAG,"onScaleEnd span:"+span+"\t step:"+step+"\tcurrent text size"+currentFontSize+"\t max text size:"+maxFontSize+"\tmin :"+baseFontSize); - if(currentFontSize>maxFontSize*1.3){ - currentFontSize=maxFontSize; - } - if(currentFontSizemaxFontSize*1.3){ + // currentFontSize=maxFontSize; + //} + //if(currentFontSize soundFileCache=new HashMap<>(); public void playHandUp(Context activity){ if (!ScreenManager.isScreenOn() || ScreenManager.isApplicationBroughtToBackground(ClockApplication.getContext())) return; - playSoundWithRawId(activity,R.raw.handup_didi); + if (!isReporttime) { + playSoundWithRawId(activity, R.raw.handup_didi); + } } + public void playSoundWithRawId(Context activity,int soundId){ if (mediaPlayer == null) mediaPlayer = buildMediaPlayer(); - - if (handUpFile == null) - handUpFile = activity.getResources().openRawResourceFd(soundId); + soundFile =soundFileCache.get(soundId); + if (soundFile == null) { + soundFile = activity.getResources().openRawResourceFd(soundId); + soundFileCache.put(soundId, soundFile); + } try { mediaPlayer.reset(); - mediaPlayer.setDataSource(handUpFile.getFileDescriptor(), handUpFile.getStartOffset(), handUpFile.getLength()); + mediaPlayer.setDataSource(soundFile.getFileDescriptor(), soundFile.getStartOffset(), soundFile.getLength()); mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME); mediaPlayer.prepare(); mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { 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 c8e93e0..b06c4b4 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 @@ -56,12 +56,12 @@ public class AutoScrollTextView extends android.support.v7.widget.AppCompatTextV textLength = paint.measureText(text); viewWidth = getWidth(); - Log.e(TAG,"--->"+textLength+"--->"+viewWidth+"-->"+getTextSize()); + //Log.e(TAG,"--->"+textLength+"--->"+viewWidth+"-->"+getTextSize()); if(viewWidth == 0) { viewWidth = 600;//获取屏幕的宽度 } - Log.e(TAG,"屏幕的宽度-->"+ 600); + //Log.e(TAG,"屏幕的宽度-->"+ 600); step = textLength;//文字真实的长度 temp_view_plus_text_length = viewWidth/2 + textLength; temp_view_plus_two_text_length = viewWidth + textLength * 2;//文字移动的距离应该是控件的长度+左边一个文字的长度+右边一个文字的长度 diff --git a/app/src/main/java/clock/socoolby/com/clock/widget/textview/DigitTextView.java b/app/src/main/java/clock/socoolby/com/clock/widget/textview/DigitTextView.java index 9eb6bcd..39fc7d4 100644 --- a/app/src/main/java/clock/socoolby/com/clock/widget/textview/DigitTextView.java +++ b/app/src/main/java/clock/socoolby/com/clock/widget/textview/DigitTextView.java @@ -207,7 +207,7 @@ public class DigitTextView extends android.support.v7.widget.AppCompatTextView { } if (charAnimator != null) { charAnimator.drawCharAnimator(canvas, startX + (baseCharWidth - charWidth) / 2, startY + baseLineDown, mTextPaint); - Log.d(Tag,"charAnimator index i:"+i+"\tanimator percent:"); + //Log.d(Tag,"charAnimator index i:"+i+"\tanimator percent:"); invalidate(); }else drawChar(canvas, c, startX + (baseCharWidth - charWidth) / 2, startY + baseLineDown, mTextPaint); diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 2090a57..79cb8d0 100755 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -32,210 +32,6 @@ android:textColor="#fff" /> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/theme_sample.xml b/app/src/main/res/layout/theme_sample.xml new file mode 100644 index 0000000..5c2d856 --- /dev/null +++ b/app/src/main/res/layout/theme_sample.xml @@ -0,0 +1,206 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/raw/tick1.mp3 b/app/src/main/res/raw/tick1.mp3 new file mode 100644 index 0000000..0e40af3 Binary files /dev/null and b/app/src/main/res/raw/tick1.mp3 differ diff --git a/app/src/main/res/raw/tick2.mp3 b/app/src/main/res/raw/tick2.mp3 new file mode 100644 index 0000000..a00263c Binary files /dev/null and b/app/src/main/res/raw/tick2.mp3 differ