first commit

master
unknown 6 years ago
commit bf48481c25

8
.gitignore vendored

@ -0,0 +1,8 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures

Binary file not shown.

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<resourceExtensions />
<wildcardResourcePatterns>
<entry name="!?*.java" />
<entry name="!?*.form" />
<entry name="!?*.class" />
<entry name="!?*.groovy" />
<entry name="!?*.scala" />
<entry name="!?*.flex" />
<entry name="!?*.kt" />
<entry name="!?*.clj" />
<entry name="!?*.aj" />
</wildcardResourcePatterns>
<annotationProcessing>
<profile default="true" name="Default" enabled="false">
<processorPath useClasspath="true" />
</profile>
</annotationProcessing>
</component>
</project>

@ -0,0 +1,3 @@
<component name="CopyrightManager">
<settings default="" />
</component>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="PROJECT" charset="UTF-8" />
</component>
</project>

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
</GradleProjectSettings>
</option>
</component>
</project>

@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="EntryPointsManager">
<entry_points version="2.0" />
</component>
<component name="NullableNotNullManager">
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
<option name="myNullables">
<value>
<list size="10">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
<item index="4" class="java.lang.String" itemvalue="javax.annotation.CheckForNull" />
<item index="5" class="java.lang.String" itemvalue="androidx.annotation.Nullable" />
<item index="6" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNullable" />
<item index="7" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.qual.Nullable" />
<item index="8" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NullableDecl" />
<item index="9" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NullableType" />
</list>
</value>
</option>
<option name="myNotNulls">
<value>
<list size="9">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
<item index="4" class="java.lang.String" itemvalue="androidx.annotation.NonNull" />
<item index="5" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNonNull" />
<item index="6" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.qual.NonNull" />
<item index="7" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NonNullDecl" />
<item index="8" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NonNullType" />
</list>
</value>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
</project>

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/My Diary.iml" filepath="$PROJECT_DIR$/My Diary.iml" />
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
</modules>
</component>
</project>

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
</set>
</option>
</component>
</project>

