The 3 main categories are: - Panel Opened - Panel Closed - Panel Slice interaction There are 3 close events: - See more button - Done button - Clicking outside the panel Slice interactions will log the Uri of the Slice and the ActionType, such as Toggle, Slider, Content (intent). Change-Id: Iecad948f39f50dd12ae1bcb23a5d523e0df8bb98 Fixes: 117804231 Test: robotests
141 lines
5.0 KiB
Java
141 lines
5.0 KiB
Java
/*
|
|
* 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.app.settings.SettingsEnums;
|
|
import android.content.Context;
|
|
import android.os.Bundle;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.widget.Button;
|
|
import android.widget.TextView;
|
|
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.Nullable;
|
|
import androidx.fragment.app.Fragment;
|
|
import androidx.fragment.app.FragmentActivity;
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
import com.android.internal.annotations.VisibleForTesting;
|
|
import com.android.settings.R;
|
|
import com.android.settings.overlay.FeatureFactory;
|
|
import com.android.settings.panel.PanelLoggingContract.PanelClosedKeys;
|
|
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
|
|
|
public class PanelFragment extends Fragment {
|
|
|
|
private static final String TAG = "PanelFragment";
|
|
|
|
private TextView mTitleView;
|
|
private Button mSeeMoreButton;
|
|
private Button mDoneButton;
|
|
private RecyclerView mPanelSlices;
|
|
|
|
private PanelContent mPanel;
|
|
private final MetricsFeatureProvider mMetricsProvider;
|
|
|
|
@VisibleForTesting
|
|
PanelSlicesAdapter mAdapter;
|
|
|
|
public PanelFragment() {
|
|
final Context context = getActivity();
|
|
mMetricsProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
|
|
}
|
|
|
|
@Nullable
|
|
@Override
|
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
|
|
@Nullable Bundle savedInstanceState) {
|
|
final FragmentActivity activity = getActivity();
|
|
final View view = inflater.inflate(R.layout.panel_layout, container, false);
|
|
|
|
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.panel_title);
|
|
|
|
final Bundle arguments = getArguments();
|
|
final String panelType =
|
|
arguments.getString(SettingsPanelActivity.KEY_PANEL_TYPE_ARGUMENT);
|
|
final String callingPackageName =
|
|
arguments.getString(SettingsPanelActivity.KEY_CALLING_PACKAGE_NAME);
|
|
final String mediaPackageName =
|
|
arguments.getString(SettingsPanelActivity.KEY_MEDIA_PACKAGE_NAME);
|
|
|
|
// TODO (b/124399577) transform interface to take a context and bundle.
|
|
mPanel = FeatureFactory.getFactory(activity)
|
|
.getPanelFeatureProvider()
|
|
.getPanel(activity, panelType, mediaPackageName);
|
|
|
|
// Log panel opened.
|
|
mMetricsProvider.action(
|
|
0 /* attribution */,
|
|
SettingsEnums.PAGE_VISIBLE /* opened panel - Action */,
|
|
mPanel.getMetricsCategory(),
|
|
callingPackageName,
|
|
0 /* value */);
|
|
|
|
mAdapter = new PanelSlicesAdapter(this, mPanel);
|
|
|
|
mPanelSlices.setHasFixedSize(true);
|
|
mPanelSlices.setLayoutManager(new LinearLayoutManager((activity)));
|
|
mPanelSlices.setAdapter(mAdapter);
|
|
|
|
mTitleView.setText(mPanel.getTitle());
|
|
|
|
mSeeMoreButton.setOnClickListener(getSeeMoreListener());
|
|
mDoneButton.setOnClickListener(getCloseListener());
|
|
|
|
//If getSeeMoreIntent() is null, hide the mSeeMoreButton.
|
|
if (mPanel.getSeeMoreIntent() == null) {
|
|
mSeeMoreButton.setVisibility(View.GONE);
|
|
}
|
|
|
|
return view;
|
|
}
|
|
|
|
@VisibleForTesting
|
|
View.OnClickListener getSeeMoreListener() {
|
|
return (v) -> {
|
|
mMetricsProvider.action(
|
|
0 /* attribution */,
|
|
SettingsEnums.PAGE_HIDE ,
|
|
mPanel.getMetricsCategory(),
|
|
PanelClosedKeys.KEY_SEE_MORE,
|
|
0 /* value */);
|
|
final FragmentActivity activity = getActivity();
|
|
activity.startActivityForResult(mPanel.getSeeMoreIntent(), 0);
|
|
activity.finish();
|
|
};
|
|
}
|
|
|
|
@VisibleForTesting
|
|
View.OnClickListener getCloseListener() {
|
|
return (v) -> {
|
|
mMetricsProvider.action(
|
|
0 /* attribution */,
|
|
SettingsEnums.PAGE_HIDE,
|
|
mPanel.getMetricsCategory(),
|
|
PanelClosedKeys.KEY_DONE,
|
|
0 /* value */);
|
|
getActivity().finish();
|
|
};
|
|
}
|
|
}
|