• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 Esmertec AG.
3  * Copyright (C) 2008 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 package com.android.mms.ui;
19 
20 import static com.android.mms.util.RateController.RATE_LIMIT_CONFIRMED_ACTION;
21 
22 import com.android.mms.R;
23 import com.android.mms.util.RateController;
24 
25 import android.app.Activity;
26 import android.content.Intent;
27 import android.os.Bundle;
28 import android.os.Handler;
29 import android.util.Config;
30 import android.util.Log;
31 import android.view.KeyEvent;
32 import android.view.View;
33 import android.view.Window;
34 import android.view.View.OnClickListener;
35 import android.widget.Button;
36 
37 public class ConfirmRateLimitActivity extends Activity {
38     private static final String TAG = "ConfirmRateLimitActivity";
39     private static final boolean DEBUG = false;
40     private static final boolean LOCAL_LOGV = DEBUG ? Config.LOGD : Config.LOGV;
41 
42     private long mCreateTime;
43     private Handler mHandler;
44     private Runnable mRunnable;
45 
46     @Override
onCreate(Bundle savedInstanceState)47     protected void onCreate(Bundle savedInstanceState) {
48         super.onCreate(savedInstanceState);
49 
50         requestWindowFeature(Window.FEATURE_NO_TITLE);
51         setContentView(R.layout.confirm_rate_limit_activity);
52 
53         Button button = (Button) findViewById(R.id.btn_yes);
54         button.setOnClickListener(new OnClickListener() {
55             public void onClick(View v) {
56                 doAnswer(true);
57             }
58         });
59 
60         button = (Button) findViewById(R.id.btn_no);
61         button.setOnClickListener(new OnClickListener() {
62             public void onClick(View v) {
63                 doAnswer(false);
64             }
65         });
66 
67         mHandler = new Handler();
68         mRunnable = new Runnable() {
69             public void run() {
70                 if (LOCAL_LOGV) {
71                     Log.v(TAG, "Runnable executed.");
72                 }
73                 doAnswer(false);
74             }
75         };
76 
77         mCreateTime = System.currentTimeMillis();
78     }
79 
80     @Override
onResume()81     protected void onResume() {
82         super.onResume();
83 
84         long delay = mCreateTime - System.currentTimeMillis()
85                         + (RateController.ANSWER_TIMEOUT - 500);
86 
87         if (delay <= 0) {
88             doAnswer(false);
89         } else if (mHandler != null) {
90             // Close this activity after certain seconds if no user action.
91             mHandler.postDelayed(mRunnable, delay);
92         }
93     }
94 
95     @Override
onPause()96     protected void onPause() {
97         super.onPause();
98 
99         if (mHandler != null) {
100             mHandler.removeCallbacks(mRunnable);
101         }
102     }
103 
104     @Override
onKeyDown(int keyCode, KeyEvent event)105     public boolean onKeyDown(int keyCode, KeyEvent event) {
106         if ((keyCode == KeyEvent.KEYCODE_BACK)
107                 && (event.getRepeatCount() == 0)) {
108             doAnswer(false);
109         }
110         return super.onKeyDown(keyCode, event);
111     }
112 
doAnswer(boolean answer)113     private void doAnswer(boolean answer) {
114         Intent intent = new Intent(RATE_LIMIT_CONFIRMED_ACTION);
115         intent.putExtra("answer", answer);
116         sendBroadcast(intent);
117         finish();
118     }
119 }
120