Skip to content

Commit

Permalink
Custom Carrier Label & Carrier Label Placement [1/2]
Browse files Browse the repository at this point in the history
Squash commits:

Keyguard/Statusbar Carrier label options [1/2]
* Stock behavior(only on keyguard), only on statusbar,both disabled or both enabled
* code originally writted by @Altaf-Mahdi i just squased into one commit
PureNexusProject-Legacy/android_frameworks_base@688d56f

Show carrier label / custom & change color [1/2]
*code originally written by @martincz
*includes various fixs by the du team
PureNexusProject-Legacy/android_frameworks_base@16a247a

Carrier label - fix capitilization bug
PureNexusProject-Legacy/android_frameworks_base@4b9e22b

remove carrier label color and make carrier label play nice with dark statusbar
PureNexusProject-Legacy/android_frameworks_base@3f32102

Fix Carrier Label font size not changing on system font size change
DirtyUnicorns/android_frameworks_base@8da9dcf

include carrier label in icon merger width calculation
PureNexusProject-Legacy/android_frameworks_base@9df3a0c

Credit/Thanks to @Altaf-Mahdi @beanstown106 @dwitherell and @martincz

PureNexus Edits:
- Adapt statusbar hook for N

AICPfy:
- Adapt for AICP (CM14) source
- add missing @hide

AICP brought up to O by AliB:
- Adapt to O statusbar
- Adapt to DarkController
- parts of the code adapted from
   http://gerrit.aicp-rom.com/#/c/53587/

Change-Id: Ic1ecdbc606248dce5b2a2277374a8fa04c23b164
Signed-off-by: PMS22 <prathams99@rediff.com>
  • Loading branch information
