Skip to content

Instantly share code, notes, and snippets.

🚀
Building Coinverse's Android app

AdamHurwitz AdamSHurwitz

🚀
Building Coinverse's Android app
Block or report user

Report or block AdamSHurwitz

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@AdamSHurwitz
AdamSHurwitz / someMenuStyle.xml
Created Mar 25, 2020
ODG - Toolbar: Menu style
View someMenuStyle.xml
<style name="GroupsToolBarTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:colorPrimaryDark">@color/statusBar</item>
<item name="android:textColor">@color/white</item>
<item name="android:textSize">19sp</item>
<!--Menu style-->
<item name="popupTheme">@style/PopUpMenuStyle</item>
<!--Menu item color-->
<item name="colorControlNormal">@color/splash_title</item>
@AdamSHurwitz
AdamSHurwitz / CollapsingToolBarLayoutListener.kt
Last active Mar 25, 2020
ODG - Toolbar: CollapsingToolBarLayout listener
View CollapsingToolBarLayoutListener.kt
appBar.addOnOffsetChangedListener(object : AppBarLayout.OnOffsetChangedListener {
override fun onOffsetChanged(appBarLayout: AppBarLayout, verticalOffset: Int) {
if (Math.abs(verticalOffset) - appBarLayout.getTotalScrollRange() == 0) {
// Collapsed
} else {
// Expanded
}
}
})
@AdamSHurwitz
AdamSHurwitz / SomeStyles.xml
Last active Mar 25, 2020
ODG - Toolbar: Theme
View SomeStyles.xml
// SomeStyles.xml
<style name="MapTheme">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
// Toolbar color
<item name="colorPrimary">@color/style_guide_primary</item>
// Status bar color
<item name="colorPrimaryDark">@color/style_guide_primary_dark</item>
@AdamSHurwitz
AdamSHurwitz / SampleVectors.xml
Created Mar 22, 2020
ODG - Vectors: Samples
View SampleVectors.xml
// Rectangle
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/listview_background_shape">
<stroke
android:width="1dp"
android:color="@color/replies_offer_indicator_color"/>
<padding
android:bottom="2dp"
android:left="2dp"
@AdamSHurwitz
AdamSHurwitz / SimpleDateFormat.kt
Last active Mar 22, 2020
ODG - Android Date and Time: SimpleDateFormat
View SimpleDateFormat.kt
@BindingAdapter("timestamp")
fun TextView.setTimestamp(createdAt: String) {
val twitterFormat = "EEE MMM dd HH:mm:ss ZZZZZ yyyy"
val simpleDateFormat = SimpleDateFormat(twitterFormat, Locale.getDefault())
val date = simpleDateFormat.parse(createdAt)
simpleDateFormat.applyPattern("h:mm a MMM d")
val newString = simpleDateFormat.format(date)
this.text = newString
}
@AdamSHurwitz
AdamSHurwitz / Calendar.kt
Created Mar 22, 2020
ODG - Android Date and Time: Calendar
View Calendar.kt
val c = Calendar.getInstance()
val minute = c.get(Calendar.MINUTE)
val second = c.get(Calendar.SECOND)
val mSecond = c.get(Calendar.MILLISECOND)
calendar.add(Calendar.DAY_OF_YEAR, timeframeToQuery)
@AdamSHurwitz
AdamSHurwitz / Resource.kt
Created Mar 21, 2020
ODG - UDF: Resource
View Resource.kt
/*
* Copyright (C) 2017 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
@AdamSHurwitz
AdamSHurwitz / dimens.xml
Last active Mar 21, 2020
ODG - Android Resource Files
View dimens.xml
<!--File path: app > src > main > res > values-->
<resources xmlns:tools="http://schemas.android.com/tools">
<!--Default screen margins, per the Android Design guidelines-->
<dimen name="margin_tiniest">2dp</dimen>
<dimen name="margin_tiny">4dp</dimen>
<dimen name="margin_small">8dp</dimen>
<dimen name="margin_medium">16dp</dimen>
<dimen name="margin_large">24dp</dimen>
@AdamSHurwitz
AdamSHurwitz / SomeClass.kt
Created Mar 20, 2020
ODG - Layouts: Padding and Margin
View SomeClass.kt
val viewParams = LayoutType.LayoutParams(
LayoutType.LayoutParams.WRAP_CONTENT,
LayoutType.LayoutParams.WRAP_CONTENT)
viewParams.addRule(LayoutType.BELOW, R.id.id_name)
viewParams.setMargins(leftInt, topInt, intRight, bottomInt)
viewName.setLayoutParams(viewParams)
...
@AdamSHurwitz
AdamSHurwitz / BindingAdapters.kt
Last active Mar 21, 2020
ODG - Data Binding: BindingAdapters
View BindingAdapters.kt
// Custom XML attribute 'app:title="someTitle"'.
@BindingAdapter("title")
fun TextView.setTitle(titleRes: Int) {
this.text = if (titleRes != 0) context.getString(titleRes) else ""
}
// Custom XML attributes 'app:imageUrl="someImageUrl"' and 'app:placeholder="somePlaceholder"'.
@BindingAdapter(value={"imageUrl", "placeholder"}, requireAll=false)
fun ImageView.setImageUrl(url: String, placeHolder: Drawable) {
if (url == null) {
You can’t perform that action at this time.