Update sherpafy activities

This commit is contained in:
Victor Shcherb 2014-06-04 11:11:01 +02:00
parent 5484549ea2
commit d70877787e
8 changed files with 163 additions and 10 deletions

View file

@ -3,13 +3,23 @@
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="@+id/select_tour"
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:singleLine="true"
android:text="@string/select_tour" />
android:layout_gravity="center" >
<Button
android:id="@+id/select_tour"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="@string/select_tour" />
<ImageButton
android:id="@+id/access_code"
android:src="@drawable/ic_action_settings_dark"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</FrameLayout>

View file

@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<resources>
<string name="access_code_is_not_valid">Access code is not valid</string>
<string name="enter_access_code">Enter access code</string>
<string name="overview">Overview</string>
<string name="selecting_tour_progress">Selecting tour...</string>
<string name="no_stages_provided">No stages provided</string>

View file

@ -140,6 +140,15 @@ public class ContextMenuAdapter {
public String[] getItemNames() {
return itemNames.toArray(new String[itemNames.size()]);
}
public void removeItem(int pos) {
items.removeAt(pos);
itemNames.remove(pos);
selectedList.removeAt(pos);
iconList.removeAt(pos);
iconListLight.removeAt(pos);
listeners.remove(pos);
}
@ -173,4 +182,6 @@ public class ContextMenuAdapter {
return listadapter;
}
}

View file

@ -15,6 +15,7 @@ import net.osmand.plus.activities.SettingsActivity;
import net.osmand.plus.activities.search.SearchActivity;
import net.osmand.plus.api.SettingsAPI;
import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.views.OsmandMapTileView;
import android.app.Activity;
import android.view.Window;
@ -92,4 +93,13 @@ public class OsmAndAppCustomization {
return Collections.emptyList();
}
public void prepareLayerContextMenu(MapActivity activity, ContextMenuAdapter adapter) {
}
public void prepareOptionsMenu(MapActivity mapActivity, ContextMenuAdapter optionsMenuHelper) {
}
public void prepareLocationMenu(MapActivity mapActivity, ContextMenuAdapter adapter) {
}
}

View file

@ -416,6 +416,8 @@ public class MapActivityActions implements DialogProvider {
OsmandPlugin.registerMapContextMenu(mapActivity, latitude, longitude, adapter, selectedObj);
getMyApplication().getAppCustomization().prepareLocationMenu(mapActivity, adapter);
final Builder builder = new AlertDialog.Builder(mapActivity);
ListAdapter listAdapter ;
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB){
@ -843,6 +845,7 @@ public class MapActivityActions implements DialogProvider {
// app.closeApplication(mapActivity);
}
}).reg();
getMyApplication().getAppCustomization().prepareOptionsMenu(mapActivity, optionsMenuHelper);
return optionsMenuHelper;
}

View file

