跳到主要內容

發表文章

[Android]在圖上畫圖與dp<=>px轉換

有兩種做法: 1. 以Canvas畫在指定位址與縮放,再將Canvas所畫的Bitmap拿來用 2. 以Layout檔Inflate,再將View轉為Bitmap拿來用 結論: 第二種方法較快且容易擴充與調整 方法一: Bitmap org = BitmapFactory.decodeResource(getResources(), R.drawable.empty_pinpoint); Bitmap pinPoint = Bitmap.createScaledBitmap(org, dp2px(52), dp2px(68), true); Canvas pinPointCanvas = new Canvas(pinPoint); Bitmap head = BitmapFactory.decodeResource(getResources(), R.drawable.test_head); pinPointCanvas.drawBitmap(head, null, new Rect(dp2px(6), dp2px(3), dp2px(46), dp2px(43)), null); ImageView view = (ImageView) findViewById(R.id.imgResult); view.setImageBitmap(pinPoint); 方法二:         //1. Make a bitmap to draw to.         Bitmap bmp = Bitmap.createBitmap(480, 800, Bitmap.Config.ARGB_8888);         //2. We need a Canvas to handle drawing to the bitmap. Bitmap has no draw methods of its own.         Canvas canvas = new Canvas(bmp);         //3. Get a ref...

[Android]Send Message To android.os.Handler的快速寫法

快速寫法: mHandler.sendMessage(mHandler. obtainMessage (MSG_ADD_TO_PLAYLIST, intent)); 其內部其實就是: public final Message obtainMessage(int what, Object obj)     {         return Message.obtain(this, what, obj);     } public static Message obtain(Handler h, int what, Object obj) {         Message m = obtain();         m.target = h;         m.what = what;         m.obj = obj;         return m;     }

Programming Language 大比較

Programming Language 大比較 Constructor     使用一 Class     class Vector     {         public Vector()         {             //Do Something         }         public Vector(int i)         {              //Do Something         }     } In C++   Vector u();       Vector v(10); In Java,C#    Vector u = new Vector();    Vector v = new Vector(10);

[Android]Android中的Intent.FLAG_ACTIVITY_NEW_TASK

Android中的Intent.FLAG_ACTIVITY_NEW_TASK i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 有此行程式可將不同的activity看成好像是同一個應用程式 當你從 主activity 跳至 另一個activity (此activity早己存在於系統之中) 當你按下"back"後它會跳回主activity 如果沒加入此程式當按下"back"後它則會離開主activity

[Android]Google Map View的一堆陷阱!!!

以下是Google Map View的一堆陷阱!!! 請小心服用: 基本常識區: 1. 需使用MapActivity 2. <uses-library android:name="com.google.android.maps"/> 3. <uses-permission android:name="android.permission.INTERNET"/> 4. API Key, Sign APK 陷阱區: 1.在加入ItemizedOverlay後請使用 invalidate 重繪         mMapView.getOverlays().add(draggableItemizedOverlay);         mMapView.invalidate(); 2.ItemizedOverlay其super(drawable)建構子的drawable可以為NULL 3.加入ItemizedOverlay的OverlayItem 其drawable可以是使用預設(即建構子時給的,此時加入的 OverlayItem 可不用.setMarker) 或使用各Item的Marker,在AddItem前.setMarker 務必記住其drawable皆需要在ItemizedOverlay中呼叫 boundCenterBottom(drawable) !! 沒叫會看不見

[Android]取得與綁定Activity的Label,Description

在AndroidManifest中綁定Activity的標籤(Label)與敘述(Description)  <activity        android:name=".activity.ResourceSearchViewActivity"       android:theme="@style/Theme.Sherlock.SearchView"        android:label ="@string/resource_search_view_title"        android:description ="@string/resource_search_view_descr"/> 在Java中解析 PackageManager mPackageManager = context.getPackageManager(); ResolveInfo info = mPackageManager.resolveActivity( YOUR_Intent , 0); title.setText( info.activityInfo.labelRes ); descr.setText( info.activityInfo.descriptionRes );

Android Thread Constructs

Android Thread Constructs Service Thread IntentService AsyncTask When to use ? Task with no UI, but shouldn't be too long. Use threads within service for long tasks. - Long task in general. - For tasks in parallel use Multiple threads (traditional mechanisms) - Long task  usually  with no communication to main thread. (Update) - If communication is required, can use main thread handler or broadcast intents [3] - When callbacks are needed (Intent triggered tasks).  - Long task having to communicate with main thread. - For tasks in parallel use multiple instances OR Executor  [1] Trigger Call to method onStartService() Thread start() method Intent Call to method execute() Triggered From (thread) Any thread Any Thread Main Thread (Intent is received on main thread and then worker thread is spawed) Main Thread Runs On (thread) Main Thread Its own thread Separate worker thread Worker thread. However, Main thread methods may be invoked in betw...