Skip to content

Instantly share code, notes, and snippets.

@marvinlix
marvinlix / ItemClickSupport.java
Created August 25, 2016 06:19 — forked from nesquena/ItemClickSupport.java
Click handling for RecyclerView
/*
Source: http://www.littlerobots.nl/blog/Handle-Android-RecyclerView-Clicks/
USAGE:
ItemClickSupport.addTo(mRecyclerView).setOnItemClickListener(new ItemClickSupport.OnItemClickListener() {
@Override
public void onItemClicked(RecyclerView recyclerView, int position, View v) {
// do it
}
});
import android.support.v7.widget.RecyclerView;
public class RecyclerViewSwipeListener extends RecyclerView.OnFlingListener {
private static final int SWIPE_THRESHOLD = 100;
private static final int SWIPE_VELOCITY_THRESHOLD = 100;
boolean mIsScrollingVertically;
// change swipe listener depending on whether we are scanning items horizontally or vertically
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="red_500_primary">#f44336</color>
<color name="red_50">#ffebee</color>
<color name="red_100">#ffcdd2</color>
<color name="red_200">#ef9a9a</color>
<color name="red_300">#e57373</color>
<color name="red_400">#ef5350</color>
<color name="red_600">#e53935</color>
<color name="red_700">#d32f2f</color>
/*
* Copyright 2014 Chris Banes
*
* 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
/*
* Copyright 2014 Chris Banes
*
* 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
@marvinlix
marvinlix / gist:5149532
Created March 13, 2013 05:07
selector.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/btn_share_press"/>
<item android:state_selected="true" android:drawable="@drawable/btn_share_press"/>
<item android:state_focused="true" android:drawable="@drawable/btn_share_press"/>
<item android:state_enabled="false"
@marvinlix
marvinlix / status_bar_height.java
Created May 7, 2012 12:45
get statusbar height
Class<?> c = null;
Object obj = null;
Field field = null;
int x = 0, sbar = 0;
try {
c = Class.forName("com.android.internal.R$dimen");
obj = c.newInstance();
field = c.getField("status_bar_height");
x = Integer.parseInt(field.get(obj).toString());
sbar = getResources().getDimensionPixelSize(x);
@marvinlix
marvinlix / io.java
Created April 26, 2012 15:40
java io example code
package IO;
import java.io.*;
public class FileDirectoryDemo {
public static void main(String[] args) {
// 如果没有指定参数,则缺省为当前目录。
if (args.length == 0) {
args = new String[] { "." };
}
@marvinlix
marvinlix / add_contact.java
Created April 19, 2012 13:57
add contacts in android2.2
/*
主要数据有三张表:contacts, raw_contacts,data。
contacts:主要是raw_contacts的一个合并。
raw_contacts:是每条记录表示一条联系人。
data:最基本的表,其中包含所有联系人的数据。每条记录都有一个mime type代表该记录的类型。
*/
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
ops.add(ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI)
.withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, "com.android.exchange")
@marvinlix
marvinlix / LogActivity.java
Created April 18, 2012 11:26
LogActivity
package com.test.android;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class LogActivity extends Activity {
private String extendClassName = null;