diff --git a/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/CameraFragment.java b/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/CameraFragment.java index 6228aac..7c523a3 100644 --- a/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/CameraFragment.java +++ b/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/CameraFragment.java @@ -1,5 +1,6 @@ package nl.myhyvesbookplus.tagram; +import android.app.Activity; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; @@ -10,13 +11,17 @@ import android.net.Uri; import android.os.Bundle; import android.app.Fragment; import android.support.design.widget.FloatingActionButton; +import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.view.inputmethod.InputMethodManager; +import android.widget.EditText; import android.widget.RelativeLayout; import nl.myhyvesbookplus.tagram.controller.PostUploader; +import nl.myhyvesbookplus.tagram.model.BitmapPost; /** * A simple {@link Fragment} subclass. @@ -80,6 +85,9 @@ public class CameraFragment extends Fragment implements PostUploader.PostUploadL public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // 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); mCamera = getCameraInstance(facing); @@ -108,6 +116,7 @@ public class CameraFragment extends Fragment implements PostUploader.PostUploadL mCameraLayout.removeView(mPreview); mCamera = getCameraInstance(facing); + mPreview = new CameraPreview(getActivity().getBaseContext(), mCamera); mCameraLayout.addView(mPreview); @@ -122,12 +131,12 @@ public class CameraFragment extends Fragment implements PostUploader.PostUploadL 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; +// Bitmap bmp = rotate(BitmapFactory.decodeByteArray(data, 0, data.length, null), 90); +// mPhoto = bmp; + mPhoto = BitmapFactory.decodeByteArray(data, 0, data.length, null); PicturePreview mPicPreview = new PicturePreview(getActivity().getBaseContext(), mPhoto); mPicPreview.setId(R.id.pic_preview); - Log.d(TAG, "onPictureTaken: PICTURE"); 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() { @Override 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 = null; @@ -155,7 +178,7 @@ public class CameraFragment extends Fragment implements PostUploader.PostUploadL mCamera = getCameraInstance(facing); Camera.Parameters params = mCamera.getParameters(); - params.setRotation(0); + params.setRotation(90); mCamera.setParameters(params); 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(); 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; } + 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 public void onButtonPressed(Uri uri) { if (mListener != null) { @@ -231,14 +269,22 @@ public class CameraFragment extends Fragment implements PostUploader.PostUploadL mListener = null; } - public static Bitmap rotate(Bitmap bitmap, int degree) { - int w = bitmap.getWidth(); - int h = bitmap.getHeight(); + @Override + public void onDestroyView() { + 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(); - 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) { @@ -261,18 +307,18 @@ public class CameraFragment extends Fragment implements PostUploader.PostUploadL 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); +// FloatingActionButton save = (FloatingActionButton) view.findViewById(R.id.save_button); if (((Integer)upload.getVisibility()).equals(View.VISIBLE)) { upload.hide(); - save.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(); +// save.show(); view.findViewById(R.id.picture_button).setVisibility(View.GONE); view.findViewById(R.id.switch_camera_button).setVisibility(View.GONE); diff --git a/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/CameraPreview.java b/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/CameraPreview.java index 84fbe45..0f07ad2 100644 --- a/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/CameraPreview.java +++ b/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/CameraPreview.java @@ -11,7 +11,6 @@ public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback private static String TAG = "CameraPreview"; private SurfaceHolder mHolder; private Camera mCamera; - private static int facing = Camera.CameraInfo.CAMERA_FACING_BACK; public CameraPreview(Context context, Camera camera) { super(context); @@ -25,7 +24,6 @@ public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback @Override public void surfaceCreated(SurfaceHolder mHolder) { try { - Log.d(TAG, "surfaceCreated: CREATED"); mCamera.setPreviewDisplay(mHolder); mCamera.startPreview(); } catch (IOException e) { @@ -62,15 +60,7 @@ public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback @Override public void surfaceDestroyed(SurfaceHolder holder) { - Log.d(TAG, "surfaceDestroyed: DESTROYED"); mCamera.stopPreview(); 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; - } } diff --git a/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/MainActivity.java b/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/MainActivity.java index ab1768c..9d4e938 100644 --- a/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/MainActivity.java +++ b/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/MainActivity.java @@ -15,6 +15,7 @@ import android.view.View; import com.google.firebase.auth.FirebaseAuth; import nl.myhyvesbookplus.tagram.controller.DownloadClass; +import nl.myhyvesbookplus.tagram.controller.PostUploader; import nl.myhyvesbookplus.tagram.controller.ProfilePictureUploader; public class MainActivity extends AppCompatActivity implements diff --git a/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/PicturePreview.java b/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/PicturePreview.java index 4fe18a5..80c2dee 100644 --- a/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/PicturePreview.java +++ b/app/MyHyvesBookPlusStagram/app/src/main/java/nl/myhyvesbookplus/tagram/PicturePreview.java @@ -28,6 +28,7 @@ public class PicturePreview extends SurfaceView implements SurfaceHolder.Callbac public PicturePreview(Context context, Bitmap bmp) { super(context); picture = Bitmap.createScaledBitmap(bmp, 1920, 1440, false); +// picture = Bitmap.createBitmap(bmp); setWillNotDraw(false); } @@ -41,17 +42,26 @@ public class PicturePreview extends SurfaceView implements SurfaceHolder.Callbac switch (currentFilter) { case FILTER_NONE: canvas.drawBitmap(picture, 0, 0, null); + canvas.rotate(90); filterPicture = picture; break; case FILTER_SEPIA: canvas.drawBitmap(toSepia(picture), 0, 0, null); + canvas.rotate(90); filterPicture = toSepia(picture); break; case FILTER_BW: + Canvas bw = new Canvas(); + filterPicture = Bitmap.createBitmap(1920, 1440, null); +// filterPicture = Bitmap.createBitmap(picture.getWidth(), picture.getHeight(), null); cm.setSaturation(0); filter = new ColorMatrixColorFilter(cm); paint.setColorFilter(filter); + bw.setBitmap(filterPicture); + bw.drawBitmap(picture, 0, 0, paint); + bw.rotate(90); canvas.drawBitmap(picture, 0, 0, paint); + canvas.rotate(90); break; } } @@ -85,7 +95,7 @@ public class PicturePreview extends SurfaceView implements SurfaceHolder.Callbac } public Bitmap toSepia(Bitmap color) { - int red, green, blue, pixel, gry; + int red, green, blue, pixel; int height = color.getHeight(); int width = color.getWidth(); int depth = 20; diff --git a/app/MyHyvesBookPlusStagram/app/src/main/res/layout/fragment_camera.xml b/app/MyHyvesBookPlusStagram/app/src/main/res/layout/fragment_camera.xml index fca8b36..27b8601 100644 --- a/app/MyHyvesBookPlusStagram/app/src/main/res/layout/fragment_camera.xml +++ b/app/MyHyvesBookPlusStagram/app/src/main/res/layout/fragment_camera.xml @@ -70,6 +70,35 @@ android:src="@drawable/ic_arrow_forward_black_24dp"/> + + + + + +