1
1
package com .next .androidintentlibrary ;
2
2
3
3
import android .app .Activity ;
4
- import android .content .ActivityNotFoundException ;
5
4
import android .content .ComponentName ;
6
5
import android .content .Context ;
7
6
import android .content .Intent ;
11
10
import android .provider .MediaStore ;
12
11
13
12
import androidx .annotation .NonNull ;
14
- import androidx .appcompat .app .AppCompatActivity ;
15
-
16
- import android .widget .Toast ;
17
13
18
14
import java .io .File ;
19
15
import java .util .List ;
@@ -33,54 +29,53 @@ public static CameraIntents from(@NonNull Context context)
33
29
return new CameraIntents (context );
34
30
}
35
31
36
- public void recordCameraPhoto ( Uri location , String fileName )
32
+ public CameraIntents openPhotoCamera ( )
37
33
{
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 ;
44
42
}
45
43
46
- public void recordCameraVideo (Uri location , String fileName )
44
+ public CameraIntents capturePhoto (Uri location , String fileName )
47
45
{
48
- Intent intent = new Intent (MediaStore .ACTION_VIDEO_CAPTURE );
46
+ intent = new Intent (MediaStore .ACTION_IMAGE_CAPTURE );
49
47
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 ;
54
49
}
55
50
56
- public void openCameraPhoto ()
51
+ // TODO:
52
+ private CameraIntents capturePhoto (String file )
57
53
{
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 ;
63
58
}
64
59
65
- public void openCameraVideo ( )
60
+ public CameraIntents captureVideo ( Uri location , String fileName )
66
61
{
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 ;
72
65
}
73
66
74
- public static boolean isCropAvailable (Context context )
67
+ // TODO:
68
+ private boolean isCropAvailable ()
75
69
{
76
- Intent intent = new Intent ("com.android.camera.action.CROP" );
70
+ intent = new Intent ("com.android.camera.action.CROP" );
77
71
intent .setType ("image/*" );
78
- return isIntentAvailable (context , intent );
72
+ return isIntentAvailable (intent );
79
73
}
80
74
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 )
82
77
{
83
- Intent intent = new Intent ("com.android.camera.action.CROP" );
78
+ intent = new Intent ("com.android.camera.action.CROP" );
84
79
intent .setType ("image/*" );
85
80
86
81
List <ResolveInfo > list = context .getPackageManager ().queryIntentActivities (intent , 0 );
@@ -95,18 +90,10 @@ public static Intent cropImage(Context context, File image, int outputX, int out
95
90
intent .setData (Uri .fromFile (image ));
96
91
97
92
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 ;
107
94
}
108
95
109
- private static boolean isIntentAvailable (Context context , Intent intent )
96
+ private boolean isIntentAvailable (Intent intent )
110
97
{
111
98
PackageManager packageManager = context .getPackageManager ();
112
99
List <ResolveInfo > list = packageManager .queryIntentActivities (intent , PackageManager .MATCH_DEFAULT_ONLY );
@@ -131,9 +118,4 @@ public void show()
131
118
{
132
119
startActivity (build ());
133
120
}
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 ;
139
121
}
0 commit comments