Add stage view
This commit is contained in:
parent
e290509137
commit
22f8d73776
14 changed files with 460 additions and 141 deletions
14
OsmAnd/res/drawable/sherpafy_tour_row.xml
Normal file
14
OsmAnd/res/drawable/sherpafy_tour_row.xml
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:state_selected="true"
|
||||
android:drawable="@color/sherpafy_selection"/>
|
||||
<item
|
||||
android:state_pressed="true"
|
||||
android:drawable="@color/sherpafy_selection"/>
|
||||
<item
|
||||
android:state_focused="true"
|
||||
android:drawable="@color/sherpafy_selection"/>
|
||||
<item
|
||||
android:drawable="@color/shadow_color" />
|
||||
</selector>
|
|
@ -2,7 +2,7 @@
|
|||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="#eeeeee" >
|
||||
android:background="@drawable/sherpafy_tour_row" >
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="fill_parent"
|
||||
|
@ -11,7 +11,8 @@
|
|||
android:layout_marginLeft="14dp"
|
||||
android:layout_marginRight="14dp"
|
||||
android:layout_marginTop="15dp"
|
||||
android:background="#ffffff"
|
||||
android:id="@+id/AreaPreview"
|
||||
android:background="@color/color_white"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<FrameLayout
|
||||
|
@ -65,6 +66,7 @@
|
|||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="14sp"
|
||||
android:focusable="false"
|
||||
/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
|
|
@ -24,4 +24,4 @@
|
|||
android:textSize="18sp" />
|
||||
</LinearLayout>
|
||||
|
||||
</FrameLayout>
|
||||
</FrameLayout>
|
||||
|
|
59
OsmAnd/res/layout/sherpafy_stage_info.xml
Normal file
59
OsmAnd/res/layout/sherpafy_stage_info.xml
Normal file
|
@ -0,0 +1,59 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent" >
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/Icon"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:scaleType="centerCrop"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:layout_marginRight="8dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:orientation="horizontal" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/HeaderText"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
android:layout_weight="1"
|
||||
android:textSize="19sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/AdditionalText"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_gravity="bottom"
|
||||
android:layout_marginLeft="7dp"
|
||||
android:textColor="@color/sherpafy_add_text"
|
||||
android:textSize="16sp" />
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/Text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:layout_marginRight="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:singleLine="false"
|
||||
android:textColor="@color/sherpafy_add_text"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<WebView android:id="@+id/Description"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:layout_marginRight="8dp"/>
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
|
@ -6,17 +6,21 @@
|
|||
android:paddingTop="8dp"
|
||||
android:orientation="horizontal" >
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/Icon"
|
||||
<FrameLayout
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:layout_marginRight="8dp" />
|
||||
|
||||
android:layout_marginRight="8dp" >
|
||||
<ImageView
|
||||
android:id="@+id/Icon"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"/>
|
||||
</FrameLayout>
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1" >
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/HeaderText"
|
||||
|
@ -32,7 +36,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center"
|
||||
android:gravity="center_vertical"
|
||||
android:maxLines="1"
|
||||
android:textSize="14sp" />
|
||||
</LinearLayout>
|
||||
|
@ -40,11 +44,11 @@
|
|||
<TextView
|
||||
android:id="@+id/AdditionalText"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_marginLeft="7dp"
|
||||
android:layout_marginRight="7dp"
|
||||
android:gravity="center_vertical"
|
||||
android:textColor="#b9b9b9"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:textColor="@color/sherpafy_add_text"
|
||||
android:textSize="14sp" />
|
||||
|
||||
</LinearLayout>
|
|
@ -65,4 +65,7 @@
|
|||
|
||||
<color name="distance_color">#dd6CB336</color>
|
||||
<color name="shadow_color">#33888888</color>
|
||||
<color name="sherpafy_selection">#ff33b5e5</color>
|
||||
<color name="sherpafy_add_text">#b9b9b9</color>
|
||||
|
||||
</resources>
|
|
@ -3,8 +3,11 @@
|
|||
<string name="sherpafy_tour_info_txt">Tour Information</string>
|
||||
<string name="sherpafy_stages_txt">Stages</string>
|
||||
<string name="sherpafy_instructions">Instructions</string>
|
||||
<string name="sherpafy_instructions_desr">Please read before start</string>
|
||||
<string name="sherpafy_overview">Overview</string>
|
||||
<string name="sherpafy_overview_desr">About your tour</string>
|
||||
<string name="sherpafy_gallery">Gallery</string>
|
||||
<string name="sherpafy_gallery_descr">Pictures of your tour</string>
|
||||
<string name="sherpafy_more_information">MORE INFORMATION</string>
|
||||
<string name="sherpafy_continue_stage">Continue</string>
|
||||
<string name="sherpafy_start_stage">Start</string>
|
||||
|
@ -18,6 +21,7 @@
|
|||
<string name="download_more">Download more</string>
|
||||
<string name="no_tour_selected">No tour selected</string>
|
||||
<string name="settings_file_create_error">Couldn\'t create settings file in tour folder.</string>
|
||||
<string name="tab_stage">Stage</string>
|
||||
<string name="tab_stages">Stages</string>
|
||||
<string name="tab_tours">Tours</string>
|
||||
<string name="tab_current_tour">Current</string>
|
||||
|
@ -27,6 +31,9 @@
|
|||
<string name="indexing_tour">Loading selected tour \'%s\'…</string>
|
||||
<string name="tour_activity_title">Tour</string>
|
||||
<string name="select_tour">Select tour</string>
|
||||
<string name="continue_stage">Continue</string>
|
||||
<string name="start_stage">Start</string>
|
||||
<string name="continue_tour">Continue tour</string>
|
||||
<string name="start_tour">Start tour</string>
|
||||
<string name="download_tour">Download tour</string>
|
||||
<string name="sherpafy_app_name">Sherpafy</string>
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
package net.osmand.plus.sherpafy;
|
||||
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.webkit.WebView;
|
||||
|
||||
import com.actionbarsherlock.app.SherlockFragment;
|
||||
|
||||
public class SherpafyHtmlFragment extends SherlockFragment {
|
||||
public static final String HTML = "HTML";
|
||||
public static final String TITLE = "TITLE";
|
||||
OsmandApplication app;
|
||||
private WebView wv;
|
||||
|
||||
public SherpafyHtmlFragment() {
|
||||
}
|
||||
|
||||
|
||||
public View onCreateView(android.view.LayoutInflater inflater, android.view.ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
app = (OsmandApplication) getSherlockActivity().getApplication();
|
||||
wv = new WebView(getActivity());
|
||||
return wv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(final View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
String data = getArguments().getString(HTML);
|
||||
String tl = getArguments().getString(TITLE);
|
||||
if(tl != null){
|
||||
getSherlockActivity().getSupportActionBar().setTitle(tl);
|
||||
}
|
||||
wv.loadData("<html><body>"+data+"</body></html", "text/html", "utf-8");
|
||||
}
|
||||
|
||||
}
|
|
@ -6,7 +6,6 @@ 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.LocalIndexesActivity;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.AlertDialog.Builder;
|
||||
|
@ -17,14 +16,14 @@ import android.graphics.Typeface;
|
|||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.text.SpannableString;
|
||||
import android.text.TextPaint;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.text.style.ClickableSpan;
|
||||
import android.text.util.Linkify;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
|
@ -40,12 +39,12 @@ import com.actionbarsherlock.view.MenuInflater;
|
|||
import com.actionbarsherlock.view.MenuItem;
|
||||
import com.actionbarsherlock.view.MenuItem.OnMenuItemClickListener;
|
||||
|
||||
public class SherpafyToursFragment extends SherlockListFragment {
|
||||
public class SherpafySelectToursFragment extends SherlockListFragment {
|
||||
private static final int ACTION_DOWNLOAD = 5;
|
||||
OsmandApplication app;
|
||||
private SherpafyCustomization custom;
|
||||
|
||||
public SherpafyToursFragment() {
|
||||
public SherpafySelectToursFragment() {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -61,7 +60,7 @@ public class SherpafyToursFragment extends SherlockListFragment {
|
|||
|
||||
@Override
|
||||
public void onListItemClick(ListView l, View v, int position, long id) {
|
||||
Toast.makeText(getActivity(), getListAdapter().getItem(position).toString(), Toast.LENGTH_LONG).show();
|
||||
((TourViewActivity) getActivity()).selectMenu(getListAdapter().getItem(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -87,7 +86,13 @@ public class SherpafyToursFragment extends SherlockListFragment {
|
|||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
getListView().setBackgroundColor(0x00eeeeee);
|
||||
// getListView().setOnItemClickListener(new OnItemClickListener() {
|
||||
//
|
||||
// @Override
|
||||
// public void onItemClick(AdapterView<?> parent, View view, int position,long arg3) {
|
||||
// view.findViewById(R.id.AreaPreview).setSelected(true);
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
protected void openAccessCode(final boolean startDownload) {
|
201
OsmAnd/src/net/osmand/plus/sherpafy/SherpafyStageFragment.java
Normal file
201
OsmAnd/src/net/osmand/plus/sherpafy/SherpafyStageFragment.java
Normal file
|
@ -0,0 +1,201 @@
|
|||
package net.osmand.plus.sherpafy;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.osmand.access.AccessibleAlertBuilder;
|
||||
import net.osmand.plus.GPXUtilities.GPXFile;
|
||||
import net.osmand.plus.GPXUtilities.WptPt;
|
||||
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.sherpafy.TourInformation.StageInformation;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.text.Html;
|
||||
import android.text.Html.ImageGetter;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.webkit.WebView;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ScrollView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.actionbarsherlock.app.SherlockFragment;
|
||||
import com.actionbarsherlock.view.Menu;
|
||||
import com.actionbarsherlock.view.MenuInflater;
|
||||
import com.actionbarsherlock.view.MenuItem;
|
||||
|
||||
public class SherpafyStageFragment extends SherlockFragment {
|
||||
public static final String STAGE_PARAM = "STAGE";
|
||||
public static final String TOUR_PARAM = "TOUR";
|
||||
private static final int START = 8;
|
||||
OsmandApplication app;
|
||||
private SherpafyCustomization customization;
|
||||
private StageInformation stage;
|
||||
private TourInformation tour;
|
||||
private View view;
|
||||
|
||||
public SherpafyStageFragment() {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
app = (OsmandApplication) getSherlockActivity().getApplication();
|
||||
customization = (SherpafyCustomization) app.getAppCustomization();
|
||||
|
||||
setHasOptionsMenu(true);
|
||||
String id = getArguments().getString(TOUR_PARAM);
|
||||
for(TourInformation ti : customization.getTourInformations()) {
|
||||
if(ti.getId().equals(id)) {
|
||||
tour = ti;
|
||||
getSherlockActivity().getSupportActionBar().setTitle(tour.getName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
int k = getArguments().getInt(STAGE_PARAM);
|
||||
if(tour != null && tour.getStageInformation().size() > k) {
|
||||
stage = tour.getStageInformation().get(k);
|
||||
getSherlockActivity().getSupportActionBar().setTitle(getString(R.string.tab_stage) + " " + (k+1));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
// createMenuItem(menu, ACTION_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);
|
||||
if (tour != null) {
|
||||
((TourViewActivity) getSherlockActivity()).createMenuItem(menu, START, R.string.start_tour,
|
||||
0, 0,
|
||||
MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if(item.getItemId() == START) {
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
view = inflater.inflate(R.layout.sherpafy_stage_info, container, false);
|
||||
WebView description = (WebView) view.findViewById(R.id.Description);
|
||||
ImageView icon = (ImageView) view.findViewById(R.id.Icon);
|
||||
TextView additional = (TextView) view.findViewById(R.id.AdditionalText);
|
||||
TextView text = (TextView) view.findViewById(R.id.Text);
|
||||
TextView header = (TextView) view.findViewById(R.id.HeaderText);
|
||||
|
||||
if(stage.getImageBitmap() != null) {
|
||||
icon.setImageBitmap(stage.getImageBitmap()) ;
|
||||
} else {
|
||||
icon.setVisibility(View.GONE);
|
||||
}
|
||||
if (stage.getDistance() > 0) {
|
||||
additional.setText(OsmAndFormatter.getFormattedDistance((float) stage.getDistance(), getMyApplication()));
|
||||
} else {
|
||||
additional.setText("");
|
||||
}
|
||||
header.setText(stage.getName());
|
||||
text.setText(stage.getShortDescription());
|
||||
description.loadData("<html><body>" + stage.getFullDescription() + "</body></html", "text/html", "utf-8");
|
||||
return view;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private ImageGetter getImageGetter(final View v) {
|
||||
return new Html.ImageGetter() {
|
||||
@Override
|
||||
public Drawable getDrawable(String s) {
|
||||
Bitmap file = customization.getSelectedTour().getImageBitmapFromPath(s);
|
||||
v.setTag(file);
|
||||
Drawable bmp = new BitmapDrawable(getResources(), file);
|
||||
// if image is thicker than screen - it may cause some problems, so we need to scale it
|
||||
int imagewidth = bmp.getIntrinsicWidth();
|
||||
// TODO
|
||||
// if (displaySize.x - 1 > imagewidth) {
|
||||
// bmp.setBounds(0, 0, bmp.getIntrinsicWidth(), bmp.getIntrinsicHeight());
|
||||
// } else {
|
||||
// double scale = (double) (displaySize.x - 1) / imagewidth;
|
||||
// bmp.setBounds(0, 0, (int) (scale * bmp.getIntrinsicWidth()),
|
||||
// (int) (scale * bmp.getIntrinsicHeight()));
|
||||
// }
|
||||
return bmp;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void addOnClickListener(final TextView tv) {
|
||||
tv.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (v.getTag() instanceof Bitmap) {
|
||||
final AccessibleAlertBuilder dlg = new AccessibleAlertBuilder(getActivity());
|
||||
dlg.setPositiveButton(R.string.default_buttons_ok, null);
|
||||
ScrollView sv = new ScrollView(getActivity());
|
||||
ImageView img = new ImageView(getActivity());
|
||||
img.setImageBitmap((Bitmap) tv.getTag());
|
||||
sv.addView(img);
|
||||
dlg.setView(sv);
|
||||
dlg.show();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void prepareBitmap(Bitmap imageBitmap) {
|
||||
ImageView img = null;
|
||||
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 void goToMap() {
|
||||
if (customization.getSelectedStage() != null) {
|
||||
GPXFile gpx = customization.getSelectedStage().getGpx();
|
||||
List<SelectedGpxFile> sgpx = getMyApplication().getSelectedGpxHelper().getSelectedGPXFiles();
|
||||
if (gpx == null && sgpx.size() > 0) {
|
||||
getMyApplication().getSelectedGpxHelper().clearAllGpxFileToShow();
|
||||
} else if (sgpx.size() != 1 || sgpx.get(0).getGpxFile() != gpx) {
|
||||
getMyApplication().getSelectedGpxHelper().clearAllGpxFileToShow();
|
||||
if (gpx != null && gpx.findPointToShow() != null) {
|
||||
WptPt p = gpx.findPointToShow();
|
||||
getMyApplication().getSettings().setMapLocationToShow(p.lat, p.lon, 16, null);
|
||||
getMyApplication().getSelectedGpxHelper().setGpxFileToDisplay(gpx);
|
||||
}
|
||||
}
|
||||
}
|
||||
Intent newIntent = new Intent(getActivity(), customization.getMapActivity());
|
||||
newIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
|
||||
this.startActivityForResult(newIntent, 0);
|
||||
}
|
||||
|
||||
private OsmandApplication getMyApplication() {
|
||||
return (OsmandApplication) getActivity().getApplication();
|
||||
}
|
||||
|
||||
}
|
|
@ -3,23 +3,14 @@ package net.osmand.plus.sherpafy;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.osmand.access.AccessibleAlertBuilder;
|
||||
import net.osmand.plus.GPXUtilities.GPXFile;
|
||||
import net.osmand.plus.GPXUtilities.WptPt;
|
||||
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.actions.ShareDialog;
|
||||
import net.osmand.plus.sherpafy.TourInformation.StageInformation;
|
||||
import net.osmand.util.Algorithms;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.text.Html;
|
||||
import android.text.Html.ImageGetter;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -29,23 +20,23 @@ import android.widget.ArrayAdapter;
|
|||
import android.widget.ImageView;
|
||||
import android.widget.ImageView.ScaleType;
|
||||
import android.widget.ListView;
|
||||
import android.widget.ScrollView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.actionbarsherlock.app.SherlockListFragment;
|
||||
import com.actionbarsherlock.view.Menu;
|
||||
import com.actionbarsherlock.view.MenuInflater;
|
||||
import com.actionbarsherlock.view.MenuItem;
|
||||
|
||||
public class SherpafyTourOverviewFragment extends SherlockListFragment {
|
||||
public class SherpafyTourFragment extends SherlockListFragment {
|
||||
private static final int SHARE_ID = 6;
|
||||
private static final int START = 7;
|
||||
OsmandApplication app;
|
||||
private SherpafyCustomization customization;
|
||||
private TourInformation tour;
|
||||
private StageAdapter stageAdapter;
|
||||
private ImageView imageView;
|
||||
|
||||
public SherpafyTourOverviewFragment() {
|
||||
public SherpafyTourFragment() {
|
||||
}
|
||||
|
||||
|
||||
|
@ -92,7 +83,20 @@ public class SherpafyTourOverviewFragment extends SherlockListFragment {
|
|||
|
||||
@Override
|
||||
public void onListItemClick(ListView l, View v, int position, long id) {
|
||||
Toast.makeText(getActivity(), getListAdapter().getItem(position).toString(), Toast.LENGTH_LONG).show();
|
||||
if(position > 0) {
|
||||
StageItem si = (StageItem) getListAdapter().getItem(position - 1);
|
||||
if(si.type instanceof StageInformation) {
|
||||
((TourViewActivity) getSherlockActivity()).selectMenu(si.type);
|
||||
} else {
|
||||
if(si.type ==StageItemType.GALLERY) {
|
||||
//((TourViewActivity) getSherlockActivity()).showGallery(tour);
|
||||
} else if(si.type ==StageItemType.OVERVIEW) {
|
||||
((TourViewActivity) getSherlockActivity()).showHtmlFragment(si.header, tour.getFulldescription());
|
||||
} else if(si.type ==StageItemType.INSTRUCTIONS) {
|
||||
((TourViewActivity) getSherlockActivity()).showHtmlFragment(si.header, tour.getInstructions());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -101,9 +105,12 @@ public class SherpafyTourOverviewFragment extends SherlockListFragment {
|
|||
// createMenuItem(menu, ACTION_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);
|
||||
if (tour != null) {
|
||||
((TourViewActivity) getSherlockActivity()).createMenuItem(menu, SHARE_ID, R.string.settings,
|
||||
R.drawable.ic_action_gshare_light, R.drawable.ic_action_gshare_dark,
|
||||
((TourViewActivity) getSherlockActivity()).createMenuItem(menu, START, R.string.start_tour,
|
||||
0, 0,
|
||||
MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
|
||||
((TourViewActivity) getSherlockActivity()).createMenuItem(menu, SHARE_ID, R.string.share_fav,
|
||||
R.drawable.ic_action_gshare_light, R.drawable.ic_action_gshare_dark,
|
||||
MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -124,16 +131,25 @@ public class SherpafyTourOverviewFragment extends SherlockListFragment {
|
|||
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
List<StageItem> items = new ArrayList<SherpafyTourOverviewFragment.StageItem>();
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View v = super.onCreateView(inflater, container, savedInstanceState);
|
||||
imageView = new ImageView(getActivity());
|
||||
imageView.setLayoutParams(new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
|
||||
imageView.setScaleType(ScaleType.CENTER_CROP);
|
||||
return v;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
List<StageItem> items = new ArrayList<SherpafyTourFragment.StageItem>();
|
||||
items.add(new StageItem(StageItemType.TEXT, "", getString(R.string.sherpafy_tour_info_txt), false));
|
||||
items.add(new StageItem(StageItemType.OVERVIEW, getString(R.string.sherpafy_overview),
|
||||
getString(R.string.sherpafy_overview), false));
|
||||
getString(R.string.sherpafy_overview_desr), false));
|
||||
items.add(new StageItem(StageItemType.INSTRUCTIONS, getString(R.string.sherpafy_instructions),
|
||||
getString(R.string.sherpafy_instructions), false));
|
||||
getString(R.string.sherpafy_instructions_desr), false));
|
||||
items.add(new StageItem(StageItemType.GALLERY, getString(R.string.sherpafy_gallery),
|
||||
getString(R.string.sherpafy_gallery), false));
|
||||
getString(R.string.sherpafy_gallery_descr), false));
|
||||
items.add(new StageItem(StageItemType.TEXT, "", getString(R.string.sherpafy_stages_txt), true));
|
||||
if (tour != null) {
|
||||
for (StageInformation si : tour.getStageInformation()) {
|
||||
|
@ -141,17 +157,21 @@ public class SherpafyTourOverviewFragment extends SherlockListFragment {
|
|||
items.add(it);
|
||||
}
|
||||
stageAdapter = new StageAdapter(items);
|
||||
|
||||
ImageView iv = new ImageView(getActivity());
|
||||
iv.setLayoutParams(new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
|
||||
iv.setScaleType(ScaleType.CENTER_CROP);
|
||||
iv.setImageBitmap(tour.getImageBitmap());
|
||||
getListView().addHeaderView(iv);
|
||||
imageView.setImageBitmap(tour.getImageBitmap());
|
||||
if(imageView != null) {
|
||||
getListView().addHeaderView(imageView);
|
||||
}
|
||||
setListAdapter(stageAdapter);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
setListAdapter(null);
|
||||
}
|
||||
|
||||
|
||||
class StageAdapter extends ArrayAdapter<StageItem> {
|
||||
|
||||
|
@ -172,9 +192,13 @@ public class SherpafyTourOverviewFragment extends SherlockListFragment {
|
|||
TextView text = (TextView) row.findViewById(R.id.Text);
|
||||
TextView addtext = (TextView) row.findViewById(R.id.AdditionalText);
|
||||
|
||||
if(ti.type instanceof StageInformation) {
|
||||
// TODO !!
|
||||
addtext.setText("10 km");
|
||||
if (ti.type instanceof StageInformation) {
|
||||
double d = ((StageInformation) ti.type).getDistance();
|
||||
if (d > 0) {
|
||||
addtext.setText(OsmAndFormatter.getFormattedDistance((float) d, getMyApplication()));
|
||||
} else {
|
||||
addtext.setText("");
|
||||
}
|
||||
} else {
|
||||
addtext.setText("");
|
||||
}
|
||||
|
@ -206,90 +230,13 @@ public class SherpafyTourOverviewFragment extends SherlockListFragment {
|
|||
} else {
|
||||
img.setVisibility(View.VISIBLE);
|
||||
img.setImageDrawable(new StageImageDrawable(getActivity(),
|
||||
StageImageDrawable.INFO_COLOR, ti.txt.substring(0, 1) +"", 0 ));
|
||||
StageImageDrawable.INFO_COLOR, ti.header.substring(0, 1) +"", 0 ));
|
||||
}
|
||||
return row;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private ImageGetter getImageGetter(final View v) {
|
||||
return new Html.ImageGetter() {
|
||||
@Override
|
||||
public Drawable getDrawable(String s) {
|
||||
Bitmap file = customization.getSelectedTour().getImageBitmapFromPath(s);
|
||||
v.setTag(file);
|
||||
Drawable bmp = new BitmapDrawable(getResources(), file);
|
||||
// if image is thicker than screen - it may cause some problems, so we need to scale it
|
||||
int imagewidth = bmp.getIntrinsicWidth();
|
||||
// TODO
|
||||
// if (displaySize.x - 1 > imagewidth) {
|
||||
// bmp.setBounds(0, 0, bmp.getIntrinsicWidth(), bmp.getIntrinsicHeight());
|
||||
// } else {
|
||||
// double scale = (double) (displaySize.x - 1) / imagewidth;
|
||||
// bmp.setBounds(0, 0, (int) (scale * bmp.getIntrinsicWidth()),
|
||||
// (int) (scale * bmp.getIntrinsicHeight()));
|
||||
// }
|
||||
return bmp;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void addOnClickListener(final TextView tv) {
|
||||
tv.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (v.getTag() instanceof Bitmap) {
|
||||
final AccessibleAlertBuilder dlg = new AccessibleAlertBuilder(getActivity());
|
||||
dlg.setPositiveButton(R.string.default_buttons_ok, null);
|
||||
ScrollView sv = new ScrollView(getActivity());
|
||||
ImageView img = new ImageView(getActivity());
|
||||
img.setImageBitmap((Bitmap) tv.getTag());
|
||||
sv.addView(img);
|
||||
dlg.setView(sv);
|
||||
dlg.show();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void prepareBitmap(Bitmap imageBitmap) {
|
||||
ImageView img = null;
|
||||
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 void goToMap() {
|
||||
if (customization.getSelectedStage() != null) {
|
||||
GPXFile gpx = customization.getSelectedStage().getGpx();
|
||||
List<SelectedGpxFile> sgpx = getMyApplication().getSelectedGpxHelper().getSelectedGPXFiles();
|
||||
if (gpx == null && sgpx.size() > 0) {
|
||||
getMyApplication().getSelectedGpxHelper().clearAllGpxFileToShow();
|
||||
} else if (sgpx.size() != 1 || sgpx.get(0).getGpxFile() != gpx) {
|
||||
getMyApplication().getSelectedGpxHelper().clearAllGpxFileToShow();
|
||||
if (gpx != null && gpx.findPointToShow() != null) {
|
||||
WptPt p = gpx.findPointToShow();
|
||||
getMyApplication().getSettings().setMapLocationToShow(p.lat, p.lon, 16, null);
|
||||
getMyApplication().getSelectedGpxHelper().setGpxFileToDisplay(gpx);
|
||||
}
|
||||
}
|
||||
}
|
||||
Intent newIntent = new Intent(getActivity(), customization.getMapActivity());
|
||||
newIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
|
||||
this.startActivityForResult(newIntent, 0);
|
||||
}
|
||||
|
||||
private OsmandApplication getMyApplication() {
|
||||
return (OsmandApplication) getActivity().getApplication();
|
||||
}
|
|
@ -90,7 +90,7 @@ public class StageImageDrawable extends Drawable {
|
|||
// bs.inset((int)(bs.width() - min + 3 * density) / 2,
|
||||
// (int) (bs.height() - min + 3 * density) / 2);
|
||||
if(textPaint != null) {
|
||||
textPaint.setTextSize(bs.height() * 3 / 4);
|
||||
textPaint.setTextSize(bs.height() * 5 / 8);
|
||||
}
|
||||
if(drawable != null) {
|
||||
drawable.setBounds(bs);
|
||||
|
@ -108,7 +108,7 @@ public class StageImageDrawable extends Drawable {
|
|||
if (drawable != null) {
|
||||
drawable.draw(canvas);
|
||||
} else if(text != null ){
|
||||
canvas.drawText(text, cx, cy + 3 * rx / 8, textPaint);
|
||||
canvas.drawText(text, cx, cy + rx / 2, textPaint);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,10 +28,12 @@ public class TourInformation {
|
|||
private String homeUrl = "";
|
||||
private String shortDescription = "";
|
||||
private String fulldescription = "";
|
||||
private String instructions = "";
|
||||
private Bitmap defaultImg = null;
|
||||
private File imgFile;
|
||||
private List<StageInformation> stageInformation = new ArrayList<TourInformation.StageInformation>();
|
||||
|
||||
|
||||
public TourInformation(File f) {
|
||||
this.folder = f;
|
||||
this.name = f.getName().replace('_', ' ');
|
||||
|
@ -41,6 +43,10 @@ public class TourInformation {
|
|||
return folder.getName();
|
||||
}
|
||||
|
||||
public String getInstructions() {
|
||||
return instructions;
|
||||
}
|
||||
|
||||
|
||||
private static Reader getUTF8Reader(InputStream f) throws IOException {
|
||||
BufferedInputStream bis = new BufferedInputStream(f);
|
||||
|
@ -78,6 +84,10 @@ public class TourInformation {
|
|||
stage.name = name;
|
||||
} else if (tag.equals("fullDescription")){
|
||||
fulldescription = getInnerXml(parser);
|
||||
} else if (tag.equals("instructions")){
|
||||
instructions = getInnerXml(parser);
|
||||
} else if (stage != null && tag.equals("interval")){
|
||||
stage.distance = Double.parseDouble(getDefAttribute(parser, "distance", "0"));
|
||||
} else if (stage != null && tag.equals("description")){
|
||||
stage.fullDescription = getInnerXml(parser);
|
||||
}
|
||||
|
@ -90,21 +100,23 @@ public class TourInformation {
|
|||
stage = null;
|
||||
} else if(stage != null && tag.equals("fullDescription")) {
|
||||
stage.fullDescription = text;
|
||||
} else if(stage != null && tag.equals("image")) {
|
||||
} else if(stage != null && tag.equals("defaultImage")) {
|
||||
if(text.startsWith(FILE_PREFIX)) {
|
||||
stage.imgFile = getFile(text);
|
||||
}
|
||||
} else if(tag.equals("defaultImage")) {
|
||||
if(text.startsWith(FILE_PREFIX)) {
|
||||
imgFile = getFile(text);
|
||||
}
|
||||
} else if(stage != null && tag.equals("gpx")) {
|
||||
if(text.startsWith(FILE_PREFIX)) {
|
||||
stage.gpxFile = getFile(text);
|
||||
}
|
||||
} else if(tag.equals("fullDescription")) {
|
||||
fulldescription = text;
|
||||
} else if(tag.equals("shortDescription")) {
|
||||
shortDescription = text;
|
||||
} else if(tag.equals("defaultImage")) {
|
||||
if(text.startsWith(FILE_PREFIX)) {
|
||||
imgFile = getFile(text);
|
||||
if(stage != null) {
|
||||
stage.shortDescription = text;
|
||||
} else {
|
||||
shortDescription = text;
|
||||
}
|
||||
}
|
||||
text = "";
|
||||
|
@ -180,6 +192,7 @@ public class TourInformation {
|
|||
String fullDescription = "";
|
||||
Bitmap img = null;
|
||||
File imgFile;
|
||||
double distance;
|
||||
private TourInformation tour;
|
||||
private int order;
|
||||
|
||||
|
@ -228,6 +241,10 @@ public class TourInformation {
|
|||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public double getDistance() {
|
||||
return distance;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -219,14 +219,14 @@ public class TourViewActivity extends SherlockFragmentActivity {
|
|||
Fragment fragment = fragments.get(item);
|
||||
if (new Integer(R.string.sherpafy_tours).equals(item)) {
|
||||
if (fragment == null) {
|
||||
fragment = new SherpafyToursFragment();
|
||||
fragment = new SherpafySelectToursFragment();
|
||||
fragments.put(item, fragment);
|
||||
}
|
||||
state = STATE_SELECT_TOUR;
|
||||
} else if(item instanceof TourInformation) {
|
||||
state = STATE_TOUR_VIEW;
|
||||
if (fragment == null) {
|
||||
fragment = new SherpafyTourOverviewFragment();
|
||||
fragment = new SherpafyTourFragment();
|
||||
Bundle bl = new Bundle();
|
||||
bl.putString("TOUR", ((TourInformation) item).getId());
|
||||
fragment.setArguments(bl);
|
||||
|
@ -234,6 +234,14 @@ public class TourViewActivity extends SherlockFragmentActivity {
|
|||
}
|
||||
} else if(item instanceof StageInformation) {
|
||||
state = STATE_STAGE_OVERVIEW;
|
||||
if (fragment == null) {
|
||||
fragment = new SherpafyStageFragment();
|
||||
Bundle bl = new Bundle();
|
||||
bl.putString(SherpafyStageFragment.TOUR_PARAM, ((StageInformation) item).getTour().getId());
|
||||
bl.putInt(SherpafyStageFragment.STAGE_PARAM, ((StageInformation) item).getOrder());
|
||||
fragment.setArguments(bl);
|
||||
fragments.put(item, fragment);
|
||||
}
|
||||
}
|
||||
if(fragment != null) {
|
||||
fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
|
||||
|
@ -265,4 +273,18 @@ public class TourViewActivity extends SherlockFragmentActivity {
|
|||
}
|
||||
updateActionBarTitle();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void showHtmlFragment(String title, String cont) {
|
||||
FragmentManager fragmentManager = getSupportFragmentManager();
|
||||
SherpafyHtmlFragment fragment = new SherpafyHtmlFragment();
|
||||
Bundle bl = new Bundle();
|
||||
bl.putString(SherpafyHtmlFragment.HTML, cont);
|
||||
bl.putString(SherpafyHtmlFragment.TITLE, title);
|
||||
fragment.setArguments(bl);
|
||||
fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue