Android / ProblemSolving

Learn and Develope Android Application – Buyer and Seller System (Part – 4.1)

Hello Everyone !!

Now next ,we are going to start with next layouts.

Forget Password Screen: In this we are going to accept two details username and verification code and he will request further process.once request completes we will request user to enter new password.

content_forget.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="**Your_Packge_Name**.ForgetActivity"
    tools:showIn="@layout/activity_forget">

    <TextView
        android:id="@+id/tvusername"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Enter Username"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginTop="16dp"
        android:layout_marginLeft="16dp"
        app:layout_constraintLeft_toLeftOf="parent" />

    <EditText
        android:id="@+id/etusername"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textPersonName"
        android:hint="UserName"
        android:layout_marginTop="10dp"
        app:layout_constraintTop_toBottomOf="@+id/tvusername"
        android:layout_marginLeft="16dp"
        app:layout_constraintLeft_toLeftOf="parent"
        android:layout_marginRight="8dp"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintHorizontal_bias="0.0" />

    <TextView
        android:id="@+id/tvverificaton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Enter Verification Code"
        android:layout_marginTop="22dp"
        app:layout_constraintTop_toBottomOf="@+id/etusername"
        android:layout_marginLeft="16dp"
        app:layout_constraintLeft_toLeftOf="parent" />

    <EditText
        android:id="@+id/etverifyno"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textPersonName"
        android:hint="Verification No."
        android:layout_marginLeft="16dp"
        app:layout_constraintLeft_toLeftOf="parent"
        android:layout_marginTop="10dp"
        app:layout_constraintTop_toBottomOf="@+id/tvverificaton"
        android:layout_marginRight="8dp"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintHorizontal_bias="0.0" />

    <Button
        android:id="@+id/btnrequest"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="REQUEST"
        app:layout_constraintLeft_toLeftOf="parent"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintHorizontal_bias="0.028"
        android:layout_marginTop="8dp"
        app:layout_constraintTop_toBottomOf="@+id/etverifyno" />
</android.support.constraint.ConstraintLayout>

ForgetActivity.java Code:

package ***Your PackageName ***;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class ForgetActivity extends AppCompatActivity {

    EditText etusername,etverifno;
    Button btnrequestpass;

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

       etusername=(EditText)findViewById(R.id.etusername);
        etverifno=(EditText)findViewById(R.id.etverifyno);
        btnrequestpass=(Button)findViewById(R.id.btnrequest);

        btnrequestpass.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(ForgetActivity.this, "Requesting Password Process", Toast.LENGTH_SHORT).show();
                finish();
            }
        });
    }
}

On this screen ,when user request password, we will query server and get entry_id if user registration exists, and we will request user to enter new password. Next we will look at Registration Screen.

In Registration Screen ,We have lots of details to accept. We have to ways to show UI as on one single scrolling screen or categories it and put it on different screen. We will use second way. We made two categories person details and other is login details. These two layouts we will include using include tag in activity_register.xml coordinator layout. The first page we will make visible and second hide. On next button click, we will save data in variables and hide first page and view second page. on Register button,we will collect all data and register user and divert user to login screen.

activity_register.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"
    android:id="@+id/registercontainer"
    tools:context="***Your_Package_Name**.RegisterActivity">

    <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_register"
        android:id="@+id/include1"
        android:visibility="visible"/>
    <include layout="@layout/content_register2"
        android:id="@+id/include2"
        android:visibility="gone"/>
</android.support.design.widget.CoordinatorLayout>

