diff --git a/.gitignore b/.gitignore
index f9e9ca8..101d97c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -17,3 +17,7 @@ build/
.gradle/
local.properties
+
+#Idea
+*.iml
+/.idea
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..3813ca9
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,8 @@
+The MIT License (MIT)
+Copyright (c) 2016 ToggleButton
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/README.md b/README.md
index a1dd340..b6bb40e 100644
--- a/README.md
+++ b/README.md
@@ -3,7 +3,10 @@ ToggleButton
ToggleButton Widget For Android Developers
-
+@Deprecated
+!!!项目已经停止维护,新项目移至https://github.com/zcweng/SwitchButton !!!
+
+
How To Use
```xml
@@ -12,11 +15,11 @@ ToggleButton Widget For Android Developers
```
@@ -47,4 +50,10 @@ ToggleButton Widget For Android Developers
Default Size:width=50dp,height=30dp.
-
+
+
+引用方式
+```
+2016/8/3 17:04:53
+compile 'com.zcw:togglebutton-library:1.0.0'
+```
diff --git a/ToggleButtonLib/.classpath b/ToggleButtonLib/.classpath
deleted file mode 100644
index 7bc01d9..0000000
--- a/ToggleButtonLib/.classpath
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
-
-
-
-
-
-
-
diff --git a/ToggleButtonLib/.project b/ToggleButtonLib/.project
deleted file mode 100644
index 6fd14db..0000000
--- a/ToggleButtonLib/.project
+++ /dev/null
@@ -1,33 +0,0 @@
-
-
- ToggleButtonLib
-
-
-
-
-
- com.android.ide.eclipse.adt.ResourceManagerBuilder
-
-
-
-
- com.android.ide.eclipse.adt.PreCompilerBuilder
-
-
-
-
- org.eclipse.jdt.core.javabuilder
-
-
-
-
- com.android.ide.eclipse.adt.ApkBuilder
-
-
-
-
-
- com.android.ide.eclipse.adt.AndroidNature
- org.eclipse.jdt.core.javanature
-
-
diff --git a/ToggleButtonLib/bin/AndroidManifest.xml b/ToggleButtonLib/bin/AndroidManifest.xml
deleted file mode 100644
index 713f807..0000000
--- a/ToggleButtonLib/bin/AndroidManifest.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
diff --git a/ToggleButtonLib/bin/R.txt b/ToggleButtonLib/bin/R.txt
deleted file mode 100644
index ae45383..0000000
--- a/ToggleButtonLib/bin/R.txt
+++ /dev/null
@@ -1,11 +0,0 @@
-int attr borderWidth 0x7f010000
-int attr offBorderColor 0x7f010001
-int attr offColor 0x7f010002
-int attr onColor 0x7f010003
-int attr spotColor 0x7f010004
-int[] styleable ToggleButton { 0x7f010000, 0x7f010001, 0x7f010002, 0x7f010003, 0x7f010004 }
-int styleable ToggleButton_borderWidth 0
-int styleable ToggleButton_offBorderColor 1
-int styleable ToggleButton_offColor 2
-int styleable ToggleButton_onColor 3
-int styleable ToggleButton_spotColor 4
diff --git a/ToggleButtonLib/bin/togglebuttonlib.jar b/ToggleButtonLib/bin/togglebuttonlib.jar
deleted file mode 100644
index d453e2b..0000000
Binary files a/ToggleButtonLib/bin/togglebuttonlib.jar and /dev/null differ
diff --git a/ToggleButtonLib/build.gradle b/ToggleButtonLib/build.gradle
deleted file mode 100644
index 272edbe..0000000
--- a/ToggleButtonLib/build.gradle
+++ /dev/null
@@ -1,39 +0,0 @@
-apply plugin: 'android-sdk-manager'
-apply plugin: 'com.android.library'
-
-dependencies {
- compile 'com.facebook.rebound:rebound:0.3.+'
-}
-
-android {
- compileSdkVersion 21
- buildToolsVersion '21.1.0'
-
- compileOptions {
- sourceCompatibility JavaVersion.VERSION_1_7
- targetCompatibility JavaVersion.VERSION_1_7
- }
-
- defaultConfig {
- minSdkVersion 8
- targetSdkVersion 21
- }
-
- sourceSets {
- main {
- manifest.srcFile 'AndroidManifest.xml'
- java.srcDirs = ['src']
- resources.srcDirs = ['src']
- aidl.srcDirs = ['src']
- renderscript.srcDirs = ['src']
- res.srcDirs = ['res']
- assets.srcDirs = ['assets']
- }
- }
-
- lintOptions {
- abortOnError false
- }
-}
-
-apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle'
diff --git a/ToggleButtonLib/res/values/toggle_button_attrs.xml b/ToggleButtonLib/res/values/toggle_button_attrs.xml
deleted file mode 100644
index e3dfa13..0000000
--- a/ToggleButtonLib/res/values/toggle_button_attrs.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/ToggleButtonLib/src/com/facebook/rebound/AndroidSpringLooperFactory.java b/ToggleButtonLib/src/com/facebook/rebound/AndroidSpringLooperFactory.java
deleted file mode 100644
index f6fb01e..0000000
--- a/ToggleButtonLib/src/com/facebook/rebound/AndroidSpringLooperFactory.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * Copyright (c) 2013, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- *
- */
-
-package com.facebook.rebound;
-
-import android.annotation.TargetApi;
-import android.os.Build;
-import android.os.Handler;
-import android.os.SystemClock;
-import android.view.Choreographer;
-
-/**
- * Android version of the spring looper that uses the most appropriate frame callback mechanism
- * available. It uses Android's {@link Choreographer} when available, otherwise it uses a
- * {@link Handler}.
- */
-abstract class AndroidSpringLooperFactory {
-
- /**
- * Create an Android {@link com.facebook.rebound.SpringLooper} for the detected Android platform.
- * @return a SpringLooper
- */
- public static SpringLooper createSpringLooper() {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
- return ChoreographerAndroidSpringLooper.create();
- } else {
- return LegacyAndroidSpringLooper.create();
- }
- }
-
- /**
- * The base implementation of the Android spring looper, using a {@link Handler} for the
- * frame callbacks.
- */
- private static class LegacyAndroidSpringLooper extends SpringLooper {
-
- private final Handler mHandler;
- private final Runnable mLooperRunnable;
- private boolean mStarted;
- private long mLastTime;
-
- /**
- * @return an Android spring looper using a new {@link Handler} instance
- */
- public static SpringLooper create() {
- return new LegacyAndroidSpringLooper(new Handler());
- }
-
- public LegacyAndroidSpringLooper(Handler handler) {
- mHandler = handler;
- mLooperRunnable = new Runnable() {
- @Override
- public void run() {
- if (!mStarted || mSpringSystem == null) {
- return;
- }
- long currentTime = SystemClock.uptimeMillis();
- mSpringSystem.loop(currentTime - mLastTime);
- mHandler.post(mLooperRunnable);
- }
- };
- }
-
- @Override
- public void start() {
- if (mStarted) {
- return;
- }
- mStarted = true;
- mLastTime = SystemClock.uptimeMillis();
- mHandler.removeCallbacks(mLooperRunnable);
- mHandler.post(mLooperRunnable);
- }
-
- @Override
- public void stop() {
- mStarted = false;
- mHandler.removeCallbacks(mLooperRunnable);
- }
- }
-
- /**
- * The Jelly Bean and up implementation of the spring looper that uses Android's
- * {@link Choreographer} instead of a {@link Handler}
- */
- @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
- private static class ChoreographerAndroidSpringLooper extends SpringLooper {
-
- private final Choreographer mChoreographer;
- private final Choreographer.FrameCallback mFrameCallback;
- private boolean mStarted;
- private long mLastTime;
-
- /**
- * @return an Android spring choreographer using the system {@link Choreographer}
- */
- public static ChoreographerAndroidSpringLooper create() {
- return new ChoreographerAndroidSpringLooper(Choreographer.getInstance());
- }
-
- public ChoreographerAndroidSpringLooper(Choreographer choreographer) {
- mChoreographer = choreographer;
- mFrameCallback = new Choreographer.FrameCallback() {
- @Override
- public void doFrame(long frameTimeNanos) {
- if (!mStarted || mSpringSystem == null) {
- return;
- }
- long currentTime = SystemClock.uptimeMillis();
- mSpringSystem.loop(currentTime - mLastTime);
- mLastTime = currentTime;
- mChoreographer.postFrameCallback(mFrameCallback);
- }
- };
- }
-
- @Override
- public void start() {
- if (mStarted) {
- return;
- }
- mStarted = true;
- mLastTime = SystemClock.uptimeMillis();
- mChoreographer.removeFrameCallback(mFrameCallback);
- mChoreographer.postFrameCallback(mFrameCallback);
- }
-
- @Override
- public void stop() {
- mStarted = false;
- mChoreographer.removeFrameCallback(mFrameCallback);
- }
- }
-}
\ No newline at end of file
diff --git a/ToggleButtonLib/src/com/facebook/rebound/BaseSpringSystem.java b/ToggleButtonLib/src/com/facebook/rebound/BaseSpringSystem.java
deleted file mode 100644
index 967a5ab..0000000
--- a/ToggleButtonLib/src/com/facebook/rebound/BaseSpringSystem.java
+++ /dev/null
@@ -1,194 +0,0 @@
-/*
- * Copyright (c) 2013, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- *
- */
-
-package com.facebook.rebound;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.CopyOnWriteArraySet;
-
-/**
- * BaseSpringSystem maintains the set of springs within an Application context. It is responsible for
- * Running the spring integration loop and maintains a registry of all the Springs it solves for.
- * In addition to listening to physics events on the individual Springs in the system, listeners
- * can be added to the BaseSpringSystem itself to provide pre and post integration setup.
- */
-public class BaseSpringSystem {
-
- private final Map mSpringRegistry = new HashMap();
- private final Set mActiveSprings = new CopyOnWriteArraySet();
- private final SpringLooper mSpringLooper;
- private final CopyOnWriteArraySet mListeners = new CopyOnWriteArraySet();
- private boolean mIdle = true;
-
- /**
- * create a new BaseSpringSystem
- * @param springLooper parameterized springLooper to allow testability of the
- * physics loop
- */
- public BaseSpringSystem(SpringLooper springLooper) {
- if (springLooper == null) {
- throw new IllegalArgumentException("springLooper is required");
- }
- mSpringLooper = springLooper;
- mSpringLooper.setSpringSystem(this);
- }
-
- /**
- * check if the system is idle
- * @return is the system idle
- */
- public boolean getIsIdle() {
- return mIdle;
- }
-
- /**
- * create a spring with a random uuid for its name.
- * @return the spring
- */
- public Spring createSpring() {
- Spring spring = new Spring(this);
- registerSpring(spring);
- return spring;
- }
-
- /**
- * get a spring by name
- * @param id id of the spring to retrieve
- * @return Spring with the specified key
- */
- public Spring getSpringById(String id) {
- if (id == null) {
- throw new IllegalArgumentException("id is required");
- }
- return mSpringRegistry.get(id);
- }
-
- /**
- * return all the springs in the simulator
- * @return all the springs
- */
- public List getAllSprings() {
- Collection collection = mSpringRegistry.values();
- List list;
- if (collection instanceof List) {
- list = (List)collection;
- } else {
- list = new ArrayList(collection);
- }
- return Collections.unmodifiableList(list);
- }
-
- /**
- * Registers a Spring to this BaseSpringSystem so it can be iterated if active.
- * @param spring the Spring to register
- */
- void registerSpring(Spring spring) {
- if (spring == null) {
- throw new IllegalArgumentException("spring is required");
- }
- if (mSpringRegistry.containsKey(spring.getId())) {
- throw new IllegalArgumentException("spring is already registered"); }
- mSpringRegistry.put(spring.getId(), spring);
- }
-
- /**
- * Deregisters a Spring from this BaseSpringSystem, so it won't be iterated anymore. The Spring should
- * not be used anymore after doing this.
- *
- * @param spring the Spring to deregister
- */
- void deregisterSpring(Spring spring) {
- if (spring == null) {
- throw new IllegalArgumentException("spring is required");
- }
- mActiveSprings.remove(spring);
- mSpringRegistry.remove(spring.getId());
- }
-
- /**
- * update the springs in the system
- * @param deltaTime delta since last update in millis
- */
- void advance(double deltaTime) {
- for (Spring spring : mActiveSprings) {
- // advance time in seconds
- if (spring.systemShouldAdvance()) {
- spring.advance(deltaTime / 1000.0);
- } else {
- mActiveSprings.remove(spring);
- }
- }
- }
-
- /**
- * loop the system until idle
- */
- public void loop(double ellapsedMillis) {
- for (SpringSystemListener listener : mListeners) {
- listener.onBeforeIntegrate(this);
- }
- advance(ellapsedMillis);
- if (mActiveSprings.isEmpty()) {
- mIdle = true;
- }
- for (SpringSystemListener listener : mListeners) {
- listener.onAfterIntegrate(this);
- }
- if (mIdle) {
- mSpringLooper.stop();
- }
- }
-
- /**
- * This is used internally by the {@link Spring}s created by this {@link BaseSpringSystem} to notify
- * it has reached a state where it needs to be iterated. This will add the spring to the list of
- * active springs on this system and start the iteration if the system was idle before this call.
- * @param springId the id of the Spring to be activated
- */
- void activateSpring(String springId) {
- Spring spring = mSpringRegistry.get(springId);
- if (spring == null) {
- throw new IllegalArgumentException("springId " + springId + " does not reference a registered spring");
- }
- mActiveSprings.add(spring);
- if (getIsIdle()) {
- mIdle = false;
- mSpringLooper.start();
- }
- }
-
- /** listeners **/
-
- public void addListener(SpringSystemListener newListener) {
- if (newListener == null) {
- throw new IllegalArgumentException("newListener is required");
- }
- mListeners.add(newListener);
- }
-
- public void removeListener(SpringSystemListener listenerToRemove) {
- if (listenerToRemove == null) {
- throw new IllegalArgumentException("listenerToRemove is required");
- }
- mListeners.remove(listenerToRemove);
- }
-
- public void removeAllListeners() {
- mListeners.clear();
- }
-}
-
-
diff --git a/ToggleButtonLib/src/com/facebook/rebound/OrigamiValueConverter.java b/ToggleButtonLib/src/com/facebook/rebound/OrigamiValueConverter.java
deleted file mode 100644
index 4c99b76..0000000
--- a/ToggleButtonLib/src/com/facebook/rebound/OrigamiValueConverter.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package com.facebook.rebound;
-
-/**
- * Helper math util to convert tension & friction values from the Origami design tool to values that
- * the spring system needs.
- */
-public class OrigamiValueConverter {
-
- public static double tensionFromOrigamiValue(double oValue) {
- return oValue == 0 ? 0 : (oValue - 30.0) * 3.62 + 194.0;
- }
-
- public static double origamiValueFromTension(double tension) {
- return tension == 0 ? 0 : (tension - 194.0) / 3.62 + 30.0;
- }
-
- public static double frictionFromOrigamiValue(double oValue) {
- return oValue == 0 ? 0 : (oValue - 8.0) * 3.0 + 25.0;
- }
-
- public static double origamiValueFromFriction(double friction) {
- return friction == 0 ? 0 : (friction - 25.0) / 3.0 + 8.0;
- }
-
-}
diff --git a/ToggleButtonLib/src/com/facebook/rebound/SimpleSpringListener.java b/ToggleButtonLib/src/com/facebook/rebound/SimpleSpringListener.java
deleted file mode 100644
index 0bf41ba..0000000
--- a/ToggleButtonLib/src/com/facebook/rebound/SimpleSpringListener.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (c) 2013, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- *
- */
-
-package com.facebook.rebound;
-
-public class SimpleSpringListener implements SpringListener {
- @Override
- public void onSpringUpdate(Spring spring) {
- }
-
- @Override
- public void onSpringAtRest(Spring spring) {
- }
-
- @Override
- public void onSpringActivate(Spring spring) {
- }
-
- @Override
- public void onSpringEndStateChange(Spring spring) {
- }
-}
diff --git a/ToggleButtonLib/src/com/facebook/rebound/Spring.java b/ToggleButtonLib/src/com/facebook/rebound/Spring.java
deleted file mode 100644
index 4ea2470..0000000
--- a/ToggleButtonLib/src/com/facebook/rebound/Spring.java
+++ /dev/null
@@ -1,519 +0,0 @@
-/*
- * Copyright (c) 2013, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- *
- */
-
-package com.facebook.rebound;
-
-import java.util.concurrent.CopyOnWriteArraySet;
-
-/**
- * Classical spring implementing Hooke's law with configurable friction and tension.
- */
-public class Spring {
-
- // unique incrementer id for springs
- private static int ID = 0;
-
- // maximum amount of time to simulate per physics iteration in seconds (4 frames at 60 FPS)
- private static final double MAX_DELTA_TIME_SEC = 0.064;
- // fixed timestep to use in the physics solver in seconds
- private static final double SOLVER_TIMESTEP_SEC = 0.001;
- private SpringConfig mSpringConfig;
- private boolean mOvershootClampingEnabled;
-
- // storage for the current and prior physics state while integration is occurring
- private static class PhysicsState {
- double position;
- double velocity;
- }
-
- // unique id for the spring in the system
- private final String mId;
- // all physics simulation objects are final and reused in each processing pass
- private final PhysicsState mCurrentState = new PhysicsState();
- private final PhysicsState mPreviousState = new PhysicsState();
- private final PhysicsState mTempState = new PhysicsState();
- private double mStartValue;
- private double mEndValue;
- private boolean mWasAtRest = true;
- // thresholds for determining when the spring is at rest
- private double mRestSpeedThreshold = 0.005;
- private double mDisplacementFromRestThreshold = 0.005;
- private CopyOnWriteArraySet mListeners = new CopyOnWriteArraySet();
- private double mTimeAccumulator = 0;
-
- private final BaseSpringSystem mSpringSystem;
-
- /**
- * create a new spring
- */
- Spring(BaseSpringSystem springSystem) {
- if (springSystem == null) {
- throw new IllegalArgumentException("Spring cannot be created outside of a BaseSpringSystem");
- }
- mSpringSystem = springSystem;
- mId = "spring:" + ID++;
- setSpringConfig(SpringConfig.defaultConfig);
- }
-
- /**
- * Destroys this Spring, meaning that it will be deregistered from its BaseSpringSystem so it won't be
- * iterated anymore and will clear its set of listeners. Do not use the Spring after calling this,
- * doing so may just cause an exception to be thrown.
- */
- public void destroy() {
- mListeners.clear();
- mSpringSystem.deregisterSpring(this);
- }
-
- /**
- * get the unique id for this spring
- * @return the unique id
- */
- public String getId() {
- return mId;
- }
-
- /**
- * set the config class
- * @param springConfig config class for the spring
- * @return this Spring instance for chaining
- */
- public Spring setSpringConfig(SpringConfig springConfig) {
- if (springConfig == null) {
- throw new IllegalArgumentException("springConfig is required");
- }
- mSpringConfig = springConfig;
- return this;
- }
-
- /**
- * retrieve the spring config for this spring
- * @return the SpringConfig applied to this spring
- */
- public SpringConfig getSpringConfig() {
- return mSpringConfig;
- }
-
- /**
- * Set the displaced value to determine the displacement for the spring from the rest value.
- * This value is retained and used to calculate the displacement ratio.
- * This also updates the start value of the Spring.
- * @param currentValue the new start and current value for the spring
- * @return the spring for chaining
- */
- public Spring setCurrentValue(double currentValue) {
- mStartValue = currentValue;
- mCurrentState.position = currentValue;
- mSpringSystem.activateSpring(this.getId());
- for (SpringListener listener : mListeners) {
- listener.onSpringUpdate(this);
- }
- return this;
- }
-
- /**
- * Get the displacement value from the last time setCurrentValue was called.
- * @return displacement value
- */
- public double getStartValue() {
- return mStartValue;
- }
-
- /**
- * Get the current
- * @return current value
- */
- public double getCurrentValue() {
- return mCurrentState.position;
- }
-
- /**
- * get the displacement of the springs current value from its rest value.
- * @return the distance displaced by
- */
- public double getCurrentDisplacementDistance() {
- return getDisplacementDistanceForState(mCurrentState);
- }
-
- /**
- * get the displacement from rest for a given physics state
- * @param state the state to measure from
- * @return the distance displaced by
- */
- private double getDisplacementDistanceForState(PhysicsState state) {
- return Math.abs(mEndValue - state.position);
- }
-
- /**
- * set the rest value to determine the displacement for the spring
- * @param endValue the endValue for the spring
- * @return the spring for chaining
- */
- public Spring setEndValue(double endValue) {
- if (mEndValue == endValue && isAtRest()) {
- return this;
- }
- mStartValue = getCurrentValue();
- mEndValue = endValue;
- mSpringSystem.activateSpring(this.getId());
- for (SpringListener listener : mListeners) {
- listener.onSpringEndStateChange(this);
- }
- return this;
- }
-
- /**
- * get the rest value used for determining the displacement of the spring
- * @return the rest value for the spring
- */
- public double getEndValue() {
- return mEndValue;
- }
-
- /**
- * set the velocity on the spring in pixels per second
- * @return the spring for chaining
- */
- public Spring setVelocity(double velocity) {
- mCurrentState.velocity = velocity;
- mSpringSystem.activateSpring(this.getId());
- return this;
- }
-
- /**
- * get the velocity of the spring
- * @return the current velocity
- */
- public double getVelocity() {
- return mCurrentState.velocity;
- }
-
- /**
- * Sets the speed at which the spring should be considered at rest.
- * @param restSpeedThreshold speed pixels per second
- * @return the spring for chaining
- */
- public Spring setRestSpeedThreshold(double restSpeedThreshold) {
- mRestSpeedThreshold = restSpeedThreshold;
- return this;
- }
-
- /**
- * Returns the speed at which the spring should be considered at rest in pixels per second
- * @return speed in pixels per second
- */
- public double getRestSpeedThreshold() {
- return mRestSpeedThreshold;
- }
-
- /**
- * set the threshold of displacement from rest below which the spring should be considered at rest
- * @param displacementFromRestThreshold displacement to consider resting below
- * @return the spring for chaining
- */
- public Spring setRestDisplacementThreshold(double displacementFromRestThreshold) {
- mDisplacementFromRestThreshold = displacementFromRestThreshold;
- return this;
- }
-
- /**
- * get the threshold of displacement from rest below which the spring should be considered at rest
- * @return displacement to consider resting below
- */
- public double getRestDisplacementThreshold() {
- return mDisplacementFromRestThreshold;
- }
-
- /**
- * Force the spring to clamp at its end value to avoid overshooting the target value.
- * @param overshootClampingEnabled whether or not to enable overshoot clamping
- * @return the spring for chaining
- */
- public Spring setOvershootClampingEnabled(boolean overshootClampingEnabled) {
- mOvershootClampingEnabled = overshootClampingEnabled;
- return this;
- }
-
- /**
- * Check if overshoot clamping is enabled.
- * @return is overshoot clamping enabled
- */
- public boolean isOvershootClampingEnabled() {
- return mOvershootClampingEnabled;
- }
-
- /**
- * Check if the spring is overshooting beyond its target.
- * @return true if the spring is overshooting its target
- */
- public boolean isOvershooting() {
- return (mStartValue < mEndValue && getCurrentValue() > mEndValue) ||
- (mStartValue > mEndValue && getCurrentValue() < mEndValue);
- }
-
- /**
- * advance the physics simulation in SOLVER_TIMESTEP_SEC sized chunks to fulfill the required
- * realTimeDelta.
- * The math is inlined inside the loop since it made a huge performance impact when there are
- * several springs being advanced.
- * @param time clock time
- * @param realDeltaTime clock drift
- */
- void advance(double realDeltaTime) {
-
- boolean isAtRest = isAtRest();
-
- if (isAtRest && mWasAtRest) {
- /* begin debug
- Log.d(TAG, "bailing out because we are at rest:" + getName());
- end debug */
- return;
- }
-
- // clamp the amount of realTime to simulate to avoid stuttering in the UI. We should be able
- // to catch up in a subsequent advance if necessary.
- double adjustedDeltaTime = realDeltaTime;
- if (realDeltaTime > MAX_DELTA_TIME_SEC) {
- adjustedDeltaTime = MAX_DELTA_TIME_SEC;
- }
-
- /* begin debug
- long startTime = System.currentTimeMillis();
- int iterations = 0;
- end debug */
-
- mTimeAccumulator += adjustedDeltaTime;
-
- double tension = mSpringConfig.tension;
- double friction = mSpringConfig.friction;
-
- double position = mCurrentState.position;
- double velocity = mCurrentState.velocity;
- double tempPosition = mTempState.position;
- double tempVelocity = mTempState.velocity;
-
- double aVelocity, aAcceleration;
- double bVelocity, bAcceleration;
- double cVelocity, cAcceleration;
- double dVelocity, dAcceleration;
-
- double dxdt, dvdt;
-
- // iterate over the true time
- while (mTimeAccumulator >= SOLVER_TIMESTEP_SEC) {
- /* begin debug
- iterations++;
- end debug */
- mTimeAccumulator -= SOLVER_TIMESTEP_SEC;
-
- if (mTimeAccumulator < SOLVER_TIMESTEP_SEC) {
- // This will be the last iteration. Remember the previous state in case we need to
- // interpolate
- mPreviousState.position = position;
- mPreviousState.velocity = velocity;
- }
-
- // Perform an RK4 integration to provide better detection of the acceleration curve via
- // sampling of Euler integrations at 4 intervals feeding each derivative into the calculation
- // of the next and taking a weighted sum of the 4 derivatives as the final output.
-
- // This math was inlined since it made for big performance improvements when advancing several
- // springs in one pass of the BaseSpringSystem.
-
- // The initial derivative is based on the current velocity and the calculated acceleration
- aVelocity = velocity;
- aAcceleration = (tension * (mEndValue - tempPosition)) - friction * velocity;
-
- // Calculate the next derivatives starting with the last derivative and integrating over the
- // timestep
- tempPosition = position + aVelocity * SOLVER_TIMESTEP_SEC * 0.5;
- tempVelocity = velocity + aAcceleration * SOLVER_TIMESTEP_SEC * 0.5;
- bVelocity = tempVelocity;
- bAcceleration = (tension * (mEndValue - tempPosition)) - friction * tempVelocity;
-
- tempPosition = position + bVelocity * SOLVER_TIMESTEP_SEC * 0.5;
- tempVelocity = velocity + bAcceleration * SOLVER_TIMESTEP_SEC * 0.5;
- cVelocity = tempVelocity;
- cAcceleration = (tension * (mEndValue - tempPosition)) - friction * tempVelocity;
-
- tempPosition = position + cVelocity * SOLVER_TIMESTEP_SEC;
- tempVelocity = velocity + cAcceleration * SOLVER_TIMESTEP_SEC;
- dVelocity = tempVelocity;
- dAcceleration = (tension * (mEndValue - tempPosition)) - friction * tempVelocity;
-
- // Take the weighted sum of the 4 derivatives as the final output.
- dxdt = 1.0/6.0 * (aVelocity + 2.0 * (bVelocity + cVelocity) + dVelocity);
- dvdt = 1.0/6.0 * (aAcceleration + 2.0 * (bAcceleration + cAcceleration) + dAcceleration);
-
- position += dxdt * SOLVER_TIMESTEP_SEC;
- velocity += dvdt * SOLVER_TIMESTEP_SEC;
- }
-
- mTempState.position = tempPosition;
- mTempState.velocity = tempVelocity;
-
- mCurrentState.position = position;
- mCurrentState.velocity = velocity;
-
- if (mTimeAccumulator > 0) {
- interpolate(mTimeAccumulator / SOLVER_TIMESTEP_SEC);
- }
-
- // End the spring immediately if it is overshooting and overshoot clamping is enabled.
- // Also make sure that if the spring was considered within a resting threshold that it's now
- // snapped to its end value.
- if (isAtRest() || (mOvershootClampingEnabled && isOvershooting())) {
- // Don't call setCurrentValue because that forces a call to onSpringUpdate
- mStartValue = mEndValue;
- mCurrentState.position = mEndValue;
- setVelocity(0);
- isAtRest = true;
- }
-
- /* begin debug
- long endTime = System.currentTimeMillis();
- long elapsedMillis = endTime - startTime;
- Log.d(TAG,
- "iterations:" + iterations +
- " iterationTime:" + elapsedMillis +
- " position:" + mCurrentState.position +
- " velocity:" + mCurrentState.velocity +
- " realDeltaTime:" + realDeltaTime +
- " adjustedDeltaTime:" + adjustedDeltaTime +
- " isAtRest:" + isAtRest +
- " wasAtRest:" + mWasAtRest);
- end debug */
-
- // NB: do these checks outside the loop so all listeners are properly notified of the state
- // transition
- boolean notifyActivate = false;
- if (mWasAtRest) {
- mWasAtRest = false;
- notifyActivate = true;
- }
- boolean notifyAtRest = false;
- if (isAtRest) {
- mWasAtRest = true;
- notifyAtRest = true;
- }
- for (SpringListener listener : mListeners) {
- // starting to move
- if (notifyActivate) {
- listener.onSpringActivate(this);
- }
-
- // updated
- listener.onSpringUpdate(this);
-
- // coming to rest
- if (notifyAtRest) {
- listener.onSpringAtRest(this);
- }
- }
- }
-
- /**
- * Check if this spring should be advanced by the system. * The rule is if the spring is
- * currently at rest and it was at rest in the previous advance, the system can skip this spring
- * @return should the system process this spring
- */
- public boolean systemShouldAdvance() {
- return !isAtRest() || !wasAtRest();
- }
-
- /**
- * Check if the spring was at rest in the prior iteration. This is used for ensuring the ending
- * callbacks are fired as the spring comes to a rest.
- * @return true if the spring was at rest in the prior iteration
- */
- public boolean wasAtRest() {
- return mWasAtRest;
- }
-
- /**
- * check if the current state is at rest
- * @return is the spring at rest
- */
- public boolean isAtRest() {
- return Math.abs(mCurrentState.velocity) <= mRestSpeedThreshold &&
- getDisplacementDistanceForState(mCurrentState) <= mDisplacementFromRestThreshold;
- }
-
- /**
- * Set the spring to be at rest by making its end value equal to its current value and setting
- * velocity to 0.
- */
- public Spring setAtRest() {
- mEndValue = mCurrentState.position;
- mTempState.position = mCurrentState.position;
- mCurrentState.velocity = 0;
- return this;
- }
-
- /**
- * linear interpolation between the previous and current physics state based on the amount of
- * timestep remaining after processing the rendering delta time in timestep sized chunks.
- * @param alpha from 0 to 1, where 0 is the previous state, 1 is the current state
- */
- private void interpolate(double alpha) {
- mCurrentState.position = mCurrentState.position * alpha + mPreviousState.position *(1-alpha);
- mCurrentState.velocity = mCurrentState.velocity * alpha + mPreviousState.velocity *(1-alpha);
- }
-
- /** listeners **/
-
- /**
- * add a listener
- * @param newListener to add
- * @return the spring for chaining
- */
- public Spring addListener(SpringListener newListener) {
- if (newListener == null) {
- throw new IllegalArgumentException("newListener is required");
- }
- mListeners.add(newListener);
- return this;
- }
-
- /**
- * remove a listener
- * @param listenerToRemove to remove
- * @return the spring for chaining
- */
- public Spring removeListener(SpringListener listenerToRemove) {
- if (listenerToRemove == null) {
- throw new IllegalArgumentException("listenerToRemove is required");
- }
- mListeners.remove(listenerToRemove);
- return this;
- }
-
- /**
- * remove all of the listeners
- * @return the spring for chaining
- */
- public Spring removeAllListeners() {
- mListeners.clear();
- return this;
- }
-
- /**
- * This method checks to see that the current spring displacement value is equal to the input,
- * accounting for the spring's rest displacement threshold.
- * @param value The value to compare the spring value to
- * @return Whether the displacement value from the spring is within the bounds of the compare
- * value, accounting for threshold
- */
- public boolean currentValueIsApproximately(double value) {
- return Math.abs(getCurrentValue() - value) <= getRestDisplacementThreshold();
- }
-
-}
-
diff --git a/ToggleButtonLib/src/com/facebook/rebound/SpringConfig.java b/ToggleButtonLib/src/com/facebook/rebound/SpringConfig.java
deleted file mode 100644
index a28b5d2..0000000
--- a/ToggleButtonLib/src/com/facebook/rebound/SpringConfig.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (c) 2013, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- *
- */
-
-package com.facebook.rebound;
-
-/**
- * Data structure for storing spring configuration.
- */
-public class SpringConfig {
- public double friction;
- public double tension;
-
- public static SpringConfig defaultConfig = SpringConfig.fromOrigamiTensionAndFriction(40, 7);
-
- /**
- * constructor for the SpringConfig
- * @param tension tension value for the SpringConfig
- * @param friction friction value for the SpringConfig
- */
- public SpringConfig(double tension, double friction) {
- this.tension = tension;
- this.friction = friction;
- }
-
- /**
- * A helper to make creating a SpringConfig easier with values mapping to the Origami values.
- * @param qcTension tension as defined in the Quartz Composition
- * @param qcFriction friction as defined in the Quartz Composition
- * @return a SpringConfig that maps to these values
- */
- public static SpringConfig fromOrigamiTensionAndFriction(double qcTension, double qcFriction) {
- return new SpringConfig(
- OrigamiValueConverter.tensionFromOrigamiValue(qcTension),
- OrigamiValueConverter.frictionFromOrigamiValue(qcFriction)
- );
- }
-}
diff --git a/ToggleButtonLib/src/com/facebook/rebound/SpringConfigRegistry.java b/ToggleButtonLib/src/com/facebook/rebound/SpringConfigRegistry.java
deleted file mode 100644
index 8771db2..0000000
--- a/ToggleButtonLib/src/com/facebook/rebound/SpringConfigRegistry.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Copyright (c) 2013, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- *
- */
-
-package com.facebook.rebound;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * class for maintaining a registry of all spring configs
- */
-public class SpringConfigRegistry {
-
- private static final SpringConfigRegistry INSTANCE = new SpringConfigRegistry(true);
-
- public static SpringConfigRegistry getInstance() {
- return INSTANCE;
- }
-
- private final Map mSpringConfigMap;
-
- /**
- * constructor for the SpringConfigRegistry
- */
- SpringConfigRegistry(boolean includeDefaultEntry) {
- mSpringConfigMap = new HashMap();
- if (includeDefaultEntry) {
- addSpringConfig(SpringConfig.defaultConfig, "default config");
- }
- }
-
- /**
- * add a SpringConfig to the registry
- *
- * @param springConfig SpringConfig to add to the registry
- * @param configName name to give the SpringConfig in the registry
- * @return true if the SpringConfig was added, false if a config with that name is already
- * present.
- */
- public boolean addSpringConfig(SpringConfig springConfig, String configName) {
- if (springConfig == null) {
- throw new IllegalArgumentException("springConfig is required");
- }
- if (configName == null) {
- throw new IllegalArgumentException("configName is required");
- }
- if (mSpringConfigMap.containsKey(springConfig)) {
- return false;
- }
- mSpringConfigMap.put(springConfig, configName);
- return true;
- }
-
- /**
- * remove a specific SpringConfig from the registry
- * @param springConfig the of the SpringConfig to remove
- * @return true if the SpringConfig was removed, false if it was not present.
- */
- public boolean removeSpringConfig(SpringConfig springConfig) {
- if (springConfig == null) {
- throw new IllegalArgumentException("springConfig is required");
- }
- return mSpringConfigMap.remove(springConfig) != null;
- }
-
- /**
- * retrieve all SpringConfig in the registry
- * @return a list of all SpringConfig
- */
- public Map getAllSpringConfig() {
- return Collections.unmodifiableMap(mSpringConfigMap);
- }
-
- /**
- * clear all SpringConfig in the registry
- */
- public void removeAllSpringConfig() {
- mSpringConfigMap.clear();
- }
-}
-
diff --git a/ToggleButtonLib/src/com/facebook/rebound/SpringListener.java b/ToggleButtonLib/src/com/facebook/rebound/SpringListener.java
deleted file mode 100644
index ae1f407..0000000
--- a/ToggleButtonLib/src/com/facebook/rebound/SpringListener.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (c) 2013, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- *
- */
-
-package com.facebook.rebound;
-
-public interface SpringListener {
-
- /**
- * called whenever the spring is updated
- * @param spring the Spring sending the update
- */
- void onSpringUpdate(Spring spring);
-
- /**
- * called whenever the spring achieves a resting state
- * @param spring the spring that's now resting
- */
- void onSpringAtRest(Spring spring);
-
- /**
- * called whenever the spring leaves its resting state
- * @param spring the spring that has left its resting state
- */
- void onSpringActivate(Spring spring);
-
- /**
- * called whenever the spring notifies of displacement state changes
- * @param spring the spring whose end state has changed
- */
- void onSpringEndStateChange(Spring spring);
-}
-
diff --git a/ToggleButtonLib/src/com/facebook/rebound/SpringLooper.java b/ToggleButtonLib/src/com/facebook/rebound/SpringLooper.java
deleted file mode 100644
index d25ddb9..0000000
--- a/ToggleButtonLib/src/com/facebook/rebound/SpringLooper.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (c) 2013, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- *
- */
-
-package com.facebook.rebound;
-
-/**
- * The spring looper is an interface for implementing platform-dependent run loops.
- */
-public abstract class SpringLooper {
-
- protected BaseSpringSystem mSpringSystem;
-
- /**
- * Set the BaseSpringSystem that the SpringLooper will call back to.
- * @param springSystem the spring system to call loop on.
- */
- public void setSpringSystem(BaseSpringSystem springSystem) {
- mSpringSystem = springSystem;
- }
-
- /**
- * The BaseSpringSystem has requested that the looper begins running this {@link Runnable}
- * on every frame. The {@link Runnable} will continue running on every frame until
- * {@link #stop()} is called.
- * If an existing {@link Runnable} had been started on this looper, it will be cancelled.
- */
- public abstract void start();
-
- /**
- * The looper will no longer run the {@link Runnable}.
- */
- public abstract void stop();
-}
\ No newline at end of file
diff --git a/ToggleButtonLib/src/com/facebook/rebound/SpringSystem.java b/ToggleButtonLib/src/com/facebook/rebound/SpringSystem.java
deleted file mode 100644
index 9881342..0000000
--- a/ToggleButtonLib/src/com/facebook/rebound/SpringSystem.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package com.facebook.rebound;
-
-/**
- * This is a wrapper for BaseSpringSystem that provides the convenience of automatically providing
- * the AndroidSpringLooper dependency in {@link SpringSystem#create}.
- */
-public class SpringSystem extends BaseSpringSystem {
-
- /**
- * Create a new SpringSystem providing the appropriate constructor parameters to work properly
- * in an Android environment.
- * @return the SpringSystem
- */
- public static SpringSystem create() {
- return new SpringSystem(AndroidSpringLooperFactory.createSpringLooper());
- }
-
- private SpringSystem(SpringLooper springLooper) {
- super(springLooper);
- }
-
-}
\ No newline at end of file
diff --git a/ToggleButtonLib/src/com/facebook/rebound/SpringSystemListener.java b/ToggleButtonLib/src/com/facebook/rebound/SpringSystemListener.java
deleted file mode 100644
index 9b4bc8e..0000000
--- a/ToggleButtonLib/src/com/facebook/rebound/SpringSystemListener.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (c) 2013, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- *
- */
-
-package com.facebook.rebound;
-
-/**
- * SpringSystemListener provides an interface for listening to events before and after each Physics
- * solving loop the BaseSpringSystem runs.
- */
-public interface SpringSystemListener {
-
- /**
- * Runs before each pass through the physics integration loop providing an opportunity to do any
- * setup or alterations to the Physics state before integrating.
- * @param springSystem the BaseSpringSystem listened to
- */
- void onBeforeIntegrate(BaseSpringSystem springSystem);
-
- /**
- * Runs after each pass through the physics integration loop providing an opportunity to do any
- * setup or alterations to the Physics state after integrating.
- * @param springSystem the BaseSpringSystem listened to
- */
- void onAfterIntegrate(BaseSpringSystem springSystem);
-}
-
diff --git a/ToggleButtonLib/src/com/facebook/rebound/SpringUtil.java b/ToggleButtonLib/src/com/facebook/rebound/SpringUtil.java
deleted file mode 100644
index bbe5dd8..0000000
--- a/ToggleButtonLib/src/com/facebook/rebound/SpringUtil.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (c) 2013, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- *
- */
-
-package com.facebook.rebound;
-
-public class SpringUtil {
-
- /**
- * Map a value within a given range to another range.
- * @param value the value to map
- * @param fromLow the low end of the range the value is within
- * @param fromHigh the high end of the range the value is within
- * @param toLow the low end of the range to map to
- * @param toHigh the high end of the range to map to
- * @return the mapped value
- */
- public static double mapValueFromRangeToRange(
- double value,
- double fromLow,
- double fromHigh,
- double toLow,
- double toHigh) {
- double fromRangeSize = fromHigh - fromLow;
- double toRangeSize = toHigh - toLow;
- double valueScale = (value - fromLow) / fromRangeSize;
- return toLow + (valueScale * toRangeSize);
- }
-
- /**
- * Clamp a value to be within the provided range.
- * @param value the value to clamp
- * @param low the low end of the range
- * @param high the high end of the range
- * @return the clamped value
- */
- public static double clamp(double value, double low, double high) {
- return Math.min(Math.max(value, low), high);
- }
-
- public static int clamp(int value, int low, int high) {
- return Math.min(Math.max(value, low), high);
- }
-
-
-}
-
diff --git a/ToggleButtonLib/src/com/facebook/rebound/SteppingLooper.java b/ToggleButtonLib/src/com/facebook/rebound/SteppingLooper.java
deleted file mode 100644
index 936f0fb..0000000
--- a/ToggleButtonLib/src/com/facebook/rebound/SteppingLooper.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- * Copyright (c) 2013, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- */
-
-package com.facebook.rebound;
-
-public class SteppingLooper extends SpringLooper {
-
- private boolean mStarted;
- private long mLastTime;
-
- @Override
- public void start() {
- mStarted = true;
- mLastTime = 0;
- }
-
- public boolean step(long interval) {
- if (mSpringSystem == null || !mStarted) {
- return false;
- }
- long currentTime = mLastTime + interval;
- mSpringSystem.loop(currentTime);
- mLastTime = currentTime;
- return mSpringSystem.getIsIdle();
- }
-
- @Override
- public void stop() {
- mStarted = false;
- }
-}
-
diff --git a/ToggleButtonLib/src/com/facebook/rebound/SynchronousLooper.java b/ToggleButtonLib/src/com/facebook/rebound/SynchronousLooper.java
deleted file mode 100644
index 652c3c3..0000000
--- a/ToggleButtonLib/src/com/facebook/rebound/SynchronousLooper.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/**
- * Copyright (c) 2013, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- */
-
-package com.facebook.rebound;
-
-public class SynchronousLooper extends SpringLooper {
-
- public static double SIXTY_FPS = 16.6667;
- private double mTimeStep;
- private boolean mRunning;
-
- public SynchronousLooper() {
- mTimeStep = SIXTY_FPS;
- }
-
- public double getTimeStep() {
- return mTimeStep;
- }
-
- public void setTimeStep(double timeStep) {
- mTimeStep = timeStep;
- }
-
- @Override
- public void start() {
- mRunning = true;
- while (!mSpringSystem.getIsIdle()) {
- if (mRunning == false) {
- break;
- }
- mSpringSystem.loop(mTimeStep);
- }
- }
-
- @Override
- public void stop() {
- mRunning = false;
- }
-}
-
diff --git a/ToggleButtonLib/src/com/facebook/rebound/ui/SpringConfiguratorView.java b/ToggleButtonLib/src/com/facebook/rebound/ui/SpringConfiguratorView.java
deleted file mode 100644
index 60e1e22..0000000
--- a/ToggleButtonLib/src/com/facebook/rebound/ui/SpringConfiguratorView.java
+++ /dev/null
@@ -1,419 +0,0 @@
-/*
- * Copyright (c) 2013, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- *
- */
-
-package com.facebook.rebound.ui;
-
-import android.annotation.TargetApi;
-import android.content.Context;
-import android.content.res.Resources;
-import android.graphics.Color;
-import android.os.Build;
-import android.util.AttributeSet;
-import android.view.Gravity;
-import android.view.MotionEvent;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.AbsListView;
-import android.widget.AdapterView;
-import android.widget.BaseAdapter;
-import android.widget.FrameLayout;
-import android.widget.LinearLayout;
-import android.widget.SeekBar;
-import android.widget.Spinner;
-import android.widget.TableLayout;
-import android.widget.TextView;
-
-import com.facebook.rebound.OrigamiValueConverter;
-import com.facebook.rebound.Spring;
-import com.facebook.rebound.SpringConfig;
-import com.facebook.rebound.SpringConfigRegistry;
-import com.facebook.rebound.SpringListener;
-import com.facebook.rebound.SpringSystem;
-
-import java.text.DecimalFormat;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import static com.facebook.rebound.ui.Util.*;
-
-/**
- * The SpringConfiguratorView provides a reusable view for live-editing all registered springs
- * within an Application. Each registered Spring can be accessed by its id and its tension and
- * friction properties can be edited while the user tests the effected UI live.
- */
-public class SpringConfiguratorView extends FrameLayout {
-
- private static final int MAX_SEEKBAR_VAL = 100000;
- private static final float MIN_TENSION = 0;
- private static final float MAX_TENSION = 200;
- private static final float MIN_FRICTION = 0;
- private static final float MAX_FRICTION = 50;
- private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("#.#");
-
- private final SpinnerAdapter spinnerAdapter;
- private final List mSpringConfigs = new ArrayList();
- private final Spring mRevealerSpring;
- private final float mStashPx;
- private final float mRevealPx;
- private final SpringConfigRegistry springConfigRegistry;
- private final int mTextColor = Color.argb(255, 225, 225, 225);
- private SeekBar mTensionSeekBar;
- private SeekBar mFrictionSeekBar;
- private Spinner mSpringSelectorSpinner;
- private TextView mFrictionLabel;
- private TextView mTensionLabel;
- private SpringConfig mSelectedSpringConfig;
-
- public SpringConfiguratorView(Context context) {
- this(context, null);
- }
-
- public SpringConfiguratorView(Context context, AttributeSet attrs) {
- this(context, attrs, 0);
- }
-
- @TargetApi(Build.VERSION_CODES.HONEYCOMB)
- public SpringConfiguratorView(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
-
- SpringSystem springSystem = SpringSystem.create();
- springConfigRegistry = SpringConfigRegistry.getInstance();
- spinnerAdapter = new SpinnerAdapter(context);
-
- Resources resources = getResources();
- mRevealPx = dpToPx(40, resources);
- mStashPx = dpToPx(280, resources);
-
- mRevealerSpring = springSystem.createSpring();
- SpringListener revealerSpringListener = new RevealerSpringListener();
- mRevealerSpring
- .setCurrentValue(1)
- .setEndValue(1)
- .addListener(revealerSpringListener);
-
- addView(generateHierarchy(context));
-
- SeekbarListener seekbarListener = new SeekbarListener();
- mTensionSeekBar.setMax(MAX_SEEKBAR_VAL);
- mTensionSeekBar.setOnSeekBarChangeListener(seekbarListener);
-
- mFrictionSeekBar.setMax(MAX_SEEKBAR_VAL);
- mFrictionSeekBar.setOnSeekBarChangeListener(seekbarListener);
-
- mSpringSelectorSpinner.setAdapter(spinnerAdapter);
- mSpringSelectorSpinner.setOnItemSelectedListener(new SpringSelectedListener());
- refreshSpringConfigurations();
-
- this.setTranslationY(mStashPx);
- }
-
- /**
- * Programmatically build up the view hierarchy to avoid the need for resources.
- * @return View hierarchy
- */
- private View generateHierarchy(Context context) {
- Resources resources = getResources();
-
- FrameLayout.LayoutParams params;
- int fivePx = dpToPx(5, resources);
- int tenPx = dpToPx(10, resources);
- int twentyPx = dpToPx(20, resources);
- TableLayout.LayoutParams tableLayoutParams = new TableLayout.LayoutParams(
- 0,
- ViewGroup.LayoutParams.WRAP_CONTENT,
- 1f);
- tableLayoutParams.setMargins(0, 0, fivePx, 0);
- LinearLayout seekWrapper;
-
- FrameLayout root = new FrameLayout(context);
- params = createLayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, dpToPx(300, resources));
- root.setLayoutParams(params);
-
- FrameLayout container = new FrameLayout(context);
- params = createMatchParams();
- params.setMargins(0, twentyPx, 0, 0);
- container.setLayoutParams(params);
- container.setBackgroundColor(Color.argb(100, 0, 0, 0));
- root.addView(container);
-
- mSpringSelectorSpinner = new Spinner(context, Spinner.MODE_DIALOG);
- params = createMatchWrapParams();
- params.gravity = Gravity.TOP;
- params.setMargins(tenPx, tenPx, tenPx, 0);
- mSpringSelectorSpinner.setLayoutParams(params);
- container.addView(mSpringSelectorSpinner);
-
- LinearLayout linearLayout = new LinearLayout(context);
- params = createMatchWrapParams();
- params.setMargins(0, 0, 0, dpToPx(80, resources));
- params.gravity = Gravity.BOTTOM;
- linearLayout.setLayoutParams(params);
- linearLayout.setOrientation(LinearLayout.VERTICAL);
- container.addView(linearLayout);
-
- seekWrapper = new LinearLayout(context);
- params = createMatchWrapParams();
- params.setMargins(tenPx, tenPx, tenPx, twentyPx);
- seekWrapper.setPadding(tenPx, tenPx, tenPx, tenPx);
- seekWrapper.setLayoutParams(params);
- seekWrapper.setOrientation(LinearLayout.HORIZONTAL);
- linearLayout.addView(seekWrapper);
-
- mTensionSeekBar = new SeekBar(context);
- mTensionSeekBar.setLayoutParams(tableLayoutParams);
- seekWrapper.addView(mTensionSeekBar);
-
- mTensionLabel = new TextView(getContext());
- mTensionLabel.setTextColor(mTextColor);
- params = createLayoutParams(
- dpToPx(50, resources),
- ViewGroup.LayoutParams.MATCH_PARENT);
- mTensionLabel.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
- mTensionLabel.setLayoutParams(params);
- mTensionLabel.setMaxLines(1);
- seekWrapper.addView(mTensionLabel);
-
- seekWrapper = new LinearLayout(context);
- params = createMatchWrapParams();
- params.setMargins(tenPx, tenPx, tenPx, twentyPx);
- seekWrapper.setPadding(tenPx, tenPx, tenPx, tenPx);
- seekWrapper.setLayoutParams(params);
- seekWrapper.setOrientation(LinearLayout.HORIZONTAL);
- linearLayout.addView(seekWrapper);
-
- mFrictionSeekBar = new SeekBar(context);
- mFrictionSeekBar.setLayoutParams(tableLayoutParams);
- seekWrapper.addView(mFrictionSeekBar);
-
- mFrictionLabel = new TextView(getContext());
- mFrictionLabel.setTextColor(mTextColor);
- params = createLayoutParams(dpToPx(50, resources), ViewGroup.LayoutParams.MATCH_PARENT);
- mFrictionLabel.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
- mFrictionLabel.setLayoutParams(params);
- mFrictionLabel.setMaxLines(1);
- seekWrapper.addView(mFrictionLabel);
-
- View nub = new View(context);
- params = createLayoutParams(dpToPx(60, resources), dpToPx(40, resources));
- params.gravity = Gravity.TOP | Gravity.CENTER;
- nub.setLayoutParams(params);
- nub.setOnTouchListener(new OnNubTouchListener());
- nub.setBackgroundColor(Color.argb(255, 0, 164, 209));
- root.addView(nub);
-
- return root;
- }
-
- /**
- * remove the configurator from its parent and clean up springs and listeners
- */
- public void destroy() {
- ViewGroup parent = (ViewGroup) getParent();
- if (parent != null) {
- parent.removeView(this);
- }
- mRevealerSpring.destroy();
- }
-
- /**
- * reload the springs from the registry and update the UI
- */
- public void refreshSpringConfigurations() {
- Map springConfigMap = springConfigRegistry.getAllSpringConfig();
-
- spinnerAdapter.clear();
- mSpringConfigs.clear();
-
- for (Map.Entry entry : springConfigMap.entrySet()) {
- if (entry.getKey() == SpringConfig.defaultConfig) {
- continue;
- }
- mSpringConfigs.add(entry.getKey());
- spinnerAdapter.add(entry.getValue());
- }
- // Add the default config in last.
- mSpringConfigs.add(SpringConfig.defaultConfig);
- spinnerAdapter.add(springConfigMap.get(SpringConfig.defaultConfig));
- spinnerAdapter.notifyDataSetChanged();
- if (mSpringConfigs.size() > 0) {
- mSpringSelectorSpinner.setSelection(0);
- }
- }
-
- private class SpringSelectedListener implements AdapterView.OnItemSelectedListener {
-
- @Override
- public void onItemSelected(AdapterView> adapterView, View view, int i, long l) {
- mSelectedSpringConfig = mSpringConfigs.get(i);
- updateSeekBarsForSpringConfig(mSelectedSpringConfig);
- }
-
- @Override
- public void onNothingSelected(AdapterView> adapterView) {
- }
- }
-
- /**
- * listen to events on seekbars and update registered springs accordingly
- */
- private class SeekbarListener implements SeekBar.OnSeekBarChangeListener {
-
- @Override
- public void onProgressChanged(SeekBar seekBar, int val, boolean b) {
- float tensionRange = MAX_TENSION - MIN_TENSION;
- float frictionRange = MAX_FRICTION - MIN_FRICTION;
-
- if (seekBar == mTensionSeekBar) {
- float scaledTension = ((val) * tensionRange) / MAX_SEEKBAR_VAL + MIN_TENSION;
- mSelectedSpringConfig.tension =
- OrigamiValueConverter.tensionFromOrigamiValue(scaledTension);
- String roundedTensionLabel = DECIMAL_FORMAT.format(scaledTension);
- mTensionLabel.setText("T:" + roundedTensionLabel);
- }
-
- if (seekBar == mFrictionSeekBar) {
- float scaledFriction = ((val) * frictionRange) / MAX_SEEKBAR_VAL + MIN_FRICTION;
- mSelectedSpringConfig.friction =
- OrigamiValueConverter.frictionFromOrigamiValue(scaledFriction);
- String roundedFrictionLabel = DECIMAL_FORMAT.format(scaledFriction);
- mFrictionLabel.setText("F:" + roundedFrictionLabel);
- }
- }
-
- @Override
- public void onStartTrackingTouch(SeekBar seekBar) {
- }
-
- @Override
- public void onStopTrackingTouch(SeekBar seekBar) {
- }
- }
-
- /**
- * update the position of the seekbars based on the spring value;
- * @param springConfig current editing spring
- */
- private void updateSeekBarsForSpringConfig(SpringConfig springConfig) {
- float tension = (float) OrigamiValueConverter.origamiValueFromTension(springConfig.tension);
- float tensionRange = MAX_TENSION - MIN_TENSION;
- int scaledTension = Math.round(((tension - MIN_TENSION) * MAX_SEEKBAR_VAL) / tensionRange);
-
- float friction = (float) OrigamiValueConverter.origamiValueFromFriction(springConfig.friction);
- float frictionRange = MAX_FRICTION - MIN_FRICTION;
- int scaledFriction = Math.round(((friction - MIN_FRICTION) * MAX_SEEKBAR_VAL) / frictionRange);
-
- mTensionSeekBar.setProgress(scaledTension);
- mFrictionSeekBar.setProgress(scaledFriction);
- }
-
- /**
- * toggle visibility when the nub is tapped.
- */
- private class OnNubTouchListener implements View.OnTouchListener {
- @Override
- public boolean onTouch(View view, MotionEvent motionEvent) {
- if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
- togglePosition();
- }
- return true;
- }
- }
-
- private void togglePosition() {
- double currentValue = mRevealerSpring.getEndValue();
- mRevealerSpring
- .setEndValue(currentValue == 1 ? 0 : 1);
- }
-
- private class RevealerSpringListener implements SpringListener {
-
- @Override
- public void onSpringUpdate(Spring spring) {
- float val = (float) spring.getCurrentValue();
- float minTranslate = mRevealPx;
- float maxTranslate = mStashPx;
- float range = maxTranslate - minTranslate;
- float yTranslate = (val * range) + minTranslate;
- SpringConfiguratorView.this.setTranslationY(yTranslate);
- }
-
- @Override
- public void onSpringAtRest(Spring spring) {
- }
-
- @Override
- public void onSpringActivate(Spring spring) {
- }
-
- @Override
- public void onSpringEndStateChange(Spring spring) {
- }
- }
-
- private class SpinnerAdapter extends BaseAdapter {
-
- private final Context mContext;
- private final List mStrings;
-
- public SpinnerAdapter(Context context) {
- mContext = context;
- mStrings = new ArrayList();
- }
-
- @Override
- public int getCount() {
- return mStrings.size();
- }
-
- @Override
- public Object getItem(int position) {
- return mStrings.get(position);
- }
-
- @Override
- public long getItemId(int position) {
- return position;
- }
-
- public void add(String string) {
- mStrings.add(string);
- notifyDataSetChanged();
- }
-
- /**
- * Remove all elements from the list.
- */
- public void clear() {
- mStrings.clear();
- notifyDataSetChanged();
- }
-
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- TextView textView;
- if (convertView == null) {
- textView = new TextView(mContext);
- AbsListView.LayoutParams params = new AbsListView.LayoutParams(
- ViewGroup.LayoutParams.MATCH_PARENT,
- ViewGroup.LayoutParams.MATCH_PARENT);
- textView.setLayoutParams(params);
- int twelvePx = dpToPx(12, getResources());
- textView.setPadding(twelvePx, twelvePx, twelvePx, twelvePx);
- textView.setTextColor(mTextColor);
- } else {
- textView = (TextView) convertView;
- }
- textView.setText(mStrings.get(position));
- return textView;
- }
- }
-}
-
diff --git a/ToggleButtonLib/src/com/facebook/rebound/ui/Util.java b/ToggleButtonLib/src/com/facebook/rebound/ui/Util.java
deleted file mode 100644
index e1d7134..0000000
--- a/ToggleButtonLib/src/com/facebook/rebound/ui/Util.java
+++ /dev/null
@@ -1,49 +0,0 @@
-package com.facebook.rebound.ui;
-
-import android.content.res.Resources;
-import android.util.TypedValue;
-import android.view.ViewGroup;
-import android.widget.FrameLayout;
-import android.widget.RelativeLayout;
-
-/**
- * Utilities for generating view hierarchies without using resources.
- */
-public abstract class Util {
-
- public static final int dpToPx(float dp, Resources res) {
- return (int) TypedValue.applyDimension(
- TypedValue.COMPLEX_UNIT_DIP,
- dp,
- res.getDisplayMetrics());
- }
-
- public static final FrameLayout.LayoutParams createLayoutParams(int width, int height) {
- return new FrameLayout.LayoutParams(width, height);
- }
-
- public static final FrameLayout.LayoutParams createMatchParams() {
- return createLayoutParams(
- ViewGroup.LayoutParams.MATCH_PARENT,
- ViewGroup.LayoutParams.MATCH_PARENT);
- }
-
- public static final FrameLayout.LayoutParams createWrapParams() {
- return createLayoutParams(
- ViewGroup.LayoutParams.WRAP_CONTENT,
- ViewGroup.LayoutParams.WRAP_CONTENT);
- }
-
- public static final FrameLayout.LayoutParams createWrapMatchParams() {
- return createLayoutParams(
- ViewGroup.LayoutParams.WRAP_CONTENT,
- ViewGroup.LayoutParams.MATCH_PARENT);
- }
-
- public static final FrameLayout.LayoutParams createMatchWrapParams() {
- return createLayoutParams(
- ViewGroup.LayoutParams.MATCH_PARENT,
- ViewGroup.LayoutParams.WRAP_CONTENT);
- }
-
-}
diff --git a/ToggleButtonLib/src/com/zcw/togglebutton/package-info.java b/ToggleButtonLib/src/com/zcw/togglebutton/package-info.java
deleted file mode 100644
index 0dab636..0000000
--- a/ToggleButtonLib/src/com/zcw/togglebutton/package-info.java
+++ /dev/null
@@ -1,5 +0,0 @@
-/**
- * @author zcw
- *
- */
-package com.zcw.togglebutton;
\ No newline at end of file
diff --git a/ToggleButtonSample/.classpath b/ToggleButtonSample/.classpath
deleted file mode 100644
index 7bc01d9..0000000
--- a/ToggleButtonSample/.classpath
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
-
-
-
-
-
-
-
diff --git a/ToggleButtonSample/.project b/ToggleButtonSample/.project
deleted file mode 100644
index c11c0fe..0000000
--- a/ToggleButtonSample/.project
+++ /dev/null
@@ -1,33 +0,0 @@
-
-
- ToggleButtonSample
-
-
-
-
-
- com.android.ide.eclipse.adt.ResourceManagerBuilder
-
-
-
-
- com.android.ide.eclipse.adt.PreCompilerBuilder
-
-
-
-
- org.eclipse.jdt.core.javabuilder
-
-
-
-
- com.android.ide.eclipse.adt.ApkBuilder
-
-
-
-
-
- com.android.ide.eclipse.adt.AndroidNature
- org.eclipse.jdt.core.javanature
-
-
diff --git a/ToggleButtonSample/.settings/org.eclipse.jdt.core.prefs b/ToggleButtonSample/.settings/org.eclipse.jdt.core.prefs
deleted file mode 100644
index b080d2d..0000000
--- a/ToggleButtonSample/.settings/org.eclipse.jdt.core.prefs
+++ /dev/null
@@ -1,4 +0,0 @@
-eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
-org.eclipse.jdt.core.compiler.compliance=1.6
-org.eclipse.jdt.core.compiler.source=1.6
diff --git a/ToggleButtonSample/bin/AndroidManifest.xml b/ToggleButtonSample/bin/AndroidManifest.xml
deleted file mode 100644
index 00109c3..0000000
--- a/ToggleButtonSample/bin/AndroidManifest.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/ToggleButtonSample/bin/R.txt b/ToggleButtonSample/bin/R.txt
deleted file mode 100644
index 5e63fb9..0000000
--- a/ToggleButtonSample/bin/R.txt
+++ /dev/null
@@ -1,19 +0,0 @@
-int attr borderWidth 0x7f010000
-int attr offBorderColor 0x7f010001
-int attr offColor 0x7f010002
-int attr onColor 0x7f010003
-int attr spotColor 0x7f010004
-int dimen activity_horizontal_margin 0x7f040000
-int dimen activity_vertical_margin 0x7f040001
-int drawable ic_launcher 0x7f020000
-int id group1 0x7f060000
-int layout activity_main 0x7f030000
-int string action_settings 0x7f050002
-int string app_name 0x7f050000
-int string hello_world 0x7f050001
-int[] styleable ToggleButton { 0x7f010000, 0x7f010001, 0x7f010002, 0x7f010003, 0x7f010004 }
-int styleable ToggleButton_borderWidth 0
-int styleable ToggleButton_offBorderColor 1
-int styleable ToggleButton_offColor 2
-int styleable ToggleButton_onColor 3
-int styleable ToggleButton_spotColor 4
diff --git a/ToggleButtonSample/bin/classes/.gitignore b/ToggleButtonSample/bin/classes/.gitignore
deleted file mode 100644
index 4651645..0000000
--- a/ToggleButtonSample/bin/classes/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-/com/
-/.gitignore
diff --git a/ToggleButtonSample/bin/jarlist.cache b/ToggleButtonSample/bin/jarlist.cache
deleted file mode 100644
index 0565465..0000000
--- a/ToggleButtonSample/bin/jarlist.cache
+++ /dev/null
@@ -1,3 +0,0 @@
-# cache for current jar dependency. DO NOT EDIT.
-# format is
-# Encoding is UTF-8
diff --git a/ToggleButtonSample/build.gradle b/ToggleButtonSample/build.gradle
deleted file mode 100644
index 4c06fb9..0000000
--- a/ToggleButtonSample/build.gradle
+++ /dev/null
@@ -1,39 +0,0 @@
-apply plugin: 'android-sdk-manager'
-apply plugin: 'com.android.application'
-
-dependencies {
- compile project(':ToggleButtonLib')
-}
-
-android {
- compileSdkVersion 21
- buildToolsVersion '21.1.0'
-
- compileOptions {
- sourceCompatibility JavaVersion.VERSION_1_7
- targetCompatibility JavaVersion.VERSION_1_7
- }
-
- defaultConfig {
- minSdkVersion 8
- targetSdkVersion 21
- }
-
- sourceSets {
- main {
- manifest.srcFile 'AndroidManifest.xml'
- java.srcDirs = ['src']
- resources.srcDirs = ['src']
- aidl.srcDirs = ['src']
- renderscript.srcDirs = ['src']
- res.srcDirs = ['res']
- assets.srcDirs = ['assets']
- }
- }
-
- lintOptions {
- abortOnError false
- }
-}
-
-apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle'
diff --git a/ToggleButtonSample/gen/.gitignore b/ToggleButtonSample/gen/.gitignore
deleted file mode 100644
index 4651645..0000000
--- a/ToggleButtonSample/gen/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-/com/
-/.gitignore
diff --git a/ToggleButtonSample/ic_launcher-web.png b/ToggleButtonSample/ic_launcher-web.png
deleted file mode 100644
index a18cbb4..0000000
Binary files a/ToggleButtonSample/ic_launcher-web.png and /dev/null differ
diff --git a/ToggleButtonSample/res/layout/activity_main.xml b/ToggleButtonSample/res/layout/activity_main.xml
deleted file mode 100644
index 546a525..0000000
--- a/ToggleButtonSample/res/layout/activity_main.xml
+++ /dev/null
@@ -1,71 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/build.gradle b/build.gradle
index 6386cea..0f85975 100644
--- a/build.gradle
+++ b/build.gradle
@@ -4,17 +4,25 @@ buildscript {
}
dependencies {
- classpath 'com.android.tools.build:gradle:0.14.+'
- classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.12.+'
+ classpath 'com.android.tools.build:gradle:2.1.2'
}
}
-task wrapper(type: Wrapper) {
- gradleVersion = '2.1'
-}
-
allprojects {
repositories {
jcenter()
}
}
+
+task clean(type: Delete) {
+ delete rootProject.buildDir
+}
+
+ext {
+ groupName = 'com.zcw'
+ artifactName = 'togglebutton'
+ artifactDescription = 'ToggleButton'
+ artifactLabels = ['togglebutton']
+ releaseVersionCode = 1
+ releaseVersionName = '1.0.0'
+}
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index af2634f..063e5e5 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-2.1-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-bin.zip
diff --git a/ToggleButtonSample/21879.gif b/images/21879.gif
similarity index 100%
rename from ToggleButtonSample/21879.gif
rename to images/21879.gif
diff --git a/ToggleButtonSample/device-2014-08-31-231538.png b/images/device-2014-08-31-231538.png
similarity index 100%
rename from ToggleButtonSample/device-2014-08-31-231538.png
rename to images/device-2014-08-31-231538.png
diff --git a/library/bintray.gradle b/library/bintray.gradle
new file mode 100644
index 0000000..9e43bd2
--- /dev/null
+++ b/library/bintray.gradle
@@ -0,0 +1,113 @@
+group = PROJ_GROUP
+version = PROJ_VERSION
+project.archivesBaseName = PROJ_ARTIFACTID
+
+apply plugin: 'com.jfrog.bintray'
+apply plugin: 'com.github.dcendents.android-maven'
+
+task sourcesJar(type: Jar) {
+ from android.sourceSets.main.java.srcDirs
+ classifier = 'sources'
+}
+
+task javadoc(type: Javadoc) {
+ source = android.sourceSets.main.java.srcDirs
+ classpath += configurations.compile
+ classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
+}
+
+task javadocJar(type: Jar, dependsOn: javadoc) {
+ classifier = 'javadoc'
+ from javadoc.destinationDir
+}
+
+javadoc {
+ options{
+ encoding "UTF-8"
+ charSet 'UTF-8'
+ author true
+ version true
+ links "http://docs.oracle.com/javase/7/docs/api"
+ title "$PROJ_NAME $PROJ_VERSION"
+ }
+}
+
+artifacts {
+ archives sourcesJar
+ archives javadocJar
+}
+
+install {
+ repositories.mavenInstaller {
+ pom.project {
+ name PROJ_NAME
+ description PROJ_DESCRIPTION
+ url PROJ_WEBSITEURL
+ inceptionYear '2016'
+
+ packaging 'aar'
+ groupId PROJ_GROUP
+ artifactId PROJ_ARTIFACTID
+ version PROJ_VERSION
+
+ licenses {
+ license {
+ name 'The Apache Software License, Version 2.0'
+ url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
+ distribution 'repo'
+ }
+ }
+
+ scm {
+ connection PROJ_VCSURL
+ url PROJ_WEBSITEURL
+
+ }
+ developers {
+ developer {
+ id "zcweng"
+ name "zcweng"
+ }
+ developer {
+ id "ErQi"
+ name "ErQi"
+ email "shengguangchanhui@foxmail.com"
+ }
+ developer {
+ id "msdx"
+ name "Geek_Soledad"
+ email "msdx.android@qq.com"
+ }
+ }
+ }
+ }
+}
+
+bintray {
+ user = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : project.property('BINTRAY_USER')
+ key = project.hasProperty('bintrayKey') ? project.property('bintrayKey') : project.property('BINTRAY_KEY')
+
+ configurations = ['archives']
+
+ dryRun = false
+ publish = true
+
+ pkg {
+ repo = 'maven'
+ name = PROJ_NAME
+ licenses = ['Apache-2.0']
+ vcsUrl = PROJ_VCSURL
+ websiteUrl = PROJ_WEBSITEURL
+ issueTrackerUrl = PROJ_ISSUETRACKERURL
+ publicDownloadNumbers = true
+ version {
+ name = PROJ_VERSION
+ desc = PROJ_DESCRIPTION
+ vcsTag = PROJ_VERSION
+
+ gpg {
+ sign = true
+ }
+ }
+ }
+}
diff --git a/library/build.gradle b/library/build.gradle
new file mode 100644
index 0000000..bc0c433
--- /dev/null
+++ b/library/build.gradle
@@ -0,0 +1,28 @@
+buildscript {
+ repositories {
+ jcenter()
+ }
+ dependencies {
+ classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
+ classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6'
+ }
+}
+apply plugin: 'com.android.library'
+
+android {
+ compileSdkVersion 22
+ buildToolsVersion '22.0.1'
+
+ defaultConfig {
+ minSdkVersion 8
+ targetSdkVersion 22
+ }
+}
+
+dependencies {
+ compile 'com.facebook.rebound:rebound:0.3.8'
+}
+
+if (hasProperty("bintrayUser") || hasProperty("BINTRAY_USER")) {
+ apply from: 'bintray.gradle'
+}
diff --git a/library/gradle.properties b/library/gradle.properties
new file mode 100644
index 0000000..cae1156
--- /dev/null
+++ b/library/gradle.properties
@@ -0,0 +1,8 @@
+PROJ_GROUP=com.githang
+PROJ_VERSION=1.0
+PROJ_NAME=zcweng-ToggleButton
+PROJ_WEBSITEURL=https://github.com/zcweng/ToggleButton
+PROJ_ISSUETRACKERURL=https://github.com/zcweng/ToggleButton/issues
+PROJ_VCSURL=git@github.com:zcweng/ToggleButton.git
+PROJ_DESCRIPTION=ToggleButton Widget For Android Dev
+PROJ_ARTIFACTID=zcweng-togglebutton
\ No newline at end of file
diff --git a/ToggleButtonLib/proguard-project.txt b/library/proguard-project.txt
similarity index 100%
rename from ToggleButtonLib/proguard-project.txt
rename to library/proguard-project.txt
diff --git a/ToggleButtonLib/project.properties b/library/project.properties
similarity index 100%
rename from ToggleButtonLib/project.properties
rename to library/project.properties
diff --git a/ToggleButtonLib/AndroidManifest.xml b/library/src/main/AndroidManifest.xml
similarity index 96%
rename from ToggleButtonLib/AndroidManifest.xml
rename to library/src/main/AndroidManifest.xml
index 713f807..ca401fd 100644
--- a/ToggleButtonLib/AndroidManifest.xml
+++ b/library/src/main/AndroidManifest.xml
@@ -1,10 +1,10 @@
-
-
-
-
-
+
+
+
+
+
diff --git a/ToggleButtonLib/src/com/zcw/togglebutton/ToggleButton.java b/library/src/main/java/com/zcw/togglebutton/ToggleButton.java
similarity index 93%
rename from ToggleButtonLib/src/com/zcw/togglebutton/ToggleButton.java
rename to library/src/main/java/com/zcw/togglebutton/ToggleButton.java
index f3bfc2e..b13fb6d 100644
--- a/ToggleButtonLib/src/com/zcw/togglebutton/ToggleButton.java
+++ b/library/src/main/java/com/zcw/togglebutton/ToggleButton.java
@@ -106,13 +106,13 @@ public void onClick(View arg0) {
});
TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.ToggleButton);
- offBorderColor = typedArray.getColor(R.styleable.ToggleButton_offBorderColor, offBorderColor);
- onColor = typedArray.getColor(R.styleable.ToggleButton_onColor, onColor);
- spotColor = typedArray.getColor(R.styleable.ToggleButton_spotColor, spotColor);
- offColor = typedArray.getColor(R.styleable.ToggleButton_offColor, offColor);
- borderWidth = typedArray.getDimensionPixelSize(R.styleable.ToggleButton_borderWidth, borderWidth);
- defaultAnimate = typedArray.getBoolean(R.styleable.ToggleButton_animate, defaultAnimate);
- isDefaultOn = typedArray.getBoolean(R.styleable.ToggleButton_isDefaultOn, isDefaultOn);
+ offBorderColor = typedArray.getColor(R.styleable.ToggleButton_tbOffBorderColor, offBorderColor);
+ onColor = typedArray.getColor(R.styleable.ToggleButton_tbOnColor, onColor);
+ spotColor = typedArray.getColor(R.styleable.ToggleButton_tbSpotColor, spotColor);
+ offColor = typedArray.getColor(R.styleable.ToggleButton_tbOffColor, offColor);
+ borderWidth = typedArray.getDimensionPixelSize(R.styleable.ToggleButton_tbBorderWidth, borderWidth);
+ defaultAnimate = typedArray.getBoolean(R.styleable.ToggleButton_tbAnimate, defaultAnimate);
+ isDefaultOn = typedArray.getBoolean(R.styleable.ToggleButton_tbAsDefaultOn, isDefaultOn);
typedArray.recycle();
borderColor = offBorderColor;
@@ -148,7 +148,11 @@ public void toggleOff() {
listener.onToggle(toggleOn);
}
}
-
+
+ public boolean isToggleOn() {
+ return toggleOn;
+ }
+
/**
* 设置显示成打开样式,不会触发toggle事件
*/
@@ -157,7 +161,7 @@ public void setToggleOn() {
}
/**
- * @param animate
+ * @param animate asd
*/
public void setToggleOn(boolean animate){
toggleOn = true;
@@ -308,7 +312,7 @@ private void calculateEffect(final double value) {
*/
public interface OnToggleChanged{
/**
- * @param on
+ * @param on = =
*/
public void onToggle(boolean on);
}
diff --git a/library/src/main/res/values/toggle_button_attrs.xml b/library/src/main/res/values/toggle_button_attrs.xml
new file mode 100644
index 0000000..53699d1
--- /dev/null
+++ b/library/src/main/res/values/toggle_button_attrs.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/sample/build.gradle b/sample/build.gradle
new file mode 100644
index 0000000..10c33c8
--- /dev/null
+++ b/sample/build.gradle
@@ -0,0 +1,24 @@
+apply plugin: 'com.android.application'
+
+dependencies {
+ compile project(':library')
+}
+
+android {
+ compileSdkVersion 22
+ buildToolsVersion '22.0.1'
+
+ compileOptions {
+ sourceCompatibility JavaVersion.VERSION_1_7
+ targetCompatibility JavaVersion.VERSION_1_7
+ }
+
+ defaultConfig {
+ minSdkVersion 8
+ targetSdkVersion 22
+ }
+
+ lintOptions {
+ abortOnError false
+ }
+}
diff --git a/ToggleButtonSample/libs/android-support-v4.jar b/sample/libs/android-support-v4.jar
similarity index 100%
rename from ToggleButtonSample/libs/android-support-v4.jar
rename to sample/libs/android-support-v4.jar
diff --git a/ToggleButtonSample/lint.xml b/sample/lint.xml
similarity index 100%
rename from ToggleButtonSample/lint.xml
rename to sample/lint.xml
diff --git a/ToggleButtonSample/proguard-project.txt b/sample/proguard-project.txt
similarity index 100%
rename from ToggleButtonSample/proguard-project.txt
rename to sample/proguard-project.txt
diff --git a/ToggleButtonSample/project.properties b/sample/project.properties
similarity index 100%
rename from ToggleButtonSample/project.properties
rename to sample/project.properties
diff --git a/ToggleButtonSample/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml
similarity index 100%
rename from ToggleButtonSample/AndroidManifest.xml
rename to sample/src/main/AndroidManifest.xml
diff --git a/ToggleButtonSample/src/com/zcw/togglebutton/sample/MainActivity.java b/sample/src/main/java/com/zcw/togglebutton/sample/MainActivity.java
similarity index 100%
rename from ToggleButtonSample/src/com/zcw/togglebutton/sample/MainActivity.java
rename to sample/src/main/java/com/zcw/togglebutton/sample/MainActivity.java
diff --git a/ToggleButtonSample/res/drawable-hdpi/ic_launcher.png b/sample/src/main/res/drawable-hdpi/ic_launcher.png
similarity index 100%
rename from ToggleButtonSample/res/drawable-hdpi/ic_launcher.png
rename to sample/src/main/res/drawable-hdpi/ic_launcher.png
diff --git a/ToggleButtonSample/res/drawable-mdpi/ic_launcher.png b/sample/src/main/res/drawable-mdpi/ic_launcher.png
similarity index 100%
rename from ToggleButtonSample/res/drawable-mdpi/ic_launcher.png
rename to sample/src/main/res/drawable-mdpi/ic_launcher.png
diff --git a/ToggleButtonSample/res/drawable-xhdpi/ic_launcher.png b/sample/src/main/res/drawable-xhdpi/ic_launcher.png
similarity index 100%
rename from ToggleButtonSample/res/drawable-xhdpi/ic_launcher.png
rename to sample/src/main/res/drawable-xhdpi/ic_launcher.png
diff --git a/ToggleButtonSample/res/drawable-xxhdpi/ic_launcher.png b/sample/src/main/res/drawable-xxhdpi/ic_launcher.png
similarity index 100%
rename from ToggleButtonSample/res/drawable-xxhdpi/ic_launcher.png
rename to sample/src/main/res/drawable-xxhdpi/ic_launcher.png
diff --git a/sample/src/main/res/layout/activity_main.xml b/sample/src/main/res/layout/activity_main.xml
new file mode 100644
index 0000000..ad83249
--- /dev/null
+++ b/sample/src/main/res/layout/activity_main.xml
@@ -0,0 +1,70 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/ToggleButtonSample/res/values-w820dp/dimens.xml b/sample/src/main/res/values-w820dp/dimens.xml
similarity index 100%
rename from ToggleButtonSample/res/values-w820dp/dimens.xml
rename to sample/src/main/res/values-w820dp/dimens.xml
diff --git a/ToggleButtonSample/res/values/dimens.xml b/sample/src/main/res/values/dimens.xml
similarity index 100%
rename from ToggleButtonSample/res/values/dimens.xml
rename to sample/src/main/res/values/dimens.xml
diff --git a/ToggleButtonSample/res/values/strings.xml b/sample/src/main/res/values/strings.xml
similarity index 100%
rename from ToggleButtonSample/res/values/strings.xml
rename to sample/src/main/res/values/strings.xml
diff --git a/ToggleButtonSample/res/values/styles.xml b/sample/src/main/res/values/styles.xml
similarity index 100%
rename from ToggleButtonSample/res/values/styles.xml
rename to sample/src/main/res/values/styles.xml
diff --git a/settings.gradle b/settings.gradle
index bece3c7..a882e41 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -1,2 +1 @@
-include 'ToggleButtonLib'
-include 'ToggleButtonSample'
+include 'library', 'sample'