1/*
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.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.net.Uri;
27
28import androidx.core.graphics.drawable.IconCompat;
29import androidx.slice.Slice.Builder;
30import androidx.slice.core.test.R;
31
32public class SliceTestProvider extends androidx.slice.SliceProvider {
33
34    @Override
35    public boolean onCreateSliceProvider() {
36        getContext().getPackageName();
37        return true;
38    }
39
40    @Override
41    public Slice onBindSlice(Uri sliceUri) {
42        switch (sliceUri.getPath()) {
43            case "/set_flag":
44                SliceTest.sFlag = true;
45                break;
46            case "/subslice":
47                Builder b = new Builder(sliceUri);
48                return b.addSubSlice(new Slice.Builder(b).build(), "subslice").build();
49            case "/text":
50                return new Slice.Builder(sliceUri).addText("Expected text", "text").build();
51            case "/icon":
52                return new Slice.Builder(sliceUri).addIcon(
53                        IconCompat.createWithResource(getContext(), R.drawable.size_48x48),
54                        "icon").build();
55            case "/action":
56                Builder builder = new Builder(sliceUri);
57                Slice subSlice = new Slice.Builder(builder).build();
58                PendingIntent broadcast = PendingIntent.getBroadcast(getContext(), 0,
59                        new Intent(getContext().getPackageName() + ".action"), 0);
60                return builder.addAction(broadcast, subSlice, "action").build();
61            case "/int":
62                return new Slice.Builder(sliceUri).addInt(0xff121212, "int").build();
63            case "/timestamp":
64                return new Slice.Builder(sliceUri).addTimestamp(43, "timestamp").build();
65            case "/hints":
66                return new Slice.Builder(sliceUri)
67                        .addHints(HINT_LIST)
68                        .addText("Text", null, HINT_TITLE)
69                        .addIcon(IconCompat.createWithResource(getContext(), R.drawable.size_48x48),
70                                null, HINT_NO_TINT, HINT_LARGE)
71                        .build();
72        }
73        return new Slice.Builder(sliceUri).build();
74    }
75
76}
77