ANDROIDFM Module Learning four source analysis (ix)

Source: Internet
Author: User

Next, let's take a look at Android\vendor\qcom\opensource\fm\fmapp2\src\com\caf\fmradio\presetlist.java.

Define a list list<presetstation>mpresetlist = new arraylist<presetstation> ();

Number of simultaneous stations

public synchronized int Getstationcount () {        return mpresetlist.size ();    }

Get the radio name

Public synchronized string getstationname (int stationnum) {        String name = "";        if (Mpresetlist.size () > Stationnum) {            name = Mpresetlist.get (stationnum). GetName ();        }        return name;    

Get Radio Frequency

public synchronized int getstationfrequency (int stationnum) {        int frequency = 102100;        if (Mpresetlist.size () > Stationnum) {            frequency = Mpresetlist.get (stationnum). Getfrequency ();        }        return frequency;    }

Set the radio frequency

Public synchronized void setstationfrequency (int stationnum, int frequency) {        Presetstation mstation = Mpresetlist.get (stationnum);        Mstation.setfrequency (frequency);    }

Set the station name

Public synchronized void Setstationname (int stationnum, String name) {        Presetstation mstation = Mpresetlist.get ( Stationnum);        Mstation.setname (name);    }

Get the radio by ID

Public synchronized presetstation getstationfromindex (int index) {        int totalpresets = Mpresetlist.size ();        Presetstation station = NULL;        if (Index < totalpresets) {Station            = mpresetlist.get (index);        }        return station;    }

Get the radio through the frequency

Public synchronized presetstation getstationfromfrequency (int frequency) {        int totalpresets = Mpresetlist.size ();        for (int presetnum = 0, presetnum < totalpresets; presetnum++) {            Presetstation station = Mpresetlist.get (presetnum );            if (station = null) {                if (frequency = = Station.getfrequency ()) {return station;}}        }        return null;    }

Add station name and frequency

Public synchronized presetstation addstation (String name, int freq) {        presetstation addstation = new Presetstation ( Name, freq);        if (addstation! = null) {            mpresetlist.add (addstation);        }        return addstation;    }

Add Station

Public synchronized presetstation addstation (Presetstation station) {        presetstation addstation = null;        if (station! = NULL) {            addstation = new Presetstation (station);            Mpresetlist.add (addstation);        }        return addstation;    }

Delete Station

Public synchronized void removestation (int index) {       int totalpresets = Mpresetlist.size ();       if (index >= 0) && (Index < totalpresets))       {          mpresetlist.remove (index);}    }

Clear FM List

Public synchronized void Clear () {        mpresetlist.clear ();    }

/* If the user chooses a new station in this list, this function will be called to update the list.

* /

Public synchronized Boolean setselectedstation (Presetstation selectstation) {        int totalpresets = Mpresetlist.size ( );        if (selectstation! = null) {for            (int presetnum = 0; presetnum < totalpresets; presetnum++) {                Presetstation St ation = Mpresetlist.get (presetnum);                if (station = null) {                    if (selectstation.getfrequency () = = Station.getfrequency ()) {                        if (Selectstation.getname ( ). Equalsignorecase (Station.getname ())) {                            mcurrentstation = presetnum;                            return true        ;        }}}} return false;    }

/* Check if there are same stations present in the list

* /

Public synchronized Boolean samestationexists (Presetstation comparestation) {        int totalpresets = Mpresetlist.size ( );        if (comparestation! = null) {for            (int presetnum = 0; presetnum < totalpresets; presetnum++) {                presetstation s tation = Mpresetlist.get (presetnum);                if (station = null) {                    if (comparestation.getfrequency () = = Station.getfrequency ()) {                        return true;                    }                }            }        }        return false;    }

/* If the user selects a new station in this list, this routine will be called

* Update the list.

* /

Public synchronized Boolean setselectedstation (int stationindex) {        Boolean foundstation = false;        int totalpresets = Mpresetlist.size ();        if (Stationindex < totalpresets) {            mcurrentstation = Stationindex;            Foundstation = true;        }        return foundstation;    }

Select Station

<pre name= "code" class= "java" >public synchronized void Selectstation (Presetstation selectstation) {        int Totalpresets = Mpresetlist.size ();        if (selectstation! = null) {for            (int presetnum = 0; presetnum < totalpresets; presetnum++) {                Presetstation St ation = Mpresetlist.get (presetnum);                if (station = null) {                    if (selectstation.getfrequency () = = Station.getfrequency ()) {                        Mcurrentstation    = Presetnum;                        return;}}}}    


Get the selected station

Public synchronized Presetstation getselectedstation () {        int totalpresets = Mpresetlist.size ();        Presetstation station = NULL;        if (Mcurrentstation < totalpresets) {Station            = Mpresetlist.get (mcurrentstation);        }        return station;    }

Select the next station

Public synchronized Presetstation selectnextstation () {        int totalpresets = Mpresetlist.size ();        Presetstation station = NULL;        if (Totalpresets > 0) {            mcurrentstation + +;            if ((mcurrentstation) >= totalpresets) {                mcurrentstation =0;            }            Station = Mpresetlist.get (mcurrentstation);        }        return station;    }


Select a previous station

Public synchronized Presetstation selectprevstation () {        int totalpresets = Mpresetlist.size ();        Presetstation station = NULL;        if (Totalpresets > 0) {            mcurrentstation--;            if (Mcurrentstation < 0) {                mcurrentstation = totalPresets-1;            }            Station = Mpresetlist.get (mcurrentstation);        }        return station;    }


ANDROIDFM Module Learning four source analysis (ix)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.