Skip to content

Instantly share code, notes, and snippets.

View riggaroo's full-sized avatar
🌍

Rebecca Franks riggaroo

🌍
View GitHub Profile
@riggaroo
riggaroo / RestServiceMockUtils.java
Last active May 1, 2021 17:52
Mocking API Responses using a Retrofit Client in Android
public class RestServiceMockUtils {
public static String convertStreamToString(InputStream is) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line).append("\n");
}
reader.close();
@riggaroo
riggaroo / tools_namespace_example.xml
Last active November 2, 2015 07:04
Example usage of the tools namespace for creating a meaningful Design View
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
tools:visibility="visible"
tools:text="Rebecca Franks" />
@riggaroo
riggaroo / BaseResponse.java
Created April 13, 2016 17:27
Retrofit 2.0 - Parsing Error Responses
public static BaseResponseDto parseError(Response<?> response) {
Converter<ResponseBody, BaseResponseDto> converter =
Injection.getRetrofitInstance()
.responseBodyConverter(BaseResponseDto.class, new Annotation[0]);
BaseResponseDto error;
try {
error = converter.convert(response.errorBody());
} catch (IOException e) {
@riggaroo
riggaroo / AndroidManifest.xml
Created April 13, 2016 17:31
Custom Android Espresso Test Runner - Unlocking a Device, Granting Permission to turn animations off, turning the Screen on.
<?xml version="1.0" encoding="utf-8"?>
<!-- Put this file in the "debug" folder so it only gets merged into debug builds -->
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="org.bookdash.android">
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<!-- Disable animations on debug builds so that the animations do not interfere with Espresso
@riggaroo
riggaroo / RecyclerViewAdapterTemplate.java
Created May 2, 2016 16:12
File Template for Android Studio for creating a RecyclerViewAdapter without having to remember much of the boilerplate.
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import java.util.List;
#parse("File Header.java")

Keybase proof

I hereby claim:

  • I am riggaroo on github.
  • I am riggaroo (https://keybase.io/riggaroo) on keybase.
  • I have a public key ASBwdwxxd9GeCz_wXXJYp-hWBxALsHCP9wZLUxYZpcx2cAo

To claim this, I am signing this object:

@riggaroo
riggaroo / MainActivity.java
Last active July 15, 2020 12:30
Online Presence with Firebase and Android based off article https://firebase.googleblog.com/2013/06/how-to-build-presence-system.html . Read the article as it explains the whole .onDisconnect().removeValue() nicely.
private void initialiseOnlinePresence() {
final DatabaseReference onlineRef = databaseReference.child(".info/connected");
final DatabaseReference currentUserRef = databaseReference.child("/presence/" + userId);
onlineRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(final DataSnapshot dataSnapshot) {
Log.d(TAG, "DataSnapshot:" + dataSnapshot);
if (dataSnapshot.getValue(Boolean.class)){
currentUserRef.onDisconnect().removeValue();
currentUserRef.setValue(true);
@riggaroo
riggaroo / FriendsActivity.java
Last active November 23, 2016 17:26
Firebase Staged Rollout Features - Sample Gist showing how to use Firebase Remote Config for stage rollout of features.
public class FriendsActivity extends AppCompatActivity {
private static final String TAG = "MainActivity";
public static final String FEATURE_FLAG_ADD_FRIENDS = "feature_add_friends";
private FirebaseRemoteConfig remoteConfig;
private Button buttonAddFriend;
@Override
protected void onCreate(Bundle savedInstanceState) {
@riggaroo
riggaroo / create_bookdashbook.sh
Last active January 8, 2017 18:57
Script for creating book dash books from PDF for android app.
#/usr/local/bin/bash
# Prerequistes: You need to install imagemagick and pdfimages for this script to work
# Usage - ./convert_book.sh pdf_name.pdf
# output - zip file with images and bookdetails.json file
# This script assumes the normal structure of a book dash book and wont work for bigger books or books with different formatting to the standard book dash book
# it is always advised to check the output zipped file to ensure its correct
folderName=$(basename "$1")
folderName="${folderName%.*}"
import android.content.Context
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.ImageFormat
import android.graphics.Matrix
import android.hardware.camera2.*
import android.hardware.camera2.CameraAccessException.CAMERA_ERROR
import android.media.ImageReader
import android.os.Handler
import android.util.Log