Refactor activities
This commit is contained in:
parent
115924384f
commit
dded78403b
12 changed files with 388 additions and 306 deletions
|
@ -147,8 +147,6 @@
|
|||
<activity android:name="net.osmand.plus.activities.search.SearchStreetByNameActivity"></activity>
|
||||
<activity android:name="net.osmand.plus.activities.search.SearchStreet2ByNameActivity"></activity>
|
||||
<activity android:name="net.osmand.plus.activities.search.SearchBuildingByNameActivity"></activity>
|
||||
<activity android:name="net.osmand.plus.sherpafy.TourCommonActivity"></activity>
|
||||
<activity android:name="net.osmand.plus.sherpafy.SherpafySelectTourActivity" />
|
||||
<activity android:name="net.osmand.plus.sherpafy.TourViewActivity" android:exported="true" android:launchMode= "singleInstance"/>
|
||||
<activity android:name="net.osmand.plus.activities.EditPOIFilterActivity"></activity>
|
||||
<activity android:name="net.osmand.plus.activities.search.GeoIntentActivity">
|
||||
|
|
26
OsmAnd/res/layout/sherpafy_loading.xml
Normal file
26
OsmAnd/res/layout/sherpafy_loading.xml
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent" >
|
||||
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:gravity="center_vertical|center_horizontal"
|
||||
android:orientation="horizontal" >
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/ProgressBar"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/ProgressMessage"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/loading_data"
|
||||
android:textSize="22sp" />
|
||||
</LinearLayout>
|
||||
|
||||
</FrameLayout>
|
|
@ -1,22 +1,37 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<LinearLayout android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:orientation="horizontal">
|
||||
<Button android:id="@+id/select_tour"
|
||||
android:layout_marginRight="10dp"
|
||||
android:layout_width="120dp"
|
||||
android:text="@string/select_tour"
|
||||
android:layout_height="wrap_content"/>
|
||||
<Button android:id="@+id/download_tour"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:text="@string/download_tour"
|
||||
android:layout_width="120dp"
|
||||
android:layout_height="wrap_content"/>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal" >
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginRight="10dp"
|
||||
android:layout_weight="1" >
|
||||
|
||||
<Button
|
||||
android:id="@+id/select_tour"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:singleLine="true"
|
||||
android:text="@string/select_tour" />
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_weight="1" >
|
||||
|
||||
<Button
|
||||
android:id="@+id/download_tour"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:singleLine="true"
|
||||
android:text="@string/download_tour" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
|
@ -5,24 +5,27 @@
|
|||
android:orientation="vertical" >
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginLeft="15dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:orientation="horizontal" >
|
||||
|
||||
<ToggleButton
|
||||
android:id="@+id/collapse"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textOn=""
|
||||
android:textOff=""
|
||||
android:button="@drawable/expandable_category"
|
||||
android:background="@null" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tour_name"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginLeft="5dp"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/select_tour"
|
||||
android:textSize="21sp" />
|
||||
|
@ -31,7 +34,6 @@
|
|||
android:id="@+id/start_tour"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="right"
|
||||
android:layout_marginRight="5dp"
|
||||
android:text="@string/start_tour" />
|
||||
</LinearLayout>
|
||||
|
@ -42,7 +44,7 @@
|
|||
android:layout_height="fill_parent" >
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:layout_marginRight="8dp"
|
||||
|
@ -58,7 +60,7 @@
|
|||
|
||||
<TextView
|
||||
android:id="@+id/tour_description"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="2dp"
|
||||
android:layout_marginTop="2dp"
|
||||
|
@ -76,7 +78,7 @@
|
|||
|
||||
<TextView
|
||||
android:id="@+id/tour_fulldescription"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="textMultiLine"
|
||||
android:layout_marginBottom="2dp"
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<resources>
|
||||
<string name="selecting_tour_progress">"Selecting tour...</string>
|
||||
<string name="overview">Overview</string>
|
||||
<string name="selecting_tour_progress">Selecting tour...</string>
|
||||
<string name="no_stages_provided">No stages provided</string>
|
||||
<string name="download_more">Download more</string>
|
||||
<string name="no_tour_selected">No tour selected</string>
|
||||
|
|
|
@ -63,6 +63,7 @@ import android.util.TypedValue;
|
|||
import android.view.accessibility.AccessibilityManager;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.LinearLayout.LayoutParams;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
@ -96,8 +97,7 @@ public class OsmandApplication extends Application {
|
|||
OsmAndTaskManager taskManager;
|
||||
|
||||
// start variables
|
||||
private ProgressDialogImplementation startDialog;
|
||||
private List<String> startingWarnings;
|
||||
private ProgressImplementation startDialog;
|
||||
private Handler uiHandler;
|
||||
private GPXFile gpxFileToDisplay;
|
||||
private SavingTrackHelper savingTrackHelper;
|
||||
|
@ -307,33 +307,31 @@ public class OsmandApplication extends Application {
|
|||
|
||||
public static final int PROGRESS_DIALOG = 5;
|
||||
|
||||
/**
|
||||
* @param activity
|
||||
* that supports onCreateDialog({@link #PROGRESS_DIALOG}) and returns @param progressdialog
|
||||
* @param progressDialog
|
||||
* - it should be exactly the same as onCreateDialog
|
||||
* @return
|
||||
*/
|
||||
public void checkApplicationIsBeingInitialized(Activity activity, ProgressDialog progressDialog) {
|
||||
// start application if it was previously closed
|
||||
startApplication();
|
||||
synchronized (OsmandApplication.this) {
|
||||
if (startDialog != null) {
|
||||
try {
|
||||
SpecialPhrases.setLanguage(this, osmandSettings);
|
||||
} catch (IOException e) {
|
||||
LOG.error("I/O exception", e);
|
||||
Toast error = Toast.makeText(this, "Error while reading the special phrases. Restart OsmAnd if possible",
|
||||
Toast.LENGTH_LONG);
|
||||
error.show();
|
||||
}
|
||||
|
||||
progressDialog.setTitle(getString(R.string.loading_data));
|
||||
progressDialog.setMessage(getString(R.string.reading_indexes));
|
||||
activity.showDialog(PROGRESS_DIALOG);
|
||||
startDialog.setDialog(progressDialog);
|
||||
} else if (startingWarnings != null) {
|
||||
showWarnings(startingWarnings, activity);
|
||||
} else {
|
||||
progressDialog.dismiss();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void checkApplicationIsBeingInitialized(Activity activity, TextView tv, ProgressBar progressBar,
|
||||
Runnable onClose) {
|
||||
// start application if it was previously closed
|
||||
startApplication();
|
||||
synchronized (OsmandApplication.this) {
|
||||
if (startDialog != null ) {
|
||||
tv.setText(getString(R.string.loading_data));
|
||||
startDialog.setProgressBar(tv, progressBar, onClose);
|
||||
} else if (onClose != null) {
|
||||
onClose.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -433,7 +431,7 @@ public class OsmandApplication extends Application {
|
|||
if(dlg != null) {
|
||||
dlg.dismiss();
|
||||
}
|
||||
showWarning(uiContext, e.getError());
|
||||
showToastMessage(e.getError());
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
|
@ -513,7 +511,7 @@ public class OsmandApplication extends Application {
|
|||
return;
|
||||
}
|
||||
applicationInitializing = true;
|
||||
startDialog = new ProgressDialogImplementation(this, null, false);
|
||||
startDialog = new ProgressImplementation(this, null, false);
|
||||
|
||||
startDialog.setRunnable("Initializing app", new Runnable() { //$NON-NLS-1$
|
||||
@Override
|
||||
|
@ -530,6 +528,12 @@ public class OsmandApplication extends Application {
|
|||
private void startApplicationBackground() {
|
||||
List<String> warnings = new ArrayList<String>();
|
||||
try {
|
||||
try {
|
||||
SpecialPhrases.setLanguage(this, osmandSettings);
|
||||
} catch (IOException e) {
|
||||
LOG.error("I/O exception", e);
|
||||
warnings.add("Error while reading the special phrases. Restart OsmAnd if possible");
|
||||
}
|
||||
if (!Version.isBlackberry(this)) {
|
||||
if (osmandSettings.NATIVE_RENDERING_FAILED.get()) {
|
||||
osmandSettings.SAFE_MODE.set(true);
|
||||
|
@ -574,17 +578,23 @@ public class OsmandApplication extends Application {
|
|||
} finally {
|
||||
synchronized (OsmandApplication.this) {
|
||||
final ProgressDialog toDismiss;
|
||||
final Runnable pb;
|
||||
if (startDialog != null) {
|
||||
toDismiss = startDialog.getDialog();
|
||||
pb = startDialog.getFinishRunnable();
|
||||
} else {
|
||||
toDismiss = null;
|
||||
pb = null;
|
||||
}
|
||||
startDialog = null;
|
||||
|
||||
if (toDismiss != null) {
|
||||
if (toDismiss != null || pb != null) {
|
||||
uiHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if(pb != null) {
|
||||
|
||||
}
|
||||
if (toDismiss != null) {
|
||||
// TODO handling this dialog is bad, we need a better standard way
|
||||
toDismiss.dismiss();
|
||||
|
@ -592,38 +602,28 @@ public class OsmandApplication extends Application {
|
|||
}
|
||||
}
|
||||
});
|
||||
showWarnings(warnings, toDismiss.getContext());
|
||||
} else {
|
||||
startingWarnings = warnings;
|
||||
}
|
||||
if (warnings != null && !warnings.isEmpty()) {
|
||||
showToastMessage(formatWarnings(warnings).toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void showWarnings(List<String> warnings, final Context uiContext) {
|
||||
if (warnings != null && !warnings.isEmpty()) {
|
||||
final StringBuilder b = new StringBuilder();
|
||||
boolean f = true;
|
||||
for (String w : warnings) {
|
||||
if (f) {
|
||||
f = false;
|
||||
} else {
|
||||
b.append('\n');
|
||||
}
|
||||
b.append(w);
|
||||
private StringBuilder formatWarnings(List<String> warnings) {
|
||||
final StringBuilder b = new StringBuilder();
|
||||
boolean f = true;
|
||||
for (String w : warnings) {
|
||||
if (f) {
|
||||
f = false;
|
||||
} else {
|
||||
b.append('\n');
|
||||
}
|
||||
showWarning(uiContext, b.toString());
|
||||
b.append(w);
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
private void showWarning(final Context uiContext, final String b) {
|
||||
uiHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
AccessibleToast.makeText(uiContext, b, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private class DefaultExceptionHandler implements UncaughtExceptionHandler {
|
||||
|
||||
|
|
|
@ -7,8 +7,10 @@ import android.content.DialogInterface;
|
|||
import android.content.DialogInterface.OnCancelListener;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class ProgressDialogImplementation implements IProgress {
|
||||
public class ProgressImplementation implements IProgress {
|
||||
|
||||
private static final int HANDLER_START_TASK = OsmAndConstants.UI_HANDLER_PROGRESS + 1;
|
||||
private static final int HADLER_UPDATE_PROGRESS = OsmAndConstants.UI_HANDLER_PROGRESS + 2;
|
||||
|
@ -22,54 +24,70 @@ public class ProgressDialogImplementation implements IProgress {
|
|||
private Thread run;
|
||||
private Context context;
|
||||
private ProgressDialog dialog = null;
|
||||
private ProgressBar progressBar = null;
|
||||
private Runnable finishRunnable = null;
|
||||
private final boolean cancelable;
|
||||
private TextView tv;
|
||||
|
||||
|
||||
public ProgressDialogImplementation(Context ctx, ProgressDialog dlg, boolean cancelable){
|
||||
public ProgressImplementation(Context ctx, ProgressDialog dlg, boolean cancelable) {
|
||||
this.cancelable = cancelable;
|
||||
context = ctx;
|
||||
setDialog(dlg);
|
||||
|
||||
mViewUpdateHandler = new Handler(){
|
||||
|
||||
mViewUpdateHandler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
super.handleMessage(msg);
|
||||
if(dialog != null){
|
||||
switch (msg.what) {
|
||||
case HANDLER_START_TASK:
|
||||
dialog.setMessage(message);
|
||||
if (isIndeterminate()) {
|
||||
dialog.setMax(1);
|
||||
dialog.setIndeterminate(true);
|
||||
} else {
|
||||
dialog.setIndeterminate(false);
|
||||
dialog.setMax(work);
|
||||
}
|
||||
dialog.show();
|
||||
break;
|
||||
case HADLER_UPDATE_PROGRESS:
|
||||
dialog.setProgress(msg.arg1);
|
||||
break;
|
||||
|
||||
switch (msg.what) {
|
||||
case HANDLER_START_TASK:
|
||||
if (dialog != null) {
|
||||
dialog.setMessage(message);
|
||||
if (isIndeterminate()) {
|
||||
dialog.setMax(1);
|
||||
dialog.setIndeterminate(true);
|
||||
} else {
|
||||
dialog.setIndeterminate(false);
|
||||
dialog.setMax(work);
|
||||
}
|
||||
dialog.show();
|
||||
}
|
||||
if (tv != null) {
|
||||
tv.setText(message);
|
||||
}
|
||||
if (progressBar != null) {
|
||||
if (isIndeterminate()) {
|
||||
progressBar.setMax(1);
|
||||
progressBar.setIndeterminate(true);
|
||||
} else {
|
||||
progressBar.setIndeterminate(false);
|
||||
progressBar.setMax(work);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case HADLER_UPDATE_PROGRESS:
|
||||
if (dialog != null) {
|
||||
dialog.setProgress(msg.arg1);
|
||||
} else if (progressBar != null) {
|
||||
progressBar.setProgress(msg.arg1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
public ProgressDialogImplementation(ProgressDialog dlg, boolean cancelable){
|
||||
public ProgressImplementation(ProgressDialog dlg, boolean cancelable){
|
||||
this(dlg.getContext(), dlg, cancelable);
|
||||
}
|
||||
|
||||
public ProgressDialogImplementation(final ProgressDialog dlg){
|
||||
this(dlg, false);
|
||||
}
|
||||
|
||||
|
||||
public static ProgressDialogImplementation createProgressDialog(Context ctx, String title, String message, int style) {
|
||||
public static ProgressImplementation createProgressDialog(Context ctx, String title, String message, int style) {
|
||||
return createProgressDialog(ctx, title, message, style, null);
|
||||
}
|
||||
|
||||
public static ProgressDialogImplementation createProgressDialog(Context ctx, String title, String message, int style, final DialogInterface.OnCancelListener listener) {
|
||||
public static ProgressImplementation createProgressDialog(Context ctx, String title, String message, int style, final DialogInterface.OnCancelListener listener) {
|
||||
ProgressDialog dlg = new ProgressDialog(ctx) {
|
||||
@Override
|
||||
public void cancel() {
|
||||
|
@ -98,7 +116,13 @@ public class ProgressDialogImplementation implements IProgress {
|
|||
// failure, must be older device
|
||||
}
|
||||
dlg.setProgressStyle(style);
|
||||
return new ProgressDialogImplementation(dlg, true);
|
||||
return new ProgressImplementation(dlg, true);
|
||||
}
|
||||
|
||||
public void setProgressBar(TextView tv, ProgressBar progressBar, Runnable finish) {
|
||||
this.tv = tv;
|
||||
this.progressBar = progressBar;
|
||||
this.finishRunnable = finish;
|
||||
}
|
||||
|
||||
public void setDialog(ProgressDialog dlg){
|
||||
|
@ -188,7 +212,11 @@ public class ProgressDialogImplementation implements IProgress {
|
|||
public ProgressDialog getDialog() {
|
||||
return dialog;
|
||||
}
|
||||
|
||||
|
||||
public Runnable getFinishRunnable() {
|
||||
return finishRunnable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startWork(int work) {
|
||||
this.work = work;
|
|
@ -18,7 +18,7 @@ import net.osmand.plus.OsmandApplication;
|
|||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.OsmandSettings.DrivingRegion;
|
||||
import net.osmand.plus.OsmandSettings.MetricsConstants;
|
||||
import net.osmand.plus.ProgressDialogImplementation;
|
||||
import net.osmand.plus.ProgressImplementation;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.Version;
|
||||
import net.osmand.plus.base.SuggestExternalDirectoryDialog;
|
||||
|
@ -345,7 +345,7 @@ public class SettingsGeneralActivity extends SettingsBaseActivity {
|
|||
private File to;
|
||||
private Context ctx;
|
||||
private File from;
|
||||
protected ProgressDialogImplementation progress;
|
||||
protected ProgressImplementation progress;
|
||||
private Runnable runOnSuccess;
|
||||
|
||||
public MoveFilesToDifferentDirectory(Context ctx, File from, File to) {
|
||||
|
@ -360,7 +360,7 @@ public class SettingsGeneralActivity extends SettingsBaseActivity {
|
|||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
progress = ProgressDialogImplementation.createProgressDialog(
|
||||
progress = ProgressImplementation.createProgressDialog(
|
||||
ctx, ctx.getString(R.string.copying_osmand_files),
|
||||
ctx.getString(R.string.copying_osmand_files_descr, to.getPath()),
|
||||
ProgressDialog.STYLE_HORIZONTAL);
|
||||
|
|
|
@ -13,7 +13,7 @@ import net.osmand.osm.edit.EntityInfo;
|
|||
import net.osmand.osm.edit.Node;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.ProgressDialogImplementation;
|
||||
import net.osmand.plus.ProgressImplementation;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.activities.OsmandListActivity;
|
||||
|
@ -200,7 +200,7 @@ public class LocalOpenstreetmapActivity extends OsmandListActivity {
|
|||
protected Dialog onCreateDialog(int id) {
|
||||
switch (id) {
|
||||
case DIALOG_PROGRESS_UPLOAD:
|
||||
return ProgressDialogImplementation.createProgressDialog(
|
||||
return ProgressImplementation.createProgressDialog(
|
||||
LocalOpenstreetmapActivity.this,
|
||||
getString(R.string.uploading),
|
||||
getString(R.string.local_openstreetmap_uploading),
|
||||
|
|
|
@ -1,153 +0,0 @@
|
|||
package net.osmand.plus.sherpafy;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.osmand.IProgress;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.DownloadIndexActivity;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
|
||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class SherpafySelectTourActivity extends SherlockFragmentActivity {
|
||||
|
||||
private SherpafyCustomization customization;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
if (!(getMyApplication().getAppCustomization() instanceof SherpafyCustomization)) {
|
||||
getMyApplication().setAppCustomization(new SherpafyCustomization());
|
||||
}
|
||||
customization = (SherpafyCustomization) getMyApplication().getAppCustomization();
|
||||
setTheme(R.style.OsmandLightTheme);
|
||||
((OsmandApplication) getApplication()).setLanguage(this);
|
||||
super.onCreate(savedInstanceState);
|
||||
getSherlock().setUiOptions(ActivityInfo.UIOPTION_SPLIT_ACTION_BAR_WHEN_NARROW);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
|
||||
getSupportActionBar().setTitle(R.string.sherpafy_app_name);
|
||||
super.setContentView(R.layout.sherpafy_start);
|
||||
|
||||
ProgressDialog startProgressDialog = new ProgressDialog(this);
|
||||
getMyApplication().checkApplicationIsBeingInitialized(this, startProgressDialog);
|
||||
|
||||
setContentView();
|
||||
|
||||
// FIXME is this needed?
|
||||
// if (customization.getTourInformations().isEmpty()) {
|
||||
// customization.onIndexingFiles(IProgress.EMPTY_PROGRESS, new ConcurrentHashMap<String, String>());
|
||||
// }
|
||||
}
|
||||
|
||||
private OsmandApplication getMyApplication() {
|
||||
return (OsmandApplication) getApplication();
|
||||
}
|
||||
|
||||
private void setContentView() {
|
||||
final Button selectTour = (Button) findViewById(R.id.select_tour);
|
||||
selectTour.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// creating alert dialog with multiple tours to select
|
||||
AlertDialog.Builder adb = new AlertDialog.Builder(getActivity());
|
||||
final List<TourInformation> tours = customization.getTourInformations();
|
||||
if (customization.getSelectedTour() != null) {
|
||||
String[] tourNames = new String[tours.size()];
|
||||
// creating list of tour names to select
|
||||
for (int i = 0; i < tours.size(); i++) {
|
||||
tourNames[i] = tours.get(i).getName();
|
||||
}
|
||||
int i;
|
||||
for (i = 0; i < tours.size(); i++) {
|
||||
if (customization.getSelectedTour().equals(tours.get(i))) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
adb.setSingleChoiceItems(tourNames, i, new DialogInterface.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
selectTour(tours.get(i));
|
||||
dialogInterface.dismiss();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
String[] tourNames = new String[tours.size() + 1];
|
||||
tourNames[0] = getString(R.string.none);
|
||||
for (int i = 1; i < tours.size() + 1; i++) {
|
||||
tourNames[i] = tours.get(i - 1).getName();
|
||||
}
|
||||
adb.setSingleChoiceItems(tourNames, 0, new DialogInterface.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
if (i == 0) {
|
||||
return;
|
||||
}
|
||||
selectTour(tours.get(i - 1));
|
||||
dialogInterface.dismiss();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
adb.setTitle(R.string.select_tour);
|
||||
adb.setNegativeButton(R.string.default_buttons_cancel, null);
|
||||
adb.show();
|
||||
}
|
||||
});
|
||||
|
||||
Button downloadTour = (Button) findViewById(R.id.download_tour);
|
||||
downloadTour.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
final Intent download = new Intent(v.getContext(), DownloadIndexActivity.class);
|
||||
download.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
|
||||
v.getContext().startActivity(download);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private Activity getActivity() {
|
||||
return this;
|
||||
}
|
||||
|
||||
private void selectTour(final TourInformation tour){
|
||||
new AsyncTask<TourInformation, Void, Void>(){
|
||||
private ProgressDialog dlg;
|
||||
|
||||
protected void onPreExecute() {
|
||||
dlg = new ProgressDialog(getActivity());
|
||||
dlg.setTitle(R.string.selecting_tour_progress);
|
||||
dlg.setMessage(getString(R.string.indexing_tour, tour == null ? "" : tour.getName()));
|
||||
dlg.show();
|
||||
};
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(TourInformation... params) {
|
||||
customization.selectTour(params[0], IProgress.EMPTY_PROGRESS);
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void onPostExecute(Void result) {
|
||||
dlg.dismiss();
|
||||
|
||||
Intent intent = new Intent(getApplicationContext(), TourViewActivity.class);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
};
|
||||
}.execute(tour);
|
||||
}
|
||||
}
|
|
@ -77,6 +77,8 @@ public class TourInformation {
|
|||
stage = null;
|
||||
} else if(stage != null && tag.equals("description")) {
|
||||
stage.description = text;
|
||||
} else if(stage != null && tag.equals("fullDescription")) {
|
||||
stage.fullDescription = text;
|
||||
} else if(stage != null && tag.equals("gpx")) {
|
||||
if(text.startsWith(FILE_PREFIX)) {
|
||||
stage.gpxFile = new File(folder, text.substring(FILE_PREFIX.length()));
|
||||
|
@ -139,6 +141,7 @@ public class TourInformation {
|
|||
File gpxFile;
|
||||
String name = "";
|
||||
String description = "";
|
||||
String fullDescription = "";
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -148,6 +151,10 @@ public class TourInformation {
|
|||
return description;
|
||||
}
|
||||
|
||||
public String getFullDescription() {
|
||||
return fullDescription;
|
||||
}
|
||||
|
||||
public File getGpxFile() {
|
||||
return gpxFile;
|
||||
}
|
||||
|
|
|
@ -5,30 +5,43 @@ import java.util.List;
|
|||
import net.osmand.IProgress;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.DownloadIndexActivity;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.text.SpannableString;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.text.style.ClickableSpan;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.RadioGroup;
|
||||
import android.widget.TextView;
|
||||
import android.widget.ToggleButton;
|
||||
|
||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||
import com.actionbarsherlock.view.Menu;
|
||||
import com.actionbarsherlock.view.MenuItem;
|
||||
import com.actionbarsherlock.view.MenuItem.OnMenuItemClickListener;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class TourViewActivity extends SherlockFragmentActivity {
|
||||
|
||||
private static final int GO_TO_MAP = 1;
|
||||
private static final int SETTINGS_ID = 2;
|
||||
private static final int STATE_TOUR_VIEW = 1;
|
||||
private static final int STATE_LOADING = 0;
|
||||
private static final int STATE_SELECT_TOUR = -1;
|
||||
int state = 0;
|
||||
private SherpafyCustomization customization;
|
||||
ImageView img;
|
||||
TextView description;
|
||||
|
@ -36,6 +49,7 @@ public class TourViewActivity extends SherlockFragmentActivity {
|
|||
List<TourInformation.StageInformation> stagesInfo;
|
||||
TourInformation curTour;
|
||||
RadioGroup stages;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -46,13 +60,27 @@ public class TourViewActivity extends SherlockFragmentActivity {
|
|||
setTheme(R.style.OsmandLightTheme);
|
||||
((OsmandApplication) getApplication()).setLanguage(this);
|
||||
super.onCreate(savedInstanceState);
|
||||
getSherlock().setUiOptions(ActivityInfo.UIOPTION_SPLIT_ACTION_BAR_WHEN_NARROW);
|
||||
if(getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT ||
|
||||
getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT) {
|
||||
getSherlock().setUiOptions(ActivityInfo.UIOPTION_SPLIT_ACTION_BAR_WHEN_NARROW);
|
||||
}
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
|
||||
getSupportActionBar().setTitle(R.string.sherpafy_app_name);
|
||||
|
||||
ProgressDialog startProgressDialog = new ProgressDialog(this);
|
||||
getMyApplication().checkApplicationIsBeingInitialized(this, startProgressDialog);
|
||||
|
||||
setContentView(R.layout.sherpafy_loading);
|
||||
state = STATE_LOADING;
|
||||
getMyApplication().checkApplicationIsBeingInitialized(this, (TextView) findViewById(R.id.ProgressMessage),
|
||||
(ProgressBar) findViewById(R.id.ProgressBar), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
setMainContent();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void setTourInfoContent() {
|
||||
setContentView(R.layout.sherpafy_tour_info);
|
||||
|
||||
ToggleButton collapser = (ToggleButton) findViewById(R.id.collapse);
|
||||
|
@ -64,12 +92,13 @@ public class TourViewActivity extends SherlockFragmentActivity {
|
|||
customization.selectStage(null, IProgress.EMPTY_PROGRESS);
|
||||
fullDescription.setText(curTour.getFulldescription());
|
||||
description.setText((curTour.getShortDescription()));
|
||||
((TextView)findViewById(R.id.tour_name)).setText(getString(R.string.overview));
|
||||
prepareBitmap();
|
||||
} else {
|
||||
//-1 because there's one more item Overview, which is not exactly a stage.
|
||||
customization.selectStage(stagesInfo.get(i - 1), IProgress.EMPTY_PROGRESS);
|
||||
description.setText(stagesInfo.get(i - 1).getDescription());
|
||||
fullDescription.setText("");
|
||||
fullDescription.setText(stagesInfo.get(i - 1).getFullDescription());
|
||||
((TextView)findViewById(R.id.tour_name)).setText(stagesInfo.get(i - 1).getName());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -83,36 +112,56 @@ public class TourViewActivity extends SherlockFragmentActivity {
|
|||
} else {
|
||||
stages.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
TextView settings = (TextView) findViewById(R.id.btn_settings);
|
||||
SpannableString content = new SpannableString(settings.getText());
|
||||
content.setSpan(new ClickableSpan() {
|
||||
|
||||
@Override
|
||||
public void onClick(View widget) {
|
||||
Intent intent = new Intent(getApplicationContext(), SherpafySelectTourActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
}, 0, content.length(), 0);
|
||||
settings.setText(content);
|
||||
settings.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
private void startSettings() {
|
||||
if(state != STATE_SELECT_TOUR) {
|
||||
setTourSelectionContentView();
|
||||
state = STATE_SELECT_TOUR;
|
||||
}
|
||||
}
|
||||
|
||||
private void setMainContent() {
|
||||
if(customization.getSelectedTour() != null) {
|
||||
if(state != STATE_TOUR_VIEW) {
|
||||
setTourInfoContent();
|
||||
state = STATE_TOUR_VIEW;
|
||||
}
|
||||
getSupportActionBar().setTitle(customization.getSelectedTour().getName());
|
||||
updateTourView();
|
||||
} else {
|
||||
// Intent intent = new Intent(getApplicationContext(), SherpafySelectTourActivity.class);
|
||||
// startActivity(intent);
|
||||
//
|
||||
startSettings();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) {
|
||||
createMenuItem(menu, GO_TO_MAP, R.string.start_tour,
|
||||
0, 0,/*R.drawable.ic_action_marker_light,*/
|
||||
MenuItem.SHOW_AS_ACTION_ALWAYS| MenuItem.SHOW_AS_ACTION_WITH_TEXT);
|
||||
createMenuItem(menu, SETTINGS_ID, R.string.osmo_share_session,
|
||||
R.drawable.ic_action_settings_light, R.drawable.ic_action_settings_dark,
|
||||
MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
public MenuItem createMenuItem(Menu m, int id, int titleRes, int iconLight, int iconDark, int menuItemType) {
|
||||
// int r = getMyApplication().getSettings().isLightActionBar() ? iconLight : iconDark;
|
||||
int r = iconLight;
|
||||
MenuItem menuItem = m.add(0, id, 0, titleRes);
|
||||
if (r != 0) {
|
||||
menuItem.setIcon(r);
|
||||
}
|
||||
menuItem.setShowAsActionFlags(menuItemType).setOnMenuItemClickListener(new OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(com.actionbarsherlock.view.MenuItem item) {
|
||||
return onOptionsItemSelected(item);
|
||||
}
|
||||
});
|
||||
return menuItem;
|
||||
}
|
||||
|
||||
|
||||
private void updateTourView() {
|
||||
|
@ -126,39 +175,33 @@ public class TourViewActivity extends SherlockFragmentActivity {
|
|||
fullDescription.setVisibility(View.VISIBLE);
|
||||
Button start_tour = (Button) findViewById(R.id.start_tour);
|
||||
|
||||
//in case of reloading view - remove all previous radio buttons
|
||||
// in case of reloading view - remove all previous radio buttons
|
||||
stages.removeAllViews();
|
||||
|
||||
start_tour.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
MapActivity.launchMapActivityMoveToTop(GetActivity());
|
||||
goToMap();
|
||||
}
|
||||
});
|
||||
|
||||
//get count of radio buttons
|
||||
// get count of radio buttons
|
||||
final int count = stagesInfo.size() + 1;
|
||||
final RadioButton[] rb = new RadioButton[count];
|
||||
|
||||
rb[0] = new RadioButton(this);
|
||||
rb[0].setId(0);
|
||||
stages.addView(rb[0]);
|
||||
rb[0].setText("Overview");
|
||||
rb[0].setTextColor(getResources().getColor(R.color.color_black));
|
||||
//add radio buttons to view
|
||||
rb[0].setText(getString(R.string.overview));
|
||||
// add radio buttons to view
|
||||
for (int i = 1; i < count; i++) {
|
||||
rb[i] = new RadioButton(this);
|
||||
rb[i].setId(i);
|
||||
stages.addView(rb[i]);
|
||||
rb[i].setText(stagesInfo.get(i - 1).getName());
|
||||
rb[i].setTextColor(getResources().getColor(R.color.color_black));
|
||||
}
|
||||
|
||||
TourInformation.StageInformation curStage = customization.getSelectedStage();
|
||||
|
||||
//if there's no current stage - overview should be selected
|
||||
if (curStage == null) {
|
||||
//DIRTY HACK, I dunno why, but after activity onResume it's not possible to just check item 0
|
||||
stages.check(0);
|
||||
description.setText(curTour.getShortDescription());
|
||||
fullDescription.setText(curTour.getFulldescription());
|
||||
|
@ -176,6 +219,11 @@ public class TourViewActivity extends SherlockFragmentActivity {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void goToMap() {
|
||||
MapActivity.launchMapActivityMoveToTop(getActivity());
|
||||
// TODO select GPX
|
||||
}
|
||||
|
||||
private void prepareBitmap() {
|
||||
final Bitmap imageBitmap = curTour.getImageBitmap();
|
||||
|
@ -194,7 +242,117 @@ public class TourViewActivity extends SherlockFragmentActivity {
|
|||
return (OsmandApplication) getApplication();
|
||||
}
|
||||
|
||||
private TourViewActivity GetActivity() {
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) {
|
||||
if (item.getItemId() == GO_TO_MAP) {
|
||||
goToMap();
|
||||
return true;
|
||||
} else if (item.getItemId() == SETTINGS_ID) {
|
||||
startSettings();
|
||||
return true;
|
||||
} else {
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void setTourSelectionContentView() {
|
||||
setContentView(R.layout.sherpafy_start);
|
||||
final Button selectTour = (Button) findViewById(R.id.select_tour);
|
||||
final Button downloadTour = (Button) findViewById(R.id.download_tour);
|
||||
int width = Math.max(downloadTour.getWidth(), selectTour.getWidth());
|
||||
downloadTour.setWidth(width);
|
||||
selectTour.setWidth(width);
|
||||
selectTour.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// creating alert dialog with multiple tours to select
|
||||
AlertDialog.Builder adb = new AlertDialog.Builder(getActivity());
|
||||
final List<TourInformation> tours = customization.getTourInformations();
|
||||
if (customization.getSelectedTour() != null) {
|
||||
String[] tourNames = new String[tours.size()];
|
||||
// creating list of tour names to select
|
||||
for (int i = 0; i < tours.size(); i++) {
|
||||
tourNames[i] = tours.get(i).getName();
|
||||
}
|
||||
int i;
|
||||
for (i = 0; i < tours.size(); i++) {
|
||||
if (customization.getSelectedTour().equals(tours.get(i))) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
adb.setSingleChoiceItems(tourNames, i, new DialogInterface.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
selectTour(tours.get(i));
|
||||
dialogInterface.dismiss();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
String[] tourNames = new String[tours.size() + 1];
|
||||
tourNames[0] = getString(R.string.none);
|
||||
for (int i = 1; i < tours.size() + 1; i++) {
|
||||
tourNames[i] = tours.get(i - 1).getName();
|
||||
}
|
||||
adb.setSingleChoiceItems(tourNames, 0, new DialogInterface.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
if (i == 0) {
|
||||
return;
|
||||
}
|
||||
selectTour(tours.get(i - 1));
|
||||
dialogInterface.dismiss();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
adb.setTitle(R.string.select_tour);
|
||||
adb.setNegativeButton(R.string.default_buttons_cancel, null);
|
||||
adb.show();
|
||||
}
|
||||
});
|
||||
|
||||
downloadTour.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
final Intent download = new Intent(v.getContext(), DownloadIndexActivity.class);
|
||||
download.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
|
||||
v.getContext().startActivity(download);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private Activity getActivity() {
|
||||
return this;
|
||||
}
|
||||
|
||||
private void selectTour(final TourInformation tour){
|
||||
new AsyncTask<TourInformation, Void, Void>(){
|
||||
private ProgressDialog dlg;
|
||||
|
||||
protected void onPreExecute() {
|
||||
dlg = new ProgressDialog(getActivity());
|
||||
dlg.setTitle(R.string.selecting_tour_progress);
|
||||
dlg.setMessage(getString(R.string.indexing_tour, tour == null ? "" : tour.getName()));
|
||||
dlg.show();
|
||||
};
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(TourInformation... params) {
|
||||
customization.selectTour(params[0], IProgress.EMPTY_PROGRESS);
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void onPostExecute(Void result) {
|
||||
dlg.dismiss();
|
||||
setTourInfoContent();
|
||||
};
|
||||
}.execute(tour);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue