Search code examples
androidandroid-intentandroid-cameraandroid-gallery

how to make own custom camera gallery view


am working on android camera application when i click it save image in gallery when i click on gallery view it show default gallery of mobile but i want own custom view with button like delete ,share , favorite . how can i implement this please assist me

public void clickedGallery(View view) {
    if (MyDebug.LOG)
        Log.d(TAG, "clickedGallery");
    //Intent intent = new Intent(Intent.ACTION_VIEW, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    Uri uri = null;
    Media media = getLatestMedia();
    if (media != null) {
        uri = media.uri;
    }

    if (uri != null) {
        // check uri exists
        if (MyDebug.LOG)
            Log.d(TAG, "found most recent uri: " + uri);
        try {
            ContentResolver cr = getContentResolver();
            ParcelFileDescriptor pfd = cr.openFileDescriptor(uri, "r");
            if (pfd == null) {
                if (MyDebug.LOG)
                    Log.d(TAG, "uri no longer exists (1): " + uri);
                uri = null;
            }
            pfd.close();
        } catch (IOException e) {
            if (MyDebug.LOG)
                Log.d(TAG, "uri no longer exists (2): " + uri);
            uri = null;
        }
    }
    if (uri == null) {
        uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
    }
    if (!is_test) {
        // don't do if testing, as unclear how to exit activity to finish test (for testGallery())
        if (MyDebug.LOG)
            Log.d(TAG, "launch uri:" + uri);
        final String REVIEW_ACTION = "com.android.camera.action.REVIEW";
        try {
            // REVIEW_ACTION means we can view video files without autoplaying
            Intent intent = new Intent(REVIEW_ACTION, uri);
            this.startActivity(intent);
        } catch (ActivityNotFoundException e) {
            if (MyDebug.LOG)
                Log.d(TAG, "REVIEW_ACTION intent didn't work, try ACTION_VIEW");
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            // from http://stackoverflow.com/questions/11073832/no-activity-found-to-handle-intent - needed to fix crash if no gallery app installed
            //Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("blah")); // test
            if (intent.resolveActivity(getPackageManager()) != null) {
                this.startActivity(intent);
            } else {
                preview.showToast(null, R.string.no_gallery_app);
            }
        }
    }
}

Solution

  • Use this example as base.

    https://www.caveofprogramming.com/guest-posts/custom-gridview-with-imageview-and-textview-in-android.html

    In the programlist.xml add your buttons.

    In the CustomAdapter.java in the getView method implement the buttons listeners.

    In the MainActivity set descendantfocusability to the Gridview