From 9263b3eb582d67b0aa9e86f45bb3bf41819d8e29 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Wed, 23 Jul 2014 05:27:50 +0200 Subject: [PATCH] Sherpafy Update --- OsmAnd/res/values/sherpafy.xml | 4 + .../plus/sherpafy/SherpafyHtmlFragment.java | 3 +- .../plus/sherpafy/SherpafyStageFragment.java | 152 +++++++++++++++--- .../sherpafy/SherpafyStageInfoFragment.java | 91 +++++++++++ .../SherpafyStageItineraryFragment.java | 21 +++ .../plus/sherpafy/SherpafyTourFragment.java | 12 +- .../osmand/plus/sherpafy/TourInformation.java | 22 ++- .../plus/sherpafy/TourViewActivity.java | 19 ++- 8 files changed, 291 insertions(+), 33 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/sherpafy/SherpafyStageInfoFragment.java create mode 100644 OsmAnd/src/net/osmand/plus/sherpafy/SherpafyStageItineraryFragment.java diff --git a/OsmAnd/res/values/sherpafy.xml b/OsmAnd/res/values/sherpafy.xml index dbc0d30a1b..243de084d6 100644 --- a/OsmAnd/res/values/sherpafy.xml +++ b/OsmAnd/res/values/sherpafy.xml @@ -1,5 +1,9 @@ + Fav + Target + Route + Info Tour Information Stages Instructions diff --git a/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyHtmlFragment.java b/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyHtmlFragment.java index 8e6b217e9e..b56815383f 100644 --- a/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyHtmlFragment.java +++ b/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyHtmlFragment.java @@ -24,6 +24,7 @@ public class SherpafyHtmlFragment extends SherlockFragment { wv = new WebView(getActivity()); WebSettings settings = wv.getSettings(); settings.setDefaultTextEncodingName("utf-8"); + setHasOptionsMenu(true); return wv; } @@ -35,7 +36,7 @@ public class SherpafyHtmlFragment extends SherlockFragment { if(tl != null){ getSherlockActivity().getSupportActionBar().setTitle(tl); } - wv.loadData(""+data+""+data+" 0) { - additional.setText(OsmAndFormatter.getFormattedDistance((float) stage.getDistance(), getMyApplication())); - } else { - additional.setText(""); - } - header.setText(stage.getName()); - text.setText(stage.getShortDescription()); - description.loadData("" + stage.getFullDescription() + " mTabs = new ArrayList(); + + 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 TabSpec 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(); + return tabSpec; + } + + + @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); + } + + @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) { + } + } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyStageInfoFragment.java b/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyStageInfoFragment.java new file mode 100644 index 0000000000..08162eb503 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyStageInfoFragment.java @@ -0,0 +1,91 @@ +package net.osmand.plus.sherpafy; + +import net.osmand.plus.OsmAndFormatter; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; +import net.osmand.plus.sherpafy.TourInformation.StageInformation; +import android.app.Activity; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.webkit.WebSettings; +import android.webkit.WebView; +import android.widget.ImageView; +import android.widget.TextView; + +import com.actionbarsherlock.app.SherlockFragment; + +public class SherpafyStageInfoFragment extends SherlockFragment { + public static final String STAGE_PARAM = "STAGE"; + public static final String TOUR_PARAM = "TOUR"; + OsmandApplication app; + private SherpafyCustomization customization; + protected StageInformation stage; + private TourInformation tour; + private View view; + + public SherpafyStageInfoFragment() { + } + + + @Override + public void onAttach(Activity activity) { + super.onAttach(activity); + app = (OsmandApplication) getSherlockActivity().getApplication(); + customization = (SherpafyCustomization) app.getAppCustomization(); + + setHasOptionsMenu(true); + String id = getArguments().getString(TOUR_PARAM); + for(TourInformation ti : customization.getTourInformations()) { + if(ti.getId().equals(id)) { + tour = ti; + getSherlockActivity().getSupportActionBar().setTitle(tour.getName()); + break; + } + } + int k = getArguments().getInt(STAGE_PARAM); + if(tour != null && tour.getStageInformation().size() > k) { + stage = tour.getStageInformation().get(k); + } + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + view = inflater.inflate(R.layout.sherpafy_stage_info, container, false); + WebView description = (WebView) view.findViewById(R.id.Description); + WebSettings settings = description.getSettings(); + settings.setDefaultTextEncodingName("utf-8"); + ImageView icon = (ImageView) view.findViewById(R.id.Icon); + TextView additional = (TextView) view.findViewById(R.id.AdditionalText); + TextView text = (TextView) view.findViewById(R.id.Text); + TextView header = (TextView) view.findViewById(R.id.HeaderText); + + updateView(description, icon, additional, text, header); + return view; + } + + + protected void updateView(WebView description, ImageView icon, TextView additional, TextView text, TextView header) { + if (stage.getImageBitmap() != null) { + icon.setImageBitmap(stage.getImageBitmap()); + } else { + icon.setVisibility(View.GONE); + } + if (stage.getDistance() > 0) { + additional.setText(OsmAndFormatter.getFormattedDistance((float) stage.getDistance(), getMyApplication())); + } else { + additional.setText(""); + } + header.setText(stage.getName()); + text.setText(stage.getShortDescription()); + description.loadData("" + stage.getFullDescription() + "" + stage.getItinerary() + + " drawerAdapter; private WeakHashMap fragments = new WeakHashMap(); - private Object selectedItem; + private static Object selectedItem; @Override protected void onCreate(Bundle savedInstanceState) { @@ -97,15 +97,14 @@ public class TourViewActivity extends SherlockFragmentActivity { displaySize = new Point(); getWindowManager().getDefaultDisplay().getSize(displaySize); + mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_navigation_drawer_light, + R.string.default_buttons_other_actions, R.string.close); if (getMyApplication().isApplicationInitializing()) { FragmentManager fragmentManager = getSupportFragmentManager(); fragmentManager.beginTransaction().replace(R.id.content_frame, new SherpafyLoadingFragment()).commit(); } else { showSelectedItem(); } - - mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_navigation_drawer_light, - R.string.default_buttons_other_actions, R.string.close); } @@ -124,7 +123,11 @@ public class TourViewActivity extends SherlockFragmentActivity { setImageResource(R.drawable.icon_sherpafy); tv.setText(getString(R.string.sherpafy_tours)); } else if(it instanceof TourInformation){ - imView.setImageResource(R.drawable.ic_action_globus_light); + if(selectedItem == it) { + imView.setImageResource(R.drawable.ic_action_ok_light); + } else { + imView.setImageResource(R.drawable.ic_action_globus_light); + } tv.setText(((TourInformation) it).getName()); } else if(it instanceof StageInformation){ if(customization.getSelectedStage() == it) { @@ -281,12 +284,14 @@ public class TourViewActivity extends SherlockFragmentActivity { } private void setDrawerIndicatorVisible(boolean b) { - mDrawerToggle.setDrawerIndicatorEnabled(b); + if(mDrawerToggle.isDrawerIndicatorEnabled() != b) { + mDrawerToggle.setDrawerIndicatorEnabled(b); + } } public void showSelectedItem() { - if(selectedItem == null) { + if(selectedItem != null) { selectMenu(selectedItem); } else { if(customization.getSelectedStage() != null) {