content_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"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="fbasetrial.apps.shrenoid.com.myapplication.RegisterActivity"
    tools:showIn="@layout/activity_register"
    android:id="@+id/registerlayout1">

    <EditText
        android:id="@+id/etname"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textPersonName"
        android:text="Name"
        android:layout_marginRight="8dp"
        app:layout_constraintRight_toRightOf="parent"
        android:layout_marginLeft="8dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintHorizontal_bias="0.32"
        android:layout_marginTop="35dp"
        app:layout_constraintTop_toBottomOf="@+id/textView3" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Register Yourself Here..."
        android:textStyle="bold"
        android:textSize="15dp"
        android:layout_marginRight="8dp"
        app:layout_constraintRight_toRightOf="parent"
        android:layout_marginLeft="8dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginTop="16dp"
        app:layout_constraintHorizontal_bias="0.502" />

    <EditText
        android:id="@+id/etstate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textPersonName"
        android:text="State"
        android:layout_marginLeft="8dp"
        app:layout_constraintLeft_toLeftOf="parent"
        android:layout_marginRight="8dp"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintHorizontal_bias="0.32"
        android:layout_marginTop="8dp"
        app:layout_constraintTop_toBottomOf="@+id/etname" />

    <EditText
        android:id="@+id/etcity"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textPersonName"
        android:text="City"
        android:layout_marginLeft="16dp"
        app:layout_constraintLeft_toLeftOf="parent"
        android:layout_marginRight="8dp"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintHorizontal_bias="0.282"
        android:layout_marginTop="8dp"
        app:layout_constraintTop_toBottomOf="@+id/etstate" />

    <EditText
        android:id="@+id/etmobno"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textPersonName"
        android:text="Mobile No."
        android:layout_marginLeft="8dp"
        app:layout_constraintLeft_toLeftOf="parent"
        android:layout_marginRight="8dp"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintHorizontal_bias="0.32"
        android:layout_marginTop="8dp"
        app:layout_constraintTop_toBottomOf="@+id/etcity" />

    <EditText
        android:id="@+id/etverificatno"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textPersonName"
        android:text="Verification No."
        android:layout_marginLeft="12dp"
        app:layout_constraintLeft_toLeftOf="parent"
        android:layout_marginRight="8dp"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintHorizontal_bias="0.302"
        android:layout_marginTop="8dp"
        app:layout_constraintTop_toBottomOf="@+id/etmobno" />

    <Button
        android:id="@+id/btnnext"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Next"
        android:layout_marginRight="8dp"
        app:layout_constraintRight_toRightOf="parent"
        android:layout_marginLeft="8dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        android:layout_marginBottom="8dp"
        android:layout_marginTop="8dp"
        app:layout_constraintTop_toBottomOf="@+id/etverificatno"
        app:layout_constraintVertical_bias="0.107" />
</android.support.constraint.ConstraintLayout>

content_register2.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"
    android:id="@+id/registerlayout2">

    <EditText
        android:id="@+id/etregusername"
        android:layout_width="304dp"
        android:layout_height="47dp"
        android:ems="10"
        android:inputType="textPersonName"
        android:hint="UserName"
        android:layout_marginTop="10dp"
        app:layout_constraintTop_toBottomOf="@+id/spinner"
        android:layout_marginLeft="8dp"
        app:layout_constraintLeft_toLeftOf="parent" />

    <EditText
        android:id="@+id/etregpass"
        android:layout_width="304dp"
        android:layout_height="47dp"
        android:ems="10"
        android:inputType="textPersonName"
        android:hint="Password"
        android:layout_marginTop="8dp"
        app:layout_constraintTop_toBottomOf="@+id/etregusername"
        android:layout_marginLeft="8dp"
        app:layout_constraintLeft_toLeftOf="parent" />

    <EditText
        android:id="@+id/etregrepass"
        android:layout_width="304dp"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textPersonName"
        android:hint="Re-Password"
        android:layout_marginTop="14dp"
        app:layout_constraintTop_toBottomOf="@+id/etregpass"
        android:layout_marginLeft="8dp"
        app:layout_constraintLeft_toLeftOf="parent" />

    <Button
        android:id="@+id/btnregister"
        android:layout_width="304dp"
        android:layout_height="48dp"
        android:text="Register Me"
        android:layout_marginTop="26dp"
        app:layout_constraintTop_toBottomOf="@+id/etregrepass"
        app:layout_constraintBottom_toBottomOf="parent"
        android:layout_marginBottom="8dp"
        app:layout_constraintVertical_bias="0.112"
        android:layout_marginLeft="8dp"
        app:layout_constraintLeft_toLeftOf="parent" />

    <Spinner
        android:id="@+id/spinner"
        android:entries="@array/user_type"
        android:layout_width="304dp"
        android:layout_height="38dp"
        android:layout_marginLeft="8dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginTop="69dp" />
