1/*
2 * Copyright (C) 2009 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
17package com.android.imftest.samples;
18
19import android.app.Activity;
20import android.os.Bundle;
21import android.view.KeyEvent;
22import android.view.View;
23import android.widget.LinearLayout;
24import android.view.inputmethod.InputMethodManager;
25import android.widget.EditText;
26import android.widget.Button;
27import android.widget.TextView;
28
29public class ButtonActivity extends Activity
30{
31    static boolean mKeyboardIsActive = false;
32    public static final int BUTTON_ID = 0;
33    private View mRootView;
34
35    @Override
36    public void onCreate(Bundle savedInstanceState)
37    {
38        super.onCreate(savedInstanceState);
39        final ButtonActivity instance = this;
40
41        final Button myButton = new Button(this);
42        myButton.setClickable(true);
43        myButton.setText("Keyboard UP!");
44        myButton.setId(BUTTON_ID);
45        myButton.setFocusableInTouchMode(true);
46        myButton.setOnClickListener(new View.OnClickListener()
47        {
48            public void onClick (View v)
49            {
50                InputMethodManager imm = InputMethodManager.getInstance();
51                if (mKeyboardIsActive)
52                {
53                    imm.hideSoftInputFromInputMethod(v.getWindowToken(), 0);
54                    myButton.setText("Keyboard UP!");
55
56                }
57                else
58                {
59                    myButton.requestFocusFromTouch();
60                    imm.showSoftInput(v, 0);
61                    myButton.setText("Keyboard DOWN!");
62                }
63
64                mKeyboardIsActive = !mKeyboardIsActive;
65            }
66        });
67
68       LinearLayout layout = new LinearLayout(this);
69       layout.setOrientation(LinearLayout.VERTICAL);
70       layout.addView(myButton);
71       setContentView(layout);
72       mRootView = layout;
73    }
74
75    public View getRootView() {
76        return mRootView;
77    }
78}
79