Skip to content

Instantly share code, notes, and snippets.

@xxxzhi
xxxzhi / gist:7209875
Created October 29, 2013 06:18
turn the view to bitmap
linear.setDrawingCacheEnabled(true);
//you could not use this.
//linear.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
// MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
//linear.layout(0, 0, linear.getMeasuredWidth(), linear.getMeasuredHeight());
linear.buildDrawingCache();
//获取显示的内容当成图片来显示。
iv.setImageBitmap(linear.getDrawingCache());
@xxxzhi
xxxzhi / 0_reuse_code.js
Created October 29, 2013 06:26
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@xxxzhi
xxxzhi / AudioOpeateIterface
Created October 30, 2013 08:53
监听ImageView 实现按住弹出popwindow 说话,可设置上滑还是下滑取消说话
public interface AudioOpeateIterface{
public void setPlayCompletionListener(MediaPlayer.OnCompletionListener listener);
public void playRecord(String src);
public void startRecord();
public String stopRecord();
public void deleteRecord();
@xxxzhi
xxxzhi / setVisibility
Last active October 20, 2016 02:28
use handler to deal with the invalid when setVisibility(View.GONE). At most time ,if the view is under use,setVisibility will be useless.
Message.obtain(handler,new Runnable() {
@Override
public void run() {
System.out.println("gone");
viewGroup.getChildAt(i).clearAnimation(); // this is very imporant! clear animation
for(int i=0;i!=viewGroup.getChildCount();++i){
if(viewGroup.getChildAt(i).getId() == id){
viewGroup.getChildAt(i).setVisibility(View.VISIBLE);
}else{
@xxxzhi
xxxzhi / new_gist_file.java
Created November 17, 2013 10:23
android obtain the drawable array 。 android 获取资源数组
TypedArray array = resources.obtainTypedArray(R.array.share_str);
Drawable drawable = array.getDrawable(0);
@xxxzhi
xxxzhi / SimpleAdapterDemo.java
Created November 17, 2013 10:28
From http://blog.csdn.net/u010142437/article/details/9059359 demo of SimpleAdapter SimpleAdapter 的使用案例
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
@xxxzhi
xxxzhi / SingleTraveralRandom.h
Created November 25, 2013 15:28
single traversal random algorithm
/*
* SingleTraveralRandom.h
*
* Created on: 2013年11月25日
* Author: houzhi
*/
#ifndef SINGLETRAVERALRANDOM_H_
#define SINGLETRAVERALRANDOM_H_
AAssetDir* assetDir = AAssetManager_openDir(mgr, "");
const char* filename = (const char*)NULL;
while ((filename = AAssetDir_getNextFileName(assetDir)) != NULL) {
AAsset* asset = AAssetManager_open(mgr, filename, AASSET_MODE_STREAMING);
char buf[BUFSIZ];
int nb_read = 0;
FILE* out = fopen(filename, "w");
while ((nb_read = AAsset_read(asset, buf, BUFSIZ)) > 0)
fwrite(buf, nb_read, 1, out);
fclose(out);
@xxxzhi
xxxzhi / android.mk
Created August 14, 2014 08:50
这是在cocos2d-x 中 使用下面这一部分能够自动包含 class 目录下面的源文件,以及 jni/ 下面的源文件。目录递归包含。摘自:http://blog.ready4go.com/blog/2013/10/12/update-android-dot-mk-with-local-src-files-and-local-c-includes/
# 配置自己的源文件目录和源文件后缀名
MY_FILES_PATH := $(LOCAL_PATH) \
$(LOCAL_PATH)/../../Classes
MY_FILES_SUFFIX := %.cpp %.c
# 递归遍历目录下的所有的文件
rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))
# 获取相应的源文件
@xxxzhi
xxxzhi / attr.java
Created January 15, 2015 06:48
From http://stackoverflow.com/questions/7896615/android-how-to-get-value-of-an-attribute-in-code using java to get attribute。 用java 代码去获取属性的值。
TypedValue typedValue = new TypedValue();
// ((Activity)context).getTheme().resolveAttribute(android.R.attr.textAppearanceLarge, typedValue, true);
int[] textSizeAttr = new int[] { android.R.attr.textSize };
int indexOfAttrTextSize = 0;
TypedArray a = context.obtainStyledAttributes(typedValue.data, textSizeAttr);
int textSize = a.getDimensionPixelSize(indexOfAttrTextSize, -1);
a.recycle();