Advertisement
lawrinzela

alkitab

Mar 31st, 2017
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 56.43 KB | None | 0 0
  1. === activity add account ===
  2. <?xml version="1.0" encoding="utf-8"?>
  3. <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
  4.     xmlns:app="http://schemas.android.com/apk/res-auto"
  5.     xmlns:tools="http://schemas.android.com/tools"
  6.     android:layout_width="match_parent"
  7.     android:layout_height="match_parent"
  8.     tools:context="com.ramli.latianuts.AddAccountActivity">
  9.      
  10.     <TableLayout
  11.         android:layout_width="match_parent"
  12.         android:layout_height="match_parent">  
  13.         <TableRow>
  14.             <TextView
  15.                 android:layout_weight="1"
  16.                 android:layout_width="0dp"
  17.                 android:layout_height="wrap_content"
  18.                 android:text="Username"/>
  19.             <EditText
  20.                 android:id="@+id/editUsername"
  21.                 android:layout_weight="1"
  22.                 android:layout_width="0dp"
  23.                 android:layout_height="wrap_content"
  24.                 android:hint="username"
  25.                 android:inputType="text"/>
  26.         </TableRow>
  27.         <TableRow>
  28.             <TextView
  29.                 android:layout_weight="1"
  30.                 android:layout_width="0dp"
  31.                 android:layout_height="wrap_content"
  32.                 android:text="Password"/>
  33.             <EditText
  34.                 android:id="@+id/editPassword"
  35.                 android:layout_weight="1"
  36.                 android:layout_width="0dp"
  37.                 android:layout_height="wrap_content"
  38.                 android:hint="password"
  39.                 android:inputType="textPassword"/>
  40.         </TableRow>
  41.         <TableRow>
  42.             <TextView
  43.                 android:layout_weight="1"
  44.                 android:layout_width="0dp"
  45.                 android:layout_height="wrap_content"
  46.                 android:text="Password Confirmation"/>
  47.             <EditText
  48.                 android:id="@+id/editPasswordConfirmation"
  49.                 android:layout_weight="1"
  50.                 android:layout_width="0dp"
  51.                 android:layout_height="wrap_content"
  52.                 android:hint="confirm password"
  53.                 android:inputType="textPassword"/>
  54.         </TableRow>
  55.         <TableRow>
  56.             <TextView
  57.                 android:layout_weight="1"
  58.                 android:layout_width="0dp"
  59.                 android:layout_height="wrap_content"
  60.                 android:text="Name"/>
  61.             <EditText
  62.                 android:id="@+id/editName"
  63.                 android:layout_weight="1"
  64.                 android:layout_width="0dp"
  65.                 android:layout_height="wrap_content"
  66.                 android:hint="Name"
  67.                 android:inputType="text"/>
  68.         </TableRow>
  69.         <TableRow>
  70.             <TextView
  71.                 android:layout_weight="1"
  72.                 android:layout_width="0dp"
  73.                 android:layout_height="wrap_content"
  74.                 android:text="Address"/>
  75.             <EditText
  76.                 android:id="@+id/editAddress"
  77.                 android:layout_weight="1"
  78.                 android:layout_width="0dp"
  79.                 android:layout_height="wrap_content"
  80.                 android:hint="Address"
  81.                 android:inputType="textMultiLine"/>
  82.         </TableRow>
  83.         <TableRow>
  84.             <TextView
  85.                 android:layout_weight="1"
  86.                 android:layout_width="0dp"
  87.                 android:layout_height="wrap_content"
  88.                 android:text="Email"/>
  89.             <EditText
  90.                 android:id="@+id/editEmail"
  91.                 android:layout_weight="1"
  92.                 android:layout_width="0dp"
  93.                 android:layout_height="wrap_content"
  94.                 android:hint="email"
  95.                 android:inputType="textEmailAddress"/>
  96.         </TableRow>
  97.         <TableRow>
  98.             <Button android:layout_weight="1"
  99.                 android:layout_width="0dp"
  100.                 android:layout_height="wrap_content"
  101.                 android:id="@+id/btnBack"
  102.                 android:text="BACK"/>
  103.             <Button
  104.                 android:layout_weight="1"
  105.                 android:layout_width="0dp"
  106.                 android:layout_height="wrap_content"
  107.                 android:id="@+id/btnSubmit"
  108.                 android:text="SUBMIT"/>
  109.         </TableRow>
  110.     </TableLayout>
  111. </ScrollView>  
  112.  
  113. ===activity add course===
  114.  
  115. <?xml version="1.0" encoding="utf-8"?>
  116. <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
  117.     xmlns:app="http://schemas.android.com/apk/res-auto"
  118.     xmlns:tools="http://schemas.android.com/tools"
  119.     android:layout_width="match_parent"
  120.     android:layout_height="match_parent"
  121.     tools:context="com.ramli.latianuts.AddCourseActivity">  
  122.     <TableLayout
  123.         android:layout_width="match_parent"
  124.         android:layout_height="match_parent">
  125.         <TableRow>
  126.             <TextView
  127.                 android:layout_weight="1"
  128.                 android:layout_width="0dp"
  129.                 android:layout_height="wrap_content"
  130.                 android:text="Course Name"/>
  131.             <EditText
  132.                 android:id="@+id/editCourseName"
  133.                 android:layout_weight="1"
  134.                 android:layout_width="0dp"
  135.                 android:layout_height="wrap_content"
  136.                 android:hint="Course Name"
  137.                 android:inputType="text"/>
  138.         </TableRow>
  139.         <TableRow>
  140.             <TextView
  141.                 android:layout_weight="1"
  142.                 android:layout_width="0dp"
  143.                 android:layout_height="wrap_content"
  144.                 android:text="Deskripsi"/>
  145.             <EditText
  146.                 android:id="@+id/editDesc"
  147.                 android:layout_weight="1"
  148.                 android:layout_width="0dp"
  149.                 android:layout_height="wrap_content"
  150.                 android:hint="Deskripsi"
  151.                 android:inputType="text"/>
  152.         </TableRow>
  153.         <TableRow>
  154.             <Button android:layout_weight="1"
  155.                 android:layout_width="0dp"
  156.                 android:layout_height="wrap_content"
  157.                 android:id="@+id/btnBack"
  158.                 android:text="BACK"/>
  159.             <Button
  160.                 android:layout_weight="1"
  161.                 android:layout_width="0dp"
  162.                 android:layout_height="wrap_content"
  163.                 android:id="@+id/btnSubmit"
  164.                 android:text="SUBMIT"/>
  165.         </TableRow>
  166.     </TableLayout>
  167. </ScrollView>  
  168.  
  169. ===activity edit account ===
  170.  
  171. <?xml version="1.0" encoding="utf-8"?>
  172. <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
  173.     xmlns:app="http://schemas.android.com/apk/res-auto"
  174.     xmlns:tools="http://schemas.android.com/tools"
  175.     android:layout_width="match_parent"
  176.     android:layout_height="match_parent"
  177.     tools:context="com.ramli.latianuts.EditAccountActivity">
  178.     <TableLayout
  179.         android:layout_width="match_parent"
  180.         android:layout_height="match_parent">  
  181.         <TableRow>
  182.             <TextView
  183.                 android:layout_weight="1"
  184.                 android:layout_width="0dp"
  185.                 android:layout_height="wrap_content"
  186.                 android:text="Username"/>
  187.             <EditText
  188.                 android:id="@+id/editUsername"
  189.                 android:layout_weight="1"
  190.                 android:layout_width="0dp"
  191.                 android:layout_height="wrap_content"
  192.                 android:hint="username"
  193.                 android:inputType="text"
  194.                 android:enabled="false"/>
  195.         </TableRow>
  196.         <TableRow>
  197.             <TextView
  198.                 android:layout_weight="1"
  199.                 android:layout_width="0dp"
  200.                 android:layout_height="wrap_content"
  201.                 android:text="Password"/>
  202.             <EditText
  203.                 android:id="@+id/editPassword"
  204.                 android:layout_weight="1"
  205.                 android:layout_width="0dp"
  206.                 android:layout_height="wrap_content"
  207.                 android:hint="password"
  208.                 android:enabled="false"
  209.                 android:inputType="textPassword"/>
  210.         </TableRow>
  211.         <TableRow>
  212.             <TextView
  213.                 android:layout_weight="1"
  214.                 android:layout_width="0dp"
  215.                 android:layout_height="wrap_content"
  216.                 android:text="Password Confirmation"/>
  217.             <EditText
  218.                 android:id="@+id/editNewPassword"
  219.                 android:layout_weight="1"
  220.                 android:layout_width="0dp"
  221.                 android:layout_height="wrap_content"
  222.                 android:hint="new password"
  223.                 android:inputType="textPassword"/>
  224.         </TableRow>
  225.         <TableRow>
  226.             <TextView
  227.                 android:layout_weight="1"
  228.                 android:layout_width="0dp"
  229.                 android:layout_height="wrap_content"
  230.                 android:text="Password Confirmation"/>
  231.             <EditText
  232.                 android:id="@+id/editPasswordConfirmation"
  233.                 android:layout_weight="1"
  234.                 android:layout_width="0dp"
  235.                 android:layout_height="wrap_content"
  236.                 android:hint="confirm password"
  237.                 android:inputType="textPassword"/>
  238.         </TableRow>
  239.         <TableRow>
  240.             <TextView
  241.                 android:layout_weight="1"
  242.                 android:layout_width="0dp"
  243.                 android:layout_height="wrap_content"
  244.                 android:text="Name"/>
  245.             <EditText
  246.                 android:id="@+id/editName"
  247.                 android:layout_weight="1"
  248.                 android:layout_width="0dp"
  249.                 android:layout_height="wrap_content"
  250.                 android:hint="Name"
  251.                 android:inputType="text"/>
  252.         </TableRow>
  253.         <TableRow>
  254.             <TextView
  255.                 android:layout_weight="1"
  256.                 android:layout_width="0dp"
  257.                 android:layout_height="wrap_content"
  258.                 android:text="Address"/>
  259.             <EditText
  260.                 android:id="@+id/editAddress"
  261.                 android:layout_weight="1"
  262.                 android:layout_width="0dp"
  263.                 android:layout_height="wrap_content"
  264.                 android:hint="Address"
  265.                 android:inputType="textMultiLine"/>
  266.         </TableRow>
  267.         <TableRow>
  268.             <TextView
  269.                 android:layout_weight="1"
  270.                 android:layout_width="0dp"
  271.                 android:layout_height="wrap_content"
  272.                 android:text="Email"/>
  273.             <EditText
  274.                 android:id="@+id/editEmail"
  275.                 android:layout_weight="1"
  276.                 android:layout_width="0dp"
  277.                 android:layout_height="wrap_content"
  278.                 android:hint="email"
  279.                 android:inputType="textEmailAddress"/>
  280.         </TableRow>
  281.         <TableRow>
  282.             <Button android:layout_weight="1"
  283.                 android:layout_width="0dp"
  284.                 android:layout_height="wrap_content"
  285.                 android:id="@+id/btnBack"
  286.                 android:text="BACK"/>
  287.             <Button
  288.                 android:layout_weight="1"
  289.                 android:layout_width="0dp"
  290.                 android:layout_height="wrap_content"
  291.                 android:id="@+id/btnSubmit"
  292.                 android:text="SUBMIT"/>
  293.         </TableRow>
  294.     </TableLayout>  
  295. </ScrollView>  
  296.  
  297. ====activity login  =====
  298.  
  299. <?xml version="1.0" encoding="utf-8"?>
  300. <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
  301.     xmlns:app="http://schemas.android.com/apk/res-auto"
  302.     xmlns:tools="http://schemas.android.com/tools"
  303.     android:layout_width="match_parent"
  304.     android:layout_height="match_parent"
  305.     tools:context="com.ramli.latianuts.LoginActivity">
  306.  
  307.     <TableLayout
  308.         android:layout_width="match_parent"
  309.         android:layout_height="match_parent"
  310.         android:layout_gravity="center">  
  311.         <TableRow>
  312.             <TextView
  313.                 android:layout_weight="1"
  314.                 android:layout_width="0dp"
  315.                 android:layout_height="wrap_content"
  316.                 android:text="Username"/>
  317.             <EditText
  318.                 android:layout_weight="1"
  319.                 android:layout_width="0dp"
  320.                 android:layout_height="wrap_content"
  321.                 android:id="@+id/editUsername"
  322.                 android:hint="Username"
  323.                 android:inputType="text"/>
  324.         </TableRow>
  325.         <TableRow>
  326.             <TextView
  327.                 android:layout_weight="1"
  328.                 android:layout_width="0dp"
  329.                 android:layout_height="wrap_content"
  330.                 android:text="Password"/>
  331.             <EditText
  332.                 android:layout_weight="1"
  333.                 android:layout_width="0dp"
  334.                 android:layout_height="wrap_content"
  335.                 android:id="@+id/editPassword"
  336.                 android:hint="Password"
  337.                 android:inputType="textPassword"/>
  338.         </TableRow>
  339.         <TableRow
  340.             android:gravity="center">
  341.             <CheckBox
  342.                 android:id="@+id/cbRemember"
  343.                 android:text="Remember Me"/>
  344.         </TableRow>
  345.         <TableRow>
  346.             <Button
  347.                 android:id="@+id/btnSubmit"
  348.                 android:text="Login"
  349.                 android:layout_weight="1"
  350.                 android:layout_width="0dp"
  351.                 android:layout_height="wrap_content"/>
  352.         </TableRow>
  353.     </TableLayout>    
  354. </ScrollView>  
  355.  
  356. ====activity menu  ====
  357. <?xml version="1.0" encoding="utf-8"?>
  358. <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
  359.     xmlns:app="http://schemas.android.com/apk/res-auto"
  360.     xmlns:tools="http://schemas.android.com/tools"
  361.     android:layout_width="match_parent"
  362.     android:layout_height="match_parent"
  363.     tools:context="com.ramli.latianuts.MenuActivity"
  364.     android:id="@+id/svMenu"
  365.     android:layout_gravity="center">  
  366. </ScrollView>
  367.  
  368. ====activity show list course  ====
  369. <?xml version="1.0" encoding="utf-8"?>
  370. <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
  371.     xmlns:app="http://schemas.android.com/apk/res-auto"
  372.     xmlns:tools="http://schemas.android.com/tools"
  373.     android:layout_width="match_parent"
  374.     android:layout_height="match_parent"
  375.     tools:context="com.ramli.latianuts.ShowListCourseActivity"
  376.     android:id="@+id/svShowListCourse">  
  377. </ScrollView>  
  378. menu add account  
  379. <?xml version="1.0" encoding="utf-8"?>
  380. <menu xmlns:tools="http://schemas.android.com/tools"
  381.     xmlns:android="http://schemas.android.com/apk/res/android"
  382.     tools:context=".LoginActivity">
  383.     <item
  384.         android:id="@+id/actionAddAccount"
  385.         android:title="Add Account"
  386.         />
  387. </menu>
  388.  
  389. ====account java====
  390.  
  391. package com.ramli.latianuts;  
  392. import java.io.Serializable;  
  393. /**
  394.  * Created by Ramlivan's Y50 on 27/03/2017.
  395.  */  
  396. public class Account implements Serializable{
  397.     private String username, password, name, address, email;  
  398.     Account(String username, String password, String name, String address, String email){
  399.         this.username = username;
  400.         this.password = password;
  401.         this.name = name;
  402.         this.address = address;
  403.         this.email = email;
  404.     }  
  405.     public String getName() {
  406.         return name;
  407.     }  
  408.     public String getUsername() {
  409.         return username;
  410.     }  
  411.     public String getPassword() {
  412.         return password;
  413.     }  
  414.     public String getAddress() {
  415.         return address;
  416.     }  
  417.     public String getEmail() {
  418.         return email;
  419.     }  
  420.     public void setAddress(String address) {
  421.         this.address = address;
  422.     }  
  423.     public void setEmail(String email) {
  424.         this.email = email;
  425.     }  
  426.     public void setName(String name) {
  427.         this.name = name;
  428.     }  
  429.     public void setPassword(String password) {
  430.         this.password = password;
  431.     }  
  432.     public void setUsername(String username) {
  433.         this.username = username;
  434.     }
  435. }
  436.  
  437. ====addaccountactivity.java  ====
  438.  
  439. package com.ramli.latianuts;  
  440. import android.content.ContentValues;
  441. import android.content.Intent;
  442. import android.database.sqlite.SQLiteDatabase;
  443. import android.support.v7.app.AppCompatActivity;
  444. import android.os.Bundle;
  445. import android.util.Log;
  446. import android.view.View;
  447. import android.widget.Button;
  448. import android.widget.EditText;  
  449. public class AddAccountActivity extends AppCompatActivity {
  450.     Account olUser;
  451.     String lvAccess;
  452.     @Override
  453.     protected void onCreate(Bundle savedInstanceState) {
  454.         super.onCreate(savedInstanceState);
  455.         setContentView(R.layout.activity_add_account);
  456.         lvAccess = getIntent().getStringExtra("ACCESS_LEVEL");
  457.         olUser = (Account) getIntent().getSerializableExtra("OL_USER");
  458.         if(lvAccess != null && olUser != null){
  459.             Log.d("online user", olUser.getName() + "-" + lvAccess);
  460.         } else {
  461.             Log.d("online user", "ini ga masuk");
  462.         }  
  463.         final EditText editUsername = (EditText) findViewById(R.id.editUsername);
  464.         final EditText editPassword = (EditText) findViewById(R.id.editPassword);
  465.         final EditText editPasswordConfirmation = (EditText) findViewById(R.id.editPasswordConfirmation);
  466.         final EditText editName = (EditText) findViewById(R.id.editName);
  467.         final EditText editAddress = (EditText) findViewById(R.id.editAddress);
  468.         final EditText editEmail = (EditText) findViewById(R.id.editEmail);
  469.         Button btnSubmit = (Button) findViewById(R.id.btnSubmit);
  470.         Button btnBack = (Button) findViewById(R.id.btnBack);  
  471.         btnSubmit.setOnClickListener(new View.OnClickListener() {
  472.             @Override
  473.             public void onClick(View v) {
  474.                 DBAdapter.AccountDbHelper accountDbHelper =
  475.                         new DBAdapter.AccountDbHelper(AddAccountActivity.this);  
  476.                 SQLiteDatabase db = accountDbHelper.getWritableDatabase();
  477.                 ContentValues contentValues = new ContentValues();  
  478.                 contentValues.put(
  479.                         DBAdapter.AccountEntry.colUsername,
  480.                         editUsername.getText().toString()
  481.                 );
  482.                 contentValues.put(
  483.                         DBAdapter.AccountEntry.colPassword,
  484.                         editPassword.getText().toString()
  485.                 );
  486.                 contentValues.put(
  487.                         DBAdapter.AccountEntry.colName,
  488.                         editName.getText().toString()
  489.                 );
  490.                 contentValues.put(
  491.                         DBAdapter.AccountEntry.colAddress,
  492.                         editAddress.getText().toString()
  493.                 );
  494.                 contentValues.put(
  495.                         DBAdapter.AccountEntry.colEmail,
  496.                         editEmail.getText().toString()
  497.                 );  
  498.                 long newVal = db.insert(
  499.                         DBAdapter.AccountEntry.tbName,
  500.                         null,
  501.                         contentValues
  502.                 );
  503.                 if(lvAccess != null && olUser != null){
  504.                     Intent i = new Intent(AddAccountActivity.this, MenuActivity.class);
  505.                     i.putExtra("OL_USER", olUser);
  506.                     i.putExtra("ACCESS_LEVEL", lvAccess);
  507.                     startActivity(i);
  508.                 } else {
  509.                     startActivity(new Intent(AddAccountActivity.this, LoginActivity.class));
  510.                 }  
  511.             }
  512.         });  
  513.         btnBack.setOnClickListener(new View.OnClickListener() {
  514.             @Override
  515.             public void onClick(View v) {
  516.                 AddAccountActivity.super.onBackPressed();
  517.             }
  518.         });
  519.     }
  520. }  
  521. ====addcourseactivity  ====
  522.  
  523. package com.ramli.latianuts;  
  524. import android.content.ContentValues;
  525. import android.content.Intent;
  526. import android.database.sqlite.SQLiteDatabase;
  527. import android.support.v7.app.AppCompatActivity;
  528. import android.os.Bundle;
  529. import android.view.View;
  530. import android.widget.Button;
  531. import android.widget.EditText;  
  532. public class AddCourseActivity extends AppCompatActivity {
  533.     Account olUser;
  534.     String lvAccess;
  535.     @Override
  536.     protected void onCreate(Bundle savedInstanceState) {
  537.         super.onCreate(savedInstanceState);
  538.         setContentView(R.layout.activity_add_course);  
  539.         lvAccess = getIntent().getStringExtra("ACCESS_LEVEL");
  540.         olUser = (Account) getIntent().getSerializableExtra("OL_USER");  
  541.         final EditText editCourseName = (EditText) findViewById(R.id.editCourseName);
  542.         final EditText editDesc = (EditText) findViewById(R.id.editDesc);
  543.         Button btnBack = (Button) findViewById(R.id.btnBack);
  544.         Button btnSubmit = (Button) findViewById(R.id.btnSubmit);  
  545.         btnSubmit.setOnClickListener(new View.OnClickListener() {
  546.             @Override
  547.             public void onClick(View v) {
  548.                 DBAdapter.CourseDbHelper courseDbHelper = new DBAdapter.CourseDbHelper(AddCourseActivity.this);
  549.                 SQLiteDatabase db = courseDbHelper.getWritableDatabase();  
  550.                 ContentValues contentValues = new ContentValues();  
  551.                 contentValues.put(
  552.                         DBAdapter.CourseEntry.colName,
  553.                         editCourseName.getText().toString()
  554.                 );  
  555.                 contentValues.put(
  556.                         DBAdapter.CourseEntry.colDesc,
  557.                         editDesc.getText().toString()
  558.                 );  
  559.                 long newVal = db.insert(
  560.                         DBAdapter.CourseEntry.tbName,
  561.                         null,
  562.                         contentValues
  563.                 );  
  564.                 Intent i = new Intent(AddCourseActivity.this, MenuActivity.class);
  565.                 i.putExtra("OL_USER", olUser);
  566.                 i.putExtra("ACCESS_LEVEL", lvAccess);
  567.                 startActivity(i);
  568.             }
  569.         });  
  570.         btnBack.setOnClickListener(new View.OnClickListener() {
  571.             @Override
  572.             public void onClick(View v) {
  573.                 AddCourseActivity.super.onBackPressed();
  574.             }
  575.         });
  576.     }
  577. }  
  578. ====course  ====
  579. package com.ramli.latianuts;  
  580. /**
  581.  * Created by Ramlivan's Y50 on 27/03/2017.
  582.  */  
  583. public class Course {
  584.     private String code, name, desc;  
  585.     Course(String code, String name, String desc){
  586.         this.code = code;
  587.         this.name = name;
  588.         this.desc = desc;
  589.     }  
  590.     public String getName() {
  591.         return name;
  592.     }  
  593.     public String getDesc() {
  594.         return desc;
  595.     }  
  596.     public String getCode() {
  597.         return code;
  598.     }
  599. }  
  600. ====dbadapter ====
  601. package com.ramli.latianuts;  
  602. import android.content.Context;
  603. import android.database.sqlite.SQLiteDatabase;
  604. import android.database.sqlite.SQLiteOpenHelper;
  605. import android.provider.BaseColumns;  
  606. /**
  607.  * Created by Ramlivan's Y50 on 27/03/2017.
  608.  */  
  609. public final class DBAdapter {
  610.     public static class AccountEntry implements BaseColumns{
  611.         public static final String tbName = "account";
  612.         public static final String colUsername = "username";
  613.         public static final String colPassword = "password";
  614.         public static final String colName = "name";
  615.         public static final String colAddress = "address";
  616.         public static final String colEmail = "email";
  617.     }  
  618.     public static final String sqlCreateAccount = String.format(
  619.             "create table %s(%s, %s, %s, %s, %s);",
  620.             AccountEntry.tbName,
  621.             String.format("%s varchar(40) primary key", AccountEntry.colUsername),
  622.             String.format("%s varchar(40)", AccountEntry.colPassword),
  623.             String.format("%s varchar(40)", AccountEntry.colName),
  624.             String.format("%s varchar(40)", AccountEntry.colAddress),
  625.             String.format("%s varchar(40)", AccountEntry.colEmail)
  626.     );  
  627.     public static final String sqlDeleteAccount = String.format(
  628.             "drop table if exists %s",
  629.             AccountEntry.tbName
  630.     );  
  631.     public static class AccountDbHelper extends SQLiteOpenHelper{
  632.         public static final int dbVersion = 1;
  633.         public static final String dbName = "mobile.uts.ramli.db";  
  634.         public AccountDbHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
  635.             super(context, name, factory, version);
  636.         }  
  637.         public AccountDbHelper(Context context) {
  638.             super(context, dbName, null, dbVersion);
  639.         }
  640.  
  641.         @Override
  642.         public void onCreate(SQLiteDatabase db) {
  643.             db.execSQL(sqlCreateAccount);
  644.         }  
  645.         @Override
  646.         public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  647.             db.execSQL(sqlDeleteAccount);
  648.             onCreate(db);
  649.         }  
  650.         @Override
  651.         public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  652.             onUpgrade(db,oldVersion,newVersion);
  653.             //super.onDowngrade(db, oldVersion, newVersion);
  654.         }
  655.     }  
  656.     public static class CourseEntry implements BaseColumns{
  657.         public static final String tbName = "course";
  658.         public static final String colName = "name";
  659.         public static final String colDesc = "desc";
  660.     }  
  661.     public static final String sqlCreateCouse = String.format(
  662.             "create table %s(%s, %s, %s)",
  663.             CourseEntry.tbName,
  664.             String.format("%s integer primary key autoincrement", CourseEntry._ID),
  665.             String.format("%s varchar(40)", CourseEntry.colName),
  666.             String.format("%s varchar(100)", CourseEntry.colDesc)
  667.     );  
  668.     public static final String sqlDeleteCourse = String.format(
  669.             "drop table if exists %s",
  670.             CourseEntry.tbName
  671.     );  
  672.     public static class CourseDbHelper extends SQLiteOpenHelper{
  673.         public static final int dbVer = 1;
  674.         public static final String dbName = "mobile_ramli.db";  
  675.         public CourseDbHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
  676.             super(context, name, factory, version);
  677.         }  
  678.         public CourseDbHelper(Context context){
  679.             super(context, dbName, null, dbVer);
  680.         }  
  681.         @Override
  682.         public void onCreate(SQLiteDatabase db) {
  683.             db.execSQL(sqlCreateCouse);
  684.         }  
  685.         @Override
  686.         public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  687.             db.execSQL(sqlDeleteCourse);
  688.             onCreate(db);
  689.         }  
  690.         @Override
  691.         public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  692.             onUpgrade(db, oldVersion, newVersion);
  693.             //super.onDowngrade(db, oldVersion, newVersion);
  694.         }
  695.     }
  696. }  
  697. ====editaccountactivity ====
  698.  
  699. package com.ramli.latianuts;  
  700. import android.content.ContentValues;
  701. import android.content.Intent;
  702. import android.database.sqlite.SQLiteDatabase;
  703. import android.support.v7.app.AppCompatActivity;
  704. import android.os.Bundle;
  705. import android.view.View;
  706. import android.widget.Button;
  707. import android.widget.EditText;  
  708. public class EditAccountActivity extends AppCompatActivity {
  709.     Account olUser;
  710.     String lvAccess;
  711.     @Override
  712.     protected void onCreate(Bundle savedInstanceState) {
  713.         super.onCreate(savedInstanceState);
  714.         setContentView(R.layout.activity_edit_account);  
  715.         final EditText editUsername = (EditText) findViewById(R.id.editUsername);
  716.         final EditText editPassword = (EditText) findViewById(R.id.editPassword);
  717.         final EditText editNewPassword = (EditText) findViewById(R.id.editNewPassword);
  718.         final EditText editPasswordConfirmation = (EditText) findViewById(R.id.editPasswordConfirmation);
  719.         final EditText editName = (EditText) findViewById(R.id.editName);
  720.         final EditText editAddress = (EditText) findViewById(R.id.editAddress);
  721.         final EditText editEmail = (EditText) findViewById(R.id.editEmail);
  722.         Button btnSubmit = (Button) findViewById(R.id.btnSubmit);
  723.         Button btnBack = (Button) findViewById(R.id.btnBack);  
  724.         lvAccess = getIntent().getStringExtra("ACCESS_LEVEL");
  725.         olUser = (Account) getIntent().getSerializableExtra("OL_USER");
  726.         editUsername.setText(olUser.getUsername());
  727.         editPassword.setText(olUser.getPassword());
  728.         editName.setText(olUser.getName());
  729.         editAddress.setText(olUser.getAddress());
  730.         editEmail.setText(olUser.getEmail());
  731.         if(olUser.getUsername().equals("admin")){
  732.             editNewPassword.setEnabled(false);
  733.             editPasswordConfirmation.setEnabled(false);
  734.             editName.setEnabled(false);
  735.             editAddress.setEnabled(false);
  736.             editEmail.setEnabled(false);
  737.             btnSubmit.setEnabled(false);
  738.         }  
  739.         btnSubmit.setOnClickListener(new View.OnClickListener() {
  740.             @Override
  741.             public void onClick(View v) {
  742.                 DBAdapter.AccountDbHelper accountDbHelper
  743.                         = new DBAdapter.AccountDbHelper(EditAccountActivity.this);
  744.                 SQLiteDatabase db = accountDbHelper.getReadableDatabase();
  745.  
  746.                 ContentValues contentValues = new ContentValues();
  747.                 contentValues.put(
  748.                         DBAdapter.AccountEntry.colPassword,
  749.                         editNewPassword.getText().toString()
  750.                 );
  751.                 contentValues.put(
  752.                         DBAdapter.AccountEntry.colName,
  753.                         editName.getText().toString()
  754.                 );
  755.                 contentValues.put(
  756.                         DBAdapter.AccountEntry.colAddress,
  757.                         editAddress.getText().toString()
  758.                 );
  759.                 contentValues.put(
  760.                         DBAdapter.AccountEntry.colEmail,
  761.                         editEmail.getText().toString()
  762.                 );
  763.                 String selection = String.format(
  764.                         "%s = ?",
  765.                         DBAdapter.AccountEntry.colUsername
  766.                 );  
  767.                 String[] selectionArgs = { olUser.getUsername()};  
  768.                 int count = db.update(
  769.                   DBAdapter.AccountEntry.tbName,
  770.                         contentValues,
  771.                         selection,
  772.                         selectionArgs
  773.                 );
  774.                 Intent i = new Intent(EditAccountActivity.this, MenuActivity.class);
  775.                 olUser = new Account(olUser.getUsername(),editNewPassword.getText().toString(), editName.getText().toString(), editAddress.getText().toString(), editEmail.getText().toString());
  776.                 i.putExtra("OL_USER", olUser);
  777.                 i.putExtra("ACCESS_LEVEL", lvAccess);
  778.                 startActivity(i);
  779.             }
  780.         });  
  781.         btnBack.setOnClickListener(new View.OnClickListener() {
  782.             @Override
  783.             public void onClick(View v) {
  784.                 EditAccountActivity.super.onBackPressed();
  785.             }
  786.         });
  787.     }
  788. }  
  789. ====login activity ====
  790.  
  791. package com.ramli.latianuts;  
  792. import android.content.Intent;
  793. import android.content.SharedPreferences;
  794. import android.database.Cursor;
  795. import android.database.Observable;
  796. import android.database.sqlite.SQLiteDatabase;
  797. import android.support.v7.app.AppCompatActivity;
  798. import android.os.Bundle;
  799. import android.util.Log;
  800. import android.view.Menu;
  801. import android.view.MenuInflater;
  802. import android.view.MenuItem;
  803. import android.view.View;
  804. import android.widget.Button;
  805. import android.widget.CheckBox;
  806. import android.widget.EditText;
  807. import android.widget.Toast;  
  808. import java.util.ArrayList;
  809. import java.util.List;  
  810. public class LoginActivity extends AppCompatActivity {  
  811.     Account olUser;  
  812.     @Override
  813.     protected void onStart() {
  814.         super.onStart();  
  815.         SharedPreferences pref = getSharedPreferences("LOGIN_PREF", MODE_PRIVATE);
  816.         Intent i = new Intent(this, MenuActivity.class);
  817.         if(pref.getString("ACCESS_LEVEL", "").equals("admin")){
  818.             i.putExtra("ACCESS_LEVEL", "admin");
  819.             i.putExtra("OL_USER", new Account("admin", "admin" , "admin", "", ""));
  820.             startActivity(i);
  821.         } else if (pref.getString("ACCESS_LEVEL", "").equals("user")){
  822.             i.putExtra("ACCESS_LEVEL", "user");
  823.             i.putExtra("OL_USER", olUser);
  824.             startActivity(i);
  825.         }
  826.     }
  827.  
  828.     @Override
  829.     protected void onCreate(Bundle savedInstanceState) {
  830.         super.onCreate(savedInstanceState);
  831.         setContentView(R.layout.activity_login);  
  832.         final EditText editUsername = (EditText) findViewById(R.id.editUsername);
  833.         final EditText editPassword = (EditText) findViewById(R.id.editPassword);
  834.         final CheckBox checkRememberMe = (CheckBox) findViewById(R.id.cbRemember);
  835.         Button btnLogin = (Button) findViewById(R.id.btnSubmit);  
  836.         btnLogin.setOnClickListener(new View.OnClickListener() {
  837.             @Override
  838.             public void onClick(View v) {
  839.                 if(editUsername.getText().toString().equals("admin")
  840.                         && editPassword.getText().toString().equals("admin")){
  841.                     SharedPreferences.Editor prefEdit =
  842.                             getSharedPreferences("LOGIN_PREF", MODE_PRIVATE).edit();
  843.                     prefEdit.putString("ACCESS_LEVEL", "admin");
  844.                     prefEdit.commit();  
  845.                     prefEdit = getPreferences(MODE_PRIVATE).edit();
  846.                     if(checkRememberMe.isChecked()){
  847.                         prefEdit.putString("USERNAME", editUsername.getText().toString());
  848.                         prefEdit.putString("PASSWORD", editPassword.getText().toString());
  849.                     } else {
  850.                         prefEdit.clear();
  851.                     }
  852.                     prefEdit.putBoolean("REMEMBER_ME", checkRememberMe.isChecked());
  853.                     prefEdit.commit();
  854.                     Intent i = new Intent(LoginActivity.this,MenuActivity.class);
  855.                     i.putExtra("ACCESS_LEVEL", "admin");
  856.                     i.putExtra("OL_USER", new Account("admin", "admin" , "admin", "", ""));
  857.                     startActivity(i);
  858.                 }else{
  859.                     List<Account> accFromDb = new ArrayList<Account>();
  860.                     String username = editUsername.getText().toString();
  861.                     String password = editPassword.getText().toString();
  862.                     DBAdapter.AccountDbHelper accountDbHelper =
  863.                             new DBAdapter.AccountDbHelper(LoginActivity.this);
  864.                     SQLiteDatabase db = accountDbHelper.getReadableDatabase();  
  865.                     Cursor cursor = db.query(
  866.                             DBAdapter.AccountEntry.tbName,
  867.                             new String[]{
  868.                                     DBAdapter.AccountEntry.colUsername,
  869.                                     DBAdapter.AccountEntry.colPassword,
  870.                                     DBAdapter.AccountEntry.colName,
  871.                                     DBAdapter.AccountEntry.colAddress,
  872.                                     DBAdapter.AccountEntry.colEmail
  873.                             },
  874.                             null,null,null,null,null
  875.                     );
  876.                     cursor.moveToFirst();
  877.                     for(int i=0;i<cursor.getCount();i++,cursor.moveToNext()){
  878.                         Account acc = new Account(
  879.                                 cursor.getString(
  880.                                         cursor.getColumnIndex(
  881.                                                 DBAdapter.AccountEntry.colUsername
  882.                                         )
  883.                                 ),
  884.                                 cursor.getString(
  885.                                         cursor.getColumnIndex(
  886.                                                 DBAdapter.AccountEntry.colPassword
  887.                                         )
  888.                                 ),
  889.                                 cursor.getString(
  890.                                         cursor.getColumnIndex(
  891.                                                 DBAdapter.AccountEntry.colName
  892.                                         )
  893.                                 ),
  894.                                 cursor.getString(
  895.                                         cursor.getColumnIndex(
  896.                                                 DBAdapter.AccountEntry.colAddress
  897.                                         )
  898.                                 ),
  899.                                 cursor.getString(
  900.                                         cursor.getColumnIndex(
  901.                                                 DBAdapter.AccountEntry.colEmail
  902.                                         )
  903.                                 )
  904.                         );
  905.                         if(acc != null) {
  906.                             //Log.d(acc.getUsername(),acc.getName());
  907.                             //accFromDb.set(i, acc);
  908.                             accFromDb.add(acc);
  909.                         }
  910.                     }
  911.                     int loginFlag = 0;
  912.                     for (Account idx: accFromDb) {
  913.                         if(username.equals(idx.getUsername()) && password.equals(idx.getPassword())){
  914.                             loginFlag=1;
  915.                             olUser = idx;
  916.                             break;
  917.                         }
  918.                     }
  919.                     if(loginFlag == 1){
  920.                         SharedPreferences.Editor prefEdit = getSharedPreferences("LOGIN_PREF", MODE_PRIVATE).edit();
  921.                         prefEdit.putString("ACCESS_LEVEL", "user");
  922.                         prefEdit.commit();  
  923.                         prefEdit = getPreferences(MODE_PRIVATE).edit();
  924.                         if(checkRememberMe.isChecked()){
  925.                             prefEdit.putString("USERNAME", editUsername.getText().toString());
  926.                             prefEdit.putString("PASSWORD", editPassword.getText().toString());
  927.                         } else {
  928.                             prefEdit.clear();
  929.                         }
  930.                         prefEdit.putBoolean("REMEMBER_ME", checkRememberMe.isChecked());
  931.                         prefEdit.commit();
  932.                         Intent i = new Intent(LoginActivity.this,MenuActivity.class);
  933.                         i.putExtra("ACCESS_LEVEL", "user");
  934.                         i.putExtra("OL_USER", olUser);
  935.                         startActivity(i);
  936.                     } else {
  937.                         Toast.makeText(
  938.                                 getApplicationContext(),
  939.                                 "Username or password doesn't match",
  940.                                 Toast.LENGTH_SHORT
  941.                         ).show();
  942.                     }  
  943.                 }
  944.             }
  945.         });
  946.         SharedPreferences pref = getPreferences(MODE_PRIVATE);
  947.         editUsername.setText(pref.getString("USERNAME", ""));
  948.         editPassword.setText(pref.getString("PASSWORD", ""));
  949.         checkRememberMe.setChecked(pref.getBoolean("REMEMBER_ME", false));
  950.     }  
  951.     @Override
  952.     public boolean onCreateOptionsMenu(Menu menu) {
  953. //        return super.onCreateOptionsMenu(menu);
  954.         MenuInflater menuInflater = getMenuInflater();
  955.         menuInflater.inflate(R.menu.menu_add_account, menu);
  956.         return true;
  957.     }  
  958.     @Override
  959.     public void onBackPressed() {
  960.         super.onBackPressed();
  961.     }  
  962.     @Override
  963.     public boolean onOptionsItemSelected(MenuItem item) {
  964.         if(item.getItemId() == R.id.actionAddAccount){
  965.             Intent i = new Intent(LoginActivity.this, AddAccountActivity.class);
  966.             startActivity(i);
  967.         }
  968.         return super.onOptionsItemSelected(item);
  969.     }
  970. }  
  971.  
  972. ====menu activity====
  973.  
  974. package com.ramli.latianuts;  
  975. import android.content.Intent;
  976. import android.content.SharedPreferences;
  977. import android.database.Cursor;
  978. import android.database.sqlite.SQLiteDatabase;
  979. import android.support.v7.app.AppCompatActivity;
  980. import android.os.Bundle;
  981. import android.util.Log;
  982. import android.view.Gravity;
  983. import android.view.Menu;
  984. import android.view.View;
  985. import android.view.ViewGroup;
  986. import android.widget.Button;
  987. import android.widget.ScrollView;
  988. import android.widget.TableLayout;
  989. import android.widget.TableRow;
  990. import android.widget.Toast;  
  991. import java.util.ArrayList;
  992. import java.util.List;  
  993. public class MenuActivity extends AppCompatActivity {
  994.     String lvAccess;
  995.     Account olUser;  
  996.     @Override
  997.     protected void onCreate(Bundle savedInstanceState) {
  998.         super.onCreate(savedInstanceState);
  999.         setContentView(R.layout.activity_menu);  
  1000.         lvAccess = getIntent().getStringExtra("ACCESS_LEVEL");
  1001.         olUser = (Account) getIntent().getSerializableExtra("OL_USER");
  1002.         if(olUser == null){
  1003.             SharedPreferences.Editor prefEdit =
  1004.                     getSharedPreferences("LOGIN_PREF", MODE_PRIVATE).edit();
  1005.             prefEdit.clear();
  1006.             prefEdit.commit();
  1007.             startActivity(new Intent(MenuActivity.this, LoginActivity.class));
  1008.         }
  1009.         Log.d("OL USER DI MENU", olUser.getUsername());
  1010.         Log.d("LV USER DI MENU", lvAccess);  
  1011.         ScrollView svMenu = (ScrollView) findViewById(R.id.svMenu);
  1012.         TableLayout tbLayoutMain = new TableLayout(this);
  1013.         TableRow tbRowBtnEditDataUser = new TableRow(this);
  1014.         TableRow tbRowBtnAddUser = new TableRow(this);
  1015.         TableRow tbRowBtnAddCourse = new TableRow(this);
  1016.         TableRow tbRowBtnDeleteAllAccount = new TableRow(this);
  1017.         TableRow tbRowBtnShowListCourse = new TableRow(this);
  1018.         TableRow tbRowBtnSignOut = new TableRow(this);  
  1019.         Button btnEditDataUser = new Button(this);
  1020.         Button btnAddUser = new Button(this);
  1021.         Button btnAddCourse = new Button(this);
  1022.         Button btnDeleteAllAccount = new Button(this);
  1023.         Button btnShowListCourse = new Button(this);
  1024.         Button btnSignOut = new Button(this);  
  1025.         btnEditDataUser.setLayoutParams(new TableRow.LayoutParams(
  1026.                 0,
  1027.                 ViewGroup.LayoutParams.WRAP_CONTENT,
  1028.                 1
  1029.         ));
  1030.         btnEditDataUser.setText("Edit Data User");
  1031.         tbRowBtnEditDataUser.addView(btnEditDataUser);  
  1032.         if(lvAccess.equals("admin")){
  1033.             btnAddUser.setLayoutParams(new TableRow.LayoutParams(
  1034.                     0,
  1035.                     ViewGroup.LayoutParams.WRAP_CONTENT,
  1036.                     1
  1037.             ));
  1038.             btnAddUser.setText("Add User");
  1039.             tbRowBtnAddUser.addView(btnAddUser);  
  1040.             btnAddCourse.setLayoutParams(new TableRow.LayoutParams(
  1041.                     0,
  1042.                     ViewGroup.LayoutParams.WRAP_CONTENT,
  1043.                     1
  1044.             ));
  1045.             btnAddCourse.setText("Add Course");
  1046.             tbRowBtnAddCourse.addView(btnAddCourse);  
  1047.             btnDeleteAllAccount.setLayoutParams(new TableRow.LayoutParams(
  1048.                     0,
  1049.                     ViewGroup.LayoutParams.WRAP_CONTENT,
  1050.                     1
  1051.             ));
  1052.             btnDeleteAllAccount.setText("Delete All Account");
  1053.             tbRowBtnDeleteAllAccount.addView(btnDeleteAllAccount);
  1054.  
  1055.         }  
  1056.         btnShowListCourse.setLayoutParams(new TableRow.LayoutParams(
  1057.                 0,
  1058.                 ViewGroup.LayoutParams.WRAP_CONTENT,
  1059.                 1
  1060.         ));
  1061.         btnShowListCourse.setText("Show List Course");
  1062.         tbRowBtnShowListCourse.addView(btnShowListCourse);  
  1063.         btnSignOut.setLayoutParams(new TableRow.LayoutParams(
  1064.                 0,
  1065.                 ViewGroup.LayoutParams.WRAP_CONTENT,
  1066.                 1
  1067.         ));
  1068.         btnSignOut.setText("Sign Out");
  1069.         tbRowBtnSignOut.addView(btnSignOut);  
  1070.         tbLayoutMain.addView(tbRowBtnEditDataUser);
  1071.         if(lvAccess.equals("admin")){
  1072.             tbLayoutMain.addView(tbRowBtnAddUser);
  1073.             tbLayoutMain.addView(tbRowBtnAddCourse);
  1074.             tbLayoutMain.addView(tbRowBtnDeleteAllAccount);
  1075.         }
  1076.         tbLayoutMain.addView(tbRowBtnShowListCourse);
  1077.         tbLayoutMain.addView(tbRowBtnSignOut);  
  1078.         tbLayoutMain.setLayoutParams(new ScrollView.LayoutParams(
  1079.                 ViewGroup.LayoutParams.MATCH_PARENT,
  1080.                 ViewGroup.LayoutParams.MATCH_PARENT
  1081.         ));
  1082.         tbLayoutMain.setGravity(Gravity.CENTER);  
  1083.         svMenu.addView(tbLayoutMain);  
  1084.         btnEditDataUser.setOnClickListener(new View.OnClickListener() {
  1085.             @Override
  1086.             public void onClick(View v) {
  1087.                 Intent i = new Intent(MenuActivity.this, EditAccountActivity.class);
  1088.                 i.putExtra("OL_USER", olUser);
  1089.                 i.putExtra("ACCESS_LEVEL", lvAccess);
  1090.                 startActivity(i);
  1091.             }
  1092.         });  
  1093.         btnSignOut.setOnClickListener(new View.OnClickListener() {
  1094.             @Override
  1095.             public void onClick(View v) {
  1096.                 SharedPreferences.Editor prefEdit =
  1097.                         getSharedPreferences("LOGIN_PREF", MODE_PRIVATE).edit();
  1098.                 prefEdit.clear();
  1099.                 prefEdit.commit();
  1100.                 startActivity(new Intent(MenuActivity.this, LoginActivity.class));
  1101.             }
  1102.         });  
  1103.         btnAddCourse.setOnClickListener(new View.OnClickListener() {
  1104.             @Override
  1105.             public void onClick(View v) {
  1106.                 Intent i = new Intent(MenuActivity.this, AddCourseActivity.class);
  1107.                 i.putExtra("OL_USER", olUser);
  1108.                 i.putExtra("ACCESS_LEVEL", lvAccess);
  1109.                 startActivity(i);
  1110.             }
  1111.         });  
  1112.         btnAddUser.setOnClickListener(new View.OnClickListener() {
  1113.             @Override
  1114.             public void onClick(View v) {
  1115.                 Intent i = new Intent(MenuActivity.this, AddAccountActivity.class);
  1116.                 i.putExtra("OL_USER", olUser);
  1117.                 i.putExtra("ACCESS_LEVEL", lvAccess);
  1118.                 startActivity(i);
  1119.             }
  1120.         });  
  1121.         btnShowListCourse.setOnClickListener(new View.OnClickListener() {
  1122.             @Override
  1123.             public void onClick(View v) {
  1124.                 Intent i = new Intent(MenuActivity.this, ShowListCourseActivity.class);
  1125.                 i.putExtra("OL_USER", olUser);
  1126.                 i.putExtra("ACCESS_LEVEL", lvAccess);
  1127.                 startActivity(i);
  1128.             }
  1129.         });  
  1130.         btnDeleteAllAccount.setOnClickListener(new View.OnClickListener() {
  1131.             @Override
  1132.             public void onClick(View v) {
  1133.                 DBAdapter.AccountDbHelper accountDbHelper = new DBAdapter.AccountDbHelper(MenuActivity.this);
  1134.                 SQLiteDatabase db = accountDbHelper.getReadableDatabase();
  1135.                 db.delete(DBAdapter.AccountEntry.tbName,null,null);
  1136.                 Toast.makeText(
  1137.                         MenuActivity.this,
  1138.                         "Delete all data user except admin",
  1139.                         Toast.LENGTH_SHORT
  1140.                 ).show();
  1141.             }
  1142.         });  
  1143.     }  
  1144.     @Override
  1145.     public void onBackPressed() {  
  1146.     }
  1147. }  
  1148.  
  1149. ====showlistcourseactivity  ====
  1150.  
  1151. package com.ramli.latianuts;  
  1152. import android.app.AlertDialog;
  1153. import android.app.Dialog;
  1154. import android.content.DialogInterface;
  1155. import android.database.Cursor;
  1156. import android.database.sqlite.SQLiteDatabase;
  1157. import android.support.v7.app.AppCompatActivity;
  1158. import android.os.Bundle;
  1159. import android.util.Log;
  1160. import android.view.Gravity;
  1161. import android.view.View;
  1162. import android.view.ViewGroup;
  1163. import android.widget.Button;
  1164. import android.widget.ScrollView;
  1165. import android.widget.TableLayout;
  1166. import android.widget.TableRow;
  1167. import android.widget.TextView;
  1168. import android.widget.Toast;  
  1169. import java.util.ArrayList;
  1170. import java.util.List;  
  1171. public class ShowListCourseActivity extends AppCompatActivity {
  1172.     String lvAccess;
  1173.     Account olUser;
  1174.     List<Course> listCourse;
  1175.     int deleteIdx;  
  1176.     public void getCourseFromDb(){
  1177.         DBAdapter.CourseDbHelper courseDbHelper = new DBAdapter.CourseDbHelper(ShowListCourseActivity.this);
  1178.         SQLiteDatabase db = courseDbHelper.getReadableDatabase();
  1179.         listCourse = new ArrayList<>();
  1180.         Cursor cursor = db.query(
  1181.                 DBAdapter.CourseEntry.tbName,
  1182.                 new String[] {
  1183.                         DBAdapter.CourseEntry._ID,
  1184.                         DBAdapter.CourseEntry.colName,
  1185.                         DBAdapter.CourseEntry.colDesc
  1186.                 },
  1187.                 null,null,null,null,null
  1188.         );
  1189.         cursor.moveToFirst();
  1190.         for(int i=0; i<cursor.getCount(); i++, cursor.moveToNext()){
  1191.             listCourse.add(new Course(
  1192.                     cursor.getString(
  1193.                             cursor.getColumnIndex(
  1194.                                     DBAdapter.CourseEntry._ID
  1195.                             )
  1196.                     ),
  1197.                     cursor.getString(
  1198.                             cursor.getColumnIndex(
  1199.                                     DBAdapter.CourseEntry.colName
  1200.                             )
  1201.                     ),
  1202.                     cursor.getString(
  1203.                             cursor.getColumnIndex(
  1204.                                     DBAdapter.CourseEntry.colDesc
  1205.                             )
  1206.                     )
  1207.             ));
  1208.         }
  1209.         Log.d("jumlah course", "" + listCourse.size());
  1210.     }
  1211.     @Override
  1212.     protected void onCreate(Bundle savedInstanceState) {
  1213.         super.onCreate(savedInstanceState);
  1214.         setContentView(R.layout.activity_show_list_course);  
  1215.         lvAccess = getIntent().getStringExtra("ACCESS_LEVEL");
  1216.         olUser = (Account) getIntent().getSerializableExtra("OL_USER");
  1217.         Log.d("OL USER DI MENU", olUser.getUsername());
  1218.         Log.d("LV USER DI MENU", lvAccess);
  1219.  
  1220.         getCourseFromDb();  
  1221.         ScrollView svShowListCourse = (ScrollView) findViewById(R.id.svShowListCourse);
  1222.         TableLayout tlAll = new TableLayout(this);
  1223.         tlAll.setLayoutParams(new ScrollView.LayoutParams(
  1224.                 ViewGroup.LayoutParams.MATCH_PARENT,
  1225.                 ViewGroup.LayoutParams.MATCH_PARENT
  1226.         ));
  1227.         tlAll.setGravity(Gravity.CENTER);
  1228.         TableRow trBtnDeleteAllCourse = new TableRow(this);
  1229.         TableRow trBtnBack = new TableRow(this);
  1230.         List<TableRow> listTrCourse = new ArrayList<TableRow>();
  1231.         List<TextView> listTvCourse = new ArrayList<TextView>();
  1232.         final List<Button> listBtnCourse = new ArrayList<Button>();  
  1233.         Button btnDeleteAllCourse = new Button(this);
  1234.         Button btnBack = new Button(this);  
  1235.         if(listCourse.size() == 0){
  1236.             TableRow trTvNoData = new TableRow(this);
  1237.             TextView tvNoData = new TextView(this);
  1238.             tvNoData.setLayoutParams(new TableRow.LayoutParams(
  1239.                     0,
  1240.                     ViewGroup.LayoutParams.WRAP_CONTENT,
  1241.                     1
  1242.             ));
  1243.             tvNoData.setText("NO DATA");
  1244.             trTvNoData.addView(tvNoData);
  1245.             tlAll.addView(trTvNoData);
  1246.             Log.d("Course Kosong", "ya");
  1247.         } else {
  1248.             for(int i=0; i<listCourse.size(); i++){
  1249.                 listTrCourse.add(new TableRow(this));
  1250.                 listTvCourse.add(new TextView(this));
  1251.                 listBtnCourse.add(new Button(this));
  1252.                 listTvCourse.get(i).setLayoutParams(new TableRow.LayoutParams(
  1253.                         0,
  1254.                         ViewGroup.LayoutParams.WRAP_CONTENT,
  1255.                         1
  1256.                 ));
  1257.                 listBtnCourse.get(i).setLayoutParams(new TableRow.LayoutParams(
  1258.                         0,
  1259.                         ViewGroup.LayoutParams.WRAP_CONTENT,
  1260.                         1
  1261.                 ));
  1262.                 listTvCourse.get(i).setTextSize(12);
  1263.                 listTvCourse.get(i).setText(listCourse.get(i).getName());
  1264.                 listBtnCourse.get(i).setText(listCourse.get(i).getName());
  1265.                 listTrCourse.get(i).addView(listTvCourse.get(i));
  1266.                 listTrCourse.get(i).addView(listBtnCourse.get(i));
  1267.                 tlAll.addView(listTrCourse.get(i));
  1268.                 deleteIdx = i;
  1269.                 if(lvAccess.equals("admin")){
  1270.                     listTvCourse.get(i).setOnClickListener(new View.OnClickListener() {
  1271.                         @Override
  1272.                         public void onClick(View v) {
  1273.                             Log.d("id tombol", ""+v.getId());
  1274.                             Log.d("Masuk klik bentar", listCourse.get(v.getId()-1).getName());
  1275.                         }
  1276.                     });
  1277.                     listTvCourse.get(i).setOnLongClickListener(new View.OnLongClickListener() {
  1278.                         @Override
  1279.                         public boolean onLongClick(View v) {
  1280.                             Log.d("id tombol", ""+v.getId());
  1281.                             Log.d("Masuk klik lama", listCourse.get(v.getId()-1).getName());
  1282.                             return false;
  1283.                         }
  1284.                     });
  1285.                     listBtnCourse.get(i).setOnClickListener(new View.OnClickListener() {
  1286.                         @Override
  1287.                         public void onClick(View v) {
  1288.                             Log.d("id tombol", ""+v.getId());
  1289.                             Log.d("Masuk klik bentar", listCourse.get(v.getId()-1).getName());
  1290.                         }
  1291.                     });
  1292.                     listBtnCourse.get(i).setOnLongClickListener(new View.OnLongClickListener() {
  1293.                         @Override
  1294.                         public boolean onLongClick(View v) {
  1295.                             Log.d("id tombol", ""+v.getId());
  1296.                             Log.d("Masuk klik lama", listCourse.get(v.getId()-1).getName());
  1297.                             return false;
  1298.                         }
  1299.                     });  
  1300.                 }
  1301.             }
  1302.         }  
  1303.         btnDeleteAllCourse.setLayoutParams(new TableRow.LayoutParams(
  1304.                 0,
  1305.                 ViewGroup.LayoutParams.WRAP_CONTENT,
  1306.                 1
  1307.         ));
  1308.         btnDeleteAllCourse.setText("Delete All Course");
  1309.         trBtnDeleteAllCourse.addView(btnDeleteAllCourse);  
  1310.         btnBack.setLayoutParams(new TableRow.LayoutParams(
  1311.                 0,
  1312.                 ViewGroup.LayoutParams.WRAP_CONTENT,
  1313.                 1
  1314.         ));
  1315.         btnBack.setText("Back");
  1316.         trBtnBack.addView(btnBack);  
  1317.         if(lvAccess.equals("admin")){
  1318.             tlAll.addView(trBtnDeleteAllCourse);
  1319.         }
  1320.         tlAll.addView(trBtnBack);  
  1321.         svShowListCourse.addView(tlAll);  
  1322.         btnDeleteAllCourse.setOnClickListener(new View.OnClickListener() {
  1323.             @Override
  1324.             public void onClick(View v) {
  1325.                 DBAdapter.CourseDbHelper courseDbHelper = new DBAdapter.CourseDbHelper(ShowListCourseActivity.this);
  1326.                 SQLiteDatabase db = courseDbHelper.getReadableDatabase();
  1327.                 db.delete(DBAdapter.CourseEntry.tbName,null,null);
  1328.                 Toast.makeText(
  1329.                         ShowListCourseActivity.this,
  1330.                         "Delete all data course",
  1331.                         Toast.LENGTH_SHORT
  1332.                 ).show();
  1333.                 finish();
  1334.                 startActivity(getIntent());
  1335.             }
  1336.         });  
  1337.         btnBack.setOnClickListener(new View.OnClickListener() {
  1338.             @Override
  1339.             public void onClick(View v) {
  1340.                 ShowListCourseActivity.super.onBackPressed();
  1341.             }
  1342.         });  
  1343.     }
  1344. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement