Skip to content

Commit

Permalink
Push after holiday
Browse files Browse the repository at this point in the history
  • Loading branch information
egroeg121 committed Aug 23, 2018
1 parent d4a6e09 commit 761b904
Show file tree
Hide file tree
Showing 11 changed files with 158 additions and 36 deletions.
10 changes: 10 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path="android/app/src/androidTest/java"/>
<classpathentry kind="src" path="android/app/src/main/java"/>
<classpathentry kind="src" path="android/app/src/test/java"/>
<classpathentry kind="lib" path="android/app/libs/connectiq.jar"/>
<classpathentry kind="lib" path="android/gradle/wrapper/gradle-wrapper.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
17 changes: 17 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Sleep-as-Android-Garmin-Addon</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>connectiq.builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>connectiq.projectNature</nature>
</natures>
</projectDescription>
2 changes: 1 addition & 1 deletion android/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,6 @@ dependencies {
implementation 'com.android.support:appcompat-v7:25.0.1'
// compile 'com.urbandroid:common:1.0@aar'
testImplementation 'junit:junit:4.12'
implementation 'org.jetbrains:annotations-java5:15.0'
}

Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ public class MainActivity extends Activity {

private static final String PACKAGE_SLEEP = "com.urbandroid.sleep";
private static final String PACKAGE_GCM = "com.garmin.android.apps.connectmobile";
private static final String PACKAGE_SLEEP_WATCH_STARTER = "com.urbandroid.watchsleepstarter";
private static final String IQ_APP_ID = SleepAsAndroidProviderService.IQ_APP_ID;
private boolean sleepInstalled = true;
private boolean gcmInstalled = true;
private boolean watchappInstalled = true;
private boolean watchsleepstarterInstalled = true;

private ConnectIQ mConnectIQ;
private IQDevice mDevice;
Expand Down Expand Up @@ -149,17 +151,7 @@ protected void onCreate(Bundle savedInstanceState) {
GlobalInitializer.initializeIfRequired(this);
setContentView(R.layout.activity_main);

try {
this.getPackageManager().getApplicationInfo(PACKAGE_SLEEP, 0);
} catch (PackageManager.NameNotFoundException e) {
sleepInstalled = false;
}

try {
this.getPackageManager().getApplicationInfo(PACKAGE_GCM, 0);
} catch (PackageManager.NameNotFoundException e) {
gcmInstalled = false;
}

Logger.logDebug("Main Activity conectIQ intialiszation");

Expand Down Expand Up @@ -200,9 +192,40 @@ public void onClick(View v) {
setupSleep();
}
});
findViewById(R.id.install_watchsleepstarter).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
installSleepWatchStarter();
}
});
}

@Override
protected void onResume() {
super.onResume();

try {
this.getPackageManager().getApplicationInfo(PACKAGE_SLEEP, 0);
} catch (PackageManager.NameNotFoundException e) {
sleepInstalled = false;
}

try {
this.getPackageManager().getApplicationInfo(PACKAGE_GCM, 0);
} catch (PackageManager.NameNotFoundException e) {
gcmInstalled = false;
}

try {
this.getPackageManager().getApplicationInfo(PACKAGE_SLEEP_WATCH_STARTER, 0);
} catch (PackageManager.NameNotFoundException e) {
watchsleepstarterInstalled = false;
}

findViewById(R.id.card_install_saa).setVisibility(!sleepInstalled ? View.VISIBLE : View.GONE);
findViewById(R.id.card_install_gcm).setVisibility(!gcmInstalled ? View.VISIBLE : View.GONE);
findViewById(R.id.card_install_watchsleepstarter).setVisibility(!watchsleepstarterInstalled ? View.VISIBLE : View.GONE);

}

private void setupSleep() {
Expand Down Expand Up @@ -269,4 +292,13 @@ public void onSdkShutDown() {
Logger.logSevere(e);
}
}

private void installSleepWatchStarter(){
try {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id="+PACKAGE_SLEEP_WATCH_STARTER));
startActivity(i);
} catch (Exception e) {
Logger.logSevere(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ public class SleepAsAndroidProviderService extends Service {
final static String HINT = "com.urbandroid.sleep.watch.HINT";
final static String CHECK_CONNECTED = "com.urbandroid.sleep.watch.CHECK_CONNECTED";
final static String REPORT = "com.urbandroid.sleep.watch.REPORT";
final static String ROMPT_NOT_SHOWN = "PROMPT_NOT_SHOWN_ON_DEVICE";

// App Names (app names/user friendly names)
private static final String PACKAGE_SLEEP = "com.urbandroid.sleep";
private static final String PACKAGE_SLEEP_USERFRIENDLY = "Sleep As Android";
private static final String PACKAGE_GCM = "com.garmin.android.apps.connectmobile";
private static final String PACKAGE_GCM_USERFRIENDLY = "Garmin Connect Mobile";
private static final String PACKAGE_SLEEP_WATCH_STARTER = "com.urbandroid.watchsleepstarter";
private static final String PACKAGE_SLEEP_WATCH_STARTER_USERFRIENDLY = "Sleep Watch Starter For Sleep";

// Just for testing
public static final String EXTRA_MESSAGE = "message";
Expand Down Expand Up @@ -115,7 +124,12 @@ public void onCreate() {
handler = new Handler();

// checking if Garmin Connect Mobile installed
if (isAppInstalled("com.garmin.android.apps.connectmobile")) {
if (!isAppInstalled(PACKAGE_SLEEP_WATCH_STARTER)) {
launchPlayStore(PACKAGE_SLEEP_USERFRIENDLY,PACKAGE_SLEEP_WATCH_STARTER);
}

// checking if Garmin Connect Mobile installed
if (isAppInstalled(PACKAGE_GCM)) {
if (GlobalInitializer.debug){
connectIQ = ConnectIQ.getInstance(this, IQConnectType.TETHERED);
}else{
Expand All @@ -125,21 +139,26 @@ public void onCreate() {
//initialize SDK
connectIQ.initialize(this, true, mListener);
} else {
final String appPackageName = "com.garmin.android.apps.connectmobile";
Toast.makeText(getApplicationContext(), "Garmin Connect Mobile not installed", Toast.LENGTH_LONG).show();
try {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName));
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
} catch (android.content.ActivityNotFoundException anfe) {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName));
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
}
launchPlayStore(PACKAGE_GCM_USERFRIENDLY,PACKAGE_GCM);
stopSelf();
}
}



private void launchPlayStore(String userFriendlyName,final String appPackageName){
Toast.makeText(getApplicationContext(), userFriendlyName + " not installed", Toast.LENGTH_LONG).show();
try {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName));
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
} catch (android.content.ActivityNotFoundException anfe) {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName));
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
}
}

