-
Notifications
You must be signed in to change notification settings - Fork 387
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to show usage of Spring Animation in details
- Loading branch information
Showing
9 changed files
with
354 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
147 changes: 147 additions & 0 deletions
147
app/src/main/java/io/codetail/circualrevealsample/SpringSettingsBottomDialog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.