This repository has been archived by the owner on Jul 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 142
/
LoginActivity.java
129 lines (114 loc) · 4.92 KB
/
LoginActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
/**
* Copyright (C) 2017 Google Inc and other contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.fabric.samples.cannonball.activity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import com.crashlytics.android.Crashlytics;
import com.crashlytics.android.answers.Answers;
import com.crashlytics.android.answers.CustomEvent;
import com.crashlytics.android.answers.LoginEvent;
import com.digits.sdk.android.AuthCallback;
import com.digits.sdk.android.DigitsAuthButton;
import com.digits.sdk.android.DigitsException;
import com.digits.sdk.android.DigitsSession;
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.TwitterLoginButton;
import io.fabric.samples.cannonball.R;
import io.fabric.samples.cannonball.SessionRecorder;
public class LoginActivity extends Activity {
private TwitterLoginButton twitterButton;
private DigitsAuthButton phoneButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
setUpViews();
}
private void setUpViews() {
setUpSkip();
setUpTwitterButton();
setUpDigitsButton();
}
private void setUpTwitterButton() {
twitterButton = (TwitterLoginButton) findViewById(R.id.twitter_button);
twitterButton.setCallback(new Callback<TwitterSession>() {
@Override
public void success(Result<TwitterSession> result) {
SessionRecorder.recordSessionActive("Login: twitter account active", result.data);
Answers.getInstance().logLogin(new LoginEvent().putMethod("Twitter").putSuccess(true));
startThemeChooser();
}
@Override
public void failure(TwitterException exception) {
Answers.getInstance().logLogin(new LoginEvent().putMethod("Twitter").putSuccess(false));
Toast.makeText(getApplicationContext(),
getResources().getString(R.string.toast_twitter_signin_fail),
Toast.LENGTH_SHORT).show();
Crashlytics.logException(exception);
}
});
}
private void setUpDigitsButton() {
phoneButton = (DigitsAuthButton) findViewById(R.id.phone_button);
phoneButton.setAuthTheme(R.style.AppTheme);
phoneButton.setCallback(new AuthCallback() {
@Override
public void success(DigitsSession digitsSession, String phoneNumber) {
SessionRecorder.recordSessionActive("Login: digits account active", digitsSession);
Answers.getInstance().logLogin(new LoginEvent().putMethod("Digits").putSuccess(true));
startThemeChooser();
}
@Override
public void failure(DigitsException e) {
Answers.getInstance().logLogin(new LoginEvent().putMethod("Digits").putSuccess(false));
Toast.makeText(getApplicationContext(),
getResources().getString(R.string.toast_twitter_digits_fail),
Toast.LENGTH_SHORT).show();
Crashlytics.logException(e);
}
});
}
private void setUpSkip() {
TextView skipButton;
skipButton = (TextView) findViewById(R.id.skip);
skipButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Crashlytics.log("Login: skipped login");
Answers.getInstance().logCustom(new CustomEvent("skipped login"));
startThemeChooser();
overridePendingTransition(R.anim.slide_down, R.anim.slide_up);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
twitterButton.onActivityResult(requestCode, resultCode, data);
}
private void startThemeChooser() {
final Intent themeChooserIntent = new Intent(LoginActivity.this,
ThemeChooserActivity.class);
startActivity(themeChooserIntent);
}
}