Jason Monk | 6fa0c9b | 2017-12-12 20:55:35 -0500 | [diff] [blame] | 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 | |
| 17 | package androidx.app.slice; |
| 18 | |
| 19 | import static android.app.slice.Slice.HINT_LARGE; |
| 20 | import static android.app.slice.Slice.HINT_LIST; |
| 21 | import static android.app.slice.Slice.HINT_NO_TINT; |
| 22 | import static android.app.slice.Slice.HINT_TITLE; |
| 23 | |
| 24 | import android.app.PendingIntent; |
| 25 | import android.content.Intent; |
| 26 | import android.graphics.drawable.Icon; |
| 27 | import android.net.Uri; |
| 28 | |
| 29 | import androidx.app.slice.Slice.Builder; |
| 30 | import androidx.app.slice.core.test.R; |
| 31 | |
| 32 | public 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 Monk | 98ae4f8 | 2017-12-18 11:29:07 -0500 | [diff] [blame] | 60 | case "/int": |
| 61 | return new Slice.Builder(sliceUri).addInt(0xff121212, "int").build(); |
Jason Monk | 6fa0c9b | 2017-12-12 20:55:35 -0500 | [diff] [blame] | 62 | 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 | } |