Delta Bartalk Master



Comments



Description

SystemUiHider.java 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: spawrks 09/18/14 package com.delta.bartalk.util; import android.app.Activity; import android.os.Build; import android.view.View; /** * A utility class that helps with showing and hiding system UI such as the * status bar and navigation/system bar. This class uses backward-compatibility * techniques described in <a href= * "http://developer.android.com/training/backward-compatible-ui/index.html"> * Creating Backward-Compatible UIs</a> to ensure that devices running any * version of ndroid OS are supported. More specifically, there are separate * implementations of this abstract class: for newer devices, * {@link #getInstance} will return a {@link SystemUiHiderHoneycomb} instance, * while on older devices {@link #getInstance} will return a * {@link SystemUiHiderBase} instance. * <p> * For more on system bars, see <a href= * "http://developer.android.com/design/get-started/ui-overview.html#system-bars" * > System Bars</a>. * * @see android.view.View#setSystemUiVisibility(int) * @see android.view.WindowManager.LayoutParams#FLAG_FULLSCREEN */ public abstract class SystemUiHider { /** * When this flag is set, the * {@link android.view.WindowManager.LayoutParams#FLAG_LAYOUT_IN_SCREEN} * flag will be set on older devices, making the status bar "float" on top * of the activity layout. This is most useful when there are no controls at * the top of the activity layout. * <p> * This flag isn’t used on newer devices because the <a * href="http://developer.android.com/design/patterns/actionbar.html">action * bar</a>, the most important structural element of an Android app, should * be visible and not obscured by the system UI. */ public static final int FLAG_LAYOUT_IN_SCREEN_OLDER_DEVICES = 0x1; /** * When this flag is set, {@link #show()} and {@link #hide()} will toggle * the visibility of the status bar. If there is a navigation bar, show and * hide will toggle low profile mode. */ public static final int FLAG_FULLSCREEN = 0x2; /** 1-1/4(1) SystemUiHider.java 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: spawrks 09/18/14 * When this flag is set, {@link #show()} and {@link #hide()} will toggle * the visibility of the navigation bar, if it’s present on the device and * the device allows hiding it. In cases where the navigation bar is present * but cannot be hidden, show and hide will toggle low profile mode. */ public static final int FLAG_HIDE_NAVIGATION = FLAG_FULLSCREEN | 0x4; /** * The activity associated with this UI hider object. */ protected Activity mActivity; /** * The view on which {@link View#setSystemUiVisibility(int)} will be called. */ protected View mAnchorView; /** * The current UI hider flags. * * @see #FLAG_FULLSCREEN * @see #FLAG_HIDE_NAVIGATION * @see #FLAG_LAYOUT_IN_SCREEN_OLDER_DEVICES */ protected int mFlags; /** * The current visibility callback. */ protected OnVisibilityChangeListener mOnVisibilityChangeListener = sDummyListener; /** * Creates and returns an instance of {@link SystemUiHider} that is * appropriate for this device. The object will be either a * {@link SystemUiHiderBase} or {@link SystemUiHiderHoneycomb} depending on * the device. * * @param activity The activity whose window’s system UI should be * controlled by this class. * @param anchorView The view on which * {@link View#setSystemUiVisibility(int)} will be called. * @param flags Either 0 or any combination of {@link #FLAG_FULLSCREEN}, * {@link #FLAG_HIDE_NAVIGATION}, and * {@link #FLAG_LAYOUT_IN_SCREEN_OLDER_DEVICES}. */ public static SystemUiHider getInstance(Activity activity, View anchorView, int flags) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { return new SystemUiHiderHoneycomb(activity, anchorView, flags); 1-2/4(2) } /** * Sets up the system UI hider. /** * Hide the system UI. /** * Returns whether or not the system UI is visible. } } protected SystemUiHider(Activity activity. } } /** * Registers a callback. } else { show(). */ public abstract void hide(). /** * Toggle the visibility of the system UI. View anchorView. */ public abstract void show().java 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: spawrks 09/18/14 } else { return new SystemUiHiderBase(activity. mAnchorView = anchorView. Should be called from * {@link Activity#onCreate}. */ public abstract boolean isVisible(). */ public void toggle() { if (isVisible()) { hide(). flags). to be triggered when the system UI visibility * changes. */ public void setOnVisibilityChangeListener(OnVisibilityChangeListener listener) { 1-3/4(3) . mFlags = flags. int flags) { mActivity = activity. */ public abstract void setup().SystemUiHider. anchorView. /** * Show the system UI. java 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: } spawrks 09/18/14 if (listener == null) { listener = sDummyListener. } mOnVisibilityChangeListener = listener. } 1-4/4(4) . } /** * A dummy no-op callback for use when there is no other listener set. /** * A callback interface used to listen for system UI visibility changes. */ public interface OnVisibilityChangeListener { /** * Called when the system UI visibility has changed. * * @param visible True if the system UI is visible.SystemUiHider. */ private static OnVisibilityChangeListener sDummyListener = new OnVisibilityChangeListener() { @Override public void onVisibilityChange(boolean visible) { } }. */ public void onVisibilityChange(boolean visible). setFlags( WindowManager.FLAG_LAYOUT_NO_LIMITS).Activity.SystemUiHiderBase. */ protected SystemUiHiderBase(Activity activity.app. View anchorView.LayoutParams.bartalk. } 2-1/2(5) . /** * A base implementation of {@link SystemUiHider}.FLAG_FULLSCREEN). WindowManager. } @Override public void hide() { if ((mFlags & FLAG_FULLSCREEN) != 0) { mActivity.view.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager. import android. anchorView. */ private boolean mVisible = true. Uses APIs available in all * API levels to show and hide the status bar.LayoutParams. } @Override public void setup() { if ((mFlags & FLAG_LAYOUT_IN_SCREEN_OLDER_DEVICES) == 0) { mActivity.getWindow().util. WindowManager.view. /** * Constructor not intended to be called by clients. flags).WindowManager. Use * {@link SystemUiHider#getInstance} to obtain an instance.FLAG_LAYOUT_NO_LIMITS. */ public class SystemUiHiderBase extends SystemUiHider { /** * Whether or not the system UI is currently visible. This is a cached value * from calls to {@link #hide()} and {@link #show()}.LayoutParams.getWindow(). } } @Override public boolean isVisible() { return mVisible.java 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: spawrks 09/18/14 package com. import android. import android. int flags) { super(activity.FLAG_FULLSCREEN.LayoutParams.delta.View.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager.setFlags( WindowManager. mVisible = false.getWindow().FLAG_FULLSCREEN). mVisible = true.SystemUiHiderBase.onVisibilityChange(true).java 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: } spawrks 09/18/14 mOnVisibilityChangeListener. } 2-2/2(6) .onVisibilityChange(false). } mOnVisibilityChangeListener. } @Override public void show() { if ((mFlags & FLAG_FULLSCREEN) != 0) { mActivity. WindowManager.setFlags( 0.LayoutParams. */ @TargetApi(Build.util.SystemUiHiderHoneycomb.SYSTEM_UI_FLAG_VISIBLE.OnSystemUiVisibilityChangeListener#onSystemUiVisibilityChange(int)} * to determine the system UI visibility state. Uses APIs available in * Honeycomb and later (specifically {@link View#setSystemUiVisibility(int)}) to * show and hide the system UI. */ private int mShowFlags.View.view.TargetApi. 3-1/3(7) . /** * Whether or not the system UI is currently visible. flags). */ private int mHideFlags.View.os. View anchorView. android. */ protected SystemUiHiderHoneycomb(Activity activity.VERSION_CODES.HONEYCOMB) public class SystemUiHiderHoneycomb extends SystemUiHiderBase { /** * Flags for {@link View#setSystemUiVisibility(int)} to use when showing the * system UI. int flags) { super(activity.OnSystemUiVisibilityChangeListener}.view. android. anchorView.java 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: spawrks 09/18/14 package com.View.bartalk. */ private int mTestFlags. */ private boolean mVisible = true. mShowFlags = View. Use * {@link SystemUiHider#getInstance} to obtain an instance.annotation. import import import import import android.app.Build.Activity.delta. /** * Flags for {@link View#setSystemUiVisibility(int)} to use when hiding the * system UI. android. android. /** * An API 11+ implementation of {@link SystemUiHider}.WindowManager.view. /** * Constructor not intended to be called by clients. This is cached from * {@link android. /** * Flags to test against the first parameter in * {@link android.view. mHideFlags |= View. } private View.OnSystemUiVisibilityChangeListener() { 3-2/3(8) . mShowFlags |= View. mHideFlags |= View. } /** {@inheritDoc} */ @Override public void show() { mAnchorView. mShowFlags |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION.setSystemUiVisibility(mHideFlags).setSystemUiVisibility(mShowFlags).SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN.SYSTEM_UI_FLAG_HIDE_NAVIGATION.SystemUiHiderHoneycomb.OnSystemUiVisibilityChangeListener mSystemUiVisibilityChangeListener = new View.SYSTEM_UI_FLAG_LOW_PROFILE.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View. as they are inlined // at compile-time and do nothing on pre-Jelly Bean devices. } /** {@inheritDoc} */ @Override public boolean isVisible() { return mVisible. } if ((mFlags & FLAG_HIDE_NAVIGATION) != 0) { // If the client requested hiding navigation. if ((mFlags & FLAG_FULLSCREEN) != 0) { // If the client requested fullscreen.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View. } /** {@inheritDoc} */ @Override public void hide() { mAnchorView. mTestFlags = View. It is safe to use them.java 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: spawrks 09/18/14 mHideFlags = View. add flags relevant to hiding // the status bar.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION.setOnSystemUiVisibilityChangeListener(mSystemUiVisibilityChangeListener).SYSTEM_UI_FLAG_FULLSCREEN. mTestFlags |= View. Note that some of these constants are new as of // API 16 (Jelly Bean).SYSTEM_UI_FLAG_LOW_PROFILE. add relevant flags. } } /** {@inheritDoc} */ @Override public void setup() { mAnchorView. if ((vis & mTestFlags) != 0) { if (Build. 3-3/3(9) .VERSION.VERSION.SDK_INT < Build.LayoutParams.getWindow().getWindow(). we must manually hide the action bar // and use the old window flags API.onVisibilityChange(false). mActivity. mVisible = false.VERSION_CODES. } // Trigger the registered listener and cache the visibility // state. WindowManager.setFlags( WindowManager. WindowManager. mOnVisibilityChangeListener. if (Build.JELLY_BEAN) { // Pre-Jelly Bean.setSystemUiVisibility(mShowFlags).getActionBar().VERSION_CODES.SystemUiHiderHoneycomb.setFlags( 0.LayoutParams. mActivity. mActivity. } // Trigger the registered listener and cache the visibility // state.hide().LayoutParams. mActivity.show(). } else { mAnchorView.java 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: } spawrks 09/18/14 @Override public void onSystemUiVisibilityChange(int vis) { // Test against mTestFlags to see if the system UI is visible.FLAG_FULLSCREEN.FLAG_FULLSCREEN). mOnVisibilityChangeListener.JELLY_BEAN) { // Pre-Jelly Bean.SDK_INT < Build.getActionBar().onVisibilityChange(true). mVisible = true. we must manually show the action bar // and use the old window flags API. } } }.FLAG_FULLSCREEN). TextPaint.text.util.Layout. private TextPaint mPaint. android. android.graphics.util.delta.Resources. android.Alignment. android. android.StaticLayout.SparseIntArray.text. android. 4-1/7(10) . } private RectF mTextRect = new RectF(). android.annotation. android. private RectF mAvailableSpaceRect. import import import import import import import import import import import import android. android. /* Taken from http://stackoverflow.os. private SparseIntArray mTextCachedSizes.TargetApi.bartalk.content. android.text.util.TextView.TypedValue.AttributeSet.content. android. > 0 * otherwise */ public int onTestSize(int suggestedSize.AutoResizeTextView. it takes less space than {@code availableSpace}.res.com/questions/5033012/auto-scale-textview-text-to-fit-within-bounds/17782522#17782522 m-wajeeh provided a completely amazingly robust widget to handle auto-resizing! */ public class AutoResizeTextView extends TextView { private interface SizeTester { /** * * @param suggestedSize * Size of text to be tested * @param availableSpace * available space in which text must fit * @return an integer < 0 if after applying {@code suggestedSize} to * text.com/users/1112882/m-wajeeh ’s code on Stack Overflow here: http://stackoverflow.widget.java 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: spawrks 09/18/14 package com.Context. RectF availableSpace).RectF.Build. } public AutoResizeTextView(Context context. private boolean mInitiallized. 4-2/7(11) . BufferType type) { super. if (mMaxLines == 0) { // no value was assigned during construction mMaxLines = NO_LINE_LIMIT. } private void initialize() { mPaint = new TextPaint(getPaint()). attrs). initialize().java 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: spawrks 09/18/14 private float mMaxTextSize. AttributeSet attrs) { super(context. type).setText(text.toString()). } public AutoResizeTextView(Context context. mAvailableSpaceRect = new RectF(). private static final int NO_LINE_LIMIT = -1.AutoResizeTextView. initialize(). mTextCachedSizes = new SparseIntArray().0f. private float mSpacingAdd = 0. mMaxTextSize = getTextSize(). private int mMaxLines. } @Override public void setText(final CharSequence text. defStyle). } mInitiallized = true. attrs. private float mMinTextSize = 20. private boolean mEnableSizeCache = true. private float mSpacingMult = 1. public AutoResizeTextView(Context context) { super(context).0f. adjustTextSize(text. initialize(). private int mWidthLimit. AttributeSet attrs. int defStyle) { super(context. } @Override public void setLines(int lines) { super. reAdjust(). } reAdjust(). reAdjust().setLines(lines). mMaxLines = 1.toString()).setMaxLines(maxlines). adjustTextSize(getText(). mTextCachedSizes.java 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: spawrks 09/18/14 } @Override public void setTextSize(float size) { mMaxTextSize = size. } else { mMaxLines = NO_LINE_LIMIT. } @Override public void setSingleLine(boolean singleLine) { super. } @Override public void setTextSize(int unit. 4-3/7(12) .setSingleLine(singleLine).AutoResizeTextView.setSingleLine(). if (singleLine) { mMaxLines = 1. mMaxLines = maxlines. } public int getMaxLines() { return mMaxLines. } @Override public void setSingleLine() { super.clear(). float size) { Context c = getContext(). mMaxLines = lines. } @Override public void setMaxLines(int maxlines) { super. reAdjust(). mSpacingAdd = add. if (c == null) r = Resources. reAdjust().setLineSpacing(add. adjustTextSize(getText().setTextSize( TypedValue.clear(). mult).getCompoundPaddingTop(). mTextCachedSizes.getCompoundPaddingBottom() . mAvailableSpaceRect.getDisplayMetrics()). mAvailableSpaceRect.getResources(). efficientTextSizeSearch(startSize. mAvailableSpaceRect)). int heightLimit = getMeasuredHeight() . size.toString()).toString()). (int) mMaxTextSize.bottom = heightLimit. } /** * Set the lower text size limit and invalidate the view * * @param minTextSize */ public void setMinTextSize(float minTextSize) { mMinTextSize = minTextSize. super. else r = c.COMPLEX_UNIT_PX. mSizeTester.getCompoundPaddingRight(). } @Override public void setLineSpacing(float add. } private void reAdjust() { adjustTextSize(getText(). } int startSize = (int) mMinTextSize. } private void adjustTextSize(String string) { if (!mInitiallized) { return. mSpacingMult = mult. r. float mult) { super.getCompoundPaddingLeft() . mMaxTextSize = TypedValue.AutoResizeTextView. mWidthLimit = getMeasuredWidth() .applyDimension(unit.getSystem().java 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: spawrks 09/18/14 Resources r.right = mWidthLimit. 4-4/7(13) . mTextRect. int maxWidth = -1. if (singleline) { mTextRect. mSpacingAdd. don’t worry we will find the best match return -1.getLineWidth(i).measureText(text). if (availableSPace.VERSION_CODES. mPaint. } else { StaticLayout layout = new StaticLayout(text. // return early if we have more lines if (getMaxLines() != NO_LINE_LIMIT && layout. } mTextRect. } } mTextRect. 0). mSpacingMult. This stores the font * size against getText(). RectF availableSPace) { mPaint.offsetTo(0.getLineCount() > getMaxLines()) { return 1.right = mPaint.bottom = mPaint. enabling it will improve performance * where you are animating a value inside TextView. } } }. * 4-5/7(14) .JELLY_BEAN) @Override public int onTestSize(int suggestedSize. } mTextRect.length() Be careful though while enabling it as 0 * takes more space than 1 on some fonts and so on.getFontSpacing(). for (int i = 0.right = maxWidth.getLineWidth(i)) { maxWidth = (int) layout.ALIGN_NORMAL.toString().setTextSize(suggestedSize). } else { // too big return 1.contains(mTextRect)) { // may be too small. String text = getText(). i < layout.bottom = layout.getHeight(). Alignment. /** * Enables or disables size caching. mWidthLimit.AutoResizeTextView. boolean singleline = getMaxLines() == 1.getLineCount(). i++) { if (maxWidth < layout. true).java 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: spawrks 09/18/14 } private final SizeTester mSizeTester = new SizeTester() { @TargetApi(Build. 1. while (lo <= hi) { mid = (lo + hi) >>> 1. end.toString()). int size = mTextCachedSizes. } else { return mid. if (size != 0) { return size. 4-6/7(15) . } else if (midValCmp > 0) { hi = mid . lo = mid + 1.get(key). int lo = start. RectF availableSpace) { int lastBest = start. int midValCmp = sizeTester. int key = text == null ? 0 : text. availableSpace). int hi = end . int end. } size = binarySearch(start.AutoResizeTextView.onTestSize(mid. } private int efficientTextSizeSearch(int start. return size. } private static int binarySearch(int start. mTextCachedSizes. SizeTester sizeTester.1. mTextCachedSizes. SizeTester sizeTester. int end.toString(). size).java 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: spawrks 09/18/14 * @param enable * enable font size caching */ public void enableSizeCache(boolean enable) { mEnableSizeCache = enable. adjustTextSize(getText().clear().length(). } } // make sure to return last best // this is what should always be returned return lastBest. if (midValCmp < 0) { lastBest = lo. } String text = getText(). sizeTester. availableSpace). int mid = 0. availableSpace). end. sizeTester. lastBest = hi. RectF availableSpace) { if (!mEnableSizeCache) { return binarySearch(start.put(key. before. oldheight). final int before. } } 4-7/7(16) . height.clear(). int height. after). reAdjust().java 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: } spawrks 09/18/14 } @Override protected void onTextChanged(final CharSequence text. if (width != oldwidth || height != oldheight) { reAdjust(). int oldwidth. oldwidth.onTextChanged(text. start.AutoResizeTextView. super. final int after) { super. final int start. int oldheight) { mTextCachedSizes. } @Override protected void onSizeChanged(int width.onSizeChanged(width. e. /** * If set.bartalk.Editable. 5-1/4(17) .MotionEvent.View. */ private static final int HIDER_FLAGS = SystemUiHider. android.bartalk. Otherwise.text.ActionBar. the number of milliseconds to wait after * user interaction before hiding the system UI. /** * If {@link #AUTO_HIDE} is set.FLAG_HIDE_NAVIGATION. android.widget.delta.os.EditText. android. * * @see SystemUiHider */ public class BartalkActivity extends Activity { /** * Whether or not the system UI should be auto-hidden after * {@link #AUTO_HIDE_DELAY_MILLIS} milliseconds.java 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: spawrks 09/18/14 package com. android.TextView. android.delta. import com.Bundle. android. /** * An example full-screen activity that shows and hides the system UI (i. /** * The flags to pass to {@link SystemUiHider#getInstance}. android.annotation.TextWatcher. */ private static final boolean AUTO_HIDE = true.app.Activity.Handler.view. android. */ private static final int AUTO_HIDE_DELAY_MILLIS = 3000.text. */ private static final boolean TOGGLE_ON_CLICK = true.app. * will show the system UI visibility upon interaction.BartalkActivity.widget. android. import import import import import import import import import import import import android.util. will toggle the system UI visibility upon interaction. * status bar and navigation/system bar) with user interaction.SystemUiHider.Build. android. android.TargetApi.view.os.os. java 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: spawrks 09/18/14 /** * The instance of the {@link SystemUiHider} for this activity. // Set up an instance of SystemUiHider to control the system UI for // this activity.fullscreen_content). @Override 5-2/4(18) . int count.fullscreen_content_controls).onCreate(savedInstanceState). } }). int mControlsHeight.input_text). int after){} public void onTextChanged(CharSequence s. mInputText= (EditText) findViewById(R.id. // // Bartalk code // mOutputText = (TextView) findViewById(R. int mShortAnimTime. final View controlsView = findViewById(R.id. int count){ mOutputText. int start. actionBar. mInputText.OnVisibilityChangeListener() { // Cached values. EditText mInputText. int before. int start.fullscreen_content). mSystemUiHider.id. mSystemUiHider = SystemUiHider.BartalkActivity.getInstance(this. HIDER_FLAGS).setup(). contentView. @Override protected void onCreate(Bundle savedInstanceState) { super. */ private SystemUiHider mSystemUiHider. ActionBar actionBar = getActionBar().addTextChangedListener(new TextWatcher(){ public void afterTextChanged(Editable s) {} public void beforeTextChanged(CharSequence s. mSystemUiHider .layout.setOnVisibilityChangeListener(new SystemUiHider. // // Bartalk instance variables // TextView mOutputText.setText(mInputText.getText()). setContentView(R. final View contentView = findViewById(R.id.hide().activity_bartalk). contentView.R.OnClickListener() { @Override public void onClick(View view) { if (TOGGLE_ON_CLICK) { mSystemUiHider. use it to animate the // in-layout UI controls at the bottom of the // screen.setVisibility(visible ? View.animate() . } controlsView. delay any scheduled hide() // operations to prevent the jarring behavior of controls going away // while interacting with the UI. } else { // If the ViewPropertyAnimator APIs aren’t // available.java 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: spawrks 09/18/14 @TargetApi(Build. delayedHide(AUTO_HIDE_DELAY_MILLIS).GONE). 5-3/4(19) .BartalkActivity.VERSION.id. } if (mShortAnimTime == 0) { mShortAnimTime = getResources().translationY(visible ? 0 : mControlsHeight) .input_text).VERSION_CODES.getHeight().setDuration(mShortAnimTime).setOnClickListener(new View. } } }). } } }). if (mControlsHeight == 0) { mControlsHeight = controlsView.HONEYCOMB_MR2) { // If the ViewPropertyAnimator API is available // (Honeycomb MR2 and later). controlsView. } if (visible && AUTO_HIDE) { // Schedule a hide(). } else { mSystemUiHider.integer. // Set up the user interaction to manually show or hide the system UI. simply show or hide the in-layout UI // controls. findViewById(R.HONEYCOMB_MR2) public void onVisibilityChange(boolean visible) { if (Build.SDK_INT >= Build.getInteger( android.config_shortAnimTime).show().setOnTouchListener(mDelayHideTouchListener).VERSION_CODES.VISIBLE : View. // Upon interacting with UI controls.toggle(). delayMillis). mHideHandler. } return false. } 5-4/4(20) . /** * Schedules a call to hide() in [delay] milliseconds. */ View. } }. */ private void delayedHide(int delayMillis) { mHideHandler. to briefly hint to the user that UI controls // are available. // Trigger the initial hide() shortly after the activity has been // created.OnTouchListener mDelayHideTouchListener = new View. MotionEvent motionEvent) { if (AUTO_HIDE) { delayedHide(AUTO_HIDE_DELAY_MILLIS).onPostCreate(savedInstanceState). } }.java 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: } spawrks 09/18/14 } @Override protected void onPostCreate(Bundle savedInstanceState) { super.BartalkActivity.hide(). Handler mHideHandler = new Handler().removeCallbacks(mHideRunnable). delayedHide(100).OnTouchListener() { @Override public boolean onTouch(View view.postDelayed(mHideRunnable. } /** * Touch listener to use for in-layout UI controls to delay hiding the * system UI. canceling any * previously scheduled calls. Runnable mHideRunnable = new Runnable() { @Override public void run() { mSystemUiHider. This is to prevent the jarring behavior of controls going away * while interacting with activity UI. java 3 pages 133 lines 14/03/12 16:02:03 bartalk/src/main/java/com/delta/bartalk/AutoResizeTextView.java 4 pages 172 lines 14/03/12 16:02:03 bartalk/src/main/java/com/delta/bartalk/util/SystemUiHiderBase.java 4 pages 189 lines 14/03/12 16:23:47 -1/1(21) .Table of Contents 1 2 3 4 5 spawrks 09/18/14 bartalk/src/main/java/com/delta/bartalk/util/SystemUiHider.java 7 pages 306 lines 14/03/12 16:20:57 bartalk/src/main/java/com/delta/bartalk/BartalkActivity.java 2 pages 63 lines 14/03/12 16:02:03 bartalk/src/main/java/com/delta/bartalk/util/SystemUiHiderHoneycomb.
Copyright © 2024 DOKUMEN.SITE Inc.