Android Studio 的NotePad制作(日志本)

themeList.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

@Override

public boolean onPreferenceChange(Preference preference, Object newValue) {

String value = (String)newValue;

themeList.setSummary(value);

PrefVO.setThemeListValue(value);

return true;

}

});

设置密码的话,因为我已经设置过了,所以有显示为旧密码,如果第一次设置密码,他只有输入密码和确认密码,两个dialog代码如下:

builder_1 = new AlertDialog.Builder(NotePadPreferenceActivity.this);

builder_1.setView(linearLayout_1);

builder_1.setTitle(“设置新密码”);

builder_1.setIcon(R.drawable.suo);

builder_1.setPositiveButton(“确定”, new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

String key = newkeyyext.getText().toString();

String keyagain = newkeyagaintext.getText().toString();

if(key.equals(“”) || keyagain.equals(“”)){

Toast.makeText(NotePadPreferenceActivity.this,“密码不能为空”,Toast.LENGTH_LONG).show();

}

else if(key.equals(keyagain)){

PrefVO.setUserPasswordValue(key);

usersafety.setTitle(“修改密码” );

}

else if(!key.equals(keyagain)){

Toast.makeText(NotePadPreferenceActivity.this,“两次密码不一致”,Toast.LENGTH_LONG).show();

}

dialog_1.dismiss();

clearText();

}

});

builder_1.setNegativeButton(“取消”, new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

dialog_1.dismiss();

clearText();

}

});

dialog_1 = builder_1.create();

builder_2 = new AlertDialog.Builder(NotePadPreferenceActivity.this);

builder_2.setView(linearLayout_2);

builder_2.setIcon(R.drawable.suo);

builder_2.setPositiveButton(“确定”, new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

String oldkey = oldkeytext.getText().toString();

String modifykey = modifykeytext.getText().toString();

String modifyagainkey = modifykeyagaintext.getText().toString();

if(!oldkey.equals(PrefVO.userPasswordValue)){

Toast.makeText(NotePadPreferenceActivity.this,“密码错误”,Toast.LENGTH_LONG).show();

}

else if(modifykey.equals(“”)){

Toast.makeText(NotePadPreferenceActivity.this,“密码不能为空”,Toast.LENGTH_LONG).show();

}

else if(!modifyagainkey.equals(modifyagainkey)){

Toast.makeText(NotePadPreferenceActivity.this,“两次输入密码不正确”,Toast.LENGTH_LONG).show();

}

else if(modifykey.equals(modifyagainkey)){

PrefVO.setUserPasswordValue(modifykey);

}

dialog_2.dismiss();

clearText();

}

});

builder_2.setNegativeButton(“取消”, new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

dialog_2.dismiss();

clearText();

}

});

dialog_2 = builder_2.create();

//定义的密码为“”,所以根据密码来判断是第一次设置密码还是修改密码

usersafety = findPreference(“usersafety”);

if(PrefVO.userPasswordValue.equals(“”)){

usersafety.setTitle(“设置新密码”);

}

else {

usersafety.setTitle(“修改密码”);

}

usersafety.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

@Override

public boolean onPreferenceClick(Preference preference) {

if(PrefVO.userPasswordValue.equals(“”))

dialog_1.show();

else

dialog_2.show();

return false;

}

});

}

//此方法清空editview,同时要将光标聚焦到第一个EditView

private void clearText() {

newkeyyext.setText(“”);

newkeyagaintext.setText(“”);

newkeyyext.requestFocus();

oldkeytext.setText(“”);

modifykeytext.setText(“”);

modifykeyagaintext.setText(“”);

oldkeytext.requestFocus();

}

接下来为新建日志本,这里自己写了两个分别继承TextView和EditView的子控件:NoteTextView,NoteEditView,做了少许的更改。

