• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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 package com.android.customization.model;
17 
18 import android.util.Log;
19 
20 import androidx.annotation.Nullable;
21 
22 import java.util.List;
23 
24 /**
25  * Interface for a class that handles a "Customization" (eg, "Themes", "Clockfaces", etc)
26  * @param <T> the type of {@link CustomizationOption} that this Manager class provides.
27  */
28 public interface CustomizationManager<T extends CustomizationOption> {
29 
30     /**
31      * Callback for applying a customization option.
32      */
33     interface Callback {
34         /**
35          * Called after an option was applied successfully.
36          */
onSuccess()37         void onSuccess();
38 
39         /**
40          * Called if there was an error applying the customization
41          * @param throwable Exception thrown if available.
42          */
onError(@ullable Throwable throwable)43         void onError(@Nullable Throwable throwable);
44     }
45 
46     /**
47      * Listener interface for fetching CustomizationOptions
48      */
49     interface OptionsFetchedListener<T extends CustomizationOption> {
50         /**
51          * Called when the options have been retrieved.
52          */
onOptionsLoaded(List<T> options)53         void onOptionsLoaded(List<T> options);
54 
55         /**
56          * Called if there was an error loading grid options
57          */
onError(@ullable Throwable throwable)58         default void onError(@Nullable Throwable throwable) {
59             if (throwable != null) {
60                 Log.e("OptionsFecthedListener", "Error loading options", throwable);
61             }
62         }
63     }
64 
65     /**
66      * Returns whether this customization is available in the system.
67      */
isAvailable()68     boolean isAvailable();
69 
70     /**
71      * Applies the given option into the system.
72      */
apply(T option, Callback callback)73     void apply(T option, Callback callback);
74 
75     /**
76      * Loads the available options for the type of Customization managed by this class, calling the
77      * given callback when done.
78      */
fetchOptions(OptionsFetchedListener<T> callback, boolean reload)79     void fetchOptions(OptionsFetchedListener<T> callback, boolean reload);
80 }
81