Skip to content

Instantly share code, notes, and snippets.

@BenDLH
BenDLH / CenteredTitleToolbar.java
Last active November 18, 2020 08:14
The Joy of Custom Views: How to make a centered title Toolbar in Android
//
// CenteredTitleToolbar
//
// Created by Ben De La Haye on 25/05/2016.
//
public class CenteredTitleToolbar extends Toolbar {
private TextView _titleTextView;
private int _screenWidth;
private boolean _centerTitle = true;
@BenDLH
BenDLH / PaddingItemDecoration.java
Last active July 28, 2024 11:13
Item decoration to add padding vertically and horizontally to RecyclerViews using Linear and Grid layout managers.
//
// Created by Ben on 28/09/2016.
// Copyright (c) 2016 SHAPE A/S. All rights reserved.
//
public class PaddingItemDecoration extends RecyclerView.ItemDecoration {
private final Context _context;
private Resources _resources;
private Paint _paint = new Paint(Paint.ANTI_ALIAS_FLAG);
//
// Usage :
// recyclerView.setLayoutManager(new SmoothScrollingLayoutManager(getContext()));
// recyclerView.smoothScrollToPosition(0);
//
//
// SmoothScrollingLayoutManager
// Makersphere
//
Open a terminal window and cd into a folder under the repository. Then:
git fsck | awk '{print $3}' > tmp.txt
cat tmp.txt | xargs git show > tmp2.txt
Now open tmp2.txt in editor, locate your lost code, and find the commit-id on top of it. Then apply the code:
git stash apply <commit id>
rm tmp.txt tmp2.txt
@BenDLH
BenDLH / GoogleSignInManager.java
Created October 4, 2016 07:52
Helper class for integrating Google sign in on Android
//
// GoogleSignInManager
// Created by Ben De La Haye on 24/03/2016.
//
public class GoogleSignInManager implements GoogleApiClient.OnConnectionFailedListener {
public interface Listener {
void onUserSignedIn(GoogleSignInAccount account);
void onUserSignInFailed(int errorCode, String errorMessage);
void onUserDataRetrieved(@Nullable Person person);
@BenDLH
BenDLH / BaseAuthActivity.java
Created October 4, 2016 07:56
A basic implementation of the GoogleSignInManager
//
// BaseAuthActivity
// Created by Ben De La Haye on 28/04/2016.
//
public abstract class BaseAuthActivity extends BaseActivity implements GoogleSignInManager.Listener, Callback<LoginResponse> {
private GoogleSignInManager _googleSignInManager;
private AuthenticatedUser authenticatedUser;
public abstract void onUserLoggedIn();
@BenDLH
BenDLH / ParallaxScrollBehaviour.java
Last active February 21, 2017 13:05
CoordinatorLayout behaviour for a parallaxing header above a RecyclerView
//
// ParallaxScrollBehaviour
// Created by Ben De La Haye on 17/10/2016
//
public class ParallaxScrollBehavior<V extends View> extends CoordinatorLayout.Behavior<V> {
private static final float PARALLAX_RATIO = 0.8f;
private RecyclerView _recyclerView;
@BenDLH
BenDLH / parallax_header_example.xml
Last active October 18, 2016 07:30
Sample implementation of the ParallaxScrollBehaviour
<?xml version="1.0" encoding="utf-8"?>
<layout 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.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
@BenDLH
BenDLH / commands.txt
Created October 22, 2016 18:06
Connect to Dragonboard 410c GPIO's via adb
adb devices (See if Dragonboard is connected)
adb shell (Open shell on Dragonboard)
su (Need super user access)
cd sys/class/gpio (Navigate to GPIO directory)
==> GPIO pin numbers are offset by 902 (pin 34 => GPIO 935)
echo {GPIO number, eg. 935} > export (Exports GPIO to be accessed and modified)
cd {exported GPIO number directory, eg. gpio935}
ls (Lists commands available for GPIO)
cat direction (prints direction (IN or OUT))
@BenDLH
BenDLH / CloudTemp-v5.ino
Created December 11, 2016 13:12
Reads temp and humidity from DHT22 sensor and writes values to LCD panel, Particle server and Serial.
#include "Adafruit_DHT.h"
#include "LiquidCrystal.h"
//
// Ben De La Haye
// CloudTemp-v5.ino
//
// Reads temp and humidity from DHT22 sensor and writes values to LCD panel, Particle
// server and Serial.