org.artoolkitx.arx.arxj.camera

## Class CameraPreferencesActivity

- java.lang.Object
- - PreferenceActivity
  - - org.artoolkitx.arx.arxj.camera.CameraPreferencesActivity

-     public class CameraPreferencesActivity
      extends PreferenceActivity

  CameraPreferencesActivity provides a menu which allows the camera and its resolution to be selected interactively by the user.
  To use CameraPreferencesActivity in your own application, add the following to your AndroidManifest.xml:
  \\
  The activity draws on string values provided by ARXJ's strings.xml resource.
  Additionally, if your activity is not based on ARActivity, the following additional additions must be made:
  Once per install of Application and prior to using any of the camera preferences, e.g. in Application.onCreate(), or if not subclassing Application, in Activity.onCreate():
  import android.preference.PreferenceManager; PreferenceManager.setDefaultValues(this, org.artoolkitx.arx.arxj.R.xml.preferences, false);
  When opening the camera:
  import android.os.Build; import android.preference.PreferenceManager; Camera camera = null; if (Build.VERSION.SDK_INT \>= Build.VERSION_CODES.GINGERBREAD) { int cameraIndex = Integer.parseInt(PreferenceManager.getDefaultSharedPreferences (callingContext).getString("pref_cameraIndex", "0")); Camera.open(cameraIndex); } else { else camera = Camera.open(); }
  When configuring camera:
  String camResolution = PreferenceManager.getDefaultSharedPreferences(callingContext ).getString("pref_cameraResolution", getResources().getString(R.string.pref_defaultValue_cameraResolution)); String[] dims = camResolution.split("x", 2); Camera.Parameters parameters = camera.getParameters(); parameters.setPreviewSize(Integer.parseInt(dims[0]), Integer.parseInt(dims[1])); camera.setParameters(parameters);
  To determine if the camera is rear-facing or front-facing:
  boolean frontFacing = false; if (Build.VERSION.SDK_INT \>= Build.VERSION_CODES.GINGERBREAD) { Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); int cameraIndex = Integer.parseInt(PreferenceManager.getDefaultSharedPreferences (callingContext).getString("pref_cameraIndex", "0")); Camera.getCameraInfo(cameraIndex, cameraInfo); if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) frontFacing = true; }

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `CameraPreferencesActivity.ASPECT_RATIO`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `CameraPreferencesActivity()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `CameraPreferencesActivity.ASPECT_RATIO` | `findAspectRatio(int w, int h)` A convenience method which makes it easy to determine the approximate aspect ratio of an image with the given resolution (expressed in pixel width and height).
    `java.lang.String` | `findAspectRatioName(int w, int h)` A convenience method which makes it easy to determine the approximate aspect ratio of an image with the given resolution (expressed in pixel width and height).
    `void` | `onCreate(Bundle savedInstanceState)`
    `protected void` | `onPause()`
    `protected void` | `onResume()`
    `void` | `onSharedPreferenceChanged(SharedPreferences sharedPreferences, java.lang.String key)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### CameraPreferencesActivity

          public CameraPreferencesActivity()

  - ### Method Detail

    - #### onCreate

          public void onCreate(Bundle savedInstanceState)

    - #### onResume

          protected void onResume()

    - #### onSharedPreferenceChanged

          public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
                                                java.lang.String key)

    - #### onPause

          protected void onPause()

    - #### findAspectRatio

          public CameraPreferencesActivity.ASPECT_RATIO findAspectRatio(int w,
                                                                        int h)

      A convenience method which makes it easy to determine the approximate aspect ratio of an image with the given resolution (expressed in pixel width and height). Returns a symbolic constant for the aspect ratio, which makes it easy to determine whether two different resolutions have the same aspect ratio.
      Parameters:
        `w` - Width in pixels
        `h` - Height in pixels
      Returns:
        If a matching commonly-used aspect ratio can be found, returns symbolic constant for that aspect ratio.

    - #### findAspectRatioName

          public java.lang.String findAspectRatioName(int w,
                                                      int h)

      A convenience method which makes it easy to determine the approximate aspect ratio of an image with the given resolution (expressed in pixel width and height).
      Parameters:
        `w` - Width in pixels
        `h` - Height in pixels
      Returns:
        If a matching commonly-used aspect ratio can be found, returns string name for that aspect ratio.