1 /* 2 * Copyright (C) 2022 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.wallpaper.effects; 17 18 import android.content.Context; 19 import android.net.Uri; 20 import android.os.Bundle; 21 22 /** 23 * Utility class to provide methods to generate effects for the wallpaper. 24 */ 25 public abstract class EffectsController { 26 public static final int ERROR_ORIGINAL_DESTROY_CONTROLLER = -16; 27 public static final int ERROR_ORIGINAL_FINISH_ONGOING_SERVICE = -8; 28 public static final int ERROR_ORIGINAL_SERVICE_DISCONNECT = -4; 29 public static final int ERROR_ORIGINAL_TIME_OUT = -2; 30 31 public static final int RESULT_ORIGINAL_UNKNOWN = -1; 32 public static final int RESULT_SUCCESS = 0; 33 public static final int RESULT_ERROR_TRY_ANOTHER_PHOTO = 1; 34 public static final int RESULT_ERROR_TRY_AGAIN_LATER = 2; 35 public static final int RESULT_ERROR_CONTINUE = 4; 36 public static final int RESULT_ERROR_DEFAULT = 37 RESULT_ERROR_TRY_ANOTHER_PHOTO + RESULT_ERROR_CONTINUE; 38 public static final int RESULT_ERROR_DISCONNECT_NO_BUTTON = 8; 39 public static final int RESULT_PROBE_SUCCESS = 16; 40 public static final int RESULT_PROBE_ERROR = 32; 41 public static final int RESULT_SUCCESS_REUSED = 64; 42 public static final int RESULT_SUCCESS_WITH_GENERATION_ERROR = 128; 43 public static final int RESULT_ERROR_PROBE_SUPPORT_FOREGROUND = 256; 44 public static final int RESULT_FOREGROUND_DOWNLOAD_SUCCEEDED = 512; 45 public static final int RESULT_FOREGROUND_DOWNLOAD_FAILED = 1024; 46 public static final int RESULT_PROBE_FOREGROUND_DOWNLOADING = 2048; 47 /** 48 * Interface of the Effect enum. 49 */ 50 public interface EffectEnumInterface { 51 } 52 public enum Effect implements EffectEnumInterface { 53 NONE, 54 } 55 56 protected boolean mBound = false; 57 58 /** 59 * Call to generate an effect. 60 * 61 * @param effect the effect type we want to generate. 62 * @param image the image that will have the effect applied. 63 */ generateEffect(Effect effect, Uri image)64 public void generateEffect(Effect effect, Uri image) { 65 } 66 67 /** 68 * Binds the Effects Service. 69 */ bindEffectsService()70 public void bindEffectsService() { 71 } 72 73 /** 74 * Destroys the controller 75 */ destroy()76 public void destroy() { 77 } 78 79 /** 80 * If the Effects Service is bound. 81 * 82 * @return if the Effects Service is bound. 83 */ isBound()84 public boolean isBound() { 85 return mBound; 86 } 87 88 /** 89 * Triggers the effect. 90 * 91 * @param context the context 92 */ triggerEffect(Context context)93 public void triggerEffect(Context context) { 94 } 95 96 /** 97 * Interface to listen to different key moments of the connection with the Effects Service. 98 */ 99 public interface EffectsServiceListener { 100 /** 101 * Called when an effect has finished being processed. 102 * 103 * @param effect The effect that was generated. 104 * @param bundle The data that the Service might have sent to the picker. 105 * @param error The error code. if there's an error, value is greater than zero. 106 * @param originalStatusCode The original status code used for metrics logging. 107 * @param errorMessage The error message. 108 */ onEffectFinished(EffectEnumInterface effect, Bundle bundle, int error, int originalStatusCode, String errorMessage)109 void onEffectFinished(EffectEnumInterface effect, Bundle bundle, int error, 110 int originalStatusCode, String errorMessage); 111 } 112 113 /** 114 * Gets whether the effect triggering is successful or not. 115 * 116 * @return whether the effect triggering is successful or not. 117 */ isEffectTriggered()118 public boolean isEffectTriggered() { 119 return false; 120 } 121 122 } 123