*/
package com.owncloud.android.ui.preview;
+import android.annotation.SuppressLint;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.ServiceConnection;
import android.content.SharedPreferences;
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;
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 DownloadFinishReceiver mDownloadFinishReceiver;
- private boolean mFullScreen;
+ //private boolean mFullScreen;
+
+ private View mFullScreenAnchorView;
@Override
requestPinCode();
}
- mFullScreen = true;
+ //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 {
}
+ 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) {
+ 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. When the window gains focus,
+ // hide the system UI.
+ if (hasFocus) {
+ delayedHide(INITIAL_HIDE_DELAY);
+ } else {
+ mHideSystemUiHandler.removeMessages(0);
+ }
+ }
+
+
+
@Override
public void onStart() {
super.onStart();
}
- public void toggleFullScreen() {
- ActionBar actionBar = getSupportActionBar();
+ @SuppressLint("InlinedApi")
+ public void toggleFullScreen() {
+ //ActionBar actionBar = getSupportActionBar();
+
+ 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()
+ }
+ /*
if (mFullScreen) {
actionBar.show();
}
mFullScreen = !mFullScreen;
+ */
}
@Override
// 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
+ );
+ }
+
+
}