Revamp configuration UI, handle preferences the android way
- Icon's are no longer shown in settings - It's now possible to define a summary and an about activity (useful to fulfill license requirements)
|
@ -1,8 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.microg.nlp"
|
||||
android:versionName="1.1.0"
|
||||
android:versionCode="1100">
|
||||
android:versionName="1.1.1"
|
||||
android:versionCode="1101">
|
||||
|
||||
<uses-sdk
|
||||
android:minSdkVersion="9" />
|
||||
|
@ -75,7 +75,7 @@
|
|||
android:value="false" />
|
||||
</service>
|
||||
|
||||
<activity android:name=".ui.PreferencesActivity"
|
||||
<activity android:name=".ui.SettingsActivity"
|
||||
android:label="@string/nlp_settings_label">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
|
|
@ -11,4 +11,6 @@ public class NlpApiConstants {
|
|||
public static final String LOCATION_EXTRA_BACKEND_COMPONENT = "SERVICE_BACKEND_COMPONENT";
|
||||
public static final String LOCATION_EXTRA_OTHER_BACKENDS = "OTHER_BACKEND_RESULTS";
|
||||
public static final String METADATA_BACKEND_SETTINGS_ACTIVITY = "org.microg.nlp.BACKEND_SETTINGS_ACTIVITY";
|
||||
public static final String METADATA_BACKEND_ABOUT_ACTIVITY = "org.microg.nlp.BACKEND_ABOUT_ACTIVITY";
|
||||
public static final String METADATA_BACKEND_SUMMARY = "org.microg.nlp.BACKEND_SUMMARY";
|
||||
}
|
||||
|
|
BIN
res/drawable-hdpi/info.png
Normal file
After Width: | Height: | Size: 616 B |
BIN
res/drawable-hdpi/settings.png
Normal file
After Width: | Height: | Size: 608 B |
BIN
res/drawable-mdpi/info.png
Normal file
After Width: | Height: | Size: 445 B |
BIN
res/drawable-mdpi/settings.png
Normal file
After Width: | Height: | Size: 451 B |
BIN
res/drawable-xhdpi/info.png
Normal file
After Width: | Height: | Size: 775 B |
BIN
res/drawable-xhdpi/settings.png
Normal file
After Width: | Height: | Size: 725 B |
BIN
res/drawable-xxhdpi/info.png
Normal file
After Width: | Height: | Size: 1 KiB |
BIN
res/drawable-xxhdpi/settings.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
res/drawable-xxxhdpi/info.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
res/drawable-xxxhdpi/settings.png
Normal file
After Width: | Height: | Size: 1.4 KiB |
|
@ -7,11 +7,6 @@
|
|||
android:gravity="center_vertical"
|
||||
android:padding="16dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@android:id/icon"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp" />
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="0dip"
|
||||
|
@ -37,12 +32,31 @@
|
|||
|
||||
</LinearLayout>
|
||||
|
||||
<ImageView
|
||||
android:id="@android:id/button2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:focusable="false"
|
||||
android:clickable="false"
|
||||
android:tintMode="src_in"
|
||||
android:tint="?android:attr/textColorPrimary"
|
||||
android:background="?android:selectableItemBackground"
|
||||
android:visibility="gone"
|
||||
android:src="@drawable/info" />
|
||||
|
||||
<ImageView
|
||||
android:id="@android:id/button1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:focusable="false"
|
||||
android:clickable="false"
|
||||
android:tintMode="src_in"
|
||||
android:tint="?android:attr/textColorPrimary"
|
||||
android:background="?android:selectableItemBackground"
|
||||
android:src="@drawable/ic_menu_moreoverflow_normal_holo_light" />
|
||||
android:src="@drawable/settings" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/enabled"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<include layout="@layout/toolbar" />
|
||||
|
||||
<fragment android:name="org.microg.nlp.ui.GeocodeBackendConfigFragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
|
@ -1,11 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<include layout="@layout/toolbar" />
|
||||
|
||||
<fragment android:name="org.microg.nlp.ui.LocationBackendConfigFragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
|
@ -1,73 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<include layout="@layout/toolbar" />
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
|
||||
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd">
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:text="@string/network_location"
|
||||
android:layout_marginStart="2dip"
|
||||
android:layout_marginEnd="6dip"
|
||||
android:layout_marginTop="12dip"/>
|
||||
<RelativeLayout
|
||||
android:id="@+id/location_backends"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="12dip"
|
||||
android:paddingBottom="12dip"
|
||||
android:background="?android:attr/selectableItemBackground">
|
||||
<TextView
|
||||
android:id="@+android:id/title"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/configure_backends"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
<TextView
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:text="@string/configure_location_backends_summary"
|
||||
android:layout_below="@android:id/title"
|
||||
android:layout_alignStart="@android:id/title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
</RelativeLayout>
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:text="@string/geocoding"
|
||||
android:layout_marginStart="2dip"
|
||||
android:layout_marginEnd="6dip"
|
||||
android:layout_marginTop="12dip"/>
|
||||
<RelativeLayout
|
||||
android:id="@+id/geocoder_backends"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="12dip"
|
||||
android:paddingBottom="12dip"
|
||||
android:background="?android:attr/selectableItemBackground">
|
||||
<TextView
|
||||
android:id="@+android:id/title"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/configure_backends"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
<TextView
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:text="@string/configure_geocoder_backends_summary"
|
||||
android:layout_below="@android:id/title"
|
||||
android:layout_alignStart="@android:id/title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
|
@ -1,26 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<org.microg.nlp.ui.DynamicListView
|
||||
android:id="@android:id/list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<Button
|
||||
android:id="@android:id/button1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="?android:listPreferredItemHeight"
|
||||
android:layout_gravity="center"
|
||||
android:paddingRight="20dp"
|
||||
android:drawableLeft="@drawable/ic_action_add"
|
||||
android:drawablePadding="8dp"
|
||||
android:gravity="center_vertical"
|
||||
android:textAppearance="?android:textAppearanceMedium"
|
||||
android:textStyle="bold"
|
||||
android:textAllCaps="true"
|
||||
android:text="@string/add_backend" />
|
||||
</LinearLayout>
|
19
res/layout/settings_activity.xml
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
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" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/content_wrapper"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
</LinearLayout>
|
|
@ -14,4 +14,6 @@
|
|||
<string name="configure_geocoder_backends_summary">
|
||||
Enable, disable and configure backends for (reverse) geocoding.
|
||||
</string>
|
||||
<string name="pref_location_backends">location_backends</string>
|
||||
<string name="pref_geocoder_backends">geocoder_backends</string>
|
||||
</resources>
|
||||
|
|
16
res/xml/nlp_preferences.xml
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:key="nlp_preferences">
|
||||
<PreferenceCategory android:title="@string/network_location">
|
||||
<org.microg.nlp.ui.LocationBackendPreference
|
||||
android:key="@string/pref_location_backends"
|
||||
android:title="@string/configure_backends"
|
||||
android:summary="@string/configure_location_backends_summary" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory android:title="@string/geocoding">
|
||||
<org.microg.nlp.ui.GeocoderBackendPreference
|
||||
android:key="@string/pref_geocoder_backends"
|
||||
android:title="@string/configure_backends"
|
||||
android:summary="@string/configure_geocoder_backends_summary" />
|
||||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
|
@ -2,14 +2,13 @@ package org.microg.nlp;
|
|||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
|
||||
public class Preferences {
|
||||
private static final String DEFAULT_LOCATION_BACKENDS = "default_location_backends";
|
||||
private static final String LOCATION_BACKENDS = "location_backends";
|
||||
private static final String DEFAULT_GEOCODER_BACKENDS = "default_geocoder_backends";
|
||||
private static final String GEOCODER_BACKENDS = "geocoder_backends";
|
||||
private final Context context;
|
||||
|
||||
public Preferences(Context context) {
|
||||
|
@ -17,33 +16,34 @@ public class Preferences {
|
|||
}
|
||||
|
||||
private SharedPreferences getSharedPreferences() {
|
||||
return context.getSharedPreferences("config", Context.MODE_PRIVATE);
|
||||
return PreferenceManager.getDefaultSharedPreferences(context);
|
||||
}
|
||||
|
||||
public String getDefaultLocationBackends() {
|
||||
String defBackends = Settings.System
|
||||
.getString(context.getContentResolver(), DEFAULT_LOCATION_BACKENDS);
|
||||
return defBackends == null ? "" : defBackends;
|
||||
}
|
||||
|
||||
public String getLocationBackends() {
|
||||
String defBackends = Settings.System
|
||||
.getString(context.getContentResolver(), DEFAULT_LOCATION_BACKENDS);
|
||||
String s = getSharedPreferences()
|
||||
.getString(LOCATION_BACKENDS, defBackends == null ? "" : defBackends);
|
||||
Log.d("nlpPreferences", "location_backends: "+s);
|
||||
String s = getSharedPreferences().getString(
|
||||
context.getString(R.string.pref_location_backends), getDefaultLocationBackends());
|
||||
return s;
|
||||
}
|
||||
|
||||
public void setLocationBackends(String backends) {
|
||||
getSharedPreferences().edit().putString(LOCATION_BACKENDS, backends).commit();
|
||||
public String getDefaultGeocoderBackends() {
|
||||
String defBackends = Settings.System
|
||||
.getString(context.getContentResolver(), DEFAULT_GEOCODER_BACKENDS);
|
||||
return defBackends == null ? "" : defBackends;
|
||||
}
|
||||
|
||||
public String getGeocoderBackends() {
|
||||
String defBackends = Settings.System
|
||||
.getString(context.getContentResolver(), DEFAULT_GEOCODER_BACKENDS);
|
||||
return getSharedPreferences()
|
||||
.getString(GEOCODER_BACKENDS, defBackends == null ? "" : defBackends);
|
||||
return getSharedPreferences().getString(
|
||||
context.getString(R.string.pref_geocoder_backends), getDefaultGeocoderBackends());
|
||||
}
|
||||
|
||||
public void setGeocoderBackends(String backends) {
|
||||
getSharedPreferences().edit().putString(GEOCODER_BACKENDS, backends).commit();
|
||||
}
|
||||
|
||||
public static String[] splitBackendString(String backendString) {
|
||||
return backendString.split("\\|");
|
||||
}
|
||||
|
|
|
@ -1,290 +0,0 @@
|
|||
package org.microg.nlp.ui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ComponentInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.content.pm.ServiceInfo;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.*;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.PopupMenu;
|
||||
import android.widget.TextView;
|
||||
import org.microg.nlp.Preferences;
|
||||
import org.microg.nlp.R;
|
||||
import org.microg.nlp.location.LocationService;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.microg.nlp.api.NlpApiConstants.METADATA_BACKEND_SETTINGS_ACTIVITY;
|
||||
|
||||
public abstract class AbstractBackendConfigFragment extends Fragment {
|
||||
private final String TAG;
|
||||
private List<ServiceInfo> activeBackends;
|
||||
private Map<ServiceInfo, KnownBackend> knownBackends;
|
||||
private List<ServiceInfo> unusedBackends;
|
||||
private Adapter adapter;
|
||||
private DynamicListView listView;
|
||||
private View addButton;
|
||||
private PopupMenu popUp;
|
||||
|
||||
public AbstractBackendConfigFragment(String TAG) {
|
||||
this.TAG = TAG;
|
||||
Log.d(TAG, "<ctor>");
|
||||
}
|
||||
|
||||
protected abstract Map<ServiceInfo, KnownBackend> queryKnownBackends();
|
||||
|
||||
protected abstract List<ServiceInfo> queryActiveBackends();
|
||||
|
||||
protected abstract void saveActiveBackends(List<ServiceInfo> activeBackends);
|
||||
|
||||
public Map<ServiceInfo, KnownBackend> getKnownBackends() {
|
||||
return knownBackends;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
Log.d(TAG, "onCreateView");
|
||||
View view = inflater.inflate(R.layout.pluginselection, null);
|
||||
listView = (DynamicListView) view.findViewById(android.R.id.list);
|
||||
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> view, View view2, int i, long l) {
|
||||
Log.d(TAG, "onItemClick: " + l);
|
||||
}
|
||||
});
|
||||
addButton = view.findViewById(android.R.id.button1);
|
||||
addButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
showAddPluginPopup(view);
|
||||
}
|
||||
});
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
Log.d(TAG, "onActivityCreated");
|
||||
updateBackends();
|
||||
}
|
||||
|
||||
private void updateBackends() {
|
||||
knownBackends = queryKnownBackends();
|
||||
activeBackends = queryActiveBackends();
|
||||
unusedBackends = new ArrayList<ServiceInfo>();
|
||||
updateAddButton();
|
||||
resetAdapter();
|
||||
}
|
||||
|
||||
private void updateAddButton() {
|
||||
if (activeBackends.size() == knownBackends.size()) {
|
||||
if (knownBackends.isEmpty()) {
|
||||
// No backend installed
|
||||
// TODO: notify user about that
|
||||
}
|
||||
addButton.setVisibility(View.GONE);
|
||||
} else {
|
||||
addButton.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
private void resetAdapter() {
|
||||
List<ServiceInfo> backends = activeBackends;
|
||||
adapter = new Adapter(backends);
|
||||
listView.setList(backends);
|
||||
listView.setAdapter(adapter);
|
||||
}
|
||||
|
||||
private void updateUnusedBackends() {
|
||||
unusedBackends.clear();
|
||||
for (KnownBackend backend : knownBackends.values()) {
|
||||
if (!activeBackends.contains(backend.serviceInfo)) {
|
||||
unusedBackends.add(backend.serviceInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void enableBackend(ServiceInfo serviceInfo) {
|
||||
activeBackends.add(serviceInfo);
|
||||
onBackendsChanged();
|
||||
}
|
||||
|
||||
private void disabledBackend(ServiceInfo serviceInfo) {
|
||||
activeBackends.remove(serviceInfo);
|
||||
onBackendsChanged();
|
||||
}
|
||||
|
||||
private void onBackendsChanged() {
|
||||
updateAddButton();
|
||||
resetAdapter();
|
||||
saveActiveBackends(activeBackends);
|
||||
}
|
||||
|
||||
public static String serviceInfosToBackendString(List<ServiceInfo> backends) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (ServiceInfo backend : backends) {
|
||||
if (sb.length() != 0) {
|
||||
sb.append("|");
|
||||
}
|
||||
sb.append(backend.packageName).append("/").append(backend.name);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static List<ServiceInfo> backendStringToServiceInfos(String backends,
|
||||
Set<ServiceInfo> infoSet) {
|
||||
List<ServiceInfo> backendInfos = new ArrayList<ServiceInfo>();
|
||||
for (String backend : Preferences.splitBackendString(backends)) {
|
||||
String[] parts = backend.split("/");
|
||||
if (parts.length == 2) {
|
||||
for (ServiceInfo serviceInfo : infoSet) {
|
||||
Log.d("nlp.StringToInfo", backend + ": " + serviceInfo);
|
||||
if (serviceInfo.packageName.equals(parts[0]) &&
|
||||
serviceInfo.name.equals(parts[1])) {
|
||||
backendInfos.add(serviceInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return backendInfos;
|
||||
}
|
||||
|
||||
public static Map<ServiceInfo, KnownBackend> intentToKnownBackendMap(Context context,
|
||||
Intent intent) {
|
||||
Map<ServiceInfo, AbstractBackendConfigFragment.KnownBackend> knownBackends = new HashMap<ServiceInfo, KnownBackend>();
|
||||
List<ResolveInfo> resolveInfos = context.getPackageManager()
|
||||
.queryIntentServices(intent, PackageManager.GET_META_DATA);
|
||||
for (ResolveInfo info : resolveInfos) {
|
||||
ServiceInfo serviceInfo = info.serviceInfo;
|
||||
String simpleName = String
|
||||
.valueOf(serviceInfo.loadLabel(context.getPackageManager()));
|
||||
Drawable icon = serviceInfo.loadIcon(context.getPackageManager());
|
||||
Log.d("nlp.IntentToBackend", intent.getAction() + ": " + serviceInfo);
|
||||
knownBackends.put(serviceInfo, new KnownBackend(serviceInfo, simpleName, icon));
|
||||
}
|
||||
return knownBackends;
|
||||
}
|
||||
|
||||
private void showAddPluginPopup(View anchorView) {
|
||||
updateUnusedBackends();
|
||||
|
||||
if (popUp != null) {
|
||||
popUp.dismiss();
|
||||
}
|
||||
popUp = new PopupMenu(getActivity(), anchorView);
|
||||
|
||||
for (int i = 0; i < unusedBackends.size(); i++) {
|
||||
KnownBackend backend = knownBackends.get(unusedBackends.get(i));
|
||||
String label = backend.simpleName;
|
||||
if (TextUtils.isEmpty(label)) {
|
||||
label = backend.serviceInfo.name;
|
||||
}
|
||||
popUp.getMenu().add(Menu.NONE, i, Menu.NONE, label);
|
||||
}
|
||||
popUp.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem menuItem) {
|
||||
popUp.dismiss();
|
||||
popUp = null;
|
||||
|
||||
enableBackend(unusedBackends.get(menuItem.getItemId()));
|
||||
return true;
|
||||
}
|
||||
});
|
||||
popUp.show();
|
||||
}
|
||||
|
||||
private Intent createSettingsIntent(ComponentInfo componentInfo) {
|
||||
Intent settingsIntent = new Intent(Intent.ACTION_VIEW);
|
||||
settingsIntent.setPackage(componentInfo.packageName);
|
||||
settingsIntent.setClassName(componentInfo.packageName,
|
||||
componentInfo.metaData.getString(METADATA_BACKEND_SETTINGS_ACTIVITY));
|
||||
return settingsIntent;
|
||||
}
|
||||
|
||||
private void showSettingsPopup(View anchorView, final KnownBackend backend) {
|
||||
if (popUp != null) {
|
||||
popUp.dismiss();
|
||||
}
|
||||
popUp = new PopupMenu(getActivity(), anchorView);
|
||||
popUp.getMenu().add(Menu.NONE, 0, Menu.NONE, "Remove"); // TODO label
|
||||
if (backend.serviceInfo.metaData != null &&
|
||||
backend.serviceInfo.metaData.getString(METADATA_BACKEND_SETTINGS_ACTIVITY) !=
|
||||
null) {
|
||||
if (getActivity().getPackageManager()
|
||||
.resolveActivity(createSettingsIntent(backend.serviceInfo), 0) != null) {
|
||||
popUp.getMenu().add(Menu.NONE, 1, Menu.NONE, "Settings"); // TODO label
|
||||
}
|
||||
}
|
||||
popUp.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
popUp.dismiss();
|
||||
popUp = null;
|
||||
|
||||
if (item.getItemId() == 0) {
|
||||
disabledBackend(backend.serviceInfo);
|
||||
} else if (item.getItemId() == 1) {
|
||||
startActivity(createSettingsIntent(backend.serviceInfo));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
popUp.show();
|
||||
}
|
||||
|
||||
private class Adapter extends DynamicListView.StableArrayAdapter {
|
||||
public Adapter(List<ServiceInfo> backends) {
|
||||
super(getActivity(), R.layout.backend_list_entry, android.R.id.text2,
|
||||
backends);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
View v = super.getView(position, convertView, parent);
|
||||
final KnownBackend backend = knownBackends.get(getItem(position));
|
||||
ImageView icon = (ImageView) v.findViewById(android.R.id.icon);
|
||||
icon.setImageDrawable(backend.icon);
|
||||
TextView title = (TextView) v.findViewById(android.R.id.text1);
|
||||
title.setText(backend.simpleName);
|
||||
TextView subtitle = (TextView) v.findViewById(android.R.id.text2);
|
||||
subtitle.setText(backend.serviceInfo.name);
|
||||
View overflow = v.findViewById(android.R.id.button1);
|
||||
overflow.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
showSettingsPopup(view, backend);
|
||||
}
|
||||
});
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
public static class KnownBackend {
|
||||
private ServiceInfo serviceInfo;
|
||||
private String simpleName;
|
||||
private Drawable icon;
|
||||
|
||||
public KnownBackend(ServiceInfo serviceInfo, String simpleName, Drawable icon) {
|
||||
this.serviceInfo = serviceInfo;
|
||||
this.simpleName = simpleName;
|
||||
this.icon = icon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return simpleName;
|
||||
}
|
||||
}
|
||||
}
|
198
src/org/microg/nlp/ui/AbstractBackendPreference.java
Normal file
|
@ -0,0 +1,198 @@
|
|||
package org.microg.nlp.ui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.content.pm.ServiceInfo;
|
||||
import android.preference.DialogPreference;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.*;
|
||||
import org.microg.nlp.Preferences;
|
||||
import org.microg.nlp.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.microg.nlp.api.NlpApiConstants.*;
|
||||
|
||||
public abstract class AbstractBackendPreference extends DialogPreference {
|
||||
private ListView listView;
|
||||
private Adapter adapter;
|
||||
private List<BackendInfo> knownBackends;
|
||||
|
||||
public AbstractBackendPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
setPositiveButtonText(android.R.string.ok);
|
||||
setNegativeButtonText(android.R.string.cancel);
|
||||
|
||||
setDialogIcon(null);
|
||||
|
||||
adapter = new Adapter();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected View onCreateDialogView() {
|
||||
listView = new ListView(getContext());
|
||||
updateBackends();
|
||||
return listView;
|
||||
}
|
||||
|
||||
private void updateBackends() {
|
||||
knownBackends = queryKnownBackends();
|
||||
markBackendsAsEnabled();
|
||||
resetAdapter();
|
||||
}
|
||||
|
||||
protected List<BackendInfo> queryKnownBackends() {
|
||||
return intentToKnownBackends(buildBackendIntent());
|
||||
}
|
||||
|
||||
private void resetAdapter() {
|
||||
adapter.clear();
|
||||
adapter.addAll(knownBackends);
|
||||
listView.setAdapter(adapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (BackendInfo backend : knownBackends) {
|
||||
if (backend.enabled) {
|
||||
if (sb.length() != 0) {
|
||||
sb.append("|");
|
||||
}
|
||||
sb.append(backend.serviceInfo.packageName).append("/").append(backend.serviceInfo.name);
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public void markBackendsAsEnabled() {
|
||||
for (String backend : Preferences.splitBackendString(getPersistedString(defaultValue()))) {
|
||||
String[] parts = backend.split("/");
|
||||
if (parts.length == 2) {
|
||||
for (BackendInfo backendInfo : knownBackends) {
|
||||
ServiceInfo serviceInfo = backendInfo.serviceInfo;
|
||||
if (serviceInfo.packageName.equals(parts[0]) &&
|
||||
serviceInfo.name.equals(parts[1])) {
|
||||
backendInfo.enabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<BackendInfo> intentToKnownBackends(Intent intent) {
|
||||
List<BackendInfo> knownBackends = new ArrayList<BackendInfo>();
|
||||
List<ResolveInfo> resolveInfos = getContext().getPackageManager()
|
||||
.queryIntentServices(intent, PackageManager.GET_META_DATA);
|
||||
for (ResolveInfo info : resolveInfos) {
|
||||
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;
|
||||
}
|
||||
|
||||
private Intent createExternalIntent(BackendInfo backendInfo, String metaName) {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setPackage(backendInfo.serviceInfo.packageName);
|
||||
intent.setClassName(backendInfo.serviceInfo.packageName, backendInfo.getMeta(metaName));
|
||||
return intent;
|
||||
}
|
||||
|
||||
private class Adapter extends ArrayAdapter<BackendInfo> {
|
||||
|
||||
public Adapter() {
|
||||
super(AbstractBackendPreference.this.getContext(), R.layout.backend_list_entry);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
View v = ((LayoutInflater) getContext()
|
||||
.getSystemService(Context.LAYOUT_INFLATER_SERVICE))
|
||||
.inflate(R.layout.backend_list_entry, null);
|
||||
final BackendInfo backend = getItem(position);
|
||||
TextView title = (TextView) v.findViewById(android.R.id.text1);
|
||||
title.setText(backend.simpleName);
|
||||
TextView subtitle = (TextView) v.findViewById(android.R.id.text2);
|
||||
if (backend.getMeta(METADATA_BACKEND_SUMMARY) != null) {
|
||||
subtitle.setText(backend.serviceInfo.metaData.getString(METADATA_BACKEND_SUMMARY));
|
||||
subtitle.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
subtitle.setVisibility(View.GONE);
|
||||
}
|
||||
final CheckBox checkbox = (CheckBox) v.findViewById(R.id.enabled);
|
||||
if (checkbox.isChecked() != backend.enabled) {
|
||||
checkbox.toggle();
|
||||
}
|
||||
checkbox.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
backend.enabled = checkbox.isChecked();
|
||||
}
|
||||
});
|
||||
configureExternalButton(backend, v.findViewById(android.R.id.button1),
|
||||
METADATA_BACKEND_SETTINGS_ACTIVITY);
|
||||
configureExternalButton(backend, v.findViewById(android.R.id.button2),
|
||||
METADATA_BACKEND_ABOUT_ACTIVITY);
|
||||
return v;
|
||||
}
|
||||
|
||||
private void configureExternalButton(final BackendInfo backend, View button,
|
||||
final String metaName) {
|
||||
if (backend.getMeta(metaName) != null) {
|
||||
button.setVisibility(View.VISIBLE);
|
||||
button.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
getContext().startActivity(createExternalIntent(backend, metaName));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
button.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onDialogClosed(boolean positiveResult) {
|
||||
if (positiveResult) {
|
||||
persistString(toString());
|
||||
onValueChanged();
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void onValueChanged();
|
||||
protected abstract Intent buildBackendIntent();
|
||||
protected abstract String defaultValue();
|
||||
|
||||
private class BackendInfo {
|
||||
private ServiceInfo serviceInfo;
|
||||
private String simpleName;
|
||||
private boolean enabled = false;
|
||||
|
||||
public BackendInfo(ServiceInfo serviceInfo, String simpleName) {
|
||||
this.serviceInfo = serviceInfo;
|
||||
this.simpleName = simpleName;
|
||||
}
|
||||
|
||||
public String getMeta(String metaName) {
|
||||
return serviceInfo.metaData != null ? serviceInfo.metaData.getString(metaName) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return simpleName;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,613 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2013 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.microg.nlp.ui;
|
||||
|
||||
import android.animation.*;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ServiceInfo;
|
||||
import android.graphics.*;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.widget.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The dynamic listview is an extension of listview that supports cell dragging
|
||||
* and swapping.
|
||||
* <p/>
|
||||
* This layout is in charge of positioning the hover cell in the correct location
|
||||
* on the screen in response to user touch events. It uses the position of the
|
||||
* hover cell to determine when two cells should be swapped. If two cells should
|
||||
* be swapped, all the corresponding data set and layout changes are handled here.
|
||||
* <p/>
|
||||
* If no cell is selected, all the touch events are passed down to the listview
|
||||
* and behave normally. If one of the items in the listview experiences a
|
||||
* long press event, the contents of its current visible state are captured as
|
||||
* a bitmap and its visibility is set to INVISIBLE. A hover cell is then created and
|
||||
* added to this layout as an overlaying BitmapDrawable above the listview. Once the
|
||||
* hover cell is translated some distance to signify an item swap, a data set change
|
||||
* accompanied by animation takes place. When the user releases the hover cell,
|
||||
* it animates into its corresponding position in the listview.
|
||||
* <p/>
|
||||
* When the hover cell is either above or below the bounds of the listview, this
|
||||
* listview also scrolls on its own so as to reveal additional content.
|
||||
*/
|
||||
public class DynamicListView extends ListView {
|
||||
|
||||
/**
|
||||
* This TypeEvaluator is used to animate the BitmapDrawable back to its
|
||||
* final location when the user lifts his finger by modifying the
|
||||
* BitmapDrawable's bounds.
|
||||
*/
|
||||
private final static TypeEvaluator<Rect> sBoundEvaluator = new TypeEvaluator<Rect>() {
|
||||
public Rect evaluate(float fraction, Rect startValue, Rect endValue) {
|
||||
return new Rect(interpolate(startValue.left, endValue.left, fraction),
|
||||
interpolate(startValue.top, endValue.top, fraction),
|
||||
interpolate(startValue.right, endValue.right, fraction),
|
||||
interpolate(startValue.bottom, endValue.bottom, fraction));
|
||||
}
|
||||
|
||||
public int interpolate(int start, int end, float fraction) {
|
||||
return (int) (start + fraction * (end - start));
|
||||
}
|
||||
};
|
||||
private final int SMOOTH_SCROLL_AMOUNT_AT_EDGE = 15;
|
||||
private final int MOVE_DURATION = 150;
|
||||
private final int LINE_THICKNESS = 15;
|
||||
private final int INVALID_ID = -1;
|
||||
private long mBelowItemId = INVALID_ID;
|
||||
private long mMobileItemId = INVALID_ID;
|
||||
private long mAboveItemId = INVALID_ID;
|
||||
private final int INVALID_POINTER_ID = -1;
|
||||
private int mActivePointerId = INVALID_POINTER_ID;
|
||||
public List<ServiceInfo> mList;
|
||||
private int mLastEventY = -1;
|
||||
private int mDownY = -1;
|
||||
private int mDownX = -1;
|
||||
private int mTotalOffset = 0;
|
||||
private boolean mCellIsMobile = false;
|
||||
private boolean mIsMobileScrolling = false;
|
||||
private int mSmoothScrollAmountAtEdge = 0;
|
||||
private BitmapDrawable mHoverCell;
|
||||
/**
|
||||
* Listens for long clicks on any items in the listview. When a cell has
|
||||
* been selected, the hover cell is created and set up.
|
||||
*/
|
||||
private AdapterView.OnItemLongClickListener mOnItemLongClickListener =
|
||||
new AdapterView.OnItemLongClickListener() {
|
||||
public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int pos, long id) {
|
||||
mTotalOffset = 0;
|
||||
|
||||
int position = pointToPosition(mDownX, mDownY);
|
||||
int itemNum = position - getFirstVisiblePosition();
|
||||
|
||||
View selectedView = getChildAt(itemNum);
|
||||
mMobileItemId = getAdapter().getItemId(position);
|
||||
mHoverCell = getAndAddHoverView(selectedView);
|
||||
selectedView.setVisibility(INVISIBLE);
|
||||
|
||||
mCellIsMobile = true;
|
||||
|
||||
updateNeighborViewsForID(mMobileItemId);
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
private Rect mHoverCellCurrentBounds;
|
||||
private Rect mHoverCellOriginalBounds;
|
||||
private boolean mIsWaitingForScrollFinish = false;
|
||||
private int mScrollState = OnScrollListener.SCROLL_STATE_IDLE;
|
||||
|
||||
public DynamicListView(Context context) {
|
||||
super(context);
|
||||
init(context);
|
||||
}
|
||||
|
||||
public DynamicListView(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
init(context);
|
||||
}
|
||||
|
||||
public DynamicListView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context);
|
||||
}
|
||||
|
||||
public void init(Context context) {
|
||||
setOnItemLongClickListener(mOnItemLongClickListener);
|
||||
setOnScrollListener(mScrollListener);
|
||||
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
|
||||
mSmoothScrollAmountAtEdge = (int) (SMOOTH_SCROLL_AMOUNT_AT_EDGE / metrics.density);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the hover cell with the appropriate bitmap and of appropriate
|
||||
* size. The hover cell's BitmapDrawable is drawn on top of the bitmap every
|
||||
* single time an invalidate call is made.
|
||||
*/
|
||||
private BitmapDrawable getAndAddHoverView(View v) {
|
||||
|
||||
int w = v.getWidth();
|
||||
int h = v.getHeight();
|
||||
int top = v.getTop();
|
||||
int left = v.getLeft();
|
||||
|
||||
Bitmap b = getBitmapWithBorder(v);
|
||||
|
||||
BitmapDrawable drawable = new BitmapDrawable(getResources(), b);
|
||||
|
||||
mHoverCellOriginalBounds = new Rect(left, top, left + w, top + h);
|
||||
mHoverCellCurrentBounds = new Rect(mHoverCellOriginalBounds);
|
||||
|
||||
drawable.setBounds(mHoverCellCurrentBounds);
|
||||
|
||||
return drawable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a black border over the screenshot of the view passed in.
|
||||
*/
|
||||
private Bitmap getBitmapWithBorder(View v) {
|
||||
Bitmap bitmap = getBitmapFromView(v);
|
||||
Canvas can = new Canvas(bitmap);
|
||||
|
||||
Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
|
||||
|
||||
Paint paint = new Paint();
|
||||
paint.setStyle(Paint.Style.STROKE);
|
||||
paint.setStrokeWidth(LINE_THICKNESS);
|
||||
paint.setColor(Color.BLACK);
|
||||
|
||||
can.drawBitmap(bitmap, 0, 0, null);
|
||||
can.drawRect(rect, paint);
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a bitmap showing a screenshot of the view passed in.
|
||||
*/
|
||||
private Bitmap getBitmapFromView(View v) {
|
||||
Bitmap bitmap = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888);
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
v.draw(canvas);
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores a reference to the views above and below the item currently
|
||||
* corresponding to the hover cell. It is important to note that if this
|
||||
* item is either at the top or bottom of the list, mAboveItemId or mBelowItemId
|
||||
* may be invalid.
|
||||
*/
|
||||
private void updateNeighborViewsForID(long itemID) {
|
||||
int position = getPositionForID(itemID);
|
||||
StableArrayAdapter adapter = ((StableArrayAdapter) getAdapter());
|
||||
mAboveItemId = adapter.getItemId(position - 1);
|
||||
mBelowItemId = adapter.getItemId(position + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the view in the list corresponding to itemID
|
||||
*/
|
||||
public View getViewForID(long itemID) {
|
||||
int firstVisiblePosition = getFirstVisiblePosition();
|
||||
StableArrayAdapter adapter = ((StableArrayAdapter) getAdapter());
|
||||
for (int i = 0; i < getChildCount(); i++) {
|
||||
View v = getChildAt(i);
|
||||
int position = firstVisiblePosition + i;
|
||||
long id = adapter.getItemId(position);
|
||||
if (id == itemID) {
|
||||
return v;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the position in the list corresponding to itemID
|
||||
*/
|
||||
public int getPositionForID(long itemID) {
|
||||
View v = getViewForID(itemID);
|
||||
if (v == null) {
|
||||
return -1;
|
||||
} else {
|
||||
return getPositionForView(v);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* dispatchDraw gets invoked when all the child views are about to be drawn.
|
||||
* By overriding this method, the hover cell (BitmapDrawable) can be drawn
|
||||
* over the listview's items whenever the listview is redrawn.
|
||||
*/
|
||||
@Override
|
||||
protected void dispatchDraw(Canvas canvas) {
|
||||
super.dispatchDraw(canvas);
|
||||
if (mHoverCell != null) {
|
||||
mHoverCell.draw(canvas);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
|
||||
switch (event.getAction() & MotionEvent.ACTION_MASK) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
mDownX = (int) event.getX();
|
||||
mDownY = (int) event.getY();
|
||||
mActivePointerId = event.getPointerId(0);
|
||||
break;
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
if (mActivePointerId == INVALID_POINTER_ID) {
|
||||
break;
|
||||
}
|
||||
|
||||
int pointerIndex = event.findPointerIndex(mActivePointerId);
|
||||
|
||||
mLastEventY = (int) event.getY(pointerIndex);
|
||||
int deltaY = mLastEventY - mDownY;
|
||||
|
||||
if (mCellIsMobile) {
|
||||
mHoverCellCurrentBounds.offsetTo(mHoverCellOriginalBounds.left,
|
||||
mHoverCellOriginalBounds.top + deltaY + mTotalOffset);
|
||||
mHoverCell.setBounds(mHoverCellCurrentBounds);
|
||||
invalidate();
|
||||
|
||||
handleCellSwitch();
|
||||
|
||||
mIsMobileScrolling = false;
|
||||
handleMobileCellScroll();
|
||||
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case MotionEvent.ACTION_UP:
|
||||
touchEventsEnded();
|
||||
break;
|
||||
case MotionEvent.ACTION_CANCEL:
|
||||
touchEventsCancelled();
|
||||
break;
|
||||
case MotionEvent.ACTION_POINTER_UP:
|
||||
/* If a multitouch event took place and the original touch dictating
|
||||
* the movement of the hover cell has ended, then the dragging event
|
||||
* ends and the hover cell is animated to its corresponding position
|
||||
* in the listview. */
|
||||
pointerIndex = (event.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >>
|
||||
MotionEvent.ACTION_POINTER_INDEX_SHIFT;
|
||||
final int pointerId = event.getPointerId(pointerIndex);
|
||||
if (pointerId == mActivePointerId) {
|
||||
touchEventsEnded();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return super.onTouchEvent(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method determines whether the hover cell has been shifted far enough
|
||||
* to invoke a cell swap. If so, then the respective cell swap candidate is
|
||||
* determined and the data set is changed. Upon posting a notification of the
|
||||
* data set change, a layout is invoked to place the cells in the right place.
|
||||
* Using a ViewTreeObserver and a corresponding OnPreDrawListener, we can
|
||||
* offset the cell being swapped to where it previously was and then animate it to
|
||||
* its new position.
|
||||
*/
|
||||
private void handleCellSwitch() {
|
||||
final int deltaY = mLastEventY - mDownY;
|
||||
int deltaYTotal = mHoverCellOriginalBounds.top + mTotalOffset + deltaY;
|
||||
|
||||
View belowView = getViewForID(mBelowItemId);
|
||||
View mobileView = getViewForID(mMobileItemId);
|
||||
View aboveView = getViewForID(mAboveItemId);
|
||||
|
||||
boolean isBelow = (belowView != null) && (deltaYTotal > belowView.getTop());
|
||||
boolean isAbove = (aboveView != null) && (deltaYTotal < aboveView.getTop());
|
||||
|
||||
if (isBelow || isAbove) {
|
||||
|
||||
final long switchItemID = isBelow ? mBelowItemId : mAboveItemId;
|
||||
View switchView = isBelow ? belowView : aboveView;
|
||||
final int originalItem = getPositionForView(mobileView);
|
||||
|
||||
if (switchView == null) {
|
||||
updateNeighborViewsForID(mMobileItemId);
|
||||
return;
|
||||
}
|
||||
|
||||
swapElements(mList, originalItem, getPositionForView(switchView));
|
||||
|
||||
((BaseAdapter) getAdapter()).notifyDataSetChanged();
|
||||
|
||||
mDownY = mLastEventY;
|
||||
|
||||
final int switchViewStartTop = switchView.getTop();
|
||||
|
||||
mobileView.setVisibility(View.VISIBLE);
|
||||
switchView.setVisibility(View.INVISIBLE);
|
||||
|
||||
updateNeighborViewsForID(mMobileItemId);
|
||||
|
||||
final ViewTreeObserver observer = getViewTreeObserver();
|
||||
observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
|
||||
public boolean onPreDraw() {
|
||||
observer.removeOnPreDrawListener(this);
|
||||
|
||||
View switchView = getViewForID(switchItemID);
|
||||
|
||||
mTotalOffset += deltaY;
|
||||
|
||||
int switchViewNewTop = switchView.getTop();
|
||||
int delta = switchViewStartTop - switchViewNewTop;
|
||||
|
||||
switchView.setTranslationY(delta);
|
||||
|
||||
ObjectAnimator animator = ObjectAnimator.ofFloat(switchView,
|
||||
View.TRANSLATION_Y, 0);
|
||||
animator.setDuration(MOVE_DURATION);
|
||||
animator.start();
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void swapElements(List arrayList, int indexOne, int indexTwo) {
|
||||
Object temp = arrayList.get(indexOne);
|
||||
arrayList.set(indexOne, arrayList.get(indexTwo));
|
||||
arrayList.set(indexTwo, temp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets all the appropriate fields to a default state while also animating
|
||||
* the hover cell back to its correct location.
|
||||
*/
|
||||
private void touchEventsEnded() {
|
||||
final View mobileView = getViewForID(mMobileItemId);
|
||||
if (mCellIsMobile || mIsWaitingForScrollFinish) {
|
||||
mCellIsMobile = false;
|
||||
mIsWaitingForScrollFinish = false;
|
||||
mIsMobileScrolling = false;
|
||||
mActivePointerId = INVALID_POINTER_ID;
|
||||
|
||||
// If the autoscroller has not completed scrolling, we need to wait for it to
|
||||
// finish in order to determine the final location of where the hover cell
|
||||
// should be animated to.
|
||||
if (mScrollState != OnScrollListener.SCROLL_STATE_IDLE) {
|
||||
mIsWaitingForScrollFinish = true;
|
||||
return;
|
||||
}
|
||||
|
||||
mHoverCellCurrentBounds.offsetTo(mHoverCellOriginalBounds.left, mobileView.getTop());
|
||||
|
||||
ObjectAnimator hoverViewAnimator = ObjectAnimator.ofObject(mHoverCell, "bounds",
|
||||
sBoundEvaluator, mHoverCellCurrentBounds);
|
||||
hoverViewAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
|
||||
@Override
|
||||
public void onAnimationUpdate(ValueAnimator valueAnimator) {
|
||||
invalidate();
|
||||
}
|
||||
});
|
||||
hoverViewAnimator.addListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationStart(Animator animation) {
|
||||
setEnabled(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
mAboveItemId = INVALID_ID;
|
||||
mMobileItemId = INVALID_ID;
|
||||
mBelowItemId = INVALID_ID;
|
||||
mobileView.setVisibility(VISIBLE);
|
||||
mHoverCell = null;
|
||||
setEnabled(true);
|
||||
invalidate();
|
||||
}
|
||||
});
|
||||
hoverViewAnimator.start();
|
||||
} else {
|
||||
touchEventsCancelled();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets all the appropriate fields to a default state.
|
||||
*/
|
||||
private void touchEventsCancelled() {
|
||||
View mobileView = getViewForID(mMobileItemId);
|
||||
if (mCellIsMobile) {
|
||||
mAboveItemId = INVALID_ID;
|
||||
mMobileItemId = INVALID_ID;
|
||||
mBelowItemId = INVALID_ID;
|
||||
mobileView.setVisibility(VISIBLE);
|
||||
mHoverCell = null;
|
||||
invalidate();
|
||||
}
|
||||
mCellIsMobile = false;
|
||||
mIsMobileScrolling = false;
|
||||
mActivePointerId = INVALID_POINTER_ID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether this listview is in a scrolling state invoked
|
||||
* by the fact that the hover cell is out of the bounds of the listview;
|
||||
*/
|
||||
private void handleMobileCellScroll() {
|
||||
mIsMobileScrolling = handleMobileCellScroll(mHoverCellCurrentBounds);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is in charge of determining if the hover cell is above
|
||||
* or below the bounds of the listview. If so, the listview does an appropriate
|
||||
* upward or downward smooth scroll so as to reveal new items.
|
||||
*/
|
||||
public boolean handleMobileCellScroll(Rect r) {
|
||||
int offset = computeVerticalScrollOffset();
|
||||
int height = getHeight();
|
||||
int extent = computeVerticalScrollExtent();
|
||||
int range = computeVerticalScrollRange();
|
||||
int hoverViewTop = r.top;
|
||||
int hoverHeight = r.height();
|
||||
|
||||
if (hoverViewTop <= 0 && offset > 0) {
|
||||
smoothScrollBy(-mSmoothScrollAmountAtEdge, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (hoverViewTop + hoverHeight >= height && (offset + extent) < range) {
|
||||
smoothScrollBy(mSmoothScrollAmountAtEdge, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setList(List<ServiceInfo> list) {
|
||||
this.mList = list;
|
||||
}
|
||||
|
||||
/**
|
||||
* This scroll listener is added to the listview in order to handle cell swapping
|
||||
* when the cell is either at the top or bottom edge of the listview. If the hover
|
||||
* cell is at either edge of the listview, the listview will begin scrolling. As
|
||||
* scrolling takes place, the listview continuously checks if new cells became visible
|
||||
* and determines whether they are potential candidates for a cell swap.
|
||||
*/
|
||||
private AbsListView.OnScrollListener mScrollListener = new AbsListView.OnScrollListener() {
|
||||
|
||||
private int mPreviousFirstVisibleItem = -1;
|
||||
private int mPreviousVisibleItemCount = -1;
|
||||
private int mCurrentFirstVisibleItem;
|
||||
private int mCurrentVisibleItemCount;
|
||||
private int mCurrentScrollState;
|
||||
|
||||
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
|
||||
int totalItemCount) {
|
||||
mCurrentFirstVisibleItem = firstVisibleItem;
|
||||
mCurrentVisibleItemCount = visibleItemCount;
|
||||
|
||||
mPreviousFirstVisibleItem = (mPreviousFirstVisibleItem == -1) ? mCurrentFirstVisibleItem
|
||||
: mPreviousFirstVisibleItem;
|
||||
mPreviousVisibleItemCount = (mPreviousVisibleItemCount == -1) ? mCurrentVisibleItemCount
|
||||
: mPreviousVisibleItemCount;
|
||||
|
||||
checkAndHandleFirstVisibleCellChange();
|
||||
checkAndHandleLastVisibleCellChange();
|
||||
|
||||
mPreviousFirstVisibleItem = mCurrentFirstVisibleItem;
|
||||
mPreviousVisibleItemCount = mCurrentVisibleItemCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScrollStateChanged(AbsListView view, int scrollState) {
|
||||
mCurrentScrollState = scrollState;
|
||||
mScrollState = scrollState;
|
||||
isScrollCompleted();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is in charge of invoking 1 of 2 actions. Firstly, if the listview
|
||||
* is in a state of scrolling invoked by the hover cell being outside the bounds
|
||||
* of the listview, then this scrolling event is continued. Secondly, if the hover
|
||||
* cell has already been released, this invokes the animation for the hover cell
|
||||
* to return to its correct position after the listview has entered an idle scroll
|
||||
* state.
|
||||
*/
|
||||
private void isScrollCompleted() {
|
||||
if (mCurrentVisibleItemCount > 0 && mCurrentScrollState == SCROLL_STATE_IDLE) {
|
||||
if (mCellIsMobile && mIsMobileScrolling) {
|
||||
handleMobileCellScroll();
|
||||
} else if (mIsWaitingForScrollFinish) {
|
||||
touchEventsEnded();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the listview scrolled up enough to reveal a new cell at the
|
||||
* top of the list. If so, then the appropriate parameters are updated.
|
||||
*/
|
||||
public void checkAndHandleFirstVisibleCellChange() {
|
||||
if (mCurrentFirstVisibleItem != mPreviousFirstVisibleItem) {
|
||||
if (mCellIsMobile && mMobileItemId != INVALID_ID) {
|
||||
updateNeighborViewsForID(mMobileItemId);
|
||||
handleCellSwitch();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the listview scrolled down enough to reveal a new cell at the
|
||||
* bottom of the list. If so, then the appropriate parameters are updated.
|
||||
*/
|
||||
public void checkAndHandleLastVisibleCellChange() {
|
||||
int currentLastVisibleItem = mCurrentFirstVisibleItem + mCurrentVisibleItemCount;
|
||||
int previousLastVisibleItem = mPreviousFirstVisibleItem + mPreviousVisibleItemCount;
|
||||
if (currentLastVisibleItem != previousLastVisibleItem) {
|
||||
if (mCellIsMobile && mMobileItemId != INVALID_ID) {
|
||||
updateNeighborViewsForID(mMobileItemId);
|
||||
handleCellSwitch();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public static class StableArrayAdapter extends ArrayAdapter<ServiceInfo> {
|
||||
|
||||
final int INVALID_ID = -1;
|
||||
|
||||
HashMap<ServiceInfo, Integer> mIdMap = new HashMap<ServiceInfo, Integer>();
|
||||
|
||||
public StableArrayAdapter(Context context, int rootViewResourceId, int textViewResourceId,
|
||||
List<ServiceInfo> objects) {
|
||||
super(context, rootViewResourceId, textViewResourceId, objects);
|
||||
init(objects);
|
||||
}
|
||||
|
||||
private void init(List<ServiceInfo> objects) {
|
||||
for (int i = 0; i < objects.size(); ++i) {
|
||||
mIdMap.put(objects.get(i), i);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
if (position < 0 || position >= mIdMap.size()) {
|
||||
return INVALID_ID;
|
||||
}
|
||||
ServiceInfo item = getItem(position);
|
||||
return mIdMap.get(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasStableIds() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package org.microg.nlp.ui;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import org.microg.nlp.R;
|
||||
|
||||
public class GeocodeBackendConfig extends ActionBarActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.geocoder_backend_config_activity);
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
if (toolbar != null) {
|
||||
setSupportActionBar(toolbar);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
package org.microg.nlp.ui;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.content.pm.ServiceInfo;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import org.microg.nlp.Preferences;
|
||||
import org.microg.nlp.geocode.GeocodeService;
|
||||
import org.microg.nlp.location.LocationService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.microg.nlp.api.NlpApiConstants.ACTION_GEOCODER_BACKEND;
|
||||
import static org.microg.nlp.api.NlpApiConstants.ACTION_LOCATION_BACKEND;
|
||||
|
||||
public class GeocodeBackendConfigFragment extends AbstractBackendConfigFragment {
|
||||
private static final String TAG = GeocodeBackendConfigFragment.class.getName();
|
||||
|
||||
public GeocodeBackendConfigFragment() {
|
||||
super(TAG);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<ServiceInfo, KnownBackend> queryKnownBackends() {
|
||||
return intentToKnownBackendMap(getActivity(), new Intent(ACTION_GEOCODER_BACKEND));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<ServiceInfo> queryActiveBackends() {
|
||||
return backendStringToServiceInfos(new Preferences(getActivity()).getGeocoderBackends(),
|
||||
getKnownBackends().keySet());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveActiveBackends(List<ServiceInfo> activeBackends) {
|
||||
new Preferences(getActivity()).setGeocoderBackends(serviceInfosToBackendString(activeBackends));
|
||||
GeocodeService.reloadLocationService(getActivity());
|
||||
}
|
||||
}
|
33
src/org/microg/nlp/ui/GeocoderBackendPreference.java
Normal file
|
@ -0,0 +1,33 @@
|
|||
package org.microg.nlp.ui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.util.AttributeSet;
|
||||
import org.microg.nlp.Preferences;
|
||||
import org.microg.nlp.R;
|
||||
import org.microg.nlp.geocode.GeocodeService;
|
||||
|
||||
import static org.microg.nlp.api.NlpApiConstants.ACTION_GEOCODER_BACKEND;
|
||||
|
||||
public class GeocoderBackendPreference extends AbstractBackendPreference {
|
||||
public GeocoderBackendPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
setDialogTitle(R.string.configure_geocoder_backends);
|
||||
setTitle(R.string.configure_geocoder_backends);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onValueChanged() {
|
||||
GeocodeService.reloadLocationService(getContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Intent buildBackendIntent() {
|
||||
return new Intent(ACTION_GEOCODER_BACKEND);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String defaultValue() {
|
||||
return new Preferences(getContext()).getDefaultGeocoderBackends();
|
||||
}
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
package org.microg.nlp.ui;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import org.microg.nlp.R;
|
||||
|
||||
public class LocationBackendConfig extends ActionBarActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.location_backend_config_activity);
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
if (toolbar != null) {
|
||||
setSupportActionBar(toolbar);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
package org.microg.nlp.ui;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ServiceInfo;
|
||||
import org.microg.nlp.Preferences;
|
||||
import org.microg.nlp.location.LocationService;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.microg.nlp.api.NlpApiConstants.ACTION_LOCATION_BACKEND;
|
||||
|
||||
public class LocationBackendConfigFragment extends AbstractBackendConfigFragment {
|
||||
private static final String TAG = LocationBackendConfigFragment.class.getName();
|
||||
|
||||
public LocationBackendConfigFragment() {
|
||||
super(TAG);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<ServiceInfo, AbstractBackendConfigFragment.KnownBackend> queryKnownBackends() {
|
||||
return intentToKnownBackendMap(getActivity(), new Intent(ACTION_LOCATION_BACKEND));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<ServiceInfo> queryActiveBackends() {
|
||||
return backendStringToServiceInfos(new Preferences(getActivity()).getLocationBackends(),
|
||||
getKnownBackends().keySet());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveActiveBackends(List<ServiceInfo> activeBackends) {
|
||||
new Preferences(getActivity())
|
||||
.setLocationBackends(serviceInfosToBackendString(activeBackends));
|
||||
LocationService.reloadLocationService(getActivity());
|
||||
}
|
||||
|
||||
}
|
33
src/org/microg/nlp/ui/LocationBackendPreference.java
Normal file
|
@ -0,0 +1,33 @@
|
|||
package org.microg.nlp.ui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.util.AttributeSet;
|
||||
import org.microg.nlp.Preferences;
|
||||
import org.microg.nlp.R;
|
||||
import org.microg.nlp.location.LocationService;
|
||||
|
||||
import static org.microg.nlp.api.NlpApiConstants.ACTION_LOCATION_BACKEND;
|
||||
|
||||
public class LocationBackendPreference extends AbstractBackendPreference {
|
||||
public LocationBackendPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
setDialogTitle(R.string.configure_location_backends);
|
||||
setTitle(R.string.configure_location_backends);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onValueChanged() {
|
||||
LocationService.reloadLocationService(getContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Intent buildBackendIntent() {
|
||||
return new Intent(ACTION_LOCATION_BACKEND);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String defaultValue() {
|
||||
return new Preferences(getContext()).getDefaultLocationBackends();
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
package org.microg.nlp.ui;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.View;
|
||||
import org.microg.nlp.R;
|
||||
|
||||
public class PreferencesActivity extends ActionBarActivity {
|
||||
private Toolbar toolbar;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.nlp_config);
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
if (toolbar != null) {
|
||||
setSupportActionBar(toolbar);
|
||||
}
|
||||
findViewById(R.id.location_backends).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
startActivity(new Intent(PreferencesActivity.this, LocationBackendConfig.class));
|
||||
}
|
||||
});
|
||||
findViewById(R.id.geocoder_backends).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
startActivity(new Intent(PreferencesActivity.this, GeocodeBackendConfig.class));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
40
src/org/microg/nlp/ui/SettingsActivity.java
Normal file
|
@ -0,0 +1,40 @@
|
|||
package org.microg.nlp.ui;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceActivity;
|
||||
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;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
addPreferencesFromResource(R.xml.nlp_preferences);
|
||||
toolbar.setTitle(getTitle());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentView(int layoutResID) {
|
||||
ViewGroup contentView = (ViewGroup) LayoutInflater.from(this)
|
||||
.inflate(R.layout.settings_activity, new LinearLayout(this), false);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|