aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMady Mellor <madym@google.com>2017-11-02 11:26:20 -0700
committerJason Monk <jmonk@google.com>2017-11-13 19:43:20 -0500
commit0d7a7d5ac49a1df90d2fd7eafbab30f89d83611a (patch)
treea0aebac1796cbae2d57a01132894b08bc1f25c34
parentc2cea36857ad8ac7de989869f3b79dbb98780de3 (diff)
downloadexperimental-0d7a7d5ac49a1df90d2fd7eafbab30f89d83611a.tar.gz
Updates to provider app to have toggle slices for settings
Test: manual Change-Id: I643655a6dae38a68e65243bbf03a0d1232c9b19c
-rw-r--r--SliceBrowser/src/com/android/experimental/slicepresenter/SlicePresenter.java1
-rw-r--r--SlicesApp/AndroidManifest.xml12
-rw-r--r--SlicesApp/src/com/android/experimental/slicesapp/SlicesActivity.java6
-rw-r--r--SlicesApp/src/com/android/experimental/slicesapp/SlicesBroadcastReceiver.java29
-rw-r--r--SlicesApp/src/com/android/experimental/slicesapp/SlicesProvider.java101
5 files changed, 116 insertions, 33 deletions
diff --git a/SliceBrowser/src/com/android/experimental/slicepresenter/SlicePresenter.java b/SliceBrowser/src/com/android/experimental/slicepresenter/SlicePresenter.java
index 6b8a90e..99e32ac 100644
--- a/SliceBrowser/src/com/android/experimental/slicepresenter/SlicePresenter.java
+++ b/SliceBrowser/src/com/android/experimental/slicepresenter/SlicePresenter.java
@@ -60,7 +60,6 @@ public class SlicePresenter extends Activity {
private ArrayList<Uri> mSliceUris = new ArrayList<Uri>();
private String mSelectedMode;
private ViewGroup mContainer;
- private boolean mShowingIntentSlice;
private SearchView mSearchView;
private SimpleCursorAdapter mAdapter;
private SubMenu mTypeMenu;
diff --git a/SlicesApp/AndroidManifest.xml b/SlicesApp/AndroidManifest.xml
index 40f714d..87def87 100644
--- a/SlicesApp/AndroidManifest.xml
+++ b/SlicesApp/AndroidManifest.xml
@@ -36,6 +36,7 @@
android:host="com.android.experimental.slicesapp"
android:pathPrefix="/main" />
</intent-filter>
+
<meta-data android:name="android.metadata.SLICE_URI"
android:value="content://com.android.experimental.slicesapp/main" />
</activity>
@@ -44,11 +45,18 @@
android:authorities="com.android.experimental.slicesapp"
android:exported="true">
<intent-filter>
- <action android:name="android.intent.action.VIEW_SLICE" />
- <action android:name="android.intent.action.EXAMPLE_ACTION" />
+ <action android:name="android.intent.action.EXAMPLE_SLICE_INTENT" />
</intent-filter>
</provider>
+ <receiver
+ android:name=".SlicesBroadcastReceiver"
+ android:exported="true" >
+ <intent-filter>
+ <action android:name="android.intent.action.EXAMPLE_SLICE_ACTION"/>
+ </intent-filter>
+ </receiver>
+
</application>
</manifest>
diff --git a/SlicesApp/src/com/android/experimental/slicesapp/SlicesActivity.java b/SlicesApp/src/com/android/experimental/slicesapp/SlicesActivity.java
index 42f4cb8..a51e2d4 100644
--- a/SlicesApp/src/com/android/experimental/slicesapp/SlicesActivity.java
+++ b/SlicesApp/src/com/android/experimental/slicesapp/SlicesActivity.java
@@ -22,7 +22,6 @@ import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.net.Uri;
import android.os.Bundle;
-import android.os.Handler;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
@@ -31,7 +30,6 @@ import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.Spinner;
import android.widget.TextView;
-
import java.util.ArrayList;
import java.util.List;
@@ -80,12 +78,12 @@ public class SlicesActivity extends Activity {
list.add("Single-line action");
list.add("Two-line");
list.add("Two-line action");
- list.add("Grid");
list.add("Weather");
list.add("Messaging");
- list.add("Shortcut");
list.add("Keep actions");
list.add("Maps multi");
+ list.add("Settings");
+ list.add("Settings content");
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
android.R.layout.simple_spinner_item, list);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
diff --git a/SlicesApp/src/com/android/experimental/slicesapp/SlicesBroadcastReceiver.java b/SlicesApp/src/com/android/experimental/slicesapp/SlicesBroadcastReceiver.java
new file mode 100644
index 0000000..26adaa7
--- /dev/null
+++ b/SlicesApp/src/com/android/experimental/slicesapp/SlicesBroadcastReceiver.java
@@ -0,0 +1,29 @@
+package com.android.experimental.slicesapp;
+
+import android.app.slice.Slice;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.util.Log;
+import android.widget.Toast;
+
+public class SlicesBroadcastReceiver extends BroadcastReceiver {
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ final String action = intent.getAction();
+ if (SlicesProvider.SLICE_ACTION.equals(action)) {
+ // A slice was clicked and we've got an action to handle
+ Bundle bundle = intent.getExtras();
+ String message = "";
+ boolean newState = false;
+ if (bundle != null) {
+ message = bundle.getString(SlicesProvider.INTENT_ACTION_EXTRA);
+ newState = bundle.getBoolean(Slice.EXTRA_TOGGLE_STATE);
+ }
+ String text = message + " new state: " + newState;
+ Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
+ }
+ }
+}
diff --git a/SlicesApp/src/com/android/experimental/slicesapp/SlicesProvider.java b/SlicesApp/src/com/android/experimental/slicesapp/SlicesProvider.java
index 32a6704..226bbcc 100644
--- a/SlicesApp/src/com/android/experimental/slicesapp/SlicesProvider.java
+++ b/SlicesApp/src/com/android/experimental/slicesapp/SlicesProvider.java
@@ -22,7 +22,6 @@ import android.app.slice.SliceProvider;
import android.content.ContentResolver;
import android.content.Intent;
import android.content.SharedPreferences;
-import android.graphics.Color;
import android.graphics.drawable.Icon;
import android.net.Uri;
import android.text.format.DateUtils;
@@ -34,7 +33,9 @@ import java.util.function.Consumer;
public class SlicesProvider extends SliceProvider {
private static final String TAG = "SliceProvider";
- private static final String INTENT_ACTION = "android.intent.action.EXAMPLE_ACTION";
+ public static final String SLICE_INTENT = "android.intent.action.EXAMPLE_SLICE_INTENT";
+ public static final String SLICE_ACTION = "android.intent.action.EXAMPLE_SLICE_ACTION";
+ public static final String INTENT_ACTION_EXTRA = "android.intent.slicesapp.INTENT_ACTION_EXTRA";
private final int NUM_LIST_ITEMS = 10;
@@ -56,7 +57,7 @@ public class SlicesProvider extends SliceProvider {
//@Override
public Uri onMapIntentToUri(Intent intent) {
- if (intent.getAction().equals(INTENT_ACTION)) {
+ if (intent.getAction().equals(SLICE_INTENT)) {
return getIntentUri();
}
return null;//super.onMapIntentToUri(intent);
@@ -84,32 +85,26 @@ public class SlicesProvider extends SliceProvider {
type = "Intent";
}
switch (type) {
- case "Shortcut":
- b.addColor(Color.CYAN).addIcon(
- Icon.createWithResource(getContext(), R.drawable.mady),
- Slice.HINT_LARGE);
- break;
case "Single-line":
b.addSubSlice(makeList(new Slice.Builder(b), this::makeSingleLine,
this::addIcon));
- addColorIcon(b);
+ addPrimaryAction(b);
break;
case "Single-line action":
b.addSubSlice(makeList(new Slice.Builder(b), this::makeSingleLine,
this::addAltActions));
- addColorIcon(b);
+ addPrimaryAction(b);
break;
case "Two-line":
b.addSubSlice(makeList(new Slice.Builder(b), this::makeTwoLine,
this::addIcon));
- addColorIcon(b);
+ addPrimaryAction(b);
break;
case "Two-line action":
b.addSubSlice(makeList(new Slice.Builder(b), this::makeTwoLine,
this::addAltActions));
- addColorIcon(b);
+ addPrimaryAction(b);
break;
- case "Grid":
case "Weather":
b.addSubSlice(createWeather(new Slice.Builder(b)));
break;
@@ -125,6 +120,12 @@ public class SlicesProvider extends SliceProvider {
case "Intent":
b.addSubSlice(createIntentSlice(new Slice.Builder(b)));
break;
+ case "Settings":
+ createSettingsSlice(b);
+ break;
+ case "Settings content":
+ createSettingsContentSlice(b);
+ break;
}
if (mSharedPrefs.getBoolean("show_action_row", false)) {
Intent intent = new Intent(getContext(), SlicesActivity.class);
@@ -150,23 +151,28 @@ public class SlicesProvider extends SliceProvider {
private Slice createWeather(Builder grid) {
grid.addHints(Slice.HINT_HORIZONTAL);
grid.addSubSlice(new Slice.Builder(grid)
- .addIcon(Icon.createWithResource(getContext(), R.drawable.weather_1))
+ .addIcon(Icon.createWithResource(getContext(), R.drawable.weather_1),
+ Slice.HINT_LARGE)
.addText("MON")
.addText("69\u00B0", Slice.HINT_LARGE).build());
grid.addSubSlice(new Slice.Builder(grid)
- .addIcon(Icon.createWithResource(getContext(), R.drawable.weather_2))
+ .addIcon(Icon.createWithResource(getContext(), R.drawable.weather_2),
+ Slice.HINT_LARGE)
.addText("TUE")
.addText("71\u00B0", Slice.HINT_LARGE).build());
grid.addSubSlice(new Slice.Builder(grid)
- .addIcon(Icon.createWithResource(getContext(), R.drawable.weather_3))
+ .addIcon(Icon.createWithResource(getContext(), R.drawable.weather_3),
+ Slice.HINT_LARGE)
.addText("WED")
.addText("76\u00B0", Slice.HINT_LARGE).build());
grid.addSubSlice(new Slice.Builder(grid)
- .addIcon(Icon.createWithResource(getContext(), R.drawable.weather_4))
+ .addIcon(Icon.createWithResource(getContext(), R.drawable.weather_4),
+ Slice.HINT_LARGE)
.addText("THU")
.addText("69\u00B0", Slice.HINT_LARGE).build());
grid.addSubSlice(new Slice.Builder(grid)
- .addIcon(Icon.createWithResource(getContext(), R.drawable.weather_2))
+ .addIcon(Icon.createWithResource(getContext(), R.drawable.weather_2),
+ Slice.HINT_LARGE)
.addText("FRI")
.addText("71\u00B0", Slice.HINT_LARGE).build());
return grid.build();
@@ -178,7 +184,8 @@ public class SlicesProvider extends SliceProvider {
.addHints(Slice.HINT_MESSAGE)
.addText("yo home \uD83C\uDF55, I emailed you the info")
.addTimestamp(System.currentTimeMillis() - 20 * DateUtils.MINUTE_IN_MILLIS)
- .addIcon(Icon.createWithResource(getContext(), R.drawable.mady), Slice.HINT_SOURCE)
+ .addIcon(Icon.createWithResource(getContext(), R.drawable.mady), Slice.HINT_SOURCE,
+ Slice.HINT_TITLE, Slice.HINT_LARGE)
.build());
b2.addSubSlice(new Builder(b2)
.addHints(Slice.HINT_MESSAGE)
@@ -190,7 +197,8 @@ public class SlicesProvider extends SliceProvider {
.addText("yay! can't wait for getContext() weekend!\n"
+ "\uD83D\uDE00")
.addTimestamp(System.currentTimeMillis() - 5 * DateUtils.MINUTE_IN_MILLIS)
- .addIcon(Icon.createWithResource(getContext(), R.drawable.mady), Slice.HINT_SOURCE)
+ .addIcon(Icon.createWithResource(getContext(), R.drawable.mady), Slice.HINT_SOURCE,
+ Slice.HINT_LARGE)
.build());
RemoteInput ri = new RemoteInput.Builder("someKey").setLabel("someLabel")
.setAllowFreeFormInput(true).build();
@@ -226,9 +234,15 @@ public class SlicesProvider extends SliceProvider {
b.addText("Secondary text");
}
- private void addColorIcon(Builder b) {
- b.addColor(0xFFFF5722);
- b.addIcon(Icon.createWithResource(getContext(), R.drawable.ic_slice));
+ private void addPrimaryAction(Builder b) {
+ Intent intent = new Intent(getContext(), SlicesActivity.class);
+ PendingIntent pi = PendingIntent.getActivity(getContext(), 0, intent, 0);
+ b.addSubSlice(new Slice.Builder(b).addAction(pi,
+ new Slice.Builder(b).addColor(0xFFFF5722)
+ .addIcon(Icon.createWithResource(getContext(), R.drawable.ic_slice),
+ Slice.HINT_TITLE)
+ .addText("Slice App", Slice.HINT_TITLE)
+ .build()).addHints(Slice.HINT_HIDDEN, Slice.HINT_TITLE).build());
}
private Slice makeList(Builder list, Consumer<Builder> lineCreator,
@@ -270,8 +284,7 @@ public class SlicesProvider extends SliceProvider {
private Slice createMapsMulti(Builder b) {
Intent intent = new Intent(getContext(), SlicesActivity.class);
PendingIntent pi = PendingIntent.getActivity(getContext(), 0, intent, 0);
-
- b.addHints(Slice.HINT_HORIZONTAL, Slice.HINT_LIST).addColor(0xff0B8043);
+ b.addHints(Slice.HINT_HORIZONTAL, Slice.HINT_LIST);
b.addSubSlice(new Slice.Builder(b)
.addAction(pi, new Slice.Builder(b)
.addIcon(Icon.createWithResource(getContext(), R.drawable.ic_home)).build())
@@ -284,9 +297,10 @@ public class SlicesProvider extends SliceProvider {
.addText("1 hour 23 min").build());
b.addSubSlice(new Slice.Builder(b)
.addAction(pi, new Slice.Builder(b)
- .addIcon(Icon.createWithResource(getContext(), R.drawable.ic_home)).build())
+ .addIcon(Icon.createWithResource(getContext(), R.drawable.ic_car)).build())
.addText("Mom's", Slice.HINT_LARGE)
.addText("37 min").build());
+ b.addColor(0xff0B8043);
return b.build();
}
@@ -310,4 +324,39 @@ public class SlicesProvider extends SliceProvider {
.addText("Previous", Slice.HINT_LARGE).build());
return b.build();
}
+
+ private Slice.Builder createSettingsSlice(Builder b) {
+ b.addSubSlice(new Slice.Builder(b)
+ .addAction(getIntent("toggled"), new Slice.Builder(b)
+ .addText("Wi-fi")
+ .addText("GoogleGuest")
+ .addHints(Slice.HINT_TOGGLE, Slice.HINT_SELECTED)
+ .build())
+ .build());
+ return b;
+ }
+
+ private Slice.Builder createSettingsContentSlice(Builder b) {
+ b.addSubSlice(new Slice.Builder(b)
+ .addAction(getIntent("main content"),
+ new Slice.Builder(b)
+ .addText("Wi-fi")
+ .addText("GoogleGuest")
+ .build())
+ .addAction(getIntent("toggled"),
+ new Slice.Builder(b)
+ .addHints(Slice.HINT_TOGGLE, Slice.HINT_SELECTED)
+ .build())
+ .build());
+ return b;
+ }
+
+ private PendingIntent getIntent(String message) {
+ Intent intent = new Intent(SLICE_ACTION);
+ intent.setClass(getContext(), SlicesBroadcastReceiver.class);
+ intent.putExtra(INTENT_ACTION_EXTRA, message);
+ PendingIntent pi = PendingIntent.getBroadcast(getContext(), 0, intent,
+ PendingIntent.FLAG_CANCEL_CURRENT);
+ return pi;
+ }
}