[Amazfit] tqf:
adding UTC time

hi!

great watchface! excellent for use as starting point.

I am trying to add the UTC time, not as widget as it is already done, but be fixed and also automatically calculate the UTC time, based on the current time zone.

The issue I have is that the UTC time doesn't get updated in sleep mode. Any suggestions?

I added the following:

arrays.xml

:

<array name="utcTime">
<item name="font_size">52px</item>
<item name="left">95px</item>
<item name="top">270px</item>
<item name="color">#fff</item>
<item name="align_left">true</item>
</array>
<array name="utcTimeOffset">
<item name="font_size">20px</item>
<item name="left">65px</item>
<item name="top">270px</item>
<item name="color">#fff</item>
<item name="align_left">true</item>
</array>
<array name="utcString">
<item name="font_size">20px</item>
<item name="left">80px</item>
<item name="top">250px</item>
<item name="color">#fff</item>
<item name="align_left">false</item>
</array>

LoadSettings.java

:

private void defaultParameters(){
...
// utcTime
this.utcTimeBool = sharedPreferences.getBoolean("utcTimeBool", res.getIdentifier("utcTime", "array", context.getPackageName())!=0);
if(this.utcTimeBool) {
TypedArray utcTime = res.obtainTypedArray(res.getIdentifier("utcTime", "array", context.getPackageName()));
i = 0;
this.utcTimeFontSize = sharedPreferences.getFloat("utcTimeFontSize", utcTime.getDimension(i++, 0));
this.utcTimeLeft = sharedPreferences.getFloat("utcTimeLeft", utcTime.getDimension(i++, 0));
this.utcTimeTop = sharedPreferences.getFloat("utcTimeTop", utcTime.getDimension(i++, 0));
if (this.color > -1 && theme_elements.indexOf("utcTime") > -1) {
this.utcTimeColor = Color.parseColor(color_codes[this.color]);
i++;
} else {
this.utcTimeColor = sharedPreferences.getInt("utcTimeColor", utcTime.getColor(i++, 0));
}
this.utcTimeAlignLeft = sharedPreferences.getBoolean("utcTimeAlignLeft", utcTime.getBoolean(i, false));
utcTime.recycle();
// Log.w("DinoDevs-GreatFit", "utcTimeBool: " + this.utcTimeBool);
}

// utcTimeOffset
this.utcTimeOffsetBool = sharedPreferences.getBoolean("utcTimeOffsetBool", res.getIdentifier("utcTimeOffset", "array", context.getPackageName())!=0);
if(this.utcTimeOffsetBool) {
TypedArray utcTimeOffset = res.obtainTypedArray(res.getIdentifier("utcTimeOffset", "array", context.getPackageName()));
i = 0;
this.utcTimeOffsetFontSize = sharedPreferences.getFloat("utcTimeOffsetFontSize", utcTimeOffset.getDimension(i++, 0));
this.utcTimeOffsetLeft = sharedPreferences.getFloat("utcTimeOffsetLeft", utcTimeOffset.getDimension(i++, 0));
this.utcTimeOffsetTop = sharedPreferences.getFloat("utcTimeOffsetTop", utcTimeOffset.getDimension(i++, 0));
if(this.color>-1 && theme_elements.indexOf("utcTimeOffset")>-1){
this.utcTimeOffsetColor = Color.parseColor(color_codes[this.color]);
i++;
}else{
this.utcTimeOffsetColor = sharedPreferences.getInt("utcTimeOffsetColor", utcTimeOffset.getColor(i++, 0));
}
this.utcTimeOffsetAlignLeft = sharedPreferences.getBoolean("utcTimeOffsetAlignLeft", utcTimeOffset.getBoolean(i, false));
utcTimeOffset.recycle();
// Log.w("DinoDevs-GreatFit", "utcTimeOffsetBool: "+ this.utcTimeOffsetBool);

}

// utcString
this.utcStringBool = sharedPreferences.getBoolean("utcStringBool", res.getIdentifier("utcString", "array", context.getPackageName())!=0);
if(this.utcStringBool) {
TypedArray utcString = res.obtainTypedArray(res.getIdentifier("utcString", "array", context.getPackageName()));
i = 0;
this.utcStringFontSize = sharedPreferences.getFloat("utcStringFontSize", utcString.getDimension(i++, 0));
this.utcStringLeft = sharedPreferences.getFloat("utcStringLeft", utcString.getDimension(i++, 0));
this.utcStringTop = sharedPreferences.getFloat("utcStringTop", utcString.getDimension(i++, 0));
if(this.color>-1 && theme_elements.indexOf("utcString")>-1){
this.utcStringColor = Color.parseColor(color_codes[this.color]);
i++;
}else{
this.utcStringColor = sharedPreferences.getInt("utcStringColor", utcString.getColor(i++, 0));
}
this.utcStringAlignLeft = sharedPreferences.getBoolean("utcStringAlignLeft", utcString.getBoolean(i, false));
utcString.recycle();
// Log.w("DinoDevs-GreatFit", "utcStringBool: "+ this.utcStringBool);
}

MainClock.java

:

this.utcTimeFont = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
this.utcTimeFont.setTypeface(ResourceManager.getTypeFace(service.getResources(), ResourceManager.Font.FONT_FILE));
this.utcTimeFont.setTextSize(settings.utcTimeFontSize);
this.utcTimeFont.setColor(settings.utcTimeColor);
this.utcTimeFont.setTextAlign((settings.utcTimeAlignLeft) ? Paint.Align.LEFT : Paint.Align.CENTER);

this.utcTimeOffsetFont = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
this.utcTimeOffsetFont.setTypeface(ResourceManager.getTypeFace(service.getResources(), ResourceManager.Font.FONT_FILE));
this.utcTimeOffsetFont.setTextSize(settings.utcTimeOffsetFontSize);
this.utcTimeOffsetFont.setColor(settings.utcTimeOffsetColor);
this.utcTimeOffsetFont.setTextAlign((settings.utcTimeOffsetAlignLeft) ? Paint.Align.LEFT : Paint.Align.CENTER);

this.utcStringFont = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
this.utcStringFont.setTypeface(ResourceManager.getTypeFace(service.getResources(), ResourceManager.Font.FONT_FILE));
this.utcStringFont.setTextSize(settings.utcStringFontSize);
this.utcStringFont.setColor(settings.utcStringColor);
this.utcStringFont.setTextAlign((settings.utcStringAlignLeft) ? Paint.Align.LEFT : Paint.Align.CENTER);

public void onDrawDigital(Canvas canvas, float width, float height, float centerX, float centerY, int seconds, int minutes, int hours, int year, int month, int day, int week, int ampm) {
...
// Draw UTC time, if enabled
if (settings.utcTimeBool) {
int dst = calendar.get(Calendar.DST_OFFSET);
int timeZone = calendar.get(Calendar.ZONE_OFFSET);
float utcTime = -(dst + timeZone) / (float) 3600000;

// Log.w("DinoDevs-GreatFit", "zone:" + timeZone);
// Log.w("DinoDevs-GreatFit", "DST:" + dst);
// Log.w("DinoDevs-GreatFit", "UTC:" + utcTime);

calendar.add(Calendar.HOUR, (int) utcTime);
if (utcTime % 1 != 0)
calendar.add(Calendar.MINUTE, (utcTime > 0) ? 30 : -30);
// Log.w("DinoDevs-GreatFit", "adding: " + ((utcTime > 0) ? 30 : -30) + "min");

canvas.drawText(Util.formatTime(calendar.get(Calendar.HOUR_OF_DAY)) + Util.formatTime(calendar.get(Calendar.MINUTE)), settings.utcTimeLeft, settings.utcTimeTop, this.utcTimeFont);

// Draw utcTime, if enabled
if (settings.utcTimeOffsetBool)
canvas.drawText(Float.toString(utcTime), settings.utcTimeOffsetLeft, settings.utcTimeOffsetTop, utcTimeOffsetFont);
if (settings.utcStringBool)
canvas.drawText("UTC", settings.utcStringLeft, settings.utcStringTop, utcStringFont);

}

public List<SlptViewComponent> buildSlptViewComponent(Service service, boolean better_resolution) {
...
// Draw utcTime
if (settings.utcTimeBool) {
Calendar calendar = Calendar.getInstance();
int dst = calendar.get(Calendar.DST_OFFSET);
int timeZone = calendar.get(Calendar.ZONE_OFFSET);
float utcTime = -(dst + timeZone) / (float) 3600000;

calendar.add(Calendar.HOUR, (int) utcTime);
if (utcTime % 1 != 0)
calendar.add(Calendar.MINUTE, (utcTime > 0) ? 30 : -30);

int hours = calendar.get(Calendar.HOUR_OF_DAY);
int minutes = calendar.get(Calendar.MINUTE);

// Log.w("DinoDevs-GreatFit", "hours: " + hours);
// Log.w("DinoDevs-GreatFit", "minutes: " + minutes);

SlptLinearLayout utcTimeLayout = new SlptLinearLayout();
SlptPictureView utcTimeString = new SlptPictureView();
utcTimeString.setStringPicture(Util.formatTime(hours) + Util.formatTime(minutes));
utcTimeLayout.add(utcTimeString);

utcTimeLayout.setTextAttrForAll(settings.utcTimeFontSize, settings.utcTimeColor, timeTypeFace);
// Position based on screen on
utcTimeLayout.alignX = 2;
utcTimeLayout.alignY = 0;
utcTimeLayout.setRect((int) (2 * settings.utcTimeLeft + 715), (int) (settings.utcTimeFontSize));
utcTimeLayout.setStart(-320, (int) (settings.utcTimeTop - ((float) settings.font_ratio / 100) * settings.utcTimeFontSize));
//Add it to the list
slpt_objects.add(utcTimeLayout);

// Draw utcTimeOffset, if enabled
// if (settings.utcTimeOffsetBool) {
// Calendar calendar = Calendar.getInstance();
// int dst = calendar.get(Calendar.DST_OFFSET);
// int timeZone = calendar.get(Calendar.ZONE_OFFSET);
// float utcTime = -(dst + timeZone) / (float) 3600000;

// Log.w("DinoDevs-GreatFit", "utc: " + utcTime);

SlptLinearLayout utcTimeOffsetLayout = new SlptLinearLayout();
SlptPictureView utcTimeOffsetString = new SlptPictureView();
utcTimeOffsetString.setStringPicture(Float.toString(utcTime));
utcTimeOffsetLayout.add(utcTimeOffsetString);

utcTimeOffsetLayout.setTextAttrForAll(settings.utcTimeOffsetFontSize, settings.utcTimeOffsetColor, timeTypeFace);
// Position based on screen on
utcTimeOffsetLayout.alignX = 2;
utcTimeOffsetLayout.alignY = 0;
utcTimeOffsetLayout.setRect((int) (2 * settings.utcTimeOffsetLeft + 665), (int) (settings.utcTimeOffsetFontSize));
utcTimeOffsetLayout.setStart(-320, (int) (settings.utcTimeOffsetTop - ((float) settings.font_ratio / 100) * settings.utcTimeOffsetFontSize));
//Add it to the list
slpt_objects.add(utcTimeOffsetLayout);
// }

// Draw utcString, if enabled
// if (settings.utcStringBool) {
SlptLinearLayout utcStringLayout = new SlptLinearLayout();
SlptPictureView utcStringString = new SlptPictureView();
utcStringString.setStringPicture("UTC");
utcStringLayout.add(utcStringString);

utcStringLayout.setTextAttrForAll(settings.utcStringFontSize, settings.utcStringColor, timeTypeFace);
// Position based on screen on
utcStringLayout.alignX = 2;
utcStringLayout.alignY = 0;
utcStringLayout.setRect((int) (2 * settings.utcStringLeft + 640), (int) (settings.utcStringFontSize));
utcStringLayout.setStart(-320, (int) (settings.utcStringTop - ((float) settings.font_ratio / 100) * settings.utcStringFontSize));
//Add it to the list
slpt_objects.add(utcStringLayout);
// }

}