sync #17

Merged
pbyhqr72x merged 8 commits from develop into master 3 years ago

Binary file not shown.

@ -33,6 +33,7 @@
<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" >
@ -47,8 +48,8 @@
<!--android:uiOptions="splitActionBarWhenNarrow"-->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.CALLr" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
@ -82,12 +83,44 @@
android:resource="@xml/searchable" />
</activity>
<activity
<<<<<<< HEAD:hxs_xiaomi2/res/AndroidManifest.xml
android:name=".ui.PassWordEditActivity"
android:theme="@style/NoteActionBarStyle">
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
=======
android:name=".ui.PassWordEditActivity"
android:theme="@style/NoteActionBarStyle">
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
>>>>>>> d01c3b5117a761c71533cfaeda365327c587bd93:src/Notes-master/AndroidManifest.xml
<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">
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<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

@ -0,0 +1,160 @@
<?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: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/lg_user"-->
<!-- android:layout_width="150dp"-->
<!-- android:layout_height="wrap_content" />-->
<!-- </LinearLayout>-->
<LinearLayout
android:layout_width="match_parent"
@ -47,11 +31,6 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="确认"/>
<!-- <Button-->
<!-- android:id="@+id/lg_registered"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:text="注册"/>-->
</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,63 +14,10 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<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: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>
<EditText
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/et_foler_name"
android:layout_width="fill_parent"
android:hint="@string/hint_foler_name"
android:layout_height="fill_parent" />

@ -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,7 +17,6 @@
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/note_item"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
@ -76,10 +75,4 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
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>

@ -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>

@ -58,4 +58,9 @@
<item
android:id="@+id/menu_delete_passwd"
android:title="Delete password" />
<item
android:id="@+id/menu_font_select"
android:title="@string/menu_font_style" />
</menu>

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

@ -83,6 +83,7 @@
<!-- TOP -->
<string name="menu_top">置顶</string>
<string name="note_top">置顶</string>
<string name="menu_font_style">选择字体</string>
<!-- Sync -->
<string name="ticker_syncing">同步便签...</string>
<string name="ticker_success">同步成功</string>

@ -91,6 +91,7 @@
<string name="sync_progress_login">登陸%1$s...</string>
<string name="sync_progress_init_list">正在獲取服務器便籤列表...</string>
<string name="sync_progress_syncing">正在同步本地便籤...</string>
<string name="menu_font_style">選擇字体</string>
<!-- Preferences -->
<string name="preferences_title">設置</string>
<string name="preferences_account_title">同步賬號</string>

@ -71,7 +71,9 @@
<string name="menu_move_parent_folder">Parent folder</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_locked_folder" translatable="false">该文件夹包含加密便签,无法删除,请先移出加密便签。</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_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>
@ -87,6 +89,7 @@
<!-- TOP -->
<string name="menu_top">menu top</string>
<string name="note_top">note top</string>
<string name="menu_font_style">Select font</string>
<!-- Sync -->
<string name="ticker_syncing">Syncing notes...</string>
<string name="ticker_success">Sync is successful</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;
}*/
}

@ -298,6 +298,13 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
}
return mInstance;
}
//另写一个返回mInstance的函数
public static synchronized NotesDatabaseHelper getmInstanceForLocker(Context context){
if (mInstance == null) {
mInstance = new NotesDatabaseHelper(context);
}
return mInstance;
}
@Override
public void onCreate(SQLiteDatabase db) {

@ -309,15 +309,44 @@ public class NotesProvider extends ContentProvider {
Cursor cursor = null;
cursor = db.query(NotesDatabaseHelper.TABLE.NOTE, null, null, null, null, null, null);
//判断游标是否为空
System.out.println(cursor.getCount());
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++) {
if (cursor.getLong(SqlNote.ID_COLUMN) == id && !cursor.getString(SqlNote.LOCKER_COLUMN).equals("0")) {
cursor.close();
return true;
}
cursor.moveToNext();
if (cursor.getLong(SqlNote.ID_COLUMN) == id ) {
if (cursor.getString(SqlNote.LOCKER_COLUMN).equals("1")) {
cursor.close();
return true;
}
}
}
}
cursor.close();

