Skip to content

Instantly share code, notes, and snippets.

View tajchert's full-sized avatar
🏠
Working from home

Michal Tajchert tajchert

🏠
Working from home
View GitHub Profile
@tajchert
tajchert / robot.js
Created December 4, 2012 15:05
Primosz_PL
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
robot.clone();
@tajchert
tajchert / robot.js
Created December 4, 2012 15:10
Primosz_PL
var Robot = function(robot) {
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
robot.ahead(5);
robot.turn(10);
};
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot;
@tajchert
tajchert / robot.js
Created December 4, 2012 20:02
CIRBOT
var Robot = function(robot) {
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
robot.clone();
robot.ahead(Math.floor((Math.random()*7)+4));
robot.turn(10);
};
Robot.prototype.onScannedRobot = function(ev) {
@tajchert
tajchert / robot.js
Created December 4, 2012 20:48
RUSH, RUSH
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
robot.turn(360);
@tajchert
tajchert / scaleTopCrop
Created July 18, 2014 08:22
Crop Top of a Bitmap to particular size.
//Author: Michal Tajchert
//tajchert.pl
public Bitmap scaleTopCrop(Bitmap source, int newHeight, int newWidth) {
int sourceWidth = source.getWidth();
int sourceHeight = source.getHeight();
float xScale = (float) newWidth / sourceWidth;
float yScale = (float) newHeight / sourceHeight;
float scale = Math.max(xScale, yScale);
float scaledWidth = scale * sourceWidth;
@tajchert
tajchert / BuildConfSolution
Created August 15, 2014 21:42
Android Wear Build Configuration problem
If you build and deploy Android Wear app from IDE to watch directly you most likely will see Build Configuration screen and if you will clik "Run" you will get "Build Configuration is still incorrect, do you want to edit it again?"
SOLUTION
To solve it just check "Do not launch Activity" in Activity section of a "Run/Debug Configurations" of a "wear" project.
Simple like that and will save you bunch of seconds each build, minutes each day, hours each year - enjoy!

Send uncaught Exceptions from Android Wear to Android

This is a short Gist showing how I transmit any uncaught exceptions happening in the Wearable part of my App to the connected Smartphone/Tablet. This is necessary because Android Wear devices are not directly connected to the Internet themselves.

##Wear

  • WearApp.java
  • AndroidManifest.xml
  • ErrorService.java
@tajchert
tajchert / gist:a49c22f54962bd9005bc
Created February 14, 2015 03:16
Screen Shape Detection On Android Wear Devices
Add this class to your project, sample: https://github.com/tajchert/ShapeWear/blob/master/wear/src/main/java/pl/tajchert/shapewearsample/MainActivity.java
To start call `ShapeWear.initShapeWear(this);` and in most basic case use `ShapeWear.isRound()` to check if device screen is round.
Source: https://github.com/tajchert/ShapeWear
```java
package pl.tajchert.shapewear;
/*
@tajchert
tajchert / A_DATABASEWEAR.md
Last active December 19, 2022 12:30
Android Wear Realm Database Sync

This short code will show how to sync database file using Realm, but can be used for any file that you need to send to Wear (using Data API). It just takes any file, change it to Asset object and send it over to Wear device. Also it can be used Mobile->Wear, and Wear->Mobile.

When you need to sync database just call FileSender.syncRealm(context);, that is it!

DISCLAIMER "Proper" way would be to synchronize each transaction to DB, but it in most cases Wear is used very rarely comparing to mobile, so it would most likely cause a battery drain. My idea was to synchronize it only whene it is needed (so for example when app closes). If you want to make sure that you are using latest DB, just send trigger data using MessageAPI from Wear to Phone with ask of syncing over its database, or keep some timestapm of last edit and check it.

RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY).build();
NotificationCompat.Action action =
new NotificationCompat.Action.Builder(...)
.addRemoteInput(remoteInput)
.build();
NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender().addAction(action);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(MainActivity.this).extend(wearableExtender);