Question

(Android Studio)

Create a camera app that allows the user to upload a picture from their phone camera gallery, see the picture via summary page, and edit the picture as well. Clicking on "Insert picture here from camera photo gallery" in the add page will allow the user to upload a picture from their existing camera photo gallery on their phone. The user can choose where to save the picture, starting with Picture 1-5. Once they choose where to save the picture from, they can view that picture in the summary page. In the summary page, the user can see the picture that they uploaded. They can also change or edit the picture that they uploaded using the Edit button from the Summary Page. Clicking on the Edit Button will take you to the Edit page, where the user can click and edit on the Image View from Picture 1-5 and change the picture. Once they hit the "done" button in the Edit page, it will update the new photo added in the Summary Page.

INSERT PICTURE HERE FROM Camera photo gallery Clicking on this box allows you to add a picture from your camera photo gallery) Choose where to save Picture in. Picture I Picture 2 ?? Picture 3 Picture 4 scroll Picture 5 ADD PICTURE Add Page

Notes:

1. Make the application according to the requirement. .

2. Do not screenshot, do not write this on paper. Please copy and paste source codes on Chegg.  

3. Please post all codes from both XML and Java codes. If there are any changes in Manifest or values codes, post those as well.  

4. If there are specific instructions like how to get the home icon, please describe it in the solution.  

5. Screen shot the output, NOT the codes of the camera app.  

0 0
Add a comment Improve this question Transcribed image text
Answer #1

MainActivity:

package com.practice.com.cameraHomeworkLib;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.Spinner;

import java.io.ByteArrayOutputStream;

public class MainActivity extends AppCompatActivity {
    public static final String[] paths = {"Picture 1", "Picture 2", "Picture 3", "Picture 4", "Picture 5"};
    private static final int REQUEST_CODE = 1;
    private static final String TAG = "galley";
    private ImageView imageView;
    private Spinner mySpinner;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mySpinner = findViewById(R.id.spinner);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(MainActivity.this,
                android.R.layout.simple_spinner_item, paths);
        imageView = findViewById(R.id.imageView);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        mySpinner.setAdapter(adapter);
    }

    public void selectPicture(View view) {
        Intent intent = new Intent();
        intent.setType("image/*");
        intent.setAction(Intent.ACTION_GET_CONTENT);
        startActivityForResult(Intent.createChooser(intent, "Select Picture"), REQUEST_CODE);
    }

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        try {
            switch (requestCode) {

                case REQUEST_CODE:
                    if (resultCode == Activity.RESULT_OK) {
                        Uri selectedImage = data.getData();
                        Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), selectedImage);
                        imageView.setImageBitmap(bitmap);
                        break;
                    } else if (resultCode == Activity.RESULT_CANCELED) {
                        Log.e(TAG, "Selecting picture cancelled");
                    }
                    break;
            }
        } catch (Exception e) {
            Log.e(TAG, "Exception in onActivityResult : " + e.getMessage());
        }
    }

    public void goToSummary(View view) {
        Intent intent = new Intent(this, SummaryPage.class);
        String imageName = mySpinner.getSelectedItem().toString();
        Bitmap bmp = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
        byte[] byteArray = stream.toByteArray();
        intent.putExtra("picture", byteArray);
        intent.putExtra("imagePosition", imageName);
        startActivity(intent);
    }
}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="84dp"
        android:layout_marginTop="68dp"
        android:onClick="selectPicture"
        android:text="Insert Picture From Here"
        android:textAllCaps="false"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <com.practice.com.cameraHomeworkLib.VisibleScrollbarSpinner
        android:id="@+id/spinner"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="220dp"
        android:layout_marginStart="116dp"
        android:layout_marginTop="8dp"
        android:background="@android:drawable/btn_dropdown"
        android:spinnerMode="dropdown"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/button"
        app:layout_constraintVertical_bias="1.0" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="24dp"
        android:layout_marginEnd="16dp"
        android:layout_marginStart="8dp"
        android:text="Add Picture"
        android:onClick="goToSummary"
        android:textAllCaps="false"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="1.0"
        app:layout_constraintStart_toStartOf="parent" />

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="gone"/>

</android.support.constraint.ConstraintLayout>

SummaryPage.java

package com.practice.com.cameraHomeworkLib;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;

import static com.practice.com.cameraHomeworkLib.MainActivity.paths;

public class SummaryPage extends AppCompatActivity {

