// Path: app/src/main/java/com/yan/mobilesafe/DataBase/AddressDB.java
// public class AddressDB {
//     private static final String PATH = "data/data/com.yan.mobilesafe/files/address.db";
// 
//     public static String getAddress(String number){
//         String address = "未知号码";
// 
//         //获取数据库对象
//         SQLiteDatabase database = SQLiteDatabase.openDatabase(PATH,null,SQLiteDatabase.OPEN_READONLY);
// 
//         //手机号正则表达式匹配
//         //1 + （3.4.5.6.7.8)+(9位数字)
//         //^1[3-8]\d{9}$
// 
//         if (number.matches("^1[3-8]\\d{9}$")){
//             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+$")){ //匹配数字
//             switch (number.length()){
//                 case 3:
//                     address = "报警电话";
//                     break;
//                 case 4:
//                     address = "模拟器电话";
//                     break;
//                 case 5:
//                     address = "客服电话";
//                     break;
//                 case 7:
//                 case 8:
//                     address = "本地电话";
//                     break;
//                 default:
//                     //03154011111
//                     //01055225525
//                     if (number.startsWith("0") && number.length()>10){  //可能是长途电话
//                         //先查询3位区号
//                         Cursor cursor = database.rawQuery("select location from data2 where area = ?",
//                                 new String[]{number.substring(1,3)});
//                         if (cursor.moveToNext()){
//                             address = cursor.getString(0);
//                             address = address.substring(0,address.length()-2);
//                         }else {
//                             cursor.close();
//                             //查询4位区号
//                             cursor = database.rawQuery("select location from data2 where area = ?",
//                                     new String[]{number.substring(1,4)});
//                             if (cursor.moveToNext()){
//                                 address = cursor.getString(0);
//                                 address = address.substring(0,address.length()-2);
//                             }
//                             cursor.close();
//                         }
//                     }
//                     break;
//             }
//         }
// 
//         database.close();
//         return address;
//     }
// }


import android.annotation.TargetApi;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.yan.mobilesafe.DataBase.AddressDB;
import com.yan.mobilesafe.R;
package com.yan.mobilesafe.activity.Atool;



/**
 * 号码归属地查询
 * Created by a7501 on 2015/11/30.
 */
public class AddressActivity extends AppCompatActivity {

    private EditText inputNumber;
    private Button select;
    private TextView result;

    @TargetApi(Build.VERSION_CODES.KITKAT)
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_address_layout);

        //透明状态栏
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        //透明导航栏
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);

        inputNumber = (EditText) findViewById(R.id.et_number_address);
        select = (Button) findViewById(R.id.btn_ok);
        result = (TextView) findViewById(R.id.tv_result);

        inputNumber.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
// Path: app/src/main/java/com/yan/mobilesafe/DataBase/AddressDB.java
// public class AddressDB {
//     private static final String PATH = "data/data/com.yan.mobilesafe/files/address.db";
// 
//     public static String getAddress(String number){
//         String address = "未知号码";
// 
//         //获取数据库对象
//         SQLiteDatabase database = SQLiteDatabase.openDatabase(PATH,null,SQLiteDatabase.OPEN_READONLY);
// 
//         //手机号正则表达式匹配
//         //1 + （3.4.5.6.7.8)+(9位数字)
//         //^1[3-8]\d{9}$
// 
//         if (number.matches("^1[3-8]\\d{9}$")){
//             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+$")){ //匹配数字
//             switch (number.length()){
//                 case 3:
//                     address = "报警电话";
//                     break;
//                 case 4:
//                     address = "模拟器电话";
//                     break;
//                 case 5:
//                     address = "客服电话";
//                     break;
//                 case 7:
//                 case 8:
//                     address = "本地电话";
//                     break;
//                 default:
//                     //03154011111
//                     //01055225525
//                     if (number.startsWith("0") && number.length()>10){  //可能是长途电话
//                         //先查询3位区号
//                         Cursor cursor = database.rawQuery("select location from data2 where area = ?",
//                                 new String[]{number.substring(1,3)});
//                         if (cursor.moveToNext()){
//                             address = cursor.getString(0);
//                             address = address.substring(0,address.length()-2);
//                         }else {
//                             cursor.close();
//                             //查询4位区号
//                             cursor = database.rawQuery("select location from data2 where area = ?",
//                                     new String[]{number.substring(1,4)});
//                             if (cursor.moveToNext()){
//                                 address = cursor.getString(0);
//                                 address = address.substring(0,address.length()-2);
//                             }
//                             cursor.close();
//                         }
//                     }
//                     break;
//             }
//         }
// 
//         database.close();
//         return address;
//     }
// }


// Path: app/src/main/java/com/yan/mobilesafe/activity/Atool/AddressActivity.java
import android.annotation.TargetApi;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.yan.mobilesafe.DataBase.AddressDB;
import com.yan.mobilesafe.R;

package com.yan.mobilesafe.activity.Atool;



/**
 * 号码归属地查询
 * Created by a7501 on 2015/11/30.
 */
public class AddressActivity extends AppCompatActivity {

    private EditText inputNumber;
    private Button select;
    private TextView result;

    @TargetApi(Build.VERSION_CODES.KITKAT)
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_address_layout);

        //透明状态栏
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        //透明导航栏
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);

        inputNumber = (EditText) findViewById(R.id.et_number_address);
        select = (Button) findViewById(R.id.btn_ok);
        result = (TextView) findViewById(R.id.tv_result);

        inputNumber.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                result.setText(AddressDB.getAddress(s.toString()));