Anda di halaman 1dari 35

IMPLEMENTATION :

5.1 Log In :

LoginActivity.java

package com.example.blogapp.Activities;

import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.Toast;

import com.example.blogapp.R;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;

public class LoginActivity extends AppCompatActivity {

private EditText userMail,userPassword;


private Button btnLogin;
private ProgressBar loginProgress;
private FirebaseAuth mAuth;
private Intent HomeActivity;
private ImageView login_photo;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);

userMail = findViewById(R.id.login_mail);
userPassword = findViewById(R.id.login_password);
btnLogin = findViewById(R.id.login_btn);
loginProgress = findViewById(R.id.login_progress);
mAuth = FirebaseAuth.getInstance();
HomeActivity = new Intent(this, com.example.blogapp.Activities.Home.class);
login_photo = findViewById(R.id.login_photo);
login_photo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

Intent registerActivity = new Intent(getApplicationContext(),RegisterActivity.class);


startActivity(registerActivity);
finish();

}
});

loginProgress.setVisibility(View.INVISIBLE);
btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
loginProgress.setVisibility(View.VISIBLE);
btnLogin.setVisibility(View.INVISIBLE);

final String mail = userMail.getText().toString();


final String password = userPassword.getText().toString();

if (mail.isEmpty() || password.isEmpty()) {

showMessage("please verify all fields");


btnLogin.setVisibility(View.VISIBLE);
loginProgress.setVisibility(View.INVISIBLE);

}
else
{
signIn(mail,password);
}

}
});

private void signIn(String mail, String password) {

mAuth.signInWithEmailAndPassword(mail,password).addOnCompleteListener(new
OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {

if (task.isSuccessful()) {

loginProgress.setVisibility(View.INVISIBLE);
btnLogin.setVisibility(View.VISIBLE);
updateUI();

} else{
showMessage(task.getException().getMessage());
btnLogin.setVisibility(View.VISIBLE);
loginProgress.setVisibility(View.INVISIBLE);

}
});

private void updateUI() {

startActivity(HomeActivity);
finish();
}

private void showMessage(String text) {

Toast.makeText(getApplicationContext(),text,Toast.LENGTH_LONG).show();

@Override
protected void onStart() {
super.onStart();
FirebaseUser user = mAuth.getCurrentUser();

if(user !=null) {
updateUI();
}

}
}
-------------------- ------------------------------------------- ---------------------------------------------------
Activity_login.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=".Activities.LoginActivity"
android:background="#fff">

<ImageView
android:id="@+id/login_photo"
android:layout_width="265dp"
android:layout_height="100dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/userphoto" />

<android.support.constraint.Guideline
android:id="@+id/guideline2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.5" />

<EditText
android:hint="Email"
android:background="@drawable/reg_edittext_style"
android:id="@+id/login_mail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="4dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintBottom_toTopOf="@+id/guideline2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/login_photo" />

<EditText
android:hint="password"
android:background="@drawable/reg_edittext_style"
android:id="@+id/login_password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="136dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintBottom_toTopOf="@+id/login_btn"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/login_mail" />

<Button
android:textColor="#fff"
android:id="@+id/login_btn"
android:layout_width="145dp"
android:layout_height="50dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
android:background="@drawable/reg_btn_style"
android:text="LogIn"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/login_password" />

<ProgressBar
android:id="@+id/login_progress"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="@+id/login_btn"
app:layout_constraintEnd_toEndOf="@+id/login_btn"
app:layout_constraintStart_toStartOf="@+id/login_btn"
app:layout_constraintTop_toTopOf="@+id/login_btn" />
</android.support.constraint.ConstraintLayout>

--------------------------------------------------------------------------------------
5.2 Register :

RegisterActivity.java

package com.example.blogapp.Activities;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.media.Image;
import android.net.Uri;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.Toast;

import com.example.blogapp.R;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
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 com.google.firebase.storage.UploadTask;

public class RegisterActivity extends AppCompatActivity {

ImageView ImgUserPhoto;
static int PReqCode = 1;
static int REQUESCODE = 1;
Uri pickedImgUri ;

private EditText userEmail, userPassword, userPassword2,userName;


private ProgressBar loadingProgress;
private Button regbtn;
private FirebaseAuth mAuth;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);

//inu Views
userEmail = findViewById(R.id.regMail);
userPassword = findViewById(R.id.regPassword);
userPassword2 = findViewById(R.id.regPassword2);
userName = findViewById(R.id.regName);
loadingProgress = findViewById(R.id.regProgressBar);
regbtn = findViewById(R.id.regBtn);
loadingProgress.setVisibility(View.INVISIBLE);

mAuth = FirebaseAuth.getInstance();

regbtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

regbtn.setVisibility(View.INVISIBLE);
loadingProgress.setVisibility(View.VISIBLE);
final String email = userEmail.getText().toString();
final String password = userPassword.getText().toString();
final String password2 = userPassword2.getText().toString();
final String name = userName.getText().toString();

if ( email.isEmpty() || name.isEmpty() || password.isEmpty() ||


!password.equals(password2)) {

showMessage("Please verify all fields") ;


regbtn.setVisibility(View.VISIBLE);
loadingProgress.setVisibility(View.INVISIBLE);

}
else {
CreateUserAccount(email,name,password);
}

}
});

