| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
package com.android.internal.globalactions; |
| 17 |
|
| 18 |
import android.content.Context; |
| 19 |
import android.graphics.drawable.Drawable; |
| 20 |
import android.text.TextUtils; |
| 21 |
import android.view.LayoutInflater; |
| 22 |
import android.view.View; |
| 23 |
import android.view.ViewGroup; |
| 24 |
import android.widget.ImageView; |
| 25 |
import android.widget.TextView; |
| 26 |
import com.android.internal.R; |
| 27 |
|
| 28 |
|
| 29 |
public abstract class SinglePressAction implements Action { |
| 30 |
private final int mIconResId; |
| 31 |
private final Drawable mIcon; |
| 32 |
private final int mMessageResId; |
| 33 |
private final CharSequence mMessage; |
| 34 |
|
| 35 |
protected SinglePressAction(int iconResId, int messageResId) { |
| 36 |
mIconResId = iconResId; |
| 37 |
mMessageResId = messageResId; |
| 38 |
mMessage = null; |
| 39 |
mIcon = null; |
| 40 |
} |
| 41 |
|
| 42 |
protected SinglePressAction(int iconResId, Drawable icon, CharSequence message) { |
| 43 |
mIconResId = iconResId; |
| 44 |
mMessageResId = 0; |
| 45 |
mMessage = message; |
| 46 |
mIcon = icon; |
| 47 |
} |
| 48 |
|
| 49 |
@Override |
| 50 |
public boolean isEnabled() { |
| 51 |
return true; |
| 52 |
} |
| 53 |
|
| 54 |
public String getStatus() { |
| 55 |
return null; |
| 56 |
} |
| 57 |
|
| 58 |
@Override |
| 59 |
abstract public void onPress(); |
| 60 |
|
| 61 |
@Override |
| 62 |
public CharSequence getLabelForAccessibility(Context context) { |
| 63 |
if (mMessage != null) { |
| 64 |
return mMessage; |
| 65 |
} else { |
| 66 |
return context.getString(mMessageResId); |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
@Override |
| 71 |
public View create( |
| 72 |
Context context, View convertView, ViewGroup parent, LayoutInflater inflater) { |
| 73 |
View v = inflater.inflate(R.layout.global_actions_item, parent, false); |
| 74 |
|
| 75 |
ImageView icon = v.findViewById(R.id.icon); |
| 76 |
TextView messageView = v.findViewById(R.id.message); |
| 77 |
|
| 78 |
TextView statusView = v.findViewById(R.id.status); |
| 79 |
final String status = getStatus(); |
| 80 |
if (statusView != null) { |
| 81 |
if (!TextUtils.isEmpty(status)) { |
| 82 |
statusView.setText(status); |
| 83 |
} else { |
| 84 |
statusView.setVisibility(View.GONE); |
| 85 |
} |
| 86 |
} |
| 87 |
if (icon != null) { |
| 88 |
if (mIcon != null) { |
| 89 |
icon.setImageDrawable(mIcon); |
| 90 |
icon.setScaleType(ImageView.ScaleType.CENTER_CROP); |
| 91 |
} else if (mIconResId != 0) { |
| 92 |
icon.setImageDrawable(context.getDrawable(mIconResId)); |
| 93 |
} |
| 94 |
} |
| 95 |
if (messageView != null) { |
| 96 |
if (mMessage != null) { |
| 97 |
messageView.setText(mMessage); |
| 98 |
} else { |
| 99 |
messageView.setText(mMessageResId); |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
return v; |
| 104 |
} |
| 105 |
} |