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

Commit

Permalink
Stand 07.04.2014
Browse files Browse the repository at this point in the history
  • Loading branch information
WebDucer committed Apr 7, 2014
1 parent bb5b99f commit a7ebcec
Show file tree
Hide file tree
Showing 7 changed files with 233 additions and 85 deletions.
1 change: 1 addition & 0 deletions Zeiterfassung/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<provider
android:name=".db.ZeitProvider"
android:authorities="de.mvhs.android.zeiterfassung.zeitprovider" />
<activity android:name="AuflistungActivity"></activity>
</application>

</manifest>
8 changes: 8 additions & 0 deletions Zeiterfassung/res/layout/activity_list.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@android:id/list" >


</ListView>
6 changes: 6 additions & 0 deletions Zeiterfassung/res/menu/main_menu.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/mnu_list" android:title="@string/mnu_list" android:showAsAction="ifRoom"></item>


</menu>
1 change: 1 addition & 0 deletions Zeiterfassung/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
<string name="EndButton">BEENDEN</string>
<string name="PauseLabel">Pause:</string>
<string name="CommentLabel">Kommentar:</string>
<string name="mnu_list">Auflistung</string>

</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package de.mvhs.android.zeiterfassung;

import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.view.MenuItem;
import android.widget.SimpleCursorAdapter;
import de.mvhs.android.zeiterfassung.db.ZeitContracts;

public class AuflistungActivity extends ListActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_list);

getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setDisplayShowHomeEnabled(true);
}

@Override
protected void onStart() {
super.onStart();

// Laden der Daten
// -- Einen Adapter initialisieren
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, // Context
android.R.layout.simple_list_item_2, // Layout für die Zeile
null, // Cursor Daten
new String[] { ZeitContracts.Zeit.Columns.START,
ZeitContracts.Zeit.Columns.END }, new int[] {
android.R.id.text1, android.R.id.text2 }, // UI-Elemente
// in denen
// diese
// Werte
// dargestellt
// werden
// sollen
0);

// Laden der Daten
Cursor data = getContentResolver().query(
ZeitContracts.Zeit.CONTENT_URI, null, null, null, null);

// Zuordnung des Adapters zur Liste
getListView().setAdapter(adapter);

// Daten an Adapter übergeben
adapter.swapCursor(data);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
this.finish();

break;

default:
break;
}
return super.onOptionsItemSelected(item);
}
}
226 changes: 141 additions & 85 deletions Zeiterfassung/src/de/mvhs/android/zeiterfassung/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package de.mvhs.android.zeiterfassung;

import java.text.DateFormat;
import java.text.ParseException;
import java.util.Date;

import android.app.Activity;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
Expand All @@ -16,118 +21,169 @@

public class MainActivity extends Activity {

private boolean _IsStarted = false;
private Button _StartCommand = null;
private Button _StopCommand = null;
private EditText _StartTime = null;
private EditText _EndTime = null;
private long _CurrentId = -1;
private boolean _IsStarted = false;
private Button _StartCommand = null;
private Button _StopCommand = null;
private EditText _StartTime = null;
private EditText _EndTime = null;
private long _CurrentId = -1;

private final static String[] _SEARCH_PROJECTION = { ZeitContracts.Zeit.Columns._ID, ZeitContracts.Zeit.Columns.START };
private final static String _SEARCH_SELECTION = "IFNULL(" + ZeitContracts.Zeit.Columns.START + ",'')=''";
private final static String[] _SEARCH_PROJECTION = {
ZeitContracts.Zeit.Columns._ID, ZeitContracts.Zeit.Columns.START };
private final static String _SEARCH_SELECTION = "IFNULL("
+ ZeitContracts.Zeit.Columns.END + ",'')=''";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
private final static DateFormat _UI_DATE_FORMATTER = DateFormat
.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);

setContentView(R.layout.activity_main);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

@Override
protected void onStart() {
super.onStart();
setContentView(R.layout.activity_main);
}

// UI Elemente initialisieren
_StartCommand = (Button) findViewById(R.id.StartCommand);
_StopCommand = (Button) findViewById(R.id.EndCommand);
_StartTime = (EditText) findViewById(R.id.StartTime);
_EndTime = (EditText) findViewById(R.id.EndTime);
@Override
protected void onStart() {
super.onStart();

// Click Event registrieren
_StartCommand.setOnClickListener(new OnStartButtonClicked());
_StopCommand.setOnClickListener(new OnEndButtonClicked());
// UI Elemente initialisieren
_StartCommand = (Button) findViewById(R.id.StartCommand);
_StopCommand = (Button) findViewById(R.id.EndCommand);
_StartTime = (EditText) findViewById(R.id.StartTime);
_EndTime = (EditText) findViewById(R.id.EndTime);

// Bearbeitung in den Textfeldern verbieten
_StartTime.setKeyListener(null);
_EndTime.setKeyListener(null);
// Click Event registrieren
_StartCommand.setOnClickListener(new OnStartButtonClicked());
_StopCommand.setOnClickListener(new OnEndButtonClicked());

// Prüfen, ob ein angefangener Eintrag in der Datenbank vorliegt
checkTrackState();
}
// Bearbeitung in den Textfeldern verbieten
_StartTime.setKeyListener(null);
_EndTime.setKeyListener(null);

@Override
protected void onStop() {
// Click Event deregistrieren
_StartCommand.setOnClickListener(null);
_StopCommand.setOnClickListener(null);
// Prüfen, ob ein angefangener Eintrag in der Datenbank vorliegt
checkTrackState();
}

