編輯:關於Android編程
從圖片中我們可以看到,這裡在語義上有一定的重復,當然這是谷歌的原始設計。這個問題在博客上進行共享從表面上來看著實沒有什麼太大的意義,不過由於Android4.3在鎖屏功能上比起老版本做了很大的改動,而且通過常規方法(Strings.xml中字符串)對該問題的定位會有很大的難度,拿這個界面來說,EMERGENCY CALL並不是Strings中值,而是
在Android4.3當中當前的鎖屏界面不是一個Activity而是一個View,該View位於/frameworks/base/policy/src/com/android/internal/policy/impl/keyguard目錄下的KeyguardPatternView.java,其所對應的布局文件為keyguard_pattern_view.xml.
android:id="@+id/keyguard_pattern_view"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_maxWidth="@dimen/keyguard_security_width"
android:layout_maxHeight="@dimen/keyguard_security_height"
android:gravity="center_horizontal"
android:contentDescription="@string/keyguard_accessibility_pattern_unlock">
<frameLayout
android:layout_height="match_parent">
android:layout_width="wrap_content"
android:orientation="vertical"
android:layout_gravity="center">
android:layout_height="wrap_content"
/>
<frameLayout
android:background="@*android:drawable/kg_bouncer_bg_white"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
>
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginEnd="8dip"
android:layout_marginBottom="4dip"
android:layout_marginStart="8dip"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:contentDescription="@string/keyguard_accessibility_pattern_area" />
</frameLayout>
android:id="@+id/keyguard_selector_fade_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="bottom|center_horizontal"
android:gravity="center_horizontal" />
</frameLayout>
而keyguard_eca即使我們需要修改的鎖屏界面下的緊急撥號按鈕所對應的布局Alias.xml中的keyguard_emergency_carrier_area.xml布局。
Alias.xml:
keyguard_emergency_carrier_area.xml
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:layout_gravity="center_horizontal"
android:layout_alignParentBottom="true"
android:clickable="true">
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout="@layout/msim_keyguard_carrier_area" />
android:id="@+id/carrier_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="@dimen/kg_status_line_font_size"
android:textColor="?android:attr/textColorSecondary"/>
android:layout_height="wrap_content"
android:layout_marginTop="-10dip"
android:orientation="horizontal"
android:gravity="center"
android:weightSum="2">
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableLeft="@*android:drawable/lockscreen_emergency_button"
android:text="@string/kg_emergency_call_label"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="@dimen/kg_status_line_font_size"
android:textColor="?android:attr/textColorSecondary"
android:drawablePadding="8dip" />
上述代碼中的CarrierText即是我們需要著的控件,它繼承自TextView。
package com.android.internal.policy.impl.keyguard;
import android.content.Context;
import android.os.SystemProperties;
import android.provider.Settings;
import android.provider.Settings.SettingNotFoundException;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.TextView;
import com.android.internal.R;
import com.android.internal.telephony.IccCardConstants;
import com.android.internal.telephony.IccCardConstants.State;
import com.android.internal.widget.LockPatternUtils;
public class CarrierText extends TextView {
private static final String TAG = "CarrierText";
private static CharSequence mSeparator;
private LockPatternUtils mLockPatternUtils;
protected boolean mAirplaneMode;
// For prop key to show carrier.
static final String PROP_KEY_SHOW_CARRIER = "persist.env.sys.SHOW_CARRIER";
static final String PROP_ENV_SPEC = SystemProperties.get("persist.env.spec");
static final int ORIGIN_CARRIER_NAME_ID = R.array.origin_carrier_names;
static final int LOCALE_CARRIER_NAME_ID = R.array.locale_carrier_names;
static final int LOCKSCREEN_CARRIER_DEFAULT_ID =
R.string.lockscreen_carrier_default;
private KeyguardUpdateMonitorCallback mCallback = new KeyguardUpdateMonitorCallback() {
private CharSequence mPlmn;
private CharSequence mSpn;
private State mSimState;
@Override
public void onRefreshCarrierInfo(CharSequence plmn, CharSequence spn) {
mPlmn = plmn;
mSpn = spn;
updateCarrierText(mSimState, mPlmn, mSpn);
}
@Override
public void onSimStateChanged(IccCardConstants.State simState) {
mSimState = simState;
updateCarrierText(mSimState, mPlmn, mSpn);
}
@Override
void onAirplaneModeChanged(boolean on) {
mAirplaneMode = on;
updateCarrierText(mSimState, mPlmn, mSpn);
}
};
/**
* The status of this lock screen. Primarily used for widgets on LockScreen.
*/
private static enum StatusMode {
Normal, // Normal case (sim card present, it's not locked)
PersoLocked, // SIM card is 'perso locked'.
SimMissing, // SIM card is missing.
SimMissingLocked, // SIM card is missing, and device isn't provisioned; don't allow access
SimPukLocked, // SIM card is PUK locked because SIM entered wrong too many times
SimLocked, // SIM card is currently locked
SimPermDisabled, // SIM card is permanently disabled due to PUK unlock failure
SimNotReady, // SIM is not ready yet. May never be on devices w/o a SIM.
SimIOError; //The sim card is faulty
}
public CarrierText(Context context) {
this(context, null);
}
public CarrierText(Context context, AttributeSet attrs) {
super(context, attrs);
mLockPatternUtils = new LockPatternUtils(mContext);
try {
mAirplaneMode = Settings.System.getInt(mContext.getContentResolver(),
Settings.System.AIRPLANE_MODE_ON) == 1;
} catch (SettingNotFoundException snfe) {
Log.e(TAG, "get airplane mode exception");
}
}
protected void updateCarrierText(State simState, CharSequence plmn, CharSequence spn) {
CharSequence text = "";
if (mAirplaneMode) {
// if airplane mode is on, show "airplane mode"
text = getContext().getText(R.string.lockscreen_airplane_mode_on);
} else {
text = getCarrierTextForSimState(simState, plmn, spn);
}
setText(text);
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
mSeparator = getResources().getString(R.string.kg_text_message_separator);
setSelected(true); // Allow marquee to work.
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
if (KeyguardUpdateMonitor.sIsMultiSimEnabled) {
return;
}
KeyguardUpdateMonitor.getInstance(mContext).registerCallback(mCallback);
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
KeyguardUpdateMonitor.getInstance(mContext).removeCallback(mCallback);
}
/**
* Top-level function for creating carrier text. Makes text based on simState, PLMN
* and SPN as well as device capabilities, such as being emergency call capable.
*
* @param simState
* @param plmn
* @param spn
* @return
*/
protected CharSequence getCarrierTextForSimState(IccCardConstants.State simState,
CharSequence plmn, CharSequence spn) {
CharSequence carrierText = null;
StatusMode status = getStatusForIccState(simState);
Log.d(TAG, "getCarrierTextForSimState, plmn: " + plmn + ", spn: " + spn);
String localPlmn = null;
if (plmn != null) {
localPlmn= mContext.getLocalString(plmn.toString(),
com.android.internal.R.array.origin_carrier_names,
com.android.internal.R.array.locale_carrier_names);
}
String localSpn = null;
if (spn != null) {
localSpn= mContext.getLocalString(spn.toString(),
com.android.internal.R.array.origin_carrier_names,
com.android.internal.R.array.locale_carrier_names);
}
Log.d(TAG, "getCarrierTextForSimState, localPlmn: "
+ localPlmn + ", localSpn: " + localSpn);
int resTextIdOfNoSimCard = R.string.lockscreen_missing_sim_message_short;
if (PROP_ENV_SPEC.equalsIgnoreCase("ChinaTelecom")) {
resTextIdOfNoSimCard = R.string.lockscreen_missing_uim_message_short;
}
// For CMCC requirement to show 3G in plmn if camping in TD_SCDMA.
TelephonyManager tm = (TelephonyManager)getContext()
.getSystemService(Context.TELEPHONY_SERVICE);
boolean show3G = !mAirplaneMode && tm != null && plmn != null &&
tm.getVoiceNetworkType() == TelephonyManager.NETWORK_TYPE_TD_SCDMA;
if (show3G && localPlmn != null) {
localPlmn = localPlmn + " 3G";
}
switch (status) {
case Normal:
carrierText = concatenate(localPlmn, localSpn);
break;
case SimNotReady:
carrierText = null; // nothing to display yet.
break;
case PersoLocked:
carrierText = makeCarrierStringOnEmergencyCapable(
getContext().getText(R.string.lockscreen_perso_locked_message),
plmn);
break;
case SimMissing:
// Shows "No SIM card | Emergency calls only" on devices that are voice-capable.
// This depends on mPlmn containing the text "Emergency calls only" when the radio
// has some connectivity. Otherwise, it should be null or empty and just show
// "No SIM card"
carrierText = makeCarrierStringOnEmergencyCapable(
getContext().getText(resTextIdOfNoSimCard),
plmn);
break;
case SimPermDisabled:
carrierText = getContext().getText(
R.string.lockscreen_permanent_disabled_sim_message_short);
break;
case SimMissingLocked:
carrierText = makeCarrierStringOnEmergencyCapable(
getContext().getText(resTextIdOfNoSimCard),
plmn);
break;
case SimLocked:
carrierText = makeCarrierStringOnEmergencyCapable(
getContext().getText(R.string.lockscreen_sim_locked_message),
plmn);
break;
case SimPukLocked:
carrierText = makeCarrierStringOnEmergencyCapable(
getContext().getText(R.string.lockscreen_sim_puk_locked_message),
plmn);
break;
case SimIOError:
carrierText = makeCarrierStringOnEmergencyCapable(
getContext().getText(R.string.lockscreen_sim_error_message_short),
plmn);
break;
}
return carrierText;
}
/*
* Add emergencyCallMessage to carrier string only if phone supports emergency calls.
*/
private CharSequence makeCarrierStringOnEmergencyCapable(
CharSequence simMessage, CharSequence emergencyCallMessage) {
if (mLockPatternUtils.isEmergencyCallCapable()) {
return concatenate(simMessage, emergencyCallMessage);
}
return simMessage;
}
/**
* Determine the current status of the lock screen given the SIM state and other stuff.
*/
private StatusMode getStatusForIccState(IccCardConstants.State simState) {
// Since reading the SIM may take a while, we assume it is present until told otherwise.
if (simState == null) {
return StatusMode.Normal;
}
final boolean missingAndNotProvisioned =
!KeyguardUpdateMonitor.getInstance(mContext).isDeviceProvisioned()
&& (simState == IccCardConstants.State.ABSENT ||
simState == IccCardConstants.State.PERM_DISABLED);
// Assume we're PERSO_LOCKED if not provisioned
simState = missingAndNotProvisioned ? IccCardConstants.State.PERSO_LOCKED : simState;
switch (simState) {
case ABSENT:
return StatusMode.SimMissing;
case PERSO_LOCKED:
return StatusMode.PersoLocked;
case NOT_READY:
return StatusMode.SimNotReady;
case PIN_REQUIRED:
return StatusMode.SimLocked;
case PUK_REQUIRED:
return StatusMode.SimPukLocked;
case READY:
return StatusMode.Normal;
case PERM_DISABLED:
return StatusMode.SimPermDisabled;
case UNKNOWN:
return StatusMode.SimMissing;
case CARD_IO_ERROR:
return StatusMode.SimIOError;
}
return StatusMode.SimMissing;
}
private static CharSequence concatenate(CharSequence plmn, CharSequence spn) {
final boolean plmnValid = !TextUtils.isEmpty(plmn);
final boolean spnValid = !TextUtils.isEmpty(spn);
/*if (plmnValid && spnValid) {
return new StringBuilder().append(plmn).append(mSeparator).append(spn).toString();
} else if (plmnValid) {
return plmn;
} else if (spnValid) {
return spn;
} else {
return "";
}*/
if (spnValid) {
return spn;
} else {
return "";
}
}
private CharSequence getCarrierHelpTextForSimState(IccCardConstants.State simState,
String plmn, String spn) {
int carrierHelpTextId = 0;
StatusMode status = getStatusForIccState(simState);
switch (status) {
case PersoLocked:
carrierHelpTextId = R.string.lockscreen_instructions_when_pattern_disabled;
break;
case SimMissing:
carrierHelpTextId = R.string.lockscreen_missing_sim_instructions_long;
break;
case SimPermDisabled:
carrierHelpTextId = R.string.lockscreen_permanent_disabled_sim_instructions;
break;
case SimMissingLocked:
carrierHelpTextId = R.string.lockscreen_missing_sim_instructions;
break;
case Normal:
case SimLocked:
case SimPukLocked:
break;
}
return mContext.getText(carrierHelpTextId);
}
上述加粗標紅的代碼就是我們需要作出修改的位置。
啦啦啦,這是山寨UC浏覽器的下拉刷新效果的第二篇,第一篇請移步Android 自定義View UC下拉刷新效果(一)我們看圖說話:主要工作1.下拉刷新的圓形向回首頁的圓形
本文實例為大家分享了TextView繪制背景的方法,供大家參考,具體內容如下效果:實現流程:1.初始化:對畫筆進行設置mPaintIn = new Paint();mPa
周末 特地把Android SwipeMenuListView(滑動菜單)的知識資料整理一番,以下是整理內容:SwipeMenuListView(滑動菜單)A swipe
自定義PullToRefreshListView繼承ListView,在ListView頭部添加一個下拉的頭部布局。跟ListView用法完全一致。該自定義Listvie