工具代碼整理_1

1.如何求兩個整數的百分比

  1. int currentindex = 55;  
  2. int totalcount = 66;  
  3. NumberFormat nf = NumberFormat.getPercentInstance();  
  4. final String persent = nf.format(((float)currentindex/(float)totalcount));  


2.從一個鏈接中獲取域名

  1. String url = "http://blog.csdn.net/zuolongsnail";  
  2. Pattern p = Pattern.compile(  
  3.         "(?<=http://|\\.)[^.]*?\\.(com|cn|net|org|biz|info|cc|tv)",  
  4.         Pattern.CASE_INSENSITIVE);  
  5. Matcher matcher = p.matcher(url);  
  6. matcher.find();  
  7. System.out.println(matcher.group());  


3.顯示年月日時分秒星期

  1. Date date = new Date();  
  2. SimpleDateFormat dateformat = new SimpleDateFormat(  
  3.         "yyyy年MM月dd日 HH時mm分ss秒 E");  
  4. String dateStr = dateformat.format(date);  
  5. System.out.println(dateStr);  

4.顯示年月日時分秒毫秒
  1. Date date = new Date();  
  2. SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日HH時mm分ss秒SSS");  
  3. String dateStr = sdf.format(date);  
  4. System.out.println(dateStr);  


5.發送多條短信

  1. PendingIntent sentPI = PendingIntent.getBroadcast(context,  
  2.         System.identityHashCode(intent), intent, 0);  
  3. SmsManager smsManager = SmsManager.getDefault();  
  4. // 超過70字分段發送  
  5. if (text.length() > 70) {  
  6.     ArrayList<PendingIntent> sentPIs = new ArrayList<PendingIntent>();  
  7.     sentPIs.add(sentPI);  
  8.     smsManager.sendMultipartTextMessage(destAdress, null,  
  9.             smsManager.divideMessage(text), sentPIs, null);  
  10. else {  
  11.     smsManager.sendTextMessage(destAdress, null, text, sentPI, null);  
  12. }  


6.屏蔽多點觸摸

  1. android:splitMotionEvents="false"  
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章