• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.settings.connecteddevice.audiosharing.audiostreams;
18 
19 import android.app.settings.SettingsEnums;
20 import android.os.Bundle;
21 
22 import androidx.annotation.Nullable;
23 import androidx.annotation.VisibleForTesting;
24 import androidx.preference.Preference;
25 
26 import com.android.settings.R;
27 import com.android.settings.core.SubSettingLauncher;
28 import com.android.settings.dashboard.DashboardFragment;
29 
30 class SourcePresentState extends AudioStreamStateHandler {
31     @VisibleForTesting
32     static final int AUDIO_STREAM_SOURCE_PRESENT_STATE_SUMMARY = R.string.audio_streams_present_now;
33 
34     @Nullable private static SourcePresentState sInstance = null;
35 
SourcePresentState()36     SourcePresentState() {}
37 
getInstance()38     static SourcePresentState getInstance() {
39         if (sInstance == null) {
40             sInstance = new SourcePresentState();
41         }
42         return sInstance;
43     }
44 
45     @Override
performAction( AudioStreamPreference preference, AudioStreamsProgressCategoryController controller, AudioStreamsHelper helper)46     void performAction(
47             AudioStreamPreference preference,
48             AudioStreamsProgressCategoryController controller,
49             AudioStreamsHelper helper) {
50         // nothing to do
51     }
52 
53     @Override
getSummary()54     int getSummary() {
55         return AUDIO_STREAM_SOURCE_PRESENT_STATE_SUMMARY;
56     }
57 
58     @Override
getOnClickListener( AudioStreamsProgressCategoryController controller)59     Preference.OnPreferenceClickListener getOnClickListener(
60             AudioStreamsProgressCategoryController controller) {
61         return preference -> {
62             var p = (AudioStreamPreference) preference;
63             Bundle broadcast = new Bundle();
64             broadcast.putString(
65                     AudioStreamDetailsFragment.BROADCAST_NAME_ARG, (String) p.getTitle());
66             broadcast.putInt(
67                     AudioStreamDetailsFragment.BROADCAST_ID_ARG, p.getAudioStreamBroadcastId());
68 
69             new SubSettingLauncher(p.getContext())
70                     .setTitleRes(R.string.audio_streams_detail_page_title)
71                     .setDestination(AudioStreamDetailsFragment.class.getName())
72                     .setSourceMetricsCategory(
73                             !(controller.getFragment() instanceof DashboardFragment)
74                                     ? SettingsEnums.PAGE_UNKNOWN
75                                     : ((DashboardFragment) controller.getFragment())
76                                             .getMetricsCategory())
77                     .setArguments(broadcast)
78                     .launch();
79             return true;
80         };
81     }
82 
83     @Override
getStateEnum()84     AudioStreamsProgressCategoryController.AudioStreamState getStateEnum() {
85         return AudioStreamsProgressCategoryController.AudioStreamState.SOURCE_PRESENT;
86     }
87 }
88