1
1
package io .fullstack .oauth ;
2
2
3
3
import android .annotation .SuppressLint ;
4
+ import android .app .Dialog ;
4
5
import android .app .DialogFragment ;
5
6
import android .content .Context ;
6
7
import android .content .Intent ;
8
+ import android .content .res .Resources ;
7
9
import android .graphics .Bitmap ;
10
+ import android .graphics .Color ;
11
+ import android .graphics .drawable .ColorDrawable ;
8
12
import android .net .Uri ;
9
13
import android .os .Build ;
10
14
import android .os .Bundle ;
16
20
import android .view .View ;
17
21
import android .view .ViewGroup ;
18
22
import android .view .ViewGroup .LayoutParams ;
23
+ import android .view .Window ;
19
24
import android .view .WindowManager ;
20
25
import android .webkit .WebView ;
21
26
import android .webkit .WebViewClient ;
22
- import android .widget .FrameLayout ;
27
+ import android .widget .ProgressBar ;
28
+ import android .widget .RelativeLayout ;
23
29
24
30
import com .facebook .react .bridge .ReactContext ;
25
31
import com .github .scribejava .core .model .OAuth1AccessToken ;
@@ -39,6 +45,7 @@ public class OAuthManagerDialogFragment extends DialogFragment implements Advanc
39
45
40
46
private ReactContext mReactContext ;
41
47
private AdvancedWebView mWebView ;
48
+ private ProgressBar mProgressBar ;
42
49
43
50
public static final OAuthManagerDialogFragment newInstance (
44
51
final ReactContext reactContext ,
@@ -58,21 +65,36 @@ public OAuthManagerDialogFragment(
58
65
this .mReactContext = reactContext ;
59
66
}
60
67
68
+ @ Override
69
+ public Dialog onCreateDialog (Bundle savedInstanceState ) {
70
+ Dialog dialog = super .onCreateDialog (savedInstanceState );
71
+ dialog .getWindow ().requestFeature (Window .FEATURE_NO_TITLE );
72
+ return dialog ;
73
+ }
74
+
75
+ @ Override
76
+ public void onStart () {
77
+ super .onStart ();
78
+ Dialog dialog = getDialog ();
79
+ if (dialog != null ) {
80
+ dialog .getWindow ().setLayout (ViewGroup .LayoutParams .MATCH_PARENT , ViewGroup .LayoutParams .MATCH_PARENT );
81
+ dialog .getWindow ().setBackgroundDrawable (new ColorDrawable (Color .TRANSPARENT ));
82
+ }
83
+ }
84
+
61
85
@ Override
62
86
public View onCreateView (LayoutInflater inflater , ViewGroup container , Bundle savedInstanceState ) {
63
- // View rootView = inflater.inflate(R.id.primary, container, false);
64
- // final Context context = inflater.getContext();
65
- // DisplayMetrics metrics = context.getResources().getDisplayMetrics();
66
- // final int DIALOG_HEIGHT = (int) Math.min(0.99f * metrics.heightPixels, 1024);
67
-
68
- // LayoutParams rootViewLayoutParams = new LayoutParams(
69
- // LayoutParams.FILL_PARENT,
70
- // LayoutParams.FILL_PARENT
71
- // );
72
87
final Context context = mReactContext ;
73
88
LayoutParams rootViewLayoutParams = this .getFullscreenLayoutParams (context );
74
89
75
- FrameLayout rootView = new FrameLayout (context );
90
+ RelativeLayout rootView = new RelativeLayout (context );
91
+
92
+ mProgressBar = new ProgressBar (context );
93
+ RelativeLayout .LayoutParams progressParams = new RelativeLayout .LayoutParams (convertDpToPixel (50f ,context ),convertDpToPixel (50f ,context ));
94
+ progressParams .addRule (RelativeLayout .CENTER_IN_PARENT );
95
+ mProgressBar .setLayoutParams (progressParams );
96
+ mProgressBar .setIndeterminate (true );
97
+
76
98
getDialog ().setCanceledOnTouchOutside (true );
77
99
rootView .setLayoutParams (rootViewLayoutParams );
78
100
@@ -89,13 +111,14 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
89
111
90
112
LayoutParams layoutParams = this .getFullscreenLayoutParams (context );
91
113
//new LayoutParams(
92
- // LayoutParams.FILL_PARENT,
114
+ // LayoutParams.FILL_PARENT,
93
115
// DIALOG_HEIGHT
94
116
// );
95
117
// mWebView.setLayoutParams(layoutParams);
96
118
97
119
rootView .addView (mWebView , layoutParams );
98
-
120
+ rootView .addView (mProgressBar ,progressParams );
121
+
99
122
// LinearLayout pframe = new LinearLayout(context);
100
123
// pframe.setId(WIDGET_TAG);
101
124
// pframe.setOrientation(LinearLayout.VERTICAL);
@@ -146,7 +169,7 @@ private LayoutParams getFullscreenLayoutParams(Context context) {
146
169
realHeight = display .getHeight ();
147
170
}
148
171
149
- return new LayoutParams (realWidth , realHeight );
172
+ return new LayoutParams (realWidth , realHeight - 100 );
150
173
}
151
174
152
175
@@ -157,7 +180,13 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) {
157
180
return interceptUrl (view , url , true );
158
181
}
159
182
160
- @ Override
183
+ @ Override
184
+ public void onPageFinished (WebView view , String url ) {
185
+ super .onPageFinished (view , url );
186
+ mProgressBar .setVisibility (View .GONE );
187
+ }
188
+
189
+ @ Override
161
190
public void onReceivedError (WebView view , int code , String desc , String failingUrl ) {
162
191
Log .i (TAG , "onReceivedError: " + failingUrl );
163
192
super .onReceivedError (view , code , desc , failingUrl );
@@ -184,12 +213,6 @@ public void setComplete(final OAuth1AccessToken accessToken) {
184
213
Log .d (TAG , "Completed: " + accessToken );
185
214
}
186
215
187
- @ Override
188
- public void onStart () {
189
- super .onStart ();
190
-
191
- Log .d (TAG , "onStart for DialogFragment" );
192
- }
193
216
194
217
// @Override
195
218
// public void onDismiss(final DialogInterface dialog) {
@@ -296,4 +319,11 @@ static boolean isCallbackUri(String uri, String callbackUrl) {
296
319
if (!TextUtils .isEmpty (frag ) && !TextUtils .equals (frag , u .getFragment ())) return false ;
297
320
return true ;
298
321
}
322
+
323
+ public static int convertDpToPixel (float dp , Context context ){
324
+ Resources resources = context .getResources ();
325
+ DisplayMetrics metrics = resources .getDisplayMetrics ();
326
+ float px = dp * ((float )metrics .densityDpi / DisplayMetrics .DENSITY_DEFAULT );
327
+ return (int )px ;
328
+ }
299
329
}
0 commit comments