11package ir .smartdevelopers .smartfilebrowser .acitivties ;
22
3- import androidx .activity .OnBackPressedCallback ;
4- import androidx .annotation .NonNull ;
5- import androidx .annotation .Nullable ;
6- import androidx .appcompat .app .AppCompatActivity ;
7- import androidx .appcompat .widget .AppCompatTextView ;
8- import androidx .constraintlayout .widget .Group ;
9- import androidx .core .app .ActivityCompat ;
10- import androidx .core .app .ActivityOptionsCompat ;
11- import androidx .core .app .SharedElementCallback ;
12- import androidx .core .content .ContextCompat ;
13- import androidx .core .content .FileProvider ;
14- import androidx .core .graphics .Insets ;
15- import androidx .core .graphics .drawable .DrawableKt ;
16- import androidx .core .view .ViewCompat ;
17- import androidx .core .view .WindowCompat ;
18- import androidx .core .view .WindowInsetsCompat ;
19- import androidx .interpolator .view .animation .FastOutSlowInInterpolator ;
20- import androidx .lifecycle .LiveData ;
21- import androidx .lifecycle .Observer ;
22- import androidx .lifecycle .ViewModelProvider ;
23- import androidx .recyclerview .widget .LinearLayoutManager ;
24- import androidx .recyclerview .widget .RecyclerView ;
25-
263import android .Manifest ;
274import android .animation .Animator ;
285import android .animation .AnimatorListenerAdapter ;
3916import android .graphics .Color ;
4017import android .graphics .Rect ;
4118import android .graphics .drawable .ColorDrawable ;
19+ import android .graphics .drawable .Drawable ;
4220import android .net .Uri ;
4321import android .os .Build ;
4422import android .os .Bundle ;
6745import android .widget .TextView ;
6846import android .widget .Toast ;
6947
48+ import androidx .activity .OnBackPressedCallback ;
49+ import androidx .annotation .NonNull ;
50+ import androidx .annotation .Nullable ;
51+ import androidx .appcompat .app .AppCompatActivity ;
52+ import androidx .appcompat .content .res .AppCompatResources ;
53+ import androidx .appcompat .widget .AppCompatTextView ;
54+ import androidx .constraintlayout .widget .Group ;
55+ import androidx .core .app .ActivityCompat ;
56+ import androidx .core .app .ActivityOptionsCompat ;
57+ import androidx .core .app .SharedElementCallback ;
58+ import androidx .core .content .ContextCompat ;
59+ import androidx .core .content .FileProvider ;
60+ import androidx .core .graphics .Insets ;
61+ import androidx .core .graphics .drawable .DrawableKt ;
62+ import androidx .core .view .ViewCompat ;
63+ import androidx .core .view .WindowCompat ;
64+ import androidx .core .view .WindowInsetsCompat ;
65+ import androidx .exifinterface .media .ExifInterface ;
66+ import androidx .interpolator .view .animation .FastOutSlowInInterpolator ;
67+ import androidx .lifecycle .LiveData ;
68+ import androidx .lifecycle .Observer ;
69+ import androidx .lifecycle .ViewModelProvider ;
70+ import androidx .recyclerview .widget .LinearLayoutManager ;
71+ import androidx .recyclerview .widget .RecyclerView ;
7072
7173import com .aurelhubert .ahbottomnavigation .AHBottomNavigation ;
7274import com .aurelhubert .ahbottomnavigation .AHBottomNavigationItem ;
73-
7475import com .google .android .material .appbar .AppBarLayout ;
7576import com .google .android .material .bottomsheet .BottomSheetBehavior ;
7677
8788import ir .smartdevelopers .smartfilebrowser .adapters .AlbumAdapter ;
8889import ir .smartdevelopers .smartfilebrowser .adapters .FileBrowserAdapter ;
8990import ir .smartdevelopers .smartfilebrowser .adapters .GalleryAdapter ;
91+ import ir .smartdevelopers .smartfilebrowser .customClasses .FileUtil ;
9092import ir .smartdevelopers .smartfilebrowser .customClasses .GalleryLayoutManager ;
9193import ir .smartdevelopers .smartfilebrowser .customClasses .GalleyItemDecoration ;
9294import ir .smartdevelopers .smartfilebrowser .customClasses .MyBehavior ;
93- import ir .smartdevelopers .smartfilebrowser .customClasses .OnItemLongClickListener ;
94- import ir .smartdevelopers .smartfilebrowser .customClasses .OnSearchListener ;
95- import ir .smartdevelopers .smartfilebrowser .customClasses .ResultListener ;
96- import ir .smartdevelopers .smartfilebrowser .customClasses .Utils ;
97- import ir .smartdevelopers .smartfilebrowser .models .FileModel ;
98- import ir .smartdevelopers .smartfilebrowser .customClasses .FileUtil ;
9995import ir .smartdevelopers .smartfilebrowser .customClasses .OnItemChooseListener ;
10096import ir .smartdevelopers .smartfilebrowser .customClasses .OnItemClickListener ;
97+ import ir .smartdevelopers .smartfilebrowser .customClasses .OnItemLongClickListener ;
10198import ir .smartdevelopers .smartfilebrowser .customClasses .OnItemSelectListener ;
99+ import ir .smartdevelopers .smartfilebrowser .customClasses .OnSearchListener ;
100+ import ir .smartdevelopers .smartfilebrowser .customClasses .ResultListener ;
102101import ir .smartdevelopers .smartfilebrowser .customClasses .RoundLinearLayout ;
103102import ir .smartdevelopers .smartfilebrowser .customClasses .SFBFileFilter ;
104103import ir .smartdevelopers .smartfilebrowser .customClasses .SearchView ;
104+ import ir .smartdevelopers .smartfilebrowser .customClasses .Utils ;
105105import ir .smartdevelopers .smartfilebrowser .models .AlbumModel ;
106106import ir .smartdevelopers .smartfilebrowser .models .FileBrowserModel ;
107+ import ir .smartdevelopers .smartfilebrowser .models .FileModel ;
107108import ir .smartdevelopers .smartfilebrowser .models .GalleryModel ;
108109import ir .smartdevelopers .smartfilebrowser .viewModel .FilesViewModel ;
109110import ir .smartdevelopers .smartfilebrowser .viewModel .GalleryViewModel ;
@@ -244,8 +245,9 @@ public boolean accept(File pathname) {
244245
245246 @ Override
246247 protected void onCreate (Bundle savedInstanceState ) {
247- setTheme (R .style .sfb_MainAppTheme_sfb_AppTheme );
248+ setTheme (R .style .sfb_AppTheme );
248249 Window window = getWindow ();
250+ // window.setSharedElementsUseOverlay(false);
249251 WindowCompat .enableEdgeToEdge (window );
250252 window .setBackgroundDrawable (new ColorDrawable (Color .TRANSPARENT ));
251253 window .addFlags (WindowManager .LayoutParams .FLAG_DIM_BEHIND );
@@ -732,11 +734,11 @@ public void onItemClicked(GalleryModel model, View view, int position) {
732734 }
733735 };
734736 }
735-
736737 private void openVideoActivity (GalleryModel model , View view , int position ) {
737738 Uri uri = FileProvider .getUriForFile (this , getPackageName () + ".sfb_provider" , model .getCurrentFile ());
738739 Intent videoActivityIntent = new Intent (this , VideoViewActivity .class );
739740 videoActivityIntent .setData (uri );
741+
740742 Bundle options = null ;
741743 if (view != null ) {
742744 String sharedName = ViewCompat .getTransitionName (view );
@@ -746,7 +748,8 @@ private void openVideoActivity(GalleryModel model, View view, int position) {
746748 options = ActivityOptionsCompat .makeSceneTransitionAnimation (this , view , sharedName ).toBundle ();
747749 videoActivityIntent .putExtra (VideoViewActivity .KEY_TRANSITION_NAME , sharedName );
748750 }
749- ActivityCompat .startActivity (this , videoActivityIntent , options );
751+ ActivityCompat .startActivityForResult (this ,videoActivityIntent ,696987 , options );
752+ // ContextCompat.startActivity(this,videoActivityIntent, options);
750753 }
751754
752755 private void openImageEditor (GalleryModel model , View view , int position ) {
@@ -758,11 +761,13 @@ private void openImageEditor(GalleryModel model, View view, int position) {
758761 Intent editorIntent = new Intent (this , PhotoEditorActivity .class );
759762 editorIntent .setData (uri );
760763 if (view instanceof ImageView ){
761- Rect rect = Utils .calculateBitmapBound (getResources (),model );
762- Bitmap preview = DrawableKt .toBitmap (((ImageView ) view ).getDrawable (),rect .width (),rect .height (), Bitmap .Config .ARGB_8888 );
763-
764- PhotoEditorActivity .Preview = preview ;
764+ Drawable d = ((ImageView ) view ).getDrawable ();
765+ if (d != null ){
766+ Rect rect = Utils .calculateBitmapBound (getResources (),model );
767+ PhotoEditorActivity .Preview = DrawableKt .toBitmap (d ,rect .width (),rect .height (), Bitmap .Config .ARGB_8888 );
768+ }
765769 }
770+
766771 editorIntent .putExtra (PhotoEditorActivity .KEY_SAVE_PATH , mEditedImagePath );
767772 Bundle options = null ;
768773 if (view != null ) {
@@ -804,25 +809,39 @@ private void setFileBrowserEnabled(boolean enabled) {
804809 mFileBrowserEnabled = enabled ;
805810 }
806811
807-
812+ private AHBottomNavigationItem createNavItem (int colorAttr , int titleRes , int iconRes ){
813+ TypedValue value = new TypedValue ();
814+ getTheme ().resolveAttribute (colorAttr ,value ,true );
815+ return new AHBottomNavigationItem (
816+ getString (titleRes ),
817+ AppCompatResources .getDrawable (this ,iconRes ),
818+ value .data );
819+ }
808820 private void initViews (Bundle savedInstanceState ) {
809821
822+ int [] attrs ={R .attr .SFBColorGallery ,R .attr .SFBColorPDF ,R .attr .SFBColorAudio ,R .attr .SFBColorFile };
823+
810824 if (mShowGalleryTab ) {
811- AHBottomNavigationItem gallery = new AHBottomNavigationItem (R .string .sfb_gallery , R .drawable .sfb_ic_gallery , R .color .sfb_color_gallery );
812- mBottomNavigationView .addItem (gallery );
825+ mBottomNavigationView .addItem (createNavItem (attrs [0 ],R .string .sfb_gallery ,R .drawable .sfb_ic_gallery ));
813826 }
814827 if (mShowPDFTab ) {
815- AHBottomNavigationItem pdf = new AHBottomNavigationItem (R .string .sfb_PDF , R .drawable .sfb_ic_pdf , R .color .sfb_color_pdf );
816- mBottomNavigationView .addItem (pdf );
828+ mBottomNavigationView .addItem (createNavItem (attrs [1 ],R .string .sfb_PDF , R .drawable .sfb_ic_pdf ));
817829 }
818830 if (mShowAudioTab ) {
819- AHBottomNavigationItem audio = new AHBottomNavigationItem (R .string .sfb_audio , R .drawable .sfb_ic_square_audio , R .color .sfb_color_audio );
820- mBottomNavigationView .addItem (audio );
831+ mBottomNavigationView .addItem (createNavItem (attrs [2 ],R .string .sfb_audio , R .drawable .sfb_ic_square_audio ));
821832 }
822833 if (mShowFilesTab ) {
823- AHBottomNavigationItem files = new AHBottomNavigationItem (R .string .sfb_file , R .drawable .sfb_ic_file , R .color .sfb_color_file );
824- mBottomNavigationView .addItem (files );
825- }
834+ mBottomNavigationView .addItem (createNavItem (attrs [3 ],R .string .sfb_file , R .drawable .sfb_ic_file ));
835+ }
836+ TypedValue value = new TypedValue ();
837+ getTheme ().resolveAttribute (R .attr .SFBBottomNavActiveColor ,value ,true );
838+ int colorActive = value .data ;
839+ getTheme ().resolveAttribute (R .attr .SFBBottomNavInactiveColor ,value ,true );
840+ int colorInactive = value .data ;
841+ mBottomNavigationView .setColoredModeColors (colorActive ,colorInactive );
842+ getTheme ().resolveAttribute (R .attr .SFBBottomNavColorDisabled ,value ,true );
843+ int colorDisabled = value .data ;
844+ mBottomNavigationView .setItemDisableColor (colorDisabled );
826845 mBottomNavigationView .setOnTabSelectedListener (mOnMenuItemSelectionListener );
827846 mBottomNavigationView .setColored (true );
828847 mBottomNavigationView .setUseElevation (true );
@@ -1213,7 +1232,7 @@ public void onChanged(List<AlbumModel> albumModels) {
12131232 mAlbumListIsShowing = true ;
12141233 int duration = animate ? 100 : 0 ;
12151234 FrameLayout albumPlaceHolderRoot = findViewById (R .id .fileBrowser_activity_main_albumPlaceHolderRoot );
1216-
1235+ albumPlaceHolderRoot . setAlpha ( 0 );
12171236 mAlbumPlaceHolder .post (() -> {
12181237 AppCompatTextView spnSelectAlbum = findViewById (R .id .fileBrowser_activity_main_spnSelectAlbum );
12191238 int [] location = new int [2 ];
@@ -1223,6 +1242,18 @@ public void onChanged(List<AlbumModel> albumModels) {
12231242 mAlbumPlaceHolder .setX (x );
12241243 mAlbumPlaceHolder .setY (y );
12251244 mAlbumPlaceHolder .animate ().setDuration (duration ).scaleY (1 ).scaleX (1 ).alpha (1 )
1245+ .setUpdateListener (new ValueAnimator .AnimatorUpdateListener () {
1246+ @ Override
1247+ public void onAnimationUpdate (@ NonNull ValueAnimator animation ) {
1248+ float alpha = 0 ;
1249+ if (mAlbumListIsShowing ){
1250+ alpha = animation .getAnimatedFraction ();
1251+ }else {
1252+ alpha = 1 - animation .getAnimatedFraction ();
1253+ }
1254+ albumPlaceHolderRoot .setAlpha (alpha );
1255+ }
1256+ })
12261257 .withStartAction (() -> {
12271258 mAlbumPlaceHolder .setAlpha (0 );
12281259 mAlbumPlaceHolder .setScaleY (0 );
@@ -1237,6 +1268,9 @@ public void onChanged(List<AlbumModel> albumModels) {
12371268 @ SuppressLint ("ClickableViewAccessibility" )
12381269 @ Override
12391270 public boolean onTouch (View v , MotionEvent event ) {
1271+ if (!mAlbumListIsShowing ){
1272+ return false ;
1273+ }
12401274 hideAlbumList (true );
12411275 return true ;
12421276 }
@@ -1879,15 +1913,43 @@ protected void onActivityResult(int requestCode, int resultCode, @Nullable Inten
18791913 if (requestCode == REQ_CODE_TACK_PICTURE ) {
18801914 if (resultCode == Activity .RESULT_OK ) {
18811915 File takenPic = new File (tackingPictureFilePath );
1916+
18821917 if (takenPic .isFile ()) {
1918+ int width = 0 ;
1919+ int height = 0 ;
1920+ int orientation = 0 ;
1921+
18831922 FileUtil .scanMediaFile (this , takenPic );
1923+ try {
1924+ ExifInterface exifInterface = new ExifInterface (takenPic );
1925+ width = exifInterface .getAttributeInt (ExifInterface .TAG_IMAGE_WIDTH , 0 );
1926+ height = exifInterface .getAttributeInt (ExifInterface .TAG_IMAGE_LENGTH , 0 );
1927+ int orint = exifInterface .getAttributeInt (ExifInterface .TAG_ORIENTATION , 0 );
1928+ switch (orint ) {
1929+ case ExifInterface .ORIENTATION_ROTATE_90 :
1930+ orientation = 90 ;
1931+ break ;
1932+ case ExifInterface .ORIENTATION_ROTATE_180 :
1933+ orientation = 180 ;
1934+ break ;
1935+ case ExifInterface .ORIENTATION_ROTATE_270 :
1936+ orientation = 270 ;
1937+ break ;
1938+ }
1939+ } catch (Exception ignore ) {
1940+
1941+ }
1942+
18841943 GalleryModel newPicModel = new GalleryModel ();
18851944 newPicModel .setType (FileUtil .TYPE_IMAGE );
18861945 newPicModel .setSelected (true );
18871946 newPicModel .setName (takenPic .getName ());
18881947 newPicModel .setPath (takenPic .getPath ());
18891948 newPicModel .setUri (FileProvider .getUriForFile (getApplicationContext (),
18901949 getPackageName () + ".sfb_provider" , takenPic ));
1950+ newPicModel .setWidth (width );
1951+ newPicModel .setHeight (height );
1952+ newPicModel .setOrientation (orientation );
18911953 mGalleryAdapter .addNewPic (newPicModel );
18921954
18931955 }
0 commit comments