Update the radio app to use the Toolbar.
- Removed BandSelectorToggle since it could not be used with Toolbar.
- Extracted the band selection logic to BandController.
Bug: 143297376
Test: Manual
Change-Id: I223ebceb1f314bf3e265fb03734b8fdcc476081d
diff --git a/res/layout/band_selector_toggle.xml b/res/layout/band_selector_toggle.xml
deleted file mode 100644
index 887cc64..0000000
--- a/res/layout/band_selector_toggle.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2018 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.
--->
-<merge xmlns:android="http://schemas.android.com/apk/res/android">
- <ImageButton
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:scaleType="fitXY"
- style="@style/RadioButton" />
-</merge>
diff --git a/res/layout/radio_activity.xml b/res/layout/radio_activity.xml
index 60ed8ff..45c022b 100644
--- a/res/layout/radio_activity.xml
+++ b/res/layout/radio_activity.xml
@@ -26,47 +26,14 @@
android:orientation="horizontal"
app:layout_constraintGuide_begin="@dimen/car_ui_toolbar_first_row_height" />
- <com.android.car.apps.common.widget.CarTabLayout
- android:id="@+id/tabs"
- android:layout_width="0dp"
- android:layout_height="@dimen/tab_height"
- android:layout_marginLeft="@dimen/tab_margin_left"
- android:layout_marginRight="@dimen/tab_margin_right"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintEnd_toStartOf="@+id/band_toggle_button"
- app:layout_constraintTop_toTopOf="parent"/>
-
- <com.android.car.radio.widget.BandSelectorToggle
- android:id="@+id/band_toggle_button"
- android:layout_width="@dimen/band_selector_size"
- android:layout_height="@dimen/band_selector_size"
- android:layout_marginTop="@dimen/control_button_margin"
- android:layout_marginRight="@dimen/control_button_margin"
- android:scaleType="center"
- app:layout_constraintEnd_toStartOf="@+id/app_selector_container"
- app:layout_constraintBottom_toTopOf="@+id/app_bar_bottom"
- app:layout_constraintTop_toTopOf="parent"/>
-
- <!-- TODO (b/143297376): Replace this and all the toolbar elements with
- com.android.car.ui.toolbar.Toolbar -->
- <FrameLayout
- android:id="@+id/app_selector_container"
- android:layout_width="@dimen/app_selector_icon_touch_target"
- android:layout_height="@dimen/app_selector_icon_touch_target"
- android:background="?android:attr/selectableItemBackground"
- android:layout_marginRight="@dimen/app_selector_margin_x"
+ <com.android.car.ui.toolbar.Toolbar
+ android:id="@+id/toolbar"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ app:title="@string/app_name"
app:layout_constraintTop_toTopOf="parent"
- app:layout_constraintBottom_toTopOf="@+id/app_bar_bottom"
- app:layout_constraintRight_toRightOf="parent">
-
- <ImageView
- android:id="@+id/app_selector"
- android:layout_width="@dimen/app_selector_icon_size"
- android:layout_height="@dimen/app_selector_icon_size"
- android:layout_gravity="center"
- android:src="@drawable/ic_app_switch"
- android:tint="@color/icon_tint" />
- </FrameLayout>
+ app:logo="@drawable/logo_fm_radio"
+ app:state="home"/>
<androidx.viewpager.widget.ViewPager
android:id="@+id/viewpager"
@@ -76,14 +43,14 @@
android:layout_weight="@integer/radio_activity_view_weight"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintTop_toBottomOf="@+id/tabs"
+ app:layout_constraintTop_toBottomOf="@+id/toolbar"
app:layout_constraintBottom_toTopOf="@+id/main_radio_display" />
<TextView
android:id="@+id/status_message"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintTop_toBottomOf="@+id/tabs"
+ app:layout_constraintTop_toBottomOf="@+id/toolbar"
app:layout_constraintBottom_toTopOf="@+id/main_radio_display"
android:visibility="gone"
style="@style/RadioStatusMessage" />
diff --git a/src/com/android/car/radio/BandController.java b/src/com/android/car/radio/BandController.java
new file mode 100644
index 0000000..c7f039b
--- /dev/null
+++ b/src/com/android/car/radio/BandController.java
@@ -0,0 +1,80 @@
+/**
+ * Copyright (C) 2018 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.car.radio;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import com.android.car.radio.bands.ProgramType;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * Keeps track of the current band and list of supported program types/bands (AM/FM/DAB etc).
+ */
+public class BandController {
+ private final Object mLock = new Object();
+
+ @NonNull private List<ProgramType> mSupportedBands = new ArrayList<>();
+ @Nullable private ProgramType mCurrentBand;
+
+ /**
+ * Sets supported program types.
+ */
+ public void setSupportedProgramTypes(@NonNull List<ProgramType> supported) {
+ synchronized (mLock) {
+ mSupportedBands = Objects.requireNonNull(supported);
+ }
+ }
+
+ /**
+ * Switches to the next supported band.
+ *
+ * @return The current band after the switch
+ */
+ public ProgramType switchToNext() {
+ synchronized (mLock) {
+ if (mSupportedBands.isEmpty()) {
+ return null;
+ }
+ mCurrentBand = mSupportedBands.get(
+ (mSupportedBands.indexOf(mCurrentBand) + 1) % mSupportedBands.size());
+ return mCurrentBand;
+ }
+ }
+
+ /**
+ * Sets the current band.
+ *
+ * @param programType Program type to set.
+ */
+ public void setType(@NonNull ProgramType programType) {
+ synchronized (mLock) {
+ mCurrentBand = programType;
+ }
+ }
+
+ /**
+ * Retrieves the current band.
+ */
+ public ProgramType getCurrentBand() {
+ return mCurrentBand;
+ }
+}
+
diff --git a/src/com/android/car/radio/DisplayController.java b/src/com/android/car/radio/DisplayController.java
index 15ae9c9..14b131e 100644
--- a/src/com/android/car/radio/DisplayController.java
+++ b/src/com/android/car/radio/DisplayController.java
@@ -50,7 +50,7 @@
private final Context mContext;
- private final View mTabs;
+ private final View mToolbar;
private final View mViewpager;
private final TextView mStatusMessage;
private final TextView mChannel;
@@ -60,7 +60,6 @@
private final ImageView mBackwardSeekButton;
private final ImageView mForwardSeekButton;
private final PlayPauseButton mPlayButton;
- private final View mBandButton;
private boolean mIsFavorite = false;
private final ImageView mFavoriteButton;
@@ -86,7 +85,7 @@
@NonNull RadioController radioController) {
mContext = Objects.requireNonNull(activity);
- mTabs = activity.findViewById(R.id.tabs);
+ mToolbar = activity.findViewById(R.id.toolbar);
mViewpager = activity.findViewById(R.id.viewpager);
mStatusMessage = activity.findViewById(R.id.status_message);
mChannel = activity.findViewById(R.id.station_channel);
@@ -95,7 +94,6 @@
mBackwardSeekButton = activity.findViewById(R.id.back_button);
mForwardSeekButton = activity.findViewById(R.id.forward_button);
mPlayButton = activity.findViewById(R.id.play_button);
- mBandButton = activity.findViewById(R.id.band_toggle_button);
mFavoriteButton = activity.findViewById(R.id.add_presets_button);
radioController.getPlaybackState().observe(activity, this::onPlaybackStateChanged);
@@ -142,14 +140,12 @@
mBackwardSeekButton.setEnabled(enabled);
mBackwardSeekButton.setColorFilter(tint);
}
- if (mBandButton != null) {
- mBandButton.setVisibility(enabled ? View.VISIBLE : View.GONE);
- }
+
if (mFavoriteButton != null) {
mFavoriteButton.setVisibility(enabled ? View.VISIBLE : View.GONE);
}
- if (mTabs != null) {
- mTabs.setVisibility(enabled ? View.VISIBLE : View.INVISIBLE);
+ if (mToolbar != null) {
+ mToolbar.setVisibility(enabled ? View.VISIBLE : View.INVISIBLE);
}
if (mViewpager != null) {
mViewpager.setVisibility(enabled ? View.VISIBLE : View.GONE);
diff --git a/src/com/android/car/radio/ManualTunerController.java b/src/com/android/car/radio/ManualTunerController.java
index 6082dc5..f9c8a8c 100644
--- a/src/com/android/car/radio/ManualTunerController.java
+++ b/src/com/android/car/radio/ManualTunerController.java
@@ -24,7 +24,7 @@
import com.android.car.radio.bands.ProgramType;
import com.android.car.radio.bands.RegionConfig;
-import com.android.car.radio.widget.BandSelector;
+import com.android.car.radio.widget.BandSelectorFlat;
import java.util.ArrayList;
import java.util.List;
@@ -36,7 +36,7 @@
private final List<View> mDigitButtons = new ArrayList<>();
private final View mEnterButton;
private final TextView mChannelDisplay;
- private BandSelector mBandSelector;
+ private BandSelectorFlat mBandSelector;
private ProgramType mProgramType;
private final RegionConfig mRegionConfig;
diff --git a/src/com/android/car/radio/RadioActivity.java b/src/com/android/car/radio/RadioActivity.java
index 3348d11..a9a956a 100644
--- a/src/com/android/car/radio/RadioActivity.java
+++ b/src/com/android/car/radio/RadioActivity.java
@@ -18,21 +18,23 @@
import android.car.Car;
import android.content.Intent;
+import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.KeyEvent;
-import android.view.View;
import androidx.annotation.NonNull;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager.widget.ViewPager;
-import com.android.car.apps.common.widget.CarTabLayout;
import com.android.car.media.common.source.MediaSource;
import com.android.car.media.common.source.MediaSourceViewModel;
import com.android.car.radio.bands.ProgramType;
import com.android.car.radio.util.Log;
-import com.android.car.radio.widget.BandSelector;
+import com.android.car.ui.toolbar.MenuItem;
+import com.android.car.ui.toolbar.TabLayout;
+import com.android.car.ui.toolbar.Toolbar;
+import java.util.Arrays;
import java.util.List;
/**
@@ -54,9 +56,8 @@
"android.intent.action.RADIO_APP_STATE";
private RadioController mRadioController;
- private BandSelector mBandSelector;
-
- private CarTabLayout mCarTabLayout;
+ private BandController mBandController = new BandController();
+ private Toolbar mToolbar;
private RadioPagerAdapter mRadioPagerAdapter;
@Override
@@ -66,23 +67,27 @@
Log.d(TAG, "Radio app main activity created");
setContentView(R.layout.radio_activity);
- mBandSelector = findViewById(R.id.band_toggle_button);
-
- View appSelector = findViewById(R.id.app_selector_container);
- Intent appSelectorIntent = MediaSource.getSourceSelectorIntent(this, false);
- appSelector.setOnClickListener(e -> startActivity(appSelectorIntent));
mRadioController = new RadioController(this);
- mBandSelector.setCallback(mRadioController::switchBand);
- mRadioController.getCurrentProgram().observe(this, info ->
- mBandSelector.setType(ProgramType.fromSelector(info.getSelector())));
+ mRadioController.getCurrentProgram().observe(this, info -> {
+ ProgramType programType = ProgramType.fromSelector(info.getSelector());
+ if (programType != null) {
+ mBandController.setType(programType);
+ updateMenuItems();
+ }
+ });
mRadioPagerAdapter =
new RadioPagerAdapter(this, getSupportFragmentManager(), mRadioController);
ViewPager viewPager = findViewById(R.id.viewpager);
viewPager.setAdapter(mRadioPagerAdapter);
- mCarTabLayout = findViewById(R.id.tabs);
- setupTabsWithViewPager(mCarTabLayout, viewPager);
+
+ mToolbar = requireViewById(R.id.toolbar);
+ mToolbar.registerOnTabSelectedListener(t ->
+ viewPager.setCurrentItem(mToolbar.getTabLayout().getTabPosition(t)));
+
+ updateMenuItems();
+ setupTabsWithViewPager(viewPager);
MediaSourceViewModel model = MediaSourceViewModel.get(getApplication());
model.getPrimaryMediaSource().observe(this, source -> {
@@ -138,11 +143,11 @@
}
/**
- * Set whether background scanning is supported, to know whether to show the browse tab or not
+ * Set whether background scanning is supported, to know whether to show the browse tab or not.
*/
public void setProgramListSupported(boolean supported) {
if (supported && mRadioPagerAdapter.addBrowseTab()) {
- buildTabs();
+ updateTabs();
}
}
@@ -150,32 +155,44 @@
* Sets supported program types.
*/
public void setSupportedProgramTypes(@NonNull List<ProgramType> supported) {
- mBandSelector.setSupportedProgramTypes(supported);
+ mBandController.setSupportedProgramTypes(supported);
}
- private void setupTabsWithViewPager(CarTabLayout carTabLayout, ViewPager viewPager) {
- carTabLayout.addOnCarTabSelectedListener(new CarTabLayout.SimpleOnCarTabSelectedListener() {
- @Override
- public void onCarTabSelected(CarTabLayout.CarTab carTab) {
- viewPager.setCurrentItem(carTabLayout.getCarTabPosition(carTab));
- }
- });
+ private void setupTabsWithViewPager(ViewPager viewPager) {
viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
- carTabLayout.selectCarTab(position);
+ mToolbar.selectTab(position);
}
});
- buildTabs();
+ updateTabs();
}
- private void buildTabs() {
- mCarTabLayout.clearAllCarTabs();
+ private void updateMenuItems() {
+ ProgramType currentBand = mBandController.getCurrentBand();
+ MenuItem bandSelectorMenuItem = MenuItem.builder(this)
+ .setIcon(currentBand != null ? currentBand.getResourceId() : 0)
+ .setOnClickListener(i -> {
+ ProgramType programType = mBandController.switchToNext();
+ mRadioController.switchBand(programType);
+ })
+ .build();
+
+ Intent appSelectorIntent = MediaSource.getSourceSelectorIntent(this, false);
+ MenuItem appSelectorMenuItem = MenuItem.builder(this)
+ .setIcon(R.drawable.ic_app_switch)
+ .setOnClickListener(m -> startActivity(appSelectorIntent))
+ .build();
+
+ mToolbar.setMenuItems(Arrays.asList(bandSelectorMenuItem, appSelectorMenuItem));
+ }
+
+ private void updateTabs() {
+ mToolbar.clearAllTabs();
for (int i = 0; i < mRadioPagerAdapter.getCount(); i++) {
- CarTabLayout.CarTab carTab = new CarTabLayout.CarTab(mRadioPagerAdapter.getPageIcon(i),
- mRadioPagerAdapter.getPageTitle(i));
- mCarTabLayout.addCarTab(carTab);
+ Drawable icon = mRadioPagerAdapter.getPageIcon(i);
+ CharSequence title = mRadioPagerAdapter.getPageTitle(i);
+ mToolbar.addTab(new TabLayout.Tab(icon, title));
}
}
-
}
diff --git a/src/com/android/car/radio/bands/AMProgramType.java b/src/com/android/car/radio/bands/AMProgramType.java
index c775a10..a863f85 100644
--- a/src/com/android/car/radio/bands/AMProgramType.java
+++ b/src/com/android/car/radio/bands/AMProgramType.java
@@ -16,6 +16,7 @@
package com.android.car.radio.bands;
+import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
@@ -39,6 +40,12 @@
}
@Override
+ @DrawableRes
+ public int getResourceId() {
+ return R.drawable.ic_radio_am;
+ }
+
+ @Override
protected int getLeadingDigitsFactor() {
return 1;
}
diff --git a/src/com/android/car/radio/bands/DABProgramType.java b/src/com/android/car/radio/bands/DABProgramType.java
index d619aab..bc9f275 100644
--- a/src/com/android/car/radio/bands/DABProgramType.java
+++ b/src/com/android/car/radio/bands/DABProgramType.java
@@ -18,6 +18,7 @@
import android.hardware.radio.ProgramSelector;
+import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
@@ -47,6 +48,12 @@
}
@Override
+ @DrawableRes
+ public int getResourceId() {
+ return 0;
+ }
+
+ @Override
public void tuneToDefault(@NonNull RadioTunerExt tuner, @NonNull RegionConfig config,
@Nullable TuneCallback result) {
Log.e(TAG, "Tunning to a default DAB channel is not supported yet");
diff --git a/src/com/android/car/radio/bands/FMProgramType.java b/src/com/android/car/radio/bands/FMProgramType.java
index 21fee6f..5a85db9 100644
--- a/src/com/android/car/radio/bands/FMProgramType.java
+++ b/src/com/android/car/radio/bands/FMProgramType.java
@@ -16,6 +16,7 @@
package com.android.car.radio.bands;
+import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
@@ -39,6 +40,12 @@
}
@Override
+ @DrawableRes
+ public int getResourceId() {
+ return R.drawable.ic_radio_fm;
+ }
+
+ @Override
protected int getLeadingDigitsFactor() {
return 100;
}
diff --git a/src/com/android/car/radio/bands/ProgramType.java b/src/com/android/car/radio/bands/ProgramType.java
index 27606bd..4f14ef4 100644
--- a/src/com/android/car/radio/bands/ProgramType.java
+++ b/src/com/android/car/radio/bands/ProgramType.java
@@ -20,6 +20,7 @@
import android.os.Parcel;
import android.os.Parcelable;
+import androidx.annotation.DrawableRes;
import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -96,6 +97,12 @@
public abstract int getLocalizedName();
/**
+ * Retrieves resourceId of this program type.
+ */
+ @DrawableRes
+ public abstract int getResourceId();
+
+ /**
* Tunes to a default channel from this band.
*
* @param tuner Tuner to take action on.
diff --git a/src/com/android/car/radio/widget/BandSelector.java b/src/com/android/car/radio/widget/BandSelector.java
deleted file mode 100644
index 0ec18ec..0000000
--- a/src/com/android/car/radio/widget/BandSelector.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/**
- * Copyright (C) 2018 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.car.radio.widget;
-
-import android.content.Context;
-import android.util.AttributeSet;
-import android.widget.LinearLayout;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-
-import com.android.car.radio.bands.ProgramType;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Objects;
-
-/**
- * A base class for widgets switching program types/bands (AM/FM/DAB etc).
- */
-public abstract class BandSelector extends LinearLayout {
- private final Object mLock = new Object();
-
- @Nullable private Callback mCallback;
-
- @NonNull private List<ProgramType> mSupportedBands = new ArrayList<>();
- @Nullable private ProgramType mCurrentBand;
-
- /**
- * Widget's onClick event translated to band callback.
- */
- public interface Callback {
- /**
- * Called when user uses this button to switch the band.
- *
- * @param pt ProgramType to switch to
- */
- void onSwitchTo(@NonNull ProgramType pt);
- }
-
- public BandSelector(Context context, AttributeSet attrs, int defStyleAttr) {
- super(context, attrs, defStyleAttr);
- }
-
- /**
- * Sets band selection callback.
- */
- public void setCallback(@Nullable Callback callback) {
- synchronized (mLock) {
- mCallback = callback;
- }
- }
-
- /**
- * Sets supported program types.
- */
- public void setSupportedProgramTypes(@NonNull List<ProgramType> supported) {
- synchronized (mLock) {
- mSupportedBands = Objects.requireNonNull(supported);
- }
- }
-
- protected void switchToNext() {
- synchronized (mLock) {
- switchTo(mSupportedBands.get(
- (mSupportedBands.indexOf(mCurrentBand) + 1) % mSupportedBands.size()));
- }
- }
-
- protected void switchTo(@NonNull ProgramType ptype) {
- synchronized (mLock) {
- if (mCallback != null) mCallback.onSwitchTo(ptype);
- }
- }
-
- /**
- * Sets band button state.
- *
- * This method doesn't trigger callback.
- *
- * @param ptype Program type to set.
- */
- public void setType(@NonNull ProgramType ptype) {
- synchronized (mLock) {
- mCurrentBand = ptype;
- }
- }
-}
diff --git a/src/com/android/car/radio/widget/BandSelectorFlat.java b/src/com/android/car/radio/widget/BandSelectorFlat.java
index b4dd9f5..def2eb2 100644
--- a/src/com/android/car/radio/widget/BandSelectorFlat.java
+++ b/src/com/android/car/radio/widget/BandSelectorFlat.java
@@ -20,8 +20,10 @@
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.Button;
+import android.widget.LinearLayout;
import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
import com.android.car.radio.R;
import com.android.car.radio.bands.ProgramType;
@@ -32,11 +34,24 @@
/**
* A band selector that shows a flat list of band buttons.
*/
-public class BandSelectorFlat extends BandSelector {
+public class BandSelectorFlat extends LinearLayout {
private final Object mLock = new Object();
+ @Nullable private Callback mCallback;
private final List<Button> mButtons = new ArrayList<>();
+ /**
+ * Widget's onClick event translated to band callback.
+ */
+ public interface Callback {
+ /**
+ * Called when user uses this button to switch the band.
+ *
+ * @param pt ProgramType to switch to
+ */
+ void onSwitchTo(@NonNull ProgramType pt);
+ }
+
public BandSelectorFlat(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
@@ -45,11 +60,26 @@
super(context, attrs, defStyleAttr);
}
- @Override
+ private void switchTo(@NonNull ProgramType ptype) {
+ synchronized (mLock) {
+ if (mCallback != null) mCallback.onSwitchTo(ptype);
+ }
+ }
+
+ /**
+ * Sets band selection callback.
+ */
+ public void setCallback(@Nullable Callback callback) {
+ synchronized (mLock) {
+ mCallback = callback;
+ }
+ }
+
+ /**
+ * Updates the list of supported program types.
+ */
public void setSupportedProgramTypes(@NonNull List<ProgramType> supported) {
synchronized (mLock) {
- super.setSupportedProgramTypes(supported);
-
final LayoutInflater inflater = LayoutInflater.from(getContext());
mButtons.clear();
@@ -65,11 +95,13 @@
}
}
- @Override
+ /**
+ * Updates the selected button based on the given program type.
+ *
+ * @param ptype The program type that needs to be selected.
+ */
public void setType(@NonNull ProgramType ptype) {
synchronized (mLock) {
- super.setType(ptype);
-
Context ctx = getContext();
for (Button btn : mButtons) {
boolean active = btn.getTag() == ptype;
diff --git a/src/com/android/car/radio/widget/BandSelectorToggle.java b/src/com/android/car/radio/widget/BandSelectorToggle.java
deleted file mode 100644
index e7edef3..0000000
--- a/src/com/android/car/radio/widget/BandSelectorToggle.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/**
- * Copyright (C) 2018 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.car.radio.widget;
-
-import android.content.Context;
-import android.util.AttributeSet;
-import android.view.LayoutInflater;
-import android.widget.ImageButton;
-
-import androidx.annotation.NonNull;
-
-import com.android.car.radio.R;
-import com.android.car.radio.bands.ProgramType;
-
-/**
- * A band selector that cycles through bands with a single button.
- */
-public class BandSelectorToggle extends BandSelector {
- private final ImageButton mButton;
-
- public BandSelectorToggle(Context context, AttributeSet attrs) {
- this(context, attrs, 0);
- }
-
- public BandSelectorToggle(Context context, AttributeSet attrs, int defStyleAttr) {
- super(context, attrs, defStyleAttr);
-
- LayoutInflater.from(context).inflate(R.layout.band_selector_toggle, this, true);
- mButton = (ImageButton) getChildAt(0); // ImageButton is the only child
- mButton.setOnClickListener(v -> switchToNext());
- }
-
- @Override
- public void setType(@NonNull ProgramType ptype) {
- super.setType(ptype);
-
- switch (ptype.id) {
- case ProgramType.ID_FM:
- mButton.setImageResource(R.drawable.ic_radio_fm);
- break;
- case ProgramType.ID_AM:
- mButton.setImageResource(R.drawable.ic_radio_am);
- break;
- default:
- mButton.setImageDrawable(null);
- }
- }
-}