Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c4b16ea4 authored by Danny Baumann's avatar Danny Baumann Committed by Steve Kondik
Browse files

Clean up keyguard carrier text handling.

Return to AOSP code while still keeping the support for MSIM. Doing so
both simplifies the code and fixes the left alignment.

Change-Id: Icc48082818eccbaab80a9b96d7200e30458727dc
parent 71f5743c
Loading
Loading
Loading
Loading
+0 −110
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
**
**Copyright (c) 2014, The Linux Foundation. All rights reserved.
**
**Redistribution and use in source and binary forms, with or without
**modification, are permitted provided that the following conditions are
**met:
**    * Redistributions of source code must retain the above copyright
**      notice, this list of conditions and the following disclaimer.
**    * Redistributions in binary form must reproduce the above
**      copyright notice, this list of conditions and the following
**      disclaimer in the documentation and/or other materials provided
**      with the distribution.
**    * Neither the name of The Linux Foundation nor the names of its
**      contributors may be used to endorse or promote products derived
**      from this software without specific prior written permission.
**
**THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
**WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
**MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
**ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
**BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
**CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
**SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
**BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
**WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
**OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
**IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**
-->
<merge xmlns:android="http://schemas.android.com/apk/res/android">
    <TextView
        android:id="@+id/airplane_mode"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:layout_gravity="center"
        android:gravity="start"
        android:ellipsize="marquee"
        android:singleLine="true"
        android:textDirection = "locale"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="?android:attr/textColorPrimary"
        android:textSize="@dimen/keyguard_lockscreen_status_line_font_size"
        android:visibility="gone" />

    <TextView
        android:id="@+id/carrier1"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:layout_gravity="center"
        android:gravity="start"
        android:ellipsize="marquee"
        android:singleLine="true"
        android:textDirection = "locale"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="?android:attr/textColorPrimary"
        android:textSize="@dimen/keyguard_lockscreen_status_line_font_size"
        android:visibility="gone" />

    <TextView
        android:id="@+id/carrier_divider1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:paddingLeft="12dp"
        android:paddingRight="12dp"
        android:visibility="gone" />

    <TextView
        android:id="@+id/carrier2"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:layout_gravity="center"
        android:gravity="start"
        android:ellipsize="marquee"
        android:singleLine="true"
        android:textDirection = "locale"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="?android:attr/textColorPrimary"
        android:textSize="@dimen/keyguard_lockscreen_status_line_font_size"
        android:visibility="gone" />

    <TextView
        android:id="@+id/carrier_divider2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:paddingLeft="12dp"
        android:paddingRight="12dp"
        android:visibility="gone" />

    <TextView
        android:id="@+id/carrier3"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:layout_gravity="center"
        android:gravity="start"
        android:ellipsize="marquee"
        android:singleLine="true"
        android:textDirection = "locale"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="?android:attr/textColorPrimary"
        android:textSize="@dimen/keyguard_lockscreen_status_line_font_size"
        android:visibility="gone" />
</merge>
+5 −2
Original line number Diff line number Diff line
@@ -31,9 +31,12 @@

    <com.android.keyguard.CarrierText
        android:id="@+id/carrier_text"
        android:layout_width="match_parent"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:ellipsize="marquee"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textSize="@dimen/kg_status_line_font_size"
        android:textColor="?android:attr/textColorSecondary"
        android:visibility="gone"
        androidprv:allCaps="@bool/kg_use_all_caps" />

+65 −88
Original line number Diff line number Diff line
@@ -18,88 +18,60 @@ package com.android.keyguard;

import android.content.Context;
import android.content.res.TypedArray;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.text.method.SingleLineTransformationMethod;
import android.text.TextUtils;
import android.telephony.TelephonyManager;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.android.internal.telephony.IccCardConstants;
import com.android.internal.telephony.IccCardConstants.State;
import com.android.internal.widget.LockPatternUtils;

import java.util.Locale;
import java.util.HashMap;
import android.util.Log;

public class CarrierText extends LinearLayout {
public class CarrierText extends TextView {
    private static final String TAG = "CarrierText";
    private static final boolean DEBUG = KeyguardConstants.DEBUG;
    private static final int mNumPhones = TelephonyManager.getDefault().getPhoneCount();
    private static CharSequence mSeparator;
    private static final int PHONE_COUNT = TelephonyManager.getDefault().getPhoneCount();

    private static CharSequence sSeparator;
    private LockPatternUtils mLockPatternUtils;

    private boolean mShowAPM;

    private KeyguardUpdateMonitor mUpdateMonitor;
    private TextView mOperatorName[];
    private TextView mOperatorSeparator[];
    private TextView mAirplaneModeText;

    private boolean mDisplayAirplaneMode;
    private boolean mAirplaneModeActive;

    private KeyguardUpdateMonitorCallback mCallback = new KeyguardUpdateMonitorCallback() {
        @Override
        public void onRefreshCarrierInfo(long subId, CharSequence plmn, CharSequence spn) {
            updateCarrierText(mUpdateMonitor.getSimState(subId), plmn, spn, subId);
            updateCarrierText();
        }

        @Override
        public void onSimStateChanged(long subId, IccCardConstants.State simState) {
            updateCarrierText(simState, mUpdateMonitor.getTelephonyPlmn(subId),
                mUpdateMonitor.getTelephonySpn(subId), subId);
            updateCarrierText();
        }

        @Override
        void onAirplaneModeChanged(boolean on) {
            if (on && mShowAPM) {
                for (int i = 0; i < mNumPhones; i++) {
                    mOperatorName[i].setVisibility(View.GONE);
                    if (i < mNumPhones-1) {
                        mOperatorSeparator[i].setVisibility(View.GONE);
                    }
                }
                if (mAirplaneModeText != null) {
                    mAirplaneModeText.setVisibility(View.VISIBLE);
                }
            } else {
                for (int i = 0; i < mNumPhones; i++) {
                    mOperatorName[i].setVisibility(View.VISIBLE);
                    if (i < mNumPhones-1) {
                        mOperatorSeparator[i].setVisibility(View.VISIBLE);
                    }
                }
                if (mAirplaneModeText != null) {
                    mAirplaneModeText.setVisibility(View.GONE);
                }
            mAirplaneModeActive = on;
            if (mDisplayAirplaneMode) {
                updateCarrierText();
            }
        }

        public void onScreenTurnedOff(int why) {
            for (int i = 0; i < mNumPhones; i++) {
                mOperatorName[i].setSelected(false);
            }
            setSelected(false);
        };

        public void onScreenTurnedOn() {
            for (int i = 0; i < mNumPhones; i++) {
                mOperatorName[i].setSelected(true);
            }
            setSelected(true);
        };
    };

    /**
     * The status of this lock screen. Primarily used for widgets on LockScreen.
     */
@@ -121,59 +93,32 @@ public class CarrierText extends LinearLayout {

    public CarrierText(Context context, AttributeSet attrs) {
        super(context, attrs);
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(
                Context.LAYOUT_INFLATER_SERVICE);
            inflater.inflate(R.layout.keyguard_carrier_text_view, this, true);

        mLockPatternUtils = new LockPatternUtils(mContext);
        mUpdateMonitor = KeyguardUpdateMonitor.getInstance(mContext);

        mOperatorName = new TextView[mNumPhones];
        mOperatorSeparator = new TextView[mNumPhones-1];

        mShowAPM = context.getResources().getBoolean(R.bool.config_display_APM);
        boolean useAllCaps;
        TypedArray a = context.getTheme().obtainStyledAttributes(
                attrs, R.styleable.CarrierText, 0, 0);
        try {
            useAllCaps = a.getBoolean(R.styleable.CarrierText_allCaps, false);
        } finally {
            a.recycle();
        }

    protected void updateCarrierText(State simState, CharSequence plmn, CharSequence spn,
            long subId) {
        if(DEBUG) Log.d(TAG, "updateCarrierText, simState=" + simState + " plmn=" + plmn
            + " spn=" + spn +" subId=" + subId);
        int phoneId = mUpdateMonitor.getPhoneIdBySubId(subId);
        if (!mUpdateMonitor.isValidPhoneId(phoneId)) {
            if(DEBUG) Log.d(TAG, "updateCarrierText, invalidate phoneId=" + phoneId);
            return;
        }

        String airplaneMode = getResources().getString(
                com.android.internal.R.string.lockscreen_airplane_mode_on);
        CharSequence text = getCarrierTextForSimState(simState, plmn, spn);
        TextView updateCarrierView = mOperatorName[phoneId];
        if (mAirplaneModeText != null && mShowAPM) {
            mAirplaneModeText.setText(airplaneMode);
        }
        updateCarrierView.setText(text != null ? text.toString() : null);
        setTransformationMethod(new CarrierTextTransformationMethod(mContext, useAllCaps));
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        mSeparator = getResources().getString(R.string.kg_text_message_separator);
        int[] operatorNameId = {R.id.carrier1, R.id.carrier2, R.id.carrier3};
        int[] operatorSepId = {R.id.carrier_divider1, R.id.carrier_divider2};
        if (sSeparator == null) {
            sSeparator = getResources().getString(R.string.kg_text_message_separator);
        }
        mDisplayAirplaneMode = getResources().getBoolean(R.bool.config_display_APM);

        final boolean screenOn = KeyguardUpdateMonitor.getInstance(mContext).isScreenOn();
        setSelected(screenOn); // Allow marquee to work.

        for (int i = 0; i < mNumPhones; i++) {
            mOperatorName[i] = (TextView) findViewById(operatorNameId[i]);
            mOperatorName[i].setVisibility(View.VISIBLE);
            mOperatorName[i].setSelected(true);
            if (i < mNumPhones-1) {
                mOperatorSeparator[i] = (TextView) findViewById(operatorSepId[i]);
                mOperatorSeparator[i].setVisibility(View.VISIBLE);
                mOperatorSeparator[i].setText("|");
            }
        }
        mAirplaneModeText = (TextView) findViewById(R.id.airplane_mode);
        updateCarrierText();
    }

    @Override
@@ -188,6 +133,39 @@ public class CarrierText extends LinearLayout {
        KeyguardUpdateMonitor.getInstance(mContext).removeCallback(mCallback);
    }

    private void updateCarrierText() {
        if (mDisplayAirplaneMode && mAirplaneModeActive) {
            setText(com.android.internal.R.string.lockscreen_airplane_mode_on);
            return;
        }

        StringBuilder text = new StringBuilder();

        for (int i = 0; i < PHONE_COUNT; i++) {
            long subId = mUpdateMonitor.getSubIdByPhoneId(i);
            if (subId == SubscriptionManager.INVALID_SUB_ID) {
                continue;
            }

            CharSequence carrierText = getCarrierTextForSimState(
                    mUpdateMonitor.getSimState(subId),
                    mUpdateMonitor.getTelephonyPlmn(subId),
                    mUpdateMonitor.getTelephonySpn(subId));
            if (DEBUG) Log.d(TAG, "getCarrierTextForSimState(sub " + subId
                    + "): carrierText=" + carrierText);
            if (carrierText == null) {
                continue;
            }

            if (text.length() > 0) {
                text.append(" | ");
            }
            text.append(carrierText);
        }

        setText(text);
    }

    /**
     * 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.
@@ -256,7 +234,6 @@ public class CarrierText extends LinearLayout {
                break;
        }

        if (DEBUG) Log.d(TAG, "getCarrierTextForSimState: carrierText=" + carrierText);
        return carrierText;
    }

@@ -317,7 +294,7 @@ public class CarrierText extends LinearLayout {
            if (plmn.equals(spn)) {
                return plmn;
            } else {
                return new StringBuilder().append(plmn).append(mSeparator).append(spn).toString();
                return new StringBuilder().append(plmn).append(sSeparator).append(spn).toString();
            }
        } else if (plmnValid) {
            return plmn;