ActionBar
to implement the recommended
* design for navigation drawers.
*/
- private ActionBarDrawerToggle mDrawerToggle;
+ private static ActionBarDrawerToggle mDrawerToggle;
/*
* The Drawer Layout
*/
- private CustomDrawerLayout mDrawerLayout;
- private GoodScrollView verticalScroll;
- private String sFilePath = "";
- private Editor mEditor;
- private HorizontalScrollView horizontalScroll;
+ private static CustomDrawerLayout mDrawerLayout;
+ private static GoodScrollView verticalScroll;
+ private static String sFilePath = "";
+ private static Editor mEditor;
+ private static HorizontalScrollView horizontalScroll;
private boolean searchingText;
- private SearchResult searchResult;
- private PageSystem pageSystem;
- private PageSystemButtons pageSystemButtons;
- private String currentEncoding = "UTF-8";
- private Toolbar toolbar;
+ private static SearchResult searchResult;
+ private static PageSystem pageSystem;
+ private static PageSystemButtons pageSystemButtons;
+ private static String currentEncoding = "UTF-8";
+ private static Toolbar toolbar;
/*
Navigation Drawer
*/
- private AdapterDrawer arrayAdapter;
- private LinkedListThe {@link #FLAG_IMMERSIVE_STICKY} flag can be used to control how the system bars are + * displayed. + */ + public static final int LEVEL_IMMERSIVE = 3; + + /** + * 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. + *
+ * This flag isn't used on newer devices because the action + * bar, 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; + + /** + * Used with {@link #LEVEL_IMMERSIVE}. When this flag is set, an inward swipe in the system + * bars areas will cause the system bars to temporarily appear in a semi-transparent state, + * but no flags are cleared, and your system UI visibility change listeners are not triggered. + * The bars automatically hide again after a short delay, or if the user interacts with the + * middle of the screen. + */ + public static final int FLAG_IMMERSIVE_STICKY = 0x2; + + private static final String LOG_TAG = SystemUiHelper.class.getSimpleName(); + + private final SystemUiHelperImpl mImpl; + + private final Handler mHandler; + private final Runnable mHideRunnable; + + /** + * Construct a new SystemUiHelper. + * + * @param activity The Activity who's system UI should be changed + * @param level The level of hiding. Should be either {@link #LEVEL_LOW_PROFILE}, + * {@link #LEVEL_HIDE_STATUS_BAR}, {@link #LEVEL_LEAN_BACK} or + * {@link #LEVEL_IMMERSIVE} + * @param flags Additional options. See {@link #FLAG_LAYOUT_IN_SCREEN_OLDER_DEVICES} and + * {@link #FLAG_IMMERSIVE_STICKY} + */ + public SystemUiHelper(Activity activity, int level, int flags) { + this(activity, level, flags, null); + } + + /** + * Construct a new SystemUiHelper. + * + * @param activity The Activity who's system UI should be changed + * @param level The level of hiding. Should be either {@link #LEVEL_LOW_PROFILE}, + * {@link #LEVEL_HIDE_STATUS_BAR}, {@link #LEVEL_LEAN_BACK} or + * {@link #LEVEL_IMMERSIVE} + * @param flags Additional options. See {@link #FLAG_LAYOUT_IN_SCREEN_OLDER_DEVICES} and + * {@link #FLAG_IMMERSIVE_STICKY} + * @param listener A listener which is called when the system visibility is changed + */ + public SystemUiHelper(Activity activity, int level, int flags, + OnVisibilityChangeListener listener) { + + mHandler = new Handler(Looper.getMainLooper()); + mHideRunnable = new HideRunnable(); + + // Create impl + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + mImpl = new SystemUiHelperImplKK(activity, level, flags, listener); + } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + mImpl = new SystemUiHelperImplJB(activity, level, flags, listener); + } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { + mImpl = new SystemUiHelperImplICS(activity, level, flags, listener); + } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { + mImpl = new SystemUiHelperImplHC(activity, level, flags, listener); + } else { + mImpl = new SystemUiHelperImplBase(activity, level, flags, listener); + } + } + + /** + * @return true if the system UI is currently showing. What this means depends on the mode this + * {@link android.example.android.systemuivis.SystemUiHelper} was instantiated with. + */ + public boolean isShowing() { + return mImpl.isShowing(); + } + + /** + * Show the system UI. What this means depends on the mode this {@link android.example.android.systemuivis.SystemUiHelper} was + * instantiated with. + * + *
Any currently queued delayed hide requests will be removed. + */ + public void show() { + // Ensure that any currently queued hide calls are removed + removeQueuedRunnables(); + + mImpl.show(); + } + + /** + * Hide the system UI. What this means depends on the mode this {@link android.example.android.systemuivis.SystemUiHelper} was + * instantiated with. + * + *
Any currently queued delayed hide requests will be removed. + */ + public void hide() { + // Ensure that any currently queued hide calls are removed + removeQueuedRunnables(); + + mImpl.hide(); + } + + /** + * Request that the system UI is hidden after a delay. + * + *
Any currently queued delayed hide requests will be removed.
+ *
+ * @param delayMillis The delay (in milliseconds) until the Runnable
+ * will be executed.
+ */
+ public void delayHide(long delayMillis) {
+ // Ensure that any currently queued hide calls are removed
+ removeQueuedRunnables();
+
+ mHandler.postDelayed(mHideRunnable, delayMillis);
+ }
+
+ /**
+ * Toggle whether the system UI is displayed.
+ */
+ public void toggle() {
+ if (mImpl.isShowing()) {
+ mImpl.hide();
+ } else {
+ mImpl.show();
+ }
+ }
+
+ private void removeQueuedRunnables() {
+ // Ensure that any currently queued hide calls are removed
+ mHandler.removeCallbacks(mHideRunnable);
+ }
+
+ /**
+ * 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.
+ */
+ public void onVisibilityChange(boolean visible);
+ }
+
+ static abstract class SystemUiHelperImpl {
+
+ final Activity mActivity;
+ final int mLevel;
+ final int mFlags;
+ final OnVisibilityChangeListener mOnVisibilityChangeListener;
+
+ boolean mIsShowing = true;
+
+ SystemUiHelperImpl(Activity activity, int level, int flags,
+ OnVisibilityChangeListener onVisibilityChangeListener) {
+ mActivity = activity;
+ mLevel = level;
+ mFlags = flags;
+ mOnVisibilityChangeListener = onVisibilityChangeListener;
+ }
+
+ abstract void show();
+ abstract void hide();
+
+ boolean isShowing() {
+ return mIsShowing;
+ }
+
+ void setIsShowing(boolean isShowing) {
+ mIsShowing = isShowing;
+
+ if (mOnVisibilityChangeListener != null) {
+ mOnVisibilityChangeListener.onVisibilityChange(mIsShowing);
+ }
+ }
+ }
+
+ /**
+ * Base implementation. Used on API level 10 and below.
+ */
+ static class SystemUiHelperImplBase extends SystemUiHelperImpl {
+
+ SystemUiHelperImplBase(Activity activity, int level, int flags,
+ OnVisibilityChangeListener onVisibilityChangeListener) {
+ super(activity, level, flags, onVisibilityChangeListener);
+
+ if ((mFlags & SystemUiHelper.FLAG_LAYOUT_IN_SCREEN_OLDER_DEVICES) != 0) {
+ mActivity.getWindow().addFlags(
+ WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
+ | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
+ }
+ }
+
+ @Override
+ void show() {
+ if (mLevel > SystemUiHelper.LEVEL_LOW_PROFILE) {
+ mActivity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
+ setIsShowing(true);
+ }
+ }
+
+ @Override
+ void hide() {
+ if (mLevel > SystemUiHelper.LEVEL_LOW_PROFILE) {
+ mActivity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
+ setIsShowing(false);
+ }
+ }
+ }
+
+ private class HideRunnable implements Runnable {
+ @Override
+ public void run() {
+ hide();
+ }
+ }
+
+}
diff --git a/libraries/sharedCode/src/main/java/sharedcode/turboeditor/util/systemui/SystemUiHelperImplHC.java b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/util/systemui/SystemUiHelperImplHC.java
new file mode 100644
index 0000000..431f6d8
--- /dev/null
+++ b/libraries/sharedCode/src/main/java/sharedcode/turboeditor/util/systemui/SystemUiHelperImplHC.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2014 Vlad Mihalachi
+ *
+ * This file is part of Turbo Editor.
+ *
+ * Turbo Editor is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Turbo Editor is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see