-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
347 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,8 @@ public void onCreate() { | |
return; | ||
} | ||
refWatcher = LeakCanary.install(this); | ||
|
||
|
||
} | ||
|
||
@Override | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
include ':app' | ||
include ':vk' | ||
include ':instagram' | ||
//include ':twitter' | ||
include ':twitter' | ||
include ':facebook' | ||
include ':google' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.ebr163.socialauth.twitter"> | ||
|
||
<application android:allowBackup="true" android:label="@string/app_name" | ||
android:supportsRtl="true"> | ||
<uses-permission android:name="android.permission.INTERNET" /> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true"> | ||
<activity android:name=".TwitterAuthActivity" /> | ||
</application> | ||
|
||
</manifest> | ||
</manifest> |
83 changes: 83 additions & 0 deletions
83
twitter/src/main/java/com/ebr163/socialauth/twitter/TwitterAuthActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.ebr163.socialauth.twitter; | ||
|
||
import android.app.Activity; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.support.v4.app.Fragment; | ||
import android.support.v7.app.AppCompatActivity; | ||
|
||
import com.twitter.sdk.android.core.Callback; | ||
import com.twitter.sdk.android.core.Result; | ||
import com.twitter.sdk.android.core.TwitterException; | ||
import com.twitter.sdk.android.core.TwitterSession; | ||
import com.twitter.sdk.android.core.identity.TwitterAuthClient; | ||
|
||
public class TwitterAuthActivity extends AppCompatActivity { | ||
|
||
public static final String KEY_ACCESS_TOKEN = "access_token"; | ||
public static final String CODE_EXCEPTION = "code_exception"; | ||
|
||
private TwitterAuthClient twitterClient; | ||
private boolean wasShown; | ||
|
||
public static void authorize(Fragment fragment, int requestCode) { | ||
fragment.startActivityForResult( | ||
getIntent(fragment.getActivity()), | ||
requestCode | ||
); | ||
fragment.getActivity().overridePendingTransition(0, 0); | ||
} | ||
|
||
public static void authorize(Activity activity, int requestCode) { | ||
activity.startActivityForResult( | ||
getIntent(activity), | ||
requestCode | ||
); | ||
activity.overridePendingTransition(0, 0); | ||
} | ||
|
||
private static Intent getIntent(Context context) { | ||
return new Intent(context, TwitterAuthActivity.class); | ||
} | ||
|
||
@Override | ||
protected void onStart() { | ||
super.onStart(); | ||
|
||
if (!wasShown) { | ||
wasShown = true; | ||
twitterClient = new TwitterAuthClient(); | ||
twitterClient.authorize(this, | ||
new Callback<TwitterSession>() { | ||
@Override | ||
public void success(Result<TwitterSession> result) { | ||
Intent resultIntent = new Intent(); | ||
resultIntent.putExtra(KEY_ACCESS_TOKEN, result.data.getAuthToken().toString()); | ||
setResult(Activity.RESULT_OK, resultIntent); | ||
finish(); | ||
} | ||
|
||
@Override | ||
public void failure(TwitterException e) { | ||
Intent resultIntent = new Intent(); | ||
resultIntent.putExtra(CODE_EXCEPTION, e.getMessage()); | ||
setResult(RESULT_CANCELED, resultIntent); | ||
finish(); | ||
} | ||
} | ||
); | ||
} | ||
} | ||
|
||
@Override | ||
protected void onActivityResult(int requestCode, int resultCode, Intent data) { | ||
super.onActivityResult(requestCode, resultCode, data); | ||
twitterClient.onActivityResult(requestCode, resultCode, data); | ||
} | ||
|
||
@Override | ||
public void finish() { | ||
super.finish(); | ||
overridePendingTransition(0, 0); | ||
} | ||
} |
Oops, something went wrong.