Mobile Security Guard-advanced tools-remote telephone query and security guard local query

Source: Internet
Author: User

Mobile Security Guard-advanced tools-remote telephone query and security guard local query

AToolsActivity. java

// Advanced tool public class AtoolsActivity extends Activity {@ Override protected void onCreate (Bundle savedInstanceState) {// TODO Auto-generated method stub super. onCreate (savedInstanceState); setContentView (R. layout.Activity_atools);} // Phone number query... we useDatabase QueryPublic void numberAddressQuery (View view) {startActivity (new Intent (this,AddressActivity. Class ));}}
AddressActivity.java
// Public classAddressActivityExtends Activity {private EditText etNumber; private TextView tvResult; @ Override protected void onCreate (Bundle savedInstanceState) {// TODO Auto-generated method stub super. onCreate (savedInstanceState); setContentView (R. layout.Activity_address); EtNumber = (EditText) findViewById (R. id. et_number); tvResult = (TextView) findViewById (R. id. TV _result); // listens for the change of edittext, and monitors the change of etNumber in TexiView in real time.AddTextChangedListener(New TextWatcher () {@ Override public void onTextChanged (CharSequence s, int start, int before, int count) {// TODO Auto-generated method stub // callback String address = AddressDao when the text changes. getAddress (s. toString (); tvResult. setText (address) ;}@ Override public void beforeTextChanged (CharSequence s, int start, int count, int after) {}@ Override public void afterTextChanged (Editable s) {}}) ;}// start the query,QueryButton click event public void query (View view) {String number = etNumber. getText (). toString (). trim (); if (! TextUtils. isEmpty (number) {String address = AddressDao. getAddress (number); tvResult. setText (address);} When else {// The Window jitters when no input is made, this is an Animation shake =AnimationUtils. LoadAnimation (this, R. anim. shake); etNumber. startAnimation (shake); vibrate () ;}// shake the phone. You must have the permission to private void vibrate () {Vibrator v = (Vibrator)GetSystemService (VIBRATOR_SERVICE); // System ServiceV. vibrate (2000); // v. vibrate (new long [] {,},-1); // wait for 1 s, shake 2 S, wait 1 S, shake 3 s. -1 indicates that the task is executed only once without repeating. Rhythmic vibration // v. cancel (); // cancel the vibration }}

Shake. xml

<? Xml version = "1.0" encoding = "UTF-8"?> <Translate xmlns: android = "http://schemas.android.com/apk/res/android" android: duration = "1000" android: fromXDelta = "0" android:Interpolator= "@ Anim/Cycle_7"Android: toXDelta =" 10 "/> <! -- Interpolator 7 cycles, that is, 1 s jitters 7 times -->
cycle_7.xml
<?xml version="1.0" encoding="utf-8"?><cycleInterpolator xmlns:android="http://schemas.android.com/apk/res/android" android:cycles="7" />

AddressDao. java

/***** */Public class AddressDao {private static final String PATH = "data/com. mxn. mobilesafe/files/address. db "; // note that the path must be a file in the data/data Directory; otherwise, the database will not be able to access it. // return the place name public static String getAddress (String number) {String address = "Unknown number"; // obtain the database object //Read only from the default location, but not assert. Therefore, you need to copy the database to the data/data directory. Copy the database on the SplashActivity page. SQLiteDatabaseDatabase = SQLiteDatabase. openDatabase (PATH, null, SQLiteDatabase. OPEN_READONLY); // mobile phone number features: 1 + (3, 4, 5, 6, 7, 8) + (9 digits) // Regular Expression // ^ 1 [3-8] \ d {9} $ if (number. matches ("^ 1 [3-8] \ d {9} $") {// match the mobile phone number Cursor cursor = database. rawQuery ("Select location from data2 where id = (select outkey from data1 where id =?) ", New String [] {number. substring (0, 7)}); if (cursor. moveToNext () {address = cursor. getString (0);} cursor. close ();} else if (number. matches ("^ \ d + $") {// match the number switch (number. length () {case 3: address = "alarm phone"; break; case 4: address = "Simulator"; break; case 5: address = "customer service phone"; break; case 7: case 8: address = "local phone"; break; default: // 01088881234 // 048388888888 if (number. startsWith ("0 ") & Amp; number. length ()> 10) {// It may be a long-distance call. // some area numbers are 4 and some area numbers are 3 (including 0) // first query the four-digit area code Cursor cursor = database. rawQuery ("select location from data2 where area =? ", New String [] {number. substring (1, 4)}); if (cursor. moveToNext () {address = cursor. getString (0);} else {cursor. close (); // query the three-digit region code cursor = database. rawQuery ("select location from data2 where area =? ", New String [] {number. substring (1, 3)}); if (cursor. moveToNext () {address = cursor. getString (0);} cursor. close () ;}} break ;}} database. close (); // close the database return address ;}}

 



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.