Skip to content

Commit 3023572

Browse files
committed
library ready for release 1.0.
1 parent 92f8dcd commit 3023572

17 files changed

+477
-667
lines changed

Library/src/main/java/com/next/androidintentlibrary/BrowserIntents.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@
44
import android.content.Context;
55
import android.content.Intent;
66
import android.net.Uri;
7+
import android.text.TextUtils;
78

89
import androidx.annotation.NonNull;
910

10-
import android.text.TextUtils;
11-
1211
public class BrowserIntents
1312
{
1413
private Context context;
15-
protected Intent intent;
14+
private Intent intent;
1615

1716
private BrowserIntents(Context context)
1817
{
Lines changed: 31 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.next.androidintentlibrary;
22

33
import android.app.Activity;
4-
import android.content.ActivityNotFoundException;
54
import android.content.ComponentName;
65
import android.content.Context;
76
import android.content.Intent;
@@ -11,9 +10,6 @@
1110
import android.provider.MediaStore;
1211

1312
import androidx.annotation.NonNull;
14-
import androidx.appcompat.app.AppCompatActivity;
15-
16-
import android.widget.Toast;
1713

1814
import java.io.File;
1915
import java.util.List;
@@ -33,54 +29,53 @@ public static CameraIntents from(@NonNull Context context)
3329
return new CameraIntents(context);
3430
}
3531

36-
public void recordCameraPhoto(Uri location, String fileName)
32+
public CameraIntents openPhotoCamera()
3733
{
38-
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
39-
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.withAppendedPath(location, fileName));
40-
if (intent.resolveActivity(context.getPackageManager()) == null)
41-
Toast.makeText(context, "No Activity Was Found To Handle This Intent", Toast.LENGTH_LONG).show();
42-
else
43-
((AppCompatActivity) context).startActivityForResult(intent, REQUEST_IMAGE_CAPTURE);
34+
intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
35+
return this;
36+
}
37+
38+
public CameraIntents openVideoCamera()
39+
{
40+
intent = new Intent(MediaStore.INTENT_ACTION_VIDEO_CAMERA);
41+
return this;
4442
}
4543

46-
public void recordCameraVideo(Uri location, String fileName)
44+
public CameraIntents capturePhoto(Uri location, String fileName)
4745
{
48-
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
46+
intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
4947
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.withAppendedPath(location, fileName));
50-
if (intent.resolveActivity(context.getPackageManager()) == null)
51-
Toast.makeText(context, "No Activity Was Found To Handle This Intent", Toast.LENGTH_LONG).show();
52-
else
53-
((AppCompatActivity) context).startActivityForResult(intent, REQUEST_VIDEO_CAPTURE);
48+
return this;
5449
}
5550

56-
public void openCameraPhoto()
51+
// TODO:
52+
private CameraIntents capturePhoto(String file)
5753
{
58-
Intent intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
59-
if (intent.resolveActivity(context.getPackageManager()) == null)
60-
Toast.makeText(context, "No Activity Was Found To Handle This Intent", Toast.LENGTH_LONG).show();
61-
else
62-
((AppCompatActivity) context).startActivityForResult(intent, REQUEST_STILL_IMAGE_CAMERA);
54+
Uri uri = Uri.fromFile(new File(file));
55+
intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
56+
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
57+
return this;
6358
}
6459

65-
public void openCameraVideo()
60+
public CameraIntents captureVideo(Uri location, String fileName)
6661
{
67-
Intent intent = new Intent(MediaStore.INTENT_ACTION_VIDEO_CAMERA);
68-
if (intent.resolveActivity(context.getPackageManager()) == null)
69-
Toast.makeText(context, "No Activity Was Found To Handle This Intent", Toast.LENGTH_LONG).show();
70-
else
71-
((AppCompatActivity) context).startActivityForResult(intent, REQUEST_ACTION_VIDEO_CAMERA);
62+
intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
63+
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.withAppendedPath(location, fileName));
64+
return this;
7265
}
7366

74-
public static boolean isCropAvailable(Context context)
67+
// TODO:
68+
private boolean isCropAvailable()
7569
{
76-
Intent intent = new Intent("com.android.camera.action.CROP");
70+
intent = new Intent("com.android.camera.action.CROP");
7771
intent.setType("image/*");
78-
return isIntentAvailable(context, intent);
72+
return isIntentAvailable(intent);
7973
}
8074

