Fix tour information

This commit is contained in:
vshcherb 2014-05-01 01:59:09 +02:00
parent 3b59d2112e
commit bf61c9ed75
17 changed files with 759 additions and 45 deletions

View file

@ -127,6 +127,7 @@
<activity android:name="net.osmand.plus.activities.search.SearchStreetByNameActivity"></activity>
<activity android:name="net.osmand.plus.activities.search.SearchStreet2ByNameActivity"></activity>
<activity android:name="net.osmand.plus.activities.search.SearchBuildingByNameActivity"></activity>
<activity android:name="net.osmand.plus.sherpafy.TourCommonActivity"></activity>
<activity android:name="net.osmand.plus.activities.EditPOIFilterActivity"></activity>
<activity android:name="net.osmand.plus.activities.search.GeoIntentActivity">
<intent-filter>

View file

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" xmlns:android="http://schemas.android.com/apk/res/android">
<TextView android:id="@+id/tour_name" android:gravity="center_horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content"
android:textSize="25sp"></TextView>
<ImageView android:id="@+id/tour_image"
android:paddingLeft="8dp" android:paddingRight="8dp"
android:layout_width="wrap_content"
android:paddingTop="4dp" android:layout_height="wrap_content"/>
<TextView android:id="@+id/tour_description" android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textSize="18sp"></TextView>
</LinearLayout>

View file

@ -0,0 +1,18 @@
<?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:paddingTop="5dp"
android:paddingBottom="5dp"
android:orientation="horizontal">
<ImageView android:id="@+id/icon" android:layout_width="37dip"
android:paddingLeft="8dp" android:paddingRight="8dp"
android:paddingTop="2dp" android:layout_height="fill_parent" />
<TextView android:id="@+id/label" android:layout_width="0dp" android:layout_weight="1"
android:layout_height="wrap_content" style="@style/ListText"/>
<ImageView android:id="@+id/check_item"
android:paddingLeft="4dp" android:paddingRight="8dp" android:src="@drawable/ic_action_ok_light"
android:layout_width="37dip"
android:paddingTop="2dp" android:layout_height="fill_parent" />
</LinearLayout>

View file

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<TabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TabWidget
android:id="@android:id/tabs"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
/>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
</LinearLayout>
</TabHost>

View file

@ -1,6 +1,13 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<resources>
<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_stages">Stages</string>
<string name="tab_tours">Tours</string>
<string name="tab_current_tour">Current</string>
<string name="tour">Tour</string>
<string name="download_tours">Tours</string>
<string name="indexing_tour">Indexing selected tour \'%s\'&#8230;</string>
<string name="tour_activity_title">Tour</string>
</resources>

View file

@ -1,10 +1,13 @@
package net.osmand.plus;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import android.app.Activity;
import android.view.Window;
import net.osmand.IProgress;
import net.osmand.plus.activities.DownloadIndexActivity;
import net.osmand.plus.activities.FavouritesActivity;
import net.osmand.plus.activities.LocalIndexesActivity;
@ -86,4 +89,8 @@ public class OsmAndAppCustomization {
public void updatedLoadedFiles(Map<String, String> indexFileNames, Map<String, String> indexActivatedFileNames) {
}
public Collection<? extends String> onIndexingFiles(IProgress progress, Map<String, String> indexFileNames) {
return Collections.emptyList();
}
}

View file

@ -568,7 +568,7 @@ public class OsmandSettings {
}
@SuppressWarnings("unchecked")
public CommonPreference<String> registerBooleanPreference(String id, String defValue) {
public CommonPreference<String> registerStringPreference(String id, String defValue) {
if(registeredPreferences.containsKey(id)) {
return (CommonPreference<String>) registeredPreferences.get(id);
}

View file

@ -501,32 +501,32 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
@Override
public boolean accept(File dir, String filename) {
if (filename.endsWith(ext)) {
String date = dateFormat.format(findFile(new File(dir, filename)).lastModified());
String date = dateFormat.format(findFileInDir(new File(dir, filename)).lastModified());
files.put(filename, date);
return true;
} else {
return false;
}
}
private File findFile(File file) {
if(file.isDirectory()) {
File[] lf = file.listFiles();
if(lf != null) {
for(File f : lf) {
if(f.isFile()) {
return f;
}
}
}
}
return file;
}
});
}
return files;
}
public static File findFileInDir(File file) {
if(file.isDirectory()) {
File[] lf = file.listFiles();
if(lf != null) {
for(File f : lf) {
if(f.isFile()) {
return f;
}
}
}
}
return file;
}
protected void downloadFilesCheckFreeVersion() {
if (Version.isFreeVersion(getMyApplication()) ) {

View file

@ -4,6 +4,7 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
@ -103,7 +104,11 @@ public class FileSettingsAPIImpl implements SettingsAPI {
public boolean saveFile() {
try {
Properties ps = new Properties();
ps.putAll(map);
Iterator<Entry<String, Object>> it = map.entrySet().iterator();
while(it.hasNext()) {
Entry<String, Object> e = it.next();
ps.put(e.getKey(), String.valueOf(e.getValue()));
}
final FileOutputStream fout = new FileOutputStream(file);
ps.store(fout, null);
fout.close();

View file

@ -415,6 +415,7 @@ public class ResourceManager {
warnings.addAll(indexingMaps(progress));
warnings.addAll(indexVoiceFiles(progress));
warnings.addAll(OsmandPlugin.onIndexingFiles(progress));
warnings.addAll(context.getAppCustomization().onIndexingFiles(progress, indexFileNames));
return warnings;
}
@ -456,7 +457,6 @@ public class ResourceManager {
}
}
return warnings;
}
private List<String> checkAssets(IProgress progress) {

View file

@ -2,16 +2,20 @@ package net.osmand.plus.sherpafy;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
import net.osmand.IndexConstants;
import net.osmand.IProgress;
import net.osmand.plus.OsmAndAppCustomization;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.CommonPreference;
import net.osmand.plus.R;
import net.osmand.plus.activities.DownloadIndexActivity;
import net.osmand.plus.activities.MainMenuActivity;
import net.osmand.plus.api.FileSettingsAPIImpl;
import net.osmand.plus.download.DownloadActivityType;
import android.app.Activity;
@ -26,34 +30,19 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
private static final String SELECTED_TOUR = "sherpafy_tour";
private OsmandSettings originalSettings;
private CommonPreference<String> selectedTourPref;
private File selectedTourFolder = null;
private List<TourInformation> tourPresent = new ArrayList<TourInformation>();
private TourInformation selectedTour = null;
private File toursFolder;
@Override
public void setup(OsmandApplication app) {
super.setup(app);
originalSettings = createSettings(app.getSettings().getSettingsAPI());
selectedTourPref = originalSettings.registerBooleanPreference(SELECTED_TOUR, null).makeGlobal();
File toursFolder = new File(originalSettings.getExternalStorageDirectory(), "tours");
if(selectedTourPref.get() != null) {
selectedTourFolder = new File(toursFolder, selectedTourPref.get());
selectedTourFolder.mkdirs();
}
if(selectedTourFolder != null) {
File settingsFile = new File(selectedTourFolder, "settings.props");
FileSettingsAPIImpl fapi;
try {
fapi = new FileSettingsAPIImpl(app, settingsFile);
if (!settingsFile.exists()) {
fapi.saveFile();
}
app.getSettings().setSettingsAPI(fapi);
} catch (IOException e) {
app.showToastMessage(R.string.settings_file_create_error);
}
}
selectedTourPref = originalSettings.registerStringPreference(SELECTED_TOUR, null).makeGlobal();
toursFolder = new File(originalSettings.getExternalStorageDirectory(), "osmand/tours");
}
public boolean checkExceptionsOnStart() {
return false;
}
@ -74,7 +63,7 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
TextView toursButtonText = (TextView) window.findViewById(R.id.SettingsButtonText);
toursButtonText.setText(R.string.tour);
View toursButton = window.findViewById(R.id.SearchButton);
View toursButton = window.findViewById(R.id.SettingsButton);
toursButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
@ -87,7 +76,7 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
}
private Class<?> getTourSelectionActivity() {
return MainMenuActivity.class;
return TourCommonActivity.class;
}
@Override
@ -97,7 +86,69 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
}
public void updatedLoadedFiles(java.util.Map<String,String> indexFileNames, java.util.Map<String,String> indexActivatedFileNames) {
DownloadIndexActivity.listWithAlternatives(app.getResourceManager().getDateFormat(),
app.getAppPath("tours"), "", indexFileNames);
// DownloadIndexActivity.listWithAlternatives(app.getResourceManager().getDateFormat(),
// toursFolder, "", indexFileNames);
}
public Collection<? extends String> onIndexingFiles(IProgress progress, Map<String, String> indexFileNames) {
ArrayList<TourInformation> tourPresent = new ArrayList<TourInformation>();
if(toursFolder.exists()) {
File[] availableTours = toursFolder.listFiles();
if(availableTours != null) {
String selectedName = selectedTourPref.get();
for(File tr : availableTours) {
if (tr.isDirectory()) {
boolean selected = selectedName != null && selectedName.equals(tr.getName());
String date = app.getResourceManager().getDateFormat()
.format(new Date(DownloadIndexActivity.findFileInDir(tr).lastModified()));
indexFileNames.put(tr.getName(), date);
final TourInformation tourInformation = new TourInformation(tr);
tourPresent.add(tourInformation);
if (selected) {
reloadSelectedTour(progress, tr, tourInformation);
}
}
}
}
}
this.tourPresent = tourPresent;
return Collections.emptyList();
}
public List<TourInformation> getTourInformations() {
return tourPresent;
}
public TourInformation getSelectedTour() {
return selectedTour;
}
private void reloadSelectedTour(IProgress progress, File tr, final TourInformation tourInformation) {
if(progress != null) {
progress.startTask(app.getString(R.string.indexing_tour, tr.getName()), -1);
}
File settingsFile = new File(tr, "settings.props");
FileSettingsAPIImpl fapi;
try {
fapi = new FileSettingsAPIImpl(app, settingsFile);
if (!settingsFile.exists()) {
fapi.saveFile();
}
app.getSettings().setSettingsAPI(fapi);
} catch (IOException e) {
app.showToastMessage(R.string.settings_file_create_error);
}
tourInformation.loadFullInformation();
selectedTour = tourInformation;
}
public void selectTour(TourInformation tour) {
if(tour == null) {
selectedTourPref.set(null);
} else {
selectedTourPref.set(tour.getName());
}
app.getResourceManager().reloadIndexes(IProgress.EMPTY_PROGRESS);
}
}

View file

@ -0,0 +1,210 @@
package net.osmand.plus.sherpafy;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TabHost;
import android.widget.TabWidget;
import com.actionbarsherlock.app.SherlockFragmentActivity;
public class TourCommonActivity extends SherlockFragmentActivity {
public static final String TOUR_SELECTION = "TOUR_SELECTION";
public static final String TOUR_STAGE = "TOUR_STAGE";
public static final String TOUR_INFO = "TOUR_INFO";
private TabsAdapter mTabsAdapter;
List<WeakReference<Fragment>> fragList = new ArrayList<WeakReference<Fragment>>();
@Override
protected void onCreate(Bundle savedInstanceState) {
((OsmandApplication) getApplication()).applyTheme(this);
super.onCreate(savedInstanceState);
getSherlock().setUiOptions(ActivityInfo.UIOPTION_SPLIT_ACTION_BAR_WHEN_NARROW);
// getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
setContentView(R.layout.tour_main);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle(R.string.tour_activity_title);
// TabWidget tabs = (TabWidget) findViewById(android.R.id.tabs);
TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost);
tabHost.setup();
ViewPager mViewPager = (ViewPager)findViewById(R.id.pager);
mTabsAdapter = new TabsAdapter(this, tabHost, mViewPager);
mTabsAdapter.addTab(tabHost.newTabSpec(TOUR_INFO).setIndicator(getString(R.string.tab_current_tour)),
TourInformationFragment.class, null);
mTabsAdapter.addTab(tabHost.newTabSpec(TOUR_STAGE).setIndicator(getString(R.string.tab_stages)),
TourStageFragment.class, null);
mTabsAdapter.addTab(tabHost.newTabSpec(TOUR_SELECTION).setIndicator(getString(R.string.tab_tours)),
TourSelectionFragment.class, null);
if (savedInstanceState != null) {
tabHost.setCurrentTabByTag(savedInstanceState.getString("tab"));
}
}
@Override
public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) {
int itemId = item.getItemId();
switch (itemId) {
case android.R.id.home:
finish();
return true;
}
return false;
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putString("tab", mTabsAdapter.mTabHost.getCurrentTabTag());
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
}
@Override
protected void onResume() {
super.onResume();
}
@Override
protected void onPause() {
super.onPause();
}
@Override
public void onAttachFragment (Fragment fragment) {
fragList.add(new WeakReference<Fragment>(fragment));
}
/**
* This is a helper class that implements the management of tabs and all
* details of connecting a ViewPager with associated TabHost. It relies on a
* trick. Normally a tab host has a simple API for supplying a View or
* Intent that each tab will show. This is not sufficient for switching
* between pages. So instead we make the content part of the tab host
* 0dp high (it is not shown) and the TabsAdapter supplies its own dummy
* view to show as the tab content. It listens to changes in tabs, and takes
* care of switch to the correct paged in the ViewPager whenever the selected
* tab changes.
*/
public static class TabsAdapter extends FragmentPagerAdapter
implements TabHost.OnTabChangeListener, ViewPager.OnPageChangeListener {
private final Context mContext;
private final TabHost mTabHost;
private final ViewPager mViewPager;
private final ArrayList<TabInfo> mTabs = new ArrayList<TabInfo>();
static final class TabInfo {
private final String tag;
private Class<?> clss;
private Bundle args;
TabInfo(String _tag, Class<?> _class, Bundle _args) {
tag = _tag;
clss = _class;
args = _args;
}
}
static class DummyTabFactory implements TabHost.TabContentFactory {
private final Context mContext;
public DummyTabFactory(Context context) {
mContext = context;
}
@Override
public View createTabContent(String tag) {
View v = new View(mContext);
v.setMinimumWidth(0);
v.setMinimumHeight(0);
return v;
}
}
public TabsAdapter(FragmentActivity activity, TabHost tabHost, ViewPager pager) {
super(activity.getSupportFragmentManager());
mContext = activity;
mTabHost = tabHost;
mViewPager = pager;
mTabHost.setOnTabChangedListener(this);
mViewPager.setAdapter(this);
mViewPager.setOnPageChangeListener(this);
}
public void addTab(TabHost.TabSpec tabSpec, Class<?> clss, Bundle args) {
tabSpec.setContent(new DummyTabFactory(mContext));
String tag = tabSpec.getTag();
TabInfo info = new TabInfo(tag, clss, args);
mTabs.add(info);
mTabHost.addTab(tabSpec);
notifyDataSetChanged();
}
@Override
public int getCount() {
return mTabs.size();
}
@Override
public Fragment getItem(int position) {
TabInfo info = mTabs.get(position);
return Fragment.instantiate(mContext, info.clss.getName(), info.args);
}
@Override
public void onTabChanged(String tabId) {
int position = mTabHost.getCurrentTab();
mViewPager.setCurrentItem(position);
if (TOUR_INFO.equals(tabId)) {
} else if (TOUR_STAGE.equals(tabId)) {
} else if (TOUR_SELECTION.equals(tabId)) {
}
}
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
// Unfortunately when TabHost changes the current tab, it kindly
// also takes care of putting focus on it when not in touch mode.
// The jerk.
// This hack tries to prevent this from pulling focus out of our
// ViewPager.
TabWidget widget = mTabHost.getTabWidget();
int oldFocusability = widget.getDescendantFocusability();
widget.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
mTabHost.setCurrentTab(position);
widget.setDescendantFocusability(oldFocusability);
}
@Override
public void onPageScrollStateChanged(int state) {
}
}
}

