How to set photosphere mode when open panorama Android
Asked Answered
C

1

13

I am stuck with a problem when I want open a photosphere picture with my android application. Indeed, I can open it but the application show a sort of preview of the photosphere (it scrolls the picture from left to right). I want that my application open the photosphere with the acceloremeter mode (the mode that we need to turn the phone to show the entire picture) without clicking the button at the bottom right.

I use that code to open the panorama :

Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setComponent(new ComponentName("com.google.android.gms", "com.google.android.gms.panorama.PanoramaViewActivity"));
intent.setData(Uri.parse("file://" + Environment.getExternalStorageDirectory() + "/DCIM/Camera/PANO_20131209_130755.jpg"));
startActivity(intent);

Thanks in advance,

Contractual answered 6/1, 2014 at 15:18 Comment(4)
"file://" + "/sdcard - this is bad approach. See Environment classPantin
Yes i known. I just put this for a test.Contractual
provide the code of buttons that scrolls your image please.Arboretum
Unfortunately, it's currently not possible to supply the mode in which to display the given photo. PanoramaViewActivity only looks at the data Uri set to the incoming Intent, or EXTRA_STREAM if the former is null. There is no 'extra' to supply the mode.Swanger
D
3

Hope the following below helps:

public class YourActivity extends Activity implements ConnectionCallbacks,
        OnConnectionFailedListener {

private GoogleApiClient gacClient;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    gacClient= new GoogleApiClient.Builder(this, this, this)
            .addApi(Panorama.API)
            .build();
}

@Override
public void onStart() {
    super.onStart();
    gacClient.connect();
}

@Override
public void onConnected(Bundle connectionHint) {
    Uri uri = Uri.parse("file://" + Environment.getExternalStorageDirectory() + "/DCIM/Camera/PANO_20131209_130755.jpg");

    Panorama.PanoramaApi.loadPanoramaInfo(gacClient, uri).setResultCallback(
            new ResultCallback<PanoramaResult>() {
        @Override
        public void onResult(PanoramaResult result) {
            Intent i;
            if (result.getStatus().isSuccess() && (i = result.getViewerIntent()) != null) {
                startActivity(i);
            } else {
                // Handle unsuccessful result
            }
        }
    });
}

@Override
public void onConnectionSuspended(int cause) {
    // Handle connection being suspended
}

@Override
public void onConnectionFailed(ConnectionResult status) {
    // Handle connection failure.
}

@Override
public void onStop() {
    super.onStop();
    gacClient.disconnect();
}
}

Below is a link and example of library to use PhotoSphere without Google+:

https://github.com/kennydude/photosphere

Intent i = new Intent(MainActivity.this, SphereViewer.class);
                i.setData(Uri.parse("file://" + Environment.getExternalStorageDirectory() + "/DCIM/Camera/PANO_20131209_130755.jpg"));
                startActivity(i);

PhotoSphere uses gyroscope and not accelerometer, however I am sure you can use the second solution and add your own accelerometer functionality.

Dykstra answered 27/3, 2015 at 22:18 Comment(4)
OP said that "I want that my application open the photosphere with the acceloremeter mode (the mode that we need to turn the phone to show the entire picture) without clicking the button at the bottom right." Looks like your solution opens the photosphere in the preview mode, not accelerometer mode.Hame
I meant that OP wanted to start the panorama in the mode that, quote, "the mode that we need to turn the phone to show the entire picture without clicking the button at the bottom right". Your solution opens the panorama in the preview mode, just like the OP solution does (the only difference is that your solution is adapted to newer API).Hame
Do you know to use SensorEventListener along with SensorManager ?Dykstra
Can this also be used with panorama images in the assets folder? And does the image has to be created with the google camera app?Franky

© 2022 - 2024 — McMap. All rights reserved.