summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/AutoFitTextView.java
diff options
context:
space:
mode:
authorRajesh Yengisetty <rajesh@cyngn.com>2014-07-22 17:21:09 -0700
committerRaj Yengisetty <rajesh@cyngn.com>2015-03-06 15:37:44 -0800
commitd9324529ed3b5dcd23f10f1c147b783725deedee (patch)
tree762dee35e0e6cc1af77634997a86b492e7cd33f3 /src/com/android/launcher3/AutoFitTextView.java
parent73b5610b8c69485d91c36253428627fbcd78274d (diff)
downloadandroid_packages_apps_Trebuchet-d9324529ed3b5dcd23f10f1c147b783725deedee.tar.gz
android_packages_apps_Trebuchet-d9324529ed3b5dcd23f10f1c147b783725deedee.tar.bz2
android_packages_apps_Trebuchet-d9324529ed3b5dcd23f10f1c147b783725deedee.zip
Trebuchet: Implement new app drawer.
commit 535c5e89c7484ae96f83af021487a8061f3e0b04 Author: Adnan <adnan@cyngn.com> Date: Tue Jul 22 17:21:09 2014 -0700 Trebuchet: Implement new app drawer. Change-Id: Ibf6152352520ece4dff201b8013378a1ad562894 commit d46c52032ef20d9f97409114e6efc34650245fb6 Author: Raj Yengisetty <rajesh@cyngn.com> Date: Fri Jul 25 09:13:38 2014 -0700 Fix: With the new App Drawer implementation AppsDrawerListAdapter should clone it's AppInfo ArrayList before removing elements from it, otherwise the AppsCustomizePagedView will not add any apps to it's instance variables and will never dispaly widgets. Repro: Long press on workspace to get to overview mode Click widgets button Observe no Widgets (empty page) Change-Id: I7574ae23dbf3298674585060d5da5e00a5852d46 commit b0c7e4fad041e492816a36e538a505983d996a75 Author: Adnan <adnan@cyngn.com> Date: Tue Jul 22 19:06:15 2014 -0700 Catapult: Allow elements to be draggable out of drawer. Change-Id: I711b42bad0fc6ae14399f3eb88ec60cd443f87d1 commit 00148d42288a7ee37e8aa05cccb121e9bcf6fbda Author: Danesh M <danesh@cyngn.com> Date: Wed Jul 23 10:37:19 2014 -0700 Catapult : Make flowlayout wrap_content Change-Id: I9db6d39274b71ee2750058fd65f4917701394ac0 commit 268e707d14be0c29448b9f5aee4f26a3180c75fd Author: Adnan <adnan@cyngn.com> Date: Wed Jul 23 13:27:06 2014 -0700 Catapult: Use recyclerview for side app drawer. Change-Id: Ie6f916792375f82a8f97a0369b98b813416216e8 commit efcbdc635e34511b73939639cbcf910728b1b3b2 Author: Adnan <adnan@cyngn.com> Date: Wed Jul 23 14:30:37 2014 -0700 Catapult: Handle app install and uninstall in drawer. Change-Id: Ia22876574e96b9ff0d4b4d93a853d7e92633376c commit 3fb7c6cb0b4bb9cfaf1d11c787df14c6767a72a9 Author: Danesh M <danesh@cyngn.com> Date: Thu Jul 24 10:19:57 2014 -0700 Catapult : Improve scroll performance Change-Id: I294beb9c9e1946724108bad2c0bca8839c5bf56b commit 85828036bd4af0a242f408ba18236b11920a0120 Author: Adnan <adnan@cyngn.com> Date: Thu Jul 24 10:46:58 2014 -0700 Catapult: Use setHasFixedSize on RecyclerView. Change-Id: Id06faa37d69f2d3ef533f829d991971ea2a32012 commit 4206cc348bb8aa788b0e4a0f2080deeb55a73d38 Author: Adnan <adnan@cyngn.com> Date: Thu Jul 24 10:49:15 2014 -0700 Catapult: Show App Info and Uninstall options on drag. Change-Id: Ica307eef4d2a086733f84704d129ac893f9bbb34 commit 283db64b47a5ec395e7ec07d5e34660c98cef91d Author: Adnan <adnan@cyngn.com> Date: Thu Jul 24 15:00:37 2014 -0700 Catapult: Properly handle install, remove, and update. Change-Id: I16138503bb5d31e999f293afc00e1adc2d574727 commit ca19c304fac9de8b97c0345b0c9a7cf3c3bdf155 Author: Adnan <adnan@cyngn.com> Date: Thu Jul 24 15:27:09 2014 -0700 Catapult: Ignore index 0 when added. Change-Id: Id00a41feb1813c419fda4425327024292d51e300 commit f595d415d3b8d9775d7448f1bbc4b542ea40c7a3 Author: Adnan <adnan@cyngn.com> Date: Thu Jul 24 15:51:32 2014 -0700 Catapult: Clean up after drag. Change-Id: I858c9aa5e30bc6ca13d4ca53397b769bb6b2b86b commit c337a69e43f213cacc0fe50a0d001f4cb3a5d9f4 Author: Adnan <adnan@cyngn.com> Date: Fri Jul 25 12:46:39 2014 -0700 Catapult: Fix app updates for new data structure. - Also fix line wrapping in class. Change-Id: I3c4f33d6e3e236952ea6d73f8402f32ac059f810 commit ef6b88c44f2c6c3372136773fa01821c4fc7ba62 Author: Danesh M <danesh@cyngn.com> Date: Thu Jul 24 23:26:41 2014 -0700 Catapult : Add scrubber Change-Id: Ied2e44e2d393bc5537f77c29a4b099da1e1f2a64 commit a96939b669f8adfad7bb633aa9acfa18fe72ff1e Author: Adnan <adnan@cyngn.com> Date: Mon Jul 28 11:01:37 2014 -0700 Catapult: Fix crashes for addition of next sections in list. Change-Id: I66d8e02523595655458d0f30d75ccfbe3b65e69d commit 48dd4872ba59499e7cea950fe4b1f8e4c6774a24 Author: Adnan <adnan@cyngn.com> Date: Mon Jul 28 11:59:20 2014 -0700 Catapult: Place all special or numerics in a single category. - Also implement AutoFitTextView for character resizing. Change-Id: Ida4e702b43dc934835021cbbf3e0b41d9cea0b16 commit 40ed85a3f518dcabfbf8533f534934e029cb3835 Author: Adnan <adnan@cyngn.com> Date: Mon Jul 28 13:22:14 2014 -0700 Catapult: Disable split touch events within drawer item. Change-Id: I990717140d5b420b9a658aede317206947e9fbce commit d76583a1a4e5dd0a5792ce6d39adc427934d7db9 Author: Adnan <adnan@cyngn.com> Date: Mon Jul 28 15:53:23 2014 -0700 Catapult: Add spacer to last item in list. Change-Id: Ia3f2d7d12c09886ab24e8976549518c1bb1a9a0b commit 467e9cb6428b33fd6846be8d30bb8dcfe127acdf Author: Adnan <adnan@cyngn.com> Date: Tue Jul 29 12:39:37 2014 -0700 Catapult: Group special characters together under section. Change-Id: Ic2508eb101e1604c9e1544bdc858c7487f426a44 commit 1f566b1b5b9bac71d0d79d07084f024ba67982e1 Author: Danesh M <danesh@cyngn.com> Date: Tue Jul 29 14:25:26 2014 -0700 Catapult : Fix scrubber - Make seekbar height of entire scrubber - Cancel viewproperty animator instead of Animation - Reduce scrubber animation duration - Ignore swipe events if in scrubber area Change-Id: I3a80b5bc392105bd1d5deff1defed8c083512029 commit b54ace6ee3ecca153f4c8fd2cda35366b205106f Author: Danesh M <danesh@cyngn.com> Date: Tue Jul 29 14:29:44 2014 -0700 Catapult : Check if appdrawer is null when intercepting Change-Id: I8d1b095acc8484d2ffb3f3ffc07608a639c9a3a3 commit 7a544638641e953aa2e75e6bc3f353906887440e Author: Adnan <adnan@cyngn.com> Date: Tue Jul 29 18:23:30 2014 -0700 Catapult: Use isLetter to fix locale issues in some languages. Change-Id: I253139ab3a93a9b48d3158f790e3975f776ce666 commit 96d1198ec28e5b858aa5cda268eecdf2335c6cf2 Author: Danesh Mondegarian <danesh@cyngn.com> Date: Fri Aug 8 23:30:15 2014 -0700 Catapult : Improve scrubber 9patch Change-Id: Ide249c0fe269d2f8966c753f6fdd9c1f673a0df9 commit 4920d0fdd94f7b0df6fccc3d16f5b98cbf4d19a2 Author: Danesh M <danesh@cyngn.com> Date: Fri Aug 8 15:44:20 2014 -0700 Catapult : Improve app drawer perf Change-Id: I78f699dbeac2618dceaa463940175e33ce685677 commit 10004f024b01029b2c137520407cefb5568b8c47 Author: Raj Yengisetty <rajesh@cyngn.com> Date: Thu Feb 26 11:42:17 2015 -0800 Remove scrubber swipe logic from Workspace Change-Id: I44d94a412ccdb60ce0f537fd6ddb71c2daffc906 Change-Id: Ibf6152352520ece4dff201b8013378a1ad562894
Diffstat (limited to 'src/com/android/launcher3/AutoFitTextView.java')
-rw-r--r--src/com/android/launcher3/AutoFitTextView.java381
1 files changed, 381 insertions, 0 deletions
diff --git a/src/com/android/launcher3/AutoFitTextView.java b/src/com/android/launcher3/AutoFitTextView.java
new file mode 100644
index 000000000..208dd4073
--- /dev/null
+++ b/src/com/android/launcher3/AutoFitTextView.java
@@ -0,0 +1,381 @@
+/*
+ * Copyright (C) 2014 Grantland Chew
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.launcher3;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.content.res.TypedArray;
+import android.text.Layout;
+import android.text.StaticLayout;
+import android.text.TextPaint;
+import android.text.method.TransformationMethod;
+import android.util.AttributeSet;
+import android.util.DisplayMetrics;
+import android.util.Log;
+import android.util.TypedValue;
+import android.widget.TextView;
+
+/**
+ * A TextView that resizes it's text to be no larger than the width of the view.
+ *
+ * @author Grantland Chew <grantlandchew@gmail.com>
+ */
+public class AutoFitTextView extends TextView {
+
+ private static final String TAG = "AutoFitTextView";
+ private static final boolean SPEW = false;
+
+ // Minimum size of the text in pixels
+ private static final int DEFAULT_MIN_TEXT_SIZE = 8; //sp
+ // How precise we want to be when reaching the target textWidth size
+ private static final float PRECISION = 0.5f;
+
+ // Attributes
+ private boolean mSizeToFit;
+ private int mMaxLines;
+ private float mMinTextSize;
+ private float mMaxTextSize;
+ private float mPrecision;
+ private TextPaint mPaint;
+
+ public AutoFitTextView(Context context) {
+ super(context);
+ init(context, null, 0);
+ }
+
+ public AutoFitTextView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ init(context, attrs, 0);
+ }
+
+ public AutoFitTextView(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ init(context, attrs, defStyle);
+ }
+
+ private void init(Context context, AttributeSet attrs, int defStyle) {
+ float scaledDensity = context.getResources().getDisplayMetrics().scaledDensity;
+ boolean sizeToFit = true;
+ int minTextSize = (int) scaledDensity * DEFAULT_MIN_TEXT_SIZE;
+ float precision = PRECISION;
+
+ if (attrs != null) {
+ TypedArray ta = context.obtainStyledAttributes(
+ attrs,
+ R.styleable.AutofitTextView,
+ defStyle,
+ 0);
+ sizeToFit = ta.getBoolean(R.styleable.AutofitTextView_sizeToFit, sizeToFit);
+ minTextSize = ta.getDimensionPixelSize(R.styleable.AutofitTextView_minTextSize,
+ minTextSize);
+ precision = ta.getFloat(R.styleable.AutofitTextView_precision, precision);
+ ta.recycle();
+ }
+
+ mPaint = new TextPaint();
+ setSizeToFit(sizeToFit);
+ setRawTextSize(super.getTextSize());
+ setRawMinTextSize(minTextSize);
+ setPrecision(precision);
+ }
+
+ // Getters and Setters
+
+ /**
+ * @return whether or not the text will be automatically resized to fit its constraints.
+ */
+ public boolean isSizeToFit() {
+ return mSizeToFit;
+ }
+
+ /**
+ * Sets the property of this field (singleLine, to automatically resize the text to fit its constraints.
+ */
+ public void setSizeToFit() {
+ setSizeToFit(true);
+ }
+
+ /**
+ * If true, the text will automatically be resized to fit its constraints; if false, it will
+ * act like a normal TextView.
+ *
+ * @param sizeToFit
+ */
+ public void setSizeToFit(boolean sizeToFit) {
+ mSizeToFit = sizeToFit;
+ refitText();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public float getTextSize() {
+ return mMaxTextSize;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setTextSize(int unit, float size) {
+ Context context = getContext();
+ Resources r = Resources.getSystem();
+
+ if (context != null) {
+ r = context.getResources();
+ }
+
+ setRawTextSize(TypedValue.applyDimension(unit, size, r.getDisplayMetrics()));
+ }
+
+ private void setRawTextSize(float size) {
+ if (size != mMaxTextSize) {
+ mMaxTextSize = size;
+ refitText();
+ }
+ }
+
+ /**
+ * @return the minimum size (in pixels) of the text size in this AutofitTextView
+ */
+ public float getMinTextSize() {
+ return mMinTextSize;
+ }
+
+ /**
+ * Set the minimum text size to a given unit and value. See TypedValue for the possible
+ * dimension units.
+ *
+ * @param unit The desired dimension unit.
+ * @param minSize The desired size in the given units.
+ *
+ * @attr ref me.grantland.R.styleable#AutofitTextView_minTextSize
+ */
+ public void setMinTextSize(int unit, float minSize) {
+ Context context = getContext();
+ Resources r = Resources.getSystem();
+
+ if (context != null) {
+ r = context.getResources();
+ }
+
+ setRawMinTextSize(TypedValue.applyDimension(unit, minSize, r.getDisplayMetrics()));
+ }
+
+ /**
+ * Set the minimum text size to the given value, interpreted as "scaled pixel" units. This size
+ * is adjusted based on the current density and user font size preference.
+ *
+ * @param minSize The scaled pixel size.
+ *
+ * @attr ref me.grantland.R.styleable#AutofitTextView_minTextSize
+ */
+ public void setMinTextSize(int minSize) {
+ setMinTextSize(TypedValue.COMPLEX_UNIT_SP, minSize);
+ }
+
+ private void setRawMinTextSize(float minSize) {
+ if (minSize != mMinTextSize) {
+ mMinTextSize = minSize;
+ refitText();
+ }
+ }
+
+ /**
+ * @return the amount of precision used to calculate the correct text size to fit within it's
+ * bounds.
+ */
+ public float getPrecision() {
+ return mPrecision;
+ }
+
+ /**
+ * Set the amount of precision used to calculate the correct text size to fit within it's
+ * bounds. Lower precision is more precise and takes more time.
+ *
+ * @param precision The amount of precision.
+ */
+ public void setPrecision(float precision) {
+ if (precision != mPrecision) {
+ mPrecision = precision;
+ refitText();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setLines(int lines) {
+ super.setLines(lines);
+ mMaxLines = lines;
+ refitText();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int getMaxLines() {
+ return mMaxLines;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setMaxLines(int maxLines) {
+ super.setMaxLines(maxLines);
+ if (maxLines != mMaxLines) {
+ mMaxLines = maxLines;
+ refitText();
+ }
+ }
+
+ /**
+ * Re size the font so the specified text fits in the text box assuming the text box is the
+ * specified width.
+ */
+ private void refitText() {
+ if (!mSizeToFit) {
+ return;
+ }
+
+ if (mMaxLines <= 0) {
+ // Don't auto-size since there's no limit on lines.
+ return;
+ }
+
+ CharSequence text = getText();
+ TransformationMethod method = getTransformationMethod();
+ if (method != null) {
+ text = method.getTransformation(text, this);
+ }
+ int targetWidth = getWidth() - getPaddingLeft() - getPaddingRight();
+ if (targetWidth > 0) {
+ Context context = getContext();
+ Resources r = Resources.getSystem();
+ DisplayMetrics displayMetrics;
+
+ float size = mMaxTextSize;
+ float high = size;
+ float low = 0;
+
+ if (context != null) {
+ r = context.getResources();
+ }
+ displayMetrics = r.getDisplayMetrics();
+
+ mPaint.set(getPaint());
+ mPaint.setTextSize(size);
+
+ if ((mMaxLines == 1 && mPaint.measureText(text, 0, text.length()) > targetWidth)
+ || getLineCount(text, mPaint, size, targetWidth, displayMetrics) > mMaxLines) {
+ size = getTextSize(text, mPaint, targetWidth, mMaxLines, low, high, mPrecision,
+ displayMetrics);
+ }
+
+ if (size < mMinTextSize) {
+ size = mMinTextSize;
+ }
+
+ super.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
+ }
+ }
+
+ /**
+ * Recursive binary search to find the best size for the text
+ */
+ private static float getTextSize(CharSequence text, TextPaint paint,
+ float targetWidth, int maxLines,
+ float low, float high, float precision,
+ DisplayMetrics displayMetrics) {
+ float mid = (low + high) / 2.0f;
+ int lineCount = 1;
+ StaticLayout layout = null;
+
+ paint.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, mid,
+ displayMetrics));
+
+ if (maxLines != 1) {
+ layout = new StaticLayout(text, paint, (int)targetWidth, Layout.Alignment.ALIGN_NORMAL,
+ 1.0f, 0.0f, true);
+ lineCount = layout.getLineCount();
+ }
+
+ if (SPEW) Log.d(TAG, "low=" + low + " high=" + high + " mid=" + mid +
+ " target=" + targetWidth + " maxLines=" + maxLines + " lineCount=" + lineCount);
+
+ if (lineCount > maxLines) {
+ return getTextSize(text, paint, targetWidth, maxLines, low, mid, precision,
+ displayMetrics);
+ }
+ else if (lineCount < maxLines) {
+ return getTextSize(text, paint, targetWidth, maxLines, mid, high, precision,
+ displayMetrics);
+ }
+ else {
+ float maxLineWidth = 0;
+ if (maxLines == 1) {
+ maxLineWidth = paint.measureText(text, 0, text.length());
+ } else {
+ for (int i = 0; i < lineCount; i++) {
+ if (layout.getLineWidth(i) > maxLineWidth) {
+ maxLineWidth = layout.getLineWidth(i);
+ }
+ }
+ }
+
+ if ((high - low) < precision) {
+ return low;
+ } else if (maxLineWidth > targetWidth) {
+ return getTextSize(text, paint, targetWidth, maxLines, low, mid, precision,
+ displayMetrics);
+ } else if (maxLineWidth < targetWidth) {
+ return getTextSize(text, paint, targetWidth, maxLines, mid, high, precision,
+ displayMetrics);
+ } else {
+ return mid;
+ }
+ }
+ }
+
+ private static int getLineCount(CharSequence text, TextPaint paint, float size, float width,
+ DisplayMetrics displayMetrics) {
+ paint.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, size,
+ displayMetrics));
+ StaticLayout layout = new StaticLayout(text, paint, (int)width,
+ Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, true);
+ return layout.getLineCount();
+ }
+
+ @Override
+ protected void onTextChanged(final CharSequence text, final int start,
+ final int lengthBefore, final int lengthAfter) {
+ super.onTextChanged(text, start, lengthBefore, lengthAfter);
+ refitText();
+ }
+
+ @Override
+ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
+ super.onSizeChanged(w, h, oldw, oldh);
+ if (w != oldw) {
+ refitText();
+ }
+ }
+} \ No newline at end of file