Handle special case slices
Create a handler for any slice that doesn't include anything from a PreferenceController. Test: robotests Change-Id: If23947152d61877537d0cac6240e96b9ab977bce Bug: 80263568
This commit is contained in:
88
src/com/android/settings/slices/CustomSliceManager.java
Normal file
88
src/com/android/settings/slices/CustomSliceManager.java
Normal file
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.slices;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.util.ArrayMap;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Manages custom {@link androidx.slice.Slice Slices}, which are all Slices not backed by
|
||||
* preferences.
|
||||
* <p>
|
||||
* By default, all Slices in Settings should be built by a
|
||||
* </p>
|
||||
*/
|
||||
public class CustomSliceManager {
|
||||
|
||||
protected final Map<Uri, Class<? extends CustomSliceable>> mUriMap;
|
||||
|
||||
private final Context mContext;
|
||||
|
||||
public CustomSliceManager(Context context) {
|
||||
mContext = context;
|
||||
mUriMap = new ArrayMap<>();
|
||||
addSlices();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a {@link CustomSliceable} associated to the Uri.
|
||||
* <p>
|
||||
* Do not change this method signature to accommodate for a special-case slicable - a context is
|
||||
* the only thing that should be needed to create the object.
|
||||
*/
|
||||
public CustomSliceable getSliceableFromUri(Uri uri) {
|
||||
final Class clazz = mUriMap.get(uri);
|
||||
|
||||
if (clazz == null) {
|
||||
throw new IllegalArgumentException("No Slice found for uri: " + uri);
|
||||
}
|
||||
|
||||
return CustomSliceable.createInstance(mContext, clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a {@link CustomSliceable} associated to the Action.
|
||||
* <p>
|
||||
* Do not change this method signature to accommodate for a special-case sliceable - a context
|
||||
* is the only thing that should be needed to create the object.
|
||||
*/
|
||||
public CustomSliceable getSliceableFromIntentAction(String action) {
|
||||
return getSliceableFromUri(Uri.parse(action));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if {@param uri} is a valid Slice Uri handled by
|
||||
* {@link CustomSliceManager}.
|
||||
*/
|
||||
public boolean isValidUri(Uri uri) {
|
||||
return mUriMap.containsKey(uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if {@param action} is a valid intent action handled by
|
||||
* {@link CustomSliceManager}.
|
||||
*/
|
||||
public boolean isValidAction(String action) {
|
||||
return isValidUri(Uri.parse(action));
|
||||
}
|
||||
|
||||
private void addSlices() {
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user