super.onStop();
}
@Override
protected void onStop() {
// Click Event deregistrieren
_StartCommand.setOnClickListener(null);
_StopCommand.setOnClickListener(null);

private void setButtonState() {
super.onStop();
}

_StartCommand.setEnabled(_IsStarted == false);
_StopCommand.setEnabled(_IsStarted);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_menu, menu);

private void checkTrackState() {
Cursor data = getContentResolver().query(ZeitContracts.Zeit.CONTENT_URI, _SEARCH_PROJECTION, _SEARCH_SELECTION, null, null);
return super.onCreateOptionsMenu(menu);
}

if (data != null && data.moveToFirst()) {
// Ein Eintrag gefunden
_CurrentId = data.getLong(0);
@Override
public boolean onOptionsItemSelected(MenuItem item) {

String startDate = data.getString(1);
// Menüpunkt herausfinden
switch (item.getItemId()) {
case R.id.mnu_list:
// Aktion für unser List-Menü-Eintrag
Intent listIntent = new Intent(this, AuflistungActivity.class);
startActivity(listIntent);
break;

_StartTime.setText(startDate);
_EndTime.setText("");
default:
break;
}

_IsStarted = true;
} else {
// Keine Einträge gefunden
_StartTime.setText("");
_EndTime.setText("");
return super.onOptionsItemSelected(item);
}

_IsStarted = false;
}
private void setButtonState() {

setButtonState();
}
_StartCommand.setEnabled(_IsStarted == false);
_StopCommand.setEnabled(_IsStarted);
}

private final class OnEndButtonClicked implements OnClickListener {
@Override
public void onClick(View v) {
// Verhalten beim Click auf den Ende-Button
Date currentTime = new Date();
_EndTime.setText(currentTime.toString());
private void checkTrackState() {
Cursor data = getContentResolver().query(
ZeitContracts.Zeit.CONTENT_URI, _SEARCH_PROJECTION,
_SEARCH_SELECTION, null, null);

ContentValues values = new ContentValues();
values.put(ZeitContracts.Zeit.Columns.END, currentTime.toString());
if (data != null && data.moveToFirst()) {
// Ein Eintrag gefunden
_CurrentId = data.getLong(0);

Uri updateUri = ContentUris.withAppendedId(ZeitContracts.Zeit.CONTENT_URI, _CurrentId);
String startDate = data.getString(1);

getContentResolver().update(updateUri, values, null, null);
try {
// Konvertierung des Datums aus der Datenbank
Date startTime = ZeitContracts.Converters.DB_FORMATTER
.parse(startDate);

_IsStarted = false;
setButtonState();
}
}
// Ausgabe an der UI
_StartTime.setText(_UI_DATE_FORMATTER.format(startTime));

private final class OnStartButtonClicked implements OnClickListener {
@Override
public void onClick(View v) {
// Verhalten beim Klick auf den Strat Button
Date currentTime = new Date();
_StartTime.setText(currentTime.toString());
} catch (ParseException e) {
e.printStackTrace();
}

ContentValues values = new ContentValues();
values.put(ZeitContracts.Zeit.Columns.START, currentTime.toString());
_EndTime.setText("");

getContentResolver().insert(ZeitContracts.Zeit.CONTENT_URI, values);
_IsStarted = true;
} else {
// Keine Einträge gefunden
_StartTime.setText("");
_EndTime.setText("");

_IsStarted = true;
setButtonState();
}
_IsStarted = false;
}

}
setButtonState();
}

private final class OnEndButtonClicked implements OnClickListener {
@Override
public void onClick(View v) {
// Verhalten beim Click auf den Ende-Button
Date currentTime = new Date();
_EndTime.setText(_UI_DATE_FORMATTER.format(currentTime));

ContentValues values = new ContentValues();
values.put(ZeitContracts.Zeit.Columns.END,
ZeitContracts.Converters.DB_FORMATTER.format(currentTime));

Uri updateUri = ContentUris.withAppendedId(
ZeitContracts.Zeit.CONTENT_URI, _CurrentId);

getContentResolver().update(updateUri, values, null, null);

_CurrentId = -1;

_IsStarted = false;
setButtonState();
}
}

private final class OnStartButtonClicked implements OnClickListener {
@Override
public void onClick(View v) {
// Verhalten beim Klick auf den Strat Button
Date currentTime = new Date();
_StartTime.setText(_UI_DATE_FORMATTER.format(currentTime));

ContentValues values = new ContentValues();
values.put(ZeitContracts.Zeit.Columns.START,
ZeitContracts.Converters.DB_FORMATTER.format(currentTime));

Uri insertUri = getContentResolver().insert(
ZeitContracts.Zeit.CONTENT_URI, values);

_CurrentId = ContentUris.parseId(insertUri);

_IsStarted = true;
setButtonState();
}

}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package de.mvhs.android.zeiterfassung.db;

import java.text.DateFormat;
import java.text.SimpleDateFormat;

import android.content.ContentResolver;
import android.net.Uri;
import android.provider.BaseColumns;
Expand All @@ -16,6 +19,14 @@ public final class ZeitContracts {
*/
public final static Uri AUTHORITY_URI = Uri.parse("content://" + BASE_PATH);

public final static class Converters {
// Format Pattern
private final static String _DB_DATE_PATTERN = "yyyy-MM-dd'T'HH:mm";

public final static DateFormat DB_FORMATTER = new SimpleDateFormat(
_DB_DATE_PATTERN);
}

/**
* Klasse für die Beschreibung der Tabelle
*/
Expand Down

0 comments on commit a7ebcec

Please sign in to comment.