Skip to content

Instantly share code, notes, and snippets.

View CapnSpellcheck's full-sized avatar

Julian Pellico CapnSpellcheck

View GitHub Profile
@CapnSpellcheck
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 android.graphics.*
import android.graphics.drawable.DrawableWrapper
import android.graphics.drawable.VectorDrawable
import androidx.annotation.DrawableRes
import androidx.core.graphics.withSave
import com.sdsmdg.harjot.vectormaster.models.VectorModel
import java.lang.reflect.Field
@CapnSpellcheck
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
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
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.support.annotation.IntegerRes
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
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.graphics.Canvas
import android.graphics.drawable.Drawable
import android.util.AttributeSet
import android.widget.ImageView
import letstwinkle.com.twinkle.R
class BetterForegroundImageView : ImageView {
constructor(ctx: Context) : super(ctx)
constructor(ctx: Context, attrs: AttributeSet) : super(ctx, attrs) {
@CapnSpellcheck
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…
package letstwinkle.com.twinkle.util
import android.annotation.SuppressLint
import android.os.Bundle
import android.support.v4.os.ConfigurationCompat
import android.text.Spannable
import android.text.SpannableStringBuilder
import android.text.style.ImageSpan
import android.view.View
import android.view.ViewTreeObserver
@CapnSpellcheck
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 <julian@julians-mbp.attlocal.net>
Date: Thu, 17 Nov 2016 13:34:11 -0800
Subject: [PATCH] destroying the mid zoom
---
.../co/senab/photoview/DefaultOnDoubleTapListener.java | 17 ++++++++++++-----
.../java/uk/co/senab/photoview/PhotoViewAttacher.java | 16 +++++++++++-----
2 files changed, 23 insertions(+), 10 deletions(-)
package letstwinkle.com.twinkle.widget
import android.graphics.Bitmap
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