├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml ├── scopes │ └── scope_settings.xml └── vcs.xml ├── README.md ├── android.iml ├── app ├── .gitignore ├── app.iml ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── oneall │ │ └── oneallsample │ │ └── ApplicationTest.java │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── oneall │ │ └── oneallsample │ │ ├── ImageDownloader.java │ │ ├── OAMainActivity.java │ │ └── PostActivity.java │ └── res │ ├── drawable │ └── button_background.xml │ ├── layout │ ├── activity_oamain.xml │ └── activity_post.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── oneallsdk ├── .gitignore ├── build.gradle ├── gradle.properties ├── libs │ └── logentries-android-2.1.4.jar ├── maven-push.gradle ├── oneallsdk.iml ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── oneall │ │ └── oneallsdk │ │ ├── FacebookWrapper.java │ │ ├── MessagePostResult.java │ │ ├── OAError.java │ │ ├── OALog.java │ │ ├── OAManager.java │ │ ├── ProviderFragment.java │ │ ├── ProviderManager.java │ │ ├── ProviderSelectActivity.java │ │ ├── Settings.java │ │ ├── TwitterWrapper.java │ │ ├── UserInputDialog.java │ │ ├── WebLoginActivity.java │ │ └── rest │ │ ├── ItemTypeAdapterFactory.java │ │ ├── ServiceCallback.java │ │ ├── ServiceManagerProvider.java │ │ ├── models │ │ ├── NativeLoginRequest.java │ │ ├── PostMessageRequest.java │ │ ├── PostMessageResponse.java │ │ ├── Provider.java │ │ ├── ResponseConnection.java │ │ ├── ResponseProvidersList.java │ │ ├── ServiceResponseBase.java │ │ └── User.java │ │ └── service │ │ ├── ConnectionService.java │ │ ├── MessagePostService.java │ │ ├── ProviderService.java │ │ └── UserService.java │ └── res │ ├── drawable │ ├── button_login_amazon.png │ ├── button_login_blogger.png │ ├── button_login_devianart.png │ ├── button_login_disqus.png │ ├── button_login_facebook.png │ ├── button_login_foursquare.png │ ├── button_login_github.png │ ├── button_login_google.png │ ├── button_login_instagram.png │ ├── button_login_linkedin.png │ ├── button_login_livejournal.png │ ├── button_login_mailru.png │ ├── button_login_msn.png │ ├── button_login_myspace.png │ ├── button_login_odnoklassniki.png │ ├── button_login_openid.png │ ├── button_login_paypal.png │ ├── button_login_reddit.png │ ├── button_login_skyrock.png │ ├── button_login_stackexchange.png │ ├── button_login_steam.png │ ├── button_login_twitch.png │ ├── button_login_twitter.png │ ├── button_login_vimeo.png │ ├── button_login_vkontakte.png │ ├── button_login_windowslive.png │ ├── button_login_wordpress.png │ ├── button_login_yahoo.png │ └── button_login_youtube.png │ ├── layout │ ├── activity_provider_select.xml │ ├── activity_web_login.xml │ ├── fragment_provider.xml │ └── user_input_dialog.xml │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── dimens.xml │ └── strings.xml ├── proguard-com.twitter.sdk.android.twitter.txt ├── screenshots └── login_providers_selector.png └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /local.properties 3 | /.idea/workspace.xml 4 | /.idea/libraries 5 | .DS_Store 6 | /build 7 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 20 | 21 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 36 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/scopes/scope_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Developing Android application with OneAll SDK 2 | 3 | OneAll SDK provides tools to use OneAll Social Login features on Android Platform. It allows logging in users and posting messages on social networks using existing OneAll connectors. The library is integrated in a few lines of code and uses native Android integration with Facebook and Twitter where possible. 4 | 5 | ## Integrating SDK 6 | 7 | ### Running Sample Application 8 | 9 | In order to run sample application, number of specific settings have to be updated in the code. Open `app/src/main/res/values/strings.xml` file and update the following values: 10 | - `oneall_subdomain`- OneAll application subdomain from your [application dashboard](https://app.oneall.com/applications/). 11 | - `facebook_app_id`- Facebook application ID used for authentication. 12 | - `fb_login_protocol_scheme`- Facebook login protol scheme. generally should be in format "fb", i.e. "fb1234567890" 13 | - `twitter_consumer_key`- Twitter application consumer key from [Twitter Application Settings](http://apps.twitter.com/). 14 | - `twitter_consumer_secret`- Twitter application consumer secrect from [Twitter Application Settings](http://apps.twitter.com/). 15 | 16 | Twitter consumer key and twitter consumer secret are optional and may be omitted if you don't want to use native Android Twitter authentication. 17 | 18 | 19 | ### Including Libraries 20 | 21 | SDK added to the project with a few lines of code using Gradle. 22 | 23 | After opening the project, edit `build.gradle` file. Add this to Module-level `/app/build.gradle` before `dependencies`: 24 | ```groovy 25 | repositories { 26 | mavenCentral() 27 | maven { 'https://maven.fabric.io/public' } 28 | } 29 | ``` 30 | Add the compile dependency with the latest version of the OneAll SDK in the `build.gradle` file: 31 | ```groovy 32 | dependencies { 33 | compile 'com.oneall:oneall-sdk:1.0' 34 | } 35 | ``` 36 | Sync Gradle and build your project. Now you will be able to use `com.oneall.OAManager` in your code: 37 | 38 | ```java 39 | OAManager 40 | .getInstance() 41 | .setup(this, "demo", TWITTER_KEY_OR_NULL, TWITTER_SECRET_OR_NULL); 42 | ``` 43 | Of course, replace "demo" with the subdomain of your OneAll application. 44 | 45 | ### Setting Up Facebook Integration 46 | 47 | This part is required in order for Facebook login to work correct. The instructions here are similar to [Facebook Android Getting Started Guide](https://developers.facebook.com/docs/android/getting-started) . 48 | 49 | Add your Facebook App ID to your project's strings file and update your Android manifest: 50 | 51 | 1. Open `res/values/strings.xml` 52 | 2. Add a new string with the name `facebook_app_id` and value as your Facebook App ID 53 | 3. Open `AndroidManifest.xml` 54 | 4. Add a uses-permission element to the manifest: `` 55 | 5. Add a meta-data element to the application element: 56 | 57 | ```xml 58 | 59 | ... 60 | 61 | ... 62 | 63 | ``` 64 | 65 | Next, setup your Facebook application by creating and setting up development hash as described in **"Create a Development Key Hash**" and **"Setting a Release Key Hash**" sections of [Getting Started Guide](https://developers.facebook.com/docs/android/getting-started) 66 | 67 | ### Code Integration 68 | 69 | Open the activity class that will use OneAll integration. Add the following into `onCreate` 70 | ```java 71 | import com.oneall.oneallsdk.OAManager; 72 | import com.oneall.oneallsdk.rest.models.User; 73 | import com.oneall.oneallsdk.OAError; 74 | @Override 75 | protected void onCreate(Bundle savedInstanceState) { 76 | super.onCreate(savedInstanceState); 77 | // Your initialization code 78 | OAManager 79 | .getInstance() 80 | .setup(this, "demo", TWITTER_KEY_OR_NULL, TWITTER_SECRET_OR_NULL); 81 | OAManager.getInstance().onCreate(this, savedInstanceState); 82 | } 83 | ``` 84 | This will initialize OneAll module and set it up with your subdomain settings. 85 | 86 | Now, pass all activity creation events to the manager: 87 | ```java 88 | @Override 89 | protected void onResume() { 90 | super.onResume(); 91 | OAManager.getInstance().onResume(); 92 | } 93 | @Override 94 | protected void onPostResume() { 95 | super.onPostResume(); 96 | OAManager.getInstance().onPostResume(this); 97 | } 98 | @Override 99 | protected void onPause() { 100 | super.onPause(); 101 | OAManager.getInstance().onPause(); 102 | } 103 | @Override 104 | protected void onDestroy() { 105 | super.onDestroy(); 106 | OAManager.getInstance().onDestroy(); 107 | } 108 | @Override 109 | protected void onSaveInstanceState(Bundle outState) { 110 | super.onSaveInstanceState(outState); 111 | OAManager.getInstance().onSaveInstanceState(outState); 112 | } 113 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 114 | super.onActivityResult(requestCode, resultCode, data); 115 | OAManager.getInstance().onActivityResult(requestCode, resultCode, data); 116 | } 117 | ``` 118 | Next, use the manager to login into OneAll: 119 | ```java 120 | OAManager.getInstance().login(this, new OAManager.LoginHandler() { 121 | @Override 122 | public void loginSuccess(User user, Boolean newUser) { 123 | Log.v("tag", String.format("OA user %s", user.identity.name.formatted)); 124 | } 125 | @Override 126 | public void loginFailure(OAError error) { 127 | Log.v("tag", String.format("Failed to login into OA: %s", error.getMessage())); 128 | } 129 | }); 130 | ``` 131 | The SDK will show selector of platforms configured for specified OneAll subdomain: 132 | 133 | ![](https://raw.githubusercontent.com/oneall/android-sdk/master/screenshots/login_providers_selector.png) 134 | 135 | You can use your own native design and login without activating the selector: 136 | 137 | OAManager.getInstance().login(this, "facebook", loginHandler); 138 | 139 | ### Posting Messages onto Wall 140 | 141 | In order to post message `OAManager` provides `postMessage` method: 142 | ```java 143 | public void postMessage( 144 | String text, 145 | String pictureUrl, 146 | String videoUrl, 147 | String linkUrl, 148 | String linkName, 149 | String linkCaption, 150 | String linkDescription, 151 | Boolean enableTracking, 152 | String userToken, 153 | String publishToken, 154 | final Collection providers, 155 | final OAManagerPostHandler handler) 156 | ``` 157 | Example usage: 158 | ```java 159 | OAManager.getInstance().postMessage( 160 | "Me and the elephant", 161 | "[](https://drscdn.500px.org/photo/57410272/m%3D2048/9e1b37755cc09022b7eb0993379cc6f6)https://drscdn.500px.org/photo/57410272/m%3D2048/9e1b37755cc09022b7eb0993379cc6f6", 162 | null, 163 | null, 164 | null, 165 | null, 166 | null, 167 | true, 168 | user.userToken, 169 | user.publishToken.key, 170 | new string[] { "facebook" }, 171 | new OAManager.OAManagerPostHandler() { 172 | @Override 173 | public void postComplete(Boolean success, PostMessageResponse response) { 174 | if (success) { 175 | Log.v("posted message to user wall"); 176 | } else { 177 | Log.v("failed to post message to user wall"); 178 | } 179 | } 180 | } 181 | ); 182 | ``` 183 | Where `user` object is the same user object that was received via callback on user authentication earlier in the process. This object implements `Serializable` interface and can be serialized and cached between session to avoid repeated logins on every application run. 184 | -------------------------------------------------------------------------------- /android.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/app.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | maven { url 'https://maven.fabric.io/public' } 4 | } 5 | 6 | dependencies { 7 | classpath 'io.fabric.tools:gradle:1.21.7' 8 | } 9 | } 10 | apply plugin: 'com.android.application' 11 | apply plugin: 'io.fabric' 12 | 13 | android { 14 | compileSdkVersion 26 15 | buildToolsVersion "25.0.3" 16 | defaultConfig { 17 | applicationId "com.oneall.oneallsample" 18 | minSdkVersion 15 19 | targetSdkVersion 26 20 | versionName '1.1' 21 | versionCode 1 22 | } 23 | buildTypes { 24 | release { 25 | minifyEnabled false 26 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 27 | } 28 | } 29 | productFlavors { 30 | } 31 | } 32 | 33 | repositories { 34 | mavenCentral() 35 | maven { url 'https://maven.fabric.io/public' } 36 | } 37 | 38 | dependencies { 39 | compile fileTree(dir: 'libs', include: ['*.jar']) 40 | compile 'com.android.support:appcompat-v7:25.3.1' 41 | compile project(':oneallsdk') 42 | } 43 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/urk/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/oneall/oneallsample/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.oneall.oneallsample; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 12 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 29 | 30 | 31 | 34 | 35 | 38 | 39 | 41 | 42 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /app/src/main/java/com/oneall/oneallsample/ImageDownloader.java: -------------------------------------------------------------------------------- 1 | package com.oneall.oneallsample; 2 | 3 | import android.graphics.Bitmap; 4 | import android.graphics.BitmapFactory; 5 | import android.os.AsyncTask; 6 | import android.util.Log; 7 | import android.widget.ImageView; 8 | 9 | import java.io.InputStream; 10 | import java.net.HttpURLConnection; 11 | import java.net.URL; 12 | 13 | /** 14 | * Download image in background and put downloaded image into ImageView 15 | */ 16 | class ImageDownloader extends AsyncTask { 17 | 18 | private final static String TAG = ImageDownloader.class.toString(); 19 | 20 | private ImageView bmImage; 21 | 22 | ImageDownloader(ImageView bmImage) { 23 | this.bmImage = bmImage; 24 | } 25 | 26 | protected Bitmap doInBackground(String... urls) { 27 | String urldisplay = urls[0]; 28 | Bitmap mIcon11 = null; 29 | 30 | Log.i(TAG, String.format("Downloading image from %s", urldisplay)); 31 | 32 | HttpURLConnection conn = null; 33 | try { 34 | URL url = new URL(urldisplay); 35 | conn = (HttpURLConnection) url.openConnection(); 36 | if (conn.getResponseCode() == 200) { 37 | InputStream is = conn.getInputStream(); 38 | mIcon11 = BitmapFactory.decodeStream(is); 39 | 40 | Log.i(TAG, String.format("Image downloaded from %s", urldisplay)); 41 | } else { 42 | Log.i(TAG, String.format("Failed to download image from %s with status code %d", 43 | urldisplay, conn.getResponseCode())); 44 | } 45 | 46 | Log.i(TAG, String.format("Image downloaded from %s", urldisplay)); 47 | } catch (Exception e) { 48 | Log.e(TAG, e.getMessage()); 49 | } finally { 50 | if (conn != null) { 51 | conn.disconnect(); 52 | } 53 | } 54 | return mIcon11; 55 | } 56 | 57 | protected void onPostExecute(Bitmap result) { 58 | bmImage.setImageBitmap(result); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /app/src/main/java/com/oneall/oneallsample/OAMainActivity.java: -------------------------------------------------------------------------------- 1 | package com.oneall.oneallsample; 2 | 3 | import com.oneall.oneallsdk.OAError; 4 | import com.oneall.oneallsdk.OAManager; 5 | import com.oneall.oneallsdk.rest.models.User; 6 | 7 | import android.content.Intent; 8 | import android.os.Bundle; 9 | import android.support.v7.app.ActionBarActivity; 10 | import android.util.Log; 11 | import android.view.View; 12 | import android.widget.Button; 13 | import android.widget.ImageView; 14 | import android.widget.TextView; 15 | 16 | public class OAMainActivity extends ActionBarActivity { 17 | 18 | // Note: Your consumer key and secret should be obfuscated in your source code before shipping. 19 | private String mTwitterKey; 20 | private String mTwitterSecret; 21 | private String mSubdomain; 22 | 23 | // region Properties 24 | 25 | private User user; 26 | private Button buttonPost; 27 | private ImageView imageUserAvatar; 28 | private TextView textUserName; 29 | 30 | // endregion 31 | 32 | private OAManager.LoginHandler loginHandler = new OAManager.LoginHandler() { 33 | @Override 34 | public void loginSuccess(User user, Boolean newUser) { 35 | Log.v(OAMainActivity.class.toString(), "successfully logged into OA"); 36 | textUserName.setText(user.identity.name.formatted); 37 | new ImageDownloader(imageUserAvatar).execute(user.identity.pictureUrl); 38 | OAMainActivity.this.user = user; 39 | 40 | buttonPost.setEnabled(true); 41 | } 42 | 43 | @Override 44 | public void loginFailure(OAError error) { 45 | Log.v(OAMainActivity.class.toString(), "Failed to login into OA"); 46 | buttonPost.setEnabled(false); 47 | textUserName.setText(null); 48 | imageUserAvatar.setImageDrawable(null); 49 | } 50 | }; 51 | 52 | @Override 53 | protected void onResume() { 54 | super.onResume(); 55 | OAManager.getInstance().onResume(); 56 | } 57 | 58 | @Override 59 | protected void onPause() { 60 | super.onPause(); 61 | OAManager.getInstance().onPause(); 62 | } 63 | 64 | @Override 65 | protected void onDestroy() { 66 | super.onDestroy(); 67 | OAManager.getInstance().onDestroy(); 68 | OAManager.destroyInstance(); 69 | } 70 | 71 | @Override 72 | protected void onSaveInstanceState(Bundle outState) { 73 | super.onSaveInstanceState(outState); 74 | OAManager.getInstance().onSaveInstanceState(outState); 75 | } 76 | 77 | @Override 78 | protected void onCreate(Bundle savedInstanceState) { 79 | super.onCreate(savedInstanceState); 80 | 81 | setContentView(R.layout.activity_oamain); 82 | 83 | mTwitterKey = getString(R.string.twitter_consumer_key); 84 | mTwitterSecret = getString(R.string.twitter_consumer_secret); 85 | mSubdomain = getString(R.string.oneall_subdomain); 86 | 87 | OAManager.getInstance().setup(this, mSubdomain, mTwitterKey, mTwitterSecret); 88 | OAManager.getInstance().onCreate(this, savedInstanceState); 89 | 90 | imageUserAvatar = (ImageView) findViewById(R.id.main_activity_user_avatar); 91 | textUserName = (TextView) findViewById(R.id.main_activity_user_name); 92 | 93 | findViewById(R.id.button_login).setOnClickListener(new View.OnClickListener() { 94 | @Override 95 | public void onClick(View v) { 96 | OAManager.getInstance().login(OAMainActivity.this, loginHandler); 97 | } 98 | }); 99 | 100 | findViewById(R.id.button_main_login_facebook).setOnClickListener(new View.OnClickListener() { 101 | @Override 102 | public void onClick(View v) { 103 | OAManager.getInstance().login(OAMainActivity.this, "facebook", loginHandler); 104 | } 105 | }); 106 | 107 | findViewById(R.id.button_main_login_foursquare).setOnClickListener(new View.OnClickListener() { 108 | @Override 109 | public void onClick(View v) { 110 | OAManager.getInstance().login(OAMainActivity.this, "foursquare", loginHandler); 111 | } 112 | }); 113 | 114 | buttonPost = (Button) findViewById(R.id.button_post); 115 | buttonPost.setOnClickListener(new View.OnClickListener() { 116 | @Override 117 | public void onClick(View v) { 118 | handlerButtonPost(); 119 | } 120 | }); 121 | } 122 | 123 | @Override 124 | protected void onPostResume() { 125 | super.onPostResume(); 126 | OAManager.getInstance().onPostResume(this); 127 | } 128 | 129 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 130 | super.onActivityResult(requestCode, resultCode, data); 131 | OAManager.getInstance().onActivityResult(requestCode, resultCode, data); 132 | } 133 | 134 | private void handlerButtonPost() { 135 | Intent intent = new Intent(this, PostActivity.class); 136 | intent.putExtra(PostActivity.INTENT_EXTRA_USER, user); 137 | startActivity(intent); 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /app/src/main/java/com/oneall/oneallsample/PostActivity.java: -------------------------------------------------------------------------------- 1 | package com.oneall.oneallsample; 2 | 3 | import android.app.AlertDialog; 4 | import android.app.Dialog; 5 | import android.content.DialogInterface; 6 | import android.support.v7.app.ActionBarActivity; 7 | import android.os.Bundle; 8 | import android.util.Log; 9 | import android.view.Menu; 10 | import android.view.MenuItem; 11 | import android.view.View; 12 | import android.widget.EditText; 13 | 14 | import com.oneall.oneallsdk.OAError; 15 | import com.oneall.oneallsdk.OAManager; 16 | import com.oneall.oneallsdk.rest.models.PostMessageResponse; 17 | import com.oneall.oneallsdk.rest.models.User; 18 | 19 | import java.util.ArrayList; 20 | import java.util.Arrays; 21 | import java.util.Collection; 22 | 23 | 24 | public class PostActivity extends ActionBarActivity { 25 | 26 | // region Constants 27 | 28 | public final static String INTENT_EXTRA_USER = "user"; 29 | 30 | private final static String TAG = PostActivity.class.toString(); 31 | 32 | // endregion 33 | 34 | @Override 35 | protected void onCreate(Bundle savedInstanceState) { 36 | super.onCreate(savedInstanceState); 37 | setContentView(R.layout.activity_post); 38 | 39 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 40 | 41 | if (getIntent().getExtras().get(INTENT_EXTRA_USER) == null) { 42 | finish(); 43 | } 44 | 45 | findViewById(R.id.post_activity_button_post).setOnClickListener(new View.OnClickListener() { 46 | @Override 47 | public void onClick(View v) { 48 | handlerButtonPost(); 49 | } 50 | }); 51 | } 52 | 53 | @Override 54 | public boolean onOptionsItemSelected(MenuItem item) { 55 | if (item.getItemId() == android.R.id.home) { 56 | finish(); 57 | return true; 58 | } 59 | return super.onOptionsItemSelected(item); 60 | } 61 | 62 | private void handlerButtonPost() { 63 | User user = (User) getIntent().getExtras().get(INTENT_EXTRA_USER); 64 | 65 | OAManager.getInstance().postMessage( 66 | ((EditText) findViewById(R.id.post_activity_text_text)).getText().toString(), 67 | ((EditText) findViewById(R.id.post_activity_text_picture)).getText().toString(), 68 | ((EditText) findViewById(R.id.post_activity_text_video)).getText().toString(), 69 | ((EditText) findViewById(R.id.post_activity_text_link)).getText().toString(), 70 | ((EditText) findViewById(R.id.post_activity_text_link_name)).getText().toString(), 71 | ((EditText) findViewById(R.id.post_activity_text_link_caption)).getText().toString(), 72 | ((EditText) findViewById(R.id.post_activity_text_link_description)).getText().toString(), 73 | true, 74 | user.userToken, 75 | user.publishToken.key, 76 | getProvidersForUser(user), 77 | new OAManager.OAManagerPostHandler() { 78 | @Override 79 | public void postComplete(Boolean success, PostMessageResponse response) { 80 | postResponseComplete(success, response); 81 | } 82 | } 83 | ); 84 | } 85 | 86 | private Collection getProvidersForUser(User user) { 87 | ArrayList rv = new ArrayList<>(); 88 | rv.add(user.identity.provider); 89 | return rv; 90 | } 91 | 92 | private void postResponseComplete(Boolean success, PostMessageResponse response) { 93 | ArrayList failures = new ArrayList<>(); 94 | for (PostMessageResponse.Data.Message.Publication pub : response.data.message.publications) { 95 | if (pub.status == null || 96 | pub.status.flag == null || 97 | !pub.status.flag.equals("success")) { 98 | failures.add(pub.provider); 99 | } 100 | } 101 | 102 | DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() { 103 | @Override 104 | public void onClick(DialogInterface dialog, int which) { 105 | finish(); 106 | } 107 | }; 108 | 109 | if (failures.size() > 0) { 110 | new AlertDialog.Builder(this) 111 | .setTitle("Oops") 112 | .setMessage("Failed providers list: " + failures) 113 | .setPositiveButton("OK", listener) 114 | .show(); 115 | 116 | } else { 117 | new AlertDialog.Builder(this) 118 | .setTitle("Posted") 119 | .setMessage("Message has been posted") 120 | .setPositiveButton("OK", listener) 121 | .show(); 122 | } 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/button_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_oamain.xml: -------------------------------------------------------------------------------- 1 | 9 | 10 | 22 | 27 | 30 |