blob: 1c5fca635bf9630a606b1802ce6eab6a79f855be [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;
Srikanth Chintala89aa6602014-03-14 16:26:57 +053035import com.android.internal.telephony.cat.CatLog;
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;
Wink Savillee68857d2014-10-17 15:23:05 -070043 int mSlotId = -1;
Ryuto Sawadacf98c7c2017-10-19 15:36:11 +090044 private AlertDialog mAlertDialog;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080045
Wink Savillee68857d2014-10-17 15:23:05 -070046 private static final String LOG_TAG = new Object(){}.getClass().getEnclosingClass().getName();
47
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080048 @Override
49 protected void onCreate(Bundle icicle) {
50 super.onCreate(icicle);
51
Wink Savillee68857d2014-10-17 15:23:05 -070052 CatLog.d(LOG_TAG, "onCreate");
Wink Savillea8e4f502012-09-26 16:43:29 -070053 initFromIntent(getIntent());
Srikanth Chintala89aa6602014-03-14 16:26:57 +053054 // Register receiver
55 IntentFilter filter = new IntentFilter();
56 filter.addAction(StkAppService.FINISH_TONE_ACTIVITY_ACTION);
57 registerReceiver(mFinishActivityReceiver, filter);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080058
Sanket Padawe33501882017-04-19 18:30:09 -070059 AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
60 LayoutInflater inflater = this.getLayoutInflater();
61 View dialogView = inflater.inflate(R.layout.stk_tone_dialog, null);
62 alertDialogBuilder.setView(dialogView);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080063
Sanket Padawe33501882017-04-19 18:30:09 -070064 TextView tv = (TextView) dialogView.findViewById(R.id.message);
65 ImageView iv = (ImageView) dialogView.findViewById(R.id.icon);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080066
67 // set text and icon
Wink Savillee68857d2014-10-17 15:23:05 -070068 if ((null == toneMsg) || (null == toneMsg.text) || (toneMsg.text.equals(""))) {
69 CatLog.d(LOG_TAG, "onCreate - null tone text");
70 } else {
71 tv.setText(toneMsg.text);
72 }
73
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080074 if (toneMsg.icon == null) {
75 iv.setImageResource(com.android.internal.R.drawable.ic_volume);
76 } else {
77 iv.setImageBitmap(toneMsg.icon);
78 }
79
Teruaki Minamib97605d2016-06-16 15:47:08 +090080 if (toneMsg.iconSelfExplanatory && toneMsg.icon != null) {
81 tv.setVisibility(View.GONE);
82 }
Ryuto Sawadacf98c7c2017-10-19 15:36:11 +090083
84 alertDialogBuilder.setOnCancelListener(new DialogInterface.OnCancelListener() {
85 @Override
86 public void onCancel(DialogInterface dialog) {
87 sendStopTone();
88 finish();
89 }
90 });
91
92 mAlertDialog = alertDialogBuilder.create();
93 mAlertDialog.show();
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080094 }
95
96 @Override
97 protected void onDestroy() {
Wink Savillee68857d2014-10-17 15:23:05 -070098 CatLog.d(LOG_TAG, "onDestroy");
Srikanth Chintala89aa6602014-03-14 16:26:57 +053099 super.onDestroy();
Wink Saville79085fc2009-06-09 10:27:23 -0700100
Ryuto Sawadacf98c7c2017-10-19 15:36:11 +0900101 unregisterReceiver(mFinishActivityReceiver);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800102
Ryuto Sawadacf98c7c2017-10-19 15:36:11 +0900103 if (mAlertDialog != null && mAlertDialog.isShowing()) {
104 mAlertDialog.dismiss();
105 mAlertDialog = null;
Li Qiang075340e2013-08-13 09:59:44 +0200106 }
Li Qiang075340e2013-08-13 09:59:44 +0200107 }
108
Srikanth Chintala89aa6602014-03-14 16:26:57 +0530109 private BroadcastReceiver mFinishActivityReceiver = new BroadcastReceiver() {
110 @Override
111 public void onReceive(Context context, Intent intent) {
112 // Intent received from StkAppService to finish ToneDialog activity,
113 // after finishing off playing the tone.
114 if (intent.getAction().equals(StkAppService.FINISH_TONE_ACTIVITY_ACTION)) {
115 CatLog.d(this, "Finishing Tone dialog activity");
116 finish();
117 }
118 }
119 };
120
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800121 private void initFromIntent(Intent intent) {
122 if (intent == null) {
123 finish();
124 }
125 toneMsg = intent.getParcelableExtra("TEXT");
Wink Savillee68857d2014-10-17 15:23:05 -0700126 mSlotId = intent.getIntExtra(StkAppService.SLOT_ID, -1);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800127 }
128
Srikanth Chintala89aa6602014-03-14 16:26:57 +0530129 // Send stop playing tone to StkAppService, when user presses back key.
130 private void sendStopTone() {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800131 Bundle args = new Bundle();
Srikanth Chintala89aa6602014-03-14 16:26:57 +0530132 args.putInt(StkAppService.OPCODE, StkAppService.OP_STOP_TONE_USER);
Wink Savillee68857d2014-10-17 15:23:05 -0700133 args.putInt(StkAppService.SLOT_ID, mSlotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800134 startService(new Intent(this, StkAppService.class).putExtras(args));
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800135 }
136}