blob: 275969046ad9b69d48f678ccffd4ed98962c1592 [file] [log] [blame]
Matthew Fritzef1a70062018-05-18 10:23:34 -07001/*
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
18package com.android.settings.location;
19
20import static android.provider.SettingsSlicesContract.KEY_LOCATION;
Fan Zhang23f8d592018-08-28 15:11:40 -070021
Matthew Fritzef1a70062018-05-18 10:23:34 -070022import static androidx.slice.builders.ListBuilder.ICON_IMAGE;
23
24import android.annotation.ColorInt;
25import android.app.PendingIntent;
Fan Zhang31b21002019-01-16 13:49:47 -080026import android.app.settings.SettingsEnums;
Matthew Fritzef1a70062018-05-18 10:23:34 -070027import android.content.Context;
28import android.content.Intent;
29import android.net.Uri;
Matthew Fritzef1a70062018-05-18 10:23:34 -070030
Matthew Fritzef1a70062018-05-18 10:23:34 -070031import androidx.core.graphics.drawable.IconCompat;
32import androidx.slice.Slice;
33import androidx.slice.builders.ListBuilder;
Jason Monkfee23c42018-08-06 09:44:22 -040034import androidx.slice.builders.ListBuilder.RowBuilder;
Matthew Fritzef1a70062018-05-18 10:23:34 -070035import androidx.slice.builders.SliceAction;
36
Fan Zhang23f8d592018-08-28 15:11:40 -070037import com.android.settings.R;
38import com.android.settings.SubSettings;
39import com.android.settings.Utils;
Fan Zhang53f75f02018-11-27 16:14:51 -080040import com.android.settings.slices.CustomSliceRegistry;
Fan Zhangd7fa2fa2018-12-05 14:42:53 -080041import com.android.settings.slices.CustomSliceable;
Fan Zhang23f8d592018-08-28 15:11:40 -070042import com.android.settings.slices.SliceBuilderUtils;
43
Matthew Fritzef1a70062018-05-18 10:23:34 -070044/**
45 * Utility class to build an intent-based Location Slice.
46 */
Fan Zhangd7fa2fa2018-12-05 14:42:53 -080047public class LocationSlice implements CustomSliceable {
Matthew Fritzef1a70062018-05-18 10:23:34 -070048
Fan Zhangd7fa2fa2018-12-05 14:42:53 -080049 private final Context mContext;
50
51 public LocationSlice(Context context) {
52 mContext = context;
Matthew Fritzef1a70062018-05-18 10:23:34 -070053 }
54
Fan Zhangd7fa2fa2018-12-05 14:42:53 -080055 @Override
56 public Slice getSlice() {
57 final IconCompat icon = IconCompat.createWithResource(mContext,
Amin Shaikh93913612019-01-24 18:00:29 -050058 com.android.internal.R.drawable.ic_signal_location);
Fan Zhangd7fa2fa2018-12-05 14:42:53 -080059 final CharSequence title = mContext.getText(R.string.location_settings_title);
60 @ColorInt final int color = Utils.getColorAccentDefaultColor(mContext);
61 final PendingIntent primaryAction = getPrimaryAction();
Raff Tsai626c6e02018-11-30 16:16:10 +080062 final SliceAction primarySliceAction = SliceAction.createDeeplink(primaryAction, icon,
63 ListBuilder.ICON_IMAGE, title);
Matthew Fritzef1a70062018-05-18 10:23:34 -070064
Fan Zhangd7fa2fa2018-12-05 14:42:53 -080065 return new ListBuilder(mContext, CustomSliceRegistry.LOCATION_SLICE_URI,
Fan Zhang53f75f02018-11-27 16:14:51 -080066 ListBuilder.INFINITY)
Matthew Fritzef1a70062018-05-18 10:23:34 -070067 .setAccentColor(color)
Jason Monkfee23c42018-08-06 09:44:22 -040068 .addRow(new RowBuilder()
Matthew Fritzef1a70062018-05-18 10:23:34 -070069 .setTitle(title)
70 .setTitleItem(icon, ICON_IMAGE)
71 .setPrimaryAction(primarySliceAction))
72 .build();
73 }
74
Fan Zhangd7fa2fa2018-12-05 14:42:53 -080075 @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 Fritzef1a70062018-05-18 10:23:34 -070088 final Uri contentUri = new Uri.Builder().appendPath(KEY_LOCATION).build();
Fan Zhangd7fa2fa2018-12-05 14:42:53 -080089 return SliceBuilderUtils.buildSearchResultPageIntent(mContext,
Matthew Fritzef1a70062018-05-18 10:23:34 -070090 LocationSettings.class.getName(), KEY_LOCATION, screenTitle,
Fan Zhang31b21002019-01-16 13:49:47 -080091 SettingsEnums.LOCATION)
Fan Zhangd7fa2fa2018-12-05 14:42:53 -080092 .setClassName(mContext.getPackageName(), SubSettings.class.getName())
Matthew Fritzef1a70062018-05-18 10:23:34 -070093 .setData(contentUri);
Matthew Fritzea5591032018-05-24 16:09:05 -070094 }
Matthew Fritzef1a70062018-05-18 10:23:34 -070095
Fan Zhangd7fa2fa2018-12-05 14:42:53 -080096 private PendingIntent getPrimaryAction() {
97 final Intent intent = getIntent();
98 return PendingIntent.getActivity(mContext, 0 /* requestCode */,
Matthew Fritzef1a70062018-05-18 10:23:34 -070099 intent, 0 /* flags */);
100 }
101}