Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- === activity add account ===
- <?xml version="1.0" encoding="utf-8"?>
- <ScrollView 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="com.ramli.latianuts.AddAccountActivity">
- <TableLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- <TableRow>
- <TextView
- android:layout_weight="1"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:text="Username"/>
- <EditText
- android:id="@+id/editUsername"
- android:layout_weight="1"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:hint="username"
- android:inputType="text"/>
- </TableRow>
- <TableRow>
- <TextView
- android:layout_weight="1"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:text="Password"/>
- <EditText
- android:id="@+id/editPassword"
- android:layout_weight="1"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:hint="password"
- android:inputType="textPassword"/>
- </TableRow>
- <TableRow>
- <TextView
- android:layout_weight="1"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:text="Password Confirmation"/>
- <EditText
- android:id="@+id/editPasswordConfirmation"
- android:layout_weight="1"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:hint="confirm password"
- android:inputType="textPassword"/>
- </TableRow>
- <TableRow>
- <TextView
- android:layout_weight="1"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:text="Name"/>
- <EditText
- android:id="@+id/editName"
- android:layout_weight="1"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:hint="Name"
- android:inputType="text"/>
- </TableRow>
- <TableRow>
- <TextView
- android:layout_weight="1"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:text="Address"/>
- <EditText
- android:id="@+id/editAddress"
- android:layout_weight="1"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:hint="Address"
- android:inputType="textMultiLine"/>
- </TableRow>
- <TableRow>
- <TextView
- android:layout_weight="1"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:text="Email"/>
- <EditText
- android:id="@+id/editEmail"
- android:layout_weight="1"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:hint="email"
- android:inputType="textEmailAddress"/>
- </TableRow>
- <TableRow>
- <Button android:layout_weight="1"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:id="@+id/btnBack"
- android:text="BACK"/>
- <Button
- android:layout_weight="1"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:id="@+id/btnSubmit"
- android:text="SUBMIT"/>
- </TableRow>
- </TableLayout>
- </ScrollView>
- ===activity add course===
- <?xml version="1.0" encoding="utf-8"?>
- <ScrollView 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="com.ramli.latianuts.AddCourseActivity">
- <TableLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- <TableRow>
- <TextView
- android:layout_weight="1"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:text="Course Name"/>
- <EditText
- android:id="@+id/editCourseName"
- android:layout_weight="1"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:hint="Course Name"
- android:inputType="text"/>
- </TableRow>
- <TableRow>
- <TextView
- android:layout_weight="1"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:text="Deskripsi"/>
- <EditText
- android:id="@+id/editDesc"
- android:layout_weight="1"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:hint="Deskripsi"
- android:inputType="text"/>
- </TableRow>
- <TableRow>
- <Button android:layout_weight="1"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:id="@+id/btnBack"
- android:text="BACK"/>
- <Button
- android:layout_weight="1"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:id="@+id/btnSubmit"
- android:text="SUBMIT"/>
- </TableRow>
- </TableLayout>
- </ScrollView>
- ===activity edit account ===
- <?xml version="1.0" encoding="utf-8"?>
- <ScrollView 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="com.ramli.latianuts.EditAccountActivity">
- <TableLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- <TableRow>
- <TextView
- android:layout_weight="1"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:text="Username"/>
- <EditText
- android:id="@+id/editUsername"
- android:layout_weight="1"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:hint="username"
- android:inputType="text"
- android:enabled="false"/>
- </TableRow>
- <TableRow>
- <TextView
- android:layout_weight="1"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:text="Password"/>
- <EditText
- android:id="@+id/editPassword"
- android:layout_weight="1"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:hint="password"
- android:enabled="false"
- android:inputType="textPassword"/>
- </TableRow>
- <TableRow>
- <TextView
- android:layout_weight="1"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:text="Password Confirmation"/>
- <EditText
- android:id="@+id/editNewPassword"
- android:layout_weight="1"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:hint="new password"
- android:inputType="textPassword"/>
- </TableRow>
- <TableRow>
- <TextView
- android:layout_weight="1"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:text="Password Confirmation"/>
- <EditText
- android:id="@+id/editPasswordConfirmation"
- android:layout_weight="1"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:hint="confirm password"
- android:inputType="textPassword"/>
- </TableRow>
- <TableRow>
- <TextView
- android:layout_weight="1"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:text="Name"/>
- <EditText
- android:id="@+id/editName"
- android:layout_weight="1"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:hint="Name"
- android:inputType="text"/>
- </TableRow>
- <TableRow>
- <TextView
- android:layout_weight="1"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:text="Address"/>
- <EditText
- android:id="@+id/editAddress"
- android:layout_weight="1"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:hint="Address"
- android:inputType="textMultiLine"/>
- </TableRow>
- <TableRow>
- <TextView
- android:layout_weight="1"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:text="Email"/>
- <EditText
- android:id="@+id/editEmail"
- android:layout_weight="1"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:hint="email"
- android:inputType="textEmailAddress"/>
- </TableRow>
- <TableRow>
- <Button android:layout_weight="1"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:id="@+id/btnBack"
- android:text="BACK"/>
- <Button
- android:layout_weight="1"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:id="@+id/btnSubmit"
- android:text="SUBMIT"/>
- </TableRow>
- </TableLayout>
- </ScrollView>
- ====activity login =====
- <?xml version="1.0" encoding="utf-8"?>
- <ScrollView 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="com.ramli.latianuts.LoginActivity">
- <TableLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_gravity="center">
- <TableRow>
- <TextView
- android:layout_weight="1"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:text="Username"/>
- <EditText
- android:layout_weight="1"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:id="@+id/editUsername"
- android:hint="Username"
- android:inputType="text"/>
- </TableRow>
- <TableRow>
- <TextView
- android:layout_weight="1"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:text="Password"/>
- <EditText
- android:layout_weight="1"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:id="@+id/editPassword"
- android:hint="Password"
- android:inputType="textPassword"/>
- </TableRow>
- <TableRow
- android:gravity="center">
- <CheckBox
- android:id="@+id/cbRemember"
- android:text="Remember Me"/>
- </TableRow>
- <TableRow>
- <Button
- android:id="@+id/btnSubmit"
- android:text="Login"
- android:layout_weight="1"
- android:layout_width="0dp"
- android:layout_height="wrap_content"/>
- </TableRow>
- </TableLayout>
- </ScrollView>
- ====activity menu ====
- <?xml version="1.0" encoding="utf-8"?>
- <ScrollView 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="com.ramli.latianuts.MenuActivity"
- android:id="@+id/svMenu"
- android:layout_gravity="center">
- </ScrollView>
- ====activity show list course ====
- <?xml version="1.0" encoding="utf-8"?>
- <ScrollView 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="com.ramli.latianuts.ShowListCourseActivity"
- android:id="@+id/svShowListCourse">
- </ScrollView>
- menu add account
- <?xml version="1.0" encoding="utf-8"?>
- <menu xmlns:tools="http://schemas.android.com/tools"
- xmlns:android="http://schemas.android.com/apk/res/android"
- tools:context=".LoginActivity">
- <item
- android:id="@+id/actionAddAccount"
- android:title="Add Account"
- />
- </menu>
- ====account java====
- package com.ramli.latianuts;
- import java.io.Serializable;
- /**
- * Created by Ramlivan's Y50 on 27/03/2017.
- */
- public class Account implements Serializable{
- private String username, password, name, address, email;
- Account(String username, String password, String name, String address, String email){
- this.username = username;
- this.password = password;
- this.name = name;
- this.address = address;
- this.email = email;
- }
- public String getName() {
- return name;
- }
- public String getUsername() {
- return username;
- }
- public String getPassword() {
- return password;
- }
- public String getAddress() {
- return address;
- }
- public String getEmail() {
- return email;
- }
- public void setAddress(String address) {
- this.address = address;
- }
- public void setEmail(String email) {
- this.email = email;
- }
- public void setName(String name) {
- this.name = name;
- }
- public void setPassword(String password) {
- this.password = password;
- }
- public void setUsername(String username) {
- this.username = username;
- }
- }
- ====addaccountactivity.java ====
- package com.ramli.latianuts;
- import android.content.ContentValues;
- import android.content.Intent;
- import android.database.sqlite.SQLiteDatabase;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- public class AddAccountActivity extends AppCompatActivity {
- Account olUser;
- String lvAccess;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_add_account);
- lvAccess = getIntent().getStringExtra("ACCESS_LEVEL");
- olUser = (Account) getIntent().getSerializableExtra("OL_USER");
- if(lvAccess != null && olUser != null){
- Log.d("online user", olUser.getName() + "-" + lvAccess);
- } else {
- Log.d("online user", "ini ga masuk");
- }
- final EditText editUsername = (EditText) findViewById(R.id.editUsername);
- final EditText editPassword = (EditText) findViewById(R.id.editPassword);
- final EditText editPasswordConfirmation = (EditText) findViewById(R.id.editPasswordConfirmation);
- final EditText editName = (EditText) findViewById(R.id.editName);
- final EditText editAddress = (EditText) findViewById(R.id.editAddress);
- final EditText editEmail = (EditText) findViewById(R.id.editEmail);
- Button btnSubmit = (Button) findViewById(R.id.btnSubmit);
- Button btnBack = (Button) findViewById(R.id.btnBack);
- btnSubmit.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- DBAdapter.AccountDbHelper accountDbHelper =
- new DBAdapter.AccountDbHelper(AddAccountActivity.this);
- SQLiteDatabase db = accountDbHelper.getWritableDatabase();
- ContentValues contentValues = new ContentValues();
- contentValues.put(
- DBAdapter.AccountEntry.colUsername,
- editUsername.getText().toString()
- );
- contentValues.put(
- DBAdapter.AccountEntry.colPassword,
- editPassword.getText().toString()
- );
- contentValues.put(
- DBAdapter.AccountEntry.colName,
- editName.getText().toString()
- );
- contentValues.put(
- DBAdapter.AccountEntry.colAddress,
- editAddress.getText().toString()
- );
- contentValues.put(
- DBAdapter.AccountEntry.colEmail,
- editEmail.getText().toString()
- );
- long newVal = db.insert(
- DBAdapter.AccountEntry.tbName,
- null,
- contentValues
- );
- if(lvAccess != null && olUser != null){
- Intent i = new Intent(AddAccountActivity.this, MenuActivity.class);
- i.putExtra("OL_USER", olUser);
- i.putExtra("ACCESS_LEVEL", lvAccess);
- startActivity(i);
- } else {
- startActivity(new Intent(AddAccountActivity.this, LoginActivity.class));
- }
- }
- });
- btnBack.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- AddAccountActivity.super.onBackPressed();
- }
- });
- }
- }
- ====addcourseactivity ====
- package com.ramli.latianuts;
- import android.content.ContentValues;
- import android.content.Intent;
- import android.database.sqlite.SQLiteDatabase;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- public class AddCourseActivity extends AppCompatActivity {
- Account olUser;
- String lvAccess;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_add_course);
- lvAccess = getIntent().getStringExtra("ACCESS_LEVEL");
- olUser = (Account) getIntent().getSerializableExtra("OL_USER");
- final EditText editCourseName = (EditText) findViewById(R.id.editCourseName);
- final EditText editDesc = (EditText) findViewById(R.id.editDesc);
- Button btnBack = (Button) findViewById(R.id.btnBack);
- Button btnSubmit = (Button) findViewById(R.id.btnSubmit);
- btnSubmit.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- DBAdapter.CourseDbHelper courseDbHelper = new DBAdapter.CourseDbHelper(AddCourseActivity.this);
- SQLiteDatabase db = courseDbHelper.getWritableDatabase();
- ContentValues contentValues = new ContentValues();
- contentValues.put(
- DBAdapter.CourseEntry.colName,
- editCourseName.getText().toString()
- );
- contentValues.put(
- DBAdapter.CourseEntry.colDesc,
- editDesc.getText().toString()
- );
- long newVal = db.insert(
- DBAdapter.CourseEntry.tbName,
- null,
- contentValues
- );
- Intent i = new Intent(AddCourseActivity.this, MenuActivity.class);
- i.putExtra("OL_USER", olUser);
- i.putExtra("ACCESS_LEVEL", lvAccess);
- startActivity(i);
- }
- });
- btnBack.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- AddCourseActivity.super.onBackPressed();
- }
- });
- }
- }
- ====course ====
- package com.ramli.latianuts;
- /**
- * Created by Ramlivan's Y50 on 27/03/2017.
- */
- public class Course {
- private String code, name, desc;
- Course(String code, String name, String desc){
- this.code = code;
- this.name = name;
- this.desc = desc;
- }
- public String getName() {
- return name;
- }
- public String getDesc() {
- return desc;
- }
- public String getCode() {
- return code;
- }
- }
- ====dbadapter ====
- package com.ramli.latianuts;
- import android.content.Context;
- import android.database.sqlite.SQLiteDatabase;
- import android.database.sqlite.SQLiteOpenHelper;
- import android.provider.BaseColumns;
- /**
- * Created by Ramlivan's Y50 on 27/03/2017.
- */
- public final class DBAdapter {
- public static class AccountEntry implements BaseColumns{
- public static final String tbName = "account";
- public static final String colUsername = "username";
- public static final String colPassword = "password";
- public static final String colName = "name";
- public static final String colAddress = "address";
- public static final String colEmail = "email";
- }
- public static final String sqlCreateAccount = String.format(
- "create table %s(%s, %s, %s, %s, %s);",
- AccountEntry.tbName,
- String.format("%s varchar(40) primary key", AccountEntry.colUsername),
- String.format("%s varchar(40)", AccountEntry.colPassword),
- String.format("%s varchar(40)", AccountEntry.colName),
- String.format("%s varchar(40)", AccountEntry.colAddress),
- String.format("%s varchar(40)", AccountEntry.colEmail)
- );
- public static final String sqlDeleteAccount = String.format(
- "drop table if exists %s",
- AccountEntry.tbName
- );
- public static class AccountDbHelper extends SQLiteOpenHelper{
- public static final int dbVersion = 1;
- public static final String dbName = "mobile.uts.ramli.db";
- public AccountDbHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
- super(context, name, factory, version);
- }
- public AccountDbHelper(Context context) {
- super(context, dbName, null, dbVersion);
- }
- @Override
- public void onCreate(SQLiteDatabase db) {
- db.execSQL(sqlCreateAccount);
- }
- @Override
- public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
- db.execSQL(sqlDeleteAccount);
- onCreate(db);
- }
- @Override
- public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
- onUpgrade(db,oldVersion,newVersion);
- //super.onDowngrade(db, oldVersion, newVersion);
- }
- }
- public static class CourseEntry implements BaseColumns{
- public static final String tbName = "course";
- public static final String colName = "name";
- public static final String colDesc = "desc";
- }
- public static final String sqlCreateCouse = String.format(
- "create table %s(%s, %s, %s)",
- CourseEntry.tbName,
- String.format("%s integer primary key autoincrement", CourseEntry._ID),
- String.format("%s varchar(40)", CourseEntry.colName),
- String.format("%s varchar(100)", CourseEntry.colDesc)
- );
- public static final String sqlDeleteCourse = String.format(
- "drop table if exists %s",
- CourseEntry.tbName
- );
- public static class CourseDbHelper extends SQLiteOpenHelper{
- public static final int dbVer = 1;
- public static final String dbName = "mobile_ramli.db";
- public CourseDbHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
- super(context, name, factory, version);
- }
- public CourseDbHelper(Context context){
- super(context, dbName, null, dbVer);
- }
- @Override
- public void onCreate(SQLiteDatabase db) {
- db.execSQL(sqlCreateCouse);
- }
- @Override
- public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
- db.execSQL(sqlDeleteCourse);
- onCreate(db);
- }
- @Override
- public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
- onUpgrade(db, oldVersion, newVersion);
- //super.onDowngrade(db, oldVersion, newVersion);
- }
- }
- }
- ====editaccountactivity ====
- package com.ramli.latianuts;
- import android.content.ContentValues;
- import android.content.Intent;
- import android.database.sqlite.SQLiteDatabase;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- public class EditAccountActivity extends AppCompatActivity {
- Account olUser;
- String lvAccess;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_edit_account);
- final EditText editUsername = (EditText) findViewById(R.id.editUsername);
- final EditText editPassword = (EditText) findViewById(R.id.editPassword);
- final EditText editNewPassword = (EditText) findViewById(R.id.editNewPassword);
- final EditText editPasswordConfirmation = (EditText) findViewById(R.id.editPasswordConfirmation);
- final EditText editName = (EditText) findViewById(R.id.editName);
- final EditText editAddress = (EditText) findViewById(R.id.editAddress);
- final EditText editEmail = (EditText) findViewById(R.id.editEmail);
- Button btnSubmit = (Button) findViewById(R.id.btnSubmit);
- Button btnBack = (Button) findViewById(R.id.btnBack);
- lvAccess = getIntent().getStringExtra("ACCESS_LEVEL");
- olUser = (Account) getIntent().getSerializableExtra("OL_USER");
- editUsername.setText(olUser.getUsername());
- editPassword.setText(olUser.getPassword());
- editName.setText(olUser.getName());
- editAddress.setText(olUser.getAddress());
- editEmail.setText(olUser.getEmail());
- if(olUser.getUsername().equals("admin")){
- editNewPassword.setEnabled(false);
- editPasswordConfirmation.setEnabled(false);
- editName.setEnabled(false);
- editAddress.setEnabled(false);
- editEmail.setEnabled(false);
- btnSubmit.setEnabled(false);
- }
- btnSubmit.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- DBAdapter.AccountDbHelper accountDbHelper
- = new DBAdapter.AccountDbHelper(EditAccountActivity.this);
- SQLiteDatabase db = accountDbHelper.getReadableDatabase();
- ContentValues contentValues = new ContentValues();
- contentValues.put(
- DBAdapter.AccountEntry.colPassword,
- editNewPassword.getText().toString()
- );
- contentValues.put(
- DBAdapter.AccountEntry.colName,
- editName.getText().toString()
- );
- contentValues.put(
- DBAdapter.AccountEntry.colAddress,
- editAddress.getText().toString()
- );
- contentValues.put(
- DBAdapter.AccountEntry.colEmail,
- editEmail.getText().toString()
- );
- String selection = String.format(
- "%s = ?",
- DBAdapter.AccountEntry.colUsername
- );
- String[] selectionArgs = { olUser.getUsername()};
- int count = db.update(
- DBAdapter.AccountEntry.tbName,
- contentValues,
- selection,
- selectionArgs
- );
- Intent i = new Intent(EditAccountActivity.this, MenuActivity.class);
- olUser = new Account(olUser.getUsername(),editNewPassword.getText().toString(), editName.getText().toString(), editAddress.getText().toString(), editEmail.getText().toString());
- i.putExtra("OL_USER", olUser);
- i.putExtra("ACCESS_LEVEL", lvAccess);
- startActivity(i);
- }
- });
- btnBack.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- EditAccountActivity.super.onBackPressed();
- }
- });
- }
- }
- ====login activity ====
- package com.ramli.latianuts;
- import android.content.Intent;
- import android.content.SharedPreferences;
- import android.database.Cursor;
- import android.database.Observable;
- import android.database.sqlite.SQLiteDatabase;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.Menu;
- import android.view.MenuInflater;
- import android.view.MenuItem;
- import android.view.View;
- import android.widget.Button;
- import android.widget.CheckBox;
- import android.widget.EditText;
- import android.widget.Toast;
- import java.util.ArrayList;
- import java.util.List;
- public class LoginActivity extends AppCompatActivity {
- Account olUser;
- @Override
- protected void onStart() {
- super.onStart();
- SharedPreferences pref = getSharedPreferences("LOGIN_PREF", MODE_PRIVATE);
- Intent i = new Intent(this, MenuActivity.class);
- if(pref.getString("ACCESS_LEVEL", "").equals("admin")){
- i.putExtra("ACCESS_LEVEL", "admin");
- i.putExtra("OL_USER", new Account("admin", "admin" , "admin", "", ""));
- startActivity(i);
- } else if (pref.getString("ACCESS_LEVEL", "").equals("user")){
- i.putExtra("ACCESS_LEVEL", "user");
- i.putExtra("OL_USER", olUser);
- startActivity(i);
- }
- }
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_login);
- final EditText editUsername = (EditText) findViewById(R.id.editUsername);
- final EditText editPassword = (EditText) findViewById(R.id.editPassword);
- final CheckBox checkRememberMe = (CheckBox) findViewById(R.id.cbRemember);
- Button btnLogin = (Button) findViewById(R.id.btnSubmit);
- btnLogin.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- if(editUsername.getText().toString().equals("admin")
- && editPassword.getText().toString().equals("admin")){
- SharedPreferences.Editor prefEdit =
- getSharedPreferences("LOGIN_PREF", MODE_PRIVATE).edit();
- prefEdit.putString("ACCESS_LEVEL", "admin");
- prefEdit.commit();
- prefEdit = getPreferences(MODE_PRIVATE).edit();
- if(checkRememberMe.isChecked()){
- prefEdit.putString("USERNAME", editUsername.getText().toString());
- prefEdit.putString("PASSWORD", editPassword.getText().toString());
- } else {
- prefEdit.clear();
- }
- prefEdit.putBoolean("REMEMBER_ME", checkRememberMe.isChecked());
- prefEdit.commit();
- Intent i = new Intent(LoginActivity.this,MenuActivity.class);
- i.putExtra("ACCESS_LEVEL", "admin");
- i.putExtra("OL_USER", new Account("admin", "admin" , "admin", "", ""));
- startActivity(i);
- }else{
- List<Account> accFromDb = new ArrayList<Account>();
- String username = editUsername.getText().toString();
- String password = editPassword.getText().toString();
- DBAdapter.AccountDbHelper accountDbHelper =
- new DBAdapter.AccountDbHelper(LoginActivity.this);
- SQLiteDatabase db = accountDbHelper.getReadableDatabase();
- Cursor cursor = db.query(
- DBAdapter.AccountEntry.tbName,
- new String[]{
- DBAdapter.AccountEntry.colUsername,
- DBAdapter.AccountEntry.colPassword,
- DBAdapter.AccountEntry.colName,
- DBAdapter.AccountEntry.colAddress,
- DBAdapter.AccountEntry.colEmail
- },
- null,null,null,null,null
- );
- cursor.moveToFirst();
- for(int i=0;i<cursor.getCount();i++,cursor.moveToNext()){
- Account acc = new Account(
- cursor.getString(
- cursor.getColumnIndex(
- DBAdapter.AccountEntry.colUsername
- )
- ),
- cursor.getString(
- cursor.getColumnIndex(
- DBAdapter.AccountEntry.colPassword
- )
- ),
- cursor.getString(
- cursor.getColumnIndex(
- DBAdapter.AccountEntry.colName
- )
- ),
- cursor.getString(
- cursor.getColumnIndex(
- DBAdapter.AccountEntry.colAddress
- )
- ),
- cursor.getString(
- cursor.getColumnIndex(
- DBAdapter.AccountEntry.colEmail
- )
- )
- );
- if(acc != null) {
- //Log.d(acc.getUsername(),acc.getName());
- //accFromDb.set(i, acc);
- accFromDb.add(acc);
- }
- }
- int loginFlag = 0;
- for (Account idx: accFromDb) {
- if(username.equals(idx.getUsername()) && password.equals(idx.getPassword())){
- loginFlag=1;
- olUser = idx;
- break;
- }
- }
- if(loginFlag == 1){
- SharedPreferences.Editor prefEdit = getSharedPreferences("LOGIN_PREF", MODE_PRIVATE).edit();
- prefEdit.putString("ACCESS_LEVEL", "user");
- prefEdit.commit();
- prefEdit = getPreferences(MODE_PRIVATE).edit();
- if(checkRememberMe.isChecked()){
- prefEdit.putString("USERNAME", editUsername.getText().toString());
- prefEdit.putString("PASSWORD", editPassword.getText().toString());
- } else {
- prefEdit.clear();
- }
- prefEdit.putBoolean("REMEMBER_ME", checkRememberMe.isChecked());
- prefEdit.commit();
- Intent i = new Intent(LoginActivity.this,MenuActivity.class);
- i.putExtra("ACCESS_LEVEL", "user");
- i.putExtra("OL_USER", olUser);
- startActivity(i);
- } else {
- Toast.makeText(
- getApplicationContext(),
- "Username or password doesn't match",
- Toast.LENGTH_SHORT
- ).show();
- }
- }
- }
- });
- SharedPreferences pref = getPreferences(MODE_PRIVATE);
- editUsername.setText(pref.getString("USERNAME", ""));
- editPassword.setText(pref.getString("PASSWORD", ""));
- checkRememberMe.setChecked(pref.getBoolean("REMEMBER_ME", false));
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // return super.onCreateOptionsMenu(menu);
- MenuInflater menuInflater = getMenuInflater();
- menuInflater.inflate(R.menu.menu_add_account, menu);
- return true;
- }
- @Override
- public void onBackPressed() {
- super.onBackPressed();
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- if(item.getItemId() == R.id.actionAddAccount){
- Intent i = new Intent(LoginActivity.this, AddAccountActivity.class);
- startActivity(i);
- }
- return super.onOptionsItemSelected(item);
- }
- }
- ====menu activity====
- package com.ramli.latianuts;
- import android.content.Intent;
- import android.content.SharedPreferences;
- import android.database.Cursor;
- import android.database.sqlite.SQLiteDatabase;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.Gravity;
- import android.view.Menu;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.Button;
- import android.widget.ScrollView;
- import android.widget.TableLayout;
- import android.widget.TableRow;
- import android.widget.Toast;
- import java.util.ArrayList;
- import java.util.List;
- public class MenuActivity extends AppCompatActivity {
- String lvAccess;
- Account olUser;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_menu);
- lvAccess = getIntent().getStringExtra("ACCESS_LEVEL");
- olUser = (Account) getIntent().getSerializableExtra("OL_USER");
- if(olUser == null){
- SharedPreferences.Editor prefEdit =
- getSharedPreferences("LOGIN_PREF", MODE_PRIVATE).edit();
- prefEdit.clear();
- prefEdit.commit();
- startActivity(new Intent(MenuActivity.this, LoginActivity.class));
- }
- Log.d("OL USER DI MENU", olUser.getUsername());
- Log.d("LV USER DI MENU", lvAccess);
- ScrollView svMenu = (ScrollView) findViewById(R.id.svMenu);
- TableLayout tbLayoutMain = new TableLayout(this);
- TableRow tbRowBtnEditDataUser = new TableRow(this);
- TableRow tbRowBtnAddUser = new TableRow(this);
- TableRow tbRowBtnAddCourse = new TableRow(this);
- TableRow tbRowBtnDeleteAllAccount = new TableRow(this);
- TableRow tbRowBtnShowListCourse = new TableRow(this);
- TableRow tbRowBtnSignOut = new TableRow(this);
- Button btnEditDataUser = new Button(this);
- Button btnAddUser = new Button(this);
- Button btnAddCourse = new Button(this);
- Button btnDeleteAllAccount = new Button(this);
- Button btnShowListCourse = new Button(this);
- Button btnSignOut = new Button(this);
- btnEditDataUser.setLayoutParams(new TableRow.LayoutParams(
- 0,
- ViewGroup.LayoutParams.WRAP_CONTENT,
- 1
- ));
- btnEditDataUser.setText("Edit Data User");
- tbRowBtnEditDataUser.addView(btnEditDataUser);
- if(lvAccess.equals("admin")){
- btnAddUser.setLayoutParams(new TableRow.LayoutParams(
- 0,
- ViewGroup.LayoutParams.WRAP_CONTENT,
- 1
- ));
- btnAddUser.setText("Add User");
- tbRowBtnAddUser.addView(btnAddUser);
- btnAddCourse.setLayoutParams(new TableRow.LayoutParams(
- 0,
- ViewGroup.LayoutParams.WRAP_CONTENT,
- 1
- ));
- btnAddCourse.setText("Add Course");
- tbRowBtnAddCourse.addView(btnAddCourse);
- btnDeleteAllAccount.setLayoutParams(new TableRow.LayoutParams(
- 0,
- ViewGroup.LayoutParams.WRAP_CONTENT,
- 1
- ));
- btnDeleteAllAccount.setText("Delete All Account");
- tbRowBtnDeleteAllAccount.addView(btnDeleteAllAccount);
- }
- btnShowListCourse.setLayoutParams(new TableRow.LayoutParams(
- 0,
- ViewGroup.LayoutParams.WRAP_CONTENT,
- 1
- ));
- btnShowListCourse.setText("Show List Course");
- tbRowBtnShowListCourse.addView(btnShowListCourse);
- btnSignOut.setLayoutParams(new TableRow.LayoutParams(
- 0,
- ViewGroup.LayoutParams.WRAP_CONTENT,
- 1
- ));
- btnSignOut.setText("Sign Out");
- tbRowBtnSignOut.addView(btnSignOut);
- tbLayoutMain.addView(tbRowBtnEditDataUser);
- if(lvAccess.equals("admin")){
- tbLayoutMain.addView(tbRowBtnAddUser);
- tbLayoutMain.addView(tbRowBtnAddCourse);
- tbLayoutMain.addView(tbRowBtnDeleteAllAccount);
- }
- tbLayoutMain.addView(tbRowBtnShowListCourse);
- tbLayoutMain.addView(tbRowBtnSignOut);
- tbLayoutMain.setLayoutParams(new ScrollView.LayoutParams(
- ViewGroup.LayoutParams.MATCH_PARENT,
- ViewGroup.LayoutParams.MATCH_PARENT
- ));
- tbLayoutMain.setGravity(Gravity.CENTER);
- svMenu.addView(tbLayoutMain);
- btnEditDataUser.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Intent i = new Intent(MenuActivity.this, EditAccountActivity.class);
- i.putExtra("OL_USER", olUser);
- i.putExtra("ACCESS_LEVEL", lvAccess);
- startActivity(i);
- }
- });
- btnSignOut.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- SharedPreferences.Editor prefEdit =
- getSharedPreferences("LOGIN_PREF", MODE_PRIVATE).edit();
- prefEdit.clear();
- prefEdit.commit();
- startActivity(new Intent(MenuActivity.this, LoginActivity.class));
- }
- });
- btnAddCourse.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Intent i = new Intent(MenuActivity.this, AddCourseActivity.class);
- i.putExtra("OL_USER", olUser);
- i.putExtra("ACCESS_LEVEL", lvAccess);
- startActivity(i);
- }
- });
- btnAddUser.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Intent i = new Intent(MenuActivity.this, AddAccountActivity.class);
- i.putExtra("OL_USER", olUser);
- i.putExtra("ACCESS_LEVEL", lvAccess);
- startActivity(i);
- }
- });
- btnShowListCourse.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Intent i = new Intent(MenuActivity.this, ShowListCourseActivity.class);
- i.putExtra("OL_USER", olUser);
- i.putExtra("ACCESS_LEVEL", lvAccess);
- startActivity(i);
- }
- });
- btnDeleteAllAccount.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- DBAdapter.AccountDbHelper accountDbHelper = new DBAdapter.AccountDbHelper(MenuActivity.this);
- SQLiteDatabase db = accountDbHelper.getReadableDatabase();
- db.delete(DBAdapter.AccountEntry.tbName,null,null);
- Toast.makeText(
- MenuActivity.this,
- "Delete all data user except admin",
- Toast.LENGTH_SHORT
- ).show();
- }
- });
- }
- @Override
- public void onBackPressed() {
- }
- }
- ====showlistcourseactivity ====
- package com.ramli.latianuts;
- import android.app.AlertDialog;
- import android.app.Dialog;
- import android.content.DialogInterface;
- import android.database.Cursor;
- import android.database.sqlite.SQLiteDatabase;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.Gravity;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.Button;
- import android.widget.ScrollView;
- import android.widget.TableLayout;
- import android.widget.TableRow;
- import android.widget.TextView;
- import android.widget.Toast;
- import java.util.ArrayList;
- import java.util.List;
- public class ShowListCourseActivity extends AppCompatActivity {
- String lvAccess;
- Account olUser;
- List<Course> listCourse;
- int deleteIdx;
- public void getCourseFromDb(){
- DBAdapter.CourseDbHelper courseDbHelper = new DBAdapter.CourseDbHelper(ShowListCourseActivity.this);
- SQLiteDatabase db = courseDbHelper.getReadableDatabase();
- listCourse = new ArrayList<>();
- Cursor cursor = db.query(
- DBAdapter.CourseEntry.tbName,
- new String[] {
- DBAdapter.CourseEntry._ID,
- DBAdapter.CourseEntry.colName,
- DBAdapter.CourseEntry.colDesc
- },
- null,null,null,null,null
- );
- cursor.moveToFirst();
- for(int i=0; i<cursor.getCount(); i++, cursor.moveToNext()){
- listCourse.add(new Course(
- cursor.getString(
- cursor.getColumnIndex(
- DBAdapter.CourseEntry._ID
- )
- ),
- cursor.getString(
- cursor.getColumnIndex(
- DBAdapter.CourseEntry.colName
- )
- ),
- cursor.getString(
- cursor.getColumnIndex(
- DBAdapter.CourseEntry.colDesc
- )
- )
- ));
- }
- Log.d("jumlah course", "" + listCourse.size());
- }
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_show_list_course);
- lvAccess = getIntent().getStringExtra("ACCESS_LEVEL");
- olUser = (Account) getIntent().getSerializableExtra("OL_USER");
- Log.d("OL USER DI MENU", olUser.getUsername());
- Log.d("LV USER DI MENU", lvAccess);
- getCourseFromDb();
- ScrollView svShowListCourse = (ScrollView) findViewById(R.id.svShowListCourse);
- TableLayout tlAll = new TableLayout(this);
- tlAll.setLayoutParams(new ScrollView.LayoutParams(
- ViewGroup.LayoutParams.MATCH_PARENT,
- ViewGroup.LayoutParams.MATCH_PARENT
- ));
- tlAll.setGravity(Gravity.CENTER);
- TableRow trBtnDeleteAllCourse = new TableRow(this);
- TableRow trBtnBack = new TableRow(this);
- List<TableRow> listTrCourse = new ArrayList<TableRow>();
- List<TextView> listTvCourse = new ArrayList<TextView>();
- final List<Button> listBtnCourse = new ArrayList<Button>();
- Button btnDeleteAllCourse = new Button(this);
- Button btnBack = new Button(this);
- if(listCourse.size() == 0){
- TableRow trTvNoData = new TableRow(this);
- TextView tvNoData = new TextView(this);
- tvNoData.setLayoutParams(new TableRow.LayoutParams(
- 0,
- ViewGroup.LayoutParams.WRAP_CONTENT,
- 1
- ));
- tvNoData.setText("NO DATA");
- trTvNoData.addView(tvNoData);
- tlAll.addView(trTvNoData);
- Log.d("Course Kosong", "ya");
- } else {
- for(int i=0; i<listCourse.size(); i++){
- listTrCourse.add(new TableRow(this));
- listTvCourse.add(new TextView(this));
- listBtnCourse.add(new Button(this));
- listTvCourse.get(i).setLayoutParams(new TableRow.LayoutParams(
- 0,
- ViewGroup.LayoutParams.WRAP_CONTENT,
- 1
- ));
- listBtnCourse.get(i).setLayoutParams(new TableRow.LayoutParams(
- 0,
- ViewGroup.LayoutParams.WRAP_CONTENT,
- 1
- ));
- listTvCourse.get(i).setTextSize(12);
- listTvCourse.get(i).setText(listCourse.get(i).getName());
- listBtnCourse.get(i).setText(listCourse.get(i).getName());
- listTrCourse.get(i).addView(listTvCourse.get(i));
- listTrCourse.get(i).addView(listBtnCourse.get(i));
- tlAll.addView(listTrCourse.get(i));
- deleteIdx = i;
- if(lvAccess.equals("admin")){
- listTvCourse.get(i).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Log.d("id tombol", ""+v.getId());
- Log.d("Masuk klik bentar", listCourse.get(v.getId()-1).getName());
- }
- });
- listTvCourse.get(i).setOnLongClickListener(new View.OnLongClickListener() {
- @Override
- public boolean onLongClick(View v) {
- Log.d("id tombol", ""+v.getId());
- Log.d("Masuk klik lama", listCourse.get(v.getId()-1).getName());
- return false;
- }
- });
- listBtnCourse.get(i).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Log.d("id tombol", ""+v.getId());
- Log.d("Masuk klik bentar", listCourse.get(v.getId()-1).getName());
- }
- });
- listBtnCourse.get(i).setOnLongClickListener(new View.OnLongClickListener() {
- @Override
- public boolean onLongClick(View v) {
- Log.d("id tombol", ""+v.getId());
- Log.d("Masuk klik lama", listCourse.get(v.getId()-1).getName());
- return false;
- }
- });
- }
- }
- }
- btnDeleteAllCourse.setLayoutParams(new TableRow.LayoutParams(
- 0,
- ViewGroup.LayoutParams.WRAP_CONTENT,
- 1
- ));
- btnDeleteAllCourse.setText("Delete All Course");
- trBtnDeleteAllCourse.addView(btnDeleteAllCourse);
- btnBack.setLayoutParams(new TableRow.LayoutParams(
- 0,
- ViewGroup.LayoutParams.WRAP_CONTENT,
- 1
- ));
- btnBack.setText("Back");
- trBtnBack.addView(btnBack);
- if(lvAccess.equals("admin")){
- tlAll.addView(trBtnDeleteAllCourse);
- }
- tlAll.addView(trBtnBack);
- svShowListCourse.addView(tlAll);
- btnDeleteAllCourse.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- DBAdapter.CourseDbHelper courseDbHelper = new DBAdapter.CourseDbHelper(ShowListCourseActivity.this);
- SQLiteDatabase db = courseDbHelper.getReadableDatabase();
- db.delete(DBAdapter.CourseEntry.tbName,null,null);
- Toast.makeText(
- ShowListCourseActivity.this,
- "Delete all data course",
- Toast.LENGTH_SHORT
- ).show();
- finish();
- startActivity(getIntent());
- }
- });
- btnBack.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- ShowListCourseActivity.super.onBackPressed();
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement