NotePad源碼學習

來源:互聯網
上載者:User

1、ContentProvider的使用
       NotePad.java定義了資料庫中唯一的Notes表的若干欄位及其屬性。Notes表實現了BaseColumns介面,即擁有了_id和_count的屬性。資料庫表的Uri的命名規則一般是:content://**/資料庫名   (**代表provider的authorities)。

     NotePadProvider.java繼承自ContentProvider,所以需要實現onCreate()、query()、insert()、delete()、update()和getType()共六個方法。

          onCreate方法在ContentProvider初始化的時候,執行相應的語句,如果初始化成功返回true,否則返回false。一般在該方法裡,初始化資料庫擷取DatabaseHelper的對象,所有資料庫表的建立都是在Databasehelper對象的onCreate方法裡執行的。

          getType方法的作用是:當使用隱式的Intent調用activity的時候,該方法的傳回值決定了activity是否被選中。隱式調用activity方法

            intent.setAction(action);
            intent.setData(data);
            intent.addCategory(category);

    

[java]
<intent-filter android:label="@string/resolve_edit"> 
     <action android:name="android.intent.action.VIEW" /> 
     <action android:name="android.intent.action.EDIT" /> 
     <action android:name="com.android.notepad.action.EDIT_NOTE" /> 
     <category android:name="android.intent.category.DEFAULT" /> 
     <data android:mimeType="vnd.android.cursor.item/vnd.google.note" /> 
 </intent-filter> 
     getType的方法傳回值和mimeType的值對應。

2、android的即時檔案夾   個人覺得掌握起來也容易,但是用到的可能性很小。   參考網址:http://www.bkjia.com/kf/201204/128715.html


3、擴充EditText的LineEditText控制項。注意getLineCount和getLineBounds兩個方法。

[java]
public static class LinedEditText extends EditText { 
        private Rect mRect; 
        private Paint mPaint; 
 
        // we need this constructor for LayoutInflater 
        public LinedEditText(Context context, AttributeSet attrs) { 
            super(context, attrs); 
             
            mRect = new Rect(); 
            mPaint = new Paint(); 
            mPaint.setStyle(Paint.Style.STROKE); 
            mPaint.setColor(0x800000FF); 
        } 
         
        @Override 
        protected void onDraw(Canvas canvas) { 
            int count = getLineCount(); 
            Rect r = mRect; 
            Paint paint = mPaint; 
 
            for (int i = 0; i < count; i++) { 
                int baseline = getLineBounds(i, r); 
 
                canvas.drawLine(r.left, baseline + 1, r.right, baseline + 1, paint); 
            } 
 
            super.onDraw(canvas); 
        } 
    } 



摘自 單曲迴圈

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.