Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

show alarms as bell icon, delete alarm from event context menu

  • Loading branch information...
commit 7e4c3f6a656c12ea7dd66cedfc02fdbf9cb929cb 1 parent 15af68b
@tuxmobil authored
View
65 bell.svg
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ width="210mm"
+ height="297mm"
+ id="svg2"
+ version="1.1"
+ inkscape:version="0.48.1 r9760"
+ sodipodi:docname="bell.svg">
+ <defs
+ id="defs4" />
+ <sodipodi:namedview
+ id="base"
+ pagecolor="#ffffff"
+ bordercolor="#666666"
+ borderopacity="1.0"
+ inkscape:pageopacity="0.0"
+ inkscape:pageshadow="2"
+ inkscape:zoom="2.8"
+ inkscape:cx="331.34315"
+ inkscape:cy="952.95867"
+ inkscape:document-units="px"
+ inkscape:current-layer="layer1"
+ showgrid="false"
+ inkscape:window-width="1366"
+ inkscape:window-height="741"
+ inkscape:window-x="0"
+ inkscape:window-y="1"
+ inkscape:window-maximized="1" />
+ <metadata
+ id="metadata7">
+ <rdf:RDF>
+ <cc:Work
+ rdf:about="">
+ <dc:format>image/svg+xml</dc:format>
+ <dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+ <dc:title></dc:title>
+ </cc:Work>
+ </rdf:RDF>
+ </metadata>
+ <g
+ inkscape:label="Ebene 1"
+ inkscape:groupmode="layer"
+ id="layer1">
+ <path
+ id="path2989"
+ style="fill:none;stroke:#000000;stroke-width:4;stroke-linecap:square;stroke-linejoin:round;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
+ d="m 372.2427,134.1479 c 0,-8.35709 -8.64995,-10.27075 -9.97697,-19.83924 -5.39282,-38.885042 -4.79467,-48.37505 -27.00788,-48.37505 -22.21321,0 -21.61506,9.490008 -27.00788,48.37505 -1.32702,9.56849 -9.97697,11.48215 -9.97697,19.83924 l 36.98485,0 z"
+ inkscape:connector-curvature="0"
+ sodipodi:nodetypes="cscsccc" />
+ <path
+ style="fill:none;stroke:#000000;stroke-width:4;stroke-linecap:square;stroke-miterlimit:4;stroke-dasharray:none"
+ d="M 325.8125 134.15625 C 325.88416 139.32473 330.06449 143.5 335.25 143.5 C 340.43551 143.5 344.61584 139.32473 344.6875 134.15625 L 335.25 134.15625 L 325.8125 134.15625 z "
+ id="path3818" />
+ </g>
+</svg>
View
BIN  res/drawable/bell.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
5 res/layout-land/event_layout.xml
@@ -3,9 +3,12 @@
android:layout_width="match_parent" android:layout_height="wrap_content"
android:orientation="vertical" android:padding="10dp"
android:background="@drawable/event_border">
+ <RelativeLayout android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/relativeLayout1" android:gravity="bottom" android:layout_gravity="bottom">
<TextView android:text="TextView" android:id="@+id/event_title"
android:layout_width="wrap_content" android:layout_height="wrap_content"
- android:textStyle="bold" android:textColor="#000000" android:textSize="12sp"></TextView>
+ android:textStyle="bold" android:textColor="#000000" android:textSize="12sp" android:layout_alignParentLeft="true"></TextView>
+ <ImageView android:src="@drawable/bell" android:id="@+id/bell" android:layout_alignParentRight="true" android:scaleType="centerInside" android:layout_alignParentTop="true" android:paddingTop="6dp" android:layout_height="14dp" android:layout_width="14dp"></ImageView>
+ </RelativeLayout>
<TextView android:text="TextView" android:id="@+id/event_subtitle"
android:layout_width="wrap_content" android:layout_height="fill_parent"
android:layout_weight="1" android:textColor="#000000" android:textSize="9sp"></TextView>
View
9 res/layout-port/event_layout.xml
@@ -1,11 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent" android:layout_height="wrap_content"
+ android:layout_height="wrap_content"
android:orientation="vertical" android:padding="10dp"
- android:background="@drawable/event_border">
+ android:background="@drawable/event_border" android:layout_width="match_parent">
+ <RelativeLayout android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/relativeLayout1" android:gravity="bottom" android:layout_gravity="bottom">
<TextView android:text="TextView" android:id="@+id/event_title"
android:layout_width="wrap_content" android:layout_height="wrap_content"
- android:textSize="16sp" android:textStyle="bold" android:textColor="#000000"></TextView>
+ android:textSize="16sp" android:textStyle="bold" android:textColor="#000000" android:layout_alignParentLeft="true" android:layout_alignParentTop="true"></TextView>
+ <ImageView android:src="@drawable/bell" android:id="@+id/bell" android:layout_alignParentRight="true" android:scaleType="centerInside" android:layout_alignParentTop="true" android:paddingTop="6dp" android:layout_height="18dp" android:layout_width="18dp"></ImageView>
+ </RelativeLayout>
<TextView android:text="TextView" android:id="@+id/event_subtitle"
android:layout_width="wrap_content" android:layout_height="fill_parent"
android:textSize="12sp" android:layout_weight="1" android:textColor="#000000"></TextView>
View
1  res/values-de/strings.xml
@@ -53,4 +53,5 @@
<string name="toggle_highlight">Markierung an/aus</string>
<string name="set_alarm">Alarm setzen</string>
<string name="copyright_notes">Copyright 2011 Daniel Dorau. Portions Copyright 2008-2011 The K-9 Dog Walkers and 2006-2011 the Android Open Source Project.</string>
+ <string name="delete_alarm">Alarm löschen</string>
</resources>
View
1  res/values/strings.xml
@@ -52,4 +52,5 @@
<string name="toggle_highlight">Marker on/off</string>
<string name="set_alarm">Set alarm</string>
<string name="copyright_notes">Copyright 2011 Daniel Dorau. Portions Copyright 2008-2011 The K-9 Dog Walkers and 2006-2011 the Android Open Source Project.</string>
+ <string name="delete_alarm">Clear alarm</string>
</resources>
View
7 src/nerd/tuxmobil/fahrplan/camp11/AlarmList.java
@@ -34,9 +34,9 @@ public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.alarms);
- AlarmsDBOpenHelper lecturesDB = new AlarmsDBOpenHelper(this);
+ AlarmsDBOpenHelper alarmsDB = new AlarmsDBOpenHelper(this);
- db = lecturesDB.getReadableDatabase();
+ db = alarmsDB.getReadableDatabase();
Cursor cursor;
try {
@@ -63,6 +63,8 @@ public void onCreate(Bundle savedInstanceState) {
this.setListAdapter(mAdapter);
registerForContextMenu(getListView());
+
+ setResult(RESULT_CANCELED);
}
@Override
@@ -78,6 +80,7 @@ public boolean onContextItemSelected(MenuItem item) {
switch (menuItemIndex) {
case 0:
delete_alarm(info.position);
+ setResult(RESULT_OK);
break;
}
return true;
View
149 src/nerd/tuxmobil/fahrplan/camp11/Fahrplan.java
@@ -38,6 +38,7 @@
import android.view.animation.AnimationUtils;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
+import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.ScrollView;
@@ -69,10 +70,12 @@
private Animation slideDownOut;
private TextView statusLineText;
private LecturesDBOpenHelper lecturesDB;
+ private AlarmsDBOpenHelper alarmDB;
private MetaDBOpenHelper metaDB;
private SQLiteDatabase metadb = null;
private SQLiteDatabase lecturedb = null;
private SQLiteDatabase highlightdb = null;
+ private SQLiteDatabase alarmdb = null;
private HashMap<String, Integer> trackColorsHi;
private HighlightDBOpenHelper highlightDB;
public static final String PREFS_NAME = "settings";
@@ -142,6 +145,7 @@ public void onClick(View v) {
lecturesDB = new LecturesDBOpenHelper(this);
metaDB = new MetaDBOpenHelper(this);
highlightDB = new HighlightDBOpenHelper(this);
+ alarmDB = new AlarmsDBOpenHelper(this);
loadMeta();
@@ -208,6 +212,7 @@ public void onDestroy() {
if (metadb != null) metadb.close();
if (lecturedb != null) lecturedb.close();
if (highlightdb != null) highlightdb.close();
+ if (alarmdb != null) alarmdb.close();
}
@Override
@@ -278,7 +283,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
return true;
case R.id.item_alarms:
intent = new Intent(this, AlarmList.class);
- startActivity(intent);
+ startActivityForResult(intent, MyApp.ALARMLIST);
return true;
case R.id.item_settings:
intent = new Intent(this, Prefs.class);
@@ -304,6 +309,19 @@ private void viewDay(boolean reload) {
.format("%s %d", getString(R.string.day), day));
}
+ private void setBell(Lecture lecture)
+ {
+ final ScrollView parent = (ScrollView)findViewById(R.id.scrollView1);
+ View v = parent.findViewWithTag(lecture);
+ ImageView bell = (ImageView)v.findViewById(R.id.bell);
+
+ if (lecture.has_alarm) {
+ bell.setVisibility(View.VISIBLE);
+ } else {
+ bell.setVisibility(View.GONE);
+ }
+ }
+
private void scrollTo(String lecture_id) {
int height;
switch (getResources().getConfiguration().orientation) {
@@ -528,6 +546,12 @@ private void fillRoom(String roomName, int roomId) {
}
View event = inflater.inflate(R.layout.event_layout, null);
int height = (int) (standardHeight * (lecture.duration / 15) * scale);
+ ImageView bell = (ImageView) event.findViewById(R.id.bell);
+ if (lecture.has_alarm) {
+ bell.setVisibility(View.VISIBLE);
+ } else {
+ bell.setVisibility(View.GONE);
+ }
room.addView(event, LayoutParams.MATCH_PARENT, height);
TextView title = (TextView) event
.findViewById(R.id.event_title);
@@ -586,6 +610,8 @@ private void loadLectureList(int day, boolean force) {
e.printStackTrace();
lecturedb.close();
lecturedb = null;
+ highlightdb.close();
+ highlightdb = null;
return;
}
try {
@@ -651,8 +677,47 @@ private void loadLectureList(int day, boolean force) {
hCursor.moveToNext();
}
hCursor.close();
+
+ loadAlarms();
}
+ private void loadAlarms() {
+ Cursor alarmCursor;
+
+ for (Lecture lecture : MyApp.lectureList) {
+ lecture.has_alarm = false;
+ }
+
+ if (alarmdb == null) {
+ alarmdb = alarmDB.getReadableDatabase();
+ }
+ try {
+ alarmCursor = alarmdb.query("alarms", AlarmsDBOpenHelper.allcolumns,
+ null, null, null,
+ null, null);
+ } catch (SQLiteException e) {
+ e.printStackTrace();
+ alarmdb.close();
+ alarmdb = null;
+ return;
+ }
+ Log.d(LOG_TAG, "Got " + alarmCursor.getCount() + " alarm rows.");
+
+ alarmCursor.moveToFirst();
+ while (!alarmCursor.isAfterLast()) {
+ String lecture_id = alarmCursor.getString(4);
+ Log.d(LOG_TAG, "lecture "+lecture_id+" has alarm");
+
+ for (Lecture lecture : MyApp.lectureList) {
+ if (lecture.lecture_id.equals(lecture_id)) {
+ lecture.has_alarm = true;
+ }
+ }
+ alarmCursor.moveToNext();
+ }
+ alarmCursor.close();
+ }
+
private void loadMeta() {
if (metadb == null) {
metadb = metaDB.getReadableDatabase();
@@ -810,6 +875,57 @@ public void onClick(DialogInterface dialog,
private int[] alarm_times = { 0, 5, 10, 15, 30, 45, 60 };
private View contextMenuView;
+ public void deleteAlarm(Lecture lecture) {
+ AlarmsDBOpenHelper alarmDB = new AlarmsDBOpenHelper(this);
+ SQLiteDatabase db = alarmDB.getWritableDatabase();
+ Cursor cursor;
+
+ try {
+ cursor = db.query("alarms", AlarmsDBOpenHelper.allcolumns,
+ "eventid=?", new String[] { lecture.lecture_id }, null,
+ null, null);
+ } catch (SQLiteException e) {
+ e.printStackTrace();
+ Log.d(LOG_TAG,"failure on alarm query");
+ db.close();
+ return;
+ }
+
+ if (cursor.getCount() == 0) {
+ db.close();
+ cursor.close();
+ Log.d(LOG_TAG, "alarm for " + lecture.lecture_id + " not found");
+ return;
+ }
+
+ cursor.moveToFirst();
+
+ Intent intent = new Intent(this, AlarmReceiver.class);
+ String lecture_id = cursor.getString(4);
+ intent.putExtra("lecture_id", lecture_id);
+ int day = cursor.getInt(6);
+ intent.putExtra("day", day);
+ String title = cursor.getString(1);
+ intent.putExtra("title", title);
+ long startTime = cursor.getLong(5);
+ intent.putExtra("startTime", startTime);
+ // delete any previous alarms of this lecture
+ db.delete("alarms", "eventid=?", new String[] { lecture.lecture_id });
+ db.close();
+
+ intent.setAction("de.machtnix.fahrplan.ALARM");
+ intent.setData(Uri.parse("alarm://"+lecture.lecture_id));
+
+ AlarmManager alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
+ PendingIntent pendingintent = PendingIntent.getBroadcast(this, Integer.parseInt(lecture.lecture_id), intent, 0);
+
+ // Cancel any existing alarms for this lecture
+ alarmManager.cancel(pendingintent);
+
+ lecture.has_alarm = false;
+ setBell(lecture);
+ }
+
public void addAlarm(View v, int alarmTime) {
Lecture lecture = (Lecture) v.getTag();
Time time = lecture.getTime();
@@ -861,6 +977,9 @@ public void addAlarm(View v, int alarmTime) {
db.insert("alarms", null, values);
db.close();
+
+ lecture.has_alarm = true;
+ setBell(lecture);
}
public void writeHighlight(Lecture lecture) {
@@ -907,6 +1026,9 @@ public boolean onContextItemSelected(MenuItem item) {
case 1:
getAlarmTimeDialog(contextMenuView);
break;
+ case 2:
+ deleteAlarm(lecture);
+ break;
}
return true;
}
@@ -917,6 +1039,31 @@ public void onCreateContextMenu(ContextMenu menu, View v,
menu.add(0, 0, 0, getString(R.string.toggle_highlight));
menu.add(0, 1, 1, getString(R.string.set_alarm));
contextMenuView = v;
+ Lecture lecture = (Lecture)contextMenuView.getTag();
+ if (lecture.has_alarm) {
+ menu.add(0, 2, 2, getString(R.string.delete_alarm));
+ }
}
+ public void refreshViews() {
+ for (Lecture lecture : MyApp.lectureList) {
+ setBell(lecture);
+ }
+ }
+
+ public void onActivityResult(int requestCode, int resultCode, Intent intent)
+ {
+ super.onActivityResult(requestCode, resultCode, intent);
+
+ switch (requestCode) {
+ case MyApp.ALARMLIST:
+ Log.d(LOG_TAG, "Return from AlarmList with result " + resultCode);
+ if (resultCode == RESULT_OK) {
+ Log.d(LOG_TAG, "Reload alarms");
+ loadAlarms();
+ refreshViews();
+ }
+ break;
+ }
+ }
}
View
2  src/nerd/tuxmobil/fahrplan/camp11/Lecture.java
@@ -20,6 +20,7 @@
public String links;
public String date;
public boolean highlight;
+ public boolean has_alarm;
public Lecture(String lecture_id) {
title = "";
@@ -39,6 +40,7 @@ public Lecture(String lecture_id) {
date = "";
this.lecture_id = lecture_id;
highlight = false;
+ has_alarm = false;
}
public static int parseStartTime(String text) {
View
3  src/nerd/tuxmobil/fahrplan/camp11/MyApp.java
@@ -19,6 +19,9 @@
PARSE
}
+ // requestCodes für startActivityForResult
+ final public static int ALARMLIST = 1;
+
public static TASKS task_running = TASKS.NONE;
public static String fahrplan_xml;
public static int lectureListDay = 0;
Please sign in to comment.
Something went wrong with that request. Please try again.