Camera filter switching and uploading
This commit is contained in:
@@ -1,25 +1,20 @@
|
|||||||
package nl.myhyvesbookplus.tagram;
|
package nl.myhyvesbookplus.tagram;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
|
import android.graphics.Matrix;
|
||||||
import android.hardware.Camera;
|
import android.hardware.Camera;
|
||||||
import android.hardware.Camera.PictureCallback;
|
import android.hardware.Camera.PictureCallback;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.design.widget.FloatingActionButton;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ImageButton;
|
|
||||||
import android.widget.RelativeLayout;
|
import android.widget.RelativeLayout;
|
||||||
import android.widget.RelativeLayout.LayoutParams;
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple {@link Fragment} subclass.
|
* A simple {@link Fragment} subclass.
|
||||||
@@ -31,6 +26,7 @@ import java.io.IOException;
|
|||||||
*/
|
*/
|
||||||
public class CameraFragment extends Fragment {
|
public class CameraFragment extends Fragment {
|
||||||
// TODO: Rename parameter arguments, choose names that match
|
// TODO: Rename parameter arguments, choose names that match
|
||||||
|
private static final String TAG = "CameraFragment";
|
||||||
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
||||||
private static final String ARG_PARAM1 = "param1";
|
private static final String ARG_PARAM1 = "param1";
|
||||||
private static final String ARG_PARAM2 = "param2";
|
private static final String ARG_PARAM2 = "param2";
|
||||||
@@ -43,6 +39,9 @@ public class CameraFragment extends Fragment {
|
|||||||
|
|
||||||
private Camera mCamera;
|
private Camera mCamera;
|
||||||
private CameraPreview mPreview;
|
private CameraPreview mPreview;
|
||||||
|
private byte[] mPhotoRaw;
|
||||||
|
private Bitmap mPhoto;
|
||||||
|
private int facing = Camera.CameraInfo.CAMERA_FACING_BACK;
|
||||||
|
|
||||||
public CameraFragment() {
|
public CameraFragment() {
|
||||||
// Required empty public constructor
|
// Required empty public constructor
|
||||||
@@ -73,9 +72,6 @@ public class CameraFragment extends Fragment {
|
|||||||
mParam1 = getArguments().getString(ARG_PARAM1);
|
mParam1 = getArguments().getString(ARG_PARAM1);
|
||||||
mParam2 = getArguments().getString(ARG_PARAM2);
|
mParam2 = getArguments().getString(ARG_PARAM2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hide top bar
|
|
||||||
// ((AppCompatActivity) getActivity()).getSupportActionBar().hide();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -84,57 +80,130 @@ public class CameraFragment extends Fragment {
|
|||||||
// Inflate the layout for this fragment
|
// Inflate the layout for this fragment
|
||||||
final View view = inflater.inflate(R.layout.fragment_camera, container, false);
|
final View view = inflater.inflate(R.layout.fragment_camera, container, false);
|
||||||
|
|
||||||
|
mCamera = getCameraInstance(facing);
|
||||||
|
Camera.Parameters params = mCamera.getParameters();
|
||||||
|
params.setRotation(0);
|
||||||
|
mCamera.setParameters(params);
|
||||||
|
|
||||||
mPreview = new CameraPreview(getActivity().getBaseContext(), mCamera);
|
mPreview = new CameraPreview(getActivity().getBaseContext(), mCamera);
|
||||||
final RelativeLayout preview = (RelativeLayout) view.findViewById(R.id.camera_preview);
|
final RelativeLayout pictureButtons = (RelativeLayout) view.findViewById(R.id.picture_taken_buttons);
|
||||||
|
final RelativeLayout filterButtons = (RelativeLayout) view.findViewById(R.id.filter_buttons);
|
||||||
|
final RelativeLayout mCameraLayout = (RelativeLayout) view.findViewById(R.id.camera_preview);
|
||||||
|
// final RelativeLayout mImageTaken = (RelativeLayout) view.findViewById(R.id.picture_view);
|
||||||
|
|
||||||
preview.addView(mPreview);
|
mCameraLayout.addView(mPreview);
|
||||||
|
|
||||||
// Draw picture and switch button over preview
|
// Draw buttons over preview
|
||||||
view.findViewById(R.id.picture_button).bringToFront();
|
view.findViewById(R.id.picture_button).bringToFront();
|
||||||
view.findViewById(R.id.switch_camera_button).bringToFront();
|
view.findViewById(R.id.switch_camera_button).bringToFront();
|
||||||
|
pictureButtons.bringToFront();
|
||||||
|
filterButtons.bringToFront();
|
||||||
|
|
||||||
((ImageButton)view.findViewById(R.id.picture_button)).setOnClickListener(new View.OnClickListener() {
|
(view.findViewById(R.id.switch_camera_button)).setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
Toast.makeText(getActivity(), "Snap!", Toast.LENGTH_SHORT).show();
|
switchFacing();
|
||||||
/*
|
|
||||||
PictureCallback mPicture = new PictureCallback() {
|
|
||||||
|
|
||||||
@Override
|
mCameraLayout.removeView(mPreview);
|
||||||
public void onPictureTaken(byte[] data, Camera camera) {
|
mCamera = getCameraInstance(facing);
|
||||||
Log.v("picture", "Getting output media file");
|
|
||||||
File pictureFile = getOutputMediaFile();
|
|
||||||
if (pictureFile == null) {
|
|
||||||
Log.v("picture", "Error creating output file");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
FileOutputStream fos = new FileOutputStream(pictureFile);
|
|
||||||
fos.write(data);
|
|
||||||
fos.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
Log.v("picture", e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
((ImageButton)view.findViewById(R.id.switch_camera_button)).setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
CameraPreview.switchFacing();
|
|
||||||
|
|
||||||
preview.removeView(mPreview);
|
|
||||||
mPreview = new CameraPreview(getActivity().getBaseContext(), mCamera);
|
mPreview = new CameraPreview(getActivity().getBaseContext(), mCamera);
|
||||||
preview.addView(mPreview);
|
mCameraLayout.addView(mPreview);
|
||||||
|
|
||||||
view.findViewById(R.id.picture_button).bringToFront();
|
view.findViewById(R.id.picture_button).bringToFront();
|
||||||
view.findViewById(R.id.switch_camera_button).bringToFront();
|
view.findViewById(R.id.switch_camera_button).bringToFront();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
(view.findViewById(R.id.picture_button)).setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
mCamera.takePicture(null, null, new PictureCallback() {
|
||||||
|
@Override
|
||||||
|
public void onPictureTaken(byte[] data, Camera camera) {
|
||||||
|
Bitmap bmp = rotate(BitmapFactory.decodeByteArray(data, 0, data.length, null), 90);
|
||||||
|
mPhoto = bmp;
|
||||||
|
|
||||||
|
PicturePreview mPicPreview = new PicturePreview(getActivity().getBaseContext(), mPhoto);
|
||||||
|
mPicPreview.setId(R.id.pic_preview);
|
||||||
|
Log.d(TAG, "onPictureTaken: PICTURE");
|
||||||
|
|
||||||
|
mCameraLayout.addView(mPicPreview);
|
||||||
|
|
||||||
|
filterButtons.setVisibility(View.VISIBLE);
|
||||||
|
filterButtons.bringToFront();
|
||||||
|
|
||||||
|
// mPicPreview.invalidate();
|
||||||
|
switchButtons(view);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
(view.findViewById(R.id.upload_button)).setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
UploadClass upload = new UploadClass();
|
||||||
|
upload.uploadPicture(mPhoto);
|
||||||
|
|
||||||
|
mPhoto.recycle();
|
||||||
|
mPhoto = null;
|
||||||
|
|
||||||
|
filterButtons.setVisibility(View.GONE);
|
||||||
|
switchButtons(view);
|
||||||
|
|
||||||
|
mCameraLayout.removeView(mPreview);
|
||||||
|
|
||||||
|
mCamera = getCameraInstance(facing);
|
||||||
|
Camera.Parameters params = mCamera.getParameters();
|
||||||
|
params.setRotation(0);
|
||||||
|
mCamera.setParameters(params);
|
||||||
|
|
||||||
|
mPreview = new CameraPreview(getActivity().getBaseContext(), mCamera);
|
||||||
|
mCameraLayout.addView(mPreview);
|
||||||
|
|
||||||
|
view.findViewById(R.id.picture_button).bringToFront();
|
||||||
|
view.findViewById(R.id.switch_camera_button).bringToFront();
|
||||||
|
|
||||||
|
mCameraLayout.removeView(view.findViewById(R.id.pic_preview));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
(view.findViewById(R.id.filter_left)).setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
mCameraLayout.removeView(view.findViewById(R.id.pic_preview));
|
||||||
|
|
||||||
|
PicturePreview.filterPrev();
|
||||||
|
|
||||||
|
PicturePreview mPicPreview = new PicturePreview(getActivity().getBaseContext(), mPhoto);
|
||||||
|
mPicPreview.setId(R.id.pic_preview);
|
||||||
|
|
||||||
|
mCameraLayout.addView(mPicPreview);
|
||||||
|
|
||||||
|
view.findViewById(R.id.picture_taken_buttons).bringToFront();
|
||||||
|
filterButtons.setVisibility(View.VISIBLE);
|
||||||
|
filterButtons.bringToFront();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
(view.findViewById(R.id.filter_right)).setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
mCameraLayout.removeView(view.findViewById(R.id.pic_preview));
|
||||||
|
|
||||||
|
PicturePreview.filterNext();
|
||||||
|
|
||||||
|
PicturePreview mPicPreview = new PicturePreview(getActivity().getBaseContext(), mPhoto);
|
||||||
|
mPicPreview.setId(R.id.pic_preview);
|
||||||
|
|
||||||
|
mCameraLayout.addView(mPicPreview);
|
||||||
|
|
||||||
|
view.findViewById(R.id.picture_taken_buttons).bringToFront();
|
||||||
|
filterButtons.setVisibility(View.VISIBLE);
|
||||||
|
filterButtons.bringToFront();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,6 +231,16 @@ public class CameraFragment extends Fragment {
|
|||||||
mListener = null;
|
mListener = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Bitmap rotate(Bitmap bitmap, int degree) {
|
||||||
|
int w = bitmap.getWidth();
|
||||||
|
int h = bitmap.getHeight();
|
||||||
|
|
||||||
|
Matrix mtx = new Matrix();
|
||||||
|
mtx.postRotate(degree);
|
||||||
|
|
||||||
|
return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true);
|
||||||
|
}
|
||||||
|
|
||||||
public static Camera getCameraInstance(int facing) {
|
public static Camera getCameraInstance(int facing) {
|
||||||
Camera c = null;
|
Camera c = null;
|
||||||
try {
|
try {
|
||||||
@@ -172,6 +251,34 @@ public class CameraFragment extends Fragment {
|
|||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void switchFacing() {
|
||||||
|
if (facing == Camera.CameraInfo.CAMERA_FACING_FRONT)
|
||||||
|
facing = Camera.CameraInfo.CAMERA_FACING_BACK;
|
||||||
|
else
|
||||||
|
facing = Camera.CameraInfo.CAMERA_FACING_FRONT;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void switchButtons(View view) {
|
||||||
|
RelativeLayout pictureButtons = (RelativeLayout) view.findViewById(R.id.picture_taken_buttons);
|
||||||
|
FloatingActionButton upload = (FloatingActionButton) view.findViewById(R.id.upload_button);
|
||||||
|
FloatingActionButton save = (FloatingActionButton) view.findViewById(R.id.save_button);
|
||||||
|
|
||||||
|
if (((Integer)upload.getVisibility()).equals(View.VISIBLE)) {
|
||||||
|
upload.hide();
|
||||||
|
save.hide();
|
||||||
|
|
||||||
|
view.findViewById(R.id.picture_button).setVisibility(View.VISIBLE);
|
||||||
|
view.findViewById(R.id.switch_camera_button).setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
pictureButtons.bringToFront();
|
||||||
|
upload.show();
|
||||||
|
save.show();
|
||||||
|
|
||||||
|
view.findViewById(R.id.picture_button).setVisibility(View.GONE);
|
||||||
|
view.findViewById(R.id.switch_camera_button).setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
@@ -182,10 +289,6 @@ public class CameraFragment extends Fragment {
|
|||||||
super.onResume();
|
super.onResume();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCamera(Camera c) {
|
|
||||||
this.mCamera = c;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This interface must be implemented by activities that contain this
|
* This interface must be implemented by activities that contain this
|
||||||
* fragment to allow an interaction in this fragment to be communicated
|
* fragment to allow an interaction in this fragment to be communicated
|
||||||
|
|||||||
@@ -8,13 +8,14 @@ import android.view.SurfaceView;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback {
|
public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback {
|
||||||
|
private static String TAG = "CameraPreview";
|
||||||
private SurfaceHolder mHolder;
|
private SurfaceHolder mHolder;
|
||||||
private Camera mCamera;
|
private Camera mCamera;
|
||||||
private static int facing = 0;
|
private static int facing = Camera.CameraInfo.CAMERA_FACING_BACK;
|
||||||
|
|
||||||
public CameraPreview(Context context, Camera camera) {
|
public CameraPreview(Context context, Camera camera) {
|
||||||
super(context);
|
super(context);
|
||||||
mCamera = camera.open(facing);
|
mCamera = camera;
|
||||||
mCamera.setDisplayOrientation(90);
|
mCamera.setDisplayOrientation(90);
|
||||||
|
|
||||||
mHolder = getHolder();
|
mHolder = getHolder();
|
||||||
@@ -24,6 +25,7 @@ public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback
|
|||||||
@Override
|
@Override
|
||||||
public void surfaceCreated(SurfaceHolder mHolder) {
|
public void surfaceCreated(SurfaceHolder mHolder) {
|
||||||
try {
|
try {
|
||||||
|
Log.d(TAG, "surfaceCreated: CREATED");
|
||||||
mCamera.setPreviewDisplay(mHolder);
|
mCamera.setPreviewDisplay(mHolder);
|
||||||
mCamera.startPreview();
|
mCamera.startPreview();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@@ -60,6 +62,7 @@ public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void surfaceDestroyed(SurfaceHolder holder) {
|
public void surfaceDestroyed(SurfaceHolder holder) {
|
||||||
|
Log.d(TAG, "surfaceDestroyed: DESTROYED");
|
||||||
mCamera.stopPreview();
|
mCamera.stopPreview();
|
||||||
mCamera.release();
|
mCamera.release();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,134 @@
|
|||||||
|
package nl.myhyvesbookplus.tagram;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.ColorFilter;
|
||||||
|
import android.graphics.ColorMatrix;
|
||||||
|
import android.graphics.ColorMatrixColorFilter;
|
||||||
|
import android.graphics.Paint;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.SurfaceHolder;
|
||||||
|
import android.view.SurfaceView;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by felix on 23/06/2017.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class PicturePreview extends SurfaceView implements SurfaceHolder.Callback {
|
||||||
|
private static final int FILTER_NONE = 0;
|
||||||
|
private static final int FILTER_SEPIA = 1;
|
||||||
|
private static final int FILTER_BW = 2;
|
||||||
|
|
||||||
|
private static int currentFilter = FILTER_NONE;
|
||||||
|
|
||||||
|
Bitmap picture;
|
||||||
|
Bitmap filterPicture;
|
||||||
|
|
||||||
|
public PicturePreview(Context context, Bitmap bmp) {
|
||||||
|
super(context);
|
||||||
|
picture = Bitmap.createScaledBitmap(bmp, 1920, 1440, false);
|
||||||
|
setWillNotDraw(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDraw(Canvas canvas) {
|
||||||
|
super.onDraw(canvas);
|
||||||
|
ColorMatrix cm = new ColorMatrix();
|
||||||
|
Paint paint = new Paint();
|
||||||
|
ColorMatrixColorFilter filter;
|
||||||
|
|
||||||
|
switch (currentFilter) {
|
||||||
|
case FILTER_NONE:
|
||||||
|
canvas.drawBitmap(picture, 0, 0, null);
|
||||||
|
filterPicture = picture;
|
||||||
|
break;
|
||||||
|
case FILTER_SEPIA:
|
||||||
|
canvas.drawBitmap(toSepia(picture), 0, 0, null);
|
||||||
|
filterPicture = toSepia(picture);
|
||||||
|
break;
|
||||||
|
case FILTER_BW:
|
||||||
|
cm.setSaturation(0);
|
||||||
|
filter = new ColorMatrixColorFilter(cm);
|
||||||
|
paint.setColorFilter(filter);
|
||||||
|
canvas.drawBitmap(picture, 0, 0, paint);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void filterPrev() {
|
||||||
|
switch (currentFilter) {
|
||||||
|
case FILTER_NONE:
|
||||||
|
currentFilter = FILTER_BW;
|
||||||
|
break;
|
||||||
|
case FILTER_SEPIA:
|
||||||
|
currentFilter = FILTER_NONE;
|
||||||
|
break;
|
||||||
|
case FILTER_BW:
|
||||||
|
currentFilter = FILTER_SEPIA;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void filterNext() {
|
||||||
|
switch (currentFilter) {
|
||||||
|
case FILTER_NONE:
|
||||||
|
currentFilter = FILTER_SEPIA;
|
||||||
|
break;
|
||||||
|
case FILTER_SEPIA:
|
||||||
|
currentFilter = FILTER_BW;
|
||||||
|
break;
|
||||||
|
case FILTER_BW:
|
||||||
|
currentFilter = FILTER_NONE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Bitmap toSepia(Bitmap color) {
|
||||||
|
int red, green, blue, pixel, gry;
|
||||||
|
int height = color.getHeight();
|
||||||
|
int width = color.getWidth();
|
||||||
|
int depth = 20;
|
||||||
|
|
||||||
|
Bitmap sepia = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||||||
|
|
||||||
|
int[] pixels = new int[width * height];
|
||||||
|
color.getPixels(pixels, 0, width, 0, 0, width, height);
|
||||||
|
for (int i = 0; i < pixels.length; i++) {
|
||||||
|
pixel = pixels[i];
|
||||||
|
|
||||||
|
red = (pixel >> 16) & 0xFF;
|
||||||
|
green = (pixel >> 8) & 0xFF;
|
||||||
|
blue = pixel & 0xFF;
|
||||||
|
|
||||||
|
red = green = blue = (red + green + blue) / 3;
|
||||||
|
|
||||||
|
red += (depth * 2);
|
||||||
|
green += depth;
|
||||||
|
|
||||||
|
if (red > 255)
|
||||||
|
red = 255;
|
||||||
|
if (green > 255)
|
||||||
|
green = 255;
|
||||||
|
pixels[i] = (0xFF << 24) | (red << 16) | (green << 8) | blue;
|
||||||
|
}
|
||||||
|
sepia.setPixels(pixels, 0, width, 0, 0, width, height);
|
||||||
|
return sepia;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Bitmap getPicture() {
|
||||||
|
return filterPicture;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void surfaceCreated(SurfaceHolder holder) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void surfaceDestroyed(SurfaceHolder holder) {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,6 +13,7 @@ import com.google.firebase.storage.StorageReference;
|
|||||||
import com.google.firebase.storage.UploadTask;
|
import com.google.firebase.storage.UploadTask;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by marijnjansen on 20/06/2017.
|
* Created by marijnjansen on 20/06/2017.
|
||||||
@@ -24,7 +25,8 @@ public class UploadClass {
|
|||||||
|
|
||||||
|
|
||||||
public UploadClass() {
|
public UploadClass() {
|
||||||
mStorageRef = FirebaseStorage.getInstance().getReference().child("images");
|
String name = Integer.toString(new Random().nextInt(10000));
|
||||||
|
mStorageRef = FirebaseStorage.getInstance().getReference().child("images/" + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] bitmapToBytes(Bitmap bitmap) {
|
private byte[] bitmapToBytes(Bitmap bitmap) {
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 199 B |
Binary file not shown.
|
After Width: | Height: | Size: 222 B |
@@ -5,40 +5,103 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context="nl.myhyvesbookplus.tagram.CameraFragment">
|
tools:context="nl.myhyvesbookplus.tagram.CameraFragment">
|
||||||
|
|
||||||
<LinearLayout
|
<RelativeLayout
|
||||||
|
android:id="@+id/camera_preview"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent" >
|
||||||
android:orientation="vertical">
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/picture_button"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentBottom="true"
|
||||||
|
android:layout_centerHorizontal="true"
|
||||||
|
android:background="@android:color/transparent"
|
||||||
|
android:layout_margin="10dp"
|
||||||
|
android:padding="10dp"
|
||||||
|
android:scaleType="center"
|
||||||
|
android:scaleX="2"
|
||||||
|
android:scaleY="2"
|
||||||
|
app:srcCompat="@android:drawable/ic_menu_camera" />
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/switch_camera_button"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentRight="true"
|
||||||
|
android:layout_margin="9dp"
|
||||||
|
android:background="@android:color/transparent"
|
||||||
|
app:srcCompat="@android:drawable/ic_menu_revert" />
|
||||||
|
|
||||||
|
<ProgressBar
|
||||||
|
android:id="@+id/load_bar"
|
||||||
|
android:visibility="gone"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:indeterminate="true"
|
||||||
|
android:layout_centerInParent="true"/>
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:id="@+id/camera_preview"
|
android:id="@+id/filter_buttons"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="fill_parent" >
|
android:layout_height="wrap_content"
|
||||||
|
android:visibility="gone"
|
||||||
|
android:layout_marginBottom="60dp"
|
||||||
|
android:layout_centerVertical="true">
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/picture_button"
|
android:id="@+id/filter_left"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="@android:color/transparent"
|
||||||
|
android:scaleX="0.5"
|
||||||
|
android:scaleY="0.5"
|
||||||
|
android:layout_alignParentLeft="true"
|
||||||
|
android:src="@drawable/ic_arrow_back_black_24dp"/>
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/filter_right"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="@android:color/transparent"
|
||||||
|
android:scaleX="0.5"
|
||||||
|
android:scaleY="0.5"
|
||||||
|
android:layout_alignParentRight="true"
|
||||||
|
android:src="@drawable/ic_arrow_forward_black_24dp"/>
|
||||||
|
</RelativeLayout>
|
||||||
|
|
||||||
|
<RelativeLayout
|
||||||
|
android:id="@+id/picture_taken_buttons"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentBottom="true"
|
||||||
|
android:layout_marginLeft="30dp"
|
||||||
|
android:layout_marginRight="30dp"
|
||||||
|
android:layout_marginBottom="20dp">
|
||||||
|
|
||||||
|
<android.support.design.widget.FloatingActionButton
|
||||||
|
android:id="@+id/upload_button"
|
||||||
|
android:visibility="gone"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentBottom="true"
|
android:layout_alignParentBottom="true"
|
||||||
android:layout_centerHorizontal="true"
|
android:layout_alignParentLeft="true"
|
||||||
android:background="@android:color/transparent"
|
android:scaleType="center"
|
||||||
android:layout_margin="10dp"
|
app:fabSize="normal"
|
||||||
android:padding="10dp"
|
android:src="@android:drawable/ic_menu_upload"/>
|
||||||
android:scaleX="2"
|
|
||||||
android:scaleY="2"
|
|
||||||
app:srcCompat="@android:drawable/ic_menu_camera" />
|
|
||||||
|
|
||||||
<ImageButton
|
<android.support.design.widget.FloatingActionButton
|
||||||
android:id="@+id/switch_camera_button"
|
android:id="@+id/save_button"
|
||||||
|
android:visibility="gone"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
android:layout_margin="9dp"
|
android:layout_alignParentBottom="true"
|
||||||
android:background="@android:color/transparent"
|
android:scaleType="center"
|
||||||
app:srcCompat="@android:drawable/ic_menu_revert" />
|
app:fabSize="normal"
|
||||||
|
android:src="@android:drawable/ic_menu_save"/>
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|||||||
@@ -2,5 +2,6 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<color name="colorPrimary">#fbbf2d</color>
|
<color name="colorPrimary">#fbbf2d</color>
|
||||||
<color name="colorPrimaryDark">#ffa70f</color>
|
<color name="colorPrimaryDark">#ffa70f</color>
|
||||||
<color name="colorAccent">#4CAF50</color>
|
<color name="colorAccent">#4bAfe5</color>
|
||||||
|
<!--<color name="colorAccent">#4CAF50</color>-->
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<item name="pic_preview" type="id"/>
|
||||||
|
<item name="camera_preview" type="id"/>
|
||||||
|
</resources>
|
||||||
@@ -24,4 +24,7 @@
|
|||||||
<string name="profile_picture_description">profile picture</string>
|
<string name="profile_picture_description">profile picture</string>
|
||||||
<string name="change_psw_button">Change Password</string>
|
<string name="change_psw_button">Change Password</string>
|
||||||
<string name="please_wait">Please Wait</string>
|
<string name="please_wait">Please Wait</string>
|
||||||
|
|
||||||
|
<string name="upload">Upload</string>
|
||||||
|
<string name="save">Save</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user