Skip to content

Commit a0781f7

Browse files
committed
android custom share add
1 parent 10f2ad7 commit a0781f7

File tree

10 files changed

+131
-5
lines changed

10 files changed

+131
-5
lines changed

plugin.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,18 @@
6666
<resource-file src="src/android/res/drawable-xhdpi/ic_action_remove.png" target="res/drawable-xhdpi/ic_action_remove.png" />
6767
<resource-file src="src/android/res/drawable-xxhdpi/ic_action_remove.png" target="res/drawable-xxhdpi/ic_action_remove.png" />
6868

69+
70+
<resource-file src="src/android/res/drawable-hdpi/ic_action_share.png" target="res/drawable-hdpi/ic_action_share.png" />
71+
<resource-file src="src/android/res/drawable-mdpi/ic_action_share.png" target="res/drawable-mdpi/ic_action_share.png" />
72+
<resource-file src="src/android/res/drawable-xhdpi/ic_action_share.png" target="res/drawable-xhdpi/ic_action_share.png" />
73+
<resource-file src="src/android/res/drawable-xxhdpi/ic_action_share.png" target="res/drawable-xxhdpi/ic_action_share.png" />
74+
75+
76+
<resource-file src="src/android/res/drawable-hdpi/ic_action_remove_white.png" target="res/drawable-hdpi/ic_action_remove_white.png" />
77+
<resource-file src="src/android/res/drawable-mdpi/ic_action_remove_white.png" target="res/drawable-mdpi/ic_action_remove_white.png" />
78+
<resource-file src="src/android/res/drawable-xhdpi/ic_action_remove_white.png" target="res/drawable-xhdpi/ic_action_remove_white.png" />
79+
<resource-file src="src/android/res/drawable-xxhdpi/ic_action_remove_white.png" target="res/drawable-xxhdpi/ic_action_remove_white.png" />
80+
6981
</platform>
7082

7183
<!-- ios -->

src/android/InAppBrowser.java

Lines changed: 119 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ public class InAppBrowser extends CordovaPlugin {
102102
private static final String CLEAR_SESSION_CACHE = "clearsessioncache";
103103
private static final String HARDWARE_BACK_BUTTON = "hardwareback";
104104
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://";
105110
private static final String SHOULD_PAUSE = "shouldPauseOnSuspend";
106111
private static final Boolean DEFAULT_HARDWARE_BACK = true;
107112
private static final String USER_WIDE_VIEW_PORT = "useWideViewPort";
@@ -773,6 +778,27 @@ public void onClick(View v) {
773778
return _close;
774779
}
775780

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+
776802
@SuppressLint("NewApi")
777803
public void run() {
778804

@@ -870,7 +896,13 @@ public void onClick(View v) {
870896
textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5);
871897
edittext.setLayoutParams(textLayoutParams);
872898
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+
874906
edittext.setText(url);
875907
edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI);
876908
edittext.setImeOptions(EditorInfo.IME_ACTION_GO);
@@ -886,7 +918,7 @@ public boolean onKey(View v, int keyCode, KeyEvent event) {
886918
}
887919
});
888920

889-
921+
/*
890922
// Header Close/Done button
891923
int closeButtonId = leftToRight ? 1 : 5;
892924
View close = createCloseButton(closeButtonId);
@@ -910,7 +942,55 @@ public boolean onKey(View v, int keyCode, KeyEvent event) {
910942
911943
View footerClose = createCloseButton(7);
912944
footer.addView(footerClose);
945+
*/
913946

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);
914994

915995
// WebView
916996
inAppWebView = new WebView(cordova.getActivity());
@@ -1009,6 +1089,7 @@ public void postMessage(String data) {
10091089
// Add the views to our toolbar if they haven't been disabled
10101090
if (!hideNavigationButtons) toolbar.addView(actionButtonContainer);
10111091
if (!hideUrlBar) toolbar.addView(edittext);
1092+
toolbar.addView(customButtonContainer);
10121093

10131094
// Don't add the toolbar if its been disabled
10141095
if (getShowLocationBar()) {
@@ -1022,9 +1103,9 @@ public void postMessage(String data) {
10221103
main.addView(webViewLayout);
10231104

10241105
// 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+
// }
10281109

10291110
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
10301111
lp.copyFrom(dialog.getWindow().getAttributes());
@@ -1200,6 +1281,7 @@ public boolean shouldOverrideUrlLoading(String url, String method) {
12001281
} catch (android.content.ActivityNotFoundException e) {
12011282
LOG.e(LOG_TAG, "Error dialing " + url + ": " + e.toString());
12021283
}
1284+
// [hogangnono] Make to install when use doesn't have app
12031285
} else if (url.startsWith("geo:") || url.startsWith(WebView.SCHEME_MAILTO) || url.startsWith("market:") || url.startsWith("intent:")) {
12041286
try {
12051287
Intent intent = new Intent(Intent.ACTION_VIEW);
@@ -1241,6 +1323,38 @@ else if (url.startsWith("sms:")) {
12411323
LOG.e(LOG_TAG, "Error sending sms " + url + ":" + e.toString());
12421324
}
12431325
}
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+
}
12441358
// Test for whitelisted custom scheme names like mycoolapp:// or twitteroauthresponse:// (Twitter Oauth Response)
12451359
else if (!url.startsWith("http:") && !url.startsWith("https:") && url.matches("^[A-Za-z0-9+.-]*://.*?$")) {
12461360
if (allowedSchemes == null) {
1.71 KB
Loading
1.72 KB
Loading
1.55 KB
Loading
1.93 KB
Loading
1.86 KB
Loading
2.21 KB
Loading
2.03 KB
Loading
1.96 KB
Loading

0 commit comments

Comments
 (0)