Guest User

Untitled

a guest
Apr 18th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.09 KB | None | 0 0
  1. package com.example.josep.loginactivity;
  2.  
  3. import android.content.DialogInterface;
  4. import android.content.Intent;
  5. import android.os.Bundle;
  6. import android.support.annotation.NonNull;
  7. import android.support.design.widget.BottomNavigationView;
  8. import android.support.v4.app.Fragment;
  9. import android.support.v4.app.FragmentManager;
  10. import android.support.v4.app.FragmentTransaction;
  11. import android.support.v7.app.AlertDialog;
  12. import android.support.v7.app.AppCompatActivity;
  13. import android.view.MenuItem;
  14. import android.view.View;
  15. import android.widget.AdapterView;
  16. import android.widget.ArrayAdapter;
  17. import android.widget.ListView;
  18. import android.widget.TextView;
  19. import android.widget.Toast;
  20.  
  21. import java.util.ArrayList;
  22. import java.util.Calendar;
  23. import java.util.List;
  24.  
  25. public class Home extends AppCompatActivity {
  26.  
  27.  
  28.  
  29. //private TextView mTextMessage;
  30.  
  31. private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
  32. = new BottomNavigationView.OnNavigationItemSelectedListener() {
  33.  
  34. @Override
  35. public boolean onNavigationItemSelected(@NonNull MenuItem item) {
  36. switch (item.getItemId()) {
  37. case R.id.navigation_home:
  38. setTitle("Pill List");
  39. Intent intent = new Intent(Home.this, PillListActivity.class);
  40. startActivity(intent);
  41. return true;
  42. case R.id.navigation_dashboard:
  43. setTitle("Add a New Pill");
  44. Intent intent2 = new Intent(Home.this, AddPill.class);
  45. startActivity(intent2);
  46. return true;
  47. case R.id.navigation_notifications:
  48. return true;
  49. }
  50. return false;
  51. }
  52. };
  53.  
  54. @Override
  55. protected void onCreate(Bundle savedInstanceState)
  56. {
  57. super.onCreate(savedInstanceState);
  58. setContentView(R.layout.activity_home);
  59.  
  60. //mTextMessage = (TextView) findViewById(R.id.message);
  61. BottomNavigationView navigation = findViewById(R.id.navigation);
  62. navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
  63.  
  64. Calendar calendar = Calendar.getInstance();
  65. int day = calendar.get(Calendar.DAY_OF_WEEK);
  66. int mine;
  67. switch (day) {
  68. case Calendar.SUNDAY:
  69. mine =6;
  70. break;
  71. case Calendar.MONDAY:
  72. mine =0;
  73. break;
  74.  
  75. case Calendar.TUESDAY:
  76. mine=1;
  77. break;
  78.  
  79. case Calendar.WEDNESDAY:
  80. mine=2;
  81. break;
  82.  
  83. case Calendar.THURSDAY:
  84. mine=3;
  85. break;
  86. case Calendar.FRIDAY:
  87. mine=4;
  88. break;
  89.  
  90. case Calendar.SATURDAY:
  91. mine=5;
  92. break;
  93. }
  94. String set = "";
  95.  
  96.  
  97.  
  98. DBhelper dbPill = new DBhelper(this);
  99. List<pillModel> pillList = dbPill.getAllPills();
  100.  
  101. for(pillModel p: pillList)
  102. {
  103. Boolean[]find = p.getDays();
  104. for (int i =0; i<find.length; i++)
  105. if(find[i])
  106. {
  107. set += p.getName() ;
  108. set += " ";
  109. }
  110. }
  111.  
  112. /*
  113.  
  114. AlertDialog.Builder builder = new AlertDialog.Builder(this);
  115. builder.setMessage("today you need to take "+ set);
  116.  
  117. builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
  118. @Override
  119. public void onClick(DialogInterface dialog, int which) {
  120. //perform any action
  121. Toast.makeText(getApplicationContext(), "Thank YOu", Toast.LENGTH_SHORT).show();
  122. }
  123. });
  124.  
  125.  
  126. */
  127. //creating alert dialog
  128. /*AlertDialog alertDialog = builder.create();
  129. alertDialog.show();
  130. */
  131.  
  132.  
  133.  
  134.  
  135. }
  136. }
  137.  
  138. package com.example.josep.loginactivity;
  139.  
  140.  
  141. import android.content.ContentValues;
  142. import android.content.Context;
  143. import android.database.Cursor;
  144. import android.database.sqlite.SQLiteDatabase;
  145. import android.database.sqlite.SQLiteOpenHelper;
  146. import android.view.View;
  147. import android.widget.Toast;
  148.  
  149. import java.util.ArrayList;
  150. import java.util.List;
  151.  
  152. public class DBhelper extends SQLiteOpenHelper {
  153.  
  154.  
  155. // Database Name
  156. private static final String DATABASE_NAME = "motherDB2";
  157. // Database Version
  158. private static final int DATABASE_VERSION = 2;
  159.  
  160. // Table Names
  161. //private static final String TABLE_POLL = "Poll";
  162. //private static final String TABLE_VOTER = "voter";
  163. private static final String TABLE_USER = "user";
  164. private static final String TABLE_PILL = "pill";
  165. // private static final String TABLE_APPT = "appt";
  166.  
  167.  
  168.  
  169. // create Tables for poll, voter, and user
  170. //private static final String CREATE_TABLE_POLL = "CREATE TABLE " + TABLE_POLL+ " (CANDIDATEID INTEGER PRIMARY KEY AUTOINCREMENT, FIRSTNAME TEXT, LASTNAME TEXT, PARTY TEXT, STATE TEXT, ELECTIONYEAR INTEGER)";
  171. //private static final String CREATE_TABLE_VOTER = "CREATE TABLE " + TABLE_VOTER+ " (VOTERID INTEGER PRIMARY KEY AUTOINCREMENT, FIRSTNAME TEXT, LASTNAME TEXT, STATE TEXT, ADDRESS TEXT, ZIPCODE TEXT)";
  172. // private static final String CREATE_TABLE_APPT = "CREATE TABLE " + TABLE_APPT+ " (APPTID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT, EMAIL TEXT, DATE TEXT, COMMENT TEXT)";
  173. private static final String CREATE_TABLE_USER = "CREATE TABLE " + TABLE_USER+ " (USERID INTEGER PRIMARY KEY AUTOINCREMENT, EMAIL TEXT, PASSWORD TEXT)";
  174. private static final String CREATE_TABLE_PILL = "CREATE TABLE " + TABLE_PILL+
  175. " (PILLID INTEGER PRIMARY KEY AUTOINCREMENT, PILL TEXT, DOSE INTEGER, MONDAY BOOLEAN, TUESDAY BOOLEAN, WEDNESDAY BOOLEAN, THURSDAY BOOLEAN, FRIDAY BOOLEAN, SATURDAY BOOLEAN, SUNDAY BOOLEAN, ACTIVE BOOLEAN)";
  176.  
  177. public DBhelper(Context context)
  178. {
  179. super(context, DATABASE_NAME, null, DATABASE_VERSION);
  180. }
  181.  
  182.  
  183.  
  184.  
  185. @Override
  186. public void onCreate(SQLiteDatabase sqLiteDatabase)
  187. {
  188. // creating required tables
  189. //sqLiteDatabase.execSQL(CREATE_TABLE_POLL);
  190. //sqLiteDatabase.execSQL(CREATE_TABLE_VOTER);
  191. sqLiteDatabase.execSQL(CREATE_TABLE_PILL);
  192. sqLiteDatabase.execSQL(CREATE_TABLE_USER);
  193. // sqLiteDatabase.execSQL(CREATE_TABLE_DEAL);
  194. }
  195.  
  196. @Override
  197. public void onUpgrade(SQLiteDatabase sqLiteDatabase, int oldVersion, int newVersion)
  198. {
  199. // on upgrade drop older tables
  200. //sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + TABLE_POLL);
  201. //sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + TABLE_VOTER);
  202. sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + TABLE_USER);
  203. sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + TABLE_PILL);
  204. // sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + TABLE_APPT);
  205. // create new tables
  206. onCreate(sqLiteDatabase);
  207. }
  208.  
  209. // ------------------------ "POLL" table methods ----------------//
  210.  
  211. public boolean insertPill(pillModel pill)
  212. {
  213. SQLiteDatabase db = this.getWritableDatabase();
  214. ContentValues values = new ContentValues();
  215. values.put("PILL", pill.getName());
  216. values.put("DOSE", pill.getDoses());
  217. values.put("MONDAY", pill.isMonday());
  218. values.put("TUESDAY", pill.isTuesday());
  219. values.put("WEDNESDAY", pill.isWednesday());
  220. values.put("THURSDAY", pill.isThursday());
  221. values.put("FRIDAY", pill.isFriday());
  222. values.put("SATURDAY", pill.isSaturday());
  223. values.put("SUNDAY", pill.isSunday());
  224. values.put("ACTIVE", pill.isActive());
  225.  
  226. long result = db.insert(TABLE_PILL, null, values );
  227. if(result == -1)
  228. return false;
  229. else
  230. return true;
  231.  
  232. }
  233.  
  234. public String getPillInfo(pillModel pill){
  235. SQLiteDatabase db = this.getReadableDatabase();
  236. String query = "Select PILL , DOSE, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY,"+
  237. "SATURDAY ,SUNDAY , ACTIVE FROM " + TABLE_PILL ;
  238. Cursor resultSet = db.rawQuery(query, null);
  239. if(resultSet.getCount()== 0)
  240. return null;
  241. else
  242. return query;
  243. }
  244. public List<pillModel> getAllPills()
  245. {
  246. List<pillModel> pillList = new ArrayList<pillModel>();
  247. String selectQuery = "SELECT * FROM " + TABLE_PILL;
  248. SQLiteDatabase db = this.getReadableDatabase();
  249. Cursor resultSet = db.rawQuery(selectQuery, null);
  250. // looping through all rows and adding to list
  251. if (resultSet.moveToFirst())
  252. {
  253. do
  254. {
  255. pillModel pill = new pillModel();
  256. pill.setPillID((resultSet.getInt(resultSet.getColumnIndex("PILLID"))));
  257. pill.setName((resultSet.getString(resultSet.getColumnIndex("PILL"))));
  258. pill.setDoses((resultSet.getInt(resultSet.getColumnIndex("DOSE"))));
  259. pill.setMonday(Boolean.parseBoolean((resultSet.getString(resultSet.getColumnIndex("MONDAY")))));
  260. pill.setTuesday(Boolean.parseBoolean((resultSet.getString(resultSet.getColumnIndex("TUESDAY")))));
  261. pill.setWednesday(Boolean.parseBoolean((resultSet.getString(resultSet.getColumnIndex("WEDNESDAY")))));
  262. pill.setThursday(Boolean.parseBoolean((resultSet.getString(resultSet.getColumnIndex("THURSDAY")))));
  263. pill.setFriday(Boolean.parseBoolean((resultSet.getString(resultSet.getColumnIndex("FRIDAY")))));
  264. pill.setSaturday(Boolean.parseBoolean((resultSet.getString(resultSet.getColumnIndex("SATURDAY")))));
  265. pill.setSunday(Boolean.parseBoolean((resultSet.getString(resultSet.getColumnIndex("SUNDAY")))));
  266. pill.setActive(Boolean.parseBoolean((resultSet.getString(resultSet.getColumnIndex("ACTIVE")))));
  267.  
  268. // adding to poll list
  269. pillList.add(pill);
  270. } while (resultSet.moveToNext());
  271. }
  272. return pillList;
  273. }
  274.  
  275. public boolean insertUser(userModel user)
  276. {
  277. SQLiteDatabase db = this.getWritableDatabase();
  278. ContentValues values = new ContentValues();
  279. values.put("EMAIL", user.getEmail());
  280. values.put("PASSWORD", user.getPass());
  281. long result = db.insert(TABLE_USER, null, values );
  282. if(result == -1)
  283. return false;
  284. else
  285. return true;
  286.  
  287. }
  288. public Boolean getLoginInfo(userModel user){
  289. SQLiteDatabase db = this.getReadableDatabase();
  290. String query = "Select EMAIL, PASSWORD FROM " + TABLE_USER + " WHERE EMAIL = '"+user.getEmail() +"' AND PASSWORD= '"+user.getPass()+"'";
  291. Cursor resultSet = db.rawQuery(query, null);
  292. if(resultSet.getCount()== 0)
  293. return false;
  294. else
  295. return true;
  296. }
  297. public String getDose(String pill)
  298. {
  299. String query = "Select PILL FROM " + TABLE_PILL + " WHERE PILL = '"+pill +"'";
  300. return query;
  301. }
  302. public void addDose(String pill){
  303. SQLiteDatabase db = this.getWritableDatabase();
  304. String dose = "Select DOSE FROM " + TABLE_PILL + " WHERE PILL = '"+pill +"'";
  305. int house = Integer.parseInt(dose);
  306. house+=1;
  307. String mind =""+house;
  308. String query = "Update DOSE FROM " + TABLE_PILL + " SET DOSE = '"+mind +"'";
  309.  
  310. }
  311.  
  312. public void romoveDose(String pill){
  313. SQLiteDatabase db = this.getWritableDatabase();
  314. String dose = "Select DOSE FROM " + TABLE_PILL + " WHERE PILL = '"+pill +"'";
  315. int house = Integer.parseInt(dose);
  316. house-=1;
  317. String mind =""+house;
  318. String query = "Update " + TABLE_PILL + " SET DOSE = '"+mind +"'";
  319. //db.update("Update"+TABLE_PILL+ " SET DOSE="+ mind + "WHERE PILL="+pill);
  320. }
  321. }
  322.  
  323. package com.example.josep.loginactivity;
  324.  
  325. public class pillModel {
  326.  
  327.  
  328. private String name;
  329. private int Doses;
  330. private int pillID;
  331. private boolean monday;
  332. private boolean tuesday;
  333. private boolean wednesday;
  334. private boolean thursday;
  335. private boolean friday;
  336. private boolean saturday;
  337. private boolean sunday;
  338. private boolean active;
  339.  
  340. public void setPillID(int id)
  341. {
  342. this.pillID = id;
  343. }
  344. public int getpillID()
  345. {
  346. return pillID;
  347. }
  348.  
  349. public void setName(String name)
  350. {
  351. this.name = name;
  352. }
  353.  
  354. public String getName()
  355. {
  356. return name;
  357. }
  358.  
  359. public void setDoses(int Doeses)
  360. {
  361. this.Doses = Doses;
  362. }
  363.  
  364. public Integer getDoses()
  365. {
  366. return Doses;
  367. }
  368.  
  369. public boolean isActive() {
  370. return active;
  371. }
  372.  
  373. public void setActive(boolean active) {
  374. this.active = active;
  375. }
  376.  
  377. public boolean isSunday() {
  378. return sunday;
  379. }
  380.  
  381. public void setSunday(boolean sunday) {
  382. this.sunday = sunday;
  383. }
  384.  
  385. public boolean isSaturday() {
  386. return saturday;
  387. }
  388.  
  389. public void setSaturday(boolean saturday) {
  390. this.saturday = saturday;
  391. }
  392.  
  393. public boolean isFriday() {
  394. return friday;
  395. }
  396.  
  397. public void setFriday(boolean friday) {
  398. this.friday = friday;
  399. }
  400.  
  401. public boolean isThursday() {
  402. return thursday;
  403. }
  404.  
  405. public void setThursday(boolean thursday) {
  406. this.thursday = thursday;
  407. }
  408.  
  409. public boolean isWednesday() {
  410. return wednesday;
  411. }
  412.  
  413. public void setWednesday(boolean wednesday) {
  414. this.wednesday = wednesday;
  415. }
  416.  
  417. public boolean isTuesday() {
  418. return tuesday;
  419. }
  420.  
  421. public void setTuesday(boolean tuesday) {
  422. this.tuesday = tuesday;
  423. }
  424.  
  425. public boolean isMonday() {
  426. return monday;
  427. }
  428.  
  429. public void setMonday(boolean monday) {
  430. this.monday = monday;
  431. }
  432.  
  433. public Boolean[] getDays()
  434. {
  435. Boolean[]Days =new Boolean[6];
  436. String house = getName();
  437. if(isActive() && isMonday())
  438. {
  439. Days[0]=true;
  440.  
  441. }
  442. if(isActive() && isTuesday())
  443. {
  444. Days[1]=true;
  445.  
  446. }
  447. if(isActive() && isWednesday())
  448. {
  449. Days[2]=true;
  450.  
  451. }
  452. if(isActive() && isThursday())
  453. {
  454. Days[3]=true;
  455. }
  456. if(isActive() && isFriday())
  457. {
  458. Days[4]=true;
  459.  
  460. }
  461. if(isActive() && isSaturday())
  462. {
  463. Days[5]=true;
  464.  
  465. }
  466. if(isActive() && isSunday())
  467. {
  468. Days[6]=true;
  469.  
  470. }
  471. return Days;
  472. }
  473.  
  474. public pillModel() {
  475.  
  476. }
  477.  
  478. public pillModel(String name, int Doses, boolean monday, boolean tuesday, boolean wednesday, boolean thursday,
  479. boolean friday, boolean saturday, boolean sunday, boolean active) {
  480.  
  481. this.name = name;
  482. this.Doses = Doses;
  483. this.monday = monday;
  484. this.tuesday = tuesday;
  485. this.wednesday = wednesday;
  486. this.thursday = thursday;
  487. this.friday = friday;
  488. this.saturday = saturday;
  489. this.sunday = sunday;
  490. this.active = active;
  491. }
  492. }
Add Comment
Please, Sign In to add comment