Merge branch 'felix' into 'master'

Make camera (mostly) fullscreen + add comment function

See merge request !18
This commit was merged in pull request #18.
This commit is contained in:
Felix Atsma
2017-06-26 23:37:29 +02:00
5 changed files with 102 additions and 26 deletions

View File

@@ -1,5 +1,6 @@
package nl.myhyvesbookplus.tagram; package nl.myhyvesbookplus.tagram;
import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
@@ -10,13 +11,17 @@ import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.app.Fragment; import android.app.Fragment;
import android.support.design.widget.FloatingActionButton; import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
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.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import nl.myhyvesbookplus.tagram.controller.PostUploader; import nl.myhyvesbookplus.tagram.controller.PostUploader;
import nl.myhyvesbookplus.tagram.model.BitmapPost;
/** /**
* A simple {@link Fragment} subclass. * A simple {@link Fragment} subclass.
@@ -80,6 +85,9 @@ public class CameraFragment extends Fragment implements PostUploader.PostUploadL
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
// Inflate the layout for this fragment // Inflate the layout for this fragment
((AppCompatActivity)getActivity()).getSupportActionBar().hide();
getActivity().findViewById(R.id.content).setPadding(0,0,0,0);
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); mCamera = getCameraInstance(facing);
@@ -108,6 +116,7 @@ public class CameraFragment extends Fragment implements PostUploader.PostUploadL
mCameraLayout.removeView(mPreview); mCameraLayout.removeView(mPreview);
mCamera = getCameraInstance(facing); mCamera = getCameraInstance(facing);
mPreview = new CameraPreview(getActivity().getBaseContext(), mCamera); mPreview = new CameraPreview(getActivity().getBaseContext(), mCamera);
mCameraLayout.addView(mPreview); mCameraLayout.addView(mPreview);
@@ -122,12 +131,12 @@ public class CameraFragment extends Fragment implements PostUploader.PostUploadL
mCamera.takePicture(null, null, new PictureCallback() { mCamera.takePicture(null, null, new PictureCallback() {
@Override @Override
public void onPictureTaken(byte[] data, Camera camera) { public void onPictureTaken(byte[] data, Camera camera) {
Bitmap bmp = rotate(BitmapFactory.decodeByteArray(data, 0, data.length, null), 90); // Bitmap bmp = rotate(BitmapFactory.decodeByteArray(data, 0, data.length, null), 90);
mPhoto = bmp; // mPhoto = bmp;
mPhoto = BitmapFactory.decodeByteArray(data, 0, data.length, null);
PicturePreview mPicPreview = new PicturePreview(getActivity().getBaseContext(), mPhoto); PicturePreview mPicPreview = new PicturePreview(getActivity().getBaseContext(), mPhoto);
mPicPreview.setId(R.id.pic_preview); mPicPreview.setId(R.id.pic_preview);
Log.d(TAG, "onPictureTaken: PICTURE");
mCameraLayout.addView(mPicPreview); mCameraLayout.addView(mPicPreview);
@@ -144,6 +153,20 @@ public class CameraFragment extends Fragment implements PostUploader.PostUploadL
(view.findViewById(R.id.upload_button)).setOnClickListener(new View.OnClickListener() { (view.findViewById(R.id.upload_button)).setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
view.findViewById(R.id.comment_box).bringToFront();
}
});
(view.findViewById(R.id.comment_submit)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EditText mComment = (EditText) view.findViewById(R.id.comment_text);
String comment = mComment.getText().toString();
mComment.setText("");
PostUploader upload = new PostUploader(getActivity());
upload.uploadPicture(new BitmapPost(((PicturePreview)view.findViewById(R.id.pic_preview)).getPicture(), comment));
mPhoto.recycle(); mPhoto.recycle();
mPhoto = null; mPhoto = null;
@@ -155,7 +178,7 @@ public class CameraFragment extends Fragment implements PostUploader.PostUploadL
mCamera = getCameraInstance(facing); mCamera = getCameraInstance(facing);
Camera.Parameters params = mCamera.getParameters(); Camera.Parameters params = mCamera.getParameters();
params.setRotation(0); params.setRotation(90);
mCamera.setParameters(params); mCamera.setParameters(params);
mPreview = new CameraPreview(getActivity().getBaseContext(), mCamera); mPreview = new CameraPreview(getActivity().getBaseContext(), mCamera);
@@ -165,6 +188,7 @@ public class CameraFragment extends Fragment implements PostUploader.PostUploadL
view.findViewById(R.id.switch_camera_button).bringToFront(); view.findViewById(R.id.switch_camera_button).bringToFront();
mCameraLayout.removeView(view.findViewById(R.id.pic_preview)); mCameraLayout.removeView(view.findViewById(R.id.pic_preview));
} }
}); });
@@ -204,9 +228,23 @@ public class CameraFragment extends Fragment implements PostUploader.PostUploadL
} }
}); });
(view.findViewById(R.id.comment_text)).setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
hideKeyboard(v);
}
}
});
return view; return view;
} }
public void hideKeyboard(View view) {
InputMethodManager inputMethodManager =(InputMethodManager) getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
// TODO: Rename method, update argument and hook method into UI event // TODO: Rename method, update argument and hook method into UI event
public void onButtonPressed(Uri uri) { public void onButtonPressed(Uri uri) {
if (mListener != null) { if (mListener != null) {
@@ -231,14 +269,22 @@ public class CameraFragment extends Fragment implements PostUploader.PostUploadL
mListener = null; mListener = null;
} }
public static Bitmap rotate(Bitmap bitmap, int degree) { @Override
int w = bitmap.getWidth(); public void onDestroyView() {
int h = bitmap.getHeight(); super.onDestroyView();
int padding = 16; // 6 dps
float scale = getResources().getDisplayMetrics().density;
int dp = (int) (padding * scale + 0.5f);
((AppCompatActivity)getActivity()).getSupportActionBar().show();
getActivity().findViewById(R.id.content).setPadding(dp,dp,dp,dp);
}
public static Bitmap rotate(Bitmap bmp, int degree) {
Matrix mtx = new Matrix(); Matrix mtx = new Matrix();
mtx.postRotate(degree); mtx.setRotate(degree);
return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true); return Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), mtx, true);
} }
public static Camera getCameraInstance(int facing) { public static Camera getCameraInstance(int facing) {
@@ -261,18 +307,18 @@ public class CameraFragment extends Fragment implements PostUploader.PostUploadL
public void switchButtons(View view) { public void switchButtons(View view) {
RelativeLayout pictureButtons = (RelativeLayout) view.findViewById(R.id.picture_taken_buttons); RelativeLayout pictureButtons = (RelativeLayout) view.findViewById(R.id.picture_taken_buttons);
FloatingActionButton upload = (FloatingActionButton) view.findViewById(R.id.upload_button); FloatingActionButton upload = (FloatingActionButton) view.findViewById(R.id.upload_button);
FloatingActionButton save = (FloatingActionButton) view.findViewById(R.id.save_button); // FloatingActionButton save = (FloatingActionButton) view.findViewById(R.id.save_button);
if (((Integer)upload.getVisibility()).equals(View.VISIBLE)) { if (((Integer)upload.getVisibility()).equals(View.VISIBLE)) {
upload.hide(); upload.hide();
save.hide(); // save.hide();
view.findViewById(R.id.picture_button).setVisibility(View.VISIBLE); view.findViewById(R.id.picture_button).setVisibility(View.VISIBLE);
view.findViewById(R.id.switch_camera_button).setVisibility(View.VISIBLE); view.findViewById(R.id.switch_camera_button).setVisibility(View.VISIBLE);
} else { } else {
pictureButtons.bringToFront(); pictureButtons.bringToFront();
upload.show(); upload.show();
save.show(); // save.show();
view.findViewById(R.id.picture_button).setVisibility(View.GONE); view.findViewById(R.id.picture_button).setVisibility(View.GONE);
view.findViewById(R.id.switch_camera_button).setVisibility(View.GONE); view.findViewById(R.id.switch_camera_button).setVisibility(View.GONE);

View File

@@ -11,7 +11,6 @@ public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback
private static String TAG = "CameraPreview"; private static String TAG = "CameraPreview";
private SurfaceHolder mHolder; private SurfaceHolder mHolder;
private Camera mCamera; private Camera mCamera;
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);
@@ -25,7 +24,6 @@ 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) {
@@ -62,15 +60,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();
} }
public static void switchFacing() {
if (facing == Camera.CameraInfo.CAMERA_FACING_FRONT)
facing = Camera.CameraInfo.CAMERA_FACING_BACK;
else
facing = Camera.CameraInfo.CAMERA_FACING_FRONT;
}
} }

View File

@@ -15,6 +15,7 @@ import android.view.View;
import com.google.firebase.auth.FirebaseAuth; import com.google.firebase.auth.FirebaseAuth;
import nl.myhyvesbookplus.tagram.controller.DownloadClass; import nl.myhyvesbookplus.tagram.controller.DownloadClass;
import nl.myhyvesbookplus.tagram.controller.PostUploader;
import nl.myhyvesbookplus.tagram.controller.ProfilePictureUploader; import nl.myhyvesbookplus.tagram.controller.ProfilePictureUploader;
public class MainActivity extends AppCompatActivity implements public class MainActivity extends AppCompatActivity implements

View File

@@ -28,6 +28,7 @@ public class PicturePreview extends SurfaceView implements SurfaceHolder.Callbac
public PicturePreview(Context context, Bitmap bmp) { public PicturePreview(Context context, Bitmap bmp) {
super(context); super(context);
picture = Bitmap.createScaledBitmap(bmp, 1920, 1440, false); picture = Bitmap.createScaledBitmap(bmp, 1920, 1440, false);
// picture = Bitmap.createBitmap(bmp);
setWillNotDraw(false); setWillNotDraw(false);
} }
@@ -41,17 +42,26 @@ public class PicturePreview extends SurfaceView implements SurfaceHolder.Callbac
switch (currentFilter) { switch (currentFilter) {
case FILTER_NONE: case FILTER_NONE:
canvas.drawBitmap(picture, 0, 0, null); canvas.drawBitmap(picture, 0, 0, null);
canvas.rotate(90);
filterPicture = picture; filterPicture = picture;
break; break;
case FILTER_SEPIA: case FILTER_SEPIA:
canvas.drawBitmap(toSepia(picture), 0, 0, null); canvas.drawBitmap(toSepia(picture), 0, 0, null);
canvas.rotate(90);
filterPicture = toSepia(picture); filterPicture = toSepia(picture);
break; break;
case FILTER_BW: case FILTER_BW:
Canvas bw = new Canvas();
filterPicture = Bitmap.createBitmap(1920, 1440, null);
// filterPicture = Bitmap.createBitmap(picture.getWidth(), picture.getHeight(), null);
cm.setSaturation(0); cm.setSaturation(0);
filter = new ColorMatrixColorFilter(cm); filter = new ColorMatrixColorFilter(cm);
paint.setColorFilter(filter); paint.setColorFilter(filter);
bw.setBitmap(filterPicture);
bw.drawBitmap(picture, 0, 0, paint);
bw.rotate(90);
canvas.drawBitmap(picture, 0, 0, paint); canvas.drawBitmap(picture, 0, 0, paint);
canvas.rotate(90);
break; break;
} }
} }
@@ -85,7 +95,7 @@ public class PicturePreview extends SurfaceView implements SurfaceHolder.Callbac
} }
public Bitmap toSepia(Bitmap color) { public Bitmap toSepia(Bitmap color) {
int red, green, blue, pixel, gry; int red, green, blue, pixel;
int height = color.getHeight(); int height = color.getHeight();
int width = color.getWidth(); int width = color.getWidth();
int depth = 20; int depth = 20;

View File

@@ -70,6 +70,35 @@
android:src="@drawable/ic_arrow_forward_black_24dp"/> android:src="@drawable/ic_arrow_forward_black_24dp"/>
</RelativeLayout> </RelativeLayout>
<LinearLayout
android:id="@+id/comment_box"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Comment:"/>
<EditText
android:id="@+id/comment_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lines="4"
android:layout_margin="4dp"
android:padding="5dp"
android:visibility="visible"
android:background="@android:color/darker_gray"/>
<Button
android:id="@+id/comment_submit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Submit"/>
</LinearLayout>
<RelativeLayout <RelativeLayout
android:id="@+id/picture_taken_buttons" android:id="@+id/picture_taken_buttons"
android:layout_width="match_parent" android:layout_width="match_parent"
@@ -85,12 +114,12 @@
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_alignParentLeft="true" android:layout_centerHorizontal="true"
android:scaleType="center" android:scaleType="center"
app:fabSize="normal" app:fabSize="normal"
android:src="@android:drawable/ic_menu_upload"/> android:src="@android:drawable/ic_menu_upload"/>
<android.support.design.widget.FloatingActionButton <!--<android.support.design.widget.FloatingActionButton
android:id="@+id/save_button" android:id="@+id/save_button"
android:visibility="gone" android:visibility="gone"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@@ -99,7 +128,7 @@
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true"
android:scaleType="center" android:scaleType="center"
app:fabSize="normal" app:fabSize="normal"
android:src="@android:drawable/ic_menu_save"/> android:src="@android:drawable/ic_menu_save"/>-->
</RelativeLayout> </RelativeLayout>
</RelativeLayout> </RelativeLayout>