├── settings.gradle
├── screenshots
├── big_icon.png
└── screenshot1.png
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── app
├── src
│ └── main
│ │ ├── res
│ │ ├── drawable-hdpi
│ │ │ ├── ball.png
│ │ │ └── wood.jpg
│ │ ├── mipmap-hdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ │ └── ic_launcher.png
│ │ ├── values
│ │ │ └── strings.xml
│ │ └── layout
│ │ │ └── main.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── android
│ │ └── accelerometerplay
│ │ └── AccelerometerPlayActivity.java
└── build.gradle
├── README.md
├── NOTICE
├── .google
└── packaging.yaml
├── CONTRIBUTING.md
├── gradlew.bat
├── gradlew
└── LICENSE
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/screenshots/big_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlearchive/android-AccelerometerPlay/master/screenshots/big_icon.png
--------------------------------------------------------------------------------
/screenshots/screenshot1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlearchive/android-AccelerometerPlay/master/screenshots/screenshot1.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlearchive/android-AccelerometerPlay/master/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ball.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlearchive/android-AccelerometerPlay/master/app/src/main/res/drawable-hdpi/ball.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/wood.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlearchive/android-AccelerometerPlay/master/app/src/main/res/drawable-hdpi/wood.jpg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlearchive/android-AccelerometerPlay/master/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlearchive/android-AccelerometerPlay/master/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlearchive/android-AccelerometerPlay/master/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlearchive/android-AccelerometerPlay/master/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlearchive/android-AccelerometerPlay/master/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Aug 16 14:25:21 PDT 2016
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | Android AccelerometerPlay Sample
3 | ================================
4 |
5 | This sample has been deprecated/archived meaning it's read-only and it's no longer actively maintained (more details on archiving can be found [here][1]).
6 |
7 | For other related samples, check out the new [github.com/android/sensors-samples][2] repo. Thank you!
8 |
9 | [1]: https://help.github.com/en/articles/about-archiving-repositories
10 | [2]: https://github.com/android/sensors-samples
11 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "24.0.1"
6 |
7 | defaultConfig {
8 | applicationId "com.example.android.accelerometerplay"
9 | minSdkVersion 11
10 | targetSdkVersion 23
11 | }
12 |
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/NOTICE:
--------------------------------------------------------------------------------
1 |
2 | This sample uses the following software:
3 |
4 | Copyright 2016 The Android Open Source Project
5 |
6 | Licensed under the Apache License, Version 2.0 (the "License");
7 | you may not use this file except in compliance with the License.
8 | You may obtain a copy of the License at
9 |
10 | http://www.apache.org/licenses/LICENSE-2.0
11 |
12 | Unless required by applicable law or agreed to in writing, software
13 | distributed under the License is distributed on an "AS IS" BASIS,
14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | See the License for the specific language governing permissions and
16 | limitations under the License.
17 |
--------------------------------------------------------------------------------
/.google/packaging.yaml:
--------------------------------------------------------------------------------
1 |
2 | # GOOGLE SAMPLE PACKAGING DATA
3 | #
4 | # This file is used by Google as part of our samples packaging process.
5 | # End users may safely ignore this file. It has no relevance to other systems.
6 | ---
7 | status: PUBLISHED
8 | technologies: [Android]
9 | categories: [Sensors]
10 | languages: [Java]
11 | solutions: [Mobile]
12 | github: android-AccelerometerPlay
13 | level: ADVANCED
14 | icon: screenshots/big_icon.png
15 | apiRefs:
16 | - android:android.hardware.Sensor
17 | - android:android.hardware.SensorEvent
18 | - android:android.hardware.SensorEventListener
19 | - android:android.hardware.SensorManager
20 | license: apache2
21 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
18 | AccelerometerPlay
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
23 |
24 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # How to become a contributor and submit your own code
2 |
3 | ## Contributor License Agreements
4 |
5 | We'd love to accept your sample apps and patches! Before we can take them, we
6 | have to jump a couple of legal hurdles.
7 |
8 | Please fill out either the individual or corporate Contributor License Agreement (CLA).
9 |
10 | * If you are an individual writing original source code and you're sure you
11 | own the intellectual property, then you'll need to sign an [individual CLA]
12 | (https://cla.developers.google.com).
13 | * If you work for a company that wants to allow you to contribute your work,
14 | then you'll need to sign a [corporate CLA]
15 | (https://cla.developers.google.com).
16 |
17 | Follow either of the two links above to access the appropriate CLA and
18 | instructions for how to sign and return it. Once we receive it, we'll be able to
19 | accept your pull requests.
20 |
21 | ## Contributing A Patch
22 |
23 | 1. Submit an issue describing your proposed change to the repo in question.
24 | 1. The repo owner will respond to your issue promptly.
25 | 1. If your proposed change is accepted, and you haven't already done so, sign a
26 | Contributor License Agreement (see details above).
27 | 1. Fork the desired repo, develop and test your code changes.
28 | 1. Ensure that your code adheres to the existing style in the sample to which
29 | you are contributing. Refer to the
30 | [Android Code Style Guide]
31 | (https://source.android.com/source/code-style.html) for the
32 | recommended coding standards for this organization.
33 | 1. Ensure that your code has an appropriate set of unit tests which all pass.
34 | 1. Submit a pull request.
35 |
36 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
20 |
21 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/android/accelerometerplay/AccelerometerPlayActivity.java:
--------------------------------------------------------------------------------
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.accelerometerplay;
18 |
19 | import android.annotation.TargetApi;
20 | import android.app.Activity;
21 | import android.content.Context;
22 | import android.graphics.Bitmap;
23 | import android.graphics.Canvas;
24 | import android.graphics.BitmapFactory.Options;
25 | import android.hardware.Sensor;
26 | import android.hardware.SensorEvent;
27 | import android.hardware.SensorEventListener;
28 | import android.hardware.SensorManager;
29 | import android.os.Build;
30 | import android.os.Bundle;
31 | import android.os.PowerManager;
32 | import android.os.PowerManager.WakeLock;
33 | import android.util.AttributeSet;
34 | import android.util.DisplayMetrics;
35 | import android.view.Display;
36 | import android.view.Surface;
37 | import android.view.View;
38 | import android.view.ViewGroup;
39 | import android.view.WindowManager;
40 | import android.widget.FrameLayout;
41 |
42 | /**
43 | * This is an example of using the accelerometer to integrate the device's
44 | * acceleration to a position using the Verlet method. This is illustrated with
45 | * a very simple particle system comprised of a few iron balls freely moving on
46 | * an inclined wooden table. The inclination of the virtual table is controlled
47 | * by the device's accelerometer.
48 | *
49 | * @see SensorManager
50 | * @see SensorEvent
51 | * @see Sensor
52 | */
53 |
54 | public class AccelerometerPlayActivity extends Activity {
55 |
56 | private SimulationView mSimulationView;
57 | private SensorManager mSensorManager;
58 | private PowerManager mPowerManager;
59 | private WindowManager mWindowManager;
60 | private Display mDisplay;
61 | private WakeLock mWakeLock;
62 |
63 | /** Called when the activity is first created. */
64 | @Override
65 | public void onCreate(Bundle savedInstanceState) {
66 | super.onCreate(savedInstanceState);
67 |
68 | // Get an instance of the SensorManager
69 | mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
70 |
71 | // Get an instance of the PowerManager
72 | mPowerManager = (PowerManager) getSystemService(POWER_SERVICE);
73 |
74 | // Get an instance of the WindowManager
75 | mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
76 | mDisplay = mWindowManager.getDefaultDisplay();
77 |
78 | // Create a bright wake lock
79 | mWakeLock = mPowerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, getClass()
80 | .getName());
81 |
82 | // instantiate our simulation view and set it as the activity's content
83 | mSimulationView = new SimulationView(this);
84 | mSimulationView.setBackgroundResource(R.drawable.wood);
85 | setContentView(mSimulationView);
86 | }
87 |
88 | @Override
89 | protected void onResume() {
90 | super.onResume();
91 | /*
92 | * when the activity is resumed, we acquire a wake-lock so that the
93 | * screen stays on, since the user will likely not be fiddling with the
94 | * screen or buttons.
95 | */
96 | mWakeLock.acquire();
97 |
98 | // Start the simulation
99 | mSimulationView.startSimulation();
100 | }
101 |
102 | @Override
103 | protected void onPause() {
104 | super.onPause();
105 | /*
106 | * When the activity is paused, we make sure to stop the simulation,
107 | * release our sensor resources and wake locks
108 | */
109 |
110 | // Stop the simulation
111 | mSimulationView.stopSimulation();
112 |
113 | // and release our wake-lock
114 | mWakeLock.release();
115 | }
116 |
117 | class SimulationView extends FrameLayout implements SensorEventListener {
118 | // diameter of the balls in meters
119 | private static final float sBallDiameter = 0.004f;
120 | private static final float sBallDiameter2 = sBallDiameter * sBallDiameter;
121 |
122 | private final int mDstWidth;
123 | private final int mDstHeight;
124 |
125 | private Sensor mAccelerometer;
126 | private long mLastT;
127 |
128 | private float mXDpi;
129 | private float mYDpi;
130 | private float mMetersToPixelsX;
131 | private float mMetersToPixelsY;
132 | private float mXOrigin;
133 | private float mYOrigin;
134 | private float mSensorX;
135 | private float mSensorY;
136 | private float mHorizontalBound;
137 | private float mVerticalBound;
138 | private final ParticleSystem mParticleSystem;
139 | /*
140 | * Each of our particle holds its previous and current position, its
141 | * acceleration. for added realism each particle has its own friction
142 | * coefficient.
143 | */
144 | class Particle extends View {
145 | private float mPosX = (float) Math.random();
146 | private float mPosY = (float) Math.random();
147 | private float mVelX;
148 | private float mVelY;
149 |
150 | public Particle(Context context) {
151 | super(context);
152 | }
153 |
154 | public Particle(Context context, AttributeSet attrs) {
155 | super(context, attrs);
156 | }
157 |
158 | public Particle(Context context, AttributeSet attrs, int defStyleAttr) {
159 | super(context, attrs, defStyleAttr);
160 | }
161 |
162 | @TargetApi(Build.VERSION_CODES.LOLLIPOP)
163 | public Particle(Context context, AttributeSet attrs, int defStyleAttr,
164 | int defStyleRes) {
165 | super(context, attrs, defStyleAttr, defStyleRes);
166 | }
167 |
168 | public void computePhysics(float sx, float sy, float dT) {
169 |
170 | final float ax = -sx/5;
171 | final float ay = -sy/5;
172 |
173 | mPosX += mVelX * dT + ax * dT * dT / 2;
174 | mPosY += mVelY * dT + ay * dT * dT / 2;
175 |
176 | mVelX += ax * dT;
177 | mVelY += ay * dT;
178 | }
179 |
180 | /*
181 | * Resolving constraints and collisions with the Verlet integrator
182 | * can be very simple, we simply need to move a colliding or
183 | * constrained particle in such way that the constraint is
184 | * satisfied.
185 | */
186 | public void resolveCollisionWithBounds() {
187 | final float xmax = mHorizontalBound;
188 | final float ymax = mVerticalBound;
189 | final float x = mPosX;
190 | final float y = mPosY;
191 | if (x > xmax) {
192 | mPosX = xmax;
193 | mVelX = 0;
194 | } else if (x < -xmax) {
195 | mPosX = -xmax;
196 | mVelX = 0;
197 | }
198 | if (y > ymax) {
199 | mPosY = ymax;
200 | mVelY = 0;
201 | } else if (y < -ymax) {
202 | mPosY = -ymax;
203 | mVelY = 0;
204 | }
205 | }
206 | }
207 |
208 | /*
209 | * A particle system is just a collection of particles
210 | */
211 | class ParticleSystem {
212 | static final int NUM_PARTICLES = 5;
213 | private Particle mBalls[] = new Particle[NUM_PARTICLES];
214 |
215 | ParticleSystem() {
216 | /*
217 | * Initially our particles have no speed or acceleration
218 | */
219 | for (int i = 0; i < mBalls.length; i++) {
220 | mBalls[i] = new Particle(getContext());
221 | mBalls[i].setBackgroundResource(R.drawable.ball);
222 | mBalls[i].setLayerType(LAYER_TYPE_HARDWARE, null);
223 | addView(mBalls[i], new ViewGroup.LayoutParams(mDstWidth, mDstHeight));
224 | }
225 | }
226 |
227 | /*
228 | * Update the position of each particle in the system using the
229 | * Verlet integrator.
230 | */
231 | private void updatePositions(float sx, float sy, long timestamp) {
232 | final long t = timestamp;
233 | if (mLastT != 0) {
234 | final float dT = (float) (t - mLastT) / 1000.f /** (1.0f / 1000000000.0f)*/;
235 | final int count = mBalls.length;
236 | for (int i = 0; i < count; i++) {
237 | Particle ball = mBalls[i];
238 | ball.computePhysics(sx, sy, dT);
239 | }
240 | }
241 | mLastT = t;
242 | }
243 |
244 | /*
245 | * Performs one iteration of the simulation. First updating the
246 | * position of all the particles and resolving the constraints and
247 | * collisions.
248 | */
249 | public void update(float sx, float sy, long now) {
250 | // update the system's positions
251 | updatePositions(sx, sy, now);
252 |
253 | // We do no more than a limited number of iterations
254 | final int NUM_MAX_ITERATIONS = 10;
255 |
256 | /*
257 | * Resolve collisions, each particle is tested against every
258 | * other particle for collision. If a collision is detected the
259 | * particle is moved away using a virtual spring of infinite
260 | * stiffness.
261 | */
262 | boolean more = true;
263 | final int count = mBalls.length;
264 | for (int k = 0; k < NUM_MAX_ITERATIONS && more; k++) {
265 | more = false;
266 | for (int i = 0; i < count; i++) {
267 | Particle curr = mBalls[i];
268 | for (int j = i + 1; j < count; j++) {
269 | Particle ball = mBalls[j];
270 | float dx = ball.mPosX - curr.mPosX;
271 | float dy = ball.mPosY - curr.mPosY;
272 | float dd = dx * dx + dy * dy;
273 | // Check for collisions
274 | if (dd <= sBallDiameter2) {
275 | /*
276 | * add a little bit of entropy, after nothing is
277 | * perfect in the universe.
278 | */
279 | dx += ((float) Math.random() - 0.5f) * 0.0001f;
280 | dy += ((float) Math.random() - 0.5f) * 0.0001f;
281 | dd = dx * dx + dy * dy;
282 | // simulate the spring
283 | final float d = (float) Math.sqrt(dd);
284 | final float c = (0.5f * (sBallDiameter - d)) / d;
285 | final float effectX = dx * c;
286 | final float effectY = dy * c;
287 | curr.mPosX -= effectX;
288 | curr.mPosY -= effectY;
289 | ball.mPosX += effectX;
290 | ball.mPosY += effectY;
291 | more = true;
292 | }
293 | }
294 | curr.resolveCollisionWithBounds();
295 | }
296 | }
297 | }
298 |
299 | public int getParticleCount() {
300 | return mBalls.length;
301 | }
302 |
303 | public float getPosX(int i) {
304 | return mBalls[i].mPosX;
305 | }
306 |
307 | public float getPosY(int i) {
308 | return mBalls[i].mPosY;
309 | }
310 | }
311 |
312 | public void startSimulation() {
313 | /*
314 | * It is not necessary to get accelerometer events at a very high
315 | * rate, by using a slower rate (SENSOR_DELAY_UI), we get an
316 | * automatic low-pass filter, which "extracts" the gravity component
317 | * of the acceleration. As an added benefit, we use less power and
318 | * CPU resources.
319 | */
320 | mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_GAME);
321 | }
322 |
323 | public void stopSimulation() {
324 | mSensorManager.unregisterListener(this);
325 | }
326 |
327 | public SimulationView(Context context) {
328 | super(context);
329 | mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
330 |
331 | DisplayMetrics metrics = new DisplayMetrics();
332 | getWindowManager().getDefaultDisplay().getMetrics(metrics);
333 | mXDpi = metrics.xdpi;
334 | mYDpi = metrics.ydpi;
335 | mMetersToPixelsX = mXDpi / 0.0254f;
336 | mMetersToPixelsY = mYDpi / 0.0254f;
337 |
338 | // rescale the ball so it's about 0.5 cm on screen
339 | mDstWidth = (int) (sBallDiameter * mMetersToPixelsX + 0.5f);
340 | mDstHeight = (int) (sBallDiameter * mMetersToPixelsY + 0.5f);
341 | mParticleSystem = new ParticleSystem();
342 |
343 | Options opts = new Options();
344 | opts.inDither = true;
345 | opts.inPreferredConfig = Bitmap.Config.RGB_565;
346 | }
347 |
348 | @Override
349 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
350 | // compute the origin of the screen relative to the origin of
351 | // the bitmap
352 | mXOrigin = (w - mDstWidth) * 0.5f;
353 | mYOrigin = (h - mDstHeight) * 0.5f;
354 | mHorizontalBound = ((w / mMetersToPixelsX - sBallDiameter) * 0.5f);
355 | mVerticalBound = ((h / mMetersToPixelsY - sBallDiameter) * 0.5f);
356 | }
357 |
358 | @Override
359 | public void onSensorChanged(SensorEvent event) {
360 | if (event.sensor.getType() != Sensor.TYPE_ACCELEROMETER)
361 | return;
362 | /*
363 | * record the accelerometer data, the event's timestamp as well as
364 | * the current time. The latter is needed so we can calculate the
365 | * "present" time during rendering. In this application, we need to
366 | * take into account how the screen is rotated with respect to the
367 | * sensors (which always return data in a coordinate space aligned
368 | * to with the screen in its native orientation).
369 | */
370 |
371 | switch (mDisplay.getRotation()) {
372 | case Surface.ROTATION_0:
373 | mSensorX = event.values[0];
374 | mSensorY = event.values[1];
375 | break;
376 | case Surface.ROTATION_90:
377 | mSensorX = -event.values[1];
378 | mSensorY = event.values[0];
379 | break;
380 | case Surface.ROTATION_180:
381 | mSensorX = -event.values[0];
382 | mSensorY = -event.values[1];
383 | break;
384 | case Surface.ROTATION_270:
385 | mSensorX = event.values[1];
386 | mSensorY = -event.values[0];
387 | break;
388 | }
389 | }
390 |
391 | @Override
392 | protected void onDraw(Canvas canvas) {
393 | /*
394 | * Compute the new position of our object, based on accelerometer
395 | * data and present time.
396 | */
397 | final ParticleSystem particleSystem = mParticleSystem;
398 | final long now = System.currentTimeMillis();
399 | final float sx = mSensorX;
400 | final float sy = mSensorY;
401 |
402 | particleSystem.update(sx, sy, now);
403 |
404 | final float xc = mXOrigin;
405 | final float yc = mYOrigin;
406 | final float xs = mMetersToPixelsX;
407 | final float ys = mMetersToPixelsY;
408 | final int count = particleSystem.getParticleCount();
409 | for (int i = 0; i < count; i++) {
410 | /*
411 | * We transform the canvas so that the coordinate system matches
412 | * the sensors coordinate system with the origin in the center
413 | * of the screen and the unit is the meter.
414 | */
415 | final float x = xc + particleSystem.getPosX(i) * xs;
416 | final float y = yc - particleSystem.getPosY(i) * ys;
417 | particleSystem.mBalls[i].setTranslationX(x);
418 | particleSystem.mBalls[i].setTranslationY(y);
419 | }
420 |
421 | // and make sure to redraw asap
422 | invalidate();
423 | }
424 |
425 | @Override
426 | public void onAccuracyChanged(Sensor sensor, int accuracy) {
427 | }
428 | }
429 | }
430 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | --------------
3 |
4 | Version 2.0, January 2004
5 | http://www.apache.org/licenses/
6 |
7 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8 |
9 | 1. Definitions.
10 |
11 | "License" shall mean the terms and conditions for use, reproduction,
12 | and distribution as defined by Sections 1 through 9 of this document.
13 |
14 | "Licensor" shall mean the copyright owner or entity authorized by
15 | the copyright owner that is granting the License.
16 |
17 | "Legal Entity" shall mean the union of the acting entity and all
18 | other entities that control, are controlled by, or are under common
19 | control with that entity. For the purposes of this definition,
20 | "control" means (i) the power, direct or indirect, to cause the
21 | direction or management of such entity, whether by contract or
22 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
23 | outstanding shares, or (iii) beneficial ownership of such entity.
24 |
25 | "You" (or "Your") shall mean an individual or Legal Entity
26 | exercising permissions granted by this License.
27 |
28 | "Source" form shall mean the preferred form for making modifications,
29 | including but not limited to software source code, documentation
30 | source, and configuration files.
31 |
32 | "Object" form shall mean any form resulting from mechanical
33 | transformation or translation of a Source form, including but
34 | not limited to compiled object code, generated documentation,
35 | and conversions to other media types.
36 |
37 | "Work" shall mean the work of authorship, whether in Source or
38 | Object form, made available under the License, as indicated by a
39 | copyright notice that is included in or attached to the work
40 | (an example is provided in the Appendix below).
41 |
42 | "Derivative Works" shall mean any work, whether in Source or Object
43 | form, that is based on (or derived from) the Work and for which the
44 | editorial revisions, annotations, elaborations, or other modifications
45 | represent, as a whole, an original work of authorship. For the purposes
46 | of this License, Derivative Works shall not include works that remain
47 | separable from, or merely link (or bind by name) to the interfaces of,
48 | the Work and Derivative Works thereof.
49 |
50 | "Contribution" shall mean any work of authorship, including
51 | the original version of the Work and any modifications or additions
52 | to that Work or Derivative Works thereof, that is intentionally
53 | submitted to Licensor for inclusion in the Work by the copyright owner
54 | or by an individual or Legal Entity authorized to submit on behalf of
55 | the copyright owner. For the purposes of this definition, "submitted"
56 | means any form of electronic, verbal, or written communication sent
57 | to the Licensor or its representatives, including but not limited to
58 | communication on electronic mailing lists, source code control systems,
59 | and issue tracking systems that are managed by, or on behalf of, the
60 | Licensor for the purpose of discussing and improving the Work, but
61 | excluding communication that is conspicuously marked or otherwise
62 | designated in writing by the copyright owner as "Not a Contribution."
63 |
64 | "Contributor" shall mean Licensor and any individual or Legal Entity
65 | on behalf of whom a Contribution has been received by Licensor and
66 | subsequently incorporated within the Work.
67 |
68 | 2. Grant of Copyright License. Subject to the terms and conditions of
69 | this License, each Contributor hereby grants to You a perpetual,
70 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
71 | copyright license to reproduce, prepare Derivative Works of,
72 | publicly display, publicly perform, sublicense, and distribute the
73 | Work and such Derivative Works in Source or Object form.
74 |
75 | 3. Grant of Patent License. Subject to the terms and conditions of
76 | this License, each Contributor hereby grants to You a perpetual,
77 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
78 | (except as stated in this section) patent license to make, have made,
79 | use, offer to sell, sell, import, and otherwise transfer the Work,
80 | where such license applies only to those patent claims licensable
81 | by such Contributor that are necessarily infringed by their
82 | Contribution(s) alone or by combination of their Contribution(s)
83 | with the Work to which such Contribution(s) was submitted. If You
84 | institute patent litigation against any entity (including a
85 | cross-claim or counterclaim in a lawsuit) alleging that the Work
86 | or a Contribution incorporated within the Work constitutes direct
87 | or contributory patent infringement, then any patent licenses
88 | granted to You under this License for that Work shall terminate
89 | as of the date such litigation is filed.
90 |
91 | 4. Redistribution. You may reproduce and distribute copies of the
92 | Work or Derivative Works thereof in any medium, with or without
93 | modifications, and in Source or Object form, provided that You
94 | meet the following conditions:
95 |
96 | (a) You must give any other recipients of the Work or
97 | Derivative Works a copy of this License; and
98 |
99 | (b) You must cause any modified files to carry prominent notices
100 | stating that You changed the files; and
101 |
102 | (c) You must retain, in the Source form of any Derivative Works
103 | that You distribute, all copyright, patent, trademark, and
104 | attribution notices from the Source form of the Work,
105 | excluding those notices that do not pertain to any part of
106 | the Derivative Works; and
107 |
108 | (d) If the Work includes a "NOTICE" text file as part of its
109 | distribution, then any Derivative Works that You distribute must
110 | include a readable copy of the attribution notices contained
111 | within such NOTICE file, excluding those notices that do not
112 | pertain to any part of the Derivative Works, in at least one
113 | of the following places: within a NOTICE text file distributed
114 | as part of the Derivative Works; within the Source form or
115 | documentation, if provided along with the Derivative Works; or,
116 | within a display generated by the Derivative Works, if and
117 | wherever such third-party notices normally appear. The contents
118 | of the NOTICE file are for informational purposes only and
119 | do not modify the License. You may add Your own attribution
120 | notices within Derivative Works that You distribute, alongside
121 | or as an addendum to the NOTICE text from the Work, provided
122 | that such additional attribution notices cannot be construed
123 | as modifying the License.
124 |
125 | You may add Your own copyright statement to Your modifications and
126 | may provide additional or different license terms and conditions
127 | for use, reproduction, or distribution of Your modifications, or
128 | for any such Derivative Works as a whole, provided Your use,
129 | reproduction, and distribution of the Work otherwise complies with
130 | the conditions stated in this License.
131 |
132 | 5. Submission of Contributions. Unless You explicitly state otherwise,
133 | any Contribution intentionally submitted for inclusion in the Work
134 | by You to the Licensor shall be under the terms and conditions of
135 | this License, without any additional terms or conditions.
136 | Notwithstanding the above, nothing herein shall supersede or modify
137 | the terms of any separate license agreement you may have executed
138 | with Licensor regarding such Contributions.
139 |
140 | 6. Trademarks. This License does not grant permission to use the trade
141 | names, trademarks, service marks, or product names of the Licensor,
142 | except as required for reasonable and customary use in describing the
143 | origin of the Work and reproducing the content of the NOTICE file.
144 |
145 | 7. Disclaimer of Warranty. Unless required by applicable law or
146 | agreed to in writing, Licensor provides the Work (and each
147 | Contributor provides its Contributions) on an "AS IS" BASIS,
148 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
149 | implied, including, without limitation, any warranties or conditions
150 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
151 | PARTICULAR PURPOSE. You are solely responsible for determining the
152 | appropriateness of using or redistributing the Work and assume any
153 | risks associated with Your exercise of permissions under this License.
154 |
155 | 8. Limitation of Liability. In no event and under no legal theory,
156 | whether in tort (including negligence), contract, or otherwise,
157 | unless required by applicable law (such as deliberate and grossly
158 | negligent acts) or agreed to in writing, shall any Contributor be
159 | liable to You for damages, including any direct, indirect, special,
160 | incidental, or consequential damages of any character arising as a
161 | result of this License or out of the use or inability to use the
162 | Work (including but not limited to damages for loss of goodwill,
163 | work stoppage, computer failure or malfunction, or any and all
164 | other commercial damages or losses), even if such Contributor
165 | has been advised of the possibility of such damages.
166 |
167 | 9. Accepting Warranty or Additional Liability. While redistributing
168 | the Work or Derivative Works thereof, You may choose to offer,
169 | and charge a fee for, acceptance of support, warranty, indemnity,
170 | or other liability obligations and/or rights consistent with this
171 | License. However, in accepting such obligations, You may act only
172 | on Your own behalf and on Your sole responsibility, not on behalf
173 | of any other Contributor, and only if You agree to indemnify,
174 | defend, and hold each Contributor harmless for any liability
175 | incurred by, or claims asserted against, such Contributor by reason
176 | of your accepting any such warranty or additional liability.
177 |
178 | END OF TERMS AND CONDITIONS
179 |
180 | APPENDIX: How to apply the Apache License to your work.
181 |
182 | To apply the Apache License to your work, attach the following
183 | boilerplate notice, with the fields enclosed by brackets "{}"
184 | replaced with your own identifying information. (Don't include
185 | the brackets!) The text should be enclosed in the appropriate
186 | comment syntax for the file format. We also recommend that a
187 | file or class name and description of purpose be included on the
188 | same "printed page" as the copyright notice for easier
189 | identification within third-party archives.
190 |
191 | Copyright {yyyy} {name of copyright owner}
192 |
193 | Licensed under the Apache License, Version 2.0 (the "License");
194 | you may not use this file except in compliance with the License.
195 | You may obtain a copy of the License at
196 |
197 | http://www.apache.org/licenses/LICENSE-2.0
198 |
199 | Unless required by applicable law or agreed to in writing, software
200 | distributed under the License is distributed on an "AS IS" BASIS,
201 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
202 | See the License for the specific language governing permissions and
203 | limitations under the License.
204 |
205 | All image and audio files (including *.png, *.jpg, *.svg, *.mp3, *.wav
206 | and *.ogg) are licensed under the CC-BY-NC license. All other files are
207 | licensed under the Apache 2 license.
208 |
209 | CC-BY-NC License
210 | ----------------
211 |
212 | Attribution-NonCommercial-ShareAlike 4.0 International
213 |
214 | =======================================================================
215 |
216 | Creative Commons Corporation ("Creative Commons") is not a law firm and
217 | does not provide legal services or legal advice. Distribution of
218 | Creative Commons public licenses does not create a lawyer-client or
219 | other relationship. Creative Commons makes its licenses and related
220 | information available on an "as-is" basis. Creative Commons gives no
221 | warranties regarding its licenses, any material licensed under their
222 | terms and conditions, or any related information. Creative Commons
223 | disclaims all liability for damages resulting from their use to the
224 | fullest extent possible.
225 |
226 | Using Creative Commons Public Licenses
227 |
228 | Creative Commons public licenses provide a standard set of terms and
229 | conditions that creators and other rights holders may use to share
230 | original works of authorship and other material subject to copyright
231 | and certain other rights specified in the public license below. The
232 | following considerations are for informational purposes only, are not
233 | exhaustive, and do not form part of our licenses.
234 |
235 | Considerations for licensors: Our public licenses are
236 | intended for use by those authorized to give the public
237 | permission to use material in ways otherwise restricted by
238 | copyright and certain other rights. Our licenses are
239 | irrevocable. Licensors should read and understand the terms
240 | and conditions of the license they choose before applying it.
241 | Licensors should also secure all rights necessary before
242 | applying our licenses so that the public can reuse the
243 | material as expected. Licensors should clearly mark any
244 | material not subject to the license. This includes other CC-
245 | licensed material, or material used under an exception or
246 | limitation to copyright. More considerations for licensors:
247 | wiki.creativecommons.org/Considerations_for_licensors
248 |
249 | Considerations for the public: By using one of our public
250 | licenses, a licensor grants the public permission to use the
251 | licensed material under specified terms and conditions. If
252 | the licensor's permission is not necessary for any reason--for
253 | example, because of any applicable exception or limitation to
254 | copyright--then that use is not regulated by the license. Our
255 | licenses grant only permissions under copyright and certain
256 | other rights that a licensor has authority to grant. Use of
257 | the licensed material may still be restricted for other
258 | reasons, including because others have copyright or other
259 | rights in the material. A licensor may make special requests,
260 | such as asking that all changes be marked or described.
261 | Although not required by our licenses, you are encouraged to
262 | respect those requests where reasonable. More_considerations
263 | for the public:
264 | wiki.creativecommons.org/Considerations_for_licensees
265 |
266 | =======================================================================
267 |
268 | Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
269 | Public License
270 |
271 | By exercising the Licensed Rights (defined below), You accept and agree
272 | to be bound by the terms and conditions of this Creative Commons
273 | Attribution-NonCommercial-ShareAlike 4.0 International Public License
274 | ("Public License"). To the extent this Public License may be
275 | interpreted as a contract, You are granted the Licensed Rights in
276 | consideration of Your acceptance of these terms and conditions, and the
277 | Licensor grants You such rights in consideration of benefits the
278 | Licensor receives from making the Licensed Material available under
279 | these terms and conditions.
280 |
281 |
282 | Section 1 -- Definitions.
283 |
284 | a. Adapted Material means material subject to Copyright and Similar
285 | Rights that is derived from or based upon the Licensed Material
286 | and in which the Licensed Material is translated, altered,
287 | arranged, transformed, or otherwise modified in a manner requiring
288 | permission under the Copyright and Similar Rights held by the
289 | Licensor. For purposes of this Public License, where the Licensed
290 | Material is a musical work, performance, or sound recording,
291 | Adapted Material is always produced where the Licensed Material is
292 | synched in timed relation with a moving image.
293 |
294 | b. Adapter's License means the license You apply to Your Copyright
295 | and Similar Rights in Your contributions to Adapted Material in
296 | accordance with the terms and conditions of this Public License.
297 |
298 | c. BY-NC-SA Compatible License means a license listed at
299 | creativecommons.org/compatiblelicenses, approved by Creative
300 | Commons as essentially the equivalent of this Public License.
301 |
302 | d. Copyright and Similar Rights means copyright and/or similar rights
303 | closely related to copyright including, without limitation,
304 | performance, broadcast, sound recording, and Sui Generis Database
305 | Rights, without regard to how the rights are labeled or
306 | categorized. For purposes of this Public License, the rights
307 | specified in Section 2(b)(1)-(2) are not Copyright and Similar
308 | Rights.
309 |
310 | e. Effective Technological Measures means those measures that, in the
311 | absence of proper authority, may not be circumvented under laws
312 | fulfilling obligations under Article 11 of the WIPO Copyright
313 | Treaty adopted on December 20, 1996, and/or similar international
314 | agreements.
315 |
316 | f. Exceptions and Limitations means fair use, fair dealing, and/or
317 | any other exception or limitation to Copyright and Similar Rights
318 | that applies to Your use of the Licensed Material.
319 |
320 | g. License Elements means the license attributes listed in the name
321 | of a Creative Commons Public License. The License Elements of this
322 | Public License are Attribution, NonCommercial, and ShareAlike.
323 |
324 | h. Licensed Material means the artistic or literary work, database,
325 | or other material to which the Licensor applied this Public
326 | License.
327 |
328 | i. Licensed Rights means the rights granted to You subject to the
329 | terms and conditions of this Public License, which are limited to
330 | all Copyright and Similar Rights that apply to Your use of the
331 | Licensed Material and that the Licensor has authority to license.
332 |
333 | j. Licensor means the individual(s) or entity(ies) granting rights
334 | under this Public License.
335 |
336 | k. NonCommercial means not primarily intended for or directed towards
337 | commercial advantage or monetary compensation. For purposes of
338 | this Public License, the exchange of the Licensed Material for
339 | other material subject to Copyright and Similar Rights by digital
340 | file-sharing or similar means is NonCommercial provided there is
341 | no payment of monetary compensation in connection with the
342 | exchange.
343 |
344 | l. Share means to provide material to the public by any means or
345 | process that requires permission under the Licensed Rights, such
346 | as reproduction, public display, public performance, distribution,
347 | dissemination, communication, or importation, and to make material
348 | available to the public including in ways that members of the
349 | public may access the material from a place and at a time
350 | individually chosen by them.
351 |
352 | m. Sui Generis Database Rights means rights other than copyright
353 | resulting from Directive 96/9/EC of the European Parliament and of
354 | the Council of 11 March 1996 on the legal protection of databases,
355 | as amended and/or succeeded, as well as other essentially
356 | equivalent rights anywhere in the world.
357 |
358 | n. You means the individual or entity exercising the Licensed Rights
359 | under this Public License. Your has a corresponding meaning.
360 |
361 |
362 | Section 2 -- Scope.
363 |
364 | a. License grant.
365 |
366 | 1. Subject to the terms and conditions of this Public License,
367 | the Licensor hereby grants You a worldwide, royalty-free,
368 | non-sublicensable, non-exclusive, irrevocable license to
369 | exercise the Licensed Rights in the Licensed Material to:
370 |
371 | a. reproduce and Share the Licensed Material, in whole or
372 | in part, for NonCommercial purposes only; and
373 |
374 | b. produce, reproduce, and Share Adapted Material for
375 | NonCommercial purposes only.
376 |
377 | 2. Exceptions and Limitations. For the avoidance of doubt, where
378 | Exceptions and Limitations apply to Your use, this Public
379 | License does not apply, and You do not need to comply with
380 | its terms and conditions.
381 |
382 | 3. Term. The term of this Public License is specified in Section
383 | 6(a).
384 |
385 | 4. Media and formats; technical modifications allowed. The
386 | Licensor authorizes You to exercise the Licensed Rights in
387 | all media and formats whether now known or hereafter created,
388 | and to make technical modifications necessary to do so. The
389 | Licensor waives and/or agrees not to assert any right or
390 | authority to forbid You from making technical modifications
391 | necessary to exercise the Licensed Rights, including
392 | technical modifications necessary to circumvent Effective
393 | Technological Measures. For purposes of this Public License,
394 | simply making modifications authorized by this Section 2(a)
395 | (4) never produces Adapted Material.
396 |
397 | 5. Downstream recipients.
398 |
399 | a. Offer from the Licensor -- Licensed Material. Every
400 | recipient of the Licensed Material automatically
401 | receives an offer from the Licensor to exercise the
402 | Licensed Rights under the terms and conditions of this
403 | Public License.
404 |
405 | b. Additional offer from the Licensor -- Adapted Material.
406 | Every recipient of Adapted Material from You
407 | automatically receives an offer from the Licensor to
408 | exercise the Licensed Rights in the Adapted Material
409 | under the conditions of the Adapter's License You apply.
410 |
411 | c. No downstream restrictions. You may not offer or impose
412 | any additional or different terms or conditions on, or
413 | apply any Effective Technological Measures to, the
414 | Licensed Material if doing so restricts exercise of the
415 | Licensed Rights by any recipient of the Licensed
416 | Material.
417 |
418 | 6. No endorsement. Nothing in this Public License constitutes or
419 | may be construed as permission to assert or imply that You
420 | are, or that Your use of the Licensed Material is, connected
421 | with, or sponsored, endorsed, or granted official status by,
422 | the Licensor or others designated to receive attribution as
423 | provided in Section 3(a)(1)(A)(i).
424 |
425 | b. Other rights.
426 |
427 | 1. Moral rights, such as the right of integrity, are not
428 | licensed under this Public License, nor are publicity,
429 | privacy, and/or other similar personality rights; however, to
430 | the extent possible, the Licensor waives and/or agrees not to
431 | assert any such rights held by the Licensor to the limited
432 | extent necessary to allow You to exercise the Licensed
433 | Rights, but not otherwise.
434 |
435 | 2. Patent and trademark rights are not licensed under this
436 | Public License.
437 |
438 | 3. To the extent possible, the Licensor waives any right to
439 | collect royalties from You for the exercise of the Licensed
440 | Rights, whether directly or through a collecting society
441 | under any voluntary or waivable statutory or compulsory
442 | licensing scheme. In all other cases the Licensor expressly
443 | reserves any right to collect such royalties, including when
444 | the Licensed Material is used other than for NonCommercial
445 | purposes.
446 |
447 |
448 | Section 3 -- License Conditions.
449 |
450 | Your exercise of the Licensed Rights is expressly made subject to the
451 | following conditions.
452 |
453 | a. Attribution.
454 |
455 | 1. If You Share the Licensed Material (including in modified
456 | form), You must:
457 |
458 | a. retain the following if it is supplied by the Licensor
459 | with the Licensed Material:
460 |
461 | i. identification of the creator(s) of the Licensed
462 | Material and any others designated to receive
463 | attribution, in any reasonable manner requested by
464 | the Licensor (including by pseudonym if
465 | designated);
466 |
467 | ii. a copyright notice;
468 |
469 | iii. a notice that refers to this Public License;
470 |
471 | iv. a notice that refers to the disclaimer of
472 | warranties;
473 |
474 | v. a URI or hyperlink to the Licensed Material to the
475 | extent reasonably practicable;
476 |
477 | b. indicate if You modified the Licensed Material and
478 | retain an indication of any previous modifications; and
479 |
480 | c. indicate the Licensed Material is licensed under this
481 | Public License, and include the text of, or the URI or
482 | hyperlink to, this Public License.
483 |
484 | 2. You may satisfy the conditions in Section 3(a)(1) in any
485 | reasonable manner based on the medium, means, and context in
486 | which You Share the Licensed Material. For example, it may be
487 | reasonable to satisfy the conditions by providing a URI or
488 | hyperlink to a resource that includes the required
489 | information.
490 | 3. If requested by the Licensor, You must remove any of the
491 | information required by Section 3(a)(1)(A) to the extent
492 | reasonably practicable.
493 |
494 | b. ShareAlike.
495 |
496 | In addition to the conditions in Section 3(a), if You Share
497 | Adapted Material You produce, the following conditions also apply.
498 |
499 | 1. The Adapter's License You apply must be a Creative Commons
500 | license with the same License Elements, this version or
501 | later, or a BY-NC-SA Compatible License.
502 |
503 | 2. You must include the text of, or the URI or hyperlink to, the
504 | Adapter's License You apply. You may satisfy this condition
505 | in any reasonable manner based on the medium, means, and
506 | context in which You Share Adapted Material.
507 |
508 | 3. You may not offer or impose any additional or different terms
509 | or conditions on, or apply any Effective Technological
510 | Measures to, Adapted Material that restrict exercise of the
511 | rights granted under the Adapter's License You apply.
512 |
513 |
514 | Section 4 -- Sui Generis Database Rights.
515 |
516 | Where the Licensed Rights include Sui Generis Database Rights that
517 | apply to Your use of the Licensed Material:
518 |
519 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right
520 | to extract, reuse, reproduce, and Share all or a substantial
521 | portion of the contents of the database for NonCommercial purposes
522 | only;
523 |
524 | b. if You include all or a substantial portion of the database
525 | contents in a database in which You have Sui Generis Database
526 | Rights, then the database in which You have Sui Generis Database
527 | Rights (but not its individual contents) is Adapted Material,
528 | including for purposes of Section 3(b); and
529 |
530 | c. You must comply with the conditions in Section 3(a) if You Share
531 | all or a substantial portion of the contents of the database.
532 |
533 | For the avoidance of doubt, this Section 4 supplements and does not
534 | replace Your obligations under this Public License where the Licensed
535 | Rights include other Copyright and Similar Rights.
536 |
537 |
538 | Section 5 -- Disclaimer of Warranties and Limitation of Liability.
539 |
540 | a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
541 | EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
542 | AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
543 | ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
544 | IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
545 | WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
546 | PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
547 | ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
548 | KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
549 | ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
550 |
551 | b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
552 | TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
553 | NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
554 | INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
555 | COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
556 | USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
557 | ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
558 | DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
559 | IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
560 |
561 | c. The disclaimer of warranties and limitation of liability provided
562 | above shall be interpreted in a manner that, to the extent
563 | possible, most closely approximates an absolute disclaimer and
564 | waiver of all liability.
565 |
566 |
567 | Section 6 -- Term and Termination.
568 |
569 | a. This Public License applies for the term of the Copyright and
570 | Similar Rights licensed here. However, if You fail to comply with
571 | this Public License, then Your rights under this Public License
572 | terminate automatically.
573 |
574 | b. Where Your right to use the Licensed Material has terminated under
575 | Section 6(a), it reinstates:
576 |
577 | 1. automatically as of the date the violation is cured, provided
578 | it is cured within 30 days of Your discovery of the
579 | violation; or
580 |
581 | 2. upon express reinstatement by the Licensor.
582 |
583 | For the avoidance of doubt, this Section 6(b) does not affect any
584 | right the Licensor may have to seek remedies for Your violations
585 | of this Public License.
586 |
587 | c. For the avoidance of doubt, the Licensor may also offer the
588 | Licensed Material under separate terms or conditions or stop
589 | distributing the Licensed Material at any time; however, doing so
590 | will not terminate this Public License.
591 |
592 | d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
593 | License.
594 |
595 |
596 | Section 7 -- Other Terms and Conditions.
597 |
598 | a. The Licensor shall not be bound by any additional or different
599 | terms or conditions communicated by You unless expressly agreed.
600 |
601 | b. Any arrangements, understandings, or agreements regarding the
602 | Licensed Material not stated herein are separate from and
603 | independent of the terms and conditions of this Public License.
604 |
605 |
606 | Section 8 -- Interpretation.
607 |
608 | a. For the avoidance of doubt, this Public License does not, and
609 | shall not be interpreted to, reduce, limit, restrict, or impose
610 | conditions on any use of the Licensed Material that could lawfully
611 | be made without permission under this Public License.
612 |
613 | b. To the extent possible, if any provision of this Public License is
614 | deemed unenforceable, it shall be automatically reformed to the
615 | minimum extent necessary to make it enforceable. If the provision
616 | cannot be reformed, it shall be severed from this Public License
617 | without affecting the enforceability of the remaining terms and
618 | conditions.
619 |
620 | c. No term or condition of this Public License will be waived and no
621 | failure to comply consented to unless expressly agreed to by the
622 | Licensor.
623 |
624 | d. Nothing in this Public License constitutes or may be interpreted
625 | as a limitation upon, or waiver of, any privileges and immunities
626 | that apply to the Licensor or You, including from the legal
627 | processes of any jurisdiction or authority.
628 |
629 | =======================================================================
630 |
631 | Creative Commons is not a party to its public licenses.
632 | Notwithstanding, Creative Commons may elect to apply one of its public
633 | licenses to material it publishes and in those instances will be
634 | considered the "Licensor." Except for the limited purpose of indicating
635 | that material is shared under a Creative Commons public license or as
636 | otherwise permitted by the Creative Commons policies published at
637 | creativecommons.org/policies, Creative Commons does not authorize the
638 | use of the trademark "Creative Commons" or any other trademark or logo
639 | of Creative Commons without its prior written consent including,
640 | without limitation, in connection with any unauthorized modifications
641 | to any of its public licenses or any other arrangements,
642 | understandings, or agreements concerning use of licensed material. For
643 | the avoidance of doubt, this paragraph does not form part of the public
644 | licenses.
645 |
646 | Creative Commons may be contacted at creativecommons.org.
647 |
648 |
--------------------------------------------------------------------------------