Skip to content

Commit

Permalink
Merge branch 'feature/component' into 'develop'
Browse files Browse the repository at this point in the history
Feature/component



See merge request !5
  • Loading branch information
Irina Galata committed Mar 28, 2017
2 parents 9426d6b + eec3592 commit 47dd862
Show file tree
Hide file tree
Showing 15 changed files with 221 additions and 115 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ allprojects {
repositories {
jcenter()
}

}

task clean(type: Delete) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,43 @@
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.AppCompatEditText;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;

import com.yalantis.jellytoolbar.listener.JellyListener;
import com.yalantis.jellytoolbar.widget.JellyToolbar;

public class MainActivity extends AppCompatActivity {

private static final String TEXT_KEY = "text";

private JellyToolbar toolbar;
private AppCompatEditText editText;
private JellyListener jellyListener = new JellyListener() {
@Override
public void onCancelIconClicked() {
if (TextUtils.isEmpty(editText.getText())) {
toolbar.collapse();
} else {
editText.getText().clear();
}
}
};

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

JellyToolbar toolbar = (JellyToolbar) findViewById(R.id.toolbar);
toolbar.getToolbar().setLogo(R.drawable.ic_menu);
toolbar = (JellyToolbar) findViewById(R.id.toolbar);
toolbar.getToolbar().setNavigationIcon(R.drawable.ic_menu);
toolbar.setJellyListener(jellyListener);
toolbar.getToolbar().setPadding(0, getStatusBarHeight(), 0, 0);

AppCompatEditText editText = new AppCompatEditText(this);
editText = (AppCompatEditText) LayoutInflater.from(this).inflate(R.layout.edit_text, null);
editText.setBackgroundResource(R.color.colorTransparent);
toolbar.setContentView(LayoutInflater.from(this).inflate(R.layout.edit_text, null));
toolbar.setContentView(editText);

getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
Expand All @@ -36,4 +54,18 @@ private int getStatusBarHeight() {
}
return result;
}

@Override
protected void onSaveInstanceState(Bundle outState) {
outState.putString(TEXT_KEY, editText.getText().toString());
super.onSaveInstanceState(outState);
}

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
editText.setText(savedInstanceState.getString(TEXT_KEY));
editText.setSelection(editText.getText().length());
}

}
6 changes: 3 additions & 3 deletions demo/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
app:cancelIcon="@drawable/ic_close"
app:endColor="#8463d4"
app:endColor="@color/colorEnd"
app:icon="@drawable/ic_search"
app:startColor="#cb5ed9"
app:title=" News feed"
app:startColor="@color/colorStart"
app:title="@string/str_news_feed"
app:titleTextColor="@android:color/white" />

