android的一些特殊玩法

1.让一个图片透明:

复制到剪贴板 Java代码

1. Bitmap buffer = Bitmap.createBitmap(width, border="1" Height, Bitmap.Config.ARGB_4444);buffer.eraseColor(Color.TRANSPARENT);

2.直接发送邮件:

复制到剪贴板 Java代码

1. Intent intent = new Intent(Intent.ACTION_SENDTO, Uri .fromParts( "mailto" , "test@test.com" , null ));

2. intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

3. context.startActivity(intent);

3.程序控制屏幕变亮:

复制到剪贴板 Java代码

1. WindowManager.LayoutParams lp = getWindow().getAttributes();

2. lp.screenBrightness = 100 / 100 .0f;

3. getWindow().setAttributes(lp);

4.过滤特定文本

复制到剪贴板 Java代码

1. Filter filter = myAdapter.getFilter();

2. filter.filter(mySearchText);

5.scrollView scroll停止事件

复制到剪贴板 Java代码

1. setOnScrollListener( new OnScrollListener(){

2. public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {

3. // TODO Auto-generated method stub }

4. public void onScrollStateChanged(AbsListView view, int scrollState) {

5. // TODO Auto-generated method stub

6. if (scrollState == 0 ) Log.i( "a" , "scrolling stopped..." ); } });}

6. 对于特定的程序 发起一个关联供打开

复制到剪贴板 C/C++代码

1. Bitmap bmp = getImageBitmap(jpg);

2. String path = getFilesDir().getAbsolutePath() + "/test.png" ;

3. File file = new File(path);

4. FileOutputStream fos = new FileOutputStream(file);

5. bmp.compress( CompressFormat.PNG, 100, fos );

6. fos.close();

7.

8. Intent intent = new Intent();

9. intent.setAction(android .content.Intent.ACTION_VIEW);

10. intent.setDataAndType(Uri .fromFile( new File(path)), "image/png"

*byte转化为Bitmap,防止内存溢出
Java代码
   
ByteArrayInputStream is =new ByteArrayInputStream(byte[]);     
BitmapFactory.Options options=new BitmapFactory.Options();      
options.inPurgeable = true;     
options.inInputShareable = true;     
options.inSampleSize = 2;     
try {     
    BitmapFactory.Options.class.getField("inNativeAlloc").setBoolean(options,true);     
} catch(Exception ex) {     
    ex.printStackTrace();     
}     
Bitmap imgBit = (new WeakReference<Bitmap>(BitmapFactory.decodeStream(is, null, options))).get(); 

posted @ 2012-11-28 17:13  crazywenza  阅读(318)  评论(0编辑  收藏  举报