1 /* 2 * Copyright 2021 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 androidx.constraintlayout.core.state; 17 18 import java.util.HashMap; 19 import java.util.Set; 20 21 public class Registry { 22 23 private static final Registry sRegistry = new Registry(); 24 getInstance()25 public static Registry getInstance() { 26 return sRegistry; 27 } 28 29 private HashMap<String, RegistryCallback> mCallbacks = new HashMap<>(); 30 31 // @TODO: add description register(String name, RegistryCallback callback)32 public void register(String name, RegistryCallback callback) { 33 mCallbacks.put(name, callback); 34 } 35 36 // @TODO: add description unregister(String name, RegistryCallback callback)37 public void unregister(String name, RegistryCallback callback) { 38 mCallbacks.remove(name); 39 } 40 41 // @TODO: add description updateContent(String name, String content)42 public void updateContent(String name, String content) { 43 RegistryCallback callback = mCallbacks.get(name); 44 if (callback != null) { 45 callback.onNewMotionScene(content); 46 } 47 } 48 49 // @TODO: add description updateProgress(String name, float progress)50 public void updateProgress(String name, float progress) { 51 RegistryCallback callback = mCallbacks.get(name); 52 if (callback != null) { 53 callback.onProgress(progress); 54 } 55 } 56 57 // @TODO: add description currentContent(String name)58 public String currentContent(String name) { 59 RegistryCallback callback = mCallbacks.get(name); 60 if (callback != null) { 61 return callback.currentMotionScene(); 62 } 63 return null; 64 } 65 66 // @TODO: add description currentLayoutInformation(String name)67 public String currentLayoutInformation(String name) { 68 RegistryCallback callback = mCallbacks.get(name); 69 if (callback != null) { 70 return callback.currentLayoutInformation(); 71 } 72 return null; 73 } 74 75 // @TODO: add description setDrawDebug(String name, int debugMode)76 public void setDrawDebug(String name, int debugMode) { 77 RegistryCallback callback = mCallbacks.get(name); 78 if (callback != null) { 79 callback.setDrawDebug(debugMode); 80 } 81 } 82 83 // @TODO: add description setLayoutInformationMode(String name, int mode)84 public void setLayoutInformationMode(String name, int mode) { 85 RegistryCallback callback = mCallbacks.get(name); 86 if (callback != null) { 87 callback.setLayoutInformationMode(mode); 88 } 89 } 90 getLayoutList()91 public Set<String> getLayoutList() { 92 return mCallbacks.keySet(); 93 } 94 95 // @TODO: add description getLastModified(String name)96 public long getLastModified(String name) { 97 RegistryCallback callback = mCallbacks.get(name); 98 if (callback != null) { 99 return callback.getLastModified(); 100 } 101 return Long.MAX_VALUE; 102 } 103 104 // @TODO: add description updateDimensions(String name, int width, int height)105 public void updateDimensions(String name, int width, int height) { 106 RegistryCallback callback = mCallbacks.get(name); 107 if (callback != null) { 108 callback.onDimensions(width, height); 109 } 110 } 111 } 112