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

Commit ffe490fd authored by Evan Chen's avatar Evan Chen Committed by Android (Google) Code Review
Browse files

Merge "Add BT and WIFI icon for mutiple devices UI"

parents ef1efc53 557a8bd2
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -39,6 +39,7 @@ android_app {
    static_libs: [
    static_libs: [
        "androidx.lifecycle_lifecycle-livedata",
        "androidx.lifecycle_lifecycle-livedata",
        "androidx.lifecycle_lifecycle-extensions",
        "androidx.lifecycle_lifecycle-extensions",
        "androidx.recyclerview_recyclerview",
        "androidx.appcompat_appcompat",
        "androidx.appcompat_appcompat",
    ],
    ],


+20 −0
Original line number Original line 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 Original line Diff line number Diff line
@@ -49,7 +49,7 @@
            android:layout_height="0dp"
            android:layout_height="0dp"
            android:layout_weight="1">
            android:layout_weight="1">


        <ListView
        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/device_list"
            android:id="@+id/device_list"
                style="@android:style/Widget.Material.ListView"
                style="@android:style/Widget.Material.ListView"
                android:layout_width="match_parent"
                android:layout_width="match_parent"
+2 −1
Original line number Original line Diff line number Diff line
@@ -19,7 +19,8 @@
              android:layout_height="wrap_content"
              android:layout_height="wrap_content"
              android:orientation="horizontal"
              android:orientation="horizontal"
              android:gravity="center_vertical"
              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. -->
    <!-- Do NOT change the ID of the root LinearLayout above: it's referenced in CTS tests. -->


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


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


import java.util.List;
import java.util.List;


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


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


    // The flag used to prevent double taps, that may lead to sending several requests for creating
    // 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);
        mTitle = findViewById(R.id.title);
        mSummary = findViewById(R.id.summary);
        mSummary = findViewById(R.id.summary);


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


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


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

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


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


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


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


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


@@ -393,10 +395,12 @@ public class CompanionDeviceActivity extends AppCompatActivity {
        mTitle.setText(title);
        mTitle.setText(title);
        mSummary.setText(summary);
        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.
        // 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(
        CompanionDeviceDiscoveryService.getScanResult().observe(
                /* lifecycleOwner */ this,
                /* lifecycleOwner */ this,
                /* observer */ mAdapter);
                /* observer */ mAdapter);
@@ -414,6 +418,8 @@ public class CompanionDeviceActivity extends AppCompatActivity {
            if (DEBUG) Log.w(TAG, "Already selected.");
            if (DEBUG) Log.w(TAG, "Already selected.");
            return;
            return;
        }
        }
        // Notify the adapter to highlight the selected item.
        mAdapter.setSelectedPosition(position);


        mSelectedDevice = requireNonNull(selectedDevice);
        mSelectedDevice = requireNonNull(selectedDevice);


Loading