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

Commit b00ffce7 authored by Danny Baumann's avatar Danny Baumann
Browse files

Use TabLayout for DSDA tabs.

Change-Id: Ibdeef9d9c4bd4493d0b0dab8efec04e5d83b59a5
parent 15e82087
Loading
Loading
Loading
Loading
+29 −4
Original line number Original line Diff line number Diff line
@@ -15,9 +15,34 @@
-->
-->


<!-- In-call Phone UI; see InCallActivity.java. -->
<!-- In-call Phone UI; see InCallActivity.java. -->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_height="match_parent"
    android:animateLayoutChanges="true"
    android:orientation="vertical">

    <!-- tabMaxWidth is set to a large value (which is supposed to ever
         be larger than the TabLayout width) in order to make sure it's
         never taken into consideration and tab size is always TabLayout
         width divided by tab count -->
    <android.support.design.widget.TabLayout
        android:id="@+id/dsda_tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:visibility="gone"
        app:tabGravity="fill"
        app:tabMode="fixed"
        app:tabMaxWidth="10000dp"
        app:tabTextColor="@color/tab_text_color"
        app:tabSelectedTextColor="@color/incall_tab_indicator_color"
        app:tabIndicatorColor="@color/incall_tab_indicator_color" />

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="@android:color/black"
        android:background="@android:color/black"
    android:id="@+id/main" >
        android:id="@+id/main" />
</FrameLayout>

</LinearLayout>
+0 −5
Original line number Original line Diff line number Diff line
@@ -44,11 +44,6 @@
    <string name="recording_warning_title">Enable call recording?</string>
    <string name="recording_warning_title">Enable call recording?</string>
    <string name="recording_warning_text">Notice: You are responsible for compliance with any laws, regulations and rules that apply to the use of call recording functionality and the use or distribution of those recordings.</string>
    <string name="recording_warning_text">Notice: You are responsible for compliance with any laws, regulations and rules that apply to the use of call recording functionality and the use or distribution of those recordings.</string>


    <!-- Set Subscription screen: label sub 1 -->
    <string name="sub_1">SIM 1</string>
    <!-- Set Subscription screen: label sub 2 -->
    <string name="sub_2">SIM 2</string>

    <string name="call_failed_due_to_validate_number">Unable to make video call, the number format is not correct</string>
    <string name="call_failed_due_to_validate_number">Unable to make video call, the number format is not correct</string>
    <string name="call_state_dialing">Dialing</string>
    <string name="call_state_dialing">Dialing</string>
    <string name="call_state_holding">Holding</string>
    <string name="call_state_holding">Holding</string>
+3 −0
Original line number Original line Diff line number Diff line
@@ -32,6 +32,9 @@
    <color name="incall_action_bar_background_color">@color/incall_background_color</color>
    <color name="incall_action_bar_background_color">@color/incall_background_color</color>
    <color name="incall_action_bar_text_color">@color/incall_call_banner_text_color</color>
    <color name="incall_action_bar_text_color">@color/incall_call_banner_text_color</color>


    <color name="incall_tab_text_color">#ffffff</color>
    <color name="incall_tab_indicator_color">#ffffff</color>

    <color name="incall_photo_background_color">#545454</color>
    <color name="incall_photo_background_color">#545454</color>


    <!-- Put on top of each photo, implying 80% darker than usual. -->
    <!-- Put on top of each photo, implying 80% darker than usual. -->
+1 −1
Original line number Original line Diff line number Diff line
@@ -74,7 +74,7 @@
         circular reveal animation for a new outgoing call to work correctly. We don't just use
         circular reveal animation for a new outgoing call to work correctly. We don't just use
         Theme.Black.NoTitleBar directly, since we want any popups or dialogs from the
         Theme.Black.NoTitleBar directly, since we want any popups or dialogs from the
         InCallActivity to have the correct Material style. -->
         InCallActivity to have the correct Material style. -->
    <style name="Theme.InCallScreen" parent="@android:style/Theme.Material.Light">
    <style name="Theme.InCallScreen" parent="@style/Theme.AppCompat.Light">
        <item name="android:windowAnimationStyle">@null</item>
        <item name="android:windowAnimationStyle">@null</item>
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:windowBackground">@android:color/transparent</item>
+94 −110
Original line number Original line Diff line number Diff line
@@ -17,8 +17,6 @@
package com.android.incallui;
package com.android.incallui;


