Android Open Source - android-animeinfo Anime Summary






From Project

Back to project page android-animeinfo.

License

The source code is released under:

This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a co...

If you think the Android project android-animeinfo 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

package net.winterday.android.Model;
/*from w w  w  .  j  a v a2 s .c  o  m*/
import java.util.Collection;
import java.util.Vector;

import net.winterday.android.Anime.Util.JSONFetcher;

import org.json.JSONArray;
import org.json.JSONObject;

import android.graphics.drawable.Drawable;
import android.util.Log;

public class AnimeSummary extends Anime {
  
  private String imageUrl;
  private int episodes;
  private String classification;
  private float rating;
  private String synopsis;
  private Drawable image;  
  private String type;

  public String getType() {
    return type;
  }

  public void setType(String type) {
    this.type = type;
  }

  public AnimeSummary()
  {
    
  }
  
  public AnimeSummary(JSONObject source) throws Exception {
    super(source);
    
    synopsis = source.getString("synopsis");
    type = source.getString("type");
    episodes = source.getInt("episodes");
    classification = source.getString("classification");
    imageUrl = source.getString("image_url");
    rating = source.getLong("members_score");

    try {
      Log.i("AnimeSummary", "Trying to download " + imageUrl);
      image = JSONFetcher.downloadImage(imageUrl);
      Log.i("AnimeSummary", "Succeeded.");
    }
    catch (Exception e)
    {
      Log.e("AnimeSummary", "Failed to download " + imageUrl, e);
    }
  }
  
  public float getRating() {
    return rating;
  }
  public void setRating(float rating) {
    this.rating = rating;
  }
  
  public Drawable getImage() {
    return image;
  }
  public void setImage(Drawable image) {
    this.image = image;
  }

  public String getImageUrl() {
    return imageUrl;
  }
  
  public String getTvString() {
    return type + " (" + episodes + ")";
  }
  
  public void setImageUrl(String imageUrl) {
    this.imageUrl = imageUrl;
  }
  public int getEpisodes() {
    return episodes;
  }
  public void setEpisodes(int episodes) {
    this.episodes = episodes;
  }

  public String getClassification() {
    return classification;
  }
  public void setClassification(String classification) {
    this.classification = classification;
  }
  public String getSynopsis() {
    return synopsis;
  }
  public void setSynopsis(String synopsis) {
    this.synopsis = synopsis;
  }
  
  public static Collection<AnimeSummary> findResults(String query) throws Exception
  {
    JSONObject object = JSONFetcher.downloadJSON("http://mal-api.com/anime/search?q=" + query.replace(' ', '+'));
    Vector<AnimeSummary> animations = new Vector<AnimeSummary>();
    
    JSONArray response = object.getJSONArray("results");
    
    for (int i = 0; i < response.length(); i++) {
      AnimeSummary anime = new AnimeSummary(response.getJSONObject(i));
      
      animations.add(anime);
    }
    
    return animations;
  }
  
}




Java Source Code List

net.winterday.android.Anime.DetailsActivity.java
net.winterday.android.Anime.SearchActivity.java
net.winterday.android.Anime.SearchResultsAdapter.java
net.winterday.android.Anime.Util.JSONFetcher.java
net.winterday.android.Model.AnimeFull.java
net.winterday.android.Model.AnimeSummary.java
net.winterday.android.Model.Anime.java