<ScrollView
Expand Down
1 change: 1 addition & 0 deletions demo/src/main/res/layout/edit_text.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorTransparent"
android:lines="1"
android:textColor="#7fffffff" />
2 changes: 2 additions & 0 deletions demo/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
<color name="colorPrimaryDark">#8a53cf</color>
<color name="colorAccent">#FF4081</color>
<color name="colorTransparent">#00ffffff</color>
<color name="colorStart">#cb5ed9</color>
<color name="colorEnd">#8463d4</color>
</resources>
1 change: 1 addition & 0 deletions demo/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<resources>
<string name="app_name">Jelly animation demo</string>
<string name="str_news_feed">News feed</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ package com.yalantis.jellytoolbar
*/
object Constant {

val ANIMATION_DURATION = 1000L
const val ANIMATION_DURATION = 1100L

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ import android.view.animation.Interpolator
* Created by irinagalata on 11/23/16.
*/
class BounceInterpolator : Interpolator {
val ROTATION_TIME = 0.46667f
val MOVE_TIME = 0.46667f
val FIRST_BOUNCE_TIME = 0.26666f

override fun getInterpolation(t: Float): Float {
if (t < ROTATION_TIME)
return rotation(t)
else if (t < ROTATION_TIME + FIRST_BOUNCE_TIME)
return firstBounce(t)
else
return secondBounce(t)
override fun getInterpolation(t: Float): Float = when {
t < MOVE_TIME ->
move(t)
t < MOVE_TIME + FIRST_BOUNCE_TIME ->
firstBounce(t)
else ->
secondBounce(t)
}

private fun rotation(t: Float): Float {
private fun move(t: Float): Float {
return 4.592f * t * t
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import android.view.animation.Interpolator
*/
class JellyInterpolator : Interpolator {

override fun getInterpolation(t: Float): Float {
return (Math.min(1.0, Math.sin(28 * (t - 0.22)) / (t - 0.22) / 5)).toFloat()
}
override fun getInterpolation(t: Float) = (Math.min(1.0, Math.sin(28 * t - 6.16) / (5 * t - 1.1))).toFloat()

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@ import android.animation.Animator
*/
abstract class AnimationListener : Animator.AnimatorListener {

override fun onAnimationRepeat(animation: Animator?) {
}
override fun onAnimationRepeat(animation: Animator?) = Unit

override abstract fun onAnimationEnd(animation: Animator?)
override fun onAnimationStart(animation: Animator?) = Unit

override fun onAnimationStart(animation: Animator?) {
}
override fun onAnimationCancel(animation: Animator?) = Unit

override fun onAnimationCancel(animation: Animator?) {
}
override abstract fun onAnimationEnd(animation: Animator?)

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ package com.yalantis.jellytoolbar.listener
/**
* Created by irinagalata on 11/25/16.
*/
interface JellyListener {
abstract class JellyListener {

fun onToolbarExpandingStarted()
open fun onToolbarExpandingStarted() = Unit

fun onToolbarCollapsingStarted()
open fun onToolbarCollapsingStarted() = Unit

fun onToolbarExpanded()
open fun onToolbarExpanded() = Unit

fun onToolbarCollapsed()
open fun onToolbarCollapsed() = Unit

abstract fun onCancelIconClicked()

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,40 @@ class ContentLayout : RelativeLayout, JellyWidget {
value?.let {
container.removeAllViews()
container.addView(it)
field = value
}
}
@DrawableRes var iconRes: Int? = null
set(value) {
value?.let { icon.setBackgroundResource(it) }
value?.let {
icon.setBackgroundResource(it)
field = value
}
}
@DrawableRes var cancelIconRes: Int? = null
set(value) {
value?.let { cancelIcon.setBackgroundResource(it) }
value?.let {
cancelIcon.setBackgroundResource(it)
field = value
}
}

internal var onIconClickListener: OnClickListener? = null
set(value) {
icon.setOnClickListener(value)
field = value
}
internal var onCancelIconClickListener: OnClickListener? = null
set(value) {
cancelIcon.setOnClickListener(value)
field = value
}

private var mStartPosition = 0f
private var mEndPosition = 0f
private var mIsInitialized = false
private var startPosition = 0f
private var endPosition = 0f
private var isInitialized = false
private val iconFullSize = getDimen(R.dimen.icon_full_size)
private val iconPadding = getDimen(R.dimen.icon_padding)

constructor(context: Context?) : this(context, null)
constructor(context: Context?, attrs: AttributeSet?) : this(context, attrs, 0)
Expand All @@ -56,53 +67,61 @@ class ContentLayout : RelativeLayout, JellyWidget {
override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) {
super.onLayout(changed, l, t, r, b)

if (!mIsInitialized) {
if (!isInitialized) {
init()
mIsInitialized = true
isInitialized = true
}
}

fun init() {
translationX = width.toFloat() - getDimen(R.dimen.icon_full_size)
mStartPosition = width.toFloat() - getDimen(R.dimen.icon_full_size)
mEndPosition = -height.toFloat() + getDimen(R.dimen.icon_full_size) - getDimen(R.dimen.icon_padding) * 0.5f
override fun init() {
translationX = width.toFloat() - iconFullSize
startPosition = width.toFloat() - iconFullSize
endPosition = -height.toFloat() + iconFullSize - iconPadding * 0.5f
}

override fun collapse() {
ValueAnimator.ofFloat(mEndPosition, mStartPosition).apply {
ValueAnimator.ofFloat(endPosition, startPosition).apply {
startDelay = 50
translationX = mEndPosition
translationX = endPosition
duration = Constant.ANIMATION_DURATION / 3
interpolator = BounceInterpolator()
addUpdateListener {
translationX = animatedValue as Float
icon.alpha = 1f - 0.5f * getProgress(mEndPosition, mStartPosition, animatedFraction)
cancelIcon.rotationY = 90 * getProgress(mEndPosition, mStartPosition, animatedFraction) * 10
icon.alpha = 0.5f + 0.5f * animatedFraction

with(cancelIcon) {
rotation = 360 * animatedFraction
scaleX = 1 - animatedFraction
scaleY = 1 - animatedFraction
alpha = 1 - animatedFraction
translationX = endPosition - animatedValue as Float
}
}
}.start()
ValueAnimator.ofFloat(0f, 90f).apply {
startDelay = 50
duration = 50
addUpdateListener { cancelIcon.rotation = animatedValue as Float }
}.start()
}

override fun expand() {
ValueAnimator.ofFloat(mStartPosition, mEndPosition).apply {
ValueAnimator.ofFloat(startPosition, endPosition).apply {
startDelay = 50
translationX = mStartPosition
translationX = startPosition
duration = Constant.ANIMATION_DURATION / 3
interpolator = BounceInterpolator()

with(cancelIcon) {
translationX = 0f
alpha = 1f
scaleX = 1f
scaleY = 1f
}
addUpdateListener {
translationX = animatedValue as Float
icon.alpha = 0.5f + 0.5f * getProgress(mStartPosition, mEndPosition, animatedFraction)
icon.alpha = 1f - 0.5f * animatedFraction
}
}.start()
}

private fun getProgress(startValue: Float, endValue: Float, currentValue: Float): Float {
return currentValue / (endValue - startValue)
override fun expandImmediately() {
expand()
}


}
Loading

0 comments on commit 47dd862

Please sign in to comment.