• 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.clock;
17 
18 import com.android.customization.model.CustomizationManager;
19 
20 /**
21  * {@link CustomizationManager} for clock faces.
22  */
23 public abstract class BaseClockManager implements CustomizationManager<Clockface> {
24 
25     private final ClockProvider mClockProvider;
26 
BaseClockManager(ClockProvider provider)27     public BaseClockManager(ClockProvider provider) {
28         mClockProvider = provider;
29     }
30 
31     @Override
isAvailable()32     public boolean isAvailable() {
33         return mClockProvider.isAvailable();
34     }
35 
36     @Override
apply(Clockface option, Callback callback)37     public void apply(Clockface option, Callback callback) {
38         handleApply(option, callback);
39     }
40 
41     @Override
fetchOptions(OptionsFetchedListener<Clockface> callback, boolean reload)42     public void fetchOptions(OptionsFetchedListener<Clockface> callback, boolean reload) {
43         mClockProvider.fetch(callback, false);
44     }
45 
46     /** Returns the ID of the current clock face, which may be null for the default clock face. */
getCurrentClock()47     String getCurrentClock() {
48         return lookUpCurrentClock();
49     }
50 
51     /**
52      * Implement to apply the clock picked by the user for {@link BaseClockManager#apply}.
53      *
54      * @param option Clock option, containing ID of the clock, that the user picked.
55      * @param callback Report success and failure.
56      */
handleApply(Clockface option, Callback callback)57     protected abstract void handleApply(Clockface option, Callback callback);
58 
59     /**
60      * Implement to look up the current clock face for {@link BaseClockManager#getCurrentClock()}.
61      *
62      * @return ID of current clock. Can be null for the default clock face.
63      */
lookUpCurrentClock()64     protected abstract String lookUpCurrentClock();
65 }
66