blob: 4f67b06d94d0679e57e8f35de1085b1aa55a43e2 [file] [log] [blame]
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.stk;
18
19import android.app.Activity;
Sanket Padawe33501882017-04-19 18:30:09 -070020import android.app.AlertDialog;
Srikanth Chintala89aa6602014-03-14 16:26:57 +053021import android.content.BroadcastReceiver;
22import android.content.Context;
Ryuto Sawadacf98c7c2017-10-19 15:36:11 +090023import android.content.DialogInterface;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080024import android.content.Intent;
Srikanth Chintala89aa6602014-03-14 16:26:57 +053025import android.content.IntentFilter;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080026import android.os.Bundle;
27import android.os.Handler;
28import android.os.Message;
Sanket Padawe33501882017-04-19 18:30:09 -070029import android.view.LayoutInflater;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080030import android.view.View;
31import android.widget.ImageView;
32import android.widget.TextView;
Wink Savillee68857d2014-10-17 15:23:05 -070033import com.android.internal.telephony.cat.CatLog;
Alex Yakavenkad41f1d92010-07-12 14:13:13 -070034import com.android.internal.telephony.cat.TextMessage;
Umashankar Godachid345b362017-11-27 15:46:55 +053035import com.android.internal.telephony.cat.ToneSettings;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080036
37/**
Srikanth Chintala89aa6602014-03-14 16:26:57 +053038 * Activity used to display tone dialog.
Wink Saville79085fc2009-06-09 10:27:23 -070039 *
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080040 */
41public class ToneDialog extends Activity {
42 TextMessage toneMsg = null;
Umashankar Godachid345b362017-11-27 15:46:55 +053043 ToneSettings settings = null;
Wink Savillee68857d2014-10-17 15:23:05 -070044 int mSlotId = -1;
Ryuto Sawadacf98c7c2017-10-19 15:36:11 +090045 private AlertDialog mAlertDialog;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080046
Yoshiaki Naka3a980db2019-10-30 17:11:33 +090047 private static final String LOG_TAG =
48 new Object(){}.getClass().getEnclosingClass().getSimpleName();
Wink Savillee68857d2014-10-17 15:23:05 -070049
Umashankar Godachid345b362017-11-27 15:46:55 +053050 Handler mToneStopper = new Handler() {
51 @Override
52 public void handleMessage(Message msg) {
53 switch (msg.what) {
54 case MSG_ID_STOP_TONE:
55 CatLog.d(LOG_TAG, "Finishing Tone dialog activity");
56 finish();
57 break;
58 }
59 }
60 };
61
62 // Message id to signal tone duration timeout.
63 private static final int MSG_ID_STOP_TONE = 0xda;
64
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080065 @Override
66 protected void onCreate(Bundle icicle) {
67 super.onCreate(icicle);
68
Wink Savillee68857d2014-10-17 15:23:05 -070069 CatLog.d(LOG_TAG, "onCreate");
Wink Savillea8e4f502012-09-26 16:43:29 -070070 initFromIntent(getIntent());
Srikanth Chintala89aa6602014-03-14 16:26:57 +053071 // Register receiver
72 IntentFilter filter = new IntentFilter();
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080073
Sanket Padawe33501882017-04-19 18:30:09 -070074 AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
75 LayoutInflater inflater = this.getLayoutInflater();
76 View dialogView = inflater.inflate(R.layout.stk_tone_dialog, null);
77 alertDialogBuilder.setView(dialogView);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080078
Sanket Padawe33501882017-04-19 18:30:09 -070079 TextView tv = (TextView) dialogView.findViewById(R.id.message);
80 ImageView iv = (ImageView) dialogView.findViewById(R.id.icon);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080081
82 // set text and icon
Wink Savillee68857d2014-10-17 15:23:05 -070083 if ((null == toneMsg) || (null == toneMsg.text) || (toneMsg.text.equals(""))) {
84 CatLog.d(LOG_TAG, "onCreate - null tone text");
85 } else {
86 tv.setText(toneMsg.text);
87 }
88
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080089 if (toneMsg.icon == null) {
90 iv.setImageResource(com.android.internal.R.drawable.ic_volume);
91 } else {
92 iv.setImageBitmap(toneMsg.icon);
93 }
94
Teruaki Minamib97605d2016-06-16 15:47:08 +090095 if (toneMsg.iconSelfExplanatory && toneMsg.icon != null) {
96 tv.setVisibility(View.GONE);
97 }
Ryuto Sawadacf98c7c2017-10-19 15:36:11 +090098
Umashankar Godachid345b362017-11-27 15:46:55 +053099 if (null == settings) {
100 CatLog.d(LOG_TAG, "onCreate - null settings - finish");
101 finish();
102 return;
103 }
104
105 int timeout = StkApp.calculateDurationInMilis(settings.duration);
106 if (timeout == 0) {
107 timeout = StkApp.TONE_DEFAULT_TIMEOUT;
108 }
109 mToneStopper.sendEmptyMessageDelayed(MSG_ID_STOP_TONE, timeout);
110
Ryuto Sawadacf98c7c2017-10-19 15:36:11 +0900111 alertDialogBuilder.setOnCancelListener(new DialogInterface.OnCancelListener() {
112 @Override
113 public void onCancel(DialogInterface dialog) {
114 sendStopTone();
115 finish();
116 }
117 });
118
119 mAlertDialog = alertDialogBuilder.create();
120 mAlertDialog.show();
Yoshiaki Nakafac708c2020-01-22 19:49:27 +0900121
122 StkAppService appService = StkAppService.getInstance();
123 // Finish the activity if the specified duration is too short and timed-out already.
124 if (appService != null && (appService.isNoTonePlaying())) {
125 finish();
126 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800127 }
128
129 @Override
130 protected void onDestroy() {
Wink Savillee68857d2014-10-17 15:23:05 -0700131 CatLog.d(LOG_TAG, "onDestroy");
Umashankar Godachid345b362017-11-27 15:46:55 +0530132 mToneStopper.removeMessages(MSG_ID_STOP_TONE);
Srikanth Chintala89aa6602014-03-14 16:26:57 +0530133 super.onDestroy();
Wink Saville79085fc2009-06-09 10:27:23 -0700134
Ryuto Sawadacf98c7c2017-10-19 15:36:11 +0900135 if (mAlertDialog != null && mAlertDialog.isShowing()) {
136 mAlertDialog.dismiss();
137 mAlertDialog = null;
Li Qiang075340e2013-08-13 09:59:44 +0200138 }
Li Qiang075340e2013-08-13 09:59:44 +0200139 }
140
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800141 private void initFromIntent(Intent intent) {
142 if (intent == null) {
143 finish();
144 }
145 toneMsg = intent.getParcelableExtra("TEXT");
Umashankar Godachid345b362017-11-27 15:46:55 +0530146 settings = intent.getParcelableExtra("TONE");
Wink Savillee68857d2014-10-17 15:23:05 -0700147 mSlotId = intent.getIntExtra(StkAppService.SLOT_ID, -1);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800148 }
149
Srikanth Chintala89aa6602014-03-14 16:26:57 +0530150 // Send stop playing tone to StkAppService, when user presses back key.
151 private void sendStopTone() {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800152 Bundle args = new Bundle();
Srikanth Chintala89aa6602014-03-14 16:26:57 +0530153 args.putInt(StkAppService.OPCODE, StkAppService.OP_STOP_TONE_USER);
Wink Savillee68857d2014-10-17 15:23:05 -0700154 args.putInt(StkAppService.SLOT_ID, mSlotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800155 startService(new Intent(this, StkAppService.class).putExtras(args));
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800156 }
157}