Skip to content

Instantly share code, notes, and snippets.

View searover's full-sized avatar
💭
I may be slow to respond.

Edmund Lu searover

💭
I may be slow to respond.
View GitHub Profile
@searover
searover / CustomTitleView.java
Last active August 29, 2015 14:18
android-snippets
/**
* Created by searover on 3/29/15.
*/
public class CustomTitleView extends View {
/**
* 文本
*/
private String mTitleText;
@searover
searover / Utils.java
Last active August 29, 2015 14:18
android code for checking is online
public boolean isOnline() {
ConnectivityManager connMgr = (ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
return (networkInfo != null && networkInfo.isConnected());
}
@searover
searover / TypeArrayUsage.java
Created April 12, 2015 10:40
A TypeArray usage
TypedArray array = context.getTheme().obtainStyledAttributes(attrs,
R.styleable.PieChart,0,0);
try {
mShowText = array.getBoolean(R.styleable.PieChart_showText,false);
mTextPos = array.getInteger(R.styleable.PieChart_labelPosition,0);
}finally {
array.recycle();
}
@searover
searover / obtainStyledAttributes.java
Last active August 29, 2015 14:19
Resources obtainStyledAttributes function
public TypedArray obtainStyledAttributes(AttributeSet set,
int[] attrs, int defStyleAttr, int defStyleRes) {
final int len = attrs.length;
final TypedArray array = TypedArray.obtain(Resources.this, len);
// other code .....
return array;
}
@searover
searover / TypedArray.java
Created April 12, 2015 10:49
TypedArray Class
/**
* Container for an array of values that were retrieved with
* {@link Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
* or {@link Resources#obtainAttributes}. Be
* sure to call {@link #recycle} when done with them.
*
* The indices used to retrieve values from this structure correspond to
* the positions of the attributes given to obtainStyledAttributes.
*/
public class TypedArray {
@searover
searover / NetworkHelper.java
Created July 22, 2015 11:27
The HTTP Get and Post request method based on Apache HttpClient
package com.anchnet.ddos.report.utils;
import com.anchnet.ddos.report.beans.MessagePack;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import java.io.IOException;
package com.searover.hctest;
import org.apache.commons.lang.time.StopWatch;
import org.apache.http.HttpEntity;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
@searover
searover / TrackCounter.java
Last active September 26, 2015 07:39
Using parameterized advice to count how many times a track is played
package soundsystem;
import java.util.HashMap;
import java.util.Map;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
@Aspect
public class TrackCounter{
public class LinkedStack<T> {
private static class Node<U> {
U item;
Node<U> next;
Node(){
item = null;
next = null;
}
Node(U item, Node<U> next){
this.item = item;
class VolatileExample {
int x = 0;
volatile boolean v = false;
void writer() {
x = 42;
v = true;
}
void reader() {