Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

initial refactoring to separate app from framework

  • Loading branch information...
commit 3078df1527f5177ef50e0dd4591826f8f751106b 1 parent f241c60
@mschoch mschoch authored
View
2  AndroidManifest.xml
@@ -22,7 +22,7 @@
<uses-feature android:name="android.hardware.camera.autofocus"/>
<application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true">
- <activity android:name=".AndroidCouchbaseCallback" android:label="@string/app_name" android:configChanges="orientation|keyboardHidden">
+ <activity android:name="ExampleAppActivity" android:label="@string/app_name" android:configChanges="orientation|keyboardHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
View
62 src/com/couchbase/callback/AndroidCouchbaseCallback.java
@@ -26,6 +26,11 @@
import com.couchbase.android.ICouchbaseDelegate;
import com.phonegap.DroidGap;
+/**
+ * Avoid making changes to this class. If you find the need, please
+ * make suggestions here: https://groups.google.com/forum/#!forum/mobile-couchbase
+ */
+
public class AndroidCouchbaseCallback extends DroidGap
{
public static final String TAG = AndroidCouchbaseCallback.class.getName();
@@ -34,17 +39,47 @@
private ServiceConnection couchbaseService;
private String couchappDatabase;
+ protected boolean showSplashScreen() {
+ return true;
+ }
+
+ protected int getSplashScreenDrawable() {
+ return R.drawable.splash;
+ }
+
+ protected String getDatabaseName() {
+ return findCouchApp();
+ }
+
+ protected String getDesignDocName() {
+ return findCouchApp();
+ }
+
+ protected String getAttachmentPath() {
+ return "/index.html";
+ }
+
+ protected String getCouchAppURL(String host, int port) {
+ return "http://" + host + ":" + port + "/" + getDatabaseName() + "/_design/" + getDesignDocName() + getAttachmentPath();
+ }
+
+ protected void couchbaseStarted(String host, int port) {
+
+ }
+
+
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
- // show the splash screen
- // NOTE: Callback won't show the splash until we try to load a URL
- // so we start a load, with a wait time we should never exceed
- setIntegerProperty("splashscreen", R.drawable.splash);
- loadUrl("file:///android_asset/www/error.html", 30000);
-
+ if(showSplashScreen()) {
+ // show the splash screen
+ // NOTE: Callback won't show the splash until we try to load a URL
+ // so we start a load, with a wait time we should never exceed
+ setIntegerProperty("splashscreen", getSplashScreenDrawable());
+ loadUrl("file:///android_asset/www/error.html", 30000);
+ }
// increase the default timeout
super.setIntegerProperty("loadUrlTimeoutValue", 60000);
@@ -52,7 +87,7 @@ public void onCreate(Bundle savedInstanceState)
couchbaseMobile = new CouchbaseMobile(getBaseContext(), couchCallbackHandler);
try {
// look for a .couch file in the assets folder
- couchappDatabase = findCouchApp();
+ couchappDatabase = getDatabaseName();
if(couchappDatabase != null) {
// if we found one, install it
couchbaseMobile.installDatabase(couchappDatabase + COUCHBASE_DATABASE_SUFFIX);
@@ -71,10 +106,15 @@ public void onCreate(Bundle savedInstanceState)
* @return the name of the database (without the .couch extension)
* @throws IOException
*/
- public String findCouchApp() throws IOException {
+ public String findCouchApp() {
String result = null;
AssetManager assetManager = getAssets();
- String[] assets = assetManager.list("");
+ String[] assets = null;
+ try {
+ assets = assetManager.list("");
+ } catch (IOException e) {
+ Log.e(TAG, "Error listing assets", e);
+ }
if(assets != null) {
for (String asset : assets) {
if(asset.endsWith(COUCHBASE_DATABASE_SUFFIX)) {
@@ -110,11 +150,13 @@ public void couchbaseStarted(String host, int port) {
//stop the load that we started to display the splash screen
cancelLoadUrl();
if(couchappDatabase != null) {
- AndroidCouchbaseCallback.this.loadUrl("http://" + host + ":" + port + "/" + couchappDatabase + "/_design/" + couchappDatabase + "/index.html");
+ AndroidCouchbaseCallback.this.loadUrl(getCouchAppURL(host, port));
}
else {
AndroidCouchbaseCallback.this.loadUrl("file:///android_asset/www/couchapp.html");
}
+
+ AndroidCouchbaseCallback.this.couchbaseStarted(host, port);
}
@Override
View
53 src/com/couchbase/callback/ExampleAppActivity.java
@@ -0,0 +1,53 @@
+package com.couchbase.callback;
+
+/**
+ * This is the main activity for your application.
+ *
+ * You can safely refactor the class name and package to meet your needs.
+ *
+ */
+public class ExampleAppActivity extends AndroidCouchbaseCallback {
+
+ /**
+ * Override this method to do additional work upon startup
+ */
+// @Override
+// public void onCreate(Bundle savedInstanceState) {
+// super.onCreate(savedInstanceState);
+// }
+
+ /**
+ * Override this method to do additional work after Couchbase has started
+ */
+// @Override
+// protected void couchbaseStarted(String host, int port) {
+//
+// }
+
+ /**
+ * Override this method to disable the splash screen
+ */
+// @Override
+// protected boolean showSplashScreen() {
+// return false;
+// }
+
+ /**
+ * Override this method to change the drawable used in the splash screen
+ */
+// @Override
+// protected int getSplashScreenDrawable() {
+// return R.drawable.mySplashScreen;
+// }
+
+ /**
+ * After you've deployed your couchapp you can override this method to
+ * directly return the name of your database, instead of using the
+ * default logic to look for databases in the assets folder
+ */
+// @Override
+// protected String getDatabaseName() {
+// return "mydatabase";
+// }
+
+}
Please sign in to comment.
Something went wrong with that request. Please try again.