Made 'Open Pebble App' compatible with either pebble classic or pebble time app, and added an 'install watch app' button to the start-up screen to allow the user to install the watch app from OpenSeizureDetector.
This commit is contained in:
@@ -32,6 +32,7 @@ import android.content.pm.PackageManager;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
@@ -156,13 +157,7 @@ public class MainActivity extends Activity {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_launch_pebble_app:
|
||||
Log.v(TAG, "action_launch_pebble_app");
|
||||
try {
|
||||
PackageManager pm = this.getPackageManager();
|
||||
Intent pebbleAppIntent = pm.getLaunchIntentForPackage("com.getpebble.android");
|
||||
this.startActivity(pebbleAppIntent);
|
||||
} catch (Exception ex) {
|
||||
Log.v(TAG, "exception starting pebble App " + ex.toString());
|
||||
}
|
||||
mUtil.startPebbleApp();
|
||||
return true;
|
||||
|
||||
case R.id.action_accept_alarm:
|
||||
@@ -185,12 +180,14 @@ public class MainActivity extends Activity {
|
||||
mUtil.bindToServer(this, mConnection);
|
||||
}
|
||||
return true;
|
||||
/* fault beep test does not work with fault timer, so disable test option.
|
||||
case R.id.action_test_fault_beep:
|
||||
Log.v(TAG, "action_test_fault_beep");
|
||||
if (mConnection.mBound) {
|
||||
mConnection.mSdServer.faultWarningBeep();
|
||||
}
|
||||
return true;
|
||||
*/
|
||||
case R.id.action_test_alarm_beep:
|
||||
Log.v(TAG, "action_test_alarm_beep");
|
||||
if (mConnection.mBound) {
|
||||
@@ -299,7 +296,7 @@ public class MainActivity extends Activity {
|
||||
if (mUtil.isServerRunning()) {
|
||||
tv = (TextView) findViewById(R.id.serverStatusTv);
|
||||
if (mConnection.mBound)
|
||||
tv.setText("Server Running OK\n"+mConnection.mSdServer.mSdDataSourceName+" Data Source");
|
||||
tv.setText("Server Running OK\n" + mConnection.mSdServer.mSdDataSourceName + " Data Source");
|
||||
tv.setBackgroundColor(okColour);
|
||||
tv.setTextColor(okTextColour);
|
||||
tv = (TextView) findViewById(R.id.serverIpTv);
|
||||
@@ -428,8 +425,10 @@ public class MainActivity extends Activity {
|
||||
pb.setMax(100);
|
||||
pb.setProgress((int) powerPc);
|
||||
pbDrawable = getResources().getDrawable(R.drawable.progress_bar_blue);
|
||||
if (powerPc > 75) pbDrawable = getResources().getDrawable(R.drawable.progress_bar_yellow);
|
||||
if (powerPc > 100) pbDrawable = getResources().getDrawable(R.drawable.progress_bar_red);
|
||||
if (powerPc > 75)
|
||||
pbDrawable = getResources().getDrawable(R.drawable.progress_bar_yellow);
|
||||
if (powerPc > 100)
|
||||
pbDrawable = getResources().getDrawable(R.drawable.progress_bar_red);
|
||||
|
||||
//pb.getProgressDrawable().setColorFilter(colour, PorterDuff.Mode.SRC_IN);
|
||||
|
||||
@@ -439,8 +438,10 @@ public class MainActivity extends Activity {
|
||||
pb.setMax(100);
|
||||
pb.setProgress((int) specPc);
|
||||
pbDrawable = getResources().getDrawable(R.drawable.progress_bar_blue);
|
||||
if (specPc > 75) pbDrawable = getResources().getDrawable(R.drawable.progress_bar_yellow);
|
||||
if (specPc > 100) pbDrawable = getResources().getDrawable(R.drawable.progress_bar_red);
|
||||
if (specPc > 75)
|
||||
pbDrawable = getResources().getDrawable(R.drawable.progress_bar_yellow);
|
||||
if (specPc > 100)
|
||||
pbDrawable = getResources().getDrawable(R.drawable.progress_bar_red);
|
||||
//pb.getProgressDrawable().setColorFilter(colour, PorterDuff.Mode.SRC_IN);
|
||||
pb.setProgressDrawable(pbDrawable);
|
||||
} else { // Not bound to server
|
||||
|
||||
@@ -187,4 +187,48 @@ public class OsdUtil {
|
||||
Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Open Pebble or Pebble Time app. If it is not installed, open Play store so the user can install it.
|
||||
*/
|
||||
public void startPebbleApp() {
|
||||
// first try to launch the original pebble app
|
||||
Intent pebbleAppIntent;
|
||||
PackageManager pm = mContext.getPackageManager();
|
||||
try {
|
||||
pebbleAppIntent = pm.getLaunchIntentForPackage("com.getpebble.android");
|
||||
mContext.startActivity(pebbleAppIntent);
|
||||
} catch (Exception ex1) {
|
||||
// and if original pebble app fails, try Pebble Time app...
|
||||
Log.v(TAG, "exception starting original pebble App - trying pebble time..." + ex1.toString());
|
||||
try {
|
||||
pebbleAppIntent = pm.getLaunchIntentForPackage("com.getpebble.android.basalt");
|
||||
mContext.startActivity(pebbleAppIntent);
|
||||
} catch (Exception ex2) {
|
||||
// and if that fails, open play store so the user can install it:
|
||||
Log.v(TAG, "exception starting Pebble Time App." + ex2.toString());
|
||||
this.showToast("Error Launching Pebble or Pebble Time App - Please make sure it is installed...");
|
||||
final String appPackageName = "com.getpebble.android.basalt";
|
||||
try {
|
||||
// try using play store app.
|
||||
mContext.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
|
||||
} catch (android.content.ActivityNotFoundException anfe) {
|
||||
// and if play store app is not installed, use browser to open app page.
|
||||
mContext.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Install the OpenSeizureDetector watch app onto the watch.
|
||||
* based on https://forums.getpebble.com/discussion/13128/install-watch-app-pebble-store-from-android-companion-app
|
||||
*/
|
||||
public void installOsdWatchApp() {
|
||||
Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("pebble://appstore/54d28a43e4d94c043f000008"));
|
||||
myIntent.setFlags( Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK );
|
||||
mContext.startActivity(myIntent);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -91,14 +91,16 @@ public class StartupActivity extends Activity {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Log.v(TAG, "pebble button clicked");
|
||||
try {
|
||||
PackageManager pm = getPackageManager();
|
||||
Intent pebbleAppIntent = pm.getLaunchIntentForPackage("com.getpebble.android");
|
||||
startActivity(pebbleAppIntent);
|
||||
} catch (Exception ex) {
|
||||
Log.v(TAG, "exception starting pebble App " + ex.toString());
|
||||
mUtil.startPebbleApp();
|
||||
}
|
||||
});
|
||||
|
||||
b = (Button)findViewById(R.id.installOsdAppButton);
|
||||
b.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Log.v(TAG, "install Osd Watch App button clicked");
|
||||
mUtil.installOsdWatchApp();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -115,11 +117,13 @@ public class StartupActivity extends Activity {
|
||||
TextView tv = (TextView)findViewById(R.id.dataSourceTextView);
|
||||
tv.setText("DataSource = "+dataSourceName);
|
||||
|
||||
// disable pebble configuration button if we have not selected the pebble datasource
|
||||
// disable pebble configuration buttons if we have not selected the pebble datasource
|
||||
if (!dataSourceName.equals("Pebble")) {
|
||||
Log.v(TAG, "Not Pebble Datasource - deactivating Pebble Button");
|
||||
Button b = (Button) findViewById(R.id.pebbleButton);
|
||||
b.setEnabled(false);
|
||||
b = (Button) findViewById(R.id.installOsdAppButton);
|
||||
b.setEnabled(false);
|
||||
}
|
||||
|
||||
if (mUtil.isServerRunning()) {
|
||||
|
||||
@@ -139,21 +139,38 @@
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_horizontal">
|
||||
android:layout_height="wrap_content">
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Edit Settings"
|
||||
android:id="@+id/settingsButton"
|
||||
android:layout_gravity="center_horizontal" />
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_horizontal">
|
||||
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Configure Pebble"
|
||||
android:id="@+id/pebbleButton"
|
||||
android:layout_gravity="center_horizontal" />
|
||||
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Install Watch App"
|
||||
android:id="@+id/installOsdAppButton" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
|
||||
@@ -17,12 +17,13 @@
|
||||
android:showAsAction="never|withText"
|
||||
android:title="Stop Server" />
|
||||
|
||||
<!-- fault beep test does not work because of fault timer so don't show menu option
|
||||
<item
|
||||
android:id="@+id/action_test_fault_beep"
|
||||
android:icon="@drawable/stop_server"
|
||||
android:showAsAction="never|withText"
|
||||
android:title="Test Fault Beep" />
|
||||
|
||||
-->
|
||||
<item
|
||||
android:id="@+id/action_test_alarm_beep"
|
||||
android:icon="@drawable/stop_server"
|
||||
|
||||
Reference in New Issue
Block a user