进入新建页面后,会将焦点放在content上,然后标题跟随打印内容,直到用户自己想写一个标题的时候。在按下返回键后,重写onBackPressed,将新写的日志内容存入到数据库,页面来到查看页面,Toast打印已保存。

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-O8cF2dQW-1587976591599)(//img-blog.csdn.net/20180314120118935?watermark/2/text/Ly9ibG9nLmNzZG4ubmV0L3Jpa2thdGhld29ybGQ=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70)]

实现代码如下:

protected void onCreate(Bundle saveInstanceState) {

super.onCreate(saveInstanceState);

setContentView(R.layout.edit);

editLayout = findViewById(R.id.editlayout);

editLayout.setBackgroundColor(PrefVO.themeColorValue);

noteTitleText = findViewById(R.id.titleedit);

noteContentText = findViewById(R.id.contentedit);

noteContentText.requestFocus();

noteContentText.addTextChangedListener(new TextWatcher() {

@Override

public void beforeTextChanged(CharSequence s, int start, int count, int after) {

if(flagTextChanged && (noteTitleText.getText().toString().trim().equals(null) ||

noteTitleText.getText().toString().trim().equals(“”))){

flagTextChanged = true;

}

else if(!noteTitleText.getText().toString().equals(noteContentText.getText().toString()))

flagTextChanged = false;

}

@Override

public void onTextChanged(CharSequence s, int start, int before, int count) {

if(flagTextChanged)

noteTitleText.setText(noteContentText.getText());

}

@Override

public void afterTextChanged(Editable s) {

}

});

}

public void onBackPressed(){

super.onBackPressed();

String noteTitle = noteTitleText.getText().toString();

String noteContent = noteContentText.getText().toString();

if (noteTitle.toString().trim().equals(“”) && noteContent.toString().trim().equals(“”))

NotePadNewActivity.this.finish();

else{

NoteVO note = new NoteVO();

note.setNoteTitle(noteTitle);

note.setNoteContent(noteContent);

note.setNoteDate(new Date());

DBAccess access = new DBAccess(this);

access.insertNote(note);

Toast.makeText(this,“已保存”,Toast.LENGTH_LONG).show();

Intent intent = new Intent();

intent.setClass(this,NotePadScanActivity.class);

Bundle bundle = new Bundle();

bundle.putParcelable(“note”,note);

intent.putExtra(“noteBundle”,bundle);

this.startActivity(intent);

this.finish();

}

}

进入查看界面有三个可选操作:编辑,删除,短信发送。编辑即返回到edit的页面。

这里写图片描述这里写图片描述这里写图片描述

实现代码如下:

scanLayout = findViewById(R.id.scanlayout);

scanLayout.setBackgroundColor(PrefVO.themeColorValue);

noteTitleText = findViewById(R.id.titlescan);

noteContentText = findViewById(R.id.contentscan);

noteContentText.setMovementMethod(ScrollingMovementMethod.getInstance());

notedateText = findViewById(R.id.datescan);

intent = this.getIntent();

Bundle bundle = intent.getBundleExtra(“noteBundle”);

noteVO = bundle.getParcelable(“note”);

noteTitleText.setText(noteVO.getNoteTitle());

notedateText.setText(ConvertDate.datetoString(noteVO.getNoteDate()));

noteContentText.setText(noteVO.getNoteContent());

bianji = findViewById(R.id.bianji);

bianji.setOnTouchListener(new View.OnTouchListener() {

@Override

public boolean onTouch(View v, MotionEvent event) {

Intent intent = new Intent();

intent.setClass(NotePadScanActivity.this,NotePadEditActivity.class);

Bundle bundle= new Bundle();

bundle.putParcelable(“note”,noteVO);

intent.putExtra(“noteBundle”,bundle);

NotePadScanActivity.this.startActivity(intent);

NotePadScanActivity.this.finish();

return false;

}

});

duanxin = findViewById(R.id.duanxin);

duanxin.setOnTouchListener(new View.OnTouchListener() {

@Override

public boolean onTouch(View v, MotionEvent event) {

Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse(“smsto:”));

if(!noteVO.getNoteContent().equals(noteVO.getNoteTitle())){

intent.putExtra(“sms_body”, noteVO.getNoteTitle() + “\n” + noteVO.getNoteContent());

}

else {

intent.putExtra(“sms_body”, noteVO.getNoteContent());

}

NotePadScanActivity.this.startActivity(intent);

return false;

}

});

shanchu = findViewById(R.id.shanchu);

shanchu.setOnTouchListener(new View.OnTouchListener() {

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数初中级安卓工程师,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年最新Android移动开发全套学习资料》送给大家,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
img
img
img
img

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频
如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注Android)
img

学习分享

在当下这个信息共享的时代,很多资源都可以在网络上找到,只取决于你愿不愿意找或是找的方法对不对了

很多朋友不是没有资料,大多都是有几十上百个G,但是杂乱无章,不知道怎么看从哪看起,甚至是看后就忘

如果大家觉得自己在网上找的资料非常杂乱、不成体系的话,我也分享一套给大家,比较系统,我平常自己也会经常研读。

2021最新上万页的大厂面试真题

七大模块学习资料:如NDK模块开发、Android框架体系架构…

只有系统,有方向的学习,才能在段时间内迅速提高自己的技术。

这份体系学习笔记,适应人群:
**第一,**学习知识比较碎片化,没有合理的学习路线与进阶方向。
**第二,**开发几年,不知道如何进阶更进一步,比较迷茫。
**第三,**到了合适的年纪,后续不知道该如何发展,转型管理,还是加强技术研究。如果你有需要,我这里恰好有为什么,不来领取!说不定能改变你现在的状态呢!

由于文章内容比较多,篇幅不允许,部分未展示内容以截图方式展示 。如有需要获取完整的资料文档的朋友点击我的【GitHub】免费获取。

看从哪看起,甚至是看后就忘

如果大家觉得自己在网上找的资料非常杂乱、不成体系的话,我也分享一套给大家,比较系统,我平常自己也会经常研读。

2021最新上万页的大厂面试真题

[外链图片转存中…(img-Z3cRaaBl-1710761821793)]

七大模块学习资料:如NDK模块开发、Android框架体系架构…

[外链图片转存中…(img-JsM5hEVI-1710761821793)]

只有系统,有方向的学习,才能在段时间内迅速提高自己的技术。

这份体系学习笔记,适应人群:
**第一,**学习知识比较碎片化,没有合理的学习路线与进阶方向。
**第二,**开发几年,不知道如何进阶更进一步,比较迷茫。
**第三,**到了合适的年纪,后续不知道该如何发展,转型管理,还是加强技术研究。如果你有需要,我这里恰好有为什么,不来领取!说不定能改变你现在的状态呢!

由于文章内容比较多,篇幅不允许,部分未展示内容以截图方式展示 。如有需要获取完整的资料文档的朋友点击我的【GitHub】免费获取。

  • 16
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值