The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.stk; |
| 18 | |
| 19 | import android.app.Activity; |
Sanket Padawe | 3350188 | 2017-04-19 18:30:09 -0700 | [diff] [blame] | 20 | import android.app.AlertDialog; |
Srikanth Chintala | 89aa660 | 2014-03-14 16:26:57 +0530 | [diff] [blame] | 21 | import android.content.BroadcastReceiver; |
| 22 | import android.content.Context; |
Ryuto Sawada | cf98c7c | 2017-10-19 15:36:11 +0900 | [diff] [blame] | 23 | import android.content.DialogInterface; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 24 | import android.content.Intent; |
Srikanth Chintala | 89aa660 | 2014-03-14 16:26:57 +0530 | [diff] [blame] | 25 | import android.content.IntentFilter; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 26 | import android.os.Bundle; |
| 27 | import android.os.Handler; |
| 28 | import android.os.Message; |
Sanket Padawe | 3350188 | 2017-04-19 18:30:09 -0700 | [diff] [blame] | 29 | import android.view.LayoutInflater; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 30 | import android.view.View; |
| 31 | import android.widget.ImageView; |
| 32 | import android.widget.TextView; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 33 | import com.android.internal.telephony.cat.CatLog; |
Alex Yakavenka | d41f1d9 | 2010-07-12 14:13:13 -0700 | [diff] [blame] | 34 | import com.android.internal.telephony.cat.TextMessage; |
Umashankar Godachi | d345b36 | 2017-11-27 15:46:55 +0530 | [diff] [blame] | 35 | import com.android.internal.telephony.cat.ToneSettings; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 36 | |
| 37 | /** |
Srikanth Chintala | 89aa660 | 2014-03-14 16:26:57 +0530 | [diff] [blame] | 38 | * Activity used to display tone dialog. |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 39 | * |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 40 | */ |
| 41 | public class ToneDialog extends Activity { |
| 42 | TextMessage toneMsg = null; |
Umashankar Godachi | d345b36 | 2017-11-27 15:46:55 +0530 | [diff] [blame] | 43 | ToneSettings settings = null; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 44 | int mSlotId = -1; |
Ryuto Sawada | cf98c7c | 2017-10-19 15:36:11 +0900 | [diff] [blame] | 45 | private AlertDialog mAlertDialog; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 46 | |
Yoshiaki Naka | 3a980db | 2019-10-30 17:11:33 +0900 | [diff] [blame] | 47 | private static final String LOG_TAG = |
| 48 | new Object(){}.getClass().getEnclosingClass().getSimpleName(); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 49 | |
Umashankar Godachi | d345b36 | 2017-11-27 15:46:55 +0530 | [diff] [blame] | 50 | 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 Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 65 | @Override |
| 66 | protected void onCreate(Bundle icicle) { |
| 67 | super.onCreate(icicle); |
| 68 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 69 | CatLog.d(LOG_TAG, "onCreate"); |
Wink Saville | a8e4f50 | 2012-09-26 16:43:29 -0700 | [diff] [blame] | 70 | initFromIntent(getIntent()); |
Srikanth Chintala | 89aa660 | 2014-03-14 16:26:57 +0530 | [diff] [blame] | 71 | // Register receiver |
| 72 | IntentFilter filter = new IntentFilter(); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 73 | |
Sanket Padawe | 3350188 | 2017-04-19 18:30:09 -0700 | [diff] [blame] | 74 | 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 Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 78 | |
Sanket Padawe | 3350188 | 2017-04-19 18:30:09 -0700 | [diff] [blame] | 79 | TextView tv = (TextView) dialogView.findViewById(R.id.message); |
| 80 | ImageView iv = (ImageView) dialogView.findViewById(R.id.icon); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 81 | |
| 82 | // set text and icon |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 83 | 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 Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 89 | if (toneMsg.icon == null) { |
| 90 | iv.setImageResource(com.android.internal.R.drawable.ic_volume); |
| 91 | } else { |
| 92 | iv.setImageBitmap(toneMsg.icon); |
| 93 | } |
| 94 | |
Teruaki Minami | b97605d | 2016-06-16 15:47:08 +0900 | [diff] [blame] | 95 | if (toneMsg.iconSelfExplanatory && toneMsg.icon != null) { |
| 96 | tv.setVisibility(View.GONE); |
| 97 | } |
Ryuto Sawada | cf98c7c | 2017-10-19 15:36:11 +0900 | [diff] [blame] | 98 | |
Umashankar Godachi | d345b36 | 2017-11-27 15:46:55 +0530 | [diff] [blame] | 99 | 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 Sawada | cf98c7c | 2017-10-19 15:36:11 +0900 | [diff] [blame] | 111 | 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(); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | @Override |
| 124 | protected void onDestroy() { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 125 | CatLog.d(LOG_TAG, "onDestroy"); |
Umashankar Godachi | d345b36 | 2017-11-27 15:46:55 +0530 | [diff] [blame] | 126 | mToneStopper.removeMessages(MSG_ID_STOP_TONE); |
Srikanth Chintala | 89aa660 | 2014-03-14 16:26:57 +0530 | [diff] [blame] | 127 | super.onDestroy(); |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 128 | |
Ryuto Sawada | cf98c7c | 2017-10-19 15:36:11 +0900 | [diff] [blame] | 129 | if (mAlertDialog != null && mAlertDialog.isShowing()) { |
| 130 | mAlertDialog.dismiss(); |
| 131 | mAlertDialog = null; |
Li Qiang | 075340e | 2013-08-13 09:59:44 +0200 | [diff] [blame] | 132 | } |
Li Qiang | 075340e | 2013-08-13 09:59:44 +0200 | [diff] [blame] | 133 | } |
| 134 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 135 | private void initFromIntent(Intent intent) { |
| 136 | if (intent == null) { |
| 137 | finish(); |
| 138 | } |
| 139 | toneMsg = intent.getParcelableExtra("TEXT"); |
Umashankar Godachi | d345b36 | 2017-11-27 15:46:55 +0530 | [diff] [blame] | 140 | settings = intent.getParcelableExtra("TONE"); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 141 | mSlotId = intent.getIntExtra(StkAppService.SLOT_ID, -1); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 142 | } |
| 143 | |
Srikanth Chintala | 89aa660 | 2014-03-14 16:26:57 +0530 | [diff] [blame] | 144 | // Send stop playing tone to StkAppService, when user presses back key. |
| 145 | private void sendStopTone() { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 146 | Bundle args = new Bundle(); |
Srikanth Chintala | 89aa660 | 2014-03-14 16:26:57 +0530 | [diff] [blame] | 147 | args.putInt(StkAppService.OPCODE, StkAppService.OP_STOP_TONE_USER); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 148 | args.putInt(StkAppService.SLOT_ID, mSlotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 149 | startService(new Intent(this, StkAppService.class).putExtras(args)); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 150 | } |
| 151 | } |