Skip to content

Instantly share code, notes, and snippets.

@billynyh
billynyh / VerticalScrollView.js
Created August 25, 2012 03:16
Using horizontal viewpager inside vertical scrollview
//http://stackoverflow.com/questions/2646028/android-horizontalscrollview-within-scrollview-touch-handling
public class VerticalScrollView extends ScrollView {
private float xDistance, yDistance, lastX, lastY;
public VerticalScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
@billynyh
billynyh / gist:3495860
Created August 28, 2012 07:30
read android app meta-data
// get meta-data from AndroidManifest.xml
ApplicationInfo ai = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);
String meta = ai.metaData.getString("key");
// get version name and version code
PackageInfo pinfo = getPackageManager().getPackageInfo(getPackageName(), 0);
String versionName = pinfo.versionName;
int versionCode = pinfo.versionCode;
@billynyh
billynyh / gist:3565241
Created September 1, 2012 06:08
my default styles.xml
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppTheme" parent="android:Theme.Light" />
<style name="FP">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">fill_parent</item>
</style>
<style name="WC">
<item name="android:layout_width">wrap_content</item>
@billynyh
billynyh / gist:3719885
Created September 14, 2012 04:57
my android text helper : strike text, underline, decimal format
public class TextHelper {
public static SpannableString strikeText(String text){
if (text==null)text = "";
SpannableString str = new SpannableString(text);
str.setSpan(new StrikethroughSpan(), 0, str.length(), Spanned.SPAN_PARAGRAPH);
return str;
}
public static SpannableString underlineText(String text){
if (text==null)text = "";
SpannableString str = new SpannableString(text);
@billynyh
billynyh / gist:3779607
Created September 25, 2012 02:25
adb command list
// home intent
adb shell am start -c android.intent.category.HOME -a android.intent.action.MAIN
@billynyh
billynyh / gist:3869877
Last active October 11, 2015 13:58
common command
# recursive cat
find . -name '*.php' | xargs wc -l
# format json
echo '{"json":"obj"}' | python -mjson.tool
# git diff
git difftool --tool=tkdiff --no-prompt
# grep
@billynyh
billynyh / gist:4037680
Created November 8, 2012 09:10
iosched 2012 - handle fragment in onSaveInstanceState
// iosched/android/src/com/google/android/apps/iosched/ui/HomeActivity.java
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
// Since the pager fragments don't have known tags or IDs, the only way to persist the
// reference is to use putFragment/getFragment. Remember, we're not persisting the exact
// Fragment instance. This mechanism simply gives us a way to persist access to the
// 'current' fragment instance for the given fragment (which changes across orientation
@billynyh
billynyh / gist:4043695
Created November 9, 2012 04:27
android monkeyrunner screencap
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice, MonkeyImage
import datetime
def capture_and_save(fname):
device = MonkeyRunner.waitForConnection()
snapshot = device.takeSnapshot()
snapshot.writeToFile(fname)
def capture(prefix=""):
d = datetime.datetime.now()
@billynyh
billynyh / RoundedCornerImageView.java
Created November 28, 2012 04:07
#android rounded corner ImageView
//http://stackoverflow.com/questions/1705239/how-should-i-give-images-rounded-corners-in-android
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Path;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.ImageView;
@billynyh
billynyh / gist:4276985
Created December 13, 2012 15:06
android pattern repeat drawable
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/leather_1"
android:tileMode="repeat" />