here-android-sdk-examples icon indicating copy to clipboard operation
here-android-sdk-examples copied to clipboard

Picture in Picture mode

Open yousufshawon opened this issue 4 years ago • 7 comments

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.

yousufshawon avatar Apr 25 '20 23:04 yousufshawon

Hi @yousufshawon Currently HERE SDK does not support PIP, but we will consider supporting this in the next release. Thanks.

NazarKacharaba avatar Apr 28 '20 09:04 NazarKacharaba

Thanks for consideration

yousufshawon avatar Apr 28 '20 09:04 yousufshawon

Hi @NazarKacharaba any guess when will be the next release with PIP support. Thanks.

yousufshawon avatar May 02 '20 17:05 yousufshawon

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();
    }
}

NazarKacharaba avatar May 27 '20 08:05 NazarKacharaba

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 avatar May 29 '20 15:05 yousufshawon

@yousufshawon What device do you use? Could you post your code so we can try to reproduce this issue?

NazarKacharaba avatar Jun 03 '20 08:06 NazarKacharaba

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

yousufshawon avatar Jun 03 '20 13:06 yousufshawon