</android.support.constraint.ConstraintLayout>

For Spinner ,we need to add entries ,so we will add following tag lines to res/values/strings.xml :

<string-array name="user_type">
    <item>Select User Type</item>
    <item>Buyer</item>
    <item>Seller</item>
</string-array>

RegisterActivity.java Code:

package ***Your_Package_Name**;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;

public class RegisterActivity extends AppCompatActivity {

    EditText etname,etstate,etcity,etmobno,etverifyno;
    EditText etusername,etpass,etrepass;
    Spinner spinner;
    Button btnnext,btnregister;
    View view1,view2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        view1=findViewById(R.id.include1);
        view2=findViewById(R.id.include2);

        etname=(EditText)findViewById(R.id.etname);
        etstate=(EditText)findViewById(R.id.etstate);
        etcity=(EditText)findViewById(R.id.etcity);
        etmobno=(EditText)findViewById(R.id.etmobno);
        etverifyno=(EditText)findViewById(R.id.etverificatno);
        btnnext=(Button)findViewById(R.id.btnnext);

        etusername=(EditText)findViewById(R.id.etregusername);
        etpass=(EditText)findViewById(R.id.etregpass);
        etrepass=(EditText)findViewById(R.id.etregrepass);
        btnregister=(Button)findViewById(R.id.btnregister);
        spinner=(Spinner)findViewById(R.id.spinner);

        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                if(i!=0)
                Toast.makeText(RegisterActivity.this, ""+spinner.getItemAtPosition(i), Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {

            }
        });
        btnnext.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {


                view2.setVisibility(View.VISIBLE);
                view1.setVisibility(View.GONE);
            }
        });

        btnregister.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                    Toast.makeText(RegisterActivity.this, "U R Registered", Toast.LENGTH_SHORT).show();
                finish();
            }
        });
    }

Now ,Let’s Create Admin Main Screen ,we are providing admin with four controls – Approve Sellers, Approve Buyers, Add State ,City and Add Grain Details.Approve Sellers and Approve Buyers have similar layout,similarly Add State,City and Add Grain Details . So,Create Two Activity class with layout for Approval_Screen and Add Details Screen.

