├── .gitignore ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── aykuttasil │ │ └── percentbarapp │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── aykuttasil │ │ │ └── percentbarapp │ │ │ ├── MainActivity.java │ │ │ └── util │ │ │ └── AutoFitTextView.java │ └── res │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── aykuttasil │ └── percentbarapp │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle ├── bintray-android-v1.gradle ├── bintray-java-v1.gradle ├── install-v1.gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── percentbar ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── aykuttasil │ │ └── percentbar │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── aykuttasil │ │ │ └── percentbar │ │ │ ├── PercentBarView.java │ │ │ ├── models │ │ │ └── BarImageModel.java │ │ │ └── util │ │ │ ├── PicassoCircleTransform.java │ │ │ └── adapter │ │ │ └── MaterialListAdapter.java │ └── res │ │ ├── drawable │ │ └── ic_add_circle_indigo_300_48dp.png │ │ └── values │ │ ├── attrs.xml │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── aykuttasil │ └── percentbar │ └── ExampleUnitTest.java └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # files for the dex VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # generated files 12 | bin/ 13 | gen/ 14 | build/ 15 | 16 | # Local configuration file (sdk path, etc) 17 | local.properties 18 | 19 | # Eclipse project files 20 | .classpath 21 | .project 22 | 23 | # Android Studio 24 | .idea/ 25 | .gradle 26 | /*/local.properties 27 | /*/out 28 | /*/*/build 29 | /*/build 30 | /*/*/production 31 | *.iml 32 | *.iws 33 | *.ipr 34 | *~ 35 | *.swp 36 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-PercentBarView-green.svg?style=true)](https://android-arsenal.com/details/1/4373) 2 | 3 | # PercentBar 4 | 5 | Show result in Percent Bar with animation. 6 | 7 | # How to Use 8 | 9 | ``` 10 | List mList = new ArrayList<>(); 11 | mList.add(new BarImageModel("https://s-media-cache-ak0.pinimg.com/564x/2b/74/04/2b74046c2e2e488fe1f2be60680671dd.jpg", "Abc", PercentBarView.BarField.LEFT)); 12 | mList.add(new BarImageModel("https://s-media-cache-ak0.pinimg.com/564x/65/01/b5/6501b5ae42a0c1aa863b1ae33a746ce2.jpg", "Def", PercentBarView.BarField.RIGHT)); 13 | mList.add(new BarImageModel("https://s-media-cache-ak0.pinimg.com/564x/5a/e9/50/5ae9501fc3b49810db7901873f77d6f7.jpg", "Lorem", PercentBarView.BarField.RIGHT)); 14 | mList.add(new BarImageModel("https://s-media-cache-ak0.pinimg.com/564x/9d/1c/86/9d1c861252a4d0067def3f567467b175.jpg", "Qwerty", PercentBarView.BarField.LEFT)); 15 | mList.add(new BarImageModel("https://s-media-cache-ak0.pinimg.com/564x/5e/bd/17/5ebd1769bf115773ad83803b29ea4bac.jpg", "WWW", PercentBarView.BarField.LEFT)); 16 | mList.add(new BarImageModel("https://s-media-cache-ak0.pinimg.com/564x/67/51/c3/6751c3d814fdda7db7e4844c3007db7c.jpg", "Aykut", PercentBarView.BarField.LEFT)); 17 | 18 | View alphaView = findViewById(R.id.ImageViewSoruImage); 19 | percentBarView = (PercentBarView) findViewById(R.id.PercentBarView); 20 | percentBarView.addAlphaView(alphaView); 21 | percentBarView.setRightBarValue(70); 22 | percentBarView.setLeftBarValue(30); 23 | percentBarView.setImages(mList); 24 | percentBarView.setImagesListTitle("X List"); 25 | percentBarView.setRightBarColor(Color.MAGENTA); 26 | ``` 27 | 28 | **and** 29 | 30 | ``` 31 | 34 | 35 | 44 | 45 | 53 | 54 | 55 | ``` 56 | 57 | **All Feature** 58 | 59 | ``` 60 | View alphaView = findViewById(R.id.ImageViewSoruImage); 61 | PercentBarView percentBarView = (PercentBarView) findViewById(R.id.PercentBarView); 62 | 63 | percentBarView.setRightBarValue(70); 64 | percentBarView.setLeftBarValue(1); 65 | 66 | percentBarView.setImages(mList); 67 | percentBarView.setImagesListTitle("X List"); 68 | percentBarView.setImageListItemSize(50) 69 | 70 | percentBarView.setLeftBarColor(Color.GREEN); 71 | percentBarView.setRightBarColor(Color.MAGENTA); 72 | 73 | percentBarView.addAlphaView(alphaView); 74 | percentBarView.setAlphaViewValue(0.5f); // alpha value 75 | percentBarView.setAnimAlphaViewDuration(3000); 76 | percentBarView.setAnimBarDuration(2000); 77 | 78 | percentBarView.setLeftBarWidth(60); 79 | percentBarView.setRightBarWidth(40); 80 | 81 | percentBarView.setAutoShow(true); // show bar when start app 82 | ``` 83 | 84 | 85 | 86 |

