diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..96cc43e --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..326e24e --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,19 @@ + + + + + + \ No newline at end of file diff --git a/.idea/libraries/animated_vector_drawable_24_2_1.xml b/.idea/libraries/animated_vector_drawable_24_2_1.xml new file mode 100644 index 0000000..e0c746d --- /dev/null +++ b/.idea/libraries/animated_vector_drawable_24_2_1.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/appcompat_v7_24_2_1.xml b/.idea/libraries/appcompat_v7_24_2_1.xml new file mode 100644 index 0000000..efdb838 --- /dev/null +++ b/.idea/libraries/appcompat_v7_24_2_1.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/library_2_4_0.xml b/.idea/libraries/library_2_4_0.xml new file mode 100644 index 0000000..eedfc0d --- /dev/null +++ b/.idea/libraries/library_2_4_0.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/support_annotations_24_2_1.xml b/.idea/libraries/support_annotations_24_2_1.xml new file mode 100644 index 0000000..8ce9120 --- /dev/null +++ b/.idea/libraries/support_annotations_24_2_1.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/support_compat_24_2_1.xml b/.idea/libraries/support_compat_24_2_1.xml new file mode 100644 index 0000000..644ba85 --- /dev/null +++ b/.idea/libraries/support_compat_24_2_1.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/support_core_ui_24_2_1.xml b/.idea/libraries/support_core_ui_24_2_1.xml new file mode 100644 index 0000000..865c5af --- /dev/null +++ b/.idea/libraries/support_core_ui_24_2_1.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/support_core_utils_24_2_1.xml b/.idea/libraries/support_core_utils_24_2_1.xml new file mode 100644 index 0000000..98a3039 --- /dev/null +++ b/.idea/libraries/support_core_utils_24_2_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/support_fragment_24_2_1.xml b/.idea/libraries/support_fragment_24_2_1.xml new file mode 100644 index 0000000..d697b37 --- /dev/null +++ b/.idea/libraries/support_fragment_24_2_1.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/support_media_compat_24_2_1.xml b/.idea/libraries/support_media_compat_24_2_1.xml new file mode 100644 index 0000000..387aa09 --- /dev/null +++ b/.idea/libraries/support_media_compat_24_2_1.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/support_v4_24_2_1.xml b/.idea/libraries/support_v4_24_2_1.xml new file mode 100644 index 0000000..9afc61a --- /dev/null +++ b/.idea/libraries/support_v4_24_2_1.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/support_vector_drawable_24_2_1.xml b/.idea/libraries/support_vector_drawable_24_2_1.xml new file mode 100644 index 0000000..e7e9164 --- /dev/null +++ b/.idea/libraries/support_vector_drawable_24_2_1.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..7158618 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1.8 + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..25285bf --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..0ed8e92 --- /dev/null +++ b/README.md @@ -0,0 +1,123 @@ +TimelyTimeView +============== + + +## Animated Time View like Timely app + +Screenshots: +-------- + +![Screenshots/screenshot1](https://github.com/iballan/TimelyTextView/raw/master/Screenshots/TimelyTimeView_screenshot.gif) ![Screenshots/screenshot2](https://github.com/iballan/TimelyTextView/raw/master/Screenshots/TimelyView_Screenshot.gif) + + + +Usage : + +XML Layout: +``` xml + + + + +``` + +Java: +``` java + public class MainActivity extends Activity { + private TimelyTimeView ttv; + TimelyShortTimeView tstv_hours; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + // TimelyTimeView + ttv = (TimelyTimeView) findViewById(R.id.ttv); + ttv.setTextColor(Color.WHITE); + ttv.setSeperatorsTextSize(50); + + // Then whenever you want to set the time and animate to it + ttv.setTime("00:00:00"); // As formatted String + // OR + ttv.setTime(new int[]{12:12:12}); + // OR + ttv.setTime(new Date()); + + // ------------------ + // TimelyShortTimeView for (hour:min) + tstv_hours = (TimelyShortTimeView) findViewById(R.id.tstv_hours); + tstv_hours.setTextColor(Color.BLACK); + tstv_hours.setTimeFormat(TimelyShortTimeView.FORMAT_HOUR_MIN); // can be set as TimelyShortTimeView.FORMAT_MIN_SEC + tstv_hours.setSeperatorsTextSize(50); + + // Then whenever you want to set the time and animate to it + ttv.setTime("00:00"); // As formatted String + // OR + ttv.setTime(new int[]{20:20}); + // OR + ttv.setTime(new Date()); + // OR + long timeAsMilliseconds = new Date().getTime(); + ttv.setTime(timeAsMilliseconds); + } + } +``` + +Install +-------- + +You can install using Gradle: + +```gradle + repositories { + maven { url "https://jitpack.io" } + } + dependencies { + compile 'com.github.iballan:TimelyView:1.0.0' + } +``` + +Contact me: +-------- + +Twitter: [@mbh01t](https://twitter.com/mbh01t) + +Github: [iballan](https://github.com/iballan) + +Website: [www.mbh01.com](http://mbh01.com) + +Credits: +-------- + +TimelyTextView : https://github.com/adnan-SM/TimelyTextView + +Sriram Ramani article : http://sriramramani.wordpress.com/2013/10/14/number-tweening/ + +License +-------- + + Copyright 2014 Mohamad Ballan. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. \ No newline at end of file diff --git a/Screenshots/TimelyTimeView_screenshot.gif b/Screenshots/TimelyTimeView_screenshot.gif new file mode 100644 index 0000000..eb35d1c Binary files /dev/null and b/Screenshots/TimelyTimeView_screenshot.gif differ diff --git a/Screenshots/TimelyView_Screenshot.gif b/Screenshots/TimelyView_Screenshot.gif new file mode 100644 index 0000000..28fe9d7 Binary files /dev/null and b/Screenshots/TimelyView_Screenshot.gif differ diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..820e90f --- /dev/null +++ b/build.gradle @@ -0,0 +1,16 @@ +buildscript { + repositories { +// mavenCentral() + jcenter() + } + dependencies { + classpath 'com.android.tools.build:gradle:2.2.0' + } +} + +allprojects { + repositories { +// mavenCentral() + jcenter() + } +} \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..13372ae Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..372c368 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Tue Sep 20 17:09:14 EEST 2016 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..91a7e26 --- /dev/null +++ b/gradlew @@ -0,0 +1,164 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# For Cygwin, ensure paths are in UNIX format before anything is touched. +if $cygwin ; then + [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` +fi + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >&- +APP_HOME="`pwd -P`" +cd "$SAVED" >&- + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..8a0b282 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/proguard-project.txt b/proguard-project.txt new file mode 100644 index 0000000..f2fe155 --- /dev/null +++ b/proguard-project.txt @@ -0,0 +1,20 @@ +# To enable ProGuard in your project, edit project.properties +# to define the proguard.config property as described in that file. +# +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in ${sdk.dir}/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the ProGuard +# include property in project.properties. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/sample/.gitignore b/sample/.gitignore new file mode 100644 index 0000000..34e5e5d --- /dev/null +++ b/sample/.gitignore @@ -0,0 +1,34 @@ +# built application files +*.apk +*.ap_ + +# files for the dex VM +*.dex + +# Java class files +*.class + +# generated files +bin/ +gen/ + +# Local configuration file (sdk path, etc) +local.properties +gradle.properties + +# Eclipse project files +.classpath +.project + +# Proguard folder generated by Eclipse +proguard/ + +# Intellij project files +*.iml +*.ipr +*.iws +.idea/ + +# OSX files +.DS_Store +.gradle \ No newline at end of file diff --git a/sample/build.gradle b/sample/build.gradle new file mode 100644 index 0000000..cf84f2d --- /dev/null +++ b/sample/build.gradle @@ -0,0 +1,29 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 24 + buildToolsVersion "24.0.2" + + defaultConfig { + minSdkVersion 9 + targetSdkVersion 24 + versionCode 1 + versionName "1.0.0" + } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_7 + targetCompatibility JavaVersion.VERSION_1_7 + } + + buildTypes { + release { + minifyEnabled false + } + } +} + +dependencies { + compile project(':timelyview') + compile 'com.android.support:appcompat-v7:24.2.1' +} diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml new file mode 100644 index 0000000..9805ad5 --- /dev/null +++ b/sample/src/main/AndroidManifest.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sample/src/main/java/com/mbh/timelyview/sample/MainActivity.java b/sample/src/main/java/com/mbh/timelyview/sample/MainActivity.java new file mode 100644 index 0000000..900b2cb --- /dev/null +++ b/sample/src/main/java/com/mbh/timelyview/sample/MainActivity.java @@ -0,0 +1,29 @@ +package com.mbh.timelyview.sample; + +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.view.Menu; +import android.view.View; + +public class MainActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + } + + public void btn_timelyTimeViewClicked(View v){ + TimelyTimeViewActivity.start(MainActivity.this); + } + public void btn_timelyViewClicked(View v){ + TimelyViewActivity.start(MainActivity.this); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + // Inflate the menu; this adds items to the action bar if it is present. + getMenuInflater().inflate(R.menu.main, menu); + return true; + } +} diff --git a/sample/src/main/java/com/mbh/timelyview/sample/TimelyTimeViewActivity.java b/sample/src/main/java/com/mbh/timelyview/sample/TimelyTimeViewActivity.java new file mode 100644 index 0000000..6694dcd --- /dev/null +++ b/sample/src/main/java/com/mbh/timelyview/sample/TimelyTimeViewActivity.java @@ -0,0 +1,89 @@ +package com.mbh.timelyview.sample; + +import android.content.Context; +import android.content.Intent; +import android.graphics.Color; +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; + +import com.mbh.timelyview.TimelyShortTimeView; +import com.mbh.timelyview.TimelyTimeView; + +import java.util.Date; +import java.util.Timer; +import java.util.TimerTask; + +public class TimelyTimeViewActivity extends AppCompatActivity { + + TimelyTimeView ttv; + TimelyShortTimeView tstv_hours, tstv_mins; + Timer timer; + + public static void start(Context context) { + Intent starter = new Intent(context, TimelyTimeViewActivity.class); + context.startActivity(starter); + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_timely_time_view); + + ttv = (TimelyTimeView) findViewById(R.id.ttv); + tstv_hours = (TimelyShortTimeView) findViewById(R.id.tstv_hours); + tstv_mins = (TimelyShortTimeView) findViewById(R.id.tstv_mins); + + // Full time 00:00:00 + ttv.setTextColor(Color.WHITE); + ttv.setSeperatorsTextSize(50); + ttv.setTime(new int[]{99, 99, 99}); + ttv.setTime(new int[]{0, 0, 0}); + + // Short time *HOURS:MINUTES* 00:00 + tstv_hours.setTextColor(Color.BLACK); + tstv_hours.setTimeFormat(TimelyShortTimeView.FORMAT_HOUR_MIN); + tstv_hours.setSeperatorsTextSize(50); + tstv_hours.setTime("99:99"); + tstv_hours.setTime("00:00"); + + // Short time *MINUTES:SECONDS* 00:00 + tstv_mins.setTextColor(Color.WHITE); + tstv_mins.setTimeFormat(TimelyShortTimeView.FORMAT_MIN_SEC); + tstv_mins.setSeperatorsTextSize(50); + tstv_mins.setStrokeWidth(20f); + tstv_mins.setTime("99:99"); + tstv_mins.setTime("00:00"); + } + + @Override + protected void onResume() { + super.onResume(); + timer = new Timer(); + timer.scheduleAtFixedRate(getTimerTask(), 1500, 1000); + } + + @Override + protected void onPause() { + super.onPause(); + timer.cancel(); + timer = null; + } + + private TimerTask getTimerTask() { + return new TimerTask() { + @Override + public void run() { + runOnUiThread(new Runnable() { + @Override + public void run() { + Date now = new Date(); + ttv.setTime(now); + + tstv_mins.setTime(now.getTime()); // You give as milliseconds + tstv_hours.setTime(now); + } + }); + } + }; + } +} diff --git a/sample/src/main/java/com/mbh/timelyview/sample/TimelyViewActivity.java b/sample/src/main/java/com/mbh/timelyview/sample/TimelyViewActivity.java new file mode 100644 index 0000000..af91e71 --- /dev/null +++ b/sample/src/main/java/com/mbh/timelyview/sample/TimelyViewActivity.java @@ -0,0 +1,122 @@ +package com.mbh.timelyview.sample; + +import android.content.Context; +import android.content.Intent; +import android.graphics.Color; +import android.os.Bundle; +import android.os.Handler; +import android.support.v7.app.AppCompatActivity; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.SeekBar; +import android.widget.Spinner; + +import com.mbh.timelyview.TimelyView; +import com.nineoldandroids.animation.ObjectAnimator; + +import java.util.Random; + +public class TimelyViewActivity extends AppCompatActivity { + public static final int DURATION = 1000; + public static final int NO_VALUE = -1; + private TimelyView timelyView = null; + private SeekBar seekBar = null; + private Spinner fromSpinner = null; + private Spinner toSpinner = null; + private volatile ObjectAnimator objectAnimator = null; + + private volatile int from = NO_VALUE; + private volatile int to = NO_VALUE; + Handler handler; + public int getRandomColor(){ + Random rnd = new Random(); + return Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)); + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_timely_view); + + timelyView = (TimelyView) findViewById(R.id.textView1); + seekBar = (SeekBar) findViewById(R.id.seekBar); + fromSpinner = (Spinner) findViewById(R.id.fromSpinner); + toSpinner = (Spinner) findViewById(R.id.toSpinner); + + handler = new Handler(); + + new Thread(new Runnable() { + @Override + public void run() { + for (int i = 0; i <10; i++) { + final int from = i; + final int to = i==9?0:i+1; + handler.postDelayed(new Runnable() { + @Override + public void run() { + timelyView.setTextColor(getRandomColor()); + timelyView.animate(from, to).start(); + } + }, 900); + try{Thread.sleep(1000);}catch (Exception e){} + } + } + }).start(); + + ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.from_numbers_array, android.R.layout.simple_spinner_item); + adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + fromSpinner.setAdapter(adapter); + toSpinner.setAdapter(adapter); + fromSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + from = position - 1; + if(from != NO_VALUE && to != NO_VALUE) { + objectAnimator = timelyView.animate(from, to); + objectAnimator.setDuration(DURATION); + } else { + objectAnimator = null; + } + } + + @Override + public void onNothingSelected(AdapterView parent) { + } + }); + toSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + to = position - 1; + if(from != NO_VALUE && to != NO_VALUE) { + objectAnimator = timelyView.animate(from, to); + objectAnimator.setDuration(DURATION); + } else { + objectAnimator = null; + } + } + + @Override + public void onNothingSelected(AdapterView parent) { + + } + }); + + seekBar.setMax(DURATION); + seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { + @Override + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + if(objectAnimator != null) objectAnimator.setCurrentPlayTime(progress); + } + @Override + public void onStartTrackingTouch(SeekBar seekBar) {} + @Override + public void onStopTrackingTouch(SeekBar seekBar) {} + }); + } + + public static void start(Context context) { + Intent starter = new Intent(context, TimelyViewActivity.class); + context.startActivity(starter); + } +} diff --git a/sample/src/main/res/drawable-hdpi/ic_launcher.png b/sample/src/main/res/drawable-hdpi/ic_launcher.png new file mode 100644 index 0000000..96a442e Binary files /dev/null and b/sample/src/main/res/drawable-hdpi/ic_launcher.png differ diff --git a/sample/src/main/res/drawable-mdpi/ic_launcher.png b/sample/src/main/res/drawable-mdpi/ic_launcher.png new file mode 100644 index 0000000..359047d Binary files /dev/null and b/sample/src/main/res/drawable-mdpi/ic_launcher.png differ diff --git a/sample/src/main/res/drawable-xhdpi/ic_launcher.png b/sample/src/main/res/drawable-xhdpi/ic_launcher.png new file mode 100644 index 0000000..71c6d76 Binary files /dev/null and b/sample/src/main/res/drawable-xhdpi/ic_launcher.png differ diff --git a/sample/src/main/res/layout/activity_main.xml b/sample/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..595aad9 --- /dev/null +++ b/sample/src/main/res/layout/activity_main.xml @@ -0,0 +1,34 @@ + + + +