posts - 189,comments - 115,trackbacks - 0

Android 一些小效果代码

http://www.eoeandroid.com/thread-84926-1-1.html
自定义MapView类,重写其onInterceptTouchEvent方法。来实现双击以后图片变大。

java代码:
  1. public class MyMapView extends MapView {

  2. private long lastTouchTime = -1;
  3. public MyMapView(Context context, AttributeSet attrs) {
  4. super(context, attrs);
  5. // TODO Auto-generated constructor stub

  6. }

  7. @Override
  8. public boolean onInterceptTouchEvent(MotionEvent ev) {
  9. // TODO Auto-generated method stub
  10. if (ev.getAction() == MotionEvent.ACTION_DOWN) {

  11. long thisTime = System.currentTimeMillis();

  12. if (thisTime - lastTouchTime < 250) {

  13. this.getController().zoomInFixing((int) ev.getX(), (int) ev.getY());
  14. lastTouchTime = -1;

  15. }else{
  16. lastTouchTime = thisTime;

  17. }
  18. }

  19. return super.onInterceptTouchEvent(ev);
  20. }
  21. }
复制代码

       让一个图片透明:

java代码:
  1. Bitmap buffer = Bitmap.createBitmap(width, border="1" Height, Bitmap.Config.ARGB_4444);buffer.eraseColor(Color.TRANSPARENT);
复制代码

       直接发送邮件:

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);
复制代码

       程序控制屏幕变亮:

java代码:
  1. WindowManager.LayoutParams lp = getWindow().getAttributes();
  2. lp.screenBrightness = 100 / 100 .0f;
  3. getWindow().setAttributes(lp);
复制代码

        过滤特定文本

java代码:
  1. Filter filter = myAdapter.getFilter();
  2. filter.filter(mySearchText);
复制代码

       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. }

  5. public void onScrollStateChanged(AbsListView view, int scrollState) {
  6. // TODO Auto-generated method stub

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

  9. });
  10. }
复制代码

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

java代码:
  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. Intent intent = new Intent();
  8. intent.setAction(android .content.Intent.ACTION_VIEW);
  9. intent.setDataAndType(Uri .fromFile( new File(path)), "image/png"
复制代码
posted on 2011-08-02 10:28 MEYE 阅读(334) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: