11package io .fullstack .oauth ;
22
33import android .annotation .SuppressLint ;
4+ import android .app .Dialog ;
45import android .app .DialogFragment ;
56import android .content .Context ;
67import android .content .Intent ;
8+ import android .content .res .Resources ;
79import android .graphics .Bitmap ;
10+ import android .graphics .Color ;
11+ import android .graphics .drawable .ColorDrawable ;
812import android .net .Uri ;
913import android .os .Build ;
1014import android .os .Bundle ;
1620import android .view .View ;
1721import android .view .ViewGroup ;
1822import android .view .ViewGroup .LayoutParams ;
23+ import android .view .Window ;
1924import android .view .WindowManager ;
2025import android .webkit .WebView ;
2126import android .webkit .WebViewClient ;
22- import android .widget .FrameLayout ;
27+ import android .widget .ProgressBar ;
28+ import android .widget .RelativeLayout ;
2329
2430import com .facebook .react .bridge .ReactContext ;
2531import com .github .scribejava .core .model .OAuth1AccessToken ;
@@ -39,6 +45,7 @@ public class OAuthManagerDialogFragment extends DialogFragment implements Advanc
3945
4046 private ReactContext mReactContext ;
4147 private AdvancedWebView mWebView ;
48+ private ProgressBar mProgressBar ;
4249
4350 public static final OAuthManagerDialogFragment newInstance (
4451 final ReactContext reactContext ,
@@ -58,21 +65,36 @@ public OAuthManagerDialogFragment(
5865 this .mReactContext = reactContext ;
5966 }
6067
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+
6185 @ Override
6286 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- // );
7287 final Context context = mReactContext ;
7388 LayoutParams rootViewLayoutParams = this .getFullscreenLayoutParams (context );
7489
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+
7698 getDialog ().setCanceledOnTouchOutside (true );
7799 rootView .setLayoutParams (rootViewLayoutParams );
78100
@@ -89,13 +111,14 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
89111
90112 LayoutParams layoutParams = this .getFullscreenLayoutParams (context );
91113 //new LayoutParams(
92- // LayoutParams.FILL_PARENT,
114+ // LayoutParams.FILL_PARENT,
93115 // DIALOG_HEIGHT
94116 // );
95117 // mWebView.setLayoutParams(layoutParams);
96118
97119 rootView .addView (mWebView , layoutParams );
98-
120+ rootView .addView (mProgressBar ,progressParams );
121+
99122 // LinearLayout pframe = new LinearLayout(context);
100123 // pframe.setId(WIDGET_TAG);
101124 // pframe.setOrientation(LinearLayout.VERTICAL);
@@ -146,7 +169,7 @@ private LayoutParams getFullscreenLayoutParams(Context context) {
146169 realHeight = display .getHeight ();
147170 }
148171
149- return new LayoutParams (realWidth , realHeight );
172+ return new LayoutParams (realWidth , realHeight - 100 );
150173 }
151174
152175
@@ -157,7 +180,13 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) {
157180 return interceptUrl (view , url , true );
158181 }
159182
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
161190 public void onReceivedError (WebView view , int code , String desc , String failingUrl ) {
162191 Log .i (TAG , "onReceivedError: " + failingUrl );
163192 super .onReceivedError (view , code , desc , failingUrl );
@@ -184,12 +213,6 @@ public void setComplete(final OAuth1AccessToken accessToken) {
184213 Log .d (TAG , "Completed: " + accessToken );
185214 }
186215
187- @ Override
188- public void onStart () {
189- super .onStart ();
190-
191- Log .d (TAG , "onStart for DialogFragment" );
192- }
193216
194217// @Override
195218// public void onDismiss(final DialogInterface dialog) {
@@ -296,4 +319,11 @@ static boolean isCallbackUri(String uri, String callbackUrl) {
296319 if (!TextUtils .isEmpty (frag ) && !TextUtils .equals (frag , u .getFragment ())) return false ;
297320 return true ;
298321 }
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+ }
299329}
0 commit comments