|
|
|
@ -1,341 +0,0 @@
|
|
|
|
|
### 小米便签功能添加
|
|
|
|
|
|
|
|
|
|
##### 功能一、更换背景
|
|
|
|
|
|
|
|
|
|
###### 1、在res文件夹下的menu中的note_list.xml文件中加入所需要的按钮
|
|
|
|
|
|
|
|
|
|
```xml
|
|
|
|
|
<item
|
|
|
|
|
android:id="@+id/menu_girl"
|
|
|
|
|
android:title="menu_girl"/>
|
|
|
|
|
|
|
|
|
|
<item
|
|
|
|
|
android:id="@+id/menu_sea"
|
|
|
|
|
android:title="menu_sea"/>
|
|
|
|
|
|
|
|
|
|
<item
|
|
|
|
|
android:id="@+id/menu_sweet"
|
|
|
|
|
android:title="menu_sweet"/>
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
|
|
###### 2、点击按钮后进行背景更换
|
|
|
|
|
|
|
|
|
|
在**ui**包里的**NotelistActivity**中的**onOptionsItemSelected**函数中编写用户选择任一个背景后系统要进行的反应
|
|
|
|
|
|
|
|
|
|
```java
|
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
|
case R.id.menu_new_folder: {
|
|
|
|
|
showCreateOrModifyFolderDialog(true);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case R.id.menu_export_text: {
|
|
|
|
|
exportNoteToText();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case R.id.menu_sync: {
|
|
|
|
|
if (isSyncMode()) {
|
|
|
|
|
if (TextUtils.equals(item.getTitle(), getString(R.string.menu_sync))) {
|
|
|
|
|
GTaskSyncService.startSync(this);
|
|
|
|
|
} else {
|
|
|
|
|
GTaskSyncService.cancelSync(this);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
startPreferenceActivity();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case R.id.menu_setting: {
|
|
|
|
|
startPreferenceActivity();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case R.id.menu_new_note: {
|
|
|
|
|
createNewNote();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case R.id.menu_search:
|
|
|
|
|
onSearchRequested();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case R.id.menu_girl: {
|
|
|
|
|
|
|
|
|
|
mode = 1;
|
|
|
|
|
|
|
|
|
|
getWindow().setBackgroundDrawableResource(R.drawable.menu_girl);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case R.id.menu_sea: {
|
|
|
|
|
|
|
|
|
|
mode = 2;
|
|
|
|
|
|
|
|
|
|
getWindow().setBackgroundDrawableResource(R.drawable.menu_sea);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case R.id.menu_sweet: {
|
|
|
|
|
|
|
|
|
|
mode = 3;
|
|
|
|
|
|
|
|
|
|
getWindow().setBackgroundDrawableResource(R.drawable.menu_sweet);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
###### 3、效果展示
|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
##### 功能二、笔记字符数统计
|
|
|
|
|
|
|
|
|
|
###### 1、设置TextView
|
|
|
|
|
|
|
|
|
|
首先在note_edit.xml中添加id为**"@+id/text_num"**的TextView,用于显示实时字符数的统计结果
|
|
|
|
|
|
|
|
|
|
```xml
|
|
|
|
|
<TextView
|
|
|
|
|
|
|
|
|
|
android:id="@+id/text_num"
|
|
|
|
|
|
|
|
|
|
android:layout_width="wrap_content"
|
|
|
|
|
|
|
|
|
|
android:layout_height="wrap_content"
|
|
|
|
|
|
|
|
|
|
android:layout_gravity="right|center_vertical"
|
|
|
|
|
|
|
|
|
|
android:layout_marginRight="8dip"
|
|
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
###### 2、文本监听器
|
|
|
|
|
|
|
|
|
|
然后设置一个文本监听器,利用相应的方法去接受实时的文本数据,并将这些数据变成字符串并返回它们的长度
|
|
|
|
|
|
|
|
|
|
```java
|
|
|
|
|
private void count(){
|
|
|
|
|
editText = (EditText) findViewById(R.id.note_edit_view);
|
|
|
|
|
textView = (TextView) findViewById(R.id.text_num);
|
|
|
|
|
editText.addTextChangedListener(new TextWatcher() {
|
|
|
|
|
int currentLength = 0;
|
|
|
|
|
@Override
|
|
|
|
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
|
|
|
textView.setText("字符数:" + currentLength);
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
|
|
|
currentLength = editText.getText().length();
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
public void afterTextChanged(Editable s) {
|
|
|
|
|
textView.setText("字符数:" + currentLength);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
###### 3、将其添加到onCreate()方法中
|
|
|
|
|
|
|
|
|
|
```java
|
|
|
|
|
@Override
|
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
this.setContentView(R.layout.note_edit);
|
|
|
|
|
|
|
|
|
|
if (savedInstanceState == null && !initActivityState(getIntent())) {
|
|
|
|
|
finish();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
initResources();
|
|
|
|
|
|
|
|
|
|
count();
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
###### 4、效果展示
|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
##### 功能三、实现登录功能
|
|
|
|
|
|
|
|
|
|
###### 1、设置布局
|
|
|
|
|
|
|
|
|
|
```xml
|
|
|
|
|
<?xml version="1.0" encoding="utf-8"?>
|
|
|
|
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
|
|
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
|
|
|
xmlns:tools="http://schemas.android.com/tools"
|
|
|
|
|
android:layout_width="match_parent"
|
|
|
|
|
android:layout_height="match_parent"
|
|
|
|
|
tools:context=".ui.LoginActivity"
|
|
|
|
|
android:orientation="vertical">
|
|
|
|
|
|
|
|
|
|
<LinearLayout
|
|
|
|
|
android:orientation="horizontal"
|
|
|
|
|
android:layout_width="match_parent"
|
|
|
|
|
android:layout_height="60dp"
|
|
|
|
|
android:layout_gravity="center">
|
|
|
|
|
<TextView
|
|
|
|
|
android:hint="账号"
|
|
|
|
|
android:layout_width="90dp"
|
|
|
|
|
android:layout_height="wrap_content"
|
|
|
|
|
android:layout_gravity="center_vertical"
|
|
|
|
|
android:textSize="18sp"
|
|
|
|
|
android:text="@string/prompt_account" />
|
|
|
|
|
|
|
|
|
|
<EditText
|
|
|
|
|
android:id="@+id/account"
|
|
|
|
|
android:layout_width="0dp"
|
|
|
|
|
android:layout_height="wrap_content"
|
|
|
|
|
android:layout_gravity="center_vertical"
|
|
|
|
|
android:layout_weight="1"
|
|
|
|
|
tools:ignore="TouchTargetSizeCheck,TouchTargetSizeCheck,SpeakableTextPresentCheck" />
|
|
|
|
|
|
|
|
|
|
</LinearLayout>
|
|
|
|
|
|
|
|
|
|
<LinearLayout
|
|
|
|
|
android:orientation="horizontal"
|
|
|
|
|
android:layout_width="match_parent"
|
|
|
|
|
android:layout_height="60dp"
|
|
|
|
|
android:layout_gravity="center">
|
|
|
|
|
|
|
|
|
|
<TextView
|
|
|
|
|
android:hint="密码"
|
|
|
|
|
android:layout_width="90dp"
|
|
|
|
|
android:layout_height="wrap_content"
|
|
|
|
|
android:layout_gravity="center_vertical"
|
|
|
|
|
android:text="@string/prompt_password"
|
|
|
|
|
android:textSize="18sp" />
|
|
|
|
|
|
|
|
|
|
<EditText
|
|
|
|
|
android:id="@+id/password"
|
|
|
|
|
android:layout_width="0dp"
|
|
|
|
|
android:layout_height="wrap_content"
|
|
|
|
|
android:layout_gravity="center_vertical"
|
|
|
|
|
android:layout_weight="1"
|
|
|
|
|
android:inputType="textPassword"
|
|
|
|
|
android:minHeight="48dp"
|
|
|
|
|
tools:ignore="SpeakableTextPresentCheck" />
|
|
|
|
|
|
|
|
|
|
</LinearLayout>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<LinearLayout
|
|
|
|
|
android:orientation="horizontal"
|
|
|
|
|
android:layout_width="match_parent"
|
|
|
|
|
android:layout_height="60dp"
|
|
|
|
|
android:layout_gravity="center">
|
|
|
|
|
|
|
|
|
|
<Button
|
|
|
|
|
android:hint="登录"
|
|
|
|
|
android:id="@+id/login"
|
|
|
|
|
android:layout_width="match_parent"
|
|
|
|
|
android:layout_height="wrap_content"
|
|
|
|
|
android:layout_weight="1"
|
|
|
|
|
android:text="@string/prompt_login" />
|
|
|
|
|
|
|
|
|
|
<Button
|
|
|
|
|
android:id="@+id/cancel"
|
|
|
|
|
android:layout_width="match_parent"
|
|
|
|
|
android:layout_height="wrap_content"
|
|
|
|
|
android:layout_weight="1"
|
|
|
|
|
android:hint="退出"
|
|
|
|
|
android:text="@string/cancel" />
|
|
|
|
|
</LinearLayout>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</LinearLayout>
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
|
|
###### 2、添加LoginActivity类进行登录
|
|
|
|
|
|
|
|
|
|
~~~toml
|
|
|
|
|
账号:yinuo
|
|
|
|
|
密码:9410
|
|
|
|
|
~~~
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
package net.micode.notes.ui;
|
|
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
|
import android.app.ProgressDialog;
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
import android.view.View;
|
|
|
|
|
import android.widget.Button;
|
|
|
|
|
import android.widget.EditText;
|
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
|
|
import net.micode.notes.R;
|
|
|
|
|
|
|
|
|
|
public class LoginActivity extends Activity {
|
|
|
|
|
private EditText accountEdit;
|
|
|
|
|
private EditText passwordEdit;
|
|
|
|
|
private Button login;
|
|
|
|
|
private Button cancel;
|
|
|
|
|
@Override
|
|
|
|
|
protected void onCreate(Bundle savedInstanceState){
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
setContentView(R.layout.activity_login);
|
|
|
|
|
accountEdit=(EditText) findViewById(R.id.account);
|
|
|
|
|
passwordEdit=(EditText) findViewById(R.id.password);
|
|
|
|
|
login=(Button)findViewById(R.id.login);
|
|
|
|
|
cancel=(Button)findViewById(R.id.cancel);
|
|
|
|
|
cancel.setOnClickListener(new View.OnClickListener(){
|
|
|
|
|
public void onClick(View view) {
|
|
|
|
|
String account = accountEdit.getText().toString();
|
|
|
|
|
String password = passwordEdit.getText().toString();
|
|
|
|
|
if(account.equals("yinuo") && password.equals("9410")){
|
|
|
|
|
// 登录功能
|
|
|
|
|
ProgressDialog progressDialog = new ProgressDialog(LoginActivity.this);
|
|
|
|
|
progressDialog.setTitle(R.string.Loading);
|
|
|
|
|
progressDialog.setMessage("Loading...");
|
|
|
|
|
progressDialog.setCancelable(true);
|
|
|
|
|
progressDialog.show();
|
|
|
|
|
Intent intent = new Intent(LoginActivity.this,NotesListActivity.class);
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
finish();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
Toast.makeText(LoginActivity.this, R.string.invalid,Toast.LENGTH_SHORT).show();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
###### 3、效果展示
|
|
|
|
|
|
|
|
|
|
3.1 密码错误的情况下
|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
|
|
3.2 账号密码都正确进入小米便签
|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
|
|

|