Search in sources :

Example 11 with Photo

use of com.trovebox.android.common.model.Photo in project mobile-android by photo.

the class PhotoUtils method getAndRegisterOnPhotoUpdatedActionBroadcastReceiver.

/**
     * Get and register the broadcast receiver for the photo updated event
     * 
     * @param TAG
     * @param handler
     * @param activity
     * @return
     */
public static BroadcastReceiver getAndRegisterOnPhotoUpdatedActionBroadcastReceiver(final String TAG, final PhotoUpdatedHandler handler, final Activity activity) {
    BroadcastReceiver br = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            try {
                CommonUtils.debug(TAG, "Received photo updated broadcast message");
                Photo photo = intent.getParcelableExtra(PHOTO_UPDATED);
                handler.photoUpdated(photo);
            } catch (Exception ex) {
                GuiUtils.error(TAG, ex);
            }
        }
    };
    activity.registerReceiver(br, new IntentFilter(PHOTO_UPDATED_ACTION));
    return br;
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) Photo(com.trovebox.android.common.model.Photo) BroadcastReceiver(android.content.BroadcastReceiver) ClientProtocolException(org.apache.http.client.ClientProtocolException) JSONException(org.json.JSONException) IOException(java.io.IOException)

Example 12 with Photo

use of com.trovebox.android.common.model.Photo in project mobile-android by photo.

the class AlbumTest method testAlbumData.

public void testAlbumData(Album album) {
    assertNotNull(album);
    assertEquals("4", album.getId());
    assertEquals("hello@openphoto.me", album.getOwner());
    assertEquals("Beautiful Scenery", album.getName());
    assertEquals(0, album.getVisible());
    assertEquals(13, album.getCount());
    Photo cover = album.getCover();
    assertNotNull(cover);
    assertEquals("bd", cover.getId());
}
Also used : Photo(com.trovebox.android.common.model.Photo)

Example 13 with Photo

use of com.trovebox.android.common.model.Photo in project mobile-android by photo.

the class TroveboxApiTest method testCreateTokenForPhoto.

