Updated functionality of sherpafy customization. Added selecting tour stages and start map.

This commit is contained in:
unknown 2014-06-02 21:58:58 +03:00
parent a6549597cc
commit 490de9d67a
6 changed files with 217 additions and 67 deletions

View file

@ -149,6 +149,7 @@
<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.SherpafyStartActivity" android:exported="true"></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.search.GeoIntentActivity">
<intent-filter>

View file

@ -17,6 +17,13 @@
android:text="Itenerary"/>
</RelativeLayout>
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/stages">
</RadioGroup>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
@ -60,7 +67,7 @@
android:textSize="18sp" >
</TextView>
<Button android:id="@+id/settings"
<Button android:id="@+id/btn_settings"
android:text="Settings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

View file

@ -43,7 +43,6 @@ import android.view.animation.Animation;
import android.view.animation.Transformation;
import android.view.animation.TranslateAnimation;
import android.widget.TextView;
import net.osmand.plus.sherpafy.SherpafyStartActivity;
public class MainMenuActivity extends Activity {

View file

@ -1,10 +1,12 @@
package net.osmand.plus.sherpafy;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.StrictMode;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
@ -23,12 +25,12 @@ import java.util.concurrent.ConcurrentHashMap;
*/
public class SherpafyStartActivity extends SherlockFragmentActivity {
private ProgressDialog startProgressDialog;
private SherpafyCustomization customization;
@Override
protected void onCreate(Bundle savedInstanceState) {
//Initialization
((OsmandApplication) getApplication()).applyTheme(this);
super.onCreate(savedInstanceState);
getSherlock().setUiOptions(ActivityInfo.UIOPTION_SPLIT_ACTION_BAR_WHEN_NARROW);
@ -41,32 +43,27 @@ public class SherpafyStartActivity extends SherlockFragmentActivity {
customization = (SherpafyCustomization) getMyApplication().getAppCustomization();
if (customization.getTourInformations().isEmpty())
ProgressDialog startProgressDialog = new ProgressDialog(this);
getMyApplication().checkApplicationIsBeingInitialized(this, startProgressDialog);
if (startProgressDialog.isShowing())
{
customization.onIndexingFiles( IProgress.EMPTY_PROGRESS, new ConcurrentHashMap<String, String>() );
startProgressDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialogInterface) {
onStartDialogClose();
}
});
}
else {
onStartDialogClose();
}
if (customization.getSelectedTour() == null) {
startProgressDialog = new ProgressDialog(this);
getMyApplication().checkApplicationIsBeingInitialized(this, startProgressDialog);
updateDefaultView();
} else {
super.setContentView(R.layout.custom_tour_info);
updateTourView();
}
}
@Override
protected void onResume() {
super.onResume();
if (customization.getSelectedTour() != null)
{
super.setContentView(R.layout.custom_tour_info);
updateTourView();
}
}
@Override
@ -79,7 +76,6 @@ public class SherpafyStartActivity extends SherlockFragmentActivity {
}
private void updateDefaultView(){
super.setContentView(R.layout.sherpafy_start);
Button selectTour = (Button) findViewById(R.id.select_tour);
selectTour.setOnClickListener(new View.OnClickListener() {
@ -103,42 +99,22 @@ public class SherpafyStartActivity extends SherlockFragmentActivity {
});
}
private void updateTourView() {
ImageView img = (ImageView) findViewById(R.id.tour_image);
TextView description = (TextView) findViewById(R.id.tour_description);
TextView fullDescription = (TextView) findViewById(R.id.tour_fulldescription);
TextView 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.settings);
private void onStartDialogClose(){
if (customization.getTourInformations().isEmpty())
{
customization.onIndexingFiles( IProgress.EMPTY_PROGRESS, new ConcurrentHashMap<String, String>() );
}
settings.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
updateDefaultView();
}
});
TourInformation tour = customization.getSelectedTour();
List<TourInformation.StageInformation> stages = tour.getStageInformation();
name.setText(tour.getName());
description.setText(tour.getShortDescription());
description.setVisibility(View.VISIBLE);
fullDescription.setText(tour.getFulldescription());
fullDescription.setVisibility(View.VISIBLE);
final Bitmap imageBitmap = tour.getImageBitmap();
if (imageBitmap != null) {
img.setImageBitmap(imageBitmap);
img.setAdjustViewBounds(true);
img.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
img.setCropToPadding(true);
img.setVisibility(View.VISIBLE);
} else {
img.setVisibility(View.GONE);
}
}
Intent start_intent = getIntent();
if ( start_intent.getStringExtra("settings") != null || customization.getSelectedTour() == null ) {
super.setContentView(R.layout.sherpafy_start);
updateDefaultView();
} else {
Intent intent = new Intent(getApplicationContext(),TourViewActivity.class);
startActivity(intent);
finish();
}
}
}

View file

@ -69,7 +69,6 @@ public class TourCommonActivity extends SherlockFragmentActivity {
protected void onPreExecute() {
dlg = ProgressDialogImplementation.createProgressDialog(TourCommonActivity.this, "", getString(R.string.indexing_tour, ""),
ProgressDialog.STYLE_SPINNER);
};
@Override
@ -80,14 +79,17 @@ public class TourCommonActivity extends SherlockFragmentActivity {
protected void onPostExecute(Void result) {
dlg.getDialog().dismiss();
for(WeakReference<Fragment> ref : fragList) {
Fragment f = ref.get();
if(f instanceof TourFragment) {
if(!f.isDetached()) {
((TourFragment) f).refreshTour();
}
}
}
// for(WeakReference<Fragment> ref : fragList) {
// Fragment f = ref.get();
// if(f instanceof TourFragment) {
// if(!f.isDetached()) {
// ((TourFragment) f).refreshTour();
// }
// }
// }
Intent intent = new Intent(getApplicationContext(), TourViewActivity.class);
startActivity(intent);
finish();
};
}.execute(ti);
}

View file

@ -0,0 +1,165 @@
package net.osmand.plus.sherpafy;
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
import com.actionbarsherlock.app.SherlockFragment;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import net.osmand.IProgress;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import java.util.List;
/**
* Created by Barsik on 02.06.2014.
*/
public class TourViewActivity extends SherlockFragmentActivity {
private SherpafyCustomization customization;
private ProgressDialog startProgressDialog;
ImageView img;
TextView description;
TextView fullDescription;
TextView name;
List<TourInformation.StageInformation> stages_info;
TourInformation cur_tour;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
((OsmandApplication) getApplication()).applyTheme(this);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle("Sherpafy");
// if (customization.getTourInformations().isEmpty())
// {
// customization.onIndexingFiles( IProgress.EMPTY_PROGRESS, new ConcurrentHashMap<String, String>() );
// }
startProgressDialog = new ProgressDialog(this);
getMyApplication().checkApplicationIsBeingInitialized(this, startProgressDialog);
customization = (SherpafyCustomization) getMyApplication().getAppCustomization();
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();
stages.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int i) {
customization.selectStage(stages_info.get(i), IProgress.EMPTY_PROGRESS);
if (i== 0){
fullDescription.setText(cur_tour.getFulldescription());
description.setText((cur_tour.getShortDescription()));
prepareBitmap();
} else {
description.setText(stages_info.get(i).getDescription());
fullDescription.setText("");
}
}
});
settings.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), SherpafyStartActivity.class);
intent.putExtra("settings", "settings");
startActivity(intent);
}
});
//get count of radio buttons
final int count = stages_info.size();
final RadioButton[] rb = new RadioButton[count];
//add radio buttons to view
for (int i =0; i< count; i++){
rb[i] = new RadioButton(this);
rb[i].setId(i);
stages.addView(rb[i]);
String stage_name = stages_info.get(i).getName();
//if string lenght is longer than 10 - app looks like shit, need to trim and find a workaround
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();
name.setText(cur_tour.getName());
//if there's no current stage - overview should be selected
if (cur_stage == null){
stages.check(0);
description.setText(cur_tour.getShortDescription());
fullDescription.setText(cur_tour.getFulldescription());
prepareBitmap();
} else{
int i = 0;
for (i=0; i<count;i++){
if (cur_stage.equals(stages_info.get(i)))
break;
}
if (i != count){
stages.check(i);
} else{
stages.check(0);
}
}
}
private void prepareBitmap(){
final Bitmap imageBitmap = cur_tour.getImageBitmap();
if (imageBitmap != null) {
img.setImageBitmap(imageBitmap);
img.setAdjustViewBounds(true);
img.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
img.setCropToPadding(true);
img.setVisibility(View.VISIBLE);
} else {
img.setVisibility(View.GONE);
}
}
private OsmandApplication getMyApplication() {
return (OsmandApplication) getApplication();
}
private TourViewActivity GetActivity(){ return this;}
}