@ -294,6 +294,7 @@ public class MapActivityLayers {
OsmandPlugin.registerLayerContextMenu(mapView, adapter, activity);
getApplication().getAppCustomization().prepareLayerContextMenu(activity, adapter);
final LayerMenuListener listener = new LayerMenuListener(adapter, mapView, settings);

View file

@ -3,11 +3,14 @@ package net.osmand.plus.sherpafy;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.TreeSet;
import net.osmand.IProgress;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.GPXUtilities;
import net.osmand.plus.OsmAndAppCustomization;
import net.osmand.plus.OsmandApplication;
@ -15,19 +18,19 @@ import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.CommonPreference;
import net.osmand.plus.R;
import net.osmand.plus.activities.DownloadIndexActivity;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.api.FileSettingsAPIImpl;
import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.sherpafy.TourInformation.StageInformation;
import net.osmand.plus.views.OsmandMapTileView;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.TextView;
public class SherpafyCustomization extends OsmAndAppCustomization {
private static final String SELECTED_TOUR = "selected_tour";
private static final String ACCESS_CODE = "access_code";
private static final String SELECTED_STAGE = "selected_stage";
private OsmandSettings originalSettings;
private CommonPreference<String> selectedTourPref;
@ -36,15 +39,44 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
private StageInformation selectedStage = null;
private TourInformation selectedTour = null;
private File toursFolder;
private CommonPreference<String> accessCodePref;
@Override
public void setup(OsmandApplication app) {
super.setup(app);
originalSettings = createSettings(app.getSettings().getSettingsAPI());
selectedTourPref = originalSettings.registerStringPreference(SELECTED_TOUR, null).makeGlobal();
accessCodePref = originalSettings.registerStringPreference(ACCESS_CODE, "").makeGlobal();
toursFolder = new File(originalSettings.getExternalStorageDirectory(), "osmand/tours");
}
public boolean setAccessCode(String acCode) {
acCode = acCode.toUpperCase();
if(validate(acCode)) {
accessCodePref.set(acCode);
return true;
}
return false;
}
private boolean validate(String acCode) {
if (acCode.length() < 3) {
return false;
}
int k = 0;
for (int i = 0; i < acCode.length() - 1; i++) {
k += (acCode.charAt(i) - 'A');
}
return (k % 10) == (acCode.charAt(acCode.length() - 1) - '0');
}
public boolean isSettingsAvailable(){
return accessCodePref.get().startsWith("BAB2");
}
public String getAccessCode() {
return accessCodePref.get();
}
public boolean isTourSelected() {
return selectedTourPref.get() != null;
@ -204,4 +236,41 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
selectedStagePref.set(null);
app.getResourceManager().reloadIndexes(progress);
}
@Override
public void prepareLayerContextMenu(MapActivity activity, ContextMenuAdapter adapter) {
filter(adapter, R.string.layer_poi, R.string.layer_poi_label, R.string.layer_favorites);
}
@Override
public void prepareLocationMenu(MapActivity mapActivity, ContextMenuAdapter adapter) {
filter(adapter, R.string.context_menu_item_directions_to,
R.string.context_menu_item_destination_point, R.string.context_menu_item_search,
R.string.context_menu_item_share_location, R.string.context_menu_item_add_favorite);
}
@Override
public void prepareOptionsMenu(MapActivity mapActivity, ContextMenuAdapter adapter) {
filter(adapter, R.string.exit_Button, R.string.favorites_Button, R.string.menu_layers,
R.string.cancel_navigation, R.string.cancel_route, R.string.clear_destination,
R.string.get_directions,
R.string.menu_mute_on, R.string.menu_mute_off,
R.string.where_am_i);
}
public void filter(ContextMenuAdapter a, Integer... ids) {
if(isSettingsAvailable()) {
return;
}
TreeSet<Integer> set = new TreeSet<Integer>(Arrays.asList(ids));
for(int i =0; i < a.length();) {
int itemId = a.getItemId(i);
if(set.contains(itemId)) {
i++;
} else {
a.removeItem(i);
}
}
}
}

View file

@ -1,18 +1,23 @@
package net.osmand.plus.sherpafy;
import java.text.MessageFormat;
import java.util.List;
import net.osmand.IProgress;
import net.osmand.access.AccessibleToast;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.PoiFilter;
import net.osmand.plus.R;
import net.osmand.plus.activities.DownloadIndexActivity;
import net.osmand.plus.activities.EditPOIFilterActivity;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.sherpafy.TourInformation.StageInformation;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ActivityInfo;
@ -22,12 +27,16 @@ import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;
import android.widget.LinearLayout.LayoutParams;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.Menu;
@ -304,6 +313,14 @@ public class TourViewActivity extends SherlockFragmentActivity {
private void setTourSelectionContentView() {
setContentView(R.layout.sherpafy_start);
final Button selectTour = (Button) findViewById(R.id.select_tour);
final View accessCode = (View) findViewById(R.id.access_code);
accessCode.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openAccessCode(false);
}
});
if (!customization.getTourInformations().isEmpty()) {
selectTour.setText(R.string.select_tour);
selectTour.setOnClickListener(new View.OnClickListener() {
@ -317,13 +334,43 @@ public class TourViewActivity extends SherlockFragmentActivity {
selectTour.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startDownloadActivity();
if(customization.getAccessCode().length() == 0) {
openAccessCode(true);
} else {
startDownloadActivity();
}
}
});
}
}
protected void openAccessCode(final boolean startDownload) {
Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.enter_access_code);
final EditText editText = new EditText(this);
LinearLayout ll = new LinearLayout(this);
ll.setPadding(5, 3, 5, 0);
ll.addView(editText, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
builder.setView(ll);
builder.setNegativeButton(R.string.default_buttons_cancel, null);
builder.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String acCode = editText.getText().toString();
if(!customization.setAccessCode(acCode)) {
Toast.makeText(getActivity(), R.string.access_code_is_not_valid, Toast.LENGTH_LONG).show();
return;
}
if(startDownload) {
startDownloadActivity();
}
}
});
builder.create().show();
}
private void startDownloadActivity() {
final Intent download = new Intent(this, DownloadIndexActivity.class);
download.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);