Fix activities

This commit is contained in:
Victor Shcherb 2014-06-03 22:46:59 +02:00
parent 97d136c45b
commit 4775d32b89
11 changed files with 142 additions and 718 deletions

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- When selected, use grey -->
<item android:drawable="@drawable/expandable_category_pushed" android:state_checked="true"/>
<!-- When not selected, use white -->
<item android:drawable="@drawable/expandable_category_unpushed" android:state_checked="false"/>
</selector>

View file

@ -1,112 +1,91 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/color_white">
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content">
<Button android:id="@+id/start_tour"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/color_black"
android:text="Start tour"/>
<Button android:id="@+id/itenerary"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/color_black"
android:layout_alignParentRight="true"
android:text="Itenerary"/>
</RelativeLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:orientation="horizontal" >
<RelativeLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
>
<Button android:id="@+id/collapse"
android:layout_width="30dp"
android:text="-"
android:background="@color/color_black"
android:layout_height="30dp"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:textSize="20dp"
android:layout_toRightOf="@+id/collapse"
android:textColor="@color/color_black"
android:text="Stages"/>
</RelativeLayout>
<RadioGroup
android:layout_width="fill_parent"
<ToggleButton
android:id="@+id/collapse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/stages">
</RadioGroup>
android:button="@drawable/expandable_category" />
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:text="@string/select_tour"
android:textSize="21sp" />
<Button
android:id="@+id/start_tour"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="@string/start_tour" />
</LinearLayout>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:orientation="vertical" >
<RadioGroup
android:id="@+id/stages"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content">
<LinearLayout android:id="@+id/info_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:orientation="vertical" >
</RadioGroup>
<TextView
android:textColor="@color/color_black"
android:id="@+id/tour_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:layout_marginTop="2dp"
android:textSize="18sp" >
</TextView>
<ImageView
android:id="@+id/tour_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="4dp" />
<TextView
android:textColor="@color/color_black"
android:id="@+id/tour_fulldescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:layout_marginTop="2dp"
android:textSize="18sp" >
</TextView>
</LinearLayout>
<Button android:id="@+id/btn_settings"
android:text="Settings"
android:layout_below="@+id/info_layout"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:background="@color/color_black"
android:layout_height="wrap_content"/>
</RelativeLayout>
<TextView
android:id="@+id/tour_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:layout_marginTop="2dp"
android:textSize="18sp" >
</TextView>
<ImageView
android:id="@+id/tour_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="4dp" />
<TextView
android:id="@+id/tour_fulldescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:layout_marginTop="2dp"
android:textSize="16sp" >
</TextView>
<TextView
android:id="@+id/btn_settings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/settings_Button" />
</LinearLayout>
</ScrollView>
</LinearLayout>

View file

@ -9,7 +9,6 @@
android:layout_centerVertical="true"
android:orientation="horizontal">
<Button android:id="@+id/select_tour"
android:background="@color/color_black"
android:layout_marginRight="5dp"
android:maxWidth="60dp"
android:minWidth="60dp"
@ -18,7 +17,6 @@
android:layout_height="wrap_content"/>
<Button android:id="@+id/download_tour"
android:layout_marginLeft="5dp"
android:background="@color/color_black"
android:maxWidth="60dp"
android:minWidth="60dp"
android:text="@string/download_tour"

View file

@ -14,6 +14,7 @@
<string name="indexing_tour">Loading selected tour \'%s\'&#8230;</string>
<string name="tour_activity_title">Tour</string>
<string name="select_tour">Select tour</string>
<string name="start_tour">Start tour</string>
<string name="download_tour">Download tour</string>
<string name="sherpafy_app_name">Sherpafy</string>
</resources>

View file

