Android Application Report
Android Application Report
Android Application Report
Name:AFSAN MD RUBAYET
Student number: 189076015
Instructor: 陶陶
APPLICATION ARCHITECTURE
APPLICATION CONFIGURATION
register.java :
package com.example.ofori;
import android.content.ContentValues;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.example.ofori.MainActivity;
DatabaseHelper.java :
package com.example.ofori;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.widget.Toast;
}
}
activity_register :
Success.java :
package com.example.ofori;
import android.os.Bundle;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.view.View;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_success);
}
}
activity_success :
</RelativeLayout>
activity_main:
<EditText
android:id="@+id/et_1"
android:layout_width="match_parent"
android:layout_height="50dp"
android:textSize="16sp"
android:textColor="#FFAD33"
android:hint="username"
/>
<EditText
android:id="@+id/et_2"
android:layout_width="match_parent"
android:layout_height="50dp"
android:textSize="16sp"
android:textColor="#FFAD33"
android:hint="password"
android:layout_marginTop="15dp"
android:inputType="textPassword"
android:layout_below="@id/et_1"
/>
<Button
android:id="@+id/btn_login"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="@id/et_2"
android:text="Login"
android:layout_marginTop="50dp"
/>
<Button
android:id="@+id/btn_register"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="@id/btn_login"
android:text="Register"
android:layout_marginTop="50dp"
/>
</RelativeLayout>
AndroidManifest :
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Ofori">
<activity
android:name=".register"
android:label="@string/title_activity_register"
android:theme="@style/Theme.Ofori.NoActionBar" />
<activity
android:name=".Success"
android:label="@string/title_activity_success"
android:theme="@style/Theme.Ofori.NoActionBar" />
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/Theme.Ofori.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</manifest>
MainActivity.java :
package com.example.ofori;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
private Button mBtnLogin,mBtnRegister;
private EditText username,password;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final String[] user = {null};
final String[] pwd = {null};
username=(EditText)findViewById(R.id.et_1);
password=(EditText)findViewById(R.id.et_2);
mBtnLogin=(Button)findViewById(R.id.btn_login);
mBtnRegister=(Button)findViewById(R.id.btn_register);
DatabaseHelper dbHelper = new DatabaseHelper( this, "User",null,1);
SQLiteDatabase db = dbHelper.getWritableDatabase();
mBtnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Cursor cursor = db.query("User",null,null,null,null,null,"name DESC");
boolean flag=true;
while(cursor.moveToNext()){
String name = cursor.getString(cursor.getColumnIndex("name"));
String pwd= cursor.getString(cursor.getColumnIndex("password"));
if(name.equals(username.getText().toString())&&pwd.equals(password.getText().toString())) {
flag=false;
Toast.makeText(MainActivity.this,"login
success!!!",Toast.LENGTH_LONG).show();
Intent intent = new Intent(MainActivity.this, Success.class);
startActivity(intent);
}
}
if(flag)
Toast.makeText(MainActivity.this,"user or password is
wrong",Toast.LENGTH_LONG).show();
}
}
);
mBtnRegister.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this,register.class);
startActivity(intent);
}
});
username.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
user[0] =s.toString();
}
@Override
public void afterTextChanged(Editable s) {
}
});
password.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
pwd[0]=s.toString();
}
@Override
public void afterTextChanged(Editable s) {
}
});
}
}