Update SettingsPanel UI
UI changes include: - RecyclerView to host slices - Font family to headline font - Title is now centered - Added SeeMore & Done buttons - Horizontal Dividers between slices - Indented Slices - Landscape layout is fullscreen Change-Id: I3549c847fc88edd81f670ddfa2907dd3741441e0 Screenshot: https://screenshot.googleplex.com/RzWktzOZJkc Test: Robolectric Test: Manual app Bug: 118622007
This commit is contained in:
@@ -19,6 +19,7 @@ package com.android.settings.panel;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.slices.CustomSliceRegistry;
|
||||
@@ -60,6 +61,6 @@ public class InternetConnectivityPanel implements PanelContent {
|
||||
|
||||
@Override
|
||||
public Intent getSeeMoreIntent() {
|
||||
return null;
|
||||
return new Intent(Settings.ACTION_WIRELESS_SETTINGS);
|
||||
}
|
||||
}
|
||||
|
@@ -16,19 +16,20 @@
|
||||
|
||||
package com.android.settings.panel;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.slice.Slice;
|
||||
import androidx.slice.widget.SliceLiveData;
|
||||
import androidx.slice.widget.SliceView;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.settings.R;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@@ -38,20 +39,24 @@ import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PanelFragment extends Fragment {
|
||||
|
||||
private static final String TAG = "PanelFragment";
|
||||
|
||||
private List<SliceView> mSliceViewList;
|
||||
private List<LiveData<Slice>> mSliceDataList;
|
||||
private LinearLayout mPanelLayout;
|
||||
private TextView mTitleView;
|
||||
private Button mSeeMoreButton;
|
||||
private Button mDoneButton;
|
||||
private RecyclerView mPanelSlices;
|
||||
|
||||
@VisibleForTesting
|
||||
PanelSlicesAdapter mAdapter;
|
||||
|
||||
private View.OnClickListener mDoneButtonListener = (v) -> {
|
||||
Log.d(TAG, "Closing dialog");
|
||||
getActivity().finish();
|
||||
};
|
||||
|
||||
public PanelFragment() {
|
||||
mSliceViewList = new ArrayList<>();
|
||||
mSliceDataList = new ArrayList<>();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -61,28 +66,37 @@ public class PanelFragment extends Fragment {
|
||||
final FragmentActivity activity = getActivity();
|
||||
final View view = inflater.inflate(R.layout.panel_layout, container, false);
|
||||
|
||||
mPanelLayout = view.findViewById(R.id.panel_parent_layout);
|
||||
final Bundle arguments = getArguments();
|
||||
mPanelSlices = view.findViewById(R.id.panel_parent_layout);
|
||||
mSeeMoreButton = view.findViewById(R.id.see_more);
|
||||
mDoneButton = view.findViewById(R.id.done);
|
||||
mTitleView = view.findViewById(R.id.title);
|
||||
|
||||
final Bundle arguments = getArguments();
|
||||
final String panelType = arguments.getString(SettingsPanelActivity.KEY_PANEL_TYPE_ARGUMENT);
|
||||
|
||||
final PanelContent panel = FeatureFactory.getFactory(activity)
|
||||
.getPanelFeatureProvider()
|
||||
.getPanel(activity, panelType);
|
||||
|
||||
activity.setTitle(panel.getTitle());
|
||||
mAdapter = new PanelSlicesAdapter(this, panel.getSlices());
|
||||
|
||||
mPanelSlices.setHasFixedSize(true);
|
||||
mPanelSlices.setLayoutManager(new LinearLayoutManager((activity)));
|
||||
mPanelSlices.setAdapter(mAdapter);
|
||||
|
||||
for (Uri uri : panel.getSlices()) {
|
||||
final SliceView sliceView = new SliceView(activity);
|
||||
mPanelLayout.addView(sliceView);
|
||||
final LiveData<Slice> liveData = SliceLiveData.fromUri(activity, uri);
|
||||
liveData.observe(this /* lifecycleOwner */, sliceView);
|
||||
mTitleView.setText(panel.getTitle());
|
||||
|
||||
mSliceDataList.add(liveData);
|
||||
mSliceViewList.add(sliceView);
|
||||
}
|
||||
mSeeMoreButton.setOnClickListener(getSeeMoreListener(panel.getSeeMoreIntent()));
|
||||
mDoneButton.setOnClickListener(mDoneButtonListener);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
private View.OnClickListener getSeeMoreListener(final Intent intent) {
|
||||
return (v) -> {
|
||||
final FragmentActivity activity = getActivity();
|
||||
activity.startActivity(intent);
|
||||
activity.finish();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
100
src/com/android/settings/panel/PanelSlicesAdapter.java
Normal file
100
src/com/android/settings/panel/PanelSlicesAdapter.java
Normal file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.panel;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.slice.Slice;
|
||||
import androidx.slice.widget.SliceLiveData;
|
||||
import androidx.slice.widget.SliceView;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* RecyclerView adapter for Slices in Settings Panels.
|
||||
*/
|
||||
public class PanelSlicesAdapter
|
||||
extends RecyclerView.Adapter<PanelSlicesAdapter.SliceRowViewHolder> {
|
||||
|
||||
private final List<Uri> mSliceUris;
|
||||
private final PanelFragment mPanelFragment;
|
||||
|
||||
public PanelSlicesAdapter(PanelFragment fragment, List<Uri> sliceUris) {
|
||||
mPanelFragment = fragment;
|
||||
mSliceUris = new ArrayList<>(sliceUris);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public SliceRowViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
|
||||
final Context context = viewGroup.getContext();
|
||||
final LayoutInflater inflater = LayoutInflater.from(context);
|
||||
final View view = inflater.inflate(R.layout.panel_slice_row, viewGroup, false);
|
||||
|
||||
return new SliceRowViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull SliceRowViewHolder sliceRowViewHolder, int position) {
|
||||
sliceRowViewHolder.onBind(mPanelFragment, mSliceUris.get(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mSliceUris.size();
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
List<Uri> getData() {
|
||||
return mSliceUris;
|
||||
}
|
||||
|
||||
/**
|
||||
* ViewHolder for binding Slices to SliceViews.
|
||||
*/
|
||||
public static class SliceRowViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
@VisibleForTesting
|
||||
LiveData<Slice> sliceLiveData;
|
||||
|
||||
@VisibleForTesting
|
||||
final SliceView sliceView;
|
||||
|
||||
public SliceRowViewHolder(View view) {
|
||||
super(view);
|
||||
sliceView = view.findViewById(R.id.slice_view);
|
||||
sliceView.setMode(SliceView.MODE_LARGE);
|
||||
}
|
||||
|
||||
public void onBind(PanelFragment fragment, Uri sliceUri) {
|
||||
final Context context = sliceView.getContext();
|
||||
sliceLiveData = SliceLiveData.fromUri(context, sliceUri);
|
||||
sliceLiveData.observe(fragment.getViewLifecycleOwner(), sliceView);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user