    private static final int REQUEST_CODE = 1;
    private static final String TAG = "edit_mode";
    private static int postion;
    private LinearLayout linearLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_summary_page);
        Bundle extras = getIntent().getExtras();
        byte[] byteArray = extras.getByteArray("picture");
        Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
        String imagePosition = extras.getString("imagePosition");
        linearLayout = findViewById(R.id.summary_page);
        assert imagePosition != null;
        if (imagePosition.equals(paths[0])) {
            ImageView image = (ImageView) findViewById(R.id.imageView1);
            image.setImageBitmap(bmp);

        } else if (imagePosition.equals(paths[1])) {
            ImageView image = (ImageView) findViewById(R.id.imageView2);
            image.setImageBitmap(bmp);

        } else if (imagePosition.equals(paths[2])) {
            ImageView image = (ImageView) findViewById(R.id.imageView3);
            image.setImageBitmap(bmp);


        } else if (imagePosition.equals(paths[3])) {
            ImageView image = (ImageView) findViewById(R.id.imageView4);
            image.setImageBitmap(bmp);


        } else if (imagePosition.equals(paths[4])) {
            ImageView image = (ImageView) findViewById(R.id.imageView5);
            image.setImageBitmap(bmp);
        }

    }

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        try {
            switch (requestCode) {

                case REQUEST_CODE:
                    if (resultCode == Activity.RESULT_OK) {
                        Uri selectedImage = data.getData();
                        Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), selectedImage);
                        ImageView imageView = (ImageView) linearLayout.getChildAt(postion);
                        imageView.setImageBitmap(bitmap);
                        break;
                    } else if (resultCode == Activity.RESULT_CANCELED) {
                        Log.e(TAG, "Selecting picture cancelled");
                    }
                    break;
            }
        } catch (Exception e) {
            Log.e(TAG, "Exception in onActivityResult : " + e.getMessage());
        }
    }

    public void goToEdit(View view) {
        Button button = findViewById(R.id.edit_button);
        button.setVisibility(View.GONE);

        for (int i = 0; i < linearLayout.getChildCount() - 1; i++) {
            ImageView imageView = (ImageView) linearLayout.getChildAt(i);
            final int finalI = i;
            imageView.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    postion = finalI;
                    Intent intent = new Intent();
                    intent.setType("image/*");
                    intent.setAction(Intent.ACTION_GET_CONTENT);
                    startActivityForResult(Intent.createChooser(intent, "Select Picture"), REQUEST_CODE);
                }
            });
        }


        }

    public void finish(View view) {
        Button button = findViewById(R.id.edit_button);
        button.setVisibility(View.VISIBLE);

        for (int i = 0; i < linearLayout.getChildCount() - 1; i++) {
            ImageView imageView = (ImageView) linearLayout.getChildAt(i);
            imageView.setOnClickListener(null);
        }

    }
}

acitivity_summary_page.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:id="@+id/summary_page"
    android:orientation="vertical"
    tools:context=".SummaryPage">

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:src="@mipmap/ic_launcher" />

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:src="@mipmap/ic_launcher" />

    <ImageView
        android:id="@+id/imageView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:src="@mipmap/ic_launcher" />

    <ImageView
        android:id="@+id/imageView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:src="@mipmap/ic_launcher" />

    <ImageView
        android:id="@+id/imageView5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:src="@mipmap/ic_launcher" />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="left"
        android:orientation="horizontal">

        <Button
            android:id="@+id/edit_button"
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:layout_gravity="left"
            android:layout_weight="1.5"
            android:onClick="goToEdit"
            android:text="Edit" />

        <Button
            android:id="@+id/done"
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:layout_weight="1.5"
            android:onClick="finish"
            android:text="Done" />

    </LinearLayout>


</LinearLayout>

Custom Spinner

package com.practice.com.cameraHomeworkLib;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.ListPopupWindow;
import android.widget.Spinner;

import java.lang.reflect.Field;

import static android.content.ContentValues.TAG;

public class VisibleScrollbarSpinner extends Spinner {
    @Override
    public boolean performClick() {
        final boolean superResult = super.performClick();

        try {
            final Field mPopupField = Spinner.class.getDeclaredField("mPopup");
            mPopupField.setAccessible(true);
            ((ListPopupWindow) mPopupField.get(this)).getListView().setScrollbarFadingEnabled(false);
            mPopupField.setAccessible(false);
        } catch (NoSuchFieldException | IllegalAccessException e) {
            Log.e(TAG, e.toString(), e);
        }


        return superResult;
    }

    public VisibleScrollbarSpinner(Context context) {
        super(context);
    }

    public VisibleScrollbarSpinner(Context context, int mode) {
        super(context, mode);
    }

    public VisibleScrollbarSpinner(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public VisibleScrollbarSpinner(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public VisibleScrollbarSpinner(Context context, AttributeSet attrs, int defStyleAttr, int mode) {
        super(context, attrs, defStyleAttr, mode);
    }
}

i have pasted all the code.i have reused summary page as edit page also.

let me know if you have any questions.

Add a comment
Know the answer?
Add Answer to:
(Android Studio) Create a camera app that allows the user to upload a picture from their...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT