mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-20 23:56:20 +08:00
Merge branch 'master' of git://github.com/shazron/phonegap
This commit is contained in:
commit
23aa1e7006
@ -3,5 +3,6 @@
|
||||
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="gen"/>
|
||||
<classpathentry kind="lib" path="libs/commons-codec-1.3.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
@ -23,6 +23,11 @@
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name=".CameraPreview"
|
||||
android:label="@string/app_name" android:screenOrientation="landscape"
|
||||
android:configChanges="orientation|keyboardHidden">
|
||||
<action android:name="android.intent.action.PICK" />
|
||||
</activity>
|
||||
</application>
|
||||
<uses-sdk android:minSdkVersion="3" />
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
<link rel="stylesheet" href="master.css" type="text/css" media="screen" title="no title" charset="utf-8">
|
||||
<script type="text/javascript" charset="utf-8" src="phonegap.js"></script>
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
|
||||
|
||||
var deviceInfo = function(){
|
||||
document.getElementById("platform").innerHTML = device.platform;
|
||||
document.getElementById("version").innerHTML = device.version;
|
||||
@ -55,18 +55,44 @@
|
||||
return result;
|
||||
}
|
||||
|
||||
var preventBehavior = function(e) {
|
||||
var preventBehavior = function(e) {
|
||||
e.preventDefault();
|
||||
};
|
||||
|
||||
function show_pic()
|
||||
{
|
||||
navigator.camera.getPicture(dump_pic, fail, { quality: 50 });
|
||||
}
|
||||
|
||||
function init(){
|
||||
// Android is SLOW!!!! This is not present yet!
|
||||
setTimeout(deviceInfo, 1);
|
||||
document.addEventListener("touchmove", preventBehavior, false);
|
||||
}
|
||||
function dump_pic(data)
|
||||
{
|
||||
var viewport = document.getElementById('viewport');
|
||||
console.log(data);
|
||||
viewport.style.display = "";
|
||||
viewport.style.position = "absolute";
|
||||
viewport.style.top = "10px";
|
||||
viewport.style.left = "10px";
|
||||
document.getElementById("test_img").src = "data:image/jpeg;base64," + data;
|
||||
}
|
||||
|
||||
function close()
|
||||
{
|
||||
var viewport = document.getElementById('viewport');
|
||||
viewport.style.position = "relative";
|
||||
viewport.style.display = "none";
|
||||
}
|
||||
|
||||
function fail(fail)
|
||||
{
|
||||
alert(fail);
|
||||
}
|
||||
|
||||
function init(){
|
||||
document.addEventListener("touchmove", preventBehavior, false);
|
||||
setTimeout(deviceInfo, 1);
|
||||
}
|
||||
|
||||
</script>
|
||||
</script>
|
||||
</head>
|
||||
<body onload="init();" id="stage" class="theme">
|
||||
<h1>Welcome to PhoneGap!</h1>
|
||||
@ -85,6 +111,10 @@
|
||||
<a href="#" class="btn large" onclick="getLocation();">Get Location</a>
|
||||
<a href="tel://411" class="btn large">Call 411</a>
|
||||
<a href="#" class="btn" onclick="beep();">Beep</a>
|
||||
<a href="#" class="btn" onclick="vibrate();">Vibrate</a>
|
||||
<a href="#" class="btn" onclick="vibrate();">Vibrate</a>
|
||||
<a href="#" class="btn large" onclick="show_pic();">Get a Picture</a>
|
||||
<div id="viewport" class="viewport">
|
||||
<img style="width:60px;height:60px" id="test_img" src="" />
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -93,3 +93,7 @@
|
||||
width:308px;
|
||||
padding:1.2em 0;
|
||||
}
|
||||
|
||||
#viewport {
|
||||
display: none;
|
||||
}
|
||||
|
@ -308,6 +308,13 @@ function Device() {
|
||||
this.gap = null;
|
||||
this.uuid = null;
|
||||
try {
|
||||
<<<<<<< HEAD:android/assets/www/phonegap.js
|
||||
if (window['DroidGap'] != undefined && window.DroidGap.exists()) {
|
||||
this.available = true;
|
||||
this.isAndroid = true;
|
||||
this.uuid = window.DroidGap.getUuid();
|
||||
this.gapVersion = window.DroidGap.getVersion();
|
||||
=======
|
||||
if (window.DroidGap) {
|
||||
this.available = true;
|
||||
this.uuid = window.DroidGap.getUuid();
|
||||
@ -315,6 +322,7 @@ function Device() {
|
||||
this.gapVersion = window.DroidGap.getVersion();
|
||||
this.platform = window.DroidGap.getPlatform();
|
||||
this.name = window.DroidGap.getProductName();
|
||||
>>>>>>> 4c08b34a81e55a3146e67a8ad2282b7082b640e0:android/assets/www/phonegap.js
|
||||
} else {
|
||||
this.platform = DeviceInfo.platform;
|
||||
this.version = DeviceInfo.version;
|
||||
@ -510,6 +518,12 @@ function Media(src) {
|
||||
this.src = src;
|
||||
}
|
||||
|
||||
<<<<<<< HEAD:android/assets/www/phonegap.js
|
||||
Media.prototype.record = function() {
|
||||
}
|
||||
|
||||
=======
|
||||
>>>>>>> 4c08b34a81e55a3146e67a8ad2282b7082b640e0:android/assets/www/phonegap.js
|
||||
Media.prototype.play = function() {
|
||||
}
|
||||
|
||||
@ -676,12 +690,8 @@ PhoneGap.addConstructor(function() {
|
||||
* @param {Object} vel
|
||||
* @constructor
|
||||
*/
|
||||
function Position(coords, timestamp) {
|
||||
this.coords = coords;
|
||||
this.timestamp = new Date().getTime();
|
||||
}
|
||||
|
||||
function Coordinates(lat, lng, alt, acc, head, vel) {
|
||||
<<<<<<< HEAD:android/assets/www/phonegap.js
|
||||
function Position(lat, lng, acc, alt, altacc, head, vel) {
|
||||
/**
|
||||
* The latitude of the position.
|
||||
*/
|
||||
@ -698,6 +708,10 @@ function Coordinates(lat, lng, alt, acc, head, vel) {
|
||||
* The altitude of the position.
|
||||
*/
|
||||
this.altitude = alt;
|
||||
/**
|
||||
* The altitude accuracy of the position.
|
||||
*/
|
||||
this.altitudeAccuracy = altacc;
|
||||
/**
|
||||
* The direction the device is moving at the position.
|
||||
*/
|
||||
@ -705,7 +719,11 @@ function Coordinates(lat, lng, alt, acc, head, vel) {
|
||||
/**
|
||||
* The velocity with which the device is moving at the position.
|
||||
*/
|
||||
this.speed = vel;
|
||||
this.velocity = vel;
|
||||
/**
|
||||
* The time that the position was obtained.
|
||||
*/
|
||||
this.timestamp = new Date().getTime();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -880,6 +898,238 @@ UIControls.prototype.createToolBar = function() {};
|
||||
*/
|
||||
UIControls.prototype.setToolBarTitle = function(title) {};
|
||||
|
||||
PhoneGap.addConstructor(function() {
|
||||
window.uicontrols = new UIControls();
|
||||
});
|
||||
/*
|
||||
* This is because strings are not exposed
|
||||
*
|
||||
*/
|
||||
var Device = {
|
||||
|
||||
platform: "",
|
||||
version: "",
|
||||
uuid: "",
|
||||
|
||||
init: function() {
|
||||
Device.platform = DroidGap.getPlatform();
|
||||
Device.version = Droidap.getVersion();
|
||||
Device.uuid = DroidGap.getUuid();
|
||||
},
|
||||
vibrate: function(mills)
|
||||
{
|
||||
DroidGap.vibrate(mills);
|
||||
},
|
||||
beep: function()
|
||||
{
|
||||
DroidGap.beep();
|
||||
}
|
||||
=======
|
||||
function Position(coords, timestamp) {
|
||||
this.coords = coords;
|
||||
this.timestamp = new Date().getTime();
|
||||
}
|
||||
|
||||
function Coordinates(lat, lng, alt, acc, head, vel) {
|
||||
/**
|
||||
* The latitude of the position.
|
||||
*/
|
||||
this.latitude = lat;
|
||||
/**
|
||||
* The longitude of the position,
|
||||
*/
|
||||
this.longitude = lng;
|
||||
/**
|
||||
* The accuracy of the position.
|
||||
*/
|
||||
this.accuracy = acc;
|
||||
/**
|
||||
* The altitude of the position.
|
||||
*/
|
||||
this.altitude = alt;
|
||||
/**
|
||||
* The direction the device is moving at the position.
|
||||
*/
|
||||
this.heading = head;
|
||||
/**
|
||||
* The velocity with which the device is moving at the position.
|
||||
*/
|
||||
this.speed = vel;
|
||||
}
|
||||
|
||||
/**
|
||||
* This class specifies the options for requesting position data.
|
||||
* @constructor
|
||||
*/
|
||||
function PositionOptions() {
|
||||
/**
|
||||
* Specifies the desired position accuracy.
|
||||
*/
|
||||
this.enableHighAccuracy = true;
|
||||
/**
|
||||
* The timeout after which if position data cannot be obtained the errorCallback
|
||||
* is called.
|
||||
*/
|
||||
this.timeout = 10000;
|
||||
}
|
||||
|
||||
/**
|
||||
* This class contains information about any GSP errors.
|
||||
* @constructor
|
||||
*/
|
||||
function PositionError() {
|
||||
this.code = null;
|
||||
this.message = "";
|
||||
}
|
||||
|
||||
PositionError.UNKNOWN_ERROR = 0;
|
||||
PositionError.PERMISSION_DENIED = 1;
|
||||
PositionError.POSITION_UNAVAILABLE = 2;
|
||||
PositionError.TIMEOUT = 3;
|
||||
/**
|
||||
* This class provides access to the device SMS functionality.
|
||||
* @constructor
|
||||
*/
|
||||
function Sms() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends an SMS message.
|
||||
* @param {Integer} number The phone number to send the message to.
|
||||
* @param {String} message The contents of the SMS message to send.
|
||||
* @param {Function} successCallback The function to call when the SMS message is sent.
|
||||
* @param {Function} errorCallback The function to call when there is an error sending the SMS message.
|
||||
* @param {PositionOptions} options The options for accessing the GPS location such as timeout and accuracy.
|
||||
*/
|
||||
Sms.prototype.send = function(number, message, successCallback, errorCallback, options) {
|
||||
|
||||
>>>>>>> 4c08b34a81e55a3146e67a8ad2282b7082b640e0:android/assets/www/phonegap.js
|
||||
}
|
||||
|
||||
PhoneGap.addConstructor(function() {
|
||||
if (typeof navigator.sms == "undefined") navigator.sms = new Sms();
|
||||
});
|
||||
/**
|
||||
* This class provides access to the telephony features of the device.
|
||||
* @constructor
|
||||
*/
|
||||
function Telephony() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls the specifed number.
|
||||
* @param {Integer} number The number to be called.
|
||||
*/
|
||||
Telephony.prototype.call = function(number) {
|
||||
|
||||
}
|
||||
|
||||
PhoneGap.addConstructor(function() {
|
||||
if (typeof navigator.telephony == "undefined") navigator.telephony = new Telephony();
|
||||
});
|
||||
/**
|
||||
* This class exposes mobile phone interface controls to JavaScript, such as
|
||||
* native tab and tool bars, etc.
|
||||
* @constructor
|
||||
*/
|
||||
function UIControls() {
|
||||
this.tabBarTag = 0;
|
||||
this.tabBarCallbacks = {};
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a native tab bar that can have tab buttons added to it which can respond to events.
|
||||
*/
|
||||
UIControls.prototype.createTabBar = function() {};
|
||||
|
||||
/**
|
||||
* Show a tab bar. The tab bar has to be created first.
|
||||
* @param {Object} [options] Options indicating how the tab bar should be shown:
|
||||
* - \c height integer indicating the height of the tab bar (default: \c 49)
|
||||
* - \c position specifies whether the tab bar will be placed at the \c top or \c bottom of the screen (default: \c bottom)
|
||||
*/
|
||||
UIControls.prototype.showTabBar = function(options) {};
|
||||
|
||||
/**
|
||||
* Hide a tab bar. The tab bar has to be created first.
|
||||
*/
|
||||
UIControls.prototype.hideTabBar = function(animate) {};
|
||||
|
||||
/**
|
||||
* Create a new tab bar item for use on a previously created tab bar. Use ::showTabBarItems to show the new item on the tab bar.
|
||||
*
|
||||
* If the supplied image name is one of the labels listed below, then this method will construct a tab button
|
||||
* using the standard system buttons. Note that if you use one of the system images, that the \c title you supply will be ignored.
|
||||
*
|
||||
* <b>Tab Buttons</b>
|
||||
* - tabButton:More
|
||||
* - tabButton:Favorites
|
||||
* - tabButton:Featured
|
||||
* - tabButton:TopRated
|
||||
* - tabButton:Recents
|
||||
* - tabButton:Contacts
|
||||
* - tabButton:History
|
||||
* - tabButton:Bookmarks
|
||||
* - tabButton:Search
|
||||
* - tabButton:Downloads
|
||||
* - tabButton:MostRecent
|
||||
* - tabButton:MostViewed
|
||||
* @param {String} name internal name to refer to this tab by
|
||||
* @param {String} [title] title text to show on the tab, or null if no text should be shown
|
||||
* @param {String} [image] image filename or internal identifier to show, or null if now image should be shown
|
||||
* @param {Object} [options] Options for customizing the individual tab item
|
||||
* - \c badge value to display in the optional circular badge on the item; if null or unspecified, the badge will be hidden
|
||||
*/
|
||||
UIControls.prototype.createTabBarItem = function(name, label, image, options) {};
|
||||
|
||||
/**
|
||||
* Update an existing tab bar item to change its badge value.
|
||||
* @param {String} name internal name used to represent this item when it was created
|
||||
* @param {Object} options Options for customizing the individual tab item
|
||||
* - \c badge value to display in the optional circular badge on the item; if null or unspecified, the badge will be hidden
|
||||
*/
|
||||
UIControls.prototype.updateTabBarItem = function(name, options) {};
|
||||
|
||||
/**
|
||||
* Show previously created items on the tab bar
|
||||
* @param {String} arguments... the item names to be shown
|
||||
* @param {Object} [options] dictionary of options, notable options including:
|
||||
* - \c animate indicates that the items should animate onto the tab bar
|
||||
* @see createTabBarItem
|
||||
* @see createTabBar
|
||||
*/
|
||||
UIControls.prototype.showTabBarItems = function(tabs, options) {};
|
||||
|
||||
/**
|
||||
* Manually select an individual tab bar item, or nil for deselecting a currently selected tab bar item.
|
||||
* @param {String} tabName the name of the tab to select, or null if all tabs should be deselected
|
||||
* @see createTabBarItem
|
||||
* @see showTabBarItems
|
||||
*/
|
||||
UIControls.prototype.selectTabBarItem = function(tab) {};
|
||||
|
||||
/**
|
||||
* Function called when a tab bar item has been selected.
|
||||
* @param {Number} tag the tag number for the item that has been selected
|
||||
*/
|
||||
UIControls.prototype.tabBarItemSelected = function(tag) {
|
||||
if (typeof(this.tabBarCallbacks[tag]) == 'function')
|
||||
this.tabBarCallbacks[tag]();
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a toolbar.
|
||||
*/
|
||||
UIControls.prototype.createToolBar = function() {};
|
||||
|
||||
/**
|
||||
* Function called when a tab bar item has been selected.
|
||||
* @param {String} title the title to set within the toolbar
|
||||
*/
|
||||
UIControls.prototype.setToolBarTitle = function(title) {};
|
||||
|
||||
PhoneGap.addConstructor(function() {
|
||||
window.uicontrols = new UIControls();
|
||||
});
|
||||
@ -891,24 +1141,37 @@ PhoneGap.addConstructor(function() {
|
||||
|
||||
Geolocation.prototype.getCurrentPosition = function(successCallback, errorCallback, options)
|
||||
{
|
||||
<<<<<<< HEAD:android/assets/www/phonegap.js
|
||||
var position = Geo.getCurrentPosition();
|
||||
=======
|
||||
var position = Geo.getCurrentLocation();
|
||||
>>>>>>> 4c08b34a81e55a3146e67a8ad2282b7082b640e0:android/assets/www/phonegap.js
|
||||
this.global_success = successCallback;
|
||||
this.fail = errorCallback;
|
||||
}
|
||||
|
||||
|
||||
// Run the global callback
|
||||
<<<<<<< HEAD:android/assets/www/phonegap.js
|
||||
Geolocation.prototype.gotCurrentPosition = function(lat, lng)
|
||||
=======
|
||||
Geolocation.prototype.gotCurrentPosition = function(lat, lng, alt, altacc, head, vel, stamp)
|
||||
>>>>>>> 4c08b34a81e55a3146e67a8ad2282b7082b640e0:android/assets/www/phonegap.js
|
||||
{
|
||||
if (lat == "undefined" || lng == "undefined")
|
||||
if (lat == 0 || lng == 0)
|
||||
{
|
||||
this.fail();
|
||||
}
|
||||
else
|
||||
{
|
||||
<<<<<<< HEAD:android/assets/www/phonegap.js
|
||||
var p = { "lat" : lat, "lng": lng };
|
||||
this.global_success(p);
|
||||
=======
|
||||
coords = new Coordinates(lat, lng, alt, altacc, head, vel);
|
||||
loc = new Position(coords, stamp);
|
||||
this.global_success(loc);
|
||||
>>>>>>> 4c08b34a81e55a3146e67a8ad2282b7082b640e0:android/assets/www/phonegap.js
|
||||
}
|
||||
}
|
||||
|
||||
@ -937,14 +1200,18 @@ Geolocation.prototype.watchPosition = function(successCallback, errorCallback, o
|
||||
* Retrieve and stop this listener from listening to the GPS
|
||||
*
|
||||
*/
|
||||
<<<<<<< HEAD:android/assets/www/phonegap.js
|
||||
Geolocation.prototype.success(key, lat, lng)
|
||||
=======
|
||||
Geolocation.prototype.success = function(key, lat, lng, alt, altacc, head, vel, stamp)
|
||||
>>>>>>> 4c08b34a81e55a3146e67a8ad2282b7082b640e0:android/assets/www/phonegap.js
|
||||
{
|
||||
var coords = new Coordinates(lat, lng, alt, altacc, head, vel);
|
||||
var loc = new Position(coords, stamp);
|
||||
this.listeners[key].success(loc);
|
||||
}
|
||||
|
||||
Geolocation.prototype.fail = function(key)
|
||||
Geolocation.prototype.fail(key)
|
||||
{
|
||||
this.listeners[key].fail();
|
||||
}
|
||||
@ -954,6 +1221,24 @@ Geolocation.prototype.clearWatch = function(watchId)
|
||||
Geo.stop(watchId);
|
||||
}
|
||||
|
||||
<<<<<<< HEAD:android/assets/www/phonegap.js
|
||||
|
||||
Notification.prototype.vibrate = function(mills)
|
||||
{
|
||||
Device.vibrate(mills);
|
||||
}
|
||||
|
||||
/*
|
||||
* On the Android, we don't beep, we notify you with your
|
||||
* notification! We shouldn't keep hammering on this, and should
|
||||
* review what we want beep to do.
|
||||
*/
|
||||
|
||||
Notification.prototype.beep = function(count, volume)
|
||||
{
|
||||
Device.notify();
|
||||
}
|
||||
=======
|
||||
|
||||
Notification.prototype.vibrate = function(mills)
|
||||
{
|
||||
@ -1047,3 +1332,4 @@ Accelerometer.prototype.clearWatch = function(watchId) {
|
||||
PhoneGap.addConstructor(function() {
|
||||
if (typeof navigator.accelerometer == "undefined") navigator.accelerometer = new Accelerometer();
|
||||
});
|
||||
>>>>>>> 4c08b34a81e55a3146e67a8ad2282b7082b640e0:android/assets/www/phonegap.js
|
||||
|
BIN
libs/commons-codec-1.3.jar
Normal file
BIN
libs/commons-codec-1.3.jar
Normal file
Binary file not shown.
@ -7,4 +7,4 @@
|
||||
# location of the SDK. This is only used by Ant
|
||||
# For customization when using a Version Control System, please read the
|
||||
# header note.
|
||||
sdk-location=/home/bowserj/android-sdk-linux_x86-1.5_r1
|
||||
sdk-location=/home/bowserj/android-sdk-linux_x86-1.5_r3
|
||||
|
23
res/layout/preview.xml
Normal file
23
res/layout/preview.xml
Normal file
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent" android:layout_height="fill_parent"
|
||||
android:orientation="horizontal">
|
||||
<SurfaceView android:id="@+id/surface"
|
||||
android:layout_width="fill_parent" android:layout_height="fill_parent"
|
||||
android:layout_weight="1">
|
||||
</SurfaceView>
|
||||
<Button
|
||||
android:id="@+id/go"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
|
||||
android:text="@string/go"
|
||||
android:minWidth="50dip"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_marginRight="5dip"
|
||||
android:layout_marginTop="5dip"
|
||||
/>
|
||||
|
||||
</RelativeLayout>
|
@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="app_name">PhoneGap</string>
|
||||
<string name="url">file:///android_asset/www/index.html</string>
|
||||
<string name="app_name">PhoneGap</string>
|
||||
<string name="url">file:///android_asset/www/index.html</string>
|
||||
<string name="go">Snap</string>
|
||||
</resources>
|
||||
|
34
src/com/phonegap/demo/CameraLauncher.java
Normal file
34
src/com/phonegap/demo/CameraLauncher.java
Normal file
@ -0,0 +1,34 @@
|
||||
package com.phonegap.demo;
|
||||
|
||||
import android.webkit.WebView;
|
||||
|
||||
|
||||
public class CameraLauncher {
|
||||
|
||||
private WebView mAppView;
|
||||
private DroidGap mGap;
|
||||
int quality;
|
||||
|
||||
CameraLauncher(WebView view, DroidGap gap)
|
||||
{
|
||||
mAppView = view;
|
||||
mGap = gap;
|
||||
}
|
||||
|
||||
public void takePicture(int quality)
|
||||
{
|
||||
mGap.startCamera(quality);
|
||||
}
|
||||
|
||||
/* Return Base64 Encoded String to Javascript */
|
||||
public void processPicture( String js_out )
|
||||
{
|
||||
mAppView.loadUrl("javascript:navigator.camera.win('" + js_out + "');");
|
||||
}
|
||||
|
||||
public void failPicture(String err)
|
||||
{
|
||||
mAppView.loadUrl("javascript:navigator.camera.fail('" + err + "');");
|
||||
}
|
||||
|
||||
}
|
190
src/com/phonegap/demo/CameraPreview.java
Normal file
190
src/com/phonegap/demo/CameraPreview.java
Normal file
@ -0,0 +1,190 @@
|
||||
package com.phonegap.demo;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.graphics.Bitmap.CompressFormat;
|
||||
import android.hardware.Camera;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MenuItem;
|
||||
import android.view.SurfaceHolder;
|
||||
import android.view.SurfaceView;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
|
||||
public class CameraPreview extends Activity implements SurfaceHolder.Callback{
|
||||
|
||||
private static final String TAG = "PhoneGapCamera";
|
||||
private SurfaceView mSurfaceView;
|
||||
private SurfaceHolder mSurfaceHolder;
|
||||
|
||||
Camera mCamera;
|
||||
boolean mPreviewRunning = false;
|
||||
|
||||
int quality;
|
||||
Intent mIntent;
|
||||
|
||||
public void onCreate(Bundle icicle)
|
||||
{
|
||||
super.onCreate(icicle);
|
||||
|
||||
Log.e(TAG, "onCreate");
|
||||
|
||||
getWindow().setFormat(PixelFormat.TRANSLUCENT);
|
||||
|
||||
setContentView(R.layout.preview);
|
||||
mSurfaceView = (SurfaceView)findViewById(R.id.surface);
|
||||
|
||||
mSurfaceHolder = mSurfaceView.getHolder();
|
||||
mSurfaceHolder.addCallback(this);
|
||||
mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
|
||||
mIntent = this.getIntent();
|
||||
|
||||
quality = mIntent.getIntExtra("quality", 100);
|
||||
|
||||
Button stopButton = (Button) findViewById(R.id.go);
|
||||
stopButton.setOnClickListener(mSnapListener);
|
||||
}
|
||||
|
||||
private OnClickListener mSnapListener = new OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
mCamera.takePicture(null, null, mPictureCallback);
|
||||
}
|
||||
};
|
||||
|
||||
public boolean onCreateOptionsMenu(android.view.Menu menu) {
|
||||
MenuItem item = menu.add(0, 0, 0, "goto gallery");
|
||||
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
Uri target = Uri.parse("content://media/external/images/media");
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, target);
|
||||
startActivity(intent);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRestoreInstanceState(Bundle savedInstanceState)
|
||||
{
|
||||
super.onRestoreInstanceState(savedInstanceState);
|
||||
}
|
||||
|
||||
/*
|
||||
* We got the data, send it back to PhoneGap to be handled and processed.
|
||||
*
|
||||
*/
|
||||
|
||||
Camera.PictureCallback mPictureCallback = new Camera.PictureCallback() {
|
||||
public void onPictureTaken(byte[] data, Camera c) {
|
||||
Log.e(TAG, "PICTURE CALLBACK: data.length = " + data.length);
|
||||
storeAndExit(data);
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* We can't just store and exit, because Android freezes up when we try to cram a picture across a process in a Bundle.
|
||||
* We HAVE to compress this data and send back the compressed data
|
||||
*/
|
||||
public void storeAndExit(byte[] data)
|
||||
{
|
||||
ByteArrayOutputStream jpeg_data = new ByteArrayOutputStream();
|
||||
Bitmap myMap = BitmapFactory.decodeByteArray(data, 0, data.length);
|
||||
try {
|
||||
if (myMap.compress(CompressFormat.JPEG, quality, jpeg_data))
|
||||
{
|
||||
byte[] code = jpeg_data.toByteArray();
|
||||
byte[] output = Base64.encodeBase64(code);
|
||||
String js_out = new String(output);
|
||||
mIntent.putExtra("picture", js_out);
|
||||
setResult(RESULT_OK, mIntent);
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
//Do shit here
|
||||
}
|
||||
finish();
|
||||
}
|
||||
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event)
|
||||
{
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
if (keyCode == KeyEvent.KEYCODE_CAMERA || keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_SEARCH) {
|
||||
mCamera.takePicture(null, null, mPictureCallback);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void onResume()
|
||||
{
|
||||
Log.e(TAG, "onResume");
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
protected void onSaveInstanceState(Bundle outState)
|
||||
{
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
protected void onStop()
|
||||
{
|
||||
Log.e(TAG, "onStop");
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
public void surfaceCreated(SurfaceHolder holder)
|
||||
{
|
||||
Log.e(TAG, "surfaceCreated");
|
||||
mCamera = Camera.open();
|
||||
//mCamera.startPreview();
|
||||
}
|
||||
|
||||
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h)
|
||||
{
|
||||
Log.e(TAG, "surfaceChanged");
|
||||
|
||||
// XXX stopPreview() will crash if preview is not running
|
||||
if (mPreviewRunning) {
|
||||
mCamera.stopPreview();
|
||||
}
|
||||
|
||||
Camera.Parameters p = mCamera.getParameters();
|
||||
p.setPreviewSize(w, h);
|
||||
mCamera.setParameters(p);
|
||||
try {
|
||||
mCamera.setPreviewDisplay(holder);
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
mCamera.startPreview();
|
||||
mPreviewRunning = true;
|
||||
}
|
||||
|
||||
public void surfaceDestroyed(SurfaceHolder holder)
|
||||
{
|
||||
Log.e(TAG, "surfaceDestroyed");
|
||||
mCamera.stopPreview();
|
||||
mPreviewRunning = false;
|
||||
mCamera.release();
|
||||
}
|
||||
|
||||
}
|
@ -27,6 +27,7 @@ import java.lang.reflect.Field;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
@ -43,7 +44,8 @@ public class DroidGap extends Activity {
|
||||
private String uri;
|
||||
private PhoneGap gap;
|
||||
private GeoBroker geo;
|
||||
private AccelListener accel;
|
||||
private AccelListener accel;
|
||||
private CameraLauncher launcher;
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
@ -61,7 +63,7 @@ public class DroidGap extends Activity {
|
||||
appView.setWebChromeClient(new GapClient(this));
|
||||
appView.getSettings().setJavaScriptEnabled(true);
|
||||
appView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
|
||||
|
||||
|
||||
/* Bind the appView object to the gap class methods */
|
||||
bindBrowser(appView);
|
||||
|
||||
@ -91,15 +93,16 @@ public class DroidGap extends Activity {
|
||||
|
||||
private void bindBrowser(WebView appView)
|
||||
{
|
||||
// The PhoneGap class handles the Notification and Android Specific crap
|
||||
this.gap = new PhoneGap(this, appView);
|
||||
this.geo = new GeoBroker(appView, this);
|
||||
this.accel = new AccelListener(this, appView);
|
||||
|
||||
gap = new PhoneGap(this, appView);
|
||||
geo = new GeoBroker(appView, this);
|
||||
accel = new AccelListener(this, appView);
|
||||
launcher = new CameraLauncher(appView, this);
|
||||
// This creates the new javascript interfaces for PhoneGap
|
||||
// Ewww - It's called DroidGap again. :(
|
||||
appView.addJavascriptInterface(gap, "DroidGap");
|
||||
appView.addJavascriptInterface(gap, "DroidGap");
|
||||
appView.addJavascriptInterface(geo, "Geo");
|
||||
appView.addJavascriptInterface(accel, "Accel");
|
||||
appView.addJavascriptInterface(launcher, "GapCam");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -127,4 +130,30 @@ public class DroidGap extends Activity {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// This is required to start the camera activity! It has to come from the previous activity
|
||||
public void startCamera(int quality)
|
||||
{
|
||||
Intent i = new Intent(this, CameraPreview.class);
|
||||
i.setAction("android.intent.action.PICK");
|
||||
i.putExtra("quality", quality);
|
||||
startActivityForResult(i, 0);
|
||||
}
|
||||
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent intent)
|
||||
{
|
||||
String data;
|
||||
super.onActivityResult(requestCode, resultCode, intent);
|
||||
if (resultCode == RESULT_OK)
|
||||
{
|
||||
data = intent.getStringExtra("picture");
|
||||
// Send the graphic back to the class that needs it
|
||||
launcher.processPicture(data);
|
||||
}
|
||||
else
|
||||
{
|
||||
launcher.failPicture("Did not complete!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
8
src/com/phonegap/demo/VideoPreview.java
Normal file
8
src/com/phonegap/demo/VideoPreview.java
Normal file
@ -0,0 +1,8 @@
|
||||
package com.phonegap.demo;
|
||||
|
||||
import android.app.Activity;
|
||||
|
||||
|
||||
public class VideoPreview extends Activity {
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user