@ -0,0 +1,424 @@
### 前言
> 本文的内容主要是解析日记 APP 的制作流程,以及代码的具体实现,若有什么不足之处,还请提出建议,附上这个 APP 的 Github 地址 [WatermelonDiaryNew](https://github.com/developerHaoz/WatermelonDiaryNew) 欢迎大家 star 和 fork.
#### 本文的主要内容
- 日记的展示
- 悬浮菜单的实现
- 日记增删改的实现
先来一波日记的展示吧,虽然内容比较简单,但还是设计的非常用心的,因此这款 APP 还是非常简洁和优雅的
![DiaryLICE.gif](http://upload-images.jianshu.io/upload_images/4334738-2844d5478c509396.gif?imageMogr2/auto-orient/strip)
## 一、日记的展示
#### 1、伪日记的处理
可以看到刚开始进入主页面,显示的是 `今天,你什么都没写下...` 这个伪日记,其实只要是某一天没有写日记的话,界面最上面显示的就是这个,当我们写了日记之后,这个伪日记便会消失,讲道理一开始实现这个还真花了我不少心思,本来的思路是将这个伪日记作为 RecyclerView 的第一个Item如果当天有写日记了就将它隐藏起来等到了第二天再重新显示但是感觉实现起来会很麻烦后来想了想只要将这个伪日记直接写在主页面的布局中到时候如果检索到数据库里面有某篇日记的日期跟当天的日期一致的话就将伪日记从布局中 remove 掉就行了
```
if (cursor.moveToFirst()) {
do {
String date = cursor.getString(cursor.getColumnIndex("date"));
// 这是我自己写的一个获取当天日期的一个方法
String dateSystem = GetDate.getDate().toString();
if (date.equals(dateSystem)) {
mMainLlMain.removeView(mItemFirst);
break;
}
} while (cursor.moveToNext());
}
```
#### 2、使用 RecyclerView 展示日记
因为我是打算以事件线的形式来展示我们所写的日记,因此使用 RecyclerView 也算是比较合适的了。这里附上一篇将 RecyclerView 讲的很不错的博客 [RecyclerView 使用详解(一)](http://frank-zhu.github.io/android/2015/01/16/android-recyclerview-part-1/)
要想使用 RecyclerView来实现我们想要实现的效果先让我们建立一个`item_rv_diary`作为 RecyclerView 的子布局
```
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/item_ll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingRight="10dp"
android:background="@color/white"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="25dp"
android:orientation="horizontal"
android:paddingLeft="10.8dp"
android:background="#ffffff"
>
<ImageView
android:id="@+id/main_iv_circle"
android:paddingTop="2dp"
android:layout_width="22dp"
android:layout_height="22dp"
android:src="@drawable/circle"
android:layout_gravity="center_vertical"
/>
<TextView
android:id="@+id/main_tv_date"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="25dp"
android:gravity="center_vertical"
android:paddingLeft="4dp"
android:paddingTop="1dp"
android:text="2017年01月18日"
android:textSize="14sp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<LinearLayout
android:layout_width="23.3dp"
android:layout_height="match_parent"
android:background="@drawable/linear_style"
>
</LinearLayout>
<LinearLayout
android:id="@+id/item_ll_control"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<LinearLayout
android:id="@+id/main_ll_title"
android:layout_width="match_parent"
android:layout_height="35dp"
android:orientation="horizontal"
android:background="#ffffff"
>
<TextView
android:paddingTop="3dp"
android:background="#ffffff"
android:id="@+id/main_tv_title"
android:layout_width="match_parent"
android:layout_height="32dp"
android:gravity="center_vertical"
android:paddingLeft="16dp"
android:text="哈哈哈今天傻逼了"
android:textColor="@color/black"
android:textSize="19sp"
/>
</LinearLayout>
<TextView
android:paddingTop="2dp"
android:background="#ffffff"
android:id="@+id/main_tv_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lineSpacingExtra="4dp"
android:paddingLeft="33dp"
android:paddingRight="15dp"
android:text=" 在这里写些什么在这里写些什么在这里写些什么在这里写些什么在这里写些什么在这里写些什么在这里写些什么在这里写些什么在这里写些什么在这里 写些什么在这里写些什么在这里写些什么在这里写些什么在这里写些什么在这里写些什么在这里写些什么"
android:textColor="@color/black"
android:textSize="16sp"
/>
<RelativeLayout
android:id="@+id/item_rl_edit"
android:layout_width="match_parent"
android:layout_height="40dp"
android:paddingRight="5dp"
android:background="#ffffff"
>
<ImageView
android:id="@+id/main_iv_edit"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentRight="true"
android:layout_centerInParent="true"
android:src="@drawable/edit"
/>
</RelativeLayout>
<LinearLayout
android:background="#ffffff"
android:layout_width="match_parent"
android:layout_height="20dp">
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
```
布局还是比较简单的,比较难实现的应该是左边的那条竖线,其实,一开始并没有什么思路,因为
shape 中的 line 只能画横线,而画不了竖线,最后在 Google 的帮助下,终于找到了实现这个竖线的思路,我是这样处理的,定义一个 layer-list 设置在 TextView 中,将 TextView 的右边框进行描绘
```
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 边框颜色值 --><item>
<shape>
<solid android:color="#8a8a8a" />
</shape>
</item>
<!-- 主体背景颜色值 -->
<item android:right="1.5dp">
<shape>
<solid android:color="#ffffff" />
<padding android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp" />
</shape>
</item>
</layer-list>
```
写好子布局之后,再让我们来实现 RecyclerView 的 Adapter首先定义了一个 DiaryViewHolder 继承自 RecyclerView.ViewHolder传入一个保存日记信息的List然后通过 `onCreateViewHolder` 来创建布局,通过 `onBindViewHolder` 将数据绑定到对应的Item上面这里我使用了 [EventBus](https://github.com/greenrobot/EventBus) 通过点击编辑按钮打开修改日记的界面, EventBus 是一款针对Android优化的发布/订阅事件总线使用也是非常简单的可以当作一个轻量级的BroadCastReceiver 来使用,有兴趣可以看看这篇文章 [EventBus 使用详解(一)——初步使用 EventBus](http://blog.csdn.net/harvic880925/article/details/40660137)
```
public class DiaryAdapter extends RecyclerView.Adapter<DiaryAdapter.DiaryViewHolder> {
private Context mContext;
private LayoutInflater mLayoutInflater;
private List<DiaryBean> mDiaryBeanList;
public DiaryAdapter(Context context, List<DiaryBean> mDiaryBeanList){
mContext = context;
this.mLayoutInflater = LayoutInflater.from(context);
this.mDiaryBeanList = mDiaryBeanList;
}
@Override
public DiaryViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new DiaryViewHolder(mLayoutInflater.inflate(R.layout.item_rv_diary, parent, false));
}
@Override
public void onBindViewHolder(final DiaryViewHolder holder, final int position) {
String dateSystem = GetDate.getDate().toString();
/**
* 如果该日记是当天写的,则将日期左边的圆圈设置成橙色的
*/
if(mDiaryBeanList.get(position).getDate().equals(dateSystem)){
holder.mIvCircle.setImageResource(R.drawable.circle_orange);
}
holder.mTvDate.setText(mDiaryBeanList.get(position).getDate());
holder.mTvTitle.setText(mDiaryBeanList.get(position).getTitle());
holder.mTvContent.setText(mContext.getString(R.string.spaces) + mDiaryBeanList.get(position).getContent());
holder.mIvEdit.setVisibility(View.INVISIBLE);
/**
* 当点击日记的内容时候,则显示出编辑按钮
*/
holder.mLl.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (holder.mIvEdit.getVisibility() == View.INVISIBLE) {
holder.mIvEdit.setVisibility(View.VISIBLE);
}else {
holder.mIvEdit.setVisibility(View.INVISIBLE);
}
}
});
/**
* 使用 EventBus 来打开修改日记的界面,事件接收函数载 MainActivity 中
*/
holder.mIvEdit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EventBus.getDefault().post(new StartUpdateDiaryEvent(position));
}
});
}
@Override
public int getItemCount() {
return mDiaryBeanList.size();
}
static class DiaryViewHolder extends RecyclerView.ViewHolder{
TextView mTvDate;
TextView mTvTitle;
TextView mTvContent;
ImageView mIvEdit;
LinearLayout mLlTitle;
LinearLayout mLl;
ImageView mIvCircle;
LinearLayout mLlControl;
RelativeLayout mRlEdit;
DiaryViewHolder(View view){
super(view);
mIvCircle = (ImageView) view.findViewById(R.id.main_iv_circle);
mTvDate = (TextView) view.findViewById(R.id.main_tv_date);
mTvTitle = (TextView) view.findViewById(R.id.main_tv_title);
mTvContent = (TextView) view.findViewById(R.id.main_tv_content);
mIvEdit = (ImageView) view.findViewById(R.id.main_iv_edit);
mLlTitle = (LinearLayout) view.findViewById(R.id.main_ll_title);
mLl = (LinearLayout) view.findViewById(R.id.item_ll);
mLlControl = (LinearLayout) view.findViewById(R.id.item_ll_control);
mRlEdit = (RelativeLayout) view.findViewById(R.id.item_rl_edit);
}
}
}
```
最后在 MainActivity 中将 RecyclerView 进行处理就行了
```
mMainRvShowDiary.setLayoutManager(new LinearLayoutManager(this));
mMainRvShowDiary.setAdapter(new DiaryAdapter(this, mDiaryBeanList));
```
#### 二、悬浮菜单的实现
悬浮菜单看起来逼格还是挺高的, 而且观赏性也算是比较高,我是从 Github 找的一个库,来实现这个悬浮菜单的,不得不说,搞这个悬浮菜单真的花了我不少时间, 有些库要么不能调节菜单的大小,要么不能调节菜单图案,找了好久才找到这个让我比较满意的库[FloatingActionButton](https://github.com/trity1993/FloatingActionButton)
虽然逼格挺高的但使用起来却是相当的方便先在build.grade中添加
```
dependencies {
compile 'cc.trity.floatingactionbutton:library:1.0.0'
}
```
然后在布局中设置我们想要的颜色和图案,最后在 Activity 中进行悬浮按钮点击事件的处理就行了
```
<cc.trity.floatingactionbutton.FloatingActionsMenu
android:id="@+id/right_labels"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
app:fab_expandDirection="right"
app:fab_addButtonSize="mini"
>
<cc.trity.floatingactionbutton.FloatingActionButton
android:id="@+id/update_diary_fab_back"
android:layout_width="40dp"
android:layout_height="40dp"
app:fab_size="normal"
app:fab_icon = "@drawable/delete_new"
app:fab_colorNormal="#c8180e"
/>
<cc.trity.floatingactionbutton.FloatingActionButton
android:id="@+id/update_diary_fab_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/save"
app:fab_size="normal"
app:fab_title="FAB 2"
app:fab_icon = "@drawable/save_new"
app:fab_colorNormal="#24d63c"
/>
<cc.trity.floatingactionbutton.FloatingActionButton
android:id="@+id/update_diary_fab_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/delete"
app:fab_colorNormal="#d92410"
app:fab_icon = "@drawable/back_new"
app:fab_size="normal"
app:fab_title="FAB 2"
/>
</cc.trity.floatingactionbutton.FloatingActionsMenu>
```
#### 三、日记增删改的实现
日记的信息,我是使用 Android 自带的 SQLite 数据库进行保存的,做法也是比较简单的,这里附上一篇讲解 SQLite 的博客 [Android中SQLite应用详解](http://blog.csdn.net/liuhe688/article/details/6715983),先建立一个 DiaryDatabaseHelper 作为我们进行数据库操作的帮助类,因为日记的内容比较简单, 因此,我只建了一张表
```
public class DiaryDatabaseHelper extends SQLiteOpenHelper {
public static final String CREATE_DIARY = "create table Diary("
+ "id integer primary key autoincrement, "
+ "date text, "
+ "title text, "
+ "content text)";
private Context mContext;
public DiaryDatabaseHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version){
super(context, name, factory, version);
mContext = context;
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_DIARY);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("drop table if exists Diary");
onCreate(db);
}
}
```
**1、日记的添加**
获取添加日记界面中日记的日期、标题以及具体的内容,然后将这些信息添加到数据库中
```
String date = GetDate.getDate().toString();
String title = mAddDiaryEtTitle.getText().toString() + "";
String content = mAddDiaryEtContent.getText().toString() + "";
if (!title.equals("") || !content.equals("")) {
SQLiteDatabase db = mHelper.getWritableDatabase();
ContentValues values = new ContentValues();
values.put("date", date);
values.put("title", title);
values.put("content", content);
db.insert("Diary", null, values);
values.clear();
```
**2、日记的删除**
在这里我为了防止日记被误删,就做了一个对话框,当点击删除按钮的时候,便会跳出这个对话框询问用户是否真的要删除该日记
```
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setMessage("确定要删除该日记吗?").setPositiveButton("确定", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
String title = mUpdateDiaryEtTitle.getText().toString();
SQLiteDatabase dbDelete = mHelper.getWritableDatabase();
dbDelete.delete("Diary", "title = ?", new String[]{title});
MainActivity.startActivity(UpdateDiaryActivity.this);
}
}).setNegativeButton("取消", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
}).show();
```
**3、日记的修改**
```
SQLiteDatabase dbUpdate = mHelper.getWritableDatabase();
ContentValues valuesUpdate = new ContentValues();
String title = mUpdateDiaryEtTitle.getText().toString();
String content = mUpdateDiaryEtContent.getText().toString();
valuesUpdate.put("title", title);
valuesUpdate.put("content", content);
dbUpdate.update("Diary", valuesUpdate, "title = ?", new String[]{title});
dbUpdate.update("Diary", valuesUpdate, "content = ?", new String[]{content});
```
以上便是我写这个 APP 的具体实现思路,以及踩过的一些坑,记录下来,给大家看看,最后附上这个 APP 的 Github 地址 [WatermelonDiaryNew](https://github.com/developerHaoz/WatermelonDiaryNew) 欢迎大家 star 和 fork如果有什么想法或者建议非常欢迎大家来讨论
-----
### 猜你喜欢
- [手把手教你从零开始做一个好看的 APP](http://www.jianshu.com/p/8d2d74d6046f)
- [Android 能让你少走弯路的干货整理](http://www.jianshu.com/p/514656c383a2)
- [Android 撸起袖子,自己封装 DialogFragment](http://www.jianshu.com/p/c9f20ec7277a)

1
app/.gitignore vendored

@ -0,0 +1 @@
/build

Binary file not shown.

@ -0,0 +1,54 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "com.nice.mydiary"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.orhanobut:logger:1.15'
compile 'com.android.support:cardview-v7:23.4.0'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.android.support:support-annotations:23.1.1'
compile 'org.greenrobot:eventbus:3.0.0'
compile 'com.google.code.gson:gson:2.4'
compile 'com.android.support:recyclerview-v7:23.+'
compile 'com.android.support:design:23.4.0'
compile 'com.getbase:floatingactionbutton:1.5.1'
compile 'com.github.clans:fab:1.6.4'
compile 'com.oguzdev:CircularFloatingActionMenu:1.0.2'
compile 'io.github.yavski:fab-speed-dial:1.0.1'
compile 'cc.trity.floatingactionbutton:library:1.0.0'
compile 'com.github.Gennki:QRichText:v1.0.3'
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5.1'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
}
configurations.all {
resolutionStrategy.eachDependency { details ->
def requested = details.requested
if (requested.group == 'com.android.support') {
if (!requested.name.startsWith("multidex")) {
//sdk
details.useVersion '23.4.0'
}
}
}
}

@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in E:\android/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

@ -0,0 +1,13 @@
package com.nice.mydiary;
import android.app.Application;
import android.test.ApplicationTestCase;
/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/
public class ApplicationTest extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
}
}

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.nice.mydiary">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
<application
android:name=".utils.DiaryApplication"
android:allowBackup="true"
android:icon="@drawable/summer_memory_note"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:hardwareAccelerated="true">
<activity android:name=".ui.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".ui.UpdateDiaryActivity"/>
<activity android:name=".ui.AddDiaryActivity"/>
<activity android:name=".ui.TestActivity">
</activity>
</application>
</manifest>

@ -0,0 +1,50 @@
package com.nice.mydiary.bean;
public class DiaryBean {
private String date;
private String title;
private String content;
private String tag;
public DiaryBean(String date, String title, String content, String tag) {
this.date = date;
this.title = title;
this.content = content;
this.tag = tag;
}
public String getTag() {
return tag;
}
public void setTag(String tag) {
this.tag = tag;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}

@ -0,0 +1,33 @@
package com.nice.mydiary.db;
/*数据库操作的帮助类*/
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class DiaryDatabaseHelper extends SQLiteOpenHelper {
public static final String CREATE_DIARY = "create table Diary("
+ "id integer primary key autoincrement, "
+ "date text, "
+ "title text, "
+ "tag text, "
+ "content text)";
private Context mContext;
public DiaryDatabaseHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version){
super(context, name, factory, version);
mContext = context;
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_DIARY);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("drop table if exists Diary");
onCreate(db);
}
}

@ -0,0 +1,19 @@
package com.nice.mydiary.event;
public class StartUpdateDiaryEvent {
private int position;
public StartUpdateDiaryEvent(int position) {
this.position = position;
}
public void setPosition(int position) {
this.position = position;
}
public int getPosition() {
return position;
}
}

@ -0,0 +1,171 @@
package com.nice.mydiary.ui;
import android.content.ContentValues;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.nice.mydiary.R;
import com.nice.mydiary.db.DiaryDatabaseHelper;
import com.nice.mydiary.utils.AppManager;
import com.nice.mydiary.utils.GetDate;
import com.nice.mydiary.utils.StatusBarCompat;
import com.nice.mydiary.widget.LinedEditText;
import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cc.trity.floatingactionbutton.FloatingActionButton;
import cc.trity.floatingactionbutton.FloatingActionsMenu;
public class AddDiaryActivity extends AppCompatActivity {
@Bind(R.id.add_diary_tv_date)
TextView mAddDiaryTvDate;
@Bind(R.id.add_diary_et_title)
EditText mAddDiaryEtTitle;
@Bind(R.id.add_diary_et_content)
LinedEditText mAddDiaryEtContent;
@Bind(R.id.add_diary_fab_back)
FloatingActionButton mAddDiaryFabBack;
@Bind(R.id.add_diary_fab_add)
FloatingActionButton mAddDiaryFabAdd;
/*@Bind(R.id.action_font_size)
FloatingActionButton mActionFontSize;*/
@Bind(R.id.right_labels)
FloatingActionsMenu mRightLabels;
@Bind(R.id.common_tv_title)
TextView mCommonTvTitle;
@Bind(R.id.common_title_ll)
LinearLayout mCommonTitleLl;
@Bind(R.id.common_iv_back)
ImageView mCommonIvBack;
@Bind(R.id.common_iv_test)
ImageView mCommonIvTest;
private DiaryDatabaseHelper mHelper;
public static void startActivity(Context context) {
Intent intent = new Intent(context, AddDiaryActivity.class);
context.startActivity(intent);
}
public static void startActivity(Context context, String title, String content) {
Intent intent = new Intent(context, AddDiaryActivity.class);
intent.putExtra("title", title);
intent.putExtra("content", content);
context.startActivity(intent);
}
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_diary);
AppManager.getAppManager().addActivity(this);
ButterKnife.bind(this);
ActionBar actionBar = getSupportActionBar();
actionBar.hide();
Intent intent = getIntent();
mAddDiaryEtTitle.setText(intent.getStringExtra("title"));
StatusBarCompat.compat(this, Color.parseColor("#161414"));
mCommonTvTitle.setText("记录");
mAddDiaryTvDate.setText(GetDate.getDate());
mAddDiaryEtContent.setText(intent.getStringExtra("content"));
mHelper = new DiaryDatabaseHelper(this, "Diary.db", null, 1);
}
@OnClick({R.id.common_iv_back, R.id.add_diary_et_title, R.id.add_diary_et_content, R.id.add_diary_fab_back, R.id.add_diary_fab_add})
public void onClick(View view) {
switch (view.getId()) {
case R.id.common_iv_back:
MainActivity.startActivity(this);
case R.id.add_diary_et_title:
break;
case R.id.add_diary_et_content:
break;
case R.id.add_diary_fab_back:
/*获取添加日记界面中记录的日期、标题以及具体的内容,然后将这些信息添加到数据库中*/
String date = GetDate.getDate().toString();
String tag = String.valueOf(System.currentTimeMillis());
String title = mAddDiaryEtTitle.getText().toString() + "";
String content = mAddDiaryEtContent.getText().toString() + "";
if (!title.equals("") || !content.equals("")) {
SQLiteDatabase db = mHelper.getWritableDatabase();
ContentValues values = new ContentValues();
values.put("date", date);
values.put("title", title);
values.put("content", content);
values.put("tag", tag);
db.insert("Diary", null, values);
values.clear();
}
MainActivity.startActivity(this);
break;
case R.id.add_diary_fab_add:
final String dateBack = GetDate.getDate().toString();
final String titleBack = mAddDiaryEtTitle.getText().toString();
final String contentBack = mAddDiaryEtContent.getText().toString();
if(!titleBack.isEmpty() || !contentBack.isEmpty()){
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setMessage("是否保存日记内容?").setPositiveButton("确定", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
SQLiteDatabase db = mHelper.getWritableDatabase();
ContentValues values = new ContentValues();
values.put("date", dateBack);
values.put("title", titleBack);
values.put("content", contentBack);
db.insert("Diary", null, values);
values.clear();
MainActivity.startActivity(AddDiaryActivity.this);
}
}).setNegativeButton("取消", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
MainActivity.startActivity(AddDiaryActivity.this);
}
}).show();
}else{
MainActivity.startActivity(this);
}
break;
}
}
@Override
public void onBackPressed() {
super.onBackPressed();
MainActivity.startActivity(this);
}
public void bigger(){
//add_diary_et_content
}
}

@ -0,0 +1,114 @@
package com.nice.mydiary.ui;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.nice.mydiary.R;
import com.nice.mydiary.bean.DiaryBean;
import com.nice.mydiary.event.StartUpdateDiaryEvent;
import com.nice.mydiary.utils.GetDate;
import org.greenrobot.eventbus.EventBus;
import java.util.List;
public class DiaryAdapter extends RecyclerView.Adapter<DiaryAdapter.DiaryViewHolder> {
private Context mContext;
private LayoutInflater mLayoutInflater;
private List<DiaryBean> mDiaryBeanList;
private int mEditPosition = -1;
public DiaryAdapter(Context context, List<DiaryBean> mDiaryBeanList){
mContext = context;
this.mLayoutInflater = LayoutInflater.from(context);
this.mDiaryBeanList = mDiaryBeanList;
}
//创建RecyclerView布局
@Override
public DiaryViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new DiaryViewHolder(mLayoutInflater.inflate(R.layout.item_rv_diary, parent, false));
}
@Override
public void onBindViewHolder(final DiaryViewHolder holder, final int position) {
String dateSystem = GetDate.getDate().toString();
holder.mTvDate.setText(mDiaryBeanList.get(position).getDate());
holder.mTvTitle.setText(mDiaryBeanList.get(position).getTitle());
holder.mTvContent.setText(" " + mDiaryBeanList.get(position).getContent());
holder.mIvEdit.setVisibility(View.INVISIBLE);
if(mEditPosition == position){
holder.mIvEdit.setVisibility(View.VISIBLE);
}else {
holder.mIvEdit.setVisibility(View.GONE);
}
/**
*
*/
holder.mLl.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(holder.mIvEdit.getVisibility() == View.VISIBLE){
holder.mIvEdit.setVisibility(View.GONE);
}else {
holder.mIvEdit.setVisibility(View.VISIBLE);
}
if(mEditPosition != position){
notifyItemChanged(mEditPosition);
}
mEditPosition = position;
}
});
/**
* 使 EventBus MainActivity
*/
holder.mIvEdit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EventBus.getDefault().post(new StartUpdateDiaryEvent(position));
}
});
}
@Override
public int getItemCount() {
return mDiaryBeanList.size();
}
public static class DiaryViewHolder extends RecyclerView.ViewHolder{
TextView mTvDate;
TextView mTvTitle;
TextView mTvContent;
ImageView mIvEdit;
LinearLayout mLlTitle;
LinearLayout mLl;
ImageView mIvCircle;
LinearLayout mLlControl;
RelativeLayout mRlEdit;
DiaryViewHolder(View view){
super(view);
mIvCircle = (ImageView) view.findViewById(R.id.main_iv_circle);
mTvDate = (TextView) view.findViewById(R.id.main_tv_date);
mTvTitle = (TextView) view.findViewById(R.id.main_tv_title);
mTvContent = (TextView) view.findViewById(R.id.main_tv_content);
mIvEdit = (ImageView) view.findViewById(R.id.main_iv_edit);
mLlTitle = (LinearLayout) view.findViewById(R.id.main_ll_title);
mLl = (LinearLayout) view.findViewById(R.id.item_ll);
mLlControl = (LinearLayout) view.findViewById(R.id.item_ll_control);
mRlEdit = (RelativeLayout) view.findViewById(R.id.item_rl_edit);
}
}
}

@ -0,0 +1,181 @@
package com.nice.mydiary.ui;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.nice.mydiary.R;
import com.nice.mydiary.bean.DiaryBean;
import com.nice.mydiary.db.DiaryDatabaseHelper;
import com.nice.mydiary.event.StartUpdateDiaryEvent;
import com.nice.mydiary.utils.AppManager;
import com.nice.mydiary.utils.GetDate;
import com.nice.mydiary.utils.SpHelper;
import com.nice.mydiary.utils.StatusBarCompat;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import java.util.ArrayList;
import java.util.List;
import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
public class MainActivity extends AppCompatActivity {
@Bind(R.id.common_iv_back)
ImageView mCommonIvBack;
@Bind(R.id.common_tv_title)
TextView mCommonTvTitle;
@Bind(R.id.common_iv_test)
ImageView mCommonIvTest;
@Bind(R.id.common_title_ll)
LinearLayout mCommonTitleLl;
@Bind(R.id.main_tv_date)
TextView mMainTvDate;
@Bind(R.id.main_tv_content)
TextView mMainTvContent;
@Bind(R.id.item_ll_control)
LinearLayout mItemLlControl;
@Bind(R.id.main_rv_show_diary)
RecyclerView mMainRvShowDiary;
@Bind(R.id.main_fab_enter_edit)
FloatingActionButton mMainFabEnterEdit;
@Bind(R.id.main_rl_main)
RelativeLayout mMainRlMain;
@Bind(R.id.item_first)
LinearLayout mItemFirst;
@Bind(R.id.main_ll_main)
LinearLayout mMainLlMain;
private List<DiaryBean> mDiaryBeanList;
private DiaryDatabaseHelper mHelper;
private static String IS_WRITE = "true";
private int mEditPosition = -1;
/**
*
*/
private boolean isWrite = false;
private static TextView mTvTest;
public static void startActivity(Context context) {
Intent intent = new Intent(context, MainActivity.class);
context.startActivity(intent);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AppManager.getAppManager().addActivity(this);
ButterKnife.bind(this);
StatusBarCompat.compat(this, Color.parseColor("#161414"));
mHelper = new DiaryDatabaseHelper(this, "Diary.db", null, 1);
ActionBar actionBar = getSupportActionBar();
actionBar.hide();
EventBus.getDefault().register(this);
SpHelper spHelper = SpHelper.getInstance(this);
getDiaryBeanList();
initTitle();
//使用RecyclerView处理显示记录
mMainRvShowDiary.setLayoutManager(new GridLayoutManager(this,1));
mMainRvShowDiary.setAdapter(new DiaryAdapter(this, mDiaryBeanList));
mTvTest = new TextView(this);
mTvTest.setText("hello world");
}
private void initTitle() {
mMainTvDate.setText(GetDate.getDate());
mCommonTvTitle.setText("记忆");
mCommonIvBack.setVisibility(View.INVISIBLE);
mCommonIvTest.setVisibility(View.INVISIBLE);
}
private List<DiaryBean> getDiaryBeanList() {
mDiaryBeanList = new ArrayList<>();
List<DiaryBean> diaryList = new ArrayList<>();
SQLiteDatabase sqLiteDatabase = mHelper.getWritableDatabase();
Cursor cursor = sqLiteDatabase.query("Diary", null, null, null, null, null, null);
//如果今天没写记录则显示伪记录
if (cursor.moveToFirst()) {
do {
String date = cursor.getString(cursor.getColumnIndex("date"));
//获取当天日期
String dateSystem = GetDate.getDate().toString();
if (date.equals(dateSystem)) {
mMainLlMain.removeView(mItemFirst);
break;
}
} while (cursor.moveToNext());
}
if (cursor.moveToFirst()) {
do {
String date = cursor.getString(cursor.getColumnIndex("date"));
String title = cursor.getString(cursor.getColumnIndex("title"));
String content = cursor.getString(cursor.getColumnIndex("content"));
String tag = cursor.getString(cursor.getColumnIndex("tag"));
mDiaryBeanList.add(new DiaryBean(date, title, content, tag));
} while (cursor.moveToNext());
}
cursor.close();
for (int i = mDiaryBeanList.size() - 1; i >= 0; i--) {
diaryList.add(mDiaryBeanList.get(i));
}
mDiaryBeanList = diaryList;
return mDiaryBeanList;
}
@Subscribe
public void startUpdateDiaryActivity(StartUpdateDiaryEvent event) {
String title = mDiaryBeanList.get(event.getPosition()).getTitle();
String content = mDiaryBeanList.get(event.getPosition()).getContent();
String tag = mDiaryBeanList.get(event.getPosition()).getTag();
UpdateDiaryActivity.startActivity(this, title, content, tag);
}
@Override
protected void onDestroy() {
super.onDestroy();
EventBus.getDefault().unregister(this);
}
@OnClick(R.id.main_fab_enter_edit)
public void onClick() {
AddDiaryActivity.startActivity(this);
}
@Override
public void onBackPressed() {
super.onBackPressed();
AppManager.getAppManager().AppExit(this);
}
}

