1 /* 2 * Copyright (C) 2013 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.os.Bundle; 23 import android.view.Window; 24 import android.view.WindowManager; 25 import android.view.WindowManager.LayoutParams; 26 import android.widget.CheckBox; 27 import android.widget.CompoundButton; 28 import android.widget.RadioGroup; 29 30 31 public class RotationAnimation extends Activity { 32 33 private int mRotationAnimation = LayoutParams.ROTATION_ANIMATION_ROTATE; 34 35 @Override 36 protected void onCreate(Bundle savedInstanceState) { 37 super.onCreate(savedInstanceState); 38 39 setRotationAnimation(mRotationAnimation); 40 41 setContentView(R.layout.rotation_animation); 42 43 ((CheckBox)findViewById(R.id.windowFullscreen)).setOnCheckedChangeListener( 44 new CompoundButton.OnCheckedChangeListener() { 45 @Override 46 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 47 setFullscreen(isChecked); 48 } 49 } 50 ); 51 52 ((RadioGroup)findViewById(R.id.rotation_radio_group)).setOnCheckedChangeListener( 53 new RadioGroup.OnCheckedChangeListener() { 54 @Override 55 public void onCheckedChanged(RadioGroup group, int checkedId) { 56 switch (checkedId) { 57 default: 58 case R.id.rotate: 59 mRotationAnimation = LayoutParams.ROTATION_ANIMATION_ROTATE; 60 break; 61 case R.id.crossfade: 62 mRotationAnimation = LayoutParams.ROTATION_ANIMATION_CROSSFADE; 63 break; 64 case R.id.jumpcut: 65 mRotationAnimation = LayoutParams.ROTATION_ANIMATION_JUMPCUT; 66 break; 67 } 68 setRotationAnimation(mRotationAnimation); 69 } 70 } 71 ); 72 } 73 74 private void setFullscreen(boolean on) { 75 Window win = getWindow(); 76 WindowManager.LayoutParams winParams = win.getAttributes(); 77 if (on) { 78 winParams.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN; 79 } else { 80 winParams.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN; 81 } 82 win.setAttributes(winParams); 83 } 84 85 private void setRotationAnimation(int rotationAnimation) { 86 Window win = getWindow(); 87 WindowManager.LayoutParams winParams = win.getAttributes(); 88 winParams.rotationAnimation = rotationAnimation; 89 win.setAttributes(winParams); 90 } 91 } 92