Files
packages_apps_Settings/src/com/android/settings/slices/SliceData.java
Matthew Fritze 8c96843fe3 Build slice from indexed data in SliceProvider
Connect the SliceIndexing data to the SliceProvider,
such that a query to SliceProvider can build a Slice
via the indexed data from SlicesIndexingManager.

We take the key from the Uri supplied to the SettingSliceProvider
and find a potential matching row in the indexed data. The
matched data is then used to Build a slice for the caller.

Bug: 67996923
Test: robotests
Change-Id: If51bfd1a05c3f3817ae720554f95a98fc7b002e1
2018-01-10 10:58:33 -08:00

181 lines
4.5 KiB
Java

/*
* Copyright (C) 2017 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.net.Uri;
import android.text.TextUtils;
/**
* Data class representing a slice stored by {@link SlicesIndexer}.
* Note that {@link #key} is treated as a primary key for this class and determines equality.
*/
public class SliceData {
private final String key;
private final String title;
private final String summary;
private final String screenTitle;
private final int iconResource;
private final String fragmentClassName;
private final Uri uri;
private final String preferenceController;
public String getKey() {
return key;
}
public String getTitle() {
return title;
}
public String getSummary() {
return summary;
}
public String getScreenTitle() {
return screenTitle;
}
public int getIconResource() {
return iconResource;
}
public String getFragmentClassName() {
return fragmentClassName;
}
public Uri getUri() {
return uri;
}
public String getPreferenceController() {
return preferenceController;
}
private SliceData(Builder builder) {
key = builder.mKey;
title = builder.mTitle;
summary = builder.mSummary;
screenTitle = builder.mScreenTitle;
iconResource = builder.mIconResource;
fragmentClassName = builder.mFragmentClassName;
uri = builder.mUri;
preferenceController = builder.mPrefControllerClassName;
}
@Override
public int hashCode() {
return key.hashCode();
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof SliceData)) {
return false;
}
SliceData newObject = (SliceData) obj;
return TextUtils.equals(key, newObject.key);
}
static class Builder {
private String mKey;
private String mTitle;
private String mSummary;
private String mScreenTitle;
private int mIconResource;
private String mFragmentClassName;
private Uri mUri;
private String mPrefControllerClassName;
public Builder setKey(String key) {
mKey = key;
return this;
}
public Builder setTitle(String title) {
mTitle = title;
return this;
}
public Builder setSummary(String summary) {
mSummary = summary;
return this;
}
public Builder setScreenTitle(String screenTitle) {
mScreenTitle = screenTitle;
return this;
}
public Builder setIcon(int iconResource) {
mIconResource = iconResource;
return this;
}
public Builder setPreferenceControllerClassName(String controllerClassName) {
mPrefControllerClassName = controllerClassName;
return this;
}
public Builder setFragmentName(String fragmentClassName) {
mFragmentClassName = fragmentClassName;
return this;
}
public Builder setUri(Uri uri) {
mUri = uri;
return this;
}
public SliceData build() {
if (TextUtils.isEmpty(mKey)) {
throw new IllegalStateException("Key cannot be empty");
}
if (TextUtils.isEmpty(mTitle)) {
throw new IllegalStateException("Title cannot be empty");
}
if (TextUtils.isEmpty(mFragmentClassName)) {
throw new IllegalStateException("Fragment Name cannot be empty");
}
if (TextUtils.isEmpty(mPrefControllerClassName)) {
throw new IllegalStateException("Preference Controller cannot be empty");
}
return new SliceData(this);
}
public String getKey() {
return mKey;
}
}
}