Skip to content

Instantly share code, notes, and snippets.

View deveshmittal's full-sized avatar

Devesh deveshmittal

View GitHub Profile
Let's take a look at the most common implicit intents such as making a phone call, launching a web address, sending an email, etc.
Phone Call
Permissions:
<uses-permission android:name="android.permission.CALL_PHONE" />
Intent:
Intent callIntent = new Intent(Intent.ACTION_CALL);
@deveshmittal
deveshmittal / build.gradle
Last active August 29, 2015 14:14
model Build.gradle
apply plugin: 'com.android.application'
def versionMajor = 2
def versionMinor = 0
def versionPatch = 6
def versionBuild = 0 // bump for dogfood builds, public betas, etc.
android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
public void GenericAsyncTask<T> extends AsyncTask<Void, Void , T>{
public interface TaskCompletionDelegate<T>{
public void onTaskCompleted(T result)}
private Class<T> type;
private TaskCompletionDelegate<T> listener;
public GenericAsyncTask(Class<T> classType , TaskCompletionDelegate listener ){
this.type = classType;
this.listener = listener;
}
@deveshmittal
deveshmittal / gist:5825a7f212bb69c7e674
Created March 19, 2015 14:06
Cursor adapter with multiple view types
private int getItemViewType(Cursor cursor) {
String type = cursor.getString(cursor.getColumnIndex("type"));
if (type.equals("1")) {
return 0;
} else {
return 1;
}
}
@Override
@deveshmittal
deveshmittal / Main.java
Last active August 29, 2015 14:17 — forked from martiell/Main.java
import java.util.Map.Entry;
import java.util.TreeMap;
// See http://stackoverflow.com/a/13400317/611182
public class Main {
private static TreeMap<Double, String> m = new TreeMap<Double, String>();
static {
m.put(1.0, "A");
m.put(2.9, null);
For setting up adb and other platform tools at path.
echo 'export PATH=$PATH:'$HOME'/Library/Android/sdk/platform-tools' >> ~/.bash_profile
To create a symlink :
sudo ln -s ${PWD}/bin/devesh /usr/bin/devesh
@deveshmittal
deveshmittal / gist:ca2437ddb8b10766b358
Created November 13, 2015 19:47
Add environment variable to PATH in mac
/etc/profile
~/.bash_profile
~/.bash_login
~/.profile
@deveshmittal
deveshmittal / MyClass.java
Last active November 18, 2015 17:46
How to write Double check Locking correctly
public class MyClass{
private volatile MyClass myClassObject;
public MyClass getInstance(){
MyClass helper = myClassObject;
// Optimisation for getting instance, if the helper has already been initialised return that.
if(helper == null){
synchronised(MyClass.this){
// Since synchronised block takes some time to initialise ,in the mean time another thread might have entered
// the synchronised block and initialised the helper variable. By ensuring that the myclassObject is volatile, we have established
// a happens-before functionality on the myClassObject.
@deveshmittal
deveshmittal / RetrofitCachingExample.java
Created November 19, 2015 11:06 — forked from swankjesse/RetrofitCachingExample.java
Demonstrate HTTP caching with OkHttp and Retrofit.
/*
* Copyright (C) 2013 Square, Inc.
*
* 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