Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import android.content.ContentValues;

import android.database.sqlite.SQLiteDatabase;

public class Main {
    /** Name of the table */
    private static final String TABLE_NAME = "s";

    /**
     * Add an entry to the database
     *
     * @param db
     *            pointer to database
     * @param recordLine
     *            String with a record
     *            format: yy,mm,dd,hh:mm,light,solar,consumption
     *            e.g.: "15,08,13,13:54,35000,613.456,-120.22"
     */
    public static void addDay(SQLiteDatabase db, String recordLine) {

        /* Parse the string into its single values */
        String[] valuesPerLine = recordLine.split(",");

        if (valuesPerLine.length == 1) {
            return;
        }
        /** String list with hour & minute values */
        String[] hourSplit = valuesPerLine[3].split(":");

        /** ContentValues to hold the measured and calculated values to be added to the database */
        ContentValues values = new ContentValues(14);
        values.put("year", Integer.parseInt(valuesPerLine[0]));
        values.put("month", Integer.parseInt(valuesPerLine[1]));
        values.put("day", Integer.parseInt(valuesPerLine[2]));
        values.put("hour", Integer.parseInt(hourSplit[0]));
        values.put("minute", Integer.parseInt(hourSplit[1]));
        values.put("solar", Double.parseDouble(valuesPerLine[5]));
        values.put("cons", Double.parseDouble(valuesPerLine[6]));
        values.put("light", Long.parseLong(valuesPerLine[4]));

        db.insert(TABLE_NAME, null, values);
    }
}