View file

@ -0,0 +1,100 @@
package net.osmand.plus.sherpafy;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
public class TourInformation {
private String name;
private File folder;
private String description = null;
private List<StageInformation> stageInformation = new ArrayList<TourInformation.StageInformation>();
public TourInformation(File f) {
this.folder = f;
this.name = f.getName();
}
private String loadDescription() {
File fl = new File(folder, "description.txt");
StringBuilder text = new StringBuilder();
if (fl.exists()) {
try {
BufferedReader in = new BufferedReader(new FileReader(fl), 256); //$NON-NLS-1$
String s;
boolean f = true;
while ((s = in.readLine()) != null) {
if (!f) {
text.append("\n"); //$NON-NLS-1$
} else {
f = false;
}
text.append(s);
}
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return text.toString();
}
public void loadFullInformation(){
description = loadDescription();
}
public String getDescription() {
return description == null ? "" : description;
}
public String getName() {
return name;
}
public File getFolder() {
return folder;
}
public List<StageInformation> getStageInformation() {
return stageInformation;
}
public Bitmap getImageBitmap() {
File fl = new File(folder, "images/Default.jpg");
if(fl.exists()) {
return BitmapFactory.decodeFile(fl.getAbsolutePath());
}
return null;
}
public static class StageInformation {
File gpxFile;
String name;
String description;
public String getName() {
return name;
}
public String getDescription() {
return description;
}
public File getGpxFile() {
return gpxFile;
}
}
}

View file

@ -0,0 +1,59 @@
/**
*
*/
package net.osmand.plus.sherpafy;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.actionbarsherlock.app.SherlockFragment;
public class TourInformationFragment extends SherlockFragment {
private View view;
private SherpafyCustomization appCtx;
public View onCreateView(android.view.LayoutInflater inflater, android.view.ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.tour_info, container, false);
setHasOptionsMenu(true);
appCtx = (SherpafyCustomization) getApp().getAppCustomization();
return view;
}
@Override
public void onResume() {
super.onResume();
TextView description = (TextView) view.findViewById(R.id.tour_description);
ImageView img = (ImageView) view.findViewById(R.id.tour_image);
TextView name = (TextView) view.findViewById(R.id.tour_name);
if(appCtx.getSelectedTour() != null) {
name.setText(appCtx.getSelectedTour().getName());
description.setText(appCtx.getSelectedTour().getDescription());
description.setVisibility(View.VISIBLE);
final Bitmap imageBitmap = appCtx.getSelectedTour().getImageBitmap();
if(imageBitmap != null) {
img.setImageBitmap(imageBitmap);
img.setVisibility(View.VISIBLE);
} else {
img.setVisibility(View.GONE);
}
} else {
name.setText(R.string.no_tour_selected);
img.setVisibility(View.GONE);
description.setVisibility(View.GONE);
}
}
public OsmandApplication getApp(){
return (OsmandApplication) getSherlockActivity().getApplication();
}
}

View file

@ -0,0 +1,119 @@
/**
*
*/
package net.osmand.plus.sherpafy;
import java.util.List;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.activities.SettingsActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
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 TourSelectionFragment extends SherlockListFragment {
public static final int REQUEST_POI_EDIT = 55;
private static final int DOWNLOAD_MORE = 0;
private SherpafyCustomization appCtx;
private boolean lightContent;
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
appCtx = (SherpafyCustomization) getApp().getAppCustomization();
lightContent = getApp().getSettings().isLightContent();
setHasOptionsMenu(true);
// ListActivity has a ListView, which you can get with:
//ListView lv = getListView();
// Then you can create a listener like so:
// lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
// @Override
// public boolean onItemLongClick(AdapterView<?> av, View v, int pos, long id) {
// TourInformation poi = ((TourAdapter) getListAdapter()).getItem(pos);
// return false;
// }
// });
setListAdapter(new LocalAdapter(appCtx.getTourInformations()));
}
public OsmandApplication getApp(){
return (OsmandApplication) getSherlockActivity().getApplication();
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
final OsmandApplication app = (OsmandApplication) getActivity().getApplication();
boolean light = app.getSettings().isLightActionBar();
com.actionbarsherlock.view.MenuItem menuItem = menu.add(0, DOWNLOAD_MORE, 0, R.string.download_more).setShowAsActionFlags(
MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
menuItem = menuItem.setIcon(light ? R.drawable.ic_action_gdown_light : R.drawable.ic_action_gdown_dark);
menuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(com.actionbarsherlock.view.MenuItem item) {
Intent intent = new Intent(getActivity(), app.getAppCustomization().getDownloadIndexActivity());
getActivity().startActivity(intent);
return true;
}
});
}
@Override
public void onListItemClick(ListView parent, View v, int position, long id) {
final TourInformation tour = ((LocalAdapter) getListAdapter()).getItem(position);
if(appCtx.getSelectedTour() != tour) {
appCtx.selectTour(tour);
} else {
appCtx.selectTour(null);
}
}
private class LocalAdapter extends ArrayAdapter<TourInformation> {
LocalAdapter(List<TourInformation> list) {
super(getSherlockActivity(), R.layout.tour_listitem, list);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
if (row == null) {
LayoutInflater inflater = getSherlockActivity().getLayoutInflater();
row = inflater.inflate(R.layout.tour_listitem, parent, false);
}
TextView label = (TextView) row.findViewById(R.id.label);
ImageView icon = (ImageView) row.findViewById(R.id.icon);
ImageView check = (ImageView) row.findViewById(R.id.check_item);
icon.setImageResource(!lightContent ? R.drawable.ic_action_fav_dark : R.drawable.ic_action_fav_light);
final TourInformation model = getItem(position);
if (appCtx.getSelectedTour() == model) {
check.setImageResource(!lightContent ? R.drawable.ic_action_ok_dark : R.drawable.ic_action_ok_light);
check.setVisibility(View.VISIBLE);
} else {
check.setVisibility(View.INVISIBLE);
}
if(model.getDescription().length() > 0) {
label.setText(model.getName() +"\n" + model.getDescription());
} else {
label.setText(model.getName());
}
return (row);
}
}
}

