diff --git a/app/build.gradle b/app/build.gradle
index 3a5c40e..0df1258 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'
android {
- compileSdkVersion 22
- buildToolsVersion "23.0.0 rc2"
+ compileSdkVersion 25
+ buildToolsVersion "25.0.3"
defaultConfig {
applicationId "com.goka.parkedtextview"
minSdkVersion 9
- targetSdkVersion 22
+ targetSdkVersion 25
versionCode 1
versionName "1.0"
}
@@ -22,5 +22,5 @@ android {
dependencies {
compile project(':parkedtextview')
compile fileTree(dir: 'libs', include: ['*.jar'])
- compile 'com.android.support:appcompat-v7:22.2.1'
+ compile 'com.android.support:appcompat-v7:25.4.0'
}
diff --git a/app/src/main/java/com/goka/sample/MainActivity.java b/app/src/main/java/com/goka/sample/MainActivity.java
index 78768ac..245437d 100644
--- a/app/src/main/java/com/goka/sample/MainActivity.java
+++ b/app/src/main/java/com/goka/sample/MainActivity.java
@@ -1,13 +1,17 @@
package com.goka.sample;
-import com.goka.parkedtextview.ParkedTextView;
-
-import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
+import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
+import android.view.View;
+import android.widget.Button;
+import android.widget.Toast;
+
+import com.goka.parkedtextview.ParkedTextView;
public class MainActivity extends AppCompatActivity {
+ ParkedTextView mParkedTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -19,6 +23,22 @@ protected void onCreate(Bundle savedInstanceState) {
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
+ mParkedTextView = (ParkedTextView) findViewById(R.id.parked_text_view);
+ Button setButton = (Button) findViewById(R.id.btn_set_text);
+ Button getButton = (Button) findViewById(R.id.btn_get_text);
+ setButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ mParkedTextView.setTypedText("test");
+ }
+ });
+ getButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ Toast.makeText(MainActivity.this, mParkedTextView.getTypedText(),
+ Toast.LENGTH_SHORT).show();
+ }
+ });
return true;
}
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 61666f1..7b50cbe 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -1,27 +1,39 @@
-
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:paddingLeft="@dimen/activity_horizontal_margin"
+ android:paddingRight="@dimen/activity_horizontal_margin"
+ android:paddingTop="@dimen/activity_vertical_margin"
+ android:paddingBottom="@dimen/activity_vertical_margin"
+ tools:context=".MainActivity"
+ android:background="#ffaa66cc">
-
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ android:id="@+id/parked_text_view"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:gravity="center"
+ android:background="@android:color/transparent"
+ android:layout_centerInParent="true"
+ android:textSize="24sp"
+ app:parkedText=".slack.com"
+ app:parkedHint="yourteam"
+ app:parkedTextColor="FFFFFF"
+ app:parkedHintColor="CCCCCC"
+ app:parkedTextBold="true" />
+
+
diff --git a/build.gradle b/build.gradle
index 9405f3f..477cd22 100644
--- a/build.gradle
+++ b/build.gradle
@@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
- classpath 'com.android.tools.build:gradle:1.2.3'
+ classpath 'com.android.tools.build:gradle:2.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
@@ -15,5 +15,8 @@ buildscript {
allprojects {
repositories {
jcenter()
+ maven {
+ url "https://maven.google.com"
+ }
}
}
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 81a854c..dfad69c 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Tue Jul 21 16:16:04 JST 2015
+#Tue Jun 20 10:01:46 SGT 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
diff --git a/parkedtextview/build.gradle b/parkedtextview/build.gradle
index dde580b..6233e24 100644
--- a/parkedtextview/build.gradle
+++ b/parkedtextview/build.gradle
@@ -1,12 +1,12 @@
apply plugin: 'com.android.library'
android {
- compileSdkVersion 22
- buildToolsVersion "23.0.0 rc2"
+ compileSdkVersion 25
+ buildToolsVersion "25.0.3"
defaultConfig {
minSdkVersion 9
- targetSdkVersion 22
+ targetSdkVersion 25
versionCode 1
versionName "1.0"
}
@@ -19,5 +19,5 @@ android {
}
dependencies {
- compile 'com.android.support:appcompat-v7:22.2.1'
+ compile 'com.android.support:appcompat-v7:25.4.0'
}
diff --git a/parkedtextview/src/main/AndroidManifest.xml b/parkedtextview/src/main/AndroidManifest.xml
index a189dc9..2fbc53e 100644
--- a/parkedtextview/src/main/AndroidManifest.xml
+++ b/parkedtextview/src/main/AndroidManifest.xml
@@ -1,10 +1,6 @@
-
-
+ android:label="@string/app_name">
-
diff --git a/parkedtextview/src/main/java/com/goka/parkedtextview/ParkedTextView.java b/parkedtextview/src/main/java/com/goka/parkedtextview/ParkedTextView.java
index d529a78..bf1770e 100644
--- a/parkedtextview/src/main/java/com/goka/parkedtextview/ParkedTextView.java
+++ b/parkedtextview/src/main/java/com/goka/parkedtextview/ParkedTextView.java
@@ -2,34 +2,32 @@
import android.content.Context;
import android.content.res.TypedArray;
+import android.os.Build;
import android.text.Editable;
import android.text.Html;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.AttributeSet;
-import android.widget.EditText;
/**
* Created by katsuyagoto on 15/07/22.
*/
-public class ParkedTextView extends EditText {
+public class ParkedTextView extends android.support.v7.widget.AppCompatEditText {
private static final String TAG = ParkedTextView.class.getSimpleName();
private static final String DEFAULT_TEXT_COLOR = "FFFFFF";
// Able to set
private String mParkedText = "";
+ private String mHintText = "";
private boolean mIsBoldParkedText = true;
+ private boolean mIsParkedInFront = false;
private String mParkedTextColor = DEFAULT_TEXT_COLOR;
private String mParkedHintColor = DEFAULT_TEXT_COLOR;
// Unable to set
private String mText = null;
- private enum TypingState {
- Start, Typed
- }
- private TypingState mTypingState = TypingState.Start;
public ParkedTextView(Context context) {
super(context);
@@ -45,13 +43,13 @@ public ParkedTextView(Context context, AttributeSet attrs, int defStyleAttr) {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ParkedTextView, defStyleAttr, 0);
+ mIsParkedInFront = a.getBoolean(R.styleable.ParkedTextView_parkedInFront, false);
+
mParkedText = a.getString(R.styleable.ParkedTextView_parkedText);
if (mParkedText == null) {
mParkedText = "";
}
- String hint = a.getString(R.styleable.ParkedTextView_parkedHint);
-
mParkedTextColor = a.getString(R.styleable.ParkedTextView_parkedTextColor);
if (mParkedTextColor == null) {
mParkedTextColor = ParkedTextView.DEFAULT_TEXT_COLOR;
@@ -64,41 +62,65 @@ public ParkedTextView(Context context, AttributeSet attrs, int defStyleAttr) {
mIsBoldParkedText = a.getBoolean(R.styleable.ParkedTextView_parkedTextBold, true);
- init();
+ setHintText(a.getString(R.styleable.ParkedTextView_parkedHint));
- if (hint != null) {
- setPlaceholderText(hint);
- }
+ init();
a.recycle();
}
private void init() {
mText = "";
- observeText();
-
- mTypingState = TypingState.Start;
addTextChangedListener(new ParkedTextViewWatcher(this));
}
+ public void setHintText(String hint){
+ mHintText = hint;
+ if(mHintText == null)
+ mHintText = "";
+ setPlaceholderText();
+ }
+
+ public String getHintText(){
+ return mHintText;
+ }
+
public String getParkedText() {
return mParkedText;
}
public void setParkedText(String parkedText) {
- if (!TextUtils.isEmpty(mText)) {
- String typed = mText.substring(0, getBeginningPositionOfParkedText());
- mText = typed + parkedText;
+ String typed;
+ if(!TextUtils.isEmpty(mText)){
+ if(mIsParkedInFront) {
+ typed = mText.substring(getParkedText().length());
+ mText = getParkedText() + typed;
+ }else{
+ typed = mText.substring(0, getBeginningPositionOfParkedText());
+ mText = typed + getParkedText();
+ }
mParkedText = parkedText;
-
- textChanged();
- } else {
+ }else{
mParkedText = parkedText;
}
}
+ public String getTypedText() {
+ if(!mIsParkedInFront && mText.endsWith(mParkedText)){
+ return mText.substring(0, getBeginningPositionOfParkedText());
+ }else if(mIsParkedInFront && mText.startsWith(mText) && !mText.isEmpty())
+ return mText.substring(getParkedText().length());
+ else
+ return mText;
+ }
+
+ public void setTypedText(String typedText) {
+ textChanged(typedText);
+ }
+
+
private int getBeginningPositionOfParkedText() {
- int position = mText.length() - mParkedText.length();
+ int position = mText.length() - getParkedText().length();
if (position < 0) {
return 0;
}
@@ -109,39 +131,32 @@ private void goToBeginningOfParkedText() {
setSelection(getBeginningPositionOfParkedText());
}
- private String getTypedText() {
- if (mText.endsWith(mParkedText)) {
- return mText.substring(0, getBeginningPositionOfParkedText());
- }
- return mText;
+ private void goToEndOfParkedText() {
+ setSelection(mText.length());
}
- private void setTypedText(String typedText) {
- mText = typedText;
- observeText();
-
- textChanged();
+ public void setEmptyText() {
+ setText("");
}
- private void setEmptyText() {
- setTypedText("");
- }
-
- public void setPlaceholderText(String placeholderText) {
- Spanned hint = null;
+ public void setPlaceholderText() {
+ Spanned hint;
String parkedTextColor = reformatColor(mParkedTextColor);
String parkedHintColor = reformatColor(mParkedHintColor);
- if (mIsBoldParkedText) {
- hint = Html.fromHtml(String.format("%s%s", parkedHintColor, placeholderText, parkedTextColor, mParkedText));
- } else {
- hint = Html.fromHtml(String.format("%s%s", parkedHintColor, placeholderText, parkedTextColor, mParkedText));
+ if(!getHintText().isEmpty()) {
+ if (mIsParkedInFront)
+ if (mIsBoldParkedText) {
+ hint = fromHtml(String.format("%s%s", parkedTextColor, getParkedText(), parkedHintColor, getHintText()));
+ } else {
+ hint = fromHtml(String.format("%s%s", parkedTextColor, getParkedText(), parkedHintColor, getHintText()));
+ }
+ else if (mIsBoldParkedText) {
+ hint = fromHtml(String.format("%s%s", parkedHintColor, getHintText(), parkedTextColor, getParkedText()));
+ } else {
+ hint = fromHtml(String.format("%s%s", parkedHintColor, getHintText(), parkedTextColor, getParkedText()));
+ }
+ super.setHint(hint);
}
- super.setHint(hint);
- }
-
- // Call when TypedText is changed
- private String observeText() {
- return mText = getTypedText() + mParkedText;
}
private String reformatColor(String color) {
@@ -157,37 +172,50 @@ private String reformatColor(String color) {
private Spanned getHtmlText() {
String parkedTextColor = reformatColor(mParkedTextColor);
- if (mIsBoldParkedText) {
- return Html.fromHtml(String.format("%s%s", parkedTextColor, getTypedText(), parkedTextColor, mParkedText));
+ if(mIsParkedInFront){
+ if (mIsBoldParkedText) {
+ return fromHtml(
+ String.format(
+ "%s%s",
+ parkedTextColor, getParkedText(), parkedTextColor, getTypedText()));
+ }
+ return fromHtml(
+ String.format("%s", parkedTextColor,
+ getParkedText() + getTypedText()));
+ }else{
+ if (mIsBoldParkedText) {
+ return fromHtml(
+ String.format(
+ "%s%s",
+ parkedTextColor, getTypedText(), parkedTextColor, getParkedText()));
+ }
+ return fromHtml(
+ String.format("%s", parkedTextColor,
+ getTypedText() + getParkedText()));
}
- return Html.fromHtml(String.format("%s", parkedTextColor, getTypedText() + mParkedText));
}
- private void textChanged() {
- switch (mTypingState) {
- case Start:
- if (mText.length() <= 0) {
- return;
- }
- setText(getHtmlText(), BufferType.SPANNABLE);
- goToBeginningOfParkedText();
-
- mTypingState = TypingState.Typed;
-
- case Typed:
- if (mText.equals(mParkedText)) {
- mTypingState = TypingState.Start;
- setText(getHtmlText(), BufferType.SPANNABLE);
- return;
- }
-
- setText(getHtmlText(), BufferType.SPANNABLE);
-
- goToBeginningOfParkedText();
-
- default:
- break;
+ private void textChanged(String typed) {
+ if(typed.length() <= getParkedText().length() && !mText.isEmpty()){
+ mText = getParkedText();
+ }else{
+ if(mIsParkedInFront) {
+ if(typed.startsWith(getParkedText()))
+ mText = typed;
+ else
+ mText = getParkedText() + typed;
+ }else{
+ if(typed.endsWith(getParkedText()))
+ mText = typed;
+ else
+ mText = typed + getParkedText();
+ }
}
+ setText(getHtmlText(), BufferType.SPANNABLE);
+ if(mIsParkedInFront)
+ goToEndOfParkedText();
+ else
+ goToBeginningOfParkedText();
}
public boolean isBoldParkedText() {
@@ -214,50 +242,49 @@ public void setParkedHintColor(String parkedHintColor) {
mParkedHintColor = parkedHintColor;
}
- private static class ParkedTextViewWatcher implements TextWatcher {
+ private class ParkedTextViewWatcher implements TextWatcher {
private ParkedTextView mParkedTextView;
- private boolean mIsDeleteText;
- public ParkedTextViewWatcher(ParkedTextView parkedTextView) {
+ ParkedTextViewWatcher(ParkedTextView parkedTextView) {
this.mParkedTextView = parkedTextView;
}
@Override
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
+ public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
@Override
- public void onTextChanged(CharSequence s, int start, int before, int count) {
- if (before > 0) {
- mIsDeleteText = true;
- } else {
- mIsDeleteText = false;
- }
- }
+ public void onTextChanged(CharSequence s, int start, int before, int count) {}
@Override
public void afterTextChanged(Editable s) {
mParkedTextView.removeTextChangedListener(this);
-
- String text = s.toString();
- if (mIsDeleteText) {
-
- if (text.length() < mParkedTextView.getParkedText().length()) {
- mParkedTextView.setEmptyText();
- } else {
- String parkedText = text.substring(mParkedTextView.getBeginningPositionOfParkedText() - 1);
- if (!parkedText.equals(mParkedTextView.getParkedText())) {
- mParkedTextView.setEmptyText();
- } else {
- mParkedTextView.setTypedText(text);
- }
- }
- } else {
- mParkedTextView.setTypedText(text);
+ String text = s.toString().replace(" ", "");
+ if(text.equals("")) {
+ mParkedTextView.addTextChangedListener(this);
+ mText = "";
+ return;
}
-
+ boolean isParkedModified = false;
+ if(!mText.isEmpty() && mIsParkedInFront && !text.startsWith(getParkedText())){
+ setText(getHtmlText(), BufferType.SPANNABLE);
+ goToEndOfParkedText();
+ isParkedModified = true;
+ }else if(!mText.isEmpty() && !mIsParkedInFront && !text.endsWith(getParkedText())){
+ setText(getHtmlText(), BufferType.SPANNABLE);
+ goToBeginningOfParkedText();
+ isParkedModified = true;
+ }
+ if(!isParkedModified)
+ mParkedTextView.setTypedText(text);
mParkedTextView.addTextChangedListener(this);
}
}
+ @SuppressWarnings("deprecation")
+ public static Spanned fromHtml(String str){
+ if(Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N)
+ return Html.fromHtml(str, Html.FROM_HTML_MODE_LEGACY);
+ return Html.fromHtml(str);
+ }
}
diff --git a/parkedtextview/src/main/res/values/attrs.xml b/parkedtextview/src/main/res/values/attrs.xml
index 217004e..7be4d94 100644
--- a/parkedtextview/src/main/res/values/attrs.xml
+++ b/parkedtextview/src/main/res/values/attrs.xml
@@ -7,6 +7,7 @@
+
\ No newline at end of file