Skip to content

Commit

Permalink
Update to show usage of Spring Animation in details
Browse files Browse the repository at this point in the history
  • Loading branch information
ozodrukh committed Mar 16, 2017
1 parent 7505025 commit e45b1a8
Show file tree
Hide file tree
Showing 9 changed files with 354 additions and 102 deletions.
24 changes: 15 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'

android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
compileSdkVersion project.compileSDKVersion
buildToolsVersion project.buildToolsVersion

defaultConfig {
applicationId "io.codetail.circualrevealsample"
minSdkVersion 15
targetSdkVersion 23
minSdkVersion project.minSDKVersion
targetSdkVersion project.targetSDKVersion
versionCode 1
versionName "1.0"
applicationId "io.codetail.circualrevealsample"

vectorDrawables {
useSupportLibrary = true
}
}

lintOptions {
Expand All @@ -21,11 +25,13 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':circualreveal')
compile project(':spring-revealmanager')

compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:recyclerview-v7:23.4.0'
compile 'com.android.support:cardview-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile "com.android.support:appcompat-v7:$support_lib_version"
compile "com.android.support:recyclerview-v7:$support_lib_version"
compile "com.android.support:cardview-v7:$support_lib_version"
compile "com.android.support:design:$support_lib_version"
compile "com.android.support:support-dynamic-animation:$support_lib_version"

compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.jakewharton:butterknife:8.0.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,64 @@
import android.graphics.Rect;
import android.os.Build;
import android.os.Bundle;
import android.support.animation.SpringForce;
import android.support.annotation.Nullable;
import android.support.design.widget.BottomSheetBehavior;
import android.support.v4.view.animation.FastOutLinearInInterpolator;
import android.support.v4.view.animation.FastOutSlowInInterpolator;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.CardView;
import android.util.Property;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.codetail.animation.RevealViewGroup;
import io.codetail.animation.SpringViewAnimatorManager;
import io.codetail.animation.ViewAnimationUtils;
import io.codetail.animation.ViewRevealManager;
import io.codetail.widget.RevealFrameLayout;

/**
* Aware section
* https://www.google.com/design/spec/motion/material-motion.html#material-motion-how-does-material-move
* Aware section https://www.google.com/design/spec/motion/material-motion.html#material-motion-how-does-material-move
*/
public class MainActivity extends AppCompatActivity {
final static int SLOW_DURATION = 400;
final static int FAST_DURATION = 200;

@BindView(R.id.parent) RevealFrameLayout parent;
@BindView(R.id.circlesLine) ViewGroup circlesLine;
@BindView(R.id.cardsLine) ViewGroup cardsLine;
@BindView(R.id.activator_mask) CardView activatorMask;
@BindView(R.id.springSettings) SpringSettingsBottomDialog settingsView;

private float maskElevation;

@Override protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);

final ViewRevealManager revealManager = new ViewRevealManager();
final SpringViewAnimatorManager springManager = new SpringViewAnimatorManager();
springManager.setDampingRatio(SpringForce.DAMPING_RATIO_NO_BOUNCY);
springManager.setStiffness(SpringForce.STIFFNESS_LOW);

parent.setViewRevealManager(revealManager);

settingsView.addSwitch("Enable Spring", false, new CompoundButton.OnCheckedChangeListener() {
@Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
parent.setViewRevealManager(isChecked ? springManager : revealManager);
}
});
settingsView.setAnimatorManager(springManager);

final BottomSheetBehavior behavior = BottomSheetBehavior.from(settingsView);
behavior.setPeekHeight(getResources().getDimensionPixelSize(R.dimen.bottom_peek_height));
behavior.setSkipCollapsed(false);
behavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
}

@OnClick(R.id.activator) void activateAwareMotion(View target) {
Expand All @@ -58,7 +85,7 @@ public class MainActivity extends AppCompatActivity {
parent.offsetDescendantRectToMyCoords(target, bounds);
parent.offsetDescendantRectToMyCoords(activatorMask, maskBounds);

// Put Mask view at circle initial points
// Put Mask view at circle 8initial points
maskElevation = activatorMask.getCardElevation();
activatorMask.setCardElevation(0);
activatorMask.setVisibility(View.VISIBLE);
Expand All @@ -70,10 +97,11 @@ public class MainActivity extends AppCompatActivity {
final int cX = maskBounds.centerX();
final int cY = maskBounds.centerY();

final float endRadius = (float) Math.hypot(maskBounds.width() * .5f, maskBounds.height() * .5f);

Animator circularReveal =
ViewAnimationUtils.createCircularReveal(activatorMask, cX, cY, target.getWidth() / 2,
(float) Math.hypot(maskBounds.width() * .5f, maskBounds.height() * .5f),
View.LAYER_TYPE_HARDWARE);
endRadius, View.LAYER_TYPE_HARDWARE);

final float c0X = bounds.centerX() - maskBounds.centerX();
final float c0Y = bounds.centerY() - maskBounds.centerY();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,26 @@
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.support.animation.SpringForce;
import android.support.annotation.Nullable;
import android.support.design.widget.BottomSheetBehavior;
import android.support.v4.view.animation.FastOutLinearInInterpolator;
import android.support.v7.app.AppCompatActivity;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.VideoView;
import butterknife.BindView;
import butterknife.ButterKnife;
import com.squareup.picasso.Picasso;
import io.codetail.animation.SpringViewAnimatorManager;
import io.codetail.animation.ViewAnimationUtils;
import io.codetail.animation.ViewRevealManager;
import io.codetail.widget.RevealFrameLayout;

/**
* https://www.google.com/design/spec/motion/choreography.html#choreography-radial-reaction
Expand All @@ -28,9 +35,10 @@
private final static String VIDEO_URL =
"https://material-design.storage.googleapis.com/publish/material_v_8/material_ext_publish/0B14F_FSUCc01WUt2SFZkbGVuNVk/RR_Point_of_Contact_001.mp4";

@BindView(R.id.view_stack) ViewGroup stack;
@BindView(R.id.view_stack) RevealFrameLayout stack;
@BindView(R.id.san_francisco) ImageView sanFranciscoView;
@BindView(R.id.video) VideoView videoView;
@BindView(R.id.springSettings) SpringSettingsBottomDialog settingsView;

private int currentViewIndex = 0;

Expand Down Expand Up @@ -63,6 +71,25 @@
}
});
}

final ViewRevealManager revealManager = new ViewRevealManager();
final SpringViewAnimatorManager springManager = new SpringViewAnimatorManager();
springManager.setDampingRatio(SpringForce.DAMPING_RATIO_NO_BOUNCY);
springManager.setStiffness(SpringForce.STIFFNESS_LOW);

stack.setViewRevealManager(revealManager);

settingsView.addSwitch("Enable Spring", false, new CompoundButton.OnCheckedChangeListener() {
@Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
stack.setViewRevealManager(isChecked ? springManager : revealManager);
}
});
settingsView.setAnimatorManager(springManager);

final BottomSheetBehavior behavior = BottomSheetBehavior.from(settingsView);
behavior.setPeekHeight(getResources().getDimensionPixelSize(R.dimen.bottom_peek_height));
behavior.setSkipCollapsed(false);
behavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
}

private GestureDetector.OnGestureListener tapDetector =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
package io.codetail.circualrevealsample;

import android.content.Context;
import android.support.animation.SpringForce;
import android.support.v7.widget.AppCompatTextView;
import android.support.v7.widget.SwitchCompat;
import android.util.AttributeSet;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.TextView;
import io.codetail.animation.RevealViewGroup;
import io.codetail.animation.SpringViewAnimatorManager;

import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;

/**
* created at 3/16/17
*
* @author Ozodrukh
* @version 1.0
*/
public class SpringSettingsBottomDialog extends LinearLayout {
private boolean springManagerAdded = false;
private boolean switchAdded = false;

private SeekBar stiffnessView;
private SeekBar dampingView;

public SpringSettingsBottomDialog(Context context, AttributeSet attrs) {
super(context, attrs);
final int padding = dp(16);

setOrientation(VERTICAL);
setPadding(padding, padding, padding, padding);
}

public void setAnimatorManager(final SpringViewAnimatorManager animatorManager) {
if (springManagerAdded) {
// already inflated progress bars
return;
}

springManagerAdded = true;

final int stiffnessVal =
(int) ((animatorManager.getStiffness() / SpringForce.STIFFNESS_HIGH) * 100f);

final int dampingVal =
(int) (animatorManager.getDampingRatio() / SpringForce.DAMPING_RATIO_NO_BOUNCY * 100f);

stiffnessView =
createConfigurationView("Stiffness", stiffnessVal, new OnProgressChangeListener() {
@Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
animatorManager.setStiffness(3000 * (progress / 100f));
}
});

dampingView =
createConfigurationView("Damping Ratio", dampingVal, new OnProgressChangeListener() {
@Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
animatorManager.setDampingRatio(progress / 100f);
}
});
}

public void addSwitch(String label, boolean defaultState,
final CompoundButton.OnCheckedChangeListener listener) {
if (switchAdded) {
return;
}

switchAdded = true;

final SwitchCompat switchView = new SwitchCompat(getContext());
switchView.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
listener.onCheckedChanged(buttonView, isChecked);

if (springManagerAdded) {
stiffnessView.setEnabled(isChecked);
dampingView.setEnabled(isChecked);
}
}
});
switchView.setChecked(defaultState);
switchView.setText(label);

