First pass at allowing user to share images from other apps to Mastalab. Currently only allows for single images.
This commit is contained in:
parent
18edbec7a6
commit
be47c3cead
|
@ -46,6 +46,16 @@
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
<data android:mimeType="text/plain" />
|
<data android:mimeType="text/plain" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.SEND" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
<data android:mimeType="image/*" />
|
||||||
|
</intent-filter>
|
||||||
|
<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>
|
||||||
<activity android:name="fr.gouv.etalab.mastodon.activities.LoginActivity"
|
<activity android:name="fr.gouv.etalab.mastodon.activities.LoginActivity"
|
||||||
android:windowSoftInputMode="stateAlwaysHidden"
|
android:windowSoftInputMode="stateAlwaysHidden"
|
||||||
|
|
|
@ -20,6 +20,7 @@ import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.graphics.PorterDuff;
|
import android.graphics.PorterDuff;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
@ -429,7 +430,7 @@ public class MainActivity extends AppCompatActivity
|
||||||
toolbarTitle.setText(R.string.home_menu);
|
toolbarTitle.setText(R.string.home_menu);
|
||||||
matchingIntent = true;
|
matchingIntent = true;
|
||||||
}
|
}
|
||||||
}else if( Intent.ACTION_SEND.equals(action) && type != null ){
|
}else if(( Intent.ACTION_SEND.equals(action) && type != null )) {
|
||||||
if ("text/plain".equals(type)) {
|
if ("text/plain".equals(type)) {
|
||||||
String sharedSubject = intent.getStringExtra(Intent.EXTRA_SUBJECT);
|
String sharedSubject = intent.getStringExtra(Intent.EXTRA_SUBJECT);
|
||||||
String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
|
String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
|
||||||
|
@ -442,6 +443,21 @@ public class MainActivity extends AppCompatActivity
|
||||||
startActivity(intentToot);
|
startActivity(intentToot);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (type.startsWith("image/"))
|
||||||
|
{
|
||||||
|
Uri imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
|
||||||
|
|
||||||
|
if (imageUri != null) {
|
||||||
|
|
||||||
|
Intent intentToot = new Intent(getApplicationContext(), TootActivity.class);
|
||||||
|
Bundle b = new Bundle();
|
||||||
|
|
||||||
|
b.putParcelable("sharedUri", imageUri);
|
||||||
|
intentToot.putExtras(b);
|
||||||
|
startActivity(intentToot);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
intent.replaceExtras(new Bundle());
|
intent.replaceExtras(new Bundle());
|
||||||
intent.setAction("");
|
intent.setAction("");
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
package fr.gouv.etalab.mastodon.activities;
|
package fr.gouv.etalab.mastodon.activities;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.net.Uri;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.content.ActivityNotFoundException;
|
import android.content.ActivityNotFoundException;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
@ -141,6 +142,7 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
|
||||||
private HorizontalScrollView picture_scrollview;
|
private HorizontalScrollView picture_scrollview;
|
||||||
private int currentCursorPosition, searchLength;
|
private int currentCursorPosition, searchLength;
|
||||||
private TextView toot_space_left;
|
private TextView toot_space_left;
|
||||||
|
private Uri sharedUri;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -231,6 +233,7 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
|
||||||
tootReply = b.getParcelable("tootReply");
|
tootReply = b.getParcelable("tootReply");
|
||||||
sharedContent = b.getString("sharedContent", null);
|
sharedContent = b.getString("sharedContent", null);
|
||||||
sharedSubject = b.getString("sharedSubject", null);
|
sharedSubject = b.getString("sharedSubject", null);
|
||||||
|
sharedUri = b.getParcelable("sharedUri");
|
||||||
restored = b.getLong("restored", -1);
|
restored = b.getLong("restored", -1);
|
||||||
}
|
}
|
||||||
if( restored != -1 ){
|
if( restored != -1 ){
|
||||||
|
@ -276,10 +279,16 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
|
||||||
}
|
}
|
||||||
toot_content.setText( String.format("\n%s", sharedContent));
|
toot_content.setText( String.format("\n%s", sharedContent));
|
||||||
}
|
}
|
||||||
|
|
||||||
attachments = new ArrayList<>();
|
attachments = new ArrayList<>();
|
||||||
int charsInCw = 0;
|
int charsInCw = 0;
|
||||||
int charsInToot = 0;
|
int charsInToot = 0;
|
||||||
|
|
||||||
|
if (sharedUri != null)
|
||||||
|
{
|
||||||
|
uploadSharedImage(sharedUri);
|
||||||
|
}
|
||||||
|
|
||||||
boolean isAccountPrivate = account.isLocked();
|
boolean isAccountPrivate = account.isLocked();
|
||||||
|
|
||||||
if(isAccountPrivate){
|
if(isAccountPrivate){
|
||||||
|
@ -483,6 +492,26 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
|
||||||
mToast.show();
|
mToast.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void uploadSharedImage(Uri uri)
|
||||||
|
{
|
||||||
|
picture_scrollview.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
if (uri != null) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
InputStream inputStream = getContentResolver().openInputStream(uri);
|
||||||
|
loading_picture.setVisibility(View.VISIBLE);
|
||||||
|
toot_picture.setEnabled(false);
|
||||||
|
new UploadActionAsyncTask(getApplicationContext(), inputStream, TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
Toast.makeText(getApplicationContext(), R.string.toot_select_image_error, Toast.LENGTH_LONG).show();
|
||||||
|
loading_picture.setVisibility(View.GONE);
|
||||||
|
toot_picture.setEnabled(true);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
|
Loading…
Reference in New Issue