Resources in the sharp shape, switching pages with gestures, listening to boot broadcasts, and sharp gestures
Anti-theft homepage Construction
Page Effect
Custom background image (sharp shape Resource) We can customize the shape and color of the control through the shape resource. In the layout file, the control is actually TextView plus our custom background style.
Procedure:
First, create the gradient_box.xml file in the drawable Directory, which is the shape file.
Create a selector
Finally, use selector in the background attribute of texview,
Ps: textview can be switched only when click event listening is implemented
Use gestures to switch pages
Graphic Analysis
Steps:
First, the activity must be overwritten.OnTouchEvent (MotionEvent event)
Then use the GestureDetector'sOnTouchEvent Analysis and Monitoring touch events
The GestureDetector object must be overwritten.OnFling (MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) Method
Extract BaseSetupActivity
Select repeated gesture pages and click button pages on each page
Code
Public abstract class BaseSetupActivity extends Activity {private GestureDetector gestureDetector; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); // 2. Create an object for gesture management and use it to manage the gestureDetector = new GestureDetector (this, new GestureDetector) gesture action passed in onTouchEvent. simpleOnGestureListener () {@ Override public boolean onFling (MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {// if (e1.getX ()-e2.getX ()> 0) {// call the next page method of the subclass, abstract method // when the first interface is located, jump to the second interface. // when the second interface is located, jump to the third interface //....... showNextPage ();} if (e1.getX ()-e2.getX () <0) {// call the previous page method of the subclass // no response is returned on the first interface, empty implement // when the second interface is displayed, jump to the 1st interface //....... showPrePage ();} return super. onFling (e1, e2, velocityX, velocityY) ;}});} // 1. Listen to the event type on the screen (Press (once), move (multiple times ), lift (once) @ Override public boolean onTouchEvent (MotionEvent event) {// 3, receives multiple types of events through the gesture processing class, and is used to process gestureDetector. onTouchEvent (event); return super. onTouchEvent (event);} // specifies the abstract method of the next page. The subclass determines the specific method to jump to the protected abstract void showNextPage (); // specifies the abstract method of the previous page, the subclass determines the specific page to jump to. protected abstract void showPrePage (); // when you click the next page, jump to public void nextPage (View view) according to the showNextPage method of the subclass) {showNextPage () ;}// when you click the previous page, jump to public void prePage (View view) {showPrePage () ;}} Based on the showPrePage method of the subclass ();}}
Listen to boot Broadcast
Listen to the boot broadcast, determine whether the bound SIM card is changed, and send a text message to the bound Security mobile phone number
Permission
Register the boot broadcast Receiver
Start broadcast receiver code
Public class BootReceiver extends BroadcastReceiver {private static final String tag = "BootReceiver"; @ Override public void onReceive (Context context, Intent intent) {Log. I (tag, "the phone is restarted successfully, and the corresponding broadcast is listened ...... "); // 1. Obtain the serial number of the SIM card of the mobile phone after startup. TelephonyManager tm = (TelephonyManager) context. getSystemService (Context. TELEPHONY_SERVICE); String simSerialNumber = tm. getSimSerialNumber () + "xxx"; // 2. Serial card number Stri stored in sp Ng sim_number = SpUtil. getString (context, ConstantValue. SIM_NUMBER, ""); // 3, inconsistent if (! SimSerialNumber. equals (sim_number) {// 4. send a text message to the selected contact number SmsManager sms = SmsManager. getDefault (); sms. sendTextMessage ("5556", null, "sim change !!! ", Null, null );}}}