• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007 Esmertec AG.
3  * Copyright (C) 2007 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.im.app;
19 
20 import android.app.Activity;
21 import android.content.Intent;
22 import android.os.Bundle;
23 import android.view.View;
24 import android.view.ViewGroup.LayoutParams;
25 import android.widget.Button;
26 import android.widget.EditText;
27 import android.widget.TextView;
28 
29 import com.android.im.R;
30 
31 public class SimpleInputActivity extends Activity {
32 
33     public static final String EXTRA_TITLE = "title";
34     public static final String EXTRA_PROMPT = "prompt";
35     public static final String EXTRA_DEFAULT_CONTENT = "content";
36     public static final String EXTRA_OK_BUTTON_TEXT = "button_ok";
37 
38     TextView mPrompt;
39     EditText mEdit;
40     Button mBtnOk;
41     Button mBtnCancel;
42 
43     @Override
onCreate(Bundle icicle)44     public void onCreate(Bundle icicle) {
45         super.onCreate(icicle);
46 
47         setTheme(android.R.style.Theme_Dialog);
48         setContentView(R.layout.simple_input_activity);
49 
50         Bundle extras = getIntent().getExtras();
51 
52         CharSequence title = extras.getCharSequence(EXTRA_TITLE);
53         if (title != null) {
54             setTitle(title);
55         } else {
56             setTitle(R.string.default_input_title);
57         }
58 
59         CharSequence prompt = extras.getCharSequence(EXTRA_PROMPT);
60         mPrompt = (TextView) findViewById(R.id.prompt);
61         if (prompt != null) {
62             mPrompt.setText(prompt);
63         } else {
64             mPrompt.setVisibility(View.GONE);
65         }
66 
67         mEdit = (EditText) findViewById(R.id.edit);
68         CharSequence defaultText = extras.getCharSequence(EXTRA_DEFAULT_CONTENT);
69         if (defaultText != null) {
70             mEdit.setText(defaultText);
71         }
72 
73         mBtnOk = (Button) findViewById(R.id.btnOk);
74         mBtnOk.setOnClickListener(new Button.OnClickListener() {
75             public void onClick(View v) {
76                 setResult(RESULT_OK,
77                         (new Intent()).setAction(mEdit.getText().toString()));
78                 finish();
79             }
80         });
81         CharSequence okText = extras.getCharSequence(EXTRA_OK_BUTTON_TEXT);
82         if (okText != null) {
83             mBtnOk.setText(okText);
84         }
85 
86         mBtnCancel = (Button) findViewById(R.id.btnCancel);
87         mBtnCancel.setOnClickListener(new Button.OnClickListener() {
88             public void onClick(View v) {
89                 finish();
90             }
91         });
92 
93         // XXX Hack from GoogleLogin.java. The android:layout_width="fill_parent"
94         // defined in the layout xml doesn't seem to work for LinearLayout.
95         getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
96     }
97 
98 }
99