Capture Screen Import import android graphics Bitmap import

Capture Screen

Import �import android. graphics. Bitmap; �import android. widget. Image. View;

Implement Activity �View screen; => Reference to Linear layout UI � btn. Capture. Screen. set. On. Click. Listener(new On. Click. Listener(){ � @Override � public void on. Click(View arg 0) { � screen. set. Drawing. Cache. Enabled(false); � screen. set. Drawing. Cache. Enabled(true); � bm. Screen = screen. get. Drawing. Cache(); � show. Dialog(ID_SCREENDIALOG); � }});

�@Override �protected Dialog on. Create. Dialog(int id) { �// TODO Auto-generated method stub � screen. Dialog = null; � switch(id){ � case (ID_SCREENDIALOG): � screen. Dialog = new Dialog(this); � screen. Dialog. set. Content. View(R. layout. dialog);

� bm. Image = (Image. View)screen. Dialog. find. View. By. Id(R. id. image) ; � Text. Out = (Text. View)screen. Dialog. find. View. By. Id(R. id. textout); � btn. Screen. Dialog_OK = �(Button)screen. Dialog. find. View. By. Id(R. id. okdialogbutt on); �btn. Screen. Dialog_OK. set. On. Click. Listener(btn. Screen Dialog_OKOn. Click. Listener); �} �return screen. Dialog; }

�@Override � protected void on. Prepare. Dialog(int id, Dialog dialog) { � // TODO Auto-generated method stub � switch(id){ � case (ID_SCREENDIALOG): � dialog. set. Title(“Captured Screen”); � Text. Out. set. Text(Edit. Text. In. get. Text(). to. String()); � bm. Image. set. Image. Bitmap(bm. Screen); � break; �} }

�private Button. On. Click. Listener btn. Screen. Dialog_OKOn. Click. Listener � = new Button. On. Click. Listener(){ � @Override � public void on. Click(View arg 0) { � // TODO Auto-generated method stub � screen. Dialog. dismiss(); � }};

Layout � <? xml version="1. 0" encoding="utf-8"? > � <Linear. Layout xmlns: android="http: //schemas. android. com/apk/res/android" � android: orientation="vertical" � android: layout_width="fill_parent" � android: layout_height="fill_parent" � android: id="@+id/screen" �> � <Button � android: id="@+id/capturescreen" � android: layout_width="fill_parent" � android: layout_height="wrap_content" � android: text="Capture Screen" � />

�<Text. View � android: layout_width="fill_parent" � android: layout_height="wrap_content" � android: text="Enter some text here which you will see on captured screen" � /> �<Edit. Text � android: id="@+id/textin" � android: layout_width="fill_parent" � android: layout_height="wrap_content" � /> �</Linear. Layout>
- Slides: 9