Skip to content

Instantly share code, notes, and snippets.

View CapnSpellcheck's full-sized avatar

Julian Pellico CapnSpellcheck

View GitHub Profile
CapnSpellcheck / UIEditableTextFiltering.swift
Last active July 28, 2020 02:58
Extending UITextFieldDelegate and UITextViewDelegate to enable modifying edit replacements; multi-delegates provide the ability to compose delegates (filters). Note: Multi-Delegates necessarily strongref their constituents.
import Foundation
@objc protocol ExtendedUITextFieldDelegate : UITextFieldDelegate {
@objc optional func extendedTextField(_ textField: UITextField,
shouldChangeCharactersIn range: NSRange,
replacementString string: String) -> String?
class TextFieldMultiDelegate : NSObject, UITextFieldDelegate {
package com.levelfillingvectordrawable
import android.content.res.Resources
import androidx.annotation.DrawableRes
import com.sdsmdg.harjot.vectormaster.models.VectorModel
import java.lang.reflect.Field
CapnSpellcheck / NewlineLimitingInputFilter.kt
Last active December 12, 2018 03:09
An InputFilter for Android EditText that limits the number of newlines the user can type into it.
import android.text.InputFilter
import android.text.Spanned
class NewlineLimitingInputFilter(val maxLines: Int) : InputFilter {
var monitor: LimitMonitor? = null
var numNewlines = 0
override fun filter(source: CharSequence, start: Int, end: Int, dest: Spanned, dstart: Int, dend: Int): CharSequence? {
// subtract all newlines in dest range
for (char in dest.subSequence(dstart, dend)) {
CapnSpellcheck / EnumAdapter.kt
Last active February 21, 2018 02:24
Adapter extending BaseAdapter on Android to show a Spinner based on Enum. The Enum class should also implement Displayable.
* If isOptional, then position 0 is a "No response" item.
class EnumAdapter<DispEnum>(val context: Context, enumClass: Class<DispEnum>,
@IntegerRes var resource: Int = android.R.layout.simple_spinner_item,
@IntegerRes var dropDownResource: Int = android.R.layout.simple_spinner_dropdown_item,
val isOptional: Boolean = false) :
BaseAdapter() where DispEnum : Displayable, DispEnum : Enum<DispEnum>
val inflater: LayoutInflater = LayoutInflater.from(context)
CapnSpellcheck / IntRangeAdapter.kt
Created January 26, 2017 00:34
IntRangeAdapter: A BaseAdapter that allows for easy handling of an integer range. Allows the minimum or maximum to be changed at any time more easily and efficiently than an ArrayAdapter can.
import android.content.Context
import android.util.Log
import android.view.*
import android.widget.BaseAdapter
import android.widget.TextView
class IntRangeAdapter(val context: Context,
@IntegerRes var resource: Int,
CapnSpellcheck / BetterForegroundImageView.kt
Last active January 24, 2017 03:24
An ImageView that allows the foreground drawable to be positioned anywhere within the view's bounds by using a floating point range 0 - 1, where 0 means the left/top edge is snug with view's left/top, and 1 means the right/bottom edge is snug with view's right/bottom.. X and Y can be positioned separately.
import android.content.Context
import android.util.AttributeSet
import android.widget.ImageView
class BetterForegroundImageView : ImageView {
constructor(ctx: Context) : super(ctx)
constructor(ctx: Context, attrs: AttributeSet) : super(ctx, attrs) {
CapnSpellcheck / DialogListPicker.kt
Last active April 30, 2018 08:09
A class to make simple the use of DialogFragment with AlertDialog. You can set a few properties directly, or provide a delegate and deal with Builder directly. *NEW*: This now supports instance state restoration. Assigning a delegate is now deprecated. Instead, implement a provideDelegate() function. For example, Use ActivityDelegatingDialogFrag…
import android.annotation.SuppressLint
import android.os.Bundle
import android.text.Spannable
import android.text.SpannableStringBuilder
import android.view.View
import android.view.ViewTreeObserver
CapnSpellcheck / patch.diff
Created November 17, 2016 21:36
Patch to chrisbanes/PhotoView for issue #444
From 7ab87c7543deebb48a8c1ab482eb7cab524f2d29 Mon Sep 17 00:00:00 2001
From: Julian <>
Date: Thu, 17 Nov 2016 13:34:11 -0800
Subject: [PATCH] destroying the mid zoom
.../co/senab/photoview/ | 17 ++++++++++++-----
.../java/uk/co/senab/photoview/ | 16 +++++++++++-----
2 files changed, 23 insertions(+), 10 deletions(-)
import android.view.View
import android.view.animation.*
import com.nostra13.universalimageloader.core.assist.LoadedFrom
import com.nostra13.universalimageloader.core.display.CircleBitmapDisplayer
import com.nostra13.universalimageloader.core.imageaware.ImageAware