Add original project.
This commit is contained in:
1 parent
b3c2fb7e6a
commit
e02d5ef761
66 files changed
+3195
No files matched your search
+573
@@ -0,0 +1,573 @@
|
||||
package com.hyperling.carbupbeta;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.SQLException;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Created by usb on 12/24/14.
|
||||
*/
|
||||
|
||||
// Database And ListItem Helper
|
||||
public class DALIH extends SQLiteOpenHelper{
|
||||
public final boolean DEBUG = false;
|
||||
|
||||
// SQL objects
|
||||
private static final String DB_NAME = "CARBUP.db";
|
||||
|
||||
private static final String list_table = "list"; // Saved List Table name (EX: 01, Schnuck's beans)
|
||||
private static final String item_table = "item"; // Saved Item Table name (EG: 01, red beans, 70 carbs, 200 calories, etc)
|
||||
private static final String setting_table = "settings";
|
||||
|
||||
private static final String list_id_col = "list_id";
|
||||
private static final String list_name_col = "list_name";
|
||||
|
||||
private static final String item_id_col = "item_id";
|
||||
private static final String item_name_col = "item_name";
|
||||
private static final String item_cost_col = "cost";
|
||||
private static final String item_servings_col = "servings";
|
||||
private static final String item_calories_col = "calories";
|
||||
private static final String item_carbs_col = "carbs";
|
||||
private static final String item_fiber_col = "fiber";
|
||||
private static final String item_list_id_col = list_id_col;
|
||||
|
||||
private static final String setting_last_list_col = "last_list";
|
||||
private static final String setting_last_item_col = "last_item";
|
||||
private static final String setting_ads_enabled_col = "ads_enabled";
|
||||
private static final String setting_quick_load_col = "quick_load";
|
||||
private static final String setting_open_tab_col = "open_tab";
|
||||
private static final int settings_total = 5;
|
||||
private static final int setting_last_list_index = 0;
|
||||
private static final int setting_last_item_index = 1;
|
||||
private static final int setting_ads_enabled_index = 2;
|
||||
private static final int setting_quick_load_index = 3;
|
||||
private static final int setting_open_tab_index = 4;
|
||||
private static final int setting_last_list_default = -1;
|
||||
private static final int setting_last_item_default = -1;
|
||||
private static final int setting_ads_enabled_default = 1;
|
||||
private static final int setting_quick_load_default = 0;
|
||||
private static final int setting_open_tab_default = 1;
|
||||
|
||||
private static final String CREATESLTABLE = "CREATE TABLE " + list_table + "(" +
|
||||
list_id_col + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
|
||||
list_name_col + " TEXT NOT NULL" +
|
||||
"); ";
|
||||
|
||||
private static final String CREATESITABLE = "" +
|
||||
"CREATE TABLE " + item_table + "( " +
|
||||
item_id_col + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
|
||||
item_name_col + " TEXT NOT NULL, " +
|
||||
item_cost_col + " REAL NOT NULL, " +
|
||||
item_servings_col + " REAL NOT NULL, " +
|
||||
item_calories_col + " REAL NOT NULL, " +
|
||||
item_carbs_col + " REAL NOT NULL, " +
|
||||
item_fiber_col + " REAL DEFAULT 0, " +
|
||||
item_list_id_col + " INTEGER NOT NULL, " +
|
||||
"FOREIGN KEY (" + item_list_id_col + ") REFERENCES " + list_table + "(" + list_id_col + ") ON DELETE CASCADE" +
|
||||
"); ";
|
||||
|
||||
private static final String CREATESETTINGTABLE = "" +
|
||||
"CREATE TABLE " + setting_table + "( " +
|
||||
" " + setting_last_list_col + " INTEGER NOT NULL, " +
|
||||
" " + setting_last_item_col + " INTEGER NOT NULL, " +
|
||||
" " + setting_ads_enabled_col + " INTEGER NOT NULL, " +
|
||||
" " + setting_quick_load_col + " INTEGER NOT NULL, " +
|
||||
" " + setting_open_tab_col + " INTEGER NOT NULL " +
|
||||
"); ";
|
||||
|
||||
|
||||
SQLiteDatabase db;
|
||||
|
||||
public DALIH(Context context){
|
||||
//4, add fiber column to list_item
|
||||
super(context, DB_NAME, null, 4);
|
||||
return;
|
||||
}
|
||||
|
||||
// Open the database
|
||||
public void open() throws SQLException{
|
||||
if (DEBUG) System.out.println("Opening DB");
|
||||
|
||||
db = getWritableDatabase();
|
||||
return;
|
||||
}
|
||||
|
||||
// Close the database
|
||||
public void close(){
|
||||
if (DEBUG) System.out.println("Closing DB");
|
||||
|
||||
super.close();
|
||||
return;
|
||||
}
|
||||
|
||||
// Insert a ListItem into the DB
|
||||
public void insertItem(ListItemInfo listItem){
|
||||
if (DEBUG) System.out.println("Inserting item: " + listItem.getID() + " " + listItem.getName());
|
||||
|
||||
String query = "" +
|
||||
"INSERT INTO "+item_table+"("+item_name_col+", "+item_cost_col+", "+item_calories_col+", " +
|
||||
" "+item_carbs_col+", "+item_servings_col+", "+item_list_id_col+", " +
|
||||
" "+item_fiber_col+") " +
|
||||
"VALUES(\""+listItem.getName()+"\", "+listItem.getCost()+", "+listItem.getCalories()+", " +
|
||||
" "+listItem.getCarbs()+", "+listItem.getServings()+", "+listItem.getListID() + ", " +
|
||||
" "+listItem.getFiber()+"); ";
|
||||
|
||||
doQuery(query);
|
||||
return;
|
||||
}
|
||||
|
||||
public void updateItem(ListItemInfo listItem){
|
||||
if (DEBUG) System.out.println("Updating item: " + listItem.getID() + " " + listItem.getName());
|
||||
|
||||
String query = "" +
|
||||
"UPDATE "+item_table+" " +
|
||||
" SET "+item_name_col+" = \""+listItem.getName()+"\", " +
|
||||
" "+item_cost_col+" = "+listItem.getCost()+", " +
|
||||
" "+item_calories_col+" = "+listItem.getCalories()+", " +
|
||||
" "+item_carbs_col+" = "+listItem.getCarbs()+", " +
|
||||
" "+item_servings_col+" = "+listItem.getServings()+", " +
|
||||
" "+item_fiber_col+" = "+listItem.getFiber()+", " +
|
||||
" "+item_list_id_col+" = "+listItem.getListID()+" " +
|
||||
" WHERE "+item_id_col+" = "+listItem.getID() + "; ";
|
||||
|
||||
doQuery(query);
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove a ListItem from the DB
|
||||
public void deleteItem(ListItemInfo listItem){
|
||||
if (DEBUG) System.out.println("Deleting item: " + listItem.getID() + " " + listItem.getName());
|
||||
|
||||
String query = "" +
|
||||
"DELETE FROM "+item_table+" " +
|
||||
" WHERE "+item_id_col+" = "+listItem.getID() + "; ";
|
||||
|
||||
doQuery(query);
|
||||
return;
|
||||
}
|
||||
|
||||
// This method will give tab2 current List's items to sort through
|
||||
public ArrayList<ListItemInfo> getItems(int list_id){
|
||||
ArrayList<ListItemInfo> items = new ArrayList<ListItemInfo>();
|
||||
|
||||
String query = "" +
|
||||
"SELECT "+item_id_col+", " +
|
||||
" "+item_name_col+", " +
|
||||
" "+item_cost_col+", " +
|
||||
" "+item_servings_col+", " +
|
||||
" "+item_calories_col+", " +
|
||||
" "+item_carbs_col+", " +
|
||||
" "+item_fiber_col+", " +
|
||||
" "+item_list_id_col+" " +
|
||||
" FROM "+item_table+" " +
|
||||
" WHERE "+item_list_id_col+" = "+list_id+"; ";
|
||||
|
||||
if (DEBUG) System.out.println("Getting all items\n" + query);
|
||||
|
||||
Cursor c = db.rawQuery(query, null);
|
||||
|
||||
if (DEBUG) System.out.println("Cursor size: " + c.getCount());
|
||||
|
||||
c.moveToFirst();
|
||||
while(!c.isAfterLast()){
|
||||
ListItemInfo temp = new ListItemInfo();
|
||||
|
||||
temp.setID(c.getInt(0));
|
||||
temp.setName(c.getString(1));
|
||||
temp.setCost(c.getDouble(2));
|
||||
temp.setServings(c.getDouble(3));
|
||||
temp.setCalories(c.getDouble(4));
|
||||
temp.setCarbs(c.getDouble(5));
|
||||
temp.setFiber(c.getDouble(6));
|
||||
temp.setListID(c.getInt(7));
|
||||
|
||||
items.add(temp);
|
||||
c.moveToNext();
|
||||
}
|
||||
c.close();
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
public void insertList(ListInfo list){
|
||||
if (DEBUG) System.out.println("Inserting list: " + list.getID() + " " + list.getName());
|
||||
|
||||
String query = "" +
|
||||
"INSERT INTO "+list_table+"("+list_name_col+") " +
|
||||
"VALUES(\""+list.getName()+"\"); ";
|
||||
|
||||
doQuery(query);
|
||||
return;
|
||||
}
|
||||
|
||||
public void updateList(ListInfo list){
|
||||
if (DEBUG) System.out.println("Updating list: " + list.getID() + " " + list.getName());
|
||||
|
||||
String query = "" +
|
||||
"UPDATE "+list_table+" " +
|
||||
" SET "+list_name_col+" = \""+list.getName()+"\" " +
|
||||
" WHERE "+list_id_col+" = "+list.getID()+"; ";
|
||||
|
||||
doQuery(query);
|
||||
return;
|
||||
}
|
||||
|
||||
public void deleteList(ListInfo list){
|
||||
if (DEBUG) System.out.println("Deleting list: " + list.getID() + " " + list.getName());
|
||||
|
||||
String query = "" +
|
||||
"DELETE FROM "+list_table+" " +
|
||||
" WHERE "+list_id_col+" = "+list.getID()+"; ";
|
||||
|
||||
doQuery(query);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
public ArrayList<ListInfo> getLists(){
|
||||
// Return ALL lists in an ArrayList
|
||||
ArrayList<ListInfo> lists = new ArrayList<ListInfo>();
|
||||
|
||||
String query = "" +
|
||||
"SELECT "+list_id_col+", " +
|
||||
" "+list_name_col+" " +
|
||||
" FROM "+list_table+"; ";
|
||||
|
||||
if (DEBUG) System.out.println("Getting all lists\n" + query);
|
||||
|
||||
Cursor c = db.rawQuery(query, null);
|
||||
|
||||
if (DEBUG) System.out.println("Cursor size: " + c.getCount());
|
||||
|
||||
c.moveToFirst();
|
||||
while(!c.isAfterLast()){
|
||||
ListInfo temp = new ListInfo();
|
||||
|
||||
temp.setID(c.getInt(0));
|
||||
temp.setName(c.getString(1));
|
||||
|
||||
lists.add(temp);
|
||||
|
||||
c.moveToNext();
|
||||
}
|
||||
c.close();
|
||||
|
||||
return lists;
|
||||
}
|
||||
|
||||
private void setSettings(int[] settings){
|
||||
if (DEBUG) System.out.println("Setting settings");
|
||||
|
||||
int last_list = settings[getLastListIndex()];
|
||||
int last_item = settings[getLastItemIndex()];
|
||||
int ads_enabled = settings[getAdsEnabledIndex()];
|
||||
int quick_load = settings[getQuickLoadIndex()];
|
||||
int open_tab = settings[getOpenTabIndex()];
|
||||
String query = "" +
|
||||
"UPDATE "+setting_table+"" +
|
||||
" SET "+setting_last_list_col+" = "+last_list+", " +
|
||||
" "+setting_last_item_col+" = "+last_item+", " +
|
||||
" "+setting_ads_enabled_col+" = "+ads_enabled+", " +
|
||||
" "+setting_quick_load_col+" = "+quick_load+", " +
|
||||
" "+setting_open_tab_col+" = "+open_tab+"; ";
|
||||
|
||||
doQuery(query);
|
||||
return;
|
||||
}
|
||||
|
||||
private int[] getSettings(){
|
||||
if (DEBUG) System.out.println("Getting settings");
|
||||
|
||||
String query = "" +
|
||||
"SELECT "+setting_last_list_col+", " +
|
||||
" "+setting_last_item_col+", " +
|
||||
" "+setting_ads_enabled_col+", " +
|
||||
" "+setting_quick_load_col+", " +
|
||||
" "+setting_open_tab_col+" " +
|
||||
" FROM "+setting_table+"; ";
|
||||
|
||||
int[] settings = null;
|
||||
Cursor c = db.rawQuery(query, null);
|
||||
|
||||
if (DEBUG) System.out.println("Cursor size: " + c.getCount());
|
||||
|
||||
if (c.getCount() == 0){
|
||||
setDefaults();
|
||||
|
||||
settings = new int[settings_total];
|
||||
settings[getLastListIndex()] = setting_last_list_default;
|
||||
settings[getLastItemIndex()] = setting_last_item_default;
|
||||
settings[getAdsEnabledIndex()] = setting_ads_enabled_default;
|
||||
settings[getQuickLoadIndex()] = setting_quick_load_default;
|
||||
settings[getOpenTabIndex()] = setting_open_tab_default;
|
||||
}
|
||||
else {
|
||||
if (DEBUG) System.out.println("Reading settings\n" + query);
|
||||
|
||||
c.moveToFirst();
|
||||
while (!c.isAfterLast()) {
|
||||
settings = new int[settings_total];
|
||||
settings[getLastListIndex()] = c.getInt(0);
|
||||
settings[getLastItemIndex()] = c.getInt(1);
|
||||
settings[getAdsEnabledIndex()] = c.getInt(2);
|
||||
settings[getQuickLoadIndex()] = c.getInt(3);
|
||||
settings[getOpenTabIndex()] = c.getInt(4);
|
||||
c.moveToNext();
|
||||
}
|
||||
}
|
||||
c.close();
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
||||
private void setDefaults(){
|
||||
if (DEBUG) System.out.println("Setting default settings");
|
||||
|
||||
String query = "" +
|
||||
"INSERT INTO " + setting_table + "("+setting_last_list_col+", "+setting_last_item_col+", " +
|
||||
" "+setting_ads_enabled_col+", "+setting_quick_load_col+", " +
|
||||
" "+setting_open_tab_col+") " +
|
||||
"VALUES("+setting_last_list_default+", "+setting_last_item_default+", " +
|
||||
" "+setting_ads_enabled_default+", "+setting_quick_load_default+", " +
|
||||
" "+setting_open_tab_default+"); ";
|
||||
|
||||
doQuery(query);
|
||||
return;
|
||||
}
|
||||
|
||||
private int getLastListIndex(){
|
||||
if (DEBUG) System.out.println("Getting last list index");
|
||||
|
||||
return setting_last_list_index;
|
||||
}
|
||||
|
||||
private int getLastItemIndex(){
|
||||
if (DEBUG) System.out.println("Getting last item index");
|
||||
|
||||
return setting_last_item_index;
|
||||
}
|
||||
|
||||
private int getAdsEnabledIndex(){
|
||||
if (DEBUG) System.out.println("Getting ads enabled index");
|
||||
|
||||
return setting_ads_enabled_index;
|
||||
}
|
||||
|
||||
private int getQuickLoadIndex(){
|
||||
if (DEBUG) System.out.println("Getting quick load index");
|
||||
|
||||
return setting_quick_load_index;
|
||||
}
|
||||
|
||||
private int getOpenTabIndex(){
|
||||
if (DEBUG) System.out.println("Getting open tab index");
|
||||
|
||||
return setting_open_tab_index;
|
||||
}
|
||||
|
||||
public int getLastList(){
|
||||
if (DEBUG) System.out.println("Getting last list");
|
||||
|
||||
int[] settings = getSettings();
|
||||
|
||||
return settings[getLastListIndex()];
|
||||
}
|
||||
|
||||
public void setLastList(int lastList){
|
||||
if (DEBUG) System.out.println("Setting last list to " + lastList);
|
||||
|
||||
int[] settings = getSettings();
|
||||
|
||||
settings[getLastListIndex()] = lastList;
|
||||
|
||||
setSettings(settings);
|
||||
return;
|
||||
}
|
||||
|
||||
public void setLastList(){
|
||||
if (DEBUG) System.out.println("Setting last list to default, " + setting_last_list_default);
|
||||
|
||||
int[] settings = getSettings();
|
||||
|
||||
settings[getLastListIndex()] = setting_last_list_default;
|
||||
|
||||
setSettings(settings);
|
||||
return;
|
||||
}
|
||||
|
||||
public int getLastItem(){
|
||||
if (DEBUG) System.out.println("Getting last item");
|
||||
|
||||
int[] settings = getSettings();
|
||||
|
||||
return settings[getLastItemIndex()];
|
||||
}
|
||||
|
||||
public void setLastItem(int lastItem){
|
||||
if (DEBUG) System.out.println("Setting last item to " + lastItem);
|
||||
|
||||
int[] settings = getSettings();
|
||||
|
||||
settings[getLastItemIndex()] = lastItem;
|
||||
|
||||
setSettings(settings);
|
||||
return;
|
||||
}
|
||||
|
||||
public void setLastItem(){
|
||||
if (DEBUG) System.out.println("Setting last item to default, " + setting_last_item_default);
|
||||
|
||||
int[] settings = getSettings();
|
||||
|
||||
settings[getLastItemIndex()] = setting_last_item_default;
|
||||
|
||||
setSettings(settings);
|
||||
return;
|
||||
}
|
||||
|
||||
public boolean getAdsEnabled(){
|
||||
if (DEBUG) System.out.println("Getting ads enabled");
|
||||
|
||||
int[] settings = getSettings();
|
||||
|
||||
return (settings[getAdsEnabledIndex()] > 0);
|
||||
}
|
||||
|
||||
public void setAdsEnabled(boolean adsEnabled){
|
||||
if (DEBUG) System.out.println("Setting ads enabled to " + adsEnabled);
|
||||
|
||||
int[] settings = getSettings();
|
||||
|
||||
int setting;
|
||||
if (adsEnabled){
|
||||
setting = 1;
|
||||
}
|
||||
else{
|
||||
setting = 0;
|
||||
}
|
||||
|
||||
settings[getAdsEnabledIndex()] = setting;
|
||||
|
||||
setSettings(settings);
|
||||
return;
|
||||
}
|
||||
|
||||
public boolean getQuickLoad(){
|
||||
if (DEBUG) System.out.println("Getting quick load");
|
||||
|
||||
int[] settings = getSettings();
|
||||
|
||||
return (settings[getQuickLoadIndex()] > 0);
|
||||
}
|
||||
|
||||
public void setQuickLoad(boolean quickLoad){
|
||||
if (DEBUG) System.out.println("Setting quick load to " + quickLoad);
|
||||
|
||||
int[] settings = getSettings();
|
||||
|
||||
int setting;
|
||||
if (quickLoad){
|
||||
setting = 1;
|
||||
}
|
||||
else{
|
||||
setting = 0;
|
||||
}
|
||||
|
||||
settings[getQuickLoadIndex()] = setting;
|
||||
|
||||
setSettings(settings);
|
||||
return;
|
||||
}
|
||||
|
||||
public int getOpenTab(){
|
||||
if (DEBUG) System.out.println("Getting quick load");
|
||||
|
||||
int[] settings = getSettings();
|
||||
|
||||
return settings[getOpenTabIndex()];
|
||||
}
|
||||
|
||||
public void setOpenTab(int tab){
|
||||
if (DEBUG) System.out.println("Setting open tab to " + tab);
|
||||
|
||||
int[] settings = getSettings();
|
||||
|
||||
settings[getOpenTabIndex()] = tab;
|
||||
|
||||
setSettings(settings);
|
||||
return;
|
||||
}
|
||||
|
||||
private void doQuery(String query){
|
||||
if (DEBUG) System.out.println("Executing SQL:\n" + query);
|
||||
|
||||
db.execSQL(query);
|
||||
return;
|
||||
}
|
||||
|
||||
public String filterString(String input){
|
||||
if (DEBUG) System.out.println("Filtering string: " + input);
|
||||
String output = input.trim().replace("\"","").replace("\n", "").replace("\b", "").replace("\t", "");
|
||||
while(output.contains(" ")){
|
||||
if (DEBUG) System.out.println("In the space killer loop: " + output);
|
||||
output = output.replace(" ", " ");
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
private void printDML(){
|
||||
System.out.println();
|
||||
System.out.println(CREATESLTABLE);
|
||||
System.out.println();
|
||||
System.out.println(CREATESITABLE);
|
||||
System.out.println();
|
||||
System.out.println(CREATESETTINGTABLE);
|
||||
System.out.println();
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(SQLiteDatabase database) {
|
||||
if (DEBUG){
|
||||
System.out.println("Creating the DB");
|
||||
printDML();
|
||||
}
|
||||
|
||||
database.execSQL(CREATESLTABLE);
|
||||
database.execSQL(CREATESITABLE);
|
||||
database.execSQL(CREATESETTINGTABLE);
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion) {
|
||||
if (DEBUG) System.out.println("Upgrading the DB");
|
||||
|
||||
switch(oldVersion){
|
||||
case 2:
|
||||
if (DEBUG) System.out.println("UPGRADING TO DBv3");
|
||||
String DBv3 = "" +
|
||||
" ALTER TABLE "+setting_table+" " +
|
||||
" ADD "+setting_open_tab_col+" INTEGER; " +
|
||||
"" +
|
||||
"UPDATE TABLE "+setting_table+" " +
|
||||
" SET "+setting_open_tab_col+" = "+setting_open_tab_default+"; " +
|
||||
"" +
|
||||
" ALTER TABLE "+setting_table+" " +
|
||||
" ALTER COLUMN "+setting_open_tab_col+" INTEGER NOT NULL; ";
|
||||
database.execSQL(DBv3);
|
||||
case 3:
|
||||
if (DEBUG) System.out.println("UPGRADING TO DBv4");
|
||||
String DBv4 = "" +
|
||||
" ALTER TABLE "+item_table+" " +
|
||||
" ADD "+item_fiber_col+" REAL DEFAULT 0; ";
|
||||
database.execSQL(DBv4);
|
||||
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
package com.hyperling.carbupbeta;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.app.Activity;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.android.gms.ads.AdRequest;
|
||||
import com.google.android.gms.ads.AdView;
|
||||
|
||||
public class Home extends AppCompatActivity {
|
||||
|
||||
Resources recs;
|
||||
|
||||
Button btnCarbCalc, btnCalcHelp, btnWhyHCLF, btnWhyVegan;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_home);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Set up variables
|
||||
recs = getResources();
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Set up views
|
||||
btnCarbCalc = (Button) findViewById(R.id.btnCarbCalc);
|
||||
btnCalcHelp = (Button) findViewById(R.id.btnCalcHelp);
|
||||
btnWhyHCLF = (Button) findViewById(R.id.btnWhyHCLF);
|
||||
btnWhyVegan = (Button) findViewById(R.id.btnWhyVegan);
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Set up button click listeners
|
||||
btnCarbCalc.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
startActivity(new Intent(Home.this, Main.class));
|
||||
}
|
||||
});
|
||||
|
||||
btnCalcHelp = (Button) findViewById(R.id.btnCalcHelp);
|
||||
|
||||
btnWhyHCLF = (Button) findViewById(R.id.btnWhyHCLF);
|
||||
|
||||
btnWhyVegan = (Button) findViewById(R.id.btnWhyVegan);
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Finally, load ads >:)
|
||||
if (Build.VERSION.SDK_INT >= 9) {
|
||||
// Load an ad into the AdMob banner view.
|
||||
AdView adView = (AdView) findViewById(R.id.adViewHome);
|
||||
AdRequest adRequest = new AdRequest.Builder()
|
||||
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
|
||||
.addTestDevice("C6A494DC6E7C9AC29102694D48487084") // nexus 7
|
||||
.addTestDevice("B8B7561B850A9AB24E0D5B560FC50628") // Moto G
|
||||
.addTestDevice("") // Cappy, even though it doesn't support ads
|
||||
.setRequestAgent("android_studio:ad_template")
|
||||
.build();
|
||||
adView.loadAd(adRequest);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
getMenuInflater().inflate(R.menu.menu_home, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
// Handle action bar item clicks here. The action bar will
|
||||
// automatically handle clicks on the Home/Up button, so long
|
||||
// as you specify a parent activity in AndroidManifest.xml.
|
||||
int id = item.getItemId();
|
||||
|
||||
if (id == R.id.action_exit) {
|
||||
finish();
|
||||
return false;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
}
|
||||
+125
@@ -0,0 +1,125 @@
|
||||
package com.hyperling.carbupbeta;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.LinearLayout.LayoutParams;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Button;
|
||||
|
||||
/**
|
||||
* Created by ling on 12/31/15.
|
||||
*/
|
||||
public class List extends ListInfo{
|
||||
|
||||
LinearLayout linearLayout;
|
||||
Button btnDelete, btnEdit, btnItem;
|
||||
|
||||
private DALIH dalih;
|
||||
|
||||
private int textSize;
|
||||
|
||||
public List(Context context, ListInfo listInfo){
|
||||
// Set attributes
|
||||
setID(listInfo.getID());
|
||||
|
||||
dalih = new DALIH(context);
|
||||
|
||||
// Instantiate the Views
|
||||
linearLayout = new LinearLayout(context);
|
||||
btnDelete = new Button(context);
|
||||
btnEdit = new Button(context);
|
||||
btnItem = new Button(context);
|
||||
|
||||
// Give the views their required attributes (Wrap Content)
|
||||
LinearLayout.LayoutParams lay_lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
|
||||
LinearLayout.LayoutParams delete_lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
|
||||
LinearLayout.LayoutParams edit_lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
|
||||
LinearLayout.LayoutParams item_lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
|
||||
|
||||
lay_lp.setMargins(1, 1, 1, 1);
|
||||
linearLayout.setLayoutParams(lay_lp);
|
||||
linearLayout.setPadding(1, 1, 1, 1);
|
||||
|
||||
delete_lp.setMargins(1, 1, 1, 1);
|
||||
btnDelete.setLayoutParams(delete_lp);
|
||||
|
||||
edit_lp.setMargins(1, 1, 1, 1);
|
||||
btnEdit.setLayoutParams(edit_lp);
|
||||
|
||||
item_lp.setMargins(1, 1, 1, 1);
|
||||
btnItem.setLayoutParams(item_lp);
|
||||
|
||||
// Add the values to the buttons
|
||||
btnDelete.setText(R.string.delete_button); // TODO: Make this an image
|
||||
btnEdit.setText(R.string.edit_button); // TODO: Make this a pencil image
|
||||
setName(listInfo.getName());
|
||||
|
||||
// ========== Style the buttons ==========
|
||||
// Color!
|
||||
linearLayout.setBackgroundColor(Color.BLACK);
|
||||
btnDelete.setBackgroundColor(Color.LTGRAY);
|
||||
btnDelete.setTextColor(Color.BLACK);
|
||||
btnEdit.setBackgroundColor(Color.LTGRAY);
|
||||
btnEdit.setTextColor(Color.BLACK);
|
||||
btnItem.setBackgroundColor(Color.WHITE);
|
||||
btnItem.setTextColor(getRandomColor());
|
||||
// Size!
|
||||
//textSize = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getWidth()/30;
|
||||
btnDelete.setTextSize(16); //textSize-10);
|
||||
btnEdit.setTextSize(16); //textSize-10);
|
||||
btnItem.setTextSize(18); //textSize-6);
|
||||
|
||||
// Add the buttons to the layout!
|
||||
linearLayout.addView(btnDelete);
|
||||
linearLayout.addView(btnEdit);
|
||||
linearLayout.addView(btnItem);
|
||||
}
|
||||
|
||||
public LinearLayout getView(){
|
||||
return linearLayout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String name){
|
||||
super.setName(name);
|
||||
btnItem.setText(getName());
|
||||
}
|
||||
|
||||
public int getRandomColor(){
|
||||
// Make negative to turn feature off
|
||||
int choice = (int) (Math.random()*12); // Highest case + 2 includes default
|
||||
|
||||
//if (dalih.DEBUG) System.out.println(getName() + " is color " + choice);
|
||||
|
||||
switch(choice){
|
||||
// Random assortment of colors
|
||||
case 0: return Color.rgb(250, 0, 0); // red
|
||||
case 1: return Color.rgb(250, 150, 0); // orange
|
||||
case 2: return Color.rgb(200, 200, 0); // yellow
|
||||
case 3: return Color.rgb(0, 250, 0); // green
|
||||
case 4: return Color.rgb(0, 150, 250); // aqua
|
||||
case 5: return Color.rgb(0, 0, 250); // blue
|
||||
case 6: return Color.rgb(150, 0, 250); // soft purple
|
||||
case 7: return Color.rgb(200, 0, 200); // purple
|
||||
|
||||
// Unused colors
|
||||
//case 8: return Color.rgb(0, 250, 250); // cyan
|
||||
case 9: return Color.rgb(125, 250, 0); // lime
|
||||
case 10: return Color.rgb(0, 250, 125); // turqoise?
|
||||
case 11: return Color.rgb(250, 0, 125); // magenta
|
||||
|
||||
// Shades of grey
|
||||
//case 12: return Color.rgb(200, 200, 200); // light grey
|
||||
case 8: return Color.rgb(100, 100, 100); // dark grey
|
||||
|
||||
// Possible theme?
|
||||
case 69: return Color.rgb(250, 250, 0); // yellow
|
||||
case 70: return Color.rgb(125, 0, 250); // purple
|
||||
|
||||
// Catch
|
||||
default: return Color.BLACK;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.hyperling.carbupbeta;
|
||||
|
||||
/**
|
||||
* Created by ling on 12/31/15.
|
||||
*/
|
||||
public class ListInfo {
|
||||
|
||||
private String name;
|
||||
private int ID;
|
||||
|
||||
public String getName(){
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getID() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
public void setID(int ID) {
|
||||
this.ID = ID;
|
||||
}
|
||||
}
|
||||
+151
@@ -0,0 +1,151 @@
|
||||
package com.hyperling.carbupbeta;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.widget.LinearLayout;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.LinearLayout.LayoutParams;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
/**
|
||||
* Created by usb on 9/28/14.
|
||||
*/
|
||||
public class ListItem extends ListItemInfo {
|
||||
|
||||
private double calPerDol, carbPerCal;
|
||||
|
||||
LinearLayout linearLayout;
|
||||
Button btnDelete, btnEdit, btnItem;
|
||||
|
||||
private int textSize;
|
||||
|
||||
public ListItem(Context context, ListItemInfo listItemInfo){
|
||||
|
||||
// Instantiate the Views
|
||||
linearLayout = new LinearLayout(context);
|
||||
btnDelete = new Button(context);
|
||||
btnEdit = new Button(context);
|
||||
btnItem = new Button(context);
|
||||
|
||||
setID(listItemInfo.getID());
|
||||
setName(listItemInfo.getName());
|
||||
setCost(listItemInfo.getCost());
|
||||
setServings(listItemInfo.getServings());
|
||||
setCalories(listItemInfo.getCalories());
|
||||
setCarbs(listItemInfo.getCarbs());
|
||||
setFiber(listItemInfo.getFiber());
|
||||
calPerDol = getCalPerDol();
|
||||
carbPerCal = getCarbPerCal();
|
||||
|
||||
// Give the views their required attributes (Wrap Content)
|
||||
LinearLayout.LayoutParams lay_lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
|
||||
LinearLayout.LayoutParams delete_lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
|
||||
LinearLayout.LayoutParams edit_lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
|
||||
LinearLayout.LayoutParams item_lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
|
||||
|
||||
lay_lp.setMargins(1, 1, 1, 1);
|
||||
linearLayout.setLayoutParams(lay_lp);
|
||||
linearLayout.setPadding(1, 1, 1, 1);
|
||||
|
||||
delete_lp.setMargins(1, 1, 1, 1);
|
||||
btnDelete.setLayoutParams(delete_lp);
|
||||
|
||||
edit_lp.setMargins(1, 1, 1, 1);
|
||||
btnEdit.setLayoutParams(edit_lp);
|
||||
|
||||
item_lp.setMargins(1, 1, 1, 1);
|
||||
btnItem.setLayoutParams(item_lp);
|
||||
|
||||
// Load values
|
||||
btnDelete.setText(R.string.delete_button); // TODO: Make this an image?
|
||||
btnEdit.setText(R.string.edit_button); // TODO: Make this a pencil?
|
||||
setName(listItemInfo.getName ());
|
||||
|
||||
// ========== Style the buttons ==========
|
||||
// Color!
|
||||
linearLayout.setBackgroundColor(Color.BLACK);
|
||||
btnDelete.setBackgroundColor(Color.LTGRAY);
|
||||
btnDelete.setTextColor(Color.BLACK);
|
||||
btnEdit.setBackgroundColor(Color.LTGRAY);
|
||||
btnEdit.setTextColor(Color.BLACK);
|
||||
btnItem.setBackgroundColor(Color.WHITE);
|
||||
int[] colors = getColors(carbPerCal);
|
||||
btnItem.setTextColor(Color.rgb(colors[0], colors[1], colors[2]));
|
||||
// Size!
|
||||
//textSize = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getWidth()/30;
|
||||
btnDelete.setTextSize(16); //textSize-10);
|
||||
btnEdit.setTextSize(16); //textSize-10);
|
||||
btnItem.setTextSize(16); //textSize-8);
|
||||
|
||||
// Add the buttons to the layout!
|
||||
linearLayout.addView(btnDelete);
|
||||
linearLayout.addView(btnEdit);
|
||||
linearLayout.addView(btnItem);
|
||||
}
|
||||
|
||||
public LinearLayout getView(){
|
||||
return linearLayout;
|
||||
}
|
||||
|
||||
public int[] getColors(double carbPerCal){
|
||||
int r, g, b;
|
||||
b = 0;
|
||||
|
||||
// Find the ratio
|
||||
double dRed = 1-carbPerCal;
|
||||
double dGreen = carbPerCal;
|
||||
|
||||
// Find which is larger
|
||||
double max;
|
||||
if (dGreen > dRed){
|
||||
max = dGreen;
|
||||
} else {
|
||||
max = dRed;
|
||||
}
|
||||
|
||||
// Find the secret number (diff)
|
||||
double diff = 1 - max;
|
||||
|
||||
// Brighten the colors with diff!
|
||||
dRed += diff;
|
||||
dGreen += diff;
|
||||
|
||||
// Bring the colors into spectrum!
|
||||
dRed *= 255;
|
||||
dGreen *= 255;
|
||||
|
||||
// Make the numbers integers, increase to color spectrum
|
||||
r = (int) dRed;
|
||||
g = (int) dGreen;
|
||||
|
||||
// Put them in an array to pack and ship away
|
||||
int[] colors = {r, g, b};
|
||||
|
||||
if(carbPerCal >= 1){
|
||||
colors = new int[] {0, 255, 0};
|
||||
}
|
||||
|
||||
return colors;
|
||||
}
|
||||
|
||||
public double getCalPerDol(){
|
||||
// Total calories divided by $$$
|
||||
return (getCalories()*getServings())/getCost();
|
||||
}
|
||||
|
||||
public double getCarbPerCal(){
|
||||
// Calories from carbs divided by calories from all sources
|
||||
return ((getCarbs()-getFiber())*4)/getCalories();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String name){
|
||||
super.setName(name);
|
||||
DecimalFormat format = new DecimalFormat("#.##");
|
||||
String strCalPerDol = format.format(calPerDol);
|
||||
strCalPerDol = getName() + "\n" + strCalPerDol + "Cal/$ " + format.format(carbPerCal * 100) + "%Carbs";
|
||||
btnItem.setText(strCalPerDol);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package com.hyperling.carbupbeta;
|
||||
|
||||
/**
|
||||
* Created by usb on 1/4/15.
|
||||
*/
|
||||
public class ListItemInfo {
|
||||
private String name;
|
||||
private int ID, ListID;
|
||||
private double cost;
|
||||
private double servings;
|
||||
private double calories;
|
||||
private double carbs;
|
||||
private double fiber;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getID() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
public void setID(int ID) {
|
||||
this.ID = ID;
|
||||
}
|
||||
|
||||
public int getListID() {
|
||||
return ListID;
|
||||
}
|
||||
|
||||
public void setListID(int listID) {
|
||||
ListID = listID;
|
||||
}
|
||||
|
||||
public double getCost() {
|
||||
return cost;
|
||||
}
|
||||
|
||||
public void setCost(double cost) {
|
||||
this.cost = cost;
|
||||
}
|
||||
|
||||
public double getServings() {
|
||||
return servings;
|
||||
}
|
||||
|
||||
public void setServings(double servings) {
|
||||
this.servings = servings;
|
||||
}
|
||||
|
||||
public double getCalories() {
|
||||
return calories;
|
||||
}
|
||||
|
||||
public void setCalories(double calories) {
|
||||
this.calories = calories;
|
||||
}
|
||||
|
||||
public double getCarbs() {
|
||||
return carbs;
|
||||
}
|
||||
|
||||
public void setCarbs(double carbs) {
|
||||
this.carbs = carbs;
|
||||
}
|
||||
|
||||
public double getFiber() {
|
||||
return fiber;
|
||||
}
|
||||
|
||||
public void setFiber(double fiber) {
|
||||
this.fiber = fiber;
|
||||
}
|
||||
}
|
||||
+109
@@ -0,0 +1,109 @@
|
||||
package com.hyperling.carbupbeta;
|
||||
|
||||
import android.app.TabActivity;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.TabHost;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Created by usb on 9/29/14.
|
||||
*/
|
||||
public class Main extends TabActivity {
|
||||
|
||||
private DALIH dalih;
|
||||
|
||||
ArrayList<ListInfo> lists;
|
||||
|
||||
boolean createTab2 = false;
|
||||
int lastList, openTab, textSize;
|
||||
String tab2Name;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState){
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.main);
|
||||
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
|
||||
|
||||
// Instantiate DALIH
|
||||
dalih = new DALIH(this);
|
||||
|
||||
dalih.open();
|
||||
// THIS IS AN ASSIGNMENT STATEMENT. PLEASE READ IT CORRECTLY. #savecycles
|
||||
if ((lastList = dalih.getLastList()) >= 0) {
|
||||
openTab = dalih.getOpenTab();
|
||||
lists = dalih.getLists();
|
||||
}
|
||||
dalih.close();
|
||||
|
||||
if (lastList >= 0){
|
||||
createTab2 = true;
|
||||
|
||||
for (ListInfo list : lists){
|
||||
if (list.getID() == lastList){
|
||||
tab2Name = list.getName();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Init the TabHost
|
||||
TabHost tabHost = getTabHost();
|
||||
|
||||
// Create the tabs
|
||||
// Tab1
|
||||
TabHost.TabSpec createListSpec = tabHost.newTabSpec("Create List");
|
||||
if (Build.VERSION.SDK_INT >= 21) {
|
||||
createListSpec.setIndicator("Choose List", getDrawable(R.drawable.dr_face_straight2_circle));
|
||||
}
|
||||
else{
|
||||
createListSpec.setIndicator("Choose List");
|
||||
}
|
||||
Intent createList = new Intent(this, Tab1.class);
|
||||
createListSpec.setContent(createList);
|
||||
// Add tab to TabHost
|
||||
tabHost.addTab(createListSpec);
|
||||
|
||||
// Tab2
|
||||
if (createTab2) {
|
||||
if (dalih.DEBUG) System.out.println("Creating tab2");
|
||||
|
||||
TabHost.TabSpec createItemsSpec = tabHost.newTabSpec("Create Items");
|
||||
if (Build.VERSION.SDK_INT >= 21) {
|
||||
createItemsSpec.setIndicator(tab2Name);
|
||||
}
|
||||
else{
|
||||
createItemsSpec.setIndicator(tab2Name);
|
||||
}
|
||||
Intent createItems = new Intent(this, Tab2.class);
|
||||
createItemsSpec.setContent(createItems);
|
||||
|
||||
// Add tab to TabHost
|
||||
tabHost.addTab(createItemsSpec);
|
||||
}
|
||||
|
||||
// Settings/About Tab
|
||||
TabHost.TabSpec mySettingsSpec = tabHost.newTabSpec("Settings");
|
||||
if (Build.VERSION.SDK_INT >= 21) {
|
||||
mySettingsSpec.setIndicator("Settings", getDrawable(R.drawable.figsy_grass_circle_small));
|
||||
}
|
||||
else{
|
||||
mySettingsSpec.setIndicator("Settings");
|
||||
}
|
||||
Intent mySettingsList = new Intent(this, MySettings.class);
|
||||
mySettingsSpec.setContent(mySettingsList);
|
||||
// Add tab to TabHost
|
||||
tabHost.addTab(mySettingsSpec);
|
||||
|
||||
|
||||
// BEFORE FINAL, APP SHOULD OPEN ON TAB2
|
||||
//tabHost.setCurrentTab(1);
|
||||
// After app is final, app should open to tab1 if no previous lists exist
|
||||
// Otherwise, the app will open on tab 2 with the last selected list in place
|
||||
if (dalih.DEBUG) System.out.println("Opening tab " + openTab + ", index " + (openTab-1));
|
||||
tabHost.setCurrentTab(openTab-1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.hyperling.carbupbeta;
|
||||
|
||||
/**
|
||||
* Created by ling on 1/1/16.
|
||||
*/
|
||||
public class MySettingInfo {
|
||||
private String name;
|
||||
private boolean enabled;
|
||||
|
||||
public String getName(){
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name){
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public boolean getEnabled(){
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled){
|
||||
this.enabled = enabled;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
package com.hyperling.carbupbeta;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.LinearLayout.LayoutParams;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
|
||||
/**
|
||||
* Created by ling on 1/1/16.
|
||||
*/
|
||||
public class MySettingItem extends MySettingInfo{
|
||||
|
||||
private LinearLayout linearLayout;
|
||||
private RelativeLayout relativeLayout;
|
||||
Button btnItem;
|
||||
CheckBox checkBox;
|
||||
|
||||
private int textSize;
|
||||
|
||||
public MySettingItem(Context context, MySettingInfo info){
|
||||
// Instantiate the Views
|
||||
linearLayout = new LinearLayout(context);
|
||||
relativeLayout = new RelativeLayout(context);
|
||||
btnItem = new Button(context);
|
||||
checkBox = new CheckBox(context);
|
||||
|
||||
// Give the views their required attributes (Wrap Content)
|
||||
LayoutParams lay_lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
|
||||
LayoutParams rel_lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
|
||||
LayoutParams item_lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
|
||||
RelativeLayout.LayoutParams check_lp = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
|
||||
|
||||
lay_lp.setMargins(1, 1, 1, 1);
|
||||
linearLayout.setLayoutParams(lay_lp);
|
||||
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
|
||||
|
||||
relativeLayout.setLayoutParams(rel_lp);
|
||||
if (Build.VERSION.SDK_INT >= 17) {
|
||||
relativeLayout.setHorizontalGravity(RelativeLayout.ALIGN_PARENT_END);
|
||||
}
|
||||
else {
|
||||
relativeLayout.setHorizontalGravity(RelativeLayout.ALIGN_PARENT_RIGHT);
|
||||
}
|
||||
|
||||
btnItem.setLayoutParams(item_lp);
|
||||
checkBox.setLayoutParams(check_lp);
|
||||
|
||||
// Add the values to the buttons
|
||||
setName(info.getName());
|
||||
setEnabled(info.getEnabled());
|
||||
|
||||
// ========== Style the buttons ==========
|
||||
// Color!
|
||||
linearLayout.setBackgroundColor(Color.LTGRAY);
|
||||
relativeLayout.setBackgroundColor(Color.LTGRAY);
|
||||
btnItem.setBackgroundColor(Color.LTGRAY);
|
||||
btnItem.setTextColor(Color.BLACK);
|
||||
// Size!
|
||||
//textSize = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getWidth()/30;
|
||||
btnItem.setTextSize(24); // textSize);
|
||||
|
||||
// Add the items to the layout!
|
||||
relativeLayout.addView(checkBox);
|
||||
|
||||
linearLayout.addView(btnItem);
|
||||
linearLayout.addView(relativeLayout);
|
||||
|
||||
linearLayout.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (Build.VERSION.SDK_INT >= 15) {
|
||||
btnItem.callOnClick();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
relativeLayout.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (Build.VERSION.SDK_INT >= 15) {
|
||||
btnItem.callOnClick();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public LinearLayout getView(){
|
||||
return linearLayout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String name){
|
||||
super.setName(name);
|
||||
btnItem.setText(getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnabled(boolean enabled){
|
||||
super.setEnabled(enabled);
|
||||
checkBox.setChecked(getEnabled());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package com.hyperling.carbupbeta;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
/**
|
||||
* Created by ling on 1/1/16.
|
||||
*/
|
||||
public class MySettings extends Activity {
|
||||
|
||||
private DALIH dalih;
|
||||
|
||||
Context context;
|
||||
|
||||
LinearLayout settingsArea;
|
||||
MySettingItem quickLoad, adsEnabled, rainbowLists, whiteOnBlack;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.my_settings);
|
||||
|
||||
// Set default context
|
||||
context = this;
|
||||
|
||||
// Get DALIH ready to go!
|
||||
dalih = new DALIH(context);
|
||||
|
||||
// Find the layout
|
||||
settingsArea = (LinearLayout) findViewById(R.id.settingsArea);
|
||||
|
||||
// Instantiate settings
|
||||
quickLoad = new MySettingItem(context, new MySettingInfo());
|
||||
adsEnabled = new MySettingItem(context, new MySettingInfo());
|
||||
|
||||
// Name them
|
||||
quickLoad.setName("Quick Load:");
|
||||
adsEnabled.setName("Ads Enabled:");
|
||||
|
||||
// Set the checkboxes
|
||||
dalih.open();
|
||||
quickLoad.setEnabled(dalih.getQuickLoad());
|
||||
adsEnabled.setEnabled(dalih.getAdsEnabled());
|
||||
dalih.close();
|
||||
|
||||
// Set the checkbox actions
|
||||
quickLoad.btnItem.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dalih.setQuickLoad(!dalih.getQuickLoad());
|
||||
quickLoad.checkBox.setChecked(dalih.getQuickLoad());
|
||||
}
|
||||
});
|
||||
quickLoad.checkBox.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dalih.setQuickLoad(quickLoad.checkBox.isChecked());
|
||||
}
|
||||
});
|
||||
|
||||
adsEnabled.btnItem.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dalih.setAdsEnabled(!dalih.getAdsEnabled());
|
||||
adsEnabled.checkBox.setChecked(dalih.getAdsEnabled());
|
||||
}
|
||||
});
|
||||
adsEnabled.checkBox.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dalih.setAdsEnabled(adsEnabled.checkBox.isChecked());
|
||||
}
|
||||
});
|
||||
|
||||
// Throw them onto the screen
|
||||
settingsArea.addView(quickLoad.getView());
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 9) {
|
||||
settingsArea.addView(adsEnabled.getView());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
dalih.open();
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
dalih.close();
|
||||
super.onPause();
|
||||
}
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
package com.hyperling.carbupbeta;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
//This class is simply the load screen to start Tabs.class
|
||||
|
||||
|
||||
public class Splash extends Activity {
|
||||
|
||||
private DALIH dalih;
|
||||
|
||||
TextView txtStatus;
|
||||
|
||||
int loadTime = 3000;
|
||||
int quickTime = 500;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_splash);
|
||||
|
||||
dalih = new DALIH(this);
|
||||
|
||||
// Find the TextViews
|
||||
txtStatus = (TextView) findViewById(R.id.txtLoadStatus);
|
||||
|
||||
// Create the TimerTask to launch main
|
||||
TimerTask timerTask = new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
startActivity(new Intent(Splash.this, Main.class));
|
||||
//startActivity(new Intent(Splash.this, Home.class));
|
||||
finish();
|
||||
}
|
||||
};
|
||||
|
||||
dalih.open();
|
||||
if (dalih.getQuickLoad()){
|
||||
loadTime = quickTime;
|
||||
}
|
||||
dalih.close();
|
||||
|
||||
//Create and start the timer
|
||||
Timer timer = new Timer();
|
||||
timer.schedule(timerTask, loadTime);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
dalih.open();
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
dalih.close();
|
||||
super.onPause();
|
||||
}
|
||||
}
|
||||
+320
@@ -0,0 +1,320 @@
|
||||
package com.hyperling.carbupbeta;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.google.android.gms.ads.AdRequest;
|
||||
import com.google.android.gms.ads.AdView;
|
||||
|
||||
/**
|
||||
* Created by usb on 9/28/14.
|
||||
*
|
||||
* This class will:
|
||||
* Create a new list then open tab2
|
||||
*/
|
||||
|
||||
public class Tab1 extends Activity{
|
||||
|
||||
private DALIH dalih;
|
||||
|
||||
// Layout related
|
||||
Context context;
|
||||
EditText txtList;
|
||||
Button btnCreate;
|
||||
LinearLayout layListArea;
|
||||
TextView tvLeft, tvRight, selectHeader;
|
||||
AdView mAdView;
|
||||
|
||||
// The lists!
|
||||
ArrayList<List> lists = new ArrayList<List>();
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.tab1);
|
||||
|
||||
// Set default context
|
||||
context = this;
|
||||
|
||||
// Initiate DALIH
|
||||
dalih = new DALIH(context);
|
||||
|
||||
// Connect to the layout
|
||||
txtList = (EditText) findViewById(R.id.etListName);
|
||||
btnCreate = (Button) findViewById(R.id.btnAddToList);
|
||||
layListArea = (LinearLayout) findViewById(R.id.tab1ListArea);
|
||||
tvLeft = (TextView) findViewById(R.id.leftEditView);
|
||||
tvRight = (TextView) findViewById(R.id.rightEditView);
|
||||
selectHeader = (TextView) findViewById(R.id.selectListHeader);
|
||||
mAdView = (AdView) findViewById(R.id.adView);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
public void setButtonInsert(){
|
||||
btnCreate.setText(R.string.list_create_button_insert);
|
||||
tvLeft.setText("");
|
||||
tvRight.setText("");
|
||||
|
||||
dalih.setLastItem();
|
||||
|
||||
createLists();
|
||||
|
||||
btnCreate.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
ListInfo newList = new ListInfo();
|
||||
newList.setName(dalih.filterString(txtList.getText().toString()));
|
||||
|
||||
if (!testDuplicate(newList)) {
|
||||
if (dalih.DEBUG) System.out.println("List not duplicate, inserting");
|
||||
|
||||
hideKeyboard();
|
||||
|
||||
dalih.insertList(newList);
|
||||
|
||||
createLists();
|
||||
|
||||
dalih.setOpenTab(2);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
public void setButtonUpdate(final List list){
|
||||
btnCreate.setText(R.string.list_create_button_update);
|
||||
String editing = getString(R.string.list_editing) + " "; // strings.xml must get trimmed, space is not appearing
|
||||
tvLeft.setText(editing);
|
||||
tvRight.setText(list.getName());
|
||||
|
||||
// Store the ID
|
||||
dalih.setLastItem(list.getID());
|
||||
|
||||
// Recreate the lists
|
||||
createLists();
|
||||
|
||||
// Pull the text
|
||||
txtList.setText(list.getName());
|
||||
|
||||
showKeyboard();
|
||||
|
||||
btnCreate.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
list.setName(dalih.filterString(txtList.getText().toString()));
|
||||
|
||||
if (!testDuplicate(list)) {
|
||||
if (dalih.DEBUG) System.out.println("List not duplicate, updating");
|
||||
|
||||
hideKeyboard();
|
||||
|
||||
dalih.updateList(list);
|
||||
|
||||
if (dalih.getLastList() == list.getID()) {
|
||||
if (dalih.DEBUG) System.out.println("Last list renamed, resetting");
|
||||
|
||||
restart();
|
||||
}
|
||||
|
||||
setButtonInsert();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Generate all lists and place in alphabetical order
|
||||
private void createLists(){
|
||||
if (dalih.DEBUG) System.out.println("Creating lists for Tab1");
|
||||
|
||||
txtList.setText("");
|
||||
|
||||
lists = new ArrayList<List>();
|
||||
|
||||
for (ListInfo info : dalih.getLists()){
|
||||
if (dalih.DEBUG) System.out.println("Found list: " + info.getID() + " " +info.getName());
|
||||
|
||||
if (info.getID() != dalih.getLastItem()) {
|
||||
lists.add(new List(context, info));
|
||||
}
|
||||
}
|
||||
|
||||
if (lists.size() > 0){
|
||||
selectHeader.setText(R.string.list_select_header);
|
||||
}
|
||||
else{
|
||||
selectHeader.setText("");
|
||||
}
|
||||
|
||||
lists = orderLists(lists);
|
||||
|
||||
layListArea.removeAllViews();
|
||||
for (final List list : lists){
|
||||
list.btnDelete.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (dalih.DEBUG) System.out.println("Clicked delete button: " + list.getID() + " " + list.getName());
|
||||
|
||||
dalih.deleteList(list);
|
||||
|
||||
if (dalih.getLastList() == list.getID()){
|
||||
if (dalih.DEBUG) System.out.println("Last list deleted, resetting");
|
||||
|
||||
dalih.setLastList();
|
||||
|
||||
restart();
|
||||
}
|
||||
|
||||
createLists();
|
||||
}
|
||||
});
|
||||
|
||||
list.btnEdit.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (dalih.DEBUG) System.out.println("Clicked edit button: " + list.getID() + " " + list.getName());
|
||||
|
||||
// Change to update mode
|
||||
setButtonUpdate(list);
|
||||
}
|
||||
});
|
||||
|
||||
list.btnItem.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (dalih.DEBUG) System.out.println("Clicked main button: " + list.getID() + " " + list.getName());
|
||||
|
||||
dalih.setLastList(list.getID());
|
||||
|
||||
dalih.setOpenTab(2);
|
||||
|
||||
//restart();
|
||||
startActivity(new Intent(Tab1.this, Main.class));
|
||||
}
|
||||
});
|
||||
|
||||
if (dalih.DEBUG) System.out.println("Creating list: " + list.getID() + " " + list.getName());
|
||||
|
||||
layListArea.addView(list.getView());
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
private ArrayList<List> orderLists(ArrayList<List> unorderedLists){
|
||||
if (dalih.DEBUG) System.out.println("Sorting lists");
|
||||
|
||||
ArrayList<List> orderedLists = new ArrayList<>();
|
||||
|
||||
while (!unorderedLists.isEmpty()) {
|
||||
String bestName = "z";
|
||||
int index = 0;
|
||||
|
||||
for (List list : unorderedLists) {
|
||||
if (list.getName().toUpperCase().compareTo(bestName.toUpperCase()) < 0) {
|
||||
//if (dalih.DEBUG) System.out.println(list.getName() + " is better than " + bestName);
|
||||
|
||||
bestName = list.getName();
|
||||
index = unorderedLists.indexOf(list);
|
||||
}
|
||||
}
|
||||
if (dalih.DEBUG) System.out.println(bestName + " was the best");
|
||||
|
||||
orderedLists.add(unorderedLists.get(index));
|
||||
unorderedLists.remove(index);
|
||||
}
|
||||
|
||||
return orderedLists;
|
||||
}
|
||||
|
||||
private boolean testDuplicate(ListInfo listInfo) {
|
||||
for (List list : lists) {
|
||||
if (listInfo.getName().equals(list.getName()) || listInfo.getName().equals("")) {
|
||||
Toast.makeText(context, "Name must be unique!", Toast.LENGTH_SHORT).show();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void restart(){
|
||||
finish();
|
||||
startActivity(new Intent(Tab1.this, Main.class));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
if (dalih.DEBUG) System.out.println("***** Resuming Tab1 *****");
|
||||
|
||||
dalih.open();
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 9) {
|
||||
if (dalih.getAdsEnabled()) {
|
||||
if (mAdView.getVisibility() != View.VISIBLE) {
|
||||
AdRequest adRequest = new AdRequest.Builder()
|
||||
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
|
||||
.addTestDevice("C6A494DC6E7C9AC29102694D48487084") // nexus 7
|
||||
.addTestDevice("B8B7561B850A9AB24E0D5B560FC50628") // Moto G
|
||||
.addTestDevice("") // Cappy, even though it can't get ads
|
||||
.build();
|
||||
mAdView.setVisibility(View.VISIBLE);
|
||||
mAdView.loadAd(adRequest);
|
||||
}
|
||||
}
|
||||
else{
|
||||
if (mAdView.getVisibility() == View.VISIBLE) {
|
||||
mAdView.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setButtonInsert();
|
||||
|
||||
super.onResume();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
if (dalih.DEBUG) System.out.println("***** Pausing Tab1 *****");
|
||||
|
||||
dalih.close();
|
||||
|
||||
hideKeyboard();
|
||||
|
||||
super.onPause();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
public void hideKeyboard(){
|
||||
((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(btnCreate.getWindowToken(), 0);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
public void showKeyboard(){
|
||||
((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(txtList, 0);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
+369
@@ -0,0 +1,369 @@
|
||||
package com.hyperling.carbupbeta;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.android.gms.ads.AdRequest;
|
||||
import com.google.android.gms.ads.AdView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Created by usb on 9/28/14.
|
||||
*
|
||||
* This class will:
|
||||
* Add items to the current selected list
|
||||
*
|
||||
* DEEMED "GOOD ENOUGH" 13:45 2014-09-30 :D
|
||||
* ListItems are created perfectly, ordered by Cal/$, and colored by Carb/Cal
|
||||
*/
|
||||
|
||||
public class Tab2 extends Activity{
|
||||
|
||||
private DALIH dalih;
|
||||
|
||||
// Define the Views
|
||||
Context context;
|
||||
LinearLayout layListArea;
|
||||
EditText txtName, txtCost, txtServings, txtCalories, txtCarbs, txtFiber;
|
||||
Button btnClear, btnAdd;
|
||||
AdView mAdView;
|
||||
|
||||
// List
|
||||
ArrayList<ListItem> items = new ArrayList<ListItem>();
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.tab2);
|
||||
|
||||
// Set default context
|
||||
context = this;
|
||||
|
||||
// Initiate DALIH
|
||||
dalih = new DALIH(context);
|
||||
|
||||
// Load/Find the Views!
|
||||
layListArea = (LinearLayout) findViewById(R.id.layTab2ListArea);
|
||||
txtName = (EditText) findViewById(R.id.etItemName);
|
||||
txtCost = (EditText) findViewById(R.id.etItemCost);
|
||||
txtServings = (EditText) findViewById(R.id.etItemServs);
|
||||
txtCalories = (EditText) findViewById(R.id.etItemCals);
|
||||
txtCarbs = (EditText) findViewById(R.id.etItemCarbs);
|
||||
txtFiber = (EditText) findViewById(R.id.etItemFiber);
|
||||
btnClear = (Button) findViewById(R.id.btnClear);
|
||||
btnAdd = (Button) findViewById(R.id.btnAddToList);
|
||||
mAdView = (AdView) findViewById(R.id.adView);
|
||||
|
||||
// Give the Buttons their power
|
||||
btnClear.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
|
||||
removeItem();
|
||||
|
||||
// Clear all fields!
|
||||
txtName.setText("");
|
||||
txtCost.setText("");
|
||||
txtServings.setText("");
|
||||
txtCalories.setText("");
|
||||
txtCarbs.setText("");
|
||||
txtFiber.setText("");
|
||||
|
||||
setButtonInsert();
|
||||
}
|
||||
});
|
||||
|
||||
return;
|
||||
}// end onCreate
|
||||
|
||||
@Override
|
||||
protected void onResume(){
|
||||
if (dalih.DEBUG) System.out.println("***** Resuming Tab2 *****");
|
||||
|
||||
dalih.open();
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 9) {
|
||||
if (dalih.getAdsEnabled()) {
|
||||
if (mAdView.getVisibility() != View.VISIBLE) {
|
||||
AdRequest adRequest = new AdRequest.Builder()
|
||||
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
|
||||
.addTestDevice("C6A494DC6E7C9AC29102694D48487084") // nexus 7
|
||||
.addTestDevice("B8B7561B850A9AB24E0D5B560FC50628") // Moto G
|
||||
.addTestDevice("") // Cappy, even though it can't get ads
|
||||
.build();
|
||||
mAdView.setVisibility(View.VISIBLE);
|
||||
mAdView.loadAd(adRequest);
|
||||
}
|
||||
}
|
||||
else{
|
||||
if (mAdView.getVisibility() == View.VISIBLE) {
|
||||
mAdView.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setButtonInsert();
|
||||
|
||||
super.onResume();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause(){
|
||||
if (dalih.DEBUG) System.out.println("***** Pausing Tab2 *****");
|
||||
|
||||
dalih.close();
|
||||
|
||||
hideKeyboard();
|
||||
|
||||
super.onPause();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
public boolean validateItem(ListItemInfo newItem){
|
||||
// FIELDS MUST HAVE VALUES BEFORE CONVERTING!!!
|
||||
if (txtName.getText().toString().equals("")){
|
||||
Toast.makeText(context, "Item must have a name!", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
else if (txtCost.getText().toString().equals("") || txtCost.getText().toString().equals(".")){
|
||||
Toast.makeText(context, "Item must have a cost!", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
else if (txtServings.getText().toString().equals("") || txtServings.getText().toString().equals(".")){
|
||||
Toast.makeText(context, "Item must have servings!", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
else if (txtCalories.getText().toString().equals("") || txtCalories.getText().toString().equals(".")){
|
||||
Toast.makeText(context, "Item must have calories!", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
else if (txtCarbs.getText().toString().equals("") || txtCarbs.getText().toString().equals(".")){
|
||||
Toast.makeText(context, "Item must have carbohydrates!", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
else{
|
||||
|
||||
newItem.setName(txtName.getText().toString());
|
||||
newItem.setCost(Double.parseDouble(txtCost.getText().toString()));
|
||||
newItem.setServings(Double.parseDouble(txtServings.getText().toString()));
|
||||
newItem.setCalories(Double.parseDouble(txtCalories.getText().toString()));
|
||||
newItem.setCarbs(Double.parseDouble(txtCarbs.getText().toString()));
|
||||
newItem.setFiber(Double.parseDouble(txtFiber.getText().toString()));
|
||||
newItem.setListID(dalih.getLastList());
|
||||
|
||||
// NAME MUST BE UNIQUE, VALUES MUST BE GREATER THAN 0
|
||||
boolean nameDuplicated = false;
|
||||
for(ListItem li : items){
|
||||
if(newItem.getName().equals(li.getName()) || newItem.getName().equals("")){
|
||||
nameDuplicated = true;
|
||||
}
|
||||
}
|
||||
if (nameDuplicated){
|
||||
Toast.makeText(context, "Name must be unique!", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
else if (newItem.getCost() <= 0){
|
||||
Toast.makeText(context, "Cost must be greater than 0!", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
else if (newItem.getServings() <= 0){
|
||||
Toast.makeText(context, "Servings must be greater than 0!", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
else if (newItem.getCalories() <= 0){
|
||||
Toast.makeText(context, "Calories must be greater than 0!", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
else if (newItem.getFiber() > newItem.getCarbs()){
|
||||
Toast.makeText(context, "Cannot have more fiber than carbs!", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
else if ((newItem.getCarbs()-newItem.getFiber()) * 3.5 > newItem.getCalories()){
|
||||
Toast.makeText(context, "Too many carbs, not enough calories!", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
else{
|
||||
return true;
|
||||
}// end else
|
||||
}// end else
|
||||
|
||||
return false;
|
||||
}// end validateItem()
|
||||
|
||||
public void setButtonInsert(){
|
||||
btnAdd.setText(R.string.item_create_button_insert);
|
||||
|
||||
// Reset to default
|
||||
dalih.setLastItem();
|
||||
|
||||
createItems();
|
||||
|
||||
if (dalih.DEBUG) System.out.println("Setting add button to insert");
|
||||
btnAdd.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
|
||||
ListItemInfo newItem = new ListItemInfo();
|
||||
|
||||
if (validateItem(newItem)) {
|
||||
hideKeyboard();
|
||||
|
||||
dalih.insertItem(newItem);
|
||||
|
||||
createItems();
|
||||
|
||||
dalih.setOpenTab(1);
|
||||
}
|
||||
}
|
||||
});// end btnAdd.setOnClickListener
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
public void setButtonUpdate(final ListItem listItem){
|
||||
btnAdd.setText(R.string.item_create_button_update);
|
||||
|
||||
// Pull Item info into top boxes then remove the ListItem
|
||||
// Save which item we are on
|
||||
dalih.setLastItem(listItem.getID());
|
||||
|
||||
// Remove the item
|
||||
createItems();
|
||||
|
||||
// Set all fields to the values
|
||||
txtName.setText(listItem.getName());
|
||||
txtCost.setText(Double.toString(listItem.getCost()));
|
||||
txtServings.setText(Double.toString(listItem.getServings()));
|
||||
txtCalories.setText(Double.toString(listItem.getCalories()));
|
||||
txtCarbs.setText(Double.toString(listItem.getCarbs()));
|
||||
txtFiber.setText(Double.toString(listItem.getFiber()));
|
||||
|
||||
showKeyboard();
|
||||
|
||||
if (dalih.DEBUG) System.out.println("");
|
||||
btnAdd.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
|
||||
if (validateItem(listItem)) {
|
||||
hideKeyboard();
|
||||
|
||||
dalih.updateItem(listItem);
|
||||
|
||||
setButtonInsert();
|
||||
}
|
||||
}
|
||||
});// end btnAdd.setOnClickListener
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
public void createItems(){
|
||||
if (dalih.DEBUG) System.out.println("Creating items");
|
||||
|
||||
txtName.setText("");
|
||||
txtCost.setText("");
|
||||
txtServings.setText("");
|
||||
txtCalories.setText("");
|
||||
txtCarbs.setText("");
|
||||
txtFiber.setText("");
|
||||
|
||||
items = new ArrayList<ListItem>();
|
||||
|
||||
for (ListItemInfo info : dalih.getItems(dalih.getLastList())){
|
||||
if (dalih.DEBUG) System.out.println("Found item: " + info.getID() + " " + info.getName());
|
||||
|
||||
// Prevent item being edited from being displayed
|
||||
if (info.getID() != dalih.getLastItem()) {
|
||||
items.add(new ListItem(context, info));
|
||||
}
|
||||
}
|
||||
|
||||
// ========== Display the ListItems ==========
|
||||
// Order the list
|
||||
items = orderList(items);
|
||||
|
||||
// Give the Item Buttons functionality
|
||||
for (final ListItem li : items){
|
||||
li.btnEdit.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
// Change the create button to update instead of insert
|
||||
setButtonUpdate(li);
|
||||
}
|
||||
});
|
||||
|
||||
li.btnDelete.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dalih.deleteItem(li);
|
||||
|
||||
createItems();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Replace old List with new ordered list
|
||||
// Clear list
|
||||
layListArea.removeAllViews();
|
||||
// Add Views
|
||||
for (ListItem li : items) {
|
||||
layListArea.addView(li.getView());
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
public ArrayList<ListItem> orderList(ArrayList<ListItem> unorderedList){
|
||||
if (dalih.DEBUG) System.out.println("Sorting the items");
|
||||
|
||||
ArrayList<ListItem> orderedList = new ArrayList<ListItem>();
|
||||
|
||||
while (!unorderedList.isEmpty()) {
|
||||
double max = 0;
|
||||
int index = 0;
|
||||
|
||||
for (ListItem j : unorderedList) {
|
||||
if (j.getCalPerDol() > max) {
|
||||
//if (dalih.DEBUG) System.out.println(j.getCalPerDol()*100 + " is better than " + max*100);
|
||||
|
||||
max = j.getCalPerDol();
|
||||
index = unorderedList.indexOf(j);
|
||||
}
|
||||
}
|
||||
if (dalih.DEBUG) System.out.println(max*100 + " was the best");
|
||||
orderedList.add(unorderedList.get(index));
|
||||
unorderedList.remove(index);
|
||||
}
|
||||
|
||||
return orderedList;
|
||||
}
|
||||
|
||||
public void removeItem(){
|
||||
int deleteID = dalih.getLastItem();
|
||||
|
||||
for (ListItemInfo item : dalih.getItems(dalih.getLastList())){
|
||||
if (item.getID() == deleteID){
|
||||
if (dalih.DEBUG) System.out.println("Deleting item " + item.getID() + " " + item.getName());
|
||||
dalih.deleteItem(item);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
public void hideKeyboard(){
|
||||
((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(btnAdd.getWindowToken(),0);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
public void showKeyboard(){
|
||||
((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(txtName, 0);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
}// end Tab2
|
||||
@@ -0,0 +1,64 @@
|
||||
|
||||
**********
|
||||
**********
|
||||
**********
|
||||
TODO:
|
||||
- Implement a database (Moves project to Beta v1.00)
|
||||
- Create 2 tables
|
||||
- 1st is List, one attribute is ListID(PK)
|
||||
- 2nd is Item, 2 primary keys per entry (ItemID, ListID(FK)), and attributes as Price, Servings, Calories, and Carbs
|
||||
- Have Tab1 create a List entity
|
||||
- Have Tab2 create Item entities with the correct ListID
|
||||
- Have Tab3 display all Lists, with the current selected List at the top
|
||||
- Finalize the app (Moves project to Final/Release/Something meaning it isn't beta/v1.00)
|
||||
- All functionality is functional
|
||||
- App is easy to understand for new users
|
||||
- Visuals and audio are high quality
|
||||
**********
|
||||
**********
|
||||
**********
|
||||
$VERSION_NAME v$VERSION_NUMBER $DATE_STARTED - $DATE_FINISHED
|
||||
**********
|
||||
**********
|
||||
**********
|
||||
Beta v0.08 2016/01/06 - 2016/01/06
|
||||
- Make the keyboard lower after adding a list or item
|
||||
Beta v0.07 2015/12/31 - 2016/01/03
|
||||
- Changed names of tables and columns on DB
|
||||
- Deleted tab 3, moved list of Lists to tab1 and selected list to tab2
|
||||
- Always open on tab1
|
||||
- Created List and ListInfo
|
||||
- Finished DALIH, added methods for List
|
||||
- Basically re-did the entire thing
|
||||
Aplha v0.06 2014/12/29 - Unfinished
|
||||
- Created Data to hold dalih for all tabs
|
||||
- Added Data to application in manifest
|
||||
- Brought DALIH to life (with insert, delete, and get methods)
|
||||
- Started preparing a toggle button on tab2 in case I add measuring by weight
|
||||
- Got tab2 to work with DALIH
|
||||
Alpha v0.05 2014/12/24 - 2014/12/29 Uploaded as Version 1(0.05)
|
||||
- Transfer project to Android Studio 1.0
|
||||
- Add @string version_name
|
||||
- Change @string my_version_number to version_number in all files
|
||||
- Created DALIH
|
||||
- Changed to circle icon
|
||||
Alpha v0.04 2014/10/16 - 2014/10/16
|
||||
- Change carbs to return to double in edit text
|
||||
Alpha v0.03 2014/10/13 - 2014/10/13
|
||||
- EditTexts adjust height if one grows
|
||||
Alpha v0.02 2014/10/07 - 2014/10/13
|
||||
- ListItem entries editable
|
||||
- Tab2 text edits need not be able to enter only a "."
|
||||
- Add percentages
|
||||
- Fix button text being displaced
|
||||
- All Tab2 ListItem information is on its own line
|
||||
- Renamed BETA TEST LIST to Unsaved Test LIst
|
||||
Alpha v0.01
|
||||
- Added ScrollView around tab2's ListITemLayout
|
||||
Alpha v0.00
|
||||
Designed entire app, got tab 2 "working"
|
||||
- Now working on bringing to the app store
|
||||
- Tab2 needs to be able to scroll
|
||||
- v0.01
|
||||
- Tab2 needs ListItems to be editable
|
||||
- Tab2 needs to have color codes, or to display a % of carb/calorie (in addition to color)
|
||||
Reference in new issue
Block a user