| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.android.internal.widget; |
| 18 |
|
| 19 |
import android.annotation.Nullable; |
| 20 |
import android.content.Context; |
| 21 |
import android.util.AttributeSet; |
| 22 |
import android.view.View; |
| 23 |
import android.widget.RemoteViews; |
| 24 |
import android.widget.TextView; |
| 25 |
|
| 26 |
import java.util.function.Consumer; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
@RemoteViews.RemoteView |
| 32 |
public class ObservableTextView extends TextView { |
| 33 |
|
| 34 |
private Consumer<Integer> mOnVisibilityChangedListener; |
| 35 |
|
| 36 |
public ObservableTextView(Context context) { |
| 37 |
super(context); |
| 38 |
} |
| 39 |
|
| 40 |
public ObservableTextView(Context context, @Nullable AttributeSet attrs) { |
| 41 |
super(context, attrs); |
| 42 |
} |
| 43 |
|
| 44 |
public ObservableTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { |
| 45 |
super(context, attrs, defStyleAttr); |
| 46 |
} |
| 47 |
|
| 48 |
public ObservableTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, |
| 49 |
int defStyleRes) { |
| 50 |
super(context, attrs, defStyleAttr, defStyleRes); |
| 51 |
} |
| 52 |
|
| 53 |
@Override |
| 54 |
protected void onVisibilityChanged(View changedView, int visibility) { |
| 55 |
super.onVisibilityChanged(changedView, visibility); |
| 56 |
if (changedView == this) { |
| 57 |
if (mOnVisibilityChangedListener != null) { |
| 58 |
mOnVisibilityChangedListener.accept(visibility); |
| 59 |
} |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
public void setOnVisibilityChangedListener(Consumer<Integer> listener) { |
| 64 |
mOnVisibilityChangedListener = listener; |
| 65 |
} |
| 66 |
} |