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

Commit 45feb605 authored by William Escande's avatar William Escande
Browse files

Reformat java file in android/leaudio

Bug: 311772251
Flag: Exempt refactor
Test: None
Change-Id: Ie7fe7f0a1b626045770d7de875036f5a64008b6e
parent 955b30b3
Loading
Loading
Loading
Loading
+782 −617

File changed.

Preview size limit exceeded, changes collapsed.

+19 −16
Original line number Diff line number Diff line
@@ -44,8 +44,9 @@ public class BroadcastItemsAdapter
    @NonNull
    @Override
    public BroadcastItemHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View item_view = LayoutInflater.from(parent.getContext()).inflate(R.layout.broadcast_item,
                parent, false);
        View item_view =
                LayoutInflater.from(parent.getContext())
                        .inflate(R.layout.broadcast_item, parent, false);
        return new BroadcastItemHolder(item_view, mOnItemClickListener);
    }

@@ -148,12 +149,14 @@ public class BroadcastItemsAdapter
            mTextViewBroadcastId = itemView.findViewById(R.id.broadcast_id_text);
            background = itemView.findViewById(R.id.broadcast_item_card_view);

            itemView.setOnClickListener(v -> {
            itemView.setOnClickListener(
                    v -> {
                        if (listener == null) return;

                        int position = getAdapterPosition();
                        if (position != RecyclerView.NO_POSITION) {
                    Integer broadcastId = mBroadcastMetadataList.get(position).getBroadcastId();
                            Integer broadcastId =
                                    mBroadcastMetadataList.get(position).getBroadcastId();
                            listener.onItemClick(broadcastId);
                        }
                    });
+168 −113
Original line number Diff line number Diff line
@@ -54,11 +54,13 @@ public class BroadcastScanActivity extends AppCompatActivity {
        recyclerView.setHasFixedSize(true);

        adapter = new BroadcastItemsAdapter();
        adapter.setOnItemClickListener(broadcastId -> {
        adapter.setOnItemClickListener(
                broadcastId -> {
                    mViewModel.scanForBroadcasts(device, false);

                    BluetoothLeBroadcastMetadata broadcast = null;
            for (BluetoothLeBroadcastMetadata b : mViewModel.getAllBroadcasts().getValue()) {
                    for (BluetoothLeBroadcastMetadata b :
                            mViewModel.getAllBroadcasts().getValue()) {
                        if (Objects.equals(b.getBroadcastId(), broadcastId)) {
                            broadcast = b;
                            break;
@@ -66,12 +68,18 @@ public class BroadcastScanActivity extends AppCompatActivity {
                    }

                    if (broadcast == null) {
                Toast.makeText(recyclerView.getContext(), "Matching broadcast not found."
                                + " broadcastId=" + broadcastId, Toast.LENGTH_SHORT).show();
                        Toast.makeText(
                                        recyclerView.getContext(),
                                        "Matching broadcast not found."
                                                + " broadcastId="
                                                + broadcastId,
                                        Toast.LENGTH_SHORT)
                                .show();
                        return;
                    }

            // Set broadcast source on peer only if scan delegator device context is available
                    // Set broadcast source on peer only if scan delegator device context is
                    // available
                    if (device != null) {
                        // Start Dialog with the broadcast input details
                        AlertDialog.Builder alert = new AlertDialog.Builder(this);
@@ -79,8 +87,8 @@ public class BroadcastScanActivity extends AppCompatActivity {
                        alert.setTitle("Add the Broadcast:");

                        View alertView =
                        inflater.inflate(R.layout.broadcast_scan_add_encrypted_source_dialog,
                                         null);
                                inflater.inflate(
                                        R.layout.broadcast_scan_add_encrypted_source_dialog, null);

                        boolean isPublic = broadcast.isPublicBroadcast();
                        TextView addr_text = alertView.findViewById(R.id.broadcast_with_pbp_text);
@@ -108,52 +116,90 @@ public class BroadcastScanActivity extends AppCompatActivity {

                        final EditText code_input_text =
                                alertView.findViewById(R.id.broadcast_code_input);
                BluetoothLeBroadcastMetadata.Builder builder = new
                        BluetoothLeBroadcastMetadata.Builder(broadcast);
                        BluetoothLeBroadcastMetadata.Builder builder =
                                new BluetoothLeBroadcastMetadata.Builder(broadcast);

                alert.setView(alertView).setNegativeButton("Cancel", (dialog, which) -> {
                        alert.setView(alertView)
                                .setNegativeButton(
                                        "Cancel",
                                        (dialog, which) -> {
                                            // Do nothing
                }).setPositiveButton("Add", (dialog, which) -> {
                                        })
                                .setPositiveButton(
                                        "Add",
                                        (dialog, which) -> {
                                            BluetoothLeBroadcastMetadata metadata;
                                            if (code_input_text.getText() == null) {
                        Toast.makeText(recyclerView.getContext(), "Invalid broadcast code",
                                Toast.LENGTH_SHORT).show();
                                                Toast.makeText(
                                                                recyclerView.getContext(),
                                                                "Invalid broadcast code",
                                                                Toast.LENGTH_SHORT)
                                                        .show();
                                                return;
                                            }
                                            if (code_input_text.getText().length() == 0) {
                        Toast.makeText(recyclerView.getContext(), "Adding not encrypted broadcast "
                                                Toast.makeText(
                                                                recyclerView.getContext(),
                                                                "Adding not encrypted broadcast "
                                                                        + "source broadcastId="
                                       + broadcastId, Toast.LENGTH_SHORT).show();
                                                                        + broadcastId,
                                                                Toast.LENGTH_SHORT)
                                                        .show();
                                                metadata = builder.setEncrypted(false).build();
                                            } else {
                        if ((code_input_text.getText().length() > 16) ||
                                (code_input_text.getText().length() < 4)) {
                            Toast.makeText(recyclerView.getContext(),
                                                if ((code_input_text.getText().length() > 16)
                                                        || (code_input_text.getText().length()
                                                                < 4)) {
                                                    Toast.makeText(
                                                                    recyclerView.getContext(),
                                                                    "Invalid Broadcast code length",
                                           Toast.LENGTH_SHORT).show();
                                                                    Toast.LENGTH_SHORT)
                                                            .show();

                                                    return;
                                                }

                        metadata = builder.setBroadcastCode(
                                        code_input_text.getText().toString().getBytes())
                                                metadata =
                                                        builder.setBroadcastCode(
                                                                        code_input_text
                                                                                .getText()
                                                                                .toString()
                                                                                .getBytes())
                                                                .setEncrypted(true)
                                                                .build();
                                            }

                                            if ((channels_input_text.getText() != null)
                            && (channels_input_text.getText().length() != 0)) {
                        int channelMap = Integer.parseInt(channels_input_text.getText().toString());
                        // Apply a single channel map preference to all subgroups
                        for (BluetoothLeBroadcastSubgroup subGroup : metadata.getSubgroups()) {
                            List<BluetoothLeBroadcastChannel> channels = subGroup.getChannels();
                                                    && (channels_input_text.getText().length()
                                                            != 0)) {
                                                int channelMap =
                                                        Integer.parseInt(
                                                                channels_input_text
                                                                        .getText()
                                                                        .toString());
                                                // Apply a single channel map preference to all
                                                // subgroups
                                                for (BluetoothLeBroadcastSubgroup subGroup :
                                                        metadata.getSubgroups()) {
                                                    List<BluetoothLeBroadcastChannel> channels =
                                                            subGroup.getChannels();
                                                    for (int i = 0; i < channels.size(); i++) {
                                BluetoothLeBroadcastChannel channel = channels.get(i);
                                // Set the channel preference value according to the map
                                                        BluetoothLeBroadcastChannel channel =
                                                                channels.get(i);
                                                        // Set the channel preference value
                                                        // according to the map
                                                        if (channel.getChannelIndex() != 0) {
                                    if ((channelMap & (1 << (channel.getChannelIndex() - 1))) != 0) {
                                        BluetoothLeBroadcastChannel.Builder bob
                                                = new BluetoothLeBroadcastChannel.Builder(channel);
                                                            if ((channelMap
                                                                            & (1
                                                                                    << (channel
                                                                                                    .getChannelIndex()
                                                                                            - 1)))
                                                                    != 0) {
                                                                BluetoothLeBroadcastChannel.Builder
                                                                        bob =
                                                                                new BluetoothLeBroadcastChannel
                                                                                        .Builder(
                                                                                        channel);
                                                                bob.setSelected(true);
                                                                channels.set(i, bob.build());
                                                            }
@@ -162,8 +208,13 @@ public class BroadcastScanActivity extends AppCompatActivity {
                                                }
                                            }

                    Toast.makeText(recyclerView.getContext(), "Adding broadcast source"
                                    + " broadcastId=" + broadcastId, Toast.LENGTH_SHORT).show();
                                            Toast.makeText(
                                                            recyclerView.getContext(),
                                                            "Adding broadcast source"
                                                                    + " broadcastId="
                                                                    + broadcastId,
                                                            Toast.LENGTH_SHORT)
                                                    .show();
                                            mViewModel.addBroadcastSource(device, metadata);
                                        });

@@ -173,7 +224,11 @@ public class BroadcastScanActivity extends AppCompatActivity {
        recyclerView.setAdapter(adapter);

        mViewModel = ViewModelProviders.of(this).get(BroadcastScanViewModel.class);
        mViewModel.getAllBroadcasts().observe(this, audioBroadcasts -> {
        mViewModel
                .getAllBroadcasts()
                .observe(
                        this,
                        audioBroadcasts -> {
                            // Update Broadcast list in the adapter
                            adapter.setBroadcasts(audioBroadcasts);
                        });
+60 −58
Original line number Diff line number Diff line
@@ -43,7 +43,8 @@ public class BroadcastScanViewModel extends AndroidViewModel {

    BluetoothProxy mBluetooth;
    Application mApplication;
    private MutableLiveData<List<BluetoothLeBroadcastMetadata>> mAllBroadcasts = new MutableLiveData<>();
    private MutableLiveData<List<BluetoothLeBroadcastMetadata>> mAllBroadcasts =
            new MutableLiveData<>();
    private HashMap<Integer, BluetoothLeBroadcastMetadata> mScanSessionBroadcasts = new HashMap<>();

    private final BluetoothProxy.OnBassEventListener mBassEventListener =
@@ -76,7 +77,8 @@ public class BroadcastScanViewModel extends AndroidViewModel {
                            }
                        }
                    } else {
                // FIXME: Clear won't work - it would auto-update the mutable and clear it as
                        // FIXME: Clear won't work - it would auto-update the mutable and clear it
                        // as
                        // mutable uses reference to its values
                        mScanSessionBroadcasts = new HashMap<>();
                    }
@@ -103,8 +105,8 @@ public class BroadcastScanViewModel extends AndroidViewModel {
                }

                @Override
        public void onBroadcastMetadataChanged(int broadcastId,
                BluetoothLeBroadcastMetadata metadata) {
                public void onBroadcastMetadataChanged(
                        int broadcastId, BluetoothLeBroadcastMetadata metadata) {
                    refreshBroadcasts();
                }
            };
@@ -147,7 +149,8 @@ public class BroadcastScanViewModel extends AndroidViewModel {
        mBluetooth.scanForBroadcasts(mScanDelegatorDevice, scan);
    }

    public void addBroadcastSource(BluetoothDevice sink, BluetoothLeBroadcastMetadata sourceMetadata) {
    public void addBroadcastSource(
            BluetoothDevice sink, BluetoothLeBroadcastMetadata sourceMetadata) {
        mBluetooth.addBroadcastSource(sink, sourceMetadata);
    }

@@ -155,8 +158,7 @@ public class BroadcastScanViewModel extends AndroidViewModel {
        // Concatenate local broadcasts to the scanned broadcast list
        List<BluetoothLeBroadcastMetadata> localSessionBroadcasts =
                mBluetooth.getAllLocalBroadcasts();
        ArrayList<BluetoothLeBroadcastMetadata> new_arr = new ArrayList<>(
                localSessionBroadcasts);
        ArrayList<BluetoothLeBroadcastMetadata> new_arr = new ArrayList<>(localSessionBroadcasts);
        new_arr.addAll(mScanSessionBroadcasts.values());
        mAllBroadcasts.postValue(new_arr);
    }
+85 −38
Original line number Diff line number Diff line
@@ -404,49 +404,96 @@ public class BroadcasterActivity extends AppCompatActivity {
        itemsAdapter.updateBroadcastsMetadata(metadata.isEmpty() ? new ArrayList<>() : metadata);

        // Put a watch on updates
        mViewModel.getBroadcastUpdateMetadataLive().observe(this, audioBroadcast -> {
        mViewModel
                .getBroadcastUpdateMetadataLive()
                .observe(
                        this,
                        audioBroadcast -> {
                            itemsAdapter.updateBroadcastMetadata(audioBroadcast);

            Toast.makeText(BroadcasterActivity.this,
                    "Updated broadcast " + audioBroadcast.getBroadcastId(), Toast.LENGTH_SHORT)
                            Toast.makeText(
                                            BroadcasterActivity.this,
                                            "Updated broadcast " + audioBroadcast.getBroadcastId(),
                                            Toast.LENGTH_SHORT)
                                    .show();
                        });

        // Put a watch on any error reports
        mViewModel.getBroadcastStatusMutableLive().observe(this, msg -> {
            Toast.makeText(BroadcasterActivity.this, msg, Toast.LENGTH_SHORT).show();
        mViewModel
                .getBroadcastStatusMutableLive()
                .observe(
                        this,
                        msg -> {
                            Toast.makeText(BroadcasterActivity.this, msg, Toast.LENGTH_SHORT)
                                    .show();
                        });

        // Put a watch on broadcast playback states
        mViewModel.getBroadcastPlaybackStartedMutableLive().observe(this, reasonAndBidPair -> {
            Toast.makeText(BroadcasterActivity.this, "Playing broadcast " + reasonAndBidPair.second
                    + ", reason " + reasonAndBidPair.first, Toast.LENGTH_SHORT).show();
        mViewModel
                .getBroadcastPlaybackStartedMutableLive()
                .observe(
                        this,
                        reasonAndBidPair -> {
                            Toast.makeText(
                                            BroadcasterActivity.this,
                                            "Playing broadcast "
                                                    + reasonAndBidPair.second
                                                    + ", reason "
                                                    + reasonAndBidPair.first,
                                            Toast.LENGTH_SHORT)
                                    .show();

                            itemsAdapter.updateBroadcastPlayback(reasonAndBidPair.second, true);
                        });

        mViewModel.getBroadcastPlaybackStoppedMutableLive().observe(this, reasonAndBidPair -> {
            Toast.makeText(BroadcasterActivity.this, "Paused broadcast " + reasonAndBidPair.second
                    + ", reason " + reasonAndBidPair.first, Toast.LENGTH_SHORT).show();
        mViewModel
                .getBroadcastPlaybackStoppedMutableLive()
                .observe(
                        this,
                        reasonAndBidPair -> {
                            Toast.makeText(
                                            BroadcasterActivity.this,
                                            "Paused broadcast "
                                                    + reasonAndBidPair.second
                                                    + ", reason "
                                                    + reasonAndBidPair.first,
                                            Toast.LENGTH_SHORT)
                                    .show();

                            itemsAdapter.updateBroadcastPlayback(reasonAndBidPair.second, false);
                        });

        mViewModel.getBroadcastAddedMutableLive().observe(this, broadcastId -> {
        mViewModel
                .getBroadcastAddedMutableLive()
                .observe(
                        this,
                        broadcastId -> {
                            itemsAdapter.addBroadcasts(broadcastId);

            Toast.makeText(BroadcasterActivity.this,
                    "Broadcast was added broadcastId: " + broadcastId, Toast.LENGTH_SHORT).show();
                            Toast.makeText(
                                            BroadcasterActivity.this,
                                            "Broadcast was added broadcastId: " + broadcastId,
                                            Toast.LENGTH_SHORT)
                                    .show();
                        });

        // Put a watch on broadcast removal
        mViewModel.getBroadcastRemovedMutableLive().observe(this, reasonAndBidPair -> {
        mViewModel
                .getBroadcastRemovedMutableLive()
                .observe(
                        this,
                        reasonAndBidPair -> {
                            itemsAdapter.removeBroadcast(reasonAndBidPair.second);

                            Toast.makeText(
                    BroadcasterActivity.this, "Broadcast was removed " + " broadcastId: "
                            + reasonAndBidPair.second + ", reason: " + reasonAndBidPair.first,
                    Toast.LENGTH_SHORT).show();
                                            BroadcasterActivity.this,
                                            "Broadcast was removed "
                                                    + " broadcastId: "
                                                    + reasonAndBidPair.second
                                                    + ", reason: "
                                                    + reasonAndBidPair.first,
                                            Toast.LENGTH_SHORT)
                                    .show();
                        });

        // Prevent destruction when loses focus
Loading