Skip to content
This repository was archived by the owner on Nov 23, 2022. It is now read-only.

Commit e99c622

Browse files
author
WebDucer
committed
Stand 31.03.2014
1 parent 2659a12 commit e99c622

7 files changed

Lines changed: 374 additions & 124 deletions

File tree

Zeiterfassung/AndroidManifest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
<category android:name="android.intent.category.LAUNCHER"/>
1919
</intent-filter>
2020
</activity>
21+
<provider
22+
android:name=".db.ZeitProvider"
23+
android:authorities="de.mvhs.android.zeiterfassung.zeitprovider" />
2124
</application>
2225

2326
</manifest>

Zeiterfassung/res/layout-land/activity_edit.xml

100644100755
File mode changed.

Zeiterfassung/res/layout/activity_edit.xml

100644100755
File mode changed.

Zeiterfassung/src/de/mvhs/android/zeiterfassung/MainActivity.java

Lines changed: 123 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -13,122 +13,130 @@
1313
import android.widget.Button;
1414
import android.widget.EditText;
1515
import de.mvhs.android.zeiterfassung.db.DBHelper;
16+
import de.mvhs.android.zeiterfassung.db.ZeitContracts;
1617

1718
public class MainActivity extends Activity {
1819

19-
private boolean _IsStarted = false;
20-
21-
@Override
22-
protected void onCreate(Bundle savedInstanceState) {
23-
super.onCreate(savedInstanceState);
24-
25-
setContentView(R.layout.activity_main);
26-
27-
if (savedInstanceState != null) {
28-
_IsStarted = savedInstanceState.getBoolean("CurrentState", false);
29-
}
30-
31-
setButtonState();
32-
}
33-
34-
@Override
35-
protected void onStart() {
36-
super.onStart();
37-
38-
// Buttons registrieren
39-
Button commandStart = (Button) findViewById(R.id.StartCommand);
40-
Button commandEnd = (Button) findViewById(R.id.EndCommand);
41-
42-
// Click Event registrieren
43-
commandStart.setOnClickListener(new OnStartButtonClicked());
44-
45-
commandEnd.setOnClickListener(new OnEndButtonClicked());
46-
}
47-
48-
@Override
49-
protected void onSaveInstanceState(Bundle outState) {
50-
outState.putBoolean("CurrentState", _IsStarted);
51-
super.onSaveInstanceState(outState);
52-
}
53-
54-
@Override
55-
protected void onStop() {
56-
// Buttons registrieren
57-
Button commandStart = (Button) findViewById(R.id.StartCommand);
58-
Button commandEnd = (Button) findViewById(R.id.EndCommand);
59-
60-
// Click Event deregistrieren
61-
commandStart.setOnClickListener(null);
62-
commandEnd.setOnClickListener(null);
63-
super.onStop();
64-
}
65-
66-
private void setButtonState() {
67-
Button commandStart = (Button) findViewById(R.id.StartCommand);
68-
Button commandEnd = (Button) findViewById(R.id.EndCommand);
69-
70-
commandStart.setEnabled(_IsStarted == false);
71-
commandEnd.setEnabled(_IsStarted);
72-
}
73-
74-
private final class OnEndButtonClicked implements OnClickListener {
75-
@Override
76-
public void onClick(View v) {
77-
// Verhalten beim Click auf den Ende-Button
78-
EditText endTime = (EditText) findViewById(R.id.EndTime);
79-
endTime.setText(new Date().toString());
80-
_IsStarted = false;
81-
setButtonState();
82-
83-
DBHelper helper = new DBHelper(MainActivity.this);
84-
SQLiteDatabase db = helper.getReadableDatabase();
85-
Cursor data = db.query("zeit", // Tabelle
86-
new String[] { BaseColumns._ID }, // Spalten
87-
"IFNULL(end_time,'')=''", // Bedingung
88-
null, // Argumente für die bedingung
89-
null, // Grupierung
90-
null, // Having
91-
null); // Sortierung
92-
if (data != null && data.moveToFirst()) {
93-
// Datensatz gefunden, kann aktualisiert werden
94-
SQLiteDatabase updateDb = helper.getWritableDatabase();
95-
long id = data.getLong(0);
96-
97-
ContentValues values = new ContentValues();
98-
values.put("end_time", new Date().toString());
99-
100-
updateDb.update("zeit", values, "_id=?", new String[] { String.valueOf(id) });
101-
102-
updateDb.close();
103-
}
104-
105-
// Alles schließen
106-
if (data != null) {
107-
data.close();
108-
}
109-
db.close();
110-
helper.close();
111-
}
112-
}
113-
114-
private final class OnStartButtonClicked implements OnClickListener {
115-
@Override
116-
public void onClick(View v) {
117-
// Verhalten beim Klick auf den Strat Button
118-
EditText startTime = (EditText) findViewById(R.id.StartTime);
119-
startTime.setText(new Date().toString());
120-
_IsStarted = true;
121-
setButtonState();
122-
123-
DBHelper helper = new DBHelper(MainActivity.this);
124-
SQLiteDatabase db = helper.getWritableDatabase();
125-
126-
ContentValues values = new ContentValues();
127-
values.put("start_time", new Date().toString());
128-
129-
db.insert("zeit", null, values);
130-
131-
db.close();
132-
}
133-
}
20+
private boolean _IsStarted = false;
21+
22+
@Override
23+
protected void onCreate(Bundle savedInstanceState) {
24+
super.onCreate(savedInstanceState);
25+
26+
setContentView(R.layout.activity_main);
27+
28+
if (savedInstanceState != null) {
29+
_IsStarted = savedInstanceState.getBoolean("CurrentState", false);
30+
}
31+
32+
setButtonState();
33+
}
34+
35+
@Override
36+
protected void onStart() {
37+
super.onStart();
38+
39+
// Buttons registrieren
40+
Button commandStart = (Button) findViewById(R.id.StartCommand);
41+
Button commandEnd = (Button) findViewById(R.id.EndCommand);
42+
43+
// Click Event registrieren
44+
commandStart.setOnClickListener(new OnStartButtonClicked());
45+
46+
commandEnd.setOnClickListener(new OnEndButtonClicked());
47+
}
48+
49+
@Override
50+
protected void onSaveInstanceState(Bundle outState) {
51+
outState.putBoolean("CurrentState", _IsStarted);
52+
super.onSaveInstanceState(outState);
53+
}
54+
55+
@Override
56+
protected void onStop() {
57+
// Buttons registrieren
58+
Button commandStart = (Button) findViewById(R.id.StartCommand);
59+
Button commandEnd = (Button) findViewById(R.id.EndCommand);
60+
61+
// Click Event deregistrieren
62+
commandStart.setOnClickListener(null);
63+
commandEnd.setOnClickListener(null);
64+
super.onStop();
65+
}
66+
67+
private void setButtonState() {
68+
Button commandStart = (Button) findViewById(R.id.StartCommand);
69+
Button commandEnd = (Button) findViewById(R.id.EndCommand);
70+
71+
commandStart.setEnabled(_IsStarted == false);
72+
commandEnd.setEnabled(_IsStarted);
73+
}
74+
75+
private final class OnEndButtonClicked implements OnClickListener {
76+
@Override
77+
public void onClick(View v) {
78+
// Verhalten beim Click auf den Ende-Button
79+
EditText endTime = (EditText) findViewById(R.id.EndTime);
80+
endTime.setText(new Date().toString());
81+
_IsStarted = false;
82+
setButtonState();
83+
84+
DBHelper helper = new DBHelper(MainActivity.this);
85+
SQLiteDatabase db = helper.getReadableDatabase();
86+
Cursor data = db.query("zeit", // Tabelle
87+
new String[] { BaseColumns._ID }, // Spalten
88+
"IFNULL(end_time,'')=''", // Bedingung
89+
null, // Argumente für die bedingung
90+
null, // Grupierung
91+
null, // Having
92+
null); // Sortierung
93+
if (data != null && data.moveToFirst()) {
94+
// Datensatz gefunden, kann aktualisiert werden
95+
SQLiteDatabase updateDb = helper.getWritableDatabase();
96+
long id = data.getLong(0);
97+
98+
ContentValues values = new ContentValues();
99+
values.put("end_time", new Date().toString());
100+
101+
updateDb.update("zeit", values, "_id=?",
102+
new String[] { String.valueOf(id) });
103+
104+
updateDb.close();
105+
}
106+
107+
// Alles schließen
108+
if (data != null) {
109+
data.close();
110+
}
111+
db.close();
112+
helper.close();
113+
}
114+
}
115+
116+
private final class OnStartButtonClicked implements OnClickListener {
117+
@Override
118+
public void onClick(View v) {
119+
// Verhalten beim Klick auf den Strat Button
120+
EditText startTime = (EditText) findViewById(R.id.StartTime);
121+
startTime.setText(new Date().toString());
122+
_IsStarted = true;
123+
setButtonState();
124+
125+
// DBHelper helper = new DBHelper(MainActivity.this);
126+
// SQLiteDatabase db = helper.getWritableDatabase();
127+
//
128+
// ContentValues values = new ContentValues();
129+
// values.put("start_time", new Date().toString());
130+
//
131+
// db.insert("zeit", null, values);
132+
//
133+
// db.close();
134+
135+
ContentValues values = new ContentValues();
136+
values.put(ZeitContracts.Zeit.Columns.START, new Date().toString());
137+
138+
getContentResolver().insert(ZeitContracts.Zeit.CONTENT_URI, values);
139+
}
140+
141+
}
134142
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package de.mvhs.android.zeiterfassung.db;
2+
3+
import android.content.ContentResolver;
4+
import android.net.Uri;
5+
import android.provider.BaseColumns;
6+
7+
public final class ZeitContracts {
8+
/**
9+
* Basispfad für den Content-Provider
10+
*/
11+
public final static String BASE_PATH = "de.mvhs.android.zeiterfassung.zeitprovider";
12+
13+
/**
14+
* Authority des Content Providers (eideutige kennung innerhalb der Android
15+
* Betriebssystems
16+
*/
17+
public final static Uri AUTHORITY_URI = Uri.parse("content://" + BASE_PATH);
18+
19+
/**
20+
* Klasse für die Beschreibung der Tabelle
21+
*/
22+
public final static class Zeit {
23+
/**
24+
* Pfad zur Tabelle
25+
*/
26+
public final static String CONTENT_DIRECTORY = "zeit";
27+
28+
/**
29+
* Uri für den Zugriff auf die Daten der Tabelle
30+
*/
31+
public final static Uri CONTENT_URI = Uri.withAppendedPath(
32+
AUTHORITY_URI, CONTENT_DIRECTORY);
33+
34+
/**
35+
* Datentyp für die Auflistung der Zeit-Einträge
36+
*/
37+
public final static String CONTENT_TYPE = ContentResolver.CURSOR_DIR_BASE_TYPE
38+
+ "/" + CONTENT_DIRECTORY;
39+
/**
40+
* Datentyp für einen einzelnen Datensatz
41+
*/
42+
public final static String CONTENT_ITEM_TYPE = ContentResolver.CURSOR_ITEM_BASE_TYPE
43+
+ "/" + CONTENT_DIRECTORY;
44+
45+
/**
46+
* Verfügbare Spalten der Tabelle Zeit
47+
*/
48+
public static interface Columns extends BaseColumns {
49+
/**
50+
* Spaltenname für die Start-Spalte
51+
*/
52+
public final static String START = "start_time";
53+
54+
/**
55+
* Spaltenname für die Ende-Spalte
56+
*/
57+
public final static String END = "end_time";
58+
}
59+
60+
/**
61+
* Verhinder die Initialisierung der Klasse
62+
*/
63+
private Zeit() {
64+
65+
}
66+
}
67+
68+
/**
69+
* Verhindert die Initialisierung der Klasse
70+
*/
71+
private ZeitContracts() {
72+
73+
}
74+
75+
}

0 commit comments

Comments
 (0)