parent
944d53737a
commit
985757cd7e
@ -0,0 +1,39 @@
|
|||||||
|
package net.micode.notes.ui;
|
||||||
|
|
||||||
|
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 android.widget.Toast;
|
||||||
|
|
||||||
|
import net.micode.notes.R;
|
||||||
|
|
||||||
|
public class PrivateNoteLoginActivity extends Activity {
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_private_note_login);
|
||||||
|
|
||||||
|
EditText etPwd = findViewById(R.id.et_private_pwd);
|
||||||
|
Button btnLogin = findViewById(R.id.btn_private_login);
|
||||||
|
|
||||||
|
btnLogin.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
String pwd = etPwd.getText().toString();
|
||||||
|
if ("123456".equals(pwd)) {
|
||||||
|
Toast.makeText(PrivateNoteLoginActivity.this, "登录成功", Toast.LENGTH_SHORT).show();
|
||||||
|
// 标记已登录
|
||||||
|
getSharedPreferences("private_note", MODE_PRIVATE).edit().putBoolean("is_login", true).apply();
|
||||||
|
Intent intent = new Intent(PrivateNoteLoginActivity.this, PrivateNotesListActivity.class);
|
||||||
|
startActivity(intent);
|
||||||
|
finish();
|
||||||
|
} else {
|
||||||
|
Toast.makeText(PrivateNoteLoginActivity.this, "密码错误", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,82 @@
|
|||||||
|
package net.micode.notes.ui;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.ContentResolver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.ListView;
|
||||||
|
import net.micode.notes.R;
|
||||||
|
import net.micode.notes.data.Notes;
|
||||||
|
import net.micode.notes.data.Notes.NoteColumns;
|
||||||
|
import net.micode.notes.ui.NotesListAdapter;
|
||||||
|
|
||||||
|
public class PrivateNotesListActivity extends Activity {
|
||||||
|
private NotesListAdapter mNotesListAdapter;
|
||||||
|
private ListView mNotesListView;
|
||||||
|
private Button mAddNewNote;
|
||||||
|
private Button mLogout;
|
||||||
|
private ContentResolver mContentResolver;
|
||||||
|
private SharedPreferences sp;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
sp = getSharedPreferences("private_note", Context.MODE_PRIVATE);
|
||||||
|
if (!sp.getBoolean("is_login", false)) {
|
||||||
|
startActivity(new Intent(this, PrivateNoteLoginActivity.class));
|
||||||
|
finish();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setContentView(R.layout.note_list);
|
||||||
|
mContentResolver = getContentResolver();
|
||||||
|
mNotesListView = findViewById(R.id.notes_list);
|
||||||
|
mAddNewNote = findViewById(R.id.btn_new_note);
|
||||||
|
mNotesListAdapter = new NotesListAdapter(this);
|
||||||
|
mNotesListView.setAdapter(mNotesListAdapter);
|
||||||
|
mAddNewNote.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
Intent intent = new Intent(PrivateNotesListActivity.this, NoteEditActivity.class);
|
||||||
|
intent.setAction(Intent.ACTION_INSERT_OR_EDIT);
|
||||||
|
intent.putExtra("is_private", true);
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
mLogout = new Button(this);
|
||||||
|
mLogout.setText("退出私密便签");
|
||||||
|
mLogout.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
sp.edit().putBoolean("is_login", false).apply();
|
||||||
|
Intent intent = new Intent(PrivateNotesListActivity.this, NotesListActivity.class);
|
||||||
|
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
startActivity(intent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
((android.widget.LinearLayout) findViewById(android.R.id.content).getRootView().findViewById(R.id.notes_list).getParent()).addView(mLogout);
|
||||||
|
queryPrivateNotes();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void queryPrivateNotes() {
|
||||||
|
String selection = "is_private=?";
|
||||||
|
String[] selectionArgs = new String[]{"1"};
|
||||||
|
Cursor cursor = mContentResolver.query(Notes.CONTENT_NOTE_URI, null, selection, selectionArgs, null);
|
||||||
|
mNotesListAdapter.changeCursor(cursor);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
if (!sp.getBoolean("is_login", false)) {
|
||||||
|
finish();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
queryPrivateNotes();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:orientation="vertical" android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:gravity="center"
|
||||||
|
android:padding="32dp">
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/et_private_pwd"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="请输入密码"
|
||||||
|
android:inputType="textPassword"/>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/btn_private_login"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="登录"/>
|
||||||
|
</LinearLayout>
|
Loading…
Reference in new issue