Home | History | Annotate | Download | only in widget
      1 /*
      2  * Copyright 2018 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 
     17 package androidx.leanback.widget;
     18 
     19 import android.view.View;
     20 
     21 /**
     22  * Interface for a custom EditText subclass to support autofill in
     23  * {@link androidx.leanback.app.GuidedStepSupportFragment}.
     24  * <p>
     25  *
     26  * Apps who needs to supply custom layouts for {@link GuidedActionsStylist} with their own EditText
     27  * classes should implement this interface in order to support autofill in
     28  * {@link androidx.leanback.app.GuidedStepSupportFragment}. This ensures autofill event happened
     29  * within custom EditText is propagated to GuidedStepSupportFragment.
     30  * e.g.
     31  * <pre><code>
     32  * public class MyEditText extends EditText implements GuidedActionAutofillSupport {
     33  *     OnAutofillListener mAutofillViewListener;
     34  *     &#064;Override
     35  *     public void setOnAutofillListener(OnAutofillListener autofillViewListener) {
     36  *         mAutofillViewListener = autofillViewListener;
     37  *     }
     38  *
     39  *     &#064;Override
     40  *     public void autofill(AutofillValue values) {
     41  *         super.autofill(values);
     42  *         if (mAutofillViewListener != null) {
     43  *             mAutofillViewListener.onAutofill(this);
     44  *         }
     45  *     }
     46  *     // ...
     47  * }
     48  * </code></pre>
     49  *
     50  */
     51 public interface GuidedActionAutofillSupport {
     52 
     53     /**
     54      * Listener for autofill event. Leanback will set the Listener on the custom view.
     55      */
     56     interface OnAutofillListener {
     57 
     58         /**
     59          * Custom view should call this method when autofill event happened.
     60          *
     61          * @param view The view where autofill happened.
     62          */
     63         void onAutofill(View view);
     64 
     65     }
     66 
     67     /**
     68      * Sets AutofillListener on the custom view.
     69      */
     70     void setOnAutofillListener(OnAutofillListener listener);
     71 }
     72