Skip to content

Instantly share code, notes, and snippets.

View kyze8439690's full-sized avatar
📱
Working

Yang Hui kyze8439690

📱
Working
View GitHub Profile
@kyze8439690
kyze8439690 / android.mk
Created August 14, 2014 01:59
Jni android.mk
#Start from here
LOCAL+PATH:= $(call my-dir)
#Module1 definition start
include $(CLEAR_VARS)
LOCAL_MODULE := modulename1
LOCAL_SRC_FILES := modulesource1.c
include $(BUILD_STATIC_LIBRARY)
@kyze8439690
kyze8439690 / .gitignore
Created March 4, 2015 03:01
android studio project .gitignore file
.gradle
.idea
*.iml
build
gradle*
local.properties
@kyze8439690
kyze8439690 / FilterIntentChooser.java
Created October 14, 2015 06:53
FilterIntentChooser
Intent[] targetedShareIntents = new Intent[infos.size()];
for (int i = 0; i < infos.size(); i++) {
String packageName = infos.get(i).activityInfo.packageName;
Intent targetedShareIntent = new Intent(Intent.ACTION_VIEW, uri);
targetedShareIntent.setPackage(packageName);
targetedShareIntents[i] = targetedShareIntent;
}
Intent chooserIntent = Intent.createChooser(new Intent(), "打开网页");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents);
@kyze8439690
kyze8439690 / styles.xml
Last active December 27, 2015 06:09
In order to make a holo style scrollbar in android 2.3,first you have to import the holo scrollbar resource(sdk/platforms/android-18/data/res/drawable-xhdpi/scrollbar_handle_holo_light.9.png) into your drawable dir, and then to change your style xml
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:scrollbarSize">10.0dip</item><!--very important, in order to show scrollbar properly in android 2.3 and before-->
<item name="android:scrollbarThumbVertical">@drawable/scrollbar</item>
<item name="android:scrollbarThumbHorizontal">@drawable/scrollbar</item>
<item name="android:scrollbarTrackVertical">@null</item>
<item name="android:scrollbarTrackHorizontal">@null</item>
</style>
</resources>
@kyze8439690
kyze8439690 / setListViewDivider.java
Created November 2, 2013 17:22
set ListView divider drawable and height programmatically,must setDivider(Drawble) fiist, and then setDividerHeight, otherwise, the dividerheight will be 0.
getListView().setDivider(getResources().getDrawable(R.color.list_background)); //must be called first
getListView().setDividerHeight(FuncInt.dp(10));
@kyze8439690
kyze8439690 / singleton.java
Created November 4, 2013 12:53
singleton pattern
public class Singleton {
private static Object obj = new Object();
private static Singleton instance = null;
private Singleton(){
}
public static Singleton getInstance() {
// if already inited, no need to get lock everytime
@kyze8439690
kyze8439690 / convertBitmap.java
Created November 11, 2013 06:53
fix android 2.3 can't decode bitmap in rgba8888 format
public static Bitmap convert(Bitmap bitmap, Bitmap.Config config) {
Bitmap convertedBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), config);
Canvas canvas = new Canvas(convertedBitmap);
Paint paint = new Paint();
paint.setColor(Color.BLACK);
canvas.drawBitmap(bitmap, 0, 0, paint);
return convertedBitmap;
}
@kyze8439690
kyze8439690 / addHeaderView.java
Created November 22, 2013 15:58
ListView do not show header view until you add an adapter to it
listView.addHeaderView(headerView);
//add adapter and show the header
listView.setAdapter(myAdapter);
public class ExpandedGridView extends GridView{
public ExpandedGridView(Context context) {
super(context);
}
public ExpandedGridView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ExpandedGridView(Context context, AttributeSet attrs, int defStyle) {
@kyze8439690
kyze8439690 / SquareRelativeLayout.java
Created November 30, 2013 17:59
A custom RelativeLayout which will auto match its height to its width
public class SquareRelativeLayout extends RelativeLayout{
public SquareRelativeLayout(Context context) {
super(context);
}
public SquareRelativeLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public SquareRelativeLayout(Context context, AttributeSet attrs, int defStyle) {