This commit is contained in:
Alexander Sytnyk 2017-12-11 18:24:21 +02:00
parent d511e7c103
commit 3792267857
4 changed files with 44 additions and 5 deletions

View file

@ -10,6 +10,7 @@ import android.support.annotation.IdRes;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.view.View; import android.view.View;
import android.view.animation.Animation;
import android.widget.ImageView; import android.widget.ImageView;
import net.osmand.plus.IconsCache; import net.osmand.plus.IconsCache;
@ -18,10 +19,11 @@ import net.osmand.plus.OsmandSettings;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.OsmandActionBarActivity; import net.osmand.plus.activities.OsmandActionBarActivity;
public class BaseOsmAndFragment extends Fragment { public class BaseOsmAndFragment extends Fragment implements TransitionAnimator {
private IconsCache iconsCache; private IconsCache iconsCache;
private int statusBarColor = -1; private int statusBarColor = -1;
private boolean transitionAnimationAllowed = true;
@Override @Override
public void onResume() { public void onResume() {
@ -68,6 +70,27 @@ public class BaseOsmAndFragment extends Fragment {
} }
} }
@Override
public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) {
if (transitionAnimationAllowed) {
return super.onCreateAnimation(transit, enter, nextAnim);
}
Animation anim = new Animation() {
};
anim.setDuration(0);
return anim;
}
@Override
public void disableTransitionAnimation() {
transitionAnimationAllowed = false;
}
@Override
public void enableTransitionAnimation() {
transitionAnimationAllowed = true;
}
@ColorRes @ColorRes
public int getStatusBarColorId() { public int getStatusBarColorId() {
return -1; return -1;

View file

@ -0,0 +1,8 @@
package net.osmand.plus.base;
public interface TransitionAnimator {
void disableTransitionAnimation();
void enableTransitionAnimation();
}

View file

@ -440,7 +440,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
return result; return result;
} }
public boolean hide() { public boolean hide(boolean allowTransitionAnimation) {
boolean result = false; boolean result = false;
if (mapPosition != 0) { if (mapPosition != 0) {
mapActivity.getMapView().setMapPosition(mapPosition); mapActivity.getMapView().setMapPosition(mapPosition);
@ -451,12 +451,19 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
} }
WeakReference<MapContextMenuFragment> fragmentRef = findMenuFragment(); WeakReference<MapContextMenuFragment> fragmentRef = findMenuFragment();
if (fragmentRef != null) { if (fragmentRef != null) {
if (!allowTransitionAnimation) {
fragmentRef.get().disableTransitionAnimation();
}
fragmentRef.get().dismissMenu(); fragmentRef.get().dismissMenu();
result = true; result = true;
} }
return result; return result;
} }
public boolean hide() {
return hide(true);
}
public void updateControlsVisibility(boolean menuVisible) { public void updateControlsVisibility(boolean menuVisible) {
int topControlsVisibility = shouldShowTopControls(menuVisible) ? View.VISIBLE : View.GONE; int topControlsVisibility = shouldShowTopControls(menuVisible) ? View.VISIBLE : View.GONE;
mapActivity.findViewById(R.id.map_center_info).setVisibility(topControlsVisibility); mapActivity.findViewById(R.id.map_center_info).setVisibility(topControlsVisibility);

View file

@ -3,7 +3,6 @@ package net.osmand.plus.mapcontextmenu.other;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -18,12 +17,13 @@ import android.widget.TextView;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.mapcontextmenu.other.ShareMenu.ShareItem; import net.osmand.plus.mapcontextmenu.other.ShareMenu.ShareItem;
import java.util.List; import java.util.List;
public class ShareMenuFragment extends Fragment implements OnItemClickListener { public class ShareMenuFragment extends BaseOsmAndFragment implements OnItemClickListener {
public static final String TAG = "ShareMenuFragment"; public static final String TAG = "ShareMenuFragment";
private ArrayAdapter<ShareItem> listAdapter; private ArrayAdapter<ShareItem> listAdapter;
@ -119,13 +119,14 @@ public class ShareMenuFragment extends Fragment implements OnItemClickListener {
@Override @Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
menu.share(listAdapter.getItem(position)); menu.share(listAdapter.getItem(position));
disableTransitionAnimation();
dismissMenu(); dismissMenu();
} }
public void dismissMenu() { public void dismissMenu() {
menu.getMapActivity().getSupportFragmentManager().popBackStackImmediate(TAG, FragmentManager.POP_BACK_STACK_INCLUSIVE); menu.getMapActivity().getSupportFragmentManager().popBackStackImmediate(TAG, FragmentManager.POP_BACK_STACK_INCLUSIVE);
if (menu.getMapActivity().getContextMenu().isVisible()) { if (menu.getMapActivity().getContextMenu().isVisible()) {
menu.getMapActivity().getContextMenu().hide(); menu.getMapActivity().getContextMenu().hide(false);
} }
} }
} }