ImgUserPhoto = findViewById(R.id.regUserPhoto) ;

ImgUserPhoto.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

if(Build.VERSION.SDK_INT>=22){

checkAndRequestForPermission();
}
else{

openGallery();
}

}
});
}

private void CreateUserAccount(String email, final String name, String password) {

//this create email and password with specific details

mAuth.createUserWithEmailAndPassword(email,password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if(task.isSuccessful()) {
showMessage("Account Created");
updateUserInfo(name, pickedImgUri, mAuth.getCurrentUser());

}
else {
showMessage("Account Creation Failed" +
task.getException().getMessage());
regbtn.setVisibility(View.VISIBLE);
loadingProgress.setVisibility(View.INVISIBLE);

}
}
});

private void updateUserInfo(final String name, Uri pickedImgUri, final FirebaseUser


currentUser) {
StorageReference mstorage =
FirebaseStorage.getInstance().getReference().child("users_photos");
final StorageReference imageFilePath =
mstorage.child(pickedImgUri.getLastPathSegment());
imageFilePath.putFile(pickedImgUri).addOnSuccessListener(new
OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {

imageFilePath.getDownloadUrl().addOnSuccessListener(new
OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {

UserProfileChangeRequest profileUpdate = new


UserProfileChangeRequest.Builder()
.setDisplayName(name)
.setPhotoUri(uri)
.build();

currentUser.updateProfile(profileUpdate)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {

if(task.isSuccessful()) {
showMessage("Register Complete");
updateUI();
}

}
});
}
});

}
});

