2017-02-02 4 views
0

私はいくつかの画像を表示するVRアプリケーションを行っています。私はVrPanoramaViewを使用しています。vrモードでVrPanoViewを表示

私はvrモードで開くために何らかの方法でアクティビティを起動しますか?代わりに

panoViewのVRのボタンをクリックするとここに私のコードです:

public class MainVrActivity extends Activity 
{ 

    private VrPanoramaView panoWidgetView; 
    private ImageLoaderTask backgroundImageLoaderTask; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main_vr); 

     panoWidgetView = (VrPanoramaView) findViewById(R.id.pano_view); 

     loadPanoImage(); 

    } 


    @Override 
    public void onPause() { 
     panoWidgetView.pauseRendering(); 
     super.onPause(); 
    } 

    @Override 
    public void onResume() { 
     panoWidgetView.resumeRendering(); 
     super.onResume(); 
    } 

    @Override 
    public void onDestroy() { 
     // Destroy the widget and free memory. 
     panoWidgetView.shutdown(); 
     super.onDestroy(); 
    } 

    private synchronized void loadPanoImage() { 
     ImageLoaderTask task = backgroundImageLoaderTask; 
     if (task != null && !task.isCancelled()) { 
      // Cancel any task from a previous loading. 
      task.cancel(true); 
     } 

     // pass in the name of the image to load from assets. 
     VrPanoramaView.Options viewOptions = new VrPanoramaView.Options(); 
     viewOptions.inputType = VrPanoramaView.Options.TYPE_STEREO_OVER_UNDER; 

     // use the name of the image in the assets/ directory. 
     String panoImageName = "Converted.jpg"; 

     // create the task passing the widget view and call execute to start. 
     task = new ImageLoaderTask(panoWidgetView, viewOptions, panoImageName); 
     task.execute(getAssets()); 
     backgroundImageLoaderTask = task; 
    } 

} 

    public class ImageLoaderTask extends AsyncTask<AssetManager, Void, Bitmap> { 

    /*We use a WeakReference for the VrPanoramaView since the view could be destroyed while loading the image. 
    *A common cause of this is rotating the phone to another orientation. By using a weak reference, 
    *the object can be garbage collected immediately instead of waiting for this async task to be destroyed. 
    */ 
    private static final String TAG = "ImageLoaderTask"; 
    private final String assetName; 
    private final WeakReference<VrPanoramaView> viewReference; 
    private final VrPanoramaView.Options viewOptions; 

    private static WeakReference<Bitmap> lastBitmap = new WeakReference<>(null); 
    private static String lastName; 

    @Override 
    protected Bitmap doInBackground(AssetManager... params) { 
     AssetManager assetManager = params[0]; 

     if (assetName.equals(lastName) && lastBitmap.get() != null) { 
      return lastBitmap.get(); 
     } 

     try(InputStream istr = assetManager.open(assetName)) { 
      Bitmap b = BitmapFactory.decodeStream(istr); 
      lastBitmap = new WeakReference<>(b); 
      lastName = assetName; 
      return b; 
     } catch (IOException e) { 
      Log.e(TAG, "Could not decode default bitmap: " + e); 
      return null; 
     } 
    } 

    //Displaying the image 
    @Override 
    protected void onPostExecute(Bitmap bitmap) { 
     final VrPanoramaView vw = viewReference.get(); 
     if (vw != null && bitmap != null) { 
      vw.loadImageFromBitmap(bitmap, viewOptions); 
     } 
    } 

    public ImageLoaderTask(VrPanoramaView view, VrPanoramaView.Options viewOptions, String assetName) { 
     viewReference = new WeakReference<>(view); 
     this.viewOptions = viewOptions; 
     this.assetName = assetName; 
    } 

} 

答えて

0

あなたはVrWidgetView#setDisplayModeで表示モードを設定することができます。

panoWidgetView.setDisplayMode(VrWidgetView.DisplayMode.FULLSCREEN_STEREO);

関連する問題