@ -45,6 +45,10 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
}
public boolean isTourSelected() {
return selectedTourPref.get() != null;
}
public boolean checkExceptionsOnStart() {
return false;
}
@ -79,9 +83,6 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
// the image could be also updated
}
private Class<?> getTourSelectionActivity() {
return TourCommonActivity.class;
}
@Override
public void getDownloadTypes(List<DownloadActivityType> items) {

View file

@ -26,9 +26,13 @@ public class SherpafyStartActivity extends SherlockFragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
if (!(getMyApplication().getAppCustomization() instanceof SherpafyCustomization)) {
getMyApplication().setAppCustomization(new SherpafyCustomization());
}
customization = (SherpafyCustomization) getMyApplication().getAppCustomization();
//Initialization
Intent intent = getIntent();
if(intent != null && !intent.hasExtra("SETTINGS") && customization.getSelectedTour() != null) {
if(intent != null && !intent.hasExtra("SETTINGS") && customization.isTourSelected()) {
super.onCreate(savedInstanceState);
Intent nintent = new Intent(getApplicationContext(), TourViewActivity.class);
startActivity(nintent);
@ -41,14 +45,9 @@ public class SherpafyStartActivity extends SherlockFragmentActivity {
getSherlock().setUiOptions(ActivityInfo.UIOPTION_SPLIT_ACTION_BAR_WHEN_NARROW);
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
getSupportActionBar().setTitle(R.string.sherpafy_app_name);
super.setContentView(R.layout.sherpafy_start);
if (!(getMyApplication().getAppCustomization() instanceof SherpafyCustomization)) {
getMyApplication().setAppCustomization(new SherpafyCustomization());
}
customization = (SherpafyCustomization) getMyApplication().getAppCustomization();
ProgressDialog startProgressDialog = new ProgressDialog(this);
getMyApplication().checkApplicationIsBeingInitialized(this, startProgressDialog);

View file

@ -1,252 +0,0 @@
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.ProgressDialogImplementation;
import net.osmand.plus.R;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.AsyncTask;
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"));
}
}
public void selectTour(TourInformation ti){
final SherpafyCustomization c = (SherpafyCustomization) ((OsmandApplication) getApplication()).getAppCustomization();
new AsyncTask<TourInformation, Void, Void> (){
private ProgressDialogImplementation dlg;
protected void onPreExecute() {
dlg = ProgressDialogImplementation.createProgressDialog(TourCommonActivity.this, "", getString(R.string.indexing_tour, ""),
ProgressDialog.STYLE_SPINNER);
};
@Override
protected Void doInBackground(TourInformation... params) {
c.selectTour(params[0], dlg);
return null;
}
protected void onPostExecute(Void result) {
dlg.getDialog().dismiss();
// for(WeakReference<Fragment> ref : fragList) {
// Fragment f = ref.get();
// if(f instanceof TourFragment) {
// if(!f.isDetached()) {
// ((TourFragment) f).refreshTour();
// }
// }
// }
Intent intent = new Intent(getApplicationContext(), TourViewActivity.class);
startActivity(intent);
finish();
};
}.execute(ti);
}
public interface TourFragment {
public void refreshTour();
}
@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

@ -1,76 +0,0 @@
/**
*
*/
package net.osmand.plus.sherpafy;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.sherpafy.TourCommonActivity.TourFragment;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.TextView;
import com.actionbarsherlock.app.SherlockFragment;
public class TourInformationFragment extends SherlockFragment implements TourFragment {
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();
updateView();
}
private void updateView() {
ImageView img = (ImageView) view.findViewById(R.id.tour_image);
TextView description = (TextView) view.findViewById(R.id.tour_description);
TextView fullDescription = (TextView) view.findViewById(R.id.tour_fulldescription);
TextView name = (TextView) view.findViewById(R.id.tour_name);
if(appCtx.getSelectedTour() != null) {
name.setText(appCtx.getSelectedTour().getName());
description.setText(appCtx.getSelectedTour().getShortDescription());
description.setVisibility(View.VISIBLE);
fullDescription.setText(appCtx.getSelectedTour().getFulldescription());
fullDescription.setVisibility(View.VISIBLE);
final Bitmap imageBitmap = appCtx.getSelectedTour().getImageBitmap();
if(imageBitmap != null) {
img.setImageBitmap(imageBitmap);
img.setAdjustViewBounds(true);
img.setScaleType(ScaleType.CENTER_INSIDE);
img.setCropToPadding(true);
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);
fullDescription.setVisibility(View.GONE);
}
}
public OsmandApplication getApp(){
return (OsmandApplication) getSherlockActivity().getApplication();
}
@Override
public void refreshTour() {
updateView();
}
}

View file

@ -1,123 +0,0 @@
/**
*
*/
package net.osmand.plus.sherpafy;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import android.app.ProgressDialog;
import android.widget.*;
import net.osmand.IProgress;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.ProgressDialogImplementation;
import net.osmand.plus.R;
import net.osmand.plus.sherpafy.TourCommonActivity.TourFragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
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 implements TourFragment {
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();
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);
// boolean light = app.getSettings().isLightActionBar();
// 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) {
((TourCommonActivity) getActivity()).selectTour(tour);
}
}
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.getShortDescription().length() > 0) {
label.setText(model.getName() +"\n" + model.getShortDescription());
} else {
label.setText(model.getName());
}
return (row);
}
}
@Override
public void refreshTour() {
setListAdapter(new LocalAdapter(appCtx.getTourInformations()));
}
}