81-
public static Intent cropImage(Context context, File image, int outputX, int outputY, int aspectX, int aspectY, boolean scale)
75+
// TODO:
76+
private CameraIntents cropImage(File image, int outputX, int outputY, int aspectX, int aspectY, boolean scale)
8277
{
83-
Intent intent = new Intent("com.android.camera.action.CROP");
78+
intent = new Intent("com.android.camera.action.CROP");
8479
intent.setType("image/*");
8580

8681
List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(intent, 0);
@@ -95,18 +90,10 @@ public static Intent cropImage(Context context, File image, int outputX, int out
9590
intent.setData(Uri.fromFile(image));
9691

9792
intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
98-
return intent;
99-
}
100-
101-
public static Intent photoCapture(String file)
102-
{
103-
Uri uri = Uri.fromFile(new File(file));
104-
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
105-
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
106-
return intent;
93+
return this;
10794
}
10895

109-
private static boolean isIntentAvailable(Context context, Intent intent)
96+
private boolean isIntentAvailable(Intent intent)
11097
{
11198
PackageManager packageManager = context.getPackageManager();
11299
List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
@@ -131,9 +118,4 @@ public void show()
131118
{
132119
startActivity(build());
133120
}
134-
135-
public static final int REQUEST_IMAGE_CAPTURE = 1;
136-
public static final int REQUEST_VIDEO_CAPTURE = 2;
137-
public static final int REQUEST_STILL_IMAGE_CAMERA = 3;
138-
public static final int REQUEST_ACTION_VIDEO_CAMERA = 4;
139121
}

Library/src/main/java/com/next/androidintentlibrary/FileIntents.java

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,49 +26,37 @@ public static FileIntents from(@NonNull Context context)
2626
return new FileIntents(context);
2727
}
2828

29-
public FileIntents retrievAnSpecificTypeOfFile(Boolean allowMultiple, Boolean localOnly)
29+
public FileIntents fileChooser()
3030
{
3131
intent = new Intent(Intent.ACTION_GET_CONTENT);
32-
intent.setType("image/*");
33-
intent.addCategory(CATEGORY_OPENABLE);
34-
intent.putExtra(intent.EXTRA_ALLOW_MULTIPLE, allowMultiple);
35-
intent.putExtra(intent.EXTRA_LOCAL_ONLY, localOnly);
32+
intent.setType("*/*");
33+
intent.addCategory(Intent.CATEGORY_OPENABLE);
34+
intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
3635
return this;
3736
}
3837

39-
// TODO: 8/30/2017 Error close program
40-
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
41-
public FileIntents openAnSpecificTypeOfFile(String[] mimeType, Boolean allowMultiple, Boolean localOnly)
38+
public FileIntents pickFile()
4239
{
43-
intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
44-
// TODO: 8/30/2017 Primary MimeType for Bellow Line Is "*/*".
45-
intent.putExtra(intent.EXTRA_MIME_TYPES, mimeType);
46-
intent.putExtra(intent.EXTRA_ALLOW_MULTIPLE, allowMultiple);
47-
// TODO: 8/30/2017 I think bellow line used for this Action : ACTION_CREATE_DOCUMENT
48-
//intent.putExtra(intent.EXTRA_TITLE ,allowMultiple);
49-
intent.putExtra(intent.EXTRA_LOCAL_ONLY, localOnly);
50-
intent.addCategory(CATEGORY_OPENABLE);
40+
intent = new Intent(Intent.ACTION_GET_CONTENT);
41+
intent.setType("file/*");
5142
return this;
5243
}
5344

54-
// TODO: 8/30/2017 Error close program
55-
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
56-
public FileIntents createAnSpecificTypeOfFile(String[] mimeType, Boolean allowMultiple, String title, Boolean localOnly)
45+
public FileIntents pickImageFile()
5746
{
58-
intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
59-
// TODO: 8/30/2017 Primary MimeType for Bellow Line Is "*/*".
60-
intent.putExtra(intent.EXTRA_MIME_TYPES, mimeType);
61-
intent.putExtra(intent.EXTRA_ALLOW_MULTIPLE, allowMultiple);
62-
intent.putExtra(intent.EXTRA_TITLE, title);
63-
intent.putExtra(intent.EXTRA_LOCAL_ONLY, localOnly);
64-
intent.addCategory(CATEGORY_OPENABLE);
47+
intent = new Intent(Intent.ACTION_GET_CONTENT);
48+
intent.setType("image/*");
6549
return this;
6650
}
6751

68-
public FileIntents pickFile()
52+
// TODO: overload for other file types
53+
public FileIntents pickImageFile(Boolean allowMultiple, Boolean localOnly)
6954
{
7055
intent = new Intent(Intent.ACTION_GET_CONTENT);
71-
intent.setType("file/*");
56+
intent.setType("image/*");
57+
intent.addCategory(CATEGORY_OPENABLE);
58+
intent.putExtra(intent.EXTRA_ALLOW_MULTIPLE, allowMultiple);
59+
intent.putExtra(intent.EXTRA_LOCAL_ONLY, localOnly);
7260
return this;
7361
}
7462

@@ -90,4 +78,4 @@ public void show()
9078
{
9179
startActivity(build());
9280
}
93-
}
81+
}

Library/src/main/java/com/next/androidintentlibrary/GalleryIntents.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public GalleryIntents openGallery()
2727
intent.setAction(Intent.ACTION_MAIN);
2828
intent.addCategory(Intent.CATEGORY_APP_GALLERY);
2929
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
30+
// or
31+
// intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI));
3032
return this;
3133
}
3234

0 commit comments

Comments
 (0)