content_menu.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="***Your_Package_Name**.MenuActivity"
    tools:showIn="@layout/activity_menu">

    <Button
        android:id="@+id/btnapprseller"
        android:layout_width="0dp"
        android:layout_height="48dp"
        android:text="Approve Sellers"
        android:textAllCaps="false"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginTop="40dp"
        android:layout_marginRight="8dp"
        app:layout_constraintRight_toRightOf="parent"
        android:layout_marginLeft="8dp"
        app:layout_constraintLeft_toLeftOf="parent"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp"
        app:layout_constraintHorizontal_bias="0.0" />

    <Button
        android:id="@+id/btnapprvbuyer"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="Approve Buyers"
        android:textAllCaps="false"
        android:layout_marginTop="16dp"
        app:layout_constraintTop_toBottomOf="@+id/btnapprseller"
        android:layout_marginRight="8dp"
        app:layout_constraintRight_toRightOf="parent"
        android:layout_marginLeft="8dp"
        app:layout_constraintLeft_toLeftOf="parent"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp"
        app:layout_constraintHorizontal_bias="0.0" />

    <Button
        android:id="@+id/btnaddstatecity"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:textAllCaps="false"
        android:text="Add State, City"
        android:layout_marginTop="11dp"
        app:layout_constraintTop_toBottomOf="@+id/btnapprvbuyer"
        android:layout_marginLeft="8dp"
        app:layout_constraintLeft_toLeftOf="parent"
        android:layout_marginRight="8dp"
        app:layout_constraintRight_toRightOf="parent"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp"
        app:layout_constraintHorizontal_bias="0.0" />

    <Button
        android:id="@+id/btnaddgrain"
        android:layout_width="0dp"
        android:textAllCaps="false"
        android:layout_height="wrap_content"
        android:text="Add Grain Details"
        android:layout_marginTop="15dp"
        app:layout_constraintTop_toBottomOf="@+id/btnaddstatecity"
        android:layout_marginLeft="8dp"
        app:layout_constraintLeft_toLeftOf="parent"
        android:layout_marginRight="8dp"
        app:layout_constraintRight_toRightOf="parent"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp"
        app:layout_constraintHorizontal_bias="0.0" />

    <Button
        android:id="@+id/btnlogout"
        android:layout_width="0dp"
        android:textAllCaps="false"
        android:layout_height="wrap_content"
        android:text="Logout"
        android:layout_marginTop="15dp"
        app:layout_constraintTop_toBottomOf="@+id/btnaddgrain"
        android:layout_marginLeft="8dp"
        app:layout_constraintLeft_toLeftOf="parent"
        android:layout_marginRight="8dp"
        app:layout_constraintRight_toRightOf="parent"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp"
        app:layout_constraintHorizontal_bias="0.0" />

</android.support.constraint.ConstraintLayout>

MenuActivity.java Code:

package ****Your_Package_Name****;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MenuActivity extends AppCompatActivity {

    Button btnapprovseller,btnapprovbuyer,btnaddstatecity,btnaddgrain,btnlogoutadmin;

    Intent toapprovalscreen,toaddstate_city;

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

        btnapprovseller=(Button)findViewById(R.id.btnapprseller);
        btnapprovbuyer=(Button)findViewById(R.id.btnapprvbuyer);
        btnaddstatecity=(Button)findViewById(R.id.btnaddstatecity);
        btnaddgrain=(Button)findViewById(R.id.btnaddgrain);
        btnlogoutadmin=(Button)findViewById(R.id.btnlogout);

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

                Toast.makeText(MenuActivity.this, "Redirect to Approval Screen ", Toast.LENGTH_SHORT).show();
                toapprovalscreen=new Intent(MenuActivity.this,ApprovalActivity.class);
                startActivity(toapprovalscreen);

            }
        });

        btnapprovbuyer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(MenuActivity.this, "Redirect to Approval Screen ", Toast.LENGTH_SHORT).show();
                toapprovalscreen=new Intent(MenuActivity.this,ApprovalActivity.class);
                startActivity(toapprovalscreen);
            }
        });

        btnaddstatecity.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(MenuActivity.this, "Redirect to Add State,City Screen", Toast.LENGTH_SHORT).show();
                toaddstate_city=new Intent(MenuActivity.this,AddDetails.class);
                startActivity(toaddstate_city);
            }
        });

        btnaddgrain.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(MenuActivity.this, "Redirect to Add Grain Details", Toast.LENGTH_SHORT).show();
                toaddstate_city=new Intent(MenuActivity.this,AddDetails.class);
                startActivity(toaddstate_city);
            }
        });
        btnlogoutadmin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }
}

Here ,we end up with forget password, Registration and Admin Menu Screen with basic code. Next we are going to create approval screen and add details screen and some more things related to background processing of application with UI handling.

Thank You.

2 thoughts on “Learn and Develope Android Application – Buyer and Seller System (Part – 4.1)”

Leave a Reply

Your email address will not be published. Required fields are marked *