Skip to content

Instantly share code, notes, and snippets.

View webserveis's full-sized avatar

Webserveis webserveis

View GitHub Profile
@vedant1811
vedant1811 / KotlinExtensions.kt
Created June 6, 2018 07:15
Useful android kotlin extensions
/**
* Use as `"#fff".parseColor()`
*/
fun String.parseColor() = Color.parseColor(this)
/**
* Use as `16.spToPx(context)` or `16.5.spToPx(context)`
*/
fun Number.spToPx(context: Context) = TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_SP, this.toFloat(), context.resources.displayMetrics).toInt()
@ThanosFisherman
ThanosFisherman / CheckableImageButton.java
Last active February 4, 2023 19:18
It's a checkable ImageButton that respects xml selector state changes
/**
* Created by thanos on 12/8/17.
* It's a checkable ImageButton that respects xml selector state changes
*/
public final class CheckableImageButton extends AppCompatImageButton implements Checkable
{
private static final int[] DRAWABLE_STATE_CHECKED = new int[]{android.R.attr.state_checked};
private boolean mChecked;
@liangzai-cool
liangzai-cool / HttpUtils.java
Last active February 26, 2019 18:35
convert relative url to absolute url and beautify the result in java.
```
import java.net.MalformedURLException;
import java.net.URL;
public class HttpUtils {
public static void main(String[] args) throws MalformedURLException {
String urlString = "https://www.google.com///images//branding/1234567890/..\\googlelogo/abcdefg/../1x/googlelogo_color_272x92dp.png";
System.out.println(absUrl(urlString));
@passsy
passsy / KIntent.kt
Last active March 28, 2023 06:51
Kotlin extension functions to start a generic Activity
package com.pascalwelsch.extensions
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.Bundle
/**
* Extensions for simpler launching of Activities
package com.example.sampleapp;
import java.util.ArrayList;
import java.util.HashMap;
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.SimpleAdapter;
public class MoreScreen extends ListActivity {
@thotro
thotro / JaroWinklerScore.java
Created November 14, 2015 21:14
A basic Java version of the Jaro-Winkler distance algorithm for measuring the similarity of Strings. It offers good performance on shorter types of strings like names, etc.
public class JaroWinklerScore {
/**
* Applies the Jaro-Winkler distance algorithm to the given strings, providing information about the
* similarity of them.
*
* @param s1 The first string that gets compared. May be <code>null</node> or empty.
* @param s2 The second string that gets compared. May be <code>null</node> or empty.
* @return The Jaro-Winkler score (between 0.0 and 1.0), with a higher value indicating larger similarity.
*
* @author Thomas Trojer <[email protected]>
@gelldur
gelldur / FullscreenFragment.java
Created September 11, 2015 12:48
FullscreenFragment - simple android fragment that will make fullscreen for you. Remember to: "You must manually call onKeyDown and onWindowFocusChanged."
package com.dexode.fragment;
import android.annotation.TargetApi;
import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.view.KeyEvent;
@eyecatchup
eyecatchup / colors_material.xml
Last active June 27, 2021 23:18
Android L Material Color Specs
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2014 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
@Smurph82
Smurph82 / FloatingBtnAnimaControl.java
Last active May 15, 2016 13:13
Animate Floating Action Button Android L. This will give your floating action button an animation similar to the Android Google+ app when scrolling on a RecyclerView.
/**
* Copyright (c) 2014 Ben Murphy (Smurph82)
* Created - Aug 19, 2014
*
* 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
*
@wasabeef
wasabeef / AnimatedGifEncoder.java
Last active July 8, 2023 10:04
Android - AnimatedGifEncoder
import java.io.IOException;
import java.io.OutputStream;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.Paint;
public class AnimatedGifEncoder {
protected int width; // image size