Android Open Source - quick3d Helper






From Project

Back to project page quick3d.

License

The source code is released under:

GNU General Public License

If you think the Android project quick3d listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.theiner.quick3d;
/*w  w  w.  j  av a  2 s.  c o  m*/
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Application;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.hardware.Camera;
import android.media.ExifInterface;
import android.os.Environment;
import android.view.Surface;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;

/**
 * Created by TheineT on 22.09.2014.
 */
public class Helper {

    public static void setCameraDisplayOrientation(Activity activity,
                                                   int cameraId, android.hardware.Camera camera) {
        android.hardware.Camera.CameraInfo info =
                new android.hardware.Camera.CameraInfo();
        android.hardware.Camera.getCameraInfo(cameraId, info);
        int rotation = activity.getWindowManager().getDefaultDisplay()
                .getRotation();
        int degrees = 0;
        switch (rotation) {
            case Surface.ROTATION_0:
                degrees = 0;
                break;
            case Surface.ROTATION_90:
                degrees = 90;
                break;
            case Surface.ROTATION_180:
                degrees = 180;
                break;
            case Surface.ROTATION_270:
                degrees = 270;
                break;
        }

        int result;
        if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
            result = (info.orientation + degrees) % 360;
            result = (360 - result) % 360;  // compensate the mirror
        } else {  // back-facing
            result = (info.orientation - degrees + 360) % 360;
        }
        camera.setDisplayOrientation(result);
    }

    public static void setRotationParameter(Activity activity, int cameraId, Camera.Parameters param) {

        android.hardware.Camera.CameraInfo info =
                new android.hardware.Camera.CameraInfo();
        android.hardware.Camera.getCameraInfo(cameraId, info);

        int rotation = activity.getWindowManager().getDefaultDisplay()
                .getRotation();
        rotation = (rotation + 45) / 90 * 90;

        int toRotate = (info.orientation + rotation) % 360;

        param.setRotation(toRotate);
    }

    public static int getPictureSizeIndexForHeight(List<Camera.Size> sizeList, int height, float ratio) {
        int chosenHeight = -1;
        int previousHeight = 0;
        for(int i=0; i<sizeList.size(); i++) {
            float thisRatio = sizeList.get(i).width/(float)sizeList.get(i).height;
            if(thisRatio == ratio)
                if(sizeList.get(i).height < height) {
                    chosenHeight = previousHeight;
                    break;
                } else {
                    previousHeight = i;
                }
        }
        if(chosenHeight == -1)
            chosenHeight = previousHeight;
        return chosenHeight;
    }

    public static File getDir() {
        File sdDir = Environment
                .getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
        return new File(sdDir, "Quick3D");
    }

    public static Bitmap getRotatedBitmap(byte[] bildDaten) {
        Bitmap result = BitmapFactory.decodeByteArray(bildDaten, 0, bildDaten.length);
        if(result.getWidth() > result.getHeight()) {
                Matrix m = new Matrix();
                m.postRotate(90);
                result = Bitmap.createBitmap(result,
                        0, 0, result.getWidth(), result.getHeight(),
                        m, true);
        }
        return result;
    }

    public static void showTraceDialog(Q3DApplication myApp, Activity fromActivity) {
        new AlertDialog.Builder(fromActivity)
                .setTitle("Throwable + Trace")
                .setMessage(myApp.getTrace())
                .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                })
                .show();
    }
}




Java Source Code List

org.theiner.quick3d.ApplicationTest.java
org.theiner.quick3d.Helper.java
org.theiner.quick3d.LeftEyePhoto.java
org.theiner.quick3d.Q3DApplication.java
org.theiner.quick3d.Quick3DMain.java
org.theiner.quick3d.RightEyePhoto.java
org.theiner.quick3d.ShowAnaglyph.java
org.theiner.quick3d.ShowFotos.java
org.theiner.quick3d.ShowWiggle.java