Got the jar working finally

This commit is contained in:
Joe Bowser 2009-11-24 16:51:23 -08:00
parent 5e0f46a682
commit 16dcbfbbfa
2 changed files with 63 additions and 25 deletions

View File

@ -20,8 +20,11 @@ import android.view.MenuItem;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
public class CameraPreview extends Activity implements SurfaceHolder.Callback{
@ -29,6 +32,8 @@ public class CameraPreview extends Activity implements SurfaceHolder.Callback{
private SurfaceView mSurfaceView;
private SurfaceHolder mSurfaceHolder;
private RelativeLayout root;
Camera mCamera;
boolean mPreviewRunning = false;
@ -42,10 +47,33 @@ public class CameraPreview extends Activity implements SurfaceHolder.Callback{
Log.e(TAG, "onCreate");
getWindow().setFormat(PixelFormat.TRANSLUCENT);
setContentView(R.layout.preview);
mSurfaceView = (SurfaceView)findViewById(R.id.surface);
RelativeLayout.LayoutParams containerParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT);
LinearLayout.LayoutParams surfaceParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT, 0.0F);
RelativeLayout.LayoutParams buttonParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
root = new RelativeLayout(this);
root.setLayoutParams(containerParams);
mSurfaceView = new SurfaceView(this);
mSurfaceView.setLayoutParams(surfaceParams);
root.addView(mSurfaceView);
Button stopButton = new Button(this);
stopButton.setText("click");
buttonParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
buttonParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
buttonParams.rightMargin = 5;
buttonParams.topMargin = 5;
stopButton.setLayoutParams(buttonParams);
root.addView(stopButton);
setContentView(root);
mSurfaceHolder = mSurfaceView.getHolder();
mSurfaceHolder.addCallback(this);
mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
@ -53,7 +81,7 @@ public class CameraPreview extends Activity implements SurfaceHolder.Callback{
quality = mIntent.getIntExtra("quality", 100);
Button stopButton = (Button) findViewById(R.id.go);
stopButton.setOnClickListener(mSnapListener);
}

View File

@ -29,8 +29,10 @@ import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.JsResult;
@ -38,11 +40,14 @@ import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebSettings.LayoutAlgorithm;
import android.widget.LinearLayout;
public class DroidGap extends Activity {
private static final String LOG_TAG = "DroidGap";
private WebView appView;
private LinearLayout root;
private String uri;
private PhoneGap gap;
private GeoBroker geo;
@ -60,38 +65,37 @@ public class DroidGap extends Activity {
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
setContentView(R.layout.main);
// This builds the view. We could probably get away with NOT having a LinearLayout, but I like having a bucket!
LinearLayout.LayoutParams containerParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT, 0.0F);
appView = (WebView) findViewById(R.id.appView);
/* This changes the setWebChromeClient to log alerts to LogCat! Important for Javascript Debugging */
LinearLayout.LayoutParams webviewParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT, 1.0F);
root = new LinearLayout(this);
root.setOrientation(LinearLayout.VERTICAL);
root.setBackgroundColor(Color.BLACK);
root.setLayoutParams(containerParams);
appView = new WebView(this);
appView.setLayoutParams(webviewParams);
/* This changes the setWebChromeClient to log alerts to LogCat! Important for Javascript Debugging */
appView.setWebChromeClient(new GapClient(this));
appView.setInitialScale(100);
WebSettings settings = appView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);
/* Bind the appView object to the gap class methods */
bindBrowser(appView);
/* Load a URI from the strings.xml file */
Class<R.string> c = R.string.class;
Field f;
int i = 0;
try {
f = c.getField("url");
i = f.getInt(f);
this.uri = this.getResources().getString(i);
} catch (Exception e)
{
this.uri = "http://www.phonegap.com";
}
appView.loadUrl(this.uri);
root.addView(appView);
setContentView(root);
}
@ -123,6 +127,12 @@ public class DroidGap extends Activity {
appView.addJavascriptInterface(mCompass, "CompassHook");
}
public void loadUrl(String url)
{
appView.loadUrl(url);
}
/**
* Provides a hook for calling "alert" from javascript. Useful for
* debugging your javascript.