Android Open Source - GoogleImageLoader Image Viewer Fragment






From Project

Back to project page GoogleImageLoader.

License

The source code is released under:

GNU General Public License

If you think the Android project GoogleImageLoader 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 com.challenge.uber.imageloader.fragments;
/*w w w. j a v  a2  s .co  m*/
import org.json.JSONException;
import org.json.JSONObject;

import com.challenge.uber.imageloader.R;
import com.squareup.picasso.Picasso;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

/**
 * Simple fragment in order to display the selected image in big.
 * @author Julien Salvi
 *
 */
public class ImageViewerFragment extends Fragment {

  //UI references.
  private ImageView gImage;
  //JSON reference.
  private JSONObject imageObject;
  
  public ImageViewerFragment() {
    // Required empty public constructor
  }
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //Check arguments
    if (getArguments() != null) {
      try {
        imageObject = new JSONObject(getArguments().getString("image_data", null));
      } catch (JSONException e) {
        imageObject = null;
      }
    }
  }

  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_image_view, container, false);
    
    //Setup UI
    gImage = (ImageView) view.findViewById(R.id.image_googlesearch);
    
    if (imageObject != null) {
      //Setup the image title
      getActivity().getActionBar().setTitle(
          Html.fromHtml(imageObject.optString("title", "no title")));
      // Setup image and title
      Picasso
        .with(getActivity())
        .load(Html.fromHtml(
            imageObject.optString("unescapedUrl", "no_image")).toString())
        .error(R.drawable.default_img)
        .into(gImage);
    }
    return view;
  }

}




Java Source Code List

com.challenge.uber.imageloader.ImageViewerActivity.java
com.challenge.uber.imageloader.SearchImageActivity.java
com.challenge.uber.imageloader.adapter.SearchHistoryAdapter.java
com.challenge.uber.imageloader.adapter.SearchImageAdapter.java
com.challenge.uber.imageloader.fragments.ImageViewerFragment.java
com.challenge.uber.imageloader.parser.JSONParser.java
com.challenge.uber.imageloader.utils.ShadowedTransformation.java
com.challenge.uber.imageloader.utils.Utils.java