hxs_xiaomi1
Aoi 3 years ago
parent 71695c874a
commit 6a16f3c4d1

@ -33,6 +33,7 @@
<uses-permission android:name="android.permission.USE_CREDENTIALS" /> <uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application <application
android:icon="@drawable/icon_app" android:icon="@drawable/icon_app"
android:label="@string/app_name" > android:label="@string/app_name" >
@ -47,8 +48,8 @@
<!--android:uiOptions="splitActionBarWhenNarrow"--> <!--android:uiOptions="splitActionBarWhenNarrow"-->
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.CALLr" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.DEFAULT" />
</intent-filter> </intent-filter>
</activity> </activity>
@ -82,21 +83,35 @@
android:resource="@xml/searchable" /> android:resource="@xml/searchable" />
</activity> </activity>
<activity <activity
<<<<<<< HEAD:hxs_xiaomi2/res/AndroidManifest.xml
android:name=".ui.PassWordEditActivity" android:name=".ui.PassWordEditActivity"
android:theme="@style/NoteActionBarStyle"> android:theme="@style/NoteActionBarStyle">
<intent-filter> <intent-filter>
<category android:name="android.intent.category.DEFAULT"/> <category android:name="android.intent.category.DEFAULT"/>
</intent-filter> </intent-filter>
</activity> </activity>
=======
android:name=".ui.PassWordEditActivity" <activity
android:name=".account.RegisterActivity"
android:theme="@style/NoteActionBarStyle">
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity
android:name=".account.LoginActivity"
android:theme="@style/NoteActionBarStyle"> android:theme="@style/NoteActionBarStyle">
<intent-filter> <intent-filter>
<category android:name="android.intent.category.DEFAULT"/> <category android:name="android.intent.category.DEFAULT"/>
</intent-filter> </intent-filter>
</activity> </activity>
>>>>>>> d01c3b5117a761c71533cfaeda365327c587bd93:src/Notes-master/AndroidManifest.xml <activity
android:name=".account.BeginViewActivity"
android:theme="@style/NoteActionBarStyle">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<provider <provider

@ -1,160 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="net.micode.notes"
android:versionCode="1"
android:versionName="0.1" >
<!--uses-sdk android:minSdkVersion="14" /-->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:icon="@drawable/icon_app"
android:label="@string/app_name" >
<activity
android:name=".ui.NotesListActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/app_name"
android:launchMode="singleTop"
android:theme="@style/NoteTheme"
android:windowSoftInputMode="adjustPan" >
<!--android:uiOptions="splitActionBarWhenNarrow"-->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ui.NoteEditActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:launchMode="singleTop"
android:theme="@style/NoteTheme" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android.cursor.item/text_note" />
<data android:mimeType="vnd.android.cursor.item/call_note" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.INSERT_OR_EDIT" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android.cursor.item/text_note" />
<data android:mimeType="vnd.android.cursor.item/call_note" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable" />
</activity>
<activity
android:name=".ui.PassWordEditActivity"
android:theme="@style/NoteActionBarStyle">
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<provider
android:name="net.micode.notes.data.NotesProvider"
android:authorities="micode_notes"
android:multiprocess="true" />
<receiver
android:name=".widget.NoteWidgetProvider_2x"
android:label="@string/app_widget2x2" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
<action android:name="android.appwidget.action.APPWIDGET_DELETED" />
<action android:name="android.intent.action.PRIVACY_MODE_CHANGED" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/widget_2x_info" />
</receiver>
<receiver
android:name=".widget.NoteWidgetProvider_4x"
android:label="@string/app_widget4x4" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
<action android:name="android.appwidget.action.APPWIDGET_DELETED" />
<action android:name="android.intent.action.PRIVACY_MODE_CHANGED" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/widget_4x_info" />
</receiver>
<receiver android:name=".ui.AlarmInitReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<receiver
android:name="net.micode.notes.ui.AlarmReceiver"
android:process=":remote" >
</receiver>
<activity
android:name=".ui.AlarmAlertActivity"
android:label="@string/app_name"
android:launchMode="singleInstance"
android:theme="@android:style/Theme.Holo.Wallpaper.NoTitleBar" >
</activity>
<activity
android:name="net.micode.notes.ui.NotesPreferenceActivity"
android:label="@string/preferences_title"
android:launchMode="singleTop"
android:theme="@android:style/Theme.Holo.Light" >
</activity>
<service
android:name="net.micode.notes.gtask.remote.GTaskSyncService"
android:exported="false" >
</service>
<meta-data
android:name="android.app.default_searchable"
android:value=".ui.NoteEditActivity" />
</application>
</manifest>

@ -5,22 +5,6 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical" android:orientation="vertical"
android:gravity="center_vertical"> android:gravity="center_vertical">
<!-- <LinearLayout-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:gravity="center">-->
<!-- <TextView-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:text="用户:"/>-->
<!-- <EditText-->
<!-- android:id="@+id/lg_user"-->
<!-- android:layout_width="150dp"-->
<!-- android:layout_height="wrap_content" />-->
<!-- </LinearLayout>-->
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
@ -47,11 +31,6 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="确认"/> android:text="确认"/>
<!-- <Button-->
<!-- android:id="@+id/lg_registered"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:text="注册"/>-->
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>

@ -0,0 +1,34 @@
<?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"
android:gravity="center_vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<Button
android:id="@+id/login_press"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="登录" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<Button
android:id="@+id/register_press"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="注册" />
</LinearLayout>
</LinearLayout>

@ -14,10 +14,63 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
--> -->
<LinearLayout
<EditText
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/et_foler_name" android:layout_width="match_parent"
android:layout_width="fill_parent" android:layout_height="match_parent"
android:hint="@string/hint_foler_name" android:orientation="vertical"
android:layout_height="fill_parent" /> android:gravity="center_vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:id="@+id/old_password_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="输入原密码:"/>
<EditText
android:id="@+id/old_password"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:password="true"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:id="@+id/new_password_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="输入新建密码:"/>
<EditText
android:id="@+id/new_password"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:password="true"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:id="@+id/new_password_again_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="确认密码:"/>
<EditText
android:id="@+id/new_password_again"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:password="true"/>
</LinearLayout>
</LinearLayout>

@ -0,0 +1,34 @@
<?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"
android:gravity="center_vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="请再次确认是否下载云端库数据,"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="本地便签会因此被覆盖。"/>
</LinearLayout>
</LinearLayout>

@ -0,0 +1,58 @@
<?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"
android:gravity="center_vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="账号:"/>
<EditText
android:id="@+id/user_account_login"
android:layout_width="150dp"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="密码:"/>
<EditText
android:id="@+id/user_password_login"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:password="true"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<Button
android:id="@+id/login_account"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="登录"/>
<Button
android:id="@+id/login_ret"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="返回" />
</LinearLayout>
</LinearLayout>

@ -17,6 +17,7 @@
<FrameLayout <FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/note_item" android:id="@+id/note_item"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent"> android:layout_height="fill_parent">
@ -75,4 +76,10 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="top|right"/> android:layout_gravity="top|right"/>
<ImageView
android:id="@+id/iv_locker_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|left"/>
</FrameLayout> </FrameLayout>

@ -0,0 +1,72 @@
<?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"
android:gravity="center_vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="账号:"/>
<EditText
android:id="@+id/user_account"
android:layout_width="150dp"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="密码:"/>
<EditText
android:id="@+id/user_password"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:password="true"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="确认密码:"/>
<EditText
android:id="@+id/user_password_asked"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:password="true"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<Button
android:id="@+id/set_account"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="注册"/>
<Button
android:id="@+id/set_account_ret"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="返回"/>
</LinearLayout>
</LinearLayout>

@ -62,5 +62,4 @@
android:id="@+id/menu_font_select" android:id="@+id/menu_font_select"
android:title="@string/menu_font_style" /> android:title="@string/menu_font_style" />
</menu> </menu>

@ -36,4 +36,10 @@
<item <item
android:id="@+id/menu_search" android:id="@+id/menu_search"
android:title="@string/menu_search"/> android:title="@string/menu_search"/>
<item
android:id="@+id/push_sync"
android:title="上传"/>
<item
android:id="@+id/pull_sync"
android:title="下载"/>
</menu> </menu>

@ -71,7 +71,9 @@
<string name="menu_move_parent_folder">Parent folder</string> <string name="menu_move_parent_folder">Parent folder</string>
<string name="info_note_enter_desktop">Note added to home</string> <string name="info_note_enter_desktop">Note added to home</string>
<string name="alert_message_delete_folder">Confirm to delete folder and its notes?</string> <string name="alert_message_delete_folder">Confirm to delete folder and its notes?</string>
<string name="alert_message_delete_locked_folder" translatable="false">该文件夹包含加密便签,无法删除,请先移出加密便签。</string>
<string name="alert_title_delete">Delete selected notes</string> <string name="alert_title_delete">Delete selected notes</string>
<string name="alert_title_delete_locked_folder" translatable="false">警告</string>
<string name="alert_message_delete_notes">Confirm to delete the selected %d notes?</string> <string name="alert_message_delete_notes">Confirm to delete the selected %d notes?</string>
<string name="alert_message_delete_note">Confirm to delete this note?</string> <string name="alert_message_delete_note">Confirm to delete this note?</string>
<string name="format_move_notes_to_folder">Have moved selected %1$d notes to %2$s folder</string> <string name="format_move_notes_to_folder">Have moved selected %1$d notes to %2$s folder</string>

