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; 21 22 import static androidx.slice.builders.ListBuilder.ICON_IMAGE; 23 24 import android.annotation.ColorInt; 25 import android.app.PendingIntent; 26 import android.app.settings.SettingsEnums; 27 import android.content.Context; 28 import android.content.Intent; 29 import android.net.Uri; 30 31 import androidx.core.graphics.drawable.IconCompat; 32 import androidx.slice.Slice; 33 import androidx.slice.builders.ListBuilder; 34 import androidx.slice.builders.ListBuilder.RowBuilder; 35 import androidx.slice.builders.SliceAction; 36 37 import com.android.settings.R; 38 import com.android.settings.SubSettings; 39 import com.android.settings.Utils; 40 import com.android.settings.slices.CustomSliceRegistry; 41 import com.android.settings.slices.CustomSliceable; 42 import com.android.settings.slices.SliceBuilderUtils; 43 44 /** 45 * Utility class to build an intent-based Location Slice. 46 */ 47 public class LocationSlice implements CustomSliceable { 48 49 private final Context mContext; 50 LocationSlice(Context context)51 public LocationSlice(Context context) { 52 mContext = context; 53 } 54 55 @Override getSlice()56 public Slice getSlice() { 57 final IconCompat icon = IconCompat.createWithResource(mContext, 58 com.android.internal.R.drawable.ic_signal_location); 59 final CharSequence title = mContext.getText(R.string.location_settings_title); 60 @ColorInt final int color = Utils.getColorAccentDefaultColor(mContext); 61 final PendingIntent primaryAction = getPrimaryAction(); 62 final SliceAction primarySliceAction = SliceAction.createDeeplink(primaryAction, icon, 63 ListBuilder.ICON_IMAGE, title); 64 65 return new ListBuilder(mContext, CustomSliceRegistry.LOCATION_SLICE_URI, 66 ListBuilder.INFINITY) 67 .setAccentColor(color) 68 .addRow(new RowBuilder() 69 .setTitle(title) 70 .setTitleItem(icon, ICON_IMAGE) 71 .setPrimaryAction(primarySliceAction)) 72 .build(); 73 } 74 75 @Override getUri()76 public Uri getUri() { 77 return CustomSliceRegistry.LOCATION_SLICE_URI; 78 } 79 80 @Override onNotifyChange(Intent intent)81 public void onNotifyChange(Intent intent) { 82 83 } 84 85 @Override getIntent()86 public Intent getIntent() { 87 final String screenTitle = mContext.getText(R.string.location_settings_title).toString(); 88 final Uri contentUri = new Uri.Builder().appendPath(KEY_LOCATION).build(); 89 return SliceBuilderUtils.buildSearchResultPageIntent(mContext, 90 LocationSettings.class.getName(), KEY_LOCATION, screenTitle, 91 SettingsEnums.LOCATION) 92 .setClassName(mContext.getPackageName(), SubSettings.class.getName()) 93 .setData(contentUri); 94 } 95 getPrimaryAction()96 private PendingIntent getPrimaryAction() { 97 final Intent intent = getIntent(); 98 return PendingIntent.getActivity(mContext, 0 /* requestCode */, 99 intent, 0 /* flags */); 100 } 101 } 102