Skip to content

Commit

Permalink
Make watch app more helpful and descriptive
Browse files Browse the repository at this point in the history
Also adds a button to open the README on the phone.
  • Loading branch information
blunden committed Oct 31, 2023
1 parent c09160e commit e0d7c17
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 22 deletions.
8 changes: 5 additions & 3 deletions wear/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 33
buildToolsVersion '33.0.2'
compileSdkVersion 34
buildToolsVersion '34.0.0'

defaultConfig {
applicationId "se.blunden.donotdisturbsync"
Expand All @@ -22,8 +22,10 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.google.android.support:wearable:2.9.0'
implementation 'com.google.android.gms:play-services-wearable:18.1.0'
implementation 'androidx.core:core-splashscreen:1.0.1'
implementation 'androidx.wear:wear:1.3.0'
implementation 'androidx.wear:wear-remote-interactions:1.0.0'
implementation 'com.google.android.material:material:1.10.0'
compileOnly 'com.google.android.wearable:wearable:2.9.0'
}
4 changes: 4 additions & 0 deletions wear/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name="androidx.wear.activity.ConfirmationActivity">
</activity>
</application>

</manifest>
72 changes: 63 additions & 9 deletions wear/src/main/java/se/blunden/donotdisturbsync/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,25 @@
package se.blunden.donotdisturbsync;

import android.app.Activity;
import android.content.ComponentName;
import android.content.pm.PackageManager;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import androidx.core.splashscreen.SplashScreen;
import androidx.wear.activity.ConfirmationActivity;
import androidx.wear.remote.interactions.RemoteActivityHelper;

import com.google.android.material.button.MaterialButton;
import com.google.common.util.concurrent.ListenableFuture;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

public class MainActivity extends Activity {
private static final String TAG = "DndSync";
Expand All @@ -34,14 +48,54 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// Hide the launcher icon since users don't need to launch this anymore
//hideLauncherIcon();
//Log.i(TAG, "Hiding the app icon from the launcher since it is no longer needed");
MaterialButton showInstructionsButton = findViewById(R.id.button_show_instructions);
showInstructionsButton.setOnClickListener(view -> {
Intent showInstructionsIntent = new Intent(Intent.ACTION_VIEW)
.addCategory(Intent.CATEGORY_BROWSABLE)
.setData(Uri.parse("https://github.com/blunden/DoNotDisturbSync/blob/master/README.md"));

Executor executor = Executors.newSingleThreadExecutor();
RemoteActivityHelper remoteActivityHelper = new RemoteActivityHelper(this, executor);
ListenableFuture<Void> result = remoteActivityHelper.startRemoteActivity(showInstructionsIntent);

// Should really be handled by Futures.addCallback(...) but the onSuccess or onFailure
// callbacks are seemingly never executed. Let's just assume it was successful to show
// the animation and message.
result.addListener(() -> {
try {
result.get();
} catch(Exception e) {
Toast.makeText(this, "Failed to open link on companion phone", Toast.LENGTH_SHORT).show();
Log.e(TAG, "Failed to open link on companion phone");
}
}, executor);

Intent confirmationIntent = new Intent(getApplicationContext(), ConfirmationActivity.class)
.putExtra(ConfirmationActivity.EXTRA_ANIMATION_TYPE, ConfirmationActivity.OPEN_ON_PHONE_ANIMATION)
.putExtra(ConfirmationActivity.EXTRA_MESSAGE, getString(R.string.instruction_continue_on_phone));
try {
startActivity(confirmationIntent);
} catch (Exception e) {
Toast.makeText(this, "Failed to open link on companion phone", Toast.LENGTH_SHORT).show();
Log.e(TAG, "Failed to start confirmation activity");
}
});
}

private void hideLauncherIcon() {
PackageManager p = getPackageManager();
ComponentName componentName = new ComponentName(this, MainActivity.class);
p.setComponentEnabledSetting(componentName,PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
@Override
public void onResume() {
super.onResume();
updatePermissionStatus();
}

private void updatePermissionStatus() {
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
TextView activityInfoText = findViewById(R.id.info_text);
MaterialButton showInstructionsButton = findViewById(R.id.button_show_instructions);

if (notificationManager.isNotificationPolicyAccessGranted()) {
showInstructionsButton.setVisibility(View.GONE);
activityInfoText.setText(R.string.activity_info_permission_granted);
}
}
}
5 changes: 5 additions & 0 deletions wear/src/main/res/drawable/open_on_phone.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:autoMirrored="true" android:height="18dp"
android:tint="#FFFFFF" android:viewportHeight="24"
android:viewportWidth="24" android:width="18dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M17,17h2v4c0,1.1 -0.9,2 -2,2H7c-1.1,0 -2,-0.9 -2,-2V3c0,-1.1 0.9,-1.99 2,-1.99L17,1c1.1,0 2,0.9 2,2v4h-2V6H7v12h10V17zM22,12l-4,-4v3h-5v2h5v3L22,12z"/>
</vector>
30 changes: 23 additions & 7 deletions wear/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,28 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.wearable.view.BoxInsetLayout
<androidx.wear.widget.BoxInsetLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/watch_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="15dp"
android:padding="5dp"
android:background="@android:color/black"
tools:context="se.blunden.donotdisturbsync.MainActivity">

<ScrollView
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
app:layout_box="all">
android:orientation="vertical"
app:layout_boxedEdges="all">

<TextView
android:id="@+id/info_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="8dp"
android:layout_gravity="center_vertical"
android:paddingBottom="5dp"
android:textColor="@android:color/white"
android:text="@string/activity_info" />

</ScrollView>
<com.google.android.material.button.MaterialButton
style="@style/Widget.Material3.Button.IconButton.Filled"
android:id="@+id/button_show_instructions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textColor="@android:color/white"
android:text="@string/button_instructions"
app:backgroundTint="@color/colorAccent"
app:icon="@drawable/open_on_phone"
app:iconTint="@android:color/white" />

</LinearLayout>

</android.support.wearable.view.BoxInsetLayout>
</androidx.wear.widget.BoxInsetLayout>

1 change: 1 addition & 0 deletions wear/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<resources>
<color name="ic_launcher_background">#455A64</color>
<color name="colorAccent">#00BCD4</color>
</resources>
6 changes: 4 additions & 2 deletions wear/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<resources>
<string name="app_name">Do Not Disturb Sync</string>
<string name="activity_info">Having launched this app once allows it to monitor Do Not Disturb mode changes.</string>
<string name="icon_hidden_info">The app icon will now be hidden from the launcher as there is no need to launch it manually again.</string>
<string name="activity_info">To work properly, the app requires a special permission granted via ADB.</string>
<string name="activity_info_permission_granted">You have successfully granted the permission on your watch!\n\nDo Not Disturb state should now synchronize.</string>
<string name="button_instructions">Instructions</string>
<string name="instruction_continue_on_phone">Continue reading on your phone</string>

</resources>
2 changes: 1 addition & 1 deletion wear/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.App" parent="@android:style/Theme.DeviceDefault" />
<style name="Theme.App" parent="@style/Theme.Material3.Dark" />

<style name="Theme.App.Starting" parent="Theme.SplashScreen">
<!-- Set the splash screen background to black -->
Expand Down

0 comments on commit e0d7c17

Please sign in to comment.