11
11
import android .annotation .SuppressLint ;
12
12
import android .widget .LinearLayout ;
13
13
import android .view .Gravity ;
14
+ import android .os .Build ;
14
15
15
16
import android .app .DialogFragment ;
16
17
import android .content .DialogInterface ;
25
26
import android .view .ViewGroup .LayoutParams ;
26
27
import android .content .Context ;
27
28
import android .util .DisplayMetrics ;
29
+ import android .view .Display ;
30
+ import java .lang .reflect .Method ;
31
+ import android .view .WindowManager ;
28
32
29
33
import com .github .scribejava .core .model .OAuth1AccessToken ;
30
34
import com .github .scribejava .core .model .OAuth1RequestToken ;
33
37
import android .os .Bundle ;
34
38
import android .app .Fragment ;
35
39
import java .io .IOException ;
40
+ import com .facebook .react .bridge .ReactContext ;
36
41
37
42
public class OAuthManagerDialogFragment extends DialogFragment implements AdvancedWebView .Listener {
38
43
@@ -42,52 +47,72 @@ public class OAuthManagerDialogFragment extends DialogFragment implements Advanc
42
47
private static final String TAG = "OAuthManagerDialogFragment" ;
43
48
private OAuthManagerFragmentController mController ;
44
49
50
+ private ReactContext mReactContext ;
45
51
private AdvancedWebView mWebView ;
46
52
47
53
public static final OAuthManagerDialogFragment newInstance (
54
+ final ReactContext reactContext ,
48
55
OAuthManagerFragmentController controller
49
56
) {
50
57
Bundle args = new Bundle ();
51
58
OAuthManagerDialogFragment frag =
52
- new OAuthManagerDialogFragment (controller );
59
+ new OAuthManagerDialogFragment (reactContext , controller );
53
60
54
61
return frag ;
55
62
}
56
63
57
64
public OAuthManagerDialogFragment (
65
+ final ReactContext reactContext ,
58
66
OAuthManagerFragmentController controller
59
67
) {
60
68
this .mController = controller ;
69
+ this .mReactContext = reactContext ;
61
70
}
62
71
63
72
@ Override
64
73
public View onCreateView (LayoutInflater inflater , ViewGroup container , Bundle savedInstanceState ) {
65
74
// View rootView = inflater.inflate(R.id.primary, container, false);
66
- final Context context = inflater .getContext ();
75
+ // final Context context = inflater.getContext();
67
76
// DisplayMetrics metrics = context.getResources().getDisplayMetrics();
68
- // final int DIALOG_HEIGHT = (int) Math.min(0.8f * metrics.heightPixels, 1024);
77
+ // final int DIALOG_HEIGHT = (int) Math.min(0.99f * metrics.heightPixels, 1024);
78
+
79
+ // LayoutParams rootViewLayoutParams = new LayoutParams(
80
+ // LayoutParams.FILL_PARENT,
81
+ // LayoutParams.FILL_PARENT
82
+ // );
83
+ final Context context = mReactContext ;
84
+ LayoutParams rootViewLayoutParams = this .getFullscreenLayoutParams (context );
69
85
70
86
FrameLayout rootView = new FrameLayout (context );
71
87
getDialog ().setCanceledOnTouchOutside (true );
72
- rootView .setLayoutParams (new LayoutParams ( LayoutParams . FILL_PARENT , LayoutParams . FILL_PARENT ) );
88
+ rootView .setLayoutParams (rootViewLayoutParams );
73
89
74
90
// mWebView = (AdvancedWebView) rootView.findViewById(R.id.webview);
75
91
Log .d (TAG , "Creating webview" );
76
92
mWebView = new AdvancedWebView (context );
77
93
mWebView .setId (WEBVIEW_TAG );
78
94
mWebView .setListener (this , this );
79
95
mWebView .setVisibility (View .VISIBLE );
96
+ mWebView .getSettings ().setJavaScriptEnabled (true );
97
+ mWebView .getSettings ().setDomStorageEnabled (true );
98
+
99
+ LayoutParams layoutParams = this .getFullscreenLayoutParams (context );
100
+ //new LayoutParams(
101
+ // LayoutParams.FILL_PARENT,
102
+ // DIALOG_HEIGHT
103
+ // );
104
+ // mWebView.setLayoutParams(layoutParams);
80
105
81
- rootView .addView (mWebView , new LayoutParams ( LayoutParams . FILL_PARENT , LayoutParams . FILL_PARENT ) );
106
+ rootView .addView (mWebView , layoutParams );
82
107
83
- LinearLayout pframe = new LinearLayout (context );
84
- pframe .setId (WIDGET_TAG );
85
- pframe .setOrientation (LinearLayout .VERTICAL );
86
- pframe .setVisibility (View .GONE );
87
- pframe .setGravity (Gravity .CENTER );
108
+ // LinearLayout pframe = new LinearLayout(context);
109
+ // pframe.setId(WIDGET_TAG);
110
+ // pframe.setOrientation(LinearLayout.VERTICAL);
111
+ // pframe.setVisibility(View.GONE);
112
+ // pframe.setGravity(Gravity.CENTER);
113
+ // pframe.setLayoutParams(layoutParams);
88
114
89
- rootView .addView (pframe ,
90
- new LayoutParams (LayoutParams .FILL_PARENT , LayoutParams .FILL_PARENT ));
115
+ // rootView.addView(pframe, layoutParams);
91
116
92
117
this .setupWebView (mWebView );
93
118
mController .getRequestTokenUrlAndLoad (mWebView );
@@ -96,12 +121,49 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
96
121
return rootView ;
97
122
}
98
123
124
+ private LayoutParams getFullscreenLayoutParams (Context context ) {
125
+ WindowManager wm = (WindowManager ) context .getSystemService (Context .WINDOW_SERVICE );
126
+ // DisplayMetrics metrics = context.getResources().getDisplayMetrics();
127
+ Display display = wm .getDefaultDisplay ();
128
+ int realWidth ;
129
+ int realHeight ;
130
+
131
+ if (Build .VERSION .SDK_INT >= 17 ){
132
+ //new pleasant way to get real metrics
133
+ DisplayMetrics realMetrics = new DisplayMetrics ();
134
+ display .getRealMetrics (realMetrics );
135
+ realWidth = realMetrics .widthPixels ;
136
+ realHeight = realMetrics .heightPixels ;
137
+
138
+ } else if (Build .VERSION .SDK_INT >= 14 ) {
139
+ //reflection for this weird in-between time
140
+ try {
141
+ Method mGetRawH = Display .class .getMethod ("getRawHeight" );
142
+ Method mGetRawW = Display .class .getMethod ("getRawWidth" );
143
+ realWidth = (Integer ) mGetRawW .invoke (display );
144
+ realHeight = (Integer ) mGetRawH .invoke (display );
145
+ } catch (Exception e ) {
146
+ //this may not be 100% accurate, but it's all we've got
147
+ realWidth = display .getWidth ();
148
+ realHeight = display .getHeight ();
149
+ Log .e ("Display Info" , "Couldn't use reflection to get the real display metrics." );
150
+ }
151
+
152
+ } else {
153
+ //This should be close, as lower API devices should not have window navigation bars
154
+ realWidth = display .getWidth ();
155
+ realHeight = display .getHeight ();
156
+ }
157
+
158
+ return new LayoutParams (realWidth , realHeight );
159
+ }
160
+
161
+
99
162
private void setupWebView (AdvancedWebView webView ) {
100
163
webView .setWebViewClient (new WebViewClient () {
101
164
@ Override
102
165
public boolean shouldOverrideUrlLoading (WebView view , String url ) {
103
- interceptUrl (view , url , true );
104
- return true ;
166
+ return interceptUrl (view , url , true );
105
167
}
106
168
107
169
@ Override
@@ -112,6 +174,7 @@ public void onReceivedError(WebView view, int code, String desc, String failingU
112
174
}
113
175
114
176
private boolean interceptUrl (WebView view , String url , boolean loadUrl ) {
177
+ Log .i (TAG , "interceptUrl called with url: " + url );
115
178
if (isCallbackUri (url , mController .getCallbackUrl ())) {
116
179
mController .getAccessToken (mWebView , url );
117
180
@@ -192,6 +255,7 @@ public void onPageStarted(String url, Bitmap favicon) {
192
255
@ Override
193
256
public void onPageFinished (String url ) {
194
257
Log .d (TAG , "onPageFinished: " + url );
258
+ // mController.onComplete(url);
195
259
}
196
260
197
261
@ Override
0 commit comments