@Nullable
@Override
public IBinder onBind(Intent intent) {
Expand Down Expand Up @@ -183,13 +202,16 @@ public void checkAppIsAvailable() {

@Override
public void onApplicationInfoReceived(IQApp app) {


}

@Override
public void onApplicationNotInstalled(String applicationId) {
Toast.makeText(getApplicationContext(), "Sleep not installed on watch", Toast.LENGTH_LONG).show();
Logger.logDebug("Sleep watch app not installed.");
stopSelf();
Toast.makeText(getApplicationContext(), "Sleep not installed on watch", Toast.LENGTH_LONG).show();
Logger.logDebug("Sleep watch app not installed.");
stopSelf();

}
});
} catch (InvalidStateException e) {
Expand Down Expand Up @@ -505,6 +527,9 @@ public int onStartCommand(Intent intent, int flags, int startId) {
connectIQ.openApplication(getDevice(), getApp(), new IQOpenApplicationListener() {
@Override
public void onOpenApplicationResponse(IQDevice iqDevice, IQApp iqApp, IQOpenApplicationStatus iqOpenApplicationStatus) {



}
});
}
Expand All @@ -525,6 +550,9 @@ public void startWatchApp(){
connectIQ.openApplication(getDevice(), getApp(), new IQOpenApplicationListener() {
@Override
public void onOpenApplicationResponse(IQDevice iqDevice, IQApp iqApp, IQOpenApplicationStatus iqOpenApplicationStatus) {
if (iqOpenApplicationStatus == IQOpenApplicationStatus.PROMPT_NOT_SHOWN_ON_DEVICE) {
Toast.makeText(getApplicationContext(), "Failed to start Watch App. Please start manually.", Toast.LENGTH_LONG).show();
}
}
});
}
Expand Down
46 changes: 39 additions & 7 deletions android/app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
<LinearLayout
android:orientation="vertical"
android:background="@drawable/card"
android:id="@+id/card_setup"
android:id="@+id/card_install_watchsleepstarter"
android:paddingTop="16dp"
android:paddingLeft="16dp"
android:layout_marginBottom="8dp"
Expand All @@ -149,24 +149,56 @@
<TextView
android:textColor="@color/secondary"
style="?android:attr/textAppearanceMedium"
android:id="@+id/setup_text"
android:text="@string/setup_text"
android:id="@+id/install_watchsleepstarter_text"
android:text="@string/install_watchsleepstarter"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<Button
android:textStyle="bold"
android:id="@+id/install_watchsleepstarter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:textColor="@color/primary"
android:background="@drawable/button_flat"
android:text="@string/install"
android:textColor="@color/primary"
android:textStyle="bold" />


</LinearLayout>

<LinearLayout
android:id="@+id/card_setup"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="8dp"
android:background="@drawable/card"
android:orientation="vertical"
android:paddingLeft="16dp"
android:paddingTop="16dp">

<TextView
android:id="@+id/setup_text"
style="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/setup_text"
android:textColor="@color/secondary" />

<Button
android:id="@+id/setup"
android:text="@string/setup"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
android:layout_height="wrap_content"
android:layout_gravity="right"
android:background="@drawable/button_flat"
android:text="@string/setup"
android:textColor="@color/primary"
android:textStyle="bold" />

</LinearLayout>



</LinearLayout>

</ScrollView>
Expand Down
1 change: 1 addition & 0 deletions android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
<string name="install">Install</string>
<string name="setup_text">Setup Garmin with Sleep as Android</string>
<string name="setup">Setup</string>
<string name="install_watchsleepstarter">Please Install Sleep Watch Starter for Sleep as Android</string>
<string name="log">LOG appears below</string>
</resources>
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.android.tools.build:gradle:3.1.4'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
4 changes: 2 additions & 2 deletions android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Oct 26 15:26:37 CEST 2017
#Sat Aug 04 14:23:24 BST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
1 change: 1 addition & 0 deletions garmin/source/SleepMainView.mc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class SleepMainView extends Ui.View {
//! the state of this View and prepare it to be shown. This includes
//! loading resources into memory.
function onShow() {
log("")
// bkg_night = Ui.loadResource( Rez.Drawables.id_bkg_night );
log(arrayIndex);
}
Expand Down

0 comments on commit 761b904

Please sign in to comment.