@ -0,0 +1,52 @@
package com.nice.mydiary.ui;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import com.nice.mydiary.R;
import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
public class TestActivity extends AppCompatActivity {
private static final String TAG = "TestActivity";
@Bind(R.id.button1)
Button mButton1;
@Bind(R.id.button2)
Button mButton2;
@Bind(R.id.button3)
Button mButton3;
@Bind(R.id.button4)
Button mButton4;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
ButterKnife.bind(this);
}
@OnClick({R.id.button1, R.id.button2, R.id.button3, R.id.button4})
public void onViewClicked(View view) {
switch (view.getId()) {
case R.id.button1:
Log.d(TAG, "onViewClicked: You Click button1");
break;
case R.id.button2:
Log.d(TAG, "onViewClicked: You Click button2");
break;
case R.id.button3:
Log.d(TAG, "onViewClicked: You Click button3");
break;
}
}
}

@ -0,0 +1,157 @@
package com.nice.mydiary.ui;
import android.content.ContentValues;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.nice.mydiary.R;
import com.nice.mydiary.db.DiaryDatabaseHelper;
import com.nice.mydiary.utils.AppManager;
import com.nice.mydiary.utils.GetDate;
import com.nice.mydiary.utils.StatusBarCompat;
import com.nice.mydiary.widget.LinedEditText;
import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cc.trity.floatingactionbutton.FloatingActionButton;
import cc.trity.floatingactionbutton.FloatingActionsMenu;
public class UpdateDiaryActivity extends AppCompatActivity {
@Bind(R.id.update_diary_tv_date)
TextView mUpdateDiaryTvDate;
@Bind(R.id.update_diary_et_title)
EditText mUpdateDiaryEtTitle;
@Bind(R.id.update_diary_et_content)
LinedEditText mUpdateDiaryEtContent;
@Bind(R.id.update_diary_fab_back)
FloatingActionButton mUpdateDiaryFabBack;
@Bind(R.id.update_diary_fab_add)
FloatingActionButton mUpdateDiaryFabAdd;
@Bind(R.id.update_diary_fab_delete)
FloatingActionButton mUpdateDiaryFabDelete;
@Bind(R.id.right_labels)
FloatingActionsMenu mRightLabels;
@Bind(R.id.common_tv_title)
TextView mCommonTvTitle;
@Bind(R.id.common_title_ll)
LinearLayout mCommonTitleLl;
@Bind(R.id.common_iv_back)
ImageView mCommonIvBack;
@Bind(R.id.common_iv_test)
ImageView mCommonIvTest;
@Bind(R.id.update_diary_tv_tag)
TextView mTvTag;
private DiaryDatabaseHelper mHelper;
public static void startActivity(Context context, String title, String content, String tag) {
Intent intent = new Intent(context, UpdateDiaryActivity.class);
intent.putExtra("title", title);
intent.putExtra("content", content);
intent.putExtra("tag", tag);
context.startActivity(intent);
}
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_update_diary);
AppManager.getAppManager().addActivity(this);
ButterKnife.bind(this);
mHelper = new DiaryDatabaseHelper(this, "Diary.db", null, 1);
initTitle();
StatusBarCompat.compat(this, Color.parseColor("#161414"));
Intent intent = getIntent();
mUpdateDiaryTvDate.setText(GetDate.getDate());
mUpdateDiaryEtTitle.setText(intent.getStringExtra("title"));
mUpdateDiaryEtContent.setText(intent.getStringExtra("content"));
mTvTag.setText(intent.getStringExtra("tag"));
}
private void initTitle() {
ActionBar actionBar = getSupportActionBar();
actionBar.hide();
mCommonTvTitle.setText("修改记录");
}
@OnClick({R.id.common_iv_back, R.id.update_diary_tv_date, R.id.update_diary_et_title, R.id.update_diary_et_content, R.id.update_diary_fab_back, R.id.update_diary_fab_add, R.id.update_diary_fab_delete})
public void onClick(View view) {
switch (view.getId()) {
case R.id.common_iv_back:
SQLiteDatabase dbUpdate1 = mHelper.getWritableDatabase();
ContentValues valuesUpdate1 = new ContentValues();
String title1 = mUpdateDiaryEtTitle.getText().toString();
String content1 = mUpdateDiaryEtContent.getText().toString();
valuesUpdate1.put("title", title1);
valuesUpdate1.put("content", content1);
dbUpdate1.update("Diary", valuesUpdate1, "title = ?", new String[]{title1});
dbUpdate1.update("Diary", valuesUpdate1, "content = ?", new String[]{content1});
MainActivity.startActivity(this);
case R.id.update_diary_tv_date:
break;
case R.id.update_diary_et_title:
break;
case R.id.update_diary_et_content:
break;
case R.id.update_diary_fab_back:
android.support.v7.app.AlertDialog.Builder alertDialogBuilder = new android.support.v7.app.AlertDialog.Builder(this);
alertDialogBuilder.setMessage("确定要删除该条记录吗?").setPositiveButton("确定", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// String title = mUpdateDiaryEtTitle.getText().toString();
String tag = mTvTag.getText().toString();
SQLiteDatabase dbDelete = mHelper.getWritableDatabase();
dbDelete.delete("Diary", "tag = ?", new String[]{tag});
MainActivity.startActivity(UpdateDiaryActivity.this);
}
}).setNegativeButton("取消", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
}).show();
break;
case R.id.update_diary_fab_add:
SQLiteDatabase dbUpdate = mHelper.getWritableDatabase();
ContentValues valuesUpdate = new ContentValues();
String title = mUpdateDiaryEtTitle.getText().toString();
String content = mUpdateDiaryEtContent.getText().toString();
valuesUpdate.put("title", title);
valuesUpdate.put("content", content);
dbUpdate.update("Diary", valuesUpdate, "title = ?", new String[]{title});
dbUpdate.update("Diary", valuesUpdate, "content = ?", new String[]{content});
MainActivity.startActivity(this);
break;
case R.id.update_diary_fab_delete:
MainActivity.startActivity(this);
break;
}
}
@OnClick(R.id.common_tv_title)
public void onClick() {
}
@Override
public void onBackPressed() {
super.onBackPressed();
MainActivity.startActivity(this);
}
}

