Android Open Source - kluster-android Photo Viewer Fragment






From Project

Back to project page kluster-android.

License

The source code is released under:

Apache License

If you think the Android project kluster-android 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.cs446.kluster.views.fragments;
/*w w  w  .  jav a2s  .  co  m*/
import retrofit.Callback;
import retrofit.RestAdapter;
import retrofit.RetrofitError;
import retrofit.client.Response;
import android.app.Fragment;
import android.app.FragmentManager;
import android.content.ContentValues;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.webkit.WebView.FindListener;
import android.widget.ImageView;
import android.widget.TextView;

import com.cs446.kluster.R;
import com.cs446.kluster.data.PhotoProvider;
import com.cs446.kluster.data.PhotoProvider.PhotoOpenHelper;
import com.cs446.kluster.models.AuthUser;
import com.cs446.kluster.net.AuthKlusterRestAdapter;
import com.cs446.kluster.net.KlusterService;
import com.google.gson.JsonObject;
import com.squareup.picasso.Picasso;

public class PhotoViewerFragment extends Fragment {
  AuthUser user;

  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.photoview_layout, container, false);
    
    RestAdapter adapter = new AuthKlusterRestAdapter()
    .build();
    KlusterService service = adapter.create(KlusterService.class);
    
    return view;
  }
  
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    
    String url = getArguments().getString("url");
    final Integer up = Integer.parseInt(getArguments().getString("up"));
    final Integer down = Integer.parseInt(getArguments().getString("down"));
    final String id = getArguments().getString("photoid");
    final String userid = getArguments().getString("userid");
    
    ImageView imgMain =(ImageView)getView().findViewById(R.id.photoview_imgMain);
    ImageView imgUp = (ImageView)getView().findViewById(R.id.photoview_imgUp);
    final TextView txtUp = (TextView)getView().findViewById(R.id.photoview_txtUp);
    ImageView imgDown = (ImageView)getView().findViewById(R.id.photoview_imgDown);
    final TextView txtDown = (TextView)getView().findViewById(R.id.photoview_txtDown);
    final TextView txtUserName=(TextView)getView().findViewById(R.id.photoview_txtUser);
    
    txtUp.setText(Integer.toString(up));
    txtDown.setText(Integer.toString(down));
    
    RestAdapter adapter = new AuthKlusterRestAdapter()
    .build();
    KlusterService service = adapter.create(KlusterService.class);
    service.getUser(userid, new Callback<AuthUser>() {

      @Override
      public void failure(RetrofitError arg0) {
        // TODO Auto-generated method stub
        
      }

      @Override
      public void success(final AuthUser arg0, Response arg1) {
        // TODO Auto-generated method stub
        txtUserName.setText(arg0.getUserName());
        
        txtUserName.setOnClickListener(new OnClickListener() {
          
          @Override
          public void onClick(View v) {
            // TODO Auto-generated method stub
            Bundle bundle=new Bundle();
            bundle.putString("userid", userid);
            bundle.putString("username", arg0.getUserName());
            
            Fragment fragment = new UserProfileFragment();
            fragment.setArguments(bundle);
            FragmentManager fragmentManager = getFragmentManager();
            fragmentManager.beginTransaction().replace(R.id.main_container, fragment).commit(); 
            
          }
        });
      }
      
      
    });
    
    imgUp.setOnClickListener(new OnClickListener() {    
      @Override
      public void onClick(View v) {
        RestAdapter adapter = new AuthKlusterRestAdapter()
        .build();
        KlusterService service = adapter.create(KlusterService.class);
        
        JsonObject object = new JsonObject();
        object.addProperty("up", 1);
        service.ratePhotoUp(id, object, new Callback<Response>() {
          @Override
          public void failure(RetrofitError error) {
            Log.e("Rating", error.getResponse().getReason());
          }

          @Override
          public void success(Response response1, Response response2) {  
            ContentValues values = new ContentValues();
            values.put(PhotoOpenHelper.COLUMN_RATING_UP, up+1);
            
            getActivity().getContentResolver().update(PhotoProvider.CONTENT_URI,
                values, "photoid = ?", new String[] { id });
            
            txtUp.setText(Integer.toString(up+1));
          }
        });
      }
    });
    
    imgDown.setOnClickListener(new OnClickListener() {    
      @Override
      public void onClick(View v) {
        RestAdapter adapter = new AuthKlusterRestAdapter()
        .build();
        KlusterService service = adapter.create(KlusterService.class);
        
        JsonObject object = new JsonObject();
        object.addProperty("down", 1);
        service.ratePhotoUp(id, object, new Callback<Response>() {
          @Override
          public void failure(RetrofitError error) {
            Log.e("Rating", error.getResponse().getReason());
          }

          @Override
          public void success(Response response1, Response response2) {  
            ContentValues values = new ContentValues();
            values.put(PhotoOpenHelper.COLUMN_RATING_DOWN, down+1);
            
            getActivity().getContentResolver().update(PhotoProvider.CONTENT_URI,
                values, "photoid = ?", new String[] { id });            

            txtDown.setText(Integer.toString(down+1));
          }
        });
      }
    });
         
    Picasso.with(getActivity()).load(url).into(imgMain);
        
    //KlusterApplication.getInstance().getCache().loadBitmap(url, imgMain, getActivity());    
  }
}




