-
Notifications
You must be signed in to change notification settings - Fork 688
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support api 8 and up #39
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -239,8 +239,7 @@ else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { | |
|
||
private TextWatcher mTextWatcher = new AutofitTextWatcher(); | ||
|
||
private View.OnLayoutChangeListener mOnLayoutChangeListener = | ||
new AutofitOnLayoutChangeListener(); | ||
private View.OnLayoutChangeListener mOnLayoutChangeListener; | ||
|
||
private AutofitHelper(TextView view) { | ||
final Context context = view.getContext(); | ||
|
@@ -433,12 +432,31 @@ public AutofitHelper setEnabled(boolean enabled) { | |
|
||
if (enabled) { | ||
mTextView.addTextChangedListener(mTextWatcher); | ||
mTextView.addOnLayoutChangeListener(mOnLayoutChangeListener); | ||
|
||
if ( android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { | ||
if (mOnLayoutChangeListener == null){ | ||
mOnLayoutChangeListener = new View.OnLayoutChangeListener() { | ||
@Override | ||
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { | ||
autofit(); | ||
} | ||
}; | ||
} | ||
mTextView.addOnLayoutChangeListener(mOnLayoutChangeListener); | ||
} else { | ||
if ( mTextView instanceof AutofitTextView) | ||
((AutofitTextView) mTextView).setSizeListener(sizeListener); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like this will only work for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably, I've done this a while back so it's hard to rember exactly, I only needed it for AutofitTextView |
||
} | ||
|
||
autofit(); | ||
} else { | ||
mTextView.removeTextChangedListener(mTextWatcher); | ||
mTextView.removeOnLayoutChangeListener(mOnLayoutChangeListener); | ||
if ( android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { | ||
mTextView.removeOnLayoutChangeListener(mOnLayoutChangeListener); | ||
} else { | ||
if ( mTextView instanceof AutofitTextView) | ||
((AutofitTextView) mTextView).setSizeListener(null); | ||
} | ||
|
||
mTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize); | ||
} | ||
|
@@ -532,10 +550,9 @@ public void afterTextChanged(Editable editable) { | |
} | ||
} | ||
|
||
private class AutofitOnLayoutChangeListener implements View.OnLayoutChangeListener { | ||
@Override | ||
public void onLayoutChange(View view, int left, int top, int right, int bottom, | ||
int oldLeft, int oldTop, int oldRight, int oldBottom) { | ||
private AutofitSizeChangedListener sizeListener = new AutofitSizeChangedListener(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: use hungarian notation to match the style in the rest of the file There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: also keep this up top with other ivars |
||
private class AutofitSizeChangedListener implements AutofitTextView.AutofitSizeChangedListener { | ||
public void onChange(){ | ||
autofit(); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason you moved this to an anonymous class? seems to have the same functionality as before
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just a lazy initialization, there is no need for this instance in older versions...