Skip to content
This repository was archived by the owner on Feb 14, 2020. It is now read-only.

Commit 69022d8

Browse files
authored
Merge pull request #39 from Jawnnypoo/master
Improve styling
2 parents d65e6c0 + 1ba7e4f commit 69022d8

15 files changed

+1124
-2436
lines changed

library/src/main/java/com/parse/twitter/AsyncCallback.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
package com.parse.twitter;
1010

1111
public interface AsyncCallback {
12-
void onSuccess(Object result);
12+
void onSuccess(Object result);
1313

14-
void onCancel();
14+
void onCancel();
1515

16-
void onFailure(Throwable error);
16+
void onFailure(Throwable error);
1717
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/*
2+
* Copyright (c) 2015-present, Parse, LLC.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
package com.parse.twitter;
10+
11+
import android.annotation.SuppressLint;
12+
import android.content.Context;
13+
import android.content.DialogInterface;
14+
import android.content.Intent;
15+
import android.graphics.Bitmap;
16+
import android.net.Uri;
17+
import android.os.Bundle;
18+
import android.support.v7.app.AppCompatDialog;
19+
import android.view.View;
20+
import android.view.Window;
21+
import android.webkit.WebView;
22+
import android.webkit.WebViewClient;
23+
import android.widget.ProgressBar;
24+
25+
/**
26+
* For internal use.
27+
*/
28+
class OAuth1FlowDialog extends AppCompatDialog {
29+
30+
private final String callbackUrl;
31+
private final String requestUrl;
32+
private final String serviceUrlIdentifier;
33+
private final FlowResultHandler handler;
34+
35+
private WebView webView;
36+
private ProgressBar progress;
37+
38+
OAuth1FlowDialog(Context context, String requestUrl, String callbackUrl, String serviceUrlIdentifier, FlowResultHandler resultHandler) {
39+
super(context);
40+
this.requestUrl = requestUrl;
41+
this.callbackUrl = callbackUrl;
42+
this.serviceUrlIdentifier = serviceUrlIdentifier;
43+
this.handler = resultHandler;
44+
this.setOnCancelListener(new OnCancelListener() {
45+
@Override
46+
public void onCancel(DialogInterface dialog) {
47+
handler.onCancel();
48+
}
49+
});
50+
}
51+
52+
@SuppressLint("SetJavaScriptEnabled")
53+
@Override
54+
protected void onCreate(Bundle savedInstanceState) {
55+
super.onCreate(savedInstanceState);
56+
requestWindowFeature(Window.FEATURE_NO_TITLE);
57+
setContentView(R.layout.parse_twitter_dialog_login);
58+
webView = findViewById(R.id.webView);
59+
progress = findViewById(R.id.progress);
60+
61+
webView.setVerticalScrollBarEnabled(false);
62+
webView.setHorizontalScrollBarEnabled(false);
63+
webView.setWebViewClient(new OAuth1WebViewClient());
64+
webView.getSettings().setJavaScriptEnabled(true);
65+
webView.loadUrl(requestUrl);
66+
}
67+
68+
public interface FlowResultHandler {
69+
/**
70+
* Called when the user cancels the dialog.
71+
*/
72+
void onCancel();
73+
74+
/**
75+
* Called when the dialog's web view receives an error.
76+
*/
77+
void onError(int errorCode, String description, String failingUrl);
78+
79+
/**
80+
* Called when the dialog portion of the flow is complete.
81+
*
82+
* @param callbackUrl The final URL called back (including any query string appended
83+
* by the server).
84+
*/
85+
void onComplete(String callbackUrl);
86+
}
87+
88+
private class OAuth1WebViewClient extends WebViewClient {
89+
@Override
90+
public boolean shouldOverrideUrlLoading(WebView view, String url) {
91+
if (url.startsWith(callbackUrl)) {
92+
OAuth1FlowDialog.this.dismiss();
93+
handler.onComplete(url);
94+
return true;
95+
} else if (url.contains(serviceUrlIdentifier)) {
96+
return false;
97+
}
98+
// launch non-service URLs in a full browser
99+
getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
100+
return true;
101+
}
102+
103+
@Override
104+
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
105+
super.onReceivedError(view, errorCode, description, failingUrl);
106+
OAuth1FlowDialog.this.dismiss();
107+
handler.onError(errorCode, description, failingUrl);
108+
}
109+
110+
@Override
111+
public void onPageStarted(WebView view, String url, Bitmap favicon) {
112+
super.onPageStarted(view, url, favicon);
113+
progress.setVisibility(View.VISIBLE);
114+
}
115+
116+
@Override
117+
public void onPageFinished(WebView view, String url) {
118+
super.onPageFinished(view, url);
119+
progress.setVisibility(View.GONE);
120+
}
121+
}
122+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) 2015-present, Parse, LLC.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
package com.parse.twitter;
10+
11+
/**
12+
* OAuth Flow exception
13+
*/
14+
public class OAuth1FlowException extends Exception {
15+
private static final long serialVersionUID = 4272662026279290823L;
16+
private final int errorCode;
17+
private final String description;
18+
private final String failingUrl;
19+
20+
public OAuth1FlowException(int errorCode, String description, String failingUrl) {
21+
super(String.format("OAuth Flow Error %d: Url: %s Description: %s", errorCode, failingUrl,
22+
description));
23+
this.errorCode = errorCode;
24+
this.description = description;
25+
this.failingUrl = failingUrl;
26+
}
27+
28+
public int getErrorCode() {
29+
return errorCode;
30+
}
31+
32+
public String getDescription() {
33+
return description;
34+
}
35+
36+
public String getFailingUrl() {
37+
return failingUrl;
38+
}
39+
}

0 commit comments

Comments
 (0)