Intelligent Assistant
Chat with our virtual assistant to get answers promptly.
Documents from this version have been archived, and will not continue to be maintained. Please use the latest version.
Panoramas can be presented inside or outside an app.
Panorama presented outside an app: The app obtains an intent by calling the API of the HMS Core Panorama SDK and redirects to Activity in HUAWEI Panorama Kit to present panoramas. In this mode, HUAWEI Panorama Kit uses the loadImageInfo or loadImageInfoWithPermission API to create a window outside the app.
Panorama presented inside an app: The app presents panoramas in its own process by calling getLocalInstance and PanoramaLocalInterface of the HMS Core Panorama SDK. In this mode, HUAWEI Panorama Kit returns a panoramic layer, and the app determines the position to display the layer and whether to superimpose other information (such as ads) on the layer.
You can present a panorama in your app as a view control, so that you can quickly switch between panoramas and change the control mode. The procedure is as follows:
PanoramaLocalInterface getLocalInstance(Context context);
| Parameter | Description |
|---|---|
| context | APP context. To actively trigger an upgrade, pass an Activity object. |
Example:
- PanoramaInterface.PanoramaLocalInterface mLocalInstance = Panorama.getInstance().getLocalInstance(this);
Example:
- if (mLocalInstance.init() != 0) {
- //do something
- return;
- }
This API initializes the resources required by the HMS Core Panorama SDK. Subsequent APIs can be correctly called only if the initialization is successful.
Panoramic image displayed:
int setImage(Uri uri, int type);
| Parameter name | Description |
|---|---|
| uri | URI of the panorama to be loaded. Currently, only URIs starting with file, content, or android.resource are supported. |
| type | Image type. Currently, spherical(IMAGE_TYPE_SPHERICAL) and cylindrical(IMAGE_TYPE_RING) panoramas are supported. |
Example:
- if (mLocalInstance.setImage(uri, PanoramaInterface.IMAGE_TYPE_SPHERICAL) != 0) {
- //do something
- return;
- }
Panoramic video displayed:
Parameter | Description |
type | Type of images decoded from video. |
Example:
- Surface videoSurface = mLocalInstance.getSurface(PanoramaInterface.IMAGE_TYPE_RING);
After obtaining the surface, set it in MediaPlayer.
Example:
- Uri uri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.pano);
- mPlayer = new MediaPlayer();
- try {
- mPlayer.setDataSource(getApplicationContext(), uri);
- } catch (IOException e) {
- e.printStackTrace();
- return;
- }
- mPlayer.setLooping(true);
- mPlayer.setSurface(videoSurface);
If the panoramic video is displayed in a cylindrical manner, set its aspect ratio.
A complete set of sample code is provided in Example.
(Optional) Set the video's aspect ratio.
int setValue(String name, String value);
Parameter | Description |
name | Name of the attribute to be set. |
value | Value of the attribute to be set. |
Example:
- mLocalInstance.setValue(PanoramaInterface.KEY_VIDEO_RATIO, String.valueOf(mPlayer.getVideoWidth() / mPlayer.getVideoHeight()));
To set the aspect ratio of a panoramic video, it is recommended that you use getVideoWidth() and getVideoHeight() to obtain its width and height after mediaplayer.Prepare is called in MediaPlayer.
(Optional)Step 4 : Set an attribute to display panoramas in polar coordinates
int setValue(String name, String value);
| Parameter | Description |
|---|---|
| name | Name of the attribute to be set. |
| value | Value of the attribute to be set. |
Example:
- int ret = mLocalInstance .setValue(PanoramaInterface.KEY_RENDER_MODE, PanoramaInterface.VALUE_RENDER_MODE_POLAR);
- if (ret != ResultCode.SUCCEED) {
- //error process
- }
void setControlMode(int mode);
| Parameter | Description |
|---|---|
| mode | Mode in which the panorama is controlled. Currently, three modes are available: motion control, touch control, or both. updateTouchEvent must be called for touch control. |
Example:
- mLocalInstance.setControlMode(PanoramaInterface.CONTROL_TYPE_POSE); // CONTROL_TYPE_TOUCH or CONTROL_TYPE_MIX
Notes:
You can call this API to change the control mode as needed.
Example:
- View view = mLocalInstance.getView();
- // Directly present the panorama.
- setContentView(view);
You can add the obtained view to your layout as needed.
void updateTouchEvent(MotionEvent event);
| Parameter | Description |
|---|---|
| event | Android touch event |
Example:
- View view = mLocalInstance.getView();
- view.setOnTouchListener(new View.OnTouchListener() {
- @Override
- public boolean onTouch(View v, MotionEvent event) {
- if (mLocalInstance != null) {
- mLocalInstance.updateTouchEvent(event);
- }
- return true;
- }
- });
Step 8: Deinitialize the local object
Example:
- mLocalInstance.deInit();
If the service of presenting panoramas in an app is no longer needed, call this API to release resources. Otherwise, resource leak may occur.
Panoramic image displayed:
- public class LocalDisplayActivity extends AppCompatActivity implements View.OnClickListener, View.OnTouchListener {
- private static final String LOG_TAG = "PanoramaKitDemo";
- private PanoramaInterface.PanoramaLocalInterface mLocalInstance;
- private ImageButton mImageButton;
- private boolean mChangeButtonCompass = false;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.display_err);
- final Uri uri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.panoramaPic);
- // get PanoramaLocalInterface instance
- mLocalInstance = Panorama.getInstance().getLocalInstance(this);
- // Judge whether init and setimage are successful
- if (mLocalInstance.init() == 0 && mLocalInstance.setImage(uri, PanoramaInterface.IMAGE_TYPE_SPHERICAL) == 0) {
- // getview and add to layout
- RelativeLayout layout = findViewById(R.id.relativeLayout);
- View view = mLocalInstance.getView();
- layout.addView(view);
- // update MotionEvent to sdk
- view.setOnTouchListener(this);
- // change control mode
- mImageButton = findViewById(R.id.changeButton);
- mImageButton.bringToFront();
- mImageButton.setOnClickListener(this);
- } else {
- Log.e(LOG_TAG, "local api error");
- Toast.makeText(this, "Local init error!", Toast.LENGTH_LONG).show();
- }
- }
- @Override
- public void onClick(View v) {
- if (v.getId() == R.id.changeButton) {
- if (mChangeButtonCompass) {
- mImageButton.setImageDrawable(getResources().getDrawable(R.drawable.ic_touch));
- mChangeButtonCompass = false;
- mLocalInstance.setControlMode(PanoramaInterface.CONTROL_TYPE_TOUCH);
- } else {
- mImageButton.setImageDrawable(getResources().getDrawable(R.drawable.ic_compass));
- mChangeButtonCompass = true;
- mLocalInstance.setControlMode(PanoramaInterface.CONTROL_TYPE_POSE);
- }
- }
- }
- @Override
- public boolean onTouch(View v, MotionEvent event) {
- if (mLocalInstance!= null) {
- mLocalInstance.updateTouchEvent(event);
- }
- return true;
- }
- @Override
- protected void onDestroy() {
- if (mLocalInstance != null) {
- mLocalInstance.deInit();
- }
- super.onDestroy();
- }
- }
- public class LocalDisplayActivity extends AppCompatActivity implements View.OnClickListener, View.OnTouchListener {
- private static final String LOG_TAG = "PanoramaKitDemo";
- private PanoramaInterface.PanoramaLocalInterface mLocalInstance;
- private ImageButton mImageButton;
- private boolean mChangeButtonCompass = false;
- private MediaPlayer mPlayer;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.display_layout);
- final Uri uri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.video);
- // Obtain the PanoramaLocalInterface object.
- mLocalInstance = Panorama.getInstance().getLocalInstance(this);
- // Check whether the initialization and image settings are successful.
- if (mLocalInstance.init() == 0) {
- Surface videoSurface = mLocalInstance.getSurface(PanoramaInterface.IMAGE_TYPE_SPHERICAL);
- if (videoSurface == null) {
- Log.e(LOG_TAG, "videoSurface is null");
- return;
- }
- mPlayer = new MediaPlayer();
- try {
- mPlayer.setDataSource(getApplicationContext(), uri);
- } catch (IOException e) {
- e.printStackTrace();
- return;
- }
- mPlayer.setLooping(true);
- mPlayer.setSurface(videoSurface);
- try {
- mPlayer.prepare();
- } catch(IOException e) {
- Log.e(LOG_TAG, "Media Player prepare exception");
- }
- mPlayer.start();
- // Obtain the view and add it to the layout.
- RelativeLayout layout = findViewById(R.id.relativeLayout);
- View view = mLocalInstance.getView();
- layout.addView(view);
- // Update the touch event to the SDK.
- view.setOnTouchListener(this);
- // Change the control mode.
- mImageButton = findViewById(R.id.changeButton);
- mImageButton.bringToFront();
- mImageButton.setOnClickListener(this);
- } else {
- Log.e(LOG_TAG, "local api error");
- Toast.makeText(this, "Local init error!", Toast.LENGTH_LONG).show();
- }
- }
- @Override
- public void onClick(View v) {
- if (v.getId() == R.id.changeButton) {
- if (mChangeButtonCompass) {
- mImageButton.setImageDrawable(getResources().getDrawable(R.drawable.ic_touch));
- mChangeButtonCompass = false;
- mLocalInstance.setControlMode(PanoramaInterface.CONTROL_TYPE_TOUCH);
- } else {
- mImageButton.setImageDrawable(getResources().getDrawable(R.drawable.ic_compass));
- mChangeButtonCompass = true;
- mLocalInstance.setControlMode(PanoramaInterface.CONTROL_TYPE_POSE);
- }
- }
- }
- @Override
- public boolean onTouch(View v, MotionEvent event) {
- if (mLocalInstance!= null) {
- mLocalInstance.updateTouchEvent(event);
- }
- return true;
- }
- @Override
- protected void onDestroy() {
- Log.d(LOG_TAG, "onDestroy");
- if (mLocalInstance != null) {
- mLocalInstance.deInit();
- }
- super.onDestroy();
- }
- }