Skip to content
This repository has been archived by the owner on Jun 14, 2019. It is now read-only.

Commit

Permalink
Make UI compatible with square screen
Browse files Browse the repository at this point in the history
  • Loading branch information
skyred committed Dec 22, 2014
1 parent 4a5c094 commit 69bd155
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 99 deletions.
2 changes: 1 addition & 1 deletion mobile/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
package="com.insready.releasewatch"
xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0-alpha1">
android:versionName="1.0">

<uses-permission android:name="com.google.android.permission.PROVIDE_BACKGROUND"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
Expand Down
7 changes: 5 additions & 2 deletions wear/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
package="com.insready.releasewatch"
xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0-alpha1">
android:versionName="1.0">

<uses-feature android:name="android.hardware.type.watch"/>

Expand All @@ -25,7 +25,10 @@
android:resource="@xml/watch_face"/>
<meta-data
android:name="com.google.android.wearable.watchface.preview"
android:resource="@drawable/preview_d8release"/>
android:resource="@drawable/preview_d8release_square"/>
<meta-data
android:name="com.google.android.wearable.watchface.preview_circular"
android:resource="@drawable/preview_d8release_round"/>

<intent-filter>
<action android:name="android.service.wallpaper.WallpaperService"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,15 @@ public Engine onCreateEngine() {

private class Engine extends CanvasWatchFaceService.Engine implements DataApi.DataListener, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
static final int MSG_UPDATE_TIME = 0;

static final int MSG_LOAD_D8RELEASEDATA = 0;
/* receiver to update the time zone */
final BroadcastReceiver mTimeZoneReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
mTime.clear(intent.getStringExtra("time-zone"));
mTime.setToNow();
}
};
/* graphic objects */
Bitmap mBackgroundBitmap;
Bitmap mBackgroundScaledBitmap;
Expand All @@ -74,22 +82,16 @@ private class Engine extends CanvasWatchFaceService.Engine implements DataApi.Da
Paint mMajorPaint;
Paint mEstimatePaint;
Paint mMajorBGPaint;

float mRoundSquareRatio = 0f; // 1 means round, 280/320 = 0.875 means square
boolean mMute;

/* a time object */
Time mTime;

/**
* Whether the display supports fewer bits for each color in ambient mode. When true, we
* disable anti-aliasing in ambient mode.
*/
boolean mLowBitAmbient;

boolean mRegisteredTimeZoneReceiver = false;

static final int MSG_LOAD_D8RELEASEDATA = 0;

GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(D8ReleaseWatchFaceService.this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
Expand All @@ -114,90 +116,14 @@ public void onConnectionFailed(ConnectionResult connectionResult) {
Log.d(TAG, "onConnectionFailed: " + connectionResult);
}

/**
* Handler to update the time once a second in interactive mode.
*/
final Handler mUpdateTimeHandler = new Handler() {
@Override
public void handleMessage(Message message) {
switch (message.what) {
case MSG_UPDATE_TIME:
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log.v(TAG, "updating time");
}
invalidate();
if (shouldTimerBeRunning()) {
long timeMs = System.currentTimeMillis();
long delayMs = INTERACTIVE_UPDATE_RATE_MS
- (timeMs % INTERACTIVE_UPDATE_RATE_MS);
mUpdateTimeHandler.sendEmptyMessageDelayed(MSG_UPDATE_TIME, delayMs);
}
break;
}
}
};

/**
* Handler to load the meetings once a minute in interactive mode.
*/
final Handler mLoadD8ReleaseDataHandler = new Handler() {
@Override
public void handleMessage(Message message) {
switch (message.what) {
case MSG_LOAD_D8RELEASEDATA:
// the connected device to send the message to
PendingResult nodes = Wearable.NodeApi.getConnectedNodes(mGoogleApiClient);

nodes.setResultCallback(new ResultCallback<NodeApi.GetConnectedNodesResult>() {
@Override
public void onResult(final NodeApi.GetConnectedNodesResult result) {
if (result.getStatus().isSuccess()) {
Log.d(TAG, "Connected Nodes: " + result.getNodes().size());
}
for (Node node : result.getNodes()) {
if (mGoogleApiClient == null) {
Log.d(TAG, "mGoogleApiClient initialization failed");
} else {
Log.d(TAG, "mGoogleApiClient initialization succeeded");
}

PendingResult msgResult = Wearable.MessageApi.sendMessage(
mGoogleApiClient, node.getId(), GET_D8_RELEASE_DATA, null);
msgResult.setResultCallback(new ResultCallback<MessageApi.SendMessageResult>() {
@Override
public void onResult(final MessageApi.SendMessageResult feedback) {
if (!feedback.getStatus().isSuccess()) {
Log.e(TAG, "ERROR: failed to send Message: " + feedback.getStatus());
}
}
});
}
}
});
// We only need to download D8 Release Data every 6 hours according to https://drupalreleasedate.com/about
mLoadD8ReleaseDataHandler.sendEmptyMessageDelayed(MSG_LOAD_D8RELEASEDATA, 21600000);
break;
}
}
};

/* receiver to update the time zone */
final BroadcastReceiver mTimeZoneReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
mTime.clear(intent.getStringExtra("time-zone"));
mTime.setToNow();
}
};

@Override
public void onCreate(SurfaceHolder holder) {
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "onCreate");
}
super.onCreate(holder);

