mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 936756 - Part 0: refactor prefs access in GeckoApp. r=mfinkle
This commit is contained in:
parent
2ff750f868
commit
b4b02b1714
@ -1,6 +1,15 @@
|
||||
package org.mozilla.gecko;
|
||||
import android.content.Context;
|
||||
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
interface ContextGetter {
|
||||
Context getContext();
|
||||
package org.mozilla.gecko;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
public interface ContextGetter {
|
||||
Context getContext();
|
||||
SharedPreferences getSharedPreferences();
|
||||
}
|
||||
|
||||
|
@ -126,12 +126,18 @@ import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
abstract public class GeckoApp
|
||||
extends GeckoActivity
|
||||
implements GeckoEventListener, SensorEventListener, LocationListener,
|
||||
Tabs.OnTabsChangedListener, GeckoEventResponder,
|
||||
GeckoMenu.Callback, GeckoMenu.MenuPresenter,
|
||||
ContextGetter, GeckoAppShell.GeckoInterface
|
||||
public abstract class GeckoApp
|
||||
extends GeckoActivity
|
||||
implements
|
||||
ContextGetter,
|
||||
GeckoAppShell.GeckoInterface,
|
||||
GeckoEventListener,
|
||||
GeckoEventResponder,
|
||||
GeckoMenu.Callback,
|
||||
GeckoMenu.MenuPresenter,
|
||||
LocationListener,
|
||||
SensorEventListener,
|
||||
Tabs.OnTabsChangedListener
|
||||
{
|
||||
private static final String LOGTAG = "GeckoApp";
|
||||
|
||||
@ -233,10 +239,20 @@ abstract public class GeckoApp
|
||||
|
||||
void focusChrome() { }
|
||||
|
||||
@Override
|
||||
public Context getContext() {
|
||||
return sAppContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SharedPreferences getSharedPreferences() {
|
||||
return GeckoApp.getAppSharedPreferences();
|
||||
}
|
||||
|
||||
public static SharedPreferences getAppSharedPreferences() {
|
||||
return GeckoApp.sAppContext.getSharedPreferences(GeckoApp.PREFS_NAME, 0);
|
||||
}
|
||||
|
||||
public Activity getActivity() {
|
||||
return this;
|
||||
}
|
||||
@ -258,10 +274,6 @@ abstract public class GeckoApp
|
||||
return this;
|
||||
}
|
||||
|
||||
public static SharedPreferences getAppSharedPreferences() {
|
||||
return GeckoApp.sAppContext.getSharedPreferences(PREFS_NAME, 0);
|
||||
}
|
||||
|
||||
public View getCameraView() {
|
||||
return mCameraView;
|
||||
}
|
||||
|
@ -229,8 +229,7 @@ public class GeckoAppShell
|
||||
}
|
||||
|
||||
if (e instanceof OutOfMemoryError) {
|
||||
SharedPreferences prefs =
|
||||
getContext().getSharedPreferences(GeckoApp.PREFS_NAME, 0);
|
||||
SharedPreferences prefs = getSharedPreferences();
|
||||
SharedPreferences.Editor editor = prefs.edit();
|
||||
editor.putBoolean(GeckoApp.PREFS_OOM_EXCEPTION, true);
|
||||
editor.commit();
|
||||
@ -2146,6 +2145,13 @@ public class GeckoAppShell
|
||||
sContextGetter = cg;
|
||||
}
|
||||
|
||||
public static SharedPreferences getSharedPreferences() {
|
||||
if (sContextGetter == null) {
|
||||
throw new IllegalStateException("No ContextGetter; cannot fetch prefs.");
|
||||
}
|
||||
return sContextGetter.getSharedPreferences();
|
||||
}
|
||||
|
||||
public interface AppStateListener {
|
||||
public void onPause();
|
||||
public void onResume();
|
||||
|
@ -19,6 +19,7 @@ import org.json.JSONObject;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.TypedArray;
|
||||
import android.os.Handler;
|
||||
import android.util.AttributeSet;
|
||||
@ -30,6 +31,7 @@ import java.util.List;
|
||||
public class GeckoView extends LayerView
|
||||
implements GeckoEventListener, ContextGetter {
|
||||
|
||||
private static final String DEFAULT_SHARED_PREFERENCES_FILE = "GeckoView";
|
||||
private static final String LOGTAG = "GeckoView";
|
||||
|
||||
private ChromeDelegate mChromeDelegate;
|
||||
@ -305,6 +307,14 @@ public class GeckoView extends LayerView
|
||||
return GeckoAppShell.getGeckoInterface();
|
||||
}
|
||||
|
||||
protected String getSharedPreferencesFile() {
|
||||
return DEFAULT_SHARED_PREFERENCES_FILE;
|
||||
}
|
||||
|
||||
public SharedPreferences getSharedPreferences() {
|
||||
return getContext().getSharedPreferences(getSharedPreferencesFile(), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for a browser in the GeckoView container. Associated with a browser
|
||||
* element in the Gecko system.
|
||||
|
Loading…
Reference in New Issue
Block a user