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