import android.app.ActionBar;
import android.app.ActionBar;
import android.app.FragmentTransaction;
import android.app.ActionBar.Tab;
import android.app.Activity;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityManager;
import android.app.AlertDialog;
import android.app.AlertDialog;
@@ -38,8 +36,10 @@ import android.graphics.Point;
import android.hardware.SensorManager;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.os.Bundle;
import android.os.Trace;
import android.os.Trace;
import android.support.design.widget.TabLayout;
import android.telecom.DisconnectCause;
import android.telecom.DisconnectCause;
import android.telecom.PhoneAccountHandle;
import android.telecom.PhoneAccountHandle;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.SubscriptionManager;
import android.text.TextUtils;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.KeyEvent;
@@ -77,7 +77,8 @@ import java.util.Locale;
/**
/**
 * Main activity that the user interacts with while in a live call.
 * Main activity that the user interacts with while in a live call.
 */
 */
public class InCallActivity extends TransactionSafeActivity implements FragmentDisplayManager {
public class InCallActivity extends TransactionSafeActivity implements
        FragmentDisplayManager, TabLayout.OnTabSelectedListener {


    public static final String TAG = InCallActivity.class.getSimpleName();
    public static final String TAG = InCallActivity.class.getSimpleName();


@@ -141,12 +142,18 @@ public class InCallActivity extends TransactionSafeActivity implements FragmentD
    private Animation mSlideOut;
    private Animation mSlideOut;
    private boolean mDismissKeyguard = false;
    private boolean mDismissKeyguard = false;


    private final int TAB_COUNT_ONE = 1;
    private SubscriptionManager mSubManager;
    private final int TAB_COUNT_TWO = 2;
    private List<SubscriptionInfo> mSubInfos;
    private final int TAB_POSITION_FIRST = 0;
    private SubscriptionManager.OnSubscriptionsChangedListener mSubListener =

            new SubscriptionManager.OnSubscriptionsChangedListener() {
    private Tab[] mDsdaTab = new Tab[TAB_COUNT_TWO];
        @Override
    private boolean[] mDsdaTabAdd = {false, false};
        public void onSubscriptionsChanged() {
            mSubInfos = mSubManager.getActiveSubscriptionInfoList();
            updateDsdaTabLabels();
        }
    };
    private TabLayout mDsdaTabLayout;
    private boolean mDsdaTabsInitiallyShown;


    AnimationListenerAdapter mSlideOutListener = new AnimationListenerAdapter() {
    AnimationListenerAdapter mSlideOutListener = new AnimationListenerAdapter() {
        @Override
        @Override
@@ -184,20 +191,14 @@ public class InCallActivity extends TransactionSafeActivity implements FragmentD
                | WindowManager.LayoutParams.FLAG_IGNORE_CHEEK_PRESSES;
                | WindowManager.LayoutParams.FLAG_IGNORE_CHEEK_PRESSES;


        getWindow().addFlags(flags);
        getWindow().addFlags(flags);
        boolean isDsdaEnabled = CallList.getInstance().isDsdaEnabled();

        if (isDsdaEnabled) {
        // Setup action bar for the conference call manager.
            requestWindowFeature(Window.FEATURE_ACTION_BAR);
            getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
            getActionBar().setDisplayShowTitleEnabled(false);
            getActionBar().setDisplayShowHomeEnabled(false);
        } else {
        requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
        requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
        if (getActionBar() != null) {
        if (getActionBar() != null) {
            getActionBar().setDisplayHomeAsUpEnabled(true);
            getActionBar().setDisplayHomeAsUpEnabled(true);
            getActionBar().setDisplayShowTitleEnabled(true);
            getActionBar().setDisplayShowTitleEnabled(true);
            getActionBar().hide();
            getActionBar().hide();
        }
        }
        }


        // TODO(klp): Do we need to add this back when prox sensor is not available?
        // TODO(klp): Do we need to add this back when prox sensor is not available?
        // lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_DISABLE_USER_ACTIVITY;
        // lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_DISABLE_USER_ACTIVITY;
@@ -259,10 +260,16 @@ public class InCallActivity extends TransactionSafeActivity implements FragmentD
        }
        }
        mInCallOrientationEventListener = new InCallOrientationEventListener(this);
        mInCallOrientationEventListener = new InCallOrientationEventListener(this);


        if (isDsdaEnabled ) {
        if (CallList.getInstance().isDsdaEnabled()) {
            initializeDsdaSwitchTab();
            mDsdaTabLayout = (TabLayout) findViewById(R.id.dsda_tabs);
            mDsdaTabLayout.addOnTabSelectedListener(this);

            mSubManager = SubscriptionManager.from(this);
            mSubManager.addOnSubscriptionsChangedListener(mSubListener);
            mSubInfos = mSubManager.getActiveSubscriptionInfoList();
        }
        }
        Log.d(this, "onCreate(): exit" + isDsdaEnabled);

        Log.d(this, "onCreate(): exit");
    }
    }


    @Override
    @Override
