blob: 9320bc97db0b6ecd164126d4c20eb8555f9440f0 [file] [log] [blame]
Jason Monk6fa0c9b2017-12-12 20:55:35 -05001/*
2 * Copyright 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package androidx.app.slice;
18
19import static android.app.slice.Slice.HINT_LARGE;
20import static android.app.slice.Slice.HINT_LIST;
21import static android.app.slice.Slice.HINT_NO_TINT;
22import static android.app.slice.Slice.HINT_TITLE;
23
24import android.app.PendingIntent;
25import android.content.Intent;
26import android.graphics.drawable.Icon;
27import android.net.Uri;
28
29import androidx.app.slice.Slice.Builder;
30import androidx.app.slice.core.test.R;
31
32public class SliceTestProvider extends androidx.app.slice.SliceProvider {
33
34 @Override
35 public boolean onCreateSliceProvider() {
36 return true;
37 }
38
39 @Override
40 public Slice onBindSlice(Uri sliceUri) {
41 switch (sliceUri.getPath()) {
42 case "/set_flag":
43 SliceTest.sFlag = true;
44 break;
45 case "/subslice":
46 Builder b = new Builder(sliceUri);
47 return b.addSubSlice(new Slice.Builder(b).build(), "subslice").build();
48 case "/text":
49 return new Slice.Builder(sliceUri).addText("Expected text", "text").build();
50 case "/icon":
51 return new Slice.Builder(sliceUri).addIcon(
52 Icon.createWithResource(getContext(), R.drawable.size_48x48),
53 "icon").build();
54 case "/action":
55 Builder builder = new Builder(sliceUri);
56 Slice subSlice = new Slice.Builder(builder).build();
57 PendingIntent broadcast = PendingIntent.getBroadcast(getContext(), 0,
58 new Intent(getContext().getPackageName() + ".action"), 0);
59 return builder.addAction(broadcast, subSlice, "action").build();
Jason Monk98ae4f82017-12-18 11:29:07 -050060 case "/int":
61 return new Slice.Builder(sliceUri).addInt(0xff121212, "int").build();
Jason Monk6fa0c9b2017-12-12 20:55:35 -050062 case "/timestamp":
63 return new Slice.Builder(sliceUri).addTimestamp(43, "timestamp").build();
64 case "/hints":
65 return new Slice.Builder(sliceUri)
66 .addHints(HINT_LIST)
67 .addText("Text", null, HINT_TITLE)
68 .addIcon(Icon.createWithResource(getContext(), R.drawable.size_48x48),
69 null, HINT_NO_TINT, HINT_LARGE)
70 .build();
71 }
72 return new Slice.Builder(sliceUri).build();
73 }
74
75}