public void testCreateTokenForPhoto() throws Exception {
    File file = createTestFileForUpload();
    boolean priv = true;
    UploadMetaData settings = new UploadMetaData();
    String title = "Android";
    String description = "Nice picture of an android";
    String tags = "test";
    settings.setTitle(title);
    settings.setDescription(description);
    settings.setTags(tags);
    settings.setPrivate(priv);
    try {
        String hash = SHA1Utils.computeSha1ForFile(file.getAbsolutePath());
        PhotosResponse photos = mApi.getPhotos(hash);
        assertTrue(photos.isSuccess());
        boolean created = false;
        Photo photo;
        if (photos.getPhotos().size() > 0) {
            photo = photos.getPhotos().get(0);
        } else {
            UploadResponse resp = mApi.uploadPhoto(file, settings, null);
            assertTrue(resp.isSuccess());
            assertNotNull(resp.getPhoto());
            photo = resp.getPhoto();
            created = true;
        }
        try {
            assertNotNull(photo);
            assertTrue(photo.getTags().size() >= 1);
            // assertEquals("test", resp.getPhoto().getTags().get(0));
            assertEquals(title, photo.getTitle());
            assertEquals(description, photo.getDescription());
            assertEquals(priv, photo.isPrivate());
            TokenResponse tokenResponse = mApi.createTokenForPhoto(photo.getId());
            assertEquals(tokenResponse.getCode(), 201);
            Token token = tokenResponse.getToken();
            assertNotNull(token);
            assertEquals(token.getType(), "photo");
            assertEquals(token.getData(), photo.getId());
            assertNotNull(token.getId());
            assertFalse(token.getId().isEmpty());
            System.out.println(token.getDateExpires());
            assertNotNull(token.getDateExpires());
        } finally {
            if (created) {
                // remove uploaded photo
                mApi.deletePhoto(photo.getId());
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail("Exception should not happen: " + e.getClass().getSimpleName() + " - " + e.getMessage());
    }
    file.delete();
}
Also used : UploadResponse(com.trovebox.android.common.net.UploadResponse) TokenResponse(com.trovebox.android.common.net.TokenResponse) UploadMetaData(com.trovebox.android.common.net.UploadMetaData) PhotosResponse(com.trovebox.android.common.net.PhotosResponse) Photo(com.trovebox.android.common.model.Photo) Token(com.trovebox.android.common.model.Token) File(java.io.File) ClientProtocolException(org.apache.http.client.ClientProtocolException) JSONException(org.json.JSONException) IOException(java.io.IOException)

Example 14 with Photo

use of com.trovebox.android.common.model.Photo in project mobile-android by photo.

the class TroveboxApiTest method testPhotoUploadAndDetailsEdit.

public void testPhotoUploadAndDetailsEdit() throws Exception {
    File file = createTestFileForUpload();
    UploadMetaData settings = new UploadMetaData();
    String title = "Android";
    String description = "Nice picture of an android";
    String tags = "test";
    boolean priv = false;
    settings.setTitle(title);
    settings.setDescription(description);
    settings.setTags(tags);
    settings.setPrivate(priv);
    try {
        UploadResponse resp = mApi.uploadPhoto(file, settings, null);
        assertTrue(resp.isSuccess());
        assertNotNull(resp.getPhoto());
        try {
            Photo photo = resp.getPhoto();
            assertNotNull(photo);
            assertTrue(photo.getTags().size() >= 1);
            // assertEquals("test", resp.getPhoto().getTags().get(0));
            assertEquals(title, photo.getTitle());
            assertEquals(description, photo.getDescription());
            assertFalse(photo.isPrivate());
            title = "Android (Edited)";
            description = "Nice picture of an android (Edited)";
            tags = "edited";
            Collection<String> tagsCollection = new ArrayList<String>();
            tagsCollection.add("edited");
            priv = true;
            PhotoResponse photoResp = mApi.updatePhotoDetails(photo.getId(), title, description, tagsCollection, Photo.PERMISSION_PRIVATE);
            photo = photoResp.getPhoto();
            assertTrue(photoResp.isSuccess());
            assertNotNull(photo);
            assertTrue(photo.getTags().size() == 1);
            assertEquals(tags, photo.getTags().get(0));
            assertEquals(title, photo.getTitle());
            assertEquals(description, photo.getDescription());
            assertTrue(photo.isPrivate() == priv);
        } finally {
            // remove uploaded photo
            mApi.deletePhoto(resp.getPhoto().getId());
        }
    } catch (Exception e) {
        fail("Exception should not happen: " + e.getClass().getSimpleName() + " - " + e.getMessage());
    }
    file.delete();
}
Also used : UploadResponse(com.trovebox.android.common.net.UploadResponse) ArrayList(java.util.ArrayList) PhotoResponse(com.trovebox.android.common.net.PhotoResponse) UploadMetaData(com.trovebox.android.common.net.UploadMetaData) Photo(com.trovebox.android.common.model.Photo) File(java.io.File) ClientProtocolException(org.apache.http.client.ClientProtocolException) JSONException(org.json.JSONException) IOException(java.io.IOException)

Example 15 with Photo

use of com.trovebox.android.common.model.Photo in project mobile-android by photo.

the class PhotoTest method testFromJson.

public void testFromJson() {
    Photo photo;
    try {
        JSONObject json = JSONUtils.getJson(getInstrumentation().getContext(), R.raw.json_photo);
        photo = Photo.fromJson(json);
    } catch (JSONException e) {
        throw new AssertionError("This exception should not be thrown!");
    }
    assertNotNull(photo);
    assertEquals("4t", photo.getId());
    assertNotNull(photo.getTags());
    assertTrue(photo.isPrivate());
    assertEquals(2, photo.getTags().size());
    assertEquals("sunnyvale", photo.getTags().get(0));
    assertEquals("tavin", photo.getTags().get(1));
    assertEquals("Tavin riding the horsey at Murphy Park in Sunnyvale", photo.getTitle());
    assertEquals("Nice description", photo.getDescription());
    assertEquals("current.trovebox.com", photo.getAppId());
    assertEquals("http://opmecurrent.s3.amazonaws.com/base/201108/1312348300-IMAG0015.jpg", photo.getUrl("base"));
    assertEquals("http://opmecurrent.s3.amazonaws.com/original/201108/1312348300-IMAG0015.jpg", photo.getUrl("original"));
    assertEquals("http://opmecurrent.s3.amazonaws.com/custom/201108/1312348300-IMAG0015_960x960.jpg", photo.getUrl("960x960"));
    assertEquals("http://opmecurrent.s3.amazonaws.com/custom/201108/1312348300-IMAG0015_50x50xCR.jpg", photo.getUrl("50x50xCR"));
}
Also used : JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) Photo(com.trovebox.android.common.model.Photo)

Aggregations

Photo (com.trovebox.android.common.model.Photo)17 Intent (android.content.Intent)5 IOException (java.io.IOException)5 JSONException (org.json.JSONException)5 ClientProtocolException (org.apache.http.client.ClientProtocolException)4 View (android.view.View)3 TextView (android.widget.TextView)3 UploadMetaData (com.trovebox.android.common.net.UploadMetaData)3 UploadResponse (com.trovebox.android.common.net.UploadResponse)3 RunnableWithParameter (com.trovebox.android.common.util.RunnableWithParameter)3 File (java.io.File)3 ArrayList (java.util.ArrayList)3 BroadcastReceiver (android.content.BroadcastReceiver)2 Context (android.content.Context)2 IntentFilter (android.content.IntentFilter)2 OnClickListener (android.view.View.OnClickListener)2 Button (android.widget.Button)2 PhotoResponse (com.trovebox.android.common.net.PhotoResponse)2 PhotosResponse (com.trovebox.android.common.net.PhotosResponse)2 Notification (android.app.Notification)1