@@ -361,6 +368,9 @@ public class InCallActivity extends TransactionSafeActivity implements FragmentD
        InCallLowBatteryListener.getInstance().onDestroyInCallActivity();
        InCallLowBatteryListener.getInstance().onDestroyInCallActivity();
        InCallPresenter.getInstance().unsetActivity(this);
        InCallPresenter.getInstance().unsetActivity(this);
        InCallPresenter.getInstance().updateIsChangingConfigurations();
        InCallPresenter.getInstance().updateIsChangingConfigurations();
        if (mSubManager != null) {
            mSubManager.removeOnSubscriptionsChangedListener(mSubListener);
        }
        super.onDestroy();
        super.onDestroy();
    }
    }


@@ -592,6 +602,16 @@ public class InCallActivity extends TransactionSafeActivity implements FragmentD
        return false;
        return false;
    }
    }


    public void updateColor(int color) {
        getWindow().setStatusBarColor(color);
        final ActivityManager.TaskDescription td = new ActivityManager.TaskDescription(
                getString(R.string.notification_ongoing_call), null, color);
        setTaskDescription(td);
        if (mDsdaTabLayout != null) {
            mDsdaTabLayout.setBackgroundColor(color);
        }
    }

    public CallButtonFragment getCallButtonFragment() {
    public CallButtonFragment getCallButtonFragment() {
        return mCallButtonFragment;
        return mCallButtonFragment;
    }
    }
