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 android.text.TextUtils; 19 import android.view.View; 20 import android.widget.ImageView; 21 22 import com.android.customization.model.CustomizationManager; 23 import com.android.customization.model.CustomizationOption; 24 import com.android.wallpaper.R; 25 import com.android.wallpaper.asset.Asset; 26 27 public class Clockface implements CustomizationOption<Clockface> { 28 29 private final String mTitle; 30 private final String mId; 31 private final Asset mPreview; 32 private final Asset mThumbnail; 33 Clockface(String title, String id, Asset preview, Asset thumbnail)34 private Clockface(String title, String id, Asset preview, Asset thumbnail) { 35 mTitle = title; 36 mId = id; 37 mPreview = preview; 38 mThumbnail = thumbnail; 39 } 40 41 @Override getTitle()42 public String getTitle() { 43 return mTitle; 44 } 45 46 @Override bindThumbnailTile(View view)47 public void bindThumbnailTile(View view) { 48 ImageView thumbView = view.findViewById(R.id.clock_option_thumbnail); 49 mThumbnail.loadDrawableWithTransition(thumbView.getContext(), thumbView, 50, null, 50 thumbView.getResources().getColor(android.R.color.transparent, null)); 51 } 52 53 @Override isActive(CustomizationManager<Clockface> manager)54 public boolean isActive(CustomizationManager<Clockface> manager) { 55 String currentClock = ((BaseClockManager) manager).getCurrentClock(); 56 // Empty clock Id is the default system clock 57 return (TextUtils.isEmpty(currentClock) && TextUtils.isEmpty(mId)) 58 || (mId != null && mId.equals(currentClock)); 59 } 60 61 @Override getLayoutResId()62 public int getLayoutResId() { 63 return R.layout.clock_option; 64 } 65 getPreviewAsset()66 public Asset getPreviewAsset() { 67 return mPreview; 68 } 69 getId()70 public String getId() { 71 return mId; 72 } 73 74 public static class Builder { 75 private String mTitle; 76 private String mId; 77 private Asset mPreview; 78 private Asset mThumbnail; 79 build()80 public Clockface build() { 81 return new Clockface(mTitle, mId, mPreview, mThumbnail); 82 } 83 setTitle(String title)84 public Builder setTitle(String title) { 85 mTitle = title; 86 return this; 87 } 88 setId(String id)89 public Builder setId(String id) { 90 mId = id; 91 return this; 92 } 93 setPreview(Asset preview)94 public Builder setPreview(Asset preview) { 95 mPreview = preview; 96 return this; 97 } 98 setThumbnail(Asset thumbnail)99 public Builder setThumbnail(Asset thumbnail) { 100 mThumbnail = thumbnail; 101 return this; 102 } 103 } 104 } 105