Loading core/java/android/provider/Settings.java +10 −0 Original line number Diff line number Diff line Loading @@ -2236,6 +2236,16 @@ public final class Settings { */ public static final String STATUS_BAR_CLOCK = "status_bar_clock"; /** * Whether to show the signal text or signal bars. * default: 0 * 0: show signal bars * 1: show signal text numbers * 2: show signal text numbers w/small dBm appended * @hide */ public static final String STATUS_BAR_CM_SIGNAL_TEXT = "status_bar_cm_signal"; /** * Whether to display the status bar on top or bottom * 0: show status bar on top (default for most devices) Loading packages/SystemUI/res/layout/status_bar.xml +8 −0 Original line number Diff line number Diff line Loading @@ -51,6 +51,14 @@ android:gravity="center_vertical" android:orientation="horizontal"/> <com.android.systemui.statusbar.CmSignalText android:textAppearance="@*android:style/TextAppearance.StatusBar.Icon" android:layout_width="wrap_content" android:layout_height="match_parent" android:paddingRight="2dip" android:gravity="center_vertical" android:orientation="horizontal"/> <com.android.systemui.statusbar.CmBatteryText android:textAppearance="@*android:style/TextAppearance.StatusBar.Icon" android:layout_width="wrap_content" Loading packages/SystemUI/src/com/android/systemui/statusbar/CmSignalText.java 0 → 100644 +160 −0 Original line number Diff line number Diff line /* * 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 com.android.systemui.statusbar; import android.content.ContentResolver; import android.content.Context; import android.database.ContentObserver; import android.os.Handler; import android.provider.Settings; import android.telephony.PhoneStateListener; import android.telephony.SignalStrength; import android.telephony.TelephonyManager; import android.text.Spannable; import android.text.SpannableStringBuilder; import android.text.style.CharacterStyle; import android.text.style.RelativeSizeSpan; import android.util.AttributeSet; import android.view.View; import android.widget.TextView; public class CmSignalText extends TextView { int dBm = 0; int ASU = 0; private SignalStrength signal; private boolean mAttached; private static final int STYLE_HIDE = 0; private static final int STYLE_SHOW = 1; private static final int STYLE_SHOW_DBM = 2; private static int style; Handler mHandler; public CmSignalText(Context context) { this(context, null); } public CmSignalText(Context context, AttributeSet attrs) { super(context, attrs); ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).listen( mPhoneStateListener, PhoneStateListener.LISTEN_SERVICE_STATE | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS); mHandler = new Handler(); SettingsObserver settingsObserver = new SettingsObserver(mHandler); settingsObserver.observe(); updateSettings(); } @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); if (!mAttached) { mAttached = true; } } @Override protected void onDetachedFromWindow() { super.onDetachedFromWindow(); if (mAttached) { mAttached = false; } } class SettingsObserver extends ContentObserver { SettingsObserver(Handler handler) { super(handler); } void observe() { ContentResolver resolver = mContext.getContentResolver(); resolver.registerContentObserver( Settings.System.getUriFor(Settings.System.STATUS_BAR_CM_SIGNAL_TEXT), false, this); } @Override public void onChange(boolean selfChange) { updateSettings(); } } private void updateSettings() { updateSignalText(); } final void updateSignalText() { style = Settings.System.getInt(getContext().getContentResolver(), Settings.System.STATUS_BAR_CM_SIGNAL_TEXT, STYLE_HIDE); if (style == STYLE_SHOW) { this.setVisibility(View.VISIBLE); String result = Integer.toString(dBm); setText(result + " "); } else if (style == STYLE_SHOW_DBM) { this.setVisibility(View.VISIBLE); String result = Integer.toString(dBm) + " dBm "; SpannableStringBuilder formatted = new SpannableStringBuilder(result); int start = result.indexOf("d"); CharacterStyle style = new RelativeSizeSpan(0.7f); formatted.setSpan(style, start, start + 3, Spannable.SPAN_EXCLUSIVE_INCLUSIVE); setText(formatted); } else { this.setVisibility(View.GONE); } } /* * Phone listener to update signal information */ private PhoneStateListener mPhoneStateListener = new PhoneStateListener() { @Override public void onSignalStrengthsChanged(SignalStrength signalStrength) { signal = signalStrength; if (signal != null) { ASU = signal.getGsmSignalStrength(); } dBm = -113 + (2 * ASU); // update text if it's visible if (mAttached) updateSignalText(); } }; } packages/SystemUI/src/com/android/systemui/statusbar/StatusBarPolicy.java +16 −0 Original line number Diff line number Diff line Loading @@ -589,6 +589,8 @@ public class StatusBarPolicy { private boolean mShowCmBattery; private boolean mCmBatteryStatus; // need another var that superceding mPhoneSignalHidden private boolean mShowCmSignal; class SettingsObserver extends ContentObserver { SettingsObserver(Handler handler) { Loading @@ -599,6 +601,9 @@ public class StatusBarPolicy { ContentResolver resolver = mContext.getContentResolver(); resolver.registerContentObserver(Settings.System.getUriFor( Settings.System.STATUS_BAR_CM_BATTERY), false, this); resolver.registerContentObserver(Settings.System .getUriFor(Settings.System.STATUS_BAR_CM_SIGNAL_TEXT), false, this); } @Override public void onChange(boolean selfChange) { Loading Loading @@ -1097,6 +1102,11 @@ public class StatusBarPolicy { } private final void updateSignalStrength() { if (mShowCmSignal) { mService.setIconVisibility("phone_signal", false); return; } int iconLevel = -1; int[] iconList; Loading Loading @@ -1583,5 +1593,11 @@ public class StatusBarPolicy { Settings.System.STATUS_BAR_CM_BATTERY, 0) == 1); mCmBatteryStatus = !mShowCmBattery; mService.setIconVisibility("battery", !mShowCmBattery); //0 will hide the cmsignaltext and show the signal bars mShowCmSignal = Settings.System.getInt(mContext.getContentResolver(), Settings.System.STATUS_BAR_CM_SIGNAL_TEXT, 0) != 0; mService.setIconVisibility("phone_signal", !mShowCmSignal); } } Loading
core/java/android/provider/Settings.java +10 −0 Original line number Diff line number Diff line Loading @@ -2236,6 +2236,16 @@ public final class Settings { */ public static final String STATUS_BAR_CLOCK = "status_bar_clock"; /** * Whether to show the signal text or signal bars. * default: 0 * 0: show signal bars * 1: show signal text numbers * 2: show signal text numbers w/small dBm appended * @hide */ public static final String STATUS_BAR_CM_SIGNAL_TEXT = "status_bar_cm_signal"; /** * Whether to display the status bar on top or bottom * 0: show status bar on top (default for most devices) Loading
packages/SystemUI/res/layout/status_bar.xml +8 −0 Original line number Diff line number Diff line Loading @@ -51,6 +51,14 @@ android:gravity="center_vertical" android:orientation="horizontal"/> <com.android.systemui.statusbar.CmSignalText android:textAppearance="@*android:style/TextAppearance.StatusBar.Icon" android:layout_width="wrap_content" android:layout_height="match_parent" android:paddingRight="2dip" android:gravity="center_vertical" android:orientation="horizontal"/> <com.android.systemui.statusbar.CmBatteryText android:textAppearance="@*android:style/TextAppearance.StatusBar.Icon" android:layout_width="wrap_content" Loading
packages/SystemUI/src/com/android/systemui/statusbar/CmSignalText.java 0 → 100644 +160 −0 Original line number Diff line number Diff line /* * 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 com.android.systemui.statusbar; import android.content.ContentResolver; import android.content.Context; import android.database.ContentObserver; import android.os.Handler; import android.provider.Settings; import android.telephony.PhoneStateListener; import android.telephony.SignalStrength; import android.telephony.TelephonyManager; import android.text.Spannable; import android.text.SpannableStringBuilder; import android.text.style.CharacterStyle; import android.text.style.RelativeSizeSpan; import android.util.AttributeSet; import android.view.View; import android.widget.TextView; public class CmSignalText extends TextView { int dBm = 0; int ASU = 0; private SignalStrength signal; private boolean mAttached; private static final int STYLE_HIDE = 0; private static final int STYLE_SHOW = 1; private static final int STYLE_SHOW_DBM = 2; private static int style; Handler mHandler; public CmSignalText(Context context) { this(context, null); } public CmSignalText(Context context, AttributeSet attrs) { super(context, attrs); ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).listen( mPhoneStateListener, PhoneStateListener.LISTEN_SERVICE_STATE | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS); mHandler = new Handler(); SettingsObserver settingsObserver = new SettingsObserver(mHandler); settingsObserver.observe(); updateSettings(); } @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); if (!mAttached) { mAttached = true; } } @Override protected void onDetachedFromWindow() { super.onDetachedFromWindow(); if (mAttached) { mAttached = false; } } class SettingsObserver extends ContentObserver { SettingsObserver(Handler handler) { super(handler); } void observe() { ContentResolver resolver = mContext.getContentResolver(); resolver.registerContentObserver( Settings.System.getUriFor(Settings.System.STATUS_BAR_CM_SIGNAL_TEXT), false, this); } @Override public void onChange(boolean selfChange) { updateSettings(); } } private void updateSettings() { updateSignalText(); } final void updateSignalText() { style = Settings.System.getInt(getContext().getContentResolver(), Settings.System.STATUS_BAR_CM_SIGNAL_TEXT, STYLE_HIDE); if (style == STYLE_SHOW) { this.setVisibility(View.VISIBLE); String result = Integer.toString(dBm); setText(result + " "); } else if (style == STYLE_SHOW_DBM) { this.setVisibility(View.VISIBLE); String result = Integer.toString(dBm) + " dBm "; SpannableStringBuilder formatted = new SpannableStringBuilder(result); int start = result.indexOf("d"); CharacterStyle style = new RelativeSizeSpan(0.7f); formatted.setSpan(style, start, start + 3, Spannable.SPAN_EXCLUSIVE_INCLUSIVE); setText(formatted); } else { this.setVisibility(View.GONE); } } /* * Phone listener to update signal information */ private PhoneStateListener mPhoneStateListener = new PhoneStateListener() { @Override public void onSignalStrengthsChanged(SignalStrength signalStrength) { signal = signalStrength; if (signal != null) { ASU = signal.getGsmSignalStrength(); } dBm = -113 + (2 * ASU); // update text if it's visible if (mAttached) updateSignalText(); } }; }
packages/SystemUI/src/com/android/systemui/statusbar/StatusBarPolicy.java +16 −0 Original line number Diff line number Diff line Loading @@ -589,6 +589,8 @@ public class StatusBarPolicy { private boolean mShowCmBattery; private boolean mCmBatteryStatus; // need another var that superceding mPhoneSignalHidden private boolean mShowCmSignal; class SettingsObserver extends ContentObserver { SettingsObserver(Handler handler) { Loading @@ -599,6 +601,9 @@ public class StatusBarPolicy { ContentResolver resolver = mContext.getContentResolver(); resolver.registerContentObserver(Settings.System.getUriFor( Settings.System.STATUS_BAR_CM_BATTERY), false, this); resolver.registerContentObserver(Settings.System .getUriFor(Settings.System.STATUS_BAR_CM_SIGNAL_TEXT), false, this); } @Override public void onChange(boolean selfChange) { Loading Loading @@ -1097,6 +1102,11 @@ public class StatusBarPolicy { } private final void updateSignalStrength() { if (mShowCmSignal) { mService.setIconVisibility("phone_signal", false); return; } int iconLevel = -1; int[] iconList; Loading Loading @@ -1583,5 +1593,11 @@ public class StatusBarPolicy { Settings.System.STATUS_BAR_CM_BATTERY, 0) == 1); mCmBatteryStatus = !mShowCmBattery; mService.setIconVisibility("battery", !mShowCmBattery); //0 will hide the cmsignaltext and show the signal bars mShowCmSignal = Settings.System.getInt(mContext.getContentResolver(), Settings.System.STATUS_BAR_CM_SIGNAL_TEXT, 0) != 0; mService.setIconVisibility("phone_signal", !mShowCmSignal); } }