diff --git a/app/src/main/assets/pebble_sd.pbw b/app/src/main/assets/pebble_sd.pbw new file mode 100644 index 0000000..4ab17a0 Binary files /dev/null and b/app/src/main/assets/pebble_sd.pbw differ diff --git a/app/src/main/java/uk/org/openseizuredetector/SdDataSource.java b/app/src/main/java/uk/org/openseizuredetector/SdDataSource.java index ce62048..ebeeba2 100644 --- a/app/src/main/java/uk/org/openseizuredetector/SdDataSource.java +++ b/app/src/main/java/uk/org/openseizuredetector/SdDataSource.java @@ -73,6 +73,11 @@ public abstract class SdDataSource { Log.v(TAG, "stop()"); } + /** + * Install the watch app on the watch. + */ + public void installWatchApp() { Log.v(TAG,"installWatchApp"); } + /** * Display a Toast message on screen. * @param msg - message to display. diff --git a/app/src/main/java/uk/org/openseizuredetector/SdDataSourcePebble.java b/app/src/main/java/uk/org/openseizuredetector/SdDataSourcePebble.java index e4fce0f..3fd64f2 100644 --- a/app/src/main/java/uk/org/openseizuredetector/SdDataSourcePebble.java +++ b/app/src/main/java/uk/org/openseizuredetector/SdDataSourcePebble.java @@ -24,7 +24,9 @@ package uk.org.openseizuredetector; import android.content.Context; +import android.content.Intent; import android.content.SharedPreferences; +import android.net.Uri; import android.os.Handler; import android.os.Looper; import android.preference.PreferenceManager; @@ -36,6 +38,11 @@ import com.getpebble.android.kit.Constants; import com.getpebble.android.kit.PebbleKit; import com.getpebble.android.kit.util.PebbleDictionary; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.IntBuffer; @@ -576,6 +583,39 @@ public class SdDataSourcePebble extends SdDataSource { } } + /** + * Install the wach app that is bundled in the 'assets' folder of this + * phone app. + * from https://github.com/pebble-examples/pebblekit-android-example/blob/master/android/Eclipse/src/com/getpebble/pebblekitexample/MainActivity.java#L148 + */ + @Override + public void installWatchApp() { + Log.v(TAG, "SdDataSourcePebble.installWatchApp()"); + final String WATCHAPP_FILENAME = "pebble_sd.pbw"; + + try { + // Read .pbw from assets/ + Intent intent = new Intent(Intent.ACTION_VIEW); + File file = new File(mContext.getExternalFilesDir(null), WATCHAPP_FILENAME); + InputStream is = mContext.getResources().getAssets().open(WATCHAPP_FILENAME); + OutputStream os = new FileOutputStream(file); + byte[] pbw = new byte[is.available()]; + is.read(pbw); + os.write(pbw); + is.close(); + os.close(); + + // Install via Pebble Android app + intent.setDataAndType(Uri.fromFile(file), "application/pbw"); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + mContext.startActivity(intent); + } catch (IOException e) { + Toast.makeText(mContext, "App install failed: " + e.getLocalizedMessage(), Toast.LENGTH_LONG).show(); + } + + } + + diff --git a/app/src/main/java/uk/org/openseizuredetector/StartupActivity.java b/app/src/main/java/uk/org/openseizuredetector/StartupActivity.java index 05f5657..7278f0b 100644 --- a/app/src/main/java/uk/org/openseizuredetector/StartupActivity.java +++ b/app/src/main/java/uk/org/openseizuredetector/StartupActivity.java @@ -81,7 +81,6 @@ public class StartupActivity extends Activity { PreferenceManager.setDefaultValues(this, R.xml.camera_prefs, true); PreferenceManager.setDefaultValues(this, R.xml.general_prefs, true); PreferenceManager.setDefaultValues(this, R.xml.network_datasource_prefs, true); - PreferenceManager.setDefaultValues(this, R.xml.pebble_datasource_prefs, false); Button b = (Button)findViewById(R.id.settingsButton); b.setOnClickListener(new View.OnClickListener() { @@ -105,7 +104,9 @@ public class StartupActivity extends Activity { @Override public void onClick(View view) { Log.v(TAG, "pebble button clicked"); - mUtil.startPebbleApp(); + mUtil.showToast("pebble button clicked"); + //mUtil.startPebbleApp(); + mConnection.mSdServer.mSdDataSource.installWatchApp(); } });