Added BidForFix list in settings
This commit is contained in:
parent
e18f8fe18e
commit
8fc5284837
5 changed files with 251 additions and 5 deletions
|
@ -1,5 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<resources>
|
||||
<string name="default_buttons_support">Support</string>
|
||||
<string name="support_new_features">Support new features</string>
|
||||
|
||||
<string name="show_ruler_level_descr">Display ruler on the map</string>
|
||||
<string name="show_ruler_level">Display ruler</string>
|
||||
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
|
||||
<PreferenceCategory android:title="@string/profile_settings">
|
||||
<ListPreference android:summary="@string/settings_preset_descr" android:title="@string/settings_preset" android:key="application_mode"></ListPreference>
|
||||
|
||||
|
||||
<PreferenceScreen android:key="map_settings" android:title="@string/rendering_settings" android:summary="@string/rendering_settings_descr">
|
||||
<PreferenceCategory android:title="@string/pref_raster_map">
|
||||
<CheckBoxPreference android:summary="@string/map_vector_data_descr" android:title="@string/map_vector_data"
|
||||
|
@ -123,7 +121,6 @@
|
|||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
||||
|
||||
|
||||
<PreferenceScreen android:title="@string/osmand_service" android:summary="@string/osmand_service_descr">
|
||||
<CheckBoxPreference android:summary="@string/background_router_service_descr" android:title="@string/background_router_service"
|
||||
android:key="service_off_enabled"></CheckBoxPreference>
|
||||
|
|
225
OsmAnd/src/com/bidforfix/andorid/BidForFixHelper.java
Normal file
225
OsmAnd/src/com/bidforfix/andorid/BidForFixHelper.java
Normal file
|
@ -0,0 +1,225 @@
|
|||
package com.bidforfix.andorid;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import net.osmand.plus.R;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONTokener;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.AlertDialog.Builder;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.DialogInterface.OnClickListener;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.preference.Preference;
|
||||
import android.preference.Preference.OnPreferenceClickListener;
|
||||
import android.preference.PreferenceCategory;
|
||||
import android.preference.PreferenceScreen;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class BidForFixHelper {
|
||||
|
||||
private static final long DAY = 1000*60*60*24; //A DAY in millis
|
||||
|
||||
private List<BFFIssue> bffIssues = new ArrayList<BFFIssue>();
|
||||
private final String project;
|
||||
private Thread t;
|
||||
private Date initialized;
|
||||
|
||||
private final String supportButton;
|
||||
|
||||
private final String cancelButton;
|
||||
|
||||
public static class BFFIssue {
|
||||
private final String link;
|
||||
private final String name;
|
||||
private final String shortname;
|
||||
private final String descripton;
|
||||
|
||||
public BFFIssue(JSONObject jsonObject) {
|
||||
this.link = getValue(jsonObject, "link");
|
||||
this.name = getValue(jsonObject, "name");
|
||||
this.shortname = getValue(jsonObject, "short_name");
|
||||
this.descripton = getValue(jsonObject, "description");
|
||||
}
|
||||
|
||||
private String getValue(JSONObject jsonObject, String key) {
|
||||
try {
|
||||
return jsonObject.getString(key);
|
||||
} catch (JSONException e) {
|
||||
// ignore
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public BFFIssue(String link, String name, String shortname,
|
||||
String descripton) {
|
||||
this.link = link;
|
||||
this.name = name;
|
||||
this.shortname = shortname;
|
||||
this.descripton = descripton;
|
||||
}
|
||||
|
||||
public String getDescripton() {
|
||||
return descripton;
|
||||
}
|
||||
|
||||
public String getLink() {
|
||||
if (link.startsWith("http://")) {
|
||||
return link;
|
||||
} else {
|
||||
return "http://www.bidforfix.com"+link;
|
||||
}
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getShortname() {
|
||||
return shortname;
|
||||
}
|
||||
}
|
||||
|
||||
public BidForFixHelper(String project, String supportButton, String cancelButton) {
|
||||
this.project = project;
|
||||
this.supportButton = supportButton;
|
||||
this.cancelButton = cancelButton;
|
||||
}
|
||||
|
||||
private void loadList() {
|
||||
if (initialized == null || initialized.before(new Date(System.currentTimeMillis()-DAY))) {
|
||||
BufferedReader in = null;
|
||||
String project = "demo.bidforfix.com"; // TODO for testing...
|
||||
String url = "http://bidforfix-test.appspot.com/p/"
|
||||
+ project + "/issues/";
|
||||
try {
|
||||
URL twitter = new URL(url);
|
||||
URLConnection tc = twitter.openConnection();
|
||||
in = new BufferedReader(new InputStreamReader(
|
||||
tc.getInputStream()));
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String line;
|
||||
while ((line = in.readLine()) != null) {
|
||||
sb.append(line);
|
||||
}
|
||||
JSONTokener json = new JSONTokener(sb.toString());
|
||||
JSONObject root = (JSONObject) json.nextValue();
|
||||
if (root != null) {
|
||||
JSONArray issues = root.getJSONArray("issues");
|
||||
for (int i = 0; i < issues.length(); i++) {
|
||||
JSONObject jo = (JSONObject) issues.get(i);
|
||||
bffIssues.add(new BFFIssue(jo));
|
||||
}
|
||||
}
|
||||
initialized = new Date();
|
||||
} catch (MalformedURLException e) {
|
||||
initialized = new Date(Long.MAX_VALUE); //bad url, don't try anymore
|
||||
Log.w("Bad URL:" + url, e);
|
||||
} catch (IOException e) {
|
||||
//we can try some more times...
|
||||
} catch (JSONException e) {
|
||||
//bad json, try in two day again
|
||||
initialized = new Date(System.currentTimeMillis()+DAY*2);
|
||||
Log.w("Bad JSON while parsing bidforfix output", e);
|
||||
} finally {
|
||||
if (in != null) {
|
||||
try {
|
||||
in.close();
|
||||
} catch (IOException ex) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void generatePreferenceList(final PreferenceScreen screen,
|
||||
final String categoryName, final Activity context) {
|
||||
t = new Thread("BidForFixThread") {
|
||||
@Override
|
||||
public void run() {
|
||||
loadList();
|
||||
// after loading, fill the screen
|
||||
if (!bffIssues.isEmpty()) {
|
||||
context.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PreferenceCategory cat = new PreferenceCategory(
|
||||
context);
|
||||
cat.setTitle(categoryName);
|
||||
screen.addPreference(cat);
|
||||
for (int i = 0; i < bffIssues.size(); i++) {
|
||||
final BFFIssue issue = bffIssues.get(i);
|
||||
Preference preference = new Preference(context);
|
||||
preference.setTitle(issue.getName());
|
||||
preference.setSummary(issue.getDescripton());
|
||||
preference
|
||||
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(
|
||||
Preference preference) {
|
||||
Builder builder = new AlertDialog.Builder(context);
|
||||
builder.setTitle(issue.name);
|
||||
builder.setMessage(issue.descripton);
|
||||
builder.setPositiveButton(supportButton, new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
//edit the preference
|
||||
String url = issue.getLink();
|
||||
try {
|
||||
Intent i = new Intent(Intent.ACTION_VIEW);
|
||||
i.setData(Uri.parse(url));
|
||||
context.startActivity(i);
|
||||
} catch (ActivityNotFoundException ex) {
|
||||
Toast.makeText(context, ex.getMessage() + " for " + url, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(cancelButton, null);
|
||||
builder.show();
|
||||
|
||||
return false;
|
||||
}
|
||||
});
|
||||
cat.addPreference(preference);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
t = null;
|
||||
}
|
||||
};
|
||||
t.setDaemon(true);
|
||||
t.start();
|
||||
}
|
||||
|
||||
public void onDestroy() {
|
||||
// close the thread, release resources...
|
||||
if (t != null) {
|
||||
try {
|
||||
t.join(); // wait for the thread
|
||||
// TODO we should wait for the runOnUIThread??? is that possible
|
||||
// if we are in UI thread now?
|
||||
} catch (InterruptedException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -15,6 +15,11 @@ import net.osmand.FavouritePoint;
|
|||
import net.osmand.GPXUtilities;
|
||||
import net.osmand.GPXUtilities.GPXFile;
|
||||
import net.osmand.GPXUtilities.WptPt;
|
||||
import net.osmand.plus.FavouritesDbHelper;
|
||||
import net.osmand.plus.NavigationService;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.PoiFiltersHelper;
|
||||
import net.osmand.plus.ProgressDialogImplementation;
|
||||
import net.osmand.LogUtil;
|
||||
import net.osmand.access.AccessibleToast;
|
||||
import net.osmand.plus.activities.DayNightHelper;
|
||||
|
@ -40,6 +45,8 @@ import android.os.Handler;
|
|||
import android.text.format.DateFormat;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.bidforfix.andorid.BidForFixHelper;
|
||||
|
||||
public class OsmandApplication extends Application {
|
||||
public static final String EXCEPTION_PATH = ResourceManager.APP_DIR + "exception.log"; //$NON-NLS-1$
|
||||
private static final org.apache.commons.logging.Log LOG = LogUtil.getLog(OsmandApplication.class);
|
||||
|
@ -59,6 +66,7 @@ public class OsmandApplication extends Application {
|
|||
DayNightHelper daynightHelper;
|
||||
NavigationService navigationService;
|
||||
RendererRegistry rendererRegistry;
|
||||
BidForFixHelper bidforfix;
|
||||
|
||||
// start variables
|
||||
private ProgressDialogImplementation startDialog;
|
||||
|
@ -78,6 +86,7 @@ public class OsmandApplication extends Application {
|
|||
routingHelper = new RoutingHelper(osmandSettings, this, player);
|
||||
manager = new ResourceManager(this);
|
||||
daynightHelper = new DayNightHelper(this);
|
||||
bidforfix = new BidForFixHelper("osmand.net", getString(R.string.default_buttons_support), getString(R.string.default_buttons_cancel));
|
||||
uiHandler = new Handler();
|
||||
rendererRegistry = new RendererRegistry();
|
||||
checkPrefferedLocale();
|
||||
|
@ -93,6 +102,9 @@ public class OsmandApplication extends Application {
|
|||
if (routingHelper != null) {
|
||||
routingHelper.getVoiceRouter().onApplicationTerminate(getApplicationContext());
|
||||
}
|
||||
if (bidforfix != null) {
|
||||
bidforfix.onDestroy();
|
||||
}
|
||||
}
|
||||
|
||||
public RendererRegistry getRendererRegistry() {
|
||||
|
@ -305,6 +317,11 @@ public class OsmandApplication extends Application {
|
|||
this.navigationService = navigationService;
|
||||
}
|
||||
|
||||
public BidForFixHelper getBidForFix() {
|
||||
return bidforfix;
|
||||
}
|
||||
|
||||
|
||||
public synchronized void closeApplication() {
|
||||
if (applicationInitializing) {
|
||||
manager.close();
|
||||
|
@ -464,5 +481,4 @@ public class OsmandApplication extends Application {
|
|||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -59,6 +59,8 @@ import android.preference.PreferenceCategory;
|
|||
import android.preference.PreferenceScreen;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.bidforfix.andorid.BidForFixHelper;
|
||||
|
||||
public class SettingsActivity extends PreferenceActivity implements OnPreferenceChangeListener, OnPreferenceClickListener {
|
||||
|
||||
public static final String INTENT_KEY_SETTINGS_SCREEN = "INTENT_KEY_SETTINGS_SCREEN";
|
||||
|
@ -173,6 +175,9 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
|||
PreferenceScreen screen = getPreferenceScreen();
|
||||
osmandSettings = OsmandApplication.getSettings();
|
||||
|
||||
BidForFixHelper bidForFixHelper = getMyApplication().getBidForFix();
|
||||
bidForFixHelper.generatePreferenceList(screen, getString(R.string.support_new_features), this);
|
||||
|
||||
registerBooleanPreference(osmandSettings.SHOW_VIEW_ANGLE,screen);
|
||||
registerBooleanPreference(osmandSettings.USE_TRACKBALL_FOR_MOVEMENTS,screen);
|
||||
registerBooleanPreference(osmandSettings.ZOOM_BY_TRACKBALL,screen);
|
||||
|
|
Loading…
Reference in a new issue