/* configure the system UI */
/* configure the system UI */
setWatchFaceStyle(new WatchFaceStyle.Builder(D8ReleaseWatchFaceService.this)
.setCardPeekMode(WatchFaceStyle.PEEK_MODE_SHORT)
.setBackgroundVisibility(WatchFaceStyle.BACKGROUND_VISIBILITY_INTERRUPTIVE)
Expand Down Expand Up @@ -235,12 +161,10 @@ public void onCreate(SurfaceHolder holder) {

mCriticalPaint = new Paint();
mCriticalPaint.setARGB(255, 255, 255, 255);
mCriticalPaint.setTextSize(40);
mCriticalPaint.setAntiAlias(true);

mMajorPaint = new Paint();
mMajorPaint.setARGB(255, 255, 255, 255);
mMajorPaint.setTextSize(25);
mMajorPaint.setAntiAlias(true);

mMajorBGPaint = new Paint();
Expand All @@ -249,7 +173,6 @@ public void onCreate(SurfaceHolder holder) {

mEstimatePaint = new Paint();
mEstimatePaint.setARGB(255, 255, 255, 255);
mEstimatePaint.setTextSize(18);
mEstimatePaint.setAntiAlias(true);


Expand All @@ -258,6 +181,29 @@ public void onCreate(SurfaceHolder holder) {

}

/**
* Handler to update the time once a second in interactive mode.
*/
final Handler mUpdateTimeHandler = new Handler() {
@Override
public void handleMessage(Message message) {
switch (message.what) {
case MSG_UPDATE_TIME:
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log.v(TAG, "updating time");
}
invalidate();
if (shouldTimerBeRunning()) {
long timeMs = System.currentTimeMillis();
long delayMs = INTERACTIVE_UPDATE_RATE_MS
- (timeMs % INTERACTIVE_UPDATE_RATE_MS);
mUpdateTimeHandler.sendEmptyMessageDelayed(MSG_UPDATE_TIME, delayMs);
}
break;
}
}
};

@Override
public void onDestroy() {
mUpdateTimeHandler.removeMessages(MSG_UPDATE_TIME);
Expand All @@ -273,6 +219,50 @@ public void onPropertiesChanged(Bundle properties) {
}
}

/**
* Handler to load the meetings once a minute in interactive mode.
*/
final Handler mLoadD8ReleaseDataHandler = new Handler() {
@Override
public void handleMessage(Message message) {
switch (message.what) {
case MSG_LOAD_D8RELEASEDATA:
// the connected device to send the message to
PendingResult nodes = Wearable.NodeApi.getConnectedNodes(mGoogleApiClient);

nodes.setResultCallback(new ResultCallback<NodeApi.GetConnectedNodesResult>() {
@Override
public void onResult(final NodeApi.GetConnectedNodesResult result) {
if (result.getStatus().isSuccess()) {
Log.d(TAG, "Connected Nodes: " + result.getNodes().size());
}
for (Node node : result.getNodes()) {
if (mGoogleApiClient == null) {
Log.d(TAG, "mGoogleApiClient initialization failed");
} else {
Log.d(TAG, "mGoogleApiClient initialization succeeded");
}

PendingResult msgResult = Wearable.MessageApi.sendMessage(
mGoogleApiClient, node.getId(), GET_D8_RELEASE_DATA, null);
msgResult.setResultCallback(new ResultCallback<MessageApi.SendMessageResult>() {
@Override
public void onResult(final MessageApi.SendMessageResult feedback) {
if (!feedback.getStatus().isSuccess()) {
Log.e(TAG, "ERROR: failed to send Message: " + feedback.getStatus());
}
}
});
}
}
});
// We only need to download D8 Release Data every 6 hours according to https://drupalreleasedate.com/about
mLoadD8ReleaseDataHandler.sendEmptyMessageDelayed(MSG_LOAD_D8RELEASEDATA, 21600000);
break;
}
}
};

@Override
public void onTimeTick() {
super.onTimeTick();
Expand Down Expand Up @@ -334,14 +324,22 @@ public void onDraw(Canvas canvas, Rect bounds) {

// Draw D8 Release info
if (!isInAmbientMode() && mCurCritical != null && mCurMajor != null && mEstimate != null) {
Log.d(TAG, "Drawing D8 Data.");
canvas.drawCircle(152f, 238f, 48.5f, mSecondPaint);
canvas.drawText(mCurCritical + "", 127f, 250f, mCriticalPaint);
canvas.drawText(mFromYesterdayCritical + "", 143f, 270f, mEstimatePaint);
canvas.drawCircle(193f, 120f, 38f, mMajorBGPaint);
canvas.drawText(mCurMajor + "", 170f, 130f, mMajorPaint);
canvas.drawText(mFromYesterdayMajor + "", 180f, 150f, mEstimatePaint);
canvas.drawText(mEstimate, 40f, 150f, mEstimatePaint);
// Detect Round or Square
if (mRoundSquareRatio == 0f) {
mRoundSquareRatio = canvas.getWidth() / 320f;
mCriticalPaint.setTextSize(40 * mRoundSquareRatio);
mMajorPaint.setTextSize(25 * mRoundSquareRatio);
mEstimatePaint.setTextSize(18 * mRoundSquareRatio);
}
Log.d(TAG, "D8 Data comes in. Drawing on screen ratio: " + mRoundSquareRatio + "; width is: " + canvas.getWidth());

canvas.drawCircle(152f * mRoundSquareRatio, 238f * mRoundSquareRatio, 48.5f * mRoundSquareRatio, mSecondPaint);
canvas.drawText(mCurCritical + "", 127f * mRoundSquareRatio, 250f * mRoundSquareRatio, mCriticalPaint);
canvas.drawText(mFromYesterdayCritical + "", 143f * mRoundSquareRatio, 270f * mRoundSquareRatio, mEstimatePaint);
canvas.drawCircle(193f * mRoundSquareRatio, 120f * mRoundSquareRatio, 38f * mRoundSquareRatio, mMajorBGPaint);
canvas.drawText(mCurMajor + "", 170f * mRoundSquareRatio, 130f * mRoundSquareRatio, mMajorPaint);
canvas.drawText(mFromYesterdayMajor + "", 180f * mRoundSquareRatio, 150f * mRoundSquareRatio, mEstimatePaint);
canvas.drawText(mEstimate, 40f * mRoundSquareRatio, 150f * mRoundSquareRatio, mEstimatePaint);
}

// Find the center. Ignore the window insets so that, on round watches with a
Expand Down Expand Up @@ -489,6 +487,7 @@ public void onDataChanged(DataEventBuffer dataEvents) {
}
}


}

}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 69bd155

Please sign in to comment.