Skip to content

Commit

Permalink
Fw_base - Add option for position date left-right of clock [1/2]
Browse files Browse the repository at this point in the history
Change-Id: I64041cbd1e849810adf5a289f1aa8c5e5b5b98f9
Signed-off-by: Jean-Pierre Rasquin <yank555.lu@gmail.com>
  • Loading branch information
yank555-lu authored and STELIX committed Aug 22, 2016
1 parent d99a13d commit 1aaa4ba
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
8 changes: 8 additions & 0 deletions core/java/android/provider/Settings.java
Expand Up @@ -4002,6 +4002,14 @@ public boolean validate(String value) {
*/
public static final String STATUSBAR_CLOCK_FONT_SIZE = "statusbar_clock_font_size";

/**
* Position of date
* 0 - Left of clock
* 1 - Right of clock
* @hide
*/
public static final String STATUSBAR_CLOCK_DATE_POSITION = "statusbar_clock_date_position";

/**
* Defines the shortcuts to be shown on lockscreen
* Usage is like this: target:icon|target:icon|target:icon
Expand Down
Expand Up @@ -74,6 +74,9 @@ public class Clock extends TextView implements DemoMode {
public static final int CLOCK_DATE_STYLE_LOWERCASE = 1;
public static final int CLOCK_DATE_STYLE_UPPERCASE = 2;

public static final int STYLE_DATE_LEFT = 0;
public static final int STYLE_DATE_RIGHT = 1;

public static final int FONT_NORMAL = 0;
public static final int FONT_ITALIC = 1;
public static final int FONT_BOLD = 2;
Expand Down Expand Up @@ -121,6 +124,9 @@ void observe() {
resolver.registerContentObserver(Settings.System
.getUriFor(Settings.System.STATUSBAR_CLOCK_FONT_SIZE), false,
this, UserHandle.USER_ALL);
resolver.registerContentObserver(Settings.System
.getUriFor(Settings.System.STATUSBAR_CLOCK_DATE_POSITION), false,
this, UserHandle.USER_ALL);
updateSettings();
}

Expand Down Expand Up @@ -273,41 +279,54 @@ private final CharSequence getSmallTime() {

CharSequence dateString = null;

String result = sdf.format(mCalendar.getTime());
String result = "";
String timeResult = sdf.format(mCalendar.getTime());
String dateResult = "";

int clockDatePosition = Settings.System.getInt(getContext().getContentResolver(),
Settings.System.STATUSBAR_CLOCK_DATE_POSITION, 0);

if (mClockDateDisplay != CLOCK_DATE_DISPLAY_GONE) {
Date now = new Date();

String clockDateFormat = Settings.System.getString(getContext().getContentResolver(),
Settings.System.STATUS_BAR_DATE_FORMAT);

if (clockDateFormat == null || clockDateFormat.isEmpty()) {
// Set dateString to short uppercase Weekday (Default for AOKP) if empty
dateString = DateFormat.format("EEE", now) + " ";
dateString = DateFormat.format("EEE", now);
} else {
dateString = DateFormat.format(clockDateFormat, now) + " ";
dateString = DateFormat.format(clockDateFormat, now) ;
}
if (mClockDateStyle == CLOCK_DATE_STYLE_LOWERCASE) {
// When Date style is small, convert date to lowercase
result = dateString.toString().toLowerCase() + result;
dateResult = dateString.toString().toLowerCase();
} else if (mClockDateStyle == CLOCK_DATE_STYLE_UPPERCASE) {
result = dateString.toString().toUpperCase() + result;
dateResult = dateString.toString().toUpperCase();
} else {
result = dateString.toString() + result;
dateResult = dateString.toString();
}
result = (clockDatePosition == STYLE_DATE_LEFT) ?
dateResult + " " + timeResult : timeResult + " " + dateResult;
} else {
// No date, just show time
result = timeResult;
}

SpannableStringBuilder formatted = new SpannableStringBuilder(result);

if (mClockDateDisplay != CLOCK_DATE_DISPLAY_NORMAL) {
if (dateString != null) {
int dateStringLen = dateString.length();
int timeStringOffset =
(clockDatePosition == STYLE_DATE_RIGHT) ?
timeResult.length() + 1 : 0;
if (mClockDateDisplay == CLOCK_DATE_DISPLAY_GONE) {
formatted.delete(0, dateStringLen);
} else {
if (mClockDateDisplay == CLOCK_DATE_DISPLAY_SMALL) {
CharacterStyle style = new RelativeSizeSpan(0.7f);
formatted.setSpan(style, 0, dateStringLen,
formatted.setSpan(style, timeStringOffset,
timeStringOffset + dateStringLen,
Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
}
}
Expand Down

0 comments on commit 1aaa4ba

Please sign in to comment.