Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View yenerm's full-sized avatar

Murat Yener yenerm

  • Google
  • San Francisco
View GitHub Profile
<!-- Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
package com.android.examples.myawesomeapp.ui.home
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
<!-- Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:orientation="vertical"
android:layout_width="match_parent"
@yenerm
yenerm / activity_main.xml
Last active April 12, 2020 17:42
Final code
<!-- Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:orientation="vertical"
android:layout_width="match_parent"
@yenerm
yenerm / activity_main.xml
Last active April 12, 2020 17:42
Starter
<!-- Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/container"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" >
@yenerm
yenerm / fragment_home.xml
Last active April 12, 2020 17:42
Starter
<!-- Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
@yenerm
yenerm / Singleton.java
Created April 17, 2020 19:22
Naive singleton implementation
<!-- Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
public class Singleton{
private static Singleton INSTANCE;
private Singleton(){}
public static Singleton getInstance(){
if (INSTANCE == null){
INSTANCE = new Singleton();
}
@yenerm
yenerm / Singleton.java
Last active May 4, 2020 16:07
Double locking singleton
<!-- Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
public class Singleton{
private static Singleton INSTANCE;
private Singleton(){}
public static Singleton getInstance(){
if (INSTANCE == null) { // Single Checked
synchronized (Singleton.class) {
if (INSTANCE == null) { // Double checked
@yenerm
yenerm / Singleton.kt
Last active May 4, 2020 16:10
Kotlin singleton converted from Java
<!-- Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
class Singleton private constructor() {
private var count = 0
fun count(): Int {
return count++
}
companion object {
@yenerm
yenerm / Singleton.kt
Created April 17, 2020 19:30
Singleton via object
<!-- Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
object Singleton {
private var count: Int = 0
fun count() {
count++
}
}
@yenerm
yenerm / Singleton.java
Created April 17, 2020 19:32
Kotlin object decompiled to Java
<!-- Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
public final class Singleton {
private static int count;
public static final Singleton INSTANCE;
public final int getCount() {return count;}
public final void setCount(int var1) {count = var1;}
public final int count() {
int var1 = count++;