@ -0,0 +1,48 @@
package net.micode.notes.account;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.telecom.Call;
import android.view.View;
import android.widget.Button;
import net.micode.notes.R;
import net.micode.notes.ui.NotesListActivity;
public class BeginViewActivity extends Activity {
Button loginButton;//登录注册按钮
Button registerButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.begin_view);
/**
* Insert an introduction when user firstly use this application
*/
loginButton=(Button)findViewById(R.id.login_press);
registerButton=(Button)findViewById(R.id.register_press);
loginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//转到登录
Intent intent = new Intent(BeginViewActivity.this, LoginActivity.class);
intent.setAction("android.intent.action.CALLr");
startActivity(intent);
finish();
}
}
);
registerButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//转到注册
Intent intent = new Intent(BeginViewActivity.this, RegisterActivity.class);
intent.setAction("android.intent.action.CALLr");
startActivity(intent);
finish();
}
}
);
}
}

@ -0,0 +1,493 @@
package net.micode.notes.account;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.os.Looper;
import android.util.Log;
import android.widget.Toast;
import net.micode.notes.data.Notes;
import net.micode.notes.data.NotesDatabaseHelper;
import net.micode.notes.model.Note;
import net.micode.notes.model.WorkingNote;
import net.micode.notes.ui.PassWordEditActivity;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class DBConnection {
private static final String CREATE_MY_NOTE_TABLE_SQL =
NotesDatabaseHelper.TABLE.NOTE + "(" +
Notes.NoteColumns.ID + " BIGINT PRIMARY KEY," +
Notes.NoteColumns.PARENT_ID + " BIGINT NOT NULL DEFAULT 0," +
Notes.NoteColumns.ALERTED_DATE + " BIGINT NOT NULL DEFAULT 0," +
Notes.NoteColumns.BG_COLOR_ID + " BIGINT NOT NULL DEFAULT 0," +
Notes.NoteColumns.CREATED_DATE + " BIGINT," +
Notes.NoteColumns.HAS_ATTACHMENT + " BIGINT NOT NULL DEFAULT 0," +
Notes.NoteColumns.MODIFIED_DATE + " BIGINT ," +
Notes.NoteColumns.NOTES_COUNT + " BIGINT NOT NULL DEFAULT 0," +
Notes.NoteColumns.SNIPPET + " TEXT," +
Notes.NoteColumns.TYPE + " BIGINT NOT NULL DEFAULT 0," +
Notes.NoteColumns.WIDGET_ID + " BIGINT NOT NULL DEFAULT 0," +
Notes.NoteColumns.WIDGET_TYPE + " BIGINT NOT NULL DEFAULT -1," +
Notes.NoteColumns.SYNC_ID + " BIGINT NOT NULL DEFAULT 0," +
Notes.NoteColumns.LOCAL_MODIFIED + " BIGINT NOT NULL DEFAULT 0," +
Notes.NoteColumns.ORIGIN_PARENT_ID + " BIGINT NOT NULL DEFAULT 0," +
Notes.NoteColumns.GTASK_ID + " TEXT," +
Notes.NoteColumns.VERSION + " BIGINT NOT NULL DEFAULT 0," +
Notes.NoteColumns.PASSWORD + " TEXT ," +
Notes.NoteColumns.TOP + " INTEGER NOT NULL DEFAULT 0," +
Notes.NoteColumns.LOCKER + " INTEGER NOT NULL DEFAULT 0" +
//NoteColumns.PASSWORD+ " INTEGER NOT NULL DEFAULT 0" +
")";
private static final String CREATE_MY_DATA_TABLE_SQL =
NotesDatabaseHelper.TABLE.DATA + "(" +
Notes.DataColumns.ID + " BIGINT PRIMARY KEY," +
Notes.DataColumns.MIME_TYPE + " TEXT ," +
Notes.DataColumns.NOTE_ID + " BIGINT NOT NULL DEFAULT 0," +
Notes.DataColumns.CREATED_DATE + " BIGINT NOT NULL DEFAULT 0," +
Notes.DataColumns.MODIFIED_DATE + " BIGINT NOT NULL DEFAULT 0," +
Notes.DataColumns.CONTENT + " TEXT ," +
Notes.DataColumns.DATA1 + " BIGINT," +
Notes.DataColumns.DATA2 + " BIGINT," +
Notes.DataColumns.DATA3 + " TEXT ," +
Notes.DataColumns.DATA4 + " TEXT ," +
Notes.DataColumns.DATA5 + " TEXT" +
")";
private static final String INSERT_NOTE_TABLE_SQL =
"(" +
Notes.NoteColumns.ID + "," +
Notes.NoteColumns.PARENT_ID + "," +
Notes.NoteColumns.ALERTED_DATE + "," +
Notes.NoteColumns.BG_COLOR_ID + "," +
Notes.NoteColumns.CREATED_DATE + "," +
Notes.NoteColumns.HAS_ATTACHMENT + "," +
Notes.NoteColumns.MODIFIED_DATE + "," +
Notes.NoteColumns.NOTES_COUNT + "," +
Notes.NoteColumns.SNIPPET + "," +
Notes.NoteColumns.TYPE + "," +
Notes.NoteColumns.WIDGET_ID + "," +
Notes.NoteColumns.WIDGET_TYPE + "," +
Notes.NoteColumns.SYNC_ID + "," +
Notes.NoteColumns.LOCAL_MODIFIED + "," +
Notes.NoteColumns.ORIGIN_PARENT_ID + "," +
Notes.NoteColumns.GTASK_ID + "," +
Notes.NoteColumns.VERSION + "," +
Notes.NoteColumns.PASSWORD + "," +
Notes.NoteColumns.TOP + "," +
Notes.NoteColumns.LOCKER +
")";
private static final String INSERT_DATA_TABLE_SQL =
"(" +
Notes.DataColumns.ID + "," +
Notes.DataColumns.MIME_TYPE + "," +
Notes.DataColumns.NOTE_ID + "," +
Notes.DataColumns.CREATED_DATE + "," +
Notes.DataColumns.MODIFIED_DATE + "," +
Notes.DataColumns.CONTENT + "," +
Notes.DataColumns.DATA1 + "," +
Notes.DataColumns.DATA2 + "," +
Notes.DataColumns.DATA3 + "," +
Notes.DataColumns.DATA4 + "," +
Notes.DataColumns.DATA5 +
")";
public static boolean register(String user_account, String user_password, String user_password_asked) {
System.out.println("运行到link了");
//数据库的地址和账号密码
final String url = "jdbc:mysql://rm-wz9pi09a0f57c13x3co.mysql.rds.aliyuncs.com:3306/xiaomi_server?useSSL=false&ampserverTimezone=GMT";
final String user = "xiaomi_test_1";
final String password = "luoxinxin0712!@#$%^&*()";
Connection conn = null;
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
String sqlRegister;
String sqlFind;
try {
//1、加载驱动
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection(url, user, password);
System.out.println("驱动加载成功!!!");
} catch (Exception e) {
e.printStackTrace();
}
try {
//2、注册 传送数据到数据库
if (!user_password.equals(user_password_asked)) {//判断两次密码输入是否一致
System.out.println("两次输入密码不一致");
return false;
} else {
System.out.println("两次输入密码一致");
}
/**
*
*/
sqlFind = "SELECT * FROM xiaomi_server.note ";
preparedStatement = conn.prepareStatement(sqlFind);
resultSet = preparedStatement.executeQuery();
while (resultSet.next()) {
String user_account_registered = resultSet.getString("account");
if (user_account_registered.equals(user_account)) {
System.out.println("该账号已经注册");
return false;
}
}
sqlRegister = "REPLACE INTO xiaomi_server.note(account,password,note_id,data_id,is_pushsync) values (?,?,?,?,?)";
preparedStatement = conn.prepareStatement(sqlRegister);
preparedStatement.setString(1, user_account);
preparedStatement.setString(2, user_password);
preparedStatement.setString(3, user_account + "_note");
preparedStatement.setString(4, user_account + "_data");
preparedStatement.setString(5, "0");//0标志该账户还没有同步上传过意味着还没有创建相应的表
System.out.println("注册账号是:" + user_account);
System.out.println("注册密码是:" + user_password);
//注册的时候创建相应得表
sqlFind="CREATE TABLE " + user_account +"_"+CREATE_MY_NOTE_TABLE_SQL;
PreparedStatement preparedStatementTable = conn.prepareStatement(sqlFind);
preparedStatementTable.execute();
sqlFind="CREATE TABLE " + user_account +"_"+CREATE_MY_DATA_TABLE_SQL;
preparedStatementTable = conn.prepareStatement(sqlFind);
preparedStatementTable.execute();
System.out.println("创建成功");
//
int result = preparedStatement.executeUpdate();
if (result != 0) {
return true;
}
} catch (SQLException e) {
System.out.println("MySQL操作错误");
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (conn != null) {
try {
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
return false;
}
public static boolean login(String user_account, String user_password) {
System.out.println("运行到login了");
//数据库的地址和账号密码
final String url = "jdbc:mysql://rm-wz9pi09a0f57c13x3co.mysql.rds.aliyuncs.com:3306/xiaomi_server?useSSL=false&ampserverTimezone=GMT";
final String user = "xiaomi_test_1";
final String password = "luoxinxin0712!@#$%^&*()";
Connection conn = null;
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
String sqlFind;
try {
//1、加载驱动
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection(url, user, password);
System.out.println("驱动加载成功!!!");
} catch (Exception e) {
e.printStackTrace();
}
try {
//2、登录
/**
*
*/
sqlFind = "SELECT * FROM xiaomi_server.note ";
preparedStatement = conn.prepareStatement(sqlFind);
resultSet = preparedStatement.executeQuery();
while (resultSet.next()) {
String user_account_registered = resultSet.getString("account");
String user_password_registered = resultSet.getString("password");
//判断账号密码正确性
if (user_account_registered.equals(user_account)) {
System.out.println("账号正确");
if (user_password_registered.equals(user_password)) {
System.out.println("密码正确");
//
/**sqlFind="CREATE TABLE " + user_account +"_"+CREATE_MY_NOTE_TABLE_SQL;
preparedStatement=conn.prepareStatement(sqlFind);
preparedStatement.execute();*/
//
return true;
} else {
System.out.println("密码不正确");
return false;
}
} else {
System.out.println("账号不正确");
}
}
} catch (SQLException e) {
System.out.println("MySQL操作错误");
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (conn != null) {
try {
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
return false;
}
//同步上传到云端数据库函数
public static boolean pushSync(String user_account, String user_password, Context context) {
System.out.println("运行到pushsync了");
//数据库的地址和账号密码
final String url = "jdbc:mysql://rm-wz9pi09a0f57c13x3co.mysql.rds.aliyuncs.com:3306/xiaomi_server?useSSL=false&ampserverTimezone=GMT";
final String user = "xiaomi_test_1";
final String password = "luoxinxin0712!@#$%^&*()";
Connection conn = null;
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
String sqlFind;
String sql;
String user_is_pushsync = "0";//标志该用户是否第一次上传
try {
//1、加载驱动
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection(url, user, password);
System.out.println("驱动加载成功!!!");
} catch (Exception e) {
e.printStackTrace();
}
try {
/**
*
*/
sqlFind = "SELECT * FROM xiaomi_server.note ";
conn = DriverManager.getConnection(url, user, password);
preparedStatement = conn.prepareStatement(sqlFind);
resultSet = preparedStatement.executeQuery();
while (resultSet.next()) {
String user_account_registered = resultSet.getString("account");
if (user_account_registered.equals(user_account)) {
break;
}
}
//conn=DriverManager.getConnection(url, user, password);
conn = DriverManager.getConnection(url, user, password);
Cursor cursor = context.getContentResolver().query(Notes.CONTENT_NOTE_URI, WorkingNote.UP_NOTE_PROJECTION,
null, null, null);
//上传先删除云端库对应的表
sql = "DELETE FROM " + user_account + "_note";
PreparedStatement psDelNote = conn.prepareStatement(sql);
psDelNote.execute();
//再同步
sql = "INSERT INTO " + user_account + "_note " + INSERT_NOTE_TABLE_SQL +
" VALUES (?,?,?,?,?,?," +
"?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
if (cursor != null) {
if (cursor.moveToFirst()) {
do {
PreparedStatement psUpNPTE = conn.prepareStatement(sql);
psUpNPTE.setLong(1,cursor.getLong(0));
psUpNPTE.setLong(2,cursor.getLong(1));
psUpNPTE.setLong(3,cursor.getLong(2));
psUpNPTE.setLong(4,cursor.getLong(3));
psUpNPTE.setLong(5,cursor.getLong(4));
psUpNPTE.setLong(6,cursor.getLong(5));
psUpNPTE.setLong(7,cursor.getLong(6));
psUpNPTE.setLong(8,cursor.getLong(7));
psUpNPTE.setString(9,cursor.getString(8));
psUpNPTE.setLong(10,cursor.getLong(9));
psUpNPTE.setLong(11,cursor.getLong(10));
psUpNPTE.setLong(12,cursor.getLong(11));
psUpNPTE.setLong(13,cursor.getLong(12));
psUpNPTE.setLong(14,cursor.getLong(13));
psUpNPTE.setLong(15,cursor.getLong(14));
psUpNPTE.setString(16,cursor.getString(15));
psUpNPTE.setLong(17,cursor.getLong(16));
psUpNPTE.setString(18,cursor.getString(17));
psUpNPTE.setLong(19,cursor.getLong(18));
psUpNPTE.setLong(20,cursor.getLong(19));
psUpNPTE.execute();
} while (cursor.moveToNext());
cursor.close();
} else {
Log.e("upSync" , "failed");
}
//************上传DATA表原理同Note表**************
sql = "DELETE FROM " + user_account + "_data";
PreparedStatement psDelData = conn.prepareStatement(sql);
psDelData.execute();
cursor = context.getContentResolver().query(Notes.CONTENT_DATA_URI, WorkingNote.UP_DATA_PROJECTION,
null, null, null);
sql = "INSERT INTO " + user_account + "_data " + INSERT_DATA_TABLE_SQL +
" VALUES (?,?,?,?,?,?,?,?,?,?,?)";
if (cursor != null) {
if (cursor.moveToFirst()) {
do {
PreparedStatement psUpData = conn.prepareStatement(sql);
psUpData.setLong(1,cursor.getLong(0));
psUpData.setString(2,cursor.getString(1));
psUpData.setLong(3,cursor.getLong(2));
psUpData.setLong(4,cursor.getLong(3));
psUpData.setLong(5,cursor.getLong(4));
psUpData.setString(6,cursor.getString(5));
psUpData.setLong(7,cursor.getLong(6));
psUpData.setLong(8,cursor.getLong(7));
psUpData.setString(9,cursor.getString(8));
psUpData.setString(10,cursor.getString(9));
psUpData.setString(11,cursor.getString(10));
psUpData.execute();
} while (cursor.moveToNext());
}
cursor.close();
} else {
Log.e("upSync" , "failed");
}
//将note表中是否第一次上传标志为1
sql = "REPLACE INTO xiaomi_server.note(account,is_pushsync) values (?,?)";
preparedStatement = conn.prepareStatement(sql);
preparedStatement.setString(1, user_account);
preparedStatement.setString(2, "1");//0标志该账户还没有同步上传过1标志已经同步上传过
Looper.prepare();
Toast.makeText(context, "上传成功!", Toast.LENGTH_SHORT).show();
Looper.loop();
return true;
}
} catch (SQLException e) {
System.out.println("MySQL操作错误");
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (conn != null) {
try {
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
return false;
}
public static boolean pullSync(String user_account, String user_password, Context context){
System.out.println("运行到pullsync了");
//数据库的地址和账号密码
final String url = "jdbc:mysql://rm-wz9pi09a0f57c13x3co.mysql.rds.aliyuncs.com:3306/xiaomi_server?useSSL=false&ampserverTimezone=GMT";
final String user = "xiaomi_test_1";
final String password = "luoxinxin0712!@#$%^&*()";
Connection conn = null;
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
String sqlFind;
String sql;
String user_is_pushsync = "0";//标志该用户是否第一次上传
try {
//1、加载驱动
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection(url, user, password);
System.out.println("驱动加载成功!!!");
} catch (Exception e) {
e.printStackTrace();
}
try{
/**
*
*/
sqlFind = "SELECT * FROM xiaomi_server.note ";
conn = DriverManager.getConnection(url, user, password);
preparedStatement = conn.prepareStatement(sqlFind);
resultSet = preparedStatement.executeQuery();
while (resultSet.next()) {
String user_account_registered = resultSet.getString("account");
if (user_account_registered.equals(user_account)) {
break;
}
}
ContentResolver cr = context.getContentResolver();
conn = DriverManager.getConnection(url, user, password);
//先删除本地数据库中两个表的内容
String selectionNote= Notes.NoteColumns.TYPE+" >= 0";
String selectionData=Notes.NoteColumns.ID+" >= 0";
cr.delete(Notes.CONTENT_NOTE_URI, selectionNote, null);
cr.delete(Notes.CONTENT_DATA_URI, selectionData, null);
//
sql = "SELECT * FROM " + user_account + "_note";
PreparedStatement psDownNoteTable = conn.prepareStatement(sql);
ResultSet rs = psDownNoteTable.executeQuery();
//在一行行便利,每行逐列写入本地数据库
while(rs.next()){
ContentValues cv = new ContentValues();
cv.put(Notes.NoteColumns.ID, rs.getLong(Notes.NoteColumns.ID));
cv.put(Notes.NoteColumns.PARENT_ID, rs.getLong(Notes.NoteColumns.PARENT_ID));
cv.put(Notes.NoteColumns.ALERTED_DATE, rs.getLong(Notes.NoteColumns.ALERTED_DATE));
cv.put(Notes.NoteColumns.BG_COLOR_ID, rs.getLong(Notes.NoteColumns.BG_COLOR_ID));
cv.put(Notes.NoteColumns.CREATED_DATE, rs.getLong(Notes.NoteColumns.CREATED_DATE));
cv.put(Notes.NoteColumns.HAS_ATTACHMENT, rs.getLong(Notes.NoteColumns.HAS_ATTACHMENT));
cv.put(Notes.NoteColumns.MODIFIED_DATE, rs.getLong(Notes.NoteColumns.MODIFIED_DATE));
cv.put(Notes.NoteColumns.NOTES_COUNT, rs.getLong(Notes.NoteColumns.NOTES_COUNT));
cv.put(Notes.NoteColumns.SNIPPET, rs.getString(Notes.NoteColumns.SNIPPET));
cv.put(Notes.NoteColumns.TYPE, rs.getLong(Notes.NoteColumns.TYPE));
cv.put(Notes.NoteColumns.WIDGET_ID, rs.getLong(Notes.NoteColumns.WIDGET_ID));
cv.put(Notes.NoteColumns.WIDGET_TYPE, rs.getLong(Notes.NoteColumns.WIDGET_TYPE));
cv.put(Notes.NoteColumns.SYNC_ID, rs.getLong(Notes.NoteColumns.SYNC_ID));
cv.put(Notes.NoteColumns.LOCAL_MODIFIED, rs.getLong(Notes.NoteColumns.LOCAL_MODIFIED));
cv.put(Notes.NoteColumns.ORIGIN_PARENT_ID, rs.getLong(Notes.NoteColumns.ORIGIN_PARENT_ID));
cv.put(Notes.NoteColumns.GTASK_ID, rs.getString(Notes.NoteColumns.GTASK_ID));
cv.put(Notes.NoteColumns.VERSION, rs.getLong(Notes.NoteColumns.VERSION));
cv.put(Notes.NoteColumns.PASSWORD, rs.getString(Notes.NoteColumns.PASSWORD));
cv.put(Notes.NoteColumns.TOP,rs.getLong(Notes.NoteColumns.TOP));
cv.put(Notes.NoteColumns.LOCKER,rs.getLong(Notes.NoteColumns.LOCKER));
cr.insert(Notes.CONTENT_NOTE_URI, cv);
}
Log.d("midd", "data");
/****同步data和同步Note同理*******/
sql = "SELECT * FROM " + user_account + "_data";
PreparedStatement psDownDataTable = conn.prepareStatement(sql);
rs= psDownDataTable.executeQuery();
while(rs.next()){
ContentValues cv = new ContentValues();
cv.put(Notes.DataColumns.ID, rs.getLong(Notes.DataColumns.ID));
cv.put(Notes.DataColumns.MIME_TYPE, rs.getString(Notes.DataColumns.MIME_TYPE));
cv.put(Notes.DataColumns.NOTE_ID, rs.getLong(Notes.DataColumns.NOTE_ID));
cv.put(Notes.DataColumns.CREATED_DATE, rs.getLong(Notes.DataColumns.CREATED_DATE));
cv.put(Notes.DataColumns.MODIFIED_DATE, rs.getLong(Notes.DataColumns.MODIFIED_DATE));
cv.put(Notes.DataColumns.CONTENT, rs.getString(Notes.DataColumns.CONTENT));
cv.put(Notes.DataColumns.DATA1, rs.getLong(Notes.DataColumns.DATA1));
cv.put(Notes.DataColumns.DATA2, rs.getLong(Notes.DataColumns.DATA2));
cv.put(Notes.DataColumns.DATA3, rs.getString(Notes.DataColumns.DATA3));
cv.put(Notes.DataColumns.DATA4, rs.getString(Notes.DataColumns.DATA4));
cv.put(Notes.DataColumns.DATA5, rs.getString(Notes.DataColumns.DATA5));
cr.insert(Notes.CONTENT_DATA_URI, cv);
}
Looper.prepare();
Toast.makeText(context, "下载成功!", Toast.LENGTH_SHORT).show();
Looper.loop();
}
catch (SQLException e) {
System.out.println("MySQL操作错误");
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (conn != null) {
try {
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
return false;
}
}

@ -0,0 +1,72 @@
package net.micode.notes.account;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import net.micode.notes.R;
import net.micode.notes.ui.NotesListActivity;
public class LoginActivity extends Activity {
EditText userAccount;//账号密码
EditText userPassword;
Button loginButton;//登录按钮
Button loginReturn;//返回上一级
String user_account;
String user_password;
boolean isSuccess=false;//判断登录是否成功
@Override
protected void onCreate(Bundle savedInstanceState) {
System.out.println("运行到LoginActivity了");
super.onCreate(savedInstanceState);
setContentView(R.layout.login_edit);
userAccount=(EditText) findViewById(R.id.user_account_login);
userPassword=(EditText) findViewById(R.id.user_password_login);
loginButton=(Button)findViewById(R.id.login_account);
loginReturn=(Button)findViewById(R.id.login_ret);
loginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//获取输入密码 账号
user_account=userAccount.getText().toString();
user_password=userPassword.getText().toString();
new Thread(new Runnable() {
@Override
public void run() {
System.out.println("运行到run了");
isSuccess=DBConnection.login(user_account,user_password);
if (isSuccess){
System.out.println("登录成功");
Intent intent = new Intent(LoginActivity.this, NotesListActivity.class);
intent.putExtra("user_account",user_account);
intent.putExtra("user_password",user_password);//将账号密码传递到NotesListActivity中
intent.setAction("android.intent.action.CALLr");
startActivity(intent);
finish();
}
else {
System.out.println("登录失败");
userAccount.setText("");//清空
userPassword.setText("");
}
}
}).start();
}
}
);
loginReturn=(Button)findViewById(R.id.login_ret);
loginReturn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(LoginActivity.this,BeginViewActivity.class);
intent.setAction("android.intent.action.MAIN");
startActivity(intent);
finish();
}
});
}
}

@ -0,0 +1,127 @@
package net.micode.notes.account;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import net.micode.notes.R;
public class RegisterActivity extends Activity {
EditText userAccount;//注册账号密码
EditText userPassword;//
EditText userPasswordAsked;
Button setAccount;//注册确认按钮
Button registerReturn;//注册返回上一级
static String user_account="张三";//默认注册的账号密码
static String user_password="123";
static String user_password_asked;
Boolean isSuccess=false;//判断是否注册成功
@Override
protected void onCreate(Bundle savedInstanceState) {
System.out.println("运行到RegisterActivity了");
super.onCreate(savedInstanceState);
setContentView(R.layout.register_edit);
/**if (savedInstanceState == null) {
finish();
return;
}*/
System.out.println("运行到zhe了");
//不知道作用
/**getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE
| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
//*/
/**new Thread(new Runnable() {
@Override
public void run() {
System.out.println("运行到run了");
DBConnection.link(user_account,user_password);
}
}).start();*/
userAccount=(EditText) findViewById(R.id.user_account);
userPassword=(EditText) findViewById(R.id.user_password);
userPasswordAsked=(EditText)findViewById(R.id.user_password_asked);
setAccount=(Button)findViewById(R.id.set_account);
setAccount.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//获取输入密码 账号
user_account=userAccount.getText().toString();
user_password=userPassword.getText().toString();
user_password_asked=userPasswordAsked.getText().toString();
new Thread(new Runnable() {
@Override
public void run() {
isSuccess=DBConnection.register(user_account,user_password,user_password_asked);
if (isSuccess){
System.out.println("注册成功");
Intent intent = new Intent(RegisterActivity.this, LoginActivity.class);
intent.setAction("android.intent.action.CALLr");
startActivity(intent);
finish();
}
else {
System.out.println("注册失败");
userAccount.setText("");//清空
userPassword.setText("");
userPasswordAsked.setText("");
}
}
}).start();
}
}
);
registerReturn=(Button)findViewById(R.id.set_account_ret);
registerReturn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(RegisterActivity.this,BeginViewActivity.class);
intent.setAction("android.intent.action.MAIN");
startActivity(intent);
finish();
}
});
}
/**public static boolean link(String account, String pwd){
System.out.println(account);
System.out.println(pwd);
Connection connection=null;
try {
//1、加载驱动
Class.forName("com.mysql.jdbc.Driver").newInstance();
System.out.println("驱动加载成功!!!");
}
catch (Exception e){
e.printStackTrace();
}
try {
//2、获取与数据库的连接
connection = DriverManager.getConnection(url, user, password);
System.out.println("连接数据库成功!!!");
//3.sql语句
String sql = "INSERT INTO driver (id, name) VALUES ( '24100413', 'ljy')";
//4.获取用于向数据库发送sql语句的ps
PreparedStatement ps=connection.prepareStatement(sql);
ps.execute(sql);
}catch (Exception e) {
e.printStackTrace();
}
finally {
if(connection!=null){
try {
connection.close();
}catch (Exception e){
e.printStackTrace();
}
}
}
return false;
}*/
}

