diff options
| author | 2015-12-14 13:57:36 -0500 | |
|---|---|---|
| committer | 2015-12-16 15:27:05 -0500 | |
| commit | b169ebd4c40b78d8a4c79e416c288af2ab5b5046 (patch) | |
| tree | 87daaebf06d0568cf36b4970ddc7a9f23486a654 | |
| parent | 062667710edcad7a01d7ece3e2bc4a83ee2a2ca3 (diff) | |
Loading activity icons in History view.
Change-Id: I68bbef59d380ce7abe251fca75135775528429d5
4 files changed, 106 insertions, 36 deletions
diff --git a/packages/SystemUI/res/layout/recents_history_task.xml b/packages/SystemUI/res/layout/recents_history_task.xml index b9de15606bfb..ae1100604840 100644 --- a/packages/SystemUI/res/layout/recents_history_task.xml +++ b/packages/SystemUI/res/layout/recents_history_task.xml @@ -13,15 +13,30 @@ See the License for the specific language governing permissions and limitations under the License. --> -<TextView +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:theme="@android:style/Theme.Material" android:layout_width="match_parent" android:layout_height="48dp" - android:paddingLeft="32dp" - android:gravity="start|center_vertical" - android:textSize="14sp" - android:textColor="#FFFFFF" - android:fontFamily="sans-serif-medium" - android:background="?android:selectableItemBackground" - android:alpha="1" />
\ No newline at end of file + android:orientation="horizontal" + android:clickable="true" + android:focusable="true" + android:background="?android:selectableItemBackground"> + <ImageView + android:id="@+id/icon" + android:layout_width="32dp" + android:layout_height="32dp" + android:layout_gravity="center" + android:layout_marginStart="16dp" /> + <TextView + android:id="@+id/description" + android:layout_width="0dp" + android:layout_height="match_parent" + android:layout_weight="1" + android:layout_gravity="end" + android:paddingStart="16dp" + android:gravity="start|center_vertical" + android:textSize="14sp" + android:textColor="#FFFFFF" + android:fontFamily="sans-serif-medium" /> +</LinearLayout>
\ No newline at end of file diff --git a/packages/SystemUI/src/com/android/systemui/recents/history/RecentsHistoryAdapter.java b/packages/SystemUI/src/com/android/systemui/recents/history/RecentsHistoryAdapter.java index 06265bd8c12b..abe3c01f836f 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/history/RecentsHistoryAdapter.java +++ b/packages/SystemUI/src/com/android/systemui/recents/history/RecentsHistoryAdapter.java @@ -23,10 +23,12 @@ import android.text.format.DateFormat; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.ImageView; import android.widget.TextView; import com.android.systemui.R; import com.android.systemui.recents.Recents; import com.android.systemui.recents.misc.SystemServicesProxy; +import com.android.systemui.recents.model.RecentsTaskLoader; import com.android.systemui.recents.model.Task; import java.util.ArrayList; @@ -49,14 +51,34 @@ public class RecentsHistoryAdapter extends RecyclerView.Adapter<RecentsHistoryAd static final int TASK_ROW_VIEW_TYPE = 1; /** - * View holder implementation. + * View holder implementation. The {@param TaskCallbacks} are only called for TaskRow view + * holders. */ - public static class ViewHolder extends RecyclerView.ViewHolder { - public View mContent; + public static class ViewHolder extends RecyclerView.ViewHolder implements Task.TaskCallbacks { + public final View content; public ViewHolder(View v) { super(v); - mContent = v; + content = v; + } + + @Override + public void onTaskDataLoaded(Task task) { + // This callback is only made for TaskRow view holders + ImageView iv = (ImageView) content.findViewById(R.id.icon); + iv.setImageDrawable(task.applicationIcon); + } + + @Override + public void onTaskDataUnloaded() { + // This callback is only made for TaskRow view holders + ImageView iv = (ImageView) content.findViewById(R.id.icon); + iv.setImageBitmap(null); + } + + @Override + public void onTaskStackIdChanged() { + // Do nothing, this callback is only made for TaskRow view holders } } @@ -89,18 +111,16 @@ public class RecentsHistoryAdapter extends RecyclerView.Adapter<RecentsHistoryAd */ private static class TaskRow implements Row, View.OnClickListener { - public final String description; - private final int mTaskId; + public final Task task; public TaskRow(Task task) { - mTaskId = task.key.id; - description = task.activityLabel; + this.task = task; } @Override public void onClick(View v) { SystemServicesProxy ssp = Recents.getSystemServices(); - ssp.startActivityFromRecents(v.getContext(), mTaskId, description, + ssp.startActivityFromRecents(v.getContext(), task.key.id, task.activityLabel, ActivityOptions.makeBasic()); } @@ -184,25 +204,45 @@ public class RecentsHistoryAdapter extends RecyclerView.Adapter<RecentsHistoryAd @Override public void onBindViewHolder(ViewHolder holder, int position) { + RecentsTaskLoader loader = Recents.getTaskLoader(); + Row row = mRows.get(position); - int viewType = mRows.get(position).getViewType(); + int viewType = row.getViewType(); switch (viewType) { case DATE_ROW_VIEW_TYPE: { - TextView tv = (TextView) holder.mContent; + TextView tv = (TextView) holder.content; tv.setText(((DateRow) row).date); break; } case TASK_ROW_VIEW_TYPE: { - TextView tv = (TextView) holder.mContent; TaskRow taskRow = (TaskRow) row; - tv.setText(taskRow.description); - tv.setOnClickListener(taskRow); + taskRow.task.addCallback(holder); + TextView tv = (TextView) holder.content.findViewById(R.id.description); + tv.setText(taskRow.task.activityLabel); + holder.content.setOnClickListener(taskRow); + loader.loadTaskData(taskRow.task); break; } } } @Override + public void onViewRecycled(ViewHolder holder) { + RecentsTaskLoader loader = Recents.getTaskLoader(); + + int position = holder.getAdapterPosition(); + if (position != RecyclerView.NO_POSITION) { + Row row = mRows.get(position); + int viewType = row.getViewType(); + if (viewType == TASK_ROW_VIEW_TYPE) { + TaskRow taskRow = (TaskRow) row; + taskRow.task.removeCallback(holder); + loader.unloadTaskData(taskRow.task); + } + } + } + + @Override public int getItemCount() { return mRows.size(); } diff --git a/packages/SystemUI/src/com/android/systemui/recents/model/Task.java b/packages/SystemUI/src/com/android/systemui/recents/model/Task.java index 3aed3f306097..ffbbfe8e2b0a 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/model/Task.java +++ b/packages/SystemUI/src/com/android/systemui/recents/model/Task.java @@ -26,6 +26,7 @@ import com.android.systemui.recents.Recents; import com.android.systemui.recents.misc.SystemServicesProxy; import com.android.systemui.recents.misc.Utilities; +import java.util.ArrayList; import java.util.Objects; @@ -36,7 +37,7 @@ public class Task { /* Task callbacks */ public interface TaskCallbacks { /* Notifies when a task has been bound */ - public void onTaskDataLoaded(); + public void onTaskDataLoaded(Task task); /* Notifies when a task has been unbound */ public void onTaskDataUnloaded(); /* Notifies when a task's stack id has changed. */ @@ -110,7 +111,7 @@ public class Task { public String iconFilename; public Rect bounds; - private TaskCallbacks mCb; + private ArrayList<TaskCallbacks> mCallbacks = new ArrayList<>(); public Task() { // Do nothing @@ -157,9 +158,20 @@ public class Task { this.bounds = o.bounds; } - /** Set the callbacks */ - public void setCallbacks(TaskCallbacks cb) { - mCb = cb; + /** + * Add a callback. + */ + public void addCallback(TaskCallbacks cb) { + if (!mCallbacks.contains(cb)) { + mCallbacks.add(cb); + } + } + + /** + * Remove a callback. + */ + public void removeCallback(TaskCallbacks cb) { + mCallbacks.remove(cb); } /** Set the grouping */ @@ -175,8 +187,9 @@ public class Task { */ public void setStackId(int stackId) { key.stackId = stackId; - if (mCb != null) { - mCb.onTaskStackIdChanged(); + int callbackCount = mCallbacks.size(); + for (int i = 0; i < callbackCount; i++) { + mCallbacks.get(i).onTaskStackIdChanged(); } } @@ -192,8 +205,9 @@ public class Task { public void notifyTaskDataLoaded(Bitmap thumbnail, Drawable applicationIcon) { this.applicationIcon = applicationIcon; this.thumbnail = thumbnail; - if (mCb != null) { - mCb.onTaskDataLoaded(); + int callbackCount = mCallbacks.size(); + for (int i = 0; i < callbackCount; i++) { + mCallbacks.get(i).onTaskDataLoaded(this); } } @@ -201,8 +215,9 @@ public class Task { public void notifyTaskDataUnloaded(Bitmap defaultThumbnail, Drawable defaultApplicationIcon) { applicationIcon = defaultApplicationIcon; thumbnail = defaultThumbnail; - if (mCb != null) { - mCb.onTaskDataUnloaded(); + int callbackCount = mCallbacks.size(); + for (int i = 0; i < callbackCount; i++) { + mCallbacks.get(i).onTaskDataUnloaded(); } } diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/TaskView.java b/packages/SystemUI/src/com/android/systemui/recents/views/TaskView.java index ab51d5f26858..3b6130c76bf4 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/views/TaskView.java +++ b/packages/SystemUI/src/com/android/systemui/recents/views/TaskView.java @@ -678,7 +678,7 @@ public class TaskView extends FrameLayout implements Task.TaskCallbacks, /** Binds this task view to the task */ public void onTaskBound(Task t) { mTask = t; - mTask.setCallbacks(this); + mTask.addCallback(this); // Hide the action button if lock to app is disabled for this view int lockButtonVisibility = (!t.lockToTaskEnabled || !t.lockToThisTask) ? GONE : VISIBLE; @@ -689,7 +689,7 @@ public class TaskView extends FrameLayout implements Task.TaskCallbacks, } @Override - public void onTaskDataLoaded() { + public void onTaskDataLoaded(Task task) { if (mThumbnailView != null && mHeaderView != null) { // Bind each of the views to the new task data mThumbnailView.rebindToTask(mTask); @@ -706,7 +706,7 @@ public class TaskView extends FrameLayout implements Task.TaskCallbacks, public void onTaskDataUnloaded() { if (mThumbnailView != null && mHeaderView != null) { // Unbind each of the views from the task data and remove the task callback - mTask.setCallbacks(null); + mTask.removeCallback(this); mThumbnailView.unbindFromTask(); mHeaderView.unbindFromTask(); // Unbind any listeners |