summaryrefslogtreecommitdiffstats
path: root/src/com/android/incallui/MSimInCallActivity.java
blob: df7c1daec60593306298746454ecaf4bf228b7fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
/*
 * Copyright (c) 2013 The Linux Foundation. All rights reserved.
 * Not a Contribution.
 *
 * Copyright (C) 2006 The Android Open Source 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.incallui;

import android.app.ActionBar;
import android.app.FragmentTransaction;
import android.app.ActionBar.Tab;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.provider.Settings;
import android.telephony.MSimTelephonyManager;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * Phone app "multisim in call" screen.
 */
public class MSimInCallActivity extends InCallActivity {

    private MSimAnswerFragment mAnswerFragment;

    private final int TAB_COUNT_ONE = 1;
    private final int TAB_COUNT_TWO = 2;
    private final int TAB_POSITION_FIRST = 0;

    private Tab[] mDsdaTab = new Tab[TAB_COUNT_TWO];
    private boolean[] mDsdaTabAdd = {false, false};

    private static final String[] MULTI_SIM_NAME = {
        "perferred_name_sub1", "perferred_name_sub2"
    };

    @Override
    protected void onCreate(Bundle icicle) {
        Log.d(this, "onCreate()...  this = " + this);

        super.onCreate(icicle);

        // set this flag so this activity will stay in front of the keyguard
        // Have the WindowManager filter out touch events that are "too fat".
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
                | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
                | WindowManager.LayoutParams.FLAG_IGNORE_CHEEK_PRESSES);

        setTheme(R.style.InCallScreenWithActionBar);
        requestWindowFeature(Window.FEATURE_ACTION_BAR);

        getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        getActionBar().setDisplayShowTitleEnabled(false);
        getActionBar().setDisplayShowHomeEnabled(false);

        // Inflate everything in incall_screen.xml and add it to the screen.
        setContentView(R.layout.incall_screen_msim);

        initializeInCall();

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

    @Override
    protected void onStart() {
        Log.d(this, "onStart()...");
        super.onStart();

        // setting activity should be last thing in setup process
        InCallPresenter.getInstance().setActivity(this);
    }

    @Override
    public void finish() {
        Log.i(this, "finish().  Dialog showing: " + (mDialog != null));

        // skip finish if we are still showing a dialog.
        if (!hasPendingErrorDialog() && !mAnswerFragment.hasPendingDialogs()) {
            super.finish();
        }
    }

    @Override
    protected void initializeInCall() {
        if (mCallButtonFragment == null) {
            mCallButtonFragment = (CallButtonFragment) getFragmentManager()
                    .findFragmentById(R.id.callButtonFragment);
            mCallButtonFragment.setEnabled(false, false);
        }

        if (mCallCardFragment == null) {
            mCallCardFragment = (CallCardFragment) getFragmentManager()
                    .findFragmentById(R.id.callCardFragment);
        }

        if (mAnswerFragment == null) {
            mAnswerFragment = (MSimAnswerFragment) getFragmentManager()
                    .findFragmentById(R.id.answerFragment);
        }

        if (mDialpadFragment == null) {
            mDialpadFragment = (DialpadFragment) getFragmentManager()
                    .findFragmentById(R.id.dialpadFragment);
            mDialpadFragment.getView().setVisibility(View.INVISIBLE);
        }

        if (mConferenceManagerFragment == null) {
            mConferenceManagerFragment = (ConferenceManagerFragment) getFragmentManager()
                    .findFragmentById(R.id.conferenceManagerFragment);
            mConferenceManagerFragment.getView().setVisibility(View.INVISIBLE);
        }
    }

    @Override
    public void dismissPendingDialogs() {
        if (mDialog != null) {
            mDialog.dismiss();
            mDialog = null;
        }
        mAnswerFragment.dismissPendingDialogues();
    }

    private void initializeDsdaSwitchTab() {
        int phoneCount = MSimTelephonyManager.getDefault().getPhoneCount();
        ActionBar bar = getActionBar();
        View[] mDsdaTabLayout = new View[phoneCount];
        TypedArray icons = getResources().obtainTypedArray(R.array.sim_icons);
        int[] subString = {R.string.sub_1, R.string.sub_2};

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

            ((ImageView)mDsdaTabLayout[i].findViewById(R.id.tabSubIcon))
                    .setBackground(icons.getDrawable(i));

            ((TextView)mDsdaTabLayout[i].findViewById(R.id.tabSubText))
                    .setText(Settings.System.getString(getContentResolver(),
                            MULTI_SIM_NAME[i]));

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

    @Override
    public void updateDsdaTab() {
        int phoneCount = MSimTelephonyManager.getDefault().getPhoneCount();
        ActionBar bar = getActionBar();

        for (int i = 0; i < phoneCount; i++) {
            if (CallList.getInstance().existsLiveCall(i)) {
                if (!mDsdaTabAdd[i]) {
                    addDsdaTab(i);
                }
            } else {
                removeDsdaTab(i);
            }
        }

        updateDsdaTabSelection();
    }

    private void addDsdaTab(int subscription) {
        ActionBar bar = getActionBar();
        int tabCount = bar.getTabCount();

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

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

        for (int i = 0; i < tabCount; i++) {
            if (bar.getTabAt(i).equals(mDsdaTab[subscription])) {
                bar.removeTab(mDsdaTab[subscription]);
                mDsdaTabAdd[subscription] = false;
                return;
            }
        }
        Log.d(this, "removeDsdaTab, subscription = " + subscription + " tab count = " + tabCount);
    }

    private void updateDsdaTabSelection() {
        ActionBar bar = getActionBar();
        int barCount = bar.getTabCount();

        if (barCount == TAB_COUNT_ONE) {
            bar.selectTab(bar.getTabAt(TAB_POSITION_FIRST));
        } else if (barCount == TAB_COUNT_TWO) {
            bar.selectTab(bar.getTabAt(CallList.getInstance().getActiveSubscription()));
        }
    }

    private class TabListener implements ActionBar.TabListener {
        int mSubscription;

        public TabListener(int subId) {
            mSubscription = subId;
        }

        public void onTabSelected(Tab tab, FragmentTransaction ft) {
            ActionBar bar = getActionBar();
            int tabCount = bar.getTabCount();
            //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.
            if (tabCount != TAB_COUNT_ONE && CallList.getInstance().existsLiveCall(mSubscription)) {
                CallCommandClient.getInstance().setActiveSubscription(mSubscription);
            }
        }

        public void onTabUnselected(Tab tab, FragmentTransaction ft) {
        }

        public void onTabReselected(Tab tab, FragmentTransaction ft) {
        }
    }
}