Fixing various bugs across platforms
This commit is contained in:
parent
71a416d8f7
commit
a50ca828e8
|
@ -39,7 +39,7 @@
|
|||
android:focusable="false"
|
||||
android:clickable="false"
|
||||
android:tintMode="src_in"
|
||||
android:tint="?android:attr/textColorPrimary"
|
||||
android:tint="@color/primary_text_default_material_dark"
|
||||
android:background="?android:selectableItemBackground"
|
||||
android:visibility="gone"
|
||||
android:src="@drawable/info" />
|
||||
|
@ -51,7 +51,7 @@
|
|||
android:focusable="false"
|
||||
android:clickable="false"
|
||||
android:tintMode="src_in"
|
||||
android:tint="?android:attr/textColorPrimary"
|
||||
android:tint="@color/primary_text_default_material_dark"
|
||||
android:background="?android:selectableItemBackground"
|
||||
android:src="@drawable/settings" />
|
||||
|
||||
|
|
|
@ -4,11 +4,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/action_bar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="?attr/actionBarSize" />
|
||||
<include layout="@layout/toolbar" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/content_wrapper"
|
||||
|
|
297
src/android/support/v4/preference/PreferenceFragment.java
Normal file
297
src/android/support/v4/preference/PreferenceFragment.java
Normal file
|
@ -0,0 +1,297 @@
|
|||
package android.support.v4.preference;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.preference.PreferenceScreen;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ListView;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public abstract class PreferenceFragment extends Fragment {
|
||||
|
||||
private static final int FIRST_REQUEST_CODE = 100;
|
||||
private static final int MSG_BIND_PREFERENCES = 1;
|
||||
private static final String PREFERENCES_TAG = "android:preferences";
|
||||
private boolean mHavePrefs;
|
||||
private boolean mInitDone;
|
||||
private ListView mList;
|
||||
private PreferenceManager mPreferenceManager;
|
||||
|
||||
private Handler mHandler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
switch (msg.what) {
|
||||
|
||||
case MSG_BIND_PREFERENCES:
|
||||
bindPreferences();
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
final private Runnable mRequestFocus = new Runnable() {
|
||||
public void run() {
|
||||
mList.focusableViewAvailable(mList);
|
||||
}
|
||||
};
|
||||
|
||||
private void bindPreferences() {
|
||||
PreferenceScreen localPreferenceScreen = getPreferenceScreen();
|
||||
if (localPreferenceScreen != null) {
|
||||
ListView localListView = getListView();
|
||||
localPreferenceScreen.bind(localListView);
|
||||
}
|
||||
}
|
||||
|
||||
private void ensureList() {
|
||||
if (mList == null) {
|
||||
View view = getView();
|
||||
if (view == null) {
|
||||
throw new IllegalStateException("Content view not yet created");
|
||||
}
|
||||
|
||||
View listView = view.findViewById(android.R.id.list);
|
||||
if (!(listView instanceof ListView)) {
|
||||
throw new RuntimeException(
|
||||
"Content has view with id attribute 'android.R.id.list' that is not a ListView class");
|
||||
}
|
||||
|
||||
mList = (ListView) listView;
|
||||
if (mList == null) {
|
||||
throw new RuntimeException(
|
||||
"Your content must have a ListView whose id attribute is 'android.R.id.list'");
|
||||
}
|
||||
|
||||
mHandler.post(mRequestFocus);
|
||||
}
|
||||
}
|
||||
|
||||
private void postBindPreferences() {
|
||||
if (mHandler.hasMessages(MSG_BIND_PREFERENCES)) {
|
||||
mHandler.obtainMessage(MSG_BIND_PREFERENCES).sendToTarget();
|
||||
}
|
||||
}
|
||||
|
||||
private void requirePreferenceManager() {
|
||||
if (this.mPreferenceManager == null) {
|
||||
throw new RuntimeException("This should be called after super.onCreate.");
|
||||
}
|
||||
}
|
||||
|
||||
public void addPreferencesFromIntent(Intent intent) {
|
||||
requirePreferenceManager();
|
||||
PreferenceScreen screen = inflateFromIntent(intent, getPreferenceScreen());
|
||||
setPreferenceScreen(screen);
|
||||
}
|
||||
|
||||
public void addPreferencesFromResource(int resId) {
|
||||
requirePreferenceManager();
|
||||
PreferenceScreen screen = inflateFromResource(getActivity(), resId, getPreferenceScreen());
|
||||
setPreferenceScreen(screen);
|
||||
}
|
||||
|
||||
public Preference findPreference(CharSequence key) {
|
||||
if (mPreferenceManager == null) {
|
||||
return null;
|
||||
}
|
||||
return mPreferenceManager.findPreference(key);
|
||||
}
|
||||
|
||||
public ListView getListView() {
|
||||
ensureList();
|
||||
return mList;
|
||||
}
|
||||
|
||||
public PreferenceManager getPreferenceManager() {
|
||||
return mPreferenceManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
getListView().setScrollBarStyle(0);
|
||||
if (mHavePrefs) {
|
||||
bindPreferences();
|
||||
}
|
||||
mInitDone = true;
|
||||
if (savedInstanceState != null) {
|
||||
Bundle localBundle = savedInstanceState.getBundle(PREFERENCES_TAG);
|
||||
if (localBundle != null) {
|
||||
PreferenceScreen screen = getPreferenceScreen();
|
||||
if (screen != null) {
|
||||
screen.restoreHierarchyState(localBundle);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
dispatchActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle paramBundle) {
|
||||
super.onCreate(paramBundle);
|
||||
mPreferenceManager = createPreferenceManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater paramLayoutInflater, ViewGroup paramViewGroup,
|
||||
Bundle paramBundle) {
|
||||
ListView listView = new ListView(paramLayoutInflater.getContext());
|
||||
listView.setId(android.R.id.list);
|
||||
listView.setDrawSelectorOnTop(false);
|
||||
listView.setPadding(12, 6, 12, 0);
|
||||
//listView.setSelector(null);
|
||||
return listView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
dispatchActivityDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
mList = null;
|
||||
mHandler.removeCallbacks(mRequestFocus);
|
||||
mHandler.removeMessages(MSG_BIND_PREFERENCES);
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle bundle) {
|
||||
super.onSaveInstanceState(bundle);
|
||||
PreferenceScreen screen = getPreferenceScreen();
|
||||
if (screen != null) {
|
||||
Bundle localBundle = new Bundle();
|
||||
screen.saveHierarchyState(localBundle);
|
||||
bundle.putBundle(PREFERENCES_TAG, localBundle);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
dispatchActivityStop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Access methods with visibility private *
|
||||
*/
|
||||
|
||||
private PreferenceManager createPreferenceManager() {
|
||||
try {
|
||||
Constructor<PreferenceManager> c = PreferenceManager.class
|
||||
.getDeclaredConstructor(Activity.class, int.class);
|
||||
c.setAccessible(true);
|
||||
return c.newInstance(this.getActivity(), FIRST_REQUEST_CODE);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private PreferenceScreen getPreferenceScreen() {
|
||||
try {
|
||||
Method m = PreferenceManager.class.getDeclaredMethod("getPreferenceScreen");
|
||||
m.setAccessible(true);
|
||||
return (PreferenceScreen) m.invoke(mPreferenceManager);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void setPreferenceScreen(PreferenceScreen preferenceScreen) {
|
||||
try {
|
||||
Method m = PreferenceManager.class
|
||||
.getDeclaredMethod("setPreferences", PreferenceScreen.class);
|
||||
m.setAccessible(true);
|
||||
boolean result = (Boolean) m.invoke(mPreferenceManager, preferenceScreen);
|
||||
if (result && preferenceScreen != null) {
|
||||
mHavePrefs = true;
|
||||
if (mInitDone) {
|
||||
postBindPreferences();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void dispatchActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
try {
|
||||
Method m = PreferenceManager.class
|
||||
.getDeclaredMethod("dispatchActivityResult", int.class, int.class,
|
||||
Intent.class);
|
||||
m.setAccessible(true);
|
||||
m.invoke(mPreferenceManager, requestCode, resultCode, data);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void dispatchActivityDestroy() {
|
||||
try {
|
||||
Method m = PreferenceManager.class.getDeclaredMethod("dispatchActivityDestroy");
|
||||
m.setAccessible(true);
|
||||
m.invoke(mPreferenceManager);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void dispatchActivityStop() {
|
||||
try {
|
||||
Method m = PreferenceManager.class.getDeclaredMethod("dispatchActivityStop");
|
||||
m.setAccessible(true);
|
||||
m.invoke(mPreferenceManager);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public PreferenceScreen inflateFromResource(Context context, int resId,
|
||||
PreferenceScreen rootPreferences) {
|
||||
PreferenceScreen preferenceScreen;
|
||||
try {
|
||||
Method m = PreferenceManager.class
|
||||
.getDeclaredMethod("inflateFromResource", Context.class, int.class,
|
||||
PreferenceScreen.class);
|
||||
m.setAccessible(true);
|
||||
preferenceScreen = (PreferenceScreen) m
|
||||
.invoke(mPreferenceManager, context, resId, rootPreferences);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return preferenceScreen;
|
||||
}
|
||||
|
||||
public PreferenceScreen inflateFromIntent(Intent queryIntent,
|
||||
PreferenceScreen rootPreferences) {
|
||||
PreferenceScreen preferenceScreen;
|
||||
try {
|
||||
Method m = PreferenceManager.class
|
||||
.getDeclaredMethod("inflateFromIntent", Intent.class, PreferenceScreen.class);
|
||||
m.setAccessible(true);
|
||||
preferenceScreen = (PreferenceScreen) m
|
||||
.invoke(mPreferenceManager, queryIntent, rootPreferences);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return preferenceScreen;
|
||||
}
|
||||
}
|
|
@ -1,15 +1,17 @@
|
|||
package org.microg.nlp;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.os.IBinder;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
|
||||
public abstract class AbstractBackendHelper implements ServiceConnection {
|
||||
protected final Context context;
|
||||
protected final Intent serviceIntent;
|
||||
protected boolean bound;
|
||||
private boolean bound;
|
||||
private final String TAG;
|
||||
|
||||
public AbstractBackendHelper(String tag, Context context, Intent serviceIntent) {
|
||||
|
@ -22,8 +24,21 @@ public abstract class AbstractBackendHelper implements ServiceConnection {
|
|||
|
||||
public abstract boolean hasBackend();
|
||||
|
||||
@Override
|
||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||
bound = true;
|
||||
Log.d(TAG, "Bound to: " + name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceDisconnected(ComponentName name) {
|
||||
bound = false;
|
||||
Log.d(TAG, "Unbound from: " + name);
|
||||
}
|
||||
|
||||
public void unbind() {
|
||||
if (bound) {
|
||||
Log.d(TAG, "Unbinding from: " + serviceIntent);
|
||||
if (hasBackend()) {
|
||||
try {
|
||||
close();
|
||||
|
@ -42,6 +57,7 @@ public abstract class AbstractBackendHelper implements ServiceConnection {
|
|||
|
||||
public boolean bind() {
|
||||
if (!bound) {
|
||||
Log.d(TAG, "Binding to: " + serviceIntent);
|
||||
try {
|
||||
context.bindService(serviceIntent, this, Context.BIND_AUTO_CREATE);
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -15,6 +15,7 @@ public class PackageReceiver extends BroadcastReceiver {
|
|||
Log.d(TAG, "Intent received: " + intent);
|
||||
Log.d(TAG, "Reloading location service...");
|
||||
LocationService.reloadLocationService(context);
|
||||
Log.d(TAG, "Reloading geocoding service...");
|
||||
GeocodeService.reloadLocationService(context);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,4 +6,6 @@ public interface Provider {
|
|||
IBinder getBinder();
|
||||
|
||||
void reload();
|
||||
|
||||
void destroy();
|
||||
}
|
||||
|
|
|
@ -27,6 +27,12 @@ public abstract class ProviderService<T extends Provider> extends IntentService
|
|||
return provider.getBinder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onUnbind(Intent intent) {
|
||||
destroyProvider();
|
||||
return super.onUnbind(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
provider = null;
|
||||
|
@ -39,6 +45,8 @@ public abstract class ProviderService<T extends Provider> extends IntentService
|
|||
* @return a new {@link org.microg.nlp.Provider} instance
|
||||
*/
|
||||
protected abstract T createProvider();
|
||||
|
||||
protected abstract void destroyProvider();
|
||||
|
||||
@Override
|
||||
protected void onHandleIntent(Intent intent) {
|
||||
|
|
|
@ -11,20 +11,12 @@ import java.util.List;
|
|||
import static org.microg.nlp.api.NlpApiConstants.ACTION_GEOCODER_BACKEND;
|
||||
|
||||
class BackendFuser {
|
||||
private final List<BackendHelper> backendHelpers;
|
||||
private final List<BackendHelper> backendHelpers = new ArrayList<BackendHelper>();
|
||||
private final Context context;
|
||||
|
||||
public BackendFuser(Context context) {
|
||||
backendHelpers = new ArrayList<BackendHelper>();
|
||||
for (String backend : Preferences
|
||||
.splitBackendString(new Preferences(context).getGeocoderBackends())) {
|
||||
String[] parts = backend.split("/");
|
||||
if (parts.length == 2) {
|
||||
Intent intent = new Intent(ACTION_GEOCODER_BACKEND);
|
||||
intent.setPackage(parts[0]);
|
||||
intent.setClassName(parts[0], parts[1]);
|
||||
backendHelpers.add(new BackendHelper(context, intent));
|
||||
}
|
||||
}
|
||||
this.context = context;
|
||||
reset();
|
||||
}
|
||||
|
||||
public void bind() {
|
||||
|
@ -70,4 +62,19 @@ class BackendFuser {
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
unbind();
|
||||
backendHelpers.clear();
|
||||
for (String backend : Preferences
|
||||
.splitBackendString(new Preferences(context).getGeocoderBackends())) {
|
||||
String[] parts = backend.split("/");
|
||||
if (parts.length == 2) {
|
||||
Intent intent = new Intent(ACTION_GEOCODER_BACKEND);
|
||||
intent.setPackage(parts[0]);
|
||||
intent.setClassName(parts[0], parts[1]);
|
||||
backendHelpers.add(new BackendHelper(context, intent));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ class BackendHelper extends AbstractBackendHelper {
|
|||
|
||||
@Override
|
||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||
bound = true;
|
||||
super.onServiceConnected(name, service);
|
||||
backend = GeocoderBackend.Stub.asInterface(service);
|
||||
if (backend != null) {
|
||||
try {
|
||||
|
@ -60,8 +60,8 @@ class BackendHelper extends AbstractBackendHelper {
|
|||
|
||||
@Override
|
||||
public void onServiceDisconnected(ComponentName name) {
|
||||
super.onServiceDisconnected(name);
|
||||
backend = null;
|
||||
bound = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -8,12 +8,11 @@ import com.android.location.provider.GeocodeProvider;
|
|||
import java.util.List;
|
||||
|
||||
class GeocodeProviderV1 extends GeocodeProvider implements org.microg.nlp.geocode.GeocodeProvider {
|
||||
private BackendFuser backendFuser;
|
||||
private Context context;
|
||||
private final BackendFuser backendFuser;
|
||||
|
||||
public GeocodeProviderV1(Context context) {
|
||||
this.context = context;
|
||||
reload();
|
||||
backendFuser = new BackendFuser(context);
|
||||
backendFuser.bind();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -47,10 +46,13 @@ class GeocodeProviderV1 extends GeocodeProvider implements org.microg.nlp.geocod
|
|||
|
||||
@Override
|
||||
public void reload() {
|
||||
if (backendFuser != null) {
|
||||
backendFuser.unbind();
|
||||
}
|
||||
backendFuser = new BackendFuser(context);
|
||||
backendFuser.unbind();
|
||||
backendFuser.reset();
|
||||
backendFuser.bind();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
backendFuser.unbind();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,13 +2,23 @@ package org.microg.nlp.geocode;
|
|||
|
||||
public class GeocodeServiceV1 extends GeocodeService {
|
||||
private static final String TAG = GeocodeServiceV1.class.getName();
|
||||
private static GeocodeProviderV1 THE_ONE;
|
||||
|
||||
public GeocodeServiceV1() {
|
||||
super(TAG);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GeocodeProvider createProvider() {
|
||||
return new GeocodeProviderV1(this);
|
||||
protected synchronized GeocodeProvider createProvider() {
|
||||
if (THE_ONE == null) {
|
||||
THE_ONE = new GeocodeProviderV1(this);
|
||||
}
|
||||
return THE_ONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void destroyProvider() {
|
||||
THE_ONE.destroy();
|
||||
THE_ONE = null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,14 +18,20 @@ import static org.microg.nlp.api.NlpApiConstants.*;
|
|||
class BackendFuser {
|
||||
private static final String TAG = BackendFuser.class.getName();
|
||||
|
||||
private final List<BackendHelper> backendHelpers;
|
||||
private final List<BackendHelper> backendHelpers = new ArrayList<BackendHelper>();
|
||||
private final LocationProvider locationProvider;
|
||||
private final Context context;
|
||||
private Location forcedLocation;
|
||||
private boolean fusing = false;
|
||||
|
||||
public BackendFuser(Context context, LocationProvider provider) {
|
||||
locationProvider = provider;
|
||||
backendHelpers = new ArrayList<BackendHelper>();
|
||||
public BackendFuser(Context context, LocationProvider locationProvider) {
|
||||
this.locationProvider = locationProvider;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
unbind();
|
||||
backendHelpers.clear();
|
||||
for (String backend : Preferences
|
||||
.splitBackendString(new Preferences(context).getLocationBackends())) {
|
||||
String[] parts = backend.split("/");
|
||||
|
@ -125,6 +131,11 @@ class BackendFuser {
|
|||
return forcedLocation;
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
unbind();
|
||||
backendHelpers.clear();
|
||||
}
|
||||
|
||||
public static class LocationComparator implements Comparator<Location> {
|
||||
|
||||
public static final LocationComparator INSTANCE = new LocationComparator();
|
||||
|
|
|
@ -90,7 +90,7 @@ class BackendHelper extends AbstractBackendHelper {
|
|||
|
||||
@Override
|
||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||
bound = true;
|
||||
super.onServiceConnected(name, service);
|
||||
backend = LocationBackend.Stub.asInterface(service);
|
||||
if (backend != null) {
|
||||
try {
|
||||
|
@ -107,8 +107,8 @@ class BackendHelper extends AbstractBackendHelper {
|
|||
|
||||
@Override
|
||||
public void onServiceDisconnected(ComponentName name) {
|
||||
super.onServiceDisconnected(name);
|
||||
backend = null;
|
||||
bound = false;
|
||||
}
|
||||
|
||||
private class Callback extends LocationCallback.Stub {
|
||||
|
|
|
@ -10,9 +10,10 @@ import android.util.Log;
|
|||
|
||||
import static android.location.LocationProvider.AVAILABLE;
|
||||
|
||||
public class LocationProviderV1 extends com.android.location.provider.LocationProvider implements LocationProvider {
|
||||
public class LocationProviderV1 extends com.android.location.provider.LocationProvider
|
||||
implements LocationProvider {
|
||||
private static final String TAG = LocationProviderV1.class.getName();
|
||||
|
||||
|
||||
private final ThreadHelper helper;
|
||||
private long autoTime = Long.MAX_VALUE;
|
||||
private boolean autoUpdate = false;
|
||||
|
@ -110,13 +111,16 @@ public class LocationProviderV1 extends com.android.location.provider.LocationPr
|
|||
@Override
|
||||
public void onEnableLocationTracking(boolean enable) {
|
||||
Log.v(TAG, "onEnableLocationTracking: " + enable);
|
||||
autoUpdate = true;
|
||||
autoUpdate = enable;
|
||||
if (autoUpdate && autoTime != Long.MAX_VALUE) helper.enable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetMinTime(long minTime, WorkSource ws) {
|
||||
Log.v(TAG, "onSetMinTime: " + minTime + " by " + ws);
|
||||
autoTime = minTime;
|
||||
helper.setTime(autoTime);
|
||||
if (autoUpdate) helper.enable();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -143,4 +147,9 @@ public class LocationProviderV1 extends com.android.location.provider.LocationPr
|
|||
public void onRemoveListener(int uid, WorkSource ws) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
helper.destroy();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,6 +46,11 @@ class LocationProviderV2 extends LocationProviderBase implements LocationProvide
|
|||
helper.reload();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
helper.destroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
}
|
||||
|
|
|
@ -2,13 +2,23 @@ package org.microg.nlp.location;
|
|||
|
||||
public class LocationServiceV1 extends LocationService {
|
||||
private static final String TAG = LocationServiceV1.class.getName();
|
||||
private static LocationProviderV1 THE_ONE;
|
||||
|
||||
public LocationServiceV1() {
|
||||
super(TAG);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LocationProvider createProvider() {
|
||||
return new LocationProviderV1(this);
|
||||
protected synchronized LocationProvider createProvider() {
|
||||
if (THE_ONE == null) {
|
||||
THE_ONE = new LocationProviderV1(this);
|
||||
}
|
||||
return THE_ONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void destroyProvider() {
|
||||
THE_ONE.destroy();
|
||||
THE_ONE = null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,13 +2,23 @@ package org.microg.nlp.location;
|
|||
|
||||
public class LocationServiceV2 extends LocationService {
|
||||
private static final String TAG = LocationServiceV2.class.getName();
|
||||
private static LocationProviderV2 THE_ONE;
|
||||
|
||||
public LocationServiceV2() {
|
||||
super(TAG);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LocationProvider createProvider() {
|
||||
return new LocationProviderV2(this);
|
||||
protected synchronized LocationProvider createProvider() {
|
||||
if (THE_ONE == null) {
|
||||
THE_ONE = new LocationProviderV2(this);
|
||||
}
|
||||
return THE_ONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void destroyProvider() {
|
||||
THE_ONE.destroy();
|
||||
THE_ONE = null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,30 +2,23 @@ package org.microg.nlp.location;
|
|||
|
||||
import android.content.Context;
|
||||
import android.location.Location;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
class ThreadHelper implements Runnable {
|
||||
private static final String TAG = ThreadHelper.class.getName();
|
||||
private final Context context;
|
||||
private final LocationProvider locationProvider;
|
||||
private BackendFuser backendFuser;
|
||||
private final BackendFuser backendFuser;
|
||||
private ScheduledThreadPoolExecutor executor;
|
||||
private long time = 5000; // Initialize with 5s
|
||||
private boolean enabled;
|
||||
private long time = 60000; // Initialize with 60s
|
||||
private AtomicBoolean enabled = new AtomicBoolean(false);
|
||||
|
||||
public ThreadHelper(Context context, LocationProvider locationProvider) {
|
||||
this.context = context;
|
||||
this.locationProvider = locationProvider;
|
||||
updateBackendHandler();
|
||||
}
|
||||
|
||||
private void updateBackendHandler() {
|
||||
BackendFuser old = backendFuser;
|
||||
backendFuser = new BackendFuser(context, locationProvider);
|
||||
if (old != null) {
|
||||
backendFuser.forceLocation(old.getForcedLocation());
|
||||
}
|
||||
}
|
||||
|
||||
public void forceLocation(Location location) {
|
||||
|
@ -34,7 +27,7 @@ class ThreadHelper implements Runnable {
|
|||
|
||||
public void reload() {
|
||||
disable();
|
||||
updateBackendHandler();
|
||||
backendFuser.reset();
|
||||
enable();
|
||||
}
|
||||
|
||||
|
@ -43,10 +36,8 @@ class ThreadHelper implements Runnable {
|
|||
executor.shutdownNow();
|
||||
executor = null;
|
||||
}
|
||||
if (enabled) {
|
||||
backendFuser.unbind();
|
||||
enabled = false;
|
||||
}
|
||||
backendFuser.unbind();
|
||||
enabled.set(false);
|
||||
}
|
||||
|
||||
public void setTime(long time) {
|
||||
|
@ -63,9 +54,8 @@ class ThreadHelper implements Runnable {
|
|||
}
|
||||
|
||||
public void enable() {
|
||||
if (!enabled) {
|
||||
if (enabled.compareAndSet(false, true)) {
|
||||
backendFuser.bind();
|
||||
enabled = true;
|
||||
}
|
||||
reset();
|
||||
}
|
||||
|
@ -74,4 +64,11 @@ class ThreadHelper implements Runnable {
|
|||
public void run() {
|
||||
backendFuser.update();
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
if (executor != null) {
|
||||
executor.shutdownNow();
|
||||
}
|
||||
backendFuser.destroy();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -96,7 +96,6 @@ public abstract class AbstractBackendPreference extends DialogPreference {
|
|||
ServiceInfo serviceInfo = info.serviceInfo;
|
||||
String simpleName = String
|
||||
.valueOf(serviceInfo.loadLabel(getContext().getPackageManager()));
|
||||
Log.d("nlp.IntentToBackend", intent.getAction() + ": " + serviceInfo);
|
||||
knownBackends.add(new BackendInfo(serviceInfo, simpleName));
|
||||
}
|
||||
return knownBackends;
|
||||
|
|
|
@ -1,40 +1,30 @@
|
|||
package org.microg.nlp.ui;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.support.v4.preference.PreferenceFragment;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import org.microg.nlp.R;
|
||||
|
||||
public class SettingsActivity extends PreferenceActivity {
|
||||
private Toolbar toolbar;
|
||||
|
||||
public class SettingsActivity extends ActionBarActivity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
addPreferencesFromResource(R.xml.nlp_preferences);
|
||||
toolbar.setTitle(getTitle());
|
||||
setContentView(R.layout.settings_activity);
|
||||
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
getSupportFragmentManager().beginTransaction()
|
||||
.replace(R.id.content_wrapper, new MyPreferenceFragment()).commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentView(int layoutResID) {
|
||||
ViewGroup contentView = (ViewGroup) LayoutInflater.from(this)
|
||||
.inflate(R.layout.settings_activity, new LinearLayout(this), false);
|
||||
public static class MyPreferenceFragment extends PreferenceFragment {
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
toolbar = (Toolbar) contentView.findViewById(R.id.action_bar);
|
||||
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
ViewGroup contentWrapper = (ViewGroup) contentView.findViewById(R.id.content_wrapper);
|
||||
LayoutInflater.from(this).inflate(layoutResID, contentWrapper, true);
|
||||
|
||||
getWindow().setContentView(contentView);
|
||||
addPreferencesFromResource(R.xml.nlp_preferences);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue