﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-信心比金钱更重要！-随笔分类-Android基础</title><link>http://www.cppblog.com/luofeng225/category/18036.html</link><description>目标明确==&gt;&gt;&gt;计划跟踪==&gt;&gt;&gt;行动执行！</description><language>zh-cn</language><lastBuildDate>Tue, 23 Oct 2012 00:23:17 GMT</lastBuildDate><pubDate>Tue, 23 Oct 2012 00:23:17 GMT</pubDate><ttl>60</ttl><item><title>TextView 加链接所有方法</title><link>http://www.cppblog.com/luofeng225/archive/2012/05/18/175274.html</link><dc:creator>luofeng</dc:creator><author>luofeng</author><pubDate>Fri, 18 May 2012 01:50:00 GMT</pubDate><guid>http://www.cppblog.com/luofeng225/archive/2012/05/18/175274.html</guid><wfw:comment>http://www.cppblog.com/luofeng225/comments/175274.html</wfw:comment><comments>http://www.cppblog.com/luofeng225/archive/2012/05/18/175274.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/luofeng225/comments/commentRss/175274.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/luofeng225/services/trackbacks/175274.html</trackback:ping><description><![CDATA[<a href="http://blog.csdn.net/a54cc/article/details/6447447"><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 12pt; line-height: 30px; font-family: 'Microsoft YaHei'; text-align: left"></a><a style="color: rgb(0,0,0); text-decoration: none" href="http://blog.csdn.net/a54cc/article/details/6447447">TextView 加链接所有方法</a><br /><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(51,51,51); line-height: 26px; font-family: Arial; text-align: left">1：使用android:autoLink="all" 只需在textview中加入这个属性 在里面写的文字中包含网址、电话、email的会自动加入连接地址。</span></span><br /><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(51,51,51); line-height: 26px; font-family: Arial; text-align: left">2：uses a string resource containing explicit &lt;a&gt; tags to specify<br />links.<br />同时设置<span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(51,51,51); line-height: 26px; font-family: Arial; text-align: left">textView.setMovementMethod(LinkMovementMethod.getInstance());</span></span><br /></span></span><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(51,51,51); line-height: 26px; font-family: Arial; text-align: left">&nbsp;注意格式：&lt;a href<strong>="http://www.google.com</strong>"&gt;link&lt;/a&gt;&nbsp; &nbsp;&#8220;http://&#8221; 不可少。<br /></span></span><br /><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(51,51,51); line-height: 26px; font-family: Arial; text-align: left">3： builds the text in the Java code using HTML<br /></span></span><font color="#333333"><font face="Arial">同时设置<span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(51,51,51); line-height: 26px; font-family: Arial; text-align: left">textView.setMovementMethod(LinkMovementMethod.getInstance());</span></span></font></font><br /><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(51,51,51); line-height: 26px; font-family: Arial; text-align: left">4：字符串截取方法 <font color="#333333">SpannableString <br /></font><font color="#333333">同时设置<span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(51,51,51); line-height: 26px; font-family: Arial; text-align: left">textView.setMovementMethod(LinkMovementMethod.getInstance());</span></span></font><br /><br />SpannableString ss = new SpannableString("text4: Click here to dial the phone.");<br /><br />ss.setSpan(new StyleSpan(Typeface.BOLD), 0, 6, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);<br />ss.setSpan(new URLSpan("tel:4155551212"), 13, 17, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);</span></span><br />link<br />ApiDemo <a href="http://blog.csdn.net/a54cc/article/details/6447447"></span></span><br />http://blog.csdn.net/a54cc/article/details/6447447</a><img src ="http://www.cppblog.com/luofeng225/aggbug/175274.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/luofeng225/" target="_blank">luofeng</a> 2012-05-18 09:50 <a href="http://www.cppblog.com/luofeng225/archive/2012/05/18/175274.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>BroadcastReceiver</title><link>http://www.cppblog.com/luofeng225/archive/2012/05/07/173884.html</link><dc:creator>luofeng</dc:creator><author>luofeng</author><pubDate>Mon, 07 May 2012 03:01:00 GMT</pubDate><guid>http://www.cppblog.com/luofeng225/archive/2012/05/07/173884.html</guid><wfw:comment>http://www.cppblog.com/luofeng225/comments/173884.html</wfw:comment><comments>http://www.cppblog.com/luofeng225/archive/2012/05/07/173884.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/luofeng225/comments/commentRss/173884.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/luofeng225/services/trackbacks/173884.html</trackback:ping><description><![CDATA[<a href="http://blog.csdn.net/liuhe688/article/details/6955668">http://blog.csdn.net/liuhe688/article/details/6955668</a><br /><br /><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px">
<p><strong>BroadcastReceiver</strong>也就是&#8220;广播接收者&#8221;的意思，顾名思义，它就是用来接收来自系统和应用中的广播。</p>
<p>在Android系统中，广播体现在方方面面，例如当开机完成后系统会产生一条广播，接收到这条广播就能实现开机启动服务的功能；当网络状态改变时系统会产生一条广播，接收到这条广播就能及时地做出提示和保存数据等操作；当电池电量改变时，系统会产生一条广播，接收到这条广播就能在电量低时告知用户及时保存进度，等等。</p></span><br /><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px">&nbsp; 
<p><strong>静态注册</strong><br /></p>
<p>静态注册是在AndroidManifest.xml文件中配置的，注意，这种方式的注册是常驻型的，也就是说当应用关闭后，如果有广播信息传来，MyReceiver也会被系统调用而自动运行。<br /><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"></p>
<p><strong>动态注册</strong></p>
<p>动态注册需要在代码中动态的指定广播地址并注册，通常我们是在Activity或Service注册一个广播》<br />注意，registerReceiver是android.content.ContextWrapper类中的方法，Activity和Service都继承了ContextWrapper，所以可以直接调用。在实际应用中，我们在Activity或Service中注册了一个BroadcastReceiver，当这个Activity或Service被销毁时如果没有解除注册，系统会报一个异常，提示我们是否忘记解除注册了。所以，记得在特定的地方执行解除注册操作：<br /><br /><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><strong><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"></p>
<p><strong>普通广播（Normal Broadcast）<br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-weight: bold; font-size: 14px; color: rgb(44,44,44); line-height: 28px; font-family: 宋体, 'Arial Narrow', arial, serif">用<span class="Apple-converted-space">&nbsp;</span><font style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px" color="#0000ff"><code style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">Context.sendBroadcast</code>()</font>发送</span></span></strong></p>
<p>普通广播对于多个接收者来说是完全异步的，通常每个接收者都无需等待即可以接收到广播，接收者相互之间不会有影响。对于这种广播，接收者无法终止广播，即无法阻止其他接收者的接收动作。<br /></p>
<p></span><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"></p>
<p><strong><br />有序广播（Ordered Broadcast）<br /></strong></p>
<p><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-weight: bold; font-size: 14px; color: rgb(44,44,44); line-height: 28px; font-family: 宋体, 'Arial Narrow', arial, serif">用<span class="Apple-converted-space">&nbsp;</span><code style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"><font style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px" color="#0000ff">Context.sendOrderedBroadcast()</font></code>发送</span></span>有序广播比较特殊，它每次只发送到优先级较高的接收者那里，然后由优先级高的接受者再传播到优先级低的接收者那里，优先级高的接收者有能力终止这个广播。<br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-weight: bold; font-size: 14px; color: rgb(44,44,44); line-height: 28px; font-family: 宋体, 'Arial Narrow', arial, serif"><u>运行的顺序可以通过matched intent-filter 里面的android:priority来控制，当priority优先级相同的时候，Receiver以任意的顺序运行。<br /></u></span></span></p>
<p></span><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(44,44,44); line-height: 28px; font-family: 宋体, 'Arial Narrow', arial, serif"><strong style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"><font style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px" color="#0000ff"><br /><br />Permission权限</font></strong><br style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px" />&nbsp; 要接收某些action，需要在AndroidManifest.xml里面添加相应的permission。例如接收SMS:<br /></span></span><br />===============<br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(44,44,44); line-height: 28px; font-family: 宋体, 'Arial Narrow', arial, serif"></p>
<div style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">小结：</div>
<ul><li>
<div style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">. 推荐使用显式指明receiver，在配置文件AndroidManifest.xml指明；&nbsp;<br />. 每次接收广播都会重新生成一个接收广播的对象，再次调用onReceive；</div></li><li>
<div style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">. 在BroadCast 中尽量不要处理太多逻辑问题，建议复杂的逻辑交给Activity 或者 Service 去处理。</div></li></ul></span></span>
<p><br /><br />========================<br />利用Application动态注册 和 androidMenifeist.xml静态注册区别<br />退出程序，利用Application动态注册收不到广播。<br /><br /><br /><br /></p></strong></span></span></span><img src ="http://www.cppblog.com/luofeng225/aggbug/173884.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/luofeng225/" target="_blank">luofeng</a> 2012-05-07 11:01 <a href="http://www.cppblog.com/luofeng225/archive/2012/05/07/173884.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>android 电源管理</title><link>http://www.cppblog.com/luofeng225/archive/2012/05/02/173451.html</link><dc:creator>luofeng</dc:creator><author>luofeng</author><pubDate>Wed, 02 May 2012 03:49:00 GMT</pubDate><guid>http://www.cppblog.com/luofeng225/archive/2012/05/02/173451.html</guid><description><![CDATA[<span style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span style="font-size: 12px; color: rgb(59,59,59); line-height: 21px; font-family: Arial, 宋体, sans-serif">
<p style="word-break: break-all" align="left"><span style="word-break: break-all; font-family: 宋体"><span style="font-size: medium">应用层的使用</span></span><span style="word-break: break-all"><span style="word-break: break-all; font-family: 'Times New Roman'"><span style="font-size: medium">:</span></span></span></p>
<p style="word-break: break-all" align="left"><span style="word-break: break-all"><span style="word-break: break-all; font-family: 'Times New Roman'"><span style="font-size: medium">Android</span></span></span><span style="word-break: break-all; font-family: 宋体"><span style="font-size: medium">提供了现成</span></span><span style="word-break: break-all"><span style="word-break: break-all; font-family: 'Times New Roman'"><span style="font-size: medium">android.os.PowerManager</span></span></span><span style="word-break: break-all; font-family: 宋体"><span style="font-size: medium">类</span></span><span style="word-break: break-all"><span style="word-break: break-all; font-family: 'Times New Roman'"><span style="font-size: medium">,</span></span></span><span style="word-break: break-all; font-family: 宋体"><span style="font-size: medium">该类用于控制设备的电源状态的切换</span></span><span style="word-break: break-all"><span style="word-break: break-all; font-family: 'Times New Roman'"><span style="font-size: medium">.</span></span></span></p></span></span><br />代码：<br />
<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="color: #000000">PowerManager&nbsp;pm&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(PowerManager)&nbsp;getSystemService(Context.POWER_SERVICE);<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />&nbsp;PowerManager.WakeLock&nbsp;wl&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK,&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">My&nbsp;Tag</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />&nbsp;wl.acquire();<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;..screen&nbsp;will&nbsp;stay&nbsp;on&nbsp;during&nbsp;</span><span style="color: #0000ff">this</span><span style="color: #000000">&nbsp;section..<br /><img alt="" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />&nbsp;wl.release();</span></div><br /><br />权限要求：<br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 13px; color: rgb(51,51,51); font-family: arial, sans-serif"><font face="Courier New"><font size="4"><font color="#ff0000">&nbsp;&nbsp;<span class="Apple-style-span" style="font-size: medium">&lt;uses-permission android:name=</span></font></font><font color="#ff0000"><em style="word-break: break-all"><span class="Apple-style-span" style="font-size: medium">"android.permission.WAKE_LOCK"</span></em><span class="Apple-style-span" style="font-size: medium">&nbsp;/&gt;</span></font></font> 
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; word-break: break-all; text-indent: 18pt" align="left"><span lang="EN-US" style="color: red; word-break: break-all; font-family: 'Courier New'"><span class="Apple-style-span" style="font-size: medium">&lt;uses-permission android:name=</span><em style="word-break: break-all"><span class="Apple-style-span" style="font-size: medium">"android.permission.DEVICE_POWER"</span></em><span class="Apple-style-span" style="font-size: medium">&nbsp;/&gt;</span></span></p><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 12px; color: rgb(59,59,59); line-height: 21px; font-family: Arial, 宋体, sans-serif; text-align: left">
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; word-break: break-all" align="left"><span lang="EN-US" style="color: red; word-break: break-all"><span style="word-break: break-all; font-family: 'Times New Roman'"><span class="Apple-style-span" style="font-size: medium"><br /></span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; word-break: break-all" align="left"><span lang="EN-US" style="color: red; word-break: break-all"><span style="word-break: break-all; font-family: 'Times New Roman'"><span class="Apple-style-span" style="font-size: medium"></span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; word-break: break-all; text-align: left" align="left"><span style="color: red; word-break: break-all; font-family: 宋体"><span class="Apple-style-span" style="font-size: medium">注意：<br />所有的锁必须成对的使用</span></span><span lang="EN-US" style="color: red; word-break: break-all; font-family: 'Courier New'"><span class="Apple-style-span" style="font-size: medium">,</span></span><span style="color: red; word-break: break-all; font-family: 宋体"><span class="Apple-style-span" style="font-size: medium">如果申请了而没有及时释放会造成系统故障</span></span><span lang="EN-US" style="color: red; word-break: break-all; font-family: 'Courier New'"><span class="Apple-style-span" style="font-size: medium">.</span></span><span style="color: red; word-break: break-all; font-family: 宋体"><span class="Apple-style-span" style="font-size: medium">如申请了</span></span><span lang="EN-US" style="color: red; word-break: break-all; font-family: 'Courier New'"><span class="Apple-style-span" style="font-size: medium">partial wakelock,</span></span><span style="color: red; word-break: break-all; font-family: 宋体"><span class="Apple-style-span" style="font-size: medium">而没有及时释放</span></span><span lang="EN-US" style="color: red; word-break: break-all; font-family: 'Courier New'"><span class="Apple-style-span" style="font-size: medium">,</span></span><span style="color: red; word-break: break-all; font-family: 宋体"><span class="Apple-style-span" style="font-size: medium">那系统就永远进不了</span></span><span lang="EN-US" style="color: red; word-break: break-all; font-family: 'Courier New'"><span class="Apple-style-span" style="font-size: medium">Sleep</span></span><span style="color: red; word-break: break-all; font-family: 宋体"><span class="Apple-style-span" style="font-size: medium">模式</span></span><span lang="EN-US" style="color: red; word-break: break-all; font-family: 'Courier New'"><span class="Apple-style-span" style="font-size: medium">.</span></span></p></span></span></span></span><br /><br /><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 12px; color: rgb(59,59,59); line-height: 21px; font-family: Arial, 宋体, sans-serif"><span lang="EN-US" style="word-break: break-all"><span style="word-break: break-all; font-family: 'Times New Roman'"><span class="Apple-style-span" style="font-size: medium">Android framework</span></span></span><span style="word-break: break-all; font-family: 宋体"><span class="Apple-style-span" style="font-size: medium">层面|<br /></span></span><span lang="EN-US" style="word-break: break-all"><span style="word-break: break-all; font-family: 'Times New Roman'"><span class="Apple-style-span" style="font-size: medium">》》》》<br /><a href="http://www.cnblogs.com/jacktu/archive/2010/07/07/1773011.html">http://www.cnblogs.com/jacktu/archive/2010/07/07/1773011.html</a><br />&nbsp;Linux</span></span></span><span style="word-break: break-all; font-family: 宋体"><span class="Apple-style-span" style="font-size: medium">内核层面</span></span></span></span> <img src ="http://www.cppblog.com/luofeng225/aggbug/173451.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/luofeng225/" target="_blank">luofeng</a> 2012-05-02 11:49 <a href="http://www.cppblog.com/luofeng225/archive/2012/05/02/173451.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Jni记录</title><link>http://www.cppblog.com/luofeng225/archive/2012/04/26/172851.html</link><dc:creator>luofeng</dc:creator><author>luofeng</author><pubDate>Thu, 26 Apr 2012 11:35:00 GMT</pubDate><guid>http://www.cppblog.com/luofeng225/archive/2012/04/26/172851.html</guid><wfw:comment>http://www.cppblog.com/luofeng225/comments/172851.html</wfw:comment><comments>http://www.cppblog.com/luofeng225/archive/2012/04/26/172851.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/luofeng225/comments/commentRss/172851.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/luofeng225/services/trackbacks/172851.html</trackback:ping><description><![CDATA[&nbsp;<br /> JNI技术的出现主要是基于三个方面的应用需求： 
<p><font size="3">1. 解决性能问题</font><font size="3"><br />2. 解决本机平台接口调用问题<br />3. 嵌入式开发应用<br /><br /><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 13px; font-family: 'Microsoft YaHei', Verdana, Tahoma, 'Lucida Grande', Arial, sans-serif"><strong>生成头文件&nbsp;</strong>
<p style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 10px; line-height: 23px; padding-top: 0px; border-right-width: 0px">可以用javah命令来自动生成JNI的头文件，这样可以省事很多的，进入命令行，切换到项目的bin目录下，执行命令：</p>
<blockquote style="border-right: rgb(191,223,255) 1px dashed; padding-right: 10px; border-top: rgb(191,223,255) 1px dashed; padding-left: 10px; padding-bottom: 10px; margin: 10px 0px; border-left: rgb(191,223,255) 1px dashed; padding-top: 10px; border-bottom: rgb(191,223,255) 1px dashed; background-color: rgb(245,251,255); background-origin: initial; background-clip: initial">
<p style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 10px; line-height: 23px; padding-top: 0px; border-right-width: 0px"><strong style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px; border-right-width: 0px">javah -classpath . -jni 包.类名</strong></p></blockquote>
<p style="border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; border-bottom-width: 0px; padding-bottom: 0px; margin: 0px 0px 10px; line-height: 23px; padding-top: 0px; border-right-width: 0px">命令执行完以后会在bin目录下面生成一.h头文件，然后将该.h头文件拷贝到你要编写的C/C++目录下面去吧。<br /><br /><strong>方法签名<br /></strong><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 13px; color: rgb(51,51,51); line-height: 17px; font-family: verdana, sans-serif; border-collapse: collapse; webkit-border-horizontal-spacing: 2px; webkit-border-vertical-spacing: 2px"><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 13px; color: rgb(51,51,51); line-height: 17px; font-family: verdana, sans-serif; border-collapse: collapse; webkit-border-horizontal-spacing: 2px; webkit-border-vertical-spacing: 2px">使用JNI在native内调用java方法时，需要知道java方法的方法签名，利用javap工具可以方便的生成签名。由于java方法签名在jni层的表示方法的复杂性，利用这个工具生成签名信息可以避免人工分析带来的错误。</span></span><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 13px; color: rgb(51,51,51); line-height: 17px; font-family: verdana, sans-serif; border-collapse: collapse; webkit-border-horizontal-spacing: 2px; webkit-border-vertical-spacing: 2px">javap -s -p -classpath .<span class="Apple-converted-space">&nbsp;<strong>类名<br /><br /><span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 13px; color: rgb(51,51,51); line-height: 17px; font-family: verdana, sans-serif; border-collapse: collapse; webkit-border-horizontal-spacing: 2px; webkit-border-vertical-spacing: 2px">-s表示打印签名信息<br />-p表示打印所有函数和成员的签名信息，默认只打印public的签名信息。<br />注意：<br />粗体部分是.class文件的文件名，不要.class后缀，<br /><br />必备资料：<br />jni手册<br /><br /><br /></span></span></strong></span></span></span></span></span></span></span></font></p> <img src ="http://www.cppblog.com/luofeng225/aggbug/172851.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/luofeng225/" target="_blank">luofeng</a> 2012-04-26 19:35 <a href="http://www.cppblog.com/luofeng225/archive/2012/04/26/172851.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>java.lang.UnsatisfiedLinkError ，jni</title><link>http://www.cppblog.com/luofeng225/archive/2012/04/21/172250.html</link><dc:creator>luofeng</dc:creator><author>luofeng</author><pubDate>Sat, 21 Apr 2012 08:04:00 GMT</pubDate><guid>http://www.cppblog.com/luofeng225/archive/2012/04/21/172250.html</guid><wfw:comment>http://www.cppblog.com/luofeng225/comments/172250.html</wfw:comment><comments>http://www.cppblog.com/luofeng225/archive/2012/04/21/172250.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/luofeng225/comments/commentRss/172250.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/luofeng225/services/trackbacks/172250.html</trackback:ping><description><![CDATA[<div><br /><strong>java.lang.UnsatisfiedLinkError</strong><br /><br /><div>01-01 09:24:00.119: ERROR/AndroidRuntime(766): java.lang.UnsatisfiedLinkError: nativeRelease<br /><br />原因之一：动态库中没有这个jni函数。</div></div><img src ="http://www.cppblog.com/luofeng225/aggbug/172250.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/luofeng225/" target="_blank">luofeng</a> 2012-04-21 16:04 <a href="http://www.cppblog.com/luofeng225/archive/2012/04/21/172250.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>TranslateAnimation</title><link>http://www.cppblog.com/luofeng225/archive/2012/04/21/172235.html</link><dc:creator>luofeng</dc:creator><author>luofeng</author><pubDate>Sat, 21 Apr 2012 06:20:00 GMT</pubDate><guid>http://www.cppblog.com/luofeng225/archive/2012/04/21/172235.html</guid><description><![CDATA[<div><span style="color: #aaaaaa; font-family: georgia, Verdana, Helvetica, Arial; font-size: 13px; line-height: 19px; "><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span style="color: #000000; ">Android JDK为我们提供了4种动画效果，分别是：<br />&nbsp;AlphaAnimation,<br />RotateAnimation,&nbsp;<br />ScaleAnimation,&nbsp;<br />TranslateAnimation.今天我想讲解的是TranslateAnimation这个动画效果。<br />在本文中记录下来，以便以后忘记了可以查阅。</span></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span style="color: #000000; ">　　TranslateAnimation是移动的动画效果。它有三个构造函数，分别是：</span></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span style="color: #000000; ">　　1.public　　TranslateAnimation(Context context,AttributeSet attrs) &nbsp;&nbsp;略过</span></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span style="color: #000000; ">　　<br />&nbsp;&nbsp; &nbsp; &nbsp; 2.public　　TranslateAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta)</span></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span style="color: #000000; ">　　这个是我们最常用的一个构造方法，</span></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span style="color: #000000; ">　　float fromXDelta:这个参数表示动画开始的点离当前View X坐标上的差值；</span></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span style="color: #000000; ">　　float toXDelta, 这个参数表示动画结束的点离当前View X坐标上的差值；</span></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span style="color: #000000; ">　　float fromYDelta, 这个参数表示动画开始的点离当前View Y坐标上的差值；</span></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span style="color: #000000; ">　　float toYDelta)这个参数表示动画开始的点离当前View Y坐标上的差值；</span></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span style="color: #000000; ">　　如果view在A(x,y)点 那么动画就是从B点(x+fromXDelta, y+fromYDelta)点移动到C 点(x+toXDelta,y+toYDelta)点.</span></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><br /></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span style="color: #000000; ">　<strong>　3.public　　TranslateAnimation&nbsp;(int fromXType, float fromXValue, int toXType, float toXValue, int fromYType, float</strong> fromYValue, int toYType, float toYValue)</span></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span style="color: #000000; ">　　fromXType:第一个参数是x轴方向的值的参照(Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF,or Animation.RELATIVE_TO_PARENT);</span></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span style="color: #000000; ">　　fromXValue:第二个参数是第一个参数类型的起始值；</span></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span style="color: #000000; ">　　toXType,toXValue:第三个参数与第四个参数是x轴方向的终点参照与对应值；</span></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span style="color: #000000; ">　　后面四个参数就不用解释了。如果全部选择Animation.ABSOLUTE，其实就是第二个构造函数。</span></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span style="color: #000000; ">&nbsp; &nbsp; &nbsp; 以x轴为例介绍参照与对应值的关系:</span></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span style="color: #000000; ">&nbsp; &nbsp; &nbsp; 如果选择参照为Animation.ABSOLUTE，那么对应的值应该是具体的坐标值，比如100到300，指绝对的屏幕像素单位</span></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px; "><span style="color: #000000; ">&nbsp; &nbsp; &nbsp; 如果选择参照为Animation.RELATIVE_TO_SELF或者&nbsp;Animation.RELATIVE_TO_PARENT指的是相对于自身或父控件，对应值应该理解为相对于自身或者父控件的几倍或百分之多少。多试参数就明白了</span></p></span></div><img src ="http://www.cppblog.com/luofeng225/aggbug/172235.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/luofeng225/" target="_blank">luofeng</a> 2012-04-21 14:20 <a href="http://www.cppblog.com/luofeng225/archive/2012/04/21/172235.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>退出程序</title><link>http://www.cppblog.com/luofeng225/archive/2012/04/09/170595.html</link><dc:creator>luofeng</dc:creator><author>luofeng</author><pubDate>Mon, 09 Apr 2012 08:50:00 GMT</pubDate><guid>http://www.cppblog.com/luofeng225/archive/2012/04/09/170595.html</guid><description><![CDATA[<div><span style="color: #333333; font-family: Arial; line-height: 26px; "><br />第一种方法：首先获取当前进程的id，然后杀死该进程。 （建议使用）&nbsp;<br />android.os.Process.killProcess(android.os.Process.myPid())<br />&nbsp;</span></div><div><span style="color: #333333; font-family: Arial; line-height: 26px; ">第二种方法：终止当前正在运行的Java虚拟机，导致程序终止&nbsp;<br />System.exit(0);&nbsp;</span></div><br /><br /><div><div><span style="white-space:pre">		</span>//*******，完全退出程序</div><div><span style="white-space:pre">		</span>System.runFinalization();</div><div><span style="white-space:pre">		</span>System.gc();</div><div><span style="white-space:pre">		</span>//此方法会导致app进程完全退出，若不需要完全退出的app可以不调此方法</div><div><span style="white-space:pre">		</span>System.exit(0);&nbsp;<br /></div></div><div><div><span style="color: #333333; font-family: Arial; line-height: 26px; ">第三种方法：强制关闭与该包有关联的一切执行&nbsp;<br />ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);&nbsp;&nbsp;&nbsp;&nbsp;<br />manager.restartPackage(getPackageName());&nbsp;<br />&lt;uses-permission android:name="android.permission.RESTART_PACKAGES" /&gt;&nbsp;<br /><br />但是以上在android2.2以前的版本都成测试成功，而android 2.2会有BUG 但是关闭应用的所有activity 可以通过：每打开一个activity 就调用finish（），之后退出时候只关闭当前的就行了！该方法我的项目正在使用 大量测试没有BUG<br /><a href="http://blog.csdn.net/ssstudio/article/details/6216894">http://blog.csdn.net/ssstudio/article/details/6216894<br /></a><br />连环退出。<br /><br /><br /><div><a href="http://blog.csdn.net/ssstudio/article/details/6216894"><br /></a></div></span></div></div><img src ="http://www.cppblog.com/luofeng225/aggbug/170595.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/luofeng225/" target="_blank">luofeng</a> 2012-04-09 16:50 <a href="http://www.cppblog.com/luofeng225/archive/2012/04/09/170595.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>save() 和 restore()</title><link>http://www.cppblog.com/luofeng225/archive/2012/03/31/169652.html</link><dc:creator>luofeng</dc:creator><author>luofeng</author><pubDate>Sat, 31 Mar 2012 06:59:00 GMT</pubDate><guid>http://www.cppblog.com/luofeng225/archive/2012/03/31/169652.html</guid><wfw:comment>http://www.cppblog.com/luofeng225/comments/169652.html</wfw:comment><comments>http://www.cppblog.com/luofeng225/archive/2012/03/31/169652.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/luofeng225/comments/commentRss/169652.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/luofeng225/services/trackbacks/169652.html</trackback:ping><description><![CDATA[<div><span style="color: #333333; font-family: Arial; line-height: 26px; "><p><br />在创建新的控件或修改现有的控件时，我们都会涉及到重写控件或View的onDraw方法。</p><p>onDraw方法会传入一个Canvas对象，它是你用来绘制控件视觉界面的画布。</p><p>在onDraw方法里，我们经常会看到调用save和restore方法，它们到底是干什么用的呢？</p><p>❑ save：用来保存Canvas的状态。save之后，可以调用Canvas的平移、放缩、旋转、错切、裁剪等操作。</p><p>❑ restore：用来恢复Canvas之前保存的状态。防止save后对Canvas执行的操作对后续的绘制有影响。</p><p>save和restore要配对使用（restore可以比save少，但不能多），如果restore调用次数比save多，会引发Error。<br /><br /><br /><div><p>save和restore之间，往往夹杂的是对Canvas的特殊操作。canvas可能会做旋转，平移，切割等动作，然后为了让这些动作只在特定的一个程序段产生作用，不会影响下面你需要继续画的物体，</p></div></p></span></div><img src ="http://www.cppblog.com/luofeng225/aggbug/169652.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/luofeng225/" target="_blank">luofeng</a> 2012-03-31 14:59 <a href="http://www.cppblog.com/luofeng225/archive/2012/03/31/169652.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>内存泄露</title><link>http://www.cppblog.com/luofeng225/archive/2012/03/31/169611.html</link><dc:creator>luofeng</dc:creator><author>luofeng</author><pubDate>Sat, 31 Mar 2012 01:09:00 GMT</pubDate><guid>http://www.cppblog.com/luofeng225/archive/2012/03/31/169611.html</guid><wfw:comment>http://www.cppblog.com/luofeng225/comments/169611.html</wfw:comment><comments>http://www.cppblog.com/luofeng225/archive/2012/03/31/169611.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/luofeng225/comments/commentRss/169611.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/luofeng225/services/trackbacks/169611.html</trackback:ping><description><![CDATA[<br /><div><span style="font-family: Arial; line-height: 26px; ">泄漏 是指你保持一个引用并不让GC(垃圾回收机制)回收它。<br /><br /><div>Android应用程序的内存泄漏问题</div><div><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "></p><div>Context有关的内存泄露<br /></div>为了避免于Context有关的内存泄露，记住以下几点:<p>&nbsp;</p><ol><li>不要保持一个长寿命的Activity的Context的引用（一个Activity的引用的寿命应该和这个Activity一样长）</li><li>试试使用Application Context代替Activity Context</li><li>如果你不想控制他们的生命周期，避免在一个Activity内使用非静态的内部类，使用静态的内部类并且使用对Activity的弱引用。这个情况的做法是使用一个含有到外部的WeakReference的静态的内部类。就好像在ViewRoot和他的W内部类一样。</li><li>垃圾处理机制不是制服内存泄露的终极保险</li></ol></div></span></div><img src ="http://www.cppblog.com/luofeng225/aggbug/169611.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/luofeng225/" target="_blank">luofeng</a> 2012-03-31 09:09 <a href="http://www.cppblog.com/luofeng225/archive/2012/03/31/169611.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>对Android初学者学习中的几点建议【转】</title><link>http://www.cppblog.com/luofeng225/archive/2012/03/29/169447.html</link><dc:creator>luofeng</dc:creator><author>luofeng</author><pubDate>Thu, 29 Mar 2012 10:00:00 GMT</pubDate><guid>http://www.cppblog.com/luofeng225/archive/2012/03/29/169447.html</guid><wfw:comment>http://www.cppblog.com/luofeng225/comments/169447.html</wfw:comment><comments>http://www.cppblog.com/luofeng225/archive/2012/03/29/169447.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/luofeng225/comments/commentRss/169447.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/luofeng225/services/trackbacks/169447.html</trackback:ping><description><![CDATA[<br /><div><span style="font-family: 'Microsoft YaHei'; font-size: 20px; line-height: 30px; "><a href="http://blog.csdn.net/aomandeshangxiao/article/details/6723649" style="color: #000000; text-decoration: none; ">对Android初学者学习中的几点建议<br /></a><div><a href="http://blog.csdn.net/aomandeshangxiao/article/details/6723649">http://blog.csdn.net/aomandeshangxiao/article/details/6723649</a></div><a href="http://blog.csdn.net/aomandeshangxiao/article/details/6723649"></a></span></div><img src ="http://www.cppblog.com/luofeng225/aggbug/169447.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/luofeng225/" target="_blank">luofeng</a> 2012-03-29 18:00 <a href="http://www.cppblog.com/luofeng225/archive/2012/03/29/169447.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Adb connection Error:远程主机强迫关闭了一个现有的连接 。</title><link>http://www.cppblog.com/luofeng225/archive/2012/03/27/169175.html</link><dc:creator>luofeng</dc:creator><author>luofeng</author><pubDate>Tue, 27 Mar 2012 09:30:00 GMT</pubDate><guid>http://www.cppblog.com/luofeng225/archive/2012/03/27/169175.html</guid><wfw:comment>http://www.cppblog.com/luofeng225/comments/169175.html</wfw:comment><comments>http://www.cppblog.com/luofeng225/archive/2012/03/27/169175.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/luofeng225/comments/commentRss/169175.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/luofeng225/services/trackbacks/169175.html</trackback:ping><description><![CDATA[<div><h3><a href="http://blog.csdn.net/droid_zhlu/article/details/6645059"><br />Adb connection Error:远程主机强迫关闭了一个现有的连接&nbsp;<br /><span class="Apple-style-span" style="font-weight: normal;"><br /></span></a><div><p><span class="Apple-style-span" style="font-weight: normal;">调试程序的时候，eclipse的console总是出现如下的错误&#8220;<br /><em>Adb connection  Error:远程主机强迫关闭了一个现有的连接</em>&#8221;</span></p> <p><span class="Apple-style-span" style="font-weight: normal;"><br /></span></p> <p><span class="Apple-style-span" style="font-weight: normal;"><span style="color: #333333; line-height: 18px; font-family: Verdana,Helvetica,Arial,Geneva,sans-serif">问题出现的原因：这是ddms调用adb引发的.  经过一番搜索, 发现这是windows环境下, adb的一个限制, 也可以说是bug. &nbsp;当手机上同时运行的进程数大于64时, 就会引发adb奔溃.  更深层次的原因, 就是windows API的WaitForMultipleObjects所支持的最大句柄数是MAXIMUM_WAIT_OBJECTS,  即64.</span><br /></span></p> <p><span style="color: #333333; line-height: 18px; font-family: Verdana, Helvetica, Arial, Geneva, sans-serif; font-weight: normal;"><br /></span></p> <p><span style="color: #333333; line-height: 18px; font-family: Verdana, Helvetica, Arial, Geneva, sans-serif; font-weight: normal;">解决办法：<a href="http://code.google.com/p/android/issues/detail?id=12141">http://code.google.com/p/android/issues/detail?id=12141</a></span></p> <p><span class="Apple-style-span" style="font-weight: normal;"><br /></span></p> <p><span class="Apple-style-span" style="font-weight: normal; ">&nbsp;&nbsp;下载相应的adb.exe文件，用它替换掉你机器上的sdk的platform/tools目录下面的adb.exe。这样就可以完美解决问题。<br /><br />=========经过我尝试果然OK.<br /><br /><br /><br /></span></p></div><a href="http://blog.csdn.net/droid_zhlu/article/details/6645059"></a></h3></div><img src ="http://www.cppblog.com/luofeng225/aggbug/169175.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/luofeng225/" target="_blank">luofeng</a> 2012-03-27 17:30 <a href="http://www.cppblog.com/luofeng225/archive/2012/03/27/169175.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>正则表达式的分组和引用  tt</title><link>http://www.cppblog.com/luofeng225/archive/2012/03/23/168697.html</link><dc:creator>luofeng</dc:creator><author>luofeng</author><pubDate>Fri, 23 Mar 2012 02:08:00 GMT</pubDate><guid>http://www.cppblog.com/luofeng225/archive/2012/03/23/168697.html</guid><wfw:comment>http://www.cppblog.com/luofeng225/comments/168697.html</wfw:comment><comments>http://www.cppblog.com/luofeng225/archive/2012/03/23/168697.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/luofeng225/comments/commentRss/168697.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/luofeng225/services/trackbacks/168697.html</trackback:ping><description><![CDATA[<div><span style="font-family: Arial, Helvetica, simsun, u5b8bu4f53; font-size: 12px; line-height: normal; "><h3><span style="font-size: 20px; font-family: 微软雅黑, 黑体, Arial, Helvetica, sans-serif; ">正则表达式的分组和引用</span>&nbsp;&nbsp;<br /><br /><div><h4>组和捕获 </h4> <p>捕<span class="Apple-style-span" style="font-weight: normal;">获组可以通过从左到右计算其开括号来编号。例如，在表达式 <tt>((A)(B(C)))</tt> 中，存在四个这样的组： </span></p> <blockquote> <table cellspacing="0" cellpadding="1" summary="Capturing group numberings"> <tbody> <tr> <th>1&nbsp;&nbsp;&nbsp;&nbsp;</th> <td><tt><strong>((A)(B(C)))</strong></tt></td></tr> <tr> <th>2&nbsp;&nbsp;&nbsp;&nbsp;</th> <td><tt><strong>\A</strong></tt></td></tr> <tr> <th>3&nbsp;&nbsp;&nbsp;&nbsp;</th> <td><tt><strong>(B(C))</strong></tt></td></tr> <tr> <th>4&nbsp;&nbsp;&nbsp;&nbsp;</th> <td><tt><strong>(C)</strong></tt></td></tr></tbody></table></blockquote> <p><span class="Apple-style-span" style="font-weight: normal;">组零始终代表整个表达式。</span><br /><span class="Apple-style-span" style="font-weight: normal;">&nbsp;之所以这样命名捕获组是因为在匹配中，保存了与这些组匹配的输入序列的每个子序列。捕获的子序列稍后可以通过 Back  引用在表达式中使用，也可以在匹配操作完成后从匹配器获取。&nbsp;<br /></span><br />引用<br />。。。。。。。。<br /><br /><br /></p><div>非捕获&nbsp;组</div><div style="font-weight: normal; "><p>以 <tt>(?)</tt> 开头的组是纯的<em>非捕获</em> 组，它不捕获文本，也不针对组合计进行计数。<br /><br /><br /><br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000; ">String&nbsp;now&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; ">"</span><span style="color: #000000; ">25/10/2009</span><span style="color: #000000; ">"</span><span style="color: #000000; ">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Matcher&nbsp;matcher&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;Pattern.compile(</span><span style="color: #000000; ">"</span><span style="color: #000000; ">(\\d\\d)/(\\d\\d)/(\\d\\d\\d\\d)</span><span style="color: #000000; ">"</span><span style="color: #000000; ">).matcher(now);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">if</span><span style="color: #000000; ">&nbsp;(matcher.find())&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(matcher.group(</span><span style="color: #000000; ">3</span><span style="color: #000000; ">)&nbsp;</span><span style="color: #000000; ">+</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; ">"</span><span style="color: #000000; ">-</span><span style="color: #000000; ">"</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; ">+</span><span style="color: #000000; ">&nbsp;matcher.group(</span><span style="color: #000000; ">2</span><span style="color: #000000; ">)&nbsp;</span><span style="color: #000000; ">+</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; ">"</span><span style="color: #000000; ">-</span><span style="color: #000000; ">"</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; ">+</span><span style="color: #000000; ">&nbsp;matcher.group(</span><span style="color: #000000; ">1</span><span style="color: #000000; ">));<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</span></div><br />&nbsp;<br /><div><a href="http://www.blogjava.net/ycyk168/archive/2009/10/25/299659.html">http://www.blogjava.net/ycyk168/archive/2009/10/25/299659.html</a></div><br /></p></div><p>&nbsp;</p></div></h3></span></div><img src ="http://www.cppblog.com/luofeng225/aggbug/168697.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/luofeng225/" target="_blank">luofeng</a> 2012-03-23 10:08 <a href="http://www.cppblog.com/luofeng225/archive/2012/03/23/168697.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>正则表达式三种数量词</title><link>http://www.cppblog.com/luofeng225/archive/2012/03/23/168691.html</link><dc:creator>luofeng</dc:creator><author>luofeng</author><pubDate>Fri, 23 Mar 2012 01:53:00 GMT</pubDate><guid>http://www.cppblog.com/luofeng225/archive/2012/03/23/168691.html</guid><wfw:comment>http://www.cppblog.com/luofeng225/comments/168691.html</wfw:comment><comments>http://www.cppblog.com/luofeng225/archive/2012/03/23/168691.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/luofeng225/comments/commentRss/168691.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/luofeng225/services/trackbacks/168691.html</trackback:ping><description><![CDATA[<div><span style="color: #333333; font-family: Arial, Helvetica, simsun, u5b8bu4f53; font-size: 12px; line-height: normal; "><h3><span style="font-size: 20px; font-family: 微软雅黑, 黑体, Arial, Helvetica, sans-serif; "><br />正则表达式三种数量词</span>&nbsp;&nbsp;<br /><br /><div><span style="line-height: 25px; "><strong style="line-height: 25px; font-weight: normal; ">Greedy&nbsp;数量词&nbsp;&nbsp;&nbsp;(贪婪的<wbr style="line-height: 43px; ">)<wbr style="line-height: 25px; ">!【每次取最多，不成，往出吐个，再试】!<wbr style="line-height: 25px; "></strong><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">&nbsp;</span><br style="line-height: 25px; " /><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">X</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">?&nbsp;&nbsp;&nbsp;&nbsp;</span><wbr style="line-height: 25px; "><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">X</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">，一次或一次也没有&nbsp;</span><br style="line-height: 25px; " /><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">X</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">*&nbsp;&nbsp;&nbsp;&nbsp;</span><wbr style="line-height: 25px; "><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">X</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">，零次或多次</span><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">X</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">+</span><wbr style="line-height: 25px; "><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">X</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">，一次或多次&nbsp;</span><br style="line-height: 25px; " /><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">X</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">{</span><wbr style="line-height: 25px; "><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">n</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">}&nbsp;&nbsp;&nbsp;&nbsp;</span><wbr style="line-height: 25px; "><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">X</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">，恰好&nbsp;</span><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">n</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">&nbsp;次&nbsp;</span><br style="line-height: 25px; " /><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">X</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">{</span><wbr style="line-height: 25px; "><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">n</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">,}&nbsp;&nbsp;&nbsp;&nbsp;</span><wbr style="line-height: 25px; "><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">X</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">，至少&nbsp;</span><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">n</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">&nbsp;次&nbsp;</span><br style="line-height: 25px; " /><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">X</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">{</span><wbr style="line-height: 25px; "><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">n</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">,</span><wbr style="line-height: 25px; "><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">m</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">}&nbsp;&nbsp;&nbsp;&nbsp;</span><wbr style="line-height: 25px; "><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">X</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">，至少&nbsp;</span><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">n</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">&nbsp;次，但是不超过&nbsp;</span><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">m</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">&nbsp;次&nbsp;</span><br style="line-height: 25px; " /><strong style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">Reluctant&nbsp;数量词&nbsp;&nbsp;&nbsp;（不情愿的，勉强的<wbr style="line-height: 43px; ">）<wbr style="line-height: 25px; ">!【每次取最少，不成，吸入一个，再试】!<wbr style="line-height: 25px; "></strong><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">&nbsp;</span><br style="line-height: 25px; " /><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">X</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">??&nbsp;&nbsp;&nbsp;&nbsp;</span><wbr style="line-height: 25px; "><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">X</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">，一次或一次也没有&nbsp;</span><br style="line-height: 25px; " /><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">X</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">*?&nbsp;&nbsp;&nbsp;&nbsp;</span><wbr style="line-height: 25px; "><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">X</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">，零次或多次&nbsp;</span><br style="line-height: 25px; " /><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">X</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">+?&nbsp;&nbsp;&nbsp;&nbsp;</span><wbr style="line-height: 25px; "><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">X</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">，一次或多次&nbsp;</span><br style="line-height: 25px; " /><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">X</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">{</span><wbr style="line-height: 25px; "><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">n</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">}?&nbsp;&nbsp;&nbsp;&nbsp;</span><wbr style="line-height: 25px; "><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">X</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">，恰好&nbsp;</span><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">n</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">&nbsp;次</span><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">X</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">&nbsp;</span><br style="line-height: 25px; " /><span class="Apple-style-span" style="font-weight: normal;">{</span><wbr style="line-height: 25px; "><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">n</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">,}?&nbsp;&nbsp;&nbsp;&nbsp;</span><wbr style="line-height: 25px; "><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">X</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">，至少&nbsp;</span><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">n</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">&nbsp;次&nbsp;</span><br style="line-height: 25px; " /><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">X</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">{</span><wbr style="line-height: 25px; "><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">n</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">,</span><wbr style="line-height: 25px; "><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">m</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">}?&nbsp;&nbsp;&nbsp;&nbsp;</span><wbr style="line-height: 25px; "><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">X</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">，至少&nbsp;</span><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">n</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">&nbsp;次，但是不超过&nbsp;</span><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">m</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">&nbsp;次&nbsp;</span><br style="line-height: 25px; " /><strong style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">Possessive&nbsp;数量词&nbsp;&nbsp;&nbsp;（独占的<wbr style="line-height: 43px; ">）&nbsp;&nbsp;<wbr style="line-height: 25px; ">!【每次取最多，不吐】!<wbr style="line-height: 25px; "></strong><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">&nbsp;</span><br style="line-height: 25px; " /><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">X</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">?+&nbsp;&nbsp;&nbsp;&nbsp;</span><wbr style="line-height: 25px; "><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">X</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">，一次或一次也没有&nbsp;</span><br style="line-height: 25px; " /><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">X</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">*+&nbsp;&nbsp;&nbsp;&nbsp;</span><wbr style="line-height: 25px; "><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">X</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">，零次或多次&nbsp;</span><br style="line-height: 25px; " /><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">X</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">++&nbsp;&nbsp;&nbsp;&nbsp;</span><wbr style="line-height: 25px; "><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">X</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">，一次或多次&nbsp;</span><br style="line-height: 25px; " /><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">X</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">{</span><wbr style="line-height: 25px; "><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">n</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">}+&nbsp;&nbsp;&nbsp;&nbsp;</span><wbr style="line-height: 25px; "><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">X</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">，恰好&nbsp;</span><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">n</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">&nbsp;次&nbsp;</span><br style="line-height: 25px; " /><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">X</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">{</span><wbr style="line-height: 25px; "><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">n</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">,}+&nbsp;&nbsp;&nbsp;&nbsp;</span><wbr style="line-height: 25px; "><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">X</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">，至少&nbsp;</span><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">n</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">&nbsp;次&nbsp;</span><br style="line-height: 25px; " /><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">X</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">{</span><wbr style="line-height: 25px; "><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">n</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">,</span><wbr style="line-height: 25px; "><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">m</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">}+&nbsp;&nbsp;&nbsp;&nbsp;</span><wbr style="line-height: 25px; "><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">X</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">，至少&nbsp;</span><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">n</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">&nbsp;次，但是不超过&nbsp;</span><em style="line-height: 25px; font-weight: normal; "><wbr style="line-height: 25px; ">m</em><wbr style="line-height: 25px; "><span class="Apple-style-span" style="font-weight: normal;">&nbsp;次</span><br /><br /><div style="background-color: #eeeeee; font-size: 13px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; padding-right: 5px; padding-bottom: 4px; padding-left: 4px; padding-top: 4px; width: 98%; word-break: break-all; font-weight: normal; "><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080; ">1</span>&nbsp;<span style="color: #000000; ">Matcher&nbsp;m</span><span style="color: #000000; ">=</span><span style="color: #000000; ">Pattern.compile(</span><span style="color: #000000; ">"</span><span style="color: #000000; ">a.*b</span><span style="color: #000000; ">"</span><span style="color: #000000; ">)<br /></span><span style="color: #008080; ">2</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.matcher(</span><span style="color: #000000; ">"</span><span style="color: #000000; ">a====b=========b=====</span><span style="color: #000000; ">"</span><span style="color: #000000; ">);<br /></span><span style="color: #008080; ">3</span>&nbsp;<span style="color: #000000; "></span><span style="color: #0000FF; ">while</span><span style="color: #000000; ">(m.find()){<br /></span><span style="color: #008080; ">4</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(m.group());<br /></span><span style="color: #008080; ">5</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /></span><span style="color: #008080; ">6</span>&nbsp;<span style="color: #000000; "><br /></span><span style="color: #008080; ">7</span>&nbsp;<span style="color: #000000; "><br /></span><span style="color: #008080; ">8</span>&nbsp;<span style="color: #000000; ">输出：<br /></span><span style="color: #008080; ">9</span>&nbsp;<span style="color: #000000; ">a</span><span style="color: #000000; ">====</span><span style="color: #000000; ">b</span><span style="color: #000000; ">=========</span><span style="color: #000000; ">b</span></div><div><span style="font-family: Arial; line-height: 26px; "><span class="Apple-style-span" style="font-weight: normal;">因为总是从最大 匹配开始匹配，故称贪婪。</span><br /><br /><div>Reluctant<span class="Apple-style-span" style="font-weight: normal;">正好和Greedy相反，它先从最小匹配开始，先从左端吞入一个字符，然后进行匹配，若不匹配就再吞入一个字符，直到找到匹配或将整个字符串吞入为止。</span></div></span></div><div style="font-size: 13px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; padding-right: 5px; padding-bottom: 4px; padding-left: 4px; padding-top: 4px; width: 98%; word-break: break-all; background-color: #eeeeee; font-weight: normal; "><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080; ">1</span>&nbsp;<span style="color: #000000; ">Matcher&nbsp;m</span><span style="color: #000000; ">=</span><span style="color: #000000; ">Pattern.compile(</span><span style="color: #000000; ">"</span><span style="color: #000000; ">a.*?b</span><span style="color: #000000; ">"</span><span style="color: #000000; ">)<br /></span><span style="color: #008080; ">2</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.matcher(</span><span style="color: #000000; ">"</span><span style="color: #000000; ">a====b=========b=====</span><span style="color: #000000; ">"</span><span style="color: #000000; ">);<br /></span><span style="color: #008080; ">3</span>&nbsp;<span style="color: #000000; "></span><span style="color: #0000FF; ">while</span><span style="color: #000000; ">(m.find()){<br /></span><span style="color: #008080; ">4</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(m.group());<br /></span><span style="color: #008080; ">5</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /></span><span style="color: #008080; ">6</span>&nbsp;<span style="color: #000000; "><br /></span><span style="color: #008080; ">7</span>&nbsp;<span style="color: #000000; ">输出：<br /></span><span style="color: #008080; ">8</span>&nbsp;<span style="color: #000000; ">a</span><span style="color: #000000; ">====</span><span style="color: #000000; ">b</span></div><br /><div><span style="font-family: Arial; line-height: 26px; ">Possessive和Greedy的匹配方式一样，先把整个字符串吞下，然后匹配整个字符串，</span><span style="font-family: Arial; line-height: 26px; font-weight: normal; ">如果匹配，就认为匹配，如果不匹配，就认为整个字符串不匹配，它不会从右端吐出一个字符串再进行匹配，只进行一次<br /><div style="font-size: 13px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; border-image: initial; padding-right: 5px; padding-bottom: 4px; padding-left: 4px; padding-top: 4px; width: 98%; word-break: break-all; background-color: #eeeeee; "><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080; ">1</span>&nbsp;<span style="color: #000000; ">Matcher&nbsp;m</span><span style="color: #000000; ">=</span><span style="color: #000000; ">Pattern.compile(</span><span style="color: #000000; ">"</span><span style="color: #000000; ">a.*+b</span><span style="color: #000000; ">"</span><span style="color: #000000; ">)<br /></span><span style="color: #008080; ">2</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.matcher(</span><span style="color: #000000; ">"</span><span style="color: #000000; ">a====b=========b=====</span><span style="color: #000000; ">"</span><span style="color: #000000; ">);<br /></span><span style="color: #008080; ">3</span>&nbsp;<span style="color: #000000; "></span><span style="color: #0000FF; ">while</span><span style="color: #000000; ">(m.find()){<br /></span><span style="color: #008080; ">4</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(m.group());<br /></span><span style="color: #008080; ">5</span>&nbsp;<span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /></span><span style="color: #008080; ">6</span>&nbsp;<span style="color: #000000; "><br /></span><span style="color: #008080; ">7</span>&nbsp;<span style="color: #000000; ">输出：<br /></span><span style="color: #008080; ">8</span>&nbsp;<span style="color: #000000; ">（无输出）<br /><br /></span><div>*******************<br />我的理解是</div><div>String text = "a====b=========b";</div><div>String reg = "a.*+b";</div><div>由于.代表任意字符，字母b和=都算匹配到了模式中（.*+），最后 "a.*+b"中的b没有找到匹配字符，所以不匹配。</div><div>如果这样：</div><div>String text = "a54564b";</div><div>String reg = "a\\d*+b";</div><div>"a54564b"中字母b不能吸收进&#8220;\\d*+&#8221;，最后匹配结果是true。</div></div></span></div></span></div></h3></span></div><img src ="http://www.cppblog.com/luofeng225/aggbug/168691.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/luofeng225/" target="_blank">luofeng</a> 2012-03-23 09:53 <a href="http://www.cppblog.com/luofeng225/archive/2012/03/23/168691.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>正则表达式</title><link>http://www.cppblog.com/luofeng225/archive/2012/03/22/168583.html</link><dc:creator>luofeng</dc:creator><author>luofeng</author><pubDate>Thu, 22 Mar 2012 03:10:00 GMT</pubDate><guid>http://www.cppblog.com/luofeng225/archive/2012/03/22/168583.html</guid><wfw:comment>http://www.cppblog.com/luofeng225/comments/168583.html</wfw:comment><comments>http://www.cppblog.com/luofeng225/archive/2012/03/22/168583.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/luofeng225/comments/commentRss/168583.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/luofeng225/services/trackbacks/168583.html</trackback:ping><description><![CDATA[<div><span style="border-collapse: collapse; font-size: 12px; line-height: 18px; font-family: Simsun; "><div><br /><div><p><span class="Apple-style-span" style="font-weight: normal; "><strong></strong></span></p><div style="display: inline !important; "><div style="display: inline !important; "><strong><strong>java.util.regex.Pattern&nbsp;</strong></strong></div></div>正则表达式的编译表示形式。<strong>&nbsp;</strong><br />指定为字符串的正则表达式必须首先被编译为此类的实例。然后，可将得到的模式用于创建 <a title="java.util.regex 中的类" href=""><code>Matcher</code></a>  对象，依照正则表达式，该对象可以与任意<a title="java.lang 中的接口" href=""><code></code>字符序列<code></code></a>匹配。执行匹配所涉及的所有状态都驻留在匹配器中，所以多个匹配器可以共享同一模式。<br /><div>=此类的实例是不可变的，可供多个并发线程安全使用。</div> &nbsp;<br /><p>&nbsp;</p></div><strong>java.util.regex.Matcher&nbsp;</strong>过解释 <a title="java.util.regex 中的类" href=""><code>Pattern</code></a> 对 <a title="java.lang 中的接口" href=""><code></code>character  sequence<code></code></a> 执行匹配操作的引擎。</div><br />4种常用功能：<br />查询<br />提取<br />分割<br />替换<br /><br /><div><div>======================</div><div><ul><li>&nbsp;正则表达式的构造</li><li>&nbsp;转义字符（区分 java实现层次，文字表述层次）</li><li>&nbsp;模式：懒惰，贪婪，(Greedy ，Reluctant，Possessive)</li><li>&nbsp;分组 group</li></ul>&nbsp;<br />----<br /><div><strong>转义字符（区分 java实现层次，文字表述层次）</strong><br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><font class="Apple-style-span" color="#008080"><br /></font></div></div><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000; ">&nbsp;&nbsp;</span><span style="color: #008000; ">/**</span><span style="color: #008000; "><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;体会Escape(转义符号)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;字符串层次的表示&lt;br&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;和正则表达式层次的表示&lt;br&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;的区别！<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000; ">*/</span><span style="color: #000000; "><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">private</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">static</span><span style="color: #000000; ">&nbsp;</span><span style="color: #0000FF; ">void</span><span style="color: #000000; ">&nbsp;testEscape()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;str&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; ">"</span><span style="color: #000000; ">\\</span><span style="color: #000000; ">"</span><span style="color: #000000; ">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(str);<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Pattern&nbsp;p2&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;Pattern.compile(</span><span style="color: #000000; ">"</span><span style="color: #000000; ">a\\\b</span><span style="color: #000000; ">"</span><span style="color: #000000; ">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Pattern&nbsp;p3&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;Pattern.compile(</span><span style="color: #000000; ">"</span><span style="color: #000000; ">a\\b</span><span style="color: #000000; ">"</span><span style="color: #000000; ">);<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Matcher&nbsp;m2&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;p2.matcher(</span><span style="color: #000000; ">"</span><span style="color: #000000; ">a\b</span><span style="color: #000000; ">"</span><span style="color: #000000; ">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(m2.matches());<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Matcher&nbsp;m3&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;p3.matcher(</span><span style="color: #000000; ">"</span><span style="color: #000000; ">a\b</span><span style="color: #000000; ">"</span><span style="color: #000000; ">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(m3.matches());<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></div><strong><br />关于三种数量词</strong><div>Greedy ，Reluctant，Possessive)：</div><div><span style="color: #333333; font-family: arial; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: separate; line-height: normal; "><a id="Editor_Edit_hlEntryLink" title="view: 正则表达式三种数量词  todo" href="http://www.cppblog.com/luofeng225/archive/2012/03/23/168691.html" target="_blank" style="color: #cc0066; background: inherit; background-color: #f5f5f5; ">http://www.cppblog.com/luofeng225/archive/2012/03/23/168691.html<br /><br /><br /><strong>分组与捕获</strong><br /></a><div><a id="Editor_Edit_hlEntryLink" title="view: 正则表达式三种数量词  todo" href="http://www.cppblog.com/luofeng225/archive/2012/03/23/168691.html" target="_blank" style="color: #cc0066; background: inherit; background-color: #f5f5f5; "></a><a href="http://www.cppblog.com/luofeng225/archive/2012/03/23/168697.html">http://www.cppblog.com/luofeng225/archive/2012/03/23/168697.html<br /><br /><br /></a></div></span></div>================<br /><strong>关于效率？</strong></div><div><span class="Apple-style-span" style="white-space: pre; "><br /></span><span class="Apple-style-span" style="white-space: pre; "><br /></span><span class="Apple-style-span" style="white-space: pre; "><br /></span><span class="Apple-style-span" style="white-space: pre; ">=============</span><span class="Apple-style-span" style="white-space: pre; "><br /></span><div style="white-space: pre; ">Jakarta-ORO正则表达式库<br />，它是最全面的正则表达式API之一，而且它与Perl 5正则表达式完全兼容。另外，它也是优化得最好的API之一。</div><span class="Apple-style-span" style="white-space: pre; "><br /></span><span class="Apple-style-span" style="white-space: pre; "><br /></span><span class="Apple-style-span" style="white-space: pre; "><br /></span></div></div></span></div>  <img src ="http://www.cppblog.com/luofeng225/aggbug/168583.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/luofeng225/" target="_blank">luofeng</a> 2012-03-22 11:10 <a href="http://www.cppblog.com/luofeng225/archive/2012/03/22/168583.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>StringBuffer 和 StringBuilder </title><link>http://www.cppblog.com/luofeng225/archive/2012/03/21/168474.html</link><dc:creator>luofeng</dc:creator><author>luofeng</author><pubDate>Wed, 21 Mar 2012 03:10:00 GMT</pubDate><guid>http://www.cppblog.com/luofeng225/archive/2012/03/21/168474.html</guid><wfw:comment>http://www.cppblog.com/luofeng225/comments/168474.html</wfw:comment><comments>http://www.cppblog.com/luofeng225/archive/2012/03/21/168474.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/luofeng225/comments/commentRss/168474.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/luofeng225/services/trackbacks/168474.html</trackback:ping><description><![CDATA[<div><span style="color: #333333; font-family: Arial; line-height: 26px; "><div><br /><div><span style="font-size: large; "><strong>String 字符串常量<br />StringBuffer 字符串变量（线程安全）<br />StringBuilder 字符串变量（非线程安全）<br />--------------</strong></span></div><div><div style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><div style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">在大部分情况下 StringBuffer &gt; String</div></div>在大部分情况下 StringBuilder &gt; StringBuffer<br /></div><div><div>而在某些特别情况下， String 对象的字符串拼接其实是被 JVM 解释成了 StringBuffer 对象的拼接，所以这些时候 String 对象的速度并不会比 StringBuffer 对象慢，而特别是以下的字符串对象生成中， String 效率是远要比 StringBuffer 快的：<br />&nbsp;String S1 = &#8220;This is only a&#8221; + &#8220; simple&#8221; + &#8220; test&#8221;;<br />&nbsp;StringBuffer Sb = new StringBuilder(&#8220;This is only a&#8221;).append(&#8220; simple&#8221;).append(&#8220; test&#8221;);<br />&nbsp;你会很惊讶的发现，生成 String S1 对象的速度简直太快了，而这个时候 StringBuffer 居然速度上根本一点都不占优势。其实这是 JVM 的一个把戏，在 JVM 眼里，这个<br />&nbsp;String S1 = &#8220;This is only a&#8221; + &#8220; simple&#8221; + &#8220;test&#8221;; 其实就是：<br />&nbsp;String S1 = &#8220;This is only a simple test&#8221;; 所以当然不需要太多的时间了。但大家这里要注意的是，如果你的字符串是来自另外的 String 对象的话，速度就没那么快了，譬如：<br />String S2 = &#8220;This is only a&#8221;;<br />String S3 = &#8220; simple&#8221;;<br />String S4 = &#8220; test&#8221;;<br />String S1 = S2 +S3 + S4;<br />这时候 JVM 会规规矩矩的按照原来的方式去做</div><div></div></div></div><div><strong>java.lang.StringBuilder</strong><br />java.lang.StringBuilder一个可变的字符序列是5.0新增的。此类提供一个与 StringBuffer 兼容的 API，但不保证同步。该类被设计用作 StringBuffer 的一个简易替换，用在字符串缓冲区被单个线程使用的时候（这种情况很普遍）。如果可能，建议优先采用该类，因为在大多数实现中，它比 StringBuffer 要快。两者的方法基本相同。</div></span></div><img src ="http://www.cppblog.com/luofeng225/aggbug/168474.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/luofeng225/" target="_blank">luofeng</a> 2012-03-21 11:10 <a href="http://www.cppblog.com/luofeng225/archive/2012/03/21/168474.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>android Animation 动画</title><link>http://www.cppblog.com/luofeng225/archive/2012/03/19/168304.html</link><dc:creator>luofeng</dc:creator><author>luofeng</author><pubDate>Mon, 19 Mar 2012 03:17:00 GMT</pubDate><guid>http://www.cppblog.com/luofeng225/archive/2012/03/19/168304.html</guid><wfw:comment>http://www.cppblog.com/luofeng225/comments/168304.html</wfw:comment><comments>http://www.cppblog.com/luofeng225/archive/2012/03/19/168304.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/luofeng225/comments/commentRss/168304.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/luofeng225/services/trackbacks/168304.html</trackback:ping><description><![CDATA[<div><div><div><div><strong><br /></strong></div><div><div><strong>Animation<br /><span class="Apple-style-span" style="font-weight: normal; ">android 支持三种动画</span></strong></div></div><div><ol><li>动态GIF动画</li><li>逐帧动画</li><li>补简动画</li></ol></div><div>----------------------------</div><div>&nbsp;补简动画</div><div>AlphaAnimation透明度动画淡入淡出效果 （0.0 ==完全透明，不可见）</div><div>&nbsp;&nbsp;&nbsp;</div><div>TranslateAnimation 移动&nbsp;<br /><div>&nbsp;<a href="http://www.cppblog.com/luofeng225/archive/2012/04/21/172235.html">http://www.cppblog.com/luofeng225/archive/2012/04/21/172235.html</a></div></div><div>&nbsp;</div><div>Rotate：旋转效果</div><div></div><div>&nbsp;</div><div>ScaleAnimation：缩放效果</div><div></div><div></div><div><strong>++++++++++++++++++++++++++++++<br /><br />layoutAnimation有关<br /><br /></strong></div><div></div><div><strong>LayoutAnimationController</strong></div><div>&nbsp;&nbsp; &nbsp; &nbsp;LayoutAnimationController用于为一个Layout里面的控件或者是Viewgroup的控件设置动画效果。。</div><div></div><div>LayoutAnimationController 用来为一个layout 或是viewgroup 包含的子view添加动画效果， Layout中的每个元素</div><div>都会采用同一个动画效果，但开始时间不同。 子View动画的缺省开始时间为子View在Layout中的序号index 乘以 一个固定的时间间隔。&nbsp;</div><div>LayoutAnimationController 的子类可以重载getDelayForView(android.view.View)为子View定义动画开始时间，</div><div>如GridLayoutAnimationController 根据子View的行和列来计算子View动画的开始时间。</div><div></div><div>顺序：：</div><div>ORDER_NORMAL</div><div>ORDER_REVERSE</div><div>ORDER_RANDOM</div><div></div><div>====================</div><div></div><div><strong>AnimationSet</strong></div><div></div><div>Represents a group of Animations that should be played together.</div><div>&nbsp;* The transformation of each individual animation are composed&nbsp;</div><div>&nbsp;* together into a single transform.&nbsp;</div><div>&nbsp;在Android 中用于制作混合型动画</div><div>&nbsp;AnimationSet 可以包含多个Animation，但都是在同一个时间执行的，是并行，不是串行执行的。</div><div>如果AnimationSet中有一些设定，如duration,fillBefore等，它包含的子动作也设定了的，</div><div>&nbsp;</div><div>&nbsp;&nbsp;</div><div></div><div>====================</div><div>&nbsp;</div><div>&nbsp;<strong>Interpolator<br /></strong>定义了动画变化的速率或规律，其具体的实现可以使用以下子类：</div><div>&nbsp;interpolator 被用来修饰动画效果，定义动画的变化率，</div><div>&nbsp;&nbsp;可以使存在的动画效果可以 accelerated(加速)，decelerated(减速),repeated(重复),bounced(弹跳)等</div><div>&nbsp;</div><div>&nbsp;</div><div>&nbsp;=========================</div><div>&nbsp;</div><div><strong>android:layoutAnimation </strong>属性定义在ViewGroup中，因此所有ViewGroup的子类都可以定义android:layoutAnimation。 ViewGroup可以嵌套定义，从而layout animation 也可以嵌套</div></div><div></div></div></div><img src ="http://www.cppblog.com/luofeng225/aggbug/168304.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/luofeng225/" target="_blank">luofeng</a> 2012-03-19 11:17 <a href="http://www.cppblog.com/luofeng225/archive/2012/03/19/168304.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title> Android手机分辨率基础知识（DPI,DIP计算）转</title><link>http://www.cppblog.com/luofeng225/archive/2011/11/02/159506.html</link><dc:creator>luofeng</dc:creator><author>luofeng</author><pubDate>Wed, 02 Nov 2011 06:47:00 GMT</pubDate><guid>http://www.cppblog.com/luofeng225/archive/2011/11/02/159506.html</guid><wfw:comment>http://www.cppblog.com/luofeng225/comments/159506.html</wfw:comment><comments>http://www.cppblog.com/luofeng225/archive/2011/11/02/159506.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/luofeng225/comments/commentRss/159506.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/luofeng225/services/trackbacks/159506.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: &nbsp;&nbsp;<a href='http://www.cppblog.com/luofeng225/archive/2011/11/02/159506.html'>阅读全文</a><img src ="http://www.cppblog.com/luofeng225/aggbug/159506.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/luofeng225/" target="_blank">luofeng</a> 2011-11-02 14:47 <a href="http://www.cppblog.com/luofeng225/archive/2011/11/02/159506.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>