Android Open Source - kluster-android Upload Service






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.net;
//from w ww.  jav a  2s  .com
import java.io.File;

import org.json.JSONArray;
import org.json.JSONException;

import retrofit.Callback;
import retrofit.RestAdapter;
import retrofit.RetrofitError;
import retrofit.client.Response;
import retrofit.mime.TypedFile;
import retrofit.mime.TypedString;
import android.app.IntentService;
import android.content.Intent;
import android.util.Log;

import com.cs446.kluster.data.PhotoStorageAdapter;
import com.cs446.kluster.models.Photo;

public class UploadService extends IntentService {
    
  /**
   * A constructor is required, and must call the super IntentService(String)
   * constructor with a name for the worker thread.
   */
  public UploadService() {
    super("UploadService");
  }

  /**
   * The IntentService calls this method from the default worker thread with
   * the intent that started the service. When this method returns,
   * IntentService stops the service, as appropriate.
   */
  @Override
  protected void onHandleIntent(Intent intent) {
    UploadFile((Photo)intent.getParcelableExtra("com.cs446.kluster.Photo"));
  }
  
  private boolean UploadFile(Photo photo) {
    RestAdapter restAdapter = new AuthKlusterRestAdapter()
    .build();    
    KlusterService service = restAdapter.create(KlusterService.class);
      JSONArray longlat = new JSONArray();
    String time = Photo.getDateFormat().format(photo.getDate());
    
    try {
      longlat.put(photo.getLocation().longitude);
      longlat.put(photo.getLocation().latitude);
    } catch (JSONException e) {
    }  
    
    service.createPhoto(new TypedFile("application/octet-stream",
        new File(photo.getUrl())),
        new TypedString(longlat.toString()),
        new TypedString(time),
        new TypedString(photo.getTags().get(2)),
        new TypedString(photo.getTags().get(1)),
        new TypedString(photo.getTags().get(0)),
        new Callback<Photo>() {  
          @Override
          public void success(Photo photo, Response response) {
                PhotoStorageAdapter storage = new PhotoStorageAdapter(getContentResolver());    
                storage.insert(photo);
          }      
          @Override
          public void failure(RetrofitError error) {
            Log.e("UPLOAD", error.getResponse().getReason());
          }
        });
    
    return true;
  }
}




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