@ -49,24 +49,24 @@ public class SqlNote {
NoteColumns.NOTES_COUNT, NoteColumns.PARENT_ID, 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.LOCKER
NoteColumns.VERSION,NoteColumns.PASSWORD,NoteColumns.TOP,NoteColumns.LOCKER
};
public static final int ID_COLUMN = 0;
public static final int PARENT_ID_COLUMN = 1;
public static final int ALERTED_DATE_COLUMN = 1;
public static final int ALERTED_DATE_COLUMN = 2;
public static final int BG_COLOR_ID_COLUMN = 2;
public static final int BG_COLOR_ID_COLUMN = 3;
public static final int CREATED_DATE_COLUMN = 3;
public static final int CREATED_DATE_COLUMN = 4;
public static final int HAS_ATTACHMENT_COLUMN = 4;
public static final int HAS_ATTACHMENT_COLUMN = 5;
public static final int MODIFIED_DATE_COLUMN = 5;
public static final int MODIFIED_DATE_COLUMN = 6;
public static final int NOTES_COUNT_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;
@ -85,7 +85,7 @@ public class SqlNote {
public static final int GTASK_ID_COLUMN = 15;
public static final int VERSION_COLUMN = 16;
public static final int LOCKER_COLUMN = 17;
public static final int LOCKER_COLUMN = 19;
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.NoteColumns;
import net.micode.notes.data.Notes.TextNote;
import net.micode.notes.data.NotesDatabaseHelper;
import net.micode.notes.tool.ResourceParser.NoteBgResources;
@ -65,7 +66,7 @@ public class WorkingNote {
//新添加的密码变量
private String mPassword;
//添加密码标志
private String mLocker;
public String mLocker;
public static final String[] DATA_PROJECTION = new String[] {
DataColumns.ID,
@ -89,6 +90,42 @@ public class WorkingNote {
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;

@ -61,8 +61,10 @@ public class DataUtils {
*
*/
if (NotesProvider.isLockedNote(id)){
System.out.println("是上锁便签");
continue;
}
System.out.println("不是上锁便签");
ContentProviderOperation.Builder builder = ContentProviderOperation
.newDelete(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id));
operationList.add(builder.build());

@ -515,6 +515,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
@Override
public void onBackPressed() {
//setLockedFolder();//编辑完便签,按返回键即设置是否是加锁文件夹
if(clearSettingState()) {
return;
}

@ -28,6 +28,8 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;
@ -61,8 +63,11 @@ import android.widget.TextView;
import android.widget.Toast;
import net.micode.notes.R;
import net.micode.notes.account.DBConnection;
import net.micode.notes.data.Notes;
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.model.WorkingNote;
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_NEW_NODE = 103;
private String USERACCOUNT="root";//用户账号密码
private String USERPASSWORD="root";
@Override
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);
mState = ListEditState.NOTE_LIST;
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 {
@ -475,6 +493,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
HashSet<AppWidgetAttribute> widgets = mNotesListAdapter.getSelectedWidget();
if (!isSyncMode()) {
// if not synced, delete notes directly
System.out.println("直接批量删除");
if (DataUtils.batchDeleteNotes(mContentResolver, mNotesListAdapter
.getSelectedItemIds())) {
} else {
@ -483,6 +502,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
} else {
// in sync mode, we'll move the deleted note into the trash
// folder
System.out.println("移到垃圾文件夹");
if (!DataUtils.batchMoveToFolder(mContentResolver, mNotesListAdapter
.getSelectedItemIds(), Notes.ID_TRASH_FOLER)) {
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();
}
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) {
if (folderId == Notes.ID_ROOT_FOLDER) {
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);
HashSet<AppWidgetAttribute> widgets = DataUtils.getFolderNoteWidget(mContentResolver,
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 not synced, delete folder directly
DataUtils.batchDeleteNotes(mContentResolver, ids);
@ -813,6 +869,14 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
case R.id.menu_search:
onSearchRequested();
break;
case R.id.push_sync:
//上传
upSync(this,USERACCOUNT,USERPASSWORD);
break;
case R.id.pull_sync:
//下载
isSurePull();//判断是否可以下拉 如果可以就直接下载了
break;
default:
break;
}
@ -964,4 +1028,40 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}
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) {
Log.d(TAG, "Wrong item id, should not happen");
} else {
System.out.println("挑选的id是");
System.out.println(id);
itemSet.add(id);
}
}

Loading…
Cancel
Save