Fragmentation

fragment_category.xml
<?xml version=”1.0″ encoding=”utf-8″?>
<RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android&#8221;
xmlns:tools=”http://schemas.android.com/tools&#8221;
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:padding=”16dp”
android:layout_columnWeight=”2″
tools:context=”project.oleo.MainActivity”
>

<android.support.v7.widget.RecyclerView
android:id=”@+id/list_category”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
/>

</RelativeLayout>

How to code fast

format_list_category.xml
<?xml version=”1.0″ encoding=”utf-8″?>
<android.support.v7.widget.CardView xmlns:android=”http://schemas.android.com/apk/res/android&#8221;
android:layout_width=”match_parent”
android:layout_height=”150dp”
android:layout_margin=”10dp”
xmlns:tools=”http://schemas.android.com/tools&#8221;
>

<LinearLayout
android:id=”@+id/background_category”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:padding=”16dp”
>

<LinearLayout
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:orientation=”vertical”
>

<de.hdodenhof.circleimageview.CircleImageView
android:id=”@+id/foto_category”
android:layout_width=”80dp”
android:layout_height=”80dp”
android:src=”@mipmap/ic_launcher”
android:layout_gravity=”center”
/>

<TextView
android:id=”@+id/nama_category”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:fontFamily=”sans-serif-condensed”
android:textSize=”20sp”
android:textStyle=”bold”
tools:text=”Nur Rohman”
android:layout_marginTop=”5dp”
android:layout_gravity=”center”
/>

</LinearLayout>

</LinearLayout>



</android.support.v7.widget.CardView>

Making usual page

activity_main.xml
<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout
xmlns:android=”http://schemas.android.com/apk/res/android&#8221;
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:fitsSystemWindows=”true”
>

<LinearLayout
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:layout_gravity=”center_vertical”
android:orientation=”vertical”
android:paddingLeft=”24dp”
android:paddingRight=”24dp”
android:paddingTop=”56dp”
>

<ImageView
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_gravity=”center_horizontal”
android:layout_marginLeft=”80dp”
android:layout_marginRight=”80dp”
android:src=”@drawable/logo_oleo”
android:layout_weight=”1″
/>

<!–<!– Name Label –>–>
<!–<android.support.design.widget.TextInputLayout–>
<!–android:layout_width=”match_parent”–>
<!–android:layout_height=”wrap_content”–>
<!–android:layout_marginBottom=”8dp”–>
<!–android:layout_marginTop=”8dp”>–>

<!–<EditText–>
<!–android:id=”@+id/input_name”–>
<!–android:layout_width=”match_parent”–>
<!–android:layout_height=”wrap_content”–>
<!–android:hint=”Name”–>
<!–android:inputType=”textCapWords” />–>
<!–</android.support.design.widget.TextInputLayout>–>

<!– Email Label –>
<android.support.design.widget.TextInputLayout
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:layout_marginBottom=”8dp”
android:layout_marginTop=”8dp”
>

<EditText
android:id=”@+id/input_email”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:hint=”Email”
android:inputType=”textEmailAddress”
/>
</android.support.design.widget.TextInputLayout>

<!– Password Label –>
<android.support.design.widget.TextInputLayout
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:layout_marginBottom=”8dp”
android:layout_marginTop=”8dp”
>

<EditText
android:id=”@+id/input_password”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:hint=”Password”
android:inputType=”textPassword”
/>
</android.support.design.widget.TextInputLayout>

<!– Signup Button –>
<android.support.v7.widget.AppCompatButton
android:id=”@+id/button_signup”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:layout_marginBottom=”24dp”
android:layout_marginTop=”24dp”
android:padding=”12dp”
android:text=”Buat Akun”
/>

<TextView
android:id=”@+id/link_login”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:layout_marginBottom=”24dp”
android:gravity=”center”
android:text=”@string/text_signup”
android:textSize=”16dip”
/>

<ProgressBar
android:id=”@+id/progressBar”
android:layout_width=”30dp”
android:layout_height=”30dp”
android:layout_gravity=”center|bottom”
android:layout_marginBottom=”20dp”
android:visibility=”gone”
/>

</LinearLayout>


</LinearLayout>

Getting ready with java

activity_main.xml
<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android&#8221;
xmlns:app=”http://schemas.android.com/apk/res-auto&#8221;
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:orientation=”vertical”
>

<android.support.v7.widget.Toolbar
android:id=”@+id/toolbar”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:background=”?attr/colorPrimary”
android:minHeight=”?attr/actionBarSize”
app:popupTheme=”@style/ThemeOverlay.AppCompat.Light”
android:theme=”@style/ThemeOverlay.AppCompat.Dark”
app:titleTextColor=”@android:color/white”
/>

