Merge pull request #680 from Bars107/master

Updated sherpafy functionality. UI and functionality improvements.
This commit is contained in:
vshcherb 2014-06-03 20:59:20 +02:00
commit ad973d1952
6 changed files with 263 additions and 143 deletions

View file

@ -148,7 +148,7 @@
<activity android:name="net.osmand.plus.activities.search.SearchStreet2ByNameActivity"></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.activities.search.SearchBuildingByNameActivity"></activity>
<activity android:name="net.osmand.plus.sherpafy.TourCommonActivity"></activity> <activity android:name="net.osmand.plus.sherpafy.TourCommonActivity"></activity>
<activity android:name="net.osmand.plus.sherpafy.SherpafyStartActivity" android:exported="true"></activity> <activity android:name="net.osmand.plus.sherpafy.SherpafyStartActivity" android:exported="true" android:launchMode= "singleInstance"></activity>
<activity android:name="net.osmand.plus.sherpafy.TourViewActivity"></activity> <activity android:name="net.osmand.plus.sherpafy.TourViewActivity"></activity>
<activity android:name="net.osmand.plus.activities.EditPOIFilterActivity"></activity> <activity android:name="net.osmand.plus.activities.EditPOIFilterActivity"></activity>
<activity android:name="net.osmand.plus.activities.search.GeoIntentActivity"> <activity android:name="net.osmand.plus.activities.search.GeoIntentActivity">

View file

@ -3,75 +3,109 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent"
android:background="@color/color_white">
<RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content">
<Button android:id="@+id/start_tour" <Button android:id="@+id/start_tour"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@color/color_black"
android:text="Start tour"/> android:text="Start tour"/>
<Button android:id="@+id/itenerary" <Button android:id="@+id/itenerary"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@color/color_black"
android:layout_alignParentRight="true" android:layout_alignParentRight="true"
android:text="Itenerary"/> android:text="Itenerary"/>
</RelativeLayout> </RelativeLayout>
<RelativeLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
>
<Button android:id="@+id/collapse"
android:layout_width="30dp"
android:text="-"
android:background="@color/color_black"
android:layout_height="30dp"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:textSize="20dp"
android:layout_toRightOf="@+id/collapse"
android:textColor="@color/color_black"
android:text="Stages"/>
</RelativeLayout>
<RadioGroup <RadioGroup
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal" android:orientation="vertical"
android:id="@+id/stages"> android:id="@+id/stages">
</RadioGroup> </RadioGroup>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" > android:layout_height="fill_parent" >
<RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content">
<LinearLayout <LinearLayout android:id="@+id/info_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/tour_name"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center_horizontal" android:orientation="vertical" >
android:textSize="25sp" >
</TextView>
<TextView <TextView
android:id="@+id/tour_description" android:textColor="@color/color_black"
android:layout_width="wrap_content" android:id="@+id/tour_description"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:layout_marginBottom="2dp" android:layout_height="wrap_content"
android:layout_marginTop="2dp" android:layout_marginBottom="2dp"
android:textSize="18sp" > android:layout_marginTop="2dp"
</TextView> android:textSize="18sp" >
</TextView>
<ImageView <ImageView
android:id="@+id/tour_image" android:id="@+id/tour_image"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingLeft="8dp" android:paddingLeft="8dp"
android:paddingRight="8dp" android:paddingRight="8dp"
android:paddingTop="4dp" /> android:paddingTop="4dp" />
<TextView <TextView
android:id="@+id/tour_fulldescription" android:textColor="@color/color_black"
android:layout_width="wrap_content" android:id="@+id/tour_fulldescription"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:layout_marginBottom="2dp" android:layout_height="wrap_content"
android:layout_marginTop="2dp" android:layout_marginBottom="2dp"
android:textSize="18sp" > android:layout_marginTop="2dp"
</TextView> android:textSize="18sp" >
</TextView>
</LinearLayout>
<Button android:id="@+id/btn_settings" <Button android:id="@+id/btn_settings"
android:text="Settings" android:text="Settings"
android:layout_below="@+id/info_layout"
android:layout_alignParentRight="true"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:background="@color/color_black"
android:layout_height="wrap_content"/> android:layout_height="wrap_content"/>
</LinearLayout>
</RelativeLayout>
</ScrollView> </ScrollView>

