1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| import android.content.Context;
import android.view.Surface;
import android.view.SurfaceHolder;
public class DisplayManager {
private static final String TAG="DisplayManager";
private Context mContext;
private boolean mReal3dLoaded=false;
private boolean mOpenSenseLoaded=false;
public DisplayManager(Context c) {
mContext=c;
}
public boolean setMode(SurfaceHolder sh, String format) {
String type="";
String mode="";
try { //Real3D lib available
Class c_r3d=Class.forName("com.lge.real3d.Real3D");
Class c_r3di=Class.forName("com.lge.real3d.Real3DInfo");
final String LGE_3D_DISPLAY = "lge.hardware.real3d.barrier.landscape";
if(mContext.getPackageManager().hasSystemFeature(LGE_3D_DISPLAY)) {
android.util.Log.i(TAG, "Using Real3D to set display");
Object r3d=c_r3d.getConstructor(new Class[] {Class.forName("android.view.SurfaceHolder")}).newInstance(sh);
//normal
type="REAL3D_TYPE_NONE";
mode="REAL3D_TYPE_NONE";
if (format.equals("LR")) {
type="REAL3D_TYPE_SS";
mode="REAL3D_ORDER_LR";
}
else if (format.equals("TB")) {
type="REAL3D_TYPE_TB";
mode="REAL3D_ORDER_LR";
}
else if (format.equals("stereo")) {
type="REAL3D_TYPE_PIXEL_INTERLACED";
mode="REAL3D_ORDER_LR";
}
else if (format.equals("interlaced")) {
type="REAL3D_TYPE_ROW_INTERLACED";
mode="REAL3D_ORDER_LR";
}
Object r3di=c_r3di.getConstructor(new Class[] {boolean.class, int.class, int.class}).newInstance(true, c_r3d.getField(type).getInt(int.class), c_r3d.getField(mode).getInt(int.class));
r3d.getClass().getMethod("setReal3DInfo", new Class[] {c_r3di}).invoke(null, r3di);
mReal3dLoaded=true;
return mReal3dLoaded;
}
} catch (Exception e) {
android.util.Log.w(TAG, "Real3D library not available");
}
try {
Class c_ds=Class.forName("com.htc.view.DisplaySetting");
android.util.Log.i(TAG, "Using OpenSense to set display - "+format);
if (format.equals("LR"))
mode="STEREOSCOPIC_3D_FORMAT_SIDE_BY_SIDE";
else if (format.equals("TB"))
mode="STEREOSCOPIC_3D_FORMAT_TOP_BOTTOM";
else if (format.equals("interlaced"))
mode="STEREOSCOPIC_3D_FORMAT_INTERLEAVED";
c_ds.getMethod("setStereoscopic3DFormat", new Class[] {Surface.class, int.class}).invoke(mOpenSenseLoaded, new Object[] {sh.getSurface(), c_ds.getField(mode).getInt(int.class)});
android.util.Log.i(TAG, "OpenSense display mode: "+mode);
mOpenSenseLoaded=true;
return mOpenSenseLoaded;
} catch (Exception e) {
android.util.Log.w(TAG, "OpenSense 3D library not available");
mOpenSenseLoaded=false;
e.printStackTrace();
}
return mReal3dLoaded | mOpenSenseLoaded;
}
} |
Partager