Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
38 changed files
with
1,925 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
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,27 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 24 | ||
buildToolsVersion "25.0.0" | ||
defaultConfig { | ||
applicationId "com.skydoves.elasticviewsexample" | ||
minSdkVersion 19 | ||
targetSdkVersion 24 | ||
versionCode 1 | ||
versionName "1.0" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
compile fileTree(dir: 'libs', include: ['*.jar']) | ||
compile 'com.android.support:appcompat-v7:24.2.1' | ||
compile 'com.android.support:design:24.2.1' | ||
testCompile 'junit:junit:4.12' | ||
compile 'com.jakewharton:butterknife:7.0.1' | ||
} |
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,17 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in C:\Users\magician\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} |
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,23 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.skydoves.elasticviewsexample"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<activity android:name=".MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
<activity android:name=".ExampleActivity0" /> | ||
<activity android:name=".ExampleActivity1" /> | ||
<activity android:name=".ExampleActivity2"></activity> | ||
</application> | ||
|
||
</manifest> |
73 changes: 73 additions & 0 deletions
73
app/src/main/java/com/skydoves/elasticviewsexample/ElasticVIews/ElasticAction.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,73 @@ | ||
package com.skydoves.elasticviewsexample.ElasticVIews; | ||
|
||
/* | ||
* Copyright (C) 2017 skydoves | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import android.support.v4.view.ViewCompat; | ||
import android.support.v4.view.ViewPropertyAnimatorListener; | ||
import android.util.Log; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.view.animation.CycleInterpolator; | ||
|
||
public class ElasticAction { | ||
|
||
private final static String TAG = "ElasticAction"; | ||
|
||
public static void doAction(ViewGroup view, int duration, float scaleX, float scaleY){ | ||
try { | ||
if(view.getScaleX() == 1) { | ||
ViewCompat.animate(view).setDuration(duration).scaleX(scaleX).scaleY(scaleY).setInterpolator(new CycleInterpolator(0.5f)) | ||
.setListener(new ViewPropertyAnimatorListener() { | ||
|
||
@Override | ||
public void onAnimationStart(final View view) { | ||
} | ||
|
||
@Override | ||
public void onAnimationEnd(final View v) { | ||
} | ||
|
||
@Override | ||
public void onAnimationCancel(final View view) { | ||
} | ||
}).withLayer().start(); | ||
|
||
for (int index = 0; index < ((ViewGroup) view).getChildCount(); ++index) { | ||
View nextChild = ((ViewGroup) view).getChildAt(index); | ||
ViewCompat.animate(nextChild).setDuration(duration).scaleX(scaleX).scaleY(scaleY).setInterpolator(new CycleInterpolator(0.5f)) | ||
.setListener(new ViewPropertyAnimatorListener() { | ||
|
||
@Override | ||
public void onAnimationStart(final View view) { | ||
} | ||
|
||
@Override | ||
public void onAnimationEnd(final View v) { | ||
} | ||
|
||
@Override | ||
public void onAnimationCancel(final View view) { | ||
} | ||
}).withLayer().start(); | ||
} | ||
} | ||
} | ||
catch (Exception e){ | ||
Log.e(TAG, "only ViewGroups : likes RelativeLayout, LinearLayout, etc could doAction"); | ||
} | ||
} | ||
} |
158 changes: 158 additions & 0 deletions
158
app/src/main/java/com/skydoves/elasticviewsexample/ElasticVIews/ElasticButton.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,158 @@ | ||
|
||
/* | ||
* Copyright (C) 2017 skydoves | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.skydoves.elasticviewsexample.ElasticVIews; | ||
|
||
import android.content.Context; | ||
import android.content.res.TypedArray; | ||
import android.graphics.Color; | ||
import android.graphics.Typeface; | ||
import android.graphics.drawable.GradientDrawable; | ||
import android.support.v4.view.ViewCompat; | ||
import android.support.v4.view.ViewPropertyAnimatorListener; | ||
import android.util.AttributeSet; | ||
import android.view.MotionEvent; | ||
import android.view.View; | ||
import android.view.animation.CycleInterpolator; | ||
import android.widget.Button; | ||
|
||
import com.skydoves.elasticviewsexample.R; | ||
|
||
public class ElasticButton extends Button { | ||
|
||
private Button view; | ||
private OnClickListener listener; | ||
|
||
private int round = 20; | ||
private float scale = 0.9f; | ||
private int color = R.color.colorPrimary; | ||
private int duration = 500; | ||
|
||
private String labelText = ""; | ||
private int labelColor = Color.WHITE; | ||
private int labelSize = 10; | ||
private int labelStyle = 0; | ||
|
||
public ElasticButton(Context context){ | ||
super(context); | ||
onCreate(); | ||
} | ||
|
||
public ElasticButton(Context context, AttributeSet attributeSet){ | ||
super(context, attributeSet); | ||
onCreate(); | ||
getAttrs(attributeSet); | ||
} | ||
|
||
public ElasticButton(Context context, AttributeSet attributeSet, int defStyle){ | ||
super(context, attributeSet, defStyle); | ||
onCreate(); | ||
getAttrs(attributeSet, defStyle); | ||
} | ||
|
||
private void onCreate(){ | ||
view = this; | ||
view.setAllCaps(false); | ||
view.setBackgroundResource(R.drawable.rectangle_button); | ||
} | ||
|
||
private void getAttrs(AttributeSet attrs) | ||
{ | ||
TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.ElasticButton); | ||
setTypeArray(typedArray); | ||
} | ||
|
||
private void getAttrs(AttributeSet attrs, int defStyle) | ||
{ | ||
TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.ElasticButton, defStyle, 0); | ||
setTypeArray(typedArray); | ||
} | ||
|
||
private void setTypeArray(TypedArray typedArray){ | ||
GradientDrawable bgShape = (GradientDrawable)view.getBackground(); | ||
|
||
round = typedArray.getInt(R.styleable.ElasticButton_button_round, round); | ||
bgShape.setCornerRadius(round); | ||
|
||
color = typedArray.getInt(R.styleable.ElasticButton_button_backgroundColor, color); | ||
bgShape.setColor(color); | ||
|
||
scale = typedArray.getFloat(R.styleable.ElasticButton_button_scale, scale); | ||
|
||
duration = typedArray.getInt(R.styleable.ElasticButton_button_duration, duration); | ||
|
||
labelText = typedArray.getString(R.styleable.ElasticButton_button_labelText); | ||
view.setText(labelText); | ||
|
||
labelColor = typedArray.getInt(R.styleable.ElasticButton_button_labelColor, labelColor); | ||
view.setTextColor(labelColor); | ||
|
||
labelSize = typedArray.getInt(R.styleable.ElasticButton_button_labelSize, labelSize); | ||
view.setTextSize(labelSize); | ||
|
||
labelStyle = typedArray.getInt(R.styleable.ElasticButton_button_labelStyle, labelStyle); | ||
|
||
if(labelStyle == 0) | ||
view.setTypeface(null, Typeface.NORMAL); | ||
else if(labelStyle == 1) | ||
view.setTypeface(null, Typeface.BOLD); | ||
else if(labelStyle == 2) | ||
view.setTypeface(null, Typeface.ITALIC); | ||
} | ||
|
||
@Override | ||
public boolean dispatchTouchEvent(MotionEvent event) { | ||
if(event.getAction() == MotionEvent.ACTION_UP) { | ||
if(listener != null) { | ||
if(view.getScaleX() == 1) { | ||
ViewCompat.animate(view).setDuration(duration).scaleX(scale).scaleY(scale).setInterpolator(new CycleInterpolator(0.5f)) | ||
.setListener(new ViewPropertyAnimatorListener() { | ||
|
||
@Override | ||
public void onAnimationStart(final View view) { | ||
} | ||
|
||
@Override | ||
public void onAnimationEnd(final View v) { | ||
onClick(); | ||
} | ||
|
||
@Override | ||
public void onAnimationCancel(final View view) { | ||
} | ||
}) | ||
.withLayer() | ||
.start(); | ||
} | ||
} | ||
} | ||
return super.dispatchTouchEvent(event); | ||
} | ||
|
||
public void setOnClickListener(OnClickListener listener) { | ||
this.listener = listener; | ||
} | ||
|
||
private void onClick(){ | ||
listener.onClick(this); | ||
} | ||
|
||
@Override | ||
protected void onFinishInflate() { | ||
super.onFinishInflate(); | ||
} | ||
} |
Oops, something went wrong.