Aplikasi Doa Harian (Login, Register, WebView) Sqlite
Deskripsi
Aplikasi Doa Harian "Kumpulan Doa Harian", dengan adanya aplikasi - aplikasi semacam ini membantu kita sebagai Hamba Allah yang selalu mengharapkan pertolongan Allah dalam setiap kondisi apapun. Dengan kata lain, melalui berdoa, kita benar - benar berharap pada Allah agar mengabulkan apapun hajat dan yang terbaik dari Allah SWT.
Design Activity
XML - TEXT
ini merupakan source code XML di dalam pemrogrammannya.
1.1 doa_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".DoaActivity">
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="@+id/webView" />
<ProgressBar
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="110dp"
android:id="@+id/progressBar2" />
</RelativeLayout>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".DoaActivity">
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="@+id/webView" />
<ProgressBar
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="110dp"
android:id="@+id/progressBar2" />
</RelativeLayout>
1.2 activity_login.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"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_depan"
android:gravity="center_horizontal"
android:orientation="vertical"
tools:context="android.example.com.doaharian.LoginActivity">
<ImageView
android:layout_width="wrap_content"
android:layout_height="127dp"
android:layout_marginTop="50dp"
app:srcCompat="@drawable/logo" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:foreground="@android:color/transparent"
android:gravity="center_horizontal"
android:orientation="vertical">
<EditText
android:id="@+id/edittext_username"
android:layout_width="190dp"
android:layout_height="40dp"
android:layout_marginTop="10dp"
android:background="#ffffff"
android:drawableLeft="@drawable/username"
android:hint="Username"
android:paddingLeft="2dp" />
<EditText
android:id="@+id/edittext_password"
android:layout_width="190dp"
android:layout_height="40dp"
android:layout_marginTop="20dp"
android:background="#ffffff"
android:drawableLeft="@drawable/password"
android:hint="Password"
android:inputType="textPassword" />
</LinearLayout>
<Button
android:id="@+id/button_login"
android:layout_width="190dp"
android:layout_height="40dp"
android:layout_marginTop="20dp"
android:background="#6D00EA"
android:text="LOGIN"
android:textColor="#ffffff" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="35dp"
android:background="@android:color/holo_purple"
android:text=" Haven't Account? "
android:textColor="#FFFFFF" />
<TextView
android:id="@+id/textview_register"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:background="@android:color/holo_purple"
android:paddingLeft="10dp"
android:text="REGISTER "
android:textColor="#FFFFFF"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<LinearLayout
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/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_depan"
android:gravity="center_horizontal"
android:orientation="vertical"
tools:context="android.example.com.doaharian.LoginActivity">
<ImageView
android:layout_width="wrap_content"
android:layout_height="127dp"
android:layout_marginTop="50dp"
app:srcCompat="@drawable/logo" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:foreground="@android:color/transparent"
android:gravity="center_horizontal"
android:orientation="vertical">
<EditText
android:id="@+id/edittext_username"
android:layout_width="190dp"
android:layout_height="40dp"
android:layout_marginTop="10dp"
android:background="#ffffff"
android:drawableLeft="@drawable/username"
android:hint="Username"
android:paddingLeft="2dp" />
<EditText
android:id="@+id/edittext_password"
android:layout_width="190dp"
android:layout_height="40dp"
android:layout_marginTop="20dp"
android:background="#ffffff"
android:drawableLeft="@drawable/password"
android:hint="Password"
android:inputType="textPassword" />
</LinearLayout>
<Button
android:id="@+id/button_login"
android:layout_width="190dp"
android:layout_height="40dp"
android:layout_marginTop="20dp"
android:background="#6D00EA"
android:text="LOGIN"
android:textColor="#ffffff" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="35dp"
android:background="@android:color/holo_purple"
android:text=" Haven't Account? "
android:textColor="#FFFFFF" />
<TextView
android:id="@+id/textview_register"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:background="@android:color/holo_purple"
android:paddingLeft="10dp"
android:text="REGISTER "
android:textColor="#FFFFFF"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
1.3 activity_register.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" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_depan"
android:orientation="vertical"
android:gravity="center_horizontal"
tools:context="android.example.com.doaharian.RegisterActivity">
<ImageView
android:layout_width="wrap_content"
android:layout_height="127dp"
android:layout_marginTop="50dp"
app:srcCompat="@drawable/logo"/>
<EditText
android:id="@+id/edittext_username"
android:layout_width="206dp"
android:layout_height="40dp"
android:layout_marginTop="10dp"
android:background="#ffffff"
android:drawableLeft="@drawable/username"
android:hint="Username"
android:paddingLeft="2dp" />
<EditText
android:id="@+id/edittext_password"
android:layout_width="206dp"
android:layout_height="40dp"
android:layout_marginTop="20dp"
android:background="#ffffff"
android:drawableLeft="@drawable/password"
android:hint="Password"
android:inputType="textPassword" />
android:hint="@string/password"/>
<EditText
android:id="@+id/edittext_cnf_password"
android:layout_width="206dp"
android:layout_height="40dp"
android:layout_marginTop="20dp"
android:background="#ffffff"
android:drawableLeft="@drawable/password"
android:hint="Confirm Password"
android:inputType="textPassword" />
android:hint="@string/confirm_password"/>
<Button
android:id="@+id/button_register"
android:layout_width="206dp"
android:layout_height="40dp"
android:layout_marginTop="20dp"
android:background="#6D00EA"
android:text="REGISTER"
android:textColor="#ffffff" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="35dp"
android:background="@android:color/holo_purple"
android:text=" Have an Account? "
android:textColor="#FFFFFF" />
<TextView
android:id="@+id/textview_login"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:background="@android:color/holo_purple"
android:paddingLeft="10dp"
android:text=" LOGIN "
android:textColor="@android:color/background_light"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<LinearLayout
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:background="@drawable/bg_depan"
android:orientation="vertical"
android:gravity="center_horizontal"
tools:context="android.example.com.doaharian.RegisterActivity">
<ImageView
android:layout_width="wrap_content"
android:layout_height="127dp"
android:layout_marginTop="50dp"
app:srcCompat="@drawable/logo"/>
<EditText
android:id="@+id/edittext_username"
android:layout_width="206dp"
android:layout_height="40dp"
android:layout_marginTop="10dp"
android:background="#ffffff"
android:drawableLeft="@drawable/username"
android:hint="Username"
android:paddingLeft="2dp" />
<EditText
android:id="@+id/edittext_password"
android:layout_width="206dp"
android:layout_height="40dp"
android:layout_marginTop="20dp"
android:background="#ffffff"
android:drawableLeft="@drawable/password"
android:hint="Password"
android:inputType="textPassword" />
android:hint="@string/password"/>
<EditText
android:id="@+id/edittext_cnf_password"
android:layout_width="206dp"
android:layout_height="40dp"
android:layout_marginTop="20dp"
android:background="#ffffff"
android:drawableLeft="@drawable/password"
android:hint="Confirm Password"
android:inputType="textPassword" />
android:hint="@string/confirm_password"/>
<Button
android:id="@+id/button_register"
android:layout_width="206dp"
android:layout_height="40dp"
android:layout_marginTop="20dp"
android:background="#6D00EA"
android:text="REGISTER"
android:textColor="#ffffff" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="35dp"
android:background="@android:color/holo_purple"
android:text=" Have an Account? "
android:textColor="#FFFFFF" />
<TextView
android:id="@+id/textview_login"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:background="@android:color/holo_purple"
android:paddingLeft="10dp"
android:text=" LOGIN "
android:textColor="@android:color/background_light"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
1.4 progress_bar.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00060606">
<ProgressBar
android:id="@+id/progressBar1"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_centerInParent="true"
android:indeterminateDrawable="@drawable/logo" />
</RelativeLayout>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00060606">
<ProgressBar
android:id="@+id/progressBar1"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_centerInParent="true"
android:indeterminateDrawable="@drawable/logo" />
</RelativeLayout>
XML - Graphics
Ini merupakan tampilan dari source code XML.
doa_activity.xml
activity_login.xml
activity_register.xml
progress_bar.xml
Source Code (Java Class)
Beberapa source code Java Class didalam pemrogramman.
1.1 DoaActivity.java
package android.example.com.doaharian;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import androidx.appcompat.app.AppCompatActivity;
public class DoaActivity extends AppCompatActivity {
WebView webView;
ProgressBar bar;
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.doa_activity);
webView = (WebView) findViewById(R.id.webView);
bar=(ProgressBar) findViewById(R.id.progressBar2);
webView.setWebViewClient(new myWebclient());
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("https://mqrsy.blogspot.com/2020/01/kumpulan-doa-sehari-hari.html?m=1");
}
public class myWebclient extends WebViewClient{
@Override public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
bar.setVisibility(View.GONE);
}
@Override public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}
@Override public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return super.shouldOverrideUrlLoading(view, url);
}
}
@Override public boolean onKeyDown(int keyCode, KeyEvent event) {
if((keyCode==KeyEvent.KEYCODE_BACK) && webView.canGoBack()){
webView.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
}
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import androidx.appcompat.app.AppCompatActivity;
public class DoaActivity extends AppCompatActivity {
WebView webView;
ProgressBar bar;
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.doa_activity);
webView = (WebView) findViewById(R.id.webView);
bar=(ProgressBar) findViewById(R.id.progressBar2);
webView.setWebViewClient(new myWebclient());
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("https://mqrsy.blogspot.com/2020/01/kumpulan-doa-sehari-hari.html?m=1");
}
public class myWebclient extends WebViewClient{
@Override public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
bar.setVisibility(View.GONE);
}
@Override public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}
@Override public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return super.shouldOverrideUrlLoading(view, url);
}
}
@Override public boolean onKeyDown(int keyCode, KeyEvent event) {
if((keyCode==KeyEvent.KEYCODE_BACK) && webView.canGoBack()){
webView.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
}
1.2 LoginActivity.java
package android.example.com.doaharian;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
public class LoginActivity extends AppCompatActivity {
EditText mTextUsername;
EditText mTextPassword;
Button mButtonLogin;
TextView mTextViewRegister;
DatabaseHelper db;
ViewGroup progressView;
protected boolean isProgressShowing = false;
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
db = new DatabaseHelper(this);
mTextUsername = (EditText)findViewById(R.id.edittext_username);
mTextPassword = (EditText)findViewById(R.id.edittext_password);
mButtonLogin = (Button)findViewById(R.id.button_login);
mTextViewRegister = (TextView)findViewById(R.id.textview_register);
mTextViewRegister.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View view) {
Intent registerIntent = new Intent(LoginActivity.this,RegisterActivity.class);
startActivity(registerIntent);
}
});
mButtonLogin.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View view) {
String user = mTextUsername.getText().toString().trim();
String pwd = mTextPassword.getText().toString().trim();
Boolean res = db.checkUser(user, pwd);
if(res == true)
{
Intent HomePage = new Intent(LoginActivity.this,DoaActivity.class);
startActivity(HomePage);
}
else {
Toast.makeText(LoginActivity.this,"Login Error",Toast.LENGTH_SHORT).show();
}
}
});
}
public void showProgressingView() {
if (!isProgressShowing) {
View view=findViewById(R.id.progressBar1);
view.bringToFront();
}
}
public void hideProgressingView() {
View v = this.findViewById(android.R.id.content).getRootView();
ViewGroup viewGroup = (ViewGroup) v;
viewGroup.removeView(progressView);
isProgressShowing = false;
}
}
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
public class LoginActivity extends AppCompatActivity {
EditText mTextUsername;
EditText mTextPassword;
Button mButtonLogin;
TextView mTextViewRegister;
DatabaseHelper db;
ViewGroup progressView;
protected boolean isProgressShowing = false;
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
db = new DatabaseHelper(this);
mTextUsername = (EditText)findViewById(R.id.edittext_username);
mTextPassword = (EditText)findViewById(R.id.edittext_password);
mButtonLogin = (Button)findViewById(R.id.button_login);
mTextViewRegister = (TextView)findViewById(R.id.textview_register);
mTextViewRegister.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View view) {
Intent registerIntent = new Intent(LoginActivity.this,RegisterActivity.class);
startActivity(registerIntent);
}
});
mButtonLogin.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View view) {
String user = mTextUsername.getText().toString().trim();
String pwd = mTextPassword.getText().toString().trim();
Boolean res = db.checkUser(user, pwd);
if(res == true)
{
Intent HomePage = new Intent(LoginActivity.this,DoaActivity.class);
startActivity(HomePage);
}
else {
Toast.makeText(LoginActivity.this,"Login Error",Toast.LENGTH_SHORT).show();
}
}
});
}
public void showProgressingView() {
if (!isProgressShowing) {
View view=findViewById(R.id.progressBar1);
view.bringToFront();
}
}
public void hideProgressingView() {
View v = this.findViewById(android.R.id.content).getRootView();
ViewGroup viewGroup = (ViewGroup) v;
viewGroup.removeView(progressView);
isProgressShowing = false;
}
}
1.3 RegisterActivity.java
package android.example.com.doaharian;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
public class RegisterActivity extends AppCompatActivity {
DatabaseHelper db;
EditText mTextUsername;
EditText mTextPassword;
EditText mTextCnfPassword;
Button mButtonRegister;
TextView mTextViewLogin;
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
db = new DatabaseHelper(this);
mTextUsername = (EditText)findViewById(R.id.edittext_username);
mTextPassword = (EditText)findViewById(R.id.edittext_password);
mTextCnfPassword = (EditText)findViewById(R.id.edittext_cnf_password);
mButtonRegister = (Button)findViewById(R.id.button_register);
mTextViewLogin = (TextView)findViewById(R.id.textview_login);
mTextViewLogin.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View view) {
Intent LoginIntent = new Intent(RegisterActivity.this,LoginActivity.class);
startActivity(LoginIntent);
}
});
mButtonRegister.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View view) {
String user = mTextUsername.getText().toString().trim();
String pwd = mTextPassword.getText().toString().trim();
String cnf_pwd = mTextCnfPassword.getText().toString().trim();
if(pwd.equals(cnf_pwd)){
long val = db.addUser(user,pwd);
if(val > 0){
Toast.makeText(RegisterActivity.this,"You have registered",Toast.LENGTH_SHORT).show();
Intent moveToLogin = new Intent(RegisterActivity.this,LoginActivity.class);
startActivity(moveToLogin);
}
else{
Toast.makeText(RegisterActivity.this,"Registeration Error",Toast.LENGTH_SHORT).show();
}
}
else{
Toast.makeText(RegisterActivity.this,"Password is not matching",Toast.LENGTH_SHORT).show();
}
}
});
}
}
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
public class RegisterActivity extends AppCompatActivity {
DatabaseHelper db;
EditText mTextUsername;
EditText mTextPassword;
EditText mTextCnfPassword;
Button mButtonRegister;
TextView mTextViewLogin;
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
db = new DatabaseHelper(this);
mTextUsername = (EditText)findViewById(R.id.edittext_username);
mTextPassword = (EditText)findViewById(R.id.edittext_password);
mTextCnfPassword = (EditText)findViewById(R.id.edittext_cnf_password);
mButtonRegister = (Button)findViewById(R.id.button_register);
mTextViewLogin = (TextView)findViewById(R.id.textview_login);
mTextViewLogin.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View view) {
Intent LoginIntent = new Intent(RegisterActivity.this,LoginActivity.class);
startActivity(LoginIntent);
}
});
mButtonRegister.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View view) {
String user = mTextUsername.getText().toString().trim();
String pwd = mTextPassword.getText().toString().trim();
String cnf_pwd = mTextCnfPassword.getText().toString().trim();
if(pwd.equals(cnf_pwd)){
long val = db.addUser(user,pwd);
if(val > 0){
Toast.makeText(RegisterActivity.this,"You have registered",Toast.LENGTH_SHORT).show();
Intent moveToLogin = new Intent(RegisterActivity.this,LoginActivity.class);
startActivity(moveToLogin);
}
else{
Toast.makeText(RegisterActivity.this,"Registeration Error",Toast.LENGTH_SHORT).show();
}
}
else{
Toast.makeText(RegisterActivity.this,"Password is not matching",Toast.LENGTH_SHORT).show();
}
}
});
}
}
1.4 DatabaseHelper.java
package android.example.com.doaharian;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class DatabaseHelper extends SQLiteOpenHelper{
public static final String DATABASE_NAME ="register.db";
public static final String TABLE_NAME ="registeruser";
public static final String COL_1 ="ID";
public static final String COL_2 ="username";
public static final String COL_3 ="password";
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, 1);
}
@Override public void onCreate(SQLiteDatabase sqLiteDatabase) {
sqLiteDatabase.execSQL("CREATE TABLE registeruser (ID INTEGER PRIMARY KEY AUTOINCREMENT, username TEXT, password TEXT)");
}
@Override public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
sqLiteDatabase.execSQL(" DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(sqLiteDatabase);
}
public long addUser(String user, String password){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put("username",user);
contentValues.put("password",password);
long res = db.insert("registeruser",null,contentValues);
db.close();
return res;
}
public boolean checkUser(String username, String password){
String[] columns = { COL_1 };
SQLiteDatabase db = getReadableDatabase();
String selection = COL_2 + "=?" + " and " + COL_3 + "=?";
String[] selectionArgs = { username, password };
Cursor cursor = db.query(TABLE_NAME,columns,selection,selectionArgs,null,null,null);
int count = cursor.getCount();
cursor.close();
db.close();
if(count>0)
return true;
else return false;
}
}
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class DatabaseHelper extends SQLiteOpenHelper{
public static final String DATABASE_NAME ="register.db";
public static final String TABLE_NAME ="registeruser";
public static final String COL_1 ="ID";
public static final String COL_2 ="username";
public static final String COL_3 ="password";
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, 1);
}
@Override public void onCreate(SQLiteDatabase sqLiteDatabase) {
sqLiteDatabase.execSQL("CREATE TABLE registeruser (ID INTEGER PRIMARY KEY AUTOINCREMENT, username TEXT, password TEXT)");
}
@Override public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
sqLiteDatabase.execSQL(" DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(sqLiteDatabase);
}
public long addUser(String user, String password){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put("username",user);
contentValues.put("password",password);
long res = db.insert("registeruser",null,contentValues);
db.close();
return res;
}
public boolean checkUser(String username, String password){
String[] columns = { COL_1 };
SQLiteDatabase db = getReadableDatabase();
String selection = COL_2 + "=?" + " and " + COL_3 + "=?";
String[] selectionArgs = { username, password };
Cursor cursor = db.query(TABLE_NAME,columns,selection,selectionArgs,null,null,null);
int count = cursor.getCount();
cursor.close();
db.close();
if(count>0)
return true;
else return false;
}
}
Screenshoot (Run Program)
Aplikasi Kumpulan Doa Harian.
1. Halaman awal (Login) 2. Halaman Register
3. Halaman Register Error 4. Halaman Login Error
5. Halaman Register Berhasil 6. Halaman memasuki Aplikasi
7. Progress Bar (ini setelah login)
8. Halaman ini adalah inti nya, Kumpulan Doa Harian
Komentar
Posting Komentar