Refactor sherpafy

This commit is contained in:
Victor Shcherb 2014-07-20 02:39:46 +02:00
parent c5fb1c900f
commit 2655856f1a
50 changed files with 517 additions and 265 deletions

8
OsmAnd/assets/style.css Normal file
View file

@ -0,0 +1,8 @@
h3 { text-align: center}
h4 { text-align: center}
div {border-width: 1px; padding: 10px;
border: groove; margin-left:auto;margin-right:auto; }
li { text-align:justify;"}
img { max-width: 75%; width: auto; height: auto; }
p.img {text-align: center}

View file

@ -40,6 +40,11 @@
<include name="images/**/*.png"/> <include name="images/**/*.png"/>
</fileset> </fileset>
</sync> </sync>
<copy todir="assets/help">
<fileset dir="assets/" >
<include name="style.css"/>
</fileset>
</copy>
<copy todir="${src.absolute.dir}/net/osmand/render/"> <copy todir="${src.absolute.dir}/net/osmand/render/">
<fileset dir="../../resources/rendering_styles/" > <fileset dir="../../resources/rendering_styles/" >
<include name="*.xml"/> <include name="*.xml"/>
@ -58,7 +63,8 @@
</target> </target>
<target name="generate-resources" depends="">
</target>
<!-- Extra target --> <!-- Extra target -->
<target name="-pre-build" depends="copy_resources,fix_apostrophe_issues"> <target name="-pre-build" depends="copy_resources,fix_apostrophe_issues">
@ -135,6 +141,14 @@
</if> </if>
</target> </target>
<target name="copy_sherpafy">
<copy todir="gen/net/osmand/plus">
<fileset dir="gen/net/osmand/sherpafy">
<include name="R.java" />
</fileset>
</copy>
<replaceregexp file="gen/net/osmand/plus/R.java" match='package (.*);' replace='package net.osmand.plus;' byline="true" />
</target>
<!-- Compiles this project's .java files into .class files. --> <!-- Compiles this project's .java files into .class files. -->
<target name="-compile" depends="-build-setup, -pre-build, -code-gen, -pre-compile"> <target name="-compile" depends="-build-setup, -pre-build, -code-gen, -pre-compile">

Binary file not shown.

View file

@ -12,3 +12,4 @@ split.density=false
# Project target. # Project target.
target=android-19 target=android-19
android.library.reference.1=../SherlockBar android.library.reference.1=../SherlockBar
dex.force.jumbo=true

Binary file not shown.

After

Width:  |  Height:  |  Size: 171 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 137 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 133 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 158 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 182 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 140 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 140 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 206 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 208 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 8.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.2 KiB

After

Width:  |  Height:  |  Size: 12 KiB

View file

@ -0,0 +1,20 @@
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The navigation drawer -->
<ListView android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="#111"/>
</android.support.v4.widget.DrawerLayout>

View file

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" android:background="@color/color_white"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp">
<FrameLayout >
<ImageView
android:id="@+id/TourImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/TourName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="1"
android:background="@color/shadow_color"
android:ellipsize="end"
android:textSize="20sp"
android:textColor="@color/color_white"
/>
</FrameLayout>
<TextView
android:id="@+id/TourDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="3"
android:ellipsize="end"
android:textSize="20sp"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"/>
</LinearLayout>

View file

@ -1,4 +1,4 @@
<?xml version='1.0' encoding='utf-8'?> <?xml version="1.0" encoding="utf-8"?>
<resources><string name="auto_zoom_none">Без аўтаматычнага масштабіраваньня</string> <resources><string name="auto_zoom_none">Без аўтаматычнага масштабіраваньня</string>
<string name="auto_zoom_close">Зачыніць</string> <string name="auto_zoom_close">Зачыніць</string>
<string name="auto_zoom_far">Для сярэдняга масштаба</string> <string name="auto_zoom_far">Для сярэдняга масштаба</string>

View file

@ -1,4 +1,4 @@
<?xml version='1.0' encoding='utf-8'?> <?xml version="1.0" encoding="utf-8"?>
<resources><string name="show_warnings_title">Mostra els missatges d\'avís…</string> <resources><string name="show_warnings_title">Mostra els missatges d\'avís…</string>
<string name="map_widget_fluorescent">Rutes amb fluorescència</string> <string name="map_widget_fluorescent">Rutes amb fluorescència</string>
<string name="map_widget_show_ruler">Mostra el regle</string> <string name="map_widget_show_ruler">Mostra el regle</string>

View file

@ -1,4 +1,4 @@
<?xml version='1.0' encoding='utf-8'?> <?xml version="1.0" encoding="utf-8"?>
<resources><string name="srtm_paid_version_msg">Overvej at købe Højdekurve udvidelsen (\'Contour lines\') på Google Play for at støtte den videre udvikling.</string> <resources><string name="srtm_paid_version_msg">Overvej at købe Højdekurve udvidelsen (\'Contour lines\') på Google Play for at støtte den videre udvikling.</string>
<string name="av_def_action_video">Optag video</string> <string name="av_def_action_video">Optag video</string>
<string name="av_def_action_audio">Optag audio</string> <string name="av_def_action_audio">Optag audio</string>

View file

@ -1,4 +1,4 @@
<?xml version='1.0' encoding='utf-8'?> <?xml version="1.0" encoding="utf-8"?>
<resources><string name="btn_add_tag">Προσθήκη Ετικέτας</string> <resources><string name="btn_add_tag">Προσθήκη Ετικέτας</string>
<string name="btn_advanced_mode">Λειτουργία για προχωρημένους…</string> <string name="btn_advanced_mode">Λειτουργία για προχωρημένους…</string>
<string name="poi_filter_parking">Στάθμευση</string> <string name="poi_filter_parking">Στάθμευση</string>

View file

@ -1,4 +1,4 @@
<?xml version='1.0' encoding='utf-8'?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<string name="layer_map_appearance">Configura pantalla</string> <string name="layer_map_appearance">Configura pantalla</string>

View file

@ -1,4 +1,4 @@
<?xml version='1.0' encoding='utf-8'?> <?xml version="1.0" encoding="utf-8"?>
<resources><string name="local_osm_changes_backup_failed">پشتیبان‌گیری از تغییرات OsmAnd ناموفق بود</string> <resources><string name="local_osm_changes_backup_failed">پشتیبان‌گیری از تغییرات OsmAnd ناموفق بود</string>
<string name="plugin_distance_point_time">زمان</string> <string name="plugin_distance_point_time">زمان</string>
<string name="plugin_distance_point_hdop">دقت</string> <string name="plugin_distance_point_hdop">دقت</string>

View file

@ -1,4 +1,4 @@
<?xml version='1.0' encoding='utf-8'?> <?xml version="1.0" encoding="utf-8"?>
<resources><string name="offline_edition">Modifications hors-ligne</string> <resources><string name="offline_edition">Modifications hors-ligne</string>
<string name="offline_edition_descr">Toujours utiliser l\'édition hors-ligne</string> <string name="offline_edition_descr">Toujours utiliser l\'édition hors-ligne</string>
<string name="tip_recent_changes_0_7_1_t">"Changements en 0.7.1 : <string name="tip_recent_changes_0_7_1_t">"Changements en 0.7.1 :

View file

@ -1,4 +1,4 @@
<?xml version='1.0' encoding='utf-8'?> <?xml version="1.0" encoding="utf-8"?>
<resources><string name="tip_recent_changes_0_7_2_t">"A 0.7.2 kiadás változásai: <resources><string name="tip_recent_changes_0_7_2_t">"A 0.7.2 kiadás változásai:
\n\t- Natív renderelő minden eszközre \n\t- Natív renderelő minden eszközre
\n\t- Offline POI szerkesztés \n\t- Offline POI szerkesztés

View file

@ -1,4 +1,4 @@
<?xml version='1.0' encoding='utf-8'?> <?xml version="1.0" encoding="utf-8"?>
<resources><string name="use_fluorescent_overlays">Sovrapposizioni fluorescenti</string> <resources><string name="use_fluorescent_overlays">Sovrapposizioni fluorescenti</string>
<string name="use_fluorescent_overlays_descr">Usa colori fluorescenti per visualizzare tracce e percorsi</string> <string name="use_fluorescent_overlays_descr">Usa colori fluorescenti per visualizzare tracce e percorsi</string>
<string name="offline_edition">Modifiche offline</string> <string name="offline_edition">Modifiche offline</string>

View file

@ -1,4 +1,4 @@
<?xml version='1.0' encoding='utf-8'?> <?xml version="1.0" encoding="utf-8"?>
<resources><string name="vector_maps_may_display_faster_on_some_devices">벡터 맵이 더욱 빠르게 표시됩니다. 하지만, 어떤 기기에서는 잘 작동하지 않을 수 있습니다.</string> <resources><string name="vector_maps_may_display_faster_on_some_devices">벡터 맵이 더욱 빠르게 표시됩니다. 하지만, 어떤 기기에서는 잘 작동하지 않을 수 있습니다.</string>
<string name="play_commands_of_currently_selected_voice">현재 선택된 음성 명령을 재생합니다</string> <string name="play_commands_of_currently_selected_voice">현재 선택된 음성 명령을 재생합니다</string>

View file

@ -1,4 +1,4 @@
<?xml version='1.0' encoding='utf-8'?> <?xml version="1.0" encoding="utf-8"?>
<resources><string name="starting_point_too_far">Pradžios taškas yra per toli nuo artimiausio kelio.</string> <resources><string name="starting_point_too_far">Pradžios taškas yra per toli nuo artimiausio kelio.</string>
<string name="shared_location">Bendrinta vieta</string> <string name="shared_location">Bendrinta vieta</string>
<string name="osmand_parking_warning">Dėmesio</string> <string name="osmand_parking_warning">Dėmesio</string>

View file

@ -1,4 +1,4 @@
<?xml version='1.0' encoding='utf-8'?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<string name="layer_map_appearance">Configureer scherm</string> <string name="layer_map_appearance">Configureer scherm</string>

View file

@ -1,4 +1,4 @@
<?xml version='1.0' encoding='utf-8'?> <?xml version="1.0" encoding="utf-8"?>
<resources><string name="srtm_plugin_description">Этот плагин позволяет загружать линии высот (Загрузка данных -&gt; Меню -&gt; "Другие карты") для использования оффлайн.</string> <resources><string name="srtm_plugin_description">Этот плагин позволяет загружать линии высот (Загрузка данных -&gt; Меню -&gt; "Другие карты") для использования оффлайн.</string>
<string name="srtm_paid_version_msg">Рассмотрите пожалуйста покупку плагина \"Линии высот\" на Market, чтобы поддержать последующую разработку.</string> <string name="srtm_paid_version_msg">Рассмотрите пожалуйста покупку плагина \"Линии высот\" на Market, чтобы поддержать последующую разработку.</string>
<string name="srtm_paid_version_title">Линии высот</string> <string name="srtm_paid_version_title">Линии высот</string>

View file

@ -1,4 +1,4 @@
<?xml version='1.0' encoding='utf-8'?> <?xml version="1.0" encoding="utf-8"?>
<resources><string name="recording_context_menu_show">Zobraziť</string> <resources><string name="recording_context_menu_show">Zobraziť</string>
<string name="recording_photo_description">Fotografia %1$s zachytená dňa %2$s</string> <string name="recording_photo_description">Fotografia %1$s zachytená dňa %2$s</string>
<string name="av_def_action_picture">Zachytiť fotografiu</string> <string name="av_def_action_picture">Zachytiť fotografiu</string>

View file

@ -1,4 +1,4 @@
<?xml version='1.0' encoding='utf-8'?> <?xml version="1.0" encoding="utf-8"?>
<resources><string name="search_button">Iskanje</string> <resources><string name="search_button">Iskanje</string>
<string name="search_activity">Iskanje</string> <string name="search_activity">Iskanje</string>
<string name="settings_Button">Nastavitve</string> <string name="settings_Button">Nastavitve</string>

View file

@ -1,4 +1,4 @@
<?xml version='1.0' encoding='utf-8'?> <?xml version="1.0" encoding="utf-8"?>
<resources><string name="rendering_attr_roadColors_description">選擇道路的色彩調配:</string> <resources><string name="rendering_attr_roadColors_description">選擇道路的色彩調配:</string>
<string name="rendering_attr_roadColors_name">道路的色彩調配</string> <string name="rendering_attr_roadColors_name">道路的色彩調配</string>
<string name="map_widget_show_destination_arrow">顯示目的地方向</string> <string name="map_widget_show_destination_arrow">顯示目的地方向</string>

View file

@ -64,4 +64,5 @@
<color name="osmbug_not_submitted">#C8FFFF00</color> <!-- standard YELLOW --> <color name="osmbug_not_submitted">#C8FFFF00</color> <!-- standard YELLOW -->
<color name="distance_color">#dd6CB336</color> <color name="distance_color">#dd6CB336</color>
<color name="shadow_color">#33aaaaaa</color>
</resources> </resources>

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?> <?xml version="1.0" encoding="utf-8" standalone="no"?>
<resources> <resources>
<string name="app_name">OsmAnd~</string> <string name="app_name">Sherpafy</string>
<string name="app_version">1.8 alpha</string> <string name="app_version">1.8 alpha</string>
<!-- Not translatable --> <!-- Not translatable -->
<string name="ga_api_key">UA-28342846-2</string> <string name="ga_api_key">UA-28342846-2</string>

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?> <?xml version="1.0" encoding="utf-8" standalone="no"?>
<resources> <resources>
<string name="sherpafy_tours">Sherpafy Tours</string>
<string name="access_code_is_not_valid">Access code is not valid</string> <string name="access_code_is_not_valid">Access code is not valid</string>
<string name="enter_access_code">Enter access code</string> <string name="enter_access_code">Enter access code</string>
<string name="overview">Overview</string> <string name="overview">Overview</string>

View file

@ -0,0 +1,36 @@
package net.osmand.plus.sherpafy;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import android.os.Bundle;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.actionbarsherlock.app.SherlockFragment;
public class SherpafyLoadingFragment extends SherlockFragment {
OsmandApplication app;
private View view;
public SherpafyLoadingFragment(OsmandApplication app) {
this.app = app;
}
public View onCreateView(android.view.LayoutInflater inflater, android.view.ViewGroup container,
Bundle savedInstanceState) {
view = inflater.inflate(R.layout.sherpafy_loading, container, false);
app.checkApplicationIsBeingInitialized(getActivity(), (TextView) view.findViewById(R.id.ProgressMessage),
(ProgressBar) view.findViewById(R.id.ProgressBar), new Runnable() {
@Override
public void run() {
((TextView) view.findViewById(R.id.ProgressMessage)).setVisibility(View.GONE);
view.findViewById(R.id.ProgressBar).setVisibility(View.GONE);
((TourViewActivity)getSherlockActivity()).loadingFinished();
}
});
return view;
}
}

View file

@ -0,0 +1,173 @@
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.AlertDialog.Builder;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.os.AsyncTask;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ListView;
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;
import com.actionbarsherlock.view.MenuItem.OnMenuItemClickListener;
public class SherpafyToursFragment extends SherlockListFragment {
private static final int ACTION_DOWNLOAD = 5;
OsmandApplication app;
private View view;
private SherpafyCustomization custom;
public SherpafyToursFragment(OsmandApplication app) {
this.app = app;
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
OsmandApplication app = (OsmandApplication) getSherlockActivity().getApplication();
custom = (SherpafyCustomization) app.getAppCustomization();
TourAdapter tourAdapter = new TourAdapter(custom.getTourInformations());
setListAdapter(tourAdapter);
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
OsmandApplication app = (OsmandApplication) getActivity().getApplication();
boolean light = true; //app.getSettings().isLightActionBar();
com.actionbarsherlock.view.MenuItem menuItem = menu.add(0, ACTION_DOWNLOAD, 0, R.string.download_tours).setShowAsActionFlags(
MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
//menuItem = menuItem.setIcon(light ? R.drawable.ic_action_gdirections_light : R.drawable.ic_action_gdirections_dark);
menuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(com.actionbarsherlock.view.MenuItem item) {
if (custom.getAccessCode().length() == 0) {
openAccessCode(true);
} else {
startDownloadActivity();
}
return true;
}
});
}
protected void openAccessCode(final boolean startDownload) {
Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string.enter_access_code);
final EditText editText = new EditText(getActivity());
editText.setInputType(EditorInfo.TYPE_TEXT_FLAG_CAP_CHARACTERS);
LinearLayout ll = new LinearLayout(getActivity());
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 (!custom.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(getActivity(), DownloadIndexActivity.class);
download.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(download);
}
private void selectTourAsync(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) {
// if tour is already selected - do nothing
if (custom.getSelectedTour() != null) {
if (custom.getSelectedTour().equals(params[0])) {
return null;
}
}
custom.selectTour(params[0], IProgress.EMPTY_PROGRESS);
return null;
}
protected void onPostExecute(Void result) {
// to avoid illegal argument exception when rotating phone during loading
try {
dlg.dismiss();
} catch (Exception ex) {
ex.printStackTrace();
}
//startTourView();
};
}.execute(tour);
}
class TourAdapter extends ArrayAdapter<TourInformation> {
public TourAdapter(List<TourInformation> list) {
super(getActivity(), R.layout.search_history_list_item, list);
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View row = convertView;
if (row == null) {
LayoutInflater inflater = getActivity().getLayoutInflater();
row = inflater.inflate(R.layout.sherpafy_list_tour_item, parent, false);
}
TourInformation ti = getItem(position);
TextView description = (TextView) row.findViewById(R.id.TourDescription);
TextView name = (TextView) row.findViewById(R.id.TourName);
description.setText(ti.getShortDescription());
name.setText(ti.getName());
ImageView iv = (ImageView) row.findViewById(R.id.TourImage);
if(ti.getImageBitmap() != null) {
iv.setBackground(new BitmapDrawable(getResources(), ti.getImageBitmap()));
}
return row;
}
}
}

