Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View lucasr's full-sized avatar

Lucas Rocha lucasr

View GitHub Profile
@lucasr
lucasr / LazyMeasurementInterceptor.java
Created October 9, 2014 20:39
Lazy measurement with Probe (Experimental)
/*
* Copyright (C) 2014 Lucas Rocha
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@lucasr
lucasr / sample.java
Created September 1, 2014 13:20
Using ItemSelectionSupport from TwoWayView
ItemSelectionSupport itemSelection = ItemSelectionSupport.addTo(recyclerView);
itemSelection.setChoiceMode(ChoiceMode.MULTIPLE);
itemSelection.setItemChecked(2, true);
@lucasr
lucasr / GridAndListLayout.java
Last active March 29, 2017 15:35
Mixed grid/list layout built with the new TwoWayView API
public class GridAndListLayout extends TwoWayLayoutManager {
private final int NUM_LANES = 2;
public GridAndListLayout(Context context, Orientation orientation) {
super(context, orientation);
}
private boolean isGridItem(int position) {
return position < 4;
}
@lucasr
lucasr / SimpleListLayout.java
Last active May 2, 2020 06:21
List layout built with the new TwoWayView API
public class SimpleListLayout extends TwoWayLayoutManager {
public SimpleListLayout(Context context, Orientation orientation) {
super(context, orientation);
}
@Override
protected void measureChild(View child, Direction direction) {
measureChildWithMargins(child, 0, 0);
}
@lucasr
lucasr / sample.java
Last active March 5, 2016 03:41
Using ItemClickSupport from TwoWayView
ItemClickSupport itemClick = ItemClickSupport.addTo(recyclerView);
itemclick.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(RecyclerView p, View c, int pos, long id) {
...
}
});
itemClick.setOnItemLongClickListener(new OnItemLongClickListener() {
@lucasr
lucasr / StaticLayoutWithMaxLines.java
Last active March 1, 2024 15:47
Use StaticLayout's max lines support on ICS+
package org.lucasr.layoutsamples.canvas;
import android.os.Build;
import android.text.Layout.Alignment;
import android.text.StaticLayout;
import android.text.TextDirectionHeuristic;
import android.text.TextDirectionHeuristics;
import android.text.TextPaint;
import android.text.TextUtils.TruncateAt;
import android.util.Log;
@lucasr
lucasr / AnimatedLinearLayout.java
Last active December 16, 2022 19:58
Animated LinearLayout
package com.example.android_transition_samples.app;
import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;
@lucasr
lucasr / MainActivity.java
Last active November 20, 2017 19:02
Animated ListView with TransitionManager
package org.lucasr.transition.samples;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.transition.TransitionManager;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ListView;
@lucasr
lucasr / dark-google-docs-firefox.css
Last active December 17, 2015 02:38
Distraction-free dark Google Docs style. Requires the Stylish add-on for Firefox. Add a new style and copy the CSS below.
@namespace url(http://www.w3.org/1999/xhtml);
@-moz-document url-prefix("https://docs.google.com/document/") {
#docs-editor {
background-color: #000000 !important;
}
.kix-page {
background-color: #000000 !important;
border-top: 0px !important;
@lucasr
lucasr / DeveloperUtils.java
Created December 18, 2012 13:05
Simple and fairly reliable way of checking if you're running a debug build of your Android app.
package org.lucasr;
import java.io.ByteArrayInputStream;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import javax.security.auth.x500.X500Principal;
import android.content.Context;
import android.content.pm.PackageManager;