[android] Fixed navigation with download-search fragments on tablets.

This commit is contained in:
Dmitry Yunitsky 2015-07-15 20:13:34 +03:00 committed by Alex Zolotarev
parent 4aa3cd7e55
commit c8aefbf33a
4 changed files with 49 additions and 55 deletions

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_mediumAnimTime"
android:fromYDelta="100%p"
android:interpolator="@android:anim/decelerate_interpolator"
android:toYDelta="0"/>

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_mediumAnimTime"
android:fromYDelta="0"
android:interpolator="@android:anim/decelerate_interpolator"
android:toYDelta="100%p"/>

View file

@ -98,11 +98,7 @@ public class DownloadFragment extends BaseMwmListFragment implements View.OnClic
public boolean onBackPressed()
{
if (getDownloadAdapter().onBackPressed())
{
// scroll list view to the top
setSelection(0);
return true;
}
else if (getListAdapter() instanceof DownloadedAdapter)
{
mMode = MODE_DISABLED;
@ -111,12 +107,11 @@ public class DownloadFragment extends BaseMwmListFragment implements View.OnClic
mExtendedAdapter.onResume(getListView());
setListAdapter(mExtendedAdapter);
updateToolbar();
return true;
}
else
navigateUpToParent();
return false;
return true;
}
private void updateToolbar()

View file

@ -409,19 +409,26 @@ public class MWMActivity extends BaseMwmFragmentActivity
hidePlacePage();
Framework.deactivatePopup();
popFragment();
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
Fragment fragment = new SearchFragment();
fragment.setArguments(getIntent().getExtras());
transaction.setCustomAnimations(R.anim.abc_slide_in_bottom, R.anim.abc_slide_out_bottom,
R.anim.abc_slide_in_bottom, R.anim.abc_slide_out_bottom);
transaction.add(R.id.fragment_container, fragment, fragment.getClass().getName());
transaction.addToBackStack(null).commit();
replaceFragment(SearchFragment.class.getName(), true, getIntent().getExtras());
}
else
startActivity(new Intent(this, SearchActivity.class));
}
@Override
public void replaceFragment(String fragmentClassName, boolean addToBackStack, Bundle args)
{
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
Fragment fragment = Fragment.instantiate(this, fragmentClassName, args);
transaction.setCustomAnimations(R.anim.fragment_slide_in_bottom, R.anim.fragment_slide_out_bottom,
R.anim.fragment_slide_in_bottom, R.anim.fragment_slide_out_bottom);
transaction.replace(R.id.fragment_container, fragment, fragment.getClass().getName());
if (addToBackStack)
transaction.addToBackStack(null);
transaction.commit();
}
private void shareMyLocation()
{
final Location loc = LocationHelper.INSTANCE.getLastLocation();
@ -460,17 +467,7 @@ public class MWMActivity extends BaseMwmFragmentActivity
popFragment();
hidePlacePage();
SearchController.getInstance().cancelSearch();
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
Fragment fragment = new DownloadFragment();
final Bundle extras = new Bundle();
extras.putBoolean(DownloadActivity.EXTRA_OPEN_DOWNLOADED_LIST, openDownloadedList);
fragment.setArguments(extras);
transaction.setCustomAnimations(R.anim.abc_slide_in_bottom, R.anim.abc_slide_out_bottom,
R.anim.abc_slide_in_bottom, R.anim.abc_slide_out_bottom);
transaction.add(R.id.fragment_container, fragment, fragment.getClass().getName());
transaction.addToBackStack(null).commit();
replaceFragment(DownloadFragment.class.getName(), true, new Bundle());
mFadeView.fadeIn(false);
}
else
@ -553,14 +550,7 @@ public class MWMActivity extends BaseMwmFragmentActivity
initRoutingBox();
initNavigationButtons();
if (findViewById(R.id.fragment_container) != null)
{
mIsFragmentContainer = true;
// add dummy fragment to enable pop out fragment animations
Fragment fragment = new Fragment();
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.add(R.id.fragment_container, fragment);
transaction.commit();
}
}
private void initMap()
@ -1089,7 +1079,6 @@ public class MWMActivity extends BaseMwmFragmentActivity
mFadeView.fadeOut(false);
}
else if (canFragmentInterceptBackPress())
// TODO close menu & fragments accordingly
return;
else if (popFragment())
{
@ -1108,39 +1097,34 @@ public class MWMActivity extends BaseMwmFragmentActivity
private boolean canFragmentInterceptBackPress()
{
final FragmentManager manager = getSupportFragmentManager();
final int count = manager.getBackStackEntryCount();
if (count < 1) // first fragment is dummy and shouldn't be removed
return false;
DownloadFragment fragment = (DownloadFragment) manager.findFragmentByTag(DownloadFragment.class.getName());
return fragment != null && fragment.onBackPressed();
return fragment != null && fragment.isResumed() && fragment.onBackPressed();
}
private boolean popFragment()
{
final FragmentManager manager = getSupportFragmentManager();
final int count = manager.getBackStackEntryCount();
if (count < 1) // first fragment is dummy and shouldn't be removed
return false;
Fragment fragment = manager.findFragmentByTag(SearchFragment.class.getName());
// TODO we cant pop fragment, if it isn't resumed, cause of 'at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1375)'
// consider other possibilities here
if (fragment != null && fragment.isResumed())
for (String tag : new String[]{SearchFragment.class.getName(), DownloadFragment.class.getName()})
{
manager.popBackStack();
return true;
}
fragment = manager.findFragmentByTag(DownloadFragment.class.getName());
if (fragment != null && fragment.isResumed())
{
manager.popBackStack();
return true;
Fragment fragment = manager.findFragmentByTag(tag);
// TODO we cant pop fragment, if it isn't resumed, cause of 'at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1375)'
// consider other possibilities here
if (fragment != null && fragment.isResumed())
{
manager.popBackStackImmediate();
return true;
}
}
return false;
}
private void popAllFragments()
{
final FragmentManager manager = getSupportFragmentManager();
while (manager.getBackStackEntryCount() > 0)
manager.popBackStackImmediate();
}
// Callbacks from native map objects touch event.
@Override
@ -1238,7 +1222,8 @@ public class MWMActivity extends BaseMwmFragmentActivity
mTvStartRouting.setVisibility(View.VISIBLE);
mIvStartRouting.setVisibility(View.VISIBLE);
mPbRoutingProgress.setVisibility(View.GONE);
if (popFragment() && isMapFaded())
popAllFragments();
if (isMapFaded())
mFadeView.fadeOut(false);
}
}