Skip to content

Commit 0d904a7

Browse files
committed
Update demo application
1 parent fd6b821 commit 0d904a7

File tree

3 files changed

+83
-26
lines changed

3 files changed

+83
-26
lines changed

.idea/misc.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/java/com/hbisoft/pickitexample/MainActivity.java

Lines changed: 57 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ public class MainActivity extends AppCompatActivity implements PickiTCallbacks {
4444
PickiT pickiT;
4545

4646
//Views
47-
Button button_pick;
47+
Button button_pick_video, button_pick_image;
4848
TextView pickitTv, originalTv, originalTitle, pickitTitle;
49+
String videoImageRef = "";
4950

5051
@Override
5152
protected void onCreate(Bundle savedInstanceState) {
@@ -66,16 +67,28 @@ private void showLongToast(final String msg) {
6667
}
6768

6869
private void init() {
69-
button_pick = findViewById(R.id.button_pick);
70+
button_pick_video = findViewById(R.id.button_pick_video);
71+
button_pick_image = findViewById(R.id.button_pick_image);
7072
pickitTv = findViewById(R.id.pickitTv);
7173
originalTv = findViewById(R.id.originalTv);
7274
originalTitle = findViewById(R.id.originalTitle);
7375
pickitTitle = findViewById(R.id.pickitTitle);
7476
}
7577

7678
private void buttonClickEvent() {
77-
button_pick.setOnClickListener(view -> {
78-
openGallery();
79+
button_pick_video.setOnClickListener(view -> {
80+
videoImageRef = "video";
81+
openGallery("video");
82+
83+
// Make TextView's invisible
84+
originalTitle.setVisibility(View.INVISIBLE);
85+
originalTv.setVisibility(View.INVISIBLE);
86+
pickitTitle.setVisibility(View.INVISIBLE);
87+
pickitTv.setVisibility(View.INVISIBLE);
88+
});
89+
button_pick_image.setOnClickListener(view -> {
90+
videoImageRef = "image";
91+
openGallery("image");
7992

8093
// Make TextView's invisible
8194
originalTitle.setVisibility(View.INVISIBLE);
@@ -85,24 +98,44 @@ private void buttonClickEvent() {
8598
});
8699
}
87100

88-
private void openGallery() {
101+
private void openGallery(String videoOrImage) {
89102
// first check if permissions was granted
90103
if (checkSelfPermission()) {
91-
Intent intent;
92-
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
93-
intent = new Intent(Intent.ACTION_PICK, MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
94-
} else {
95-
intent = new Intent(Intent.ACTION_PICK, MediaStore.Video.Media.INTERNAL_CONTENT_URI);
96-
}
97-
// In this example we will set the type to video
98-
intent.setType("video/*");
99-
intent.setAction(Intent.ACTION_GET_CONTENT);
100-
intent.putExtra("return-data", true);
101-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
102-
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
104+
if (videoImageRef.equals("video")) {
105+
videoImageRef = "";
106+
Intent intent;
107+
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
108+
intent = new Intent(Intent.ACTION_PICK, MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
109+
} else {
110+
intent = new Intent(Intent.ACTION_PICK, MediaStore.Video.Media.INTERNAL_CONTENT_URI);
111+
}
112+
// In this example we will set the type to video
113+
intent.setType("video/*");
114+
intent.setAction(Intent.ACTION_GET_CONTENT);
115+
intent.putExtra("return-data", true);
116+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
117+
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
118+
}
119+
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
120+
activityResultLauncher.launch(intent);
121+
}else{
122+
videoImageRef = "";
123+
Intent intent;
124+
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
125+
intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
126+
} else {
127+
intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI);
128+
}
129+
// In this example we will set the type to video
130+
intent.setType("image/*");
131+
intent.setAction(Intent.ACTION_GET_CONTENT);
132+
intent.putExtra("return-data", true);
133+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
134+
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
135+
}
136+
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
137+
activityResultLauncher.launch(intent);
103138
}
104-
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
105-
activityResultLauncher.launch(intent);
106139
}
107140
}
108141

@@ -122,7 +155,11 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
122155
if (requestCode == PERMISSION_REQ_ID_WRITE_EXTERNAL_STORAGE) {
123156
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
124157
// Permissions was granted, open the gallery
125-
openGallery();
158+
if (videoImageRef.equals("video")) {
159+
openGallery("video");
160+
}else{
161+
openGallery("image");
162+
}
126163
}
127164
// Permissions was not granted
128165
else {

app/src/main/res/layout/activity_main.xml

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,35 @@
5454
android:id="@+id/pickitTv"
5555
android:visibility="invisible"/>
5656

57-
<RelativeLayout
57+
<LinearLayout
5858
android:id="@+id/button_holder"
5959
android:layout_width="match_parent"
6060
android:layout_height="wrap_content"
6161
android:layout_alignParentBottom="true"
62-
android:background="@color/colorPrimary">
62+
android:background="@color/colorPrimary"
63+
android:orientation="horizontal"
64+
android:weightSum="2">
6365

6466
<Button
65-
android:id="@+id/button_pick"
67+
android:id="@+id/button_pick_video"
6668
android:layout_width="match_parent"
6769
android:layout_height="wrap_content"
6870
android:background="@drawable/ripple_effect"
69-
android:text="@string/pick_file"
71+
android:text="Pick Video"
7072
android:textColor="@android:color/white"
71-
tools:text="@string/pick_file" />
73+
android:layout_weight="1"
74+
/>
7275

73-
</RelativeLayout>
76+
<Button
77+
android:id="@+id/button_pick_image"
78+
android:layout_width="match_parent"
79+
android:layout_height="wrap_content"
80+
android:background="@drawable/ripple_effect"
81+
android:text="Pick Image"
82+
android:textColor="@android:color/white"
83+
android:layout_weight="1"
84+
/>
85+
86+
</LinearLayout>
7487

7588
</RelativeLayout>

0 commit comments

Comments
 (0)