@ -0,0 +1,120 @@
package com.nice.mydiary.utils;
import android.app.ActivityManager;
import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import java.util.Stack;
public class AppManager {
private static Stack<AppCompatActivity> activityStack;
private static AppManager instance;
private AppManager(){}
public static AppManager getAppManager(){
if(instance == null){
synchronized (AppManager.class){
if(instance == null){
instance = new AppManager();
}
}
}
return instance;
}
public void addActivity(AppCompatActivity activity){
if(activityStack == null){
activityStack = new Stack<>();
}
activityStack.add(activity);
}
/**
* Activity(Activity)
*
* @return
*/
public AppCompatActivity currentActivity(){
if(activityStack == null || activityStack.isEmpty()){
return null;
}
AppCompatActivity acitivity = activityStack.lastElement();
return acitivity;
}
public AppCompatActivity findActivity(Class<?> cls){
AppCompatActivity activity = null;
for (AppCompatActivity appCompatActivity : activityStack) {
if(appCompatActivity.getClass().equals(cls)){
activity = appCompatActivity;
break;
}
}
return activity;
}
public void finishActivity(){
AppCompatActivity activity = activityStack.lastElement();
finishActivity(activity);
}
public void finishActivity(AppCompatActivity activity){
if(activity != null){
activityStack.remove(activity);
activity.finish();
activity = null;
}
}
public void finishActivity(Class<?> cls){
for (AppCompatActivity activity : activityStack) {
if(activity.getClass().equals(cls)){
finishActivity(activity);
}
}
}
public void finishAllActivity(){
for (int i = 0, size = activityStack.size(); i < size; i++) {
if (null != activityStack.get(i)) {
activityStack.get(i).finish();
}
}
activityStack.clear();
}
public void AppExit(Context context){
try{
finishAllActivity();
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
activityManager.killBackgroundProcesses(context.getPackageName());
System.exit(0);
}catch (Exception e){
e.printStackTrace();
}
}
}

@ -0,0 +1,15 @@
package com.nice.mydiary.utils;
import android.app.Application;
import com.squareup.leakcanary.LeakCanary;
public class DiaryApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
}
}

@ -0,0 +1,17 @@
package com.nice.mydiary.utils;
/*获取当天时间并按照格式返回*/
import java.util.Calendar;
public class GetDate {
public static StringBuilder getDate(){
StringBuilder stringBuilder = new StringBuilder();
Calendar now = Calendar.getInstance();
stringBuilder.append(now.get(Calendar.YEAR) + "年");
stringBuilder.append((int)(now.get(Calendar.MONTH) + 1) + "月");
stringBuilder.append(now.get(Calendar.DAY_OF_MONTH) + "日");
return stringBuilder;
}
}

@ -0,0 +1,50 @@
package com.nice.mydiary.utils;
import android.content.Context;
import android.content.SharedPreferences;
public class SpHelper {
private static final String SP_NAME = "sp_name";
private static SpHelper mSpHelper;
private Context mAppContext;
private SharedPreferences mSharedPreferences;
private String info;
private SpHelper(Context context){
mAppContext = context.getApplicationContext();
}
//获取SpHelper的实例
public static SpHelper getInstance(Context context){
if(mSpHelper == null){
synchronized (SpHelper.class){
if(mSpHelper == null){
mSpHelper = new SpHelper(context);
}
}
}
return mSpHelper;
}
private SharedPreferences getSharePreferences(){
if(mSharedPreferences == null){
mSharedPreferences = mAppContext.getSharedPreferences(SP_NAME, Context.MODE_APPEND);
}
return mSharedPreferences;
}
public void setInfo(String info){
this.info = info;
getSharePreferences().edit().putString("info", info).apply();
}
public String getInfo(){
if(info.equals("") || info.length() == 0){
info = getSharePreferences().getString("info", "");
}
return info;
}
}

@ -0,0 +1,73 @@
package com.nice.mydiary.utils;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.os.Build;
import android.view.View;
import android.view.ViewGroup;
/**
*
*
*/
public class StatusBarCompat
{
private static final int INVALID_VAL = -1;
private static final int COLOR_DEFAULT = Color.parseColor("#20000000");
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void compat(Activity activity, int statusColor)
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
{
if (statusColor != INVALID_VAL)
{
activity.getWindow().setStatusBarColor(statusColor);
}
return;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
{
int color = COLOR_DEFAULT;
ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content);
if (statusColor != INVALID_VAL)
{
color = statusColor;
}
View statusBarView = contentView.getChildAt(0);
//改变颜色时避免重复添加statusBarView
if (statusBarView != null && statusBarView.getMeasuredHeight() == getStatusBarHeight(activity))
{
statusBarView.setBackgroundColor(color);
return;
}
statusBarView = new View(activity);
ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
getStatusBarHeight(activity));
statusBarView.setBackgroundColor(color);
contentView.addView(statusBarView, lp);
}
}
public static void compat(Activity activity)
{
compat(activity, INVALID_VAL);
}
public static int getStatusBarHeight(Context context)
{
int result = 0;
int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0)
{
result = context.getResources().getDimensionPixelSize(resourceId);
}
return result;
}
}

