Home | History | Annotate | Download | only in samples
      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 
     17 package com.android.imftest.samples;
     18 
     19 import android.app.Activity;
     20 import android.os.Bundle;
     21 import android.view.KeyEvent;
     22 import android.view.View;
     23 import android.widget.LinearLayout;
     24 import android.view.inputmethod.InputMethodManager;
     25 import android.widget.EditText;
     26 import android.widget.Button;
     27 import android.widget.TextView;
     28 
     29 public 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