Skip to content

Instantly share code, notes, and snippets.

float scale = getResources().getDisplayMetrics().density;
int dpAsPixels = (int) (sizeInDp*scale + 0.5f);
language: android
jdk: oraclejdk7
env:
matrix:
- ANDROID_TARGET=android-19 ANDROID_ABI=armeabi-v7a
android:
components:
- build-tools-19.0.3
@burntcookie90
burntcookie90 / CheckableLinearLayout.java
Last active August 29, 2015 14:02
Checkable layout
public class CheckableLinearLayout extends LinearLayout implements Checkable {
private static final int[] CHECKED_STATE_SET = { android.R.attr.state_checked };
private boolean mChecked;
private OnCheckedChangeListener mOnCheckedChangeListener;
public CheckableLinearLayout(Context context) {
super(context, null);
}
public CheckableLinearLayout(Context context, AttributeSet attrs) {
@burntcookie90
burntcookie90 / card_bg.xml
Created June 6, 2014 18:08
Android Cards UI background
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle"
android:dither="true">
<corners android:radius="2dp"/>
<solid android:color="#dbdbdb" />
</shape>
</item>
@burntcookie90
burntcookie90 / build.gradle
Created June 24, 2014 20:06
basic build.gradle for a library project
apply plugin: 'android-library'
android {
compileSdkVersion 19
buildToolsVersion '19.1'
defaultConfig {
minSdkVersion 15
targetSdkVersion 19
versionCode 1
language: android
jdk: oraclejdk7
env:
matrix:
- ANDROID_TARGET=android-L ANDROID_ABI=armeabi-v7a
android:
components:
- build-tools-19.1
before_install:
# Install base Android SDK
/*
* Copyright (C) 2013 The Android Open Source Project
*
* 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
@burntcookie90
burntcookie90 / chrome-os-apk.py
Last active August 29, 2015 14:06
Python script to automate the creation of a chromeos apk during development
#!/usr/local/bin/python
import shutil
import json
from subprocess import call
import os
shutil.copyfile("app/build/outputs/apk/app-debug.apk", <packagename.apk>)
os.system("chromeos-apk <packagename.apk> -a")
with open('<packagename.apk>.android/manifest.json', "r+") as manifestFile:
manifestJson = json.load(manifestFile)
manifestJson["permissions"].append(<extra permissions>)
@burntcookie90
burntcookie90 / BaseFragment.java
Created September 22, 2014 14:08
BaseFragment class that handles registration with the event bus
public class BaseFragment extends Fragment {
public BaseFragment() {}
@Override public void onResume() {
super.onResume();
BusProvider.getInstance().register(this);
}
@burntcookie90
burntcookie90 / Events.java
Last active August 29, 2015 14:07
RxLoginExample
package com.example.vrajeevan.rxloginexample.rx;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.MotionEvent;
import android.widget.Button;
import android.widget.TextView;
import rx.Observable;
import rx.subjects.BehaviorSubject;