allow using the app as an image chooser
This commit is contained in:
parent
fd01e7dca5
commit
b36e85844d
|
@ -18,6 +18,12 @@
|
|||
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.PICK"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
<data android:mimeType="vnd.android.cursor.dir/image"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
|
|
|
@ -3,4 +3,5 @@ package com.simplemobiletools.gallery;
|
|||
public class Constants {
|
||||
public static final String DIRECTORY = "directory";
|
||||
public static final String MEDIUM = "medium";
|
||||
public static final String PICK_INTENT = "is_pick_intent";
|
||||
}
|
||||
|
|
|
@ -47,6 +47,7 @@ public class MainActivity extends AppCompatActivity
|
|||
@BindView(R.id.directories_grid) GridView gridView;
|
||||
|
||||
private static final int STORAGE_PERMISSION = 1;
|
||||
private static final int PICK_IMAGE = 2;
|
||||
private List<Directory> dirs;
|
||||
private int selectedItemsCnt;
|
||||
private Snackbar snackbar;
|
||||
|
@ -318,11 +319,27 @@ public class MainActivity extends AppCompatActivity
|
|||
});
|
||||
}
|
||||
|
||||
private boolean isPickIntent(Intent intent) {
|
||||
return intent != null && intent.getAction() != null && intent.getAction().equals(Intent.ACTION_PICK);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (requestCode == PICK_IMAGE && resultCode == RESULT_OK && data != null) {
|
||||
final Intent result = new Intent();
|
||||
result.setData(data.getData());
|
||||
setResult(RESULT_OK, result);
|
||||
finish();
|
||||
}
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
final Intent intent = new Intent(this, MediaActivity.class);
|
||||
intent.putExtra(Constants.DIRECTORY, dirs.get(position).getPath());
|
||||
startActivity(intent);
|
||||
intent.putExtra(Constants.PICK_INTENT, isPickIntent(getIntent()));
|
||||
startActivityForResult(intent, PICK_IMAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -234,9 +234,16 @@ public class MediaActivity extends AppCompatActivity
|
|||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
final Intent intent = new Intent(this, ViewPagerActivity.class);
|
||||
intent.putExtra(Constants.MEDIUM, media.get(position).getPath());
|
||||
startActivity(intent);
|
||||
if (getIntent().getBooleanExtra(Constants.PICK_INTENT, false)) {
|
||||
final Intent result = new Intent();
|
||||
result.setData(Uri.parse(media.get(position).getPath()));
|
||||
setResult(RESULT_OK, result);
|
||||
finish();
|
||||
} else {
|
||||
final Intent intent = new Intent(this, ViewPagerActivity.class);
|
||||
intent.putExtra(Constants.MEDIUM, media.get(position).getPath());
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue