Home | History | Annotate | Download | only in radio
      1 /*
      2  * Copyright (c) 2016, 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 package com.android.car.radio;
     17 
     18 import android.content.AsyncTaskLoader;
     19 import android.content.Context;
     20 import android.support.annotation.NonNull;
     21 import com.android.car.radio.service.RadioStation;
     22 
     23 import java.util.Collections;
     24 import java.util.List;
     25 
     26 /**
     27  * An {@link AsyncTaskLoader} that will load all the pre-scanned radio stations for a given band.
     28  */
     29 public class PreScannedChannelLoader extends AsyncTaskLoader<List<RadioStation>> {
     30     private final static int INVALID_RADIO_BAND = -1;
     31 
     32     private final RadioStorage mRadioStorage;
     33     private int mCurrentRadioBand = INVALID_RADIO_BAND;
     34 
     35     public PreScannedChannelLoader(Context context) {
     36         super(context);
     37         mRadioStorage = RadioStorage.getInstance(context);
     38     }
     39 
     40     /**
     41      * Sets the radio band that this loader should load the pre-scanned stations for.
     42      *
     43      * @param radioBand One of the band values in {@link android.hardware.radio.RadioManager}. For
     44      *                  example, {@link android.hardware.radio.RadioManager#BAND_FM}.
     45      */
     46     public void setCurrentRadioBand(int radioBand) {
     47         mCurrentRadioBand = radioBand;
     48     }
     49 
     50     /**
     51      * Returns a list of {@link RadioStation}s representing the pre-scanned channels for the band
     52      * specified by {@link #INVALID_RADIO_BAND}. If no stations exist for the given band, then an
     53      * empty list is returned.
     54      */
     55     @NonNull
     56     @Override
     57     public List<RadioStation> loadInBackground() {
     58         if (mCurrentRadioBand == INVALID_RADIO_BAND) {
     59             return Collections.emptyList();
     60         }
     61 
     62         return mRadioStorage.getPreScannedStationsForBand(mCurrentRadioBand);
     63     }
     64 }
     65