@ -62,6 +62,10 @@ public class Notes {
public static final Uri CONTENT_DATA_URI = Uri.parse("content://" + AUTHORITY + "/data"); public static final Uri CONTENT_DATA_URI = Uri.parse("content://" + AUTHORITY + "/data");
public interface NoteColumns { public interface NoteColumns {
/**
*
*/
public static final String LOCKER="_locker";
/** /**
* *
*/ */

@ -62,7 +62,8 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
NoteColumns.GTASK_ID + " TEXT NOT NULL DEFAULT ''," + NoteColumns.GTASK_ID + " TEXT NOT NULL DEFAULT ''," +
NoteColumns.VERSION + " INTEGER NOT NULL DEFAULT 0," + NoteColumns.VERSION + " INTEGER NOT NULL DEFAULT 0," +
NoteColumns.PASSWORD+ " TEXT NOT NULL DEFAULT ''," + NoteColumns.PASSWORD+ " TEXT NOT NULL DEFAULT ''," +
NoteColumns.TOP+" INTEGER NOT NULL DEFAULT 0"+ NoteColumns.TOP+" INTEGER NOT NULL DEFAULT 0,"+
NoteColumns.LOCKER + " INTEGER NOT NULL DEFAULT 0" +
//NoteColumns.PASSWORD+ " INTEGER NOT NULL DEFAULT 0" + //NoteColumns.PASSWORD+ " INTEGER NOT NULL DEFAULT 0" +
")"; ")";
@ -297,6 +298,13 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
} }
return mInstance; return mInstance;
} }
//另写一个返回mInstance的函数
public static synchronized NotesDatabaseHelper getmInstanceForLocker(Context context){
if (mInstance == null) {
mInstance = new NotesDatabaseHelper(context);
}
return mInstance;
}
@Override @Override
public void onCreate(SQLiteDatabase db) { public void onCreate(SQLiteDatabase db) {
@ -329,6 +337,10 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
upgradeToV5(db); upgradeToV5(db);
oldVersion++; oldVersion++;
} }
if (oldVersion == 5) {
upgradeToV6(db);
oldVersion++;
}
if (reCreateTriggers) { if (reCreateTriggers) {
reCreateNoteTableTriggers(db); reCreateNoteTableTriggers(db);
@ -371,5 +383,9 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.TOP db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.TOP
+ " INTEGER NOT NULL DEFAULT 0"); + " INTEGER NOT NULL DEFAULT 0");
} }
private void upgradeToV6(SQLiteDatabase db){
db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.LOCKER
+ " INTEGER NOT NULL DEFAULT 0");
}
} }

