• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.view;
18 
19 // Need the following import to get access to the app resources, since this
20 // class is in a sub-package.
21 import com.example.android.apis.R;
22 
23 import android.app.Activity;
24 import android.os.Bundle;
25 import android.widget.Button;
26 import android.widget.SeekBar;
27 
28 /**
29  * This application demonstrates the ability to transform views in 2D and 3D, scaling them,
30  * translating them, and rotating them (in 2D and 3D). Use the seek bars to set the various
31  * transform properties of the button.
32  */
33 public class RotatingButton extends Activity {
34 
35     /** Called when the activity is first created. */
36     @Override
onCreate(Bundle savedInstanceState)37     public void onCreate(Bundle savedInstanceState) {
38         super.onCreate(savedInstanceState);
39         setContentView(R.layout.rotating_view);
40         final Button rotatingButton = (Button) findViewById(R.id.rotatingButton);
41         SeekBar seekBar;
42         seekBar = (SeekBar) findViewById(R.id.translationX);
43         seekBar.setMax(400);
44         seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
45             public void onStopTrackingTouch(SeekBar seekBar) {
46             }
47 
48             public void onStartTrackingTouch(SeekBar seekBar) {
49             }
50 
51             public void onProgressChanged(SeekBar seekBar, int progress,
52                     boolean fromUser) {
53                 rotatingButton.setTranslationX((float)progress);
54             }
55         });
56         seekBar = (SeekBar) findViewById(R.id.translationY);
57         seekBar.setMax(800);
58         seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
59 
60             public void onStopTrackingTouch(SeekBar seekBar) {
61             }
62 
63             public void onStartTrackingTouch(SeekBar seekBar) {
64             }
65 
66             public void onProgressChanged(SeekBar seekBar, int progress,
67                     boolean fromUser) {
68                 rotatingButton.setTranslationY((float)progress);
69             }
70         });
71         seekBar = (SeekBar) findViewById(R.id.scaleX);
72         seekBar.setMax(50);
73         seekBar.setProgress(10);
74         seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
75 
76             public void onStopTrackingTouch(SeekBar seekBar) {
77             }
78 
79             public void onStartTrackingTouch(SeekBar seekBar) {
80             }
81 
82             public void onProgressChanged(SeekBar seekBar, int progress,
83                     boolean fromUser) {
84                 rotatingButton.setScaleX((float)progress/10f);
85             }
86         });
87         seekBar = (SeekBar) findViewById(R.id.scaleY);
88         seekBar.setMax(50);
89         seekBar.setProgress(10);
90         seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
91 
92             public void onStopTrackingTouch(SeekBar seekBar) {
93             }
94 
95             public void onStartTrackingTouch(SeekBar seekBar) {
96             }
97 
98             public void onProgressChanged(SeekBar seekBar, int progress,
99                     boolean fromUser) {
100                 rotatingButton.setScaleY((float)progress/10f);
101             }
102         });
103         seekBar = (SeekBar) findViewById(R.id.rotationX);
104         seekBar.setMax(360);
105         seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
106 
107             public void onStopTrackingTouch(SeekBar seekBar) {
108             }
109 
110             public void onStartTrackingTouch(SeekBar seekBar) {
111             }
112 
113             public void onProgressChanged(SeekBar seekBar, int progress,
114                     boolean fromUser) {
115                 // prevent seeking on app creation
116                 rotatingButton.setRotationX((float)progress);
117             }
118         });
119         seekBar = (SeekBar) findViewById(R.id.rotationY);
120         seekBar.setMax(360);
121         seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
122 
123             public void onStopTrackingTouch(SeekBar seekBar) {
124             }
125 
126             public void onStartTrackingTouch(SeekBar seekBar) {
127             }
128 
129             public void onProgressChanged(SeekBar seekBar, int progress,
130                     boolean fromUser) {
131                 // prevent seeking on app creation
132                 rotatingButton.setRotationY((float)progress);
133             }
134         });
135         seekBar = (SeekBar) findViewById(R.id.rotationZ);
136         seekBar.setMax(360);
137         seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
138 
139             public void onStopTrackingTouch(SeekBar seekBar) {
140             }
141 
142             public void onStartTrackingTouch(SeekBar seekBar) {
143             }
144 
145             public void onProgressChanged(SeekBar seekBar, int progress,
146                     boolean fromUser) {
147                 // prevent seeking on app creation
148                 rotatingButton.setRotation((float)progress);
149             }
150         });
151     }
152 }