Skip to content

Instantly share code, notes, and snippets.

public class RoundedDrawable extends Drawable {
private static final boolean USE_VIGNETTE = true;
private RectF mRect = new RectF();
private final Paint paint;
private final int mRadius;
private final BitmapShader bitmapShader;
public RoundedDrawable(Bitmap bitmap, int radius) {
bitmapShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
paint = new Paint();
@twocity
twocity / build.gradle
Created December 17, 2013 08:00
gradle ndk build
/////////////
// NDK Support
//////////////
// If using this, Android studio will fail run the following to set the environment variable for android studio:
// export ANDROID_NDK_HOME=/Android/android-ndk-r8e (Linux)
// launchctl setenv ANDROID_NDK_HOME /Android/android-ndk-r8e (Mac)
// or, better, add the export to the .profile of your user home and re-login
task copyNativeLibs(type: Copy, dependsOn: 'buildNative') {
from(new File('src/main/libs')) { include '**/*.so' }
into new File(buildDir, 'native-libs')
@twocity
twocity / build.gradle
Last active December 11, 2021 09:13
android gradle change output apk file name.
android.applicationVariants.all { variant ->
println "*********" + variant.description + "**********";
def variants = variant.baseName.split("-");
def apkName = "ricebook-";
apkName += variants[0];
apkName += "-v" + android.defaultConfig.versionName;
if (!variant.zipAlign) {
apkName += "-unaligned";
}
if (variant.buildType.name == "release") {
@twocity
twocity / ApiApplication.java
Created February 25, 2014 07:42
usage of ricebook api client
package com.ricebook.app.api;
import com.ricebook.app.api.utils.OkClientFactory;
import com.ricebook.app.api.utils.RestAdapterFactory;
import android.app.Application;
import retrofit.RestAdapter;
/**
@twocity
twocity / UiHandler
Created April 2, 2014 14:43
A thin wrapper of {@link Handler} to run a callback in UI thread,copy of UnifiledEmail
/*
* Copyright (C) 2012 Google Inc.
* Licensed to 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
*
@twocity
twocity / shise
Created September 18, 2014 09:09
var s2t = function(str) {
var _str = '';
var po;
for(var i=0; i < str.length; i++) {
if((po = sMap.indexOf(str.charAt(i))) != -1)
_str += tMap.charAt(po);
else
_str += str.charAt(i);
}
return _str;
@twocity
twocity / gist:0eab5e5075a8a2d3dd1e
Created September 24, 2014 10:26
DemoObserverActivity
public class DemoObserverActivity extends ObserverActivity<String> {
final Observable<String> observable = Observable.just("hello", "world");
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
loadData();
loadData2();
}
private void loadData() {
### Run this script via a cronjob every (every minute or so) on a server that has access to your dropbox.
### You must install youtube-dl (http://rg3.github.com/youtube-dl/) for this to work.
#!/bin/bash
QUEUE_DIR=~/Desktop/Dropbox/IFTTT/youtube-dl/*.txt
VIDEO_DIR=~/Desktop/Dropbox/youtube/
shopt -s nullglob
for queue_file in $QUEUE_DIR
do
video_url=`cat "$queue_file"`;
@twocity
twocity / BindingGraphValidator.md
Last active August 29, 2015 14:22
validateDependencyScopes
/**
   * Validates that among the dependencies are at most one scoped dependency,
   * that there are no cycles within the scoping chain, and that singleton
   * components have no scoped dependencies.
   */
  private void validateDependencyScopes(BindingGraph subject,
      Builder<BindingGraph> reportBuilder) {
    ComponentDescriptor descriptor = subject.componentDescriptor();
    Optional<AnnotationMirror> scope = subject.componentDescriptor().scope();
Step1
Remove deprecated modules(overide, library,complete),ObjectGraph
Step2
Define Dagger2 style Component and module
Step3
Inject
@ApplicationScope
ApplicationComponent
NetworkModule
Okhttp