Custom clock control for Android

Source: Internet
Author: User

Now this DEMO encapsulates it into a custom control and provides only three public interfaces:

1 public void switchClockState (_ ClockState state) // switch the clock status
2
3 public void saveTimeToSystem () // Save the dial time to system time
4
5 public void reviseTime () // The current recovery time is the system time
So it is relatively convenient to look at the code in the main Activity, is it very simple:
01 public class CustomClockDemoActivity extends Activity {
02/** Called when the activity is first created .*/
03 private CustomClock mCustomClock1;
04 private CustomClock mCustomClock2;
05 private CustomClock mCustomClock3;
06 private Button mBtnSetting;
07 private Button mBtnSave;
08 private Button mBtnNoSave;
09
10 public void onCreate (Bundle savedInstanceState ){
11 super. onCreate (savedInstanceState );
12 setContentView (R. layout. main );
13 init ();
14}
15
16 public void init (){
17 mCustomClock1 = (CustomClock) findViewById (R. id. clock1 );
18 mCustomClock1.switchClockState (CustomClock. _ ClockState. eQ_CLOCK_RUN );
19 mCustomClock2 = (CustomClock) findViewById (R. id. clock2 );
20 mCustomClock2.switchClockState (CustomClock. _ ClockState. eQ_CLOCK_RUN );
21 mCustomClock3 = (CustomClock) findViewById (R. id. clock3 );
22 mCustomClock3.switchClockState (CustomClock. _ ClockState. eQ_CLOCK_RUN );
23 mBtnSetting = (Button) findViewById (R. id. buttonSetting );
24 mBtnSetting. setOnClickListener (new OnClickListener (){
25
26 @ Override
27 public void onClick (View v ){
28 // TODO Auto-generated method stub
29 Setting ();
30}
31 });
32
33 mBtnSave = (Button) findViewById (R. id. buttonSave );
34 mBtnSave. setOnClickListener (new OnClickListener (){
35
36 @ Override
37 public void onClick (View v ){
38 // TODO Auto-generated method stub
39 Save ();
40}
41 });
42 mBtnNoSave = (Button) findViewById (R. id. buttonNoSave );
43 mBtnNoSave. setOnClickListener (new OnClickListener (){
44
45 @ Override
46 public void onClick (View v ){
47 // TODO Auto-generated method stub
48 noSave ();
49}
50 });
51 mCustomClock1.setVisibility (View. INVISIBLE );
52 mCustomClock2.setVisibility (View. GONE );
53 mCustomClock3.setVisibility (View. GONE );
54
55}
56
57 public void Setting (){
58
59 mCustomClock1.switchClockState (CustomClock. _ ClockState. eQ_CLOCK_SETTING );
60}
61
62 public void Save (){
63
64 mCustomClock1.saveTimeToSystem ();
65 mCustomClock1.switchClockState (CustomClock. _ ClockState. eQ_CLOCK_RUN );
66}
67
68 public void noSave (){
69 mCustomClock1.reviseTime ();
70 mCustomClock1.switchClockState (CustomClock. _ ClockState. eQ_CLOCK_RUN );
71}
72
73}

Android content:

  • How does android Add a view next to radiobutton?
  • How does Android obtain the MD5 certification key?
  • How does Android Add a new line to the email content?
  • Under which path can the default icon in android be found?
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.