private void updateUI() {

Intent homeActivity = new Intent(getApplicationContext(),Home.class);


startActivity(homeActivity);
finish();

private void showMessage(String message) {

Toast.makeText(getApplicationContext(),message,Toast.LENGTH_LONG).show();

private void openGallery() {


//TODO: open gallery intent and wait for user to pick an image!

Intent galleryIntent = new Intent(Intent.ACTION_GET_CONTENT);


galleryIntent.setType("image/*");
startActivityForResult(galleryIntent,REQUESCODE);

private void checkAndRequestForPermission() {


if(ContextCompat.checkSelfPermission(RegisterActivity.this,
Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(RegisterActivity.this,
Manifest.permission.READ_EXTERNAL_STORAGE)) {
Toast.makeText(RegisterActivity.this,"Please accept for requested
permission",Toast.LENGTH_SHORT).show();

}
else{
ActivityCompat.requestPermissions(RegisterActivity.this,
new
String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
PReqCode);
}
}
else
openGallery();

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK && requestCode == REQUESCODE && data !=null ) {

pickedImgUri = data.getData ();


ImgUserPhoto.setImageURI(pickedImgUri);

}
}

--------------------------------------------------------------------------------------------------------------------
Activity_Register.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=".Activities.RegisterActivity"
android:background="#ffffff">

<ImageView
android:id="@+id/regUserPhoto"
android:layout_width="265dp"
android:layout_height="100dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:src="@drawable/userphoto"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<android.support.constraint.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.47" />

<EditText
android:background="@drawable/reg_edittext_style"
android:hint="Enter Name"
android:id="@+id/regName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="28dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintBottom_toTopOf="@+id/regMail"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/regUserPhoto"
/>

<EditText
android:background="@drawable/reg_edittext_style"
android:hint="Enter Email"
android:id="@+id/regMail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintBottom_toTopOf="@+id/regPassword"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/regName" />

<EditText
android:id="@+id/regPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
android:background="@drawable/reg_edittext_style"
android:ems="10"
android:hint="Enter Password"
android:inputType="textPassword"
app:layout_constraintBottom_toTopOf="@+id/regPassword2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/regMail" />

<EditText
android:id="@+id/regPassword2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="148dp"
android:background="@drawable/reg_edittext_style"
android:ems="10"
android:hint="Confirm Password"
android:inputType="textPassword"
app:layout_constraintBottom_toTopOf="@+id/regBtn"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/regPassword" />

<Button
android:id="@+id/regBtn"
android:layout_width="132dp"
android:layout_height="46dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="50dp"
android:background="@drawable/reg_btn_style"
android:text="SignUp"
android:textColor="#ffffff"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/regPassword2" />

<ProgressBar
android:id="@+id/regProgressBar"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="@+id/regBtn"
app:layout_constraintEnd_toEndOf="@+id/regBtn"
app:layout_constraintStart_toStartOf="@+id/regBtn"
app:layout_constraintTop_toTopOf="@+id/regBtn" />
</android.support.constraint.ConstraintLayout>
---------------------------------------------------------------------------------------------------------------------

5.3 Post And Comment

Home.java

package com.example.blogapp.Activities;

import android.app.Dialog;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.view.Gravity;
import android.view.View;
import android.support.v4.view.GravityCompat;
import android.support.v7.app.ActionBarDrawerToggle;
import android.view.MenuItem;
import android.support.design.widget.NavigationView;
import android.support.v4.widget.DrawerLayout;

import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.blogapp.Fragments.HomeFragment;
import com.example.blogapp.Fragments.ProfileFragment;
import com.example.blogapp.Fragments.SettingsFragment;
import com.example.blogapp.R;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;

public class Home extends AppCompatActivity


implements NavigationView.OnNavigationItemSelectedListener {

FirebaseAuth mAuth;
FirebaseUser currentUser;
Dialog popAddPost ;
ImageView popUserImage,popupPostImage,popupAddBtn;
TextView popupTitle,popupDescription;
ProgressBar popupClickProgress;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home2);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

mAuth = FirebaseAuth.getInstance();
currentUser = mAuth.getCurrentUser();

//popup
inipopup();

FloatingActionButton fab = findViewById(R.id.fab);


fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
popAddPost.show();
}
});
DrawerLayout drawer = findViewById(R.id.drawer_layout);
NavigationView navigationView = findViewById(R.id.nav_view);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open,
R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
navigationView.setNavigationItemSelectedListener(this);

updateNavHeader();
}

private void inipopup() {


popAddPost = new Dialog(this);

popAddPost.setContentView(R.layout.popup_add_post);
popAddPost.getWindow().setBackgroundDrawable(new
ColorDrawable(Color.TRANSPARENT));

popAddPost.getWindow().setLayout(Toolbar.LayoutParams.MATCH_PARENT,Toolbar.Layo
utParams.WRAP_CONTENT);
popAddPost.getWindow().getAttributes().gravity = Gravity.TOP;

//popup widgets
popupPostImage = popAddPost.findViewById(R.id.popup_user_image);
popupTitle = popAddPost.findViewById(R.id.popup_title);
popupDescription = popAddPost.findViewById(R.id.popup_description);
popupAddBtn = popAddPost.findViewById(R.id.popup_app);
popupClickProgress = popAddPost.findViewById(R.id.popup_progressBar);

// loads users current profile


Glide.with(Home.this).load(currentUser.getPhotoUrl()).into(popupPostImage);

// Add post click listener


popupAddBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
popupAddBtn.setVisibility(View.INVISIBLE);
popupClickProgress.setVisibility(View.VISIBLE);

}
});

@Override
public void onBackPressed() {
DrawerLayout drawer = findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.home, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}

@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();

