// Path: vector/src/main/java/im/vector/view/RecentMediaLayout.java
// public class RecentMediaLayout extends RelativeLayout {
// 
//     private ImageView mThumbnailView;
//     private ImageView mTypeView;
//     private View mSelectedItemView;
// 
//     public RecentMediaLayout(Context context) {
//         super(context);
//         init();
//     }
// 
//     public RecentMediaLayout(Context context, AttributeSet attrs) {
//         super(context, attrs);
//         init();
//     }
// 
//     public RecentMediaLayout(Context context, AttributeSet attrs, int defStyleAttr) {
//         super(context, attrs, defStyleAttr);
//         init();
//     }
// 
//     private void init() {
//         inflate(getContext(), R.layout.layout_media_thumbnail, this);
// 
//         mThumbnailView = findViewById(R.id.media_thumbnail_view);
//         mTypeView = findViewById(R.id.media_type_view);
//         mSelectedItemView = findViewById(R.id.media_selected_mask_view);
//     }
// 
//     /**
//      * @return true when the layout is displayed as selected
//      */
//     public boolean isSelected() {
//         return mSelectedItemView.getVisibility() == View.VISIBLE;
//     }
// 
//     /**
//      * Update the layout thumbnail.
//      *
//      * @param thumbnail the thumbnail
//      */
//     public void setThumbnail(Bitmap thumbnail) {
//         mThumbnailView.setImageBitmap(thumbnail);
//     }
// 
//     public void setThumbnailByUri(Uri aThumbnailUri) {
//         mThumbnailView.setImageURI(aThumbnailUri);
//     }
// 
//     public void setThumbnailByResource(int aThumbnailResource) {
//         mThumbnailView.setImageResource(aThumbnailResource);
//     }
// 
//     /**
//      * Enable the display of the video thumbnail
//      *
//      * @param isVideo true to display video thumbnail
//      */
//     public void setVideoType(boolean isVideo) {
//         mTypeView.setImageResource(isVideo ? R.drawable.ic_material_movie : R.drawable.ic_material_photo);
//     }
// 
//     /**
//      * Enable the display of the gif thumbnail
//      *
//      * @param isGif true to display gif thumbnail
//      */
//     public void setGifType(boolean isGif) {
//         mTypeView.setImageResource(isGif ? R.drawable.filetype_gif : R.drawable.ic_material_photo);
//     }
// }


import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ImageFormat;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.SurfaceTexture;
import android.graphics.drawable.BitmapDrawable;
import android.hardware.Camera;
import android.media.CamcorderProfile;
import android.media.MediaActionSound;
import android.media.MediaPlayer;
import android.media.MediaRecorder;
import android.media.ThumbnailUtils;
import android.net.Uri;
import android.opengl.GLES20;
import android.os.Build;
import android.os.Bundle;
import android.os.HandlerThread;
import android.provider.MediaStore;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.MotionEvent;
import android.view.Surface;
import android.view.TextureView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.Toast;
import android.widget.VideoView;
import androidx.annotation.NonNull;
import androidx.preference.PreferenceManager;
import org.jetbrains.annotations.NotNull;
import org.matrix.androidsdk.core.ImageUtils;
import org.matrix.androidsdk.core.Log;
import org.matrix.androidsdk.core.ResourceUtils;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.egl.EGLContext;
import javax.microedition.khronos.egl.EGLDisplay;
import javax.microedition.khronos.egl.EGLSurface;
import im.vector.R;
import im.vector.VectorApp;
import im.vector.listeners.ImageViewOnTouchListener;
import im.vector.ui.themes.ActivityOtherThemes;
import im.vector.ui.themes.ThemeUtils;
import im.vector.util.PermissionsToolsKt;
import im.vector.util.PreferencesManager;
import im.vector.util.ViewUtilKt;
import im.vector.view.RecentMediaLayout;
import im.vector.view.VideoRecordView;

        mMediaStoreMediaList.clear();

        // run away from the UI thread
        mFileHandler.post(new Runnable() {
            @Override
            public void run() {
                // populate the image thumbnails from multimedia store
                final List<MediaStoreMedia> medias = listLatestMedias();

                // update the UI part
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        mMediaStoreMediaList.addAll(medias);
                        buildGalleryTableLayout();
                        progressBar.setVisibility(View.GONE);
                        mTakeImageView.setEnabled(true);
                        mTakeImageView.setAlpha(ViewUtilKt.UTILS_OPACITY_FULL);
                    }
                });
            }
        });
    }

    /**
     * Build the image gallery widget programmatically.
     */
    private void buildGalleryTableLayout() {
        TableRow tableRow = null;
// Path: vector/src/main/java/im/vector/view/RecentMediaLayout.java
// public class RecentMediaLayout extends RelativeLayout {
// 
//     private ImageView mThumbnailView;
//     private ImageView mTypeView;
//     private View mSelectedItemView;
// 
//     public RecentMediaLayout(Context context) {
//         super(context);
//         init();
//     }
// 
//     public RecentMediaLayout(Context context, AttributeSet attrs) {
//         super(context, attrs);
//         init();
//     }
// 
//     public RecentMediaLayout(Context context, AttributeSet attrs, int defStyleAttr) {
//         super(context, attrs, defStyleAttr);
//         init();
//     }
// 
//     private void init() {
//         inflate(getContext(), R.layout.layout_media_thumbnail, this);
// 
//         mThumbnailView = findViewById(R.id.media_thumbnail_view);
//         mTypeView = findViewById(R.id.media_type_view);
//         mSelectedItemView = findViewById(R.id.media_selected_mask_view);
//     }
// 
//     /**
//      * @return true when the layout is displayed as selected
//      */
//     public boolean isSelected() {
//         return mSelectedItemView.getVisibility() == View.VISIBLE;
//     }
// 
//     /**
//      * Update the layout thumbnail.
//      *
//      * @param thumbnail the thumbnail
//      */
//     public void setThumbnail(Bitmap thumbnail) {
//         mThumbnailView.setImageBitmap(thumbnail);
//     }
// 
//     public void setThumbnailByUri(Uri aThumbnailUri) {
//         mThumbnailView.setImageURI(aThumbnailUri);
//     }
// 
//     public void setThumbnailByResource(int aThumbnailResource) {
//         mThumbnailView.setImageResource(aThumbnailResource);
//     }
// 
//     /**
//      * Enable the display of the video thumbnail
//      *
//      * @param isVideo true to display video thumbnail
//      */
//     public void setVideoType(boolean isVideo) {
//         mTypeView.setImageResource(isVideo ? R.drawable.ic_material_movie : R.drawable.ic_material_photo);
//     }
// 
//     /**
//      * Enable the display of the gif thumbnail
//      *
//      * @param isGif true to display gif thumbnail
//      */
//     public void setGifType(boolean isGif) {
//         mTypeView.setImageResource(isGif ? R.drawable.filetype_gif : R.drawable.ic_material_photo);
//     }
// }


// Path: vector/src/main/java/im/vector/activity/VectorMediaPickerActivity.java
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ImageFormat;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.SurfaceTexture;
import android.graphics.drawable.BitmapDrawable;
import android.hardware.Camera;
import android.media.CamcorderProfile;
import android.media.MediaActionSound;
import android.media.MediaPlayer;
import android.media.MediaRecorder;
import android.media.ThumbnailUtils;
import android.net.Uri;
import android.opengl.GLES20;
import android.os.Build;
import android.os.Bundle;
import android.os.HandlerThread;
import android.provider.MediaStore;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.MotionEvent;
import android.view.Surface;
import android.view.TextureView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.Toast;
import android.widget.VideoView;
import androidx.annotation.NonNull;
import androidx.preference.PreferenceManager;
import org.jetbrains.annotations.NotNull;
import org.matrix.androidsdk.core.ImageUtils;
import org.matrix.androidsdk.core.Log;
import org.matrix.androidsdk.core.ResourceUtils;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.egl.EGLContext;
import javax.microedition.khronos.egl.EGLDisplay;
import javax.microedition.khronos.egl.EGLSurface;
import im.vector.R;
import im.vector.VectorApp;
import im.vector.listeners.ImageViewOnTouchListener;
import im.vector.ui.themes.ActivityOtherThemes;
import im.vector.ui.themes.ThemeUtils;
import im.vector.util.PermissionsToolsKt;
import im.vector.util.PreferencesManager;
import im.vector.util.ViewUtilKt;
import im.vector.view.RecentMediaLayout;
import im.vector.view.VideoRecordView;


        mMediaStoreMediaList.clear();

        // run away from the UI thread
        mFileHandler.post(new Runnable() {
            @Override
            public void run() {
                // populate the image thumbnails from multimedia store
                final List<MediaStoreMedia> medias = listLatestMedias();

                // update the UI part
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        mMediaStoreMediaList.addAll(medias);
                        buildGalleryTableLayout();
                        progressBar.setVisibility(View.GONE);
                        mTakeImageView.setEnabled(true);
                        mTakeImageView.setAlpha(ViewUtilKt.UTILS_OPACITY_FULL);
                    }
                });
            }
        });
    }

    /**
     * Build the image gallery widget programmatically.
     */
    private void buildGalleryTableLayout() {
        TableRow tableRow = null;
        RecentMediaLayout recentMediaView;