工具代码整理_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"  
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章