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 import android.app.Activity; 22 import android.content.Intent; 23 import android.os.Bundle; 24 import android.os.Handler; 25 import android.util.Log; 26 import android.view.KeyEvent; 27 import android.view.View; 28 import android.view.View.OnClickListener; 29 import android.view.Window; 30 import android.widget.Button; 31 32 import com.android.mms.R; 33 import com.android.mms.util.RateController; 34 35 public class ConfirmRateLimitActivity extends Activity { 36 private static final String TAG = "ConfirmRateLimitActivity"; 37 private static final boolean DEBUG = false; 38 private static final boolean LOCAL_LOGV = false; 39 40 private long mCreateTime; 41 private Handler mHandler; 42 private Runnable mRunnable; 43 44 @Override onCreate(Bundle savedInstanceState)45 protected void onCreate(Bundle savedInstanceState) { 46 super.onCreate(savedInstanceState); 47 48 requestWindowFeature(Window.FEATURE_NO_TITLE); 49 setContentView(R.layout.confirm_rate_limit_activity); 50 51 Button button = (Button) findViewById(R.id.btn_yes); 52 button.setOnClickListener(new OnClickListener() { 53 public void onClick(View v) { 54 doAnswer(true); 55 } 56 }); 57 58 button = (Button) findViewById(R.id.btn_no); 59 button.setOnClickListener(new OnClickListener() { 60 public void onClick(View v) { 61 doAnswer(false); 62 } 63 }); 64 65 mHandler = new Handler(); 66 mRunnable = new Runnable() { 67 public void run() { 68 if (LOCAL_LOGV) { 69 Log.v(TAG, "Runnable executed."); 70 } 71 doAnswer(false); 72 } 73 }; 74 75 mCreateTime = System.currentTimeMillis(); 76 } 77 78 @Override onResume()79 protected void onResume() { 80 super.onResume(); 81 82 long delay = mCreateTime - System.currentTimeMillis() 83 + (RateController.ANSWER_TIMEOUT - 500); 84 85 if (delay <= 0) { 86 doAnswer(false); 87 } else if (mHandler != null) { 88 // Close this activity after certain seconds if no user action. 89 mHandler.postDelayed(mRunnable, delay); 90 } 91 } 92 93 @Override onPause()94 protected void onPause() { 95 super.onPause(); 96 97 if (mHandler != null) { 98 mHandler.removeCallbacks(mRunnable); 99 } 100 } 101 102 @Override onKeyDown(int keyCode, KeyEvent event)103 public boolean onKeyDown(int keyCode, KeyEvent event) { 104 if ((keyCode == KeyEvent.KEYCODE_BACK) 105 && (event.getRepeatCount() == 0)) { 106 doAnswer(false); 107 } 108 return super.onKeyDown(keyCode, event); 109 } 110 doAnswer(boolean answer)111 private void doAnswer(boolean answer) { 112 Intent intent = new Intent(RATE_LIMIT_CONFIRMED_ACTION); 113 intent.putExtra("answer", answer); 114 sendBroadcast(intent); 115 finish(); 116 } 117 } 118