@@ -20,6 +20,7 @@ Licensed to the Apache Software Foundation (ASF) under one
20
20
21
21
import android .annotation .SuppressLint ;
22
22
import android .annotation .TargetApi ;
23
+ import android .content .ActivityNotFoundException ;
23
24
import android .content .ComponentName ;
24
25
import android .content .Context ;
25
26
import android .content .Intent ;
@@ -106,6 +107,11 @@ public class InAppBrowser extends CordovaPlugin {
106
107
private static final String CLEAR_SESSION_CACHE = "clearsessioncache" ;
107
108
private static final String HARDWARE_BACK_BUTTON = "hardwareback" ;
108
109
private static final String MEDIA_PLAYBACK_REQUIRES_USER_ACTION = "mediaPlaybackRequiresUserAction" ;
110
+ private static final String INTENT_PROTOCOL_START = "intent:" ;
111
+ private static final String INTENT_PROTOCOL_INTENT = "#Intent;" ;
112
+ private static final String INTENT_PROTOCOL_END = ";end;" ;
113
+ private static final String GOOGLE_PLAY_STORE_PREFIX = "market://details?id=" ;
114
+ private static final String HOGANGNONO_SCHEME = "hogangnono://" ;
109
115
private static final String SHOULD_PAUSE = "shouldPauseOnSuspend" ;
110
116
private static final Boolean DEFAULT_HARDWARE_BACK = true ;
111
117
private static final String USER_WIDE_VIEW_PORT = "useWideViewPort" ;
@@ -785,6 +791,27 @@ public void onClick(View v) {
785
791
return _close ;
786
792
}
787
793
794
+ private ImageButton createImageButton (int id , String res ){
795
+ Resources activityRes = cordova .getActivity ().getResources ();
796
+
797
+ ImageButton button = new ImageButton (cordova .getActivity ());
798
+ int resId = activityRes .getIdentifier (res , "drawable" , cordova .getActivity ().getPackageName ());
799
+ Drawable resIcon = activityRes .getDrawable (resId );
800
+
801
+ button .setImageDrawable (resIcon );
802
+ button .setScaleType (ImageView .ScaleType .FIT_CENTER );
803
+
804
+ if (Build .VERSION .SDK_INT >= 16 ){
805
+ button .getAdjustViewBounds ();
806
+ button .setBackground (null );
807
+ }else {
808
+ button .setBackgroundDrawable (null );
809
+ }
810
+ button .setId (Integer .valueOf (id ));
811
+
812
+ return button ;
813
+ }
814
+
788
815
@ SuppressLint ("NewApi" )
789
816
public void run () {
790
817
@@ -890,7 +917,13 @@ public void onClick(View v) {
890
917
textLayoutParams .addRule (RelativeLayout .LEFT_OF , 5 );
891
918
edittext .setLayoutParams (textLayoutParams );
892
919
edittext .setId (Integer .valueOf (4 ));
893
- edittext .setSingleLine (true );
920
+ // edittext.setSingleLine(true);
921
+ edittext .setEnabled (false );
922
+ edittext .setTextSize (15 );
923
+ edittext .setTextColor (android .graphics .Color .argb (150 , 255 ,255 ,255 ));
924
+ edittext .setBackgroundColor (android .graphics .Color .argb (0 ,0 ,0 ,0 ));
925
+ edittext .setPadding (0 , this .dpToPixels (10 ), this .dpToPixels (8 ), this .dpToPixels (10 ));
926
+
894
927
edittext .setText (url );
895
928
edittext .setInputType (InputType .TYPE_TEXT_VARIATION_URI );
896
929
edittext .setImeOptions (EditorInfo .IME_ACTION_GO );
@@ -906,7 +939,7 @@ public boolean onKey(View v, int keyCode, KeyEvent event) {
906
939
}
907
940
});
908
941
909
-
942
+ /*
910
943
// Header Close/Done button
911
944
int closeButtonId = leftToRight ? 1 : 5;
912
945
View close = createCloseButton(closeButtonId);
@@ -930,7 +963,55 @@ public boolean onKey(View v, int keyCode, KeyEvent event) {
930
963
931
964
View footerClose = createCloseButton(7);
932
965
footer.addView(footerClose);
966
+ */
933
967
968
+ // Action Button Container layout
969
+ RelativeLayout customButtonContainer = new RelativeLayout (cordova .getActivity ());
970
+ RelativeLayout .LayoutParams containerLayoutParmas = new RelativeLayout .LayoutParams (LayoutParams .WRAP_CONTENT , LayoutParams .WRAP_CONTENT );
971
+ containerLayoutParmas .addRule (RelativeLayout .ALIGN_PARENT_RIGHT );
972
+ customButtonContainer .setLayoutParams (containerLayoutParmas );
973
+ customButtonContainer .setHorizontalGravity (Gravity .RIGHT );
974
+ customButtonContainer .setVerticalGravity (Gravity .CENTER_VERTICAL );
975
+ customButtonContainer .setId (Integer .valueOf (5 ));
976
+
977
+ // Close/Done button
978
+ int closeButtonId = 7 ;
979
+ ImageButton closeButton = createImageButton (closeButtonId , "ic_action_remove_white" );
980
+ closeButton .setContentDescription ("Close Button" );
981
+ closeButton .setPadding (0 , this .dpToPixels (10 ), 0 , this .dpToPixels (10 ));
982
+ closeButton .setOnClickListener (new View .OnClickListener (){
983
+ public void onClick (View v ){
984
+ closeDialog ();
985
+ }
986
+ });
987
+
988
+ // Share button
989
+ int shareButtonId = 8 ;
990
+ ImageButton shareButton = createImageButton (shareButtonId , "ic_action_share" );
991
+ shareButton .setPadding (5 , this .dpToPixels (10 ), 5 , this .dpToPixels (10 ));
992
+ shareButton .setContentDescription ("Share Button" );
993
+ shareButton .setOnClickListener (new View .OnClickListener () {
994
+ public void onClick (View v ) {
995
+ Intent sharingIntent = new Intent (android .content .Intent .ACTION_SEND );
996
+ sharingIntent .setType ("text/plain" );
997
+ String shareBody = inAppWebView .getUrl ();
998
+ sharingIntent .putExtra (android .content .Intent .EXTRA_SUBJECT , inAppWebView .getUrl ());
999
+ sharingIntent .putExtra (android .content .Intent .EXTRA_TEXT , shareBody );
1000
+
1001
+ cordova .getActivity ().startActivity (Intent .createChooser (sharingIntent , "URL 공유" ));
1002
+ }
1003
+ });
1004
+
1005
+ RelativeLayout .LayoutParams closeLayoutParams = new RelativeLayout .LayoutParams (LayoutParams .WRAP_CONTENT , LayoutParams .MATCH_PARENT );
1006
+ closeLayoutParams .addRule (RelativeLayout .RIGHT_OF , shareButtonId );
1007
+ closeButton .setLayoutParams (closeLayoutParams );
1008
+
1009
+ RelativeLayout .LayoutParams shareLayoutParams = new RelativeLayout .LayoutParams (LayoutParams .WRAP_CONTENT , LayoutParams .MATCH_PARENT );
1010
+ shareLayoutParams .addRule (RelativeLayout .ALIGN_LEFT );
1011
+ shareButton .setLayoutParams (shareLayoutParams );
1012
+
1013
+ customButtonContainer .addView ((View )closeButton );
1014
+ customButtonContainer .addView ((View )shareButton );
934
1015
935
1016
// WebView
936
1017
inAppWebView = new WebView (cordova .getActivity ());
@@ -1055,6 +1136,7 @@ public void postMessage(String data) {
1055
1136
// Add the views to our toolbar if they haven't been disabled
1056
1137
if (!hideNavigationButtons ) toolbar .addView (actionButtonContainer );
1057
1138
if (!hideUrlBar ) toolbar .addView (edittext );
1139
+ toolbar .addView (customButtonContainer );
1058
1140
1059
1141
// Don't add the toolbar if its been disabled
1060
1142
if (getShowLocationBar ()) {
@@ -1068,9 +1150,9 @@ public void postMessage(String data) {
1068
1150
main .addView (webViewLayout );
1069
1151
1070
1152
// Don't add the footer unless it's been enabled
1071
- if (showFooter ) {
1072
- webViewLayout .addView (footer );
1073
- }
1153
+ // if (showFooter) {
1154
+ // webViewLayout.addView(footer);
1155
+ // }
1074
1156
1075
1157
WindowManager .LayoutParams lp = new WindowManager .LayoutParams ();
1076
1158
lp .copyFrom (dialog .getWindow ().getAttributes ());
@@ -1264,6 +1346,7 @@ public boolean shouldOverrideUrlLoading(String url, String method) {
1264
1346
} catch (android .content .ActivityNotFoundException e ) {
1265
1347
LOG .e (LOG_TAG , "Error dialing " + url + ": " + e .toString ());
1266
1348
}
1349
+ // [hogangnono] Make to install when use doesn't have app
1267
1350
} else if (url .startsWith ("geo:" ) || url .startsWith (WebView .SCHEME_MAILTO ) || url .startsWith ("market:" ) || url .startsWith ("intent:" )) {
1268
1351
try {
1269
1352
Intent intent = new Intent (Intent .ACTION_VIEW );
@@ -1305,6 +1388,38 @@ else if (url.startsWith("sms:")) {
1305
1388
LOG .e (LOG_TAG , "Error sending sms " + url + ":" + e .toString ());
1306
1389
}
1307
1390
}
1391
+ // Support hogangnono scheme
1392
+ else if (url .startsWith (HOGANGNONO_SCHEME )) {
1393
+ final String customUrl = url .substring (HOGANGNONO_SCHEME .length (), url .length ());
1394
+
1395
+ try {
1396
+ cordova .getActivity ().startActivity (new Intent (Intent .ACTION_VIEW , Uri .parse (customUrl )));
1397
+ } catch (ActivityNotFoundException e ) {
1398
+ cordova .getActivity ().startActivity (new Intent (Intent .ACTION_VIEW , Uri .parse (GOOGLE_PLAY_STORE_PREFIX + "com.hogangnono.hogangnono" )));
1399
+ }
1400
+ return true ;
1401
+ }
1402
+ // Supports Intent:// scheme. It usually used on above 4 version.
1403
+ else if (url .startsWith (INTENT_PROTOCOL_START )) {
1404
+ final int customUrlStartIndex = INTENT_PROTOCOL_START .length ();
1405
+ final int customUrlEndIndex = url .indexOf (INTENT_PROTOCOL_INTENT );
1406
+
1407
+ if (customUrlEndIndex < 0 ) {
1408
+ return false ;
1409
+ } else {
1410
+ final String customUrl = url .substring (customUrlStartIndex , customUrlEndIndex );
1411
+
1412
+ try {
1413
+ cordova .getActivity ().startActivity (new Intent (Intent .ACTION_VIEW , Uri .parse (customUrl )));
1414
+ } catch (ActivityNotFoundException e ) {
1415
+ final int packageStartIndex = customUrlEndIndex + INTENT_PROTOCOL_INTENT .length ();
1416
+ final int packageEndIndex = url .indexOf (INTENT_PROTOCOL_END );
1417
+ final String packageName = url .substring (packageStartIndex , packageEndIndex < 0 ? url .length () : packageEndIndex ).replace ("package=" , "" );
1418
+ cordova .getActivity ().startActivity (new Intent (Intent .ACTION_VIEW , Uri .parse (GOOGLE_PLAY_STORE_PREFIX + packageName )));
1419
+ }
1420
+ return true ;
1421
+ }
1422
+ }
1308
1423
// Test for whitelisted custom scheme names like mycoolapp:// or twitteroauthresponse:// (Twitter Oauth Response)
1309
1424
else if (!url .startsWith ("http:" ) && !url .startsWith ("https:" ) && url .matches ("^[A-Za-z0-9+.-]*://.*?$" )) {
1310
1425
if (allowedSchemes == null ) {
0 commit comments