11package com .next .androidintentlibrary ;
22
33import android .app .Activity ;
4- import android .content .ActivityNotFoundException ;
54import android .content .ComponentName ;
65import android .content .Context ;
76import android .content .Intent ;
1110import android .provider .MediaStore ;
1211
1312import androidx .annotation .NonNull ;
14- import androidx .appcompat .app .AppCompatActivity ;
15-
16- import android .widget .Toast ;
1713
1814import java .io .File ;
1915import 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}
0 commit comments