-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from swapnil1104/interactive_animation
Added Shake animation
- Loading branch information
Showing
10 changed files
with
108 additions
and
44 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
26 changes: 17 additions & 9 deletions
26
app/src/main/java/com/broooapps/otpedittext/MainActivity.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 |
---|---|---|
@@ -1,37 +1,45 @@ | ||
package com.broooapps.otpedittext; | ||
|
||
import androidx.appcompat.app.AppCompatActivity; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.os.Bundle; | ||
import android.view.View; | ||
import android.widget.EditText; | ||
import android.widget.TextView; | ||
import android.widget.Toast; | ||
|
||
import com.broooapps.otpedittext2.OnCompleteListener; | ||
import com.broooapps.otpedittext2.OtpEditText; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
|
||
TextView textDisplay; | ||
OtpEditText otpEditText; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
|
||
OtpEditText editText = findViewById(R.id.top); | ||
otpEditText = findViewById(R.id.oev_view); | ||
|
||
textDisplay = findViewById(R.id.text_display); | ||
|
||
|
||
editText.setOnCompleteListener(new OnCompleteListener() { | ||
otpEditText.setOnCompleteListener(new OnCompleteListener() { | ||
@SuppressLint("SetTextI18n") | ||
@Override | ||
public void onComplete(String value) { | ||
Toast.makeText(MainActivity.this, "Completed " + value, Toast.LENGTH_SHORT).show(); | ||
textDisplay.setText("Entered Value: " + value); | ||
} | ||
}); | ||
|
||
|
||
} | ||
|
||
public void displayText(View view) { | ||
|
||
String input = String.valueOf(((EditText) findViewById(R.id.top)).getText()); | ||
((TextView) findViewById(R.id.textView)).setText(input); | ||
|
||
String otpValue = otpEditText.getOtpValue(); | ||
if (otpValue != null) { | ||
textDisplay.setText("Entered Value: " + otpEditText.getOtpValue()); | ||
} | ||
} | ||
} |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,11 +4,12 @@ | |
* Created by Swapnil Tiwari on 2019-05-07. | ||
* [email protected] | ||
*/ | ||
|
||
import android.content.Context; | ||
import android.content.res.TypedArray; | ||
import android.graphics.Canvas; | ||
import android.graphics.Paint; | ||
|
||
import androidx.annotation.Nullable; | ||
import androidx.core.content.ContextCompat; | ||
import androidx.appcompat.widget.AppCompatEditText; | ||
import android.text.Editable; | ||
|
@@ -18,12 +19,12 @@ | |
import android.view.Menu; | ||
import android.view.MenuItem; | ||
import android.view.View; | ||
|
||
import android.view.animation.AnimationUtils; | ||
|
||
public class OtpEditText extends AppCompatEditText implements TextWatcher { | ||
public static final String XML_NAMESPACE_ANDROID = "http://schemas.android.com/apk/res/android"; | ||
|
||
private OnClickListener mClickListener; | ||
private View.OnClickListener mClickListener; | ||
|
||
private Paint mLinesPaint; | ||
private Paint mStrokePaint; | ||
|
@@ -69,9 +70,11 @@ public OtpEditText(Context context, AttributeSet attrs, int defStyleAttr) { | |
init(context, attrs); | ||
} | ||
|
||
private void init(Context context, AttributeSet attrs) { | ||
private void init(Context context, @Nullable AttributeSet attrs) { | ||
|
||
getAttrsFromTypedArray(attrs); | ||
if (attrs != null) { | ||
getAttrsFromTypedArray(attrs); | ||
} | ||
|
||
mTextPaint = getPaint(); | ||
mTextPaint.setColor(mTextColor); | ||
|
@@ -168,9 +171,14 @@ private void getAttrsFromTypedArray(AttributeSet attributeSet) { | |
a.recycle(); | ||
} | ||
|
||
@Override | ||
public void setOnClickListener(OnClickListener l) { | ||
mClickListener = l; | ||
@Nullable | ||
public String getOtpValue() { | ||
if (String.valueOf(getText()).length() != mMaxLength) { | ||
this.startAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.shake)); | ||
return null; | ||
} else { | ||
return String.valueOf(getText()); | ||
} | ||
} | ||
|
||
@Override | ||
|
@@ -272,9 +280,6 @@ private void updateColorForLines(boolean next, boolean current) { | |
} | ||
} | ||
|
||
public void setOnCompleteListener(OnCompleteListener listener) { | ||
completeListener = listener; | ||
} | ||
|
||
@Override | ||
public void beforeTextChanged(CharSequence s, int start, int count, int after) { | ||
|
@@ -290,4 +295,14 @@ public void afterTextChanged(Editable s) { | |
completeListener.onComplete(String.valueOf(s)); | ||
} | ||
} | ||
|
||
|
||
@Override | ||
public void setOnClickListener(OnClickListener l) { | ||
mClickListener = l; | ||
} | ||
|
||
public void setOnCompleteListener(OnCompleteListener listener) { | ||
completeListener = listener; | ||
} | ||
} |
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,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<set xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<translate android:duration="50" | ||
android:fromXDelta="-3%" | ||
android:repeatCount="3" | ||
android:repeatMode="reverse" | ||
android:toXDelta="3%"/> | ||
</set> |
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