View file

@ -1,108 +0,0 @@
/**
*
*/
package net.osmand.plus.sherpafy;
import java.util.ArrayList;
import java.util.List;
import net.osmand.IProgress;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.sherpafy.TourCommonActivity.TourFragment;
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 implements TourFragment {
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;
// }
// });
setEmptyText(getString(R.string.no_stages_provided));
if(appCtx.getSelectedTour() != null) {
setListAdapter(new LocalAdapter(appCtx.getSelectedTour().getStageInformation()));
} else {
setListAdapter(new LocalAdapter(new ArrayList<TourInformation.StageInformation>()));
}
}
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);
appCtx.selectStage(model, IProgress.EMPTY_PROGRESS);
}
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);
final StageInformation model = getItem(position);
if(appCtx.getSelectedStage() == 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);
}
}
@Override
public void refreshTour() {
if(appCtx.getSelectedTour() != null) {
setListAdapter(new LocalAdapter(appCtx.getSelectedTour().getStageInformation()));
} else {
setListAdapter(new LocalAdapter(new ArrayList<TourInformation.StageInformation>()));
}
}
}

View file

@ -1,22 +1,28 @@
package net.osmand.plus.sherpafy;
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
import com.actionbarsherlock.app.SherlockFragment;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import java.util.List;
import net.osmand.IProgress;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.ToggleButton;
import java.util.List;
import com.actionbarsherlock.app.SherlockFragmentActivity;
/**
* Created by Barsik on 02.06.2014.
*/
public class TourViewActivity extends SherlockFragmentActivity {
@ -24,59 +30,53 @@ public class TourViewActivity extends SherlockFragmentActivity {
ImageView img;
TextView description;
TextView fullDescription;
List<TourInformation.StageInformation> stages_info;
TourInformation cur_tour;
List<TourInformation.StageInformation> stagesInfo;
TourInformation curTour;
RadioGroup stages;
private boolean hack = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
((OsmandApplication) getApplication()).applyTheme(this);
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
// if (customization.getTourInformations().isEmpty())
// {
// customization.onIndexingFiles( IProgress.EMPTY_PROGRESS, new ConcurrentHashMap<String, String>() );
// }
setTheme(R.style.OsmandLightTheme);
((OsmandApplication) getApplication()).setLanguage(this);
super.onCreate(savedInstanceState);
getSherlock().setUiOptions(ActivityInfo.UIOPTION_SPLIT_ACTION_BAR_WHEN_NARROW);
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
getSupportActionBar().setTitle(R.string.sherpafy_app_name);
ProgressDialog startProgressDialog = new ProgressDialog(this);
getMyApplication().checkApplicationIsBeingInitialized(this, startProgressDialog);
setContentView(R.layout.custom_tour_info);
Button collapser = (Button) findViewById(R.id.collapse);
ToggleButton collapser = (ToggleButton) findViewById(R.id.collapse);
stages = (RadioGroup) findViewById(R.id.stages);
stages.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int i) {
if (hack) {return;}
if (i == 0) {
customization.selectStage(null, IProgress.EMPTY_PROGRESS);
fullDescription.setText(cur_tour.getFulldescription());
description.setText((cur_tour.getShortDescription()));
fullDescription.setText(curTour.getFulldescription());
description.setText((curTour.getShortDescription()));
prepareBitmap();
} else {
//-1 because there's one more item Overview, which is not exactly a stage.
customization.selectStage(stages_info.get(i - 1), IProgress.EMPTY_PROGRESS);
description.setText(stages_info.get(i - 1).getDescription());
customization.selectStage(stagesInfo.get(i - 1), IProgress.EMPTY_PROGRESS);
description.setText(stagesInfo.get(i - 1).getDescription());
fullDescription.setText("");
}
}
});
collapser.setOnClickListener(new View.OnClickListener() {
collapser.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onClick(View view) {
Button btn = (Button) view;
if (btn.getText().equals("+")) {
btn.setText("-");
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
stages.setVisibility(View.VISIBLE);
} else {
btn.setText("+");
stages.setVisibility(View.GONE);
}
}
});
@ -106,8 +106,8 @@ public class TourViewActivity extends SherlockFragmentActivity {
private void updateTourView() {
cur_tour = customization.getSelectedTour();
stages_info = cur_tour.getStageInformation();
curTour = customization.getSelectedTour();
stagesInfo = curTour.getStageInformation();
img = (ImageView) findViewById(R.id.tour_image);
description = (TextView) findViewById(R.id.tour_description);
@ -115,7 +115,6 @@ public class TourViewActivity extends SherlockFragmentActivity {
fullDescription = (TextView) findViewById(R.id.tour_fulldescription);
fullDescription.setVisibility(View.VISIBLE);
Button start_tour = (Button) findViewById(R.id.start_tour);
Button itenerary = (Button) findViewById(R.id.itenerary);
//in case of reloading view - remove all previous radio buttons
stages.removeAllViews();
@ -128,7 +127,7 @@ public class TourViewActivity extends SherlockFragmentActivity {
});
//get count of radio buttons
final int count = stages_info.size() + 1;
final int count = stagesInfo.size() + 1;
final RadioButton[] rb = new RadioButton[count];
rb[0] = new RadioButton(this);
@ -141,26 +140,23 @@ public class TourViewActivity extends SherlockFragmentActivity {
rb[i] = new RadioButton(this);
rb[i].setId(i);
stages.addView(rb[i]);
rb[i].setText(stages_info.get(i - 1).getName());
rb[i].setText(stagesInfo.get(i - 1).getName());
rb[i].setTextColor(getResources().getColor(R.color.color_black));
}
TourInformation.StageInformation cur_stage = customization.getSelectedStage();
TourInformation.StageInformation curStage = customization.getSelectedStage();
//if there's no current stage - overview should be selected
if (cur_stage == null) {
if (curStage == null) {
//DIRTY HACK, I dunno why, but after activity onResume it's not possible to just check item 0
hack = true;
stages.check(1);
stages.check(0);
hack = false;
description.setText(cur_tour.getShortDescription());
fullDescription.setText(cur_tour.getFulldescription());
description.setText(curTour.getShortDescription());
fullDescription.setText(curTour.getFulldescription());
prepareBitmap();
} else {
int i;
for (i = 1; i < count; i++) {
if (cur_stage.equals(stages_info.get(i - 1)))
if (curStage.equals(stagesInfo.get(i - 1)))
break;
}
if (i != count) {
@ -172,7 +168,7 @@ public class TourViewActivity extends SherlockFragmentActivity {
}
private void prepareBitmap() {
final Bitmap imageBitmap = cur_tour.getImageBitmap();
final Bitmap imageBitmap = curTour.getImageBitmap();
if (imageBitmap != null) {
img.setImageBitmap(imageBitmap);
img.setAdjustViewBounds(true);