View file

@ -204,6 +204,11 @@ public class TourInformation {
return img; return img;
} }
@Override
public String toString() {
return name;
}
} }
//Returns full string from which contains XML tags from XMLParser //Returns full string from which contains XML tags from XMLParser
@ -237,4 +242,9 @@ public class TourInformation {
return content; return content;
} }
@Override
public String toString() {
return name;
}
} }

View file

@ -21,24 +21,37 @@ 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.content.res.Configuration;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Point; import android.graphics.Point;
import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v4.widget.DrawerLayout.DrawerListener;
import android.text.Html; import android.text.Html;
import android.text.Html.ImageGetter; import android.text.Html.ImageGetter;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.Gravity; import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button; import android.widget.Button;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams; import android.widget.LinearLayout.LayoutParams;
import android.widget.ListView;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.RadioButton; import android.widget.RadioButton;
import android.widget.RadioGroup; import android.widget.RadioGroup;
@ -47,6 +60,7 @@ import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import android.widget.ToggleButton; import android.widget.ToggleButton;
import com.actionbarsherlock.app.SherlockFragment;
import com.actionbarsherlock.app.SherlockFragmentActivity; import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem; import com.actionbarsherlock.view.MenuItem;
@ -56,28 +70,37 @@ import com.actionbarsherlock.view.MenuItem.OnMenuItemClickListener;
*/ */
public class TourViewActivity extends SherlockFragmentActivity { public class TourViewActivity extends SherlockFragmentActivity {
private static final int GO_TO_MAP = 1; private static final int ACTION_GO_TO_MAP = 1;
private static final int SETTINGS_ID = 2; private static final int ACTION_TOUR_ID = 3;
private static final int TOUR_ID = 3; private static final int ACTION_SHARE = 4;
private static final int STATE_LOADING = -1;
private static final int STATE_TOUR_VIEW = 1; private static final int STATE_TOUR_VIEW = 1;
private static final int STATE_LOADING = 0; private static final int STATE_SELECT_TOUR = 2;
private static final int STATE_SELECT_TOUR = -1;
private static int state = STATE_LOADING; private static int state = STATE_LOADING;
public static final int APP_EXIT_CODE = 4; public static final int APP_EXIT_CODE = 4;
public static final String APP_EXIT_KEY = "APP_EXIT_KEY"; public static final String APP_EXIT_KEY = "APP_EXIT_KEY";
private SherpafyCustomization customization;
ImageView img; ImageView img;
TextView description; TextView description;
LinearLayout fullDescriptionView; LinearLayout fullDescriptionView;
RadioGroup stages; RadioGroup stages;
private ToggleButton collapser; private ToggleButton collapser;
Point size;
private Set<TourInformation> currentTourInformations = new HashSet<TourInformation>(); private Set<TourInformation> currentTourInformations = new HashSet<TourInformation>();
private SherpafyCustomization customization;
private Point displaySize;
private ActionBarDrawerToggle mDrawerToggle;
private DrawerLayout mDrawerLayout;
private ListView mDrawerList;
private ArrayAdapter<Object> drawerAdapter;
private SherpafyToursFragment toursFragment;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
if (!(getMyApplication().getAppCustomization() instanceof SherpafyCustomization)) { if (!(getMyApplication().getAppCustomization() instanceof SherpafyCustomization)) {
getMyApplication().setAppCustomization(new SherpafyCustomization()); getMyApplication().setAppCustomization(new SherpafyCustomization());
} }
@ -92,37 +115,115 @@ public class TourViewActivity extends SherlockFragmentActivity {
return; return;
} }
} }
if(getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT ||
getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT) {
getSherlock().setUiOptions(ActivityInfo.UIOPTION_SPLIT_ACTION_BAR_WHEN_NARROW); getSherlock().setUiOptions(ActivityInfo.UIOPTION_SPLIT_ACTION_BAR_WHEN_NARROW);
} getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(false); getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setTitle(R.string.sherpafy_app_name); getSupportActionBar().setTitle(R.string.sherpafy_app_name);
setContentView(R.layout.sherpafy_loading); setContentView(R.layout.sherpafy_browse_tour);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
size = new Point(); // The drawer title must be set in order to announce state changes when
getWindowManager().getDefaultDisplay().getSize(size); // accessibility is turned on. This is typically a simple description,
if (state == STATE_LOADING) { // e.g. "Navigation".
getMyApplication().checkApplicationIsBeingInitialized(this, (TextView) findViewById(R.id.ProgressMessage), mDrawerLayout.setDrawerTitle(GravityCompat.START, getString(R.string.sherpafy_app_name));
(ProgressBar) findViewById(R.id.ProgressBar), new Runnable() {
// Set the adapter for the list view
drawerAdapter = new ArrayAdapter<Object>(this, android.R.layout.simple_list_item_1){
@Override @Override
public void run() { public View getView(int position, View convertView, ViewGroup parent) {
if(customization.getSelectedTour() != null) { Object it = getItem(position);
startTourView(); if(convertView == null){
} else { convertView = getLayoutInflater().inflate(android.R.layout.simple_list_item_1, null);
startSettings();
} }
if(position == 0) {
((TextView) convertView).setText(R.string.sherpafy_tours);
} else {
((TextView) convertView).setText(it.toString());
}
return convertView;
}
};
mDrawerList.setAdapter(drawerAdapter);
// Set the list's click listener
mDrawerList.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
selectMenu(position, drawerAdapter.getItem(position));
} }
}); });
} else if(state == STATE_SELECT_TOUR ){
state = STATE_LOADING; displaySize = new Point();
startSettings(); getWindowManager().getDefaultDisplay().getSize(displaySize);
} else if(state == STATE_TOUR_VIEW){ FragmentManager fragmentManager = getSupportFragmentManager();
state = STATE_LOADING; fragmentManager.beginTransaction().replace(R.id.content_frame, new SherpafyLoadingFragment(getMyApplication()))
startTourView(); .commit();
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_navigation_drawer_light,
R.string.default_buttons_other_actions, R.string.close) {
@Override
public void onDrawerOpened(View view) {
super.onDrawerOpened(view);
invalidateOptionsMenu();
} }
@Override
public void onDrawerClosed(View view) {
super.onDrawerOpened(view);
invalidateOptionsMenu();
}
};
}
protected void selectMenu(int position, Object item) {
FragmentManager fragmentManager = getSupportFragmentManager();
if (position == 0) {
if (toursFragment == null) {
toursFragment = new SherpafyToursFragment(getMyApplication());
}
fragmentManager.beginTransaction().replace(R.id.content_frame, toursFragment).commit();
state = STATE_SELECT_TOUR;
}
updateActionBarTitle();
}
public void updateActionBarTitle() {
if(state == STATE_LOADING) {
getSupportActionBar().setTitle(R.string.app_name);
} else if(state == STATE_SELECT_TOUR) {
getSupportActionBar().setTitle(R.string.sherpafy_tours);
} else if(state == STATE_TOUR_VIEW) {
}
invalidateOptionsMenu();
}
public void loadingFinished() {
drawerAdapter.clear();
drawerAdapter.add(getString(R.string.sherpafy_tours));
if(customization.getSelectedTour() != null) {
drawerAdapter.add(customization.getSelectedTour());
if(customization.getSelectedStage() != null) {
drawerAdapter.add(customization.getSelectedStage());
}
}
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
mDrawerToggle.syncState();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mDrawerToggle.onConfigurationChanged(newConfig);
} }
private ImageGetter getImageGetter(final View v) { private ImageGetter getImageGetter(final View v) {
@ -134,10 +235,10 @@ public class TourViewActivity extends SherlockFragmentActivity {
Drawable bmp = new BitmapDrawable(getResources(), file); Drawable bmp = new BitmapDrawable(getResources(), file);
// if image is thicker than screen - it may cause some problems, so we need to scale it // if image is thicker than screen - it may cause some problems, so we need to scale it
int imagewidth = bmp.getIntrinsicWidth(); int imagewidth = bmp.getIntrinsicWidth();
if (size.x - 1 > imagewidth) { if (displaySize.x - 1 > imagewidth) {
bmp.setBounds(0, 0, bmp.getIntrinsicWidth(), bmp.getIntrinsicHeight()); bmp.setBounds(0, 0, bmp.getIntrinsicWidth(), bmp.getIntrinsicHeight());
} else { } else {
double scale = (double) (size.x - 1) / imagewidth; double scale = (double) (displaySize.x - 1) / imagewidth;
bmp.setBounds(0, 0, (int) (scale * bmp.getIntrinsicWidth()), bmp.setBounds(0, 0, (int) (scale * bmp.getIntrinsicWidth()),
(int) (scale * bmp.getIntrinsicHeight())); (int) (scale * bmp.getIntrinsicHeight()));
} }
@ -160,19 +261,19 @@ public class TourViewActivity extends SherlockFragmentActivity {
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
TourInformation selectedTour = customization.getSelectedTour(); // TourInformation selectedTour = customization.getSelectedTour();
if (selectedTour == null || currentTourInformations.contains(selectedTour)) { // if (selectedTour == null || currentTourInformations.contains(selectedTour)) {
for (TourInformation i : customization.getTourInformations()) { // for (TourInformation i : customization.getTourInformations()) {
if (!currentTourInformations.contains(i)) { // if (!currentTourInformations.contains(i)) {
currentTourInformations.add(i); // currentTourInformations.add(i);
selectedTour = i; // selectedTour = i;
} // }
} // }
if(selectedTour != null) { // if (selectedTour != null) {
selectTourAsync(selectedTour); // selectTourAsync(selectedTour);
//startTourView(); // // startTourView();
} // }
} // }
} }
private void setTourInfoContent() { private void setTourInfoContent() {
@ -228,7 +329,6 @@ public class TourViewActivity extends SherlockFragmentActivity {
} }
} }
private void setFullDescriptions(String fulldescription) { private void setFullDescriptions(String fulldescription) {
List<String> list = new ArrayList<String>(); List<String> list = new ArrayList<String>();
if (fulldescription.length() > 0) { if (fulldescription.length() > 0) {
@ -278,13 +378,6 @@ public class TourViewActivity extends SherlockFragmentActivity {
collapser.setTextOn(" " + t); collapser.setTextOn(" " + t);
} }
private void startSettings() {
if(state != STATE_SELECT_TOUR) {
setTourSelectionContentView();
state = STATE_SELECT_TOUR;
}
invalidateOptionsMenu();
}
private void startTourView() { private void startTourView() {
if (state != STATE_TOUR_VIEW) { if (state != STATE_TOUR_VIEW) {
@ -297,19 +390,17 @@ public class TourViewActivity extends SherlockFragmentActivity {
} }
@Override @Override
public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) { public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) {
if (state == STATE_TOUR_VIEW) { if (state == STATE_TOUR_VIEW) {
createMenuItem(menu, GO_TO_MAP, R.string.start_tour, 0, 0,/* R.drawable.ic_action_marker_light, */ // 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); // MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
createMenuItem(menu, SETTINGS_ID, R.string.settings, R.drawable.ic_action_settings_light, // createMenuItem(menu, ACTION_SETTINGS_ID, R.string.settings, R.drawable.ic_action_settings_light,
R.drawable.ic_action_settings_dark, MenuItem.SHOW_AS_ACTION_IF_ROOM // R.drawable.ic_action_settings_dark, MenuItem.SHOW_AS_ACTION_IF_ROOM
| MenuItem.SHOW_AS_ACTION_WITH_TEXT); // | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
} else if (state == STATE_SELECT_TOUR) { } else if (state == STATE_SELECT_TOUR) {
if (customization.isTourSelected()) { if (customization.isTourSelected()) {
createMenuItem(menu, TOUR_ID, R.string.default_buttons_ok, R.drawable.ic_action_ok_light, createMenuItem(menu, ACTION_TOUR_ID, R.string.default_buttons_ok, R.drawable.ic_action_ok_light,
R.drawable.ic_action_ok_dark, MenuItem.SHOW_AS_ACTION_IF_ROOM R.drawable.ic_action_ok_dark, MenuItem.SHOW_AS_ACTION_IF_ROOM
| MenuItem.SHOW_AS_ACTION_WITH_TEXT); | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
} }
@ -333,7 +424,6 @@ public class TourViewActivity extends SherlockFragmentActivity {
return menuItem; return menuItem;
} }
private void updateTourView() { private void updateTourView() {
TourInformation curTour = customization.getSelectedTour(); TourInformation curTour = customization.getSelectedTour();
List<StageInformation> stagesInfo = curTour.getStageInformation(); List<StageInformation> stagesInfo = curTour.getStageInformation();
@ -416,169 +506,28 @@ public class TourViewActivity extends SherlockFragmentActivity {
return (OsmandApplication) getApplication(); return (OsmandApplication) getApplication();
} }
@Override
public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) { public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) {
if (item.getItemId() == GO_TO_MAP) { if (item.getItemId() == android.R.id.home) {
if (mDrawerLayout.isDrawerOpen(mDrawerList)) {
mDrawerLayout.closeDrawer(mDrawerList);
} else {
mDrawerLayout.openDrawer(mDrawerList);
}
return true;
} else if (item.getItemId() == ACTION_GO_TO_MAP) {
goToMap(); goToMap();
return true; return true;
} else if (item.getItemId() == SETTINGS_ID) { } else if (item.getItemId() == ACTION_TOUR_ID) {
startSettings();
return true;
} else if (item.getItemId() == TOUR_ID) {
startTourView(); startTourView();
return true; return true;
} else { } else {
return super.onOptionsItemSelected(item); return true;
// return super.onOptionsItemSelected(item);
} }
} }
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() {
@Override
public void onClick(View v) {
selectTourDialog();
}
});
} else {
selectTour.setText(R.string.download_tour);
selectTour.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
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);
editText.setInputType(EditorInfo.TYPE_TEXT_FLAG_CAP_CHARACTERS);
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);
startActivity(download);
}
private void selectTourDialog() {
// creating alert dialog with multiple tours to select
AlertDialog.Builder adb = new AlertDialog.Builder(getActivity());
final List<TourInformation> tours = customization.getTourInformations();
final String[] tourNames = new String[tours.size() + 1];
// creating list of tour names to select
for (int i = 0; i < tourNames.length - 1; i++) {
tourNames[i] = tours.get(i).getName();
}
tourNames[tourNames.length - 1] = getString(R.string.download_more);
int ch = -1;
if (customization.getSelectedTour() != null) {
for (int i = 0; i < tourNames.length - 1; i++) {
if (customization.getSelectedTour().equals(tours.get(i))) {
ch = i;
break;
}
}
}
adb.setSingleChoiceItems(tourNames, ch, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
if (i == tourNames.length - 1) {
startDownloadActivity();
} else {
selectTourAsync(tours.get(i));
}
}
});
adb.setTitle(R.string.select_tour);
adb.setNegativeButton(R.string.default_buttons_cancel, null);
adb.show();
}
private Activity getActivity() { private Activity getActivity() {
return this; return this;
} }
private void selectTourAsync(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) {
//if tour is already selected - do nothing
if (customization.getSelectedTour()!= null){
if (customization.getSelectedTour().equals(params[0])){
return null;
}
}
customization.selectTour(params[0], IProgress.EMPTY_PROGRESS);
return null;
}
protected void onPostExecute(Void result) {
//to avoid illegal argument exception when rotating phone during loading
try {
dlg.dismiss();
} catch (Exception ex){
ex.printStackTrace();
}
startTourView();
};
}.execute(tour);
}
} }

View file

@ -2,7 +2,7 @@
<project name="SherlockBar" default="help"> <project name="SherlockBar" default="help">
<loadproperties srcFile="project.properties" /> <loadproperties srcFile="project.properties" />
<property file="local.properties" />
<!-- quick check on sdk.dir --> <!-- quick check on sdk.dir -->
<fail <fail