VrPanoramaActivity.java import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.util.Log;import com.google.vr.sdk.widgets.pano.VrPanoramaEv
import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.util.Log; import com.google.vr.sdk.widgets.pano.VrPanoramaEventListener; import com.google.vr.sdk.widgets.pano.VrPanoramaView; import java.io.IOException; import java.io.InputStream; public class VrPanoramaActivity extends AppCompatActivity { private final String TAG = "VrPanoramaView"; private VrPanoramaView vrPanView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); vrPanView = (VrPanoramaView) findViewById(R.id.vr_pan_view); loadImage(); } /** * 加载全景图片 */ private void loadImage() { /**获取assets中的图片,转为流**/ InputStream is = null; try { is = getAssets().open("aa.jpg"); } catch (IOException e) { e.printStackTrace(); } Bitmap bitmap = BitmapFactory.decodeStream(is); /**VrPanoramaView.Options 设置**/ VrPanoramaView.Options options = new VrPanoramaView.Options(); options.inputType = VrPanoramaView.Options.TYPE_MONO; /**设置加载图片监听**/ vrPanView.setEventListener(new VrPanoramaEventListener() { /** * 显示模式改变回调 * 1.默认 * 2.全屏模式 * 3.VR观看模式,即横屏分屏模式 */ @Override public void onDisplayModeChanged(int newDisplayMode) { super.onDisplayModeChanged(newDisplayMode); Log.d(TAG, "onDisplayModeChanged()->newDisplayMode=" + newDisplayMode); } /** * 加载VR图片失败回调 */ @Override public void onLoadError(String errorMessage) { super.onLoadError(errorMessage); Log.d(TAG, "onLoadError()->errorMessage=" + errorMessage); } /** * 加载VR图片成功回调 */ @Override public void onLoadSuccess() { super.onLoadSuccess(); Log.d(TAG, "onLoadSuccess->图片加载成功"); } /** * 点击VR图片回调 */ @Override public void onClick() { super.onClick(); Log.d(TAG, "onClick()"); } }); /**加载VR图片**/ vrPanView.loadImageFromBitmap(bitmap, options); } @Override protected void onPause() { super.onPause(); vrPanView.pauseRendering();//暂停3D渲染和跟踪 } @Override protected void onResume() { super.onResume(); vrPanView.resumeRendering();//恢复3D渲染和跟踪 } @Override protected void onDestroy() { vrPanView.shutdown();//关闭渲染下并释放相关的内存 super.onDestroy(); } }