/*
* Copyright (C) 2010 lytsing.org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.lytsing.myphonenumber;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.telephony.TelephonyManager;
import android.telephony.PhoneNumberUtils;
import android.text.TextUtils;
import android.util.Log;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.PhoneFactory;
/**
* Display and Setting My Phone Number
*/
public class MyPhoneNumber extends PreferenceActivity implements OnSharedPreferenceChangeListener {
private static final String LOG_TAG = "MyPhoneNumber";
private static final String KEY_PHONE_NUMBER_STATUS_PREFERENCE = "my_phone_number_status";
private static final String KEY_TEXTEDIT_PREFERENCE = "edittext_preference";
private Preference mPhoneNumberStatus;
private TelephonyManager mTelephonyManager;
private Phone mPhone = null;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
addPreferencesFromResource(R.xml.my_phone_number);
mPhoneNumberStatus = findPreference(KEY_PHONE_NUMBER_STATUS_PREFERENCE);
mTelephonyManager = (TelephonyManager)this
.getSystemService(Context.TELEPHONY_SERVICE);
mPhone = PhoneFactory.getDefaultPhone();
String rawNumber = mTelephonyManager.getLine1Number();
String formattedNumber = null;
if (!TextUtils.isEmpty(rawNumber)) {
formattedNumber = PhoneNumberUtils.formatNumber(rawNumber);
} else {
formattedNumber = getResources().getString(R.string.unknown);
}
mPhoneNumberStatus.setSummary(formattedNumber);
Log.d(LOG_TAG, " sim state: " + mTelephonyManager.getSimState());
// Check SIM status
if (mTelephonyManager.getSimState() != TelephonyManager.SIM_STATE_READY) {
showNoSimAlertDialog();
}
}
@Override
protected void onResume() {
super.onResume();
// Set up a listener whenever a key changes
getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
}
@Override
protected void onPause() {
super.onPause();
// Unregister the listener whenever a key changes
getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(
this);
}
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (key.equals(KEY_TEXTEDIT_PREFERENCE)) {
String alphaTag = mPhone.getLine1AlphaTag();
if (alphaTag == null || "".equals(alphaTag)) {
// No tag, set it.
alphaTag = "Voice Line 1";
}
String number = sharedPreferences.getString(key, "");
if (number.trim().length() > 0) {
mPhoneNumberStatus.setSummary(number);
mPhone.setLine1Number(alphaTag, number, null);
}
}
}
private void showNoSimAlertDialog() {
Dialog dialog = new AlertDialog.Builder(this)
.setIcon(android.R.drawable.ic_dialog_alert)
.setTitle(R.string.no_sim_error_message)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
finish();
}
})
.create();
dialog.show();
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
MyPhoneNumber-master.zip (36个子文件)
MyPhoneNumber-master
.project 816B
src
org
lytsing
myphonenumber
MyPhoneNumberWidget.java 3KB
MyPhoneNumber.java 4KB
AndroidManifest.xml 1KB
res
values-sv
strings.xml 742B
values-ko
strings.xml 682B
values-el
strings.xml 842B
values-es-rUS
strings.xml 770B
drawable-ldpi
icon.png 5KB
values-it
strings.xml 726B
values-zh-rCN
strings.xml 600B
values-zh-rTW
strings.xml 597B
xml
my_phone_number.xml 750B
number_widget_provider.xml 264B
drawable-hdpi
icon.png 8KB
values-ja
strings.xml 687B
drawable
widget_bg_normal.9.png 1KB
drawable-mdpi
icon.png 3KB
values-tr
strings.xml 683B
layout
main.xml 673B
values-pt
strings.xml 720B
values-ru
strings.xml 832B
values-cs
strings.xml 712B
values-pt-rPT
strings.xml 747B
values-es
strings.xml 715B
values-da
strings.xml 683B
values-de
strings.xml 691B
values
strings.xml 735B
values-nl
strings.xml 682B
values-nb
strings.xml 670B
values-fr
strings.xml 726B
values-pl
strings.xml 688B
Android.mk 197B
default.properties 449B
.classpath 289B
README 112B
共 36 条
- 1
jacklce
- 粉丝: 17
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页