addView(switchView, createMarginLayoutParams(MATCH_PARENT, WRAP_CONTENT, 0, 0, 0, dp(16)));

if (springManagerAdded) {
stiffnessView.setEnabled(defaultState);
dampingView.setEnabled(defaultState);
}
}

private SeekBar createConfigurationView(CharSequence label, int defaultVal,
SeekBar.OnSeekBarChangeListener changeListener) {

final TextView labelView =
new AppCompatTextView(getContext(), null, R.style.TextAppearance_AppCompat_Caption);
labelView.setText(label);
labelView.setLayoutParams(createMarginLayoutParams(MATCH_PARENT, WRAP_CONTENT, 0, 0, 0, dp(8)));

final SeekBar seekBar = new SeekBar(getContext());
seekBar.setProgress(defaultVal);
seekBar.setMax(100);
seekBar.setOnSeekBarChangeListener(changeListener);

seekBar.setLayoutParams(createMarginLayoutParams(MATCH_PARENT, WRAP_CONTENT, 0, 0, 0, dp(16)));

addView(labelView);
addView(seekBar);
return seekBar;
}

private int dp(float px) {
return (int) (getContext().getResources().getDisplayMetrics().density * px);
}

private static MarginLayoutParams createMarginLayoutParams(int w, int h, int l, int t, int r,
int b) {
MarginLayoutParams lp = new MarginLayoutParams(w, h);
lp.leftMargin = l;
lp.topMargin = t;
lp.rightMargin = r;
lp.bottomMargin = b;
return lp;
}

private static abstract class OnProgressChangeListener
implements SeekBar.OnSeekBarChangeListener {

@Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

}

@Override public void onStartTrackingTouch(SeekBar seekBar) {

}

@Override public void onStopTrackingTouch(SeekBar seekBar) {

}
}
}
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_looks_one_black_24dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M19,3L5,3c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2L21,5c0,-1.1 -0.9,-2 -2,-2zM14,17h-2L12,9h-2L10,7h4v10z"/>
</vector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_looks_two_black_24dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M19,3L5,3c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2L21,5c0,-1.1 -0.9,-2 -2,-2zM15,11c0,1.11 -0.9,2 -2,2h-2v2h4v2L9,17v-4c0,-1.11 0.9,-2 2,-2h2L13,9L9,9L9,7h4c1.1,0 2,0.89 2,2v2z"/>
</vector>
Loading

0 comments on commit e45b1a8

Please sign in to comment.