<android.support.v4.widget.DrawerLayout
android:id=”@+id/drawerLayout”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
>

<LinearLayout
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:orientation=”vertical”
>

<android.support.design.widget.TabLayout
android:id=”@+id/tab_layout”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:layout_below=”@+id/toolbar”
android:background=”@color/colorPrimary”
android:minHeight=”?attr/actionBarSize”
android:theme=”@style/ThemeOverlay.AppCompat.Dark.ActionBar”
/>

<android.support.v4.view.ViewPager
android:id=”@+id/view_pager”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
/>
</LinearLayout>


<android.support.design.widget.NavigationView
android:id=”@+id/nav_view”
android:layout_width=”wrap_content”
android:layout_height=”match_parent”
android:layout_gravity=”start”
android:fitsSystemWindows=”true”
app:menu=”@menu/drawer_menu”
/>

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

Activity Java

activity_login.xml
<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android&#8221;
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:fitsSystemWindows=”true”
>

<LinearLayout
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:layout_gravity=”center_vertical”
android:orientation=”vertical”
android:paddingLeft=”24dp”
android:paddingRight=”24dp”
android:paddingTop=”56dp”
>

<ImageView
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_gravity=”center_horizontal”
android:layout_marginLeft=”80dp”
android:layout_marginRight=”80dp”
android:src=”@drawable/logo_oleo”
android:layout_weight=”1″
/>

<!– Email Label –>
<android.support.design.widget.TextInputLayout
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:layout_marginBottom=”8dp”
android:layout_marginTop=”8dp”
>

<EditText
android:id=”@+id/input_email”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:hint=”Email”
android:inputType=”textEmailAddress”
/>
</android.support.design.widget.TextInputLayout>

<!– Password Label –>
<android.support.design.widget.TextInputLayout
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:layout_marginBottom=”8dp”
android:layout_marginTop=”8dp”
>

<EditText
android:id=”@+id/input_password”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:hint=”Password”
android:inputType=”textPassword”
/>
</android.support.design.widget.TextInputLayout>

<android.support.v7.widget.AppCompatButton
android:id=”@+id/button_login”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:layout_marginBottom=”24dp”
android:layout_marginTop=”24dp”
android:padding=”12dp”
android:text=”Masuk”
/>

<TextView
android:id=”@+id/link_signup”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:layout_marginBottom=”24dp”
android:gravity=”center”
android:text=”@string/text_login”
android:textSize=”16dip”
/>

</LinearLayout>
</LinearLayout>

Adapter Java

ViewPagerAdapter.java
package project.;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

/**
* Created by hp on 2/9/2018.
*/

public class ViewPagerAdapter extends FragmentPagerAdapter {

public ViewPagerAdapter(FragmentManager fm) {
super(fm);
}

@Override
public Fragment getItem(int position) {
if (position ==0) {
return new CategoryFragment();
} else return new CategoryFragment();
}

@Override
public int getCount() {
return 2;
}
}

Code Now

SplashScreen.java
package project.;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;

/**
* Created by hp on 2/10/2018.
*/

public class SplashScreen extends AppCompatActivity {

/** Duration of wait **/
private final int SPLASH_DISPLAY_LENGTH = 2000;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.splashscreen);

/* New Handler to start the Menu-Activity
* and close this Splash-Screen after some seconds.*/
new Handler().postDelayed(new Runnable(){
@Override
public void run() {
/* Create an Intent that will start the Menu-Activity. */
startActivity(new Intent(SplashScreen.this, LoginActivity.class));
finish();
}
}, SPLASH_DISPLAY_LENGTH);
}

}

HOW To Code 101

SessionManager.java
package project.;

import android.content.Context;
import android.content.SharedPreferences;

/**
* Created by hp on 2/17/2018.
*/

public class SessionManager {

private static final String PREF_NAME = “Oleo”;
private static final String ID_USER = “USER_ID”;
private static final String EMAIL_USER = “USER_EMAIL”;
private SharedPreferences preferences;
private SharedPreferences.Editor editor;

public SessionManager(Context context) {
preferences = context.getSharedPreferences(PREF_NAME, 0);
editor = preferences.edit();
}

public void setEmail(String email) {
editor.putString(EMAIL_USER, email);
editor.commit();
}

public void setUserID(String id) {
editor.putString(ID_USER, id);
editor.commit();
}

public String getUserID() {
return preferences.getString(ID_USER, “”);
}

public String getEmailUser() { return preferences.getString(EMAIL_USER, “”); }

public void clearUserID() {
editor.remove(ID_USER);
editor.commit();
}

public void clearAll() {
editor.clear();
editor.commit();
}

}