Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

sharing through intents completed

  • Loading branch information...
commit c031bdaa7be5b7a77f7959633007702a09f23722 1 parent d5480ff
Mark L. Chang authored
12 README.md
View
@@ -1,12 +1,14 @@
Android Instagram (Andgram)
===========================
-This is an extremely simple Android Instagram client. It doesn't do much, but
-it will let you take pictures and upload them to Instagram. It will also let
-you view your activity feed.
+This is an Instagram client for Android. It is a total and utter hack.
+Please do look too closely at the code else you will feel sick and your
+eyes will likely bleed.
-No, it won't let you create an Instagram account. No, it really doesn't do
-anything else. If you want it to, just leave a comment or shoot me an email.
+No, it won't let you create an Instagram account. No, Instagram won't let
+you have images that are non-square larger than 612x612.
+
+If you want changes, fork the repository and send a pull request.
Resources:
47 src/org/acmelab/andgram/ImageListActivity.java
View
@@ -123,7 +123,7 @@ public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
// build dialog
List<String> dialogItems = new ArrayList<String>();
- // like/unlike
+ // 0: like/unlike
if( instagramImage.liker_list != null ) {
if( instagramImage.liker_list.contains(username) ) {
dialogItems.add("Unlike");
@@ -134,9 +134,15 @@ public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
dialogItems.add("Like");
}
+ // 1: comment
dialogItems.add("Comment");
- // delete
+ // 2: share
+ if( instagramImage.username.equals(username) ) {
+ dialogItems.add("Share");
+ }
+
+ // 3: delete
if( instagramImage.username.equals(username) ) {
dialogItems.add("Delete");
}
@@ -155,6 +161,9 @@ public void onClick(DialogInterface dialog, int item) {
showCommentDialog(instagramImage, username);
break;
case 2:
+ showShareDialog(instagramImage);
+ break;
+ case 3:
showDeleteDialog(instagramImage);
break;
default:
@@ -168,6 +177,40 @@ public void onClick(DialogInterface dialog, int item) {
}
};
+ public void showShareDialog(InstagramImage image) {
+ final InstagramImage finalImage = image;
+
+ // get the permalink
+ String url = Utils.createPermalinkUrl(finalImage.pk);
+ String jsonResponse = Utils.doRestfulGet(httpClient, url, getApplicationContext());
+ if( jsonResponse != null ) {
+ try {
+ JSONTokener jsonTokener = new JSONTokener(jsonResponse);
+ JSONObject jsonObject = new JSONObject(jsonTokener);
+ String permalink = jsonObject.getString("permalink");
+ if( permalink != null ) {
+ // shoot the intent
+ // will default to "messaging / sms" if nothing else is installed
+ Intent sharingIntent = new Intent(Intent.ACTION_SEND);
+ //Text seems to be necessary for Facebook and Twitter
+ sharingIntent.setType("text/plain");
+ sharingIntent.putExtra(Intent.EXTRA_TEXT, permalink);
+ startActivity(Intent.createChooser(sharingIntent,"Share using"));
+ }
+ } catch (JSONException j) {
+ Log.e(TAG, "JSON parse error: " + j.toString());
+ Toast.makeText(getApplicationContext(),
+ "There was an error communicating with Instagram",
+ Toast.LENGTH_SHORT).show();
+ }
+ } else {
+ Toast.makeText(getApplicationContext(),
+ "Failed to get permalink for the image", Toast.LENGTH_SHORT).show();
+ }
+
+ }
+
+
public void showDeleteDialog(InstagramImage image) {
final InstagramImage finalImage = image;
17 src/org/acmelab/andgram/Utils.java
View
@@ -74,13 +74,12 @@
public static final String UPLOAD_URL = "http://instagr.am/api/v1/media/upload/";
public static final String CONFIGURE_URL = "https://instagr.am/api/v1/media/configure/";
public static final String TIMELINE_URL = "http://instagr.am/api/v1/feed/timeline/";
- public static final String LIKE_UNLIKE_PREFIX = "http://instagr.am/api/v1/media/";
+ public static final String MEDIA_PREFIX = "http://instagr.am/api/v1/media/";
public static final String LIKE_POSTFIX = "/like/";
public static final String UNLIKE_POSTFIX = "/unlike/";
- public static final String COMMENT_PREFIX = "http://instagr.am/api/v1/media/";
public static final String COMMENT_POSTFIX = "/comment/";
- public static final String DELETE_PREFIX = "http://instagr.am/api/v1/media/";
public static final String DELETE_POSTFIX = "/delete/";
+ public static final String PERMALINK_POSTFIX = "/permalink/";
public static boolean isOnline(Context ctx) {
@@ -90,20 +89,24 @@ public static boolean isOnline(Context ctx) {
}
public static String createDeleteUrl(String id) {
- return DELETE_PREFIX + id + DELETE_POSTFIX;
+ return MEDIA_PREFIX + id + DELETE_POSTFIX;
}
public static String createLikeUrl(String id) {
- return LIKE_UNLIKE_PREFIX + id + LIKE_POSTFIX;
+ return MEDIA_PREFIX + id + LIKE_POSTFIX;
}
public static String createUnlikeUrl(String id) {
- return LIKE_UNLIKE_PREFIX + id + UNLIKE_POSTFIX;
+ return MEDIA_PREFIX + id + UNLIKE_POSTFIX;
}
public static String createCommentUrl(String id) {
- return COMMENT_PREFIX + id + COMMENT_POSTFIX;
+ return MEDIA_PREFIX + id + COMMENT_POSTFIX;
+ }
+
+ public static String createPermalinkUrl(String id) {
+ return MEDIA_PREFIX + id + PERMALINK_POSTFIX;
}
public static void CopyStream(InputStream is, OutputStream os)
Please sign in to comment.
Something went wrong with that request. Please try again.