diff --git a/OsmAnd/assets/style.css b/OsmAnd/assets/style.css new file mode 100644 index 0000000000..6b930f6502 --- /dev/null +++ b/OsmAnd/assets/style.css @@ -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} + diff --git a/OsmAnd/build.xml b/OsmAnd/build.xml index c7365a4ab1..6a4e204870 100644 --- a/OsmAnd/build.xml +++ b/OsmAnd/build.xml @@ -40,6 +40,11 @@ + + + + + @@ -58,7 +63,8 @@ - + + @@ -135,6 +141,14 @@ + + + + + + + + diff --git a/OsmAnd/libs/android-support-v4.jar b/OsmAnd/libs/android-support-v4.jar new file mode 100644 index 0000000000..187bdf48b1 Binary files /dev/null and b/OsmAnd/libs/android-support-v4.jar differ diff --git a/OsmAnd/project.properties b/OsmAnd/project.properties index 155a517787..da75a72a89 100644 --- a/OsmAnd/project.properties +++ b/OsmAnd/project.properties @@ -12,3 +12,4 @@ split.density=false # Project target. target=android-19 android.library.reference.1=../SherlockBar +dex.force.jumbo=true diff --git a/OsmAnd/res/drawable-hdpi/drawer_shadow.9.png b/OsmAnd/res/drawable-hdpi/drawer_shadow.9.png new file mode 100644 index 0000000000..224cc4ff43 Binary files /dev/null and b/OsmAnd/res/drawable-hdpi/drawer_shadow.9.png differ diff --git a/OsmAnd/res/drawable-hdpi/ic_drawer_am.png b/OsmAnd/res/drawable-hdpi/ic_drawer_am.png new file mode 100644 index 0000000000..ff7b1def9a Binary files /dev/null and b/OsmAnd/res/drawable-hdpi/ic_drawer_am.png differ diff --git a/OsmAnd/res/drawable-hdpi/ic_navigation_drawer_dark.png b/OsmAnd/res/drawable-hdpi/ic_navigation_drawer_dark.png new file mode 100644 index 0000000000..5c9db3584a Binary files /dev/null and b/OsmAnd/res/drawable-hdpi/ic_navigation_drawer_dark.png differ diff --git a/OsmAnd/res/drawable-hdpi/ic_navigation_drawer_light.png b/OsmAnd/res/drawable-hdpi/ic_navigation_drawer_light.png new file mode 100644 index 0000000000..68b53bbf39 Binary files /dev/null and b/OsmAnd/res/drawable-hdpi/ic_navigation_drawer_light.png differ diff --git a/OsmAnd/res/drawable-hdpi/icon_sherpafy.png b/OsmAnd/res/drawable-hdpi/icon_sherpafy.png index 702303d671..5549aa0539 100644 Binary files a/OsmAnd/res/drawable-hdpi/icon_sherpafy.png and b/OsmAnd/res/drawable-hdpi/icon_sherpafy.png differ diff --git a/OsmAnd/res/drawable-mdpi/drawer_shadow.9.png b/OsmAnd/res/drawable-mdpi/drawer_shadow.9.png new file mode 100644 index 0000000000..3797f99c0e Binary files /dev/null and b/OsmAnd/res/drawable-mdpi/drawer_shadow.9.png differ diff --git a/OsmAnd/res/drawable-mdpi/ic_drawer_am.png b/OsmAnd/res/drawable-mdpi/ic_drawer_am.png new file mode 100644 index 0000000000..fb681ba263 Binary files /dev/null and b/OsmAnd/res/drawable-mdpi/ic_drawer_am.png differ diff --git a/OsmAnd/res/drawable-mdpi/ic_navigation_drawer_dark.png b/OsmAnd/res/drawable-mdpi/ic_navigation_drawer_dark.png new file mode 100644 index 0000000000..b7d28b5c71 Binary files /dev/null and b/OsmAnd/res/drawable-mdpi/ic_navigation_drawer_dark.png differ diff --git a/OsmAnd/res/drawable-mdpi/ic_navigation_drawer_light.png b/OsmAnd/res/drawable-mdpi/ic_navigation_drawer_light.png new file mode 100644 index 0000000000..836dde34b2 Binary files /dev/null and b/OsmAnd/res/drawable-mdpi/ic_navigation_drawer_light.png differ diff --git a/OsmAnd/res/drawable-mdpi/icon_sherpafy.png b/OsmAnd/res/drawable-mdpi/icon_sherpafy.png index ac21e6a7b3..e68e47d8a5 100644 Binary files a/OsmAnd/res/drawable-mdpi/icon_sherpafy.png and b/OsmAnd/res/drawable-mdpi/icon_sherpafy.png differ diff --git a/OsmAnd/res/drawable-xhdpi/drawer_shadow.9.png b/OsmAnd/res/drawable-xhdpi/drawer_shadow.9.png new file mode 100644 index 0000000000..fa3d853e90 Binary files /dev/null and b/OsmAnd/res/drawable-xhdpi/drawer_shadow.9.png differ diff --git a/OsmAnd/res/drawable-xhdpi/ic_drawer_am.png b/OsmAnd/res/drawable-xhdpi/ic_drawer_am.png new file mode 100644 index 0000000000..b9bc3d70f1 Binary files /dev/null and b/OsmAnd/res/drawable-xhdpi/ic_drawer_am.png differ diff --git a/OsmAnd/res/drawable-xhdpi/ic_navigation_drawer_dark.png b/OsmAnd/res/drawable-xhdpi/ic_navigation_drawer_dark.png new file mode 100644 index 0000000000..0c6062e1fd Binary files /dev/null and b/OsmAnd/res/drawable-xhdpi/ic_navigation_drawer_dark.png differ diff --git a/OsmAnd/res/drawable-xhdpi/ic_navigation_drawer_light.png b/OsmAnd/res/drawable-xhdpi/ic_navigation_drawer_light.png new file mode 100644 index 0000000000..204946d428 Binary files /dev/null and b/OsmAnd/res/drawable-xhdpi/ic_navigation_drawer_light.png differ diff --git a/OsmAnd/res/drawable-xhdpi/icon_sherpafy.png b/OsmAnd/res/drawable-xhdpi/icon_sherpafy.png index 1c4beb81f1..a7bb49b573 100644 Binary files a/OsmAnd/res/drawable-xhdpi/icon_sherpafy.png and b/OsmAnd/res/drawable-xhdpi/icon_sherpafy.png differ diff --git a/OsmAnd/res/drawable-xxhdpi/ic_navigation_drawer_dark.png b/OsmAnd/res/drawable-xxhdpi/ic_navigation_drawer_dark.png new file mode 100644 index 0000000000..42e0f81ed7 Binary files /dev/null and b/OsmAnd/res/drawable-xxhdpi/ic_navigation_drawer_dark.png differ diff --git a/OsmAnd/res/drawable-xxhdpi/ic_navigation_drawer_light.png b/OsmAnd/res/drawable-xxhdpi/ic_navigation_drawer_light.png new file mode 100644 index 0000000000..3d0df3b821 Binary files /dev/null and b/OsmAnd/res/drawable-xxhdpi/ic_navigation_drawer_light.png differ diff --git a/OsmAnd/res/drawable-xxhdpi/icon_sherpafy.png b/OsmAnd/res/drawable-xxhdpi/icon_sherpafy.png index d339f1d842..5645d91a2c 100644 Binary files a/OsmAnd/res/drawable-xxhdpi/icon_sherpafy.png and b/OsmAnd/res/drawable-xxhdpi/icon_sherpafy.png differ diff --git a/OsmAnd/res/drawable-xxxhdpi/icon_sherpafy.png b/OsmAnd/res/drawable-xxxhdpi/icon_sherpafy.png index 6a48bbf5bf..79b71f4382 100644 Binary files a/OsmAnd/res/drawable-xxxhdpi/icon_sherpafy.png and b/OsmAnd/res/drawable-xxxhdpi/icon_sherpafy.png differ diff --git a/OsmAnd/res/layout/sherpafy_browse_tour.xml b/OsmAnd/res/layout/sherpafy_browse_tour.xml new file mode 100644 index 0000000000..3105af7b84 --- /dev/null +++ b/OsmAnd/res/layout/sherpafy_browse_tour.xml @@ -0,0 +1,20 @@ + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/sherpafy_list_tour_item.xml b/OsmAnd/res/layout/sherpafy_list_tour_item.xml new file mode 100644 index 0000000000..455227c3ec --- /dev/null +++ b/OsmAnd/res/layout/sherpafy_list_tour_item.xml @@ -0,0 +1,39 @@ + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/values-be/strings.xml b/OsmAnd/res/values-be/strings.xml index 7041ee1556..65c90e1e02 100644 --- a/OsmAnd/res/values-be/strings.xml +++ b/OsmAnd/res/values-be/strings.xml @@ -1,4 +1,4 @@ - + Без аўтаматычнага масштабіраваньня Зачыніць Для сярэдняга масштаба diff --git a/OsmAnd/res/values-ca/strings.xml b/OsmAnd/res/values-ca/strings.xml index 91e026bca4..2a42577e6c 100644 --- a/OsmAnd/res/values-ca/strings.xml +++ b/OsmAnd/res/values-ca/strings.xml @@ -1,4 +1,4 @@ - + Mostra els missatges d\'avís… Rutes amb fluorescència Mostra el regle diff --git a/OsmAnd/res/values-da/strings.xml b/OsmAnd/res/values-da/strings.xml index ddde6950b0..1c6bfd0886 100644 --- a/OsmAnd/res/values-da/strings.xml +++ b/OsmAnd/res/values-da/strings.xml @@ -1,4 +1,4 @@ - + Overvej at købe Højdekurve udvidelsen (\'Contour lines\') på Google Play for at støtte den videre udvikling. Optag video Optag audio diff --git a/OsmAnd/res/values-el/strings.xml b/OsmAnd/res/values-el/strings.xml index 98631a5d50..8a297f0401 100644 --- a/OsmAnd/res/values-el/strings.xml +++ b/OsmAnd/res/values-el/strings.xml @@ -1,4 +1,4 @@ - + Προσθήκη Ετικέτας Λειτουργία για προχωρημένους… Στάθμευση diff --git a/OsmAnd/res/values-es/strings.xml b/OsmAnd/res/values-es/strings.xml index d8db68a4cf..47af0973db 100644 --- a/OsmAnd/res/values-es/strings.xml +++ b/OsmAnd/res/values-es/strings.xml @@ -1,4 +1,4 @@ - + Configura pantalla diff --git a/OsmAnd/res/values-fa/strings.xml b/OsmAnd/res/values-fa/strings.xml index af58394e98..062c1d86c0 100644 --- a/OsmAnd/res/values-fa/strings.xml +++ b/OsmAnd/res/values-fa/strings.xml @@ -1,4 +1,4 @@ - + پشتیبان‌گیری از تغییرات OsmAnd ناموفق بود زمان دقت diff --git a/OsmAnd/res/values-fr/strings.xml b/OsmAnd/res/values-fr/strings.xml index b7152b25b2..ff3466a898 100644 --- a/OsmAnd/res/values-fr/strings.xml +++ b/OsmAnd/res/values-fr/strings.xml @@ -1,4 +1,4 @@ - + Modifications hors-ligne Toujours utiliser l\'édition hors-ligne "Changements en 0.7.1 : diff --git a/OsmAnd/res/values-hu/strings.xml b/OsmAnd/res/values-hu/strings.xml index aa251e8eb4..5eb8186c0f 100644 --- a/OsmAnd/res/values-hu/strings.xml +++ b/OsmAnd/res/values-hu/strings.xml @@ -1,4 +1,4 @@ - + "A 0.7.2 kiadás változásai: \n\t- Natív renderelő minden eszközre \n\t- Offline POI szerkesztés diff --git a/OsmAnd/res/values-it/strings.xml b/OsmAnd/res/values-it/strings.xml index 1248f01a28..8ef1e988e7 100644 --- a/OsmAnd/res/values-it/strings.xml +++ b/OsmAnd/res/values-it/strings.xml @@ -1,4 +1,4 @@ - + Sovrapposizioni fluorescenti Usa colori fluorescenti per visualizzare tracce e percorsi Modifiche offline diff --git a/OsmAnd/res/values-ko/strings.xml b/OsmAnd/res/values-ko/strings.xml index af53695042..18d172fb9c 100644 --- a/OsmAnd/res/values-ko/strings.xml +++ b/OsmAnd/res/values-ko/strings.xml @@ -1,4 +1,4 @@ - + 벡터 맵이 더욱 빠르게 표시됩니다. 하지만, 어떤 기기에서는 잘 작동하지 않을 수 있습니다. 현재 선택된 음성 명령을 재생합니다 diff --git a/OsmAnd/res/values-lt/strings.xml b/OsmAnd/res/values-lt/strings.xml index 04d32ce288..56c396573c 100644 --- a/OsmAnd/res/values-lt/strings.xml +++ b/OsmAnd/res/values-lt/strings.xml @@ -1,4 +1,4 @@ - + Pradžios taškas yra per toli nuo artimiausio kelio. Bendrinta vieta Dėmesio diff --git a/OsmAnd/res/values-nl/strings.xml b/OsmAnd/res/values-nl/strings.xml index 9ceec947a6..22278fc03b 100644 --- a/OsmAnd/res/values-nl/strings.xml +++ b/OsmAnd/res/values-nl/strings.xml @@ -1,4 +1,4 @@ - + Configureer scherm diff --git a/OsmAnd/res/values-ru/strings.xml b/OsmAnd/res/values-ru/strings.xml index 82c5d93f69..56ffc7915b 100644 --- a/OsmAnd/res/values-ru/strings.xml +++ b/OsmAnd/res/values-ru/strings.xml @@ -1,4 +1,4 @@ - + Этот плагин позволяет загружать линии высот (Загрузка данных -> Меню -> "Другие карты") для использования оффлайн. Рассмотрите пожалуйста покупку плагина \"Линии высот\" на Market, чтобы поддержать последующую разработку. Линии высот diff --git a/OsmAnd/res/values-sk/strings.xml b/OsmAnd/res/values-sk/strings.xml index b91937a807..f67dc9c585 100644 --- a/OsmAnd/res/values-sk/strings.xml +++ b/OsmAnd/res/values-sk/strings.xml @@ -1,4 +1,4 @@ - + Zobraziť Fotografia %1$s zachytená dňa %2$s Zachytiť fotografiu diff --git a/OsmAnd/res/values-sl/strings.xml b/OsmAnd/res/values-sl/strings.xml index 79236835d7..88470199f1 100644 --- a/OsmAnd/res/values-sl/strings.xml +++ b/OsmAnd/res/values-sl/strings.xml @@ -1,4 +1,4 @@ - + Iskanje Iskanje Nastavitve diff --git a/OsmAnd/res/values-zh-rTW/strings.xml b/OsmAnd/res/values-zh-rTW/strings.xml index d5e0694445..ee665b99a1 100644 --- a/OsmAnd/res/values-zh-rTW/strings.xml +++ b/OsmAnd/res/values-zh-rTW/strings.xml @@ -1,4 +1,4 @@ - + 選擇道路的色彩調配: 道路的色彩調配 顯示目的地方向 diff --git a/OsmAnd/res/values/colors.xml b/OsmAnd/res/values/colors.xml index 1a7ce30d08..ba606d9c8a 100644 --- a/OsmAnd/res/values/colors.xml +++ b/OsmAnd/res/values/colors.xml @@ -64,4 +64,5 @@ #C8FFFF00 #dd6CB336 + #33aaaaaa \ No newline at end of file diff --git a/OsmAnd/res/values/no_translate.xml b/OsmAnd/res/values/no_translate.xml index 25e804ab19..e1a50148a2 100644 --- a/OsmAnd/res/values/no_translate.xml +++ b/OsmAnd/res/values/no_translate.xml @@ -1,6 +1,6 @@ - OsmAnd~ + Sherpafy 1.8 alpha UA-28342846-2 diff --git a/OsmAnd/res/values/sherpafy.xml b/OsmAnd/res/values/sherpafy.xml index 9553a0dcb9..339c8268f8 100644 --- a/OsmAnd/res/values/sherpafy.xml +++ b/OsmAnd/res/values/sherpafy.xml @@ -1,5 +1,6 @@ + Sherpafy Tours Access code is not valid Enter access code Overview diff --git a/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyLoadingFragment.java b/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyLoadingFragment.java new file mode 100644 index 0000000000..e8f1255fcf --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyLoadingFragment.java @@ -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; + } + +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyToursFragment.java b/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyToursFragment.java new file mode 100644 index 0000000000..4d002d0360 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyToursFragment.java @@ -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() { + 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 { + + public TourAdapter(List 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; + } + } + +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/sherpafy/TourInformation.java b/OsmAnd/src/net/osmand/plus/sherpafy/TourInformation.java index e5016385b5..b88d4f829c 100644 --- a/OsmAnd/src/net/osmand/plus/sherpafy/TourInformation.java +++ b/OsmAnd/src/net/osmand/plus/sherpafy/TourInformation.java @@ -204,6 +204,11 @@ public class TourInformation { return img; } + @Override + public String toString() { + return name; + } + } //Returns full string from which contains XML tags from XMLParser @@ -236,5 +241,10 @@ public class TourInformation { String content = sb.toString(); return content; } + + @Override + public String toString() { + return name; + } } diff --git a/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java b/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java index f5482e49c5..916ed5e503 100644 --- a/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java +++ b/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java @@ -21,24 +21,37 @@ import android.app.ProgressDialog; import android.content.DialogInterface; import android.content.Intent; import android.content.pm.ActivityInfo; +import android.content.res.Configuration; import android.graphics.Bitmap; import android.graphics.Point; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.os.AsyncTask; 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.ImageGetter; import android.util.TypedValue; import android.view.Gravity; +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.Button; import android.widget.CompoundButton; import android.widget.EditText; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams; +import android.widget.ListView; import android.widget.ProgressBar; import android.widget.RadioButton; import android.widget.RadioGroup; @@ -47,6 +60,7 @@ import android.widget.TextView; import android.widget.Toast; import android.widget.ToggleButton; +import com.actionbarsherlock.app.SherlockFragment; import com.actionbarsherlock.app.SherlockFragmentActivity; import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.MenuItem; @@ -56,73 +70,160 @@ import com.actionbarsherlock.view.MenuItem.OnMenuItemClickListener; */ public class TourViewActivity extends SherlockFragmentActivity { - private static final int GO_TO_MAP = 1; - private static final int SETTINGS_ID = 2; - private static final int TOUR_ID = 3; - private static final int STATE_TOUR_VIEW = 1; - private static final int STATE_LOADING = 0; - private static final int STATE_SELECT_TOUR = -1; + private static final int ACTION_GO_TO_MAP = 1; + private static final int ACTION_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_SELECT_TOUR = 2; private static int state = STATE_LOADING; + + public static final int APP_EXIT_CODE = 4; public static final String APP_EXIT_KEY = "APP_EXIT_KEY"; + - private SherpafyCustomization customization; ImageView img; TextView description; LinearLayout fullDescriptionView; RadioGroup stages; private ToggleButton collapser; - Point size; - private Set currentTourInformations = new HashSet(); + private Set currentTourInformations = new HashSet(); + + private SherpafyCustomization customization; + private Point displaySize; + private ActionBarDrawerToggle mDrawerToggle; + private DrawerLayout mDrawerLayout; + private ListView mDrawerList; + private ArrayAdapter drawerAdapter; + private SherpafyToursFragment toursFragment; @Override protected void onCreate(Bundle savedInstanceState) { - if (!(getMyApplication().getAppCustomization() instanceof SherpafyCustomization)) { - getMyApplication().setAppCustomization(new SherpafyCustomization()); - } - customization = (SherpafyCustomization) getMyApplication().getAppCustomization(); - setTheme(R.style.OsmandLightTheme); - ((OsmandApplication) getApplication()).setLanguage(this); - super.onCreate(savedInstanceState); - if(getIntent() != null){ + getMyApplication().setAppCustomization(new SherpafyCustomization()); + } + customization = (SherpafyCustomization) getMyApplication().getAppCustomization(); + setTheme(R.style.OsmandLightTheme); + ((OsmandApplication) getApplication()).setLanguage(this); + super.onCreate(savedInstanceState); + if (getIntent() != null) { Intent intent = getIntent(); - if(intent.getExtras() != null && intent.getExtras().containsKey(APP_EXIT_KEY)){ + if (intent.getExtras() != null && intent.getExtras().containsKey(APP_EXIT_KEY)) { getMyApplication().closeApplication(this); return; } } - if(getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT || - getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT) { - getSherlock().setUiOptions(ActivityInfo.UIOPTION_SPLIT_ACTION_BAR_WHEN_NARROW); - } - getSupportActionBar().setDisplayHomeAsUpEnabled(false); - getSupportActionBar().setTitle(R.string.sherpafy_app_name); + getSherlock().setUiOptions(ActivityInfo.UIOPTION_SPLIT_ACTION_BAR_WHEN_NARROW); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setHomeButtonEnabled(true); + 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(); - getWindowManager().getDefaultDisplay().getSize(size); - if (state == STATE_LOADING) { - getMyApplication().checkApplicationIsBeingInitialized(this, (TextView) findViewById(R.id.ProgressMessage), - (ProgressBar) findViewById(R.id.ProgressBar), new Runnable() { - @Override - public void run() { - if(customization.getSelectedTour() != null) { - startTourView(); - } else { - startSettings(); - } - } - }); - } else if(state == STATE_SELECT_TOUR ){ - state = STATE_LOADING; - startSettings(); - } else if(state == STATE_TOUR_VIEW){ - state = STATE_LOADING; - startTourView(); + // The drawer title must be set in order to announce state changes when + // accessibility is turned on. This is typically a simple description, + // e.g. "Navigation". + mDrawerLayout.setDrawerTitle(GravityCompat.START, getString(R.string.sherpafy_app_name)); + + // Set the adapter for the list view + drawerAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1){ + @Override + public View getView(int position, View convertView, ViewGroup parent) { + Object it = getItem(position); + if(convertView == null){ + convertView = getLayoutInflater().inflate(android.R.layout.simple_list_item_1, null); + } + 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)); + } + }); + + displaySize = new Point(); + getWindowManager().getDefaultDisplay().getSize(displaySize); + FragmentManager fragmentManager = getSupportFragmentManager(); + fragmentManager.beginTransaction().replace(R.id.content_frame, new SherpafyLoadingFragment(getMyApplication())) + .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) { @@ -134,10 +235,10 @@ public class TourViewActivity extends SherlockFragmentActivity { 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(); - if (size.x - 1 > imagewidth) { + if (displaySize.x - 1 > imagewidth) { bmp.setBounds(0, 0, bmp.getIntrinsicWidth(), bmp.getIntrinsicHeight()); } else { - double scale = (double) (size.x - 1) / imagewidth; + double scale = (double) (displaySize.x - 1) / imagewidth; bmp.setBounds(0, 0, (int) (scale * bmp.getIntrinsicWidth()), (int) (scale * bmp.getIntrinsicHeight())); } @@ -147,11 +248,11 @@ public class TourViewActivity extends SherlockFragmentActivity { }; } - + @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); - if(resultCode == APP_EXIT_CODE){ + if (resultCode == APP_EXIT_CODE) { getMyApplication().closeApplication(this); } } @@ -160,21 +261,21 @@ public class TourViewActivity extends SherlockFragmentActivity { protected void onResume() { super.onResume(); - TourInformation selectedTour = customization.getSelectedTour(); - if (selectedTour == null || currentTourInformations.contains(selectedTour)) { - for (TourInformation i : customization.getTourInformations()) { - if (!currentTourInformations.contains(i)) { - currentTourInformations.add(i); - selectedTour = i; - } - } - if(selectedTour != null) { - selectTourAsync(selectedTour); - //startTourView(); - } - } + // TourInformation selectedTour = customization.getSelectedTour(); + // if (selectedTour == null || currentTourInformations.contains(selectedTour)) { + // for (TourInformation i : customization.getTourInformations()) { + // if (!currentTourInformations.contains(i)) { + // currentTourInformations.add(i); + // selectedTour = i; + // } + // } + // if (selectedTour != null) { + // selectTourAsync(selectedTour); + // // startTourView(); + // } + // } } - + private void setTourInfoContent() { setContentView(R.layout.sherpafy_tour_info); @@ -195,7 +296,7 @@ public class TourViewActivity extends SherlockFragmentActivity { }); collapser.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - + @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { @@ -221,14 +322,13 @@ public class TourViewActivity extends SherlockFragmentActivity { StageInformation st = customization.getSelectedStage(); description.setText(Html.fromHtml(st.getShortDescription(), getImageGetter(description), null)); setFullDescriptions(st.getFullDescription()); - + // ((TextView)findViewById(R.id.tour_name)).setText(st.getName()); setCollapserText(st.getName()); prepareBitmap(st.getImageBitmap()); } } - private void setFullDescriptions(String fulldescription) { List list = new ArrayList(); if (fulldescription.length() > 0) { @@ -250,15 +350,15 @@ public class TourViewActivity extends SherlockFragmentActivity { tv.setText(Html.fromHtml(list.get(i), getImageGetter(tv), null)); fullDescriptionView.addView(tv); } - + } private void addOnClickListener(final TextView tv) { tv.setOnClickListener(new View.OnClickListener() { - + @Override public void onClick(View v) { - if(v.getTag() instanceof Bitmap) { + if (v.getTag() instanceof Bitmap) { final AccessibleAlertBuilder dlg = new AccessibleAlertBuilder(getActivity()); dlg.setPositiveButton(R.string.default_buttons_ok, null); ScrollView sv = new ScrollView(getActivity()); @@ -278,16 +378,9 @@ public class TourViewActivity extends SherlockFragmentActivity { collapser.setTextOn(" " + t); } - private void startSettings() { - if(state != STATE_SELECT_TOUR) { - setTourSelectionContentView(); - state = STATE_SELECT_TOUR; - } - invalidateOptionsMenu(); - } - + private void startTourView() { - if(state != STATE_TOUR_VIEW) { + if (state != STATE_TOUR_VIEW) { setTourInfoContent(); state = STATE_TOUR_VIEW; } @@ -295,30 +388,28 @@ public class TourViewActivity extends SherlockFragmentActivity { updateTourView(); invalidateOptionsMenu(); } - - @Override public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) { if (state == STATE_TOUR_VIEW) { - createMenuItem(menu, 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); - createMenuItem(menu, SETTINGS_ID, R.string.settings, R.drawable.ic_action_settings_light, - R.drawable.ic_action_settings_dark, MenuItem.SHOW_AS_ACTION_IF_ROOM - | MenuItem.SHOW_AS_ACTION_WITH_TEXT); - } else if(state == STATE_SELECT_TOUR) { +// 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); +// 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 +// | MenuItem.SHOW_AS_ACTION_WITH_TEXT); + } else if (state == STATE_SELECT_TOUR) { 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 | MenuItem.SHOW_AS_ACTION_WITH_TEXT); } - } + } return super.onCreateOptionsMenu(menu); } - + public MenuItem createMenuItem(Menu m, int id, int titleRes, int iconLight, int iconDark, int menuItemType) { -// int r = getMyApplication().getSettings().isLightActionBar() ? iconLight : iconDark; + // int r = getMyApplication().getSettings().isLightActionBar() ? iconLight : iconDark; int r = iconLight; MenuItem menuItem = m.add(0, id, 0, titleRes); if (r != 0) { @@ -333,7 +424,6 @@ public class TourViewActivity extends SherlockFragmentActivity { return menuItem; } - private void updateTourView() { TourInformation curTour = customization.getSelectedTour(); List stagesInfo = curTour.getStageInformation(); @@ -365,7 +455,7 @@ public class TourViewActivity extends SherlockFragmentActivity { } StageInformation stage = customization.getSelectedStage(); - + int i = 0; if (stage != null) { for (i = 1; i < count; i++) { @@ -379,12 +469,12 @@ public class TourViewActivity extends SherlockFragmentActivity { stages.check(0); } } - + private void goToMap() { if (customization.getSelectedStage() != null) { GPXFile gpx = customization.getSelectedStage().getGpx(); List sgpx = getMyApplication().getSelectedGpxHelper().getSelectedGPXFiles(); - if(gpx == null && sgpx.size() > 0) { + if (gpx == null && sgpx.size() > 0) { getMyApplication().getSelectedGpxHelper().clearAllGpxFileToShow(); } else if (sgpx.size() != 1 || sgpx.get(0).getGpxFile() != gpx) { getMyApplication().getSelectedGpxHelper().clearAllGpxFileToShow(); @@ -416,169 +506,28 @@ public class TourViewActivity extends SherlockFragmentActivity { return (OsmandApplication) getApplication(); } - - @Override 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(); return true; - } else if (item.getItemId() == SETTINGS_ID) { - startSettings(); - return true; - } else if (item.getItemId() == TOUR_ID) { + } else if (item.getItemId() == ACTION_TOUR_ID) { startTourView(); return true; } 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 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() { return this; } - private void selectTourAsync(final TourInformation tour){ - new AsyncTask(){ - 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); - } - } diff --git a/SherlockBar/build.xml b/SherlockBar/build.xml index 14367590f7..1b5845044e 100644 --- a/SherlockBar/build.xml +++ b/SherlockBar/build.xml @@ -2,7 +2,7 @@ - +