if (id == R.id.nav_home) {
getSupportActionBar().setTitle("Post And Comment");

getSupportFragmentManager().beginTransaction().replace(R.id.container,new
HomeFragment()).commit();

} else if (id == R.id.nav_profile) {


getSupportActionBar().setTitle("Profile");

getSupportFragmentManager().beginTransaction().replace(R.id.container,new
ProfileFragment()).commit();

} else if (id == R.id.nav_settings) {


getSupportActionBar().setTitle("Settings");

getSupportFragmentManager().beginTransaction().replace(R.id.container,new
SettingsFragment()).commit();

} else if (id == R.id.nav_signout) {

FirebaseAuth.getInstance().signOut();
Intent loginActivity = new Intent(getApplicationContext(),LoginActivity.class);
startActivity(loginActivity);
finish();
}

DrawerLayout drawer = findViewById(R.id.drawer_layout);


drawer.closeDrawer(GravityCompat.START);
return true;
}

public void updateNavHeader(){


NavigationView navigationView = findViewById(R.id.nav_view);
View headerView = navigationView.getHeaderView(0);
TextView navUserName = headerView.findViewById(R.id.nav_username);
TextView navUseMail = headerView.findViewById(R.id.nav_user_mail);
ImageView navUserPhoto = headerView.findViewById(R.id.nav_user_photo);

navUseMail.setText(currentUser.getEmail());
navUserName.setText(currentUser.getDisplayName());

Glide.with(this).load(currentUser.getPhotoUrl()).into(navUserPhoto);

}
activity_home.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=".Activities.HomeActivity">

</android.support.constraint.ConstraintLayout>

---------------------------------------------------------------------------------------------------------------------

activity_home2.xml

<?xml version="1.0" encoding="utf-8"?>


<android.support.v4.widget.DrawerLayout
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:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">

<include
layout="@layout/app_bar_home"
android:layout_width="match_parent"
android:layout_height="match_parent" />

<android.support.design.widget.NavigationView
android:background="#fff"
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_home"
app:menu="@menu/activity_home2_drawer" />

</android.support.v4.widget.DrawerLayout>

---------------------------------------------------------------------------------------------------------------------

app_bar_home.xml

<?xml version="1.0" encoding="utf-8"?>


<android.support.design.widget.CoordinatorLayout
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=".Activities.Home">

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

<include layout="@layout/content_home" />

<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@drawable/ic_edit_black_24dp" />

</android.support.design.widget.CoordinatorLayout>

--------------------------------------------------------------------------------------------------------------------

content_home.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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".Activities.Home"
tools:showIn="@layout/app_bar_home">

<FrameLayout
android:id="@+id/container"

android:layout_width="match_parent"
android:layout_height="match_parent"></FrameLayout>

</android.support.constraint.ConstraintLayout>

--------------------------------------------------------------------------------------------------------------------

nav_header_home.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"
android:layout_width="match_parent"
android:layout_height="@dimen/nav_header_height"
android:gravity="bottom"
android:orientation="vertical"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:theme="@style/ThemeOverlay.AppCompat.Dark"
android:background="#ffffff">

<ImageView
android:scaleType="centerCrop"
android:id="@+id/nav_user_photo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/nav_header_desc"
android:paddingTop="@dimen/nav_header_vertical_spacing"
app:srcCompat="@mipmap/ic_launcher_round" />

<TextView
android:id="@+id/nav_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/nav_header_vertical_spacing"
android:textColor="#000000"
android:text="@string/nav_header_title"
android:textAppearance="@style/TextAppearance.AppCompat.Body1" />

<TextView
android:id="@+id/nav_user_mail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/nav_header_subtitle"
android:textColor="#000000"/>

</LinearLayout>

--------------------------------------------------------------------------------------------------------------------

popup_add_post.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="wrap_content"
tools:layout_editor_absoluteY="81dp">

<ImageView
android:background="#ffffff"
android:id="@+id/popup_user_image"
android:layout_width="48dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@+id/popup_description"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/popup_title"
app:layout_constraintTop_toTopOf="parent"
tools:srcCompat="@tools:sample/avatars" />

<EditText
android:id="@+id/popup_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@drawable/popup_edittext_style"
android:ems="10"
android:hint="Title"
android:inputType="textPersonName"
app:layout_constraintEnd_toStartOf="@+id/popup_user_image"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<EditText
android:id="@+id/popup_description"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:background="@drawable/popup_edittext_style"
android:ems="10"
android:hint="Description"
android:inputType="textPersonName"
app:layout_constraintEnd_toEndOf="@+id/popup_user_image"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/popup_title" />
<ImageView
android:id="@+id/popup_app"

