Android project notepad (13), android Project
This article is my learning notes, welcome to reprint, but please note the Source: http://blog.csdn.net/jesson20121020
Today, we will implement the function of viewing images and recordings. When editing or browsing the notebook, click an image to open a custom Activity (of course, you can also call the image library of the system to view it) to view the original image of the added image, rather than the scaled image. Similarly, you can use a custom Activity to view the recording file to play the recording. :
We can also see that we must first create two activities. Of course, layout files are also indispensable, as shown below:
Activity_show_picture.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <ImageView android:id="@+id/iv_showPic" android:layout_width="match_parent" android:layout_height="match_parent" android:scaleType="fitCenter" /></LinearLayout>
ShowPicture. java
Public class ShowPicture extends Activity {private ImageView img; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); requestWindowFeature (Window. FEATURE_CUSTOM_TITLE); setContentView (R. layout. activity_show_picture); getWindow (). setFeatureInt (Window. FEATURE_CUSTOM_TITLE, R. layout. title_add); // set the title TextView TV _title = (TextView) findViewById (R. id. TV _title); TV _title.setText ("view image"); Button bt_back = (Button) findViewById (R. id. bt_back); bt_back.setOnClickListener (new OnClickListener () {@ Overridepublic void onClick (View arg0) {ShowPicture. this. finish () ;}}); Button bt_del = (Button) findViewById (R. id. bt_save); bt_del.setBackgroundResource (R. drawable. paint_icon_delete); img = (ImageView) findViewById (R. id. iv_showPic); Intent intent = this. getIntent (); String imgPath = intent. getStringExtra ("imgPath"); Bitmap bm = BitmapFactory. decodeFile (imgPath); img. setImageBitmap (bm );}}
The main idea is to use ImageView to display the image of the specified path, which was passed in from the previous Activity. Here, only the returned function is implemented for the listener event. As for how to zoom in and out the image and rotate the image, we will implement it in the next section. Activity_show_record.xml
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/bg" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:gravity="center" android:layout_centerInParent="true" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:gravity="center" android:layout_margin="5dp" > <ImageView android:id="@+id/iv_record_wave_left" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_margin="5dp" android:background="@anim/record_wave_left" /> <ImageView android:id="@+id/iv_microphone" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:src="@drawable/record_microphone_icon" android:layout_margin="5dp" /> <ImageView android:id="@+id/iv_record_wave_right" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_margin="5dp" android:background="@anim/record_wave_right" /> </LinearLayout> <TextView android:id="@+id/tv_recordTime" android:layout_width="match_parent" android:layout_height="wrap_content" android:textColor="#499df7" android:textSize="20sp" android:text="00:00:00" android:gravity="center" android:layout_margin="5dp" /> </LinearLayout> </RelativeLayout>
ShowRecord. java
Public class ShowRecord extends Activity {private String audioPath; private int isPlaying = 0; private AnimationDrawable ad_left, ad_right; private Timer mTimer; // audio operation object private MediaPlayer mPlayer = null; private ImageView outputs, iv_record_wave_right, iv_microphone; private TextView TV _recordTime; @ Overrideprotected void onCreate (Bundle savedInstanceState) {// TODO Auto-generated method stubsuper. onCreate (savedInstanceState); requestWindowFeature (Window. FEATURE_CUSTOM_TITLE); setContentView (R. layout. activity_show_record); getWindow (). setFeatureInt (Window. FEATURE_CUSTOM_TITLE, R. layout. title_add); // set the title TextView TV _title = (TextView) findViewById (R. id. TV _title); TV _title.setText ("view recording"); Button bt_back = (Button) findViewById (R. id. bt_back); bt_back.setOnClickListener (new OnClickListener () {@ Overridepublic void onClick (View arg0) {if (isPlaying = 1) {mPlayer. stop (); mPlayer. release ();} ShowRecord. this. finish () ;}}); Button bt_del = (Button) findViewById (R. id. bt_save); bt_del.setBackgroundResource (R. drawable. paint_icon_delete); Intent intent = this. getIntent (); audioPath = intent. getStringExtra ("audioPath"); iv_microphone = (ImageView) findViewById (R. id. iv_microphone); iv_microphone.setOnClickListener (new ClickEvent (); iv_record_wave_left = (ImageView) findViewById (R. id. iv_record_wave_left); iv_record_wave_right = (ImageView) findViewById (R. id. required); ad_left = (AnimationDrawable) lost (); // ad_left = (AnimationDrawable) lost (); ad_right = (AnimationDrawable) lost (); // ad_right = (AnimationDrawable) iv_record_wave_right.getDrawable (); TV _recordTime = (TextView) findViewById (R. id. TV _recordTime);} final Handler handler = new Handler () {public void handleMessage (Message msg) {switch (msg. what) {case 1: String time [] = TV _recordTime.getText (). toString (). split (":"); int hour = Integer. parseInt (time [0]); int minute = Integer. parseInt (time [1]); int second = Integer. parseInt (time [2]); if (second <59) {second ++;} else if (second = 59 & minute <59) {minute ++; second = 0;} if (second = 59 & minute = 59 & hour <98) {hour ++; minute = 0; second = 0 ;} time [0] = hour + ""; time [1] = minute + ""; time [2] = second + ""; // adjust the format to display on the screen if (second <10) time [2] = "0" + second; if (minute <10) time [1] = "0" + minute; if (hour <10) time [0] = "0" + hour; // display TV _recordTime.setText (time [0] + ":" + time [1] + ":" + time [2]); break ;}} in TextView ;}}}; class ClickEvent implements OnClickListener {@ Overridepublic void onClick (View arg0) {// TODO Auto-generated method stub // test if (isPlaying = 0) {isPlaying = 1; mPlayer = new MediaPlayer (); TV _recordTime.setText ("00:00:00"); mTimer = new Timer (); mPlayer. setOnCompletionListener (new MediaCompletion (); try {mPlayer. setDataSource (audioPath); mPlayer. prepare (); mPlayer. start ();} catch (IllegalArgumentException e) {// TODO Auto-generated catch blocke. printStackTrace ();} catch (SecurityException e) {// TODO Auto-generated catch blocke. printStackTrace ();} catch (IllegalStateException e) {// TODO Auto-generated catch blocke. printStackTrace ();} catch (IOException e) {// TODO Auto-generated catch blocke. printStackTrace ();} mTimer. schedule (new TimerTask () {@ Overridepublic void run () {Message message = new Message (); message. what = 1; handler. sendMessage (message) ;}},); // play the animation ad_left.start (); ad_right.start () ;}// end the test else {isPlaying = 0; mPlayer. stop (); mPlayer. release (); mPlayer = null; mTimer. cancel (); mTimer = null; // stop the animation seek (); ad_right.stop () ;}} class MediaCompletion implements OnCompletionListener {@ Overridepublic void onCompletion (MediaPlayer mp) {mTimer. cancel (); mTimer = null; isPlaying = 0; // stop the animation ad_left.stop (); ad_right.stop (); Toast. makeText (ShowRecord. this, "playing completed", Toast. LENGTH_SHORT ). show (); TV _recordTime.setText ("00:00:00 ");}}}
When viewing the recording, it is a little complicated to use the display and processing of the playing time, as well as the playing and stopping of the animation. These are described in the previous section "add recording.
With these two activities, the rest of the work is to start the two activities in the event of clicking an image or recording. However, how can we determine whether an image, recording, or text is clicked in the EditText in a text-and-text mix ?? In this case, you need to identify the images and texts in EditText, and then further analyze the images and click the images to view the specific images and recordings, the details are as follows:
1. Record the location and Source Path of each image in EditText
To view the original image and Recording files at any time during editing and browsing, use a List to remember the location and path of each newly added image or recording. Of course, if you are viewing records that already exist in the database, while loading data, use ListView to record the location and path of the pictures and recordings. The main code is as follows:
// Record the image in editText, which is used to determine which image is clicked when you click the private List <Map <String, String> imgList = new ArrayList <Map <String, string >> ();
Each time you click the recording list, you can view the recording. when loading the data, you can record the positions and paths of all the images and recordings. Specifically, you can add the following code to the loadDate () method:
// Use List to record the recording position and path, and click event Map <String, String> map = new HashMap <String, String> (); map. put ("location", m. start () + "-" + m. end (); map. put ("path", path); imgList. add (map );
Similarly, you also need to add the corresponding code after each image recording operation. Add the following code to the InsertBitmap () function:
// Use List to record the recording position and path, and click event Map <String, String> map = new HashMap <String, String> (); map. put ("location", selectionIndex + "-" + (selectionIndex + spannableString. length (); map. put ("path", imgPath); imgList. add (map );
2. Add a click event to EditText
private LineEditText et_Notes;... ...et_Notes.setOnClickListener(new TextClickEvent());
3. determine whether an image or plain text is clicked.
To determine whether an image or a common text is clicked, the main idea of Spanned and ImageSpan is to determine whether the current clicked position is within the range of the image. The main code is as follows:
Spanned s = et_Notes.getText (); ImageSpan [] imageSpans; imageSpans = s. getSpans (0, s. length (), ImageSpan. class); int selectionStart = et_Notes.getSelectionStart (); for (ImageSpan span: imageSpans) {int start = s. getSpanStart (span); int end = s. getSpanEnd (span); // find the image if (selectionStart> = start & selectionStart <end ){......}}
After the image is hit, determine which image is clicked?
4. Click the image.
The position and path of the image recorded in step 1 are used. Obviously, the position is used to determine the image to be clicked. The main code is as follows:
// Find the image you are currently clicking. // System. out. println (start + "-----------" + end); String path = null; for (int I = 0; I
5. Determine the recording or image, start the corresponding Activity, and pass the path
There are two ways to view images. One is to call the image library of the system to open the image, and the other is to customize the image, A custom Activity is used to open a recording, as shown below:
// Then judge whether the current image is a recording. If it is a recording, the Activity of the recording will jump to. If not, the Activity will jump to the interface for viewing the image // recording, then jump to the Activityif (path. substring (path. length ()-3, path. length ()). equals ("amr") {Intent intent = new Intent (AddActivity. this, ShowRecord. class); intent. putExtra ("audioPath", path); startActivity (intent) ;}// for the image, you can jump to the image display page else {// you can view the image in either of the following ways, the first method is to directly call the image library of the system to view images, and the second method is to customize the Activity // call the system image library to view images/* Intent intent = new Intent (Intent. ACTION_VIEW); File file = new File (path); Uri uri = Uri. fromFile (file); intent. setDataAndType (uri, "image/*"); * // use custom ActivityIntent intent = new Intent (AddActivity. this, ShowPicture. class); intent. putExtra ("imgPath", path); startActivity (intent );}
The above steps, 3, 4, and 5 are actually implemented in the click listener. The complete code is as follows:
// Set the class TextClickEvent implements OnClickListener {@ Overridepublic void onClick (View v) {Spanned s = et_Notes.getText (); ImageSpan [] imageSpans; imageSpans = s. getSpans (0, s. length (), ImageSpan. class); int selectionStart = et_Notes.getSelectionStart (); for (ImageSpan span: imageSpans) {int start = s. getSpanStart (span); int end = s. getSpanEnd (span); // find the image if (selectionStart> = start & selectionStart <end) {// Bitmap bitmap = (BitmapDrawable) span. getDrawable ()). getBitmap (); // find the image you are currently clicking. // System. out. println (start + "-----------" + end); String path = null; for (int I = 0; I
Now, you can view images and play recordings.
Who will be responsible for the Android notepad project? We are going to take the Android course. We need to prepare an Android notepad project at the end of the course.
Android Notepad program source code
Blog.csdn.net/..096216
Android notepad software download
There are a lot of Android mobile phone notepad software. Which of the following Landlords prefer to use it on their own. I know several easy-to-use notepad software and recommend it to the landlord.
Some software can be downloaded in [Android park]. You only need to enter the notepad to find it.
[Handwritten notepad]
HandCalendar is a notebook, notebook, and notebook that supports handwriting. It also supports saving recorded content to the calendar. The handwriting function of the software is relatively powerful. It supports 10 colors and 3 pen styles, and supports a maximum of three erasers to cancel the function.
[AK Notepad]
AK notepad is a powerful text document editing software. In addition to editing, reading, and writing documents and viewing TXT documents, the software also allows you to share event reminders with others through text messages, emails, and mobile phone alarms.
[With handwriting]
Hand-writing is definitely the most convenient convenience software, and the original smart scaling. Supports both handwriting (Original Handwriting) and keyboard input. Features: 1. You can remember big things on a small screen and use the original handwriting keyboard mixed-mode.
2. task management, notes, calendar, alarm clock, MMS, and schedule 3. Free graffiti, illustrations, photo notes, and voice notes on photos 4. widgets read the current notebook directly. Agree with 14 | comment