Skip to content

Instantly share code, notes, and snippets.

View AdamMc331's full-sized avatar

Adam McNeilly AdamMc331

View GitHub Profile
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Get the top text view
TextView top = (TextView) findViewById(R.id.top_text_view);
// Get the bottom text view
TextView bottom = (TextView) findViewById(R.id.bottom_text_view);
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fab="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/toolbar"/>
<FrameLayout
// The app level
apply plugin: 'com.android.application'
android {
def globalConfiguration = rootProject.extensions.getByName("ext")
compileSdkVersion globalConfiguration["androidCompileSdkVersion"]
buildToolsVersion globalConfiguration["androidBuildToolsVersion"]
@AdamMc331
AdamMc331 / Test.java
Last active May 21, 2017 04:33
Demonstrates how much boilerplate is removed by using Kotlin's `firstOrNull{}` extension.
public static String getKeyForClass(Class<?> classToCheck) {
int index = -1;
int internalClassesLength = ManagerRegistry.INTERNAL_CLASSES.size();
// Check if this class has a superclass defined in this project.
for (int i = 0; i < internalClassesLength; i++) {
if (ManagerRegistry.INTERNAL_CLASSES.get(i).isAssignableFrom(classToCheck)) {
index = i;
break;
}
@AdamMc331
AdamMc331 / Task.java
Created June 22, 2017 18:12
Shows how using a data class removes boilerplate in Kotlin. Getters/setters are built in, you're allowed default parameters so you can eliminate overloaded constructors, and the 'data' keyword gives you toString, equals, and hashCode.
package com.adammcneilly.todolist.test;
import java.util.Date;
public class Task {
private String description;
private Date date;
private boolean isCompleted;
public Task() {
@AdamMc331
AdamMc331 / Adapter.kt
Created July 18, 2017 04:13
Inline functions are neat.
// Examples of it being used inside a RecyclerView.adapter class
// Now, each instance of onCreateViewHolder is just one line instead of the same 3 every time.
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): AccountViewHolder {
return createViewHolder(::AccountViewHolder, R.layout.list_item_account, parent)
}
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): CategoryViewHolder {
return createViewHolder(::CategoryViewHolder, R.layout.list_item_textview, parent)
}
@AdamMc331
AdamMc331 / WrapContentViewPager.java
Created July 21, 2017 16:17
WrapContentViewPager
public class WrapContentViewPager extends ViewPager{
public WrapContentViewPager(Context context) {
this(context, null);
}
public WrapContentViewPager(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
}
import React, { Component } from 'react';
import { SectionList, StyleSheet, Text, View} from 'react-native';
export default class SectionListBasics extends Component {
render() {
return (
<View style={styles.container}>
<SectionList
sections={[
{title: 'D', data: ['Devin']},
/**
* We declare a package-level function main which returns Unit and takes
* an Array of strings as a parameter. Note that semicolons are optional.
*/
import java.util.Random
fun CharRange.startIndex() = indexOf(start)
fun CharRange.endIndex() = indexOf(endInclusive)
fun CharRange.random() = elementAt(Random().nextInt(endIndex() - startIndex()) + startIndex())
@AdamMc331
AdamMc331 / StaticEnum.kt
Created November 27, 2017 21:51
Shows how you can statically import an Enum class to reference it shorthand.
/**
* We declare a package-level function main which returns Unit and takes
* an Array of strings as a parameter. Note that semicolons are optional.
*/
import Status.OFF
enum class Status {
ON,
OFF
}