|
@@ -16,6 +16,7 @@
|
|
|
*/
|
|
|
package com.owncloud.android.ui.preview;
|
|
|
|
|
|
+import android.annotation.SuppressLint;
|
|
|
import android.content.BroadcastReceiver;
|
|
|
import android.content.ComponentName;
|
|
|
import android.content.Context;
|
|
@@ -23,10 +24,14 @@ import android.content.Intent;
|
|
|
import android.content.IntentFilter;
|
|
|
import android.content.ServiceConnection;
|
|
|
import android.content.SharedPreferences;
|
|
|
+import android.os.Build;
|
|
|
import android.os.Bundle;
|
|
|
+import android.os.Handler;
|
|
|
import android.os.IBinder;
|
|
|
+import android.os.Message;
|
|
|
import android.preference.PreferenceManager;
|
|
|
import android.support.v4.view.ViewPager;
|
|
|
+import android.view.View;
|
|
|
|
|
|
import com.actionbarsherlock.app.ActionBar;
|
|
|
import com.actionbarsherlock.view.MenuItem;
|
|
@@ -70,15 +75,17 @@ ViewPager.OnPageChangeListener, OnRemoteOperationListener {
|
|
|
|
|
|
public static final String KEY_WAITING_TO_PREVIEW = "WAITING_TO_PREVIEW";
|
|
|
private static final String KEY_WAITING_FOR_BINDER = "WAITING_FOR_BINDER";
|
|
|
-
|
|
|
+
|
|
|
+ private static final int INITIAL_HIDE_DELAY = 0; // immediate hide
|
|
|
+
|
|
|
private ExtendedViewPager mViewPager;
|
|
|
private PreviewImagePagerAdapter mPreviewImagePagerAdapter;
|
|
|
|
|
|
private boolean mRequestWaitingForBinder;
|
|
|
|
|
|
private DownloadFinishReceiver mDownloadFinishReceiver;
|
|
|
-
|
|
|
- private boolean mFullScreen;
|
|
|
+
|
|
|
+ private View mFullScreenAnchorView;
|
|
|
|
|
|
|
|
|
@Override
|
|
@@ -96,9 +103,31 @@ ViewPager.OnPageChangeListener, OnRemoteOperationListener {
|
|
|
// PIN CODE request
|
|
|
if (getIntent().getExtras() != null && savedInstanceState == null && fromNotification()) {
|
|
|
requestPinCode();
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Make sure we're running on Honeycomb or higher to use FullScreen and
|
|
|
+ // Immersive Mode
|
|
|
+ if (isHoneycombOrHigher()) {
|
|
|
|
|
|
- mFullScreen = true;
|
|
|
+ mFullScreenAnchorView = getWindow().getDecorView();
|
|
|
+ // to keep our UI controls visibility in line with system bars
|
|
|
+ // visibility
|
|
|
+ mFullScreenAnchorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
|
|
|
+ @SuppressLint("InlinedApi")
|
|
|
+ @Override
|
|
|
+ public void onSystemUiVisibilityChange(int flags) {
|
|
|
+ boolean visible = (flags & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
|
|
|
+ ActionBar actionBar = getSupportActionBar();
|
|
|
+ if (visible) {
|
|
|
+ actionBar.show();
|
|
|
+ } else {
|
|
|
+ actionBar.hide();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
if (savedInstanceState != null) {
|
|
|
mRequestWaitingForBinder = savedInstanceState.getBoolean(KEY_WAITING_FOR_BINDER);
|
|
|
} else {
|
|
@@ -129,6 +158,46 @@ ViewPager.OnPageChangeListener, OnRemoteOperationListener {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ protected void onPostCreate(Bundle savedInstanceState) {
|
|
|
+ super.onPostCreate(savedInstanceState);
|
|
|
+
|
|
|
+ // Trigger the initial hide() shortly after the activity has been
|
|
|
+ // created, to briefly hint to the user that UI controls
|
|
|
+ // are available
|
|
|
+ delayedHide(INITIAL_HIDE_DELAY);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ Handler mHideSystemUiHandler = new Handler() {
|
|
|
+ @Override
|
|
|
+ public void handleMessage(Message msg) {
|
|
|
+ if (isHoneycombOrHigher()) {
|
|
|
+ hideSystemUI(mFullScreenAnchorView);
|
|
|
+ }
|
|
|
+ getSupportActionBar().hide();
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ private void delayedHide(int delayMillis) {
|
|
|
+ mHideSystemUiHandler.removeMessages(0);
|
|
|
+ mHideSystemUiHandler.sendEmptyMessageDelayed(0, delayMillis);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /// handle Window Focus changes
|
|
|
+ @Override
|
|
|
+ public void onWindowFocusChanged(boolean hasFocus) {
|
|
|
+ super.onWindowFocusChanged(hasFocus);
|
|
|
+
|
|
|
+ // When the window loses focus (e.g. the action overflow is shown),
|
|
|
+ // cancel any pending hide action.
|
|
|
+ if (!hasFocus) {
|
|
|
+ mHideSystemUiHandler.removeMessages(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public void onStart() {
|
|
|
super.onStart();
|
|
@@ -390,16 +459,36 @@ ViewPager.OnPageChangeListener, OnRemoteOperationListener {
|
|
|
|
|
|
}
|
|
|
|
|
|
- public void toggleFullScreen() {
|
|
|
- ActionBar actionBar = getSupportActionBar();
|
|
|
- if (mFullScreen) {
|
|
|
- actionBar.show();
|
|
|
-
|
|
|
+ @SuppressLint("InlinedApi")
|
|
|
+ public void toggleFullScreen() {
|
|
|
+
|
|
|
+ if (isHoneycombOrHigher()) {
|
|
|
+
|
|
|
+ boolean visible = (mFullScreenAnchorView.getSystemUiVisibility()
|
|
|
+ & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
|
|
|
+
|
|
|
+ if (visible) {
|
|
|
+ hideSystemUI(mFullScreenAnchorView);
|
|
|
+ // actionBar.hide(); // propagated through
|
|
|
+ // OnSystemUiVisibilityChangeListener()
|
|
|
+ } else {
|
|
|
+ showSystemUI(mFullScreenAnchorView);
|
|
|
+ // actionBar.show(); // propagated through
|
|
|
+ // OnSystemUiVisibilityChangeListener()
|
|
|
+ }
|
|
|
+
|
|
|
} else {
|
|
|
- actionBar.hide();
|
|
|
-
|
|
|
+
|
|
|
+ ActionBar actionBar = getSupportActionBar();
|
|
|
+ if (!actionBar.isShowing()) {
|
|
|
+ actionBar.show();
|
|
|
+
|
|
|
+ } else {
|
|
|
+ actionBar.hide();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
- mFullScreen = !mFullScreen;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -460,5 +549,39 @@ ViewPager.OnPageChangeListener, OnRemoteOperationListener {
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ @SuppressLint("InlinedApi")
|
|
|
+ private void hideSystemUI(View anchorView) {
|
|
|
+ anchorView.setSystemUiVisibility(
|
|
|
+ View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hides NAVIGATION BAR; Android >= 4.0
|
|
|
+ | View.SYSTEM_UI_FLAG_FULLSCREEN // hides STATUS BAR; Android >= 4.1
|
|
|
+ | View.SYSTEM_UI_FLAG_IMMERSIVE // stays interactive; Android >= 4.4
|
|
|
+ | View.SYSTEM_UI_FLAG_LAYOUT_STABLE // draw full window; Android >= 4.1
|
|
|
+ | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN // draw full window; Android >= 4.1
|
|
|
+ | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION // draw full window; Android >= 4.1
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ @SuppressLint("InlinedApi")
|
|
|
+ private void showSystemUI(View anchorView) {
|
|
|
+ anchorView.setSystemUiVisibility(
|
|
|
+ View.SYSTEM_UI_FLAG_LAYOUT_STABLE // draw full window; Android >= 4.1
|
|
|
+ | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN // draw full window; Android >= 4.1
|
|
|
+ | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION // draw full window; Android >= 4.1
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Checks if OS version is Honeycomb one or higher
|
|
|
+ *
|
|
|
+ * @return boolean
|
|
|
+ */
|
|
|
+ private boolean isHoneycombOrHigher() {
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
}
|