├── .idea ├── .name ├── copyright │ └── profiles_settings.xml ├── scopes │ └── scope_settings.xml ├── encodings.xml ├── vcs.xml ├── gradle.xml ├── modules.xml ├── compiler.xml └── misc.xml ├── ImgurAPIv3Example ├── .gitignore ├── src │ └── main │ │ ├── ic_launcher-web.png │ │ ├── res │ │ ├── drawable-hdpi │ │ │ ├── ic_launcher.png │ │ │ ├── ic_action_search.png │ │ │ ├── content_copy_holo_dark.png │ │ │ ├── btn_default_disabled_holo_dark.9.png │ │ │ ├── btn_default_focused_holo_dark.9.png │ │ │ ├── btn_default_normal_holo_dark.9.png │ │ │ ├── btn_default_pressed_holo_dark.9.png │ │ │ ├── collections_collection_holo_dark.png │ │ │ └── btn_default_disabled_focused_holo_dark.9.png │ │ ├── drawable-mdpi │ │ │ ├── ic_launcher.png │ │ │ ├── ic_action_search.png │ │ │ ├── content_copy_holo_dark.png │ │ │ ├── btn_default_disabled_holo_dark.9.png │ │ │ ├── btn_default_focused_holo_dark.9.png │ │ │ ├── btn_default_normal_holo_dark.9.png │ │ │ ├── btn_default_pressed_holo_dark.9.png │ │ │ ├── collections_collection_holo_dark.png │ │ │ └── btn_default_disabled_focused_holo_dark.9.png │ │ ├── drawable-xhdpi │ │ │ ├── ic_launcher.png │ │ │ ├── ic_action_search.png │ │ │ ├── content_copy_holo_dark.png │ │ │ ├── btn_default_focused_holo_dark.9.png │ │ │ ├── btn_default_normal_holo_dark.9.png │ │ │ ├── btn_default_pressed_holo_dark.9.png │ │ │ ├── btn_default_disabled_holo_dark.9.png │ │ │ ├── collections_collection_holo_dark.png │ │ │ └── btn_default_disabled_focused_holo_dark.9.png │ │ ├── drawable-xxhdpi │ │ │ └── ic_launcher.png │ │ ├── values │ │ │ ├── styles.xml │ │ │ ├── dimens.xml │ │ │ └── strings.xml │ │ ├── menu │ │ │ └── activity_upload.xml │ │ ├── values-w820dp │ │ │ └── dimens.xml │ │ └── layout │ │ │ ├── activity_upload.xml │ │ │ └── choose_image_fragment.xml │ │ ├── java │ │ └── com │ │ │ └── imgur │ │ │ └── api3example │ │ │ ├── MyAppConstants.java │ │ │ ├── login │ │ │ ├── RefreshAccessTokenTask.java │ │ │ ├── LoginActivity.java │ │ │ └── ImgurAuthorization.java │ │ │ ├── ImgurSampleApplication.java │ │ │ ├── util │ │ │ └── BitmapUtils.java │ │ │ ├── ChooseImageActivity.java │ │ │ ├── ImgurUploadTask.java │ │ │ └── ChooseImageFragment.java │ │ └── AndroidManifest.xml ├── build.gradle └── ImgurAPIv3Example.iml ├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── README.md ├── ImgurAPIv3ExampleProject.iml ├── ImgurAPIv3ExampleAndroid.iml ├── gradlew.bat └── gradlew /.idea/.name: -------------------------------------------------------------------------------- 1 | ImgurAPIv3Example -------------------------------------------------------------------------------- /ImgurAPIv3Example/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':ImgurAPIv3Example' 2 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talklittle/ImgurAPIv3ExampleAndroid/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /ImgurAPIv3Example/src/main/ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talklittle/ImgurAPIv3ExampleAndroid/HEAD/ImgurAPIv3Example/src/main/ic_launcher-web.png -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /.idea/scopes/scope_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /ImgurAPIv3Example/src/main/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talklittle/ImgurAPIv3ExampleAndroid/HEAD/ImgurAPIv3Example/src/main/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /ImgurAPIv3Example/src/main/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talklittle/ImgurAPIv3ExampleAndroid/HEAD/ImgurAPIv3Example/src/main/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /ImgurAPIv3Example/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talklittle/ImgurAPIv3ExampleAndroid/HEAD/ImgurAPIv3Example/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /ImgurAPIv3Example/src/main/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talklittle/ImgurAPIv3ExampleAndroid/HEAD/ImgurAPIv3Example/src/main/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /ImgurAPIv3Example/src/main/res/drawable-hdpi/ic_action_search.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talklittle/ImgurAPIv3ExampleAndroid/HEAD/ImgurAPIv3Example/src/main/res/drawable-hdpi/ic_action_search.png -------------------------------------------------------------------------------- /ImgurAPIv3Example/src/main/res/drawable-mdpi/ic_action_search.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talklittle/ImgurAPIv3ExampleAndroid/HEAD/ImgurAPIv3Example/src/main/res/drawable-mdpi/ic_action_search.png -------------------------------------------------------------------------------- /ImgurAPIv3Example/src/main/res/drawable-xhdpi/ic_action_search.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talklittle/ImgurAPIv3ExampleAndroid/HEAD/ImgurAPIv3Example/src/main/res/drawable-xhdpi/ic_action_search.png -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /ImgurAPIv3Example/src/main/res/drawable-hdpi/content_copy_holo_dark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talklittle/ImgurAPIv3ExampleAndroid/HEAD/ImgurAPIv3Example/src/main/res/drawable-hdpi/content_copy_holo_dark.png -------------------------------------------------------------------------------- /ImgurAPIv3Example/src/main/res/drawable-mdpi/content_copy_holo_dark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talklittle/ImgurAPIv3ExampleAndroid/HEAD/ImgurAPIv3Example/src/main/res/drawable-mdpi/content_copy_holo_dark.png -------------------------------------------------------------------------------- /ImgurAPIv3Example/src/main/res/drawable-xhdpi/content_copy_holo_dark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talklittle/ImgurAPIv3ExampleAndroid/HEAD/ImgurAPIv3Example/src/main/res/drawable-xhdpi/content_copy_holo_dark.png -------------------------------------------------------------------------------- /ImgurAPIv3Example/src/main/res/drawable-hdpi/btn_default_disabled_holo_dark.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talklittle/ImgurAPIv3ExampleAndroid/HEAD/ImgurAPIv3Example/src/main/res/drawable-hdpi/btn_default_disabled_holo_dark.9.png -------------------------------------------------------------------------------- /ImgurAPIv3Example/src/main/res/drawable-hdpi/btn_default_focused_holo_dark.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talklittle/ImgurAPIv3ExampleAndroid/HEAD/ImgurAPIv3Example/src/main/res/drawable-hdpi/btn_default_focused_holo_dark.9.png -------------------------------------------------------------------------------- /ImgurAPIv3Example/src/main/res/drawable-hdpi/btn_default_normal_holo_dark.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talklittle/ImgurAPIv3ExampleAndroid/HEAD/ImgurAPIv3Example/src/main/res/drawable-hdpi/btn_default_normal_holo_dark.9.png -------------------------------------------------------------------------------- /ImgurAPIv3Example/src/main/res/drawable-hdpi/btn_default_pressed_holo_dark.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talklittle/ImgurAPIv3ExampleAndroid/HEAD/ImgurAPIv3Example/src/main/res/drawable-hdpi/btn_default_pressed_holo_dark.9.png -------------------------------------------------------------------------------- /ImgurAPIv3Example/src/main/res/drawable-hdpi/collections_collection_holo_dark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talklittle/ImgurAPIv3ExampleAndroid/HEAD/ImgurAPIv3Example/src/main/res/drawable-hdpi/collections_collection_holo_dark.png -------------------------------------------------------------------------------- /ImgurAPIv3Example/src/main/res/drawable-mdpi/btn_default_disabled_holo_dark.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talklittle/ImgurAPIv3ExampleAndroid/HEAD/ImgurAPIv3Example/src/main/res/drawable-mdpi/btn_default_disabled_holo_dark.9.png -------------------------------------------------------------------------------- /ImgurAPIv3Example/src/main/res/drawable-mdpi/btn_default_focused_holo_dark.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talklittle/ImgurAPIv3ExampleAndroid/HEAD/ImgurAPIv3Example/src/main/res/drawable-mdpi/btn_default_focused_holo_dark.9.png -------------------------------------------------------------------------------- /ImgurAPIv3Example/src/main/res/drawable-mdpi/btn_default_normal_holo_dark.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talklittle/ImgurAPIv3ExampleAndroid/HEAD/ImgurAPIv3Example/src/main/res/drawable-mdpi/btn_default_normal_holo_dark.9.png -------------------------------------------------------------------------------- /ImgurAPIv3Example/src/main/res/drawable-mdpi/btn_default_pressed_holo_dark.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talklittle/ImgurAPIv3ExampleAndroid/HEAD/ImgurAPIv3Example/src/main/res/drawable-mdpi/btn_default_pressed_holo_dark.9.png -------------------------------------------------------------------------------- /ImgurAPIv3Example/src/main/res/drawable-mdpi/collections_collection_holo_dark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talklittle/ImgurAPIv3ExampleAndroid/HEAD/ImgurAPIv3Example/src/main/res/drawable-mdpi/collections_collection_holo_dark.png -------------------------------------------------------------------------------- /ImgurAPIv3Example/src/main/res/drawable-xhdpi/btn_default_focused_holo_dark.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talklittle/ImgurAPIv3ExampleAndroid/HEAD/ImgurAPIv3Example/src/main/res/drawable-xhdpi/btn_default_focused_holo_dark.9.png -------------------------------------------------------------------------------- /ImgurAPIv3Example/src/main/res/drawable-xhdpi/btn_default_normal_holo_dark.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talklittle/ImgurAPIv3ExampleAndroid/HEAD/ImgurAPIv3Example/src/main/res/drawable-xhdpi/btn_default_normal_holo_dark.9.png -------------------------------------------------------------------------------- /ImgurAPIv3Example/src/main/res/drawable-xhdpi/btn_default_pressed_holo_dark.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talklittle/ImgurAPIv3ExampleAndroid/HEAD/ImgurAPIv3Example/src/main/res/drawable-xhdpi/btn_default_pressed_holo_dark.9.png -------------------------------------------------------------------------------- /ImgurAPIv3Example/src/main/res/drawable-xhdpi/btn_default_disabled_holo_dark.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talklittle/ImgurAPIv3ExampleAndroid/HEAD/ImgurAPIv3Example/src/main/res/drawable-xhdpi/btn_default_disabled_holo_dark.9.png -------------------------------------------------------------------------------- /ImgurAPIv3Example/src/main/res/drawable-xhdpi/collections_collection_holo_dark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talklittle/ImgurAPIv3ExampleAndroid/HEAD/ImgurAPIv3Example/src/main/res/drawable-xhdpi/collections_collection_holo_dark.png -------------------------------------------------------------------------------- /ImgurAPIv3Example/src/main/res/drawable-hdpi/btn_default_disabled_focused_holo_dark.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talklittle/ImgurAPIv3ExampleAndroid/HEAD/ImgurAPIv3Example/src/main/res/drawable-hdpi/btn_default_disabled_focused_holo_dark.9.png -------------------------------------------------------------------------------- /ImgurAPIv3Example/src/main/res/drawable-mdpi/btn_default_disabled_focused_holo_dark.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talklittle/ImgurAPIv3ExampleAndroid/HEAD/ImgurAPIv3Example/src/main/res/drawable-mdpi/btn_default_disabled_focused_holo_dark.9.png -------------------------------------------------------------------------------- /ImgurAPIv3Example/src/main/res/drawable-xhdpi/btn_default_disabled_focused_holo_dark.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/talklittle/ImgurAPIv3ExampleAndroid/HEAD/ImgurAPIv3Example/src/main/res/drawable-xhdpi/btn_default_disabled_focused_holo_dark.9.png -------------------------------------------------------------------------------- /ImgurAPIv3Example/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | *.zip 3 | .DS_Store 4 | **/assets/www/ 5 | bin/ 6 | gen/ 7 | 8 | # Android Studio and Gradle 9 | .idea/tasks.xml 10 | .idea/workspace.xml 11 | .idea/libraries 12 | .gradle 13 | build 14 | local.properties 15 | app/*.keystore 16 | 17 | -------------------------------------------------------------------------------- /ImgurAPIv3Example/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Dec 29 19:09:36 EST 2014 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Imgur API v3 Example Android 2 | ============================ 3 | 4 | Make sure to fill in your Imgur app Client ID and Client Secret in `MyAppConstants.java`. 5 | 6 | This example uses Android Studio and Gradle. 7 | 8 | [Eclipse users look here][1]. 9 | 10 | [1]: https://github.com/talklittle/ImgurAPIv3ExampleAndroidEclipse 11 | 12 | -------------------------------------------------------------------------------- /ImgurAPIv3Example/src/main/res/menu/activity_upload.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | -------------------------------------------------------------------------------- /ImgurAPIv3Example/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /ImgurAPIv3Example/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | mavenCentral() 4 | } 5 | 6 | } 7 | apply plugin: 'com.android.application' 8 | 9 | repositories { 10 | mavenCentral() 11 | } 12 | 13 | android { 14 | compileSdkVersion 21 15 | buildToolsVersion "21.1.2" 16 | 17 | defaultConfig { 18 | minSdkVersion 7 19 | targetSdkVersion 21 20 | } 21 | } 22 | 23 | dependencies { 24 | compile 'com.android.support:appcompat-v7:+' 25 | } 26 | -------------------------------------------------------------------------------- /ImgurAPIv3Example/src/main/java/com/imgur/api3example/MyAppConstants.java: -------------------------------------------------------------------------------- 1 | package com.imgur.api3example; 2 | 3 | public class MyAppConstants { 4 | public static final String MY_IMGUR_CLIENT_ID = ""; 5 | public static final String MY_IMGUR_CLIENT_SECRET = ""; 6 | //The arbitrary redirect url (Authorization callback URL), ex. awesome://imgur or http://android, 7 | // declared when registering your app with Imgur API 8 | public static final String MY_IMGUR_REDIRECT_URL = ""; 9 | } 10 | -------------------------------------------------------------------------------- /ImgurAPIv3Example/src/main/res/layout/activity_upload.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /ImgurAPIv3ExampleProject.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /ImgurAPIv3Example/src/main/java/com/imgur/api3example/login/RefreshAccessTokenTask.java: -------------------------------------------------------------------------------- 1 | package com.imgur.api3example.login; 2 | 3 | import android.os.AsyncTask; 4 | import android.text.TextUtils; 5 | import android.util.Log; 6 | 7 | public class RefreshAccessTokenTask extends AsyncTask { 8 | 9 | private static final String TAG = RefreshAccessTokenTask.class.getSimpleName(); 10 | 11 | @Override 12 | protected String doInBackground(Void... params) { 13 | String accessToken = ImgurAuthorization.getInstance().requestNewAccessToken(); 14 | if (!TextUtils.isEmpty(accessToken)) { 15 | Log.i(TAG, "Got new access token"); 16 | } 17 | else { 18 | Log.i(TAG, "Could not get new access token"); 19 | } 20 | return accessToken; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /ImgurAPIv3ExampleAndroid.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /ImgurAPIv3Example/src/main/java/com/imgur/api3example/ImgurSampleApplication.java: -------------------------------------------------------------------------------- 1 | package com.imgur.api3example; 2 | 3 | import android.app.Application; 4 | import android.content.Context; 5 | import android.content.pm.PackageManager.NameNotFoundException; 6 | import android.util.Log; 7 | 8 | public class ImgurSampleApplication extends Application { 9 | 10 | private static final String TAG = ImgurSampleApplication.class.getSimpleName(); 11 | 12 | private static Context context; 13 | 14 | public void onCreate(){ 15 | super.onCreate(); 16 | ImgurSampleApplication.context = getApplicationContext(); 17 | } 18 | 19 | /** 20 | * http://stackoverflow.com/questions/2002288/static-way-to-get-context-on-android 21 | */ 22 | public static Context getAppContext() { 23 | return ImgurSampleApplication.context; 24 | } 25 | 26 | public static String getVersionName() { 27 | try { 28 | return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName; 29 | } catch (NameNotFoundException e) { 30 | Log.e(TAG, "Package name not found.", e); 31 | return "1.0"; 32 | } 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | Android Lint 15 | 16 | 17 | Internationalization issues 18 | 19 | 20 | Performance issues 21 | 22 | 23 | 24 | 25 | Abstraction issues 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /ImgurAPIv3Example/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 11 | 12 | 13 | 14 | 20 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /ImgurAPIv3Example/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ImgurAPIv3Example 5 | Hello world! 6 | Settings 7 | 8 | 9 | Imgur API v3 10 | Imgur API v3 sample (Android) %s 11 | 12 | Settings 13 | 14 | Pick image 15 | uploading… 16 | uploaded to Imgur. 17 | failed. 18 | Error uploading image to Imgur. Please try again later. 19 | 20 | Discard 21 | Discard the upload? 22 | Yes, discard 23 | Cancel 24 | 25 | Link 26 | Copied link to clipboard. 27 | 28 | Logged in. 29 | Logged out. 30 | 31 | Login 32 | Logout 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /ImgurAPIv3Example/src/main/java/com/imgur/api3example/util/BitmapUtils.java: -------------------------------------------------------------------------------- 1 | package com.imgur.api3example.util; 2 | 3 | import java.io.FileNotFoundException; 4 | import java.io.IOException; 5 | import java.io.InputStream; 6 | 7 | import android.content.Context; 8 | import android.graphics.Bitmap; 9 | import android.graphics.BitmapFactory; 10 | import android.net.Uri; 11 | import android.util.Log; 12 | 13 | import com.imgur.api3example.ImgurSampleApplication; 14 | 15 | /** 16 | * http://developer.android.com/training/displaying-bitmaps/load-bitmap.html 17 | */ 18 | public class BitmapUtils { 19 | 20 | private static final String TAG = BitmapUtils.class.getSimpleName(); 21 | 22 | public static Bitmap decodeSampledBitmapFromUri(Uri imageUri, int reqWidth, int reqHeight) { 23 | Log.d(TAG, "imageUri=" + imageUri); 24 | 25 | Context context = ImgurSampleApplication.getAppContext(); 26 | 27 | InputStream in; 28 | try { 29 | in = context.getContentResolver().openInputStream(imageUri); 30 | } catch (FileNotFoundException e) { 31 | Log.w(TAG, "file not found", e); 32 | return null; 33 | } 34 | 35 | final BitmapFactory.Options options = new BitmapFactory.Options(); 36 | options.inJustDecodeBounds = true; 37 | BitmapFactory.decodeStream(in, null, options); 38 | 39 | try { 40 | in.close(); 41 | } catch (IOException e) { 42 | Log.e(TAG, "error closing InputStream", e); 43 | } 44 | try { 45 | in = context.getContentResolver().openInputStream(imageUri); 46 | } catch (FileNotFoundException e) { 47 | Log.w(TAG, "file not found", e); 48 | return null; 49 | } 50 | 51 | options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); 52 | options.inJustDecodeBounds = false; 53 | options.inPurgeable = true; // http://stackoverflow.com/questions/7068132/why-would-i-ever-not-use-bitmapfactorys-inpurgeable-option 54 | options.inInputShareable = false; // InputStream is not reusable 55 | try { 56 | return BitmapFactory.decodeStream(in, null, options); 57 | } finally { 58 | try { 59 | in.close(); 60 | } catch (IOException ignore) {} 61 | } 62 | } 63 | 64 | private static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) { 65 | // Raw height and width of image 66 | final int height = options.outHeight; 67 | final int width = options.outWidth; 68 | int inSampleSize = 1; 69 | 70 | Log.d(TAG, "height=" + height + " width=" + width); 71 | 72 | if (height > reqHeight || width > reqWidth) { 73 | if (width > height) { 74 | inSampleSize = Math.round((float)height / (float)reqHeight); 75 | } else { 76 | inSampleSize = Math.round((float)width / (float)reqWidth); 77 | } 78 | } 79 | return inSampleSize; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /ImgurAPIv3Example/src/main/java/com/imgur/api3example/login/LoginActivity.java: -------------------------------------------------------------------------------- 1 | package com.imgur.api3example.login; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | import android.webkit.WebView; 6 | import android.webkit.WebViewClient; 7 | import android.widget.FrameLayout; 8 | import android.widget.Toast; 9 | 10 | import com.imgur.api3example.MyAppConstants; 11 | import com.imgur.api3example.R; 12 | 13 | import java.util.regex.Matcher; 14 | import java.util.regex.Pattern; 15 | 16 | public class LoginActivity extends Activity { 17 | 18 | private WebView mWebView; 19 | 20 | private static final Pattern accessTokenPattern = Pattern.compile("access_token=([^&]*)"); 21 | private static final Pattern refreshTokenPattern = Pattern.compile("refresh_token=([^&]*)"); 22 | private static final Pattern expiresInPattern = Pattern.compile("expires_in=(\\d+)"); 23 | 24 | @Override 25 | protected void onCreate(Bundle savedInstanceState) { 26 | super.onCreate(savedInstanceState); 27 | 28 | FrameLayout root = new FrameLayout(this); 29 | mWebView = new WebView(this); 30 | root.addView(mWebView); 31 | setContentView(root); 32 | 33 | setupWebView(); 34 | 35 | mWebView.loadUrl("https://api.imgur.com/oauth2/authorize?client_id=" + MyAppConstants.MY_IMGUR_CLIENT_ID + "&response_type=token"); 36 | } 37 | 38 | private void setupWebView() { 39 | mWebView.setWebViewClient(new WebViewClient() { 40 | @Override 41 | public boolean shouldOverrideUrlLoading(WebView view, String url) { 42 | // intercept the tokens 43 | // http://example.com#access_token=ACCESS_TOKEN&token_type=Bearer&expires_in=3600 44 | boolean tokensURL = false; 45 | if (url.startsWith(MyAppConstants.MY_IMGUR_REDIRECT_URL)) { 46 | tokensURL = true; 47 | Matcher m; 48 | 49 | m = refreshTokenPattern.matcher(url); 50 | m.find(); 51 | String refreshToken = m.group(1); 52 | 53 | m = accessTokenPattern.matcher(url); 54 | m.find(); 55 | String accessToken = m.group(1); 56 | 57 | m = expiresInPattern.matcher(url); 58 | m.find(); 59 | long expiresIn = Long.valueOf(m.group(1)); 60 | 61 | ImgurAuthorization.getInstance().saveRefreshToken(refreshToken, accessToken, expiresIn); 62 | 63 | runOnUiThread(new Runnable() { 64 | @Override 65 | public void run() { 66 | Toast.makeText(LoginActivity.this, R.string.logged_in, Toast.LENGTH_SHORT).show(); 67 | finish(); 68 | } 69 | }); 70 | } 71 | return tokensURL; 72 | } 73 | }); 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /ImgurAPIv3Example/src/main/java/com/imgur/api3example/ChooseImageActivity.java: -------------------------------------------------------------------------------- 1 | package com.imgur.api3example; 2 | 3 | import android.content.Intent; 4 | import android.net.Uri; 5 | import android.os.Bundle; 6 | import android.support.v7.app.ActionBarActivity; 7 | import android.view.Menu; 8 | import android.view.MenuItem; 9 | import android.view.View; 10 | import android.widget.Toast; 11 | 12 | import com.imgur.api3example.login.ImgurAuthorization; 13 | import com.imgur.api3example.login.LoginActivity; 14 | import com.imgur.api3example.login.RefreshAccessTokenTask; 15 | 16 | public class ChooseImageActivity extends ActionBarActivity { 17 | 18 | private static final int REQ_CODE_PICK_IMAGE = 1; 19 | 20 | @Override 21 | public void onCreate(Bundle savedInstanceState) { 22 | super.onCreate(savedInstanceState); 23 | setContentView(R.layout.activity_upload); 24 | } 25 | 26 | @Override 27 | public boolean onCreateOptionsMenu(Menu menu) { 28 | getMenuInflater().inflate(R.menu.activity_upload, menu); 29 | return super.onCreateOptionsMenu(menu); 30 | } 31 | 32 | @Override 33 | public boolean onPrepareOptionsMenu(Menu menu) { 34 | boolean loggedIn = ImgurAuthorization.getInstance().isLoggedIn(); 35 | menu.findItem(R.id.menu_login).setVisible(!loggedIn); 36 | menu.findItem(R.id.menu_logout).setVisible(loggedIn); 37 | 38 | return super.onPrepareOptionsMenu(menu); 39 | } 40 | 41 | @Override 42 | public boolean onOptionsItemSelected(MenuItem item) { 43 | if (item.getItemId() == R.id.menu_login) { 44 | startActivity(new Intent(getApplicationContext(), LoginActivity.class)); 45 | return true; 46 | } 47 | else if (item.getItemId() == R.id.menu_logout) { 48 | ImgurAuthorization.getInstance().logout(); 49 | Toast.makeText(this, R.string.logged_out, Toast.LENGTH_SHORT).show(); 50 | return true; 51 | } 52 | else { 53 | return super.onOptionsItemSelected(item); 54 | } 55 | } 56 | 57 | public void pickImage(View view) { 58 | Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 59 | startActivityForResult(i, REQ_CODE_PICK_IMAGE); 60 | } 61 | 62 | @Override 63 | protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) { 64 | super.onActivityResult(requestCode, resultCode, imageReturnedIntent); 65 | 66 | switch(requestCode) { 67 | case REQ_CODE_PICK_IMAGE: 68 | if(resultCode == RESULT_OK){ 69 | Uri selectedImage = imageReturnedIntent.getData(); 70 | getChooseImageFragment().setImage(selectedImage); 71 | } 72 | } 73 | } 74 | 75 | private ChooseImageFragment getChooseImageFragment() { 76 | return (ChooseImageFragment) getSupportFragmentManager().findFragmentById(R.id.choose_image_fragment); 77 | } 78 | 79 | public void copyLink(View view) { 80 | getChooseImageFragment().copyLink(view); 81 | } 82 | 83 | @Override 84 | protected void onResume() { 85 | super.onResume(); 86 | new RefreshAccessTokenTask().execute(); 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /ImgurAPIv3Example/src/main/res/layout/choose_image_fragment.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 | 18 | 19 |