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.phone;
18 
19 import android.app.Activity;
20 import android.app.NotificationManager;
21 import android.os.Bundle;
22 import android.util.Log;
23 import android.view.View;
24 import android.view.View.OnClickListener;
25 import android.widget.Button;
26 import android.widget.EditText;
27 import android.widget.Toast;
28 
29 import com.android.internal.telephony.test.SimulatedRadioControl;
30 
31 /**
32  * A simple activity that presents you with a UI for faking incoming phone operations.
33  */
34 public class FakePhoneActivity extends Activity {
35     private static final String TAG = "FakePhoneActivity";
36 
37     private Button mPlaceCall;
38     private EditText mPhoneNumber;
39     SimulatedRadioControl mRadioControl;
40 
41     @Override
onCreate(Bundle icicle)42     public void onCreate(Bundle icicle) {
43         super.onCreate(icicle);
44 
45         setContentView(R.layout.fake_phone_activity);
46 
47         mPlaceCall = (Button) findViewById(R.id.placeCall);
48         mPlaceCall.setOnClickListener(new ButtonListener());
49 
50         mPhoneNumber = (EditText) findViewById(R.id.phoneNumber);
51         mPhoneNumber.setOnClickListener(
52                 new View.OnClickListener() {
53                     public void onClick(View v) {
54                         mPlaceCall.requestFocus();
55                     }
56                 });
57 
58         mRadioControl = PhoneGlobals.getPhone().getSimulatedRadioControl();
59 
60         Log.i(TAG, "- PhoneApp.getInstance(): " + PhoneGlobals.getInstance());
61         Log.i(TAG, "- PhoneApp.getPhone(): " + PhoneGlobals.getPhone());
62         Log.i(TAG, "- mRadioControl: " + mRadioControl);
63     }
64 
65     private class ButtonListener implements OnClickListener {
onClick(View v)66         public void onClick(View v) {
67             if (mRadioControl == null) {
68                 Log.e("Phone", "SimulatedRadioControl not available, abort!");
69                 NotificationManager nm =
70                         (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
71                 Toast.makeText(FakePhoneActivity.this, "null mRadioControl!",
72                         Toast.LENGTH_SHORT).show();
73                 return;
74             }
75 
76             mRadioControl.triggerRing(mPhoneNumber.getText().toString());
77         }
78     }
79 }
80