here-android-sdk-examples
here-android-sdk-examples copied to clipboard
Picture in Picture mode
Is HereMap Android sdk support Picture in Picture Mode. I have tried to implement Picture in Picture Mode. The problem i faced is in Picture in Picture Mode Map is not updating its UI. Background instructions are running as expected. But when i switch to PIP mode map just stops its UI render. Any solution on that. How can i solve this.
Hi @yousufshawon Currently HERE SDK does not support PIP, but we will consider supporting this in the next release. Thanks.
Thanks for consideration
Hi @NazarKacharaba any guess when will be the next release with PIP support. Thanks.
We added PIP support in AndroidXMapFragment in 3.16 that is going to be release by the end of June.
However you actually can achieve PIP mode with MapView
right now. In your Activity
or Fragment
override following methods:
@Override
protected void onResume() {
super.onResume();
mapView.onResume();
MapEngine.getInstance().onResume();
}
@Override
protected void onPause() {
super.onPause();
mapView.onPause();
MapEngine.getInstance().onPause();
}
@Override
public void onPictureInPictureModeChanged(boolean entered, Configuration confing) {
super.onPictureInPictureModeChanged(entered, confing);
if (entered) {
mapView.onResume();
MapEngine.getInstance().onResume();
} else {
mapView.onPause();
MapEngine.getInstance().onPause();
}
}
Thanks for suggestion. I have added your suggested code in my Activity but when my app enter into PIP mode the minimized window becomes black. Any suggestion for that.
@yousufshawon What device do you use? Could you post your code so we can try to reproduce this issue?
My Device Model: Motorola one(XT1941-4) Android Version: 10
Here is my code. Please let me know I have done anything wrong
@Override
protected void onCreate(Bundle savedInstanceState) {
...............
initHereMap();
}
private void initHereMap(){
MapEngine.getInstance().init(new ApplicationContext(getApplicationContext()), this);
if(!MapEngine.isInitialized()){
Timber.i("Map Not Initialized");
String diskCacheRoot = getFilesDir().getPath() + File.separator + ".here-maps";
boolean success = com.here.android.mpa.common.MapSettings.setIsolatedDiskCacheRootPath( diskCacheRoot,
getString(R.string.hereMapServiceIntentName));
if(!success){
Toast.makeText(getApplicationContext(), "Unable to set isolated disk cache path.", Toast.LENGTH_LONG).show();
return;
}
}else {
Timber.i("Map Initialized");
}
}
@Override
public void onEngineInitializationCompleted(Error error) {
if (error == OnEngineInitListener.Error.NONE) {
if (map == null) {
map = new Map();
}
mapView.setMap(map);
mapView.getMapGesture().addOnGestureListener(gestureListener, 100, true);
map.setZoomLevel(ZOOM_LEVEL);
map.addTransformListener(onTransformListener);
map.setProjectionMode(Map.Projection.MERCATOR);
............
..............
NavigationManager.getInstance().setMap(map);
.....................
NavigationManager.Error navigationError = NavigationManager.getInstance().startNavigation(route);
}
@Override
protected void onResume() {
super.onResume();
mapView.onResume();
MapEngine.getInstance().onResume();
}
@Override
protected void onPause() {
super.onPause();
mapView.onPause();
MapEngine.getInstance().onPause();
}
@Override
public void onBackPressed() {
checkPictureInPictureSupportAndSwitch();
}
private boolean checkPictureInPictureSupportAndSwitch(){
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
if(isSupportPictureInPictureMode()){
return switchPictureInPictureMode();
}else {
Toast.makeText(this, "Picture In Picture mode is not supported in your device", Toast.LENGTH_SHORT).show();
}
}
return false;
}
@RequiresApi(Build.VERSION_CODES.O)
private boolean switchPictureInPictureMode(){
hideControls();
int calculatedWidth = 405;
int calculatedHeight = 720;
Rational aspectRatio = new Rational(calculatedWidth, calculatedHeight);
mPictureInPictureParamsBuilder.setAspectRatio(aspectRatio);
return enterPictureInPictureMode(mPictureInPictureParamsBuilder.build());
}
@Override
public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, Configuration newConfig) {
super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig);
if (isInPictureInPictureMode) {
mapView.onResume();
MapEngine.getInstance().onResume();
}else {
showControls();
mapView.onPause();
MapEngine.getInstance().onPause();
}
}
Please let me know if you need any other info. Thanks