This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private val Context.picasso: Picasso | |
get() = Picasso.with(this) | |
private fun CircleImageView?.load(path: String) { | |
this!!.context.picasso.load(path).into(this) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
// 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 | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
// 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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<resources> | |
... | |
<declare-styleable name="ChipView"> | |
<attr name="imageSrc" format="integer" /> | |
<attr name="text" format="string" /> | |
<attr name="imageURL" format="string" /> | |
</declare-styleable> | |
... | |
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ChipView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
app:imageSrc="@drawable/my_chip_image" | |
app:text="@string/my_chip_text"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 | |
--> |
NewerOlder