├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml └── vcs.xml ├── MaterialPreference ├── MaterialPreference.iml ├── build.gradle └── src │ └── main │ ├── AndroidManifest.xml │ ├── assets │ └── fonts │ │ ├── Roboto-Medium.ttf │ │ └── Roboto-Regular.ttf │ ├── java │ └── com │ │ └── jenzz │ │ └── materialpreference │ │ ├── CheckBoxPreference.java │ │ ├── Preference.java │ │ ├── PreferenceCategory.java │ │ ├── PreferenceImageView.java │ │ ├── SwitchPreference.java │ │ ├── ThemeUtils.java │ │ ├── TwoStatePreference.java │ │ └── Typefaces.java │ └── res │ ├── layout │ ├── mp_checkbox_preference.xml │ ├── mp_preference.xml │ ├── mp_preference_category.xml │ └── mp_switch_preference.xml │ └── values │ └── mp_attrs.xml ├── Notes.iml ├── README.md ├── app ├── .gitignore ├── app.iml ├── build.gradle ├── libs │ ├── BmobSDK_V3.3.8_0521.jar │ ├── fastjson.jar │ └── libammsdk.jar ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── lguipeng │ │ └── notes │ │ └── ApplicationTest.java │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── lguipeng │ │ └── notes │ │ ├── App.java │ │ ├── adpater │ │ ├── BaseListAdapter.java │ │ ├── BaseRecyclerViewAdapter.java │ │ ├── ColorsListAdapter.java │ │ ├── DrawerListAdapter.java │ │ ├── MaterialSimpleListAdapter.java │ │ ├── NotesAdapter.java │ │ ├── NotesItemViewHolder.java │ │ └── SimpleListAdapter.java │ │ ├── listener │ │ ├── bmob │ │ │ ├── FindListenerImpl.java │ │ │ ├── SaveListenerImpl.java │ │ │ └── UpdateListenerImpl.java │ │ └── view │ │ │ └── RecyclerViewClickListener.java │ │ ├── model │ │ ├── CloudNote.java │ │ ├── MaterialSimpleListItem.java │ │ ├── Note.java │ │ ├── NoteOperateLog.java │ │ └── NoteType.java │ │ ├── module │ │ ├── AppModule.java │ │ └── DataModule.java │ │ ├── ui │ │ ├── AboutActivity.java │ │ ├── BaseActivity.java │ │ ├── EditNoteTypeActivity.java │ │ ├── MainActivity.java │ │ ├── NoteActivity.java │ │ ├── PayActivity.java │ │ ├── SettingActivity.java │ │ └── fragments │ │ │ ├── BaseFragment.java │ │ │ └── SettingFragment.java │ │ ├── utils │ │ ├── AccountUtils.java │ │ ├── JsonUtils.java │ │ ├── NoteConfig.java │ │ ├── NotesLog.java │ │ ├── PreferenceUtils.java │ │ ├── SnackbarUtils.java │ │ ├── ThemeUtils.java │ │ ├── TimeUtils.java │ │ ├── ViewHelper.java │ │ └── WXUtils.java │ │ └── view │ │ └── FixedRecyclerView.java │ └── res │ ├── drawable-hdpi │ ├── ic_done_white.png │ └── ic_edit_white.png │ ├── drawable-xhdpi │ ├── alipay_erweima.jpg │ ├── ic_done_white.png │ ├── ic_edit_white.png │ ├── ic_more_grey.png │ ├── ic_share_more.png │ ├── ic_sina_logo.png │ ├── ic_wx_collect.png │ ├── ic_wx_logo.png │ └── ic_wx_moments.png │ ├── drawable-xxhdpi │ ├── ic_done_white.png │ └── ic_edit_white.png │ ├── drawable │ ├── activated_background.xml │ ├── blue_grey_round.xml │ ├── blue_round.xml │ ├── brown_round.xml │ ├── deep_purple_round.xml │ ├── green_round.xml │ ├── pink_round.xml │ ├── red_round.xml │ ├── selectable_background.xml │ ├── toolbar_shadow.xml │ ├── white_button_background.xml │ └── yellow_round.xml │ ├── layout │ ├── activity_about.xml │ ├── activity_edit_note_type.xml │ ├── activity_main.xml │ ├── activity_note.xml │ ├── activity_pay.xml │ ├── activity_setting.xml │ ├── colors_image_layout.xml │ ├── colors_panel_layout.xml │ ├── drawer_list_item_layout.xml │ ├── edit_layout.xml │ ├── md_simplelist_item.xml │ ├── notes_item_layout.xml │ ├── toolbar_layout.xml │ └── toolbar_shadow_layout.xml │ ├── menu │ ├── menu_about.xml │ ├── menu_main.xml │ ├── menu_note.xml │ └── menu_notes_more.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── mipmap-xxxhdpi │ └── ic_launcher.png │ ├── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml │ └── xml │ ├── prefs.xml │ └── searchable.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── orm-library ├── .gitignore ├── build.gradle ├── orm-library.iml ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── lguipeng │ │ └── library │ │ └── ApplicationTest.java │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── net │ │ └── tsz │ │ └── afinal │ │ ├── FinalDb.java │ │ ├── annotation │ │ └── sqlite │ │ │ ├── Id.java │ │ │ ├── ManyToOne.java │ │ │ ├── OneToMany.java │ │ │ ├── Property.java │ │ │ ├── Table.java │ │ │ └── Transient.java │ │ ├── core │ │ ├── AbstractCollection.java │ │ ├── ArrayDeque.java │ │ ├── Arrays.java │ │ ├── AsyncTask.java │ │ ├── Deque.java │ │ ├── FileNameGenerator.java │ │ └── Queue.java │ │ ├── db │ │ ├── sqlite │ │ │ ├── CursorUtils.java │ │ │ ├── DbModel.java │ │ │ ├── ManyToOneLazyLoader.java │ │ │ ├── OneToManyLazyLoader.java │ │ │ ├── SqlBuilder.java │ │ │ └── SqlInfo.java │ │ └── table │ │ │ ├── Id.java │ │ │ ├── KeyValue.java │ │ │ ├── ManyToOne.java │ │ │ ├── OneToMany.java │ │ │ ├── Property.java │ │ │ └── TableInfo.java │ │ ├── exception │ │ ├── AfinalException.java │ │ └── DbException.java │ │ └── utils │ │ ├── ClassUtils.java │ │ ├── FieldUtils.java │ │ └── Utils.java │ └── res │ └── values │ └── strings.xml ├── screenshot ├── S50603-103314.jpg ├── S50605-164248.jpg ├── S50605-164615.jpg ├── S50611-163425.jpg ├── S50611-163752.jpg ├── S50611-164132.jpg └── S50611-164146.jpg └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /local.properties 3 | /.idea/workspace.xml 4 | /.idea/libraries 5 | .DS_Store 6 | /build 7 | /captures 8 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | Notes -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 20 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | 47 | 48 | 49 | 50 | 1.7 51 | 52 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /MaterialPreference/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion Integer.parseInt(ANDROID_BUILD_COMPILE_SDK_VERSION) 5 | buildToolsVersion ANDROID_BUILD_TOOLS_VERSION 6 | 7 | defaultConfig { 8 | minSdkVersion Integer.parseInt(MIN_SDK_VERSION) 9 | targetSdkVersion Integer.parseInt(ANDROID_BUILD_TARGET_SDK_VERSION) 10 | versionCode Integer.parseInt(VERSION_CODE) 11 | versionName VERSION_NAME 12 | } 13 | 14 | lintOptions { 15 | abortOnError false 16 | } 17 | } 18 | 19 | dependencies { 20 | compile 'com.android.support:appcompat-v7:22.2.0' 21 | compile 'com.balysv:material-ripple:1.0.2' 22 | } -------------------------------------------------------------------------------- /MaterialPreference/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /MaterialPreference/src/main/assets/fonts/Roboto-Medium.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daimajia/Notes/0b743136b2080dec363b156b8ebea7c019270c27/MaterialPreference/src/main/assets/fonts/Roboto-Medium.ttf -------------------------------------------------------------------------------- /MaterialPreference/src/main/assets/fonts/Roboto-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daimajia/Notes/0b743136b2080dec363b156b8ebea7c019270c27/MaterialPreference/src/main/assets/fonts/Roboto-Regular.ttf -------------------------------------------------------------------------------- /MaterialPreference/src/main/java/com/jenzz/materialpreference/CheckBoxPreference.java: -------------------------------------------------------------------------------- 1 | package com.jenzz.materialpreference; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.util.AttributeSet; 6 | import android.view.View; 7 | import android.widget.CheckBox; 8 | 9 | import static com.jenzz.materialpreference.ThemeUtils.isAtLeastL; 10 | 11 | public class CheckBoxPreference extends TwoStatePreference { 12 | 13 | public CheckBoxPreference(Context context) { 14 | super(context); 15 | init(context, null, 0, 0); 16 | } 17 | 18 | public CheckBoxPreference(Context context, AttributeSet attrs) { 19 | super(context, attrs); 20 | init(context, attrs, 0, 0); 21 | } 22 | 23 | public CheckBoxPreference(Context context, AttributeSet attrs, int defStyleAttr) { 24 | super(context, attrs, defStyleAttr); 25 | init(context, attrs, defStyleAttr, 0); 26 | } 27 | 28 | public CheckBoxPreference(Context context, AttributeSet attrs, int defStyleAttr, 29 | int defStyleRes) { 30 | super(context, attrs, defStyleAttr, defStyleRes); 31 | init(context, attrs, defStyleAttr, defStyleRes); 32 | } 33 | 34 | private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 35 | TypedArray typedArray = context.obtainStyledAttributes(attrs, new int[] { 36 | android.R.attr.summaryOn, android.R.attr.summaryOff, android.R.attr.disableDependentsState 37 | }, defStyleAttr, defStyleRes); 38 | 39 | setSummaryOn(typedArray.getString(0)); 40 | setSummaryOff(typedArray.getString(1)); 41 | setDisableDependentsState(typedArray.getBoolean(2, false)); 42 | 43 | typedArray.recycle(); 44 | 45 | setWidgetLayoutResource(R.layout.mp_checkbox_preference); 46 | } 47 | 48 | @Override @SuppressWarnings("deprecation") 49 | protected void onBindView(View view) { 50 | super.onBindView(view); 51 | 52 | CheckBox checkboxView = (CheckBox) view.findViewById(R.id.checkbox); 53 | checkboxView.setChecked(isChecked()); 54 | 55 | if (isAtLeastL()) { 56 | // remove circular background when pressed 57 | checkboxView.setBackgroundDrawable(null); 58 | } 59 | 60 | syncSummaryView(view); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /MaterialPreference/src/main/java/com/jenzz/materialpreference/Preference.java: -------------------------------------------------------------------------------- 1 | package com.jenzz.materialpreference; 2 | 3 | import android.annotation.TargetApi; 4 | import android.content.Context; 5 | import android.content.res.TypedArray; 6 | import android.graphics.drawable.Drawable; 7 | import android.util.AttributeSet; 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | import android.widget.ImageView; 12 | import android.widget.TextView; 13 | 14 | import static android.content.Context.LAYOUT_INFLATER_SERVICE; 15 | import static android.os.Build.VERSION_CODES.LOLLIPOP; 16 | import static android.text.TextUtils.isEmpty; 17 | import static android.view.View.GONE; 18 | import static android.view.View.VISIBLE; 19 | import static com.jenzz.materialpreference.Typefaces.getRobotoRegular; 20 | 21 | public class Preference extends android.preference.Preference { 22 | 23 | TextView titleView; 24 | TextView summaryView; 25 | 26 | ImageView imageView; 27 | View imageFrame; 28 | 29 | private int iconResId; 30 | private Drawable icon; 31 | 32 | public Preference(Context context) { 33 | super(context); 34 | init(context, null, 0, 0); 35 | } 36 | 37 | public Preference(Context context, AttributeSet attrs) { 38 | super(context, attrs); 39 | init(context, attrs, 0, 0); 40 | } 41 | 42 | public Preference(Context context, AttributeSet attrs, int defStyleAttr) { 43 | super(context, attrs, defStyleAttr); 44 | init(context, attrs, defStyleAttr, 0); 45 | } 46 | 47 | @TargetApi(LOLLIPOP) 48 | public Preference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 49 | super(context, attrs, defStyleAttr, defStyleRes); 50 | init(context, attrs, defStyleAttr, defStyleRes); 51 | } 52 | 53 | private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 54 | TypedArray typedArray = 55 | context.obtainStyledAttributes(attrs, new int[] { android.R.attr.icon }, defStyleAttr, 56 | defStyleRes); 57 | iconResId = typedArray.getResourceId(0, 0); 58 | typedArray.recycle(); 59 | } 60 | 61 | @Override 62 | protected View onCreateView(ViewGroup parent) { 63 | LayoutInflater layoutInflater = 64 | (LayoutInflater) getContext().getSystemService(LAYOUT_INFLATER_SERVICE); 65 | View layout = layoutInflater.inflate(R.layout.mp_preference, parent, false); 66 | 67 | ViewGroup widgetFrame = (ViewGroup) layout.findViewById(R.id.widget_frame); 68 | int widgetLayoutResId = getWidgetLayoutResource(); 69 | if (widgetLayoutResId != 0) { 70 | layoutInflater.inflate(widgetLayoutResId, widgetFrame); 71 | } 72 | widgetFrame.setVisibility(widgetLayoutResId != 0 ? VISIBLE : GONE); 73 | 74 | return layout; 75 | } 76 | 77 | @Override 78 | protected void onBindView(View view) { 79 | super.onBindView(view); 80 | 81 | CharSequence title = getTitle(); 82 | titleView = (TextView) view.findViewById(R.id.title); 83 | titleView.setText(title); 84 | titleView.setVisibility(!isEmpty(title) ? VISIBLE : GONE); 85 | titleView.setTypeface(getRobotoRegular(getContext())); 86 | 87 | CharSequence summary = getSummary(); 88 | summaryView = (TextView) view.findViewById(R.id.summary); 89 | summaryView.setText(summary); 90 | summaryView.setVisibility(!isEmpty(summary) ? VISIBLE : GONE); 91 | summaryView.setTypeface(getRobotoRegular(getContext())); 92 | 93 | if (icon == null && iconResId > 0) { 94 | icon = getContext().getResources().getDrawable(iconResId); 95 | } 96 | imageView = (ImageView) view.findViewById(R.id.icon); 97 | imageView.setImageDrawable(icon); 98 | imageView.setVisibility(icon != null ? VISIBLE : GONE); 99 | 100 | imageFrame = view.findViewById(R.id.icon_frame); 101 | imageFrame.setVisibility(icon != null ? VISIBLE : GONE); 102 | } 103 | 104 | @Override 105 | public void setIcon(int iconResId) { 106 | super.setIcon(iconResId); 107 | this.iconResId = iconResId; 108 | } 109 | 110 | @Override 111 | public void setIcon(Drawable icon) { 112 | super.setIcon(icon); 113 | this.icon = icon; 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /MaterialPreference/src/main/java/com/jenzz/materialpreference/PreferenceCategory.java: -------------------------------------------------------------------------------- 1 | package com.jenzz.materialpreference; 2 | 3 | import android.annotation.TargetApi; 4 | import android.content.Context; 5 | import android.util.AttributeSet; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.TextView; 10 | 11 | import static android.content.Context.LAYOUT_INFLATER_SERVICE; 12 | import static android.os.Build.VERSION_CODES.LOLLIPOP; 13 | import static android.text.TextUtils.isEmpty; 14 | import static android.view.View.GONE; 15 | import static android.view.View.VISIBLE; 16 | import static com.jenzz.materialpreference.ThemeUtils.resolveAccentColor; 17 | import static com.jenzz.materialpreference.Typefaces.getRobotoMedium; 18 | 19 | public class PreferenceCategory extends android.preference.PreferenceCategory { 20 | 21 | private int accentColor; 22 | 23 | public PreferenceCategory(Context context) { 24 | super(context); 25 | init(); 26 | } 27 | 28 | public PreferenceCategory(Context context, AttributeSet attrs) { 29 | super(context, attrs); 30 | init(); 31 | } 32 | 33 | public PreferenceCategory(Context context, AttributeSet attrs, int defStyleAttr) { 34 | super(context, attrs, defStyleAttr); 35 | init(); 36 | } 37 | 38 | @TargetApi(LOLLIPOP) 39 | public PreferenceCategory(Context context, AttributeSet attrs, int defStyleAttr, 40 | int defStyleRes) { 41 | super(context, attrs, defStyleAttr, defStyleRes); 42 | init(); 43 | } 44 | 45 | private void init() { 46 | accentColor = resolveAccentColor(getContext()); 47 | } 48 | 49 | @Override 50 | protected View onCreateView(ViewGroup parent) { 51 | LayoutInflater layoutInflater = 52 | (LayoutInflater) getContext().getSystemService(LAYOUT_INFLATER_SERVICE); 53 | return layoutInflater.inflate(R.layout.mp_preference_category, parent, false); 54 | } 55 | 56 | @Override 57 | protected void onBindView(View view) { 58 | super.onBindView(view); 59 | 60 | CharSequence title = getTitle(); 61 | TextView titleView = (TextView) view.findViewById(R.id.title); 62 | titleView.setText(title); 63 | titleView.setTextColor(accentColor); 64 | titleView.setVisibility(!isEmpty(title) ? VISIBLE : GONE); 65 | titleView.setTypeface(getRobotoMedium(getContext())); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /MaterialPreference/src/main/java/com/jenzz/materialpreference/PreferenceImageView.java: -------------------------------------------------------------------------------- 1 | package com.jenzz.materialpreference; 2 | 3 | import android.annotation.TargetApi; 4 | import android.content.Context; 5 | import android.util.AttributeSet; 6 | import android.widget.ImageView; 7 | 8 | import static android.os.Build.VERSION_CODES.LOLLIPOP; 9 | import static android.view.View.MeasureSpec.AT_MOST; 10 | import static android.view.View.MeasureSpec.UNSPECIFIED; 11 | import static android.view.View.MeasureSpec.getMode; 12 | import static android.view.View.MeasureSpec.getSize; 13 | import static android.view.View.MeasureSpec.makeMeasureSpec; 14 | import static java.lang.Integer.MAX_VALUE; 15 | 16 | /** 17 | * Extension of ImageView that correctly applies maxWidth and maxHeight. 18 | */ 19 | public class PreferenceImageView extends ImageView { 20 | 21 | private int maxWidth = MAX_VALUE; 22 | private int maxHeight = MAX_VALUE; 23 | 24 | public PreferenceImageView(Context context) { 25 | super(context); 26 | } 27 | 28 | public PreferenceImageView(Context context, AttributeSet attrs) { 29 | super(context, attrs); 30 | } 31 | 32 | public PreferenceImageView(Context context, AttributeSet attrs, int defStyleAttr) { 33 | super(context, attrs, defStyleAttr); 34 | } 35 | 36 | @TargetApi(LOLLIPOP) 37 | public PreferenceImageView(Context context, AttributeSet attrs, int defStyleAttr, 38 | int defStyleRes) { 39 | super(context, attrs, defStyleAttr, defStyleRes); 40 | } 41 | 42 | @Override 43 | public void setMaxWidth(int maxWidth) { 44 | super.setMaxWidth(maxWidth); 45 | this.maxWidth = maxWidth; 46 | } 47 | 48 | @Override 49 | public void setMaxHeight(int maxHeight) { 50 | super.setMaxHeight(maxHeight); 51 | this.maxHeight = maxHeight; 52 | } 53 | 54 | @Override 55 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 56 | int widthMode = getMode(widthMeasureSpec); 57 | if (widthMode == AT_MOST || widthMode == UNSPECIFIED) { 58 | int widthSize = getSize(widthMeasureSpec); 59 | if (maxWidth != MAX_VALUE && (maxWidth < widthSize || widthMode == UNSPECIFIED)) { 60 | widthMeasureSpec = makeMeasureSpec(maxWidth, AT_MOST); 61 | } 62 | } 63 | 64 | int heightMode = getMode(heightMeasureSpec); 65 | if (heightMode == AT_MOST || heightMode == UNSPECIFIED) { 66 | int heightSize = getSize(heightMeasureSpec); 67 | if (maxHeight != MAX_VALUE && (maxHeight < heightSize || heightMode == UNSPECIFIED)) { 68 | heightMeasureSpec = makeMeasureSpec(maxHeight, AT_MOST); 69 | } 70 | } 71 | 72 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 73 | } 74 | } -------------------------------------------------------------------------------- /MaterialPreference/src/main/java/com/jenzz/materialpreference/SwitchPreference.java: -------------------------------------------------------------------------------- 1 | package com.jenzz.materialpreference; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.support.v7.widget.SwitchCompat; 6 | import android.util.AttributeSet; 7 | import android.view.View; 8 | 9 | public class SwitchPreference extends TwoStatePreference { 10 | 11 | public SwitchPreference(Context context) { 12 | super(context); 13 | init(context, null, 0, 0); 14 | } 15 | 16 | public SwitchPreference(Context context, AttributeSet attrs) { 17 | super(context, attrs); 18 | init(context, attrs, 0, 0); 19 | } 20 | 21 | public SwitchPreference(Context context, AttributeSet attrs, int defStyleAttr) { 22 | super(context, attrs, defStyleAttr); 23 | init(context, attrs, defStyleAttr, 0); 24 | } 25 | 26 | public SwitchPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 27 | super(context, attrs, defStyleAttr, defStyleRes); 28 | init(context, attrs, defStyleAttr, defStyleRes); 29 | } 30 | 31 | private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 32 | TypedArray typedArray = context.obtainStyledAttributes(attrs, new int[] { 33 | android.R.attr.summaryOn, android.R.attr.summaryOff, android.R.attr.disableDependentsState 34 | }, defStyleAttr, defStyleRes); 35 | 36 | setSummaryOn(typedArray.getString(0)); 37 | setSummaryOff(typedArray.getString(1)); 38 | setDisableDependentsState(typedArray.getBoolean(2, false)); 39 | 40 | typedArray.recycle(); 41 | 42 | setWidgetLayoutResource(R.layout.mp_switch_preference); 43 | } 44 | 45 | @Override 46 | protected void onBindView(View view) { 47 | super.onBindView(view); 48 | 49 | SwitchCompat switchCompat = (SwitchCompat) view.findViewById(R.id.switch_compat); 50 | switchCompat.setChecked(isChecked()); 51 | 52 | syncSummaryView(view); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /MaterialPreference/src/main/java/com/jenzz/materialpreference/ThemeUtils.java: -------------------------------------------------------------------------------- 1 | package com.jenzz.materialpreference; 2 | 3 | import android.annotation.TargetApi; 4 | import android.content.Context; 5 | import android.content.res.Resources.Theme; 6 | import android.content.res.TypedArray; 7 | 8 | import static android.graphics.Color.parseColor; 9 | import static android.os.Build.VERSION.SDK_INT; 10 | import static android.os.Build.VERSION_CODES.LOLLIPOP; 11 | 12 | final class ThemeUtils { 13 | 14 | // material_deep_teal_500 15 | static final int FALLBACK_COLOR = parseColor("#009688"); 16 | 17 | private ThemeUtils() { 18 | // no instances 19 | } 20 | 21 | static boolean isAtLeastL() { 22 | return SDK_INT >= LOLLIPOP; 23 | } 24 | 25 | @TargetApi(LOLLIPOP) 26 | static int resolveAccentColor(Context context) { 27 | Theme theme = context.getTheme(); 28 | 29 | // on Lollipop, grab system colorAccent attribute 30 | // pre-Lollipop, grab AppCompat colorAccent attribute 31 | // finally, check for custom mp_colorAccent attribute 32 | int attr = isAtLeastL() ? android.R.attr.colorAccent : R.attr.colorAccent; 33 | TypedArray typedArray = theme.obtainStyledAttributes(new int[] { attr, R.attr.mp_colorAccent }); 34 | 35 | int accentColor = typedArray.getColor(0, FALLBACK_COLOR); 36 | accentColor = typedArray.getColor(1, accentColor); 37 | typedArray.recycle(); 38 | 39 | return accentColor; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /MaterialPreference/src/main/java/com/jenzz/materialpreference/Typefaces.java: -------------------------------------------------------------------------------- 1 | package com.jenzz.materialpreference; 2 | 3 | import android.content.Context; 4 | import android.graphics.Typeface; 5 | import android.util.Log; 6 | import java.util.Hashtable; 7 | 8 | final class Typefaces { 9 | 10 | private static final String TAG = Typefaces.class.getSimpleName(); 11 | private static final Hashtable cache = new Hashtable<>(); 12 | 13 | private Typefaces() { 14 | // no instances 15 | } 16 | 17 | static Typeface get(Context context, String assetPath) { 18 | synchronized (cache) { 19 | if (!cache.containsKey(assetPath)) { 20 | try { 21 | Typeface t = Typeface.createFromAsset(context.getAssets(), assetPath); 22 | cache.put(assetPath, t); 23 | } catch (Exception e) { 24 | Log.e(TAG, "Could not get typeface '" + assetPath + "' Error: " + e.getMessage()); 25 | return null; 26 | } 27 | } 28 | return cache.get(assetPath); 29 | } 30 | } 31 | 32 | static Typeface getRobotoRegular(Context context) { 33 | return get(context, "fonts/Roboto-Regular.ttf"); 34 | } 35 | 36 | static Typeface getRobotoMedium(Context context) { 37 | return get(context, "fonts/Roboto-Medium.ttf"); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /MaterialPreference/src/main/res/layout/mp_checkbox_preference.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /MaterialPreference/src/main/res/layout/mp_preference.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 18 | 30 | 37 | 38 | 39 | 46 | 47 | 56 | 57 | 67 | 68 | 69 | 70 | 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /MaterialPreference/src/main/res/layout/mp_preference_category.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /MaterialPreference/src/main/res/layout/mp_switch_preference.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /MaterialPreference/src/main/res/values/mp_attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | -------------------------------------------------------------------------------- /Notes.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #ScreenShot 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | #1.1.2 14 | - 增加了多款彩色主题的选择 15 | - 增加了关于界面的分享功能 16 | - 修复了笔记过长的显示问题 17 | - 修复了SwipeRefreshLayout和RecyclerView的组合问题 18 | - 优化界面的一些细节,修复已知的小bug 19 | 20 | #1.1.0 21 | - 增加了笔记列表的卡片式的布局,可在设置里面切换 22 | - 增加了下拉同步笔记的组件 23 | - 增加编辑笔记时点击返回询问是否保存 24 | - 使用了Snackbar代替了Toast的提示 25 | - 去除了编辑笔记内容的下划线 26 | - 修改了笔记列表的显示时间方式 27 | - 修复了小米2s 5.0上CardView的显示问题 28 | 29 | #1.0.2 30 | - Material Design风格,采用抽屉式菜单,悬浮滑动按钮,点击控件时的水波纹效果,状态栏透明使得与应用融为一体,用户即使在Android L系统以下的手机也能感受到良好的用户体验 31 | - 用文字记录身边随时发生的事情,或者你的待办事项 32 | - 同步,同步需要你在手机设置里面添加一个邮箱,并作为你的同步账号,提交到服务器 33 | 34 | #License 35 | ``` 36 | Copyright 2015 Liaoguipeng 37 | 38 | Licensed under the Apache License, Version 2.0 (the "License"); 39 | you may not use this file except in compliance with the License. 40 | You may obtain a copy of the License at 41 | 42 | http://www.apache.org/licenses/LICENSE-2.0 43 | 44 | Unless required by applicable law or agreed to in writing, software 45 | distributed under the License is distributed on an "AS IS" BASIS, 46 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 47 | See the License for the specific language governing permissions and 48 | limitations under the License. 49 | ``` 50 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | def packTime() { 3 | return new Date().format("yyyyMMddHHmm", TimeZone.getTimeZone("UTC")) 4 | } 5 | 6 | def projectUrl = "https://github.com/lguipeng/Notes" 7 | def blogUrl = "http://www.jianshu.com/users/f612d54d668e/latest_articles" 8 | def appDownloadUrl = "http://notes.55058a091d225.d01.nanoyun.com/release/notes.apk" 9 | def aboutAppUrl = "http://www.jianshu.com/p/640a7f2fe0c5" 10 | 11 | //remember to add your bmob app key in local.properties 12 | Properties properties = new Properties() 13 | properties.load(project.rootProject.file('local.properties').newDataInputStream()) 14 | def bmobAppKey = properties.getProperty('BMOB_KEY') 15 | def weChatId = properties.getProperty('WECHAT_ID') 16 | android { 17 | signingConfigs { 18 | debug { 19 | 20 | } 21 | release { 22 | //setting your signing.properties 23 | //first, add signing.properties to ./app/ 24 | //second, add property STORE_FILE, STORE_PASSWORD, KEY_ALIAS, KEY_PASSWORD 25 | } 26 | } 27 | compileSdkVersion Integer.parseInt(ANDROID_BUILD_COMPILE_SDK_VERSION) 28 | buildToolsVersion ANDROID_BUILD_TOOLS_VERSION 29 | defaultConfig { 30 | applicationId "com.lguipeng.notes" 31 | minSdkVersion Integer.parseInt(MIN_SDK_VERSION) 32 | targetSdkVersion Integer.parseInt(ANDROID_BUILD_TARGET_SDK_VERSION) 33 | versionCode Integer.parseInt(VERSION_CODE) 34 | versionName VERSION_NAME 35 | 36 | buildConfigField "String", "BMOB_KEY", "\"${bmobAppKey}\"" 37 | buildConfigField "String", "WECHAT_ID", "\"${weChatId}\"" 38 | buildConfigField "String", "APP_DOWNLOAD_URL", "\"${appDownloadUrl}\"" 39 | buildConfigField "String", "PROJECT_URL", "\"${projectUrl}\"" 40 | buildConfigField "String", "BLOG_URL", "\"${blogUrl}\"" 41 | buildConfigField "String", "ABOUT_APP_URL", "\"${aboutAppUrl}\"" 42 | } 43 | buildTypes { 44 | 45 | debug { 46 | versionNameSuffix " Beta" 47 | minifyEnabled false 48 | zipAlignEnabled false 49 | shrinkResources false 50 | signingConfig signingConfigs.debug 51 | } 52 | release { 53 | minifyEnabled false 54 | zipAlignEnabled false 55 | shrinkResources true 56 | signingConfig signingConfigs.release 57 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 58 | } 59 | } 60 | packagingOptions { 61 | exclude 'META-INF/LICENSE.txt' 62 | exclude 'META-INF/NOTICE.txt' 63 | } 64 | lintOptions { 65 | abortOnError false 66 | } 67 | 68 | applicationVariants.all { variant -> 69 | variant.outputs.each { output -> 70 | def outputFile = output.outputFile 71 | if (outputFile != null && outputFile.name.endsWith('.apk')) { 72 | File outputDirectory = new File(outputFile.parent); 73 | def fileName 74 | if (variant.buildType.name == "release") { 75 | fileName = "notes_v${defaultConfig.versionName}_${packTime()}.apk" 76 | }else{ 77 | fileName = "notes_beta.apk" 78 | } 79 | output.outputFile = new File(outputDirectory, fileName) 80 | } 81 | } 82 | 83 | } 84 | } 85 | 86 | dependencies { 87 | compile fileTree(include: ['*.jar'], dir: 'libs') 88 | compile 'com.android.support:support-v4:22.2.0' 89 | compile 'com.android.support:appcompat-v7:22.2.0' 90 | compile 'com.android.support:recyclerview-v7:22.2.0' 91 | compile 'com.android.support:cardview-v7:22.2.0' 92 | compile 'com.jakewharton:butterknife:6.1.0' 93 | compile 'com.readystatesoftware.systembartint:systembartint:1.0.3' 94 | compile 'com.melnykov:floatingactionbutton:1.3.0' 95 | compile 'com.rengwuxian.materialedittext:library:2.1.3' 96 | compile 'com.squareup.dagger:dagger:1.2.2' 97 | provided 'com.squareup.dagger:dagger-compiler:1.2.2' 98 | compile 'de.greenrobot:eventbus:2.4.0' 99 | compile 'com.pnikosis:materialish-progress:1.5' 100 | compile 'com.nispok:snackbar:2.10.10' 101 | compile project(':orm-library') 102 | compile project(':MaterialPreference') 103 | } 104 | 105 | File propFile = file('signing.properties'); 106 | if (propFile.exists()) { 107 | def Properties props = new Properties() 108 | props.load(new FileInputStream(propFile)) 109 | if (props.containsKey('STORE_FILE') && props.containsKey('STORE_PASSWORD') && 110 | props.containsKey('KEY_ALIAS') && props.containsKey('KEY_PASSWORD')) { 111 | android.signingConfigs.release.storeFile = file(props['STORE_FILE']) 112 | android.signingConfigs.release.storePassword = props['STORE_PASSWORD'] 113 | android.signingConfigs.release.keyAlias = props['KEY_ALIAS'] 114 | android.signingConfigs.release.keyPassword = props['KEY_PASSWORD'] 115 | } else { 116 | android.buildTypes.release.signingConfig = null 117 | } 118 | } else { 119 | android.buildTypes.release.signingConfig = null 120 | } -------------------------------------------------------------------------------- /app/libs/BmobSDK_V3.3.8_0521.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daimajia/Notes/0b743136b2080dec363b156b8ebea7c019270c27/app/libs/BmobSDK_V3.3.8_0521.jar -------------------------------------------------------------------------------- /app/libs/fastjson.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daimajia/Notes/0b743136b2080dec363b156b8ebea7c019270c27/app/libs/fastjson.jar -------------------------------------------------------------------------------- /app/libs/libammsdk.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daimajia/Notes/0b743136b2080dec363b156b8ebea7c019270c27/app/libs/libammsdk.jar -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in E:\adt-bundle-windows-x86_64-20131030/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/lguipeng/notes/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.lguipeng.notes; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 14 | 15 | 19 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 34 | 35 | 36 | 41 | 42 | 43 | 47 | 48 | 49 | 53 | 54 | 55 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /app/src/main/java/com/lguipeng/notes/App.java: -------------------------------------------------------------------------------- 1 | package com.lguipeng.notes; 2 | 3 | import android.app.Application; 4 | 5 | import com.lguipeng.notes.module.AppModule; 6 | 7 | import java.util.Arrays; 8 | import java.util.List; 9 | 10 | import cn.bmob.v3.Bmob; 11 | import dagger.ObjectGraph; 12 | 13 | /** 14 | * Created by lgp on 2015/5/24. 15 | */ 16 | public class App extends Application{ 17 | private ObjectGraph objectGraph; 18 | @Override 19 | public void onCreate() { 20 | super.onCreate(); 21 | objectGraph = ObjectGraph.create(getModules().toArray()); 22 | objectGraph.inject(this); 23 | Bmob.initialize(this, BuildConfig.BMOB_KEY); 24 | } 25 | 26 | @Override 27 | public void onTerminate() { 28 | super.onTerminate(); 29 | } 30 | 31 | @Override 32 | public void onLowMemory() { 33 | super.onLowMemory(); 34 | } 35 | 36 | private List getModules() { 37 | return Arrays.asList(new AppModule(this)); 38 | } 39 | 40 | public ObjectGraph createScopedGraph(Object... modules) { 41 | return objectGraph.plus(modules); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /app/src/main/java/com/lguipeng/notes/adpater/BaseListAdapter.java: -------------------------------------------------------------------------------- 1 | package com.lguipeng.notes.adpater; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.content.Context; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.View.OnClickListener; 8 | import android.view.ViewGroup; 9 | import android.widget.BaseAdapter; 10 | 11 | import java.util.HashMap; 12 | import java.util.List; 13 | import java.util.Map; 14 | 15 | 16 | @SuppressLint("UseSparseArrays") 17 | public abstract class BaseListAdapter extends BaseAdapter { 18 | 19 | public List list; 20 | 21 | public Context mContext; 22 | 23 | public LayoutInflater mInflater; 24 | 25 | public List getList() { 26 | return list; 27 | } 28 | 29 | public void setList(List list) { 30 | this.list = list; 31 | notifyDataSetChanged(); 32 | } 33 | 34 | public void add(E e) { 35 | this.list.add(e); 36 | notifyDataSetChanged(); 37 | } 38 | 39 | public void addAll(List list) { 40 | this.list.addAll(list); 41 | notifyDataSetChanged(); 42 | } 43 | 44 | public void remove(int position) { 45 | this.list.remove(position); 46 | notifyDataSetChanged(); 47 | } 48 | 49 | public BaseListAdapter(Context context, List list) { 50 | super(); 51 | this.mContext = context; 52 | this.list = list; 53 | mInflater = LayoutInflater.from(context); 54 | } 55 | 56 | @Override 57 | public int getCount() { 58 | return list.size(); 59 | } 60 | 61 | @Override 62 | public E getItem(int position) { 63 | return list.get(position); 64 | } 65 | 66 | @Override 67 | public long getItemId(int position) { 68 | return position; 69 | } 70 | 71 | public View getView(int position, View convertView, ViewGroup parent) { 72 | convertView = bindView(position, convertView, parent); 73 | addInternalClickListener(convertView, position, list.get(position)); 74 | return convertView; 75 | } 76 | 77 | public abstract View bindView(int position, View convertView, 78 | ViewGroup parent); 79 | 80 | public Map> canClickItem; 81 | 82 | private void addInternalClickListener(final View itemV, final Integer position, final E valuesMap) { 83 | if (canClickItem != null) { 84 | for (Integer key : canClickItem.keySet()) { 85 | View inView = itemV.findViewById(key); 86 | final onInternalClickListener listener = canClickItem.get(key); 87 | if (inView != null && listener != null) { 88 | inView.setOnClickListener(new OnClickListener() { 89 | 90 | public void onClick(View v) { 91 | listener.OnClickListener(itemV, v, position, 92 | valuesMap); 93 | } 94 | }); 95 | inView.setOnLongClickListener(new View.OnLongClickListener() { 96 | @Override 97 | public boolean onLongClick(View v) { 98 | listener.OnLongClickListener(itemV, v, position, 99 | valuesMap); 100 | return true; 101 | } 102 | }); 103 | } 104 | } 105 | } 106 | } 107 | 108 | public void setOnInViewClickListener(Integer key, 109 | onInternalClickListener onClickListener) { 110 | if (canClickItem == null) 111 | canClickItem = new HashMap<>(); 112 | canClickItem.put(key, onClickListener); 113 | } 114 | 115 | public interface onInternalClickListener { 116 | void OnClickListener(View parentV, View v, Integer position, 117 | T values); 118 | void OnLongClickListener(View parentV, View v, Integer position, 119 | T values); 120 | } 121 | 122 | public static class onInternalClickListenerImpl implements onInternalClickListener{ 123 | @Override 124 | public void OnClickListener(View parentV, View v, Integer position, T values) { 125 | 126 | } 127 | 128 | @Override 129 | public void OnLongClickListener(View parentV, View v, Integer position, T values) { 130 | 131 | } 132 | } 133 | 134 | } 135 | -------------------------------------------------------------------------------- /app/src/main/java/com/lguipeng/notes/adpater/BaseRecyclerViewAdapter.java: -------------------------------------------------------------------------------- 1 | package com.lguipeng.notes.adpater; 2 | 3 | import android.animation.Animator; 4 | import android.content.Context; 5 | import android.support.v7.widget.RecyclerView; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.view.animation.Interpolator; 9 | import android.view.animation.LinearInterpolator; 10 | 11 | import com.lguipeng.notes.utils.ViewHelper; 12 | 13 | import java.util.HashMap; 14 | import java.util.List; 15 | import java.util.Map; 16 | 17 | /** 18 | * Created by lgp on 2015/5/24. 19 | */ 20 | public abstract class BaseRecyclerViewAdapter extends RecyclerView.Adapter{ 21 | 22 | protected Context mContext; 23 | 24 | private int mDuration = 300; 25 | 26 | private Interpolator mInterpolator = new LinearInterpolator(); 27 | 28 | private int mLastPosition = -1; 29 | 30 | private boolean isFirstOnly = true; 31 | 32 | protected List list; 33 | private Map> canClickItem; 34 | public BaseRecyclerViewAdapter(List list) { 35 | this(list, null); 36 | } 37 | 38 | public BaseRecyclerViewAdapter(List list, Context context) { 39 | this.list = list; 40 | this.mContext = context; 41 | } 42 | 43 | public void add(E e) { 44 | this.list.add(0, e); 45 | notifyItemInserted(0); 46 | } 47 | 48 | public void remove(E e) { 49 | this.list.remove(e); 50 | notifyDataSetChanged(); 51 | } 52 | 53 | public void remove(int position) { 54 | this.list.remove(position); 55 | notifyDataSetChanged(); 56 | } 57 | 58 | 59 | public void setList(List list) { 60 | this.list.clear(); 61 | this.list.addAll(list); 62 | notifyDataSetChanged(); 63 | } 64 | 65 | public List getList() { 66 | return list; 67 | } 68 | 69 | @Override 70 | public int getItemCount() { 71 | return list.size(); 72 | } 73 | 74 | @Override 75 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 76 | return null; 77 | } 78 | 79 | @Override 80 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { 81 | if (holder != null){ 82 | addInternalClickListener(holder.itemView, position, list.get(position)); 83 | } 84 | } 85 | 86 | @Override 87 | public int getItemViewType(int position) { 88 | return 1; 89 | } 90 | 91 | private void addInternalClickListener(final View itemV, final Integer position, final E valuesMap) { 92 | if (canClickItem != null) { 93 | for (Integer key : canClickItem.keySet()) { 94 | View inView = itemV.findViewById(key); 95 | final onInternalClickListener listener = canClickItem.get(key); 96 | if (inView != null && listener != null) { 97 | inView.setOnClickListener(new View.OnClickListener() { 98 | public void onClick(View v) { 99 | listener.OnClickListener(itemV, v, position, 100 | valuesMap); 101 | 102 | } 103 | }); 104 | inView.setOnLongClickListener(new View.OnLongClickListener() { 105 | @Override 106 | public boolean onLongClick(View v) { 107 | listener.OnLongClickListener(itemV, v, position, 108 | valuesMap); 109 | return true; 110 | } 111 | }); 112 | } 113 | } 114 | } 115 | } 116 | 117 | public void setOnInViewClickListener(Integer key, onInternalClickListener onClickListener) { 118 | if (canClickItem == null) 119 | canClickItem = new HashMap<>(); 120 | canClickItem.put(key, onClickListener); 121 | } 122 | 123 | public interface onInternalClickListener { 124 | void OnClickListener(View parentV, View v, Integer position, 125 | T values); 126 | void OnLongClickListener(View parentV, View v, Integer position, 127 | T values); 128 | } 129 | 130 | public static class onInternalClickListenerImpl implements onInternalClickListener{ 131 | @Override 132 | public void OnClickListener(View parentV, View v, Integer position, T values) { 133 | 134 | } 135 | 136 | @Override 137 | public void OnLongClickListener(View parentV, View v, Integer position, T values) { 138 | 139 | } 140 | } 141 | 142 | public void setDuration(int duration) { 143 | mDuration = duration; 144 | } 145 | 146 | public void setInterpolator(Interpolator interpolator) { 147 | mInterpolator = interpolator; 148 | } 149 | 150 | public void setStartPosition(int start) { 151 | mLastPosition = start; 152 | } 153 | 154 | public void setFirstOnly(boolean firstOnly) { 155 | isFirstOnly = firstOnly; 156 | } 157 | 158 | protected void animate(RecyclerView.ViewHolder holder, int position){ 159 | if (!isFirstOnly || position > mLastPosition) { 160 | for (Animator anim : getAnimators(holder.itemView)) { 161 | anim.setDuration(mDuration).start(); 162 | anim.setInterpolator(mInterpolator); 163 | 164 | } 165 | mLastPosition = position; 166 | } else { 167 | ViewHelper.clear(holder.itemView); 168 | } 169 | } 170 | 171 | protected abstract Animator[] getAnimators(View view); 172 | } 173 | -------------------------------------------------------------------------------- /app/src/main/java/com/lguipeng/notes/adpater/ColorsListAdapter.java: -------------------------------------------------------------------------------- 1 | package com.lguipeng.notes.adpater; 2 | 3 | import android.content.Context; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.ImageView; 8 | 9 | import com.lguipeng.notes.R; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | * Created by lgp on 2015/6/7. 15 | */ 16 | public class ColorsListAdapter extends BaseListAdapter{ 17 | 18 | private int checkItem; 19 | 20 | public ColorsListAdapter(Context context, List list) { 21 | super(context, list); 22 | } 23 | 24 | @Override 25 | public View bindView(int position, View convertView, ViewGroup parent) { 26 | Holder holder; 27 | if (convertView == null){ 28 | convertView = LayoutInflater.from(mContext).inflate(R.layout.colors_image_layout, null); 29 | holder = new Holder(); 30 | holder.imageView1 = (ImageView)convertView.findViewById(R.id.img_1); 31 | holder.imageView2 = (ImageView)convertView.findViewById(R.id.img_2); 32 | convertView.setTag(holder); 33 | }else{ 34 | holder = (Holder)convertView.getTag(); 35 | } 36 | holder.imageView1.setImageResource(list.get(position)); 37 | if (checkItem == position){ 38 | holder.imageView2.setImageResource(R.drawable.ic_done_white); 39 | } 40 | return convertView; 41 | } 42 | 43 | public int getCheckItem() { 44 | return checkItem; 45 | } 46 | 47 | public void setCheckItem(int checkItem) { 48 | this.checkItem = checkItem; 49 | } 50 | 51 | static class Holder { 52 | ImageView imageView1; 53 | ImageView imageView2; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /app/src/main/java/com/lguipeng/notes/adpater/DrawerListAdapter.java: -------------------------------------------------------------------------------- 1 | package com.lguipeng.notes.adpater; 2 | 3 | import android.content.Context; 4 | 5 | import com.lguipeng.notes.R; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * Created by lgp on 2015/5/24. 11 | */ 12 | public class DrawerListAdapter extends SimpleListAdapter{ 13 | 14 | public DrawerListAdapter(Context mContext, List list) { 15 | super(mContext, list); 16 | } 17 | 18 | @Override 19 | protected int getLayout() { 20 | return R.layout.drawer_list_item_layout; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/lguipeng/notes/adpater/MaterialSimpleListAdapter.java: -------------------------------------------------------------------------------- 1 | package com.lguipeng.notes.adpater; 2 | 3 | import android.content.Context; 4 | import android.view.View; 5 | import android.view.ViewGroup; 6 | import android.widget.ArrayAdapter; 7 | import android.widget.ImageView; 8 | import android.widget.TextView; 9 | 10 | import com.lguipeng.notes.R; 11 | import com.lguipeng.notes.model.MaterialSimpleListItem; 12 | 13 | /** 14 | * Created by lgp on 2015/6/10. 15 | */ 16 | public class MaterialSimpleListAdapter extends ArrayAdapter { 17 | 18 | public MaterialSimpleListAdapter(Context context) { 19 | super(context, R.layout.md_simplelist_item, android.R.id.title); 20 | } 21 | 22 | @Override 23 | public View getView(final int index, View convertView, ViewGroup parent) { 24 | final View view = super.getView(index, convertView, parent); 25 | final MaterialSimpleListItem item = getItem(index); 26 | ImageView ic = (ImageView) view.findViewById(android.R.id.icon); 27 | if (item.getIcon() != null) 28 | ic.setImageDrawable(item.getIcon()); 29 | else 30 | ic.setVisibility(View.GONE); 31 | TextView tv = (TextView) view.findViewById(android.R.id.title); 32 | tv.setText(item.getContent()); 33 | return view; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /app/src/main/java/com/lguipeng/notes/adpater/NotesAdapter.java: -------------------------------------------------------------------------------- 1 | package com.lguipeng.notes.adpater; 2 | 3 | import android.animation.Animator; 4 | import android.animation.ObjectAnimator; 5 | import android.content.Context; 6 | import android.support.v7.widget.RecyclerView; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.widget.Filter; 11 | import android.widget.Filterable; 12 | 13 | import com.lguipeng.notes.R; 14 | import com.lguipeng.notes.model.Note; 15 | import com.lguipeng.notes.utils.TimeUtils; 16 | 17 | import java.util.ArrayList; 18 | import java.util.LinkedList; 19 | import java.util.List; 20 | 21 | /** 22 | * Created by lgp on 2015/4/6. 23 | */ 24 | public class NotesAdapter extends BaseRecyclerViewAdapter implements Filterable{ 25 | private final List originalList; 26 | private int upDownFactor = 1; 27 | private boolean isShowScaleAnimate = true; 28 | public NotesAdapter(List list) { 29 | super(list); 30 | originalList = new ArrayList<>(list); 31 | } 32 | 33 | public NotesAdapter(List list, Context context) { 34 | super(list, context); 35 | originalList = new ArrayList<>(list); 36 | } 37 | 38 | @Override 39 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 40 | Context context = parent.getContext(); 41 | final View view = LayoutInflater.from(context).inflate(R.layout.notes_item_layout, parent, false); 42 | return new NotesItemViewHolder(view); 43 | } 44 | 45 | @Override 46 | public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) { 47 | super.onBindViewHolder(viewHolder, position); 48 | NotesItemViewHolder holder = (NotesItemViewHolder) viewHolder; 49 | Note note = list.get(position); 50 | if (note == null) 51 | return; 52 | holder.setLabelText(note.getLabel()); 53 | holder.setContentText(note.getContent()); 54 | holder.setTimeText(TimeUtils.getConciseTime(note.getLastOprTime(), mContext)); 55 | animate(viewHolder, position); 56 | } 57 | 58 | @Override 59 | public Filter getFilter() { 60 | return new NoteFilter(this, originalList); 61 | } 62 | 63 | @Override 64 | protected Animator[] getAnimators(View view) { 65 | if (view.getMeasuredHeight() <=0 || isShowScaleAnimate){ 66 | ObjectAnimator scaleX = ObjectAnimator.ofFloat(view, "scaleX", 1.1f, 1f); 67 | ObjectAnimator scaleY = ObjectAnimator.ofFloat(view, "scaleY", 1.1f, 1f); 68 | return new ObjectAnimator[]{scaleX, scaleY}; 69 | } 70 | return new Animator[]{ 71 | ObjectAnimator.ofFloat(view, "scaleX", 1.1f, 1f), 72 | ObjectAnimator.ofFloat(view, "scaleY", 1.1f, 1f), 73 | ObjectAnimator.ofFloat(view, "translationY", upDownFactor * 1.5f * view.getMeasuredHeight(), 0) 74 | }; 75 | } 76 | 77 | @Override 78 | public void setList(List list) { 79 | super.setList(list); 80 | this.originalList.clear(); 81 | originalList.addAll(list); 82 | setUpFactor(); 83 | isShowScaleAnimate = true; 84 | } 85 | 86 | public void setDownFactor(){ 87 | upDownFactor = -1; 88 | isShowScaleAnimate = false; 89 | } 90 | 91 | public void setUpFactor(){ 92 | upDownFactor = 1; 93 | isShowScaleAnimate = false; 94 | } 95 | 96 | private static class NoteFilter extends Filter{ 97 | 98 | private final NotesAdapter adapter; 99 | 100 | private final List originalList; 101 | 102 | private final List filteredList; 103 | 104 | private NoteFilter(NotesAdapter adapter, List originalList) { 105 | super(); 106 | this.adapter = adapter; 107 | this.originalList = new LinkedList<>(originalList); 108 | this.filteredList = new ArrayList<>(); 109 | } 110 | 111 | @Override 112 | protected FilterResults performFiltering(CharSequence constraint) { 113 | filteredList.clear(); 114 | final FilterResults results = new FilterResults(); 115 | if (constraint.length() == 0) { 116 | filteredList.addAll(originalList); 117 | } else { 118 | for ( Note note : originalList) { 119 | if (note.getContent().contains(constraint) || note.getLabel().contains(constraint)) { 120 | filteredList.add(note); 121 | } 122 | } 123 | } 124 | results.values = filteredList; 125 | results.count = filteredList.size(); 126 | return results; 127 | } 128 | 129 | @Override 130 | protected void publishResults(CharSequence constraint, FilterResults results) { 131 | adapter.list.clear(); 132 | adapter.list.addAll((ArrayList) results.values); 133 | adapter.notifyDataSetChanged(); 134 | } 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /app/src/main/java/com/lguipeng/notes/adpater/NotesItemViewHolder.java: -------------------------------------------------------------------------------- 1 | package com.lguipeng.notes.adpater; 2 | 3 | import android.support.v7.widget.RecyclerView; 4 | import android.text.TextUtils; 5 | import android.view.View; 6 | import android.widget.TextView; 7 | 8 | import com.lguipeng.notes.R; 9 | 10 | /** 11 | * Created by lgp on 2015/4/6. 12 | */ 13 | public class NotesItemViewHolder extends RecyclerView.ViewHolder{ 14 | 15 | private final TextView mNoteLabelTextView; 16 | private final TextView mNoteContentTextView; 17 | private final TextView mNoteTimeTextView; 18 | public NotesItemViewHolder(View parent) { 19 | super(parent); 20 | mNoteLabelTextView = (TextView) parent.findViewById(R.id.note_label_text); 21 | mNoteContentTextView = (TextView) parent.findViewById(R.id.note_content_text); 22 | mNoteTimeTextView = (TextView) parent.findViewById(R.id.note_last_edit_text); 23 | } 24 | 25 | public void setLabelText(CharSequence text){ 26 | setTextView(mNoteLabelTextView, text); 27 | } 28 | 29 | public void setLabelText(int text){ 30 | setTextView(mNoteLabelTextView, text); 31 | } 32 | 33 | public void setContentText(CharSequence text){ 34 | setTextView(mNoteContentTextView, text); 35 | } 36 | 37 | public void setContentText(int text){ 38 | setTextView(mNoteContentTextView, text); 39 | } 40 | 41 | public void setTimeText(CharSequence text){ 42 | setTextView(mNoteTimeTextView, text); 43 | } 44 | 45 | public void setTimeText(int text){ 46 | setTextView(mNoteTimeTextView, text); 47 | } 48 | 49 | private void setTextView(TextView view, CharSequence text){ 50 | if (view == null || TextUtils.isEmpty(text)) 51 | return; 52 | view.setText(text); 53 | } 54 | 55 | private void setTextView(TextView view, int text){ 56 | if (view == null || text <= 0) 57 | return; 58 | view.setText(text); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /app/src/main/java/com/lguipeng/notes/adpater/SimpleListAdapter.java: -------------------------------------------------------------------------------- 1 | package com.lguipeng.notes.adpater; 2 | 3 | import android.content.Context; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.TextView; 8 | 9 | import com.lguipeng.notes.R; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | * Created by lgp on 2014/8/27. 15 | */ 16 | public abstract class SimpleListAdapter extends BaseListAdapter { 17 | 18 | public SimpleListAdapter(Context mContext, List list) { 19 | super(mContext, list); 20 | } 21 | 22 | @Override 23 | public View bindView(int position, View convertView, ViewGroup parent) { 24 | Holder holder; 25 | if (convertView == null){ 26 | convertView = LayoutInflater.from(mContext).inflate(getLayout(), null); 27 | holder = new Holder(); 28 | holder.textView = (TextView)convertView.findViewById(R.id.textView); 29 | convertView.setTag(holder); 30 | }else{ 31 | holder = (Holder)convertView.getTag(); 32 | } 33 | holder.textView.setText(list.get(position)); 34 | return convertView; 35 | } 36 | 37 | protected abstract int getLayout(); 38 | 39 | static class Holder { 40 | TextView textView; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /app/src/main/java/com/lguipeng/notes/listener/bmob/FindListenerImpl.java: -------------------------------------------------------------------------------- 1 | package com.lguipeng.notes.listener.bmob; 2 | 3 | import com.lguipeng.notes.utils.NotesLog; 4 | 5 | import java.util.List; 6 | 7 | import cn.bmob.v3.listener.FindListener; 8 | 9 | /** 10 | * Created by lgp on 2015/5/30. 11 | */ 12 | public class FindListenerImpl extends FindListener { 13 | @Override 14 | public void onSuccess(List list) { 15 | 16 | } 17 | 18 | @Override 19 | public void onError(int i, String s) { 20 | NotesLog.e(s); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/lguipeng/notes/listener/bmob/SaveListenerImpl.java: -------------------------------------------------------------------------------- 1 | package com.lguipeng.notes.listener.bmob; 2 | 3 | import com.lguipeng.notes.utils.NotesLog; 4 | 5 | import cn.bmob.v3.listener.SaveListener; 6 | 7 | /** 8 | * Created by lgp on 2015/5/30. 9 | */ 10 | public class SaveListenerImpl extends SaveListener { 11 | @Override 12 | public void onSuccess() { 13 | 14 | } 15 | 16 | @Override 17 | public void onFailure(int i, String s) { 18 | NotesLog.e(s); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/lguipeng/notes/listener/bmob/UpdateListenerImpl.java: -------------------------------------------------------------------------------- 1 | package com.lguipeng.notes.listener.bmob; 2 | 3 | import com.lguipeng.notes.utils.NotesLog; 4 | 5 | import cn.bmob.v3.listener.UpdateListener; 6 | 7 | /** 8 | * Created by lgp on 2015/5/30. 9 | */ 10 | public class UpdateListenerImpl extends UpdateListener { 11 | @Override 12 | public void onSuccess() { 13 | 14 | } 15 | 16 | @Override 17 | public void onFailure(int i, String s) { 18 | NotesLog.e(s); 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /app/src/main/java/com/lguipeng/notes/listener/view/RecyclerViewClickListener.java: -------------------------------------------------------------------------------- 1 | package com.lguipeng.notes.listener.view; 2 | 3 | import android.view.View; 4 | 5 | /** 6 | * Interface definition for a callback to be invoked when an item in a 7 | * RecyclerView has been clicked. 8 | */ 9 | public interface RecyclerViewClickListener { 10 | 11 | /** 12 | * Callback method to be invoked when a item in a 13 | * RecyclerView is clicked 14 | * @param v The view within the RecyclerView.Adapter 15 | * @param position The position of the view in the adapter 16 | * @param x 17 | * @param y 18 | */ 19 | void onClick(View v, int position, float x, float y); 20 | } -------------------------------------------------------------------------------- /app/src/main/java/com/lguipeng/notes/model/CloudNote.java: -------------------------------------------------------------------------------- 1 | package com.lguipeng.notes.model; 2 | 3 | import com.lguipeng.notes.utils.JsonUtils; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | import cn.bmob.v3.BmobObject; 9 | 10 | /** 11 | * Created by lgp on 2015/5/28. 12 | */ 13 | public class CloudNote extends BmobObject { 14 | 15 | public CloudNote() { 16 | this("CloudNote"); 17 | } 18 | 19 | public CloudNote(String theClassName) { 20 | super(theClassName); 21 | } 22 | 23 | private String email; 24 | 25 | private List noteList = new ArrayList<>(); 26 | 27 | private String noteType; 28 | 29 | private long version; 30 | 31 | public long getVersion() { 32 | return version; 33 | } 34 | 35 | public void setVersion(long version) { 36 | this.version = version; 37 | } 38 | 39 | public String getNoteType() { 40 | return noteType; 41 | } 42 | 43 | public void setNoteType(String noteType) { 44 | this.noteType = noteType; 45 | } 46 | 47 | public String getEmail() { 48 | return email; 49 | } 50 | 51 | public void setEmail(String email) { 52 | this.email = email; 53 | } 54 | 55 | public List getNoteList() { 56 | return noteList; 57 | } 58 | 59 | public void setNoteList(List noteList) { 60 | this.noteList = noteList; 61 | } 62 | 63 | public void addNote(Note note) { 64 | noteList.add(JsonUtils.jsonNote(note)); 65 | } 66 | 67 | public void clearNotes() { 68 | noteList.clear(); 69 | } 70 | 71 | @Override 72 | public String toString() { 73 | StringBuilder sb = new StringBuilder(); 74 | //sb.append(super.toString()); 75 | //sb.append("\n"); 76 | for (String note : noteList){ 77 | sb.append(note); 78 | sb.append("\n"); 79 | } 80 | return sb.toString(); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /app/src/main/java/com/lguipeng/notes/model/MaterialSimpleListItem.java: -------------------------------------------------------------------------------- 1 | package com.lguipeng.notes.model; 2 | 3 | import android.content.Context; 4 | import android.graphics.drawable.Drawable; 5 | import android.support.annotation.DrawableRes; 6 | import android.support.annotation.StringRes; 7 | import android.support.v4.content.ContextCompat; 8 | 9 | /** 10 | * Created by lgp on 2015/6/10. 11 | */ 12 | public class MaterialSimpleListItem { 13 | 14 | private Builder mBuilder; 15 | 16 | private MaterialSimpleListItem(Builder builder) { 17 | mBuilder = builder; 18 | } 19 | 20 | public Drawable getIcon() { 21 | return mBuilder.mIcon; 22 | } 23 | 24 | public CharSequence getContent() { 25 | return mBuilder.mContent; 26 | } 27 | 28 | public static class Builder { 29 | 30 | private Context mContext; 31 | protected Drawable mIcon; 32 | protected CharSequence mContent; 33 | 34 | public Builder(Context context) { 35 | mContext = context; 36 | } 37 | 38 | public Builder icon(Drawable icon) { 39 | this.mIcon = icon; 40 | return this; 41 | } 42 | 43 | public Builder icon(@DrawableRes int iconRes) { 44 | if (iconRes == 0) 45 | return this; 46 | return icon(ContextCompat.getDrawable(mContext, iconRes)); 47 | } 48 | 49 | public Builder content(CharSequence content) { 50 | this.mContent = content; 51 | return this; 52 | } 53 | 54 | public Builder content(@StringRes int contentRes) { 55 | return content(mContext.getString(contentRes)); 56 | } 57 | 58 | public MaterialSimpleListItem build() { 59 | return new MaterialSimpleListItem(this); 60 | } 61 | } 62 | 63 | @Override 64 | public String toString() { 65 | if (getContent() != null) 66 | return getContent().toString(); 67 | else return "(no content)"; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /app/src/main/java/com/lguipeng/notes/model/Note.java: -------------------------------------------------------------------------------- 1 | package com.lguipeng.notes.model; 2 | 3 | import com.alibaba.fastjson.annotation.JSONField; 4 | import com.lguipeng.notes.utils.JsonUtils; 5 | 6 | import net.tsz.afinal.annotation.sqlite.OneToMany; 7 | import net.tsz.afinal.annotation.sqlite.Table; 8 | import net.tsz.afinal.db.sqlite.OneToManyLazyLoader; 9 | 10 | import java.io.Serializable; 11 | 12 | /** 13 | * Created by lgp on 2015/5/25. 14 | */ 15 | @Table(name = "notes") 16 | public class Note implements Serializable{ 17 | @JSONField(serialize=false, deserialize=false) 18 | private int id; 19 | private int type; 20 | private String label; 21 | private String content; 22 | private long lastOprTime; 23 | @JSONField(serialize=false, deserialize=false) 24 | @OneToMany(manyColumn = "noteId") 25 | private OneToManyLazyLoader logs; 26 | 27 | public int getId() { 28 | return id; 29 | } 30 | 31 | public void setId(int id) { 32 | this.id = id; 33 | } 34 | 35 | public String getLabel() { 36 | return label; 37 | } 38 | 39 | public void setLabel(String label) { 40 | this.label = label; 41 | } 42 | 43 | public String getContent() { 44 | return content; 45 | } 46 | 47 | public void setContent(String content) { 48 | this.content = content; 49 | } 50 | 51 | public long getLastOprTime() { 52 | return lastOprTime; 53 | } 54 | 55 | public void setLastOprTime(long lastOprTime) { 56 | this.lastOprTime = lastOprTime; 57 | } 58 | 59 | public int getType() { 60 | return type; 61 | } 62 | 63 | public void setType(int type) { 64 | this.type = type; 65 | } 66 | 67 | public OneToManyLazyLoader getLogs() { 68 | return logs; 69 | } 70 | 71 | public void setLogs(OneToManyLazyLoader logs) { 72 | this.logs = logs; 73 | } 74 | 75 | @Override 76 | public String toString() { 77 | return JsonUtils.jsonNote(this); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /app/src/main/java/com/lguipeng/notes/model/NoteOperateLog.java: -------------------------------------------------------------------------------- 1 | package com.lguipeng.notes.model; 2 | 3 | import net.tsz.afinal.annotation.sqlite.ManyToOne; 4 | import net.tsz.afinal.annotation.sqlite.Table; 5 | 6 | import java.io.Serializable; 7 | 8 | /** 9 | * Created by lgp on 2015/5/25. 10 | */ 11 | @Table(name = "note_opr_log") 12 | public class NoteOperateLog implements Serializable { 13 | private int id; 14 | private int type; 15 | private long time; 16 | @ManyToOne(column = "noteId") 17 | private Note note; 18 | 19 | public int getId() { 20 | return id; 21 | } 22 | 23 | public void setId(int id) { 24 | this.id = id; 25 | } 26 | 27 | public int getType() { 28 | return type; 29 | } 30 | 31 | public void setType(int type) { 32 | this.type = type; 33 | } 34 | 35 | public long getTime() { 36 | return time; 37 | } 38 | 39 | public void setTime(long time) { 40 | this.time = time; 41 | } 42 | 43 | public Note getNote() { 44 | return note; 45 | } 46 | 47 | public void setNote(Note note) { 48 | this.note = note; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /app/src/main/java/com/lguipeng/notes/model/NoteType.java: -------------------------------------------------------------------------------- 1 | package com.lguipeng.notes.model; 2 | 3 | import android.text.TextUtils; 4 | 5 | import com.alibaba.fastjson.annotation.JSONField; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | /** 11 | * Created by lgp on 2015/6/2. 12 | */ 13 | public class NoteType{ 14 | 15 | @JSONField(serialize=false, deserialize=false) 16 | public final static int ALL_COUNT = 4; 17 | 18 | private List types = new ArrayList<>(); 19 | 20 | public void addType(String type){ 21 | if (types != null && types.size() < ALL_COUNT && !TextUtils.isEmpty(type)){ 22 | types.add(type); 23 | } 24 | } 25 | 26 | public String getType(int location){ 27 | if (types != null && types.size() > location){ 28 | return types.get(location); 29 | } 30 | return ""; 31 | } 32 | 33 | public List getTypes() { 34 | return types; 35 | } 36 | 37 | public void setTypes(List types) { 38 | this.types = types; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /app/src/main/java/com/lguipeng/notes/module/AppModule.java: -------------------------------------------------------------------------------- 1 | package com.lguipeng.notes.module; 2 | 3 | import android.app.Application; 4 | import android.content.Context; 5 | 6 | import com.lguipeng.notes.App; 7 | 8 | import dagger.Module; 9 | import dagger.Provides; 10 | 11 | /** 12 | * Created by lgp on 2015/5/26. 13 | */ 14 | @Module( 15 | injects = { 16 | App.class 17 | }, 18 | library = true 19 | ) 20 | public class AppModule { 21 | private App app; 22 | 23 | public AppModule(App app) { 24 | this.app = app; 25 | } 26 | 27 | @Provides 28 | Application provideApplication() { 29 | return app; 30 | } 31 | 32 | @Provides 33 | Context provideContext() { 34 | return app.getApplicationContext(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /app/src/main/java/com/lguipeng/notes/module/DataModule.java: -------------------------------------------------------------------------------- 1 | package com.lguipeng.notes.module; 2 | 3 | import android.content.Context; 4 | 5 | import com.lguipeng.notes.ui.AboutActivity; 6 | import com.lguipeng.notes.ui.EditNoteTypeActivity; 7 | import com.lguipeng.notes.ui.MainActivity; 8 | import com.lguipeng.notes.ui.NoteActivity; 9 | import com.lguipeng.notes.ui.PayActivity; 10 | import com.lguipeng.notes.ui.SettingActivity; 11 | import com.lguipeng.notes.ui.fragments.SettingFragment; 12 | 13 | import net.tsz.afinal.FinalDb; 14 | 15 | import javax.inject.Singleton; 16 | 17 | import dagger.Module; 18 | import dagger.Provides; 19 | 20 | /** 21 | * Created by lgp on 2015/5/26. 22 | */ 23 | @Module( 24 | injects = { 25 | AboutActivity.class, 26 | MainActivity.class, 27 | NoteActivity.class, 28 | SettingActivity.class, 29 | SettingFragment.class, 30 | PayActivity.class, 31 | EditNoteTypeActivity.class 32 | }, 33 | addsTo = AppModule.class, 34 | library = true 35 | ) 36 | public class DataModule { 37 | 38 | @Provides @Singleton 39 | FinalDb.DaoConfig provideDaoConfig(Context context) { 40 | FinalDb.DaoConfig config = new FinalDb.DaoConfig(); 41 | config.setDbName("notes.db"); 42 | config.setDbVersion(1); 43 | config.setDebug(true); 44 | config.setContext(context); 45 | return config; 46 | } 47 | 48 | @Provides @Singleton 49 | FinalDb provideFinalDb(FinalDb.DaoConfig config) { 50 | return FinalDb.create(config); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /app/src/main/java/com/lguipeng/notes/ui/BaseActivity.java: -------------------------------------------------------------------------------- 1 | package com.lguipeng.notes.ui; 2 | 3 | import android.annotation.TargetApi; 4 | import android.os.Build; 5 | import android.os.Bundle; 6 | import android.support.v7.app.AlertDialog; 7 | import android.support.v7.app.AppCompatActivity; 8 | import android.support.v7.widget.Toolbar; 9 | import android.util.TypedValue; 10 | import android.view.MenuItem; 11 | import android.view.WindowManager; 12 | 13 | import com.lguipeng.notes.App; 14 | import com.lguipeng.notes.R; 15 | import com.lguipeng.notes.utils.PreferenceUtils; 16 | import com.lguipeng.notes.utils.ThemeUtils; 17 | import com.readystatesoftware.systembartint.SystemBarTintManager; 18 | 19 | import java.util.List; 20 | 21 | import butterknife.ButterKnife; 22 | import dagger.ObjectGraph; 23 | 24 | /** 25 | * Created by lgp on 2015/5/24. 26 | */ 27 | public abstract class BaseActivity extends AppCompatActivity { 28 | 29 | private ObjectGraph activityGraph; 30 | 31 | protected PreferenceUtils preferenceUtils; 32 | 33 | @Override 34 | protected void onCreate(Bundle savedInstanceState) { 35 | preferenceUtils = PreferenceUtils.getInstance(this); 36 | initTheme(); 37 | super.onCreate(savedInstanceState); 38 | initWindow(); 39 | activityGraph = ((App) getApplication()).createScopedGraph(getModules().toArray()); 40 | activityGraph.inject(this); 41 | setContentView(getLayoutView()); 42 | ButterKnife.inject(this); 43 | initToolbar(); 44 | } 45 | 46 | private void initTheme(){ 47 | ThemeUtils.Theme theme = getCurrentTheme(); 48 | ThemeUtils.changTheme(this, theme); 49 | } 50 | 51 | protected int getColor(int res){ 52 | if (res <= 0) 53 | throw new IllegalArgumentException("resource id can not be less 0"); 54 | return getResources().getColor(res); 55 | } 56 | 57 | @TargetApi(19) 58 | private void initWindow(){ 59 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){ 60 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); 61 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); 62 | SystemBarTintManager tintManager = new SystemBarTintManager(this); 63 | tintManager.setStatusBarTintColor(getStatusBarColor()); 64 | tintManager.setStatusBarTintEnabled(true); 65 | } 66 | } 67 | 68 | protected void initToolbar(Toolbar toolbar){ 69 | if (toolbar == null) 70 | return; 71 | toolbar.setBackgroundColor(getColorPrimary()); 72 | toolbar.setTitle(R.string.app_name); 73 | toolbar.setTitleTextColor(getColor(R.color.action_bar_title_color)); 74 | toolbar.collapseActionView(); 75 | setSupportActionBar(toolbar); 76 | if (getSupportActionBar() != null){ 77 | getSupportActionBar().setHomeAsUpIndicator(R.drawable.abc_ic_ab_back_mtrl_am_alpha); 78 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 79 | } 80 | } 81 | 82 | public int getStatusBarColor(){ 83 | return getColorPrimary(); 84 | } 85 | 86 | public int getColorPrimary(){ 87 | TypedValue typedValue = new TypedValue(); 88 | getTheme().resolveAttribute(R.attr.colorPrimary, typedValue, true); 89 | return typedValue.data; 90 | } 91 | 92 | public int getDarkColorPrimary(){ 93 | TypedValue typedValue = new TypedValue(); 94 | getTheme().resolveAttribute(R.attr.colorPrimaryDark, typedValue, true); 95 | return typedValue.data; 96 | } 97 | 98 | protected AlertDialog.Builder generateDialogBuilder(){ 99 | ThemeUtils.Theme theme = getCurrentTheme(); 100 | AlertDialog.Builder builder; 101 | int style = R.style.RedDialogTheme; 102 | switch (theme){ 103 | case BROWN: 104 | style = R.style.BrownDialogTheme; 105 | break; 106 | case BLUE: 107 | style = R.style.BlueDialogTheme; 108 | break; 109 | case BLUE_GREY: 110 | style = R.style.BlueGreyDialogTheme; 111 | break; 112 | case YELLOW: 113 | style = R.style.YellowDialogTheme; 114 | break; 115 | case DEEP_PURPLE: 116 | style = R.style.DeepPurpleDialogTheme; 117 | break; 118 | case PINK: 119 | style = R.style.PinkDialogTheme; 120 | break; 121 | case GREEN: 122 | style = R.style.GreenDialogTheme; 123 | break; 124 | default: 125 | break; 126 | } 127 | builder = new AlertDialog.Builder(this, style); 128 | return builder; 129 | } 130 | 131 | protected ThemeUtils.Theme getCurrentTheme(){ 132 | int value = preferenceUtils.getIntParam(getString(R.string.change_theme_key), 0); 133 | return ThemeUtils.Theme.mapValueToTheme(value); 134 | } 135 | 136 | @Override 137 | public void onDestroy() { 138 | super.onDestroy(); 139 | activityGraph = null; 140 | } 141 | 142 | /** 143 | * 增加了默认的返回finish事件 144 | */ 145 | @Override 146 | public boolean onOptionsItemSelected(MenuItem item) { 147 | int id = item.getItemId(); 148 | switch (id) { 149 | case android.R.id.home: 150 | finish(); 151 | return true; 152 | default: 153 | return super.onOptionsItemSelected(item); 154 | } 155 | 156 | } 157 | 158 | protected abstract int getLayoutView(); 159 | 160 | protected abstract List getModules(); 161 | 162 | protected abstract void initToolbar(); 163 | } 164 | -------------------------------------------------------------------------------- /app/src/main/java/com/lguipeng/notes/ui/EditNoteTypeActivity.java: -------------------------------------------------------------------------------- 1 | package com.lguipeng.notes.ui; 2 | 3 | import android.content.Context; 4 | import android.os.Bundle; 5 | import android.support.v7.widget.Toolbar; 6 | import android.text.Editable; 7 | import android.text.TextUtils; 8 | import android.text.TextWatcher; 9 | import android.view.Menu; 10 | import android.view.MenuItem; 11 | import android.view.inputmethod.InputMethodManager; 12 | import android.widget.EditText; 13 | import android.widget.LinearLayout; 14 | 15 | import com.lguipeng.notes.R; 16 | import com.lguipeng.notes.model.NoteType; 17 | import com.lguipeng.notes.module.DataModule; 18 | import com.lguipeng.notes.utils.JsonUtils; 19 | import com.lguipeng.notes.utils.NoteConfig; 20 | import com.lguipeng.notes.utils.PreferenceUtils; 21 | import com.rengwuxian.materialedittext.MaterialEditText; 22 | 23 | import java.util.Arrays; 24 | import java.util.List; 25 | 26 | import butterknife.InjectView; 27 | import de.greenrobot.event.EventBus; 28 | 29 | /** 30 | * Created by lgp on 2015/6/2. 31 | */ 32 | public class EditNoteTypeActivity extends BaseActivity{ 33 | @InjectView(R.id.toolbar) 34 | Toolbar toolbar; 35 | 36 | @InjectView(R.id.edit_root_view) 37 | LinearLayout editRootView; 38 | 39 | private MaterialEditText[] editTexts = new MaterialEditText[NoteType.ALL_COUNT - 1]; 40 | 41 | private MenuItem doneMenuItem; 42 | 43 | @Override 44 | protected void onCreate(Bundle savedInstanceState) { 45 | super.onCreate(savedInstanceState); 46 | initEditTextView(); 47 | } 48 | 49 | @Override 50 | public boolean onCreateOptionsMenu(Menu menu) { 51 | getMenuInflater().inflate(R.menu.menu_note, menu); 52 | return true; 53 | } 54 | 55 | @Override 56 | public boolean onPrepareOptionsMenu(Menu menu) { 57 | doneMenuItem = menu.getItem(0); 58 | doneMenuItem.setVisible(false); 59 | return super.onPrepareOptionsMenu(menu); 60 | } 61 | 62 | @Override 63 | public boolean onOptionsItemSelected(MenuItem item) { 64 | switch (item.getItemId()){ 65 | case R.id.done: 66 | hideKeyBoard(editTexts[0]); 67 | NoteType type = new NoteType(); 68 | for (MaterialEditText view : editTexts){ 69 | type.addType(view.getText().toString()); 70 | } 71 | 72 | type.addType(getString(R.string.recycle_bin)); 73 | String json = JsonUtils.jsonNoteType(type); 74 | preferenceUtils.saveParam(PreferenceUtils.NOTE_TYPE_KEY, json); 75 | EventBus.getDefault().post(NoteConfig.NOTE_TYPE_UPDATE_EVENT); 76 | finish(); 77 | return true; 78 | default: 79 | return super.onOptionsItemSelected(item); 80 | } 81 | } 82 | 83 | @Override 84 | protected int getLayoutView() { 85 | return R.layout.activity_edit_note_type; 86 | } 87 | 88 | @Override 89 | protected List getModules() { 90 | return Arrays.asList(new DataModule()); 91 | } 92 | 93 | @Override 94 | protected void initToolbar(){ 95 | super.initToolbar(toolbar); 96 | toolbar.setTitle(R.string.edit); 97 | } 98 | 99 | private void initEditTextView(){ 100 | String json = preferenceUtils.getStringParam(PreferenceUtils.NOTE_TYPE_KEY); 101 | List lists = JsonUtils.parseNoteType(json); 102 | if (lists == null) 103 | return; 104 | for (int i=0; i< editTexts.length; i++){ 105 | MaterialEditText view = (MaterialEditText)getLayoutInflater().inflate(R.layout.edit_layout, null); 106 | view.addTextChangedListener(new SimpleTextWatcher()); 107 | if (i < lists.size()){ 108 | view.setText(lists.get(i)); 109 | view.setSelection(lists.get(i).length()); 110 | } 111 | editRootView.addView(view); 112 | editTexts[i] = view; 113 | } 114 | } 115 | 116 | class SimpleTextWatcher implements TextWatcher { 117 | 118 | @Override 119 | public void beforeTextChanged(CharSequence s, int start, int count, int after) { 120 | 121 | } 122 | 123 | @Override 124 | public void onTextChanged(CharSequence s, int start, int before, int count) { 125 | if (doneMenuItem == null) 126 | return; 127 | boolean allFill = true; 128 | for (MaterialEditText view : editTexts){ 129 | if (TextUtils.isEmpty(view.getText().toString())) 130 | allFill = false; 131 | } 132 | if (allFill){ 133 | doneMenuItem.setVisible(true); 134 | }else { 135 | doneMenuItem.setVisible(false); 136 | } 137 | } 138 | 139 | @Override 140 | public void afterTextChanged(Editable s) { 141 | 142 | } 143 | } 144 | 145 | private void hideKeyBoard(EditText editText){ 146 | InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 147 | inputMethodManager.hideSoftInputFromWindow(editText.getWindowToken(), 0); 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /app/src/main/java/com/lguipeng/notes/ui/PayActivity.java: -------------------------------------------------------------------------------- 1 | package com.lguipeng.notes.ui; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.widget.Toolbar; 5 | 6 | import com.lguipeng.notes.R; 7 | import com.lguipeng.notes.module.DataModule; 8 | 9 | import java.util.Arrays; 10 | import java.util.List; 11 | 12 | import butterknife.InjectView; 13 | 14 | /** 15 | * Created by lgp on 2015/6/1. 16 | */ 17 | public class PayActivity extends BaseActivity{ 18 | @InjectView(R.id.toolbar) 19 | Toolbar toolbar; 20 | @Override 21 | protected void onCreate(Bundle savedInstanceState) { 22 | super.onCreate(savedInstanceState); 23 | } 24 | 25 | @Override 26 | protected int getLayoutView() { 27 | return R.layout.activity_pay; 28 | } 29 | 30 | @Override 31 | protected List getModules() { 32 | return Arrays.asList(new DataModule()); 33 | } 34 | 35 | @Override 36 | protected void initToolbar(){ 37 | super.initToolbar(toolbar); 38 | toolbar.setTitle(R.string.pay_for_me); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /app/src/main/java/com/lguipeng/notes/ui/SettingActivity.java: -------------------------------------------------------------------------------- 1 | package com.lguipeng.notes.ui; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.widget.Toolbar; 5 | 6 | import com.lguipeng.notes.R; 7 | import com.lguipeng.notes.module.DataModule; 8 | import com.lguipeng.notes.ui.fragments.SettingFragment; 9 | 10 | import java.util.Arrays; 11 | import java.util.List; 12 | 13 | import butterknife.InjectView; 14 | 15 | /** 16 | * Created by lgp on 2015/5/24. 17 | */ 18 | public class SettingActivity extends BaseActivity{ 19 | @InjectView(R.id.toolbar) 20 | Toolbar toolbar; 21 | 22 | @Override 23 | protected void onCreate(Bundle savedInstanceState) { 24 | super.onCreate(savedInstanceState); 25 | init(); 26 | } 27 | 28 | @Override 29 | protected int getLayoutView() { 30 | return R.layout.activity_setting; 31 | } 32 | 33 | @Override 34 | protected List getModules() { 35 | return Arrays.asList(new DataModule()); 36 | } 37 | 38 | @Override 39 | protected void initToolbar(){ 40 | super.initToolbar(toolbar); 41 | toolbar.setTitle(R.string.setting); 42 | } 43 | 44 | private void init(){ 45 | SettingFragment settingFragment = SettingFragment.newInstance(); 46 | getFragmentManager().beginTransaction().replace(R.id.fragment_content, settingFragment).commit(); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /app/src/main/java/com/lguipeng/notes/ui/fragments/BaseFragment.java: -------------------------------------------------------------------------------- 1 | package com.lguipeng.notes.ui.fragments; 2 | 3 | import android.os.Bundle; 4 | import android.preference.PreferenceFragment; 5 | import android.support.v7.app.AlertDialog; 6 | 7 | import com.lguipeng.notes.App; 8 | import com.lguipeng.notes.R; 9 | import com.lguipeng.notes.ui.BaseActivity; 10 | import com.lguipeng.notes.utils.PreferenceUtils; 11 | import com.lguipeng.notes.utils.ThemeUtils; 12 | 13 | import java.util.List; 14 | 15 | import dagger.ObjectGraph; 16 | 17 | /** 18 | * Created by lgp on 2015/5/26. 19 | */ 20 | public abstract class BaseFragment extends PreferenceFragment { 21 | 22 | private ObjectGraph activityGraph; 23 | protected BaseActivity activity; 24 | protected PreferenceUtils preferenceUtils; 25 | @Override 26 | public void onCreate(Bundle savedInstanceState) { 27 | super.onCreate(savedInstanceState); 28 | activityGraph = ((App) getActivity().getApplication()).createScopedGraph(getModules().toArray()); 29 | activityGraph.inject(this); 30 | } 31 | 32 | @Override 33 | public void onActivityCreated(Bundle savedInstanceState) { 34 | super.onActivityCreated(savedInstanceState); 35 | if (getActivity() != null && getActivity() instanceof BaseActivity){ 36 | activity = (BaseActivity)getActivity(); 37 | } 38 | preferenceUtils = PreferenceUtils.getInstance(getActivity()); 39 | } 40 | 41 | @Override 42 | public void onDestroy() { 43 | super.onDestroy(); 44 | activityGraph = null; 45 | } 46 | 47 | protected AlertDialog.Builder generateDialogBuilder(){ 48 | ThemeUtils.Theme theme = getCurrentTheme(); 49 | AlertDialog.Builder builder; 50 | switch (theme){ 51 | case BROWN: 52 | builder = new AlertDialog.Builder(getActivity(), R.style.BrownDialogTheme); 53 | break; 54 | case BLUE: 55 | builder = new AlertDialog.Builder(getActivity(), R.style.BlueDialogTheme); 56 | break; 57 | case BLUE_GREY: 58 | builder = new AlertDialog.Builder(getActivity(), R.style.BlueGreyDialogTheme); 59 | break; 60 | default: 61 | builder = new AlertDialog.Builder(getActivity(), R.style.RedDialogTheme); 62 | break; 63 | } 64 | return builder; 65 | } 66 | 67 | protected ThemeUtils.Theme getCurrentTheme(){ 68 | int value = preferenceUtils.getIntParam(getString(R.string.change_theme_key), 0); 69 | return ThemeUtils.Theme.mapValueToTheme(value); 70 | } 71 | 72 | protected abstract List getModules(); 73 | } 74 | -------------------------------------------------------------------------------- /app/src/main/java/com/lguipeng/notes/utils/AccountUtils.java: -------------------------------------------------------------------------------- 1 | package com.lguipeng.notes.utils; 2 | 3 | import android.accounts.Account; 4 | import android.accounts.AccountManager; 5 | import android.content.Context; 6 | import android.text.TextUtils; 7 | import android.util.Patterns; 8 | 9 | import com.lguipeng.notes.R; 10 | 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | import java.util.regex.Pattern; 14 | 15 | /** 16 | * Created by lgp on 2015/5/29. 17 | */ 18 | public class AccountUtils { 19 | 20 | private static final String EMAIL_TYPE = "com.android.email"; 21 | 22 | public static void findValidAccount(Context context, AccountFinderListener listener){ 23 | if (listener == null) 24 | return; 25 | String accountString = PreferenceUtils.getInstance(context).getStringParam(context.getString(R.string.sync_account_key)); 26 | if (!TextUtils.isEmpty(accountString)){ 27 | listener.setHasAccountSave(true); 28 | } 29 | Pattern emailPattern = Patterns.EMAIL_ADDRESS; 30 | Account[] accounts = AccountManager.get(context.getApplicationContext()).getAccounts(); 31 | List accountItems = new ArrayList<>(); 32 | for (Account account : accounts) { 33 | if (emailPattern.matcher(account.name).matches() && TextUtils.equals(EMAIL_TYPE, account.type)) { 34 | accountItems.add(account.name); 35 | } 36 | } 37 | if (accountItems.size() <= 0){ 38 | if (listener.isHasAccountSave()){ 39 | listener.onOne(accountString); 40 | return; 41 | } 42 | listener.onNone(); 43 | } 44 | if (accountItems.size() == 1){ 45 | if (listener.isHasAccountSave()){ 46 | listener.onOne(accountString); 47 | return; 48 | } 49 | listener.onOne(accountItems.get(0)); 50 | } 51 | 52 | if (accountItems.size() > 1){ 53 | listener.onMore(accountItems); 54 | } 55 | } 56 | 57 | public static abstract class AccountFinderListener{ 58 | private boolean hasAccountSave = false; 59 | protected abstract void onNone(); 60 | protected abstract void onOne(String account); 61 | protected abstract void onMore(List accountItems); 62 | 63 | public boolean isHasAccountSave() { 64 | return hasAccountSave; 65 | } 66 | 67 | public void setHasAccountSave(boolean hasAccountSave) { 68 | this.hasAccountSave = hasAccountSave; 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /app/src/main/java/com/lguipeng/notes/utils/JsonUtils.java: -------------------------------------------------------------------------------- 1 | package com.lguipeng.notes.utils; 2 | 3 | import android.text.TextUtils; 4 | 5 | import com.alibaba.fastjson.JSON; 6 | import com.lguipeng.notes.model.Note; 7 | import com.lguipeng.notes.model.NoteType; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * Created by lgp on 2015/5/28. 13 | */ 14 | public class JsonUtils { 15 | 16 | public static String json(T note){ 17 | if (note == null) 18 | return ""; 19 | try { 20 | return JSON.toJSONString(note); 21 | }catch (Exception e){ 22 | e.printStackTrace(); 23 | return ""; 24 | } 25 | } 26 | 27 | public static T parse(String json, Class clazz){ 28 | if (TextUtils.isEmpty(json)) 29 | return null; 30 | try { 31 | return JSON.parseObject(json, clazz); 32 | }catch (Exception e){ 33 | e.printStackTrace(); 34 | return null; 35 | } 36 | } 37 | 38 | public static Note parseNote(String json){ 39 | return parse(json, Note.class); 40 | } 41 | 42 | public static String jsonNote(Note note){ 43 | return json(note); 44 | } 45 | 46 | public static List parseNoteType(String json){ 47 | NoteType type = parse(json, NoteType.class); 48 | if (type == null) 49 | return null; 50 | return type.getTypes(); 51 | } 52 | 53 | public static String jsonNoteType(NoteType type){ 54 | return json(type); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /app/src/main/java/com/lguipeng/notes/utils/NoteConfig.java: -------------------------------------------------------------------------------- 1 | package com.lguipeng.notes.utils; 2 | 3 | /** 4 | * Created by lgp on 2015/5/25. 5 | */ 6 | public class NoteConfig { 7 | 8 | public final static int NOTE_CREATE_OPR = 0x00; 9 | public final static int NOTE_EDIT_OPR = 0x01; 10 | 11 | public final static int NOTE_STUDY_TYPE = 0x00; 12 | public final static int NOTE_WORK_TYPE = 0x01; 13 | public final static int NOTE_OTHER_TYPE = 0x02; 14 | public final static int NOTE_TRASH_TYPE = 0x03; 15 | 16 | public final static int NOTE_UPDATE_EVENT = 0x00; 17 | public final static int NOTE_TYPE_UPDATE_EVENT = 0x01; 18 | public final static int CHANGE_THEME_EVENT = 0x02; 19 | } 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/lguipeng/notes/utils/NotesLog.java: -------------------------------------------------------------------------------- 1 | /*** 2 | This is free and unencumbered software released into the public domain. 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | For more information, please refer to 8 | */ 9 | 10 | package com.lguipeng.notes.utils; 11 | 12 | import android.util.Log; 13 | 14 | import com.lguipeng.notes.BuildConfig; 15 | 16 | /** 17 | * @date 21.06.2012 18 | * @author Mustafa Ferhan Akman 19 | * 20 | * Create a simple and more understandable Android logs. 21 | * */ 22 | 23 | public class NotesLog{ 24 | 25 | static String className; 26 | static String methodName; 27 | static int lineNumber; 28 | 29 | private NotesLog(){ 30 | /* Protect from instantiations */ 31 | } 32 | 33 | public static boolean isDebuggable() { 34 | return BuildConfig.DEBUG; 35 | } 36 | 37 | private static String createLog( String log ) { 38 | 39 | StringBuffer buffer = new StringBuffer(); 40 | buffer.append("["); 41 | buffer.append(methodName); 42 | buffer.append(":"); 43 | buffer.append(lineNumber); 44 | buffer.append("]"); 45 | buffer.append(log); 46 | 47 | return buffer.toString(); 48 | } 49 | 50 | private static void getMethodNames(StackTraceElement[] sElements){ 51 | className = sElements[1].getFileName(); 52 | methodName = sElements[1].getMethodName(); 53 | lineNumber = sElements[1].getLineNumber(); 54 | } 55 | 56 | public static void e(String message){ 57 | if (!isDebuggable()) 58 | return; 59 | 60 | // Throwable instance must be created before any methods 61 | getMethodNames(new Throwable().getStackTrace()); 62 | Log.e(className, createLog(message)); 63 | } 64 | 65 | public static void i(String message){ 66 | if (!isDebuggable()) 67 | return; 68 | 69 | getMethodNames(new Throwable().getStackTrace()); 70 | Log.i(className, createLog(message)); 71 | } 72 | 73 | public static void d(String message){ 74 | if (!isDebuggable()) 75 | return; 76 | 77 | getMethodNames(new Throwable().getStackTrace()); 78 | Log.d(className, createLog(message)); 79 | } 80 | 81 | public static void d(){ 82 | d(""); 83 | } 84 | 85 | public static void v(String message){ 86 | if (!isDebuggable()) 87 | return; 88 | 89 | getMethodNames(new Throwable().getStackTrace()); 90 | Log.v(className, createLog(message)); 91 | } 92 | 93 | public static void w(String message){ 94 | if (!isDebuggable()) 95 | return; 96 | 97 | getMethodNames(new Throwable().getStackTrace()); 98 | Log.w(className, createLog(message)); 99 | } 100 | 101 | public static void wtf(String message){ 102 | if (!isDebuggable()) 103 | return; 104 | 105 | getMethodNames(new Throwable().getStackTrace()); 106 | Log.wtf(className, createLog(message)); 107 | } 108 | 109 | } -------------------------------------------------------------------------------- /app/src/main/java/com/lguipeng/notes/utils/PreferenceUtils.java: -------------------------------------------------------------------------------- 1 | package com.lguipeng.notes.utils; 2 | 3 | import android.content.Context; 4 | import android.content.SharedPreferences; 5 | 6 | import com.lguipeng.notes.ui.fragments.SettingFragment; 7 | 8 | /** 9 | * Created by lgp on 2014/10/30. 10 | */ 11 | public class PreferenceUtils{ 12 | 13 | private SharedPreferences sharedPreferences; 14 | 15 | private SharedPreferences.Editor shareEditor; 16 | 17 | private static PreferenceUtils preferenceUtils = null; 18 | 19 | public static final String NOTE_TYPE_KEY = "NOTE_TYPE_KEY"; 20 | 21 | private PreferenceUtils(Context context){ 22 | sharedPreferences = context.getSharedPreferences(SettingFragment.PREFERENCE_FILE_NAME, Context.MODE_PRIVATE); 23 | shareEditor = sharedPreferences.edit(); 24 | } 25 | 26 | public static PreferenceUtils getInstance(Context context){ 27 | if (preferenceUtils == null) { 28 | synchronized (PreferenceUtils.class) { 29 | if (preferenceUtils == null) { 30 | preferenceUtils = new PreferenceUtils(context.getApplicationContext()); 31 | } 32 | } 33 | } 34 | return preferenceUtils; 35 | } 36 | 37 | public String getStringParam(String key){ 38 | return getStringParam(key, ""); 39 | } 40 | 41 | public String getStringParam(String key, String defaultString){ 42 | return sharedPreferences.getString(key, defaultString); 43 | } 44 | 45 | public void saveParam(String key, String value) 46 | { 47 | shareEditor.putString(key,value).commit(); 48 | } 49 | 50 | public boolean getBooleanParam(String key){ 51 | return getBooleanParam(key, false); 52 | } 53 | 54 | public boolean getBooleanParam(String key, boolean defaultBool){ 55 | return sharedPreferences.getBoolean(key, defaultBool); 56 | } 57 | 58 | public void saveParam(String key, boolean value){ 59 | shareEditor.putBoolean(key, value).commit(); 60 | } 61 | 62 | public int getIntParam(String key){ 63 | return getIntParam(key, 0); 64 | } 65 | 66 | public int getIntParam(String key, int defaultInt){ 67 | return sharedPreferences.getInt(key, defaultInt); 68 | } 69 | 70 | public void saveParam(String key, int value){ 71 | shareEditor.putInt(key, value).commit(); 72 | } 73 | 74 | public long getLongParam(String key){ 75 | return getLongParam(key, 0); 76 | } 77 | 78 | public long getLongParam(String key, long defaultInt){ 79 | return sharedPreferences.getLong(key, defaultInt); 80 | } 81 | 82 | public void saveParam(String key, long value){ 83 | shareEditor.putLong(key, value).commit(); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /app/src/main/java/com/lguipeng/notes/utils/SnackbarUtils.java: -------------------------------------------------------------------------------- 1 | package com.lguipeng.notes.utils; 2 | 3 | import android.app.Activity; 4 | import android.graphics.Color; 5 | 6 | import com.lguipeng.notes.ui.BaseActivity; 7 | import com.nispok.snackbar.Snackbar; 8 | import com.nispok.snackbar.SnackbarManager; 9 | 10 | /** 11 | * Author: lgp 12 | * Date: 2014/12/31. 13 | */ 14 | public class SnackbarUtils { 15 | 16 | public static void show(Activity activity, int message) { 17 | // Toast.makeText(mContext, message, Toast.LENGTH_SHORT).show(); 18 | // Toast toast = new Toast(mContext); 19 | // View view = LayoutInflater.from(mContext).inflate(R.layout.toast_layout, null, false); 20 | // TextView textView = (TextView)view.findViewById(R.id.toast_text); 21 | // textView.setText(message); 22 | // toast.setView(view); 23 | // toast.setDuration(Toast.LENGTH_SHORT); 24 | // toast.show(); 25 | int color = Color.BLACK; 26 | if (activity instanceof BaseActivity){ 27 | color = (((BaseActivity) activity)).getColorPrimary(); 28 | } 29 | color = color & 0xddffffff; 30 | SnackbarManager.show( 31 | Snackbar.with(activity.getApplicationContext()) 32 | .color(color) 33 | .duration((Snackbar.SnackbarDuration.LENGTH_SHORT.getDuration() / 2)) 34 | .text(message), activity); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /app/src/main/java/com/lguipeng/notes/utils/ThemeUtils.java: -------------------------------------------------------------------------------- 1 | package com.lguipeng.notes.utils; 2 | 3 | import android.app.Activity; 4 | 5 | import com.lguipeng.notes.R; 6 | 7 | /** 8 | * Created by lgp on 2015/6/7. 9 | */ 10 | public class ThemeUtils { 11 | 12 | public static void changTheme(Activity activity, Theme theme){ 13 | if (activity == null) 14 | return; 15 | int style = R.style.RedTheme; 16 | switch (theme){ 17 | case BROWN: 18 | style = R.style.BrownTheme; 19 | break; 20 | case BLUE: 21 | style = R.style.BlueTheme; 22 | break; 23 | case BLUE_GREY: 24 | style = R.style.BlueGreyTheme; 25 | break; 26 | case YELLOW: 27 | style = R.style.YellowTheme; 28 | break; 29 | case DEEP_PURPLE: 30 | style = R.style.DeepPurpleTheme; 31 | break; 32 | case PINK: 33 | style = R.style.PinkTheme; 34 | break; 35 | case GREEN: 36 | style = R.style.GreenTheme; 37 | break; 38 | default: 39 | break; 40 | } 41 | activity.setTheme(style); 42 | } 43 | 44 | public enum Theme{ 45 | RED(0x00), 46 | BROWN(0x01), 47 | BLUE(0x02), 48 | BLUE_GREY(0x03), 49 | YELLOW(0x04), 50 | DEEP_PURPLE(0x05), 51 | PINK(0x06), 52 | GREEN(0x07); 53 | 54 | private int mValue; 55 | 56 | Theme(int value){ 57 | this.mValue = value; 58 | } 59 | 60 | public static Theme mapValueToTheme(final int value) { 61 | for (Theme theme : Theme.values()) { 62 | if (value == theme.getIntValue()) { 63 | return theme; 64 | } 65 | } 66 | // If run here, return default 67 | return RED; 68 | } 69 | 70 | static Theme getDefault() 71 | { 72 | return RED; 73 | } 74 | public int getIntValue() { 75 | return mValue; 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /app/src/main/java/com/lguipeng/notes/utils/TimeUtils.java: -------------------------------------------------------------------------------- 1 | package com.lguipeng.notes.utils; 2 | 3 | import android.content.Context; 4 | 5 | import com.lguipeng.notes.R; 6 | 7 | import java.text.SimpleDateFormat; 8 | import java.util.Date; 9 | 10 | /** 11 | * Created by lgp on 2015/5/25. 12 | */ 13 | public class TimeUtils { 14 | public static final long DAY_Millis = 24 * 60 * 60 * 1000; 15 | public static final long MONTH_Millis = 30 * DAY_Millis; 16 | public static final long YEAR_Millis = 365 * DAY_Millis; 17 | public static final SimpleDateFormat DEFAULT_DATE_FORMAT = new SimpleDateFormat("yyyy.MM.dd HH : mm"); 18 | public static final SimpleDateFormat DATE_FORMAT_DATE_1 = new SimpleDateFormat(" HH : mm "); 19 | 20 | private TimeUtils() { 21 | throw new AssertionError(); 22 | } 23 | 24 | /** 25 | * long time to string 26 | * 27 | * @param timeInMillis 28 | * @param dateFormat 29 | * @return 30 | */ 31 | public static String getTime(long timeInMillis, SimpleDateFormat dateFormat) { 32 | return dateFormat.format(new Date(timeInMillis)); 33 | } 34 | 35 | /** 36 | * long time to string, format is {@link #DEFAULT_DATE_FORMAT} 37 | * 38 | * @param timeInMillis 39 | * @return 40 | */ 41 | public static String getTime(long timeInMillis) { 42 | return getTime(timeInMillis, DEFAULT_DATE_FORMAT); 43 | } 44 | 45 | @SuppressWarnings("Deprecated") 46 | public static String getConciseTime(long timeInMillis, long nowInMillis, Context context) { 47 | if (context == null) 48 | return ""; 49 | Date date = new Date(timeInMillis); 50 | Date now = new Date(nowInMillis); 51 | 52 | if (now.getYear() == date.getYear()) { 53 | if (now.getMonth() == date.getMonth()) { 54 | if (now.getDate() == date.getDate()) 55 | return context.getString(R.string.today, getTime(timeInMillis, DATE_FORMAT_DATE_1)); 56 | else{ 57 | return context.getString(R.string.before_day, now.getDate() - date.getDate()); 58 | } 59 | }else { 60 | return context.getString(R.string.before_month, now.getMonth() - date.getMonth()); 61 | } 62 | } 63 | return context.getString(R.string.before_year, now.getYear() - date.getYear()); 64 | } 65 | 66 | 67 | public static String getConciseTime(long timeInMillis, Context context) { 68 | return getConciseTime(timeInMillis, getCurrentTimeInLong(), context); 69 | } 70 | /** 71 | * get current time in milliseconds 72 | * 73 | * @return 74 | */ 75 | public static long getCurrentTimeInLong() { 76 | return System.currentTimeMillis(); 77 | } 78 | 79 | /** 80 | * get current time in milliseconds, format is {@link #DEFAULT_DATE_FORMAT} 81 | * 82 | * @return 83 | */ 84 | public static String getCurrentTimeInString() { 85 | return getTime(getCurrentTimeInLong()); 86 | } 87 | 88 | /** 89 | * get current time in milliseconds 90 | * 91 | * @return 92 | */ 93 | public static String getCurrentTimeInString(SimpleDateFormat dateFormat) { 94 | return getTime(getCurrentTimeInLong(), dateFormat); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /app/src/main/java/com/lguipeng/notes/utils/ViewHelper.java: -------------------------------------------------------------------------------- 1 | package com.lguipeng.notes.utils; 2 | 3 | import android.support.v4.view.ViewCompat; 4 | import android.view.View; 5 | 6 | /** 7 | * Created by lgp on 2015/5/27. 8 | */ 9 | public class ViewHelper { 10 | public static void clear(View v) { 11 | ViewCompat.setAlpha(v, 1); 12 | ViewCompat.setScaleY(v, 1); 13 | ViewCompat.setScaleX(v, 1); 14 | ViewCompat.setTranslationY(v, 0); 15 | ViewCompat.setTranslationX(v, 0); 16 | ViewCompat.setRotation(v, 0); 17 | ViewCompat.setRotationY(v, 0); 18 | ViewCompat.setRotationX(v, 0); 19 | // @TODO https://code.google.com/p/android/issues/detail?id=80863 20 | // ViewCompat.setPivotY(v, v.getMeasuredHeight() / 2); 21 | v.setPivotY(v.getMeasuredHeight() / 2); 22 | ViewCompat.setPivotX(v, v.getMeasuredWidth() / 2); 23 | ViewCompat.animate(v).setInterpolator(null); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /app/src/main/java/com/lguipeng/notes/view/FixedRecyclerView.java: -------------------------------------------------------------------------------- 1 | package com.lguipeng.notes.view; 2 | 3 | import android.content.Context; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.util.AttributeSet; 6 | 7 | /** 8 | * Created by lgp on 2015/6/11. 9 | */ 10 | public class FixedRecyclerView extends RecyclerView { 11 | public FixedRecyclerView(Context context) { 12 | super(context); 13 | } 14 | 15 | public FixedRecyclerView(Context context, AttributeSet attrs) { 16 | super(context, attrs); 17 | } 18 | 19 | public FixedRecyclerView(Context context, AttributeSet attrs, int defStyle) { 20 | super(context, attrs, defStyle); 21 | } 22 | 23 | @Override 24 | public boolean canScrollVertically(int direction) { 25 | // check if scrolling up 26 | if (direction < 1) { 27 | boolean original = super.canScrollVertically(direction); 28 | return !original && getChildAt(0) != null && getChildAt(0).getTop() < 0 || original; 29 | } 30 | return super.canScrollVertically(direction); 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_done_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daimajia/Notes/0b743136b2080dec363b156b8ebea7c019270c27/app/src/main/res/drawable-hdpi/ic_done_white.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_edit_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daimajia/Notes/0b743136b2080dec363b156b8ebea7c019270c27/app/src/main/res/drawable-hdpi/ic_edit_white.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/alipay_erweima.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daimajia/Notes/0b743136b2080dec363b156b8ebea7c019270c27/app/src/main/res/drawable-xhdpi/alipay_erweima.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_done_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daimajia/Notes/0b743136b2080dec363b156b8ebea7c019270c27/app/src/main/res/drawable-xhdpi/ic_done_white.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_edit_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daimajia/Notes/0b743136b2080dec363b156b8ebea7c019270c27/app/src/main/res/drawable-xhdpi/ic_edit_white.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_more_grey.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daimajia/Notes/0b743136b2080dec363b156b8ebea7c019270c27/app/src/main/res/drawable-xhdpi/ic_more_grey.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_share_more.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daimajia/Notes/0b743136b2080dec363b156b8ebea7c019270c27/app/src/main/res/drawable-xhdpi/ic_share_more.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_sina_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daimajia/Notes/0b743136b2080dec363b156b8ebea7c019270c27/app/src/main/res/drawable-xhdpi/ic_sina_logo.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_wx_collect.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daimajia/Notes/0b743136b2080dec363b156b8ebea7c019270c27/app/src/main/res/drawable-xhdpi/ic_wx_collect.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_wx_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daimajia/Notes/0b743136b2080dec363b156b8ebea7c019270c27/app/src/main/res/drawable-xhdpi/ic_wx_logo.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_wx_moments.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daimajia/Notes/0b743136b2080dec363b156b8ebea7c019270c27/app/src/main/res/drawable-xhdpi/ic_wx_moments.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_done_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daimajia/Notes/0b743136b2080dec363b156b8ebea7c019270c27/app/src/main/res/drawable-xxhdpi/ic_done_white.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_edit_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daimajia/Notes/0b743136b2080dec363b156b8ebea7c019270c27/app/src/main/res/drawable-xxhdpi/ic_edit_white.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/activated_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/blue_grey_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/blue_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/brown_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/deep_purple_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/green_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/pink_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/red_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/selectable_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/toolbar_shadow.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/white_button_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/yellow_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_about.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 18 | 23 | 31 | 39 | 48 |