mirror of
https://github.com/moparisthebest/Yaaic
synced 2024-11-26 02:42:16 -05:00
New Settings: prefix messages with timestamp, use 24h or 12h time format
This commit is contained in:
parent
7d9a727fa0
commit
ee60c3c386
@ -8,4 +8,7 @@
|
||||
|
||||
<string name="key_show_colors">show_colors</string>
|
||||
<string name="default_show_colors">true</string>
|
||||
|
||||
<string name="key_24h_format">24h_format</string>
|
||||
<string name="default_24h_format">true</string>
|
||||
</resources>
|
@ -27,7 +27,7 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
||||
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" />
|
||||
<CheckBoxPreference
|
||||
android:title="Show colors"
|
||||
android:summary="Show colors to highlight special events"
|
||||
@ -38,5 +38,11 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
||||
android:summary="Prefix all messages with a timestamp"
|
||||
android:key="@string/key_show_timestamp"
|
||||
android:defaultValue="@string/default_show_timestamp" />
|
||||
<CheckBoxPreference
|
||||
android:title="24 hour format"
|
||||
android:summary="Use 24 hour format for timestamps"
|
||||
android:key="@string/key_24h_format"
|
||||
android:defaultValue="@string/default_24h_format"
|
||||
android:dependency="@string/key_show_timestamp" />
|
||||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
||||
|
@ -20,6 +20,8 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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() + "] ";
|
||||
}
|
||||
}
|
||||
|
@ -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))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user