Skip to content
This repository
Browse code

Allow using PLMN and SPN text as part of Custom Carrier text - by Bri…

…an Larsen (Chezebel)

   When the 'Custom carrier label' option is used this change supports
   the following special character sequences:
    - $n = replaced with a newline when displayed
    - $d = replaced with the 'default' carrier text when displayed
    - $p = replaced with the 'plmn' text when displayed
    - $s = replaced with the 'spn' text when displayed

    Here is an example. Let's assume that the plmn text is "TW Mobile" and
you enter
    this string in the custom text field:
      My DHD$n$p
    The the on the Status Bar it will show up on 2 lines like this:
      My DHD
      TW Mobile

    Note that when using a lockscreen that displays custom text any '$n' is
converted
    to a space instead of a newline in order to function in the same way as
other
    carrier text on that screen, such as the Default text. So the above
example would
    look like this on 1 line:
      My DHD TW Mobile
  • Loading branch information...
commit 4d952877b22b3d2b90245ef8798ca991e5145e6b 1 parent ef1804e
Davor Bertovic authored April 22, 2012
51  packages/SystemUI/src/com/android/systemui/statusbar/phone/CarrierLabel.java
@@ -96,28 +96,41 @@ void updateNetworkName(boolean showSpn, String spn, boolean showPlmn, String plm
96 96
         customLabel = Settings.System.getString(mContext.getContentResolver(),
97 97
                 Settings.System.CUSTOM_CARRIER_LABEL);
98 98
 
99  
-        if (customLabel == null) {
100  
-
101  
-            StringBuilder str = new StringBuilder();
102  
-            boolean something = false;
103  
-            if (showPlmn && plmn != null) {
104  
-                str.append(plmn);
105  
-                something = true;
106  
-            }
107  
-            if (showSpn && spn != null) {
108  
-                if (something) {
109  
-                    str.append('\n');
110  
-                }
111  
-                str.append(spn);
112  
-                something = true;
113  
-            }
  99
+        StringBuilder str = new StringBuilder();
  100
+        boolean something = false;
  101
+        if (showPlmn && plmn != null) {
  102
+            str.append(plmn);
  103
+            something = true;
  104
+        }
  105
+        if (showSpn && spn != null) {
114 106
             if (something) {
115  
-                setText(str.toString());
116  
-            } else {
117  
-                setText(com.android.internal.R.string.lockscreen_carrier_default);
  107
+                str.append('\n');
118 108
             }
  109
+            str.append(spn);
  110
+            something = true;
  111
+        }
  112
+        if (!something) {
  113
+            str.append(com.android.internal.R.string.lockscreen_carrier_default);
  114
+        }
  115
+
  116
+        if (customLabel == null) {
  117
+            setText(str.toString());
119 118
         } else {
120  
-            setText(customLabel);
  119
+            // If the custom carrier label contains any "$x" items then we must
  120
+            // replace those with the proper text.
  121
+            //  - $n = new line
  122
+            //  - $d = default carrier text
  123
+            //  - $p = plmn carrier text
  124
+            //  - $s = spn carrier text
  125
+            //
  126
+
  127
+            // For the default carrier text we will use str, which we created above.
  128
+            String customStr = customLabel;
  129
+            customStr = customStr.replaceAll("\\$n", "\n");
  130
+            customStr = customStr.replaceAll("\\$d", (str != null) ? str.toString() : "");
  131
+            customStr = customStr.replaceAll("\\$p", (plmn != null) ? plmn : "");
  132
+            customStr = customStr.replaceAll("\\$s", (spn != null) ? spn : "");
  133
+            setText(customStr);
121 134
         }
122 135
     }
123 136
 
48  policy/src/com/android/internal/policy/impl/KeyguardStatusViewManager.java
@@ -278,7 +278,7 @@ void setOwnerInfo(CharSequence string) {
278 278
     /**
279 279
      * Sets the carrier help text message, if view is present. Carrier help text
280 280
      * messages are typically for help dealing with SIMS and connectivity.
281  
-     * 
  281
+     *
282 282
      * @param resId resource id of the message
283 283
      */
284 284
     public void setCarrierHelpText(int resId) {
@@ -293,7 +293,7 @@ private CharSequence getText(int resId) {
293 293
     /**
294 294
      * Unlock help message. This is typically for help with unlock widgets, e.g.
295 295
      * "wrong password" or "try again."
296  
-     * 
  296
+     *
297 297
      * @param textResId
298 298
      * @param lockIcon
299 299
      */
@@ -379,7 +379,7 @@ void resetStatusInfo() {
379 379
      * Update the status lines based on these rules: AlarmStatus: Alarm state
380 380
      * always gets it's own line. Status1 is shared between help, battery status
381 381
      * and generic unlock instructions, prioritized in that order.
382  
-     * 
  382
+     *
383 383
      * @param showStatusLines status lines are shown if true
384 384
      */
385 385
     void updateStatusLines(boolean showStatusLines) {
@@ -478,7 +478,7 @@ private void updateCalendar() {
478 478
                     for (EventBundle e : mCalendarEvents) {
479 479
                         String title = e.title + (e.dayString.isEmpty() ? " " : ", ");
480 480
                         String details = e.dayString
481  
-                                + ((e.allDay) ? "" : " " + DateFormat.format(
  481
+                                + ((e.allDay) ? " all-day " : " at " + DateFormat.format(
482 482
                                         DateFormat.is24HourFormat(getContext()) ? "kk:mm"
483 483
                                                 : "hh:mm a", e.begin).toString())
484 484
                                 + (!e.location.isEmpty() ? " (" + e.location + ")" : "");
@@ -655,7 +655,7 @@ private Context getContext() {
655 655
     /**
656 656
      * Update carrier text, carrier help and emergency button to match the
657 657
      * current status based on SIM state.
658  
-     * 
  658
+     *
659 659
      * @param simState
660 660
      */
661 661
     private void updateCarrierStateWithSimStatus(State simState) {
@@ -729,10 +729,25 @@ private void updateCarrierStateWithSimStatus(State simState) {
729 729
         customLabel = Settings.System.getString(getContext().getContentResolver(),
730 730
                 Settings.System.CUSTOM_CARRIER_LABEL);
731 731
 
732  
-        if (customLabel == null)
  732
+        if (customLabel == null) {
733 733
             setCarrierText(carrierText);
734  
-        else
735  
-            setCarrierText(customLabel);
  734
+        } else {
  735
+            // If the custom carrier label contains any "$x" items then we must
  736
+            // replace those with the proper text.
  737
+            //  - $n = new line
  738
+            //  - $d = default carrier text
  739
+            //  - $p = plmn carrier text
  740
+            //  - $s = spn carrier text
  741
+            //
  742
+
  743
+            // For the default carrier text we will use carrierText, which we created above.
  744
+            String customStr = customLabel;
  745
+            customStr = customStr.replaceAll("\\$n", "\n");
  746
+            customStr = customStr.replaceAll("\\$d", (carrierText != null) ? carrierText.toString() : "");
  747
+            customStr = customStr.replaceAll("\\$p", (mPlmn != null) ? mPlmn.toString() : "");
  748
+            customStr = customStr.replaceAll("\\$s", (mSpn != null) ? mSpn.toString() : "");
  749
+            setCarrierText(customStr);
  750
+        }
736 751
 
737 752
         setCarrierHelpText(carrierHelpTextId);
738 753
         updateEmergencyCallButtonState(mPhoneState);
@@ -886,7 +901,7 @@ public void onClick(View v) {
886 901
 
887 902
     /**
888 903
      * Performs concentenation of PLMN/SPN
889  
-     * 
  904
+     *
890 905
      * @param plmn
891 906
      * @param spn
892 907
      * @return
@@ -1010,9 +1025,9 @@ private void getCalendarEvents(ContentResolver resolver, String sources,
1010 1025
         }, selection, null,
1011 1026
                 CalendarContract.Instances.START_DAY + " ASC, "
1012 1027
                         + CalendarContract.Instances.START_MINUTE + " ASC");
1013  
-        
  1028
+
1014 1029
         int events = eventCur.getCount();
1015  
-        
  1030
+
1016 1031
         if (events > 0) {
1017 1032
             eventCur.moveToFirst();
1018 1033
             do {
@@ -1031,25 +1046,20 @@ private void getCalendarEvents(ContentResolver resolver, String sources,
1031 1046
         public Calendar begin;
1032 1047
         public String location;
1033 1048
         public String dayString;
1034  
-        public boolean allDay = false;
  1049
+        public boolean allDay;
1035 1050
         public int color;
1036 1051
 
1037 1052
         EventBundle(String s, long b, String l, Calendar now, boolean a, int c) {
1038 1053
             title = s;
1039 1054
             begin = Calendar.getInstance();
1040  
-            if (a) {
1041  
-                begin.setTimeInMillis(b - begin.get(Calendar.ZONE_OFFSET) - begin.get(Calendar.DST_OFFSET));
1042  
-                allDay = true;
1043  
-            } else {
1044  
-                begin.setTimeInMillis(b);
1045  
-            }
  1055
+            begin.setTimeInMillis(b);
1046 1056
             location = (l == null) ? "" : l;
1047 1057
             int beginDay = begin.get(Calendar.DAY_OF_YEAR);
1048 1058
             int today = now.get(Calendar.DAY_OF_YEAR);
1049 1059
             if (beginDay == today) { // today
1050 1060
                 dayString = "";
1051 1061
             } else if (today + 1 == beginDay || (today >= 365 && beginDay == 1)) { // tomorrow
1052  
-                dayString = getContext().getString(R.string.lockscreen_calendar_tomorrow);
  1062
+                dayString = "Tomorrow";
1053 1063
             } else { // another day of week
1054 1064
                 dayString = begin.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT,
1055 1065
                         Locale.getDefault());

0 notes on commit 4d95287

Please sign in to comment.
Something went wrong with that request. Please try again.