Updated StartUp Activity to check for pebble android app being installed, and added buttons to install android app and watch app next to relevant checks on screen.
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="uk.org.openseizuredetector"
|
||||
android:versionCode="29"
|
||||
android:versionName="2.0.8">
|
||||
android:versionCode="30"
|
||||
android:versionName="2.0.9">
|
||||
|
||||
<uses-sdk android:minSdkVersion="14" />
|
||||
|
||||
|
||||
@@ -29,15 +29,33 @@ import android.app.ActivityManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.ServiceConnection;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.FeatureInfo;
|
||||
import android.content.pm.InstrumentationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageInstaller;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PermissionGroupInfo;
|
||||
import android.content.pm.PermissionInfo;
|
||||
import android.content.pm.ProviderInfo;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.content.pm.ServiceInfo;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.XmlResourceParser;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.os.UserHandle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.format.Time;
|
||||
import android.util.Log;
|
||||
import android.view.MenuItem;
|
||||
@@ -345,5 +363,31 @@ public class OsdUtil {
|
||||
return file;
|
||||
}
|
||||
|
||||
public String getPreferredPebbleAppPackageName() {
|
||||
// returns the package name of the preferred Android Pebble App.
|
||||
return "com.getpebble.android.basalt";
|
||||
}
|
||||
|
||||
public String isPebbleAppInstalled() {
|
||||
// Returns the package name of the installed pebble App or null if it is not installed
|
||||
String pkgName;
|
||||
pkgName = "com.getpebble.android";
|
||||
if (isPackageInstalled(pkgName)) return pkgName;
|
||||
pkgName = "com.getpebble.android.basalt";
|
||||
if (isPackageInstalled(pkgName)) return pkgName;
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean isPackageInstalled(String packagename) {
|
||||
PackageManager pm = mContext.getPackageManager();
|
||||
try {
|
||||
pm.getPackageInfo(packagename, PackageManager.GET_ACTIVITIES);
|
||||
//showToast("found "+packagename);
|
||||
return true;
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
//showToast(packagename + " not found");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.preference.PreferenceManager;
|
||||
@@ -63,7 +64,8 @@ public class StartupActivity extends Activity {
|
||||
private SdServiceConnection mConnection;
|
||||
private boolean mStartedMainActivity = false;
|
||||
private Handler mHandler = new Handler(); // used to update ui from mUiTimer
|
||||
|
||||
private boolean mUsingPebbleDataSource = true;
|
||||
private String mPebbleAppPackageName = null;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -92,7 +94,28 @@ public class StartupActivity extends Activity {
|
||||
PreferenceManager.setDefaultValues(this, R.xml.general_prefs, true);
|
||||
PreferenceManager.setDefaultValues(this, R.xml.network_datasource_prefs, true);
|
||||
|
||||
Button b = (Button)findViewById(R.id.settingsButton);
|
||||
|
||||
Button b;
|
||||
b = (Button)findViewById(R.id.installPebbleAppButton);
|
||||
b.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Log.v(TAG, "install Pebble app button clicked");
|
||||
try {
|
||||
mUtil.writeToSysLogFile("Installing Pebble App");
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW)
|
||||
.setData(Uri.parse("market://details?id="+mUtil.getPreferredPebbleAppPackageName()));
|
||||
startActivity(intent);
|
||||
} catch (Exception ex) {
|
||||
Log.v(TAG, "exception starting play store activity " + ex.toString());
|
||||
mUtil.writeToSysLogFile("ERROR Starting play store Activity");
|
||||
mUtil.showToast("Error Starting Google Play Store to Install App - is Play Store instaled?");
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
b = (Button)findViewById(R.id.settingsButton);
|
||||
b.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
@@ -137,22 +160,29 @@ public class StartupActivity extends Activity {
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
mUtil.writeToSysLogFile("StartupActivity.onStart()");
|
||||
TextView tv;
|
||||
|
||||
String versionName = mUtil.getAppVersionName();
|
||||
tv = (TextView)findViewById(R.id.appNameTv);
|
||||
tv.setText("OpenSeizureDetector V"+versionName);
|
||||
|
||||
// Display the DataSource name
|
||||
SharedPreferences SP = PreferenceManager
|
||||
.getDefaultSharedPreferences(getBaseContext());;
|
||||
String dataSourceName = SP.getString("DataSource","Pebble");
|
||||
TextView tv = (TextView)findViewById(R.id.dataSourceTextView);
|
||||
tv = (TextView)findViewById(R.id.dataSourceTextView);
|
||||
tv.setText("DataSource = "+dataSourceName);
|
||||
|
||||
// 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");
|
||||
mUsingPebbleDataSource = false;
|
||||
Button b = (Button) findViewById(R.id.pebbleButton);
|
||||
b.setEnabled(false);
|
||||
b = (Button) findViewById(R.id.installOsdAppButton);
|
||||
b.setEnabled(false);
|
||||
} else {
|
||||
mUsingPebbleDataSource = true;
|
||||
}
|
||||
|
||||
if (mUtil.isServerRunning()) {
|
||||
@@ -246,13 +276,14 @@ public class StartupActivity extends Activity {
|
||||
pb.setIndeterminateDrawable(getResources().getDrawable(R.drawable.start_server));
|
||||
pb.setProgressDrawable(getResources().getDrawable(R.drawable.start_server));
|
||||
} else {
|
||||
tv.setText("Waiting to Connect to Pebble Watch.....");
|
||||
tv.setText("Watch Not Connected");
|
||||
tv.setBackgroundColor(alarmColour);
|
||||
tv.setTextColor(alarmTextColour);
|
||||
pb.setIndeterminate(true);
|
||||
allOk = false;
|
||||
}
|
||||
|
||||
/*
|
||||
// Is Pebble Watch App Running?
|
||||
tv = (TextView) findViewById(R.id.textItem4);
|
||||
pb = (ProgressBar) findViewById(R.id.progressBar4);
|
||||
@@ -260,15 +291,16 @@ public class StartupActivity extends Activity {
|
||||
tv.setText("Watch App Running OK");
|
||||
tv.setBackgroundColor(okColour);
|
||||
tv.setTextColor(okTextColour);
|
||||
pb.setIndeterminateDrawable(getResources().getDrawable(R.drawable.start_server));
|
||||
//pb.setIndeterminateDrawable(getResources().getDrawable(R.drawable.start_server));
|
||||
pb.setProgressDrawable(getResources().getDrawable(R.drawable.start_server));
|
||||
} else {
|
||||
tv.setText("Waiting for Watch App to Start.....");
|
||||
tv.setText("Watch App Not Running");
|
||||
tv.setBackgroundColor(alarmColour);
|
||||
tv.setTextColor(alarmTextColour);
|
||||
pb.setIndeterminate(true);
|
||||
allOk = false;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
// Do we have seizure detector data?
|
||||
@@ -306,6 +338,39 @@ public class StartupActivity extends Activity {
|
||||
allOk = false;
|
||||
}
|
||||
|
||||
// Is Pebble Watch App Installed?
|
||||
tv = (TextView) findViewById(R.id.textItem7);
|
||||
pb = (ProgressBar) findViewById(R.id.progressBar7);
|
||||
boolean pebbleAndroidAppInstalled;
|
||||
mPebbleAppPackageName = mUtil.isPebbleAppInstalled();
|
||||
if (mPebbleAppPackageName!=null)
|
||||
pebbleAndroidAppInstalled = true;
|
||||
else
|
||||
pebbleAndroidAppInstalled = false;
|
||||
|
||||
if (mUsingPebbleDataSource) {
|
||||
if (pebbleAndroidAppInstalled) {
|
||||
tv.setText("Pebble Android App Installed");
|
||||
tv.setBackgroundColor(okColour);
|
||||
tv.setTextColor(okTextColour);
|
||||
pb.setIndeterminateDrawable(getResources().getDrawable(R.drawable.start_server));
|
||||
pb.setProgressDrawable(getResources().getDrawable(R.drawable.start_server));
|
||||
} else {
|
||||
tv.setText("Pebble App NOT Installed: ");
|
||||
tv.setBackgroundColor(alarmColour);
|
||||
tv.setTextColor(alarmTextColour);
|
||||
pb.setIndeterminate(true);
|
||||
allOk = false;
|
||||
}
|
||||
} else {
|
||||
tv.setText("Pebble Android App Not Required");
|
||||
tv.setBackgroundColor(okColour);
|
||||
tv.setTextColor(okTextColour);
|
||||
pb.setIndeterminateDrawable(getResources().getDrawable(R.drawable.start_server));
|
||||
pb.setProgressDrawable(getResources().getDrawable(R.drawable.start_server));
|
||||
}
|
||||
|
||||
|
||||
|
||||
// If all the parameters are ok, close this activity and open the main
|
||||
// user interface activity instead.
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:text="OpenSeizureDetector"
|
||||
android:id="@+id/textView"
|
||||
android:id="@+id/appNameTv"
|
||||
android:layout_gravity="center_horizontal" />
|
||||
|
||||
<TextView
|
||||
@@ -33,6 +33,21 @@
|
||||
android:id="@+id/dataSourceTextView"
|
||||
android:layout_gravity="center_horizontal" />
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
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>
|
||||
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
@@ -46,7 +61,7 @@
|
||||
|
||||
<ProgressBar
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/progressBar1" />
|
||||
|
||||
<TextView
|
||||
@@ -55,8 +70,8 @@
|
||||
android:gravity="center_vertical"
|
||||
android:text="New Text"
|
||||
android:id="@+id/textItem1" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
@@ -73,8 +88,33 @@
|
||||
android:gravity="center_vertical"
|
||||
android:text="New Text"
|
||||
android:id="@+id/textItem2" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<ProgressBar
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/progressBar7" />
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center_vertical"
|
||||
android:autoLink="web"
|
||||
android:text="New Text"
|
||||
android:id="@+id/textItem7" />
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Install Pebble App"
|
||||
android:id="@+id/installPebbleAppButton"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
@@ -86,13 +126,20 @@
|
||||
android:id="@+id/progressBar3" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center_vertical"
|
||||
android:text="New Text"
|
||||
android:id="@+id/textItem3" />
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Configure Pebble"
|
||||
android:id="@+id/pebbleButton"
|
||||
android:layout_gravity="right" />
|
||||
|
||||
</LinearLayout>
|
||||
<!--
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
@@ -102,13 +149,13 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/progressBar4" />
|
||||
<TextView
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center_vertical"
|
||||
android:text="New Text"
|
||||
android:id="@+id/textItem4" />
|
||||
</LinearLayout>
|
||||
|
||||
-->
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
@@ -118,11 +165,16 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/progressBar5" />
|
||||
<TextView
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:text="New Text"
|
||||
android:gravity="center_vertical"
|
||||
android:id="@+id/textItem5" />
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Install Watch App"
|
||||
android:id="@+id/installOsdAppButton" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
@@ -138,45 +190,28 @@
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center_vertical"
|
||||
android:text="New Text"
|
||||
android:autoLink="web"
|
||||
android:id="@+id/textItem6" />
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<!--
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<Button
|
||||
<ProgressBar
|
||||
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>
|
||||
|
||||
|
||||
android:id="@+id/progressBar8" />
|
||||
<TextView
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center_vertical"
|
||||
android:autoLink="web"
|
||||
android:text="New Text"
|
||||
android:id="@+id/textItem8" />
|
||||
</LinearLayout>
|
||||
|
||||
-->
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user