View file

@ -0,0 +1,91 @@
/**
*
*/
package net.osmand.plus.sherpafy;
import java.util.ArrayList;
import java.util.List;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.sherpafy.TourInformation.StageInformation;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import com.actionbarsherlock.app.SherlockListFragment;
public class TourStageFragment extends SherlockListFragment {
public static final int REQUEST_POI_EDIT = 55;
private SherpafyCustomization appCtx;
private boolean lightContent;
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
appCtx = (SherpafyCustomization) getApp().getAppCustomization();
lightContent = getApp().getSettings().isLightContent();
// ListActivity has a ListView, which you can get with:
//ListView lv = getListView();
// Then you can create a listener like so:
// lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
// @Override
// public boolean onItemLongClick(AdapterView<?> av, View v, int pos, long id) {
// TourInformation poi = ((TourAdapter) getListAdapter()).getItem(pos);
// return false;
// }
// });
if(appCtx.getSelectedTour() != null) {
setListAdapter(new LocalAdapter(appCtx.getSelectedTour().getStageInformation()));
} else {
setListAdapter(new LocalAdapter(new ArrayList<TourInformation.StageInformation>()));
setEmptyText(getString(R.string.no_tour_selected));
}
}
public OsmandApplication getApp(){
return (OsmandApplication) getSherlockActivity().getApplication();
}
@Override
public void onListItemClick(ListView parent, View v, int position, long id) {
final StageInformation model = ((LocalAdapter) getListAdapter()).getItem(position);
// TODO
}
private class LocalAdapter extends ArrayAdapter<StageInformation> {
LocalAdapter(List<StageInformation> list) {
super(getSherlockActivity(), R.layout.tour_listitem, list);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
if (row == null) {
LayoutInflater inflater = getSherlockActivity().getLayoutInflater();
row = inflater.inflate(R.layout.tour_listitem, parent, false);
}
TextView label = (TextView) row.findViewById(R.id.label);
ImageView icon = (ImageView) row.findViewById(R.id.icon);
ImageView check = (ImageView) row.findViewById(R.id.check_item);
icon.setImageResource(!lightContent ? R.drawable.ic_action_fav_dark : R.drawable.ic_action_fav_light);
check.setImageResource(!lightContent ? R.drawable.ic_action_ok_dark : R.drawable.ic_action_ok_light);
final StageInformation model = getItem(position);
if(model.getDescription().length() > 0) {
label.setText(model.getName() +"\n" + model.getDescription());
} else {
label.setText(model.getName());
}
return (row);
}
}
}