9 |
--------------------------------------------------------------------------------
/RotateDemo/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
8 |
--------------------------------------------------------------------------------
/RotateView/src/main/res/values-v11/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/RotateDemo/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/RotateView/src/main/res/values-v14/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/RotateView/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | mavenCentral()
4 | }
5 | dependencies {
6 | classpath 'com.android.tools.build:gradle:0.6.+'
7 | }
8 | }
9 | apply plugin: 'android-library'
10 |
11 | repositories {
12 | mavenCentral()
13 | }
14 |
15 | android {
16 | compileSdkVersion 18
17 | buildToolsVersion "17.0.0"
18 |
19 | defaultConfig {
20 | minSdkVersion 7
21 | targetSdkVersion 18
22 | }
23 | }
24 |
25 | dependencies {
26 | }
27 |
--------------------------------------------------------------------------------
/RotateView/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
8 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/RotateDemo/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | mavenCentral()
4 | }
5 | dependencies {
6 | classpath 'com.android.tools.build:gradle:0.6.+'
7 | }
8 | }
9 | apply plugin: 'android'
10 |
11 | repositories {
12 | mavenCentral()
13 | }
14 |
15 | android {
16 | compileSdkVersion 18
17 | buildToolsVersion "17.0.0"
18 |
19 | defaultConfig {
20 | minSdkVersion 7
21 | targetSdkVersion 18
22 | }
23 | }
24 |
25 | dependencies {
26 | compile 'com.android.support:appcompat-v7:+'
27 | compile project (':RotateView')
28 | }
29 |
--------------------------------------------------------------------------------
/RotateDemo/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | RotateDemo
5 | Settings
6 | This application is demo for RotateView usage.\nClick the button to start/stop animation of RotateView
7 | Reset
8 | Start
9 | Stop
10 | No need to reset.
11 | Reset sucess.
12 |
13 |
--------------------------------------------------------------------------------
/RotateDemoProject.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/RotateView/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
14 |
15 |
16 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/RotateDemo/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
16 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/RotateView/RotateView.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/RotateDemo/src/main/res/layout/fragment_main.xml:
--------------------------------------------------------------------------------
1 |
11 |
12 |
16 |
17 |
24 |
25 |
26 |
31 |
32 |
39 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/RotateDemo/src/main/java/com/avenwu/rotatedemo/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.avenwu.rotatedemo;
2 |
3 | import android.support.v7.app.ActionBarActivity;
4 | import android.support.v4.app.Fragment;
5 | import android.os.Bundle;
6 | import android.view.LayoutInflater;
7 | import android.view.Menu;
8 | import android.view.MenuItem;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.CompoundButton;
12 | import android.widget.Toast;
13 | import android.widget.ToggleButton;
14 |
15 | import com.avenwu.rotateview.RotationView;
16 |
17 | public class MainActivity extends ActionBarActivity {
18 |
19 | @Override
20 | protected void onCreate(Bundle savedInstanceState) {
21 | super.onCreate(savedInstanceState);
22 | setContentView(R.layout.activity_main);
23 |
24 | if (savedInstanceState == null) {
25 | getSupportFragmentManager().beginTransaction()
26 | .add(R.id.container, new PlaceholderFragment())
27 | .commit();
28 | }
29 | }
30 |
31 |
32 | @Override
33 | public boolean onCreateOptionsMenu(Menu menu) {
34 |
35 | // Inflate the menu; this adds items to the action bar if it is present.
36 | getMenuInflater().inflate(R.menu.main, menu);
37 | return true;
38 | }
39 |
40 | @Override
41 | public boolean onOptionsItemSelected(MenuItem item) {
42 | // Handle action bar item clicks here. The action bar will
43 | // automatically handle clicks on the Home/Up button, so long
44 | // as you specify a parent activity in AndroidManifest.xml.
45 | switch (item.getItemId()) {
46 | case R.id.action_settings:
47 | return true;
48 | }
49 | return super.onOptionsItemSelected(item);
50 | }
51 |
52 | /**
53 | * A placeholder fragment containing a simple view.
54 | */
55 | public static class PlaceholderFragment extends Fragment {
56 | private RotationView mRotateImage;
57 | private ToggleButton mToggleState;
58 |
59 | public PlaceholderFragment() {
60 | }
61 |
62 | @Override
63 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
64 | Bundle savedInstanceState) {
65 | View rootView = inflater.inflate(R.layout.fragment_main, container, false);
66 | mRotateImage = (RotationView) rootView.findViewById(R.id.view);
67 | mToggleState = (ToggleButton) rootView.findViewById(R.id.toggleButton);
68 | mToggleState.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
69 | @Override
70 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
71 | mRotateImage.toggle();
72 | }
73 | });
74 | rootView.findViewById(R.id.btn_reset).setOnClickListener(new View.OnClickListener() {
75 | @Override
76 | public void onClick(View v) {
77 | if (mToggleState.isChecked()) {
78 | mToggleState.setChecked(false);
79 | mRotateImage.resetAnimate();
80 | Toast.makeText(getActivity(), R.string.reset_success, Toast.LENGTH_SHORT).show();
81 | } else {
82 | Toast.makeText(getActivity(), R.string.no_need_reset, Toast.LENGTH_SHORT).show();
83 | }
84 | }
85 | });
86 | return rootView;
87 | }
88 | }
89 |
90 | }
91 |
--------------------------------------------------------------------------------
/RotateDemo/RotateDemo.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/RotateView/src/main/java/com/avenwu/rotateview/RotationView.java:
--------------------------------------------------------------------------------
1 | package com.avenwu.rotateview;
2 | /*
3 | * Copyright (C) 2013 Chaobin Wu
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | import android.content.Context;
19 | import android.content.res.TypedArray;
20 | import android.graphics.Bitmap;
21 | import android.graphics.BitmapFactory;
22 | import android.graphics.Canvas;
23 | import android.graphics.Matrix;
24 | import android.graphics.Paint;
25 | import android.util.AttributeSet;
26 | import android.util.Log;
27 | import android.view.View;
28 |
29 | /**
30 | * @author chaobin
31 | * @date 10/23/13.
32 | */
33 | public class RotationView extends View {
34 | private final String TAG = "RotationView";
35 | private final int REFRESH_INTERVAL = 100;
36 | private final int ROTATING_SPEED = 5;
37 | private Paint mPaint;
38 | private Context mContext;
39 | private Bitmap mRotateBackground;
40 | private Matrix mMatrix;
41 | private int mViewHeight;
42 | private int mViewWidth;
43 | private int mRotatedDegree;
44 | private int mBitmapWidth;
45 | private int mBitmapHeight;
46 | private int mBitmapResourceId;
47 | private RefreshProgressRunnable mRefreshRunnable;
48 | private RotateWorker mRotateWorker;
49 | private BitmapFactory.Options mOptions;
50 | private boolean mAutoRotate;
51 | private boolean mDetached;
52 | private boolean mRotating;
53 | private boolean mRotateable = true;
54 | private float mMaxProgress = 100.0f;
55 |
56 |
57 | public RotationView(Context context) {
58 | this(context, null);
59 | }
60 |
61 | public RotationView(Context context, AttributeSet attrs) {
62 | this(context, attrs, 0);
63 | }
64 |
65 | public RotationView(Context context, AttributeSet attrs, int defStyle) {
66 | super(context, attrs, defStyle);
67 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RotationView, defStyle, 0);
68 | mBitmapResourceId = a.getResourceId(R.styleable.RotationView_rotateBackground, android.R.drawable.sym_def_app_icon);
69 | mAutoRotate = a.getBoolean(R.styleable.RotationView_autoRefresh, false);
70 | a.recycle();
71 | intitData(context);
72 | }
73 |
74 | private void intitData(Context context) {
75 | mContext = context;
76 | mMatrix = new Matrix();
77 | mPaint = new Paint();
78 | mPaint.setAntiAlias(true);
79 | mPaint.setFilterBitmap(true);
80 | mRefreshRunnable = new RefreshProgressRunnable();
81 | }
82 |
83 | @Override
84 | protected void onDraw(Canvas canvas) {
85 | super.onDraw(canvas);
86 | if (mRotateBackground == null) {
87 | mOptions = new BitmapFactory.Options();
88 | mOptions.inJustDecodeBounds = true;
89 | BitmapFactory.decodeResource(mContext.getResources(), mBitmapResourceId, mOptions);
90 | int imageWidth = mOptions.outWidth;
91 | int imageHeight = mOptions.outHeight;
92 | Log.d(TAG, "imageHeight = " + imageHeight + ", imageWidth =" + imageWidth);
93 | int inSampleSize = 1;
94 | if (imageHeight > mViewHeight || imageWidth > mViewWidth) {
95 | final int heightRatio = Math.round(imageHeight / (float) mViewHeight);
96 | final int widthRatio = Math.round(imageWidth / (float) mViewWidth);
97 | inSampleSize = Math.max(heightRatio, widthRatio);
98 | Log.d(TAG, "heightRatio =" + heightRatio + ", widthRatio =" + widthRatio + ", inSampleSize =" + inSampleSize);
99 | }
100 | mOptions.inSampleSize = inSampleSize;
101 | mOptions.inJustDecodeBounds = false;
102 | mRotateBackground = BitmapFactory.decodeResource(mContext.getResources(), mBitmapResourceId, mOptions);
103 | mBitmapWidth = mOptions.outWidth;
104 | mBitmapHeight = mOptions.outHeight;
105 | if (mAutoRotate && mRotateable) startAnimate();
106 | }
107 | Log.d(TAG, "RotationView = " + mRotatedDegree);
108 | canvas.translate(Math.abs((mViewWidth - mBitmapWidth) / 2), Math.abs((mViewHeight - mBitmapHeight) / 2));
109 | mMatrix.setRotate(mRotatedDegree, mBitmapWidth / 2, mBitmapHeight / 2);
110 | canvas.drawBitmap(mRotateBackground, mMatrix, mPaint);
111 | }
112 |
113 | @Override
114 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
115 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
116 | mViewHeight = View.MeasureSpec.getSize(heightMeasureSpec);
117 | mViewWidth = View.MeasureSpec.getSize(widthMeasureSpec);
118 | Log.d(TAG, "mViewHeight =" + mViewHeight + ", mViewWidth =" + mViewWidth);
119 | }
120 |
121 | private class RefreshProgressRunnable implements Runnable {
122 | public void run() {
123 | synchronized (RotationView.this) {
124 | mRotatedDegree += ROTATING_SPEED;
125 | if (mRotatedDegree > 360) mRotatedDegree -= 360;
126 | invalidate();
127 | }
128 | }
129 | }
130 |
131 | private class RotateWorker extends Thread {
132 | private boolean cancelled;
133 |
134 | @Override
135 | public void run() {
136 | while (!cancelled && !mDetached && getVisibility() == View.VISIBLE) {
137 | Log.d(TAG, "post refresh request");
138 | post(mRefreshRunnable);
139 | try {
140 | Thread.sleep(REFRESH_INTERVAL);
141 | } catch (InterruptedException e) {
142 | e.printStackTrace();
143 | }
144 | }
145 | }
146 |
147 | public void cancel() {
148 | try {
149 | cancelled = true;
150 | this.interrupt();
151 | Log.d(TAG, "cancel RotateWorker " + this.toString());
152 | } catch (Exception e) {
153 | e.printStackTrace();
154 | }
155 | }
156 | }
157 |
158 | public void startAnimate() {
159 | if (mRotateWorker != null) mRotateWorker.cancel();
160 | mRotateable = true;
161 | mRotating = true;
162 | mRotateWorker = new RotateWorker();
163 | mRotateWorker.start();
164 | }
165 |
166 | public void stopAnimate() {
167 | if (mRotateWorker != null) mRotateWorker.cancel();
168 | mRotateWorker = null;
169 | mRotating = false;
170 | }
171 |
172 | public void resetAnimate() {
173 | mRotatedDegree = 0;
174 | if (mRotateWorker != null) mRotateWorker.cancel();
175 | invalidate();
176 | }
177 |
178 | public void setProgress(int progress) {
179 | mRotatedDegree = (int) ((progress + 0.5) / mMaxProgress * 360);
180 | startAnimate();
181 | }
182 |
183 | /**
184 | * start/stop to animate according to current state
185 | */
186 | public void toggle() {
187 | if (!mRotating) startAnimate();
188 | else stopAnimate();
189 | }
190 |
191 | @Override
192 | protected void onDetachedFromWindow() {
193 | super.onDetachedFromWindow();
194 | Log.d(TAG, "detached window");
195 | mDetached = true;
196 | stopAnimate();
197 | if (mRefreshRunnable != null) removeCallbacks(mRefreshRunnable);
198 | }
199 | }
200 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction, and
10 | distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by the copyright
13 | owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all other entities
16 | that control, are controlled by, or are under common control with that entity.
17 | For the purposes of this definition, "control" means (i) the power, direct or
18 | indirect, to cause the direction or management of such entity, whether by
19 | contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
20 | outstanding shares, or (iii) beneficial ownership of such entity.
21 |
22 | "You" (or "Your") shall mean an individual or Legal Entity exercising
23 | permissions granted by this License.
24 |
25 | "Source" form shall mean the preferred form for making modifications, including
26 | but not limited to software source code, documentation source, and configuration
27 | files.
28 |
29 | "Object" form shall mean any form resulting from mechanical transformation or
30 | translation of a Source form, including but not limited to compiled object code,
31 | generated documentation, and conversions to other media types.
32 |
33 | "Work" shall mean the work of authorship, whether in Source or Object form, made
34 | available under the License, as indicated by a copyright notice that is included
35 | in or attached to the work (an example is provided in the Appendix below).
36 |
37 | "Derivative Works" shall mean any work, whether in Source or Object form, that
38 | is based on (or derived from) the Work and for which the editorial revisions,
39 | annotations, elaborations, or other modifications represent, as a whole, an
40 | original work of authorship. For the purposes of this License, Derivative Works
41 | shall not include works that remain separable from, or merely link (or bind by
42 | name) to the interfaces of, the Work and Derivative Works thereof.
43 |
44 | "Contribution" shall mean any work of authorship, including the original version
45 | of the Work and any modifications or additions to that Work or Derivative Works
46 | thereof, that is intentionally submitted to Licensor for inclusion in the Work
47 | by the copyright owner or by an individual or Legal Entity authorized to submit
48 | on behalf of the copyright owner. For the purposes of this definition,
49 | "submitted" means any form of electronic, verbal, or written communication sent
50 | to the Licensor or its representatives, including but not limited to
51 | communication on electronic mailing lists, source code control systems, and
52 | issue tracking systems that are managed by, or on behalf of, the Licensor for
53 | the purpose of discussing and improving the Work, but excluding communication
54 | that is conspicuously marked or otherwise designated in writing by the copyright
55 | owner as "Not a Contribution."
56 |
57 | "Contributor" shall mean Licensor and any individual or Legal Entity on behalf
58 | of whom a Contribution has been received by Licensor and subsequently
59 | incorporated within the Work.
60 |
61 | 2. Grant of Copyright License.
62 |
63 | Subject to the terms and conditions of this License, each Contributor hereby
64 | grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
65 | irrevocable copyright license to reproduce, prepare Derivative Works of,
66 | publicly display, publicly perform, sublicense, and distribute the Work and such
67 | Derivative Works in Source or Object form.
68 |
69 | 3. Grant of Patent License.
70 |
71 | Subject to the terms and conditions of this License, each Contributor hereby
72 | grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
73 | irrevocable (except as stated in this section) patent license to make, have
74 | made, use, offer to sell, sell, import, and otherwise transfer the Work, where
75 | such license applies only to those patent claims licensable by such Contributor
76 | that are necessarily infringed by their Contribution(s) alone or by combination
77 | of their Contribution(s) with the Work to which such Contribution(s) was
78 | submitted. If You institute patent litigation against any entity (including a
79 | cross-claim or counterclaim in a lawsuit) alleging that the Work or a
80 | Contribution incorporated within the Work constitutes direct or contributory
81 | patent infringement, then any patent licenses granted to You under this License
82 | for that Work shall terminate as of the date such litigation is filed.
83 |
84 | 4. Redistribution.
85 |
86 | You may reproduce and distribute copies of the Work or Derivative Works thereof
87 | in any medium, with or without modifications, and in Source or Object form,
88 | provided that You meet the following conditions:
89 |
90 | You must give any other recipients of the Work or Derivative Works a copy of
91 | this License; and
92 | You must cause any modified files to carry prominent notices stating that You
93 | changed the files; and
94 | You must retain, in the Source form of any Derivative Works that You distribute,
95 | all copyright, patent, trademark, and attribution notices from the Source form
96 | of the Work, excluding those notices that do not pertain to any part of the
97 | Derivative Works; and
98 | If the Work includes a "NOTICE" text file as part of its distribution, then any
99 | Derivative Works that You distribute must include a readable copy of the
100 | attribution notices contained within such NOTICE file, excluding those notices
101 | that do not pertain to any part of the Derivative Works, in at least one of the
102 | following places: within a NOTICE text file distributed as part of the
103 | Derivative Works; within the Source form or documentation, if provided along
104 | with the Derivative Works; or, within a display generated by the Derivative
105 | Works, if and wherever such third-party notices normally appear. The contents of
106 | the NOTICE file are for informational purposes only and do not modify the
107 | License. You may add Your own attribution notices within Derivative Works that
108 | You distribute, alongside or as an addendum to the NOTICE text from the Work,
109 | provided that such additional attribution notices cannot be construed as
110 | modifying the License.
111 | You may add Your own copyright statement to Your modifications and may provide
112 | additional or different license terms and conditions for use, reproduction, or
113 | distribution of Your modifications, or for any such Derivative Works as a whole,
114 | provided Your use, reproduction, and distribution of the Work otherwise complies
115 | with the conditions stated in this License.
116 |
117 | 5. Submission of Contributions.
118 |
119 | Unless You explicitly state otherwise, any Contribution intentionally submitted
120 | for inclusion in the Work by You to the Licensor shall be under the terms and
121 | conditions of this License, without any additional terms or conditions.
122 | Notwithstanding the above, nothing herein shall supersede or modify the terms of
123 | any separate license agreement you may have executed with Licensor regarding
124 | such Contributions.
125 |
126 | 6. Trademarks.
127 |
128 | This License does not grant permission to use the trade names, trademarks,
129 | service marks, or product names of the Licensor, except as required for
130 | reasonable and customary use in describing the origin of the Work and
131 | reproducing the content of the NOTICE file.
132 |
133 | 7. Disclaimer of Warranty.
134 |
135 | Unless required by applicable law or agreed to in writing, Licensor provides the
136 | Work (and each Contributor provides its Contributions) on an "AS IS" BASIS,
137 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
138 | including, without limitation, any warranties or conditions of TITLE,
139 | NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
140 | solely responsible for determining the appropriateness of using or
141 | redistributing the Work and assume any risks associated with Your exercise of
142 | permissions under this License.
143 |
144 | 8. Limitation of Liability.
145 |
146 | In no event and under no legal theory, whether in tort (including negligence),
147 | contract, or otherwise, unless required by applicable law (such as deliberate
148 | and grossly negligent acts) or agreed to in writing, shall any Contributor be
149 | liable to You for damages, including any direct, indirect, special, incidental,
150 | or consequential damages of any character arising as a result of this License or
151 | out of the use or inability to use the Work (including but not limited to
152 | damages for loss of goodwill, work stoppage, computer failure or malfunction, or
153 | any and all other commercial damages or losses), even if such Contributor has
154 | been advised of the possibility of such damages.
155 |
156 | 9. Accepting Warranty or Additional Liability.
157 |
158 | While redistributing the Work or Derivative Works thereof, You may choose to
159 | offer, and charge a fee for, acceptance of support, warranty, indemnity, or
160 | other liability obligations and/or rights consistent with this License. However,
161 | in accepting such obligations, You may act only on Your own behalf and on Your
162 | sole responsibility, not on behalf of any other Contributor, and only if You
163 | agree to indemnify, defend, and hold each Contributor harmless for any liability
164 | incurred by, or claims asserted against, such Contributor by reason of your
165 | accepting any such warranty or additional liability.
166 |
167 | END OF TERMS AND CONDITIONS
168 |
169 | APPENDIX: How to apply the Apache License to your work
170 |
171 | To apply the Apache License to your work, attach the following boilerplate
172 | notice, with the fields enclosed by brackets "[]" replaced with your own
173 | identifying information. (Don't include the brackets!) The text should be
174 | enclosed in the appropriate comment syntax for the file format. We also
175 | recommend that a file or class name and description of purpose be included on
176 | the same "printed page" as the copyright notice for easier identification within
177 | third-party archives.
178 |
179 | Copyright 2013 Chaobin Wu
180 |
181 | Licensed under the Apache License, Version 2.0 (the "License");
182 | you may not use this file except in compliance with the License.
183 | You may obtain a copy of the License at
184 |
185 | http://www.apache.org/licenses/LICENSE-2.0
186 |
187 | Unless required by applicable law or agreed to in writing, software
188 | distributed under the License is distributed on an "AS IS" BASIS,
189 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
190 | See the License for the specific language governing permissions and
191 | limitations under the License.
192 |
--------------------------------------------------------------------------------