pull/10/head
Ryuki 2 years ago
parent 9cc6b3e288
commit ecaabdc260

@ -47,6 +47,7 @@ import android.widget.CheckBox;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
@ -85,8 +86,10 @@ public class NoteEditActivity extends Activity implements OnClickListener,
public ImageView ibSetBgColor; public ImageView ibSetBgColor;
} }
//使用Map实现数据存储 //使用Map实现数据存储
private static final Map<Integer, Integer> sBgSelectorBtnsMap = new HashMap<Integer, Integer>(); private static final Map<Integer, Integer> sBgSelectorBtnsMap = new HashMap<Integer, Integer>();
static { static {
sBgSelectorBtnsMap.put(R.id.iv_bg_yellow, ResourceParser.YELLOW); sBgSelectorBtnsMap.put(R.id.iv_bg_yellow, ResourceParser.YELLOW);
sBgSelectorBtnsMap.put(R.id.iv_bg_red, ResourceParser.RED); sBgSelectorBtnsMap.put(R.id.iv_bg_red, ResourceParser.RED);
@ -97,6 +100,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
} }
private static final Map<Integer, Integer> sBgSelectorSelectionMap = new HashMap<Integer, Integer>(); private static final Map<Integer, Integer> sBgSelectorSelectionMap = new HashMap<Integer, Integer>();
static { static {
sBgSelectorSelectionMap.put(ResourceParser.YELLOW, R.id.iv_bg_yellow_select); sBgSelectorSelectionMap.put(ResourceParser.YELLOW, R.id.iv_bg_yellow_select);
sBgSelectorSelectionMap.put(ResourceParser.RED, R.id.iv_bg_red_select); sBgSelectorSelectionMap.put(ResourceParser.RED, R.id.iv_bg_red_select);
@ -107,6 +111,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
} }
private static final Map<Integer, Integer> sFontSizeBtnsMap = new HashMap<Integer, Integer>(); private static final Map<Integer, Integer> sFontSizeBtnsMap = new HashMap<Integer, Integer>();
static { static {
sFontSizeBtnsMap.put(R.id.ll_font_large, ResourceParser.TEXT_LARGE); sFontSizeBtnsMap.put(R.id.ll_font_large, ResourceParser.TEXT_LARGE);
sFontSizeBtnsMap.put(R.id.ll_font_small, ResourceParser.TEXT_SMALL); sFontSizeBtnsMap.put(R.id.ll_font_small, ResourceParser.TEXT_SMALL);
@ -116,6 +121,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
} }
private static final Map<Integer, Integer> sFontSelectorSelectionMap = new HashMap<Integer, Integer>(); private static final Map<Integer, Integer> sFontSelectorSelectionMap = new HashMap<Integer, Integer>();
static { static {
sFontSelectorSelectionMap.put(ResourceParser.TEXT_LARGE, R.id.iv_large_select); sFontSelectorSelectionMap.put(ResourceParser.TEXT_LARGE, R.id.iv_large_select);
sFontSelectorSelectionMap.put(ResourceParser.TEXT_SMALL, R.id.iv_small_select); sFontSelectorSelectionMap.put(ResourceParser.TEXT_SMALL, R.id.iv_small_select);
@ -220,7 +226,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
getWindow().setSoftInputMode( getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN
| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
} else if(TextUtils.equals(Intent.ACTION_INSERT_OR_EDIT, intent.getAction())) { } else if (TextUtils.equals(Intent.ACTION_INSERT_OR_EDIT, intent.getAction())) {
// New note // New note
// intent.getAction() // intent.getAction()
// 大多用于broadcast发送广播时给机制intent设置一个action就是一个字符串 // 大多用于broadcast发送广播时给机制intent设置一个action就是一个字符串
@ -287,6 +293,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
super.onResume(); super.onResume();
initNoteScreen(); //调用方法初始化笔记屏幕 initNoteScreen(); //调用方法初始化笔记屏幕
} }
//初始化笔记界面的方法 //初始化笔记界面的方法
private void initNoteScreen() { private void initNoteScreen() {
//设置笔记编辑器的文字样式 //设置笔记编辑器的文字样式
@ -341,8 +348,10 @@ public class NoteEditActivity extends Activity implements OnClickListener,
//没有提醒时,隐藏提醒日期和图标 //没有提醒时,隐藏提醒日期和图标
mNoteHeaderHolder.tvAlertDate.setVisibility(View.GONE); mNoteHeaderHolder.tvAlertDate.setVisibility(View.GONE);
mNoteHeaderHolder.ivAlertIcon.setVisibility(View.GONE); mNoteHeaderHolder.ivAlertIcon.setVisibility(View.GONE);
}; }
;
} }
//当活动通过意图重新初始化时调用 //当活动通过意图重新初始化时调用
@Override @Override
protected void onNewIntent(Intent intent) { protected void onNewIntent(Intent intent) {
@ -390,7 +399,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
//判断触摸事件是否在给定的视图的范围内的方法 //判断触摸事件是否在给定的视图的范围内的方法
private boolean inRangeOfView(View view, MotionEvent ev) { private boolean inRangeOfView(View view, MotionEvent ev) {
int []location = new int[2]; int[] location = new int[2];
//获取视图在屏幕上的位置 //获取视图在屏幕上的位置
view.getLocationOnScreen(location); view.getLocationOnScreen(location);
int x = location[0]; int x = location[0];
@ -400,8 +409,8 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|| ev.getX() > (x + view.getWidth()) || ev.getX() > (x + view.getWidth())
|| ev.getY() < y || ev.getY() < y
|| ev.getY() > (y + view.getHeight())) { || ev.getY() > (y + view.getHeight())) {
return false; return false;
} }
return true; return true;
} }
@ -429,7 +438,8 @@ public class NoteEditActivity extends Activity implements OnClickListener,
for (int id : sFontSizeBtnsMap.keySet()) { for (int id : sFontSizeBtnsMap.keySet()) {
View view = findViewById(id); View view = findViewById(id);
view.setOnClickListener(this); view.setOnClickListener(this);
}; }
;
//获取共享偏好设置,用于恢复特定的笔记属性,如字体的大小 //获取共享偏好设置,用于恢复特定的笔记属性,如字体的大小
mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
mFontSizeId = mSharedPrefs.getInt(PREFERENCE_FONT_SIZE, ResourceParser.BG_DEFAULT_FONT_SIZE); mFontSizeId = mSharedPrefs.getInt(PREFERENCE_FONT_SIZE, ResourceParser.BG_DEFAULT_FONT_SIZE);
@ -439,7 +449,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
* return the {@link ResourceParser#BG_DEFAULT_FONT_SIZE} * return the {@link ResourceParser#BG_DEFAULT_FONT_SIZE}
*/ */
//如果字体大小ID超出资源数组大小设置为默认字体大小 //如果字体大小ID超出资源数组大小设置为默认字体大小
if(mFontSizeId >= TextAppearanceResources.getResourcesSize()) { if (mFontSizeId >= TextAppearanceResources.getResourcesSize()) {
mFontSizeId = ResourceParser.BG_DEFAULT_FONT_SIZE; mFontSizeId = ResourceParser.BG_DEFAULT_FONT_SIZE;
} }
//初始化笔记编辑列表视图 //初始化笔记编辑列表视图
@ -451,7 +461,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
protected void onPause() { protected void onPause() {
super.onPause(); super.onPause();
//尝试保存笔记,如果成功则记录保存的长度 //尝试保存笔记,如果成功则记录保存的长度
if(saveNote()) { if (saveNote()) {
Log.d(TAG, "Note data was saved with length:" + mWorkingNote.getContent().length()); Log.d(TAG, "Note data was saved with length:" + mWorkingNote.getContent().length());
} }
//清除设置状态 //清除设置状态
@ -473,14 +483,15 @@ public class NoteEditActivity extends Activity implements OnClickListener,
return; return;
} }
//添加小部件ID到intent中 //添加小部件ID到intent中
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[] { intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[]{
mWorkingNote.getWidgetId() mWorkingNote.getWidgetId()
}); });
//发送广播以通知小部件更新 //发送广播以通知小部件更新
sendBroadcast(intent); sendBroadcast(intent);
//设置结果为OK //设置结果为OK
setResult(RESULT_OK, intent); setResult(RESULT_OK, intent);
} }
//处理点击事件 //处理点击事件
public void onClick(View v) { public void onClick(View v) {
int id = v.getId(); int id = v.getId();
@ -488,8 +499,8 @@ public class NoteEditActivity extends Activity implements OnClickListener,
if (id == R.id.btn_set_bg_color) { if (id == R.id.btn_set_bg_color) {
mNoteBgColorSelector.setVisibility(View.VISIBLE); mNoteBgColorSelector.setVisibility(View.VISIBLE);
findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility( findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(
- View.VISIBLE); -View.VISIBLE);
//更改背景颜色或字体大小的逻辑 //更改背景颜色或字体大小的逻辑
} else if (sBgSelectorBtnsMap.containsKey(id)) { } else if (sBgSelectorBtnsMap.containsKey(id)) {
findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility( findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(
View.GONE); View.GONE);
@ -515,7 +526,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
@Override @Override
public void onBackPressed() { public void onBackPressed() {
//清除设置状态,如果已经处理则返回 //清除设置状态,如果已经处理则返回
if(clearSettingState()) { if (clearSettingState()) {
return; return;
} }
//保存笔记然后正常处理返回事件 //保存笔记然后正常处理返回事件
@ -620,7 +631,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
d.setOnDateTimeSetListener(new OnDateTimeSetListener() { d.setOnDateTimeSetListener(new OnDateTimeSetListener() {
public void OnDateTimeSet(AlertDialog dialog, long date) { public void OnDateTimeSet(AlertDialog dialog, long date) {
//当用户设置了日期时间后,将这个时间保存为提醒的时间 //当用户设置了日期时间后,将这个时间保存为提醒的时间
mWorkingNote.setAlertDate(date , true); mWorkingNote.setAlertDate(date, true);
} }
}); });
//显示日期时间选择对话框 //显示日期时间选择对话框
@ -707,7 +718,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
AlarmManager alarmManager = ((AlarmManager) getSystemService(ALARM_SERVICE)); AlarmManager alarmManager = ((AlarmManager) getSystemService(ALARM_SERVICE));
//显示提醒的头部信息 //显示提醒的头部信息
showAlertHeader(); showAlertHeader();
if(!set) { if (!set) {
//如果set为false取消任何现有的闹钟 //如果set为false取消任何现有的闹钟
alarmManager.cancel(pendingIntent); alarmManager.cancel(pendingIntent);
} else { } else {
@ -745,7 +756,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
mEditTextList.removeViewAt(index);//移除指定索引处的编辑框视图 mEditTextList.removeViewAt(index);//移除指定索引处的编辑框视图
NoteEditText edit = null; NoteEditText edit = null;
if(index == 0) { //如果删除的是第一个编辑框 if (index == 0) { //如果删除的是第一个编辑框
edit = (NoteEditText) mEditTextList.getChildAt(0).findViewById( edit = (NoteEditText) mEditTextList.getChildAt(0).findViewById(
R.id.et_edit_text); R.id.et_edit_text);
} else {//否则,获取欠一个编辑框 } else {//否则,获取欠一个编辑框
@ -764,7 +775,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
/** /**
* Should not happen, check for debug * Should not happen, check for debug
*/ */
if(index > mEditTextList.getChildCount()) { if (index > mEditTextList.getChildCount()) {
Log.e(TAG, "Index out of mEditTextList boundrary, should not happen"); Log.e(TAG, "Index out of mEditTextList boundrary, should not happen");
} }
//创建新的列表项视图,然后将其添加到列表中的指定位置 //创建新的列表项视图,然后将其添加到列表中的指定位置
@ -786,7 +797,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
String[] items = text.split("\n");//按换行符拆分文本成多个项 String[] items = text.split("\n");//按换行符拆分文本成多个项
int index = 0; int index = 0;
for (String item : items) { for (String item : items) {
if(!TextUtils.isEmpty(item)) { //跳过空项 if (!TextUtils.isEmpty(item)) { //跳过空项
mEditTextList.addView(getListItem(item, index));//添加列表项 mEditTextList.addView(getListItem(item, index));//添加列表项
index++; index++;
} }
@ -862,7 +873,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
return; return;
} }
//根据文本是否存在来设置复选框的可见性 //根据文本是否存在来设置复选框的可见性
if(hasText) { if (hasText) {
mEditTextList.getChildAt(index).findViewById(R.id.cb_edit_item).setVisibility(View.VISIBLE); mEditTextList.getChildAt(index).findViewById(R.id.cb_edit_item).setVisibility(View.VISIBLE);
} else { } else {
mEditTextList.getChildAt(index).findViewById(R.id.cb_edit_item).setVisibility(View.GONE); mEditTextList.getChildAt(index).findViewById(R.id.cb_edit_item).setVisibility(View.GONE);
@ -1000,4 +1011,19 @@ public class NoteEditActivity extends Activity implements OnClickListener,
private void showToast(int resId, int duration) { private void showToast(int resId, int duration) {
Toast.makeText(this, resId, duration).show(); Toast.makeText(this, resId, duration).show();
} }
final ImageButton add_img_btn = (ImageButton) findViewById(R.id.add_img_btn);
add_img_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
log.d(TAG, "onClick: click add image button");
Intent loadImage = new Intent(Intent.ACTION_GET_CONTENT);
loadImage.addCategory(Intent.CATEGORY_OPENABLE);
loadImage.setType("image/*");
startActivityForResult(loadImage, PHOTO_REQUESt);
}
});
} }

@ -0,0 +1,29 @@
package net.micode.notes.ui;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowInsets;
import net.micode.notes.R;
public class SplashActivity extends AppCompatActivity {
Handler mHandler=new Handler();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); //加载启动界面
setContentView(R.layout.activity_splash); //加载启动
// 当计时结束时,跳转至 NotesListActivity
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent();
intent.setClass(SplashActivity.this, LoginActivity.class);
startActivity(intent);
finish(); //销毁欢迎页面
}
}, 2000); // 2 秒后跳转}
Loading…
Cancel
Save