Skip to content

Instantly share code, notes, and snippets.

View keinix's full-sized avatar

Zack Osborn keinix

View GitHub Profile
class Game {
private String answer;
private String hits;
private String misses;
public static final int MAX_MISSES = 7;
public Game(String answer) {
this.answer = answer;
hits = "";
misses = "";
@keinix
keinix / JavaGsonBasics
Last active July 14, 2017 02:00
Assign Json values to class variables or Map with Gson examples.
public class Main {
public static void main(String[] args) {
Gson gson = new Gson();
String file;
JsonObject jsonObject;
// used in the map example only
Type type = new TypeToken<Map<String, String>>(){}.getType();
FileReader json = null;
@keinix
keinix / allAndroidActivitesPortrait.java
Created July 21, 2017 00:06
Turn the entire android app to portrait only.
package com.keinix.interactivestory;
import android.app.Activity;
import android.app.Application;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
public class InteractiveStoryApplication extends Application {
@Override
public void onCreate() {
private boolean networkIsAvailable() {
ConnectivityManager manager = (ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = manager.getActiveNetworkInfo();
boolean isAvailable = false;
if (networkInfo != null && networkInfo.isConnected()) {
isAvailable = true;
}
return isAvailable;
}
@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()));
}
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);
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(),
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;
public class Book implements Literature {
// variables and methods
@Override
public int getType() {
return Literature.TYPE_BOOK;
}
}
public class Magazine implements Literature{
public class LiteratureAdapter extends RecyclerView.Adapter {
...
class BookViewHolder extends RecyclerView.ViewHolder {
public BookViewHolder(View itemView) {
super(itemView);
// get reference to views
// itemView.findViewById...