@@ -859,6 +879,10 @@ public class InCallActivity extends TransactionSafeActivity implements FragmentD


    public void showCallCardFragment(boolean show) {
    public void showCallCardFragment(boolean show) {
        showFragment(TAG_CALLCARD_FRAGMENT, show, true);
        showFragment(TAG_CALLCARD_FRAGMENT, show, true);
        if (mDsdaTabLayout != null && show) {
            mDsdaTabsInitiallyShown = true;
            updateDsdaTabVisibility();
        }
    }
    }


    /**
    /**
@@ -990,111 +1014,71 @@ public class InCallActivity extends TransactionSafeActivity implements FragmentD
        }
        }
    }
    }


    private void initializeDsdaSwitchTab() {
        int phoneCount = InCallServiceImpl.sPhoneCount;
        ActionBar bar = getActionBar();
        View[] mDsdaTabLayout = new View[phoneCount];
        int[] subString = {R.string.sub_1, R.string.sub_2};

        Log.d(TAG, "initializeDsdaSwitchTab" + phoneCount);
        for (int i = 0; i < phoneCount; i++) {
            mDsdaTabLayout[i] = getLayoutInflater()
                    .inflate(R.layout.msim_tab_sub_info, null);

            ((TextView)mDsdaTabLayout[i].findViewById(R.id.tabSubText))
                    .setText(subString[i]);

            mDsdaTab[i] = bar.newTab().setCustomView(mDsdaTabLayout[i])
                    .setTabListener(new TabListener(i));
        }
    }

    public void updateDsdaTab() {
    public void updateDsdaTab() {
        int phoneCount = InCallServiceImpl.sPhoneCount;
        int phoneCount = InCallServiceImpl.sPhoneCount;
        ActionBar bar = getActionBar();
        int activePhoneId = QtiCallUtils.getPhoneId(
                CallList.getInstance().getActiveSubId());


        for (int i = 0; i < phoneCount; i++) {
        mDsdaTabLayout.removeAllTabs();
        for (int i = 0; i < InCallServiceImpl.sPhoneCount; i++) {
            int subId = QtiCallUtils.getSubId(i);
            int subId = QtiCallUtils.getSubId(i);
            if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID
            if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID
                    && CallList.getInstance().hasAnyLiveCall(subId)) {
                    && CallList.getInstance().hasAnyLiveCall(subId)) {
                if (!mDsdaTabAdd[i]) {
                mDsdaTabLayout.addTab(mDsdaTabLayout.newTab().setTag(i),
                    addDsdaTab(i);
                        i == activePhoneId);
                }
            } else {
                removeDsdaTab(i);
            }
            }
        }
        }


        updateDsdaTabSelection();
        updateDsdaTabVisibility();
        updateDsdaTabLabels();
    }
    }


    private void addDsdaTab(int phoneId) {
    @Override
        ActionBar bar = getActionBar();
    public void onTabSelected(TabLayout.Tab tab) {
        int tabCount = bar.getTabCount();
        int phoneId = (Integer) tab.getTag();

        Log.d(this, "onTabSelected phoneId:" + phoneId);
        if (tabCount < phoneId) {
            bar.addTab(mDsdaTab[phoneId], false);
        } else {
            bar.addTab(mDsdaTab[phoneId], phoneId, false);
        }
        mDsdaTabAdd[phoneId] = true;
        Log.d(this, "addDsdaTab, phoneId = " + phoneId + " tab count = " + tabCount);
    }

    private void removeDsdaTab(int subId) {
        ActionBar bar = getActionBar();
        int tabCount = bar.getTabCount();


        for (int i = 0; i < tabCount; i++) {
        //Don't setActiveSubscription if tab count is 1.This is to avoid
            if (bar.getTabAt(i).equals(mDsdaTab[subId])) {
        //setting active subscription automatically when call on one sub
                bar.removeTab(mDsdaTab[subId]);
        //ends and it's corresponding tab is removed.For such cases active
                mDsdaTabAdd[subId] = false;
        //subscription will be set by InCallPresenter.attemptFinishActivity.
        if (mDsdaTabLayout.getTabCount() <= 1) {
            return;
            return;
        }
        }
        int subId = QtiCallUtils.getSubId(phoneId);
        if (CallList.getInstance().hasAnyLiveCall(subId)
                && CallList.getInstance().getActiveSubId() != subId) {
            Log.d(this, "Switch to other active sub: " + subId);
            QtiCallUtils.switchToActiveSub(subId);
        }
        }
        Log.d(this, "removeDsdaTab, subId = " + subId + " tab count = " + tabCount);
    }
    }


    private void updateDsdaTabSelection() {
    @Override
        ActionBar bar = getActionBar();
    public void onTabReselected(TabLayout.Tab tab) {
        int barCount = bar.getTabCount();

        if (barCount == TAB_COUNT_ONE) {
            bar.selectTab(bar.getTabAt(TAB_POSITION_FIRST));
        } else if (barCount == TAB_COUNT_TWO) {
            int phoneId = QtiCallUtils.getPhoneId(CallList
                    .getInstance().getActiveSubId());
            bar.selectTab(bar.getTabAt(phoneId));
        }
    }
    }


    private class TabListener implements ActionBar.TabListener {
    @Override
        int mPhoneId;
    public void onTabUnselected(TabLayout.Tab tab) {

        public TabListener(int phoneId) {
            mPhoneId = phoneId;
    }
    }


        public void onTabSelected(Tab tab, FragmentTransaction ft) {
    private void updateDsdaTabVisibility() {
            ActionBar bar = getActionBar();
        boolean visible = mDsdaTabsInitiallyShown && mDsdaTabLayout.getTabCount() > 1;
            int tabCount = bar.getTabCount();
        mDsdaTabLayout.setVisibility(visible ? View.VISIBLE : View.GONE);
                Log.d(this, "onTabSelected mPhoneId:" + mPhoneId);
            //Don't setActiveSubscription if tab count is 1.This is to avoid
            //setting active subscription automatically when call on one sub
            //ends and it's corresponding tab is removed.For such cases active
            //subscription will be set by InCallPresenter.attemptFinishActivity.
            int subId = QtiCallUtils.getSubId(mPhoneId);
            if (tabCount != TAB_COUNT_ONE && CallList.getInstance().hasAnyLiveCall(subId)
                    && (CallList.getInstance().getActiveSubId() != subId)) {
                Log.d(this, "Switch to other active sub: " + subId);
                QtiCallUtils.switchToActiveSub(subId);
            }
    }
    }


        public void onTabUnselected(Tab tab, FragmentTransaction ft) {
    private void updateDsdaTabLabels() {
        int tabCount = mDsdaTabLayout.getTabCount();
        for (int i = 0; i < tabCount; i++) {
            TabLayout.Tab tab = mDsdaTabLayout.getTabAt(i);
            int phoneId = (Integer) tab.getTag();
            SubscriptionInfo info = null;
            for (int j = 0; j < mSubInfos.size(); j++) {
                if (mSubInfos.get(j).getSimSlotIndex() == phoneId) {
                    info = mSubInfos.get(j);
                    break;
                }
                }

            }
        public void onTabReselected(Tab tab, FragmentTransaction ft) {
            tab.setText(info != null ? info.getDisplayName() : "SIM " + (i + 1));
        }
        }
    }
    }


Loading