Skip to content

Instantly share code, notes, and snippets.

⚜️
:)

Anton Shkurenko tonyshkurenko

⚜️
:)
Block or report user

Report or block tonyshkurenko

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@tonyshkurenko
tonyshkurenko / RawStringConverter.java
Created Oct 28, 2015
Converter Factory for Retrofit 2.0
View RawStringConverter.java
public class RawStringConverter extends Converter.Factory {
@Override
public Converter<ResponseBody, ?> fromResponseBody(Type type, Annotation[] annotations) {
//noinspection EqualsBetweenInconvertibleTypes
if (String.class.equals(type)) {
return ResponseBody::string;
}
return null;
View Two nice white colors
<color name="GhostWhite">#F8F8FF</color>
<color name="WhiteSmoke">#F5F5F5</color>
View Short bit flags description
This is an example, using a 8-bit unsigned integer to store 8 flags:
`unsigned char options;`
It is common to use larger fields, e.g. 32 bits, but I use 8 here for simplicity.
The possible options, that can be turned on or off independently are declared in an enum like this (just using some arbitrary identifiers):
```
enum Options {
OpAutoRedraw = 0x01,
View WEB_PALETTE
/**
* local max_color_component_value = 255
* local quantum = max_color_component_value / 5
* r = quantum * math.floor((r + (quantum / 2)) / quantum)
* g = quantum * math.floor((g + (quantum / 2)) / quantum)
* b = quantum * math.floor((b + (quantum / 2)) / quantum)
*
* index = (R’*36 + G’*6 + B’) / quantum
*/
View RoundedCornerLayout.java
package com.soundconcepts.mybuilder.ui.widgets;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.RectF;
View OnSwipeTouchListener.java
public class OnSwipeTouchListener implements OnTouchListener {
private final GestureDetector gestureDetector;
public OnSwipeTouchListener (Context ctx){
gestureDetector = new GestureDetector(ctx, new GestureListener());
}
@Override
public boolean onTouch(View v, MotionEvent event) {
View Adding contact to the contacts content provider
private static void addContact(Context ctx, String displayName, String mobileNumber, String homeNumber, String workNumber, String email, String company, String jobTitle) {
final ArrayList<ContentProviderOperation> ops = new ArrayList<>();
ops.add(ContentProviderOperation.newInsert(
ContactsContract.RawContacts.CONTENT_URI)
.withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, null)
.withValue(ContactsContract.RawContacts.ACCOUNT_NAME, null)
.build());
View Delimited String
public static <T> String toDelimitedString(List<T> list, String delimiter) {
final StringBuilder strb = new StringBuilder();
for (T t : list) {
strb.append(String.valueOf(t)).append(delimiter);
}
return strb.substring(0, strb.length() - delimiter.length());
}
View Major-Minor-Patch-Build gradle
import java.util.regex.Pattern
task('increaseVersionCode') << {
def manifestFile = file("src/main/AndroidManifest.xml")
def pattern = Pattern.compile("versionCode=\"(\\d+)\"")
def manifestText = manifestFile.getText()
def matcher = pattern.matcher(manifestText)
matcher.find()
def versionCode = Integer.parseInt(matcher.group(1))
def manifestContent = matcher.replaceAll("versionCode=\"" + ++versionCode + "\"")
@tonyshkurenko
tonyshkurenko / MainActivity.java
Created Jul 14, 2016
Basic activity for demos
View MainActivity.java
package io.github.tonyshkurenko.slidinguppanelsetup;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
You can’t perform that action at this time.