Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TIMOB-12970 Android: Support and document the availableCameras property in Ti.Media. #4450

Merged
merged 5 commits into from
Aug 6, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 8 additions & 7 deletions android/modules/media/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ti.modules.titanium.media"
android:versionCode="1"
android:versionName="1.0">
package="ti.modules.titanium.media"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="8" />
<uses-sdk android:minSdkVersion="10" />

<application android:label="@string/app_name">
</application>
</manifest>
<application android:label="@string/app_name" >
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@

import ti.modules.titanium.media.android.AndroidModule.MediaScannerClient;
import android.app.Activity;
import android.app.Application;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
Expand All @@ -51,6 +50,7 @@
import android.database.Cursor;
import android.graphics.BitmapFactory;
import android.hardware.Camera;
import android.hardware.Camera.CameraInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
Expand All @@ -69,7 +69,6 @@ public class MediaModule extends KrollModule

private static final long[] DEFAULT_VIBRATE_PATTERN = { 100L, 250L };
private static final String PHOTO_DCIM_CAMERA = "/sdcard/dcim/Camera";
private static final String FEATURE_CAMERA_FRONT = "android.hardware.camera.front"; // Needed until api 9 is our minimum supported.

protected static final int MSG_INVOKE_CALLBACK = KrollModule.MSG_LAST_ID + 100;
protected static final int MSG_LAST_ID = MSG_INVOKE_CALLBACK;
Expand Down Expand Up @@ -113,6 +112,9 @@ public class MediaModule extends KrollModule
@Kroll.constant public static final String MEDIA_TYPE_PHOTO = "public.image";
@Kroll.constant public static final String MEDIA_TYPE_VIDEO = "public.video";

@Kroll.constant public static final int CAMERA_FRONT = 0;
@Kroll.constant public static final int CAMERA_REAR = 1;

public MediaModule()
{
super();
Expand Down Expand Up @@ -890,19 +892,40 @@ public void takePicture()
@Kroll.method @Kroll.getProperty
public boolean getIsCameraSupported()
{
Application application = TiApplication.getInstance();
if (application == null) {
Log.w(TAG, "Could not retrieve application instance, returning false for isCameraSupported.", Log.DEBUG_MODE);
return false;
return Camera.getNumberOfCameras() > 0;
}

@Kroll.method
@Kroll.getProperty
public int[] getAvailableCameras()
{
int cameraCount = Camera.getNumberOfCameras();
if (cameraCount == 0) {
return null;
}

PackageManager pm = application.getPackageManager();
if (pm == null) {
Log.w(TAG, "Could not retrieve PackageManager instance, returning false for isCameraSupported.", Log.DEBUG_MODE);
int[] result = new int[cameraCount];

CameraInfo cameraInfo = new CameraInfo();

for (int i = 0; i < cameraCount; i++) {
Camera.getCameraInfo(i, cameraInfo);
switch (cameraInfo.facing) {
case CameraInfo.CAMERA_FACING_FRONT:
result[i] = CAMERA_FRONT;
break;
case CameraInfo.CAMERA_FACING_BACK:
result[i] = CAMERA_REAR;
break;
default:
// This would be odd. As of API level 17,
// there are just the two options.
result[i] = -1;
}
}

return pm.hasSystemFeature(PackageManager.FEATURE_CAMERA) ||
pm.hasSystemFeature(FEATURE_CAMERA_FRONT);
return result;

}
}

2 changes: 1 addition & 1 deletion android/runtime/v8/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
android:label="@string/app_name" >
</application>

</manifest>
</manifest>
24 changes: 23 additions & 1 deletion apidoc/Titanium/Media/Media.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ methods:
Must be called after calling `showCamera` and only when `autohide` is set to `false`.
This method causes the media capture UI to be hidden.
platforms: [iphone, ipad, android]
since: {android: "3.2.0"}
since:
android: "3.2.0"
- name: hideMusicLibrary
summary: Hides the music library.
description: |
Expand Down Expand Up @@ -401,6 +402,20 @@ properties:
type: Number
permission: read-only
platforms: [iphone, ipad]
- name: CAMERA_FRONT
summary: Constant specifying the front camera.
type: Number
permission: read-only
platforms: [iphone, ipad, android]
since:
android: "3.2.0"
- name: CAMERA_REAR
summary: Constant indicating the rear camera.
type: Number
permission: read-only
platforms: [iphone, ipad, android]
since:
android: "3.2.0"
- name: DEVICE_BUSY
summary: Constant for media device busy error.
type: Number
Expand Down Expand Up @@ -845,6 +860,13 @@ properties:
for audio properties on the Media module, but the iPod may be active).
type: Number
platforms: [iphone, ipad]
- name: availableCameras
summary: Array indicating which cameras are available, `CAMERA_FRONT`, `CAMERA_REAR` or both.
type: Array<Number>
platforms: [iphone, ipad, android]
since:
android: "3.2.0"
permission: read-only
- name: availableCameraMediaTypes
summary: Array of media type constants supported for the camera.
type: Array<Object>
Expand Down