@ -33,13 +33,14 @@ import net.micode.notes.R;
import net.micode.notes.data.Notes.DataColumns; import net.micode.notes.data.Notes.DataColumns;
import net.micode.notes.data.Notes.NoteColumns; import net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.data.NotesDatabaseHelper.TABLE; import net.micode.notes.data.NotesDatabaseHelper.TABLE;
import net.micode.notes.gtask.data.SqlNote;
public class NotesProvider extends ContentProvider { public class NotesProvider extends ContentProvider {
private static final UriMatcher mMatcher; private static final UriMatcher mMatcher;
private NotesDatabaseHelper mHelper; private NotesDatabaseHelper mHelper;
//创建帮助找到下了锁的对应的便签
private static NotesDatabaseHelper mFind_Locker_Helper;
private static final String TAG = "NotesProvider"; private static final String TAG = "NotesProvider";
private static final int URI_NOTE = 1; private static final int URI_NOTE = 1;
@ -82,6 +83,7 @@ public class NotesProvider extends ContentProvider {
@Override @Override
public boolean onCreate() { public boolean onCreate() {
mHelper = NotesDatabaseHelper.getInstance(getContext()); mHelper = NotesDatabaseHelper.getInstance(getContext());
mFind_Locker_Helper=NotesDatabaseHelper.getInstance(getContext());
return true; return true;
} }
@ -301,5 +303,54 @@ public class NotesProvider extends ContentProvider {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
//判断是否上锁
public static boolean isLockedNote(Long id) {
SQLiteDatabase db = mFind_Locker_Helper.getReadableDatabase();
Cursor cursor = null;
cursor = db.query(NotesDatabaseHelper.TABLE.NOTE, null, null, null, null, null, null);
//判断游标是否为空
System.out.println(cursor.getCount()+"这是行数");
/**if (cursor!=null) {
if (cursor.moveToFirst()) {
System.out.println("执行到判断语句了2");
do {
//遍历游标
System.out.println("执行到判断语句了3");
System.out.println("id1 "+cursor.getLong(SqlNote.ID_COLUMN)+"id2 "+id);
//转化成Sting类型再比较
String idS=String.valueOf(id);
String nowRowIdS=String.valueOf(cursor.getLong(SqlNote.ID_COLUMN));
//
if (idS.equals(nowRowIdS)) {
System.out.println("便签id相等 locker是");
System.out.println(cursor.getString(SqlNote.LOCKER_COLUMN));
if (cursor.getString(SqlNote.LOCKER_COLUMN).equals("1")) {
System.out.println(cursor.getLong(SqlNote.SNIPPET_COLUMN));
cursor.close();
System.out.println("这是一个加锁便签");
return true;
}
}
} while (cursor.moveToNext());
}
}
cursor.close();*/
System.out.println("执行到判断语句了1");
//判断游标是否为空
if (cursor.moveToFirst()) {
//遍历游标
for (int index = 1; index < cursor.getCount(); index++) {
cursor.moveToNext();
if (cursor.getLong(SqlNote.ID_COLUMN) == id ) {
if (cursor.getString(SqlNote.LOCKER_COLUMN).equals("1")) {
cursor.close();
return true;
}
}
}
}
cursor.close();
return false;
}
} }

@ -49,24 +49,24 @@ public class SqlNote {
NoteColumns.NOTES_COUNT, NoteColumns.PARENT_ID, NoteColumns.SNIPPET, NoteColumns.TYPE, NoteColumns.NOTES_COUNT, NoteColumns.PARENT_ID, NoteColumns.SNIPPET, NoteColumns.TYPE,
NoteColumns.WIDGET_ID, NoteColumns.WIDGET_TYPE, NoteColumns.SYNC_ID, NoteColumns.WIDGET_ID, NoteColumns.WIDGET_TYPE, NoteColumns.SYNC_ID,
NoteColumns.LOCAL_MODIFIED, NoteColumns.ORIGIN_PARENT_ID, NoteColumns.GTASK_ID, NoteColumns.LOCAL_MODIFIED, NoteColumns.ORIGIN_PARENT_ID, NoteColumns.GTASK_ID,
NoteColumns.VERSION NoteColumns.VERSION,NoteColumns.PASSWORD,NoteColumns.TOP,NoteColumns.LOCKER
}; };
public static final int ID_COLUMN = 0; public static final int ID_COLUMN = 0;
public static final int ALERTED_DATE_COLUMN = 1; public static final int PARENT_ID_COLUMN = 1;
public static final int BG_COLOR_ID_COLUMN = 2; public static final int ALERTED_DATE_COLUMN = 2;
public static final int CREATED_DATE_COLUMN = 3; public static final int BG_COLOR_ID_COLUMN = 3;
public static final int HAS_ATTACHMENT_COLUMN = 4; public static final int CREATED_DATE_COLUMN = 4;
public static final int MODIFIED_DATE_COLUMN = 5; public static final int HAS_ATTACHMENT_COLUMN = 5;
public static final int NOTES_COUNT_COLUMN = 6; public static final int MODIFIED_DATE_COLUMN = 6;
public static final int PARENT_ID_COLUMN = 7; public static final int NOTES_COUNT_COLUMN = 7;
public static final int SNIPPET_COLUMN = 8; public static final int SNIPPET_COLUMN = 8;
@ -85,6 +85,7 @@ public class SqlNote {
public static final int GTASK_ID_COLUMN = 15; public static final int GTASK_ID_COLUMN = 15;
public static final int VERSION_COLUMN = 16; public static final int VERSION_COLUMN = 16;
public static final int LOCKER_COLUMN = 19;
private Context mContext; private Context mContext;

@ -29,6 +29,7 @@ import net.micode.notes.data.Notes.DataColumns;
import net.micode.notes.data.Notes.DataConstants; import net.micode.notes.data.Notes.DataConstants;
import net.micode.notes.data.Notes.NoteColumns; import net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.data.Notes.TextNote; import net.micode.notes.data.Notes.TextNote;
import net.micode.notes.data.NotesDatabaseHelper;
import net.micode.notes.tool.ResourceParser.NoteBgResources; import net.micode.notes.tool.ResourceParser.NoteBgResources;
@ -64,6 +65,8 @@ public class WorkingNote {
private NoteSettingChangedListener mNoteSettingStatusListener; private NoteSettingChangedListener mNoteSettingStatusListener;
//新添加的密码变量 //新添加的密码变量
private String mPassword; private String mPassword;
//添加密码标志
public String mLocker;
public static final String[] DATA_PROJECTION = new String[] { public static final String[] DATA_PROJECTION = new String[] {
DataColumns.ID, DataColumns.ID,
@ -85,6 +88,43 @@ public class WorkingNote {
//增加一个密码项 //增加一个密码项
NoteColumns.PASSWORD, NoteColumns.PASSWORD,
NoteColumns.TOP, NoteColumns.TOP,
NoteColumns.LOCKER,
};
public static final String[] UP_NOTE_PROJECTION= new String[] {
NoteColumns.ID,
NoteColumns.PARENT_ID,
NoteColumns.ALERTED_DATE,
NoteColumns.BG_COLOR_ID,
NoteColumns.CREATED_DATE ,
NoteColumns.HAS_ATTACHMENT,
NoteColumns.MODIFIED_DATE,
NoteColumns.NOTES_COUNT ,
NoteColumns.SNIPPET ,
NoteColumns.TYPE ,
NoteColumns.WIDGET_ID,
NoteColumns.WIDGET_TYPE ,
NoteColumns.SYNC_ID,
NoteColumns.LOCAL_MODIFIED ,
NoteColumns.ORIGIN_PARENT_ID,
NoteColumns.GTASK_ID ,
NoteColumns.VERSION ,
NoteColumns.PASSWORD,
NoteColumns.TOP,
NoteColumns.LOCKER,
};
public static final String[] UP_DATA_PROJECTION =new String[]{
DataColumns.ID ,
DataColumns.MIME_TYPE ,
DataColumns.NOTE_ID ,
NoteColumns.CREATED_DATE ,
NoteColumns.MODIFIED_DATE ,
DataColumns.CONTENT,
DataColumns.DATA1 ,
DataColumns.DATA2 ,
DataColumns.DATA3 ,
DataColumns.DATA4 ,
DataColumns.DATA5,
}; };
private static final int DATA_ID_COLUMN = 0; private static final int DATA_ID_COLUMN = 0;
@ -108,6 +148,8 @@ public class WorkingNote {
private static final int NOTE_MODIFIED_DATE_COLUMN = 5; private static final int NOTE_MODIFIED_DATE_COLUMN = 5;
//密码 //密码
private static final int NOTE_PASSWORD_COLUMN=6; private static final int NOTE_PASSWORD_COLUMN=6;
//密码标志
private static final int NOTE_LOCKER_COLUMN=8;
/** /**
@ -140,6 +182,11 @@ public class WorkingNote {
public String getmPassword(){ public String getmPassword(){
return mPassword; return mPassword;
} }
//设置密码标志
public void setLocker(String mlocker){
mLocker=mlocker;//1标志为上锁了 0标志为没有上锁
mNote.setNoteValue(NoteColumns.LOCKER,mLocker);
}
// New note construct // New note construct
private WorkingNote(Context context, long folderId) { private WorkingNote(Context context, long folderId) {
@ -183,6 +230,8 @@ public class WorkingNote {
mModifiedDate = cursor.getLong(NOTE_MODIFIED_DATE_COLUMN); mModifiedDate = cursor.getLong(NOTE_MODIFIED_DATE_COLUMN);
//密码 //密码
mPassword= cursor.getString(NOTE_PASSWORD_COLUMN); mPassword= cursor.getString(NOTE_PASSWORD_COLUMN);
//密码标志
mLocker=cursor.getString(NOTE_LOCKER_COLUMN);
} }
cursor.close(); cursor.close();
} else { } else {

@ -25,10 +25,14 @@ import android.content.OperationApplicationException;
import android.database.Cursor; import android.database.Cursor;
import android.os.RemoteException; import android.os.RemoteException;
import android.util.Log; import android.util.Log;
import android.widget.Toast;
import net.micode.notes.data.Notes; import net.micode.notes.data.Notes;
import net.micode.notes.data.Notes.CallNote; import net.micode.notes.data.Notes.CallNote;
import net.micode.notes.data.Notes.NoteColumns; import net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.data.NotesProvider;
import net.micode.notes.ui.NoteEditActivity;
import net.micode.notes.ui.NotesListActivity;
import net.micode.notes.ui.NotesListAdapter.AppWidgetAttribute; import net.micode.notes.ui.NotesListAdapter.AppWidgetAttribute;
import java.util.ArrayList; import java.util.ArrayList;
@ -53,6 +57,14 @@ public class DataUtils {
Log.e(TAG, "Don't delete system folder root"); Log.e(TAG, "Don't delete system folder root");
continue; continue;
} }
/**
*
*/
if (NotesProvider.isLockedNote(id)){
System.out.println("是上锁便签");
continue;
}
System.out.println("不是上锁便签");
ContentProviderOperation.Builder builder = ContentProviderOperation ContentProviderOperation.Builder builder = ContentProviderOperation
.newDelete(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id)); .newDelete(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id));
operationList.add(builder.build()); operationList.add(builder.build());

@ -29,7 +29,6 @@ import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.Typeface;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.text.Spannable; import android.text.Spannable;
@ -55,7 +54,7 @@ import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import android.graphics.Typeface;
import net.micode.notes.R; import net.micode.notes.R;
import net.micode.notes.data.Notes; import net.micode.notes.data.Notes;
import net.micode.notes.data.Notes.TextNote; import net.micode.notes.data.Notes.TextNote;
@ -79,8 +78,9 @@ import java.util.regex.Pattern;
public class NoteEditActivity extends Activity implements OnClickListener, public class NoteEditActivity extends Activity implements OnClickListener,
NoteSettingChangedListener, OnTextViewChangeListener { NoteSettingChangedListener, OnTextViewChangeListener {
private AlertDialog alertDialog2; private AlertDialog alertDialog2;
private class HeadViewHolder { private class HeadViewHolder {
public TextView tvModified; public TextView tvModified;
public ImageView ivAlertIcon; public ImageView ivAlertIcon;
@ -154,6 +154,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
private String mUserQuery; private String mUserQuery;
private Pattern mPattern; private Pattern mPattern;
//private int flag=0;//作为判断删除密码时有无验证通过
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -282,16 +283,23 @@ public class NoteEditActivity extends Activity implements OnClickListener,
//创建dialog插入edittext用户输入密码并做出检验。 //创建dialog插入edittext用户输入密码并做出检验。
final AlertDialog.Builder builder = new AlertDialog.Builder(this); final AlertDialog.Builder builder = new AlertDialog.Builder(this);
View view = LayoutInflater.from(this).inflate(R.layout.dialog_edit_text, null); View view = LayoutInflater.from(this).inflate(R.layout.dialog_edit_text, null);
//编辑Text //编辑dialog界面
final EditText etName = (EditText) view.findViewById(R.id.et_foler_name); final EditText etNameOld= (EditText)view.findViewById(R.id.old_password);//只需要验证原密码
etName.setText(""); final EditText etName = (EditText) view.findViewById(R.id.new_password);
etName.setHint("请输入密码"); etName.setVisibility(view.GONE);
final TextView etName_View=(TextView)view.findViewById(R.id.new_password_view);
etName_View.setVisibility(view.GONE);
final EditText etNameAgain = (EditText) view.findViewById(R.id.new_password_again);
etNameAgain.setVisibility(view.GONE);
final TextView etNameAgain_View=(TextView)view.findViewById(R.id.new_password_again_view);
etNameAgain_View.setVisibility(view.GONE);
//
builder.setTitle("密码检验"); builder.setTitle("密码检验");
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
//获取输入的字符串 //获取输入的字符串
String password = etName.getText().toString(); String password = etNameOld.getText().toString();
Log.d("mPassword: ", mPassword); Log.d("mPassword: ", mPassword);
Log.d("password: ", password); Log.d("password: ", password);
//判断密码正确性 //判断密码正确性
@ -299,22 +307,24 @@ public class NoteEditActivity extends Activity implements OnClickListener,
Log.d("密码不正确,正确密码是:",mPassword); Log.d("密码不正确,正确密码是:",mPassword);
Toast.makeText(NoteEditActivity.this, "密码错误", Toast.LENGTH_SHORT).show(); Toast.makeText(NoteEditActivity.this, "密码错误", Toast.LENGTH_SHORT).show();
dialog.dismiss(); dialog.dismiss();
onBackPressed(); //onBackPressed();
//关闭软键盘 //关闭软键盘
InputMethodManager inputMethodManager = (InputMethodManager) InputMethodManager inputMethodManager = (InputMethodManager)
getSystemService(Context.INPUT_METHOD_SERVICE); getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(etName.getWindowToken(),0); inputMethodManager.hideSoftInputFromWindow(etName.getWindowToken(),0);
} }
else{ else{
Toast.makeText(NoteEditActivity.this, "密码正确", Toast.LENGTH_SHORT).show(); //flag=1;//密码验证正确的标志
deletePassword();
Toast.makeText(NoteEditActivity.this, "密码正确,删除密码成功。", Toast.LENGTH_SHORT).show();
return;
} }
} }
}); });
builder.setNegativeButton("cancel", new DialogInterface.OnClickListener(){ builder.setNegativeButton("cancel", new DialogInterface.OnClickListener(){
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
dialog.dismiss(); finish();
onBackPressed();
} }
}); });
final Dialog dialog = builder.setView(view).show(); final Dialog dialog = builder.setView(view).show();
@ -349,56 +359,6 @@ public class NoteEditActivity extends Activity implements OnClickListener,
*/ */
showAlertHeader(); showAlertHeader();
} }
public void showSingleAlertDiglog(){
final String[] items = {"方正舒体","仿宋","黑体","隶书","行楷","幼圆"};
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this);
alertBuilder.setTitle("字体选择");
alertBuilder.setSingleChoiceItems(items, 0, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int i) {
switch(i){
case 0:
Typeface typeface0 = Typeface.createFromAsset(getAssets(),"font/FZSTK.TTF");
mNoteEditor.setTypeface(typeface0);
break;
case 1:
Typeface typeface1 = Typeface.createFromAsset(getAssets(),"font/SIMYOU.TTF");
mNoteEditor.setTypeface(typeface1);
break;
case 2:
Typeface typeface2 = Typeface.createFromAsset(getAssets(),"font/STLITI.TTF");
mNoteEditor.setTypeface(typeface2);
break;
case 3:
Typeface typeface3 = Typeface.createFromAsset(getAssets(),"font/STXINGKA.TTF");
mNoteEditor.setTypeface(typeface3);
break;
case 4:
Typeface typeface4 = Typeface.createFromAsset(getAssets(),"font/simfang.ttf");
mNoteEditor.setTypeface(typeface4);
break;
case 5:
Typeface typeface5 = Typeface.createFromAsset(getAssets(),"font/simhei.ttf");
mNoteEditor.setTypeface(typeface5);
break;
}
}
});
alertBuilder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int i) {
alertDialog2.dismiss();
}
});
alertBuilder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int i) {
alertDialog2.dismiss();
}
});
alertDialog2 = alertBuilder.create();
alertDialog2.show();
}
private void showAlertHeader() { private void showAlertHeader() {
if (mWorkingNote.hasClockAlert()) { if (mWorkingNote.hasClockAlert()) {
@ -439,6 +399,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
} }
@Override @Override
public boolean dispatchTouchEvent(MotionEvent ev) { public boolean dispatchTouchEvent(MotionEvent ev) {
if (mNoteBgColorSelector.getVisibility() == View.VISIBLE if (mNoteBgColorSelector.getVisibility() == View.VISIBLE
&& !inRangeOfView(mNoteBgColorSelector, ev)) { && !inRangeOfView(mNoteBgColorSelector, ev)) {
@ -453,6 +414,56 @@ public class NoteEditActivity extends Activity implements OnClickListener,
} }
return super.dispatchTouchEvent(ev); return super.dispatchTouchEvent(ev);
} }
public void showSingleAlertDiglog(){
final String[] items = {"方正舒体","仿宋","黑体","隶书","行楷","幼圆"};
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this);
alertBuilder.setTitle("字体选择");
alertBuilder.setSingleChoiceItems(items, 0, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int i) {
switch(i){
case 0:
Typeface typeface0 = Typeface.createFromAsset(getAssets(),"font/FZSTK.TTF");
mNoteEditor.setTypeface(typeface0);
break;
case 1:
Typeface typeface1 = Typeface.createFromAsset(getAssets(),"font/SIMYOU.TTF");
mNoteEditor.setTypeface(typeface1);
break;
case 2:
Typeface typeface2 = Typeface.createFromAsset(getAssets(),"font/STLITI.TTF");
mNoteEditor.setTypeface(typeface2);
break;
case 3:
Typeface typeface3 = Typeface.createFromAsset(getAssets(),"font/STXINGKA.TTF");
mNoteEditor.setTypeface(typeface3);
break;
case 4:
Typeface typeface4 = Typeface.createFromAsset(getAssets(),"font/simfang.ttf");
mNoteEditor.setTypeface(typeface4);
break;
case 5:
Typeface typeface5 = Typeface.createFromAsset(getAssets(),"font/simhei.ttf");
mNoteEditor.setTypeface(typeface5);
break;
}
}
});
alertBuilder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int i) {
alertDialog2.dismiss();
}
});
alertBuilder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int i) {
alertDialog2.dismiss();
}
});
alertDialog2 = alertBuilder.create();
alertDialog2.show();
}
private boolean inRangeOfView(View view, MotionEvent ev) { private boolean inRangeOfView(View view, MotionEvent ev) {
int []location = new int[2]; int []location = new int[2];
@ -558,6 +569,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
@Override @Override
public void onBackPressed() { public void onBackPressed() {
//setLockedFolder();//编辑完便签,按返回键即设置是否是加锁文件夹
if(clearSettingState()) { if(clearSettingState()) {
return; return;
} }
@ -631,9 +643,15 @@ public class NoteEditActivity extends Activity implements OnClickListener,
builder.setPositiveButton(android.R.string.ok, builder.setPositiveButton(android.R.string.ok,
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
if (!mWorkingNote.hasPassword()) {//判断有无密码,有密码则无法删除
deleteCurrentNote(); deleteCurrentNote();
finish(); finish();
} }
else{
Toast.makeText(NoteEditActivity.this, "无法删除设密便签", Toast.LENGTH_SHORT).show();
return;
}
}
}); });
builder.setNegativeButton(android.R.string.cancel, null); builder.setNegativeButton(android.R.string.cancel, null);
builder.show(); builder.show();
@ -666,8 +684,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
//删除密码 //删除密码
case R.id.menu_delete_passwd: case R.id.menu_delete_passwd:
//删除密码前要检验密码 //删除密码前要检验密码
checkPassword(); checkPassword();//并且在里边一并执行deletepassword函数
deletePassword();
break; break;
case R.id.top: case R.id.top:
mWorkingNote.setTop((mWorkingNote.getTopId()) == 1 ? "0" : "1"); mWorkingNote.setTop((mWorkingNote.getTopId()) == 1 ? "0" : "1");
@ -685,17 +702,59 @@ public class NoteEditActivity extends Activity implements OnClickListener,
final AlertDialog.Builder builder = new AlertDialog.Builder(this); final AlertDialog.Builder builder = new AlertDialog.Builder(this);
final View view = LayoutInflater.from(this).inflate(R.layout.dialog_edit_text,null); final View view = LayoutInflater.from(this).inflate(R.layout.dialog_edit_text,null);
//编辑Text //编辑Text
final EditText etName = (EditText)view.findViewById(R.id.et_foler_name); final EditText etNameOld= (EditText)view.findViewById(R.id.old_password);//如果设置了密码,这是原密码
etNameOld.setVisibility(view.GONE);
final TextView etNameOld_View=(TextView)view.findViewById(R.id.old_password_view);
etNameOld_View.setVisibility(view.GONE);
if (mWorkingNote.hasPassword()){//如果设置了密码
etNameOld.setVisibility(view.VISIBLE);
etNameOld_View.setVisibility(view.VISIBLE);
etNameOld.setText("");
etNameOld.setHint("请输入原密码");
}
final EditText etName = (EditText)view.findViewById(R.id.new_password);//要设置的密码
final EditText etNameAgain=(EditText)view.findViewById(R.id.new_password_again);//确认密码
//final EditText finalEtNameOld = etNameOld;
etName.setText(""); etName.setText("");
etName.setHint("请输入密码"); etName.setHint("请输入密码");
builder.setTitle("为便签设置新密码"); etNameAgain.setText("");
etNameAgain.setHint("请确认密码");
builder.setTitle("设置密码");
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
//获取输入的字符串 //获取输入的字符串
String password = etName.getText().toString(); String password = etName.getText().toString();
String password_again=etNameAgain.getText().toString();
String password_old = null;
if (mWorkingNote.hasPassword()){
password_old= etNameOld.getText().toString();
}
//当输入原密码不对时
if (mWorkingNote.hasPassword()) {
if(!password_old.equals(mWorkingNote.getmPassword())) {
Toast.makeText(NoteEditActivity.this, "原密码错误", Toast.LENGTH_SHORT).show();
return;
}
}
//当设置的密码为空的时候
if (password==null || password.length()==0){
//关闭软键盘
InputMethodManager inputMethodManager = (InputMethodManager)
getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(etName.getWindowToken(),0);
dialog.dismiss();
Toast.makeText(NoteEditActivity.this, "密码不能为空", Toast.LENGTH_SHORT).show();
return;
}
//当确认密码不对时
if (!password.equals(password_again)){
Toast.makeText(NoteEditActivity.this, "密码不一致", Toast.LENGTH_SHORT).show();
return;
}
//设置密码 //设置密码
mWorkingNote.setPassword(password); mWorkingNote.setPassword(password);
mWorkingNote.setLocker("1");//设置密码标志为上锁
//设置密码成功提示 //设置密码成功提示
Toast.makeText(NoteEditActivity.this, "密码设置成功", Toast.LENGTH_SHORT).show(); Toast.makeText(NoteEditActivity.this, "密码设置成功", Toast.LENGTH_SHORT).show();
//关闭软键盘 //关闭软键盘
@ -722,6 +781,8 @@ public class NoteEditActivity extends Activity implements OnClickListener,
public void deletePassword() public void deletePassword()
{ {
mWorkingNote.setPassword(""); mWorkingNote.setPassword("");
mWorkingNote.setLocker("0");//设置密码标志为没有锁
//onBackPressed();
} }

