From 862f15aeaa7e630f7142e7dd11fbe7ab2f68b8af Mon Sep 17 00:00:00 2001 From: Paul Austian Alday Date: Tue, 20 Jun 2017 10:03:45 +0800 Subject: [PATCH 01/12] update libs --- app/build.gradle | 8 ++++---- build.gradle | 5 ++++- gradle/wrapper/gradle-wrapper.properties | 4 ++-- parkedtextview/build.gradle | 8 ++++---- 4 files changed, 14 insertions(+), 11 deletions(-) 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/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' } From a4731efcd30840ce1701dc7aaa57eca2b01f4e25 Mon Sep 17 00:00:00 2001 From: Paul Austian Alday Date: Tue, 20 Jun 2017 10:18:39 +0800 Subject: [PATCH 02/12] set typed text to public --- .../main/java/com/goka/parkedtextview/ParkedTextView.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/parkedtextview/src/main/java/com/goka/parkedtextview/ParkedTextView.java b/parkedtextview/src/main/java/com/goka/parkedtextview/ParkedTextView.java index d529a78..53df5cc 100644 --- a/parkedtextview/src/main/java/com/goka/parkedtextview/ParkedTextView.java +++ b/parkedtextview/src/main/java/com/goka/parkedtextview/ParkedTextView.java @@ -109,14 +109,14 @@ private void goToBeginningOfParkedText() { setSelection(getBeginningPositionOfParkedText()); } - private String getTypedText() { + public String getTypedText() { if (mText.endsWith(mParkedText)) { return mText.substring(0, getBeginningPositionOfParkedText()); } return mText; } - private void setTypedText(String typedText) { + public void setTypedText(String typedText) { mText = typedText; observeText(); @@ -259,5 +259,4 @@ public void afterTextChanged(Editable s) { mParkedTextView.addTextChangedListener(this); } } - } From 4d9f004622f4269def748eae9a1562cde8cd7406 Mon Sep 17 00:00:00 2001 From: Paul Austian Alday Date: Tue, 20 Jun 2017 11:45:01 +0800 Subject: [PATCH 03/12] update deprecated --- .../goka/parkedtextview/ParkedTextView.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/parkedtextview/src/main/java/com/goka/parkedtextview/ParkedTextView.java b/parkedtextview/src/main/java/com/goka/parkedtextview/ParkedTextView.java index 53df5cc..35a7e12 100644 --- a/parkedtextview/src/main/java/com/goka/parkedtextview/ParkedTextView.java +++ b/parkedtextview/src/main/java/com/goka/parkedtextview/ParkedTextView.java @@ -2,18 +2,18 @@ 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"; @@ -132,9 +132,9 @@ public void setPlaceholderText(String placeholderText) { String parkedTextColor = reformatColor(mParkedTextColor); String parkedHintColor = reformatColor(mParkedHintColor); if (mIsBoldParkedText) { - hint = Html.fromHtml(String.format("%s%s", parkedHintColor, placeholderText, parkedTextColor, mParkedText)); + hint = fromHtml(String.format("%s%s", parkedHintColor, placeholderText, parkedTextColor, mParkedText)); } else { - hint = Html.fromHtml(String.format("%s%s", parkedHintColor, placeholderText, parkedTextColor, mParkedText)); + hint = fromHtml(String.format("%s%s", parkedHintColor, placeholderText, parkedTextColor, mParkedText)); } super.setHint(hint); } @@ -158,9 +158,9 @@ 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)); + return fromHtml(String.format("%s%s", parkedTextColor, getTypedText(), parkedTextColor, mParkedText)); } - return Html.fromHtml(String.format("%s", parkedTextColor, getTypedText() + mParkedText)); + return fromHtml(String.format("%s", parkedTextColor, getTypedText() + mParkedText)); } private void textChanged() { @@ -224,11 +224,11 @@ public ParkedTextViewWatcher(ParkedTextView 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) { + if(before > 0) { mIsDeleteText = true; } else { mIsDeleteText = false; @@ -259,4 +259,11 @@ public void afterTextChanged(Editable s) { 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); + } } From 180a1564433b71dc790e834bcfb50b7c349f6361 Mon Sep 17 00:00:00 2001 From: Paul Austian Alday Date: Tue, 20 Jun 2017 13:58:43 +0800 Subject: [PATCH 04/12] fix bug --- app/src/main/res/layout/activity_main.xml | 46 +++++++++---------- parkedtextview/src/main/AndroidManifest.xml | 6 +-- .../goka/parkedtextview/ParkedTextView.java | 18 +++++--- 3 files changed, 34 insertions(+), 36 deletions(-) diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 61666f1..42cb7b8 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,27 +1,25 @@ - + 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/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 35a7e12..ffe4266 100644 --- a/parkedtextview/src/main/java/com/goka/parkedtextview/ParkedTextView.java +++ b/parkedtextview/src/main/java/com/goka/parkedtextview/ParkedTextView.java @@ -117,7 +117,10 @@ public String getTypedText() { } public void setTypedText(String typedText) { - mText = typedText; + if(typedText.endsWith(mParkedText)) + mText = typedText; + else + mText = typedText + mParkedText; observeText(); textChanged(); @@ -158,9 +161,14 @@ private String reformatColor(String color) { private Spanned getHtmlText() { String parkedTextColor = reformatColor(mParkedTextColor); if (mIsBoldParkedText) { - return fromHtml(String.format("%s%s", parkedTextColor, getTypedText(), parkedTextColor, mParkedText)); + return fromHtml( + String.format( + "%s%s", + parkedTextColor, getTypedText(), parkedTextColor, mParkedText)); } - return fromHtml(String.format("%s", parkedTextColor, getTypedText() + mParkedText)); + return fromHtml( + String.format("%s", parkedTextColor, + getTypedText() + mParkedText)); } private void textChanged() { @@ -173,18 +181,14 @@ private void textChanged() { 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; } From de82c2c351d046adc020e3add666be7328b14238 Mon Sep 17 00:00:00 2001 From: Paul Austian Alday Date: Tue, 20 Jun 2017 14:08:52 +0800 Subject: [PATCH 05/12] fix error when setting typed text --- .../main/java/com/goka/parkedtextview/ParkedTextView.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/parkedtextview/src/main/java/com/goka/parkedtextview/ParkedTextView.java b/parkedtextview/src/main/java/com/goka/parkedtextview/ParkedTextView.java index ffe4266..5b750d9 100644 --- a/parkedtextview/src/main/java/com/goka/parkedtextview/ParkedTextView.java +++ b/parkedtextview/src/main/java/com/goka/parkedtextview/ParkedTextView.java @@ -249,7 +249,11 @@ public void afterTextChanged(Editable s) { if (text.length() < mParkedTextView.getParkedText().length()) { mParkedTextView.setEmptyText(); } else { - String parkedText = text.substring(mParkedTextView.getBeginningPositionOfParkedText() - 1); + String parkedText; + if(mParkedTextView.getBeginningPositionOfParkedText() > 0) + parkedText = text.substring(mParkedTextView.getBeginningPositionOfParkedText() - 1); + else + parkedText = text; if (!parkedText.equals(mParkedTextView.getParkedText())) { mParkedTextView.setEmptyText(); } else { From 84d42b269c976f325e11875a4a2bc20b14b067f3 Mon Sep 17 00:00:00 2001 From: Paul Austian Alday Date: Tue, 20 Jun 2017 14:44:28 +0800 Subject: [PATCH 06/12] fix bugs --- .../java/com/goka/sample/MainActivity.java | 26 ++++++++++++++++--- app/src/main/res/layout/activity_main.xml | 14 ++++++++++ .../goka/parkedtextview/ParkedTextView.java | 6 ++--- 3 files changed, 39 insertions(+), 7 deletions(-) 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 42cb7b8..7b50cbe 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -22,4 +22,18 @@ app:parkedTextColor="FFFFFF" app:parkedHintColor="CCCCCC" app:parkedTextBold="true" /> +