Java Source Code List

android.app.GridFragment.java
android.app.NonSwipeableViewPager.java
android.app.ScaleImageView.java
com.cs446.kluster.ConfigManager.java
com.cs446.kluster.KlusterApplication.java
com.cs446.kluster.cache.CacheUtils.java
com.cs446.kluster.cache.DiskLruCache.java
com.cs446.kluster.cache.DiskLruImageCache.java
com.cs446.kluster.cache.KlusterCache.java
com.cs446.kluster.data.AbstractContentStorageAdapter.java
com.cs446.kluster.data.EventProvider.java
com.cs446.kluster.data.EventStorageAdapter.java
com.cs446.kluster.data.PhotoProvider.java
com.cs446.kluster.data.PhotoStorageAdapter.java
com.cs446.kluster.data.SearchProvider.java
com.cs446.kluster.data.SearchStorageAdapter.java
com.cs446.kluster.data.StorageAdapter.java
com.cs446.kluster.data.StorageConstants.java
com.cs446.kluster.data.serialize.AuthUserAdapter.java
com.cs446.kluster.data.serialize.EventAdapter.java
com.cs446.kluster.data.serialize.PhotoAdapter.java
com.cs446.kluster.data.serialize.SerializerUtils.java
com.cs446.kluster.data.serialize.UserAdapter.java
com.cs446.kluster.map.MapUtils.java
com.cs446.kluster.models.AuthUser.java
com.cs446.kluster.models.Event.java
com.cs446.kluster.models.Photo.java
com.cs446.kluster.models.User.java
com.cs446.kluster.net.AuthInterceptor.java
com.cs446.kluster.net.AuthKlusterRestAdapter.java
com.cs446.kluster.net.EventsCallback.java
com.cs446.kluster.net.KlusterRestAdapter.java
com.cs446.kluster.net.KlusterService.java
com.cs446.kluster.net.NetworkUtils.java
com.cs446.kluster.net.PhotosCallback.java
com.cs446.kluster.net.UploadService.java
com.cs446.kluster.views.activities.LoginActivity.java
com.cs446.kluster.views.activities.MainActivity.java
com.cs446.kluster.views.activities.PhotoFactory.java
com.cs446.kluster.views.activities.PhotoGridActivity.java
com.cs446.kluster.views.fragments.DiscoverFragment.java
com.cs446.kluster.views.fragments.EventDialogFragment.java
com.cs446.kluster.views.fragments.EventGridAdapter.java
com.cs446.kluster.views.fragments.EventGridFragment.java
com.cs446.kluster.views.fragments.EventMapFragment.java
com.cs446.kluster.views.fragments.FilterDialogFragment.java
com.cs446.kluster.views.fragments.PhotoGridAdapter.java
com.cs446.kluster.views.fragments.PhotoGridFragment.java
com.cs446.kluster.views.fragments.PhotoViewerFragment.java
com.cs446.kluster.views.fragments.SearchFragment.java
com.cs446.kluster.views.fragments.SearchGridFragment.java
com.cs446.kluster.views.fragments.SearchMapFragment.java
com.cs446.kluster.views.fragments.SignupFragment.java
com.cs446.kluster.views.fragments.UserProfileFragment.java
com.cs446.kluster.views.map.PhotoInfoWindowAdapter.java