android:layout_width="160dp"
android:layout_height="44dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
android:background="@drawable/circle_bg"
android:padding="12dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/popup_description"
app:layout_constraintVertical_bias="0.0"
app:srcCompat="@drawable/ic_edit_black_24dp" />

<ProgressBar
android:padding="4dp"
android:background="@drawable/circle_bg"
android:visibility="invisible"
android:id="@+id/popup_progressBar"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
app:layout_constraintBottom_toBottomOf="@+id/popup_app"
app:layout_constraintEnd_toEndOf="@+id/popup_app"
app:layout_constraintStart_toStartOf="@+id/popup_app"
app:layout_constraintTop_toTopOf="@+id/popup_app" />
</android.support.constraint.ConstraintLayout>

HomeFragment.java

package com.example.blogapp.Fragments;

import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.blogapp.R;

/**
* A simple {@link Fragment} subclass.
* Activities that contain this fragment must implement the
* {@link HomeFragment.OnFragmentInteractionListener} interface
* to handle interaction events.
* Use the {@link HomeFragment#newInstance} factory method to
* create an instance of this fragment.
*/
public class HomeFragment extends Fragment {
// 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";

// TODO: Rename and change types of parameters


private String mParam1;
private String mParam2;

private OnFragmentInteractionListener mListener;

public HomeFragment() {
// Required empty public constructor
}

/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @param param1 Parameter 1.
* @param param2 Parameter 2.
* @return A new instance of fragment HomeFragment.
*/
// TODO: Rename and change types and number of parameters
public static HomeFragment newInstance(String param1, String param2) {
HomeFragment fragment = new HomeFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_home, container, false);
}

// TODO: Rename method, update argument and hook method into UI event
public void onButtonPressed(Uri uri) {
if (mListener != null) {
mListener.onFragmentInteraction(uri);
}
}

@Override
public void onAttach(Context context) {
super.onAttach(context);
}

@Override
public void onDetach() {
super.onDetach();
mListener = null;
}

/**
* This interface must be implemented by activities that contain this
* 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.
*/
public interface OnFragmentInteractionListener {
// TODO: Update argument type and name
void onFragmentInteraction(Uri uri);
}
}

ProfileFragment.java

package com.example.blogapp.Fragments;

import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.blogapp.R;

/**
* A simple {@link Fragment} subclass.
* Activities that contain this fragment must implement the
* {@link ProfileFragment.OnFragmentInteractionListener} interface
* to handle interaction events.
* Use the {@link ProfileFragment#newInstance} factory method to
* create an instance of this fragment.
*/
public class ProfileFragment extends Fragment {
// 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";

// TODO: Rename and change types of parameters


private String mParam1;
private String mParam2;

private OnFragmentInteractionListener mListener;

public ProfileFragment() {
// Required empty public constructor
}

/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @param param1 Parameter 1.
* @param param2 Parameter 2.
* @return A new instance of fragment ProfileFragment.
*/
// TODO: Rename and change types and number of parameters
public static ProfileFragment newInstance(String param1, String param2) {
ProfileFragment fragment = new ProfileFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}

@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);
}

// TODO: Rename method, update argument and hook method into UI event
public void onButtonPressed(Uri uri) {
if (mListener != null) {
mListener.onFragmentInteraction(uri);
}
}

@Override
public void onAttach(Context context) {
super.onAttach(context);
}

@Override
public void onDetach() {
super.onDetach();
mListener = null;
}

/**
* This interface must be implemented by activities that contain this
* 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.
*/
public interface OnFragmentInteractionListener {
// TODO: Update argument type and name
void onFragmentInteraction(Uri uri);
}
}

SettingsFragment.java

package com.example.blogapp.Fragments;

import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.blogapp.R;

