Skip to content

Instantly share code, notes, and snippets.

Avatar

Murat Yener yenerm

  • Google
  • San Francisco
View GitHub Profile
View HomeFragment.kt
<!-- 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
View activity_main.xml
<!-- 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"
View activity_main.xml
<!-- 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"
View activity_main.xml
<!-- 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" >
View fragment_home.xml
<!-- 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 Apr 17, 2020
Naive singleton implementation
View Singleton.java
<!-- 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
Double locking singleton
View Singleton.java
<!-- 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
Kotlin singleton converted from Java
View Singleton.kt
<!-- 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 Apr 17, 2020
Singleton via object
View Singleton.kt
<!-- 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 Apr 17, 2020
Kotlin object decompiled to Java
View Singleton.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++;