Skip to content

Instantly share code, notes, and snippets.

View keinix's full-sized avatar

Zack Osborn keinix

View GitHub Profile
@keinix
keinix / AllGattCharacteristics.java
Created December 9, 2019 01:03 — forked from sam016/AllGattCharacteristics.java
Bluetooth GATT Services & Characteristics
package com.sam016.vsflatomation.service.ble;
import java.util.HashMap;
import java.util.UUID;
public class AllGattCharacteristics {
private static HashMap<String, String> attributes = new HashMap();
static {
attributes.put("00002a00-0000-1000-8000-00805f9b34fb", "Device Name");
public class LiteratureAdapter extends RecyclerView.Adapter {
private List<Literature> mLiteratureList;
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View itemView;
switch (viewType) {
case Literature.TYPE_BOOK:
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
switch (getItemViewType(position)) {
case Literature.TYPE_BOOK:
((BookViewHolder) holder).bindView(position);
break;
case Literature.TYPE_MAGAZINE:
((MagazineViewHolder) holder).bindView(position);
break;
case Literature.TYPE_NEWSPAPER:
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View itemView;
switch (viewType) {
case Literature.TYPE_BOOK:
itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.your_layout, parent, false);
return new BookViewHolder(itemView);
case Literature.TYPE_MAGAZINE:
public class LiteratureAdapter extends RecyclerView.Adapter {
...
class BookViewHolder extends RecyclerView.ViewHolder {
public BookViewHolder(View itemView) {
super(itemView);
// get reference to views
// itemView.findViewById...
public class Book implements Literature {
// variables and methods
@Override
public int getType() {
return Literature.TYPE_BOOK;
}
}
public class Magazine implements Literature{
package io.keinix.protoflow.util;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;
import android.view.View;
int iconMargin = (itemView.getHeight() - icon.getIntrinsicHeight()) / 2;
int iconTop = itemView.getTop() + (itemView.getHeight() - icon.getIntrinsicHeight()) / 2;
int iconBottom = iconTop + icon.getIntrinsicHeight();
if (dX > 0) { // Swiping to the right
int iconLeft = itemView.getLeft() + iconMargin + icon.getIntrinsicWidth();
int iconRight = itemView.getLeft() + iconMargin;
icon.setBounds(iconLeft, iconTop, iconRight, iconBottom);
background.setBounds(itemView.getLeft(), itemView.getTop(),
if (dX > 0) { // Swiping to the right
background.setBounds(itemView.getLeft(), itemView.getTop(),
itemView.getLeft() + ((int) dX) + backgroundCornerOffset,
itemView.getBottom());
} else if (dX < 0) { // Swiping to the left
background.setBounds(itemView.getRight() + ((int) dX) - backgroundCornerOffset,
itemView.getTop(), itemView.getRight(), itemView.getBottom());
} else { // view is unSwiped
background.setBounds(0, 0, 0, 0);
@keinix
keinix / CompareObjects.java
Last active April 26, 2018 12:15
Sort an object based on a String field
public void sortSubReddits(List<SubReddit> subreddits) {
Collections.sort(subreddits, (sub1, sub2) ->
String.CASE_INSENSITIVE_ORDER.compare(sub1.getDisplayName(), sub2.getDisplayName()));
}