/**
* A simple {@link Fragment} subclass.
* Activities that contain this fragment must implement the
* {@link SettingsFragment.OnFragmentInteractionListener} interface
* to handle interaction events.
* Use the {@link SettingsFragment#newInstance} factory method to
* create an instance of this fragment.
*/
public class SettingsFragment extends Fragment {
// 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";
// TODO: Rename and change types of parameters
private String mParam1;
private String mParam2;

private OnFragmentInteractionListener mListener;

public SettingsFragment() {
// Required empty public constructor
}

/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @param param1 Parameter 1.
* @param param2 Parameter 2.
* @return A new instance of fragment SettingsFragment.
*/
// TODO: Rename and change types and number of parameters
public static SettingsFragment newInstance(String param1, String param2) {
SettingsFragment fragment = new SettingsFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_settings, container, false);
}

// TODO: Rename method, update argument and hook method into UI event
public void onButtonPressed(Uri uri) {
if (mListener != null) {
mListener.onFragmentInteraction(uri);
}
}

@Override
public void onAttach(Context context) {
super.onAttach(context);
}

@Override
public void onDetach() {
super.onDetach();
mListener = null;
}

/**
* This interface must be implemented by activities that contain this
* 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.
*/
public interface OnFragmentInteractionListener {
// TODO: Update argument type and name
void onFragmentInteraction(Uri uri);
}
}

Fragment_Home.xml

<?xml version="1.0" encoding="utf-8"?>


<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Fragments.HomeFragment">

<!-- TODO: Update blank fragment layout -->


<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Home Fragment" />

</FrameLayout>

Fragment_Profile.xml

<?xml version="1.0" encoding="utf-8"?>


<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Fragments.ProfileFragment">

<!-- TODO: Update blank fragment layout -->


<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Profile Fragment" />

</FrameLayout>

Fragment_Settings.xml

<?xml version="1.0" encoding="utf-8"?>


<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Fragments.SettingsFragment">

<!-- TODO: Update blank fragment layout -->


<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Settings Fragment" />

</FrameLayout>

---------------------------------------------------------------------------------------------------------------------

C:\Users\KEERTHIPATIVINAY\AndroidStudioProjects\BlogApp\app\src\main\res\values\color
s.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#008577</color>
<color name="colorPrimaryDark">#00574B</color>
<color name="colorAccent">#D81B60</color>
</resources>

C:\Users\KEERTHIPATIVINAY\AndroidStudioProjects\BlogApp\app\src\main\res\values\dime
ns.xml

<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="nav_header_vertical_spacing">8dp</dimen>
<dimen name="nav_header_height">176dp</dimen>
<dimen name="fab_margin">16dp</dimen>
</resources>

C:\Users\KEERTHIPATIVINAY\AndroidStudioProjects\BlogApp\app\src\main\res\values\draw
ables.xml

<resources xmlns:android="http://schemas.android.com/apk/res/android">
<item name="ic_menu_camera"
type="drawable">@android:drawable/ic_menu_camera</item>
<item name="ic_menu_gallery"
type="drawable">@android:drawable/ic_menu_gallery</item>
<item name="ic_menu_slideshow"
type="drawable">@android:drawable/ic_menu_slideshow</item>
<item name="ic_menu_manage"
type="drawable">@android:drawable/ic_menu_manage</item>
<item name="ic_menu_share"
type="drawable">@android:drawable/ic_menu_share</item>
<item name="ic_menu_send"
type="drawable">@android:drawable/ic_menu_send</item>
</resources>

C:\Users\KEERTHIPATIVINAY\AndroidStudioProjects\BlogApp\app\src\main\res\values\strin
gs.xml

<resources>
<string name="app_name">BlogApp</string>
<string name="title_activity_home">Home</string>
<string name="navigation_drawer_open">Open navigation drawer</string>
<string name="navigation_drawer_open1">Open navigation drawer1</string>
<string name="navigation_drawer_close">Close navigation drawer</string>
<string name="navigation_drawer_close2">Close navigation drawer2</string>
<string name="nav_header_title">Android Studio</string>
<string name="nav_header_subtitle">android.studio@android.com</string>
<string name="nav_header_desc">Navigation header</string>
<string name="action_settings">Settings</string>

<string name="home">Home</string>
<string name="profile">Profile</string>
<string name="settings">Settings</string>
<string name="signout">Sign Out</string>
<string name="menu_share">Share</string>
<string name="menu_send">Send</string>

<!-- TODO: Remove or change this placeholder text -->


<string name="hello_blank_fragment">Hello blank fragment</string>
</resources>

Anda mungkin juga menyukai