From 1302b45e0d85175adc081a6a10299c2773022312 Mon Sep 17 00:00:00 2001 From: devsideal Date: Wed, 22 Aug 2018 12:14:15 +0530 Subject: [PATCH] updates for the version 1.0.1 --- .idea/caches/build_file_checksums.ser | Bin 589 -> 589 bytes .idea/misc.xml | 2 +- README.md | 8 +- app/src/main/AndroidManifest.xml | 3 +- .../devs/readmoreoptiondemo/MainActivity.java | 10 +- .../devs/readmoreoptiondemo/MyAdapter.java | 6 +- app/src/main/res/layout/activity_main.xml | 14 ++- readmoreoption/build.gradle | 2 +- .../devs/readmoreoption/ReadMoreOption.java | 110 ++++++++++++++---- 9 files changed, 122 insertions(+), 33 deletions(-) diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index 99f6dafda0f9258272cfc2d5bf716e904a05516a..fb45f77135beff04684c0e7cf428cdb87c762667 100644 GIT binary patch delta 37 vcmV+=0NVe}1kD7Hmjz{DRjDqqoJ9c;_8wAz+j-x*l;`S$jcRYllkovuKL-*l delta 37 vcmV+=0NVe}1kD7Hmjz?Lx8*ajoJ9c;AY@>rKSYrhqE - + diff --git a/README.md b/README.md index 8e3c12e..c231a79 100644 --- a/README.md +++ b/README.md @@ -36,18 +36,24 @@ Convert your TextView in ExpandableTextView with added options ReadMore/ReadLess // OR using options to customize ReadMoreOption readMoreOption = new ReadMoreOption.Builder(this) - .textLength(300) + .textLength(3, ReadMoreOption.TYPE_LINE) // OR + //.textLength(300, ReadMoreOption.TYPE_CHARACTER) .moreLabel("MORE") .lessLabel("LESS") .moreLabelColor(Color.RED) .lessLabelColor(Color.BLUE) .labelUnderLine(true) + .expandAnimation(true) .build(); readMoreOption.addReadMoreTo(textView, getString(R.string.long_desc)); ``` +### Known Issue + + - [ ] expandAnimation not works with ListView/RecyclerView. + ## License ``` Copyright 2018 Deven Singh diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 1dc6ed0..9a8634e 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -24,7 +24,8 @@ android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> - + diff --git a/app/src/main/java/com/devs/readmoreoptiondemo/MainActivity.java b/app/src/main/java/com/devs/readmoreoptiondemo/MainActivity.java index 4db1b20..a1a93cb 100644 --- a/app/src/main/java/com/devs/readmoreoptiondemo/MainActivity.java +++ b/app/src/main/java/com/devs/readmoreoptiondemo/MainActivity.java @@ -16,6 +16,7 @@ package com.devs.readmoreoptiondemo; import android.graphics.Color; +import android.media.TimedText; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.support.v7.widget.DividerItemDecoration; @@ -44,14 +45,19 @@ protected void onCreate(Bundle savedInstanceState) { recyclerView.setAdapter(mAdapter); +// TextView tv = (TextView)findViewById(R.id.tv); +// tv.setText(getString(R.string.dummy_text)); +// // ReadMoreOption readMoreOption = new ReadMoreOption.Builder(this) -// // Optional parameters -// .textLength(300) +// // Optional parameters +// .textLength(3, ReadMoreOption.TYPE_LINE) //OR +// //.textLength(300, ReadMoreOption.TYPE_CHARACTER) // .moreLabel("MORE") // .lessLabel("LESS") // .moreLabelColor(Color.RED) // .lessLabelColor(Color.BLUE) // .labelUnderLine(true) +// .expandAnimation(true) // .build(); // readMoreOption.addReadMoreTo(tv, getString(R.string.dummy_text)); diff --git a/app/src/main/java/com/devs/readmoreoptiondemo/MyAdapter.java b/app/src/main/java/com/devs/readmoreoptiondemo/MyAdapter.java index 687aee6..a98c73d 100644 --- a/app/src/main/java/com/devs/readmoreoptiondemo/MyAdapter.java +++ b/app/src/main/java/com/devs/readmoreoptiondemo/MyAdapter.java @@ -44,8 +44,7 @@ static class ViewHolder extends RecyclerView.ViewHolder { } } - // Provide a suitable constructor (depends on the kind of dataset) - public MyAdapter(Context context) { + MyAdapter(Context context) { this.context = context; readMoreOption = new ReadMoreOption.Builder(context) .build(); @@ -61,11 +60,8 @@ public MyAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, return new ViewHolder(v); } - // Replace the contents of a view (invoked by the layout manager) @Override public void onBindViewHolder(ViewHolder holder, int position) { - // - get element from your dataset at this position - // - replace the contents of the view with that element readMoreOption.addReadMoreTo(holder.mTextView,context.getString(R.string.dummy_text)); } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 1d6ad5d..b061cc9 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -13,12 +13,22 @@ ~ See the License for the specific language governing permissions and ~ limitations under the License. --> - + + + + + = Build.VERSION_CODES.JELLY_BEAN && expandAnimation) { + LayoutTransition layoutTransition = new LayoutTransition(); + layoutTransition.enableTransitionType(LayoutTransition.CHANGING); + ((ViewGroup)textView.getParent()).setLayoutTransition(layoutTransition); + } + + textView.setText(ss); + textView.setMovementMethod(LinkMovementMethod.getInstance()); } - }; - ss.setSpan(clickableSpan, ss.length() - moreLabel.length(), ss.length() , Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); - textView.setText(ss) - ; - textView.setMovementMethod(LinkMovementMethod.getInstance()); + }); + + } private void addReadLess(final TextView textView, final String text ) { + textView.setMaxLines(Integer.MAX_VALUE); SpannableString ss = new SpannableString(text + " "+ lessLabel); ClickableSpan clickableSpan = new ClickableSpan() { @Override @@ -97,8 +148,7 @@ public void updateDrawState(TextPaint ds) { } }; ss.setSpan(clickableSpan, ss.length() - lessLabel.length(), ss.length() , Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); - textView.setText(ss) - ; + textView.setText(ss); textView.setMovementMethod(LinkMovementMethod.getInstance()); } @@ -107,18 +157,28 @@ public static class Builder { private Context context; // optional private int textLength = 100; + private int textLengthType = ReadMoreOption.TYPE_CHARACTER; private String moreLabel = "read more"; private String lessLabel = "read less"; private int moreLabelColor = Color.parseColor("#ff00ff"); private int lessLabelColor = Color.parseColor("#ff00ff"); private boolean labelUnderLine = false; + private boolean expandAnimation = false; public Builder(Context context){ this.context = context; } - public Builder textLength(int length){ + /** + * @param length can be no. of line OR no. of characters - default is 100 character + * @param textLengthType ReadMoreOption.TYPE_LINE for no. of line OR + * ReadMoreOption.TYPE_CHARACTER for no. of character + * - default is ReadMoreOption.TYPE_CHARACTER + * @return Builder obj + */ + public Builder textLength(int length, int textLengthType){ this.textLength = length; + this.textLengthType = textLengthType; return this; } @@ -147,6 +207,16 @@ public Builder labelUnderLine(boolean labelUnderLine){ return this; } + /** + * @param expandAnimation either true to enable animation on expand or false to disable animation + * - default is false + * @return Builder obj + */ + public Builder expandAnimation(boolean expandAnimation){ + this.expandAnimation = expandAnimation; + return this; + } + public ReadMoreOption build(){ return new ReadMoreOption(this); }