Matthew Fritze | f1a7006 | 2018-05-18 10:23:34 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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 | |
| 18 | package com.android.settings.location; |
| 19 | |
| 20 | import static android.provider.SettingsSlicesContract.KEY_LOCATION; |
Fan Zhang | 23f8d59 | 2018-08-28 15:11:40 -0700 | [diff] [blame] | 21 | |
Matthew Fritze | f1a7006 | 2018-05-18 10:23:34 -0700 | [diff] [blame] | 22 | import static androidx.slice.builders.ListBuilder.ICON_IMAGE; |
| 23 | |
| 24 | import android.annotation.ColorInt; |
| 25 | import android.app.PendingIntent; |
Fan Zhang | 31b2100 | 2019-01-16 13:49:47 -0800 | [diff] [blame] | 26 | import android.app.settings.SettingsEnums; |
Matthew Fritze | f1a7006 | 2018-05-18 10:23:34 -0700 | [diff] [blame] | 27 | import android.content.Context; |
| 28 | import android.content.Intent; |
| 29 | import android.net.Uri; |
Matthew Fritze | f1a7006 | 2018-05-18 10:23:34 -0700 | [diff] [blame] | 30 | |
Matthew Fritze | f1a7006 | 2018-05-18 10:23:34 -0700 | [diff] [blame] | 31 | import androidx.core.graphics.drawable.IconCompat; |
| 32 | import androidx.slice.Slice; |
| 33 | import androidx.slice.builders.ListBuilder; |
Jason Monk | fee23c4 | 2018-08-06 09:44:22 -0400 | [diff] [blame] | 34 | import androidx.slice.builders.ListBuilder.RowBuilder; |
Matthew Fritze | f1a7006 | 2018-05-18 10:23:34 -0700 | [diff] [blame] | 35 | import androidx.slice.builders.SliceAction; |
| 36 | |
Fan Zhang | 23f8d59 | 2018-08-28 15:11:40 -0700 | [diff] [blame] | 37 | import com.android.settings.R; |
| 38 | import com.android.settings.SubSettings; |
| 39 | import com.android.settings.Utils; |
Fan Zhang | 53f75f0 | 2018-11-27 16:14:51 -0800 | [diff] [blame] | 40 | import com.android.settings.slices.CustomSliceRegistry; |
Fan Zhang | d7fa2fa | 2018-12-05 14:42:53 -0800 | [diff] [blame] | 41 | import com.android.settings.slices.CustomSliceable; |
Fan Zhang | 23f8d59 | 2018-08-28 15:11:40 -0700 | [diff] [blame] | 42 | import com.android.settings.slices.SliceBuilderUtils; |
| 43 | |
Matthew Fritze | f1a7006 | 2018-05-18 10:23:34 -0700 | [diff] [blame] | 44 | /** |
| 45 | * Utility class to build an intent-based Location Slice. |
| 46 | */ |
Fan Zhang | d7fa2fa | 2018-12-05 14:42:53 -0800 | [diff] [blame] | 47 | public class LocationSlice implements CustomSliceable { |
Matthew Fritze | f1a7006 | 2018-05-18 10:23:34 -0700 | [diff] [blame] | 48 | |
Fan Zhang | d7fa2fa | 2018-12-05 14:42:53 -0800 | [diff] [blame] | 49 | private final Context mContext; |
| 50 | |
| 51 | public LocationSlice(Context context) { |
| 52 | mContext = context; |
Matthew Fritze | f1a7006 | 2018-05-18 10:23:34 -0700 | [diff] [blame] | 53 | } |
| 54 | |
Fan Zhang | d7fa2fa | 2018-12-05 14:42:53 -0800 | [diff] [blame] | 55 | @Override |
| 56 | public Slice getSlice() { |
| 57 | final IconCompat icon = IconCompat.createWithResource(mContext, |
Amin Shaikh | 9391361 | 2019-01-24 18:00:29 -0500 | [diff] [blame] | 58 | com.android.internal.R.drawable.ic_signal_location); |
Fan Zhang | d7fa2fa | 2018-12-05 14:42:53 -0800 | [diff] [blame] | 59 | final CharSequence title = mContext.getText(R.string.location_settings_title); |
| 60 | @ColorInt final int color = Utils.getColorAccentDefaultColor(mContext); |
| 61 | final PendingIntent primaryAction = getPrimaryAction(); |
Raff Tsai | 626c6e0 | 2018-11-30 16:16:10 +0800 | [diff] [blame] | 62 | final SliceAction primarySliceAction = SliceAction.createDeeplink(primaryAction, icon, |
| 63 | ListBuilder.ICON_IMAGE, title); |
Matthew Fritze | f1a7006 | 2018-05-18 10:23:34 -0700 | [diff] [blame] | 64 | |
Fan Zhang | d7fa2fa | 2018-12-05 14:42:53 -0800 | [diff] [blame] | 65 | return new ListBuilder(mContext, CustomSliceRegistry.LOCATION_SLICE_URI, |
Fan Zhang | 53f75f0 | 2018-11-27 16:14:51 -0800 | [diff] [blame] | 66 | ListBuilder.INFINITY) |
Matthew Fritze | f1a7006 | 2018-05-18 10:23:34 -0700 | [diff] [blame] | 67 | .setAccentColor(color) |
Jason Monk | fee23c4 | 2018-08-06 09:44:22 -0400 | [diff] [blame] | 68 | .addRow(new RowBuilder() |
Matthew Fritze | f1a7006 | 2018-05-18 10:23:34 -0700 | [diff] [blame] | 69 | .setTitle(title) |
| 70 | .setTitleItem(icon, ICON_IMAGE) |
| 71 | .setPrimaryAction(primarySliceAction)) |
| 72 | .build(); |
| 73 | } |
| 74 | |
Fan Zhang | d7fa2fa | 2018-12-05 14:42:53 -0800 | [diff] [blame] | 75 | @Override |
| 76 | public Uri getUri() { |
| 77 | return CustomSliceRegistry.LOCATION_SLICE_URI; |
| 78 | } |
| 79 | |
| 80 | @Override |
| 81 | public void onNotifyChange(Intent intent) { |
| 82 | |
| 83 | } |
| 84 | |
| 85 | @Override |
| 86 | public Intent getIntent() { |
| 87 | final String screenTitle = mContext.getText(R.string.location_settings_title).toString(); |
Matthew Fritze | f1a7006 | 2018-05-18 10:23:34 -0700 | [diff] [blame] | 88 | final Uri contentUri = new Uri.Builder().appendPath(KEY_LOCATION).build(); |
Fan Zhang | d7fa2fa | 2018-12-05 14:42:53 -0800 | [diff] [blame] | 89 | return SliceBuilderUtils.buildSearchResultPageIntent(mContext, |
Matthew Fritze | f1a7006 | 2018-05-18 10:23:34 -0700 | [diff] [blame] | 90 | LocationSettings.class.getName(), KEY_LOCATION, screenTitle, |
Fan Zhang | 31b2100 | 2019-01-16 13:49:47 -0800 | [diff] [blame] | 91 | SettingsEnums.LOCATION) |
Fan Zhang | d7fa2fa | 2018-12-05 14:42:53 -0800 | [diff] [blame] | 92 | .setClassName(mContext.getPackageName(), SubSettings.class.getName()) |
Matthew Fritze | f1a7006 | 2018-05-18 10:23:34 -0700 | [diff] [blame] | 93 | .setData(contentUri); |
Matthew Fritze | a559103 | 2018-05-24 16:09:05 -0700 | [diff] [blame] | 94 | } |
Matthew Fritze | f1a7006 | 2018-05-18 10:23:34 -0700 | [diff] [blame] | 95 | |
Fan Zhang | d7fa2fa | 2018-12-05 14:42:53 -0800 | [diff] [blame] | 96 | private PendingIntent getPrimaryAction() { |
| 97 | final Intent intent = getIntent(); |
| 98 | return PendingIntent.getActivity(mContext, 0 /* requestCode */, |
Matthew Fritze | f1a7006 | 2018-05-18 10:23:34 -0700 | [diff] [blame] | 99 | intent, 0 /* flags */); |
| 100 | } |
| 101 | } |