Home | History | Annotate | Download | only in app
      1 /*
      2  * Copyright (C) 2010 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.example.android.apis.app;
     18 
     19 import com.example.android.apis.R;
     20 
     21 import android.app.Activity;
     22 import android.app.admin.DevicePolicyManager;
     23 import android.content.pm.ActivityInfo;
     24 import android.os.Bundle;
     25 import android.view.View;
     26 import android.widget.AdapterView;
     27 import android.widget.ArrayAdapter;
     28 import android.widget.Spinner;
     29 import android.widget.AdapterView.OnItemSelectedListener;
     30 
     31 public class ScreenOrientation extends Activity {
     32     Spinner mOrientation;
     33 
     34     // Orientation spinner choices
     35     // This list must match the list found in samples/ApiDemos/res/values/arrays.xml
     36     final static int mOrientationValues[] = new int[] {
     37         ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED,
     38         ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
     39         ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
     40         ActivityInfo.SCREEN_ORIENTATION_USER,
     41         ActivityInfo.SCREEN_ORIENTATION_BEHIND,
     42         ActivityInfo.SCREEN_ORIENTATION_SENSOR,
     43         ActivityInfo.SCREEN_ORIENTATION_NOSENSOR,
     44         ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE,
     45         ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT,
     46         ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE,
     47         ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
     48         ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR,
     49         ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE,
     50         ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT,
     51         ActivityInfo.SCREEN_ORIENTATION_FULL_USER,
     52         ActivityInfo.SCREEN_ORIENTATION_LOCKED,
     53     };
     54 
     55     @Override
     56     protected void onCreate(Bundle savedInstanceState) {
     57         super.onCreate(savedInstanceState);
     58         setContentView(R.layout.screen_orientation);
     59 
     60         mOrientation = (Spinner)findViewById(R.id.orientation);
     61         ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
     62                 this, R.array.screen_orientations, android.R.layout.simple_spinner_item);
     63         adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
     64         mOrientation.setAdapter(adapter);
     65         mOrientation.setOnItemSelectedListener(
     66                 new OnItemSelectedListener() {
     67                     public void onItemSelected(
     68                             AdapterView<?> parent, View view, int position, long id) {
     69                         setRequestedOrientation(mOrientationValues[position]);
     70                     }
     71 
     72                     public void onNothingSelected(AdapterView<?> parent) {
     73                         setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
     74                     }
     75                 });
     76     }
     77 }
     78