87 | 88 |

89 | 90 | 93 | 94 | 95 | # Installation 96 | 97 | Gradle 98 | 99 | Add it as a dependency in your app's build.gradle file 100 | ``` 101 | compile 'com.aykuttasil:percentbar:3.0.3' 102 | ``` 103 | 104 | 105 | # License 106 | 107 | ``` 108 | Copyright 2016 aykuttasil - Aykut Asil 109 | 110 | Licensed under the Apache License, Version 2.0 (the "License"); 111 | you may not use this file except in compliance with the License. 112 | You may obtain a copy of the License at 113 | 114 | http://www.apache.org/licenses/LICENSE-2.0 115 | 116 | Unless required by applicable law or agreed to in writing, software 117 | distributed under the License is distributed on an "AS IS" BASIS, 118 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 119 | See the License for the specific language governing permissions and 120 | limitations under the License. 121 | ``` 122 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion project.sdk 5 | buildToolsVersion project.buildTools 6 | 7 | defaultConfig { 8 | applicationId "com.aykuttasil.percentbarapp" 9 | minSdkVersion project.minSdk 10 | targetSdkVersion project.sdk 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(include: ['*.jar'], dir: 'libs') 24 | testCompile 'junit:junit:4.12' 25 | compile "com.android.support:appcompat-v7:$project.supportVersion" 26 | compile "com.android.support:cardview-v7:$project.supportVersion" 27 | compile "com.google.android:flexbox:0.2.1" 28 | compile project(':percentbar') 29 | } 30 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/aykutasil/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/aykuttasil/percentbarapp/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.aykuttasil.percentbarapp; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /app/src/main/java/com/aykuttasil/percentbarapp/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.aykuttasil.percentbarapp; 2 | 3 | import android.graphics.Color; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.view.View; 7 | 8 | import com.aykuttasil.percentbar.PercentBarView; 9 | import com.aykuttasil.percentbar.models.BarImageModel; 10 | 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | 14 | public class MainActivity extends AppCompatActivity { 15 | 16 | 17 | PercentBarView percentBarView; 18 | PercentBarView percentBarView1; 19 | PercentBarView percentBarView2; 20 | 21 | @Override 22 | protected void onCreate(Bundle savedInstanceState) { 23 | super.onCreate(savedInstanceState); 24 | setContentView(R.layout.activity_main); 25 | 26 | List mList = new ArrayList<>(); 27 | mList.add(new BarImageModel("https://s-media-cache-ak0.pinimg.com/564x/2b/74/04/2b74046c2e2e488fe1f2be60680671dd.jpg", "Abc", PercentBarView.BarField.LEFT)); 28 | mList.add(new BarImageModel("https://s-media-cache-ak0.pinimg.com/564x/65/01/b5/6501b5ae42a0c1aa863b1ae33a746ce2.jpg", "Def", PercentBarView.BarField.RIGHT)); 29 | mList.add(new BarImageModel("https://s-media-cache-ak0.pinimg.com/564x/5a/e9/50/5ae9501fc3b49810db7901873f77d6f7.jpg", "Lorem", PercentBarView.BarField.RIGHT)); 30 | mList.add(new BarImageModel("https://s-media-cache-ak0.pinimg.com/564x/9d/1c/86/9d1c861252a4d0067def3f567467b175.jpg", "Qwerty", PercentBarView.BarField.LEFT)); 31 | mList.add(new BarImageModel("https://s-media-cache-ak0.pinimg.com/564x/5e/bd/17/5ebd1769bf115773ad83803b29ea4bac.jpg", "WWW", PercentBarView.BarField.LEFT)); 32 | mList.add(new BarImageModel("https://s-media-cache-ak0.pinimg.com/564x/67/51/c3/6751c3d814fdda7db7e4844c3007db7c.jpg", "Aykut", PercentBarView.BarField.LEFT)); 33 | mList.add(new BarImageModel("https://pbs.twimg.com/profile_images/2658478840/b923df35a917b4acdce24d0e03c1a61a_400x400.png", "text 2", PercentBarView.BarField.RIGHT)); 34 | mList.add(new BarImageModel("https://yt3.ggpht.com/-wh6msZtAzCU/AAAAAAAAAAI/AAAAAAAAAAA/ERwt1WSIOUA/s900-c-k-no-rj-c0xffffff/photo.jpg", "text 3", PercentBarView.BarField.RIGHT)); 35 | mList.add(new BarImageModel("https://pbs.twimg.com/profile_images/2658478840/b923df35a917b4acdce24d0e03c1a61a_400x400.png", "text 4", PercentBarView.BarField.RIGHT)); 36 | mList.add(new BarImageModel("https://yt3.ggpht.com/-wh6msZtAzCU/AAAAAAAAAAI/AAAAAAAAAAA/ERwt1WSIOUA/s900-c-k-no-rj-c0xffffff/photo.jpg", "text 5", PercentBarView.BarField.LEFT)); 37 | mList.add(new BarImageModel("https://pbs.twimg.com/profile_images/2658478840/b923df35a917b4acdce24d0e03c1a61a_400x400.png", "text 6", PercentBarView.BarField.LEFT)); 38 | mList.add(new BarImageModel("https://yt3.ggpht.com/-wh6msZtAzCU/AAAAAAAAAAI/AAAAAAAAAAA/ERwt1WSIOUA/s900-c-k-no-rj-c0xffffff/photo.jpg", "text 7", PercentBarView.BarField.LEFT)); 39 | mList.add(new BarImageModel("https://pbs.twimg.com/profile_images/2658478840/b923df35a917b4acdce24d0e03c1a61a_400x400.png", "text 8", PercentBarView.BarField.LEFT)); 40 | 41 | View alphaView = findViewById(R.id.ImageViewSoruImage); 42 | percentBarView = (PercentBarView) findViewById(R.id.PercentBarView); 43 | percentBarView.addAlphaView(alphaView); 44 | percentBarView.setRightBarValue(70); 45 | percentBarView.setLeftBarValue(30); 46 | percentBarView.setImages(mList); 47 | percentBarView.setImagesListTitle("X List"); 48 | percentBarView.setRightBarColor(Color.MAGENTA); 49 | 50 | 51 | View alphaView1 = findViewById(R.id.ImageViewSoruImage1); 52 | percentBarView1 = (PercentBarView) findViewById(R.id.PercentBarView1); 53 | percentBarView1.addAlphaView(alphaView1); 54 | percentBarView1.setRightBarValue(30); 55 | percentBarView1.setLeftBarValue(80); 56 | percentBarView1.setImages(mList); 57 | percentBarView1.setImagesListTitle("Y List"); 58 | percentBarView1.setImagesListItemSize(50); 59 | percentBarView1.setRightBarWidth(70); 60 | percentBarView1.setRightBarColor(Color.BLACK); 61 | 62 | 63 | View alphaView2 = findViewById(R.id.ImageViewSoruImage2); 64 | percentBarView2 = (PercentBarView) findViewById(R.id.PercentBarView2); 65 | percentBarView2.addAlphaView(alphaView2); 66 | percentBarView2.setRightBarValue(25); 67 | percentBarView2.setLeftBarValue(42); 68 | percentBarView2.setImages(mList); 69 | percentBarView2.setImagesListTitle("Z List"); 70 | percentBarView2.setLeftBarColor(Color.GRAY); 71 | 72 | } 73 | 74 | public void ButtonShowClick(View view) { 75 | percentBarView.showResult(); 76 | percentBarView1.showResult(); 77 | percentBarView2.showResult(); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /app/src/main/java/com/aykuttasil/percentbarapp/util/AutoFitTextView.java: -------------------------------------------------------------------------------- 1 | package com.aykuttasil.percentbarapp.util; 2 | 3 | import android.annotation.TargetApi; 4 | import android.content.Context; 5 | import android.content.res.Resources; 6 | import android.graphics.RectF; 7 | import android.graphics.Typeface; 8 | import android.os.Build; 9 | import android.support.v7.widget.AppCompatTextView; 10 | import android.text.Layout; 11 | import android.text.StaticLayout; 12 | import android.text.TextPaint; 13 | import android.text.method.TransformationMethod; 14 | import android.util.AttributeSet; 15 | import android.util.TypedValue; 16 | 17 | /** 18 | * Created by aykutasil on 21.06.2016. 19 | */ 20 | public class AutoFitTextView extends AppCompatTextView { 21 | private static final int NO_LINE_LIMIT = -1; 22 | private final RectF _availableSpaceRect = new RectF(); 23 | private final SizeTester _sizeTester; 24 | private float _maxTextSize, _spacingMult = 1.0f, _spacingAdd = 0.0f, _minTextSize; 25 | private int _widthLimit, _maxLines; 26 | private boolean _initialized = false; 27 | private TextPaint _paint; 28 | 29 | private interface SizeTester { 30 | /** 31 | * @param suggestedSize Size of text to be tested 32 | * @param availableSpace available space in which text must fit 33 | * @return an integer < 0 if after applying {@code suggestedSize} to 34 | * text, it takes less space than {@code availableSpace}, > 0 35 | * otherwise 36 | */ 37 | int onTestSize(int suggestedSize, RectF availableSpace); 38 | } 39 | 40 | public AutoFitTextView(final Context context) { 41 | this(context, null, android.R.attr.textViewStyle); 42 | } 43 | 44 | public AutoFitTextView(final Context context, final AttributeSet attrs) { 45 | this(context, attrs, android.R.attr.textViewStyle); 46 | } 47 | 48 | public AutoFitTextView(final Context context, final AttributeSet attrs, final int defStyle) { 49 | super(context, attrs, defStyle); 50 | // using the minimal recommended font size 51 | _minTextSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 12, getResources().getDisplayMetrics()); 52 | _maxTextSize = getTextSize(); 53 | _paint = new TextPaint(getPaint()); 54 | if (_maxLines == 0) 55 | // no value was assigned during construction 56 | _maxLines = NO_LINE_LIMIT; 57 | // prepare size tester: 58 | _sizeTester = new SizeTester() { 59 | final RectF textRect = new RectF(); 60 | 61 | @TargetApi(Build.VERSION_CODES.JELLY_BEAN) 62 | @Override 63 | public int onTestSize(final int suggestedSize, final RectF availableSpace) { 64 | _paint.setTextSize(suggestedSize); 65 | final TransformationMethod transformationMethod = getTransformationMethod(); 66 | final String text; 67 | if (transformationMethod != null) 68 | text = transformationMethod.getTransformation(getText(), AutoFitTextView.this).toString(); 69 | else 70 | text = getText().toString(); 71 | final boolean singleLine = getMaxLines() == 1; 72 | if (singleLine) { 73 | textRect.bottom = _paint.getFontSpacing(); 74 | textRect.right = _paint.measureText(text); 75 | } else { 76 | final StaticLayout layout = new StaticLayout(text, _paint, _widthLimit, Layout.Alignment.ALIGN_NORMAL, _spacingMult, _spacingAdd, true); 77 | // return early if we have more lines 78 | if (getMaxLines() != NO_LINE_LIMIT && layout.getLineCount() > getMaxLines()) 79 | return 1; 80 | textRect.bottom = layout.getHeight(); 81 | int maxWidth = -1; 82 | for (int i = 0; i < layout.getLineCount(); i++) 83 | if (maxWidth < layout.getLineRight(i) - layout.getLineLeft(i)) 84 | maxWidth = (int) layout.getLineRight(i) - (int) layout.getLineLeft(i); 85 | textRect.right = maxWidth; 86 | } 87 | textRect.offsetTo(0, 0); 88 | if (availableSpace.contains(textRect)) 89 | // may be too small, don't worry we will find the best match 90 | return -1; 91 | // else, too big 92 | return 1; 93 | } 94 | }; 95 | _initialized = true; 96 | } 97 | 98 | @Override 99 | public void setAllCaps(boolean allCaps) { 100 | super.setAllCaps(allCaps); 101 | adjustTextSize(); 102 | } 103 | 104 | @Override 105 | public void setTypeface(final Typeface tf) { 106 | super.setTypeface(tf); 107 | adjustTextSize(); 108 | } 109 | 110 | @Override 111 | public void setTextSize(final float size) { 112 | _maxTextSize = size; 113 | adjustTextSize(); 114 | } 115 | 116 | @Override 117 | public void setMaxLines(final int maxLines) { 118 | super.setMaxLines(maxLines); 119 | _maxLines = maxLines; 120 | adjustTextSize(); 121 | } 122 | 123 | @Override 124 | public int getMaxLines() { 125 | return _maxLines; 126 | } 127 | 128 | @Override 129 | public void setSingleLine() { 130 | super.setSingleLine(); 131 | _maxLines = 1; 132 | adjustTextSize(); 133 | } 134 | 135 | @Override 136 | public void setSingleLine(final boolean singleLine) { 137 | super.setSingleLine(singleLine); 138 | if (singleLine) 139 | _maxLines = 1; 140 | else _maxLines = NO_LINE_LIMIT; 141 | adjustTextSize(); 142 | } 143 | 144 | @Override 145 | public void setLines(final int lines) { 146 | super.setLines(lines); 147 | _maxLines = lines; 148 | adjustTextSize(); 149 | } 150 | 151 | @Override 152 | public void setTextSize(final int unit, final float size) { 153 | final Context c = getContext(); 154 | Resources r; 155 | if (c == null) 156 | r = Resources.getSystem(); 157 | else r = c.getResources(); 158 | _maxTextSize = TypedValue.applyDimension(unit, size, r.getDisplayMetrics()); 159 | adjustTextSize(); 160 | } 161 | 162 | @Override 163 | public void setLineSpacing(final float add, final float mult) { 164 | super.setLineSpacing(add, mult); 165 | _spacingMult = mult; 166 | _spacingAdd = add; 167 | } 168 | 169 | /** 170 | * Set the lower text size limit and invalidate the view 171 | * 172 | * @param minTextSize 173 | */ 174 | public void setMinTextSize(final float minTextSize) { 175 | _minTextSize = minTextSize; 176 | adjustTextSize(); 177 | } 178 | 179 | private void adjustTextSize() { 180 | // This is a workaround for truncated text issue on ListView, as shown here: https://github.com/AndroidDeveloperLB/AutoFitTextView/pull/14 181 | // TODO think of a nicer, elegant solution. 182 | // post(new Runnable() 183 | // { 184 | // @Override 185 | // public void run() 186 | // { 187 | if (!_initialized) 188 | return; 189 | final int startSize = (int) _minTextSize; 190 | final int heightLimit = getMeasuredHeight() - getCompoundPaddingBottom() - getCompoundPaddingTop(); 191 | _widthLimit = getMeasuredWidth() - getCompoundPaddingLeft() - getCompoundPaddingRight(); 192 | if (_widthLimit <= 0) 193 | return; 194 | _paint = new TextPaint(getPaint()); 195 | _availableSpaceRect.right = _widthLimit; 196 | _availableSpaceRect.bottom = heightLimit; 197 | superSetTextSize(startSize); 198 | // } 199 | // }); 200 | } 201 | 202 | private void superSetTextSize(int startSize) { 203 | int textSize = binarySearch(startSize, (int) _maxTextSize, _sizeTester, _availableSpaceRect); 204 | super.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); 205 | } 206 | 207 | private int binarySearch(final int start, final int end, final SizeTester sizeTester, final RectF availableSpace) { 208 | int lastBest = start, lo = start, hi = end - 1, mid; 209 | while (lo <= hi) { 210 | mid = lo + hi >>> 1; 211 | final int midValCmp = sizeTester.onTestSize(mid, availableSpace); 212 | if (midValCmp < 0) { 213 | lastBest = lo; 214 | lo = mid + 1; 215 | } else if (midValCmp > 0) { 216 | hi = mid - 1; 217 | lastBest = hi; 218 | } else return mid; 219 | } 220 | // make sure to return last best 221 | // this is what should always be returned 222 | return lastBest; 223 | } 224 | 225 | @Override 226 | protected void onTextChanged(final CharSequence text, final int start, final int before, final int after) { 227 | super.onTextChanged(text, start, before, after); 228 | adjustTextSize(); 229 | } 230 | 231 | @Override 232 | protected void onSizeChanged(final int width, final int height, final int oldwidth, final int oldheight) { 233 | super.onSizeChanged(width, height, oldwidth, oldheight); 234 | if (width != oldwidth || height != oldheight) 235 | adjustTextSize(); 236 | } 237 | } 238 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | 18 | 19 | 28 | 29 | 30 | 33 | 34 | 40 | 41 | 44 | 45 | 56 | 57 | 58 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 80 | 81 | 90 | 91 | 92 | 95 | 96 | 102 | 103 | 106 | 107 | 118 | 119 | 120 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 142 | 143 | 152 | 153 | 154 | 157 | 158 | 164 | 165 | 168 | 169 | 180 | 181 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 |