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; |
Srikanth Chintala | 89aa660 | 2014-03-14 16:26:57 +0530 | [diff] [blame] | 35 | import com.android.internal.telephony.cat.CatLog; |
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; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 43 | int mSlotId = -1; |
Ryuto Sawada | cf98c7c | 2017-10-19 15:36:11 +0900 | [diff] [blame] | 44 | private AlertDialog mAlertDialog; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 45 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 46 | private static final String LOG_TAG = new Object(){}.getClass().getEnclosingClass().getName(); |
| 47 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 48 | @Override |
| 49 | protected void onCreate(Bundle icicle) { |
| 50 | super.onCreate(icicle); |
| 51 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 52 | CatLog.d(LOG_TAG, "onCreate"); |
Wink Saville | a8e4f50 | 2012-09-26 16:43:29 -0700 | [diff] [blame] | 53 | initFromIntent(getIntent()); |
Srikanth Chintala | 89aa660 | 2014-03-14 16:26:57 +0530 | [diff] [blame] | 54 | // Register receiver |
| 55 | IntentFilter filter = new IntentFilter(); |
| 56 | filter.addAction(StkAppService.FINISH_TONE_ACTIVITY_ACTION); |
| 57 | registerReceiver(mFinishActivityReceiver, filter); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 58 | |
Sanket Padawe | 3350188 | 2017-04-19 18:30:09 -0700 | [diff] [blame] | 59 | 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 Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 63 | |
Sanket Padawe | 3350188 | 2017-04-19 18:30:09 -0700 | [diff] [blame] | 64 | TextView tv = (TextView) dialogView.findViewById(R.id.message); |
| 65 | ImageView iv = (ImageView) dialogView.findViewById(R.id.icon); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 66 | |
| 67 | // set text and icon |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 68 | 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 Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 74 | if (toneMsg.icon == null) { |
| 75 | iv.setImageResource(com.android.internal.R.drawable.ic_volume); |
| 76 | } else { |
| 77 | iv.setImageBitmap(toneMsg.icon); |
| 78 | } |
| 79 | |
Teruaki Minami | b97605d | 2016-06-16 15:47:08 +0900 | [diff] [blame] | 80 | if (toneMsg.iconSelfExplanatory && toneMsg.icon != null) { |
| 81 | tv.setVisibility(View.GONE); |
| 82 | } |
Ryuto Sawada | cf98c7c | 2017-10-19 15:36:11 +0900 | [diff] [blame] | 83 | |
| 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 Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | @Override |
| 97 | protected void onDestroy() { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 98 | CatLog.d(LOG_TAG, "onDestroy"); |
Srikanth Chintala | 89aa660 | 2014-03-14 16:26:57 +0530 | [diff] [blame] | 99 | super.onDestroy(); |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 100 | |
Ryuto Sawada | cf98c7c | 2017-10-19 15:36:11 +0900 | [diff] [blame] | 101 | unregisterReceiver(mFinishActivityReceiver); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 102 | |
Ryuto Sawada | cf98c7c | 2017-10-19 15:36:11 +0900 | [diff] [blame] | 103 | if (mAlertDialog != null && mAlertDialog.isShowing()) { |
| 104 | mAlertDialog.dismiss(); |
| 105 | mAlertDialog = null; |
Li Qiang | 075340e | 2013-08-13 09:59:44 +0200 | [diff] [blame] | 106 | } |
Li Qiang | 075340e | 2013-08-13 09:59:44 +0200 | [diff] [blame] | 107 | } |
| 108 | |
Srikanth Chintala | 89aa660 | 2014-03-14 16:26:57 +0530 | [diff] [blame] | 109 | 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 Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 121 | private void initFromIntent(Intent intent) { |
| 122 | if (intent == null) { |
| 123 | finish(); |
| 124 | } |
| 125 | toneMsg = intent.getParcelableExtra("TEXT"); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 126 | mSlotId = intent.getIntExtra(StkAppService.SLOT_ID, -1); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 127 | } |
| 128 | |
Srikanth Chintala | 89aa660 | 2014-03-14 16:26:57 +0530 | [diff] [blame] | 129 | // Send stop playing tone to StkAppService, when user presses back key. |
| 130 | private void sendStopTone() { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 131 | Bundle args = new Bundle(); |
Srikanth Chintala | 89aa660 | 2014-03-14 16:26:57 +0530 | [diff] [blame] | 132 | args.putInt(StkAppService.OPCODE, StkAppService.OP_STOP_TONE_USER); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 133 | args.putInt(StkAppService.SLOT_ID, mSlotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 134 | startService(new Intent(this, StkAppService.class).putExtras(args)); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 135 | } |
| 136 | } |