Beanstown authored and PMS22 committed Apr 23, 2018
1 parent 160ed78 commit fb0c74a
Show file tree
Hide file tree
Showing 14 changed files with 406 additions and 18 deletions.
15 changes: 15 additions & 0 deletions core/java/android/content/Intent.java
Original file line number Diff line number Diff line change
Expand Up @@ -2775,6 +2775,21 @@ public static Intent createChooser(Intent target, CharSequence title, IntentSend
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String ACTION_AIRPLANE_MODE_CHANGED = "android.intent.action.AIRPLANE_MODE";

/**
* <p>Broadcast Action: The user has changed carrier label:</p>
* <ul>
* <li><em>state</em> - String value.</li>
* </ul>
*
* <p class="note">This is a protected intent that can only be sent
* by the system.
*
* @hide
*/
//@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String ACTION_CUSTOM_CARRIER_LABEL_CHANGED
= "android.intent.action.CUSTOM_CARRIER_LABEL";

/**
* Broadcast Action: Some content providers have parts of their namespace
* where they publish new events or items that the user may be especially
Expand Down
22 changes: 17 additions & 5 deletions core/java/android/provider/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -4072,11 +4072,6 @@ public boolean validate(String value) {
*/
public static final String QS_TILE_TITLE_VISIBILITY = "qs_tile_title_visibility";

/**
* @hide
*/
public static final String OMNIJAWS_WEATHER_ICON_PACK = "omnijaws_weather_icon_pack";

/**
* Change volume up and down handlign based on rotation
* @hide
Expand Down Expand Up @@ -4588,6 +4583,23 @@ public boolean validate(String value) {
*/
public static final String STATUS_BAR_FILE_HEADER_IMAGE = "status_bar_file_header_image";

/**
* Status bar carrier label
* 0: Hide
* 1: Display on keyguard status bar
* 2: Display on Normal status bar
* 3: Enabled for both
* @hide
*/
public static final String STATUS_BAR_SHOW_CARRIER = "status_bar_show_carrier";

/**
* custom carrier label. The value is
* String.
* @hide
*/
public static final String CUSTOM_CARRIER_LABEL = "custom_carrier_label";

/**
* Settings to backup. This is here so that it's in the same place as the settings
* keys and easy to update.
Expand Down
5 changes: 2 additions & 3 deletions packages/SystemUI/res/layout/keyguard_status_bar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,15 @@
</FrameLayout>
</LinearLayout>

<com.android.keyguard.CarrierText
<com.android.systemui.fh.carrierlabel.CarrierLabel
android:id="@+id/keyguard_carrier_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="@dimen/keyguard_carrier_text_margin"
android:layout_toStartOf="@id/system_icons_super_container"
android:gravity="center_vertical"
android:ellipsize="marquee"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?attr/wallpaperTextColorSecondary"
android:textAppearance="@style/TextAppearance.StatusBar.CarrierLabel"
android:singleLine="true" />

</com.android.systemui.statusbar.phone.KeyguardStatusBarView>
2 changes: 1 addition & 1 deletion packages/SystemUI/res/layout/notification_icon_area.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
android:layout_alignParentStart="true"
android:gravity="center_vertical"
android:orientation="horizontal"/>
</com.android.keyguard.AlphaOptimizedLinearLayout>
</com.android.keyguard.AlphaOptimizedLinearLayout>
9 changes: 9 additions & 0 deletions packages/SystemUI/res/layout/status_bar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@
android:gravity="center_vertical|start"
/>

<com.android.systemui.fh.carrierlabel.CarrierLabel
android:id="@+id/statusbar_carrier_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textAppearance="@style/TextAppearance.StatusBar.CarrierLabel"
android:visibility="gone"
android:singleLine="true"/>

<!-- The alpha of this area is controlled from both PhoneStatusBarTransitions and
PhoneStatusBar (DISABLE_NOTIFICATION_ICONS). -->
<com.android.systemui.statusbar.AlphaOptimizedFrameLayout
Expand Down
3 changes: 3 additions & 0 deletions packages/SystemUI/res/values/fh_colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@
<color name="fab_color">@*android:color/accent_device_default_light</color>
<color name="floating_action_button_icon_color">@android:color/white</color>

<!-- Custom Carrier Label -->
<color name="status_bar_carrier_color">#FFFFFFFF</color>

</resources>
7 changes: 7 additions & 0 deletions packages/SystemUI/res/values/fh_dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,12 @@

<!-- Quick QS scroller -->
<dimen name="qs_scroller_margin">8dp</dimen>
<dimen name="qs_scroller_top_margin">40dp</dimen>

<!-- Custom Carrier Label -->
<dimen name="status_bar_carrier_height">14dp</dimen>
<dimen name="qs_panel_footer_height">40dp</dimen>
<dimen name="qs_panel_margin_top">25dp</dimen>
<dimen name="qs_panel_margin_top_header">85dp</dimen>

</resources>
7 changes: 7 additions & 0 deletions packages/SystemUI/res/values/fh_styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,11 @@
<item name="android:textColor">?android:attr/textColorPrimary</item>
</style>

<!-- Custom Carrier Label -->
<style name="TextAppearance.StatusBar.CarrierLabel" parent="@*android:style/TextAppearance.StatusBar.Icon">
<item name="android:textSize">@dimen/status_bar_carrier_height</item>
<item name="android:textStyle">normal</item>
<item name="android:textColor">@color/status_bar_carrier_color</item>
</style>

</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
/*
* Copyright (C) 2014-2015 The MoKee OpenSource Project
*
* 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.fh.carrierlabel;

import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.database.ContentObserver;
import android.graphics.Rect;
import android.os.Handler;
import com.android.internal.util.fh.FhUtils;
import android.os.UserHandle;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.android.internal.telephony.TelephonyIntents;
import com.android.systemui.Dependency;
import com.android.systemui.fh.carrierlabel.SpnOverride;
import com.android.systemui.statusbar.policy.DarkIconDispatcher;
import com.android.systemui.statusbar.policy.DarkIconDispatcher.DarkReceiver;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.TimeZone;

import com.android.systemui.R;

public class CarrierLabel extends TextView implements DarkReceiver {

private Context mContext;
private boolean mAttached;
private static boolean isCN;

public CarrierLabel(Context context) {
this(context, null);
}

public CarrierLabel(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}

public CarrierLabel(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
mContext = context;
updateNetworkName(true, null, false, null);
}

@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
Dependency.get(DarkIconDispatcher.class).addDarkReceiver(this);
if (!mAttached) {
mAttached = true;
IntentFilter filter = new IntentFilter();
filter.addAction(TelephonyIntents.SPN_STRINGS_UPDATED_ACTION);
filter.addAction(Intent.ACTION_CUSTOM_CARRIER_LABEL_CHANGED);
mContext.registerReceiver(mIntentReceiver, filter, null, getHandler());
}
}

@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
Dependency.get(DarkIconDispatcher.class).removeDarkReceiver(this);
if (mAttached) {
mContext.unregisterReceiver(mIntentReceiver);
mAttached = false;
}
}

@Override
public void onDarkChanged(Rect area, float darkIntensity, int tint) {
setTextColor(DarkIconDispatcher.getTint(area, this, tint));
}

private final BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (TelephonyIntents.SPN_STRINGS_UPDATED_ACTION.equals(action)
|| Intent.ACTION_CUSTOM_CARRIER_LABEL_CHANGED.equals(action)) {
updateNetworkName(intent.getBooleanExtra(TelephonyIntents.EXTRA_SHOW_SPN, true),
intent.getStringExtra(TelephonyIntents.EXTRA_SPN),
intent.getBooleanExtra(TelephonyIntents.EXTRA_SHOW_PLMN, false),
intent.getStringExtra(TelephonyIntents.EXTRA_PLMN));
isCN = FhUtils.isChineseLanguage();
}
}
};

void updateNetworkName(boolean showSpn, String spn, boolean showPlmn, String plmn) {
final String str;
final boolean plmnValid = showPlmn && !TextUtils.isEmpty(plmn);
final boolean spnValid = showSpn && !TextUtils.isEmpty(spn);
if (spnValid) {
str = spn;
} else if (plmnValid) {
str = plmn;
} else {
str = "";
}
String customCarrierLabel = Settings.System.getStringForUser(mContext.getContentResolver(),
Settings.System.CUSTOM_CARRIER_LABEL, UserHandle.USER_CURRENT);
if (!TextUtils.isEmpty(customCarrierLabel)) {
setText(customCarrierLabel);
} else {
setText(TextUtils.isEmpty(str) ? getOperatorName() : str);
}
}

private String getOperatorName() {
String operatorName = getContext().getString(R.string.quick_settings_wifi_no_network);
TelephonyManager telephonyManager = (TelephonyManager) getContext().getSystemService(
Context.TELEPHONY_SERVICE);
if (isCN) {
String operator = telephonyManager.getNetworkOperator();
if (TextUtils.isEmpty(operator)) {
operator = telephonyManager.getSimOperator();
}
SpnOverride mSpnOverride = new SpnOverride();
operatorName = mSpnOverride.getSpn(operator);
} else {
operatorName = telephonyManager.getNetworkOperatorName();
}
if (TextUtils.isEmpty(operatorName)) {
operatorName = telephonyManager.getSimOperatorName();
}
return operatorName;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Copyright (C) 2014 The MoKee OpenSource Project
*
* 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.fh.carrierlabel;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import android.os.Environment;
import android.telephony.Rlog;
import android.util.Xml;

import com.android.internal.util.XmlUtils;

public class SpnOverride {
private HashMap<String, String> mCarrierSpnMap;


static final String LOG_TAG = "SpnOverride";
static final String PARTNER_SPN_OVERRIDE_PATH ="etc/spn-conf.xml";

public SpnOverride () {
mCarrierSpnMap = new HashMap<String, String>();
loadSpnOverrides();
}

public boolean containsCarrier(String carrier) {
return mCarrierSpnMap.containsKey(carrier);
}

public String getSpn(String carrier) {
return mCarrierSpnMap.get(carrier);
}

private void loadSpnOverrides() {
FileReader spnReader;

final File spnFile = new File(Environment.getRootDirectory(),
PARTNER_SPN_OVERRIDE_PATH);

try {
spnReader = new FileReader(spnFile);
} catch (FileNotFoundException e) {
Rlog.w(LOG_TAG, "Can not open " +
Environment.getRootDirectory() + "/" + PARTNER_SPN_OVERRIDE_PATH);
return;
}

try {
XmlPullParser parser = Xml.newPullParser();
parser.setInput(spnReader);

XmlUtils.beginDocument(parser, "spnOverrides");

while (true) {
XmlUtils.nextElement(parser);

String name = parser.getName();
if (!"spnOverride".equals(name)) {
break;
}

String numeric = parser.getAttributeValue(null, "numeric");
String data = parser.getAttributeValue(null, "spn");

mCarrierSpnMap.put(numeric, data);
}
spnReader.close();
} catch (XmlPullParserException e) {
Rlog.w(LOG_TAG, "Exception in spn-conf parser " + e);
} catch (IOException e) {
Rlog.w(LOG_TAG, "Exception in spn-conf parser " + e);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ protected void handleClick() {
@Override
public Intent getLongClickIntent() {
if (DEBUG) Log.d(TAG, "getLongClickIntent");
if (Utils.isPackageInstalled(mContext, "com.google.android.googlequicksearchbox")) {
if (FhUtils.isPackageInstalled(mContext, "com.google.android.googlequicksearchbox")) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("dynact://velour/weather/ProxyActivity"));
intent.setComponent(new ComponentName("com.google.android.googlequicksearchbox",
Expand Down
Loading

0 comments on commit fb0c74a

Please sign in to comment.