Added new page slider to favorites
This commit is contained in:
parent
c959663cc4
commit
da816e8a9f
4 changed files with 132 additions and 106 deletions
|
@ -11,7 +11,6 @@
|
|||
android:layout_height="?attr/actionBarSize"
|
||||
android:background="?attr/colorPrimary"/>
|
||||
|
||||
|
||||
<android.support.v4.view.ViewPager
|
||||
android:id="@+id/pager"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -4,20 +4,18 @@
|
|||
package net.osmand.plus.activities;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.MenuItem;
|
||||
import android.view.Window;
|
||||
import net.osmand.plus.GpxSelectionHelper;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
|
@ -25,16 +23,20 @@ import android.support.v4.app.FragmentPagerAdapter;
|
|||
import android.support.v4.view.ViewPager;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.TabHost;
|
||||
import android.widget.TabHost.TabSpec;
|
||||
import android.widget.TabWidget;
|
||||
import android.widget.TextView;
|
||||
import net.osmand.plus.activities.search.SearchActivity;
|
||||
import net.osmand.plus.dashboard.DashDownloadMapsFragment;
|
||||
import net.osmand.plus.dashboard.DashUpdatesFragment;
|
||||
import net.osmand.plus.download.IndexItem;
|
||||
import net.osmand.plus.views.controls.PagerSlidingTabStrip;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class FavouritesActivity extends ActionBarProgressActivity {
|
||||
public class FavouritesActivity extends TabActivity {
|
||||
|
||||
private static final String FAVOURITES_INFO = "FAVOURITES_INFO";
|
||||
private static final String TRACKS = "TRACKS";
|
||||
|
@ -43,10 +45,8 @@ public class FavouritesActivity extends ActionBarProgressActivity {
|
|||
public static int GPX_TAB = 1;
|
||||
public static int SELECTED_GPX_TAB = 2;
|
||||
public static String TAB_PARAM = "TAB_PARAM";
|
||||
private TabsAdapter mTabsAdapter;
|
||||
private TabSpec selectedTrack;
|
||||
private TabHost tabHost;
|
||||
|
||||
protected List<WeakReference<Fragment>> fragList = new ArrayList<WeakReference<Fragment>>();
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
|
@ -74,33 +74,38 @@ public class FavouritesActivity extends ActionBarProgressActivity {
|
|||
setContentView(R.layout.search_activity_single);
|
||||
getSupportFragmentManager().beginTransaction().add(R.id.layout, new FavouritesTreeFragment()).commit();
|
||||
} else {
|
||||
setContentView(R.layout.tab_content);
|
||||
tabHost = (TabHost) findViewById(android.R.id.tabhost);
|
||||
tabHost.setup();
|
||||
setContentView(R.layout.search_main);
|
||||
|
||||
PagerSlidingTabStrip mSlidingTabLayout = (PagerSlidingTabStrip) findViewById(R.id.sliding_tabs);
|
||||
OsmandSettings settings = ((OsmandApplication) getApplication()).getSettings();
|
||||
Integer tab = settings.FAVORITES_TAB.get();
|
||||
ViewPager mViewPager = (ViewPager) findViewById(R.id.pager);
|
||||
mTabsAdapter = new TabsAdapter(this, tabHost, mViewPager, settings, true);
|
||||
mTabsAdapter.addTab(tabHost.newTabSpec(FAVOURITES_INFO).setIndicator(getString(R.string.my_favorites)),
|
||||
FavouritesTreeFragment.class, null);
|
||||
mTabsAdapter.addTab(tabHost.newTabSpec(TRACKS).setIndicator(getString(R.string.my_tracks)),
|
||||
AvailableGPXFragment.class, null);
|
||||
selectedTrack = mTabsAdapter.addTab(tabHost.newTabSpec(SELECTED_TRACK).setIndicator(getString(R.string.selected_track)),
|
||||
SelectedGPXFragment.class, null);
|
||||
mTabs.add(getTabIndicator(R.string.my_favorites, FavouritesTreeFragment.class));
|
||||
mTabs.add(getTabIndicator(R.string.my_tracks, AvailableGPXFragment.class));
|
||||
mTabs.add(getTabIndicator(R.string.selected_track, SelectedGPXFragment.class));
|
||||
|
||||
setViewPagerAdapter(mViewPager);
|
||||
mSlidingTabLayout.setViewPager(mViewPager);
|
||||
|
||||
|
||||
Intent intent = getIntent();
|
||||
if(intent != null) {
|
||||
int tt = intent.getIntExtra(TAB_PARAM, -1);
|
||||
if(tt >= 0) {
|
||||
tabHost.setCurrentTab(tt);
|
||||
mViewPager.setCurrentItem(tt);
|
||||
}
|
||||
} else {
|
||||
tabHost.setCurrentTab(tab);
|
||||
mViewPager.setCurrentItem(tab);
|
||||
}
|
||||
updateSelectedTracks();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onAttachFragment(Fragment fragment) {
|
||||
fragList.add(new WeakReference<Fragment>(fragment));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
@ -118,22 +123,24 @@ public class FavouritesActivity extends ActionBarProgressActivity {
|
|||
super.onPause();
|
||||
((OsmandApplication) getApplication()).getSelectedGpxHelper().setUiListener(FavouritesActivity.class, null);
|
||||
}
|
||||
|
||||
|
||||
public void updateSelectedTracks() {
|
||||
if (selectedTrack != null) {
|
||||
GpxSelectionHelper gpx = ((OsmandApplication) getApplication()).getSelectedGpxHelper();
|
||||
String vl = getString(R.string.selected_track);
|
||||
if (gpx.isShowingAnyGpxFiles()) {
|
||||
vl += " (" + gpx.getSelectedGPXFiles().size()
|
||||
+ ")";
|
||||
} else {
|
||||
vl += " (0)";
|
||||
for (WeakReference<Fragment> ref : fragList) {
|
||||
Fragment f = ref.get();
|
||||
if (f instanceof SelectedGPXFragment && !f.isDetached()) {
|
||||
GpxSelectionHelper gpx = ((OsmandApplication) getApplication()).getSelectedGpxHelper();
|
||||
String vl = getString(R.string.selected_track);
|
||||
if (gpx.isShowingAnyGpxFiles()) {
|
||||
vl += " (" + gpx.getSelectedGPXFiles().size()
|
||||
+ ")";
|
||||
} else {
|
||||
vl += " (0)";
|
||||
}
|
||||
try{
|
||||
((TextView)f.getView().findViewById(android.R.id.title)).setText(vl);
|
||||
} catch (NullPointerException e) {
|
||||
}
|
||||
}
|
||||
try {
|
||||
((TextView)tabHost.getTabWidget().getChildAt(2).findViewById(android.R.id.title)).setText(vl);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
mTabsAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
80
OsmAnd/src/net/osmand/plus/activities/TabActivity.java
Normal file
80
OsmAnd/src/net/osmand/plus/activities/TabActivity.java
Normal file
|
@ -0,0 +1,80 @@
|
|||
package net.osmand.plus.activities;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.view.ViewParent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Denis
|
||||
* on 26.01.2015.
|
||||
*/
|
||||
public class TabActivity extends ActionBarProgressActivity {
|
||||
|
||||
protected TabItem getTabIndicator(int resId, Class<?> fragment){
|
||||
return new TabItem(getString(resId), Color.DKGRAY, Color.LTGRAY, fragment);
|
||||
}
|
||||
|
||||
protected List<TabItem> mTabs = new ArrayList<TabItem>();
|
||||
|
||||
protected static class TabItem {
|
||||
private final CharSequence mTitle;
|
||||
private final int mIndicatorColor;
|
||||
private final int mDividerColor;
|
||||
private final Class<?> fragment;
|
||||
|
||||
public TabItem(CharSequence mTitle, int mIndicatorColor, int mDividerColor, Class<?> fragment) {
|
||||
this.mTitle = mTitle;
|
||||
this.mIndicatorColor = mIndicatorColor;
|
||||
this.mDividerColor = mDividerColor;
|
||||
this.fragment = fragment;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void setViewPagerAdapter(ViewPager pager){
|
||||
pager.setAdapter(new SearchFragmentPagerAdapter(getSupportFragmentManager()));
|
||||
}
|
||||
|
||||
protected class SearchFragmentPagerAdapter extends FragmentPagerAdapter {
|
||||
|
||||
SearchFragmentPagerAdapter(FragmentManager fm) {
|
||||
super(fm);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the {@link android.support.v4.app.Fragment} to be displayed at {@code position}.
|
||||
* <p>
|
||||
*/
|
||||
@Override
|
||||
public Fragment getItem(int i) {
|
||||
try {
|
||||
return (Fragment) mTabs.get(i).fragment.newInstance();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return mTabs.size();
|
||||
}
|
||||
|
||||
// BEGIN_INCLUDE (pageradapter_getpagetitle)
|
||||
/**
|
||||
* Return the title of the item at {@code position}. This is important as what this method
|
||||
* returns is what is displayed in the {@link com.example.android.common.view.SlidingTabLayout}.
|
||||
* <p>
|
||||
*/
|
||||
@Override
|
||||
public CharSequence getPageTitle(int position) {
|
||||
return mTabs.get(position).mTitle;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -19,6 +19,7 @@ import net.osmand.plus.R;
|
|||
import net.osmand.plus.activities.FavouritesListActivity;
|
||||
import net.osmand.plus.activities.FavouritesListFragment;
|
||||
import net.osmand.plus.activities.NavigatePointFragment;
|
||||
import net.osmand.plus.activities.TabActivity;
|
||||
import net.osmand.plus.views.controls.PagerSlidingTabStrip;
|
||||
import net.osmand.util.Algorithms;
|
||||
import android.app.ActionBar;
|
||||
|
@ -42,7 +43,7 @@ import android.widget.Button;
|
|||
|
||||
import com.example.android.common.view.SlidingTabLayout;
|
||||
|
||||
public class SearchActivity extends ActionBarActivity implements OsmAndLocationListener {
|
||||
public class SearchActivity extends TabActivity implements OsmAndLocationListener {
|
||||
public static final int POI_TAB_INDEX = 0;
|
||||
public static final int ADDRESS_TAB_INDEX = 1;
|
||||
public static final int LOCATION_TAB_INDEX = 2;
|
||||
|
@ -73,35 +74,13 @@ public class SearchActivity extends ActionBarActivity implements OsmAndLocationL
|
|||
List<WeakReference<Fragment>> fragList = new ArrayList<WeakReference<Fragment>>();
|
||||
private boolean showOnlyOneTab;
|
||||
|
||||
private List<TabItem> mTabs = new ArrayList<TabItem>();
|
||||
|
||||
|
||||
public interface SearchActivityChild {
|
||||
|
||||
public void locationUpdate(LatLon l);
|
||||
}
|
||||
|
||||
private static class TabItem {
|
||||
private final CharSequence mTitle;
|
||||
private final int mIcon;
|
||||
private final int mIndicatorColor;
|
||||
private final int mDividerColor;
|
||||
private final Class<?> fragment;
|
||||
|
||||
public TabItem(CharSequence mTitle, int mIcon, int mIndicatorColor, int mDividerColor, Class<?> fragment) {
|
||||
this.mTitle = mTitle;
|
||||
this.mIcon = mIcon;
|
||||
this.mIndicatorColor = mIndicatorColor;
|
||||
this.mDividerColor = mDividerColor;
|
||||
this.fragment = fragment;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private TabItem getTabIndicator(int iconId, int resId, Class<?> fragment){
|
||||
return new TabItem(getString(resId), iconId, Color.DKGRAY, Color.LTGRAY, fragment);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
((OsmandApplication) getApplication()).applyTheme(this);
|
||||
|
@ -115,23 +94,19 @@ public class SearchActivity extends ActionBarActivity implements OsmAndLocationL
|
|||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
getSupportActionBar().setTitle("");
|
||||
getSupportActionBar().setElevation(0);
|
||||
// getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#39464d")));
|
||||
// getSupportActionBar().setTitle(R.string.select_search_position);
|
||||
|
||||
|
||||
|
||||
if (!showOnlyOneTab) {
|
||||
ViewPager mViewPager = (ViewPager) findViewById(R.id.pager);
|
||||
PagerSlidingTabStrip mSlidingTabLayout = (PagerSlidingTabStrip) findViewById(R.id.sliding_tabs);
|
||||
|
||||
mTabs.add(getTabIndicator(R.drawable.tab_search_poi_icon, R.string.poi, getFragment(POI_TAB_INDEX)));
|
||||
mTabs.add(getTabIndicator(R.drawable.tab_search_address_icon, R.string.address, getFragment(ADDRESS_TAB_INDEX)));
|
||||
mTabs.add(getTabIndicator(R.drawable.tab_search_location_icon, R.string.search_tabs_location, getFragment(LOCATION_TAB_INDEX)));
|
||||
mTabs.add(getTabIndicator(R.drawable.tab_search_favorites_icon, R.string.favorite, getFragment(FAVORITES_TAB_INDEX)));
|
||||
mTabs.add(getTabIndicator(R.drawable.tab_search_history_icon, R.string.history, getFragment(HISTORY_TAB_INDEX)));
|
||||
mTabs.add(getTabIndicator(R.string.poi, getFragment(POI_TAB_INDEX)));
|
||||
mTabs.add(getTabIndicator(R.string.address, getFragment(ADDRESS_TAB_INDEX)));
|
||||
mTabs.add(getTabIndicator(R.string.search_tabs_location, getFragment(LOCATION_TAB_INDEX)));
|
||||
mTabs.add(getTabIndicator(R.string.favorite, getFragment(FAVORITES_TAB_INDEX)));
|
||||
mTabs.add(getTabIndicator(R.string.history, getFragment(HISTORY_TAB_INDEX)));
|
||||
|
||||
|
||||
mViewPager.setAdapter(new SearchFragmentPagerAdapter(getSupportFragmentManager()));
|
||||
setViewPagerAdapter(mViewPager);
|
||||
mSlidingTabLayout.setViewPager(mViewPager);
|
||||
|
||||
mViewPager.setCurrentItem(Math.min(tab, HISTORY_TAB_INDEX));
|
||||
|
@ -409,41 +384,6 @@ public class SearchActivity extends ActionBarActivity implements OsmAndLocationL
|
|||
}
|
||||
|
||||
|
||||
class SearchFragmentPagerAdapter extends FragmentPagerAdapter
|
||||
/*implements TabHost.OnTabChangeListener, ViewPager.OnPageChangeListener*/ {
|
||||
|
||||
SearchFragmentPagerAdapter(FragmentManager fm) {
|
||||
super(fm);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the {@link android.support.v4.app.Fragment} to be displayed at {@code position}.
|
||||
* <p>
|
||||
*/
|
||||
@Override
|
||||
public Fragment getItem(int i) {
|
||||
try {
|
||||
return (Fragment) mTabs.get(i).fragment.newInstance();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return mTabs.size();
|
||||
}
|
||||
|
||||
// BEGIN_INCLUDE (pageradapter_getpagetitle)
|
||||
/**
|
||||
* Return the title of the item at {@code position}. This is important as what this method
|
||||
* returns is what is displayed in the {@link SlidingTabLayout}.
|
||||
* <p>
|
||||
*/
|
||||
@Override
|
||||
public CharSequence getPageTitle(int position) {
|
||||
return mTabs.get(position).mTitle;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue