1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2024-11-22 12:22:08 +01:00

make difference intent with/without extra_subject

This commit is contained in:
scoute-dich 2016-04-15 20:59:18 +02:00
parent 7f2eda535b
commit f439be77d7
2 changed files with 49 additions and 11 deletions

View file

@ -49,13 +49,19 @@
android:label="@string/new_post" android:label="@string/new_post"
android:theme="@style/AppTheme.NoActionBar" android:theme="@style/AppTheme.NoActionBar"
android:screenOrientation="portrait" > android:screenOrientation="portrait" >
<intent-filter android:label="@string/new_post" <intent-filter>
android:icon="@drawable/ic_launcher">
<action android:name="android.intent.action.SEND" /> <action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/*" /> <data android:mimeType="text/plain" />
<data android:mimeType="image/*" />
</intent-filter> </intent-filter>
<!-- //TODO Handle single image being sent
<intent-filter>
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>-->
</activity> </activity>
<service <service
@ -66,3 +72,6 @@
</application> </application>
</manifest> </manifest>

View file

@ -79,6 +79,7 @@ public class ShareActivity extends MainActivity {
Intent intent = new Intent(ShareActivity.this, MainActivity.class); Intent intent = new Intent(ShareActivity.this, MainActivity.class);
startActivityForResult(intent, 100); startActivityForResult(intent, 100);
overridePendingTransition(0, 0); overridePendingTransition(0, 0);
finish();
} else { } else {
Snackbar.make(swipeView, R.string.no_internet, Snackbar.LENGTH_LONG).show(); Snackbar.make(swipeView, R.string.no_internet, Snackbar.LENGTH_LONG).show();
} }
@ -211,12 +212,15 @@ public class ShareActivity extends MainActivity {
if (Intent.ACTION_SEND.equals(action) && type != null) { if (Intent.ACTION_SEND.equals(action) && type != null) {
if ("text/plain".equals(type)) { if ("text/plain".equals(type)) {
handleSendText(intent); // Handle text being sent TODO difference of "text/plain" intents with and without EXTRA_SUBJECT if (intent.hasExtra(Intent.EXTRA_SUBJECT)) {
handleSendSubject(intent);
} else {
handleSendText(intent);}
} else if (type.startsWith("image/")) { } else if (type.startsWith("image/")) {
// TODO Handle single image being sent // TODO Handle single image being sent -> see manifest
handleSendImage(intent); handleSendImage(intent);
} }
} else { //} else {
// Handle other intents, such as being started from the home screen // Handle other intents, such as being started from the home screen
} }
@ -231,6 +235,20 @@ public class ShareActivity extends MainActivity {
public void onPageFinished(WebView view, String url) { public void onPageFinished(WebView view, String url) {
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
finish();
Intent i = new Intent(ShareActivity.this, MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
return false;
}
});
webView.loadUrl("javascript:(function() { " + webView.loadUrl("javascript:(function() { " +
"document.getElementsByTagName('textarea')[0].style.height='110px'; " + "document.getElementsByTagName('textarea')[0].style.height='110px'; " +
"document.getElementsByTagName('textarea')[0].innerHTML = '> " + sharedText + " " + sharedBy + "'; " + "document.getElementsByTagName('textarea')[0].innerHTML = '> " + sharedText + " " + sharedBy + "'; " +
@ -244,11 +262,9 @@ public class ShareActivity extends MainActivity {
"})();"); "})();");
} }
}); });
// Update UI to reflect text being shared
} }
} }
// TODO difference of "text/plain" intents with and without EXTRA_SUBJECT
void handleSendSubject(Intent intent) { void handleSendSubject(Intent intent) {
final String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT); final String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
final String sharedSubject = intent.getStringExtra(Intent.EXTRA_SUBJECT); final String sharedSubject = intent.getStringExtra(Intent.EXTRA_SUBJECT);
@ -258,6 +274,20 @@ public class ShareActivity extends MainActivity {
public void onPageFinished(WebView view, String url) { public void onPageFinished(WebView view, String url) {
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
finish();
Intent i = new Intent(ShareActivity.this, MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
return false;
}
});
webView.loadUrl("javascript:(function() { " + webView.loadUrl("javascript:(function() { " +
"document.getElementsByTagName('textarea')[0].style.height='110px'; " + "document.getElementsByTagName('textarea')[0].style.height='110px'; " +
"document.getElementsByTagName('textarea')[0].innerHTML = '**" + sharedSubject + "** " + sharedText + " " + sharedBy + "'; " + "document.getElementsByTagName('textarea')[0].innerHTML = '**" + sharedSubject + "** " + sharedText + " " + sharedBy + "'; " +
@ -271,11 +301,10 @@ public class ShareActivity extends MainActivity {
"})();"); "})();");
} }
}); });
// Update UI to reflect text being shared
} }
} }
// TODO Handle single image being sent // TODO Handle single image being sent -> see manifest
void handleSendImage(Intent intent) { void handleSendImage(Intent intent) {
final Uri imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM); final Uri imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);