24 The completion of mobile phone anti-theft

Source: Internet
Author: User

We need in lostfindactivity this class, show the Third Setup Wizard page passed the security number, the fourth page if checked, then the anti-theft protection is turned on the picture replaced, the final result such as.




First look at the Last Setup Wizard page:


Package Com.ustc.mobilemanager;import Android.content.intent;import Android.content.sharedpreferences;import Android.content.sharedpreferences.editor;import Android.os.bundle;import Android.view.view;import Android.view.window;import Android.widget.checkbox;import Android.widget.compoundbutton;import Android.widget.compoundbutton.oncheckedchangelistener;public class Setup4activity extends Basesetupactivity { Private sharedpreferences sp;private CheckBox cb_protecting; @Overrideprotected void OnCreate (Bundle Savedinstancestate) {super.oncreate (savedinstancestate); Requestwindowfeature (Window.feature_no_title); Setcontentview (R.LAYOUT.ACTIVITY_SETUP4), SP = getsharedpreferences ("config", mode_private); cb_protecting = ( CheckBox) Findviewbyid (r.id.cb_protecting); Boolean protecting = Sp.getboolean ("Protecting", false); if (protecting) {/ /Mobile phone anti-theft has been turned on Cb_protecting.settext ("mobile phone anti-theft has been turned on"); cb_protecting.setchecked (true);} else {//Mobile phone anti-theft does not turn on Cb_protecting.settext ("mobile phone anti-theft not turned on"); cb_protecting.setchecked (false);} Cb_pRotecting.setoncheckedchangelistener (New Oncheckedchangelistener () {@Overridepublic void oncheckedchanged ( Compoundbutton Buttonview, Boolean isChecked) {if (isChecked) {Cb_protecting.settext ("mobile phone theft is turned on");} else {cb_protecting.settext ("mobile phone anti-theft is not turned on");} Save the selected state Editor editor = Sp.edit (); Editor.putboolean ("Protecting", isChecked); Editor.commit ();});} @Overridepublic void Showback () {Intent Intent = new Intent (this, setup3activity.class); startactivity (Intent); Finish () ;//require finish () or startactivity (intent) aspect to perform overridependingtransition (r.anim.tran_pre_in, r.anim.tran_pre_out);} public void ok (view view) {Editor edit = Sp.edit (); Edit.putboolean ("configed", true); Edit.commit (); Intent Intent = new Int ENT (this, lostfindactivity.class); startactivity (intent); finish ()//Request finish () or startactivity (intent) Aspect behind the execution of Overridependingtransition (r.anim.tran_in, r.anim.tran_out);} @Overridepublic void Shownext () {}}

Sets the font for the response based on the status of the checkbox.

Package Com.ustc.mobilemanager;import Android.app.activity;import Android.content.intent;import Android.content.sharedpreferences;import Android.os.bundle;import Android.view.view;import Android.view.Window; Import Android.widget.imageview;import Android.widget.textview;public class Lostfindactivity extends Activity { Private sharedpreferences sp;private ImageView iv_protecting;private TextView tv_safenumber; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Requestwindowfeature (Window.feature_no_ SP = getsharedpreferences ("config", mode_private);//Determine if you have done the Setup Wizard, if not done, jump to the Settings Wizard page to set, or stay on the current page Boolean configed = Sp.getboolean ("configed", false); if (configed) {//on the phone anti-theft page Setcontentview (r.layout.activity_lost_find); TV _safenumber = (TextView) Findviewbyid (r.id.tv_safenumber); iv_protecting = (ImageView) Findviewbyid (r.id.iv_ protecting);//Set security Number string safenumber = sp.getstring ("Safenumber", "" "), if (safenumber! = null) {Tv_safenumber.settext (Safenumber);} Set the status of the anti-theft protection Boolean protecting = Sp.getboolean ("Protecting", false), if (protecting) {Iv_protecting.setimageresource ( r.drawable.strongbox_app_lock_ic_locked);} else {iv_protecting.setimageresource (r.drawable.strongbox_app_lock_ic_unlock);}} else {//has not done setup wizard Intent intent = new Intent (Lostfindactivity.this,setup1activity.class); startactivity (intent); Finish ()//require finish () or startactivity (intent) aspect to execute overridependingtransition (r.anim.tran_in, r.anim.tran_out);}} public void back (view view) {Intent Intent = new Intent (lostfindactivity.this, Homeactivity.class); StartActivity (Intent Finish ()//require finish () or startactivity (intent) to perform overridependingtransition (r.anim.tran_pre_in, R.anim.tran_ Pre_out);} /** * Re-enter the anti-Theft Settings page (TextView click event) * * @param view */public void Reentersetup (view view) {Intent Intent = new Intent (lostfin Dactivity.this, Setup1activity.class); startactivity (intent); finish ()//Request finish () or startactivity (intent) Aspect behind the execution of Overridependingtransition (r.anim.tran_in, R.anim.tran_out);}} 

Get the Security Number and Setup Wizard page 4 status. The main operation is sharedpreferences.


An error:

Null pointer exception, Lostfindactivity class, forget Finfviewbyid to set the value of TextView, Careless!!!





24 The completion of mobile phone anti-theft

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.