View file

@ -3,18 +3,28 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent"
<Button android:id="@+id/select_tour" android:background="@color/color_white">
android:layout_centerHorizontal="true" <LinearLayout android:layout_width="wrap_content"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="Select tour" android:layout_centerHorizontal="true"
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:layout_height="wrap_content"/> android:orientation="horizontal">
<Button android:id="@+id/download_tour" <Button android:id="@+id/select_tour"
android:layout_below="@+id/select_tour" android:background="@color/color_black"
android:layout_centerHorizontal="true" android:layout_marginRight="5dp"
android:layout_width="wrap_content" android:minWidth="40dp"
android:text="Download tour" android:layout_width="wrap_content"
android:layout_height="wrap_content"/> android:text="Select tour"
android:layout_height="wrap_content"/>
<Button android:id="@+id/download_tour"
android:layout_marginLeft="5dp"
android:background="@color/color_black"
android:minWidth="40dp"
android:text="Download tour"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</RelativeLayout> </RelativeLayout>

View file

@ -1,10 +1,12 @@
package net.osmand.plus.sherpafy; package net.osmand.plus.sherpafy;
import android.app.AlertDialog;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.os.StrictMode; import android.os.StrictMode;
import android.view.View; import android.view.View;
@ -14,10 +16,14 @@ import android.widget.TextView;
import com.actionbarsherlock.app.SherlockFragmentActivity; import com.actionbarsherlock.app.SherlockFragmentActivity;
import net.osmand.IProgress; import net.osmand.IProgress;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.ProgressDialogImplementation;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.DownloadIndexActivity; import net.osmand.plus.activities.DownloadIndexActivity;
import java.util.Collection;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.ListIterator;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
/** /**
@ -77,13 +83,54 @@ public class SherpafyStartActivity extends SherlockFragmentActivity {
private void updateDefaultView(){ private void updateDefaultView(){
Button selectTour = (Button) findViewById(R.id.select_tour); final Button selectTour = (Button) findViewById(R.id.select_tour);
selectTour.setOnClickListener(new View.OnClickListener() { selectTour.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
final Intent select = new Intent(v.getContext(), TourCommonActivity.class); //creating alert dialog with multiple tours to select
select.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); AlertDialog.Builder adb = new AlertDialog.Builder(getActivity());
v.getContext().startActivity(select); final List<TourInformation> tours = customization.getTourInformations();
if (customization.getSelectedTour() != null)
{
String[] tour_names = new String[tours.size()];
//creating list of tour names to select
for (int i =0; i < tours.size();i++){
tour_names[i] = tours.get(i).getName();
}
int cur_tour_ind;
for (cur_tour_ind =0; cur_tour_ind<tours.size();cur_tour_ind++)
{
if (customization.getSelectedTour().equals(tours.get(cur_tour_ind))){break;}
}
adb.setSingleChoiceItems(tour_names,cur_tour_ind,new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
selectTour(tours.get(i));
dialogInterface.dismiss();
}
});
} else{
String[] tour_names = new String[tours.size()+1];
tour_names[0] = "None";
for (int i =1; i < tours.size()+1;i++){
tour_names[i] = tours.get(i-1).getName();
}
adb.setSingleChoiceItems(tour_names,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("Select tour");
adb.setNegativeButton("Cancel",null);
adb.show();
} }
}); });
@ -117,4 +164,35 @@ public class SherpafyStartActivity extends SherlockFragmentActivity {
} }
} }
private SherpafyStartActivity getActivity() {return this;}
private void selectTour(TourInformation tour){
ProgressDialogImplementation dlg = ProgressDialogImplementation.createProgressDialog(getActivity(), "", getString(R.string.indexing_tour, ""),
ProgressDialog.STYLE_SPINNER);
new AsyncTask<TourInformation, Void, Void>(){
private ProgressDialog dlg;
protected void onPreExecute() {
dlg = new ProgressDialog(getActivity());
dlg.setTitle("Selecting tour...");
dlg.setMessage("Please wait.");
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);
}
} }

View file

@ -21,76 +21,67 @@ import java.util.List;
public class TourViewActivity extends SherlockFragmentActivity { public class TourViewActivity extends SherlockFragmentActivity {
private SherpafyCustomization customization; private SherpafyCustomization customization;
private ProgressDialog startProgressDialog;
ImageView img; ImageView img;
TextView description; TextView description;
TextView fullDescription; TextView fullDescription;
TextView name;
List<TourInformation.StageInformation> stages_info; List<TourInformation.StageInformation> stages_info;
TourInformation cur_tour; TourInformation cur_tour;
RadioGroup stages;
private boolean hack = false;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
((OsmandApplication) getApplication()).applyTheme(this); ((OsmandApplication) getApplication()).applyTheme(this);
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(false);
getSupportActionBar().setTitle("Sherpafy");
// if (customization.getTourInformations().isEmpty()) // if (customization.getTourInformations().isEmpty())
// { // {
// customization.onIndexingFiles( IProgress.EMPTY_PROGRESS, new ConcurrentHashMap<String, String>() ); // customization.onIndexingFiles( IProgress.EMPTY_PROGRESS, new ConcurrentHashMap<String, String>() );
// } // }
startProgressDialog = new ProgressDialog(this); ProgressDialog startProgressDialog = new ProgressDialog(this);
getMyApplication().checkApplicationIsBeingInitialized(this, startProgressDialog); getMyApplication().checkApplicationIsBeingInitialized(this, startProgressDialog);
customization = (SherpafyCustomization) getMyApplication().getAppCustomization();
setContentView(R.layout.custom_tour_info); setContentView(R.layout.custom_tour_info);
updateTourView();
}
private void updateTourView() {
img = (ImageView) findViewById(R.id.tour_image);
description = (TextView) findViewById(R.id.tour_description);
description.setVisibility(View.VISIBLE);
fullDescription = (TextView) findViewById(R.id.tour_fulldescription);
fullDescription.setVisibility(View.VISIBLE);
name = (TextView) findViewById(R.id.tour_name);
Button start_tour = (Button) findViewById(R.id.start_tour);
Button itenerary = (Button) findViewById(R.id.itenerary);
Button settings = (Button) findViewById(R.id.btn_settings);
RadioGroup stages = (RadioGroup) findViewById(R.id.stages);
start_tour.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
MapActivity.launchMapActivityMoveToTop(GetActivity());
}
});
cur_tour = customization.getSelectedTour();
stages_info = cur_tour.getStageInformation();
Button collapser = (Button) findViewById(R.id.collapse);
stages = (RadioGroup) findViewById(R.id.stages);
stages.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { stages.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(RadioGroup radioGroup, int i) { public void onCheckedChanged(RadioGroup radioGroup, int i) {
customization.selectStage(stages_info.get(i), IProgress.EMPTY_PROGRESS); if (hack) {return;}
if (i== 0){ if (i == 0) {
customization.selectStage(null, IProgress.EMPTY_PROGRESS);
fullDescription.setText(cur_tour.getFulldescription()); fullDescription.setText(cur_tour.getFulldescription());
description.setText((cur_tour.getShortDescription())); description.setText((cur_tour.getShortDescription()));
prepareBitmap(); prepareBitmap();
} else { } else {
description.setText(stages_info.get(i).getDescription()); //-1 because there's one more item Overview, which is not exactly a stage.
customization.selectStage(stages_info.get(i - 1), IProgress.EMPTY_PROGRESS);
description.setText(stages_info.get(i - 1).getDescription());
fullDescription.setText(""); fullDescription.setText("");
} }
} }
}); });
collapser.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Button btn = (Button) view;
if (btn.getText().equals("+")) {
btn.setText("-");
stages.setVisibility(View.VISIBLE);
} else {
btn.setText("+");
stages.setVisibility(View.GONE);
}
}
});
Button settings = (Button) findViewById(R.id.btn_settings);
settings.setOnClickListener(new View.OnClickListener() { settings.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -101,50 +92,86 @@ public class TourViewActivity extends SherlockFragmentActivity {
}); });
}
@Override
protected void onResume() {
super.onResume();
customization = (SherpafyCustomization) getMyApplication().getAppCustomization();
getSupportActionBar().setTitle(customization.getSelectedTour().getName());
updateTourView();
}
private void updateTourView() {
cur_tour = customization.getSelectedTour();
stages_info = cur_tour.getStageInformation();
img = (ImageView) findViewById(R.id.tour_image);
description = (TextView) findViewById(R.id.tour_description);
description.setVisibility(View.VISIBLE);
fullDescription = (TextView) findViewById(R.id.tour_fulldescription);
fullDescription.setVisibility(View.VISIBLE);
Button start_tour = (Button) findViewById(R.id.start_tour);
Button itenerary = (Button) findViewById(R.id.itenerary);
//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());
}
});
//get count of radio buttons //get count of radio buttons
final int count = stages_info.size(); final int count = stages_info.size() + 1;
final RadioButton[] rb = new RadioButton[count]; 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 //add radio buttons to view
for (int i =0; i< count; i++){ for (int i = 1; i < count; i++) {
rb[i] = new RadioButton(this); rb[i] = new RadioButton(this);
rb[i].setId(i); rb[i].setId(i);
stages.addView(rb[i]); stages.addView(rb[i]);
String stage_name = stages_info.get(i).getName(); rb[i].setText(stages_info.get(i - 1).getName());
//if string lenght is longer than 10 - app looks like shit, need to trim and find a workaround rb[i].setTextColor(getResources().getColor(R.color.color_black));
if (stage_name.length() > 10){
rb[i].setText(stage_name.substring(0, 10));
} else {
rb[i].setText(stage_name);
}
} }
TourInformation.StageInformation cur_stage = customization.getSelectedStage(); TourInformation.StageInformation cur_stage = customization.getSelectedStage();
name.setText(cur_tour.getName());
//if there's no current stage - overview should be selected //if there's no current stage - overview should be selected
if (cur_stage == null){ if (cur_stage == null) {
//DIRTY HACK, I dunno why, but after activity onResume it's not possible to just check item 0
hack = true;
stages.check(1);
stages.check(0); stages.check(0);
hack = false;
description.setText(cur_tour.getShortDescription()); description.setText(cur_tour.getShortDescription());
fullDescription.setText(cur_tour.getFulldescription()); fullDescription.setText(cur_tour.getFulldescription());
prepareBitmap(); prepareBitmap();
} else{ } else {
int i = 0; int i;
for (i=0; i<count;i++){ for (i = 1; i < count; i++) {
if (cur_stage.equals(stages_info.get(i))) if (cur_stage.equals(stages_info.get(i - 1)))
break; break;
} }
if (i != count){ if (i != count) {
stages.check(i); stages.check(i);
} else{ } else {
stages.check(0); stages.check(0);
} }
} }
} }
private void prepareBitmap(){ private void prepareBitmap() {
final Bitmap imageBitmap = cur_tour.getImageBitmap(); final Bitmap imageBitmap = cur_tour.getImageBitmap();
if (imageBitmap != null) { if (imageBitmap != null) {
img.setImageBitmap(imageBitmap); img.setImageBitmap(imageBitmap);
@ -161,5 +188,7 @@ public class TourViewActivity extends SherlockFragmentActivity {
return (OsmandApplication) getApplication(); return (OsmandApplication) getApplication();
} }
private TourViewActivity GetActivity(){ return this;} private TourViewActivity GetActivity() {
return this;
}
} }

View file

@ -1,31 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="EclipseModuleManager" forced_jdk="true">
<conelement value="com.android.ide.eclipse.adt.DEPENDENCIES" />
<src_description expected_position="1">
<src_folder value="file://$MODULE_DIR$/src" expected_position="0" />
<src_folder value="file://$MODULE_DIR$/gen" expected_position="1" />
<src_folder value="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK" expected_position="2" />
<src_folder value="com.android.ide.eclipse.adt.LIBRARIES" expected_position="3" />
</src_description>
</component>
<component name="FacetManager">
<facet type="android" name="Android">
<configuration>
<option name="LIBRARY_PROJECT" value="true" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/bin/classes" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/gen" isTestSource="false" generated="true" />
</content>
<orderEntry type="jdk" jdkName="Android API 19 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="libs" level="project" />
</component>
</module>