Rebind task navigation buttons
Test: Manual Change-Id: Ia83cd9074152be8f5a1e2f6e00cac30c5109ada6
This commit is contained in:
@@ -27,16 +27,5 @@
|
||||
android:layout_marginEnd="@dimen/smallMargin"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/activity_name"
|
||||
android:textAppearance="@style/normal" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/intent_button"
|
||||
style="?android:attr/borderlessButtonStyle"
|
||||
android:layout_width="@dimen/intentButtonSize"
|
||||
android:layout_height="@dimen/intentButtonSize"
|
||||
android:src="@drawable/info_icon"
|
||||
android:tint="@color/defaultTint"
|
||||
android:tooltipText="@string/intent_button_tooltip"
|
||||
android:contentDescription="@string/intent_button_description" />
|
||||
|
||||
android:textAppearance="@style/TextAppearance.MaterialComponents.Body1" />
|
||||
</LinearLayout>
|
||||
|
||||
@@ -46,4 +46,32 @@
|
||||
android:layout_marginLeft="@dimen/smallMargin"
|
||||
android:text="@android:string/cancel" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/move_task_to_front_bar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="4dp"
|
||||
android:paddingStart="@dimen/smallMargin"
|
||||
android:paddingEnd="@dimen/smallMargin"
|
||||
android:gravity="end"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Button
|
||||
android:id="@+id/kill_task_button"
|
||||
style="@style/flatButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:text="@string/kill_task_button"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/move_task_to_front_button"
|
||||
style="@style/flatButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:text="@string/move_to_front"/>
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
@@ -24,7 +24,6 @@
|
||||
<dimen name="regularText">16sp</dimen>
|
||||
<dimen name="smallText">12sp</dimen>
|
||||
<dimen name="listItem">48dp</dimen>
|
||||
<dimen name="intentButtonSize">24dp</dimen>
|
||||
<dimen name="denseListItem">40dp</dimen>
|
||||
<dimen name="listIcon">48dp</dimen>
|
||||
<dimen name="listControl">24dp</dimen>
|
||||
|
||||
@@ -25,6 +25,9 @@ public class BaseActivityViewModel extends ViewModel {
|
||||
|
||||
private MutableLiveData<FabAction> mFabActions = new MutableLiveData<>();
|
||||
|
||||
private MutableLiveData<Object> mRefreshTree = new MutableLiveData<>();
|
||||
|
||||
|
||||
public void actOnFab(FabAction action) {
|
||||
mFabActions.setValue(action);
|
||||
}
|
||||
@@ -32,5 +35,13 @@ public class BaseActivityViewModel extends ViewModel {
|
||||
public LiveData<FabAction> getFabActions() {
|
||||
return mFabActions;
|
||||
}
|
||||
|
||||
public LiveData<Object> getRefresh() {
|
||||
return mRefreshTree;
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
mRefreshTree.setValue(new Object());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -113,15 +113,9 @@ public class InlineAdapter extends RecyclerView.Adapter<TaskViewHolder> {
|
||||
.inflate(R.layout.activity_node, mActivitiesLayout, false);
|
||||
|
||||
TextView activityName = activityView.findViewById(R.id.activity_name);
|
||||
ImageButton intentButtonView = activityView.findViewById(R.id.intent_button);
|
||||
|
||||
activityName.setText(activity.mName.getShortClassName());
|
||||
|
||||
int color = activityView.getContext().getResources()
|
||||
.getColor(ColorManager.getColorForActivity(activity.mName),
|
||||
null /* theme */);
|
||||
intentButtonView.setColorFilter(color);
|
||||
intentButtonView.setOnClickListener(clickedView -> {
|
||||
activityName.setOnClickListener(clickedView -> {
|
||||
Intent intent = activity.getIntent();
|
||||
List<String> flags;
|
||||
if (intent != null) {
|
||||
@@ -132,7 +126,8 @@ public class InlineAdapter extends RecyclerView.Adapter<TaskViewHolder> {
|
||||
} else {
|
||||
flags = Collections.singletonList("None");
|
||||
}
|
||||
showDialogWithFlags(manager, activity.mName.getShortClassName(), flags);
|
||||
showDialogWithFlags(manager, activity.mName.getShortClassName(), flags,
|
||||
task.mTaskId);
|
||||
});
|
||||
|
||||
|
||||
@@ -152,8 +147,9 @@ public class InlineAdapter extends RecyclerView.Adapter<TaskViewHolder> {
|
||||
* @param flags The flags to list.
|
||||
*/
|
||||
private void showDialogWithFlags(FragmentManager manager,
|
||||
String shortClassName, List<String> flags) {
|
||||
IntentDialogFragment.newInstance(shortClassName, flags).show(manager, "intentDialog");
|
||||
String shortClassName, List<String> flags, int taskId) {
|
||||
IntentDialogFragment.newInstance(shortClassName, flags, taskId).show(manager,
|
||||
"intentDialog");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package com.example.android.intentplayground;
|
||||
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.os.Bundle;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
@@ -30,6 +31,8 @@ import android.widget.ScrollView;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -39,20 +42,26 @@ import java.util.List;
|
||||
public class IntentDialogFragment extends DialogFragment {
|
||||
private List<String> mFlags;
|
||||
private String mActivityName;
|
||||
private int mTaskId;
|
||||
private BaseActivityViewModel mViewModel;
|
||||
private static final String ARGUMENT_ACTIVITY_NAME = "activityName";
|
||||
private static final String ARGUMENT_FLAGS = "flags";
|
||||
private static final String TASK_ID = "taskId";
|
||||
|
||||
/**
|
||||
* Creates a new IntentDialogFragment to display the given flags.
|
||||
*
|
||||
* @param activityName The name of the activity, also the title of the dialog.
|
||||
* @param flags The list of flags to be displayed.
|
||||
* @param flags The list of flags to be displayed.
|
||||
* @return A new IntentDialogFragment.
|
||||
*/
|
||||
public static IntentDialogFragment newInstance(String activityName, List<String> flags) {
|
||||
public static IntentDialogFragment newInstance(String activityName, List<String> flags,
|
||||
int taskId) {
|
||||
IntentDialogFragment fragment = new IntentDialogFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putString(ARGUMENT_ACTIVITY_NAME, activityName);
|
||||
args.putStringArrayList(ARGUMENT_FLAGS, new ArrayList<>(flags));
|
||||
args.putInt(TASK_ID, taskId);
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
@@ -63,12 +72,15 @@ public class IntentDialogFragment extends DialogFragment {
|
||||
Bundle args = getArguments();
|
||||
mFlags = args.getStringArrayList(ARGUMENT_FLAGS);
|
||||
mActivityName = args.getString(ARGUMENT_ACTIVITY_NAME);
|
||||
mTaskId = args.getInt(TASK_ID);
|
||||
mViewModel = (new ViewModelProvider(getActivity(),
|
||||
new ViewModelProvider.NewInstanceFactory())).get(BaseActivityViewModel.class);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
Bundle savedInstanceState) {
|
||||
getDialog().setTitle(mActivityName + getString(R.string.dialog_intent_flags));
|
||||
LinearLayout rootLayout = (LinearLayout) inflater
|
||||
.inflate(R.layout.fragment_intent_dialog, container, false /* attachToRoot */);
|
||||
@@ -79,6 +91,21 @@ public class IntentDialogFragment extends DialogFragment {
|
||||
rootLayout.findViewById(R.id.dialog_cancel).setOnClickListener(view -> {
|
||||
getDialog().dismiss();
|
||||
});
|
||||
|
||||
Button bringToFront = rootLayout.findViewById(R.id.move_task_to_front_button);
|
||||
bringToFront.setOnClickListener(v -> {
|
||||
moveTaskToFront(mTaskId);
|
||||
getDialog().dismiss();
|
||||
mViewModel.refresh();
|
||||
});
|
||||
|
||||
Button removeTask = rootLayout.findViewById(R.id.kill_task_button);
|
||||
removeTask.setOnClickListener(v -> {
|
||||
removeTask(mTaskId);
|
||||
getDialog().dismiss();
|
||||
mViewModel.refresh();
|
||||
});
|
||||
|
||||
Button copyFlagsButton = rootLayout.findViewById(R.id.copy_flags_button);
|
||||
if (mFlags.get(0).equals("None")) {
|
||||
copyFlagsButton.setEnabled(false);
|
||||
@@ -95,4 +122,18 @@ public class IntentDialogFragment extends DialogFragment {
|
||||
}
|
||||
return rootLayout;
|
||||
}
|
||||
|
||||
private void removeTask(int taskId) {
|
||||
ActivityManager am = getActivity().getSystemService(ActivityManager.class);
|
||||
am.getAppTasks().forEach(task -> {
|
||||
if (task.getTaskInfo().persistentId == taskId) {
|
||||
task.finishAndRemoveTask();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void moveTaskToFront(int taskId) {
|
||||
ActivityManager am = getActivity().getSystemService(ActivityManager.class);
|
||||
am.moveTaskToFront(taskId, 0 /* flags */);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,6 +59,9 @@ public class TreeFragment extends Fragment {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
mViewModel = (new ViewModelProvider(getActivity(),
|
||||
new ViewModelProvider.NewInstanceFactory())).get(BaseActivityViewModel.class);
|
||||
|
||||
mViewModel.getRefresh().observe(this, v -> this.onResumeHelper());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -86,21 +89,6 @@ public class TreeFragment extends Fragment {
|
||||
new LinearLayoutManager(getContext(), RecyclerView.VERTICAL, false));
|
||||
}
|
||||
|
||||
private void removeTask(int taskId) {
|
||||
ActivityManager am = mActivity.getSystemService(ActivityManager.class);
|
||||
am.getAppTasks().forEach(task -> {
|
||||
if (task.getTaskInfo().persistentId == taskId) {
|
||||
task.finishAndRemoveTask();
|
||||
}
|
||||
});
|
||||
onResume(); // manually trigger UI refresh
|
||||
}
|
||||
|
||||
private void moveTaskToFront(int taskId) {
|
||||
ActivityManager am = mActivity.getSystemService(ActivityManager.class);
|
||||
am.moveTaskToFront(taskId, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Expand a task group to show its child activities.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user