On the back of the main set of Interface Design Wizard interface, mainly related to the layout of the interface and the use of some controls. This time to do the Setup Wizard interface features specific implementation.
First of all, 4 interfaces are (very large repetition, this is no longer posted in the text)
/mobilesafe/res/layout/setup_wizard1.xml
/mobilesafe/res/layout/setup_wizard2.xml
/mobilesafe/res/layout/setup_wizard3.xml
/mobilesafe/res/layout/setup_wizard4.xml
Toggle animation effect between activity
- public void overridependingtransition(int enteranim, int exitanim)
Two parameters:
- Enteranim: Animated effect of entering new activity
- Exitanim: Exiting the current Activity animation effect
To create an animation effect:
- /mobilesafe/res/anim/alpha_in.xml
<?xml version= "1.0" encoding= "Utf-8"? ><alpha xmlns:android= "Http://schemas.android.com/apk/res/android" android:duration= "android:fromalpha=" 0.0 " android:toalpha=" 1.0 "></alpha>
- /mobilesafe/res/anim/alpha_out.xml
To add a click event for the Next button:
- /mobilesafe/src/com/liuhao/mobilesafe/ui/setupwizard1activity.java
Package Com.liuhao.mobilesafe.ui;import Com.liuhao.mobilesafe.r;import Android.app.activity;import Android.content.intent;import Android.os.bundle;import Android.view.view;import Android.view.View.OnClickListener Import Android.widget.button;public class Setupwizard1activity extends Activity implements Onclicklistener {private B Utton button; @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.LAYOUT.SETUP_WIZARD1); Button = (button) This.findviewbyid (R.id.bt_next); Button.setonclicklistener (this); } @Override public void OnClick (View v) {switch (V.getid ()) {r.id.bt_next:finish (); Users will not see this interface when they click "Back" Intent Intent = new Intent (this, setupwizard2activity.class); StartActivity (Intent); Sets the animation effect Overridependingtransition (r.anim.alpha_in, R.anim.alpha_out) when the activity is toggled; Break } }}
Set Interface Wizard Face 2
Requirement function: 1. Bind SIM card 2. Processing of the CheckBox State 3. Previous step, next click on the implementation of the function
When the user clicks on "Bind SIM card", the corresponding processing logic is triggered, the serial number of the current SIM card is obtained, and the serial number is accessed into the sharepreference.
To get the SIM card serial number of your phone, you need to add permissions:Android.permission.READ_PHONE_STATE
/** * Bind sim serial number * */private void Setsiminfo () { Telephonymanager manager = (Telephonymanager) getsystemservice ( Telephony_service); String Simserialnumber = Manager.getsimserialnumber (); Editor edit = Sp.edit (); Edit.putstring ("Sim", simserialnumber); Edit.commit (); Toast.maketext (Getapplicationcontext (), "SIM card is bound", Toast.length_short). Show ();
- Processing of checkbox status
First initialize the status of Chexkbox string sim = Sp.getstring ("sim", NULL), if (sim! = null) { cb_bind.settext ("bundled sim"); Cb_bind.setchecked (TRUE);} else{ cb_bind.settext ("unbound sim card"); Cb_bind.setchecked (false);} Cb_bind.setoncheckedchangelistener (New Oncheckedchangelistener () { @Override public void OnCheckedChanged ( Compoundbutton Buttonview, boolean isChecked) { if (isChecked) { setsiminfo (); Cb_bind.settext ("bundled SIM card"); } else{ cb_bind.settext ("unbound sim card");} } );
Exception handling
Fix it, run the code, bind the phone SIM card serial number, no problem.
Open again, go to Wizard 2 interface, error, program crashes.
Error log (main part extracted)E/androidruntime (26463): java.lang.RuntimeException:Unable to start activity componentinfo{com.liuhao.mobilesafe/ Com.liuhao.mobilesafe.ui.SetupWizard2Activity}: Java.lang.ClassCastException:java.lang.String cannot is cast to Java.lang.Boolean
...
E/androidruntime (26463): at Com.liuhao.mobilesafe.ui.SetupWizard2Activity.onCreate (setupwizard2activity.java:42) Reason:
Since the existence of SIM information before judging Sharepreference is based on the following logic:
First initialize the Chexkbox state if (Sp.getboolean ("Sim", False)) { Cb_bind.settext ("bundled sim"); Cb_bind.setchecked (TRUE);} else{ cb_bind.settext ("unbound sim card"); Cb_bind.setchecked (false);}
And the boolean Android.content.SharedPreferences.getBoolean (String key, Boolean Defvalue) method,
Retrieve A Boolean value from the preferences.
Parameters:key the name of the preference to retrieve. Defvalue Value to return if this preference does not exist. Returns:returns the preference value if it exists, or defvalue. Throws ClassCastException If there is a preference with the this name, which is not a Boolean. Throws:classcastexception
It can be found that if a value already exists, and this value is not a Boolean type, ClassCastException will be thrown.
Modify
First initialize the status of Chexkbox string sim = Sp.getstring ("sim", NULL), if (sim! = null) { cb_bind.settext ("bundled sim"); Cb_bind.setchecked (TRUE);} else{ cb_bind.settext ("unbound sim card"); Cb_bind.setchecked (false);}
Run effect
Full code:
- /mobilesafe/src/com/liuhao/mobilesafe/ui/setupwizard2activity.java
"Side do Project learning Android" Mobile security defender 10-set the wizard's binding SIM card