first version of custom fullscreen preference (fix for #594)
This commit is contained in:
parent
7230e2f44a
commit
8d1eb6e0b7
@ -79,14 +79,16 @@
|
||||
<string name="pref_user_loc_sum">Show users position on map</string>
|
||||
<string name="pref_user_zoom">Show zoom control</string>
|
||||
<string name="pref_user_zoom_sum">Shows +/- buttons even on multitouch capable devices.</string>
|
||||
<string name="pref_fullscreen_actionbar">Hide Action Bar in fullscreen mode</string>
|
||||
<string name="pref_fullscreen_actionbar_sum">Nice for screenshots. Note: IITCm can still be controlled via the Navigation Drawers</string>
|
||||
<string name="pref_fullscreen">Hide in fullscreen mode</string>
|
||||
<string name="pref_fullscreen_sum">Which elements should be hidden in fullscreen mode.
|
||||
Note: IITCm can still be controlled via the Navigation Drawers</string>
|
||||
<string name="pref_force_desktop">Force desktop mode</string>
|
||||
<string name="pref_force_desktop_sum">Nice for tablets, looks awful on smartphones</string>
|
||||
<string name="pref_force_https">Force https</string>
|
||||
<string name="pref_force_https_sum">Disabling may improve performance</string>
|
||||
<string name="pref_external_storage">Move cache to external storage</string>
|
||||
<string name="pref_external_storage_sum">Restart required! Write cache to sdCard. Saves internal storage. External storage has to be mounted.</string>
|
||||
<string name="pref_external_storage_sum">Restart required! Write cache to sdCard. Saves internal storage.
|
||||
External storage has to be mounted.</string>
|
||||
<string name="pref_press_twice_to_exit">Press back button twice to exit</string>
|
||||
<string name="pref_press_twice_to_exit_sum">Avoids accidental exits</string>
|
||||
<string name="pref_advanced_options">Advanced settings</string>
|
||||
@ -106,6 +108,20 @@
|
||||
<string name="pref_caching">Aggressive Caching</string>
|
||||
<string name="pref_caching_sum">Prefer cached values even if they are expired…saves traffic but
|
||||
may result in login issues</string>
|
||||
|
||||
<string-array name="pref_hide_fullscreen">
|
||||
<item>System Bar</item>
|
||||
<item>Action Bar</item>
|
||||
<item>IITC Status Bar</item>
|
||||
<item>Navigation Bar</item>
|
||||
</string-array>
|
||||
<string-array name="pref_hide_fullscreen_vals">
|
||||
<item>2</item>
|
||||
<item>4</item>
|
||||
<item>8</item>
|
||||
<item>16</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="pref_caching_array">
|
||||
<item>Always</item>
|
||||
<item>Mobile data only (default)</item>
|
||||
|
@ -24,11 +24,12 @@
|
||||
android:key="pref_user_zoom"
|
||||
android:summary="@string/pref_user_zoom_sum"
|
||||
android:title="@string/pref_user_zoom"/>
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="true"
|
||||
android:key="pref_fullscreen_actionbar"
|
||||
android:summary="@string/pref_fullscreen_actionbar_sum"
|
||||
android:title="@string/pref_fullscreen_actionbar"/>
|
||||
<MultiSelectListPreference
|
||||
android:key="pref_fullscreen"
|
||||
android:summary="@string/pref_fullscreen_sum"
|
||||
android:title="@string/pref_fullscreen"
|
||||
android:entries="@array/pref_hide_fullscreen"
|
||||
android:entryValues="@array/pref_hide_fullscreen_vals"/>
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="false"
|
||||
android:key="pref_force_desktop"
|
||||
|
@ -22,7 +22,6 @@ import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.webkit.CookieManager;
|
||||
import android.webkit.WebView;
|
||||
import android.widget.SearchView;
|
||||
@ -45,7 +44,6 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
||||
private boolean mIsLocEnabled = false;
|
||||
private Location mLastLocation = null;
|
||||
private LocationManager mLocMngr = null;
|
||||
private boolean mFullscreenMode = false;
|
||||
private IITC_DeviceAccountLogin mLogin;
|
||||
private MenuItem mSearchMenuItem;
|
||||
private boolean mDesktopMode = false;
|
||||
@ -72,11 +70,6 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
||||
setContentView(R.layout.activity_main);
|
||||
mIitcWebView = (IITC_WebView) findViewById(R.id.iitc_webview);
|
||||
|
||||
// pass ActionBar to helper because we deprecated getActionBar
|
||||
mNavigationHelper = new IITC_NavigationHelper(this, super.getActionBar());
|
||||
|
||||
mMapSettings = new IITC_MapSettings(this);
|
||||
|
||||
// do something if user changed something in the settings
|
||||
mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
mSharedPrefs.registerOnSharedPreferenceChangeListener(this);
|
||||
@ -87,6 +80,9 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
||||
// enable/disable advance menu
|
||||
mAdvancedMenu = mSharedPrefs.getBoolean("pref_advanced_menu", false);
|
||||
|
||||
// get fullscreen status from settings
|
||||
mIitcWebView.updateFullscreenStatus();
|
||||
|
||||
// Acquire a reference to the system Location Manager
|
||||
mLocMngr = (LocationManager) this
|
||||
.getSystemService(Context.LOCATION_SERVICE);
|
||||
@ -101,6 +97,12 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
||||
this);
|
||||
}
|
||||
|
||||
// pass ActionBar to helper because we deprecated getActionBar
|
||||
mNavigationHelper = new IITC_NavigationHelper(this, super.getActionBar());
|
||||
|
||||
mMapSettings = new IITC_MapSettings(this);
|
||||
|
||||
|
||||
// Clear the back stack
|
||||
mBackStack.clear();
|
||||
|
||||
@ -114,9 +116,9 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
||||
mDesktopMode = sharedPreferences.getBoolean("pref_force_desktop", false);
|
||||
mNavigationHelper.onPrefChanged();
|
||||
} else if (key.equals("pref_user_loc")) {
|
||||
mIsLocEnabled = sharedPreferences.getBoolean("pref_user_loc",
|
||||
false);
|
||||
} else if (key.equals("pref_fullscreen_actionbar")) {
|
||||
mIsLocEnabled = sharedPreferences.getBoolean("pref_user_loc", false);
|
||||
} else if (key.equals("pref_fullscreen")) {
|
||||
mIitcWebView.updateFullscreenStatus();
|
||||
mNavigationHelper.onPrefChanged();
|
||||
return;
|
||||
} else if (key.equals("pref_advanced_menu")) {
|
||||
@ -330,8 +332,8 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
// exit fullscreen mode if it is enabled and action bar is disabled or the back stack is empty
|
||||
if (mFullscreenMode && (mBackStack.isEmpty() || mNavigationHelper.hideInFullscreen())) {
|
||||
toggleFullscreen();
|
||||
if (mIitcWebView.isInFullscreen() && mBackStack.isEmpty()) {
|
||||
mIitcWebView.toggleFullscreen();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -456,7 +458,7 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
||||
reloadIITC();
|
||||
return true;
|
||||
case R.id.toggle_fullscreen:
|
||||
toggleFullscreen();
|
||||
mIitcWebView.toggleFullscreen();
|
||||
return true;
|
||||
case R.id.layer_chooser:
|
||||
mNavigationHelper.openRightDrawer();
|
||||
@ -549,16 +551,6 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
||||
}
|
||||
}
|
||||
|
||||
public void toggleFullscreen() {
|
||||
mFullscreenMode = !mFullscreenMode;
|
||||
mNavigationHelper.setFullscreen(mFullscreenMode);
|
||||
|
||||
// toggle notification bar
|
||||
WindowManager.LayoutParams attrs = getWindow().getAttributes();
|
||||
attrs.flags ^= WindowManager.LayoutParams.FLAG_FULLSCREEN;
|
||||
this.getWindow().setAttributes(attrs);
|
||||
}
|
||||
|
||||
public IITC_WebView getWebView() {
|
||||
return this.mIitcWebView;
|
||||
}
|
||||
|
@ -20,7 +20,6 @@ import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class IITC_NavigationHelper extends ActionBarDrawerToggle implements OnItemClickListener {
|
||||
// Show/hide the up arrow on the very left
|
||||
@ -111,9 +110,7 @@ public class IITC_NavigationHelper extends ActionBarDrawerToggle implements OnIt
|
||||
private final View mDrawerRight;
|
||||
|
||||
private boolean mDesktopMode = false;
|
||||
private boolean mFullscreen = false;
|
||||
private boolean mIsLoading;
|
||||
private boolean mHideInFullscreen = false;
|
||||
private Pane mPane = Pane.MAP;
|
||||
private String mHighlighter = null;
|
||||
|
||||
@ -232,12 +229,6 @@ public class IITC_NavigationHelper extends ActionBarDrawerToggle implements OnIt
|
||||
} else {
|
||||
mActionBar.setSubtitle(mHighlighter);
|
||||
}
|
||||
|
||||
if (mFullscreen && mHideInFullscreen) {
|
||||
mActionBar.hide();
|
||||
} else {
|
||||
mActionBar.show();
|
||||
}
|
||||
}
|
||||
|
||||
public void closeDrawers() {
|
||||
@ -263,10 +254,6 @@ public class IITC_NavigationHelper extends ActionBarDrawerToggle implements OnIt
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hideInFullscreen() {
|
||||
return mHideInFullscreen;
|
||||
}
|
||||
|
||||
public boolean isDrawerOpened() {
|
||||
return mDrawerLayout.isDrawerOpen(mDrawerLeft) || mDrawerLayout.isDrawerOpen(mDrawerRight);
|
||||
}
|
||||
@ -275,6 +262,7 @@ public class IITC_NavigationHelper extends ActionBarDrawerToggle implements OnIt
|
||||
public void onDrawerClosed(View drawerView) {
|
||||
super.onDrawerClosed(drawerView);
|
||||
|
||||
mIitc.getWebView().onWindowFocusChanged(true);
|
||||
// delay invalidating to prevent flickering in case another drawer is opened
|
||||
(new Handler()).postDelayed(new Runnable() {
|
||||
@Override
|
||||
@ -288,6 +276,7 @@ public class IITC_NavigationHelper extends ActionBarDrawerToggle implements OnIt
|
||||
@Override
|
||||
public void onDrawerOpened(View drawerView) {
|
||||
super.onDrawerOpened(drawerView);
|
||||
mIitc.getWebView().onWindowFocusChanged(false);
|
||||
mIitc.invalidateOptionsMenu();
|
||||
updateActionBar();
|
||||
mDrawerLayout.closeDrawer(drawerView.equals(mDrawerLeft) ? mDrawerRight : mDrawerLeft);
|
||||
@ -321,7 +310,6 @@ public class IITC_NavigationHelper extends ActionBarDrawerToggle implements OnIt
|
||||
|
||||
public void onPrefChanged() {
|
||||
mDesktopMode = mPrefs.getBoolean("pref_force_desktop", false);
|
||||
mHideInFullscreen = mPrefs.getBoolean("pref_fullscreen_actionbar", true);
|
||||
updateActionBar();
|
||||
}
|
||||
|
||||
@ -343,16 +331,6 @@ public class IITC_NavigationHelper extends ActionBarDrawerToggle implements OnIt
|
||||
}
|
||||
}
|
||||
|
||||
public void setFullscreen(boolean fullscreen) {
|
||||
mFullscreen = fullscreen;
|
||||
if (mFullscreen && mHideInFullscreen) {
|
||||
// show a toast with instructions to exit the fullscreen mode again
|
||||
Toast.makeText(mIitc, "Press back button to exit fullscreen", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
updateActionBar();
|
||||
}
|
||||
|
||||
public void setHighlighter(String name) {
|
||||
mHighlighter = name;
|
||||
updateActionBar();
|
||||
@ -368,4 +346,12 @@ public class IITC_NavigationHelper extends ActionBarDrawerToggle implements OnIt
|
||||
|
||||
updateActionBar();
|
||||
}
|
||||
|
||||
public void showActionBar() {
|
||||
mActionBar.show();
|
||||
}
|
||||
|
||||
public void hideActionBar() {
|
||||
mActionBar.hide();
|
||||
}
|
||||
}
|
||||
|
@ -11,32 +11,47 @@ import android.os.Build;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.webkit.ConsoleMessage;
|
||||
import android.webkit.GeolocationPermissions;
|
||||
import android.webkit.WebChromeClient;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.cradle.iitc_mobile.async.CheckHttpResponse;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@SuppressLint("SetJavaScriptEnabled")
|
||||
public class IITC_WebView extends WebView {
|
||||
|
||||
// fullscreen modes
|
||||
public static final int FS_ENABLED = (1 << 0);
|
||||
public static final int FS_SYSBAR = (1 << 1);
|
||||
public static final int FS_ACTIONBAR = (1 << 2);
|
||||
public static final int FS_STATUSBAR = (1 << 3);
|
||||
public static final int FS_NAVBAR = (1 << 4);
|
||||
|
||||
private WebSettings mSettings;
|
||||
private IITC_WebViewClient mIitcWebViewClient;
|
||||
private IITC_JSInterface mJsInterface;
|
||||
private Context mContext;
|
||||
private IITC_Mobile mIitc;
|
||||
private SharedPreferences mSharedPrefs;
|
||||
private int mFullscreenStatus = 0;
|
||||
private Runnable mNavHider;
|
||||
private boolean mDisableJs = false;
|
||||
private String mDefaultUserAgent;
|
||||
private final String mDesktopUserAgent = "Mozilla/5.0 (X11; Linux x86_64; rv:17.0)" +
|
||||
" Gecko/20130810 Firefox/17.0 Iceweasel/17.0.8";
|
||||
|
||||
|
||||
// init web view
|
||||
private void iitc_init(Context c) {
|
||||
if (isInEditMode()) return;
|
||||
mContext = c;
|
||||
mIitc = (IITC_Mobile) c;
|
||||
mSettings = getSettings();
|
||||
mSettings.setJavaScriptEnabled(true);
|
||||
mSettings.setDomStorageEnabled(true);
|
||||
@ -45,12 +60,21 @@ public class IITC_WebView extends WebView {
|
||||
mSettings.setAppCacheEnabled(true);
|
||||
mSettings.setDatabasePath(getContext().getApplicationInfo().dataDir + "/databases/");
|
||||
mSettings.setAppCachePath(getContext().getCacheDir().getAbsolutePath());
|
||||
mJsInterface = new IITC_JSInterface((IITC_Mobile) mContext);
|
||||
mJsInterface = new IITC_JSInterface(mIitc);
|
||||
addJavascriptInterface(mJsInterface, "android");
|
||||
mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
|
||||
mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(mIitc);
|
||||
mDefaultUserAgent = mSettings.getUserAgentString();
|
||||
setUserAgent();
|
||||
|
||||
mNavHider = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (isInFullscreen() && (getFullscreenStatus() & (FS_NAVBAR)) != 0) {
|
||||
setSystemUiVisibility(SYSTEM_UI_FLAG_HIDE_NAVIGATION);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
setWebChromeClient(new WebChromeClient() {
|
||||
/**
|
||||
* our webchromeclient should share geolocation with the iitc script
|
||||
@ -81,7 +105,7 @@ public class IITC_WebView extends WebView {
|
||||
@Override
|
||||
public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
|
||||
if (consoleMessage.messageLevel() == ConsoleMessage.MessageLevel.ERROR) {
|
||||
((IITC_Mobile) getContext()).setLoadingState(false);
|
||||
mIitc.setLoadingState(false);
|
||||
}
|
||||
return super.onConsoleMessage(consoleMessage);
|
||||
}
|
||||
@ -142,12 +166,84 @@ public class IITC_WebView extends WebView {
|
||||
}
|
||||
|
||||
// disable splash screen if a http error code is responded
|
||||
new CheckHttpResponse(mJsInterface, mContext).execute(url);
|
||||
new CheckHttpResponse(mJsInterface, mIitc).execute(url);
|
||||
Log.d("iitcm", "loading url: " + url);
|
||||
}
|
||||
super.loadUrl(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
getHandler().removeCallbacks(mNavHider);
|
||||
getHandler().postDelayed(mNavHider, 2000);
|
||||
return super.onTouchEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSystemUiVisibility(int visibility) {
|
||||
getHandler().postDelayed(mNavHider, 2000);
|
||||
super.setSystemUiVisibility(visibility);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWindowFocusChanged(boolean hasWindowFocus) {
|
||||
if (hasWindowFocus) {
|
||||
getHandler().postDelayed(mNavHider, 2000);
|
||||
} else {
|
||||
getHandler().removeCallbacks(mNavHider);
|
||||
}
|
||||
super.onWindowFocusChanged(hasWindowFocus);
|
||||
}
|
||||
|
||||
public void toggleFullscreen() {
|
||||
mFullscreenStatus ^= FS_ENABLED;
|
||||
|
||||
WindowManager.LayoutParams attrs = mIitc.getWindow().getAttributes();
|
||||
// toggle notification bar
|
||||
if (isInFullscreen()) {
|
||||
// show a toast with instructions to exit the fullscreen mode again
|
||||
Toast.makeText(mIitc, "Press back button to exit fullscreen", Toast.LENGTH_SHORT).show();
|
||||
if ((mFullscreenStatus & FS_ACTIONBAR) != 0) {
|
||||
mIitc.getNavigationHelper().hideActionBar();
|
||||
}
|
||||
if ((mFullscreenStatus & FS_SYSBAR) != 0) {
|
||||
attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
|
||||
}
|
||||
if ((mFullscreenStatus & FS_NAVBAR) != 0) {
|
||||
setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
|
||||
}
|
||||
if ((mFullscreenStatus & FS_STATUSBAR) != 0) {
|
||||
loadUrl("javascript: $('#updatestatus').hide();");
|
||||
}
|
||||
} else {
|
||||
attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
|
||||
mIitc.getNavigationHelper().showActionBar();
|
||||
loadUrl("javascript: $('#updatestatus').show();");
|
||||
}
|
||||
mIitc.getWindow().setAttributes(attrs);
|
||||
}
|
||||
|
||||
void updateFullscreenStatus() {
|
||||
Set<String> entries = mSharedPrefs.getStringSet("pref_fullscreen", new HashSet<String>());
|
||||
mFullscreenStatus &= FS_ENABLED;
|
||||
|
||||
// default values...android has no nice way to add default values to multiSelectListPreferences
|
||||
if (entries.isEmpty()) {
|
||||
mFullscreenStatus += FS_ACTIONBAR | FS_SYSBAR;
|
||||
}
|
||||
for (String entry : entries) {
|
||||
mFullscreenStatus += Integer.parseInt(entry);
|
||||
}
|
||||
}
|
||||
|
||||
int getFullscreenStatus() {
|
||||
return mFullscreenStatus;
|
||||
}
|
||||
|
||||
public boolean isInFullscreen() {
|
||||
return (mFullscreenStatus & FS_ENABLED) != 0;
|
||||
}
|
||||
|
||||
public IITC_WebViewClient getWebViewClient() {
|
||||
return mIitcWebViewClient;
|
||||
}
|
||||
@ -210,5 +306,4 @@ public class IITC_WebView extends WebView {
|
||||
Log.d("iitcm", "setting user agent to: " + ua);
|
||||
mSettings.setUserAgentString(ua);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user