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_marginEnd="@dimen/smallMargin"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:text="@string/activity_name"
|
android:text="@string/activity_name"
|
||||||
android:textAppearance="@style/normal" />
|
android:textAppearance="@style/TextAppearance.MaterialComponents.Body1" />
|
||||||
|
|
||||||
<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" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|||||||
@@ -46,4 +46,32 @@
|
|||||||
android:layout_marginLeft="@dimen/smallMargin"
|
android:layout_marginLeft="@dimen/smallMargin"
|
||||||
android:text="@android:string/cancel" />
|
android:text="@android:string/cancel" />
|
||||||
</LinearLayout>
|
</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>
|
</LinearLayout>
|
||||||
@@ -24,7 +24,6 @@
|
|||||||
<dimen name="regularText">16sp</dimen>
|
<dimen name="regularText">16sp</dimen>
|
||||||
<dimen name="smallText">12sp</dimen>
|
<dimen name="smallText">12sp</dimen>
|
||||||
<dimen name="listItem">48dp</dimen>
|
<dimen name="listItem">48dp</dimen>
|
||||||
<dimen name="intentButtonSize">24dp</dimen>
|
|
||||||
<dimen name="denseListItem">40dp</dimen>
|
<dimen name="denseListItem">40dp</dimen>
|
||||||
<dimen name="listIcon">48dp</dimen>
|
<dimen name="listIcon">48dp</dimen>
|
||||||
<dimen name="listControl">24dp</dimen>
|
<dimen name="listControl">24dp</dimen>
|
||||||
|
|||||||
@@ -25,6 +25,9 @@ public class BaseActivityViewModel extends ViewModel {
|
|||||||
|
|
||||||
private MutableLiveData<FabAction> mFabActions = new MutableLiveData<>();
|
private MutableLiveData<FabAction> mFabActions = new MutableLiveData<>();
|
||||||
|
|
||||||
|
private MutableLiveData<Object> mRefreshTree = new MutableLiveData<>();
|
||||||
|
|
||||||
|
|
||||||
public void actOnFab(FabAction action) {
|
public void actOnFab(FabAction action) {
|
||||||
mFabActions.setValue(action);
|
mFabActions.setValue(action);
|
||||||
}
|
}
|
||||||
@@ -32,5 +35,13 @@ public class BaseActivityViewModel extends ViewModel {
|
|||||||
public LiveData<FabAction> getFabActions() {
|
public LiveData<FabAction> getFabActions() {
|
||||||
return mFabActions;
|
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);
|
.inflate(R.layout.activity_node, mActivitiesLayout, false);
|
||||||
|
|
||||||
TextView activityName = activityView.findViewById(R.id.activity_name);
|
TextView activityName = activityView.findViewById(R.id.activity_name);
|
||||||
ImageButton intentButtonView = activityView.findViewById(R.id.intent_button);
|
|
||||||
|
|
||||||
activityName.setText(activity.mName.getShortClassName());
|
activityName.setText(activity.mName.getShortClassName());
|
||||||
|
activityName.setOnClickListener(clickedView -> {
|
||||||
int color = activityView.getContext().getResources()
|
|
||||||
.getColor(ColorManager.getColorForActivity(activity.mName),
|
|
||||||
null /* theme */);
|
|
||||||
intentButtonView.setColorFilter(color);
|
|
||||||
intentButtonView.setOnClickListener(clickedView -> {
|
|
||||||
Intent intent = activity.getIntent();
|
Intent intent = activity.getIntent();
|
||||||
List<String> flags;
|
List<String> flags;
|
||||||
if (intent != null) {
|
if (intent != null) {
|
||||||
@@ -132,7 +126,8 @@ public class InlineAdapter extends RecyclerView.Adapter<TaskViewHolder> {
|
|||||||
} else {
|
} else {
|
||||||
flags = Collections.singletonList("None");
|
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.
|
* @param flags The flags to list.
|
||||||
*/
|
*/
|
||||||
private void showDialogWithFlags(FragmentManager manager,
|
private void showDialogWithFlags(FragmentManager manager,
|
||||||
String shortClassName, List<String> flags) {
|
String shortClassName, List<String> flags, int taskId) {
|
||||||
IntentDialogFragment.newInstance(shortClassName, flags).show(manager, "intentDialog");
|
IntentDialogFragment.newInstance(shortClassName, flags, taskId).show(manager,
|
||||||
|
"intentDialog");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package com.example.android.intentplayground;
|
package com.example.android.intentplayground;
|
||||||
|
|
||||||
|
|
||||||
|
import android.app.ActivityManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@@ -30,6 +31,8 @@ import android.widget.ScrollView;
|
|||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.fragment.app.DialogFragment;
|
import androidx.fragment.app.DialogFragment;
|
||||||
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -39,20 +42,26 @@ import java.util.List;
|
|||||||
public class IntentDialogFragment extends DialogFragment {
|
public class IntentDialogFragment extends DialogFragment {
|
||||||
private List<String> mFlags;
|
private List<String> mFlags;
|
||||||
private String mActivityName;
|
private String mActivityName;
|
||||||
|
private int mTaskId;
|
||||||
|
private BaseActivityViewModel mViewModel;
|
||||||
private static final String ARGUMENT_ACTIVITY_NAME = "activityName";
|
private static final String ARGUMENT_ACTIVITY_NAME = "activityName";
|
||||||
private static final String ARGUMENT_FLAGS = "flags";
|
private static final String ARGUMENT_FLAGS = "flags";
|
||||||
|
private static final String TASK_ID = "taskId";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new IntentDialogFragment to display the given flags.
|
* Creates a new IntentDialogFragment to display the given flags.
|
||||||
|
*
|
||||||
* @param activityName The name of the activity, also the title of the dialog.
|
* @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.
|
* @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();
|
IntentDialogFragment fragment = new IntentDialogFragment();
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putString(ARGUMENT_ACTIVITY_NAME, activityName);
|
args.putString(ARGUMENT_ACTIVITY_NAME, activityName);
|
||||||
args.putStringArrayList(ARGUMENT_FLAGS, new ArrayList<>(flags));
|
args.putStringArrayList(ARGUMENT_FLAGS, new ArrayList<>(flags));
|
||||||
|
args.putInt(TASK_ID, taskId);
|
||||||
fragment.setArguments(args);
|
fragment.setArguments(args);
|
||||||
return fragment;
|
return fragment;
|
||||||
}
|
}
|
||||||
@@ -63,6 +72,9 @@ public class IntentDialogFragment extends DialogFragment {
|
|||||||
Bundle args = getArguments();
|
Bundle args = getArguments();
|
||||||
mFlags = args.getStringArrayList(ARGUMENT_FLAGS);
|
mFlags = args.getStringArrayList(ARGUMENT_FLAGS);
|
||||||
mActivityName = args.getString(ARGUMENT_ACTIVITY_NAME);
|
mActivityName = args.getString(ARGUMENT_ACTIVITY_NAME);
|
||||||
|
mTaskId = args.getInt(TASK_ID);
|
||||||
|
mViewModel = (new ViewModelProvider(getActivity(),
|
||||||
|
new ViewModelProvider.NewInstanceFactory())).get(BaseActivityViewModel.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -79,6 +91,21 @@ public class IntentDialogFragment extends DialogFragment {
|
|||||||
rootLayout.findViewById(R.id.dialog_cancel).setOnClickListener(view -> {
|
rootLayout.findViewById(R.id.dialog_cancel).setOnClickListener(view -> {
|
||||||
getDialog().dismiss();
|
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);
|
Button copyFlagsButton = rootLayout.findViewById(R.id.copy_flags_button);
|
||||||
if (mFlags.get(0).equals("None")) {
|
if (mFlags.get(0).equals("None")) {
|
||||||
copyFlagsButton.setEnabled(false);
|
copyFlagsButton.setEnabled(false);
|
||||||
@@ -95,4 +122,18 @@ public class IntentDialogFragment extends DialogFragment {
|
|||||||
}
|
}
|
||||||
return rootLayout;
|
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);
|
super.onViewCreated(view, savedInstanceState);
|
||||||
mViewModel = (new ViewModelProvider(getActivity(),
|
mViewModel = (new ViewModelProvider(getActivity(),
|
||||||
new ViewModelProvider.NewInstanceFactory())).get(BaseActivityViewModel.class);
|
new ViewModelProvider.NewInstanceFactory())).get(BaseActivityViewModel.class);
|
||||||
|
|
||||||
|
mViewModel.getRefresh().observe(this, v -> this.onResumeHelper());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -86,21 +89,6 @@ public class TreeFragment extends Fragment {
|
|||||||
new LinearLayoutManager(getContext(), RecyclerView.VERTICAL, false));
|
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.
|
* Expand a task group to show its child activities.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user