A Timer, that has a single hand and tick as below
-
Include
AnalogTimerView
in your layout file.<com.elyeproj.analogtimerlibrary.AnalogTimerView android:id="@+id/myTimer" android:layout_width="match_parent" android:layout_height="wrap_content"/>
-
Instantiate the
AnalogTimerView
in your Activity/Fragment.AnalogTimerView analogTimerView = (AnalogTimerView)findViewById(R.id.myTimer);
-
Start the Timer by
analogTimerView.startTimer();
-
Stop the Timer by
analogTimerView.stopTimer();
-
Reset the Timer by
analogTimerView.resetTimer();
-
You could also set the additional attribute through xml. The below example of what could be set
<com.elyeproj.analogtimerlibrary.AnalogTimerView android:id="@+id/myTimer" android:layout_width="match_parent" android:layout_height="wrap_content" app:one_cycle_ticks="60" app:period_second="1" app:max_time="60"/>
- The
one_cycle_ticks
is to indicate how many ticks is in a cycle. The default is 60. - The
period_second
is to indicate how many second does one tick takes. Default is 1 second. You could use fraction e.t. 0.5. Value shouldn't be lower than 0.1 though to avoid too much tick that force image refresh within a second. - The
max_time
is to indicate a the time will auto stop upon reaching this number of tick. This value should be equal or less thanone period second
- The
-
Setting Time Out Listener. This is useful whenever a timeout happens (i.e. when
max_time
has been achieved), the callback function will be triggered. To do this, you could set the TimeOutListener e.ganalogTimerView.setTimeOutListener(new AnalogTimerView.TimeOutListener() { @Override public void onTimeOut() { Toast.makeText(getBaseContext(), "Time Out!", Toast.LENGTH_SHORT).show(); } });
-
For the case of restoring the current state (in the event of Configuration (Orientation) Change or Don't Keep Activity), the library provides 3 APIs below for it.
int getTime()
- Get the current ticking time. Useful for saveInstanceState.void setTime(int time)
- Set the starting ticking time. Useful when restoreInstanceState.boolean isRunning()
- Check if it is current running. Use when saveInstanceState, so that when restore instance state, we could decide to start timer automatically or not.
Android SDK API Version 16 and above.
On your module build.gradle
, add
dependencies {
compile 'com.elyeproj.libraries:analogtimerlibrary:1.0.0'
}
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with the License. You may obtain a copy of the License in the LICENSE file, or 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.