├── .classpath
├── .gitignore
├── .project
├── AndroidManifest.xml
├── LICENSE.txt
├── README.md
├── libs
└── android-support-v4.jar
├── proguard-project.txt
├── project.properties
├── res
├── drawable-hdpi
│ ├── ic_action_search.png
│ └── ic_launcher.png
├── drawable-mdpi
│ ├── bg.png
│ ├── centerbutton.png
│ ├── ic_action_search.png
│ ├── ic_launcher.png
│ ├── icon0.png
│ ├── icon1.png
│ ├── icon2.png
│ ├── icon3.png
│ ├── icon4.png
│ ├── icon5.png
│ ├── icon6.png
│ ├── icon7.png
│ └── segment.png
├── drawable-xhdpi
│ ├── ic_action_search.png
│ └── ic_launcher.png
├── drawable
│ ├── bg.png
│ └── wheel_bg.xml
├── layout
│ ├── activity_main.xml
│ └── list_item.xml
├── menu
│ └── activity_main.xml
├── values-v11
│ └── styles.xml
├── values-v14
│ └── styles.xml
└── values
│ ├── strings.xml
│ └── styles.xml
└── src
└── com
├── activity
└── rotarywheel
│ └── MainActivity.java
└── rotarywheelview
├── RotaryWheelMenuEntry.java
├── RotaryWheelView.java
└── RotaryWheelViewListener.java
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | RotaryWheel
4 |
5 |
6 |
7 |
8 |
9 | com.android.ide.eclipse.adt.ResourceManagerBuilder
10 |
11 |
12 |
13 |
14 | com.android.ide.eclipse.adt.PreCompilerBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.jdt.core.javabuilder
20 |
21 |
22 |
23 |
24 | com.android.ide.eclipse.adt.ApkBuilder
25 |
26 |
27 |
28 |
29 |
30 | com.android.ide.eclipse.adt.AndroidNature
31 | org.eclipse.jdt.core.javanature
32 |
33 |
34 |
--------------------------------------------------------------------------------
/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
9 |
10 |
14 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright [yyyy] [name of copyright owner]
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
203 |
204 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | Android Rotary Wheel Menu
3 | -------------------------
4 |
5 | I wanted to implement a widget similar to the [Rotating Wheel Control with UIKit]( http://www.raywenderlich.com/9864/how-to-create-a-rotating-wheel-control-with-uikit )
6 | but on Android so I had to write my own, it is far from complete and it is drawn in an ugly way.
7 |
8 | But at least the main functionality that selects a sector from the pie works without any problems.
9 |
10 | Feel free to fork the project and please notify me, when you enhance it.
11 |
12 |
13 | Thanks for Jason Valestin's [radial-menu-widget](http://code.google.com/p/radial-menu-widget/) for giving me the idea of how
14 | to draw a Pie.
15 |
16 |
17 | Screenshot
18 | ----------
19 | 
20 |
--------------------------------------------------------------------------------
/libs/android-support-v4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/R4md4c/AndroidRotaryWheelView/a2d8950d6e59307a69c997acdcec2632e75057cd/libs/android-support-v4.jar
--------------------------------------------------------------------------------
/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-15
15 |
--------------------------------------------------------------------------------
/res/drawable-hdpi/ic_action_search.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/R4md4c/AndroidRotaryWheelView/a2d8950d6e59307a69c997acdcec2632e75057cd/res/drawable-hdpi/ic_action_search.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/R4md4c/AndroidRotaryWheelView/a2d8950d6e59307a69c997acdcec2632e75057cd/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/bg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/R4md4c/AndroidRotaryWheelView/a2d8950d6e59307a69c997acdcec2632e75057cd/res/drawable-mdpi/bg.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/centerbutton.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/R4md4c/AndroidRotaryWheelView/a2d8950d6e59307a69c997acdcec2632e75057cd/res/drawable-mdpi/centerbutton.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/ic_action_search.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/R4md4c/AndroidRotaryWheelView/a2d8950d6e59307a69c997acdcec2632e75057cd/res/drawable-mdpi/ic_action_search.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/R4md4c/AndroidRotaryWheelView/a2d8950d6e59307a69c997acdcec2632e75057cd/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/icon0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/R4md4c/AndroidRotaryWheelView/a2d8950d6e59307a69c997acdcec2632e75057cd/res/drawable-mdpi/icon0.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/icon1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/R4md4c/AndroidRotaryWheelView/a2d8950d6e59307a69c997acdcec2632e75057cd/res/drawable-mdpi/icon1.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/icon2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/R4md4c/AndroidRotaryWheelView/a2d8950d6e59307a69c997acdcec2632e75057cd/res/drawable-mdpi/icon2.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/icon3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/R4md4c/AndroidRotaryWheelView/a2d8950d6e59307a69c997acdcec2632e75057cd/res/drawable-mdpi/icon3.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/icon4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/R4md4c/AndroidRotaryWheelView/a2d8950d6e59307a69c997acdcec2632e75057cd/res/drawable-mdpi/icon4.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/icon5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/R4md4c/AndroidRotaryWheelView/a2d8950d6e59307a69c997acdcec2632e75057cd/res/drawable-mdpi/icon5.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/icon6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/R4md4c/AndroidRotaryWheelView/a2d8950d6e59307a69c997acdcec2632e75057cd/res/drawable-mdpi/icon6.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/icon7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/R4md4c/AndroidRotaryWheelView/a2d8950d6e59307a69c997acdcec2632e75057cd/res/drawable-mdpi/icon7.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/segment.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/R4md4c/AndroidRotaryWheelView/a2d8950d6e59307a69c997acdcec2632e75057cd/res/drawable-mdpi/segment.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/ic_action_search.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/R4md4c/AndroidRotaryWheelView/a2d8950d6e59307a69c997acdcec2632e75057cd/res/drawable-xhdpi/ic_action_search.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/R4md4c/AndroidRotaryWheelView/a2d8950d6e59307a69c997acdcec2632e75057cd/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable/bg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/R4md4c/AndroidRotaryWheelView/a2d8950d6e59307a69c997acdcec2632e75057cd/res/drawable/bg.png
--------------------------------------------------------------------------------
/res/drawable/wheel_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
23 |
24 |
25 |
31 |
32 |
33 |
34 |
39 |
40 |
46 |
47 |
53 |
54 |
--------------------------------------------------------------------------------
/res/layout/list_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
--------------------------------------------------------------------------------
/res/menu/activity_main.xml:
--------------------------------------------------------------------------------
1 |
7 |
--------------------------------------------------------------------------------
/res/values-v11/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/res/values-v14/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | RotaryWheel
4 | Hello world!
5 | Settings
6 | MainActivity
7 |
8 |
--------------------------------------------------------------------------------
/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/src/com/activity/rotarywheel/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.activity.rotarywheel;
2 |
3 | import java.util.HashMap;
4 | import java.util.List;
5 |
6 |
7 | import com.rotarywheelview.RotaryWheelMenuEntry;
8 | import com.rotarywheelview.RotaryWheelView;
9 | import com.rotarywheelview.RotaryWheelViewListener;
10 |
11 |
12 | import android.os.Bundle;
13 | import android.app.Activity;
14 | import android.graphics.Bitmap;
15 | import android.graphics.BitmapFactory;
16 | import android.graphics.Matrix;
17 | import android.view.Menu;
18 | import android.view.MotionEvent;
19 | import android.view.TextureView;
20 | import android.view.View;
21 | import android.view.View.OnTouchListener;
22 | import android.view.ViewGroup.MarginLayoutParams;
23 | import android.view.ViewTreeObserver.OnGlobalLayoutListener;
24 | import android.view.animation.RotateAnimation;
25 | import android.widget.Adapter;
26 | import android.widget.ArrayAdapter;
27 | import android.widget.BaseAdapter;
28 | import android.widget.ImageView;
29 | import android.widget.ListView;
30 | import android.widget.TextView;
31 | import android.widget.Toast;
32 |
33 | public class MainActivity extends Activity {
34 |
35 | private TextView mResultTextView;
36 | private ListView mListView;
37 |
38 | private HashMap> mHashmap = new HashMap>();
39 |
40 | private String[] mCategories = new String[] {
41 | "Fun",
42 | "Services",
43 | "Auto",
44 | "Drink",
45 | "Travel",
46 | "Urgent",
47 | "Movies",
48 | "Health",
49 | "Stores",
50 | "Favourites"
51 | };
52 | @Override
53 | public void onCreate(Bundle savedInstanceState) {
54 | super.onCreate(savedInstanceState);
55 | setContentView(R.layout.activity_main);
56 |
57 |
58 | RotaryWheelView wheelView = (RotaryWheelView) findViewById(R.id.wheelView);
59 |
60 |
61 | init();
62 |
63 | //mResultTextView = (TextView) findViewById(R.id.textView);
64 | mListView= (ListView) findViewById(R.id.listView);
65 |
66 | /*String[] values = new String[] { "Android", "iPhone", "WindowsMobile",
67 | "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X",
68 | "Linux", "OS/2" };
69 |
70 | // First paramenter - Context
71 | // Second parameter - Layout for the row
72 | // Third parameter - ID of the TextView to which the data is written
73 | // Forth - the Array of data
74 | ArrayAdapter adapter = new ArrayAdapter(this,
75 | R.layout.list_item, R.id.textView, values);
76 |
77 | // Assign adapter to ListView
78 | listView.setAdapter(adapter);*/
79 |
80 | wheelView.setRotaryWheelViewListener(new RotaryWheelViewListener() {
81 |
82 | @Override
83 | public void onMenuEntryChanged(RotaryWheelMenuEntry menuEntry) {
84 | //Toast.makeText(getApplicationContext(), menuEntry.getLabel(), Toast.LENGTH_LONG).show();
85 | //System.out.println(menuEntry.getLabel());
86 | mListView.setAdapter( mHashmap.get( menuEntry.getLabel()) );
87 | }
88 | });
89 | }
90 |
91 |
92 | private void init() {
93 | RotaryWheelView wheelView = (RotaryWheelView) findViewById(R.id.wheelView);
94 |
95 | String[] values = new String[] { "Android", "iPhone", "WindowsMobile",
96 | "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X",
97 | "Linux", "OS/2" };
98 |
99 |
100 | for(int i = 0; i < mCategories.length; i++) {
101 | String str = mCategories[i];
102 | wheelView.addMenuEntry(new MenuEntry(str, i));
103 | mHashmap.put(str, new ArrayAdapter(this,
104 | R.layout.list_item, R.id.textView, new String[] {str, values[i]}));
105 |
106 | }
107 | }
108 |
109 |
110 | @Override
111 | public boolean onCreateOptionsMenu(Menu menu) {
112 | getMenuInflater().inflate(R.menu.activity_main, menu);
113 | return true;
114 | }
115 |
116 |
117 | private static class MenuEntry implements RotaryWheelMenuEntry
118 | {
119 | private String mLabel;
120 | private int mIndex;
121 | public MenuEntry(String label, int index) {
122 | mLabel = label;
123 | mIndex = index;
124 | }
125 |
126 | public String getName() { return "Menu1 - No Children"; }
127 | public String getLabel() { return mLabel; }
128 | public int getIcon() { return R.drawable.icon0; }
129 | public int getIndex() { return mIndex; }
130 | public void menuActiviated()
131 | {
132 | System.out.println( "Menu #1 Activated - No Children");
133 | }
134 | }
135 | public static class Menu2 implements RotaryWheelMenuEntry
136 | {
137 | public int getIndex() { return 0; }
138 | public String getName() { return "Menu2 - No Children"; }
139 | public String getLabel() { return "Menu223\nTest"; }
140 | public int getIcon() { return R.drawable.icon1; }
141 | public void menuActiviated()
142 | {
143 | System.out.println( "Menu #2 Activated - No Children");
144 | }
145 | }
146 | }
147 |
--------------------------------------------------------------------------------
/src/com/rotarywheelview/RotaryWheelMenuEntry.java:
--------------------------------------------------------------------------------
1 | package com.rotarywheelview;
2 |
3 | public interface RotaryWheelMenuEntry {
4 |
5 | public String getName();
6 |
7 | public String getLabel();
8 |
9 | public int getIcon();
10 |
11 | public void menuActiviated();
12 |
13 | public int getIndex();
14 | }
15 |
--------------------------------------------------------------------------------
/src/com/rotarywheelview/RotaryWheelView.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009 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.rotarywheelview;
18 |
19 | import java.util.ArrayList;
20 | import java.util.List;
21 |
22 | import com.activity.rotarywheel.R;
23 |
24 | import android.content.Context;
25 | import android.graphics.Bitmap;
26 | import android.graphics.BitmapFactory;
27 | import android.graphics.BitmapShader;
28 | import android.graphics.Canvas;
29 | import android.graphics.Color;
30 | import android.graphics.RadialGradient;
31 | import android.graphics.Shader;
32 |
33 | import android.graphics.Matrix;
34 | import android.graphics.Paint;
35 | import android.graphics.Path;
36 | import android.graphics.Rect;
37 | import android.graphics.RectF;
38 | import android.graphics.Region;
39 | import android.graphics.drawable.Drawable;
40 | import android.graphics.drawable.shapes.ArcShape;
41 | import android.util.AttributeSet;
42 | import android.view.GestureDetector;
43 | import android.view.GestureDetector.SimpleOnGestureListener;
44 | import android.view.MotionEvent;
45 | import android.view.View;
46 |
47 |
48 |
49 | /**
50 | * Custom view that presents up to two items that are selectable by rotating a semi-circle from
51 | * left to right, or right to left. Used by incoming call screen, and the lock screen when no
52 | * security pattern is set.
53 | */
54 | public class RotaryWheelView extends View {
55 |
56 | private List mMenuEntries = new ArrayList();
57 |
58 | private RotaryWheelMenuEntry mCurrentSelection = null;
59 | private RotaryWheelViewListener mListener = null;
60 | private GestureDetector mDetector;
61 | private boolean[] mQuadrantTouched = new boolean[] { false, false, false, false, false };
62 | private boolean mAllowRotating = true;
63 | private Bitmap mBackgroundBitmap = BitmapFactory.decodeResource(getResources(), com.activity.rotarywheel.R.drawable.bg);
64 |
65 | private Shader mShader;
66 |
67 | private Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
68 | //private RadialGradient mSelectionWedgeGradient = new RadialGradient(x, y, radius, colors, positions, tile)
69 |
70 | private float screen_density = getContext().getResources().getDisplayMetrics().density;
71 |
72 | private boolean isViewInitialized;
73 |
74 | private int mMinSize = scalePX(35); //Radius of inner ring size
75 | private int mMaxSize = scalePX(90); //Radius of outer ring size
76 | private int r2MinSize = mMaxSize+scalePX(5); //Radius of inner second ring size
77 | private int r2MaxSize = r2MinSize+scalePX(45); //Radius of outer second ring size
78 | private double mStartAngle;
79 | private double mRotationAngle;
80 | private int MinIconSize = scalePX(15); //Min Size of Image in Wedge
81 | private int MaxIconSize = scalePX(20); //Max Size of Image in Wedge
82 | //private int BitmapSize = scalePX(40); //Size of Image in Wedge
83 | private int cRadius = mMinSize - scalePX(7); //Inner Circle Radius
84 | private int textSize = scalePX(10); //TextSize
85 | private int animateTextSize = textSize;
86 | private int mWedgeQty = 8;
87 | private int xPosition = scalePX(120); //Center X location of Radial Menu
88 | private int yPosition = scalePX(120); //Center Y location of Radial Menu
89 | private int outlineColor = Color.rgb(150, 150, 150); //color of outline
90 | private int outlineAlpha = 255; //transparency of outline
91 |
92 | private Wedge[] mWedges;
93 | private Wedge mSelectionWedge = null;
94 |
95 | private Rect[] iconRect;
96 | //A Rect that will hold the width and height of the View
97 | private RectF mViewRect = new RectF();
98 | private RectF mSelectionWedgeRect;
99 | private RectF mWedgeRect;
100 |
101 | private int textColor = Color.BLACK; //color to fill when something is selected
102 | private int textAlpha = 255; //transparency of fill when something is selected
103 |
104 | private int scalePX( int dp_size )
105 | {
106 | int px_size = (int) (dp_size * screen_density + 0.5f);
107 | return px_size;
108 | }
109 |
110 | private int getIconSize(int iconSize, int minSize, int maxSize) {
111 |
112 | if (iconSize > minSize) {
113 | if (iconSize > maxSize) {
114 | return maxSize;
115 | } else { //iconSize < maxSize
116 | return iconSize;
117 | }
118 | } else { //iconSize < minSize
119 | return minSize;
120 | }
121 |
122 | }
123 |
124 | public RotaryWheelView(Context context) {
125 | this(context, null);
126 | }
127 |
128 | /**
129 | * Constructor used when this widget is created from a layout file.
130 | */
131 | public RotaryWheelView(Context context, AttributeSet attrs) {
132 | super(context, attrs);
133 |
134 | mDetector = new GestureDetector(context, new MyGestureDetector());
135 |
136 |
137 | this.xPosition = (getResources().getDisplayMetrics().widthPixels)/2;
138 |
139 | this.yPosition = 0;
140 |
141 | isViewInitialized = false;
142 |
143 | setBackgroundColor(Color.CYAN);
144 | determineWedges();
145 |
146 |
147 |
148 | }
149 |
150 | private void determineWedges() {
151 | int entriesQty = mMenuEntries.size();
152 | if ( entriesQty > 0) {
153 | mWedgeQty = entriesQty;
154 |
155 | float degSlice = 360 / mWedgeQty;
156 | float start_degSlice = 270 - (degSlice/2);
157 | //calculates where to put the images
158 | double rSlice = (2*Math.PI) / mWedgeQty;
159 | double rStart = (2*Math.PI)*(0.75) ;
160 |
161 |
162 | this.mWedges = new Wedge[mWedgeQty];
163 | this.iconRect = new Rect[mWedgeQty];
164 |
165 | double mid = 0, min = 0, max = 0;
166 | for(int i = 0; i < this.mWedges.length; i++) {
167 | this.mWedges[i] = new Wedge(xPosition, yPosition, mMinSize, mMaxSize, (i
168 | * degSlice)+start_degSlice, degSlice);
169 | float xCenter = (float)(Math.cos((rSlice*i)+ rStart) * (mMaxSize+mMinSize)/2)+xPosition;
170 | float yCenter = (float)(Math.sin((rSlice*i)+rStart) * (mMaxSize+mMinSize)/2)+yPosition;
171 |
172 | mid = this.mWedges[i].midValue = normalizeAngle( ((i * degSlice) + start_degSlice + degSlice) / 2 );
173 | min = normalizeAngle( (i * degSlice) + start_degSlice );
174 | max = normalizeAngle( (i * degSlice) + start_degSlice + degSlice);
175 |
176 | this.mWedges[i].minValue = min;
177 | this.mWedges[i].midValue = mid;
178 | this.mWedges[i].maxValue = max;
179 |
180 | /*if (mWedges[i].maxValue - degSlice < - 360) {
181 | mid = 360;
182 | mWedges[i].midValue = mid;
183 | mWedges[i].minValue = Math.abs(mWedges[i].maxValue);
184 | min = mWedges[i].minValue;
185 | }*/
186 |
187 | if( i == mWedgeQty / 2) {
188 | mSelectionWedge = new Wedge(xPosition, yPosition, 0, mMaxSize, ( i * degSlice) + start_degSlice , degSlice );
189 | mSelectionWedge.midValue = mid;
190 | mSelectionWedge.minValue = min;
191 | mSelectionWedge.maxValue = max;
192 | }
193 |
194 | //mid -= degSlice;
195 |
196 |
197 | int h = MaxIconSize;
198 | int w = MaxIconSize;
199 | if ( mMenuEntries.get(i).getIcon() != 0 ) {
200 | Drawable drawable = getResources().getDrawable(mMenuEntries.get(i).getIcon());
201 | h = getIconSize(drawable.getIntrinsicHeight(),MinIconSize,MaxIconSize);
202 | w = getIconSize(drawable.getIntrinsicWidth(),MinIconSize,MaxIconSize);
203 | }
204 |
205 | this.iconRect[i] = new Rect( (int) xCenter-w/2, (int) yCenter-h/2, (int) xCenter+w/2, (int) yCenter+h/2);
206 |
207 | mViewRect.union( new RectF( mWedges[i].getWedgeRegion().getBounds() ) );
208 | }
209 |
210 | //mSelectionWedge = new Wedge(xPosition, yPosition, 0, mMaxSize, ( (mWedgeQty / 2) * degSlice) + start_degSlice + (degSlice / 4), degSlice / 2 );
211 |
212 |
213 | mSelectionWedgeRect = new RectF( mSelectionWedge.getWedgeRegion().getBounds() );
214 |
215 | mWedgeRect = new RectF();
216 |
217 | //Reduce the selectionWedge region with 50% to be fully contained inside the other wedges
218 | Region selectionWedgeRegion = mSelectionWedge.getWedgeRegion();
219 | Rect r = selectionWedgeRegion.getBounds();
220 | selectionWedgeRegion.set(r.left + scalePX(20), r.top + (r.height() / 2) , r.right - scalePX(20), r.bottom - scalePX(6));
221 |
222 | mShader = new RadialGradient(xPosition, yPosition, mMaxSize, new int[] { 0xff595756, 0xffCCC5C3, 0xf878280}, null, Shader.TileMode.MIRROR);
223 | //mShader = new BitmapShader(BitmapFactory.decodeResource(getResources(), R.drawable.segment), Shader.TileMode.MIRROR, Shader.TileMode.MIRROR);
224 | //this.setBackgroundResource(com.activity.rotarywheel.R.drawable.bg);
225 | invalidate();
226 |
227 |
228 | }
229 | }
230 |
231 | @Override
232 | public void onDraw(Canvas canvas) {
233 | mPaint.setColor(Color.RED);
234 |
235 | //canvas.save();
236 |
237 | canvas.scale(getWidth() / mViewRect.width(), getHeight() / mViewRect.width(), xPosition, yPosition);
238 | //canvas.getMatrix().mapRect(mViewRect);
239 | //System.out.println(mViewRect);
240 |
241 |
242 | //canvas.drawRect(mViewRect, mPaint);
243 | canvas.save(Canvas.MATRIX_SAVE_FLAG); //Saving the canvas and later restoring it so only this image will be rotated.
244 | canvas.rotate((float)mRotationAngle, xPosition, yPosition);
245 |
246 |
247 | //System.out.println(normalizeAngle( mRotationAngle) );
248 |
249 | //double rotation = normalizeAngle(mRotationAngle);
250 |
251 | for (int i = 0; i < mWedges.length; i++) {
252 | Wedge f = mWedges[i];
253 |
254 | /*System.out.println(rotation);
255 | f.minValue += rotation;
256 | f.midValue += rotation;
257 | f.maxValue += rotation;*/
258 |
259 | mPaint.setColor(0xffBFBFBF);
260 | //mPaint.setAlpha(outlineAlpha);
261 | mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
262 | canvas.drawPath(f, mPaint);
263 | //canvas.drawRect(f.getWedgeRegion().getBounds(), mPaint);
264 | Rect rf = iconRect[i];
265 |
266 | //canvas.save();
267 | //canvas.scale(1.0f, 1.0f, xPosition, yPosition);
268 | if ((mMenuEntries.get(i).getIcon() != 0) && (mMenuEntries.get(i).getLabel() != null)) {
269 |
270 | //This will look for a "new line" and split into multiple lines
271 | String menuItemName = mMenuEntries.get(i).getLabel();
272 | String[] stringArray = menuItemName.split("\n");
273 |
274 | mPaint.setColor(textColor);
275 |
276 | mPaint.setStyle(Paint.Style.FILL);
277 | mPaint.setTextSize(textSize);
278 |
279 | Rect rect = new Rect();
280 | float textHeight = 0;
281 | for (int j = 0; j < stringArray.length; j++) {
282 | mPaint.getTextBounds(stringArray[j],0,stringArray[j].length(),rect);
283 | textHeight = textHeight+(rect.height()+3);
284 | }
285 |
286 | Rect rf2 = new Rect();
287 | rf2.set(rf.left, rf.top-((int)textHeight/2), rf.right, rf.bottom-((int)textHeight/2));
288 |
289 | float textBottom = rf2.bottom;
290 | for (int j = 0; j < stringArray.length; j++) {
291 | mPaint.getTextBounds(stringArray[j],0,stringArray[j].length(),rect);
292 | float textLeft = rf.centerX() - rect.width()/2;
293 | textBottom = textBottom + (rect.height()+3);
294 | canvas.drawText(stringArray[j], textLeft-rect.left, textBottom-rect.bottom, mPaint);
295 | }
296 |
297 | //Puts in the Icon
298 | Drawable drawable = getResources().getDrawable(mMenuEntries.get(i).getIcon());
299 | drawable.setBounds(rf2);
300 |
301 | drawable.draw(canvas);
302 |
303 | //Icon Only
304 | } else if (mMenuEntries.get(i).getIcon() != 0) {
305 |
306 | //Puts in the Icon
307 | Drawable drawable = getResources().getDrawable(mMenuEntries.get(i).getIcon());
308 | drawable.setBounds(rf);
309 |
310 | drawable.draw(canvas);
311 |
312 | //Text Only
313 | } else {
314 | //Puts in the Text if no Icon
315 | mPaint.setColor(this.textColor);
316 |
317 | /*if (f != enabled && Wedge2Shown == true) {
318 | mPaint.setAlpha(disabledAlpha);
319 | } else {
320 | mPaint.setAlpha(textAlpha);
321 | }*/
322 | mPaint.setAlpha(textAlpha);
323 | mPaint.setStyle(Paint.Style.FILL);
324 | mPaint.setTextSize(textSize);
325 |
326 | //This will look for a "new line" and split into multiple lines
327 | String menuItemName = mMenuEntries.get(i).getLabel();
328 | String[] stringArray = menuItemName.split("\n");
329 |
330 |
331 | //gets total height
332 | Rect rect = new Rect();
333 | float textHeight = 0;
334 | for (int j = 0; j < stringArray.length; j++) {
335 | mPaint.getTextBounds(stringArray[j],0,stringArray[j].length(),rect);
336 | textHeight = textHeight+(rect.height()+3);
337 | }
338 |
339 |
340 |
341 | float textBottom = rf.centerY()-(textHeight/2);
342 | for (int j = 0; j < stringArray.length; j++) {
343 | mPaint.getTextBounds(stringArray[j],0,stringArray[j].length(),rect);
344 | float textLeft = rf.centerX() - rect.width()/2;
345 | textBottom = textBottom + (rect.height()+3);
346 | canvas.drawText(stringArray[j], textLeft-rect.left, textBottom-rect.bottom, mPaint);
347 |
348 | }
349 |
350 |
351 | //canvas.drawTextOnPath(text, path, hOffset, vOffset, paint)
352 | //canvas.rotate((float)mRotationAngle, xPosition, yPosition );
353 | //canvas.drawRect(rf, mPaint);
354 |
355 | }
356 |
357 | //canvas.restore();
358 |
359 | }
360 |
361 | //canvas.restore();
362 |
363 | canvas.restore();
364 |
365 |
366 | //System.out.println()
367 | canvas.save();
368 | //canvas.scale(mViewRect.width() / mBackgroundBitmap.getWidth(), (mViewRect.height() / mBackgroundBitmap.getHeight()) * 2, mViewRect.left, mViewRect.top);
369 | //canvas.drawBitmap(mBackgroundBitmap, mViewRect.left, mViewRect.top , mPaint);
370 | canvas.restore();
371 |
372 |
373 |
374 | //mPaint.setShader( new LinearGradient(0, 0, 0, getHeight(),
375 | //new int[] { 0xff514E4D, 0xff98908F, 0x00908988}, null, Shader.TileMode.MIRROR));
376 |
377 | mPaint.setShader( mShader );
378 | //mPaint.setAlpha(0x66);
379 | //Draw the Selection Segment
380 | if(mSelectionWedge != null) {
381 | canvas.drawPath(mSelectionWedge, mPaint);
382 | //canvas.drawRect(mSelectionWedge.getWedgeRegion().getBounds(), mPaint);
383 | }
384 |
385 | mPaint.setShader(null);
386 |
387 | checkSelection(canvas);
388 | }
389 |
390 |
391 | private double normalizeAngle(double angle) {
392 | if(angle >= 0) {
393 | while( angle > 360 ) {
394 | angle -= 360;
395 | }
396 | }
397 | else {
398 | while( angle < -360) {
399 | angle += 360;
400 | }
401 | }
402 | return angle;
403 | }
404 |
405 | private void checkSelection(Canvas canvas) {
406 | Matrix cmt = new Matrix();
407 | cmt.postRotate((float)mRotationAngle, xPosition, yPosition);
408 |
409 | RectF f = new RectF();
410 | mSelectionWedgeRect.set( mSelectionWedge.getWedgeRegion().getBounds() );
411 | for(int i = 0; i < mWedges.length; i++) {
412 | //mWedgeRect.set( mWedges[i].getWedgeRegion().getBounds() );
413 | mWedges[i].computeBounds(mWedgeRect, true);
414 |
415 | mWedgeRect.inset(6, 6);
416 | cmt.mapRect(mWedgeRect);
417 | //mPaint.setColor(Color.BLACK);
418 | //canvas.drawRect(mWedgeRect, mPaint);
419 | mPaint.setColor(Color.RED);
420 | canvas.drawRect(mSelectionWedgeRect, mPaint);
421 | if( mWedgeRect.contains(mSelectionWedgeRect) ) {
422 | if(mListener != null) {
423 | if(mCurrentSelection != mMenuEntries.get(i)) {
424 | mListener.onMenuEntryChanged(mMenuEntries.get(i));
425 | mCurrentSelection = mMenuEntries.get(i);
426 | System.out.println(mWedges[i]);
427 | System.out.println(mSelectionWedge);
428 | //mRotationAngle += mSelectionWedge.midValue - mWedges[i].midValue;
429 | }
430 | }
431 | }
432 | }
433 | }
434 |
435 | public void setRotaryWheelViewListener(RotaryWheelViewListener listener) {
436 | mListener = listener;
437 | }
438 |
439 |
440 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
441 | // TODO Auto-generated method stub
442 | // super.onMeasure(widthMeasureSpec, heightMeasureSpec);
443 | int wmode = MeasureSpec.getMode(widthMeasureSpec);
444 | int hmode = MeasureSpec.getMode(heightMeasureSpec);
445 | int wsize = MeasureSpec.getSize(widthMeasureSpec);
446 | int hsize = MeasureSpec.getSize(heightMeasureSpec);
447 |
448 | int width = (int)mViewRect.width();
449 | int height = (int) mViewRect.height();
450 |
451 | if (wmode == MeasureSpec.EXACTLY) {
452 | width = wsize;
453 | }
454 | if (hmode == MeasureSpec.EXACTLY) {
455 | height = hsize;
456 | }
457 |
458 | //this.xPosition = width / 2;
459 | //this.yPosition = height / 2;
460 |
461 | this.setMeasuredDimension(width, height - height / 2);
462 |
463 | invalidate();
464 |
465 | }
466 |
467 | @Override
468 | public boolean onTouchEvent(MotionEvent e) {
469 | int state = e.getAction();
470 | int eventX = (int) e.getX();
471 | int eventY = (int) e.getY();
472 |
473 |
474 | switch(state) {
475 | case MotionEvent.ACTION_DOWN:
476 | // reset the touched quadrants
477 | for (int i = 0; i < mQuadrantTouched.length; i++) {
478 | mQuadrantTouched[i] = false;
479 | }
480 |
481 | mStartAngle = getAngle(eventX, eventY);
482 |
483 |
484 | mAllowRotating = false;
485 | break;
486 | case MotionEvent.ACTION_MOVE:
487 | double currentAngle = getAngle(eventX, eventY);
488 | mRotationAngle += mStartAngle - currentAngle;
489 | mStartAngle = currentAngle;
490 |
491 | for(Wedge w : mWedges) {
492 | w.minValue += normalizeAngle(mRotationAngle);
493 | w.midValue += normalizeAngle(mRotationAngle);
494 | w.maxValue += normalizeAngle(mRotationAngle);
495 | }
496 | break;
497 | case MotionEvent.ACTION_UP:
498 | mAllowRotating = true;
499 | break;
500 | }
501 |
502 | mQuadrantTouched[getQuadrant(e.getX() - (mViewRect.width() / 2), mViewRect.height() - e.getY() - (mViewRect.height() / 2))] = true;
503 | mDetector.onTouchEvent(e);
504 |
505 | invalidate();
506 | return true;
507 | }
508 |
509 | private class Wedge extends Path {
510 | private int x, y;
511 | private int InnerSize, OuterSize;
512 | private float StartArc;
513 | private float ArcWidth;
514 | private Region mWedgeRegion;
515 |
516 | public double minValue;
517 | public double midValue;
518 | public double maxValue;
519 |
520 | private Wedge(int x, int y, int InnerSize, int OuterSize, float StartArc, float ArcWidth) {
521 | super();
522 |
523 | if (StartArc >= 360) {
524 | StartArc = StartArc-360;
525 | }
526 |
527 | minValue = midValue = maxValue = 0;
528 | mWedgeRegion = new Region();
529 | this.x = x; this.y = y;
530 | this.InnerSize = InnerSize;
531 | this.OuterSize = OuterSize;
532 | this.StartArc = StartArc;
533 | this.ArcWidth = ArcWidth;
534 | this.buildPath();
535 | }
536 |
537 | public String toString() {
538 | return minValue + " " + midValue + " " + maxValue;
539 | }
540 | /**
541 | *
542 | * @return the bottom rect that will be used for intersection
543 | */
544 | public Region getWedgeRegion() {
545 | return mWedgeRegion;
546 | }
547 |
548 | private void buildPath() {
549 |
550 | final RectF rect = new RectF();
551 | final RectF rect2 = new RectF();
552 |
553 | //Rectangles values
554 | rect.set(this.x-this.InnerSize, this.y-this.InnerSize, this.x+this.InnerSize, this.y+this.InnerSize);
555 | rect2.set(this.x-this.OuterSize, this.y-this.OuterSize, this.x+this.OuterSize, this.y+this.OuterSize);
556 |
557 |
558 | this.reset();
559 | //this.moveTo(100, 100);
560 | this.arcTo(rect2, StartArc, ArcWidth);
561 | this.arcTo(rect, StartArc+ArcWidth, -ArcWidth);
562 |
563 | this.close();
564 |
565 |
566 | mWedgeRegion.setPath( this, new Region(0,0,480,800) );
567 |
568 | }
569 | }
570 |
571 | public boolean addMenuEntry(RotaryWheelMenuEntry menuEntry) {
572 | mMenuEntries.add(menuEntry);
573 | determineWedges();
574 |
575 | return true;
576 | }
577 |
578 |
579 |
580 | /**
581 | * @return The angle of the unit circle with the image view's center
582 | */
583 | private double getAngle(double xTouch, double yTouch) {
584 | double x = xTouch - (mViewRect.width() / 2d);
585 | double y = mViewRect.height() - yTouch - (mViewRect.height() / 2d);
586 | switch (getQuadrant(x, y)) {
587 | case 1:
588 | return Math.asin(y / Math.hypot(x, y)) * 180 / Math.PI;
589 | case 2:
590 | return 180 - Math.asin(y / Math.hypot(x, y)) * 180 / Math.PI;
591 | case 3:
592 | return 180 + (-1 * Math.asin(y / Math.hypot(x, y)) * 180 / Math.PI);
593 | case 4:
594 | return 360 + Math.asin(y / Math.hypot(x, y)) * 180 / Math.PI;
595 | default:
596 | return 0;
597 | }
598 | }
599 | /**
600 | * @return The selected quadrant.
601 | */
602 | private static int getQuadrant(double x, double y) {
603 | if (x >= 0) {
604 | return y >= 0 ? 1 : 4;
605 | } else {
606 | return y >= 0 ? 2 : 3;
607 | }
608 | }
609 |
610 | private class MyGestureDetector extends SimpleOnGestureListener {
611 |
612 | @Override
613 | public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
614 | // get the quadrant of the start and the end of the fling
615 | int q1 = getQuadrant(e1.getX() - (mViewRect.width() / 2), mViewRect.height() - e1.getY() - (mViewRect.height() / 2));
616 | int q2 = getQuadrant(e2.getX() - (mViewRect.width() / 2), mViewRect.height() - e2.getY() - (mViewRect.height() / 2));
617 | // the inversed rotations
618 | if ((q1 == 2 && q2 == 2 && Math.abs(velocityX) < Math.abs(velocityY))
619 | || (q1 == 3 && q2 == 3)
620 | || (q1 == 1 && q2 == 3)
621 | || (q1 == 4 && q2 == 4 && Math.abs(velocityX) > Math.abs(velocityY))
622 | || ((q1 == 2 && q2 == 3) || (q1 == 3 && q2 == 2))
623 | || ((q1 == 3 && q2 == 4) || (q1 == 4 && q2 == 3))
624 | || (q1 == 2 && q2 == 4 && mQuadrantTouched[3])
625 | || (q1 == 4 && q2 == 2 && mQuadrantTouched[3]) ) {
626 | RotaryWheelView.this.post(new FlingRunnable(-1 * (velocityX + velocityY)));
627 | } else {
628 |
629 | // the normal rotation
630 | RotaryWheelView.this.post(new FlingRunnable(velocityX + velocityY));
631 | }
632 | return true;
633 | }
634 | }
635 |
636 | /**
637 | * A {@link Runnable} for animating the the dialer's fling.
638 | */
639 | private class FlingRunnable implements Runnable {
640 | private float velocity;
641 | public FlingRunnable(float velocity) {
642 | this.velocity = velocity;
643 | }
644 | @Override
645 | public void run() {
646 | if (Math.abs(velocity) > 5 && mAllowRotating) {
647 | mRotationAngle += velocity / 75;
648 | invalidate();
649 | velocity /= 1.0666F;
650 | // post this instance again
651 | RotaryWheelView.this.post(this);
652 | }
653 | }
654 | }
655 |
656 | }
--------------------------------------------------------------------------------
/src/com/rotarywheelview/RotaryWheelViewListener.java:
--------------------------------------------------------------------------------
1 | package com.rotarywheelview;
2 |
3 | public interface RotaryWheelViewListener {
4 | void onMenuEntryChanged( RotaryWheelMenuEntry menuEntry);
5 | }
6 |
--------------------------------------------------------------------------------