Import Java. text. simpledateformat; import Java. util. date; import android. app. activity; import android. database. contentobserver; import android. OS. bundle; import android. OS. handler; import android. provider. settings; import android. util. log; import android. view. view; import android. view. view. onclicklistener; import android. widget. button; import android. widget. textview; public class mainactivity extends Activity {Private Static final string tag = "mainactivity"; Private Static final int on = 1; Private Static final int off = 0; private button mbtngetstatus; private button mbtnautotime; private button mbtnautotimelisten; private textview mtvinfo;/*** whether to enable time synchronization listener */private Boolean islistening = false;/** called when the activity is first created. * // @ override public void oncreate (bundle savedinstancesta Te) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); mtvinfo = (textview) findviewbyid (R. id. multiautocompletetextview1); mtvinfo. settext (""); mbtngetstatus = (button) findviewbyid (R. id. button1); mbtngetstatus. setonclicklistener (New onclicklistener () {@ override public void onclick (view v) {// todo auto-generated method stub int nautotimestatus = settings. system. getint (getcont Entresolver (), settings. system. auto_time, off); outprintlog ("current time sync status:" + nautotimestatus) ;}}; mbtnautotime = (button) findviewbyid (R. id. button2); mbtnautotime. setonclicklistener (New onclicklistener () {@ override public void onclick (view v) {// todo auto-generated method stub int nautotimestatus = settings. system. getint (getcontentresolver (), settings. system. auto_time, off); settings. system. pu Tint (getcontentresolver (), settings. system. auto_time, nautotimestatus = off? On: Off); refresh () ;}}); mbtnautotimelisten = (button) findviewbyid (R. id. button3); mbtnautotimelisten. setonclicklistener (New onclicklistener () {private contentobserver mautotimeobserver = new contentobserver (new handler () {@ override public void onchange (Boolean selfchange) {log. I (TAG, "auto time state changed"); int nautotimestatus = settings. system. getint (getcontentresolver (), settings. s Ystem. auto_time, off); outprintlog ("current time sync status:" + nautotimestatus) ;};@ override public void onclick (view V) {// todo auto-generated method stub if (! Islistening) {getapplication (). getcontentresolver (). registercontentobserver (settings. system. geturifor (settings. system. auto_time), true, mautotimeobserver);} else {getapplicationcontext (). getcontentresolver (). unregistercontentobserver (this. mautotimeobserver);} islistening =! Islistening; refresh () ;}}); refresh () ;}private void refresh () {int nautotimestatus = settings. system. getint (getcontentresolver (), settings. system. auto_time, off); mbtnautotime. settext (nautotimestatus = off? R. String. app_autotime_start: R. String. app_autotime_end); mbtnautotimelisten. settext (islistening? R. string. app_autotimelisten_end: R. string. app_autotimelisten_start);} private void outprintlog (charsequence text) {mtvinfo. settext (mtvinfo. gettext ()). tostring () + new simpledateformat ("\ n mm: SS "). format (new date () + text. tostring ());}