Skip to content

Instantly share code, notes, and snippets.

@wightwulf1944
wightwulf1944 / Employee.java
Created November 22, 2019 10:02
Decorator pattern demonstration
// Only a data class. DO NOT ADD BEHAVIORS
public class Employee {
public Instant dateOfBirth;
public BigDecimal salary;
public float yearsInService;
}
public final class MainFragment extends Fragment {
public MainFragment() {
super(R.layout.fragment_main);
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
BottomNavigationView navigation = requireViewById(view, R.id.navigation);
navigation.setSelectedItemId(R.id.navigation_browse);
package me.devsaki.hentoid;
import android.os.Bundle;
public final class CoordinateActivityBundle {
private static final String KEY_X = "key_x";
private static final String KEY_Y = "key_y";
@wightwulf1944
wightwulf1944 / layout.xml
Created May 4, 2019 07:38
u/yaaaaayPancakes
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="@+id/view_main"
android:layout_width="0dp"
android:layout_height="200dp"
@wightwulf1944
wightwulf1944 / layout.xml
Created May 3, 2019 07:00
for u/yaaaaayPancakes
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="@+id/view_main"
android:layout_width="0dp"
android:layout_height="200dp"
@wightwulf1944
wightwulf1944 / RelevantBindListener.java
Last active February 13, 2019 12:10
adapter bind listener pattern
public class RelevantBindListener {
public RelevantBindListener() {
SampleAdapter adapter = new SampleAdapter();
adapter.setOnLastItemBindListener(this::onAdapterLastItemBind);
}
private void onAdapterLastItemBind() {
// THIS IS CALLED WHEN THE LAST ADAPTER ITEM IS BIND.. BOUND? BINDED??
}
public class HelloWorldActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
int notificationId = 0;
NotificationManager notificationManager = new NotificationManager(this, notificationId);
notificationManager.notify(new HelloWorldNotification());
@wightwulf1944
wightwulf1944 / Wat.txt
Created July 13, 2018 13:35
Pseudocode recover from exception
doTheThing() {
var result1 = function1Safe()
var result2 = function2Safe()
return result1 + result2
}
function1Safe() {
try {
return function1()
} catch {
package shiro.am.i.sliderexample;
import android.content.Context;
import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.LinearSnapHelper;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
public class DownloadManager implements Closeable {
private static final int MAX_TRIES = 3;
private final Realm realm = Realm.getDefaultInstance();
@Override
public void close() {
realm.close();
}