android手机android记事本源代码记录的文件在哪儿

没有更多推荐了,
不良信息举报
举报内容:
Android 记事本-Demo
举报原因:
原文地址:
原因补充:
最多只允许输入30个字
加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!因为上一个文件浏览器项目的失败,我认识到了像本周一样照抄 GitHub 开源项目是不行的。所以我找到了极客学院的实战演练视频-记事本项目来进行练习。
学习链接:
此项目主要是练习数据存储,其中涉及到两个存储知识点:存储图片/视频到手机存储器中。数据库的存储。
而这个项目是日开始由极客学院录制。今天正好是一年零2天了。
在学校的那段时间,我自己也买过极客学院的年会员。但是期间并没有好好的学习。同样的是那个自我学习的问题,跟着别人做做了很多东西,但是自己掌握的根本就没有多少知识点。真正要自己做东西的时候根本就没有办法上手。
或许,也是因为自己有点好高骛远。
沉不下心思来好好学习吧。
在学校的那段时间里面这个记事本的项目我写过三次,当然,每次都是没有写完。
之前觉得还看不出来什么差距,但是今天按照教程上面说的建立工程,建立数据库,开始写代码。把其中的第一个视频(建立数据库辅助类,建立数据库并验证成功),到第二个(布局的编写)跟着写到现在。
关于命名:极客学院全站的视频都是面向初学者的。但是大部分的 变量以及方法命名都是不规范的。随意命名。乱命名到处都是。
关于布局:此教程的布局真的写的不行,但是我们可以从一个程序员的角度去看,程序员嘛。实现功能就好了,布局又不用自己去控制。上面说是什么就是什么呗。而我想吐槽的是布局ID的命名。实在是随意的不行啊。
目前就找到这两个槽点,以后有什么以后说吧。
而今天我也不想贴图了,难道贴图上来只是为了吐槽极客学院么&&算了吧
那暂时就这样吧。
阅读(...) 评论() &android项目 之 记事本(13) ----- 查看图片及播放录音
本文是自己学习所做笔记,欢迎转载,但请注明出处:https://blog.csdn.net/jesson
今天就来实现下查看图片及录音的功能,在编辑或者浏览记事时,点击图片,打开一个自定义Activity(当然了,也可以调用的图库来查看)来查看所添加的图片的原始图片,而不是缩放后的图片,同理,用自定义Activity来查看录音文件,实现播放录音的功能。上图:
从图中也可以看出,我们首先要创建两个Activity,当然了,布局文件也是少不了的,如下:
activity_show_picture.xml
vcD4KPHByZSBjbGFzcz0="brush:">
ShowPicture.java
public class ShowPicture extends Activity {
private ImageV
protected 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);
//设置标题
TextView tv_title = (TextView)findViewById(R.id.tv_title);
tv_title.setText("查看图片");
Button bt_back = (Button)findViewById(R.id.bt_back);
bt_back.setOnClickListener(new OnClickListener() {
public 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);
主要思想就是用ImageView来显示指定路径的图片,该路径是从前一个Activity中传入进来的。这里的监听事件,只实现了返回的功能,至于,放大缩小图片,旋转图片,下节再实现吧。activity_show_record.xml
ShowRecord.java
public class ShowRecord extends Activity {
private String audioP
private int isPlaying = 0;
private AnimationDrawable ad_left,ad_
private Timer mT
//语音操作对象
private MediaPlayer mPlayer =
private ImageView iv_record_wave_left,iv_record_wave_right,iv_
private TextView tv_recordT
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.activity_show_record);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_add);
//设置标题
TextView tv_title = (TextView)findViewById(R.id.tv_title);
tv_title.setText("查看录音");
Button bt_back = (Button)findViewById(R.id.bt_back);
bt_back.setOnClickListener(new OnClickListener() {
public 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.iv_record_wave_right);
ad_left = (AnimationDrawable)iv_record_wave_left.getBackground();
//ad_left = (AnimationDrawable)iv_record_wave_left.getDrawable();
ad_right = (AnimationDrawable)iv_record_wave_right.getBackground();
//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){
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){
else if(second == 59 && minute < 59){
second = 0;
if(second == 59 && minute == 59 && hour < 98){
minute = 0;
second = 0;
time[0] = hour + "";
time[1] = minute + "";
time[2] = second + "";
//调整格式显示到屏幕上
if(second < 10)
time[2] = "0" +
if(minute < 10)
time[1] = "0" +
if(hour < 10)
time[0] = "0" +
//显示在TextView中
tv_recordTime.setText(time[0]+":"+time[1]+":"+time[2]);
class ClickEvent implements OnClickListener{
public void onClick(View arg0) {
// TODO Auto-generated method stub
if(isPlaying == 0){
isPlaying = 1;
mPlayer = new MediaPlayer();
tv_recordTime.setText("00:00:00");
mTimer = new Timer();
mPlayer.setOnCompletionListener(new MediaCompletion());
mPlayer.setDataSource(audioPath);
mPlayer.prepare();
mPlayer.start();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
mTimer.schedule(new TimerTask() {
public void run() {
Message message = new Message();
message.what = 1;
handler.sendMessage(message);
//播放动画
ad_left.start();
ad_right.start();
//结束试听
isPlaying = 0;
mPlayer.stop();
mPlayer.release();
mTimer.cancel();
//停止动画
ad_left.stop();
ad_right.stop();
class MediaCompletion implements OnCompletionListener{
public void onCompletion(MediaPlayer mp) {
mTimer.cancel();
isPlaying = 0;
//停止动画
ad_left.stop();
ad_right.stop();
Toast.makeText(ShowRecord.this, "播放完毕", Toast.LENGTH_SHORT).show();
tv_recordTime.setText("00:00:00");
在查看录音时,用到了对播放时间的显示处理,以及动画的播放与停止,稍有点复杂,这些在之前“添加录音”一节就就讲述了。
有了这两个Activity后,那么剩下的工作就是在单击图片或者录音的事件中启动这两个Activity即可。但这就有一个问题,如何在图文混排的EditText中的判断单击的是图片,录音,还是文字呢??这就需要从EditText中的识别那些是图片,那些是文字,再进一步对图片分析到底单击的是那一个图片,从而实现查看具体图片及录音的功能,具体如下:
1. 记录EditText中每个图片的位置及所在源路径
为了实现在编辑和浏览时可以随时查看原图片及录音文件,所以在每次添加图片或录音后,用一个List记住新增加的每个图片或录音的位置及所在路径,当然了,如果是浏览已经存在于中的记事时,在加载数据的同时,同样用ListView来记住所有的图片及录音的位置和路径。主要代码如下:
&#160; &#160; &#160; &#160; //记录editText中的图片,用于单击时判断单击的是那一个图片
private List<Map> imgList = new ArrayList<Map>();
每次单击记事列表项,进入查看记事,在加载数据的同时将所有图片及录音的位置及路径记录下来,具体为在loadDate()方法中添加以下代码:
&#160; &#160; &#160; &#160; //用List记录该录音的位置及所在路径,用于单击事件
Map map = new HashMap();
map.put("location", m.start()+"-"+m.end());
&#160;map.put("path", path);
&#160;imgList.add(map);
同理,也要在每次添加图片录音后也要加入相应的代码,在InsertBitmap()函数中添加如下代码:
&#160; &#160; &#160; &#160; //用List记录该录音的位置及所在路径,用于单击事件
Map map = new HashMap();
map.put("location", selectionIndex+"-"+(selectionIndex+spannableString.length()));
map.put("path", imgPath);
imgList.add(map);
2. 给EditText添加单击事件
private LineEditText et_N
et_Notes.setOnClickListener(new TextClickEvent());
3. 判断单击的是图片还是普通文字
为了判断单击的是图片还是普通文字,用到了Spanned,ImageSpan,主要思想,就是判断当前单击的位置是否在图片的位置范围内,主要代码如下:
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; Spanned s = et_Notes.getText();
ImageSpan[] imageS
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);
//找到图片
if(selectionStart >= start && selectionStart < end){
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;... ...
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; }
打到了图片,接下来就要判断单击的到底是那一图片呢?
4. 决断单击的具体是那一张图片
这就用到了第一步记录的图片的位置和路径了,显然,就是用位置来判断到底是单击的那一个图片,主要代码如下:
&#160; &#160; &#160; &#160; //查找当前单击的图片是哪一个图片
//System.out.println(start+"-----------"+end);
String path =
for(int i = 0;i < imgList.size();i++){
Map map = imgList.get(i);
if(map.get("location").equals(start+"-"+end)){
path = imgList.get(i).get("path");
5. 判断是录音还是图片,启动对应的Activity,并传递路径
查看图片,有两种方法,一种是调用系统的图库打开图片,另一种就是自定义,这里,我都实现了,打开录音用的是自定义的Activity,如下:
&#160; &#160; &#160; &#160; //接着判断当前图片是否是录音,如果为录音,则跳转到试听录音的Activity,如果不是,则跳转到查看图片的界面
//录音,则跳转到试听录音的Activity
if(path.substring(path.length()-3, path.length()).equals("amr")){
Intent intent = new Intent(AddActivity.this,ShowRecord.class);
intent.putExtra("audioPath", path);
startActivity(intent);
//图片,则跳转到查看图片的界面
//有两种方法,查看图片,第一种就是直接调用系统的图库查看图片,第二种是自定义Activity
//调用系统图库查看图片
/*Intent intent = new Intent(Intent.ACTION_VIEW);
File file = new File(path);
Uri uri = Uri.fromFile(file);
intent.setDataAndType(uri, "image/*");*/
//使用自定义Activity
Intent intent = new Intent(AddActivity.this,ShowPicture.class);
intent.putExtra("imgPath", path);
startActivity(intent);
以上,3,4,5步其实都是在单击的监听器中实现的,完整代码如下:
&#160; &#160; &#160; &#160; //为EidtText设置监听器
class TextClickEvent implements OnClickListener{
public void onClick(View v) {
Spanned s = et_Notes.getText();
ImageSpan[] imageS
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);
//找到图片
if(selectionStart >= start && selectionStart < end){
//Bitmap bitmap = ((BitmapDrawable)span.getDrawable()).getBitmap();
//查找当前单击的图片是哪一个图片
//System.out.println(start+"-----------"+end);
String path =
for(int i = 0;i < imgList.size();i++){
Map map = imgList.get(i);
if(map.get("location").equals(start+"-"+end)){
path = imgList.get(i).get("path");
//接着判断当前图片是否是录音,如果为录音,则跳转到试听录音的Activity,如果不是,则跳转到查看图片的界面
//录音,则跳转到试听录音的Activity
if(path.substring(path.length()-3, path.length()).equals("amr")){
Intent intent = new Intent(AddActivity.this,ShowRecord.class);
intent.putExtra("audioPath", path);
startActivity(intent);
//图片,则跳转到查看图片的界面
//有两种方法,查看图片,第一种就是直接调用系统的图库查看图片,第二种是自定义Activity
//调用系统图库查看图片
/*Intent intent = new Intent(Intent.ACTION_VIEW);
File file = new File(path);
Uri uri = Uri.fromFile(file);
intent.setDataAndType(uri, "image/*");*/
//使用自定义Activity
Intent intent = new Intent(AddActivity.this,ShowPicture.class);
intent.putExtra("imgPath", path);
startActivity(intent);
//如果单击的是空白出或文字,则获得焦点,即打开软键盘
imm.showSoftInput(et_Notes, 0);
至此,就实现了查看图片以及播放录音的功能。

我要回帖

更多关于 android记事本源码 的文章

 

随机推荐