Commit 810a09ab authored by Lukas F眉lling's avatar Lukas F眉lling

a d d i n i t i a l v a p o r 馃尨

parent a8100204
......@@ -7,8 +7,8 @@
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="modules">
<set>
<option value="/Volumes/Workspace/vaporface" />
<option value="/Volumes/Workspace/vaporface/app" />
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
......
......@@ -24,7 +24,7 @@
</value>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
......
......@@ -2,6 +2,8 @@
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
<module fileurl="file://$PROJECT_DIR$/vaporface.iml" filepath="$PROJECT_DIR$/vaporface.iml" />
<module fileurl="file://$PROJECT_DIR$/vaporface.iml" filepath="$PROJECT_DIR$/vaporface.iml" />
</modules>
</component>
......
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
......@@ -16,11 +16,14 @@
package io.lerk.vaporface;
import android.annotation.SuppressLint;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
......@@ -45,8 +48,6 @@ import java.util.concurrent.TimeUnit;
* low-bit ambient mode, the text is drawn without anti-aliasing in ambient mode.
*/
public class VaporFace extends CanvasWatchFaceService {
private static final Typeface NORMAL_TYPEFACE =
Typeface.create(Typeface.SANS_SERIF, Typeface.NORMAL);
/**
* Update rate in milliseconds for interactive mode. We update once a second since seconds are
......@@ -58,6 +59,7 @@ public class VaporFace extends CanvasWatchFaceService {
* Handler message id for updating the time periodically in interactive mode.
*/
private static final int MSG_UPDATE_TIME = 0;
private Typeface VAPOR_FONT;
@Override
public Engine onCreateEngine() {
......@@ -87,25 +89,37 @@ public class VaporFace extends CanvasWatchFaceService {
private class Engine extends CanvasWatchFaceService.Engine {
final Handler mUpdateTimeHandler = new EngineHandler(this);
boolean mRegisteredTimeZoneReceiver = false;
Paint mBackgroundPaint;
Paint mTextPaint;
boolean mAmbient;
Calendar mCalendar;
final BroadcastReceiver mTimeZoneReceiver = new BroadcastReceiver() {
Paint textPaint;
boolean ambient;
Calendar cal;
Bitmap bg;
final BroadcastReceiver timeZoneReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
mCalendar.setTimeZone(TimeZone.getDefault());
cal.setTimeZone(TimeZone.getDefault());
invalidate();
}
};
float mXOffset;
float mYOffset;
/**
* Whether the display supports fewer bits for each color in ambient mode. When true, we
* disable anti-aliasing in ambient mode.
*/
boolean mLowBitAmbient;
boolean lowBitAmbient;
private boolean isRound;
@Override
public void onSurfaceChanged(SurfaceHolder holder, int format, int width, int height) {
super.onSurfaceChanged(holder, format, width, height);
float scale = ((float) width) / (float) bg.getWidth();
bg = Bitmap.createScaledBitmap(
bg,
(int) (bg.getWidth() * scale),
(int) (bg.getHeight() * scale),
true);
}
@Override
public void onCreate(SurfaceHolder holder) {
......@@ -117,16 +131,17 @@ public class VaporFace extends CanvasWatchFaceService {
.setShowSystemUiTime(false)
.setAcceptsTapEvents(true)
.build());
Resources resources = VaporFace.this.getResources();
mYOffset = resources.getDimension(R.dimen.digital_y_offset);
mBackgroundPaint = new Paint();
mBackgroundPaint.setColor(resources.getColor(R.color.background));
bg = BitmapFactory.decodeResource(resources, R.drawable.vaporwave_grid);
mTextPaint = new Paint();
mTextPaint = createTextPaint(resources.getColor(R.color.digital_text));
VAPOR_FONT = Typeface.createFromAsset(getAssets(), "Monomod.ttf");
mCalendar = Calendar.getInstance();
textPaint = createTextPaint(resources.getColor(R.color.digital_text));
cal = Calendar.getInstance();
}
@Override
......@@ -138,8 +153,9 @@ public class VaporFace extends CanvasWatchFaceService {
private Paint createTextPaint(int textColor) {
Paint paint = new Paint();
paint.setColor(textColor);
paint.setTypeface(NORMAL_TYPEFACE);
paint.setTypeface(VAPOR_FONT);
paint.setAntiAlias(true);
paint.setLetterSpacing(-0.08F);
return paint;
}
......@@ -151,7 +167,7 @@ public class VaporFace extends CanvasWatchFaceService {
registerReceiver();
// Update time zone in case it changed while we weren't visible.
mCalendar.setTimeZone(TimeZone.getDefault());
cal.setTimeZone(TimeZone.getDefault());
invalidate();
} else {
unregisterReceiver();
......@@ -168,7 +184,7 @@ public class VaporFace extends CanvasWatchFaceService {
}
mRegisteredTimeZoneReceiver = true;
IntentFilter filter = new IntentFilter(Intent.ACTION_TIMEZONE_CHANGED);
VaporFace.this.registerReceiver(mTimeZoneReceiver, filter);
VaporFace.this.registerReceiver(timeZoneReceiver, filter);
}
private void unregisterReceiver() {
......@@ -176,7 +192,7 @@ public class VaporFace extends CanvasWatchFaceService {
return;
}
mRegisteredTimeZoneReceiver = false;
VaporFace.this.unregisterReceiver(mTimeZoneReceiver);
VaporFace.this.unregisterReceiver(timeZoneReceiver);
}
@Override
......@@ -185,19 +201,24 @@ public class VaporFace extends CanvasWatchFaceService {
// Load resources that have alternate values for round watches.
Resources resources = VaporFace.this.getResources();
boolean isRound = insets.isRound();
mXOffset = resources.getDimension(isRound
? R.dimen.digital_x_offset_round : R.dimen.digital_x_offset);
float textSize = resources.getDimension(isRound
? R.dimen.digital_text_size_round : R.dimen.digital_text_size);
isRound = insets.isRound();
float textSize = resources.getDimension(isRound ? R.dimen.digital_text_size_round : R.dimen.digital_text_size);
textPaint.setTextSize(textSize);
}
mTextPaint.setTextSize(textSize);
private float calculateOffset(Resources resources, boolean isRound, boolean isAmbient) {
if (isAmbient) {
return resources.getDimension(isRound ? R.dimen.digital_x_offset_round_ambient : R.dimen.digital_x_offset_ambient);
} else {
return resources.getDimension(isRound ? R.dimen.digital_x_offset_round : R.dimen.digital_x_offset);
}
}
@Override
public void onPropertiesChanged(Bundle properties) {
super.onPropertiesChanged(properties);
mLowBitAmbient = properties.getBoolean(PROPERTY_LOW_BIT_AMBIENT, false);
lowBitAmbient = properties.getBoolean(PROPERTY_LOW_BIT_AMBIENT, false);
}
@Override
......@@ -209,10 +230,10 @@ public class VaporFace extends CanvasWatchFaceService {
@Override
public void onAmbientModeChanged(boolean inAmbientMode) {
super.onAmbientModeChanged(inAmbientMode);
if (mAmbient != inAmbientMode) {
mAmbient = inAmbientMode;
if (mLowBitAmbient) {
mTextPaint.setAntiAlias(!inAmbientMode);
if (ambient != inAmbientMode) {
ambient = inAmbientMode;
if (lowBitAmbient) {
textPaint.setAntiAlias(!inAmbientMode);
}
invalidate();
}
......@@ -251,19 +272,20 @@ public class VaporFace extends CanvasWatchFaceService {
if (isInAmbientMode()) {
canvas.drawColor(Color.BLACK);
} else {
canvas.drawRect(0, 0, bounds.width(), bounds.height(), mBackgroundPaint);
canvas.drawBitmap(bg, 0F, 0F, null);
}
// Draw H:MM in ambient mode or H:MM:SS in interactive mode.
long now = System.currentTimeMillis();
mCalendar.setTimeInMillis(now);
String text = mAmbient
? String.format("%d:%02d", mCalendar.get(Calendar.HOUR),
mCalendar.get(Calendar.MINUTE))
: String.format("%d:%02d:%02d", mCalendar.get(Calendar.HOUR),
mCalendar.get(Calendar.MINUTE), mCalendar.get(Calendar.SECOND));
canvas.drawText(text, mXOffset, mYOffset, mTextPaint);
cal.setTimeInMillis(now);
@SuppressLint("DefaultLocale") //FIXME evaluate if this is really not important
String text = ambient
? String.format("%d:%02d", cal.get(Calendar.HOUR),
cal.get(Calendar.MINUTE))
: String.format("%d:%02d:%02d", cal.get(Calendar.HOUR),
cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND));
canvas.drawText(text, calculateOffset(VaporFace.this.getResources(), isRound, ambient), mYOffset, textPaint);
}
/**
......
......@@ -3,6 +3,9 @@
<dimen name="digital_text_size">40dp</dimen>
<dimen name="digital_text_size_round">45dp</dimen>
<dimen name="digital_x_offset">15dp</dimen>
<dimen name="digital_x_offset_round">25dp</dimen>
<dimen name="digital_x_offset_round">20dp</dimen>
<dimen name="digital_x_offset_ambient">64dp</dimen>
<dimen name="digital_x_offset_round_ambient">64dp</dimen>
<dimen name="digital_y_offset">90dp</dimen>
</resources>
......@@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-alpha8'
classpath 'com.android.tools.build:gradle:3.0.0-alpha9'
// NOTE: Do not place your application dependencies here; they belong
......
#Thu Aug 03 11:32:04 CEST 2017
#Thu Aug 03 22:22:52 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-milestone-1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-rc-1-all.zip
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment