| 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.view.LayoutInflater; |
| 20 |
import android.view.View; |
| 21 |
import android.view.ViewGroup; |
| 22 |
import android.widget.BaseAdapter; |
| 23 |
import java.util.function.BooleanSupplier; |
| 24 |
import java.util.List; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
public class ActionsAdapter extends BaseAdapter { |
| 32 |
private final Context mContext; |
| 33 |
private final List<Action> mItems; |
| 34 |
private final BooleanSupplier mDeviceProvisioned; |
| 35 |
private final BooleanSupplier mKeyguardShowing; |
| 36 |
|
| 37 |
public ActionsAdapter(Context context, List<Action> items, |
| 38 |
BooleanSupplier deviceProvisioned, BooleanSupplier keyguardShowing) { |
| 39 |
mContext = context; |
| 40 |
mItems = items; |
| 41 |
mDeviceProvisioned = deviceProvisioned; |
| 42 |
mKeyguardShowing = keyguardShowing; |
| 43 |
} |
| 44 |
|
| 45 |
@Override |
| 46 |
public int getCount() { |
| 47 |
final boolean keyguardShowing = mKeyguardShowing.getAsBoolean(); |
| 48 |
final boolean deviceProvisioned = mDeviceProvisioned.getAsBoolean(); |
| 49 |
int count = 0; |
| 50 |
|
| 51 |
for (int i = 0; i < mItems.size(); i++) { |
| 52 |
final Action action = mItems.get(i); |
| 53 |
|
| 54 |
if (keyguardShowing && !action.showDuringKeyguard()) { |
| 55 |
continue; |
| 56 |
} |
| 57 |
if (!deviceProvisioned && !action.showBeforeProvisioning()) { |
| 58 |
continue; |
| 59 |
} |
| 60 |
count++; |
| 61 |
} |
| 62 |
return count; |
| 63 |
} |
| 64 |
|
| 65 |
@Override |
| 66 |
public boolean isEnabled(int position) { |
| 67 |
return getItem(position).isEnabled(); |
| 68 |
} |
| 69 |
|
| 70 |
@Override |
| 71 |
public boolean areAllItemsEnabled() { |
| 72 |
return false; |
| 73 |
} |
| 74 |
|
| 75 |
@Override |
| 76 |
public Action getItem(int position) { |
| 77 |
final boolean keyguardShowing = mKeyguardShowing.getAsBoolean(); |
| 78 |
final boolean deviceProvisioned = mDeviceProvisioned.getAsBoolean(); |
| 79 |
|
| 80 |
int filteredPos = 0; |
| 81 |
for (int i = 0; i < mItems.size(); i++) { |
| 82 |
final Action action = mItems.get(i); |
| 83 |
if (keyguardShowing && !action.showDuringKeyguard()) { |
| 84 |
continue; |
| 85 |
} |
| 86 |
if (!deviceProvisioned && !action.showBeforeProvisioning()) { |
| 87 |
continue; |
| 88 |
} |
| 89 |
if (filteredPos == position) { |
| 90 |
return action; |
| 91 |
} |
| 92 |
filteredPos++; |
| 93 |
} |
| 94 |
|
| 95 |
throw new IllegalArgumentException("position " + position |
| 96 |
+ " out of range of showable actions" |
| 97 |
+ ", filtered count=" + getCount() |
| 98 |
+ ", keyguardshowing=" + keyguardShowing |
| 99 |
+ ", provisioned=" + deviceProvisioned); |
| 100 |
} |
| 101 |
|
| 102 |
@Override |
| 103 |
public long getItemId(int position) { |
| 104 |
return position; |
| 105 |
} |
| 106 |
|
| 107 |
@Override |
| 108 |
public View getView(int position, View convertView, ViewGroup parent) { |
| 109 |
Action action = getItem(position); |
| 110 |
return action.create(mContext, convertView, parent, LayoutInflater.from(mContext)); |
| 111 |
} |
| 112 |
} |