bitQuit_Android/app/src/main/java/com/tonydicola/bletest/app/MainActivity.java
private void checkCount(String rec) {

        String[] token = rec.split("[ ]+");
        int newCount = Integer.parseInt(token[1]);

        // Detect removed cigarettes
        if (numCigs > newCount) {
            FileOutputStream outputStream;

            Calendar c = Calendar.getInstance();
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String time = df.format(c.getTime());

            String datum = time + " " + Integer.toString(newCount - numCigs);

            thisMonth += numCigs - newCount;

/*
            // Write event to database file
            try {
                outputStream = openFileOutput(path, Context.MODE_APPEND);
                outputStream.write(datum.getBytes());
                outputStream.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
*/
        }
        // Save new count
        numCigs = newCount;

        // Write to countDisplay
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                countDisplay.setText("# Cigarettes: " + Integer.toString(numCigs));
                countDisplay.invalidate();
            }
        });
    }
// Check recently received cigarette count against last cigarette count
Check recently received cigarette count against last cigarette count
Check recently received cigarette count against last cigarette count
private void checkCount(String rec) {
        String[] token = rec.split("[ ]+");
        int newCount = Integer.parseInt(token[1]);
        if (numCigs > newCount) {
            FileOutputStream outputStream;
            Calendar c = Calendar.getInstance();
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String time = df.format(c.getTime());
            String datum = time + " " + Integer.toString(newCount - numCigs);
            thisMonth += numCigs - newCount;
/*
            // Write event to database file
            try {
                outputStream = openFileOutput(path, Context.MODE_APPEND);
                outputStream.write(datum.getBytes());
                outputStream.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
*/
        }
        numCigs = newCount;
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                countDisplay.setText("# Cigarettes: " + Integer.toString(numCigs));
                countDisplay.invalidate();
            }
        });
    }
private void checkCount ( String rec ) { String [ ] token = rec . split ( "[ ]+" ) ; int newCount = Integer . parseInt ( token [ 1 ] ) ; if ( numCigs > newCount ) { FileOutputStream outputStream ; Calendar c = Calendar . getInstance ( ) ; SimpleDateFormat df = new SimpleDateFormat ( "yyyy-MM-dd HH:mm:ss" ) ; String time = df . format ( c . getTime ( ) ) ; String datum = time + " " + Integer . toString ( newCount - numCigs ) ; thisMonth += numCigs - newCount ; /*
            // Write event to database file
            try {
                outputStream = openFileOutput(path, Context.MODE_APPEND);
                outputStream.write(datum.getBytes());
                outputStream.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
*/ } numCigs = newCount ; runOnUiThread ( new Runnable ( ) { @ Override public void run ( ) { countDisplay . setText ( "# Cigarettes: " + Integer . toString ( numCigs ) ) ; countDisplay . invalidate ( ) ; } } ) ; }
Check recently received cigarette count against last cigarette count
Check recently received cigarette count against last cigarette count
// Detect removed cigarettes // Save new count // Write to countDisplay