summaryrefslogtreecommitdiffstats
path: root/src/com/android/packageinstaller/auto/AutoSettingsFrameFragment.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/packageinstaller/auto/AutoSettingsFrameFragment.java')
-rw-r--r--src/com/android/packageinstaller/auto/AutoSettingsFrameFragment.java50
1 files changed, 26 insertions, 24 deletions
diff --git a/src/com/android/packageinstaller/auto/AutoSettingsFrameFragment.java b/src/com/android/packageinstaller/auto/AutoSettingsFrameFragment.java
index ea8987e3..d89ced7b 100644
--- a/src/com/android/packageinstaller/auto/AutoSettingsFrameFragment.java
+++ b/src/com/android/packageinstaller/auto/AutoSettingsFrameFragment.java
@@ -21,22 +21,21 @@ import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
-import android.widget.Button;
-import android.widget.ProgressBar;
-import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
-import androidx.preference.PreferenceFragmentCompat;
+import com.android.car.ui.preference.PreferenceFragment;
+import com.android.car.ui.toolbar.MenuItem;
+import com.android.car.ui.toolbar.ToolbarController;
import com.android.permissioncontroller.R;
+import java.util.Collections;
+
/** Common settings frame for car related settings in permission controller. */
-public abstract class AutoSettingsFrameFragment extends PreferenceFragmentCompat {
+public abstract class AutoSettingsFrameFragment extends PreferenceFragment {
- private TextView mLabelView;
- private ProgressBar mProgressBar;
- private Button mAction;
+ private ToolbarController mToolbar;
private CharSequence mLabel;
private boolean mIsLoading;
@@ -48,16 +47,10 @@ public abstract class AutoSettingsFrameFragment extends PreferenceFragmentCompat
@Nullable Bundle savedInstanceState) {
View rootView = super.onCreateView(inflater, container, savedInstanceState);
- View backButton = rootView.findViewById(R.id.back_button);
- backButton.setOnClickListener(v -> getActivity().onBackPressed());
+ mToolbar = rootView.findViewById(R.id.toolbar);
- mLabelView = rootView.findViewById(R.id.label);
updateHeaderLabel();
-
- mProgressBar = rootView.findViewById(R.id.progress_bar);
updateLoading();
-
- mAction = rootView.findViewById(R.id.action);
updateAction();
return rootView;
@@ -66,6 +59,10 @@ public abstract class AutoSettingsFrameFragment extends PreferenceFragmentCompat
/** Sets the header text of this fragment. */
public void setHeaderLabel(CharSequence label) {
mLabel = label;
+ if (getPreferenceScreen() != null) {
+ // Needed because CarUi's preference fragment reads this title
+ getPreferenceScreen().setTitle(mLabel);
+ }
updateHeaderLabel();
}
@@ -75,8 +72,8 @@ public abstract class AutoSettingsFrameFragment extends PreferenceFragmentCompat
}
private void updateHeaderLabel() {
- if (mLabelView != null) {
- mLabelView.setText(mLabel);
+ if (mToolbar != null) {
+ mToolbar.setTitle(mLabel);
}
}
@@ -91,8 +88,12 @@ public abstract class AutoSettingsFrameFragment extends PreferenceFragmentCompat
}
private void updateLoading() {
- if (mProgressBar != null) {
- mProgressBar.setVisibility(mIsLoading ? View.VISIBLE : View.GONE);
+ if (mToolbar != null) {
+ if (mIsLoading) {
+ mToolbar.showProgressBar();
+ } else {
+ mToolbar.hideProgressBar();
+ }
}
}
@@ -107,15 +108,16 @@ public abstract class AutoSettingsFrameFragment extends PreferenceFragmentCompat
}
private void updateAction() {
- if (mAction == null) {
+ if (mToolbar == null) {
return;
}
if (!TextUtils.isEmpty(mActionLabel) && mActionOnClickListener != null) {
- mAction.setText(mActionLabel);
- mAction.setOnClickListener(mActionOnClickListener);
- mAction.setVisibility(View.VISIBLE);
+ mToolbar.setMenuItems(Collections.singletonList(MenuItem.builder(getContext())
+ .setTitle(mActionLabel)
+ .setOnClickListener(i -> mActionOnClickListener.onClick(null))
+ .build()));
} else {
- mAction.setVisibility(View.GONE);
+ mToolbar.setMenuItems(null);
}
}
}