Skip to content

Instantly share code, notes, and snippets.

View vontell's full-sized avatar
🏙️
Philadelphia

Aaron Vontell vontell

🏙️
Philadelphia
View GitHub Profile
@vontell
vontell / example.js
Created April 20, 2018 20:18
Callback Example for Tej
function imAFunction(message, callback) {
console.log("Here is the message you passed in: " + message);
// Now I'm gonna pass call the callback function with a boolean
callback(true);
}
imAFunction("Hello!", function(bool) {
// 'bool' is the true passed in from line 4
console.log(bool);
});
@vontell
vontell / ChipView.kt
Created January 30, 2018 19:30
002 Extensions using Picasso
private val Context.picasso: Picasso
get() = Picasso.with(this)
private fun CircleImageView?.load(path: String) {
this!!.context.picasso.load(path).into(this)
}
@vontell
vontell / MainActivity.kt
Created January 30, 2018 19:06
002 Setting Remove Listeners
// Set the remove listener using a lambda function
customChip.setOnRemoveListener({
Toast.makeText(this, "Remove chip clicked", Toast.LENGTH_SHORT).show()
})
// Set the remove listener using an anonymous interface
customChipThree.setOnRemoveListener(object: ChipView.OnChipRemovedListener {
override fun onRemove(v: View) {
Toast.makeText(baseContext, "Remove chip clicked", Toast.LENGTH_SHORT).show()
}
@vontell
vontell / ChipView.kt
Last active January 30, 2018 19:03
002 OnChipRemoveListener
...
// METHODS AND INTERFACE FOR THE CHIP REMOVAL LISTENER -------------------------------------------------------
/**
* Interface definition for a callback to be invoked when a ChipView remove button is clicked.
*/
interface OnChipRemovedListener {
/**
* Called when a ChipView remove button has been clicked
*
@vontell
vontell / ChipView.kt
Created January 30, 2018 18:44
002 Displaying ChipView Properties
...
// METHODS FOR PROPERLY DISPLAYING THE SET INFORMATION -----------------------------------------
/**
* Displays a new ChipView label by setting the layout's text and reloading the view.
*/
private fun displayText() {
if (text != null) {
chip_text.text = text
@vontell
vontell / ChipView.kt
Created January 30, 2018 18:40
002 ChipView Properties
...
// VARIABLE DEFINITIONS AND SETTERS FOR PROPERLY LOADING INFORMATION ---------------------------
var text : String? = null
/**
* Sets the text label for this ChipView
* @param value The string to set for this label
*/
set(value) {
@vontell
vontell / ChipView.kt
Created January 30, 2018 18:03
002 ChipView Constructors / Intro
/**
* A simple ChipView class for chips in Android. Provides image, text, and listener
* functionality.
*/
class ChipView: LinearLayout {
constructor(context: Context) : this(context, null)
constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
@vontell
vontell / attrs.xml
Created January 27, 2018 17:22
002 ChipView Attributes
<resources>
...
<declare-styleable name="ChipView">
<attr name="imageSrc" format="integer" />
<attr name="text" format="string" />
<attr name="imageURL" format="string" />
</declare-styleable>
...
</resources>
@vontell
vontell / chip_example.xml
Created January 27, 2018 17:01
002 Example Chip in Layout
<ChipView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:imageSrc="@drawable/my_chip_image"
app:text="@string/my_chip_text"/>
@vontell
vontell / view_chip.xml
Last active January 29, 2018 22:14
002 Chip View Layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:background="@drawable/chip_background"
android:layout_width="wrap_content"
android:layout_height="32dp">
<!--
The circular image on the left of the chip
-->