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

Fixed image upload on 4.2 devices

This commit is contained in:
vanitasvitae 2016-09-07 23:55:25 +02:00
parent 7dbfb10229
commit e6446217a8
2 changed files with 56 additions and 46 deletions

View file

@ -52,7 +52,7 @@
<activity <activity
android:name=".activity.MainActivity" android:name=".activity.MainActivity"
android:launchMode="singleInstance" android:launchMode="singleTop"
android:windowSoftInputMode="adjustPan" android:windowSoftInputMode="adjustPan"
android:configChanges="keyboardHidden|orientation|screenSize" android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@style/AppTheme.NoActionBar" android:theme="@style/AppTheme.NoActionBar"

View file

@ -52,9 +52,7 @@ import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.ActionMenuView; import android.support.v7.widget.ActionMenuView;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.util.Log; import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
@ -107,7 +105,8 @@ public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener, WebUserProfileChangedListener { implements NavigationView.OnNavigationItemSelectedListener, WebUserProfileChangedListener {
private static final int INPUT_FILE_REQUEST_CODE = 1; private static final int INPUT_FILE_REQUEST_CODE_NEW = 1;
private static final int INPUT_FILE_REQUEST_CODE_OLD = 2;
private static final int REQUEST_CODE_ASK_PERMISSIONS = 123; private static final int REQUEST_CODE_ASK_PERMISSIONS = 123;
public static final int REQUEST_CODE_ASK_PERMISSIONS_SAVE_IMAGE = 124; public static final int REQUEST_CODE_ASK_PERMISSIONS_SAVE_IMAGE = 124;
@ -121,7 +120,8 @@ public class MainActivity extends AppCompatActivity
public static final String CONTENT_HASHTAG = "content://com.github.dfa.diaspora_android.mainactivity/"; public static final String CONTENT_HASHTAG = "content://com.github.dfa.diaspora_android.mainactivity/";
private App app; private App app;
private ValueCallback<Uri[]> mFilePathCallback; private ValueCallback<Uri[]> imageUploadFilePathCallbackNew;
private ValueCallback<Uri> imageUploadFilePathCallbackOld;
private String mCameraPhotoPath; private String mCameraPhotoPath;
private WebSettings webSettings; private WebSettings webSettings;
private AppSettings appSettings; private AppSettings appSettings;
@ -353,28 +353,16 @@ public class MainActivity extends AppCompatActivity
} }
//For Android 4.1/4.2 only. DONT REMOVE //For Android 4.1/4.2 only. DONT REMOVE
protected void openFileChooser(ValueCallback<Uri[]> uploadMsg, String acceptType, String capture) protected void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture)
{ {
Log.d(App.TAG, "openFileChooser(ValCallback<Uri[]>, String, String"); Log.d(App.TAG, "openFileChooser(ValCallback<Uri>, String, String");
mFilePathCallback = uploadMsg; imageUploadFilePathCallbackOld = uploadMsg;
Intent intent = new Intent(); Intent intent = new Intent();
intent.setType("image/*"); intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT); intent.setAction(Intent.ACTION_GET_CONTENT);
intent.putExtra("return-data", true); intent.putExtra("return-data", true);
startActivityForResult(Intent.createChooser(intent, "Select Picture"),INPUT_FILE_REQUEST_CODE); intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
} startActivityForResult(Intent.createChooser(intent, "Select Picture"), INPUT_FILE_REQUEST_CODE_OLD);
//For Android 4.1/4.2 only. DONT REMOVE
protected void openFileChooser(ValueCallback<Uri[]> uploadMsg)
{
Log.d(App.TAG, "openFileChooser(ValCallback<Uri[]>");
onShowFileChooser(webView, uploadMsg, null);
/*
mUploadMessage = uploadMsg;
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("image/*");
startActivityForResult(Intent.createChooser(i, "File Chooser"), FILECHOOSER_RESULTCODE);
*/
} }
@Override @Override
@ -404,8 +392,8 @@ public class MainActivity extends AppCompatActivity
} }
Log.d(App.TAG, "onOpenFileChooser"); Log.d(App.TAG, "onOpenFileChooser");
if (mFilePathCallback != null) mFilePathCallback.onReceiveValue(null); if (imageUploadFilePathCallbackNew != null) imageUploadFilePathCallbackNew.onReceiveValue(null);
mFilePathCallback = filePathCallback; imageUploadFilePathCallbackNew = filePathCallback;
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) { if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
@ -448,7 +436,7 @@ public class MainActivity extends AppCompatActivity
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);
Log.d(App.TAG,"startActivityForResult"); Log.d(App.TAG,"startActivityForResult");
startActivityForResult(chooserIntent, INPUT_FILE_REQUEST_CODE); startActivityForResult(chooserIntent, INPUT_FILE_REQUEST_CODE_NEW);
return true; return true;
} }
}); });
@ -581,31 +569,53 @@ public class MainActivity extends AppCompatActivity
@Override @Override
public void onActivityResult(int requestCode, int resultCode, Intent data) { public void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d(App.TAG,"onActivityResult:"); Log.d(App.TAG,"onActivityResult:");
if (requestCode != INPUT_FILE_REQUEST_CODE || mFilePathCallback == null) { switch (requestCode) {
Log.d(App.TAG,"reqCode != INPUT_FILE_REQUEST_CODE or mFilePathCallback == null"); case INPUT_FILE_REQUEST_CODE_NEW: {
super.onActivityResult(requestCode, resultCode, data); Log.d(App.TAG,"INPUT_FILE_REQUEST_CODE_NEW:");
if (imageUploadFilePathCallbackNew == null || resultCode != Activity.RESULT_OK) {
Log.e(App.TAG, "Callback is null: " + (imageUploadFilePathCallbackNew == null)
+ " resultCode: " + resultCode);
return; return;
} }
Uri[] results = null; Uri[] results = null;
if (resultCode == Activity.RESULT_OK) {
Log.d(App.TAG, "Activity.RESULT_OK");
if (data == null) { if (data == null) {
Log.d(App.TAG, "data == null");
if (mCameraPhotoPath != null) { if (mCameraPhotoPath != null) {
Log.d(App.TAG, "mCameraPhotoPath != null");
results = new Uri[]{Uri.parse(mCameraPhotoPath)}; results = new Uri[]{Uri.parse(mCameraPhotoPath)};
} }
} else { } else {
Log.d(App.TAG, "data != null");
String dataString = data.getDataString(); String dataString = data.getDataString();
if (dataString != null) { if (dataString != null) {
Log.d(App.TAG, "dataString != null");
results = new Uri[]{Uri.parse(dataString)}; results = new Uri[]{Uri.parse(dataString)};
} }
} }
mFilePathCallback.onReceiveValue(results); imageUploadFilePathCallbackNew.onReceiveValue(results);
mFilePathCallback = null; imageUploadFilePathCallbackNew = null;
return;
} }
case INPUT_FILE_REQUEST_CODE_OLD: {
Log.d(App.TAG,"INPUT_FILE_REQUEST_CODE_OLD:");
if (imageUploadFilePathCallbackOld == null || resultCode != Activity.RESULT_OK) {
Log.e(App.TAG, "Callback is null: " + (imageUploadFilePathCallbackOld == null)
+ " resultCode: " + resultCode);
return;
}
Uri results = null;
if (data == null) {
if (mCameraPhotoPath != null) {
results = Uri.parse(mCameraPhotoPath);
}
} else {
String dataString = data.getDataString();
if (dataString != null) {
results = Uri.parse(dataString);
}
}
imageUploadFilePathCallbackOld.onReceiveValue(results);
imageUploadFilePathCallbackOld = null;
return;
}
}
super.onActivityResult(requestCode, resultCode, data);
} }
@Override @Override