ImageActivity.java :  » App » gone-to-get » pt » gtg » musicinfo » generic » Android Open Source

Android Open Source » App » gone to get 
gone to get » pt » gtg » musicinfo » generic » ImageActivity.java
/**
 * Gone To Get Music Info
 * Copyright (C) 2010 Joao Eduardo Luis, Tiago Melo
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 2 as published by the Free Software Foundation.
 * 
 * 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 pt.gtg.musicinfo.generic;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;

import pt.gtg.musicinfo.R;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;

public class ImageActivity extends Activity {
  
  private static final String TAG = "Last.fm Image Activity";

  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.image);
        
    //Reads the info sent by the intent
    Intent the_intent_that_gave_life_to_everything = getIntent();
    Bundle intent_data = 
      the_intent_that_gave_life_to_everything.getExtras();

    if (intent_data == null)
    {
      Log.e(TAG, "No extra data");
      finish();
    }

    String imageUrl = intent_data.getString("url");
    if (imageUrl == null)
    {
      Log.e(TAG, "Null bundle parameters: artist name = "
          + imageUrl);
      finish();
    }

        ImageView imgV = 
          (ImageView) findViewById(R.id.image);
        imgV.setImageBitmap(urlToImage(imageUrl));
  }

  static public Bitmap urlToImage(String imageUrl) {

    URL myFileUrl = null;
    try {
      myFileUrl= new URL(imageUrl);
    } catch (MalformedURLException e) {
      e.printStackTrace();
    }

    InputStream is = null;
    try {
      is = myFileUrl.openStream();
    } catch (IOException e) {
      e.printStackTrace();
    }

    return BitmapFactory.decodeStream(is);
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.