Skip to content
This repository has been archived by the owner on May 1, 2020. It is now read-only.

Downgrade API 14 #61

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ buildscript {
}
}

allprojects {
repositories {
mavenCentral()
}
}

apply plugin: 'com.android.library'
import com.android.builder.core.BuilderConstants

Expand Down
2 changes: 2 additions & 0 deletions rebound-android-example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ apply plugin: 'com.android.application'

dependencies {
compile project(':rebound-android')
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.jakewharton:butterknife:7.0.0'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

}

android {
Expand Down
14 changes: 7 additions & 7 deletions rebound-android-example/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.facebook.rebound.example"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:targetSdkVersion="19"
android:minSdkVersion="14"/>

<application
android:label="Rebound Example"
android:hardwareAccelerated="true"
android:allowBackup="false"
android:icon="@drawable/rebound_icon"
>
android:icon="@drawable/rebound_icon">

<activity
android:name="com.facebook.rebound.example.MainActivity"
android:theme="@android:style/Theme.DeviceDefault.NoActionBar.Fullscreen"
android:theme="@style/AppTheme"
android:label="Rebound Example">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>

</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.view.ViewCompat;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;

import butterknife.Bind;
import butterknife.ButterKnife;
import com.facebook.rebound.BaseSpringSystem;
import com.facebook.rebound.SimpleSpringListener;
import com.facebook.rebound.Spring;
Expand All @@ -36,68 +39,87 @@ public class MainActivity extends Activity {

private final BaseSpringSystem mSpringSystem = SpringSystem.create();
private final ExampleSpringListener mSpringListener = new ExampleSpringListener();
private FrameLayout mRootView;

private Spring mScaleSpring;
private View mImageView;

@Bind(R.id.root_view) FrameLayout mRootView;
@Bind(R.id.image_view) View mImageView;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.main);
mRootView = (FrameLayout) findViewById(R.id.root_view);
mImageView = mRootView.findViewById(R.id.image_view);

// Create the animation spring.
mScaleSpring = mSpringSystem.createSpring();

// Add an OnTouchListener to the root view.
mRootView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
// When pressed start solving the spring to 1.
mScaleSpring.setEndValue(1);
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
// When released start solving the spring to 0.
mScaleSpring.setEndValue(0);
break;
}
return true;
}
});
ButterKnife.bind(this);
mRootView.setOnTouchListener(onTouchListener);
}

@Override
public void onResume() {
/**
* Add a listener to the spring when the Activity resumes.
*/
@Override public void onResume() {
super.onResume();
// Add a listener to the spring when the Activity resumes.
mScaleSpring.addListener(mSpringListener);
scaleSpring().addListener(mSpringListener);
}

@Override
public void onPause() {
/**
* Remove the listener to the spring when the Activity pauses.
*/
@Override public void onPause() {
scaleSpring().removeListener(mSpringListener);
super.onPause();
// Remove the listener to the spring when the Activity pauses.
mScaleSpring.removeListener(mSpringListener);
}

/**
* Create a new instance if spring if needed
*
* @return instance of Spring
*/
private Spring scaleSpring() {
if(mScaleSpring == null) {
mScaleSpring = mSpringSystem.createSpring();
}
return mScaleSpring;
}

/**
* On each update of the spring value, we adjust the scale of the image view to match the
* springs new value. We use the SpringUtil linear interpolation function mapValueFromRangeToRange
* to translate the spring's 0 to 1 scale to a 100% to 50% scale range and apply that to the View
* with setScaleX/Y. Note that rendering is an implementation detail of the application and not
* Rebound itself. If you need Gingerbread compatibility consider using ViewCompat to update
* your view properties in a backwards compatible manner.
*/
private class ExampleSpringListener extends SimpleSpringListener {
@Override
public void onSpringUpdate(Spring spring) {
// On each update of the spring value, we adjust the scale of the image view to match the
// springs new value. We use the SpringUtil linear interpolation function mapValueFromRangeToRange
// to translate the spring's 0 to 1 scale to a 100% to 50% scale range and apply that to the View
// with setScaleX/Y. Note that rendering is an implementation detail of the application and not
// Rebound itself. If you need Gingerbread compatibility consider using NineOldAndroids to update
// your view properties in a backwards compatible manner.
@Override public void onSpringUpdate(Spring spring) {
float mappedValue = (float) SpringUtil.mapValueFromRangeToRange(spring.getCurrentValue(), 0, 1, 1, 0.5);
mImageView.setScaleX(mappedValue);
mImageView.setScaleY(mappedValue);
ViewCompat.setScaleX(mImageView, mappedValue);
ViewCompat.setScaleY(mImageView, mappedValue);
}
}

/**
* # MotionEvent.ACTION_DOWN:
* When pressed start solving the spring to 1.
*
* #MotionEvent.ACTION_UP:
* #MotionEvent.ACTION_CANCEL:
* When released start solving the spring to 0.
*/
private View.OnTouchListener onTouchListener = new View.OnTouchListener() {
@Override public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
scaleSpring().setEndValue(1);
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
scaleSpring().setEndValue(0);
break;
default:
break;
}
return true;
}
};

}
18 changes: 9 additions & 9 deletions rebound-android-example/src/main/res/layout/main.xml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root_view"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
android:id="@+id/root_view"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
android:id="@+id/image_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/landscape"
android:scaleType="centerCrop"
/>
android:scaleType="centerCrop"/>

<com.facebook.rebound.ui.SpringConfiguratorView
android:id="@+id/spring_configurator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
/>
android:layout_gravity="bottom"/>

</FrameLayout>
4 changes: 4 additions & 0 deletions rebound-android-example/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="black">#000000</color>
</resources>
12 changes: 12 additions & 0 deletions rebound-android-example/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowBackground">@color/black</item>
</style>

</resources>
5 changes: 3 additions & 2 deletions rebound-android-playground/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
apply plugin: 'com.android.application'

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':rebound-android')
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.jakewharton:butterknife:7.0.0'
}

android {
Expand All @@ -14,7 +15,7 @@ android {
applicationId "com.facebook.rebound.androidplayground"
versionCode Integer.parseInt(project.VERSION_CODE)
versionName project.VERSION_NAME
minSdkVersion 19
minSdkVersion Integer.parseInt(project.ANDROID_MIN_SDK)
targetSdkVersion Integer.parseInt(project.ANDROID_TARGET_SDK_VERSION)
}

Expand Down
9 changes: 4 additions & 5 deletions rebound-android-playground/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.facebook.rebound.playground" >
<uses-sdk android:targetSdkVersion="19"
android:minSdkVersion="16"/>

<application
android:allowBackup="true"
android:icon="@drawable/rebound_icon"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:hardwareAccelerated="true"
>
android:hardwareAccelerated="true">

<activity
android:name="com.facebook.rebound.playground.app.PlaygroundActivity"
android:theme="@android:style/Theme.Holo.NoActionBar"
android:screenOrientation="portrait"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.facebook.rebound.playground.app;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import butterknife.ButterKnife;

public abstract class AbstractActivity extends AppCompatActivity {

@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(getContentViewId());
ButterKnife.bind(this);
}

protected abstract int getContentViewId();

}
Loading