First commit
This commit is contained in:
commit
e67f622cca
7
.classpath
Normal file
7
.classpath
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="gen"/>
|
||||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
33
.project
Normal file
33
.project
Normal file
@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Waldemar</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
27
AndroidManifest.xml
Normal file
27
AndroidManifest.xml
Normal file
@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="de.schatenseite.android.waldemar" android:versionCode="1"
|
||||
android:versionName="1.0">
|
||||
<application android:icon="@drawable/icon" android:label="@string/app_name"
|
||||
android:debuggable="true">
|
||||
|
||||
<receiver android:name=".WaldemarWidget" android:label="@string/app_name">
|
||||
<intent-filter>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="MIDNIGHTLY_WIDGET_UPDATE" />
|
||||
</intent-filter>
|
||||
<meta-data android:name="android.appwidget.provider"
|
||||
android:resource="@xml/waldemar_info" />
|
||||
</receiver>
|
||||
<!-- <activity android:name=".WaldemarConfig" android:label="Waldemar Config"> -->
|
||||
<activity android:name=".WaldemarPreferences" android:label="@string/preferences">
|
||||
<intent-filter>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
<uses-sdk android:minSdkVersion="8" />
|
||||
|
||||
</manifest>
|
11
default.properties
Normal file
11
default.properties
Normal file
@ -0,0 +1,11 @@
|
||||
# This file is automatically generated by Android Tools.
|
||||
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
|
||||
#
|
||||
# This file must be checked in Version Control Systems.
|
||||
#
|
||||
# To customize properties used by the Ant build system use,
|
||||
# "build.properties", and override values to adapt the script to your
|
||||
# project structure.
|
||||
|
||||
# Project target.
|
||||
target=android-8
|
34
proguard.cfg
Normal file
34
proguard.cfg
Normal file
@ -0,0 +1,34 @@
|
||||
-optimizationpasses 5
|
||||
-dontusemixedcaseclassnames
|
||||
-dontskipnonpubliclibraryclasses
|
||||
-dontpreverify
|
||||
-verbose
|
||||
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
|
||||
|
||||
-keep public class * extends android.app.Activity
|
||||
-keep public class * extends android.app.Application
|
||||
-keep public class * extends android.app.Service
|
||||
-keep public class * extends android.content.BroadcastReceiver
|
||||
-keep public class * extends android.content.ContentProvider
|
||||
-keep public class com.android.vending.licensing.ILicensingService
|
||||
|
||||
-keepclasseswithmembernames class * {
|
||||
native <methods>;
|
||||
}
|
||||
|
||||
-keepclasseswithmembernames class * {
|
||||
public <init>(android.content.Context, android.util.AttributeSet);
|
||||
}
|
||||
|
||||
-keepclasseswithmembernames class * {
|
||||
public <init>(android.content.Context, android.util.AttributeSet, int);
|
||||
}
|
||||
|
||||
-keepclassmembers enum * {
|
||||
public static **[] values();
|
||||
public static ** valueOf(java.lang.String);
|
||||
}
|
||||
|
||||
-keep class * implements android.os.Parcelable {
|
||||
public static final android.os.Parcelable$Creator *;
|
||||
}
|
BIN
res/drawable-hdpi/icon.png
Normal file
BIN
res/drawable-hdpi/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.0 KiB |
BIN
res/drawable-ldpi/icon.png
Normal file
BIN
res/drawable-ldpi/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
BIN
res/drawable-mdpi/icon.png
Normal file
BIN
res/drawable-mdpi/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.5 KiB |
BIN
res/drawable/background.png
Normal file
BIN
res/drawable/background.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 405 B |
26
res/layout/config.xml
Normal file
26
res/layout/config.xml
Normal file
@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent" android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
<TextView android:text="@string/name" android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
<EditText android:text="@string/title" android:id="@+id/name"
|
||||
android:layout_width="fill_parent" android:layout_height="wrap_content" />
|
||||
<TextView android:text="@string/dateThen"
|
||||
android:layout_width="fill_parent" android:layout_height="wrap_content" />
|
||||
<DatePicker android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content" android:id="@+id/dateThen">
|
||||
</DatePicker>
|
||||
<LinearLayout android:id="@+id/LinearLayout01"
|
||||
android:layout_width="fill_parent" android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
<Button android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content" android:id="@+id/okbutton"
|
||||
android:text="OK"></Button>
|
||||
<Button android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content" android:text="Cancel"
|
||||
android:id="@+id/cancelbutton"></Button>
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</LinearLayout>
|
26
res/layout/main.xml
Normal file
26
res/layout/main.xml
Normal file
@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/LinearLayout01" android:layout_height="100dp"
|
||||
android:layout_width="80dp" android:background="@drawable/background"
|
||||
android:gravity="center" android:orientation="vertical">
|
||||
|
||||
<TextView android:id="@+id/name" android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content" android:gravity="center"
|
||||
android:textColor="@android:color/white" android:text="@string/title"
|
||||
android:textSize="5pt" />
|
||||
|
||||
<TextView android:id="@+id/daycount" android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content" android:gravity="center"
|
||||
android:textColor="@android:color/white" android:text="@string/notyet"
|
||||
android:paddingBottom="0dp" android:textStyle="bold" android:textSize="10pt" />
|
||||
|
||||
<TextView android:id="@+id/days" android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content" android:gravity="center"
|
||||
android:textColor="@android:color/white" android:text="@string/days"
|
||||
android:paddingTop="0dp" android:textSize="4pt" />
|
||||
|
||||
<TextView android:id="@+id/debug" android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content" android:gravity="center"
|
||||
android:textColor="@android:color/white" android:text="debug"
|
||||
android:textSize="4pt" />
|
||||
</LinearLayout>
|
15
res/values/arrays.xml
Normal file
15
res/values/arrays.xml
Normal file
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string-array name="modes">
|
||||
<item>@string/mode1</item>
|
||||
<item>@string/mode2</item>
|
||||
<item>@string/mode3</item>
|
||||
<item>@string/mode4</item>
|
||||
</string-array>
|
||||
<string-array name="modes_values">
|
||||
<item>1</item>
|
||||
<item>2</item>
|
||||
<item>3</item>
|
||||
<item>4</item>
|
||||
</string-array>
|
||||
</resources>
|
28
res/values/strings.xml
Normal file
28
res/values/strings.xml
Normal file
@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="app_name">Waldemar</string>
|
||||
<string name="title">Waldemar</string>
|
||||
<string name="preferences">Waldemar Einstellungen</string>
|
||||
<string name="common">Allgemein</string>
|
||||
<string name="days">Tage</string>
|
||||
<string name="notyet">NaN</string>
|
||||
<string name="name">Name</string>
|
||||
<string name="name_summary">Überschrift des Widgets</string>
|
||||
<string name="name_prompt">Bitte eine Überschrift für das Widget eingeben</string>
|
||||
<string name="name_default">Waldemar</string>
|
||||
<string name="timing">Zeiteinstellung</string>
|
||||
<string name="mode">Modus</string>
|
||||
<string name="mode_summary">Welche Daten sind gegeben?</string>
|
||||
<string name="mode1">Nur Zieldatum</string>
|
||||
<string name="mode2">Start- und Zieldatum</string>
|
||||
<string name="mode3">Dauer und Zieldatum</string>
|
||||
<string name="mode4">Startdatum und Dauer</string>
|
||||
<string name="dateStart">Startdatum</string>
|
||||
<string name="dateStart_summary">Wann beginnt der Countdown?</string>
|
||||
<string name="duration">Dauer</string>
|
||||
<string name="duration_summary">Wie lang ist der Countdown?</string>
|
||||
<string name="duration_prompt">Bitte die Dauer in Tagen eingeben</string>
|
||||
<string name="duration_default">267</string>
|
||||
<string name="dateThen">Zieldatum</string>
|
||||
<string name="dateThen_summary">Wann endet der Countdown?</string>
|
||||
</resources>
|
25
res/xml/preferences.xml
Normal file
25
res/xml/preferences.xml
Normal file
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<PreferenceCategory android:title="@string/common">
|
||||
<EditTextPreference android:dialogTitle="@string/name_summary"
|
||||
android:dialogMessage="@string/name_prompt" android:title="@string/name"
|
||||
android:summary="@string/name_summary" android:defaultValue="@string/name_default"
|
||||
android:key="pref_name" android:singleLine="true" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory android:title="@string/timing">
|
||||
<ListPreference android:title="@string/mode"
|
||||
android:summary="@string/mode_summary" android:key="pref_mode"
|
||||
android:defaultValue="1" android:entries="@array/modes"
|
||||
android:entryValues="@array/modes_values" />
|
||||
<de.schatenseite.android.datepreference.DatePreference
|
||||
android:key="pref_dateStart" android:title="@string/dateStart"
|
||||
android:summary="@string/dateStart_summary" />
|
||||
<EditTextPreference android:dialogTitle="@string/duration_summary"
|
||||
android:dialogMessage="@string/duration_prompt" android:title="@string/duration"
|
||||
android:summary="@string/duration_summary" android:defaultValue="@string/duration_default"
|
||||
android:key="pref_duration" android:singleLine="true" android:numeric="integer" />
|
||||
<de.schatenseite.android.datepreference.DatePreference
|
||||
android:key="pref_dateThen" android:title="@string/dateThen"
|
||||
android:summary="@string/dateThen_summary" />
|
||||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
7
res/xml/waldemar_info.xml
Normal file
7
res/xml/waldemar_info.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<appwidget-provider
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:minWidth="72dp"
|
||||
android:minHeight="72dp"
|
||||
android:configure="de.schatenseite.android.waldemar.WaldemarPreferences"
|
||||
android:initialLayout="@layout/main" />
|
280
src/de/schatenseite/android/datepreference/DatePreference.java
Normal file
280
src/de/schatenseite/android/datepreference/DatePreference.java
Normal file
@ -0,0 +1,280 @@
|
||||
package de.schatenseite.android.datepreference;
|
||||
|
||||
/* based on https://github.com/bostonandroid/DatePreference */
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.TypedArray;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.preference.DialogPreference;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.DatePicker;
|
||||
|
||||
public class DatePreference extends DialogPreference implements
|
||||
DatePicker.OnDateChangedListener {
|
||||
private String dateString;
|
||||
private String changedValueCanBeNull;
|
||||
private DatePicker datePicker;
|
||||
|
||||
public DatePreference(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
}
|
||||
|
||||
public DatePreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Produces a DatePicker set to the date produced by {@link #getDate()}.
|
||||
* When overriding be sure to call the super.
|
||||
*
|
||||
* @return a DatePicker with the date set
|
||||
*/
|
||||
@Override
|
||||
protected View onCreateDialogView() {
|
||||
this.datePicker = new DatePicker(getContext());
|
||||
Calendar calendar = getDate();
|
||||
datePicker.init(calendar.get(Calendar.YEAR),
|
||||
calendar.get(Calendar.MONTH),
|
||||
calendar.get(Calendar.DAY_OF_MONTH), this);
|
||||
return datePicker;
|
||||
}
|
||||
|
||||
/**
|
||||
* Produces the date used for the date picker. If the user has not selected
|
||||
* a date, produces the default from the XML's android:defaultValue. If the
|
||||
* default is not set in the XML or if the XML's default is invalid it uses
|
||||
* the value produced by {@link #defaultCalendar()}.
|
||||
*
|
||||
* @return the Calendar for the date picker
|
||||
*/
|
||||
public Calendar getDate() {
|
||||
try {
|
||||
Date date = formatter().parse(defaultValue());
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(date);
|
||||
return cal;
|
||||
} catch (java.text.ParseException e) {
|
||||
return defaultCalendar();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the selected date to the specified string.
|
||||
*
|
||||
* @param dateString
|
||||
* The date, represented as a string, in the format specified by
|
||||
* {@link #formatter()}.
|
||||
*/
|
||||
public void setDate(String dateString) {
|
||||
this.dateString = dateString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Produces the date formatter used for dates in the XML. The default is
|
||||
* yyyy.MM.dd. Override this to change that.
|
||||
*
|
||||
* @return the SimpleDateFormat used for XML dates
|
||||
*/
|
||||
public static SimpleDateFormat formatter() {
|
||||
return new SimpleDateFormat("yyyy.MM.dd");
|
||||
}
|
||||
|
||||
/**
|
||||
* Produces the date formatter used for showing the date in the summary. The
|
||||
* default is MMMM dd, yyyy. Override this to change it.
|
||||
*
|
||||
* @return the SimpleDateFormat used for summary dates
|
||||
*/
|
||||
public static SimpleDateFormat summaryFormatter() {
|
||||
return new SimpleDateFormat("dd. MMMM yyyy");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object onGetDefaultValue(TypedArray a, int index) {
|
||||
return a.getString(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the date picker is shown or restored. If it's a restore it
|
||||
* gets the persisted value, otherwise it persists the value.
|
||||
*/
|
||||
@Override
|
||||
protected void onSetInitialValue(boolean restoreValue, Object def) {
|
||||
if (restoreValue) {
|
||||
this.dateString = getPersistedString(defaultValue());
|
||||
setTheDate(this.dateString);
|
||||
} else {
|
||||
boolean wasNull = this.dateString == null;
|
||||
setDate((String) def);
|
||||
if (!wasNull)
|
||||
persistDate(this.dateString);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when Android pauses the activity.
|
||||
*/
|
||||
@Override
|
||||
protected Parcelable onSaveInstanceState() {
|
||||
if (isPersistent())
|
||||
return super.onSaveInstanceState();
|
||||
else
|
||||
return new SavedState(super.onSaveInstanceState());
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when Android restores the activity.
|
||||
*/
|
||||
@Override
|
||||
protected void onRestoreInstanceState(Parcelable state) {
|
||||
if (state == null || !state.getClass().equals(SavedState.class)) {
|
||||
super.onRestoreInstanceState(state);
|
||||
setTheDate(((SavedState) state).dateValue);
|
||||
} else {
|
||||
SavedState s = (SavedState) state;
|
||||
super.onRestoreInstanceState(s.getSuperState());
|
||||
setTheDate(s.dateValue);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the user changes the date.
|
||||
*/
|
||||
public void onDateChanged(DatePicker view, int year, int month, int day) {
|
||||
Calendar selected = new GregorianCalendar(year, month, day);
|
||||
this.changedValueCanBeNull = formatter().format(selected.getTime());
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the dialog is closed. If the close was by pressing "OK" it
|
||||
* saves the value.
|
||||
*/
|
||||
@Override
|
||||
protected void onDialogClosed(boolean shouldSave) {
|
||||
if (shouldSave && this.changedValueCanBeNull != null) {
|
||||
setTheDate(this.changedValueCanBeNull);
|
||||
this.changedValueCanBeNull = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void setTheDate(String s) {
|
||||
setDate(s);
|
||||
persistDate(s);
|
||||
}
|
||||
|
||||
public String getSummaryString() {
|
||||
return summaryFormatter().format(getDate().getTime());
|
||||
}
|
||||
|
||||
private void persistDate(String s) {
|
||||
persistString(s);
|
||||
//setSummary(summaryFormatter().format(getDate().getTime()));
|
||||
}
|
||||
|
||||
/**
|
||||
* The default date to use when the XML does not set it or the XML has an
|
||||
* error.
|
||||
*
|
||||
* @return the Calendar set to the default date
|
||||
*/
|
||||
public static Calendar defaultCalendar() {
|
||||
return new GregorianCalendar();
|
||||
}
|
||||
|
||||
/**
|
||||
* The defaultCalendar() as a string using the {@link #formatter()}.
|
||||
*
|
||||
* @return a String representation of the default date
|
||||
*/
|
||||
public static String defaultCalendarString() {
|
||||
return formatter().format(defaultCalendar().getTime());
|
||||
}
|
||||
|
||||
private String defaultValue() {
|
||||
if (this.dateString == null)
|
||||
setDate(defaultCalendarString());
|
||||
return this.dateString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called whenever the user clicks on a button. Invokes
|
||||
* {@link #onDateChanged(DatePicker, int, int, int)} and
|
||||
* {@link #onDialogClosed(boolean)}. Be sure to call the super when
|
||||
* overriding.
|
||||
*/
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
super.onClick(dialog, which);
|
||||
datePicker.clearFocus();
|
||||
onDateChanged(datePicker, datePicker.getYear(), datePicker.getMonth(),
|
||||
datePicker.getDayOfMonth());
|
||||
onDialogClosed(which == DialogInterface.BUTTON1); // OK?
|
||||
}
|
||||
|
||||
/**
|
||||
* Produces the date the user has selected for the given preference, as a
|
||||
* calendar.
|
||||
*
|
||||
* @param preferences
|
||||
* the SharedPreferences to get the date from
|
||||
* @param field
|
||||
* the name of the preference to get the date from
|
||||
* @return a Calendar that the user has selected
|
||||
*/
|
||||
public static Calendar getDateFor(SharedPreferences preferences,
|
||||
String field) {
|
||||
Date date = stringToDate(preferences.getString(field,
|
||||
defaultCalendarString()));
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(date);
|
||||
return cal;
|
||||
}
|
||||
|
||||
private static Date stringToDate(String dateString) {
|
||||
try {
|
||||
return formatter().parse(dateString);
|
||||
} catch (ParseException e) {
|
||||
return defaultCalendar().getTime();
|
||||
}
|
||||
}
|
||||
|
||||
private static class SavedState extends BaseSavedState {
|
||||
String dateValue;
|
||||
|
||||
public SavedState(Parcel p) {
|
||||
super(p);
|
||||
dateValue = p.readString();
|
||||
}
|
||||
|
||||
public SavedState(Parcelable p) {
|
||||
super(p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel out, int flags) {
|
||||
super.writeToParcel(out, flags);
|
||||
out.writeString(dateValue);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static final Parcelable.Creator<SavedState> CREATOR = new Parcelable.Creator<SavedState>() {
|
||||
public SavedState createFromParcel(Parcel in) {
|
||||
return new SavedState(in);
|
||||
}
|
||||
|
||||
public SavedState[] newArray(int size) {
|
||||
return new SavedState[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
103
src/de/schatenseite/android/waldemar/WaldemarPreferences.java
Normal file
103
src/de/schatenseite/android/waldemar/WaldemarPreferences.java
Normal file
@ -0,0 +1,103 @@
|
||||
package de.schatenseite.android.waldemar;
|
||||
|
||||
import android.appwidget.AppWidgetManager;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.preference.EditTextPreference;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.preference.PreferenceManager;
|
||||
import de.schatenseite.android.datepreference.DatePreference;
|
||||
|
||||
public class WaldemarPreferences extends PreferenceActivity {
|
||||
int widgetId;
|
||||
public void enableDisablePreferences(String val) {
|
||||
EditTextPreference pref_name = (EditTextPreference)findPreference("pref_name");
|
||||
ListPreference pref_mode = (ListPreference)findPreference("pref_mode");
|
||||
EditTextPreference pref_duration = (EditTextPreference)findPreference("pref_duration");
|
||||
DatePreference pref_dateStart = (DatePreference)findPreference("pref_dateStart");
|
||||
DatePreference pref_dateThen = (DatePreference)findPreference("pref_dateThen");
|
||||
|
||||
pref_name.setSummary(pref_name.getText());
|
||||
|
||||
int index = pref_mode.findIndexOfValue(val);
|
||||
if (index == 0) {
|
||||
pref_mode.setSummary(R.string.mode1);
|
||||
pref_duration.setEnabled(false);
|
||||
pref_duration.setSummary(R.string.duration_summary);
|
||||
pref_dateStart.setEnabled(false);
|
||||
pref_dateStart.setSummary(R.string.dateStart_summary);
|
||||
pref_dateThen.setEnabled(true);
|
||||
pref_dateThen.setSummary(pref_dateThen.getSummaryString());
|
||||
} else if (index == 1) {
|
||||
pref_mode.setSummary(R.string.mode2);
|
||||
pref_duration.setEnabled(false);
|
||||
pref_duration.setSummary(R.string.duration_summary);
|
||||
pref_dateStart.setEnabled(true);
|
||||
pref_dateStart.setSummary(pref_dateStart.getSummaryString());
|
||||
pref_dateThen.setEnabled(true);
|
||||
pref_dateThen.setSummary(pref_dateThen.getSummaryString());
|
||||
} else if (index == 2) {
|
||||
pref_mode.setSummary(R.string.mode3);
|
||||
pref_duration.setEnabled(true);
|
||||
pref_duration.setSummary(pref_duration.getText()+" "+getApplicationContext().getString(R.string.days));
|
||||
pref_dateStart.setEnabled(false);
|
||||
pref_dateStart.setSummary(R.string.dateStart_summary);
|
||||
pref_dateThen.setEnabled(true);
|
||||
pref_dateThen.setSummary(pref_dateThen.getSummaryString());
|
||||
} else if (index == 3) {
|
||||
pref_mode.setSummary(R.string.mode4);
|
||||
pref_duration.setEnabled(true);
|
||||
pref_duration.setSummary(pref_duration.getText()+" "+getApplicationContext().getString(R.string.days));
|
||||
pref_dateStart.setEnabled(true);
|
||||
pref_dateStart.setSummary(pref_dateStart.getSummaryString());
|
||||
pref_dateThen.setEnabled(false);
|
||||
pref_dateThen.setSummary(R.string.dateThen_summary);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
|
||||
addPreferencesFromResource(R.xml.preferences);
|
||||
|
||||
Intent intent=getIntent();
|
||||
Bundle extras=intent.getExtras();
|
||||
if (extras != null) {
|
||||
widgetId=extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
|
||||
}
|
||||
|
||||
final EditTextPreference pref_name = (EditTextPreference)findPreference("pref_name");
|
||||
final ListPreference pref_mode = (ListPreference)findPreference("pref_mode");
|
||||
|
||||
String val = pref_mode.getValue();
|
||||
enableDisablePreferences(val);
|
||||
|
||||
pref_name.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
pref_name.setSummary((CharSequence)newValue);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
pref_mode.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
final String val = newValue.toString();
|
||||
enableDisablePreferences(val);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
// this is the intent broadcast/returned to the widget
|
||||
Intent updateIntent = new Intent(this, WaldemarWidget.class);
|
||||
updateIntent.setAction("PreferencesUpdated");
|
||||
updateIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);
|
||||
setResult(RESULT_OK, updateIntent);
|
||||
sendBroadcast(updateIntent);
|
||||
finish();
|
||||
}
|
||||
}
|
111
src/de/schatenseite/android/waldemar/WaldemarWidget.java
Normal file
111
src/de/schatenseite/android/waldemar/WaldemarWidget.java
Normal file
@ -0,0 +1,111 @@
|
||||
package de.schatenseite.android.waldemar;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.Locale;
|
||||
|
||||
import android.app.AlarmManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.appwidget.AppWidgetManager;
|
||||
import android.appwidget.AppWidgetProvider;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.widget.RemoteViews;
|
||||
import android.widget.Toast;
|
||||
import de.schatenseite.android.datepreference.DatePreference;
|
||||
|
||||
public class WaldemarWidget extends AppWidgetProvider {
|
||||
public static String MIDNIGHTLY_WIDGET_UPDATE = "MIDNIGHTLY_WIDGET_UPDATE";
|
||||
static AlarmManager myAlarmManager;
|
||||
static PendingIntent myPendingIntent;
|
||||
|
||||
@Override
|
||||
public void onEnabled(Context context) {
|
||||
Intent intent = new Intent(
|
||||
WaldemarWidget.MIDNIGHTLY_WIDGET_UPDATE);
|
||||
PendingIntent pendingIntent = PendingIntent.getBroadcast(
|
||||
context, 0, intent, 0);
|
||||
AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
|
||||
Calendar calendar = new GregorianCalendar();
|
||||
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
|
||||
alarmManager.setRepeating(AlarmManager.RTC,
|
||||
calendar.getTimeInMillis(), AlarmManager.INTERVAL_FIFTEEN_MINUTES, pendingIntent);
|
||||
|
||||
WaldemarWidget.SaveAlarmManager(alarmManager, pendingIntent);
|
||||
Toast.makeText(context, "onEnabled()", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisabled(Context context) {
|
||||
myAlarmManager.cancel(myPendingIntent);
|
||||
Toast.makeText(context, "onDisabled()", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (MIDNIGHTLY_WIDGET_UPDATE.equals(intent.getAction()) || "PreferencesUpdated".equals(intent.getAction())) {
|
||||
Bundle extras = intent.getExtras();
|
||||
if (extras != null) {
|
||||
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
|
||||
ComponentName thisAppWidget = new ComponentName(
|
||||
context.getPackageName(),
|
||||
WaldemarWidget.class.getName());
|
||||
int[] appWidgetIds = appWidgetManager.getAppWidgetIds(thisAppWidget);
|
||||
|
||||
onUpdate(context, appWidgetManager, appWidgetIds);
|
||||
}
|
||||
} else {
|
||||
super.onReceive(context, intent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
|
||||
int[] appWidgetIds) {
|
||||
for (int appWidgetId : appWidgetIds) {
|
||||
updateAppWidget(context, appWidgetManager, appWidgetId);
|
||||
}
|
||||
}
|
||||
|
||||
public static void updateAppWidget(Context context,
|
||||
AppWidgetManager appWidgetManager, int appWidgetId) {
|
||||
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.main);
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
remoteViews.setTextViewText(R.id.name, prefs.getString("pref_name", context.getString(R.string.title)));
|
||||
|
||||
Calendar calNow = new GregorianCalendar();
|
||||
calNow.set(Calendar.HOUR_OF_DAY, 0);
|
||||
calNow.set(Calendar.MINUTE, 0);
|
||||
calNow.set(Calendar.SECOND, 0);
|
||||
long timeNow = calNow.getTimeInMillis();
|
||||
|
||||
Calendar calThen = DatePreference.getDateFor(PreferenceManager.getDefaultSharedPreferences(context), "pref_dateThen");
|
||||
long timeThen = calThen.getTimeInMillis();
|
||||
|
||||
long days = Math.round((double) (timeThen - timeNow) / 86400000.);
|
||||
remoteViews.setTextViewText(R.id.daycount, String.valueOf(days));
|
||||
|
||||
DateFormat format = SimpleDateFormat.getTimeInstance(
|
||||
SimpleDateFormat.MEDIUM, Locale.getDefault());
|
||||
remoteViews.setTextViewText(R.id.debug, format.format(new Date()));
|
||||
|
||||
appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
|
||||
}
|
||||
|
||||
static void SaveAlarmManager(AlarmManager tAlarmManager,
|
||||
PendingIntent tPendingIntent) {
|
||||
myAlarmManager = tAlarmManager;
|
||||
myPendingIntent = tPendingIntent;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user