@ -19,6 +19,7 @@ package net.micode.notes.ui;
import android.content.Context; import android.content.Context;
import android.database.Cursor; import android.database.Cursor;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log;
import net.micode.notes.data.Contact; import net.micode.notes.data.Contact;
import net.micode.notes.data.Notes; import net.micode.notes.data.Notes;
@ -40,6 +41,7 @@ public class NoteItemData {
NoteColumns.TYPE, NoteColumns.TYPE,
NoteColumns.WIDGET_ID, NoteColumns.WIDGET_ID,
NoteColumns.WIDGET_TYPE, NoteColumns.WIDGET_TYPE,
NoteColumns.LOCKER,
}; };
private static final int ID_COLUMN = 0; private static final int ID_COLUMN = 0;
@ -54,6 +56,8 @@ public class NoteItemData {
private static final int TYPE_COLUMN = 9; private static final int TYPE_COLUMN = 9;
private static final int WIDGET_ID_COLUMN = 10; private static final int WIDGET_ID_COLUMN = 10;
private static final int WIDGET_TYPE_COLUMN = 11; private static final int WIDGET_TYPE_COLUMN = 11;
//密码标志
private static final int LOCKER_COLUMN=12;
private long mId; private long mId;
private long mAlertDate; private long mAlertDate;
@ -69,6 +73,8 @@ public class NoteItemData {
private int mWidgetType; private int mWidgetType;
private String mName; private String mName;
private String mPhoneNumber; private String mPhoneNumber;
//密码标志
private String mLocker;
private boolean mIsLastItem; private boolean mIsLastItem;
private boolean mIsFirstItem; private boolean mIsFirstItem;
@ -76,6 +82,17 @@ public class NoteItemData {
private boolean mIsOneNoteFollowingFolder; private boolean mIsOneNoteFollowingFolder;
private boolean mIsMultiNotesFollowingFolder; private boolean mIsMultiNotesFollowingFolder;
//判断是否上锁
public boolean isLocked(){
if(mLocker.equals("0")) {
Log.d("标志是", mLocker);
return false;
}else {
Log.d("标志是", mLocker);
return true;
}
}
public NoteItemData(Context context, Cursor cursor) { public NoteItemData(Context context, Cursor cursor) {
mId = cursor.getLong(ID_COLUMN); mId = cursor.getLong(ID_COLUMN);
mAlertDate = cursor.getLong(ALERTED_DATE_COLUMN); mAlertDate = cursor.getLong(ALERTED_DATE_COLUMN);
@ -91,6 +108,7 @@ public class NoteItemData {
mType = cursor.getInt(TYPE_COLUMN); mType = cursor.getInt(TYPE_COLUMN);
mWidgetId = cursor.getInt(WIDGET_ID_COLUMN); mWidgetId = cursor.getInt(WIDGET_ID_COLUMN);
mWidgetType = cursor.getInt(WIDGET_TYPE_COLUMN); mWidgetType = cursor.getInt(WIDGET_TYPE_COLUMN);
mLocker = cursor.getString(LOCKER_COLUMN);
mPhoneNumber = ""; mPhoneNumber = "";
if (mParentId == Notes.ID_CALL_RECORD_FOLDER) { if (mParentId == Notes.ID_CALL_RECORD_FOLDER) {

@ -28,6 +28,8 @@ import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.database.Cursor; import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
@ -61,8 +63,11 @@ import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import net.micode.notes.R; import net.micode.notes.R;
import net.micode.notes.account.DBConnection;
import net.micode.notes.data.Notes; import net.micode.notes.data.Notes;
import net.micode.notes.data.Notes.NoteColumns; import net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.data.NotesDatabaseHelper;
import net.micode.notes.gtask.data.SqlNote;
import net.micode.notes.gtask.remote.GTaskSyncService; import net.micode.notes.gtask.remote.GTaskSyncService;
import net.micode.notes.model.WorkingNote; import net.micode.notes.model.WorkingNote;
import net.micode.notes.tool.BackupUtils; import net.micode.notes.tool.BackupUtils;
@ -134,6 +139,8 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
private final static int REQUEST_CODE_OPEN_NODE = 102; private final static int REQUEST_CODE_OPEN_NODE = 102;
private final static int REQUEST_CODE_NEW_NODE = 103; private final static int REQUEST_CODE_NEW_NODE = 103;
private String USERACCOUNT="root";//用户账号密码
private String USERPASSWORD="root";
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -229,6 +236,17 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
mTitleBar = (TextView) findViewById(R.id.tv_title_bar); mTitleBar = (TextView) findViewById(R.id.tv_title_bar);
mState = ListEditState.NOTE_LIST; mState = ListEditState.NOTE_LIST;
mModeCallBack = new ModeCallback(); mModeCallBack = new ModeCallback();
//获得从登录活动中传递过来得账号密码
Intent intent =getIntent();
USERACCOUNT=intent.getStringExtra("user_account");
USERPASSWORD=intent.getStringExtra("user_password");
//登录及下拉数据库内容
new Thread(new Runnable() {
@Override
public void run() {
DBConnection.pullSync(USERACCOUNT, USERPASSWORD, NotesListActivity.this);
}
}).start();
} }
private class ModeCallback implements ListView.MultiChoiceModeListener, OnMenuItemClickListener { private class ModeCallback implements ListView.MultiChoiceModeListener, OnMenuItemClickListener {
@ -475,6 +493,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
HashSet<AppWidgetAttribute> widgets = mNotesListAdapter.getSelectedWidget(); HashSet<AppWidgetAttribute> widgets = mNotesListAdapter.getSelectedWidget();
if (!isSyncMode()) { if (!isSyncMode()) {
// if not synced, delete notes directly // if not synced, delete notes directly
System.out.println("直接批量删除");
if (DataUtils.batchDeleteNotes(mContentResolver, mNotesListAdapter if (DataUtils.batchDeleteNotes(mContentResolver, mNotesListAdapter
.getSelectedItemIds())) { .getSelectedItemIds())) {
} else { } else {
@ -483,6 +502,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
} else { } else {
// in sync mode, we'll move the deleted note into the trash // in sync mode, we'll move the deleted note into the trash
// folder // folder
System.out.println("移到垃圾文件夹");
if (!DataUtils.batchMoveToFolder(mContentResolver, mNotesListAdapter if (!DataUtils.batchMoveToFolder(mContentResolver, mNotesListAdapter
.getSelectedItemIds(), Notes.ID_TRASH_FOLER)) { .getSelectedItemIds(), Notes.ID_TRASH_FOLER)) {
Log.e(TAG, "Move notes to trash folder error, should not happens"); Log.e(TAG, "Move notes to trash folder error, should not happens");
@ -505,7 +525,30 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
} }
}.execute(); }.execute();
} }
private boolean isLockedFolder(long folderId)
{
NotesDatabaseHelper mlockedFolder_FindHelper =NotesDatabaseHelper.getmInstanceForLocker(NotesListActivity.this);
SQLiteDatabase db = mlockedFolder_FindHelper.getReadableDatabase();
Cursor cursor = null;
cursor = db.query(NotesDatabaseHelper.TABLE.NOTE, null, null, null, null, null, null);
//判断游标是否为空
if (cursor.moveToFirst()) {
//遍历游标
for (int index = 1; index < cursor.getCount(); index++) {
cursor.moveToNext();
if (cursor.getLong(SqlNote.PARENT_ID_COLUMN) == folderId ) {
if (cursor.getString(SqlNote.LOCKER_COLUMN).equals("1")) {
System.out.println("这是加密文件夹");
System.out.println(cursor.getLong(SqlNote.SNIPPET_COLUMN));
cursor.close();
return true;
}
}
}
}
cursor.close();
return false;
}
private void deleteFolder(long folderId) { private void deleteFolder(long folderId) {
if (folderId == Notes.ID_ROOT_FOLDER) { if (folderId == Notes.ID_ROOT_FOLDER) {
Log.e(TAG, "Wrong folder id, should not happen " + folderId); Log.e(TAG, "Wrong folder id, should not happen " + folderId);
@ -516,6 +559,19 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
ids.add(folderId); ids.add(folderId);
HashSet<AppWidgetAttribute> widgets = DataUtils.getFolderNoteWidget(mContentResolver, HashSet<AppWidgetAttribute> widgets = DataUtils.getFolderNoteWidget(mContentResolver,
folderId); folderId);
//如果是加密文件夹 则弹窗警告,不可删除
if (isLockedFolder(folderId)){
//弹窗
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(getString(R.string.alert_title_delete_locked_folder));
builder.setIcon(android.R.drawable.ic_dialog_alert);
builder.setMessage(getString(R.string.alert_message_delete_locked_folder));
builder.setPositiveButton(android.R.string.ok,null);
builder.show();
return;
}
//
if (!isSyncMode()) { if (!isSyncMode()) {
// if not synced, delete folder directly // if not synced, delete folder directly
DataUtils.batchDeleteNotes(mContentResolver, ids); DataUtils.batchDeleteNotes(mContentResolver, ids);
@ -581,8 +637,8 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
private void showCreateOrModifyFolderDialog(final boolean create) { private void showCreateOrModifyFolderDialog(final boolean create) {
final AlertDialog.Builder builder = new AlertDialog.Builder(this); final AlertDialog.Builder builder = new AlertDialog.Builder(this);
View view = LayoutInflater.from(this).inflate(R.layout.dialog_edit_text, null); View view = LayoutInflater.from(this).inflate(R.layout.dialog_create_new_folder, null);
final EditText etName = (EditText) view.findViewById(R.id.et_foler_name); final EditText etName = (EditText) view.findViewById(R.id.folder_name);
showSoftInput(); showSoftInput();
if (!create) { if (!create) {
if (mFocusNoteDataItem != null) { if (mFocusNoteDataItem != null) {
@ -783,6 +839,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.menu_new_folder: { case R.id.menu_new_folder: {
showCreateOrModifyFolderDialog(true); showCreateOrModifyFolderDialog(true);
Log.d("创建了文件夹","是的");
break; break;
} }
case R.id.menu_export_text: { case R.id.menu_export_text: {
@ -812,6 +869,14 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
case R.id.menu_search: case R.id.menu_search:
onSearchRequested(); onSearchRequested();
break; break;
case R.id.push_sync:
//上传
upSync(this,USERACCOUNT,USERPASSWORD);
break;
case R.id.pull_sync:
//下载
isSurePull();//判断是否可以下拉 如果可以就直接下载了
break;
default: default:
break; break;
} }
@ -910,7 +975,13 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
case SUB_FOLDER: case SUB_FOLDER:
case CALL_RECORD_FOLDER: case CALL_RECORD_FOLDER:
if (item.getType() == Notes.TYPE_NOTE) { if (item.getType() == Notes.TYPE_NOTE) {
openNode(item); //打开PassWordEditAcitivity类并传递noteid
Intent intent = new Intent(NotesListActivity.this, PassWordEditActivity.class);
long noteId = item.getId();
intent.putExtra("noteId", noteId);
startActivity(intent);
//
//openNode(item);
} else { } else {
Log.e(TAG, "Wrong note type in SUB_FOLDER"); Log.e(TAG, "Wrong note type in SUB_FOLDER");
} }
@ -957,4 +1028,40 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
} }
return false; return false;
} }
public void upSync(Context context,String user_account,String user_password) {
new Thread(new Runnable() {
@Override
public void run() {
DBConnection.pushSync(user_account,user_password, NotesListActivity.this);
}
}).start();
}
public Boolean isSurePull() {
//创建dialog插入edittext用户输入密码并做出检验。
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
View view = LayoutInflater.from(this).inflate(R.layout.dialog_is_to_pull, null);
builder.setTitle("警告:");
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
new Thread(new Runnable() {
@Override
public void run() {
DBConnection.pullSync(USERACCOUNT, USERPASSWORD, NotesListActivity.this);
}
}).start();
}
});
builder.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
return;
}
});
final Dialog dialog = builder.setView(view).show();
dialog.show();
return false;
}
} }

@ -97,6 +97,8 @@ public class NotesListAdapter extends CursorAdapter {
if (id == Notes.ID_ROOT_FOLDER) { if (id == Notes.ID_ROOT_FOLDER) {
Log.d(TAG, "Wrong item id, should not happen"); Log.d(TAG, "Wrong item id, should not happen");
} else { } else {
System.out.println("挑选的id是");
System.out.println(id);
itemSet.add(id); itemSet.add(id);
} }
} }

@ -37,7 +37,7 @@ public class NotesListItem extends LinearLayout {
private TextView mCallName; private TextView mCallName;
private NoteItemData mItemData; private NoteItemData mItemData;
private CheckBox mCheckBox; private CheckBox mCheckBox;
private ImageView mLocker;
public NotesListItem(Context context) { public NotesListItem(Context context) {
super(context); super(context);
inflate(context, R.layout.note_item, this); inflate(context, R.layout.note_item, this);
@ -46,6 +46,8 @@ public class NotesListItem extends LinearLayout {
mTime = (TextView) findViewById(R.id.tv_time); mTime = (TextView) findViewById(R.id.tv_time);
mCallName = (TextView) findViewById(R.id.tv_name); mCallName = (TextView) findViewById(R.id.tv_name);
mCheckBox = (CheckBox) findViewById(android.R.id.checkbox); mCheckBox = (CheckBox) findViewById(android.R.id.checkbox);
//添加锁的标志
mLocker =(ImageView)findViewById(R.id.iv_locker_icon);
} }
public void bind(Context context, NoteItemData data, boolean choiceMode, boolean checked) { public void bind(Context context, NoteItemData data, boolean choiceMode, boolean checked) {
@ -75,6 +77,14 @@ public class NotesListItem extends LinearLayout {
} else { } else {
mAlert.setVisibility(View.GONE); mAlert.setVisibility(View.GONE);
} }
/**
if(data.isLocked()){
mLocker.setImageResource(R.drawable.ic_lock_idle_lock);
mLocker.setVisibility(View.VISIBLE);
} else{
mLocker.setVisibility(View.GONE);
}
*/
} else { } else {
mCallName.setVisibility(View.GONE); mCallName.setVisibility(View.GONE);
mTitle.setTextAppearance(context, R.style.TextAppearancePrimaryItem); mTitle.setTextAppearance(context, R.style.TextAppearancePrimaryItem);
@ -92,6 +102,16 @@ public class NotesListItem extends LinearLayout {
} else { } else {
mAlert.setVisibility(View.GONE); mAlert.setVisibility(View.GONE);
} }
//设置密码标志以及使加密便签内容不可见,未加密则可见。
if(data.isLocked()){
mLocker.setImageResource(R.drawable.ic_lock_idle_lock);
mLocker.setVisibility(View.VISIBLE);
String text = "已加密";
mTitle.setText(text);
} else{
mLocker.setVisibility(View.GONE);
}
//
} }
} }
mTime.setText(DateUtils.getRelativeTimeSpanString(data.getModifiedDate())); mTime.setText(DateUtils.getRelativeTimeSpanString(data.getModifiedDate()));

Loading…
Cancel
Save