Fixed bug when application shows wrong layout after rotation
This commit is contained in:
parent
3fcfa5f2aa
commit
bde478e39a
2 changed files with 71 additions and 56 deletions
|
@ -92,9 +92,9 @@ public class SherpafyTourFragment extends SherlockListFragment {
|
|||
if (si.type == StageItemType.GALLERY) {
|
||||
// ((TourViewActivity) getSherlockActivity()).showGallery(tour);
|
||||
} else if (si.type == StageItemType.OVERVIEW) {
|
||||
((TourViewActivity) getSherlockActivity()).showHtmlFragment(si.header, tour.getFulldescription());
|
||||
((TourViewActivity) getSherlockActivity()).showDetailedOverview(si.header, tour.getFulldescription());
|
||||
} else if (si.type == StageItemType.INSTRUCTIONS) {
|
||||
((TourViewActivity) getSherlockActivity()).showHtmlFragment(si.header, tour.getInstructions());
|
||||
((TourViewActivity) getSherlockActivity()).showDetailedInstructions(si.header, tour.getInstructions());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,12 +48,14 @@ public class TourViewActivity extends SherlockFragmentActivity {
|
|||
private static final int STATE_TOUR_VIEW = 2;
|
||||
private static final int STATE_STAGE_OVERVIEW = 3;
|
||||
private static final int STATE_DETAILED_OVERVIEW = 4;
|
||||
private static final int STATE_DETAILED_INSTRUCTIONS = 5;
|
||||
private static final int STAGE_GALLERY = 6;
|
||||
private static int state = STATE_LOADING;
|
||||
|
||||
|
||||
public static final int APP_EXIT_CODE = 4;
|
||||
public static final String APP_EXIT_KEY = "APP_EXIT_KEY";
|
||||
|
||||
|
||||
|
||||
private SherpafyCustomization customization;
|
||||
private Point displaySize;
|
||||
private ActionBarDrawerToggle mDrawerToggle;
|
||||
|
@ -112,6 +114,12 @@ public class TourViewActivity extends SherlockFragmentActivity {
|
|||
if (getMyApplication().isApplicationInitializing()) {
|
||||
FragmentManager fragmentManager = getSupportFragmentManager();
|
||||
fragmentManager.beginTransaction().replace(R.id.content_frame, new SherpafyLoadingFragment()).commit();
|
||||
} else if (state == STATE_DETAILED_INSTRUCTIONS) {
|
||||
TourInformation tour = (TourInformation) selectedItem;
|
||||
showDetailedInstructions(getString(R.string.sherpafy_instructions), tour.getInstructions());
|
||||
} else if (state == STATE_DETAILED_OVERVIEW) {
|
||||
TourInformation tour = (TourInformation) selectedItem;
|
||||
showDetailedInstructions(getString(R.string.sherpafy_overview), tour.getFulldescription());
|
||||
} else {
|
||||
showSelectedItem();
|
||||
}
|
||||
|
@ -122,50 +130,47 @@ public class TourViewActivity extends SherlockFragmentActivity {
|
|||
if (state == STATE_SELECT_TOUR) {
|
||||
super.onBackPressed();
|
||||
} else if (state == STATE_TOUR_VIEW) {
|
||||
SherpafyHtmlFragment fragment = (SherpafyHtmlFragment) getSupportFragmentManager().findFragmentByTag(String.valueOf(STATE_DETAILED_OVERVIEW));
|
||||
if (fragment != null && fragment.isVisible()) {
|
||||
showSelectedItem();
|
||||
} else {
|
||||
selectMenu(R.string.sherpafy_tours);
|
||||
}
|
||||
selectMenu(R.string.sherpafy_tours);
|
||||
} else if (state == STATE_STAGE_OVERVIEW) {
|
||||
SherpafyStageFragment fragment = (SherpafyStageFragment) getSupportFragmentManager().findFragmentByTag(String.valueOf(state));
|
||||
if (fragment != null) {
|
||||
fragment.onBackPressed();
|
||||
}
|
||||
} else if (state == STATE_DETAILED_OVERVIEW || state == STATE_DETAILED_INSTRUCTIONS) {
|
||||
showSelectedItem();
|
||||
}
|
||||
}
|
||||
|
||||
private ArrayAdapter<Object> setupAdapter() {
|
||||
return new ArrayAdapter<Object>(this, R.layout.sherpafy_drawer_list_item){
|
||||
return new ArrayAdapter<Object>(this, R.layout.sherpafy_drawer_list_item) {
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
Object it = getItem(position);
|
||||
if(convertView == null){
|
||||
if (convertView == null) {
|
||||
convertView = getLayoutInflater().inflate(R.layout.sherpafy_drawer_list_item, null);
|
||||
}
|
||||
final ImageView imView = (ImageView) convertView.findViewById(R.id.Icon);
|
||||
TextView tv = (TextView) convertView.findViewById(R.id.Text);
|
||||
if(it.equals(R.string.sherpafy_tours)) {
|
||||
if (it.equals(R.string.sherpafy_tours)) {
|
||||
imView.
|
||||
setImageResource(R.drawable.icon_sherpafy);
|
||||
setImageResource(R.drawable.icon_sherpafy);
|
||||
tv.setText(getString(R.string.sherpafy_tours));
|
||||
} else if(it instanceof TourInformation){
|
||||
if(selectedItem == it) {
|
||||
} else if (it instanceof TourInformation) {
|
||||
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) {
|
||||
} else if (it instanceof StageInformation) {
|
||||
if (customization.getSelectedStage() == it) {
|
||||
imView.setImageResource(R.drawable.ic_action_gplay_over_light);
|
||||
} else if(selectedItem == it) {
|
||||
} else if (selectedItem == it) {
|
||||
imView.setImageResource(R.drawable.ic_action_ok_light);
|
||||
} else {
|
||||
imView.setImageDrawable(
|
||||
new StageImageDrawable(TourViewActivity.this, StageImageDrawable.MENU_COLOR,
|
||||
(((StageInformation) it).getOrder() + 1)+"", 0));
|
||||
new StageImageDrawable(TourViewActivity.this, StageImageDrawable.MENU_COLOR,
|
||||
(((StageInformation) it).getOrder() + 1) + "", 0));
|
||||
}
|
||||
tv.setText(((StageInformation) it).getName());
|
||||
} else {
|
||||
|
@ -176,19 +181,19 @@ public class TourViewActivity extends SherlockFragmentActivity {
|
|||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void updateActionBarTitle() {
|
||||
if(state == STATE_LOADING) {
|
||||
if (state == STATE_LOADING) {
|
||||
getSupportActionBar().setTitle(R.string.app_name);
|
||||
} else if(state == STATE_SELECT_TOUR) {
|
||||
} else if (state == STATE_SELECT_TOUR) {
|
||||
getSupportActionBar().setTitle(R.string.sherpafy_tours);
|
||||
} else if(state == STATE_TOUR_VIEW) {
|
||||
} else if (state == STATE_TOUR_VIEW) {
|
||||
}
|
||||
invalidateOptionsMenu();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected void onPostCreate(Bundle savedInstanceState) {
|
||||
super.onPostCreate(savedInstanceState);
|
||||
|
@ -216,7 +221,7 @@ public class TourViewActivity extends SherlockFragmentActivity {
|
|||
}
|
||||
|
||||
public MenuItem createMenuItem(Menu m, int id, int titleRes, int iconLight, int iconDark, int menuItemType,
|
||||
final OnMenuItemClickListener listener) {
|
||||
final OnMenuItemClickListener listener) {
|
||||
// int r = getMyApplication().getSettings().isLightActionBar() ? iconLight : iconDark;
|
||||
int r = iconLight;
|
||||
MenuItem menuItem = m.add(0, id, 0, titleRes);
|
||||
|
@ -254,7 +259,7 @@ public class TourViewActivity extends SherlockFragmentActivity {
|
|||
}
|
||||
state = STATE_SELECT_TOUR;
|
||||
setDrawerIndicatorVisible(true);
|
||||
} else if(item instanceof TourInformation) {
|
||||
} else if (item instanceof TourInformation) {
|
||||
state = STATE_TOUR_VIEW;
|
||||
if (fragment == null) {
|
||||
fragment = new SherpafyTourFragment();
|
||||
|
@ -264,7 +269,7 @@ public class TourViewActivity extends SherlockFragmentActivity {
|
|||
fragments.put(item, fragment);
|
||||
}
|
||||
setDrawerIndicatorVisible(true);
|
||||
} else if(item instanceof StageInformation) {
|
||||
} else if (item instanceof StageInformation) {
|
||||
state = STATE_STAGE_OVERVIEW;
|
||||
if (fragment == null) {
|
||||
fragment = new SherpafyStageFragment();
|
||||
|
@ -276,7 +281,7 @@ public class TourViewActivity extends SherlockFragmentActivity {
|
|||
}
|
||||
setDrawerIndicatorVisible(false);
|
||||
}
|
||||
if(fragment != null) {
|
||||
if (fragment != null) {
|
||||
fragmentManager.beginTransaction().replace(R.id.content_frame, fragment, String.valueOf(state)).commit();
|
||||
}
|
||||
selectedItem = item;
|
||||
|
@ -286,41 +291,41 @@ public class TourViewActivity extends SherlockFragmentActivity {
|
|||
drawerAdapter.clear();
|
||||
drawerAdapter.add(R.string.sherpafy_tours);
|
||||
TourInformation selectedTour = customization.getSelectedTour();
|
||||
for(TourInformation it : customization.getTourInformations()) {
|
||||
for (TourInformation it : customization.getTourInformations()) {
|
||||
int insert = drawerAdapter.getCount();
|
||||
if(it == selectedTour) {
|
||||
if (it == selectedTour) {
|
||||
insert = 1;
|
||||
}
|
||||
drawerAdapter.insert(it, insert++);
|
||||
if(it == selectedItem || (selectedItem instanceof StageInformation &&
|
||||
if (it == selectedItem || (selectedItem instanceof StageInformation &&
|
||||
((StageInformation) selectedItem).getTour() == it)) {
|
||||
for(StageInformation st : it.getStageInformation()) {
|
||||
for (StageInformation st : it.getStageInformation()) {
|
||||
drawerAdapter.insert(st, insert++);
|
||||
}
|
||||
} else if(it == selectedTour) {
|
||||
} else if (it == selectedTour) {
|
||||
StageInformation st = customization.getSelectedStage();
|
||||
if(st != null) {
|
||||
if (st != null) {
|
||||
drawerAdapter.insert(st, insert++);
|
||||
}
|
||||
}
|
||||
}
|
||||
updateActionBarTitle();
|
||||
}
|
||||
|
||||
|
||||
private void setDrawerIndicatorVisible(boolean b) {
|
||||
if(mDrawerToggle.isDrawerIndicatorEnabled() != b) {
|
||||
if (mDrawerToggle.isDrawerIndicatorEnabled() != b) {
|
||||
mDrawerToggle.setDrawerIndicatorEnabled(b);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void showSelectedItem() {
|
||||
if(selectedItem != null) {
|
||||
if (selectedItem != null) {
|
||||
selectMenu(selectedItem);
|
||||
} else {
|
||||
if(customization.getSelectedStage() != null) {
|
||||
if (customization.getSelectedStage() != null) {
|
||||
selectMenu(customization.getSelectedStage());
|
||||
} else if(customization.getSelectedTour() != null) {
|
||||
} else if (customization.getSelectedTour() != null) {
|
||||
selectMenu(customization.getSelectedTour());
|
||||
} else {
|
||||
selectMenu(R.string.sherpafy_tours);
|
||||
|
@ -328,7 +333,7 @@ public class TourViewActivity extends SherlockFragmentActivity {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void showFavoriteFragment(StageInformation stage, StageFavorite sf) {
|
||||
FragmentManager fragmentManager = getSupportFragmentManager();
|
||||
setDrawerIndicatorVisible(false);
|
||||
|
@ -340,8 +345,18 @@ public class TourViewActivity extends SherlockFragmentActivity {
|
|||
fragment.setArguments(bl);
|
||||
fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
|
||||
}
|
||||
|
||||
public void showHtmlFragment(String title, String cont) {
|
||||
|
||||
public void showDetailedInstructions(String title, String cont) {
|
||||
state = STATE_DETAILED_INSTRUCTIONS;
|
||||
showHtmlFragment(title, cont);
|
||||
}
|
||||
|
||||
public void showDetailedOverview(String title, String cont) {
|
||||
state = STATE_DETAILED_OVERVIEW;
|
||||
showHtmlFragment(title, cont);
|
||||
}
|
||||
|
||||
private void showHtmlFragment(String title, String cont) {
|
||||
FragmentManager fragmentManager = getSupportFragmentManager();
|
||||
setDrawerIndicatorVisible(false);
|
||||
SherpafyHtmlFragment fragment = new SherpafyHtmlFragment();
|
||||
|
@ -358,18 +373,18 @@ public class TourViewActivity extends SherlockFragmentActivity {
|
|||
download.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
|
||||
startActivity(download);
|
||||
}
|
||||
|
||||
|
||||
public void goToMap(LatLon location) {
|
||||
if(location != null) {
|
||||
if (location != null) {
|
||||
getMyApplication().getSettings().setMapLocationToShow(location.getLatitude(), location.getLongitude(), 16, null);
|
||||
}
|
||||
Intent newIntent = new Intent(this, customization.getMapActivity());
|
||||
newIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
|
||||
this.startActivityForResult(newIntent, 0);
|
||||
}
|
||||
|
||||
|
||||
public void startStage(final StageInformation stage) {
|
||||
if(stage != customization.getSelectedStage() && customization.getSelectedStage() != null) {
|
||||
if (stage != customization.getSelectedStage() && customization.getSelectedStage() != null) {
|
||||
Builder bld = new AlertDialog.Builder(this);
|
||||
bld.setMessage(R.string.start_new_stage);
|
||||
bld.setPositiveButton(R.string.default_buttons_yes, new OnClickListener() {
|
||||
|
@ -378,7 +393,7 @@ public class TourViewActivity extends SherlockFragmentActivity {
|
|||
runStage(stage.getTour(), stage, customization.getSelectedStage() != stage);
|
||||
}
|
||||
});
|
||||
bld.setNegativeButton(R.string.default_buttons_no, null);
|
||||
bld.setNegativeButton(R.string.default_buttons_no, null);
|
||||
bld.show();
|
||||
} else {
|
||||
runStage(stage.getTour(), stage, customization.getSelectedStage() != stage);
|
||||
|
@ -387,16 +402,16 @@ public class TourViewActivity extends SherlockFragmentActivity {
|
|||
|
||||
|
||||
public void startTour(final TourInformation tour) {
|
||||
if(tour != customization.getSelectedTour() && customization.getSelectedTour() != null) {
|
||||
if (tour != customization.getSelectedTour() && customization.getSelectedTour() != null) {
|
||||
Builder bld = new AlertDialog.Builder(this);
|
||||
bld.setMessage(R.string.start_new_stage);
|
||||
bld.setPositiveButton(R.string.default_buttons_yes, new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
startTourImpl(tour);
|
||||
startTourImpl(tour);
|
||||
}
|
||||
});
|
||||
bld.setNegativeButton(R.string.default_buttons_no, null);
|
||||
bld.setNegativeButton(R.string.default_buttons_no, null);
|
||||
bld.show();
|
||||
} else {
|
||||
startTourImpl(tour);
|
||||
|
@ -433,14 +448,14 @@ public class TourViewActivity extends SherlockFragmentActivity {
|
|||
getMyApplication().getSelectedGpxHelper().setGpxFileToDisplay(gpx);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
WptPt lp = gpx.getLastPoint();
|
||||
if(lp != null) {
|
||||
if (lp != null) {
|
||||
TargetPointsHelper targetPointsHelper = getMyApplication().getTargetPointsHelper();
|
||||
targetPointsHelper.navigateToPoint(new LatLon(lp.lat, lp.lon), true, -1, lp.name);
|
||||
getMyApplication().getSettings().navigateDialog();
|
||||
}
|
||||
if(startOver && point != null){
|
||||
if (startOver && point != null) {
|
||||
goToMap(new LatLon(point.lat, point.lon));
|
||||
} else {
|
||||
goToMap(null);
|
||||
|
|
Loading…
Reference in a new issue