├── LICENSE
├── README.md
├── SizeAdjustingTextView.java
├── SizeAdjustingTextViewAndroidStudios
├── .gitignore
├── app
│ ├── .gitignore
│ ├── build.gradle
│ ├── proguard-rules.txt
│ └── src
│ │ └── main
│ │ ├── AndroidManifest.xml
│ │ ├── java
│ │ └── com
│ │ │ └── elliott
│ │ │ └── chenger
│ │ │ └── autosizingtextexampleproject
│ │ │ ├── app
│ │ │ └── MainActivity.java
│ │ │ └── utils
│ │ │ └── TextMover.java
│ │ └── res
│ │ ├── drawable-hdpi
│ │ └── ic_launcher.png
│ │ ├── drawable-mdpi
│ │ └── ic_launcher.png
│ │ ├── drawable-xhdpi
│ │ └── ic_launcher.png
│ │ ├── drawable-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── menu
│ │ └── main.xml
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
├── build.gradle
├── gradle.properties
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── settings.gradle
└── sizeadjustingtextview
│ ├── .gitignore
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── omitneedlesscode
│ │ └── sizeadjustingtextview
│ │ └── ApplicationTest.java
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── omitneedlesscode
│ │ └── sizeadjustingtextview
│ │ └── SizeAdjustingTextView.java
│ └── res
│ └── values
│ └── strings.xml
└── SizeAdjustingTextViewEclipse
├── .classpath
├── .gitignore
├── .project
├── AndroidManifest.xml
├── ic_launcher-web.png
├── libs
└── android-support-v4.jar
├── proguard-project.txt
├── project.properties
├── res
├── drawable-hdpi
│ └── ic_launcher.png
├── drawable-mdpi
│ └── ic_launcher.png
├── drawable-xhdpi
│ └── ic_launcher.png
├── drawable-xxhdpi
│ └── ic_launcher.png
├── layout
│ └── activity_main.xml
├── menu
│ └── main.xml
├── values-sw600dp
│ └── dimens.xml
├── values-sw720dp-land
│ └── dimens.xml
├── values-v11
│ └── styles.xml
├── values-v14
│ └── styles.xml
└── values
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
└── src
└── com
└── elliott
└── chenger
└── sizeadjustingtextview
├── MainActivity.java
├── utils
└── TextMover.java
└── view
└── SizeAdjustingTextView.java
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | Preamble
10 |
11 | The licenses for most software are designed to take away your
12 | freedom to share and change it. By contrast, the GNU General Public
13 | License is intended to guarantee your freedom to share and change free
14 | software--to make sure the software is free for all its users. This
15 | General Public License applies to most of the Free Software
16 | Foundation's software and to any other program whose authors commit to
17 | using it. (Some other Free Software Foundation software is covered by
18 | the GNU Lesser General Public License instead.) You can apply it to
19 | your programs, too.
20 |
21 | When we speak of free software, we are referring to freedom, not
22 | price. Our General Public Licenses are designed to make sure that you
23 | have the freedom to distribute copies of free software (and charge for
24 | this service if you wish), that you receive source code or can get it
25 | if you want it, that you can change the software or use pieces of it
26 | in new free programs; and that you know you can do these things.
27 |
28 | To protect your rights, we need to make restrictions that forbid
29 | anyone to deny you these rights or to ask you to surrender the rights.
30 | These restrictions translate to certain responsibilities for you if you
31 | distribute copies of the software, or if you modify it.
32 |
33 | For example, if you distribute copies of such a program, whether
34 | gratis or for a fee, you must give the recipients all the rights that
35 | you have. You must make sure that they, too, receive or can get the
36 | source code. And you must show them these terms so they know their
37 | rights.
38 |
39 | We protect your rights with two steps: (1) copyright the software, and
40 | (2) offer you this license which gives you legal permission to copy,
41 | distribute and/or modify the software.
42 |
43 | Also, for each author's protection and ours, we want to make certain
44 | that everyone understands that there is no warranty for this free
45 | software. If the software is modified by someone else and passed on, we
46 | want its recipients to know that what they have is not the original, so
47 | that any problems introduced by others will not reflect on the original
48 | authors' reputations.
49 |
50 | Finally, any free program is threatened constantly by software
51 | patents. We wish to avoid the danger that redistributors of a free
52 | program will individually obtain patent licenses, in effect making the
53 | program proprietary. To prevent this, we have made it clear that any
54 | patent must be licensed for everyone's free use or not licensed at all.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | GNU GENERAL PUBLIC LICENSE
60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61 |
62 | 0. This License applies to any program or other work which contains
63 | a notice placed by the copyright holder saying it may be distributed
64 | under the terms of this General Public License. The "Program", below,
65 | refers to any such program or work, and a "work based on the Program"
66 | means either the Program or any derivative work under copyright law:
67 | that is to say, a work containing the Program or a portion of it,
68 | either verbatim or with modifications and/or translated into another
69 | language. (Hereinafter, translation is included without limitation in
70 | the term "modification".) Each licensee is addressed as "you".
71 |
72 | Activities other than copying, distribution and modification are not
73 | covered by this License; they are outside its scope. The act of
74 | running the Program is not restricted, and the output from the Program
75 | is covered only if its contents constitute a work based on the
76 | Program (independent of having been made by running the Program).
77 | Whether that is true depends on what the Program does.
78 |
79 | 1. You may copy and distribute verbatim copies of the Program's
80 | source code as you receive it, in any medium, provided that you
81 | conspicuously and appropriately publish on each copy an appropriate
82 | copyright notice and disclaimer of warranty; keep intact all the
83 | notices that refer to this License and to the absence of any warranty;
84 | and give any other recipients of the Program a copy of this License
85 | along with the Program.
86 |
87 | You may charge a fee for the physical act of transferring a copy, and
88 | you may at your option offer warranty protection in exchange for a fee.
89 |
90 | 2. You may modify your copy or copies of the Program or any portion
91 | of it, thus forming a work based on the Program, and copy and
92 | distribute such modifications or work under the terms of Section 1
93 | above, provided that you also meet all of these conditions:
94 |
95 | a) You must cause the modified files to carry prominent notices
96 | stating that you changed the files and the date of any change.
97 |
98 | b) You must cause any work that you distribute or publish, that in
99 | whole or in part contains or is derived from the Program or any
100 | part thereof, to be licensed as a whole at no charge to all third
101 | parties under the terms of this License.
102 |
103 | c) If the modified program normally reads commands interactively
104 | when run, you must cause it, when started running for such
105 | interactive use in the most ordinary way, to print or display an
106 | announcement including an appropriate copyright notice and a
107 | notice that there is no warranty (or else, saying that you provide
108 | a warranty) and that users may redistribute the program under
109 | these conditions, and telling the user how to view a copy of this
110 | License. (Exception: if the Program itself is interactive but
111 | does not normally print such an announcement, your work based on
112 | the Program is not required to print an announcement.)
113 |
114 | These requirements apply to the modified work as a whole. If
115 | identifiable sections of that work are not derived from the Program,
116 | and can be reasonably considered independent and separate works in
117 | themselves, then this License, and its terms, do not apply to those
118 | sections when you distribute them as separate works. But when you
119 | distribute the same sections as part of a whole which is a work based
120 | on the Program, the distribution of the whole must be on the terms of
121 | this License, whose permissions for other licensees extend to the
122 | entire whole, and thus to each and every part regardless of who wrote it.
123 |
124 | Thus, it is not the intent of this section to claim rights or contest
125 | your rights to work written entirely by you; rather, the intent is to
126 | exercise the right to control the distribution of derivative or
127 | collective works based on the Program.
128 |
129 | In addition, mere aggregation of another work not based on the Program
130 | with the Program (or with a work based on the Program) on a volume of
131 | a storage or distribution medium does not bring the other work under
132 | the scope of this License.
133 |
134 | 3. You may copy and distribute the Program (or a work based on it,
135 | under Section 2) in object code or executable form under the terms of
136 | Sections 1 and 2 above provided that you also do one of the following:
137 |
138 | a) Accompany it with the complete corresponding machine-readable
139 | source code, which must be distributed under the terms of Sections
140 | 1 and 2 above on a medium customarily used for software interchange; or,
141 |
142 | b) Accompany it with a written offer, valid for at least three
143 | years, to give any third party, for a charge no more than your
144 | cost of physically performing source distribution, a complete
145 | machine-readable copy of the corresponding source code, to be
146 | distributed under the terms of Sections 1 and 2 above on a medium
147 | customarily used for software interchange; or,
148 |
149 | c) Accompany it with the information you received as to the offer
150 | to distribute corresponding source code. (This alternative is
151 | allowed only for noncommercial distribution and only if you
152 | received the program in object code or executable form with such
153 | an offer, in accord with Subsection b above.)
154 |
155 | The source code for a work means the preferred form of the work for
156 | making modifications to it. For an executable work, complete source
157 | code means all the source code for all modules it contains, plus any
158 | associated interface definition files, plus the scripts used to
159 | control compilation and installation of the executable. However, as a
160 | special exception, the source code distributed need not include
161 | anything that is normally distributed (in either source or binary
162 | form) with the major components (compiler, kernel, and so on) of the
163 | operating system on which the executable runs, unless that component
164 | itself accompanies the executable.
165 |
166 | If distribution of executable or object code is made by offering
167 | access to copy from a designated place, then offering equivalent
168 | access to copy the source code from the same place counts as
169 | distribution of the source code, even though third parties are not
170 | compelled to copy the source along with the object code.
171 |
172 | 4. You may not copy, modify, sublicense, or distribute the Program
173 | except as expressly provided under this License. Any attempt
174 | otherwise to copy, modify, sublicense or distribute the Program is
175 | void, and will automatically terminate your rights under this License.
176 | However, parties who have received copies, or rights, from you under
177 | this License will not have their licenses terminated so long as such
178 | parties remain in full compliance.
179 |
180 | 5. You are not required to accept this License, since you have not
181 | signed it. However, nothing else grants you permission to modify or
182 | distribute the Program or its derivative works. These actions are
183 | prohibited by law if you do not accept this License. Therefore, by
184 | modifying or distributing the Program (or any work based on the
185 | Program), you indicate your acceptance of this License to do so, and
186 | all its terms and conditions for copying, distributing or modifying
187 | the Program or works based on it.
188 |
189 | 6. Each time you redistribute the Program (or any work based on the
190 | Program), the recipient automatically receives a license from the
191 | original licensor to copy, distribute or modify the Program subject to
192 | these terms and conditions. You may not impose any further
193 | restrictions on the recipients' exercise of the rights granted herein.
194 | You are not responsible for enforcing compliance by third parties to
195 | this License.
196 |
197 | 7. If, as a consequence of a court judgment or allegation of patent
198 | infringement or for any other reason (not limited to patent issues),
199 | conditions are imposed on you (whether by court order, agreement or
200 | otherwise) that contradict the conditions of this License, they do not
201 | excuse you from the conditions of this License. If you cannot
202 | distribute so as to satisfy simultaneously your obligations under this
203 | License and any other pertinent obligations, then as a consequence you
204 | may not distribute the Program at all. For example, if a patent
205 | license would not permit royalty-free redistribution of the Program by
206 | all those who receive copies directly or indirectly through you, then
207 | the only way you could satisfy both it and this License would be to
208 | refrain entirely from distribution of the Program.
209 |
210 | If any portion of this section is held invalid or unenforceable under
211 | any particular circumstance, the balance of the section is intended to
212 | apply and the section as a whole is intended to apply in other
213 | circumstances.
214 |
215 | It is not the purpose of this section to induce you to infringe any
216 | patents or other property right claims or to contest validity of any
217 | such claims; this section has the sole purpose of protecting the
218 | integrity of the free software distribution system, which is
219 | implemented by public license practices. Many people have made
220 | generous contributions to the wide range of software distributed
221 | through that system in reliance on consistent application of that
222 | system; it is up to the author/donor to decide if he or she is willing
223 | to distribute software through any other system and a licensee cannot
224 | impose that choice.
225 |
226 | This section is intended to make thoroughly clear what is believed to
227 | be a consequence of the rest of this License.
228 |
229 | 8. If the distribution and/or use of the Program is restricted in
230 | certain countries either by patents or by copyrighted interfaces, the
231 | original copyright holder who places the Program under this License
232 | may add an explicit geographical distribution limitation excluding
233 | those countries, so that distribution is permitted only in or among
234 | countries not thus excluded. In such case, this License incorporates
235 | the limitation as if written in the body of this License.
236 |
237 | 9. The Free Software Foundation may publish revised and/or new versions
238 | of the General Public License from time to time. Such new versions will
239 | be similar in spirit to the present version, but may differ in detail to
240 | address new problems or concerns.
241 |
242 | Each version is given a distinguishing version number. If the Program
243 | specifies a version number of this License which applies to it and "any
244 | later version", you have the option of following the terms and conditions
245 | either of that version or of any later version published by the Free
246 | Software Foundation. If the Program does not specify a version number of
247 | this License, you may choose any version ever published by the Free Software
248 | Foundation.
249 |
250 | 10. If you wish to incorporate parts of the Program into other free
251 | programs whose distribution conditions are different, write to the author
252 | to ask for permission. For software which is copyrighted by the Free
253 | Software Foundation, write to the Free Software Foundation; we sometimes
254 | make exceptions for this. Our decision will be guided by the two goals
255 | of preserving the free status of all derivatives of our free software and
256 | of promoting the sharing and reuse of software generally.
257 |
258 | NO WARRANTY
259 |
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268 | REPAIR OR CORRECTION.
269 |
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278 | POSSIBILITY OF SUCH DAMAGES.
279 |
280 | END OF TERMS AND CONDITIONS
281 |
282 | How to Apply These Terms to Your New Programs
283 |
284 | If you develop a new program, and you want it to be of the greatest
285 | possible use to the public, the best way to achieve this is to make it
286 | free software which everyone can redistribute and change under these terms.
287 |
288 | To do so, attach the following notices to the program. It is safest
289 | to attach them to the start of each source file to most effectively
290 | convey the exclusion of warranty; and each file should have at least
291 | the "copyright" line and a pointer to where the full notice is found.
292 |
293 | {description}
294 | Copyright (C) {year} {fullname}
295 |
296 | This program is free software; you can redistribute it and/or modify
297 | it under the terms of the GNU General Public License as published by
298 | the Free Software Foundation; either version 2 of the License, or
299 | (at your option) any later version.
300 |
301 | This program is distributed in the hope that it will be useful,
302 | but WITHOUT ANY WARRANTY; without even the implied warranty of
303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 | GNU General Public License for more details.
305 |
306 | You should have received a copy of the GNU General Public License along
307 | with this program; if not, write to the Free Software Foundation, Inc.,
308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309 |
310 | Also add information on how to contact you by electronic and paper mail.
311 |
312 | If the program is interactive, make it output a short notice like this
313 | when it starts in an interactive mode:
314 |
315 | Gnomovision version 69, Copyright (C) year name of author
316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317 | This is free software, and you are welcome to redistribute it
318 | under certain conditions; type `show c' for details.
319 |
320 | The hypothetical commands `show w' and `show c' should show the appropriate
321 | parts of the General Public License. Of course, the commands you use may
322 | be called something other than `show w' and `show c'; they could even be
323 | mouse-clicks or menu items--whatever suits your program.
324 |
325 | You should also get your employer (if you work as a programmer) or your
326 | school, if any, to sign a "copyright disclaimer" for the program, if
327 | necessary. Here is a sample; alter the names:
328 |
329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
331 |
332 | {signature of Ty Coon}, 1 April 1989
333 | Ty Coon, President of Vice
334 |
335 | This General Public License does not permit incorporating your program into
336 | proprietary programs. If your program is a subroutine library, you may
337 | consider it more useful to permit linking proprietary applications with the
338 | library. If this is what you want to do, use the GNU Lesser General
339 | Public License instead of this License.
340 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | SizeAdjustingTextView
2 | =====================
3 |
4 | This is based on an open source autosizing textview for Android I found a few weeks ago. The initial approach
5 | didn't resize multiple lines and wasn't maintained to keep up with changes in Android. I decided to go ahead
6 | and create this as a place to preserve the auto sizing text view as well as giving it a platform for some change
7 | and to possibly add some features and functionality.
8 |
9 | ## Usage
10 | To use the SizeAdjustingTextView make sure you have the custom view somewhere in your project.
11 | From there when using XML Layouts you can simply use the com.some.package.name.SizeAdjustingTextView
12 | widget and thats it. From there you need to make sure that you set a text size as the baseline for the view.
13 | ```XML
14 |
22 | ```
23 | Lastly when using custom views in XML, make sure you have the XLMNS tag in the root of the layout tag.
24 | ```XML
25 | xmlns:app="http://schemas.android.com/apk/res/com.example.SizeAdjustingTextView"
26 | ```
27 |
28 | I didn't want to make this a library because there is no need for adding a library for one view. Just port over the SizeAdjustingTextView and you should be good.
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/SizeAdjustingTextView.java:
--------------------------------------------------------------------------------
1 |
2 | import android.content.Context;
3 | import android.text.Layout.Alignment;
4 | import android.text.StaticLayout;
5 | import android.text.TextPaint;
6 | import android.util.AttributeSet;
7 | import android.util.TypedValue;
8 | import android.widget.TextView;
9 |
10 | /**
11 | *
12 | * SizeAdjustingTextView is a TextView that adjusts text size
13 | * depending if or if not it will fit in the view bounds.
14 | * Copyright (C) 2014 Elliott Chenger
15 | *
16 | * This program is free software; you can redistribute it and/or
17 | * modify it under the terms of the GNU General Public License
18 | * as published by the Free Software Foundation; either version 2
19 | * of the License, or (at your option) any later version.
20 | *
21 | * This program is distributed in the hope that it will be useful,
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 | * GNU General Public License for more details.
25 | *
26 | * You should have received a copy of the GNU General Public License
27 | * along with this program; if not, write to the Free Software
28 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
29 | *
30 | * @author Elliott Chenger
31 | * @since Jan 18, 2014
32 | * @author Chase Colburn
33 | * @since Apr 4, 2011
34 | *
35 | */
36 | public class SizeAdjustingTextView extends TextView{
37 |
38 | // Minimum text size for this text view
39 | public static final float MIN_TEXT_SIZE = 20;
40 |
41 | // Our ellipse string
42 | private static final String mEllipsis = "...";
43 |
44 | // Flag for text and/or size changes to force a resize
45 | private boolean mNeedsResize = false;
46 |
47 | // Text size that is set from code. This acts as a starting point for resizing
48 | private float mTextSize;
49 |
50 | // Temporary upper bounds on the starting text size
51 | private float mMaxTextSize = 0;
52 |
53 | // Lower bounds for text size
54 | private float mMinTextSize = MIN_TEXT_SIZE;
55 |
56 | // Text view line spacing multiplier
57 | private float mSpacingMult = 1.0f;
58 |
59 | // Text view additional line spacing
60 | private float mSpacingAdd = 0.0f;
61 |
62 | // Add ellipsis to text that overflows at the smallest text size
63 | private boolean mAddEllipsis = true;
64 |
65 | // Default constructor override
66 | public SizeAdjustingTextView(Context context) {
67 | this(context, null);
68 | }
69 |
70 | // Default constructor when inflating from XML file
71 | public SizeAdjustingTextView(Context context, AttributeSet attrs) {
72 | this(context, attrs, 0);
73 | }
74 |
75 | // Default constructor override
76 | public SizeAdjustingTextView(Context context, AttributeSet attrs, int defStyle) {
77 | super(context, attrs, defStyle);
78 | mTextSize = getTextSize();
79 | }
80 |
81 | @Override
82 | protected void onTextChanged(final CharSequence text, final int start, final int before, final int after) {
83 | mNeedsResize = true;
84 | // Since this view may be reused, it is good to reset the text size
85 | resetTextSize();
86 | }
87 |
88 | @Override
89 | public void setText(CharSequence text, BufferType type) {
90 | super.setText(text, type);
91 | resizeText();
92 | }
93 |
94 | @Override
95 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
96 | if (w != oldw || h != oldh) {
97 | mNeedsResize = true;
98 | }
99 | }
100 |
101 |
102 | @Override
103 | public void setTextSize(float size) {
104 | super.setTextSize(size);
105 | mTextSize = getTextSize();
106 | }
107 |
108 | @Override
109 | public void setTextSize(int unit, float size) {
110 | super.setTextSize(unit, size);
111 | mTextSize = getTextSize();
112 | }
113 |
114 | @Override
115 | public void setLineSpacing(float add, float mult) {
116 | super.setLineSpacing(add, mult);
117 | mSpacingMult = mult;
118 | mSpacingAdd = add;
119 | }
120 |
121 | public void setMaxTextSize(float maxTextSize) {
122 | mMaxTextSize = maxTextSize;
123 | requestLayout();
124 | invalidate();
125 | }
126 |
127 | public float getMaxTextSize() {
128 | return mMaxTextSize;
129 | }
130 |
131 | public void setMinTextSize(float minTextSize) {
132 | mMinTextSize = minTextSize;
133 | requestLayout();
134 | invalidate();
135 | }
136 |
137 | public float getMinTextSize() {
138 | return mMinTextSize;
139 | }
140 |
141 | public void setAddEllipsis(boolean addEllipsis) {
142 | mAddEllipsis = addEllipsis;
143 | }
144 |
145 | public boolean getAddEllipsis() {
146 | return mAddEllipsis;
147 | }
148 |
149 | public void resetTextSize() {
150 | if(mTextSize > 0) {
151 | super.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
152 | mMaxTextSize = mTextSize;
153 | }
154 | }
155 |
156 | @Override
157 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
158 | if(changed || mNeedsResize) {
159 | int widthLimit = (right - left) - getCompoundPaddingLeft() - getCompoundPaddingRight();
160 | int heightLimit = (bottom - top) - getCompoundPaddingBottom() - getCompoundPaddingTop();
161 | resizeText(widthLimit, heightLimit);
162 | }
163 | super.onLayout(changed, left, top, right, bottom);
164 | }
165 |
166 |
167 | public void resizeText() {
168 | int heightLimit = getHeight() - getPaddingBottom() - getPaddingTop();
169 | int widthLimit = getWidth() - getPaddingLeft() - getPaddingRight();
170 | resizeText(widthLimit, heightLimit);
171 | }
172 |
173 | public void resizeText(int width, int height) {
174 | CharSequence text = getText();
175 | if(text == null || text.length() == 0 || height <= 0 || width <= 0 || mTextSize == 0) {
176 | return;
177 | }
178 | float newTextSize = findNewTextSize(width, height, text);
179 | changeTextSize(newTextSize);
180 | mNeedsResize = false;
181 | }
182 |
183 | private void changeTextSize(float newTextSize) {
184 | setTextSize(TypedValue.COMPLEX_UNIT_PX,newTextSize);
185 | setLineSpacing(mSpacingAdd, mSpacingMult);
186 | }
187 |
188 | private float findNewTextSize(int width, int height, CharSequence text) {
189 | TextPaint textPaint = new TextPaint(getPaint());
190 |
191 | float targetTextSize = textPaint.getTextSize();
192 |
193 | int textHeight = getTextHeight(text, textPaint, width, targetTextSize);
194 | while(textHeight > height && targetTextSize > mMinTextSize) {
195 | targetTextSize = Math.max(targetTextSize - 1, mMinTextSize);
196 | textHeight = getTextHeight(text, textPaint, width, targetTextSize);
197 | }
198 | return targetTextSize;
199 | }
200 |
201 | private int getTextHeight(CharSequence source, TextPaint paint, int width, float textSize) {
202 | paint.setTextSize(textSize);
203 | StaticLayout layout = new StaticLayout(source, paint, width, Alignment.ALIGN_NORMAL, mSpacingMult, mSpacingAdd, true);
204 | return layout.getHeight();
205 | }
206 |
207 | }
--------------------------------------------------------------------------------
/SizeAdjustingTextViewAndroidStudios/.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 | out/
15 | build/
16 |
17 | # Local configuration file (sdk path, etc)
18 | local.properties
19 |
20 | # Eclipse project files
21 | .classpath
22 | .project
23 |
24 | # Windows thumbnail db
25 | .DS_Store
26 |
27 | # IDEA/Android Studio project files, because
28 | # the project can be imported from settings.gradle
29 | .idea
30 | *.iml
31 |
32 | # Old-style IDEA project files
33 | *.ipr
34 | *.iws
35 |
36 | # Local IDEA workspace
37 | .idea/workspace.xml
38 |
39 | # Gradle cache
40 | .gradle
41 |
42 | # Sandbox stuff
43 | _sandbox
44 |
45 |
--------------------------------------------------------------------------------
/SizeAdjustingTextViewAndroidStudios/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/SizeAdjustingTextViewAndroidStudios/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 22
5 | buildToolsVersion "21.1.2"
6 |
7 | defaultConfig {
8 | minSdkVersion 14
9 | targetSdkVersion 22
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile fileTree(dir: 'libs', include: ['*.jar'])
23 | compile 'com.android.support:appcompat-v7:21.+'
24 | compile project(':sizeadjustingtextview')
25 | }
26 |
--------------------------------------------------------------------------------
/SizeAdjustingTextViewAndroidStudios/app/proguard-rules.txt:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/chenger/android-sdks/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the ProGuard
5 | # include property in project.properties.
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 | #}
--------------------------------------------------------------------------------
/SizeAdjustingTextViewAndroidStudios/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
10 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/SizeAdjustingTextViewAndroidStudios/app/src/main/java/com/elliott/chenger/autosizingtextexampleproject/app/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.elliott.chenger.autosizingtextexampleproject.app;
2 |
3 |
4 | import android.app.Activity;
5 | import android.os.Bundle;
6 | import android.view.KeyEvent;
7 | import android.view.Menu;
8 | import android.view.inputmethod.EditorInfo;
9 | import android.widget.EditText;
10 | import android.widget.TextView;
11 | import android.widget.TextView.OnEditorActionListener;
12 |
13 | import com.elliott.chenger.autosizingtextexampleproject.utils.TextMover;
14 | import com.omitneedlesscode.sizeadjustingtextview.SizeAdjustingTextView;
15 |
16 | public class MainActivity extends Activity {
17 |
18 | private EditText mMessageEditText;
19 | private SizeAdjustingTextView mTopMessageBox,
20 | mMiddleLeftBox, mMiddleRightBox, mBottomLeftBox,
21 | mBottomMiddleBox, mBottomRightBox;
22 |
23 | @Override
24 | protected void onCreate(Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | setContentView(R.layout.activity_main);
27 |
28 | mMessageEditText = (EditText)findViewById(R.id.text_input);
29 | mMessageEditText.setOnEditorActionListener(actionListener);
30 | mTopMessageBox = (SizeAdjustingTextView)findViewById(R.id.topBox);
31 |
32 | mMiddleLeftBox = (SizeAdjustingTextView)findViewById(R.id.middleLeftBox);
33 | mMiddleRightBox = (SizeAdjustingTextView)findViewById(R.id.middleRightBox);
34 |
35 | mBottomLeftBox = (SizeAdjustingTextView)findViewById(R.id.bottomLeftBox);
36 | mBottomMiddleBox = (SizeAdjustingTextView)findViewById(R.id.bottomMiddleBox);
37 | mBottomRightBox = (SizeAdjustingTextView)findViewById(R.id.bottomRightBox);
38 | }
39 |
40 | @Override
41 | public boolean onCreateOptionsMenu(Menu menu) {
42 | // Inflate the menu; this adds items to the action bar if it is present.
43 | getMenuInflater().inflate(R.menu.main, menu);
44 | return true;
45 | }
46 |
47 | OnEditorActionListener actionListener = new OnEditorActionListener() {
48 |
49 | @Override
50 | public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
51 | boolean handled = false;
52 | String incomingText = mMessageEditText.getText().toString();
53 | if(actionId==EditorInfo.IME_ACTION_SEND && !incomingText.isEmpty()){
54 | handled = true;
55 | moveText();
56 | clearEditText();
57 | }
58 | return handled;
59 | }
60 | };
61 |
62 | private void moveText() {
63 |
64 | TextMover.moveTextFromCellToCell(mBottomMiddleBox, mBottomRightBox);
65 | TextMover.moveTextFromCellToCell(mBottomLeftBox, mBottomMiddleBox);
66 | TextMover.moveTextFromCellToCell(mMiddleRightBox, mBottomLeftBox);
67 | TextMover.moveTextFromCellToCell(mMiddleLeftBox, mMiddleRightBox);
68 | TextMover.moveTextFromCellToCell(mTopMessageBox, mMiddleLeftBox);
69 | String incomingText = mMessageEditText.getText().toString();
70 | TextMover.moveNewTextIntoCell(mTopMessageBox, incomingText);
71 |
72 | }
73 |
74 | private void clearEditText(){
75 | mMessageEditText.setText("");
76 | }
77 |
78 | }
--------------------------------------------------------------------------------
/SizeAdjustingTextViewAndroidStudios/app/src/main/java/com/elliott/chenger/autosizingtextexampleproject/utils/TextMover.java:
--------------------------------------------------------------------------------
1 | package com.elliott.chenger.autosizingtextexampleproject.utils;
2 |
3 | import com.omitneedlesscode.sizeadjustingtextview.SizeAdjustingTextView;
4 |
5 | /**
6 | * Created by chenger on 5/26/14.
7 | */
8 | public class TextMover {
9 | public static void moveTextFromCellToCell(SizeAdjustingTextView startingCell,
10 | SizeAdjustingTextView endCell){
11 | if(!startingCell.getText().toString().isEmpty()){
12 | String text = startingCell.getText().toString();
13 | endCell.setText(text);
14 | }
15 | }
16 |
17 | public static void moveNewTextIntoCell(SizeAdjustingTextView targetCell,
18 | String text){
19 | targetCell.setText(text);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/SizeAdjustingTextViewAndroidStudios/app/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/erchenger/SizeAdjustingTextView/fd0af613b11c66aa32fbd93894d10bd15d19ada9/SizeAdjustingTextViewAndroidStudios/app/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/SizeAdjustingTextViewAndroidStudios/app/src/main/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/erchenger/SizeAdjustingTextView/fd0af613b11c66aa32fbd93894d10bd15d19ada9/SizeAdjustingTextViewAndroidStudios/app/src/main/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/SizeAdjustingTextViewAndroidStudios/app/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/erchenger/SizeAdjustingTextView/fd0af613b11c66aa32fbd93894d10bd15d19ada9/SizeAdjustingTextViewAndroidStudios/app/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/SizeAdjustingTextViewAndroidStudios/app/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/erchenger/SizeAdjustingTextView/fd0af613b11c66aa32fbd93894d10bd15d19ada9/SizeAdjustingTextViewAndroidStudios/app/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/SizeAdjustingTextViewAndroidStudios/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
12 |
18 |
19 |
20 |
28 |
29 |
30 |
37 |
38 |
46 |
47 |
55 |
56 |
57 |
58 |
63 |
64 |
72 |
73 |
81 |
82 |
90 |
91 |
92 |
--------------------------------------------------------------------------------
/SizeAdjustingTextViewAndroidStudios/app/src/main/res/menu/main.xml:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/SizeAdjustingTextViewAndroidStudios/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/SizeAdjustingTextViewAndroidStudios/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/SizeAdjustingTextViewAndroidStudios/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | SizeAdjustingTextView
5 | Hello world!
6 | Settings
7 |
8 |
9 |
--------------------------------------------------------------------------------
/SizeAdjustingTextViewAndroidStudios/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/SizeAdjustingTextViewAndroidStudios/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | mavenCentral()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:1.1.0'
9 | }
10 | }
11 |
12 | allprojects {
13 | repositories {
14 | mavenCentral()
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/SizeAdjustingTextViewAndroidStudios/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Settings specified in this file will override any Gradle settings
5 | # configured through the IDE.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/SizeAdjustingTextViewAndroidStudios/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/erchenger/SizeAdjustingTextView/fd0af613b11c66aa32fbd93894d10bd15d19ada9/SizeAdjustingTextViewAndroidStudios/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/SizeAdjustingTextViewAndroidStudios/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Apr 10 15:27:10 PDT 2013
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=http\://services.gradle.org/distributions/gradle-2.2.1-all.zip
7 |
--------------------------------------------------------------------------------
/SizeAdjustingTextViewAndroidStudios/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/SizeAdjustingTextViewAndroidStudios/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/SizeAdjustingTextViewAndroidStudios/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':sizeadjustingtextview'
2 |
--------------------------------------------------------------------------------
/SizeAdjustingTextViewAndroidStudios/sizeadjustingtextview/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/SizeAdjustingTextViewAndroidStudios/sizeadjustingtextview/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 22
5 | buildToolsVersion "21.1.2"
6 |
7 | defaultConfig {
8 | minSdkVersion 14
9 | targetSdkVersion 22
10 | versionCode 2
11 | versionName "1.1"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile fileTree(dir: 'libs', include: ['*.jar'])
23 | compile 'com.android.support:appcompat-v7:22.1.1'
24 | }
25 |
--------------------------------------------------------------------------------
/SizeAdjustingTextViewAndroidStudios/sizeadjustingtextview/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/elliot.chenger/Development/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 |
--------------------------------------------------------------------------------
/SizeAdjustingTextViewAndroidStudios/sizeadjustingtextview/src/androidTest/java/com/omitneedlesscode/sizeadjustingtextview/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.omitneedlesscode.sizeadjustingtextview;
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 | }
--------------------------------------------------------------------------------
/SizeAdjustingTextViewAndroidStudios/sizeadjustingtextview/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/SizeAdjustingTextViewAndroidStudios/sizeadjustingtextview/src/main/java/com/omitneedlesscode/sizeadjustingtextview/SizeAdjustingTextView.java:
--------------------------------------------------------------------------------
1 | package com.omitneedlesscode.sizeadjustingtextview;
2 | import android.content.Context;
3 | import android.text.Layout.Alignment;
4 | import android.text.StaticLayout;
5 | import android.text.TextPaint;
6 | import android.util.AttributeSet;
7 | import android.util.TypedValue;
8 | import android.widget.TextView;
9 |
10 | /**
11 | *
12 | * SizeAdjustingTextView is a TextView that adjusts text size
13 | * depending if or if not it will fit in the view bounds.
14 | * Copyright (C) 2014 Elliott Chenger
15 | *
16 | * This program is free software; you can redistribute it and/or
17 | * modify it under the terms of the GNU General Public License
18 | * as published by the Free Software Foundation; either version 2
19 | * of the License, or (at your option) any later version.
20 | *
21 | * This program is distributed in the hope that it will be useful,
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 | * GNU General Public License for more details.
25 | *
26 | * You should have received a copy of the GNU General Public License
27 | * along with this program; if not, write to the Free Software
28 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
29 | *
30 | * @author Elliott Chenger
31 | * @since Jan 18, 2014
32 | * @author Chase Colburn
33 | * @since Apr 4, 2011
34 | *
35 | */
36 | public class SizeAdjustingTextView extends TextView{
37 |
38 | // Minimum text size for this text view
39 | public static final float MIN_TEXT_SIZE = 20;
40 |
41 | // Our ellipse string
42 | private static final String mEllipsis = "...";
43 |
44 | // Flag for text and/or size changes to force a resize
45 | private boolean mNeedsResize = false;
46 |
47 | // Text size that is set from code. This acts as a starting point for resizing
48 | private float mTextSize;
49 |
50 | // Temporary upper bounds on the starting text size
51 | private float mMaxTextSize = 0;
52 |
53 | // Lower bounds for text size
54 | private float mMinTextSize = MIN_TEXT_SIZE;
55 |
56 | // Text view line spacing multiplier
57 | private float mSpacingMult = 1.0f;
58 |
59 | // Text view additional line spacing
60 | private float mSpacingAdd = 0.0f;
61 |
62 | // Add ellipsis to text that overflows at the smallest text size
63 | private boolean mAddEllipsis = true;
64 |
65 | // Default constructor override
66 | public SizeAdjustingTextView(Context context) {
67 | this(context, null);
68 | }
69 |
70 | // Default constructor when inflating from XML file
71 | public SizeAdjustingTextView(Context context, AttributeSet attrs) {
72 | this(context, attrs, 0);
73 | }
74 |
75 | // Default constructor override
76 | public SizeAdjustingTextView(Context context, AttributeSet attrs, int defStyle) {
77 | super(context, attrs, defStyle);
78 | mTextSize = getTextSize();
79 | }
80 |
81 | @Override
82 | protected void onTextChanged(final CharSequence text, final int start, final int before, final int after) {
83 | mNeedsResize = true;
84 | // Since this view may be reused, it is good to reset the text size
85 | resetTextSize();
86 | }
87 |
88 | @Override
89 | public void setText(CharSequence text, BufferType type) {
90 | super.setText(text, type);
91 | resizeText();
92 | }
93 |
94 | @Override
95 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
96 | if (w != oldw || h != oldh) {
97 | mNeedsResize = true;
98 | }
99 | }
100 |
101 |
102 | @Override
103 | public void setTextSize(float size) {
104 | super.setTextSize(size);
105 | mTextSize = getTextSize();
106 | }
107 |
108 | @Override
109 | public void setTextSize(int unit, float size) {
110 | super.setTextSize(unit, size);
111 | mTextSize = getTextSize();
112 | }
113 |
114 | @Override
115 | public void setLineSpacing(float add, float mult) {
116 | super.setLineSpacing(add, mult);
117 | mSpacingMult = mult;
118 | mSpacingAdd = add;
119 | }
120 |
121 | public void setMaxTextSize(float maxTextSize) {
122 | mMaxTextSize = maxTextSize;
123 | requestLayout();
124 | invalidate();
125 | }
126 |
127 | public float getMaxTextSize() {
128 | return mMaxTextSize;
129 | }
130 |
131 | public void setMinTextSize(float minTextSize) {
132 | mMinTextSize = minTextSize;
133 | requestLayout();
134 | invalidate();
135 | }
136 |
137 | public float getMinTextSize() {
138 | return mMinTextSize;
139 | }
140 |
141 | public void setAddEllipsis(boolean addEllipsis) {
142 | mAddEllipsis = addEllipsis;
143 | }
144 |
145 | public boolean getAddEllipsis() {
146 | return mAddEllipsis;
147 | }
148 |
149 | public void resetTextSize() {
150 | if(mTextSize > 0) {
151 | super.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
152 | mMaxTextSize = mTextSize;
153 | }
154 | }
155 |
156 | @Override
157 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
158 | if(changed || mNeedsResize) {
159 | int widthLimit = (right - left) - getCompoundPaddingLeft() - getCompoundPaddingRight();
160 | int heightLimit = (bottom - top) - getCompoundPaddingBottom() - getCompoundPaddingTop();
161 | resizeText(widthLimit, heightLimit);
162 | }
163 | super.onLayout(changed, left, top, right, bottom);
164 | }
165 |
166 |
167 | public void resizeText() {
168 | int heightLimit = getHeight() - getPaddingBottom() - getPaddingTop();
169 | int widthLimit = getWidth() - getPaddingLeft() - getPaddingRight();
170 | resizeText(widthLimit, heightLimit);
171 | }
172 |
173 | public void resizeText(int width, int height) {
174 | CharSequence text = getText();
175 | if(text == null || text.length() == 0 || height <= 0 || width <= 0 || mTextSize == 0) {
176 | return;
177 | }
178 | float newTextSize = findNewTextSize(width, height, text);
179 | changeTextSize(newTextSize);
180 | mNeedsResize = false;
181 | }
182 |
183 | private void changeTextSize(float newTextSize) {
184 | setTextSize(TypedValue.COMPLEX_UNIT_PX,newTextSize);
185 | setLineSpacing(mSpacingAdd, mSpacingMult);
186 | }
187 |
188 | private float findNewTextSize(int width, int height, CharSequence text) {
189 | TextPaint textPaint = new TextPaint(getPaint());
190 |
191 | float targetTextSize = textPaint.getTextSize();
192 |
193 | int textHeight = getTextHeight(text, textPaint, width, targetTextSize);
194 | while(textHeight > height && targetTextSize > mMinTextSize) {
195 | targetTextSize = Math.max(targetTextSize - 1, mMinTextSize);
196 | textHeight = getTextHeight(text, textPaint, width, targetTextSize);
197 | }
198 | return targetTextSize;
199 | }
200 |
201 | private int getTextHeight(CharSequence source, TextPaint paint, int width, float textSize) {
202 | paint.setTextSize(textSize);
203 | StaticLayout layout = new StaticLayout(source, paint, width, Alignment.ALIGN_NORMAL, mSpacingMult, mSpacingAdd, true);
204 | return layout.getHeight();
205 | }
206 |
207 | }
--------------------------------------------------------------------------------
/SizeAdjustingTextViewAndroidStudios/sizeadjustingtextview/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Size Adjusting Text View
3 |
4 |
--------------------------------------------------------------------------------
/SizeAdjustingTextViewEclipse/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/SizeAdjustingTextViewEclipse/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 |
15 | # Gradle files
16 | .gradle/
17 | build/
18 |
19 | # Local configuration file (sdk path, etc)
20 | local.properties
21 |
22 | # Proguard folder generated by Eclipse
23 | proguard/
24 |
25 | #Log Files
26 | *.log
--------------------------------------------------------------------------------
/SizeAdjustingTextViewEclipse/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | SizeAdjustingTextView
4 |
5 |
6 |
7 |
8 |
9 | com.android.ide.eclipse.adt.ResourceManagerBuilder
10 |
11 |
12 |
13 |
14 | com.android.ide.eclipse.adt.PreCompilerBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.jdt.core.javabuilder
20 |
21 |
22 |
23 |
24 | com.android.ide.eclipse.adt.ApkBuilder
25 |
26 |
27 |
28 |
29 |
30 | com.android.ide.eclipse.adt.AndroidNature
31 | org.eclipse.jdt.core.javanature
32 |
33 |
34 |
--------------------------------------------------------------------------------
/SizeAdjustingTextViewEclipse/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
16 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/SizeAdjustingTextViewEclipse/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/erchenger/SizeAdjustingTextView/fd0af613b11c66aa32fbd93894d10bd15d19ada9/SizeAdjustingTextViewEclipse/ic_launcher-web.png
--------------------------------------------------------------------------------
/SizeAdjustingTextViewEclipse/libs/android-support-v4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/erchenger/SizeAdjustingTextView/fd0af613b11c66aa32fbd93894d10bd15d19ada9/SizeAdjustingTextViewEclipse/libs/android-support-v4.jar
--------------------------------------------------------------------------------
/SizeAdjustingTextViewEclipse/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/SizeAdjustingTextViewEclipse/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-19
15 |
--------------------------------------------------------------------------------
/SizeAdjustingTextViewEclipse/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/erchenger/SizeAdjustingTextView/fd0af613b11c66aa32fbd93894d10bd15d19ada9/SizeAdjustingTextViewEclipse/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/SizeAdjustingTextViewEclipse/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/erchenger/SizeAdjustingTextView/fd0af613b11c66aa32fbd93894d10bd15d19ada9/SizeAdjustingTextViewEclipse/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/SizeAdjustingTextViewEclipse/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/erchenger/SizeAdjustingTextView/fd0af613b11c66aa32fbd93894d10bd15d19ada9/SizeAdjustingTextViewEclipse/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/SizeAdjustingTextViewEclipse/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/erchenger/SizeAdjustingTextView/fd0af613b11c66aa32fbd93894d10bd15d19ada9/SizeAdjustingTextViewEclipse/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/SizeAdjustingTextViewEclipse/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
12 |
18 |
19 |
20 |
28 |
29 |
30 |
37 |
38 |
46 |
47 |
55 |
56 |
57 |
58 |
63 |
64 |
72 |
73 |
81 |
82 |
90 |
91 |
92 |
--------------------------------------------------------------------------------
/SizeAdjustingTextViewEclipse/res/menu/main.xml:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/SizeAdjustingTextViewEclipse/res/values-sw600dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/SizeAdjustingTextViewEclipse/res/values-sw720dp-land/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 | 128dp
8 |
9 |
10 |
--------------------------------------------------------------------------------
/SizeAdjustingTextViewEclipse/res/values-v11/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/SizeAdjustingTextViewEclipse/res/values-v14/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/SizeAdjustingTextViewEclipse/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 16dp
5 | 16dp
6 |
7 |
8 |
--------------------------------------------------------------------------------
/SizeAdjustingTextViewEclipse/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | SizeAdjustingTextView
5 | Settings
6 | Hello world!
7 |
8 |
9 |
--------------------------------------------------------------------------------
/SizeAdjustingTextViewEclipse/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
14 |
15 |
16 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/SizeAdjustingTextViewEclipse/src/com/elliott/chenger/sizeadjustingtextview/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.elliott.chenger.sizeadjustingtextview;
2 |
3 | import com.elliott.chenger.sizeadjustingtextview.utils.TextMover;
4 | import com.elliott.chenger.sizeadjustingtextview.view.SizeAdjustingTextView;
5 |
6 | import android.app.Activity;
7 | import android.os.Bundle;
8 | import android.view.KeyEvent;
9 | import android.view.Menu;
10 | import android.view.inputmethod.EditorInfo;
11 | import android.widget.EditText;
12 | import android.widget.TextView;
13 | import android.widget.TextView.OnEditorActionListener;
14 |
15 | public class MainActivity extends Activity {
16 |
17 | private EditText mMessageEditText;
18 | private SizeAdjustingTextView mTopMessageBox,
19 | mMiddleLeftBox, mMiddleRightBox, mBottomLeftBox,
20 | mBottomMiddleBox, mBottomRightBox;
21 |
22 | @Override
23 | protected void onCreate(Bundle savedInstanceState) {
24 | super.onCreate(savedInstanceState);
25 | setContentView(R.layout.activity_main);
26 |
27 | mMessageEditText = (EditText)findViewById(R.id.text_input);
28 | mMessageEditText.setOnEditorActionListener(actionListener);
29 | mTopMessageBox = (SizeAdjustingTextView)findViewById(R.id.topBox);
30 |
31 | mMiddleLeftBox = (SizeAdjustingTextView)findViewById(R.id.middleLeftBox);
32 | mMiddleRightBox = (SizeAdjustingTextView)findViewById(R.id.middleRightBox);
33 |
34 | mBottomLeftBox = (SizeAdjustingTextView)findViewById(R.id.bottomLeftBox);
35 | mBottomMiddleBox = (SizeAdjustingTextView)findViewById(R.id.bottomMiddleBox);
36 | mBottomRightBox = (SizeAdjustingTextView)findViewById(R.id.bottomRightBox);
37 | }
38 |
39 | @Override
40 | public boolean onCreateOptionsMenu(Menu menu) {
41 | // Inflate the menu; this adds items to the action bar if it is present.
42 | getMenuInflater().inflate(R.menu.main, menu);
43 | return true;
44 | }
45 |
46 | OnEditorActionListener actionListener = new OnEditorActionListener() {
47 |
48 | @Override
49 | public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
50 | boolean handled = false;
51 | String incomingText = mMessageEditText.getText().toString();
52 | if(actionId==EditorInfo.IME_ACTION_SEND && !incomingText.isEmpty()){
53 | handled = true;
54 | moveText();
55 | clearEditText();
56 | }
57 | return handled;
58 | }
59 | };
60 |
61 | private void moveText() {
62 |
63 | TextMover.moveTextFromCellToCell(mBottomMiddleBox, mBottomRightBox);
64 | TextMover.moveTextFromCellToCell(mBottomLeftBox, mBottomMiddleBox);
65 | TextMover.moveTextFromCellToCell(mMiddleRightBox, mBottomLeftBox);
66 | TextMover.moveTextFromCellToCell(mMiddleLeftBox, mMiddleRightBox);
67 | TextMover.moveTextFromCellToCell(mTopMessageBox, mMiddleLeftBox);
68 | String incomingText = mMessageEditText.getText().toString();
69 | TextMover.moveNewTextIntoCell(mTopMessageBox, incomingText);
70 |
71 | }
72 |
73 | private void clearEditText(){
74 | mMessageEditText.setText("");
75 | }
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/SizeAdjustingTextViewEclipse/src/com/elliott/chenger/sizeadjustingtextview/utils/TextMover.java:
--------------------------------------------------------------------------------
1 | package com.elliott.chenger.sizeadjustingtextview.utils;
2 |
3 | import com.elliott.chenger.sizeadjustingtextview.view.SizeAdjustingTextView;
4 |
5 | public class TextMover {
6 |
7 | public static void moveTextFromCellToCell(SizeAdjustingTextView startingCell,
8 | SizeAdjustingTextView endCell){
9 | if(!startingCell.getText().toString().isEmpty()){
10 | String text = startingCell.getText().toString();
11 | endCell.setText(text);
12 | }
13 | }
14 |
15 | public static void moveNewTextIntoCell(SizeAdjustingTextView targetCell,
16 | String text){
17 | targetCell.setText(text);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/SizeAdjustingTextViewEclipse/src/com/elliott/chenger/sizeadjustingtextview/view/SizeAdjustingTextView.java:
--------------------------------------------------------------------------------
1 | package com.elliott.chenger.sizeadjustingtextview.view;
2 |
3 | import android.content.Context;
4 | import android.text.Layout.Alignment;
5 | import android.text.StaticLayout;
6 | import android.text.TextPaint;
7 | import android.util.AttributeSet;
8 | import android.util.TypedValue;
9 | import android.widget.TextView;
10 |
11 | /**
12 | *
13 | * SizeAdjustingTextView is a TextView that adjusts text size
14 | * depending if or if not it will fit in the view bounds.
15 | * Copyright (C) 2014 Elliott Chenger
16 | *
17 | * This program is free software; you can redistribute it and/or
18 | * modify it under the terms of the GNU General Public License
19 | * as published by the Free Software Foundation; either version 2
20 | * of the License, or (at your option) any later version.
21 | *
22 | * This program is distributed in the hope that it will be useful,
23 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 | * GNU General Public License for more details.
26 | *
27 | * You should have received a copy of the GNU General Public License
28 | * along with this program; if not, write to the Free Software
29 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
30 | *
31 | * @author Elliott Chenger
32 | * @since Jan 18, 2014
33 | * @author Chase Colburn
34 | * @since Apr 4, 2011
35 | *
36 | */
37 | public class SizeAdjustingTextView extends TextView{
38 |
39 | // Minimum text size for this text view
40 | public static final float MIN_TEXT_SIZE = 20;
41 |
42 | // Our ellipse string
43 | private static final String mEllipsis = "...";
44 |
45 | // Flag for text and/or size changes to force a resize
46 | private boolean mNeedsResize = false;
47 |
48 | // Text size that is set from code. This acts as a starting point for resizing
49 | private float mTextSize;
50 |
51 | // Temporary upper bounds on the starting text size
52 | private float mMaxTextSize = 0;
53 |
54 | // Lower bounds for text size
55 | private float mMinTextSize = MIN_TEXT_SIZE;
56 |
57 | // Text view line spacing multiplier
58 | private float mSpacingMult = 1.0f;
59 |
60 | // Text view additional line spacing
61 | private float mSpacingAdd = 0.0f;
62 |
63 | // Add ellipsis to text that overflows at the smallest text size
64 | private boolean mAddEllipsis = true;
65 |
66 | // Default constructor override
67 | public SizeAdjustingTextView(Context context) {
68 | this(context, null);
69 | }
70 |
71 | // Default constructor when inflating from XML file
72 | public SizeAdjustingTextView(Context context, AttributeSet attrs) {
73 | this(context, attrs, 0);
74 | }
75 |
76 | // Default constructor override
77 | public SizeAdjustingTextView(Context context, AttributeSet attrs, int defStyle) {
78 | super(context, attrs, defStyle);
79 | mTextSize = getTextSize();
80 | }
81 |
82 | @Override
83 | protected void onTextChanged(final CharSequence text, final int start, final int before, final int after) {
84 | mNeedsResize = true;
85 | // Since this view may be reused, it is good to reset the text size
86 | resetTextSize();
87 | }
88 |
89 | @Override
90 | public void setText(CharSequence text, BufferType type) {
91 | super.setText(text, type);
92 | resizeText();
93 | }
94 |
95 | @Override
96 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
97 | if (w != oldw || h != oldh) {
98 | mNeedsResize = true;
99 | }
100 | }
101 |
102 |
103 | @Override
104 | public void setTextSize(float size) {
105 | super.setTextSize(size);
106 | mTextSize = getTextSize();
107 | }
108 |
109 | @Override
110 | public void setTextSize(int unit, float size) {
111 | super.setTextSize(unit, size);
112 | mTextSize = getTextSize();
113 | }
114 |
115 | @Override
116 | public void setLineSpacing(float add, float mult) {
117 | super.setLineSpacing(add, mult);
118 | mSpacingMult = mult;
119 | mSpacingAdd = add;
120 | }
121 |
122 | public void setMaxTextSize(float maxTextSize) {
123 | mMaxTextSize = maxTextSize;
124 | requestLayout();
125 | invalidate();
126 | }
127 |
128 | public float getMaxTextSize() {
129 | return mMaxTextSize;
130 | }
131 |
132 | public void setMinTextSize(float minTextSize) {
133 | mMinTextSize = minTextSize;
134 | requestLayout();
135 | invalidate();
136 | }
137 |
138 | public float getMinTextSize() {
139 | return mMinTextSize;
140 | }
141 |
142 | public void setAddEllipsis(boolean addEllipsis) {
143 | mAddEllipsis = addEllipsis;
144 | }
145 |
146 | public boolean getAddEllipsis() {
147 | return mAddEllipsis;
148 | }
149 |
150 | public void resetTextSize() {
151 | if(mTextSize > 0) {
152 | super.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
153 | mMaxTextSize = mTextSize;
154 | }
155 | }
156 |
157 | @Override
158 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
159 | if(changed || mNeedsResize) {
160 | int widthLimit = (right - left) - getCompoundPaddingLeft() - getCompoundPaddingRight();
161 | int heightLimit = (bottom - top) - getCompoundPaddingBottom() - getCompoundPaddingTop();
162 | resizeText(widthLimit, heightLimit);
163 | }
164 | super.onLayout(changed, left, top, right, bottom);
165 | }
166 |
167 |
168 | public void resizeText() {
169 | int heightLimit = getHeight() - getPaddingBottom() - getPaddingTop();
170 | int widthLimit = getWidth() - getPaddingLeft() - getPaddingRight();
171 | resizeText(widthLimit, heightLimit);
172 | }
173 |
174 | public void resizeText(int width, int height) {
175 | CharSequence text = getText();
176 | if(text == null || text.length() == 0 || height <= 0 || width <= 0 || mTextSize == 0) {
177 | return;
178 | }
179 | float newTextSize = findNewTextSize(width, height, text);
180 | changeTextSize(newTextSize);
181 | mNeedsResize = false;
182 | }
183 |
184 | private void changeTextSize(float newTextSize) {
185 | setTextSize(TypedValue.COMPLEX_UNIT_PX,newTextSize);
186 | setLineSpacing(mSpacingAdd, mSpacingMult);
187 | }
188 |
189 | private float findNewTextSize(int width, int height, CharSequence text) {
190 | TextPaint textPaint = new TextPaint(getPaint());
191 |
192 | float targetTextSize = textPaint.getTextSize();
193 |
194 | int textHeight = getTextHeight(text, textPaint, width, targetTextSize);
195 | while(textHeight > height && targetTextSize > mMinTextSize) {
196 | targetTextSize = Math.max(targetTextSize - 1, mMinTextSize);
197 | textHeight = getTextHeight(text, textPaint, width, targetTextSize);
198 | }
199 | return targetTextSize;
200 | }
201 |
202 | private int getTextHeight(CharSequence source, TextPaint paint, int width, float textSize) {
203 | paint.setTextSize(textSize);
204 | StaticLayout layout = new StaticLayout(source, paint, width, Alignment.ALIGN_NORMAL, mSpacingMult, mSpacingAdd, true);
205 | return layout.getHeight();
206 | }
207 |
208 | }
209 |
--------------------------------------------------------------------------------