• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
onCreate(Bundle savedInstanceState)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                         case R.id.seamless:
68                             mRotationAnimation = LayoutParams.ROTATION_ANIMATION_SEAMLESS;
69                             break;
70                     }
71                     setRotationAnimation(mRotationAnimation);
72                 }
73             }
74         );
75     }
76 
setFullscreen(boolean on)77     private void setFullscreen(boolean on) {
78         Window win = getWindow();
79         WindowManager.LayoutParams winParams = win.getAttributes();
80         if (on) {
81             winParams.flags |=  WindowManager.LayoutParams.FLAG_FULLSCREEN;
82         } else {
83             winParams.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
84         }
85         win.setAttributes(winParams);
86     }
87 
setRotationAnimation(int rotationAnimation)88     private void setRotationAnimation(int rotationAnimation) {
89         Window win = getWindow();
90         WindowManager.LayoutParams winParams = win.getAttributes();
91         winParams.rotationAnimation = rotationAnimation;
92         win.setAttributes(winParams);
93     }
94 }
95