Merge remote-tracking branch 'origin/niels-profile' into marijn-appje

This commit is contained in:
Marijn Jansen
2017-06-23 11:50:04 +02:00
23 changed files with 475 additions and 25 deletions

View File

@@ -28,9 +28,13 @@ dependencies {
compile 'com.android.support:design:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:support-v4:25.3.1'
compile 'com.google.firebase:firebase-database:11.0.1'
compile 'com.google.firebase:firebase-auth:11.0.1'
compile 'com.google.firebase:firebase-storage:11.0.1'
// FirebaseUI Storage only
compile 'com.firebaseui:firebase-ui-storage:2.0.1'
testCompile 'junit:junit:4.12'
}

View File

@@ -2,6 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="nl.myhyvesbookplus.tagram">
<uses-permission android:name="android.permission.CAMERA" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"

View File

@@ -1,13 +1,25 @@
package nl.myhyvesbookplus.tagram;
import android.content.Context;
import android.hardware.Camera;
import android.hardware.Camera.PictureCallback;
import android.net.Uri;
import android.os.Bundle;
import android.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
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.
@@ -29,6 +41,9 @@ public class CameraFragment extends Fragment {
private OnFragmentInteractionListener mListener;
private Camera mCamera;
private CameraPreview mPreview;
public CameraFragment() {
// Required empty public constructor
}
@@ -58,13 +73,69 @@ public class CameraFragment extends Fragment {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
// Hide top bar
// ((AppCompatActivity) getActivity()).getSupportActionBar().hide();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_camera, container, false);
final View view = inflater.inflate(R.layout.fragment_camera, container, false);
mPreview = new CameraPreview(getActivity().getBaseContext(), mCamera);
final RelativeLayout preview = (RelativeLayout) view.findViewById(R.id.camera_preview);
preview.addView(mPreview);
// Draw picture and switch button over preview
view.findViewById(R.id.picture_button).bringToFront();
view.findViewById(R.id.switch_camera_button).bringToFront();
((ImageButton)view.findViewById(R.id.picture_button)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getActivity(), "Snap!", Toast.LENGTH_SHORT).show();
/*
PictureCallback mPicture = new PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
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);
preview.addView(mPreview);
view.findViewById(R.id.picture_button).bringToFront();
view.findViewById(R.id.switch_camera_button).bringToFront();
}
});
return view;
}
// TODO: Rename method, update argument and hook method into UI event
@@ -91,6 +162,30 @@ public class CameraFragment extends Fragment {
mListener = null;
}
public static Camera getCameraInstance(int facing) {
Camera c = null;
try {
c = Camera.open(facing);
} catch (Exception e) {
e.getStackTrace();
}
return c;
}
@Override
public void onPause() {
super.onPause();
}
@Override
public void onResume() {
super.onResume();
}
public void setCamera(Camera c) {
this.mCamera = c;
}
/**
* This interface must be implemented by activities that contain this
* fragment to allow an interaction in this fragment to be communicated

View File

@@ -0,0 +1,73 @@
package nl.myhyvesbookplus.tagram;
import android.content.Context;
import android.hardware.Camera;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import java.io.IOException;
public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback {
private SurfaceHolder mHolder;
private Camera mCamera;
private static int facing = 0;
public CameraPreview(Context context, Camera camera) {
super(context);
mCamera = camera.open(facing);
mCamera.setDisplayOrientation(90);
mHolder = getHolder();
mHolder.addCallback(this);
}
@Override
public void surfaceCreated(SurfaceHolder mHolder) {
try {
mCamera.setPreviewDisplay(mHolder);
mCamera.startPreview();
} catch (IOException e) {
e.getStackTrace();
}
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
if (mHolder.getSurface() == null){
// preview surface does not exist
return;
}
// stop preview before making changes
try {
mCamera.stopPreview();
} catch (Exception e){
// ignore: tried to stop a non-existent preview
}
// set preview size and make any resize, rotate or
// reformatting changes here
// start preview with new settings
try {
mCamera.setPreviewDisplay(mHolder);
mCamera.startPreview();
} catch (Exception e){
Log.d("camera", "Error starting camera preview: " + e.getMessage());
}
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
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;
}
}

View File

@@ -235,6 +235,7 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList
});
}
//TODO Make modular for use with Profile fragment.
/**
* Saves the Username to Firebase
* @param user The User object that needs to be updated

View File

@@ -4,6 +4,7 @@ import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.graphics.Bitmap;
import android.hardware.Camera;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
@@ -73,6 +74,8 @@ public class MainActivity extends AppCompatActivity implements CameraFragment.On
goToLogin();
}
Log.d(TAG, "onCreate: " + mAuth.getCurrentUser().getPhotoUrl() );
TimelineFragment fragment = new TimelineFragment();
FragmentTransaction transaction = getFragmentManager().beginTransaction();

View File

@@ -1,13 +1,38 @@
package nl.myhyvesbookplus.tagram;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.app.Fragment;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.ImageView;
import android.widget.Toast;
import com.bumptech.glide.Glide;
import com.firebase.ui.storage.images.FirebaseImageLoader;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.auth.UserProfileChangeRequest;
import com.google.firebase.storage.FirebaseStorage;
import com.google.firebase.storage.StorageReference;
import java.net.URI;
import static android.app.Activity.RESULT_OK;
import static android.content.ContentValues.TAG;
/**
* A simple {@link Fragment} subclass.
@@ -17,21 +42,33 @@ import android.view.ViewGroup;
* Use the {@link ProfileFragment#newInstance} factory method to
* create an instance of this fragment.
*/
public class ProfileFragment extends Fragment {
public class ProfileFragment extends Fragment implements View.OnClickListener {
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
static final int REQUEST_IMAGE_CAPTURE = 1;
private static Uri downloadUrl;
// TODO: Rename and change types of parameters
private String mParam1;
private String mParam2;
private OnFragmentInteractionListener mListener;
/// Views ///
protected Button changePwdButton;
protected ImageButton profilePicButton;
protected StorageReference httpsReference;
protected TextView profileName;
protected ImageView profilePicture;
private OnFragmentInteractionListener mListener;
protected FirebaseUser user;
/// Required empty public constructor ///
public ProfileFragment() {}
public ProfileFragment() {
// Required empty public constructor
}
/**
* Use this factory method to create a new instance of
@@ -58,13 +95,47 @@ public class ProfileFragment extends Fragment {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
user = FirebaseAuth.getInstance().getCurrentUser();
if (user != null && user.getPhotoUrl() != null) {
httpsReference = FirebaseStorage.getInstance().getReferenceFromUrl(user.getPhotoUrl().toString());
}
}
/**
* Assigns all views.
*/
protected void findViews(View view) {
profilePicButton = (ImageButton) view.findViewById(R.id.profile_pic_button);
profilePicture = (ImageView) view.findViewById(R.id.imageView_profile_picture);
profileName = (TextView) view.findViewById(R.id.profile_name);
changePwdButton = (Button) view.findViewById(R.id.change_psw_button);
bindOnClick();
}
protected void bindOnClick() {
profilePicButton.setOnClickListener(this);
changePwdButton.setOnClickListener(this);
}
/// Setup ///
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_profile, container, false);
View view = inflater.inflate(R.layout.fragment_profile, container, false);
findViews(view);
if (httpsReference != null) {
Glide.with(this).using(new FirebaseImageLoader()).load(httpsReference).into(profilePicture);
}
if (user != null && user.getDisplayName() != null) {
profileName.setText(user.getDisplayName());
}
return view;
}
// TODO: Rename method, update argument and hook method into UI event
@@ -74,6 +145,102 @@ public class ProfileFragment extends Fragment {
}
}
/**
* Called when a view has been clicked.
*
* @param v The view that was clicked.
*/
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.profile_pic_button:
profilePicOnClick();
break;
case R.id.change_psw_button:
changePwdOnClick();
break;
}
}
// TODO Make the function actually do something.
/**
* Performs profile picture change action.
*/
public void profilePicOnClick() {
// Log.d(TAG, "profilePicOnClick: JE KAN NOG GEEN FOTO UPLOADEN");
dispatchTakePictureIntent();
}
/**
* Starts new intent for access to the built-in camera of device.
*/
private void dispatchTakePictureIntent() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}
}
/**
* Grabs the image just taken by the built-in camera and pushes this image to the user account.
* @param requestCode
* @param resultCode
* @param data
*/
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
UploadClass uploadClass = new UploadClass();
uploadClass.uploadPicture(imageBitmap);
downloadUrl = uploadClass.getDownloadUrl();
updateUserProfilePic(user);
}
}
protected void updateUserProfilePic(final FirebaseUser user) {
UserProfileChangeRequest request = new UserProfileChangeRequest.Builder()
.setPhotoUri(downloadUrl)
.build();
user.updateProfile(request)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Log.d(TAG, "User profile updated!");
}
}
});
}
// TODO Make this function into its own class for modularity.
/**
* Performs password reset action.
*/
public void changePwdOnClick() {
if (user != null && user.getEmail() != null) {
FirebaseAuth.getInstance().sendPasswordResetEmail(user.getEmail())
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
Toast.makeText(getActivity(), task.isSuccessful()
? "An e-mail was sent, please follow its instructions."
: "An error occurred, please check internet connection.",
Toast.LENGTH_SHORT).show();
}
});
} else {
// TODO Add code here for when there is no currently active user.
}
}
/**
* Obligatory onAttach function included in fragments.
* @param context provided context for the function to operate on.
*/
@Override
public void onAttach(Context context) {
super.onAttach(context);
@@ -85,6 +252,9 @@ public class ProfileFragment extends Fragment {
}
}
/**
* Obligatory onDetach function included in fragments.
*/
@Override
public void onDetach() {
super.onDetach();
@@ -96,10 +266,8 @@ public class ProfileFragment extends Fragment {
* fragment to allow an interaction in this fragment to be communicated
* to the activity and potentially other fragments contained in that
* activity.
* <p>
* See the Android Training lesson <a href=
* "http://developer.android.com/training/basics/fragments/communicating.html"
* >Communicating with Other Fragments</a> for more information.
* See the Android Training lesson http://developer.android.com/training/basics/fragments/communicating.html
* for more information.
*/
public interface OnFragmentInteractionListener {
// TODO: Update argument type and name

View File

@@ -33,6 +33,7 @@ public class UploadClass {
private DatabaseReference mDataRef;
private static final String TAG = "UploadClass";
private static Uri downloadUrl;
public UploadClass() {
mStorageRef = FirebaseStorage.getInstance().getReference();
@@ -81,10 +82,15 @@ public class UploadClass {
} else {
Log.d(TAG, "onComplete: " + task.getException().getLocalizedMessage());
}
downloadUrl = taskSnapshot.getMetadata().getDownloadUrl();
}
});
}
public Uri getDownloadUrl() {
return downloadUrl;
}
private String getUserUid() {
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if (user != null) {

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

View File

@@ -1,4 +1,5 @@
<FrameLayout 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"
@@ -9,17 +10,35 @@
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/hello_camera" />
<RelativeLayout
android:id="@+id/camera_preview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<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: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" />
</RelativeLayout>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="logOutOnClick"
android:text="LogOut" />
</LinearLayout>
<!-- TODO: Update blank fragment layout -->
</FrameLayout>

View File

@@ -1,13 +1,81 @@
<FrameLayout 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="nl.myhyvesbookplus.tagram.ProfileFragment">
<!-- TODO: Update blank fragment layout -->
<TextView
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/hello_blank_fragment" />
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">
<Space
android:layout_width="match_parent"
android:layout_height="5dp" />
<TextView
android:id="@+id/profile_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Name:"
android:textSize="25sp"
android:textStyle="bold" />
<Space
android:layout_width="match_parent"
android:layout_height="10dp" />
<ImageButton
android:id="@+id/profile_pic_button"
android:layout_width="60dp"
android:layout_height="80dp"
android:layout_marginStart="110dp"
android:background="@android:color/transparent"
android:elevation="1dp"
app:srcCompat="@android:drawable/ic_menu_camera" />
<ImageView
android:id="@+id/imageView_profile_picture"
android:contentDescription="@string/profile_picture_description"
android:layout_width="match_parent"
android:layout_height="300dp"
app:srcCompat="@drawable/avatar_standard"
android:layout_marginTop="-70dp"/>
<Space
android:layout_width="match_parent"
android:layout_height="25dp" />
<Button
android:id="@+id/change_psw_button"
android:layout_width="300dp"
android:layout_height="50dp"
android:background="?attr/colorPrimary"
android:text="@string/change_psw_button"
android:textColor="@android:color/white"
android:textSize="16sp" />
<Space
android:layout_width="match_parent"
android:layout_height="20dp" />
<Button
android:id="@+id/logout_button"
android:layout_width="300dp"
android:layout_height="50dp"
android:background="?attr/colorPrimary"
android:onClick="logOutOnClick"
android:text="@string/logout_button"
android:textColor="@android:color/white"
android:textSize="16sp" />
</LinearLayout>
</ScrollView>
</FrameLayout>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.0 KiB

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.5 KiB

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.8 KiB

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 19 KiB

View File

@@ -13,5 +13,9 @@
<string name="username">Gebruikersnaam</string>
<string name="confirm_password_hint">bevestig wachtwoord</string>
<string name="logo_text">MyHyvesBookPlusTagram logo</string>
<string name="logout_button">Uitloggen</string>
<string name="profile_picture_button">Wijzig Profiel Foto</string>
<string name="profile_picture_description">profiel foto</string>
<string name="change_psw_button">Wachtwoord wijzigen</string>
<string name="please_wait">Wacht a.u.b.</string>
</resources>

View File

@@ -12,10 +12,17 @@
<string name="register">Register</string>
<string name="back_to_login">back to Login</string>
<string name="email">Email</string>
<string name="login_error">Please fill in email and password</string>
<string name="password_match_error">Passwords do not match</string>
<string name="register_error">Please fill in all the fields</string>
<string name="hello_blank_fragment">Hello blank fragment</string>
<string name="hello_camera">Hello Camera</string>
<string name="logo_text">MyHyvesBookPlusTagram logo</string>
<string name="logout_button">LogOut</string>
<string name="profile_picture_button">Change Profile Picture</string>
<string name="profile_picture_description">profile picture</string>
<string name="change_psw_button">Change Password</string>
<string name="please_wait">Please Wait</string>
<string name="login_error">Please fill in email and password</string>
<string name="register_error">Please fill in all the fields.</string>