Android Open Source - pandoroid Station






From Project

Back to project page pandoroid.

License

The source code is released under:

GNU General Public License

If you think the Android project pandoroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/* Pandoroid Radio - open source pandora.com client for android
 * Copyright (C) 2011  Andrew Regner <andrew@aregner.com>
 * //  ww w.  java 2  s .com
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
package com.aregner.pandora;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Vector;


public class Station implements Comparable<Station>, Serializable {
  private static final long serialVersionUID = 1L;
  
  private String id;
  private String idToken;
  private boolean isCreator;
  private boolean isQuickMix;
  private String name;

  transient private Song[] currentPlaylist;
  transient private boolean useQuickMix;
  transient private PandoraRadio pandora;

  public Station(HashMap<String, Object> d, PandoraRadio instance) {
    id = (String) d.get("stationId");
    idToken = (String) d.get("stationIdToken");
    isCreator = (Boolean) d.get("isCreator");
    isQuickMix = (Boolean) d.get("isQuickMix");
    name = (String) d.get("stationName");

    pandora = instance;
    useQuickMix = false;
  }
  
  public Song[] getPlaylist(boolean forceDownload) {
    return getPlaylist(PandoraRadio.DEFAULT_AUDIO_FORMAT, forceDownload);
  }
  
  public Song[] getPlaylist(String format, boolean forceDownload) {
    if(forceDownload || currentPlaylist == null) {
      return getPlaylist(format);
    }
    else {
      return currentPlaylist;
    }
  }

  @SuppressWarnings("unchecked")
  public Song[] getPlaylist(String format) {
    Vector<Object> args = new Vector<Object>(7);
    args.add(id);
    args.add("0");
    args.add("");
    args.add("");
    args.add(format);
    args.add("0");
    args.add("0");

    Object result = pandora.xmlrpcCall("playlist.getFragment", args);

    if(result instanceof Object[]) {
      Object[] fragmentsResult = (Object[]) result;
      Song[] list = new Song[fragmentsResult.length];
      for(int f=0; f<fragmentsResult.length; f++) {
        list[f] = new Song((HashMap<String,Object>)fragmentsResult[f], pandora);
      }
      currentPlaylist = list;
    }

    return currentPlaylist;
  }

  public long getId() {
    try {
      return Long.parseLong(id);
    } catch(NumberFormatException ex) {
      return id.hashCode();
    }
  }

  public String getName() {
    return name;
  }

  public String getStationImageUrl() {
    getPlaylist(false);
    return currentPlaylist[0].getAlbumCoverUrl();
  }
  
  public int compareTo(Station another) {
    return getName().compareTo(another.getName());
  }
  
  public boolean equals(Station another) {
    return getName().equals(another.getName());
  }

  public String getStationId() {
    return id;
  }

  public String getStationIdToken() {
    return idToken;
  }

  public boolean isCreator() {
    return isCreator;
  }

  public boolean isQuickMix() {
    return isQuickMix;
  }
}




Java Source Code List

com.aregner.android.pandoid.ImageDownloader.java
com.aregner.android.pandoid.PandoidLogin.java
com.aregner.android.pandoid.PandoidPlayer.java
com.aregner.android.pandoid.PandoidSettings.java
com.aregner.android.pandoid.PandoidStationSelect.java
com.aregner.android.pandoid.PandoraDB.java
com.aregner.android.pandoid.PandoraRadioService.java
com.aregner.pandora.Blowfish.java
com.aregner.pandora.PandoraKeys.java
com.aregner.pandora.PandoraRadio.java
com.aregner.pandora.Song.java
com.aregner.pandora.Station.java
com.aregner.pandora.XmlRpc.java
org.xmlrpc.android.Base64Coder.java
org.xmlrpc.android.IXMLRPCSerializer.java
org.xmlrpc.android.MethodCall.java
org.xmlrpc.android.Tag.java
org.xmlrpc.android.XMLRPCClient.java
org.xmlrpc.android.XMLRPCCommon.java
org.xmlrpc.android.XMLRPCException.java
org.xmlrpc.android.XMLRPCFault.java
org.xmlrpc.android.XMLRPCSerializable.java
org.xmlrpc.android.XMLRPCSerializer.java
org.xmlrpc.android.XMLRPCServer.java