Skip to content

Instantly share code, notes, and snippets.

View jmarkovic's full-sized avatar

Josip Marković jmarkovic

  • sunhill-technologies
  • Berlin, Germany
View GitHub Profile
@jmarkovic
jmarkovic / Preconditions.java
Last active September 19, 2017 08:52
Simple static methods to be called at the start of your own methods to verify correct arguments and state.
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@jmarkovic
jmarkovic / ExampleUsage.md
Last active December 14, 2016 13:28
Animated dots on the screen useful for displaying a PIN input.

Setting up the view should be very easy. First, copy the files PinDisplayView.java and attrs.xml to your project. If you don't have one already, copy ViewUtil.java file as well. It is important that you have the ViewUtil#resolveMeasureSpec method available somewhere. Fix all the imports and verify the app can compile.

Example usage

Add the view to the layout. There's nothing specific you need to do, the view works as is. If you want to, you can modify some attributes as in the example below:

@jmarkovic
jmarkovic / .gitignore
Created December 1, 2016 08:48
The .gitignore file I use for every Android project, created by gitignore.io.
# Created by https://www.gitignore.io and updated by @markovicdev
### OSX ###
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
@jmarkovic
jmarkovic / FragmentFileTemplate.java
Last active August 30, 2016 12:21
An Android Studio (and IDEA) file template that generates a Fragment with all the boilerplate: TAG (with a String literal), newInstance() factory method with arguments Bundle, check for bundle in onCreate, check and attach the Callback in onAttach, attach STUB callback in onDetach and the implementation of a STUB.
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
#parse("File Header.java")
public class ${NAME} extends Fragment {
@jmarkovic
jmarkovic / gdg_zagreb_github_bot.js
Last active June 29, 2016 08:20
Simple, and ineffective, bot for slack that tries to talk with you and find a github repo with provided query. Written using NodeJS and Botkit. Botkit is a required dependency.
var controller = require('botkit').slackbot();
var https = require("https");
var bot = controller.spawn({
debug: true,
token: "bot_token_goes_here"
});
bot.startRTM(function(err,bot,payload) {
if (err) {
@jmarkovic
jmarkovic / SlingyBehavior.java
Created February 24, 2016 22:12
A CoordinatorLayout Behavior for any scroll view, that mimics that slingy feeling and behavior that scrolling containers do on iOS. This is just a proof of concept. Fling currently does not work.
public class SlingyBehavior<V extends View> extends CoordinatorLayout.Behavior<V> implements ViewPropertyAnimatorUpdateListener {
private int moveX = 0;
private int moveY = 0;
public SlingyBehavior() {
super();
}
public SlingyBehavior(Context context, AttributeSet attrs) {
@jmarkovic
jmarkovic / PermissionDef.java
Created January 28, 2016 19:34
Android annotation defining all permissions in a StringDef annotation.
/**
* Typedef annotation listing all permissions
* available in the latest SDK.
* Using this on a method parameter
* or on a method with {@link String} return value
* will trigger value lookup in Android Studio.
*
* @version SDK23
* @author jmarkovic
*/
@jmarkovic
jmarkovic / .gitignore
Created August 11, 2014 13:35
General Android gitignore file used as base for each new project
# built application files
*.apk
*.ap_
# files for the dex VM
*.dex
# Java class files
*.class
@jmarkovic
jmarkovic / SomeActivity.java
Created July 23, 2014 15:57
This is the code I had a pleasure debugging. For some weeks now I'm debating some of my stubborn colleagues who's idea of good code is "if it works, don't change it" no matter how ugly it is. This often generates anti-patters such as exclusivity to AsyncTask for networking, strong references of Context and Activity almost everywhere and so on. T…
if (registrationId.equals("") || registrationId.equals(null)) {
} else {
// // Device is already registered on GCM
if (GCMRegistrar.isRegisteredOnServer(getApplicationContext())) {
} else {
}
@jmarkovic
jmarkovic / LiveEvent.java
Created June 3, 2014 17:11
Sortiranje evenata po minuti silazno
@Override
public int compareTo(LiveEvent another) {
int thisMinute = 0;
int thisSecondaryMinute = 0;
int anotherMinute = 0;
int anotherSecondaryMinute = 0;
try {
if (this.getMinute().contains("+")) {
String[] minutes = this.getMinute().split("\\+");
if (minutes.length >= 2) {