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

Commit 557a8bd2 authored by Evan Chen's avatar Evan Chen
Browse files

Add BT and WIFI icon for mutiple devices UI

Add BT and WIFI icon for mutiple devices ui.
Also highlight the selected item.

Test: atest CtsCompanionDeviceManagerUiAutomationTestCases:AssociationEndToEndTest
BUG: 211417476
Change-Id: I7edc2ff8734dbe440c803a8d8ab473487f383826
parent 99deef06
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ android_app {
    static_libs: [
        "androidx.lifecycle_lifecycle-livedata",
        "androidx.lifecycle_lifecycle-extensions",
        "androidx.recyclerview_recyclerview",
        "androidx.appcompat_appcompat",
    ],

+20 −0
Original line number Diff line number Diff line
<!--
  ~ Copyright (C) 2022 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.
  -->

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:color="@android:color/darker_gray"/> <!-- pressed -->
    <item android:color="@android:color/white"/>
</selector>
 No newline at end of file
+2 −2
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@
            android:layout_height="0dp"
            android:layout_weight="1">

        <ListView
        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/device_list"
                style="@android:style/Widget.Material.ListView"
                android:layout_width="match_parent"
+2 −1
Original line number Diff line number Diff line
@@ -19,7 +19,8 @@
              android:layout_height="wrap_content"
              android:orientation="horizontal"
              android:gravity="center_vertical"
              android:padding="12dp">
              android:padding="12dp"
              android:background="@color/selector">

    <!-- Do NOT change the ID of the root LinearLayout above: it's referenced in CTS tests. -->

+17 −11
Original line number Diff line number Diff line
@@ -46,10 +46,11 @@ import android.text.Spanned;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

@@ -94,9 +95,9 @@ public class CompanionDeviceActivity extends AppCompatActivity {
    // regular.
    private Button mButtonAllow;

    // The list is only shown for multiple-device regular association request, after at least one
    // matching device is found.
    private @Nullable ListView mListView;
    // The recycler view is only shown for multiple-device regular association request, after
    // at least one matching device is found.
    private @Nullable RecyclerView mRecyclerView;
    private @Nullable DeviceListAdapter mAdapter;

    // The flag used to prevent double taps, that may lead to sending several requests for creating
@@ -195,14 +196,15 @@ public class CompanionDeviceActivity extends AppCompatActivity {
        mTitle = findViewById(R.id.title);
        mSummary = findViewById(R.id.summary);

        mListView = findViewById(R.id.device_list);
        mListView.setOnItemClickListener((av, iv, position, id) -> onListItemClick(position));
        mRecyclerView = findViewById(R.id.device_list);
        mAdapter = new DeviceListAdapter(this, this::onListItemClick);

        mButtonAllow = findViewById(R.id.btn_positive);
        mButtonAllow.setOnClickListener(this::onPositiveButtonClick);
        findViewById(R.id.btn_negative).setOnClickListener(this::onNegativeButtonClick);

        final CharSequence appLabel = getApplicationLabel(this, mRequest.getPackageName());

        if (mRequest.isSelfManaged()) {
            initUiForSelfManagedAssociation(appLabel);
        } else if (mRequest.isSingleDevice()) {
@@ -333,7 +335,7 @@ public class CompanionDeviceActivity extends AppCompatActivity {
        mTitle.setText(title);
        mSummary.setText(summary);

        mListView.setVisibility(View.GONE);
        mRecyclerView.setVisibility(View.GONE);
    }

    private void initUiForSingleDevice(CharSequence appLabel) {
@@ -345,12 +347,12 @@ public class CompanionDeviceActivity extends AppCompatActivity {
                deviceFilterPairs -> updateSingleDeviceUi(
                        deviceFilterPairs, deviceProfile, appLabel));

        mListView.setVisibility(View.GONE);
        mRecyclerView.setVisibility(View.GONE);
    }

    private void updateSingleDeviceUi(List<DeviceFilterPair<?>> deviceFilterPairs,
            String deviceProfile, CharSequence appLabel) {
        // Ignore "empty" scan repots.
        // Ignore "empty" scan reports.
        if (deviceFilterPairs.isEmpty()) return;
        mSelectedDevice = requireNonNull(deviceFilterPairs.get(0));

@@ -393,10 +395,12 @@ public class CompanionDeviceActivity extends AppCompatActivity {
        mTitle.setText(title);
        mSummary.setText(summary);

        mAdapter = new DeviceListAdapter(this);
        mAdapter = new DeviceListAdapter(this, this::onListItemClick);

        // TODO: hide the list and show a spinner until a first device matching device is found.
        mListView.setAdapter(mAdapter);
        mRecyclerView.setAdapter(mAdapter);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));

        CompanionDeviceDiscoveryService.getScanResult().observe(
                /* lifecycleOwner */ this,
                /* observer */ mAdapter);
@@ -414,6 +418,8 @@ public class CompanionDeviceActivity extends AppCompatActivity {
            if (DEBUG) Log.w(TAG, "Already selected.");
            return;
        }
        // Notify the adapter to highlight the selected item.
        mAdapter.setSelectedPosition(position);

        mSelectedDevice = requireNonNull(selectedDevice);

Loading