https://code.google.com/archive/p/panoramagl-android/
下載:PanoramaGL_0.2-beta.jar
放到 Android Studio 的 libs |
File >> Project Structure |
程式碼:
package ibeacon.geosense.panorama;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import com.panoramagl.PLCubicPanorama;
import com.panoramagl.PLIPanorama;
import com.panoramagl.PLImage;
import com.panoramagl.PLView;
import com.panoramagl.enumerations.PLCubeFaceOrientation;
import com.panoramagl.hotspots.PLHotspot;
import com.panoramagl.transitions.PLTransitionBlend;
import com.panoramagl.utils.PLUtils;
public class MainActivity extends PLView {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
/**
* This event is fired when root content view is created
* @param contentView current root content view
* @return root content view that Activity will use
*/
@Override
protected View onContentViewCreated(View contentView)
{
//Load layout
ViewGroup mainView = (ViewGroup)this.getLayoutInflater().inflate(R.layout.activity_main, null);
//Add 360 view
mainView.addView(contentView, 0);
loadPanorama();
//Return root content view
return super.onContentViewCreated(mainView);
}
/**load methods*/
@SuppressWarnings("unused")
private void loadPanorama()
{
try
{
Context context = this.getApplicationContext();
PLIPanorama panorama = null;
this.setLocked(true);
PLCubicPanorama cubicPanorama = new PLCubicPanorama();
cubicPanorama.setImage(new PLImage(PLUtils.getBitmap(context, R.raw.front), false), PLCubeFaceOrientation.PLCubeFaceOrientationFront);
cubicPanorama.setImage(new PLImage(PLUtils.getBitmap(context, R.raw.back), false), PLCubeFaceOrientation.PLCubeFaceOrientationBack);
cubicPanorama.setImage(new PLImage(PLUtils.getBitmap(context, R.raw.left), false), PLCubeFaceOrientation.PLCubeFaceOrientationLeft);
cubicPanorama.setImage(new PLImage(PLUtils.getBitmap(context, R.raw.right), false), PLCubeFaceOrientation.PLCubeFaceOrientationRight);
cubicPanorama.setImage(new PLImage(PLUtils.getBitmap(context, R.raw.up), false), PLCubeFaceOrientation.PLCubeFaceOrientationUp);
cubicPanorama.setImage(new PLImage(PLUtils.getBitmap(context, R.raw.down), false), PLCubeFaceOrientation.PLCubeFaceOrientationDown);
panorama = cubicPanorama;
if(panorama != null)
{
//Set camera rotation
panorama.getCamera().lookAt(0.0f, 170.0f);
//Add a hotspot
panorama.addHotspot(new PLHotspot(1, new PLImage(PLUtils.getBitmap(context, R.raw.hotspot), false), 0.0f, 170.0f, 0.05f, 0.05f));
//Reset view
this.reset();
//Load panorama
this.startTransition(new PLTransitionBlend(2.0f), panorama); //or use
//this.setPanorama(panorama);
Toast.makeText(this.getApplicationContext(), "panorama != null ", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(this.getApplicationContext(), "panorama = null ", Toast.LENGTH_SHORT).show();
}
//Unlock panoramic view
this.setLocked(false);
}
catch(Throwable e)
{
Toast.makeText(this.getApplicationContext(), "Error: " + e, Toast.LENGTH_SHORT).show();
}
}
}
顯示情況 |
沒有留言:
張貼留言