@ -0,0 +1,83 @@
package com.nice.mydiary.widget;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.DashPathEffect;
import android.graphics.Paint;
import android.graphics.PathEffect;
import android.util.AttributeSet;
import android.widget.EditText;
@SuppressLint({ "ResourceAsColor", "DrawAllocation" })
public class LinedEditText extends android.support.v7.widget.AppCompatEditText {
//private static int tsize;
public LinedEditText(Context context) {
super(context);
initPaint();
}
public LinedEditText(Context context, AttributeSet attrs) {
super(context, attrs);
initPaint();
}
public LinedEditText(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
initPaint();
}
private void initPaint() {
}
@Override
protected void onDraw(Canvas canvas) {
Paint mPaint = new Paint();
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setColor(Color.LTGRAY);
PathEffect effects = new DashPathEffect(new float[]{5, 5, 5, 5}, 5);
mPaint.setPathEffect(effects);
int left = getLeft();
int right = getRight();
int paddingTop = getPaddingTop();
int paddingBottom = getPaddingBottom();
int paddingLeft = getPaddingLeft();
int paddingRight = getPaddingRight();
int height = getHeight();
int lineHeight = getLineHeight();
int spcingHeight = (int) getLineSpacingExtra();
int count = (height - paddingTop - paddingBottom) / lineHeight;
for (int i = 0; i < count; i++) {
int baseline = lineHeight * (i + 1) + paddingTop - spcingHeight / 2;
canvas.drawLine(paddingLeft, (int) (baseline * 1.0), right - paddingRight * (int) 1.8, (int) (baseline * 1.0), mPaint);
}
super.onDraw(canvas);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
</shape>

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 210 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 边框颜色值 --><item>
<shape>
<solid android:color="#a3a8a4" />
</shape>
</item>
<!-- 主体背景颜色值 -->
<item android:right="1dp">
<shape>
<solid android:color="#ffffff" />
<padding android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp" />
</shape>
</item>
</layer-list>

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<!--这里是Linearlayout布局的背景颜色-->
<solid android:color="#5CACEE" />
<!--这里是设置边框线的粗细和颜色-->
<stroke
android:width="1dp"
android:color="#5CACEE" />
<padding
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="1dp" />
<!--角的话,里边有参数可以单独设置-->
<corners android:radius="20dp" />
</shape>

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#FFFFFF"/>
<stroke
android:width="0.5dp"
android:color="#dddddd"/>
<padding
android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp"/>
<corners android:radius="10dp"/>
</shape>

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

@ -0,0 +1,222 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<include
layout="@layout/part_common_title"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:paddingLeft="20dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingRight="20dp"
>
<TextView
android:id="@+id/add_diary_tv_date"
android:layout_width="match_parent"
android:layout_height="30dp"
android:gravity="center_vertical"
android:paddingRight="5dp"
android:text="2019年06月19日"
android:textSize="15sp"
/>
<EditText
android:id="@+id/add_diary_et_title"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@drawable/shape_add_diary_title"
android:enabled="true"
android:gravity="top"
android:maxLines="10"
android:minLines="8"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:scrollbars="vertical"
android:hint="标题"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="20dp"/>
<com.nice.mydiary.widget.LinedEditText
android:id="@+id/add_diary_et_content"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@drawable/shape_add_diary_title"
android:enabled="true"
android:gravity="top"
android:lineSpacingExtra="5dp"
android:maxLines="10"
android:minLines="8"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="10dp"
android:scrollbars="vertical"
android:textSize="17sp"
android:hint="遇见你,是我的小确幸..."
/>
<!--<HorizontalScrollView
android:id="@+id/bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/white">-->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageButton
android:id="@+id/action_bold"
android:layout_width="40dp"
android:layout_height="40dp"
android:padding="8dp"
android:src="@drawable/font_bold"
android:scaleType="fitXY"
android:background="@color/white"/>
<ImageButton
android:id="@+id/action_italic"
android:layout_width="40dp"
android:layout_height="40dp"
android:padding="8dp"
android:src="@drawable/font_italic"
android:scaleType="fitXY"
android:background="@color/white"/>
<ImageButton
android:id="@+id/action_font_size"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="@color/white"
android:padding="8dp"
android:scaleType="fitXY"
android:src="@drawable/font_size" />
<ImageButton
android:id="@+id/action_underline"
android:layout_width="40dp"
android:layout_height="40dp"
android:padding="8dp"
android:src="@drawable/font_underline"
android:scaleType="fitXY"
android:background="@color/white"/>
<ImageButton
android:id="@+id/action_font_color"
android:layout_width="40dp"
android:layout_height="40dp"
android:padding="8dp"
android:src="@drawable/font_color"
android:scaleType="fitXY"
android:background="@color/white"/>
<ImageButton
android:id="@+id/action_font_background_color"
android:layout_width="40dp"
android:layout_height="40dp"
android:padding="8dp"
android:src="@drawable/font_background_color"
android:scaleType="fitXY"
android:background="@color/white"/>
<ImageButton
android:id="@+id/action_img"
android:layout_width="40dp"
android:layout_height="40dp"
android:padding="8dp"
android:src="@drawable/font_img"
android:scaleType="fitXY"
android:background="@color/white"/>
</LinearLayout>
<!-- </HorizontalScrollView>-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="95dp">
</LinearLayout>
</LinearLayout>
<cc.trity.floatingactionbutton.FloatingActionsMenu
android:id="@+id/right_labels"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
app:fab_expandDirection="right"
app:fab_colorNormal="#f0f01a"
app:fab_icon = "@drawable/menu"
app:fab_addButtonSize="mini"
>
<cc.trity.floatingactionbutton.FloatingActionButton
android:id="@+id/add_diary_fab_back"
android:layout_width="50dp"
android:layout_height="50dp"
app:fab_colorNormal="#24d63c"
app:fab_size="normal"
app:fab_icon = "@drawable/save_new"
/>
<cc.trity.floatingactionbutton.FloatingActionButton
android:id="@+id/add_diary_fab_add"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/save"
app:fab_size="normal"
app:fab_title="FAB 2"
app:fab_colorNormal="#e41c1c"
app:fab_icon = "@drawable/back_new"
/>
/>
</cc.trity.floatingactionbutton.FloatingActionsMenu>
</RelativeLayout>
</LinearLayout>

@ -0,0 +1,142 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_rl_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="vertical"
android:paddingBottom="10dp"
tools:context=".ui.MainActivity"
>
<LinearLayout
android:id="@+id/main_ll_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@mipmap/sakura"
>
<include
layout="@layout/part_common_title"
/>
<!--<TextView
android:layout_width="match_parent"
android:layout_height="20dp"
android:alpha="0.7"/>-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/item_first"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:orientation="vertical"
android:paddingRight="10dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="25dp"
android:background="#ffffff"
android:orientation="horizontal"
android:paddingLeft="10.8dp"
>
<TextView
android:id="@+id/main_tv_date"
android:layout_width="0dp"
android:layout_height="25dp"
android:layout_weight="1"
android:gravity="center_vertical"
android:paddingLeft="4dp"
android:paddingTop="5dp"
android:text="2017年01月18日"
android:textSize="14sp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<LinearLayout
android:layout_width="23dp"
android:layout_height="match_parent"
android:background="#ffffff"
>
</LinearLayout>
<LinearLayout
android:id="@+id/item_ll_control"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:id="@+id/main_tv_content"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#ffffff"
android:lineSpacingExtra="4dp"
android:paddingLeft="33dp"
android:paddingRight="15dp"
android:paddingTop="5dp"
android:text="今天什么都没有记录...(~ ̄▽ ̄)"
android:textColor="@color/gray"
android:textSize="16sp"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/main_rv_show_diary"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignStart="@+id/main_ll_main"
android:layout_alignBottom="@+id/main_ll_main"
android:background="#ffffff"
android:alpha="0.8">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/main_fab_enter_edit"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="36dp"
android:layout_marginLeft="30dp"
android:layout_marginStart="30dp"
android:src="@drawable/add"
app:backgroundTint="#3A5FCD"
app:borderWidth="0dp"
app:elevation="6dp"
app:fabSize="normal"
app:layout_anchorGravity="bottom|right"
app:pressedTranslationZ="12dp"
app:rippleColor="#a6a6a6"/>
</RelativeLayout>

@ -0,0 +1,34 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="40dp"
android:text="Button 1"
/>
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="40dp"
android:text="Button 2"
/>
<Button
android:id="@+id/button3"
android:layout_width="match_parent"
android:layout_height="40dp"
android:text="Button 3"
/>
<Button
android:id="@+id/button4"
android:layout_width="match_parent"
android:layout_height="40dp"
android:text="Button 4"
/>
</LinearLayout>

@ -0,0 +1,223 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<include
layout="@layout/part_common_title"
/>
<TextView
android:id="@+id/update_diary_tv_tag"
android:layout_width="0.001dp"
android:layout_height="0.001dp"
android:text="sdafaf"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:paddingLeft="20dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingRight="20dp"
>
<TextView
android:id="@+id/update_diary_tv_date"
android:layout_width="match_parent"
android:layout_height="30dp"
android:gravity="center_vertical"
android:paddingRight="5dp"
android:text="2017年01月19日"
android:textSize="15sp"
/>
<EditText
android:id="@+id/update_diary_et_title"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@drawable/shape_add_diary_title"
android:enabled="true"
android:gravity="top"
android:maxLines="10"
android:minLines="8"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:scrollbars="vertical"
android:hint="标题"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="20dp"/>
<com.nice.mydiary.widget.LinedEditText
android:id="@+id/update_diary_et_content"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@drawable/shape_add_diary_title"
android:enabled="true"
android:gravity="top"
android:lineSpacingExtra="5dp"
android:maxLines="10"
android:minLines="8"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="10dp"
android:scrollbars="vertical"
android:textSize="17sp"
android:hint="遇见你,是我的小确幸..."
/>
<HorizontalScrollView
android:id="@+id/bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/white">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageButton
android:id="@+id/action_bold"
android:layout_width="40dp"
android:layout_height="40dp"
android:padding="8dp"
android:src="@drawable/font_bold"
android:scaleType="fitXY"
android:background="@color/white"/>
<ImageButton
android:id="@+id/action_italic"
android:layout_width="40dp"
android:layout_height="40dp"
android:padding="8dp"
android:src="@drawable/font_italic"
android:scaleType="fitXY"
android:background="@color/white"/>
<ImageButton
android:id="@+id/action_font_size"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="@color/white"
android:padding="8dp"
android:scaleType="fitXY"
android:src="@drawable/font_size" />
<ImageButton
android:id="@+id/action_underline"
android:layout_width="40dp"
android:layout_height="40dp"
android:padding="8dp"
android:src="@drawable/font_underline"
android:scaleType="fitXY"
android:background="@color/white"/>
<ImageButton
android:id="@+id/action_font_color"
android:layout_width="40dp"
android:layout_height="40dp"
android:padding="8dp"
android:src="@drawable/font_color"
android:scaleType="fitXY"
android:background="@color/white"/>
<ImageButton
android:id="@+id/action_font_background_color"
android:layout_width="40dp"
android:layout_height="40dp"
android:padding="8dp"
android:src="@drawable/font_background_color"
android:scaleType="fitXY"
android:background="@color/white"/>
<ImageButton
android:id="@+id/action_img"
android:layout_width="40dp"
android:layout_height="40dp"
android:padding="8dp"
android:src="@drawable/font_img"
android:scaleType="fitXY"
android:background="@color/white"/>
</LinearLayout>
</HorizontalScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="95dp">
</LinearLayout>
</LinearLayout>
<cc.trity.floatingactionbutton.FloatingActionsMenu
android:id="@+id/right_labels"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
app:fab_expandDirection="right"
app:fab_addButtonSize="mini"
>
<cc.trity.floatingactionbutton.FloatingActionButton
android:id="@+id/update_diary_fab_back"
android:layout_width="40dp"
android:layout_height="40dp"
app:fab_size="normal"
app:fab_icon = "@drawable/delete_new"
app:fab_colorNormal="#ee0d18"
/>
<cc.trity.floatingactionbutton.FloatingActionButton
android:id="@+id/update_diary_fab_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/save"
app:fab_size="normal"
app:fab_title="FAB 2"
app:fab_icon = "@drawable/save_new"
app:fab_colorNormal="#40a30a"
/>
<cc.trity.floatingactionbutton.FloatingActionButton
android:id="@+id/update_diary_fab_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/delete"
app:fab_colorNormal="#e33e46"
app:fab_icon = "@drawable/back_new"
app:fab_size="normal"
app:fab_title="FAB 2"
/>
</cc.trity.floatingactionbutton.FloatingActionsMenu>
</RelativeLayout>
</LinearLayout>

@ -0,0 +1,82 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/item_first"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingRight="10dp"
android:background="@color/white"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="25dp"
android:orientation="horizontal"
android:paddingLeft="10.8dp"
android:background="#ffffff"
>
<ImageView
android:id="@+id/main_iv_circle"
android:paddingTop="2dp"
android:layout_width="22dp"
android:layout_height="22dp"
android:src="@drawable/circle_orange"
android:layout_gravity="center_vertical"
/>
<TextView
android:id="@+id/main_tv_date"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="25dp"
android:gravity="center_vertical"
android:paddingLeft="4dp"
android:paddingTop="1dp"
android:text="2017年01月18日"
android:textSize="14sp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<LinearLayout
android:layout_width="23dp"
android:layout_height="match_parent"
android:background="@drawable/linear_style"
>
</LinearLayout>
<LinearLayout
android:id="@+id/item_ll_control"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:paddingTop="5dp"
android:background="#ffffff"
android:id="@+id/main_tv_content"
android:layout_width="match_parent"
android:layout_height="50dp"
android:lineSpacingExtra="4dp"
android:paddingLeft="33dp"
android:paddingRight="15dp"
android:text="今天,你什么都没写下..."
android:textColor="@color/gray"
android:textSize="16sp"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>

@ -0,0 +1,157 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/item_ll"
android:layout_width="match_parent"
android:layout_height="160dp"
android:orientation="vertical"
android:paddingRight="10dp"
android:background="@drawable/set_frame"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
>
<LinearLayout
android:layout_width="314dp"
android:layout_height="25dp"
android:background="@drawable/set_frame"
android:orientation="horizontal"
android:paddingLeft="10.8dp"
android:layout_marginLeft="10dp">
<TextView
android:id="@+id/main_tv_date"
android:layout_width="0dp"
android:layout_height="25dp"
android:layout_weight="1"
android:background="#5CACEE"
android:gravity="center_vertical"
android:paddingLeft="4dp"
android:paddingTop="1dp"
android:text="2017年01月18日"
android:textSize="14sp"
android:textColor="#ffffff"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<LinearLayout
android:layout_width="23dp"
android:layout_height="31dp"
android:background="#5CACEE">
</LinearLayout>
<LinearLayout
android:id="@+id/item_ll_control"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<LinearLayout
android:id="@+id/main_ll_title"
android:layout_width="match_parent"
android:layout_height="35dp"
android:orientation="horizontal"
android:background="#ffffff"
>
<TextView
android:paddingTop="3dp"
android:background="#5CACEE"
android:id="@+id/main_tv_title"
android:layout_width="match_parent"
android:layout_height="32dp"
android:gravity="center_vertical"
android:paddingLeft="1dp"
android:text="哈哈哈今天傻逼了"
android:textColor="#ffffff"
android:textSize="19sp"
/>
</LinearLayout>
<TextView
android:paddingTop="2dp"
android:background="#5CACEE"
android:id="@+id/main_tv_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lineSpacingExtra="4dp"
android:paddingLeft="33dp"
android:paddingRight="15dp"
android:text=" 在这里写些什么在这里写些什么在这里写些什么在这里写些什么在这里 "
android:textColor="#ffffff"
android:textSize="16sp"
/>
<RelativeLayout
android:id="@+id/item_rl_edit"
android:layout_width="match_parent"
android:layout_height="40dp"
android:paddingRight="5dp"
android:background="#5CACEE"
>
<ImageView
android:id="@+id/main_iv_edit"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_alignParentRight="true"
android:layout_centerInParent="true"
android:src="@drawable/pen"
/>
</RelativeLayout>
<LinearLayout
android:background="#5CACEE"
android:layout_width="match_parent"
android:layout_height="10dp">
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/common_title_ll"
android:background="#3A5FCD"
android:layout_width="match_parent"
android:layout_height="55dp"
android:orientation="horizontal"
>
<ImageView
android:id="@+id/common_iv_back"
android:paddingLeft="5dp"
android:layout_width="50dp"
android:layout_height="30dp"
android:layout_gravity="center_vertical"
android:src="@drawable/ic_arrow_back_black_24dp"
/>
<TextView
android:id="@+id/common_tv_title"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="记录"
android:textColor="@color/white"
android:layout_gravity="center"
android:gravity="center"
android:textSize="18sp"
android:textStyle="bold"
/>
<ImageView
android:id="@+id/common_iv_test"
android:layout_width="50dp"
android:layout_height="30dp"
/>
</LinearLayout>

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 362 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 626 KiB

@ -0,0 +1,6 @@
<resources>
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
(such as screen margins) for screens with more than 820dp of available width. This
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
<dimen name="activity_horizontal_margin">64dp</dimen>
</resources>

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#5CACEE</color>
<color name="colorPrimaryDark">#5CACEE</color>
<color name="colorAccent">#5CACEE</color>
<color name="gray">#bbafb4</color>
<color name="black">#343232</color>
<color name="black_semi_transparent">#B2000000</color>
<color name="background">#e5e5e5</color>
<color name="half_black">#808080</color>
<color name="white">#fafafa</color>
<color name="white_pressed">#f1f1f1</color>
<color name="pink">#e91e63</color>
<color name="pink_pressed">#ec407a</color>
<color name="blue_semi_transparent">#805677fc</color>
<color name="blue_semi_transparent_pressed">#80738ffe</color>
</resources>

@ -0,0 +1,5 @@
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
</resources>

@ -0,0 +1,3 @@
<resources>
<string name="app_name">Summer Memory</string>
</resources>

@ -0,0 +1,11 @@
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>

@ -0,0 +1,15 @@
package com.nice.mydiary;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* To work on unit tests, switch the Test Artifact in the Build Variants view.
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() throws Exception {
assertEquals(4, 2 + 2);
}
}

@ -0,0 +1,24 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
maven { url 'https://jitpack.io' }
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

@ -0,0 +1,18 @@
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

Binary file not shown.

@ -0,0 +1,6 @@
#Tue May 09 14:01:45 CST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip

160
gradlew vendored

@ -0,0 +1,160 @@
#!/usr/bin/env bash
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn ( ) {
echo "$*"
}
die ( ) {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
esac
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"

90
gradlew.bat vendored

@ -0,0 +1,90 @@
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windowz variants
if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
goto execute
:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

@ -0,0 +1 @@
include ':app'
Loading…
Cancel
Save