2015年5月7日 星期四

[Tool] web tools

QuickScreenShare
http://portable.easylife.tw/2790


[Android] Element Image or background setting

Android
ib_camStatus=(ImageButton) listView.getChildAt(camIndex).findViewById(R.id.ib_camStatus);

// ib_camStatus.setBackgroundResource(R.drawable.blue_point);   //背景
ib_camStatus.setImageResource(R.drawable.blue_point);                   //前景

xml
android:background="@drawable/blue_point"           //背景
//android:background="@android:color/transparent"    //背景透明
android:src="@drawable/red_point"                         //前景
related reference http://www.bkjia.com/Androidjc/866967.html


=========================================
//下行為設定
background.setBackgroundColor(Color.RED);
//或是
background.setBackgroundColor(Color.parseColor("色碼")

2015年5月5日 星期二

[Android] thread communicate with UI thread by using message

put A part in thread, A part will send messages to main thread(UI thread). That is a way for sub thread to communicate with UI Thread.
A part:
// mainHandler.sendEmptyMessage(0); 
 Bundle result = new Bundle();
 result.putInt("P2Pdone", 1); 
 Message msg = new Message();
 msg.setData(result);
 msg.what = 4; // message number
 mainHandler.sendMessage(msg);

B part:
class MainHandler extends Handler {
  static final int MSGTYPE_LOG =1;
  static final int MSGTYPE_P2PTUNNEL_LOG=2;
  static final int MSGTYPE_P2PLIVE_LOG=3;
  
  @Override
  public void handleMessage(Message msg) {  
   handleMsg(msg);
   super.handleMessage(msg);
  }
  
  void handleMsg(Message msg)
  {
   switch(msg.what){
    case MSGTYPE_LOG:    //1
     _printLog((String)msg.obj);
     break;
    
    case MSGTYPE_P2PTUNNEL_LOG:   //2
     {

     }
     break;
    case MSGTYPE_P2PLIVE_LOG:    //3 , ken
//     txt_log.append(data+"\n");
     txt_log.append(msg.getData().getString("data")+"\n");
     break;  
    case 4:    //4 , ken
     if(msg.getData().getInt("P2Pdone")==1){
      uiSwitch(SC_START);
     }
     
    default:;
   }
  }
 }

2015年4月29日 星期三

[Android] check APP exist or not

以VLC APP為例

private View.OnClickListener marketListener=new View.OnClickListener() {
  @Override
  public void onClick(View v) {
   if(isPackageExisted("org.videolan.vlc")){
       Toast.makeText(getApplicationContext(), "the APP is exist.", Toast.LENGTH_SHORT).show();        
   }else{             
               // 尋找某個應用程式  
               Uri uri = Uri.parse("market://search?q=pname:org.videolan.vlc"); 
               Intent it = new Intent(Intent.ACTION_VIEW, uri);  
               startActivity(it);  
   }
  }
 }; 
 public boolean isPackageExisted(String targetPackage){
     PackageManager pm=getPackageManager();
     try {
      PackageInfo info=pm.getPackageInfo(targetPackage,PackageManager.GET_META_DATA);
         } catch (NameNotFoundException e) {
      return false;
      }
      return true;
 }

2015年4月21日 星期二