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 / testAmazon.java
Created October 2, 2016 00:04
Saving multiple values to DynamoDb at Amazon AWS - splitting list of items to be save so it doesn't exceed limits of one request (28, 25 is just for safety), as well with checking if there are no items left to saved - leftovers due to exceeding throughput limits. Might be useful for people working with Amazon DynamoDb and Java SDK.
private static void writeDynamoMultipleItems(ArrayList<Item> itemsBatchWrite, String tableName, DynamoDB dynamoDB) {
System.out.println("Write to DynamoDB with " + itemsBatchWrite.size() + " items");
if (itemsBatchWrite.size() > 25) {
System.out.println("Splitting table");
ArrayList<Item> writeItems = new ArrayList<>();
for (Item item : itemsBatchWrite) {
if (writeItems.size() < 25) {
writeItems.add(item);
} else {
writeDynamoMultipleItems(writeItems, tableName, dynamoDB);
@tajchert
tajchert / gist:73422616624090851fa5
Last active August 16, 2019 00:01 — forked from mediavrog/gist:5625602
Due to Facebook not handling any text in share intent (ACTION_SEND), and not trying to fix it (it is a "feature"), lets remove it from share dialog - as otherwise it results in broken user experience and most likely users will blame us not the Facebook. Bug on Facebook issue tracker https://developers.facebook.com/bugs/332619626816423
// Usage:
// your share intent
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, "some text");
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "a subject");
// invoke custom chooser that contains all apps just without Facebook
startActivity(Tools.customChooserIntentNoFb(intent, "Share using", context));
// Method:
RemoteInput[] remoteInputs = new RemoteInput[notificationWear.remoteInputs.size()];
Intent localIntent = new Intent();
localIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Bundle localBundle = notificationWear.bundle;
int i = 0;
for(RemoteInput remoteIn : notificationWear.remoteInputs){
getDetailsOfNotification(remoteIn);
remoteInputs[i] = remoteIn;
localBundle.putCharSequence(remoteInputs[i].getResultKey(), "Our answer");//This work, apart from Hangouts as probably they need additional parameter (notification_tag?)
notificationWear.pendingIntent = statusBarNotification.getNotification().contentIntent;
notificationWear.bundle = statusBarNotification.getNotification().extras;
List<Action> actions = wearableExtender.getActions();
for(Action act : actions) {
if(act != null && act.getRemoteInputs() != null) {
RemoteInput[] remoteInputs = act.getRemoteInputs();
}
}
WearableExtender wearableExtender = new WearableExtender(statusBarNotification.getNotification());
Bundle bundle = statusBarNotification.getNotification().extras;
for (String key : bundle.keySet()) {
Object value = bundle.get(key);
if("android.wearable.EXTENSIONS".equals(key)){
Bundle wearBundle = ((Bundle) value);
for (String keyInner : wearBundle.keySet()) {
Object valueInner = wearBundle.get(keyInner);
if(keyInner != null && valueInner != null){
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);
@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.

@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;
/*