Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d624b575 authored by Yiyi Shen's avatar Yiyi Shen Committed by Android (Google) Code Review
Browse files

Merge "[Audiosharing] Add audio sharing dialog." into main

parents d30a1939 738962fb
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (C) 2023 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.
  -->

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <Button
        android:id="@+id/device_button"
        android:overScrollMode="never"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textAlignment="center"
        android:text=""/>

</FrameLayout>
 No newline at end of file
+49 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (C) 2023 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.
  -->

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="24dp"
    android:orientation="vertical">

    <TextView
        style="@style/device_info_dialog_value"
        android:id="@+id/share_audio_subtitle1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textAlignment="center"
        android:layout_gravity="center"/>

    <TextView
        style="@style/device_info_dialog_value"
        android:id="@+id/share_audio_subtitle2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textAlignment="center"
        android:layout_gravity="center"/>

    <com.android.internal.widget.RecyclerView
        android:visibility="visible"
        android:id="@+id/btn_list"
        android:nestedScrollingEnabled="false"
        android:overScrollMode="never"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"/>
</LinearLayout>
 No newline at end of file
+2 −0
Original line number Diff line number Diff line
@@ -75,6 +75,8 @@ public class AudioSharingDashboardFragment extends DashboardFragment {
        mMainSwitchBar = activity.getSwitchBar();
        mMainSwitchBar.setTitle(getText(R.string.audio_sharing_switch_title));
        mSwitchBarController = new AudioSharingSwitchBarController(activity, mMainSwitchBar);
        mSwitchBarController.init(this);
        getSettingsLifecycle().addObserver(mSwitchBarController);
        mMainSwitchBar.show();
    }
}
+81 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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.connecteddevice.audiosharing;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.android.internal.widget.RecyclerView;
import com.android.settings.R;

import java.util.ArrayList;

public class AudioSharingDeviceAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private static final String TAG = "AudioSharingDeviceAdapter";
    private final ArrayList<String> mDevices;
    private final OnClickListener mOnClickListener;

    public AudioSharingDeviceAdapter(ArrayList<String> devices, OnClickListener listener) {
        mDevices = devices;
        mOnClickListener = listener;
    }

    private class AudioSharingDeviceViewHolder extends RecyclerView.ViewHolder {
        private final Button mButtonView;

        AudioSharingDeviceViewHolder(View view) {
            super(view);
            mButtonView = view.findViewById(R.id.device_button);
        }

        public void bindView(int position) {
            if (mButtonView != null) {
                mButtonView.setText(mDevices.get(position));
                mButtonView.setOnClickListener(v -> mOnClickListener.onClick(position));
            } else {
                Log.w(TAG, "bind view skipped due to button view is null");
            }
        }
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view =
                LayoutInflater.from(parent.getContext())
                        .inflate(R.layout.audio_sharing_device_item, parent, false);
        return new AudioSharingDeviceViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ((AudioSharingDeviceViewHolder) holder).bindView(position);
    }

    @Override
    public int getItemCount() {
        return mDevices.size();
    }

    public interface OnClickListener {
        /** Called when an item has been clicked. */
        void onClick(int position);
    }
}
+89 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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.connecteddevice.audiosharing;

import android.app.Dialog;
import android.app.settings.SettingsEnums;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;

import com.android.internal.widget.LinearLayoutManager;
import com.android.internal.widget.RecyclerView;
import com.android.settings.R;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
import com.android.settings.flags.Flags;

import java.util.ArrayList;

public class AudioSharingDialogFragment extends InstrumentedDialogFragment {
    private static final String TAG = "AudioSharingDialog";

    private View mRootView;

    @Override
    public int getMetricsCategory() {
        return SettingsEnums.DIALOG_START_AUDIO_SHARING;
    }

    /**
     * Display the {@link AudioSharingDialogFragment} dialog.
     *
     * @param host The Fragment this dialog will be hosted.
     */
    public static void show(Fragment host) {
        if (!Flags.enableLeAudioSharing()) return;
        final FragmentManager manager = host.getChildFragmentManager();
        if (manager.findFragmentByTag(TAG) == null) {
            final AudioSharingDialogFragment dialog = new AudioSharingDialogFragment();
            dialog.show(manager, TAG);
        }
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        final AlertDialog.Builder builder =
                new AlertDialog.Builder(getActivity()).setTitle("Share audio");
        mRootView =
                LayoutInflater.from(builder.getContext())
                        .inflate(R.layout.dialog_audio_sharing, /* parent= */ null);
        // TODO: use real subtitle according to device count.
        TextView subTitle1 = mRootView.findViewById(R.id.share_audio_subtitle1);
        TextView subTitle2 = mRootView.findViewById(R.id.share_audio_subtitle2);
        subTitle1.setText("2 devices connected");
        subTitle2.setText("placeholder");
        RecyclerView recyclerView = mRootView.findViewById(R.id.btn_list);
        // TODO: use real audio sharing device list.
        ArrayList<String> devices = new ArrayList<>();
        devices.add("Buds 1");
        devices.add("Buds 2");
        recyclerView.setAdapter(
                new AudioSharingDeviceAdapter(
                        devices,
                        (int position) -> {
                            // TODO: add on click callback.
                        }));
        recyclerView.setLayoutManager(
                new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
        return builder.setView(mRootView).create();
    }
}
Loading