diff --git a/res/values/settings.xml b/res/values/settings.xml
index 12997be..b03805e 100644
--- a/res/values/settings.xml
+++ b/res/values/settings.xml
@@ -8,4 +8,7 @@
show_colors
true
+
+ 24h_format
+ true
\ No newline at end of file
diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml
index ddc44af..6f31364 100644
--- a/res/xml/preferences.xml
+++ b/res/xml/preferences.xml
@@ -27,7 +27,7 @@ along with Yaaic. If not, see .
android:title="Show icons"
android:summary="Show icons to highlight special events"
android:key="@string/key_show_icons"
- android:defaultValue="" />
+ android:defaultValue="@string/default_show_icons" />
.
android:summary="Prefix all messages with a timestamp"
android:key="@string/key_show_timestamp"
android:defaultValue="@string/default_show_timestamp" />
+
diff --git a/src/org/yaaic/model/Message.java b/src/org/yaaic/model/Message.java
index e240d6f..7ebaa6a 100644
--- a/src/org/yaaic/model/Message.java
+++ b/src/org/yaaic/model/Message.java
@@ -20,6 +20,8 @@ along with Yaaic. If not, see .
*/
package org.yaaic.model;
+import java.util.Date;
+
import android.content.Context;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
@@ -112,14 +114,16 @@ public class Message {
if (canvas == null) {
String prefix = hasIcon() && settings.showIcons() ? " " : "";
- canvas = new SpannableString(prefix + text);
+ String timestamp = settings.showTimestamp() ? Message.generateTimestamp(settings.use24hFormat()) : "";
+
+ canvas = new SpannableString(prefix + timestamp + text);
if (hasIcon() && settings.showIcons()) {
Drawable drawable = context.getResources().getDrawable(icon);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
canvas.setSpan(new ImageSpan(drawable, ImageSpan.ALIGN_BOTTOM), 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
- if (color != -1 && settings.showTimestamp()) {
+ if (color != -1 && settings.showColors()) {
canvas.setSpan(new ForegroundColorSpan(color), 0, canvas.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
@@ -127,6 +131,12 @@ public class Message {
return canvas;
}
+ /**
+ * Render message as text view
+ *
+ * @param context
+ * @return
+ */
public TextView renderTextView(Context context)
{
TextView canvas = new TextView(context);
@@ -138,4 +148,23 @@ public class Message {
return canvas;
}
+
+ /**
+ * Generate a timestamp
+ *
+ * @param use24hFormat
+ * @return
+ */
+ public static String generateTimestamp(boolean use24hFormat)
+ {
+ Date date = new Date();
+
+ int hours = date.getHours();
+
+ if (!use24hFormat) {
+ hours = Math.abs(24 - hours);
+ }
+
+ return "[" + hours + ":" + date.getMinutes() + "] ";
+ }
}
diff --git a/src/org/yaaic/model/Settings.java b/src/org/yaaic/model/Settings.java
index a8a3c15..3ce0bcd 100644
--- a/src/org/yaaic/model/Settings.java
+++ b/src/org/yaaic/model/Settings.java
@@ -93,4 +93,17 @@ public class Settings
Boolean.parseBoolean(resources.getString(R.string.default_show_colors))
);
}
+
+ /**
+ * Use 24 hour format for timestamps?
+ *
+ * @return
+ */
+ public boolean use24hFormat()
+ {
+ return preferences.getBoolean(
+ resources.getString(R.string.key_24h_format),
+ Boolean.parseBoolean(resources.getString(R.string.default_24h_format))
+ );
+ }
}