@@ -102,6 +102,11 @@ public class InAppBrowser extends CordovaPlugin {
102
102
private static final String CLEAR_SESSION_CACHE = "clearsessioncache" ;
103
103
private static final String HARDWARE_BACK_BUTTON = "hardwareback" ;
104
104
private static final String MEDIA_PLAYBACK_REQUIRES_USER_ACTION = "mediaPlaybackRequiresUserAction" ;
105
+ private static final String INTENT_PROTOCOL_START = "intent:" ;
106
+ private static final String INTENT_PROTOCOL_INTENT = "#Intent;" ;
107
+ private static final String INTENT_PROTOCOL_END = ";end;" ;
108
+ private static final String GOOGLE_PLAY_STORE_PREFIX = "market://details?id=" ;
109
+ private static final String HOGANGNONO_SCHEME = "hogangnono://" ;
105
110
private static final String SHOULD_PAUSE = "shouldPauseOnSuspend" ;
106
111
private static final Boolean DEFAULT_HARDWARE_BACK = true ;
107
112
private static final String USER_WIDE_VIEW_PORT = "useWideViewPort" ;
@@ -773,6 +778,27 @@ public void onClick(View v) {
773
778
return _close ;
774
779
}
775
780
781
+ private ImageButton createImageButton (int id , String res ){
782
+ Resources activityRes = cordova .getActivity ().getResources ();
783
+
784
+ ImageButton button = new ImageButton (cordova .getActivity ());
785
+ int resId = activityRes .getIdentifier (res , "drawable" , cordova .getActivity ().getPackageName ());
786
+ Drawable resIcon = activityRes .getDrawable (resId );
787
+
788
+ button .setImageDrawable (resIcon );
789
+ button .setScaleType (ImageView .ScaleType .FIT_CENTER );
790
+
791
+ if (Build .VERSION .SDK_INT >= 16 ){
792
+ button .getAdjustViewBounds ();
793
+ button .setBackground (null );
794
+ }else {
795
+ button .setBackgroundDrawable (null );
796
+ }
797
+ button .setId (Integer .valueOf (id ));
798
+
799
+ return button ;
800
+ }
801
+
776
802
@ SuppressLint ("NewApi" )
777
803
public void run () {
778
804
@@ -870,7 +896,13 @@ public void onClick(View v) {
870
896
textLayoutParams .addRule (RelativeLayout .LEFT_OF , 5 );
871
897
edittext .setLayoutParams (textLayoutParams );
872
898
edittext .setId (Integer .valueOf (4 ));
873
- edittext .setSingleLine (true );
899
+ // edittext.setSingleLine(true);
900
+ edittext .setEnabled (false );
901
+ edittext .setTextSize (15 );
902
+ edittext .setTextColor (android .graphics .Color .argb (150 , 255 ,255 ,255 ));
903
+ edittext .setBackgroundColor (android .graphics .Color .argb (0 ,0 ,0 ,0 ));
904
+ edittext .setPadding (0 , this .dpToPixels (10 ), this .dpToPixels (8 ), this .dpToPixels (10 ));
905
+
874
906
edittext .setText (url );
875
907
edittext .setInputType (InputType .TYPE_TEXT_VARIATION_URI );
876
908
edittext .setImeOptions (EditorInfo .IME_ACTION_GO );
@@ -886,7 +918,7 @@ public boolean onKey(View v, int keyCode, KeyEvent event) {
886
918
}
887
919
});
888
920
889
-
921
+ /*
890
922
// Header Close/Done button
891
923
int closeButtonId = leftToRight ? 1 : 5;
892
924
View close = createCloseButton(closeButtonId);
@@ -910,7 +942,55 @@ public boolean onKey(View v, int keyCode, KeyEvent event) {
910
942
911
943
View footerClose = createCloseButton(7);
912
944
footer.addView(footerClose);
945
+ */
913
946
947
+ // Action Button Container layout
948
+ RelativeLayout customButtonContainer = new RelativeLayout (cordova .getActivity ());
949
+ RelativeLayout .LayoutParams containerLayoutParmas = new RelativeLayout .LayoutParams (LayoutParams .WRAP_CONTENT , LayoutParams .WRAP_CONTENT );
950
+ containerLayoutParmas .addRule (RelativeLayout .ALIGN_PARENT_RIGHT );
951
+ customButtonContainer .setLayoutParams (containerLayoutParmas );
952
+ customButtonContainer .setHorizontalGravity (Gravity .RIGHT );
953
+ customButtonContainer .setVerticalGravity (Gravity .CENTER_VERTICAL );
954
+ customButtonContainer .setId (Integer .valueOf (5 ));
955
+
956
+ // Close/Done button
957
+ int closeButtonId = 7 ;
958
+ ImageButton closeButton = createImageButton (closeButtonId , "ic_action_remove_white" );
959
+ closeButton .setContentDescription ("Close Button" );
960
+ closeButton .setPadding (0 , this .dpToPixels (10 ), 0 , this .dpToPixels (10 ));
961
+ closeButton .setOnClickListener (new View .OnClickListener (){
962
+ public void onClick (View v ){
963
+ closeDialog ();
964
+ }
965
+ });
966
+
967
+ // Share button
968
+ int shareButtonId = 8 ;
969
+ ImageButton shareButton = createImageButton (shareButtonId , "ic_action_share" );
970
+ shareButton .setPadding (5 , this .dpToPixels (10 ), 5 , this .dpToPixels (10 ));
971
+ shareButton .setContentDescription ("Share Button" );
972
+ shareButton .setOnClickListener (new View .OnClickListener () {
973
+ public void onClick (View v ) {
974
+ Intent sharingIntent = new Intent (android .content .Intent .ACTION_SEND );
975
+ sharingIntent .setType ("text/plain" );
976
+ String shareBody = inAppWebView .getUrl ();
977
+ sharingIntent .putExtra (android .content .Intent .EXTRA_SUBJECT , inAppWebView .getUrl ());
978
+ sharingIntent .putExtra (android .content .Intent .EXTRA_TEXT , shareBody );
979
+
980
+ cordova .getActivity ().startActivity (Intent .createChooser (sharingIntent , "URL 공유" ));
981
+ }
982
+ });
983
+
984
+ RelativeLayout .LayoutParams closeLayoutParams = new RelativeLayout .LayoutParams (LayoutParams .WRAP_CONTENT , LayoutParams .MATCH_PARENT );
985
+ closeLayoutParams .addRule (RelativeLayout .RIGHT_OF , shareButtonId );
986
+ closeButton .setLayoutParams (closeLayoutParams );
987
+
988
+ RelativeLayout .LayoutParams shareLayoutParams = new RelativeLayout .LayoutParams (LayoutParams .WRAP_CONTENT , LayoutParams .MATCH_PARENT );
989
+ shareLayoutParams .addRule (RelativeLayout .ALIGN_LEFT );
990
+ shareButton .setLayoutParams (shareLayoutParams );
991
+
992
+ customButtonContainer .addView ((View )closeButton );
993
+ customButtonContainer .addView ((View )shareButton );
914
994
915
995
// WebView
916
996
inAppWebView = new WebView (cordova .getActivity ());
@@ -1009,6 +1089,7 @@ public void postMessage(String data) {
1009
1089
// Add the views to our toolbar if they haven't been disabled
1010
1090
if (!hideNavigationButtons ) toolbar .addView (actionButtonContainer );
1011
1091
if (!hideUrlBar ) toolbar .addView (edittext );
1092
+ toolbar .addView (customButtonContainer );
1012
1093
1013
1094
// Don't add the toolbar if its been disabled
1014
1095
if (getShowLocationBar ()) {
@@ -1022,9 +1103,9 @@ public void postMessage(String data) {
1022
1103
main .addView (webViewLayout );
1023
1104
1024
1105
// Don't add the footer unless it's been enabled
1025
- if (showFooter ) {
1026
- webViewLayout .addView (footer );
1027
- }
1106
+ // if (showFooter) {
1107
+ // webViewLayout.addView(footer);
1108
+ // }
1028
1109
1029
1110
WindowManager .LayoutParams lp = new WindowManager .LayoutParams ();
1030
1111
lp .copyFrom (dialog .getWindow ().getAttributes ());
@@ -1200,6 +1281,7 @@ public boolean shouldOverrideUrlLoading(String url, String method) {
1200
1281
} catch (android .content .ActivityNotFoundException e ) {
1201
1282
LOG .e (LOG_TAG , "Error dialing " + url + ": " + e .toString ());
1202
1283
}
1284
+ // [hogangnono] Make to install when use doesn't have app
1203
1285
} else if (url .startsWith ("geo:" ) || url .startsWith (WebView .SCHEME_MAILTO ) || url .startsWith ("market:" ) || url .startsWith ("intent:" )) {
1204
1286
try {
1205
1287
Intent intent = new Intent (Intent .ACTION_VIEW );
@@ -1241,6 +1323,38 @@ else if (url.startsWith("sms:")) {
1241
1323
LOG .e (LOG_TAG , "Error sending sms " + url + ":" + e .toString ());
1242
1324
}
1243
1325
}
1326
+ // Support hogangnono scheme
1327
+ else if (url .startsWith (HOGANGNONO_SCHEME )) {
1328
+ final String customUrl = url .substring (HOGANGNONO_SCHEME .length (), url .length ());
1329
+
1330
+ try {
1331
+ cordova .getActivity ().startActivity (new Intent (Intent .ACTION_VIEW , Uri .parse (customUrl )));
1332
+ } catch (ActivityNotFoundException e ) {
1333
+ cordova .getActivity ().startActivity (new Intent (Intent .ACTION_VIEW , Uri .parse (GOOGLE_PLAY_STORE_PREFIX + "com.hogangnono.hogangnono" )));
1334
+ }
1335
+ return true ;
1336
+ }
1337
+ // Supports Intent:// scheme. It usually used on above 4 version.
1338
+ else if (url .startsWith (INTENT_PROTOCOL_START )) {
1339
+ final int customUrlStartIndex = INTENT_PROTOCOL_START .length ();
1340
+ final int customUrlEndIndex = url .indexOf (INTENT_PROTOCOL_INTENT );
1341
+
1342
+ if (customUrlEndIndex < 0 ) {
1343
+ return false ;
1344
+ } else {
1345
+ final String customUrl = url .substring (customUrlStartIndex , customUrlEndIndex );
1346
+
1347
+ try {
1348
+ cordova .getActivity ().startActivity (new Intent (Intent .ACTION_VIEW , Uri .parse (customUrl )));
1349
+ } catch (ActivityNotFoundException e ) {
1350
+ final int packageStartIndex = customUrlEndIndex + INTENT_PROTOCOL_INTENT .length ();
1351
+ final int packageEndIndex = url .indexOf (INTENT_PROTOCOL_END );
1352
+ final String packageName = url .substring (packageStartIndex , packageEndIndex < 0 ? url .length () : packageEndIndex ).replace ("package=" , "" );
1353
+ cordova .getActivity ().startActivity (new Intent (Intent .ACTION_VIEW , Uri .parse (GOOGLE_PLAY_STORE_PREFIX + packageName )));
1354
+ }
1355
+ return true ;
1356
+ }
1357
+ }
1244
1358
// Test for whitelisted custom scheme names like mycoolapp:// or twitteroauthresponse:// (Twitter Oauth Response)
1245
1359
else if (!url .startsWith ("http:" ) && !url .startsWith ("https:" ) && url .matches ("^[A-Za-z0-9+.-]*://.*?$" )) {
1246
1360
if (allowedSchemes == null ) {
0 commit comments