Android - 在线浏览源码,电话短信相关,文本变化监听器

unregisterReceiver(receiver);

receiver = null;

5.导入已存在的数据库

//assert资产目录里面的文件会原封不动的打包到apk里,不生成id

/**

  • 拷贝归属地的数据库

*/

private void copyAddressDB() {

File file = new File(getFilesDir(), “address.db”);

//判断数据库文件是否存在

if (file.exists() && file.length() > 0) {

Log.i(TAG, “数据库存在,无需拷贝”);

} else {

new Thread() {

p

《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》

【docs.qq.com/doc/DSkNLaERkbnFoS0ZF】 完整内容开源分享

ublic void run() {

// 把asset资产目录里面的数据库文件(在apk里面的)拷贝到手机系统里面

try {

InputStream is = getAssets().open(“address.db”);

File file = new File(getFilesDir(), “address.db”);

FileOutputStream fos = new FileOutputStream(file);

byte[] buffer = new byte[1024];

int len = -1;

while ((len = is.read(buffer)) != -1) {

fos.write(buffer, 0, len);

}

fos.close();

is.close();

} catch (Exception e) {

e.printStackTrace();

}

};

}.start();

}

}

6.查询号码归属地

/**

  • 查询手机号码的归属地信息

  • @param mobilenumber

  • @return

*/

public static String findLocation(String mobilenumber) {

String path = “/data/data/com.mythmayor.project/files/address.db”;

//打开已存在的数据库

SQLiteDatabase db = SQLiteDatabase.openDatabase(path, null,

SQLiteDatabase.OPEN_READONLY);

Cursor cursor = db.rawQuery(

“select location from data2 where id = (select outkey from data1 where id = ?)”,

new String[]{mobilenumber.substring(0, 7)});

String location ="";

if(cursor.moveToNext()){

location = cursor.getString(0);

}

cursor.close();

db.close();

return location;

}

7.判断一个号码是否是手机号码

// ^1[34578]\d{9}$

// ^ 匹配输入字符串的开始位置。

// [] 字符集合。匹配所包含的任意一个字符。

// \d 匹配一个数字字符。

// {} n 是一个非负整数。匹配确定的 n 次。

// $ 匹配输入字符串的结束位置。

boolean result = number.matches("^1[34578]\d{9}$");

8.给EditText添加文本变化监听器

// 给文本输入框注册一个内容变化的监听器.

et_number.addTextChangedListener(new TextWatcher() {

//当文本变化之前调用的方法,s为改变前字符串,可获取被替换内容

//在s中从start开始的count个字符即将被after个字符替换

@Override

public void beforeTextChanged(CharSequence s, int start, int count,

int after) {

}

//当文本变化之后调用的方法,s为改变后字符串,可获取替换内容

//在s中从start开始的before个字符刚刚被count个字符替换

@Override

public void onTextChanged(CharSequence s, int start, int before,

int count) {

if (s.length() >= 10) {

String location = AddressDBDao.findLocation(s.toString());

tv_location.setText(“归属地为:” + location);

}

}

//当文本变化之后调用的方法,s为改变后字符串,操作s可直接改变EditText内容,EditText内容改变会继续调用beforeTextChanged和onTextChanged方法

//s中有内容被改变

@Override

public void afterTextChanged(Editable s) {

}

});

每次输入都会调用3个方法,调用顺序为beforeTextChanged–>onTextChanged–>afterTextChanged

9.CharSequence、String、Editable

1.CharSequence:接口,只有length()、charAt(int index)、subSequence(int start, int end)、toString()四个方法

2.String:实现了CharSequence接口,具有很多操作字符串的方法,不可修改

3.Editable:实现了CharSequence接口,具有增删改等修改的方法,可修改

10.动画插值器Interpolator

1.interpolator定义一个动画的变化率(the rate of change)。这使得基本的动画效果(alpha, scale, translate, rotate)得以加速,减速,重复等。

2.常用Interpolator

LinearInterpolator 以常量速率改变

AccelerateInterpolator 加速

DecelerateInterpolator 减速

AccelerateDecelerateInterpolator 先加速后减速

AnticipateInterpolator

OvershootInterpolator

AnticipateOvershootInterpolator

BounceInterpolator 弹跳

CycleInterpolator 循环播放特定的次数,速率改变沿着正弦曲线

11.监听外拨电话

1.添加权限

2.注册广播接收者

receiver = new OutCallReceiver();

IntentFilter filter = new IntentFilter();

filter.addAction(Intent.ACTION_NEW_OUTGOING_CALL);

registerReceiver(receiver, filter);

private class OutCallReceiver extends BroadcastReceiver{

@Override

public void onReceive(Context context, Intent intent) {

String number = getResultData();

String address = AddressDBDao.findLocation(number);

Toast.makeText(ShowAddressService.this, address, 1).show();

}

}

3.释放资源

@Override

public void onDestroy() {

unregisterReceiver(receiver);

receiver = null;

super.onDestroy();

}

12.通过WindowManager添加自定义View到窗体

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值