2015年10月29日 星期四

【Android】Redering Problems Missing Styles

After i update my Android Studio , my XML always show  Rendering Problems Missing Style
今天在升級版的Android Studio後,在建立新應用程式後,都會出現下列的問題畫面:


Solution:

【File】→【Invalidate Caches / Restart...】:

[Android] java.io.FileNotFoundException AND android.os.NetworkOnMainThreadException!!

1.Android 4.0 has a new Exception in NetWork part.So if you request it.
You will get a android.os.NetworkOnMainThreadException!!

Android4.0在網路的部份多了一個新的Exception,
叫做android.os.NetworkOnMainThreadException
意思就是說:網路的活動跑在主要執行緒上了,很貼心的告訴你,這樣子你的APP可能會因為網路的活動等待回應太久,而被系統強制關閉(收到ANR)。

Solution:(put it in main )
StrictMode
    .setThreadPolicy(new StrictMode.ThreadPolicy.Builder()  
    .detectDiskReads()  
    .detectDiskWrites()  
    .detectNetwork()   // or .detectAll() for all detectable problems  
    .penaltyLog()  
    .build());  



2.Android 4.0 hope developer use post to request ,But if will occur
Java.io.FileNotFoundException

4.0中設置httpCon.setDoOutput(true),将導致請求以post方式提交
然後就會出現 java.io.FileNotFoundException

Soluation:
Delete-->httpCon.setDoOutput(true);

2015年8月29日 星期六

[C++]VECTOR ALLOCATION

Basis

Define:vector<int> array;

Two dynamic vector +initialize  0:

vector<vector<int> > array;
array.resize(y, vector<int>(x, 0));

OR

vector<vector<int> > array(y, vector<int>(x, 0));
**
vector<vector<int> > array(y, vector<int>(x));//ALSO '0'


2015年7月26日 星期日

【Eclipse] 中文出現亂碼 gibberish in chinese character

有時候import project的時候,就會出現中文亂碼#%$#%一整個很困擾
Sometime i import a project the chinese character all become %$#$%# !!!!
IT'S VERY NOISY!!!!! 

 SOLVE METHOD
 Step 1. 「Window」->「Preferences」
 Step 2. 「General」->「Workspace」。
 Step 3. 「Text file encoding」 Change Default (MS950) ->「UTF-8」。
 Step 4. Press 「Apply」

[Android] 通知(Notification)

Take a note !! so next time if i use notification it will become faster :")) 
新(New):Notification.Builder來快速產生出來
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE );
Builder builder = new Notification.Builder(Update.this );
PendingIntent contentIndent = PendingIntent.getActivity(Update. this, 0, new Intent(Update.this , Update. class),PendingIntent. FLAG_UPDATE_CURRENT);
builder.setContentIntent(contentIndent)
       .setSmallIcon(R.drawable.icon) // 設置狀態列裡面的圖示          
       .setTicker("New Message") // 設置狀態列的顯示的資訊
       .setWhen(System. currentTimeMillis()) // 設置發生時間
       .setContentTitle( "I-Calories計算結果通知" )//設置通知清單裡的標題
       .setContentText("共消耗"+ca); // 設置內容
							  
Notification notification = builder.getNotification();
notificationManager.notify(1, notification);
設定預設提示音(notification.defaults to set default alarm ring)
notification.defaults |= Notification.DEFAULT_SOUND;//預設鈴聲
相關連結(good learning website) 更詳細可以點及這個很棒的網站作更深入的學習 http://magiclen.org/android-notifications/ 
http://www.codedata.com.tw/mobile/android-tutorial-the-5th-class-2-notificationhttp://givemepass.blogspot.tw/2011/11/notification.html 
http://blog.maxkit.com.tw/2014/03/android-notification.html

[Android] Vibrate 振動實作

Sometime we need to let the phone vibrate when receive a message or something happen
我們現在來進行實做 "振動" 這項功能
  Vibrator myVibrator = (Vibrator) getApplication().getSystemService(Service.VIBRATOR_SERVICE);
  myVibrator.vibrate(1000);//millisecond

Don't forget to add in your AndroidManifest.xml!!!!!
<uses-permission android:name="android.permission.VIBRATE" />

[Android] Toast

We have two method to use Toast 我們有兩種方式來顯示Toast

1.ToastActivity.this depends on this class name
 Toast toast = Toast.makeText(ToastActivity.this,"Hello world!", Toast.LENGTH_LONG);
 toast.show();
2.getApplicationContext()to get Current Context
 Context context1 = getApplication();
 Toast.makeText(context2, "Hello world!", Toast.LENGTH_LONG).show();