Skip to content

Instantly share code, notes, and snippets.

View richardleggett's full-sized avatar

Richard Leggett richardleggett

View GitHub Profile
@richardleggett
richardleggett / FactoryViewModels.kt
Created May 12, 2022 17:49
AssistedInject HiltViewModels for Compose Navigation
// Screen VM
class ScreenOneViewModel @AssistedInject constructor(
// deviceManager is scoped to a flow's sub-NavGraph
@Assisted private val deviceManager: SomeBLEDeviceManager,
@Assisted private val someIdArg: Int,
logger: Logger,
otherThing: SomeOtherDependency,
) : CoroutineViewModel<ViewState, UiAction> { ... }
@richardleggett
richardleggett / README.md
Last active September 11, 2017 14:39
Lombok in Android Studio 2.2 with Jack Compiler

Steps

  1. Install the Lombok plugin via Android Studio -> Preferences -> Plugins (Search repositories).
  2. Enable Annotation Processing. With the project open go to: File -> Other Settings -> Default Settings Build, Executio... -> Compiler -> Annotation Processors
  3. Finally to be sure click File -> Invalidate Cache and Restart Android Studio

What does Lombok do?

@richardleggett
richardleggett / AndroidManifest.xml
Last active June 26, 2021 13:58
BOOT_COMPLETED
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myapphere">
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="9" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
@richardleggett
richardleggett / BaseMyContentProviderTestCase.java
Last active June 26, 2021 13:59
Using SQLCipher with ProviderTestCase2 Example
package my.app.test;
import android.content.ContentResolver;
import android.content.Context;
import android.content.SyncInfo;
import android.os.Environment;
import android.test.ProviderTestCase2;
import android.util.Log;
import net.sqlcipher.database.SQLiteDatabase;
@richardleggett
richardleggett / RoundedFrameLayout.java
Created September 4, 2014 15:45
RoundedFrameLayout - FrameLayout clipped by a rounded rectangle
package com.example.ui.widget;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Path;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
@richardleggett
richardleggett / CustomMediaController.java
Created April 24, 2014 12:36
Custom MediaController that fixes issue with controls appearing offset on pre 4.3 devices and shows how to add additional functionality such as fullscreen button
package com.app.video.ui;
import android.content.Context;
import android.os.Build;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.FrameLayout;
@richardleggett
richardleggett / Parcelable testing strategy
Last active December 30, 2015 03:49
Forgetting to balance the Parcelable read/write calls can lead to inconsistent state. Here's some helper code for testing objects that implement Parcelable...
public void testParcelableThing() throws Exception {
// sample usage
MyParcelableThing parcelable = getTheThing();
Parcel parcel = Parcel.obtain();
parcelable.writeToParcel(parcel, 0);
parcel.setDataPosition(0);
MyParcelableThing unparcelled = new MyParcelableThing(parcel);
@richardleggett
richardleggett / imagepickersnippet
Last active December 19, 2015 19:39
Image picker (camera and Photo Library) snippet
- (void)photoViewTapHandler:(UITapGestureRecognizer *)gesture {
UIActionSheet *popupQuery = [[UIActionSheet alloc] initWithTitle:@"Picture Selection" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Take a photo", @"Choose from Photo Library", nil];
popupQuery.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[popupQuery showInView:self.view];
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
[self showCamera];
} else if(buttonIndex == 1) {
@richardleggett
richardleggett / AutoHighlightImageButton
Last active December 16, 2015 01:38
Android ImageButton that automatically darkens on press, as with iOS UIButton's default highlight. The draw() method is overridden to alpha out the button if disabled. The idea is you quickly get button states without providing state list drawables.
// if you're wanting to put these inside an AdapterView, replace ImageButton below with ImageView
public class AutoHighlightImageButton extends ImageButton {
private boolean mIsPressed;
public AutoHighlightImageButton(Context context) {
super(context);
init();
}
public AutoHighlightImageButton(Context context, AttributeSet attrs) {