aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching
diff options
context:
space:
mode:
authorSammysHP <sven@sammyshp.de>2011-12-03 04:13:27 -0800
committerSammysHP <sven@sammyshp.de>2011-12-03 04:13:27 -0800
commit1bece437a2e2d0674f95a684469f59580c286e3e (patch)
treec4cbbab9d6bf75e418c85f9750efae509ef87565 /main/src/cgeo/geocaching
parent313be6a1e9fb334e1745f0f2f9117561b4be92dc (diff)
parentfbb191bb1442f1e1ad983c251866404e7648228d (diff)
downloadcgeo-1bece437a2e2d0674f95a684469f59580c286e3e.zip
cgeo-1bece437a2e2d0674f95a684469f59580c286e3e.tar.gz
cgeo-1bece437a2e2d0674f95a684469f59580c286e3e.tar.bz2
Merge pull request #850 from SammysHP/newindicator2
New viewpager-indicator
Diffstat (limited to 'main/src/cgeo/geocaching')
-rw-r--r--main/src/cgeo/geocaching/CacheDetailActivity.java68
1 files changed, 9 insertions, 59 deletions
diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java
index 3f81e3c..368d1f1 100644
--- a/main/src/cgeo/geocaching/CacheDetailActivity.java
+++ b/main/src/cgeo/geocaching/CacheDetailActivity.java
@@ -14,6 +14,9 @@ import cgeo.geocaching.utils.CancellableHandler;
import cgeo.geocaching.utils.CryptUtils;
import cgeo.geocaching.utils.UnknownTagsHandler;
+import com.viewpagerindicator.TitlePageIndicator;
+import com.viewpagerindicator.TitleProvider;
+
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringEscapeUtils;
@@ -106,12 +109,6 @@ public class CacheDetailActivity extends AbstractActivity {
private int contextMenuWPIndex = -1;
/**
- * The index of the current page. We need this hack because {@link onPageSelected()} is not called after
- * initialization.
- */
- private int currentPageIndex = 0;
-
- /**
* A {@link List} of all available pages.
*/
private final List<Page> pageOrder = new ArrayList<Page>();
@@ -127,11 +124,6 @@ public class CacheDetailActivity extends AbstractActivity {
private ViewPagerAdapter viewPagerAdapter;
/**
- * The {@link ViewPagerIndicator} for this activity.
- */
- private ViewPagerIndicator viewPagerIndicator;
-
- /**
* If another activity is called and can modify the data of this activity, we refresh it on resume.
*/
private boolean refreshOnResume = false;
@@ -246,11 +238,12 @@ public class CacheDetailActivity extends AbstractActivity {
// initialize ViewPager
ViewPager pager = (ViewPager) findViewById(R.id.viewpager);
- viewPagerIndicator = new ViewPagerIndicator();
- pager.setOnPageChangeListener(viewPagerIndicator);
viewPagerAdapter = new ViewPagerAdapter();
pager.setAdapter(viewPagerAdapter);
+ TitlePageIndicator titleIndicator = (TitlePageIndicator) findViewById(R.id.pager_indicator);
+ titleIndicator.setViewPager(pager);
+
// Initialization done. Let's load the data with the given information.
new LoadCacheThread(geocode, guid, loadCacheHandler).start();
}
@@ -594,9 +587,6 @@ public class CacheDetailActivity extends AbstractActivity {
// notify the adapter that the data has changed
viewPagerAdapter.notifyDataSetChanged();
- // notify the indicator about the change
- viewPagerIndicator.onPageSelected(currentPageIndex);
-
// rendering done! remove progress-popup if any there
progress.dismiss();
}
@@ -900,7 +890,7 @@ public class CacheDetailActivity extends AbstractActivity {
/**
* The ViewPagerAdapter for scrolling through pages of the CacheDetailActivity.
*/
- private class ViewPagerAdapter extends PagerAdapter {
+ private class ViewPagerAdapter extends PagerAdapter implements TitleProvider {
@Override
public void destroyItem(View container, int position, Object object) {
@@ -988,50 +978,10 @@ public class CacheDetailActivity extends AbstractActivity {
// The ViewPager will get it back in instantiateItem()
return POSITION_NONE;
}
- }
-
- private class ViewPagerIndicator implements ViewPager.OnPageChangeListener {
-
- // TODO: Clickable prev + next
- private TextView indicatorPrev;
- private TextView indicatorCurrent;
- private TextView indicatorNext;
-
- public ViewPagerIndicator() {
- super();
-
- indicatorPrev = (TextView) findViewById(R.id.indicator_prev);
- indicatorCurrent = (TextView) findViewById(R.id.indicator_current);
- indicatorNext = (TextView) findViewById(R.id.indicator_next);
- }
-
- @Override
- public void onPageScrollStateChanged(int state) {
- }
-
- @Override
- public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
- }
@Override
- public void onPageSelected(int position) {
- currentPageIndex = position;
-
- indicatorCurrent.setText(res.getString(pageOrder.get(position).titleStringId));
-
- if (position > 0) {
- indicatorPrev.setText(res.getString(pageOrder.get(position - 1).titleStringId));
- indicatorPrev.setVisibility(View.VISIBLE);
- } else {
- indicatorPrev.setVisibility(View.GONE);
- }
-
- if (position < (pageOrder.size() - 1)) {
- indicatorNext.setText(res.getString(pageOrder.get(position + 1).titleStringId));
- indicatorNext.setVisibility(View.VISIBLE);
- } else {
- indicatorNext.setVisibility(View.GONE);
- }
+ public String getTitle(int position) {
+ return res.getString(pageOrder.get(position).titleStringId);
}
}