You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
MiCode-Notes/output/MiCodeNotes_Analysis.md

5.9 KiB

小米便签项目设计文档

1. 项目主要功能及其代码实现关系简表

功能模块 实现类 主要功能描述
便签列表 NotesListActivity 显示便签列表,支持文件夹查看、新建便签、删除便签等功能
便签编辑 NoteEditActivity 支持便签的创建、编辑、设置提醒、背景颜色等功能
数据模型 Note, WorkingNote 便签的数据模型,包含便签的基本属性和操作方法
数据存储 NotesDatabaseHelper, NotesProvider 管理SQLite数据库提供数据访问接口
桌面小部件 NoteWidgetProvider_2x, NoteWidgetProvider_4x 提供2x2和4x4两种大小的桌面小部件
提醒功能 AlarmReceiver, AlarmAlertActivity 提供便签提醒功能
Google同步 GTaskSyncService 提供与Google Tasks的同步功能当前版本已禁用
数据导出 BackupUtils 支持将便签导出为文本文件

2. 主要的类图与关系

数据模型类图

classDiagram
    class Note {
        +long id
        +long parent_id
        +String snippet
        +long alert_date
        +long created_date
        +long modified_date
        +int bg_color_id
        +int type
        +int widget_id
        +int widget_type
        +boolean has_attachment
        +getNewNoteId()
        +syncNote()
    }
    
    class NoteData {
        +long textDataId
        +long callDataId
        +setTextData()
        +setCallData()
        +pushIntoContentResolver()
    }
    
    class WorkingNote {
        +long mNoteId
        +int mBgColorId
        +String mContent
        +long mAlertDate
        +long mModifiedDate
        +int mWidgetId
        +int mWidgetType
        +boolean mHasAttachment
        +long mFolderId
        +setAlertDate()
        +setBgColorId()
        +saveNote()
        +createEmptyNote()
    }
    
    class Notes {
        +AUTHORITY: String
        +TYPE_NOTE: int
        +TYPE_FOLDER: int
        +TYPE_SYSTEM: int
        +ID_ROOT_FOLDER: int
        +ID_TEMPARAY_FOLDER: int
        +ID_CALL_RECORD_FOLDER: int
        +ID_TRASH_FOLER: int
    }
    
    class NoteColumns {
        +ID: String
        +PARENT_ID: String
        +CREATED_DATE: String
        +MODIFIED_DATE: String
        +ALERTED_DATE: String
        +SNIPPET: String
        +WIDGET_ID: String
        +WIDGET_TYPE: String
        +BG_COLOR_ID: String
        +HAS_ATTACHMENT: String
    }
    
    class DataColumns {
        +ID: String
        +MIME_TYPE: String
        +NOTE_ID: String
        +CREATED_DATE: String
        +MODIFIED_DATE: String
        +CONTENT: String
        +DATA1: String
        +DATA2: String
        +DATA3: String
        +DATA4: String
        +DATA5: String
    }
    
    Note "1" *-- "1" NoteData : contains
    WorkingNote "1" --> "1" Note : uses
    Note --> Notes : uses constants
    Notes "1" *-- "1" NoteColumns : defines
    Notes "1" *-- "1" DataColumns : defines

数据库模式图

erDiagram
    NOTE {
        long id PK
        long parent_id FK
        long alerted_date
        int bg_color_id
        long created_date
        boolean has_attachment
        long modified_date
        int notes_count
        string snippet
        int type
        int widget_id
        int widget_type
        long sync_id
        boolean local_modified
        long origin_parent_id
        string gtask_id
        long version
    }
    
    DATA {
        long id PK
        string mime_type
        long note_id FK
        long created_date
        long modified_date
        string content
        int data1
        int data2
        string data3
        string data4
        string data5
    }
    
    NOTE ||--o{ DATA : "has"
    NOTE ||--o{ NOTE : "contains"

创建新便签的时序图

sequenceDiagram
    actor User
    participant NLA as NotesListActivity
    participant WN as WorkingNote
    participant N as Note
    participant NP as NotesProvider
    participant DB as NotesDatabaseHelper
    
    User->>NLA: Click "New Note"
    NLA->>NLA: createNewNote()
    NLA->>WN: createEmptyNote()
    WN->>N: getNewNoteId()
    N->>NP: insert(ContentValues)
    NP->>DB: insert into note table
    DB-->>NP: return note id
    NP-->>N: return Uri with id
    N-->>WN: return note id
    WN-->>NLA: return WorkingNote instance
    NLA->>NLA: startActivity(NoteEditActivity)

3. 项目架构图

MVC架构模式

graph TD
    A[Model<br>Note, WorkingNote, Notes] --> B[Controller<br>NotesProvider, NotesDatabaseHelper]
    B --> A
    C[View<br>NotesListActivity, NoteEditActivity] --> B
    B --> C
    C --> D[用户界面<br>XML布局文件]
    D --> C

4. 项目总体技术点分析

  1. MVC架构模式

    • Model层Note、WorkingNote等数据模型类
    • View层NotesListActivity、NoteEditActivity等UI类
    • Controller层NotesProvider、NotesDatabaseHelper等数据控制类
  2. ContentProvider数据访问

    • 使用ContentProviderNotesProvider提供数据访问接口
    • 支持CRUD增删改查操作
    • 通过URI标识不同的数据资源
  3. SQLite数据库存储

    • 使用SQLite数据库存储便签数据
    • 两个主要表note表和data表
    • 使用触发器Trigger维护数据一致性
  4. AppWidget桌面小部件

    • 提供2x2和4x4两种大小的桌面小部件
    • 支持通过小部件快速查看和创建便签
  5. 同步功能

    • 支持与Google Tasks同步当前版本已禁用
    • 使用REST API进行数据同步
  6. 提醒功能

    • 使用AlarmManager实现便签提醒
    • 支持设置提醒时间并在到达时间时触发通知
  7. 数据导出功能

    • 支持将便签导出为文本文件
    • 支持通过短信或邮件分享便签内容
  8. Material Design设计

    • 遵循Material Design设计规范
    • 提供美观、直观的用户界面