Home | History | Annotate | Download | only in app
      1 package com.example.android.apis.app;
      2 
      3 import com.example.android.apis.R;
      4 
      5 import android.app.Activity;
      6 import android.app.admin.DevicePolicyManager;
      7 import android.content.SharedPreferences;
      8 import android.os.Bundle;
      9 import android.view.View;
     10 import android.view.WindowManager;
     11 import android.widget.AdapterView;
     12 import android.widget.ArrayAdapter;
     13 import android.widget.EditText;
     14 import android.widget.Spinner;
     15 import android.widget.TextView;
     16 import android.widget.AdapterView.OnItemSelectedListener;
     17 
     18 /**
     19  * Demonstrates how the various soft input modes impact window resizing.
     20  */
     21 public class SoftInputModes extends Activity {
     22     Spinner mResizeMode;
     23     final CharSequence[] mResizeModeLabels = new CharSequence[] {
     24             "Unspecified", "Resize", "Pan", "Nothing"
     25     };
     26     final int[] mResizeModeValues = new int[] {
     27             WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED,
     28             WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE,
     29             WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN,
     30             WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING,
     31     };
     32 
     33     /**
     34      * Initialization of the Activity after it is first created.  Here we use
     35      * {@link android.app.Activity#setContentView setContentView()} to set up
     36      * the Activity's content, and retrieve the EditText widget whose state we
     37      * will persistent.
     38      */
     39     @Override
     40     protected void onCreate(Bundle savedInstanceState) {
     41         // Be sure to call the super class.
     42         super.onCreate(savedInstanceState);
     43 
     44         // See assets/res/any/layout/save_restore_state.xml for this
     45         // view layout definition, which is being set here as
     46         // the content of our screen.
     47         setContentView(R.layout.soft_input_modes);
     48 
     49         mResizeMode = (Spinner)findViewById(R.id.resize_mode);
     50         ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(this,
     51                 android.R.layout.simple_spinner_item, mResizeModeLabels);
     52         adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
     53         mResizeMode.setAdapter(adapter);
     54         mResizeMode.setSelection(0);
     55         mResizeMode.setOnItemSelectedListener(
     56                 new OnItemSelectedListener() {
     57                     public void onItemSelected(
     58                             AdapterView<?> parent, View view, int position, long id) {
     59                         getWindow().setSoftInputMode(mResizeModeValues[position]);
     60                     }
     61 
     62                     public void onNothingSelected(AdapterView<?> parent) {
     63                         getWindow().setSoftInputMode(mResizeModeValues[0]);
     64                     }
     65                 });
     66     }
     67 }
     68