tag:blogger.com,1999:blog-91618830887295629592024-02-08T13:39:26.744+08:00程式植物園程式、植物、隨筆… 小小世界札記JackLiaohttp://www.blogger.com/profile/15196682200013649498noreply@blogger.comBlogger66125tag:blogger.com,1999:blog-9161883088729562959.post-83160795757667686942022-04-06T17:38:00.001+08:002022-04-06T17:38:43.446+08:00[Android] RecyclerView 瀑布流(方塊List 橫跨方式)<pre style="font-family: Menlo; font-size: 10.5pt;"><span style="background-color: white;">
</span></pre>
<pre><span style="background-color: white; font-family: Menlo; font-size: 14px;">int columnCount = 3;</span></pre>
<pre><span style="background-color: white; font-family: Menlo; font-size: 14px;">int spanCount = 2;</span></pre>
<pre style="font-family: Menlo; font-size: 10.5pt;"><span style="background-color: white;">GridLayoutManager manager = new GridLayoutManager(context, columnCount,</span></pre>
<pre style="font-family: Menlo; font-size: 10.5pt;"><span style="background-color: white;"> StaggeredGridLayoutManager.<span style="font-style: italic;">VERTICAL</span>, false);
manager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup(){
@Override
public int getSpanSize(int position) {
if({判斷條件}){</span></pre>
<pre style="font-family: Menlo; font-size: 10.5pt;"><span style="background-color: white;"><pre style="font-family: Menlo; font-size: 10.5pt;"> return spanCount;</pre>
</span></pre>
<pre style="font-family: Menlo; font-size: 10.5pt;"><span style="background-color: white;"> }
return 1;
}
});
deviceView.setLayoutManager(manager</span>);</pre>
JackLiaohttp://www.blogger.com/profile/15196682200013649498noreply@blogger.comtag:blogger.com,1999:blog-9161883088729562959.post-25535424108465617392018-11-15T13:53:00.002+08:002022-04-06T17:38:11.217+08:00【開箱文】查克折合桌<div class="separator" style="clear: both; text-align: left;">
礙於現在的租屋處實在是很小,所以買的傢俱希望都能有多功能,最近老婆大人又說希望有個餐桌,所以就從可以折合式的餐桌開始找。</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
而剛好,遇到雙11,在FB廣告中看到特X屋有在賣一組價格不會太貴的查克折合桌,所以就下定啦。</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
一組含桌子與兩張椅子不用兩千
,只不過需要自己組裝。</div>
<div class="separator" style="clear: both; text-align: left;">
</div>
<a name='more'></a><br /><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHNgWcGD17Snmdi41Y7WK9KXrwKjdES_fwLlt7C_09cWpyVt9ukBi7vBQLpEsYIDAzthy7xgKtu2M4iCqi9eJk9FX1YfekesDsTm0ayYHgc3YxKNtpH6YeEPpmdcpxpbvTWHVrhNd6mvI/s1600/IMG_3214.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1600" data-original-width="1200" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHNgWcGD17Snmdi41Y7WK9KXrwKjdES_fwLlt7C_09cWpyVt9ukBi7vBQLpEsYIDAzthy7xgKtu2M4iCqi9eJk9FX1YfekesDsTm0ayYHgc3YxKNtpH6YeEPpmdcpxpbvTWHVrhNd6mvI/s320/IMG_3214.JPG" width="240" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
送來的包裝,高度將近一百公分,超重的...貨運只送到門口,還好我住二樓,一個人搬著它上來。</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvwROUlZ3uMQ2dZhBOPYIO-TIllGlEnSLegQj_m1vgE2Ca7BttUr7mzlpuuNmkt5DBSb73vD2GyjakMn7E_rZmeeIepUXoCpN2ius-J68X8q_o4WP8QDr8ksYcRi0Tr5uu_MklflZH_6E/s1600/IMG_3215.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1199" data-original-width="1600" height="239" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvwROUlZ3uMQ2dZhBOPYIO-TIllGlEnSLegQj_m1vgE2Ca7BttUr7mzlpuuNmkt5DBSb73vD2GyjakMn7E_rZmeeIepUXoCpN2ius-J68X8q_o4WP8QDr8ksYcRi0Tr5uu_MklflZH_6E/s320/IMG_3215.jpg" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
裡面就可以看到所有桌子與椅子的骨架,準備好工具開始組裝,不用擔心組裝太難,每個元件上面都會貼一個編號,只要按照說明書上面的作法一步一步的接上去。</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwW6ZdmYUhDx8M-rCtP6lsBguXasMi8QZPgYhZidZwgnfUDACqLQUmvWo9geuFtO2Ip9R-yZzShIJ9dYVlcQnQbNjoXzMNJUyBJrfV0T4-V_t-TVdiSLfX7AdUJxNXJ15xcbZLJCpgHk4/s1600/IMG_3216.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1200" data-original-width="1600" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwW6ZdmYUhDx8M-rCtP6lsBguXasMi8QZPgYhZidZwgnfUDACqLQUmvWo9geuFtO2Ip9R-yZzShIJ9dYVlcQnQbNjoXzMNJUyBJrfV0T4-V_t-TVdiSLfX7AdUJxNXJ15xcbZLJCpgHk4/s320/IMG_3216.JPG" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
花了半小時,才把椅子的骨架組裝好,每個螺絲轉大小力原來是有差別,如果鎖太緊,有可能會造成四隻腳不平均,坐起來就會搖晃。</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj44yl2netBFGW-3eCCrFJiMoJ7Yih8-i99mUdzjrS2YpXk-wGsJJVjubppZ-pQ8XCJ3XMEZBFShwSSAtpxBj4rYMS6RVksr18Fn4lYEO-BHwxnJ7DOxgmrzRJ5iAI7RpbNjQLy-nBmOGU/s1600/IMG_3217.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1200" data-original-width="1600" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj44yl2netBFGW-3eCCrFJiMoJ7Yih8-i99mUdzjrS2YpXk-wGsJJVjubppZ-pQ8XCJ3XMEZBFShwSSAtpxBj4rYMS6RVksr18Fn4lYEO-BHwxnJ7DOxgmrzRJ5iAI7RpbNjQLy-nBmOGU/s320/IMG_3217.JPG" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
全數組裝完畢。(默默過了兩個小時多)</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7iGRwl4VscYX3CKyIYsptRY2bQ7rs8zMsotvT0O4jHBcXV04UpwTDxs91M3iEktCBvr7e2BRy5wtcQPld5V0cdzzy9xZaS2f6pfnQoE-NJAfqCR9_9m-83GL1mneRHjcWEKKtt_I9aDM/s1600/IMG_3218.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1200" data-original-width="1600" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7iGRwl4VscYX3CKyIYsptRY2bQ7rs8zMsotvT0O4jHBcXV04UpwTDxs91M3iEktCBvr7e2BRy5wtcQPld5V0cdzzy9xZaS2f6pfnQoE-NJAfqCR9_9m-83GL1mneRHjcWEKKtt_I9aDM/s320/IMG_3218.JPG" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
收起來的時候,椅子可以藏在桌底下,蠻省空間的。</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<br />
<script async="" src="//js1.bloggerads.net/contentads.aspx?blogid=20150916000016" type="text/javascript"></script>
<br />
桌子規格尺寸:<br />
<div class="separator" style="clear: both; text-align: left;">
全張開深度 90 </div>
折合深度 45<br />
寬度 90 x 高度 74 公分<br />
<br />
椅子尺寸:<br />
30 x 30 x 高度 45公分。JackLiaohttp://www.blogger.com/profile/15196682200013649498noreply@blogger.comtag:blogger.com,1999:blog-9161883088729562959.post-69751468694321929482018-11-14T16:22:00.003+08:002022-04-06T17:38:20.732+08:00【開箱文】米家IH 電子鍋 Part 1不專業開箱又來了,這次開箱的玩具是小米賣的【米家電子鍋】。<br />
號稱煮出來的飯又香又好吃,先來看看它的外觀。<br />
<br />
<div style="text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEitp1DoTIrhD-kJHnMQ1J6xONjkavnZPDmz3xO1JtVD_3n-T82iHJQBHnkgzeLHm2N0CV8_oj6et1-6gfwiUx9ynwvdGuwhywo1rpEopu7zvxmk4SZziODhs1VhEfVrgUpTA7VUSmGDIB8/s1600/IMG_2586.JPG" imageanchor="1"><img border="0" data-original-height="1200" data-original-width="1600" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEitp1DoTIrhD-kJHnMQ1J6xONjkavnZPDmz3xO1JtVD_3n-T82iHJQBHnkgzeLHm2N0CV8_oj6et1-6gfwiUx9ynwvdGuwhywo1rpEopu7zvxmk4SZziODhs1VhEfVrgUpTA7VUSmGDIB8/s320/IMG_2586.JPG" width="320" /></a></div>
<div style="text-align: center;">
很簡約的外箱,正正方方的。</div>
<div style="text-align: center;">
<br />
<a name='more'></a><br /></div>
<div style="text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiw_vvRvZvObAWwCbKDVAqT2lyBzj4HfX7_iuCKuShVcNd5wkbydG7NsZRShaAW1QD_VZ2cq2VGbUBeMineoZxPpZvwRad2yNAx92v2noilX7XdTvvc2zf2xAEFkeELo06mk_Gh1mRP6TE/s1600/IMG_2587.JPG" imageanchor="1"><img border="0" data-original-height="1600" data-original-width="1200" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiw_vvRvZvObAWwCbKDVAqT2lyBzj4HfX7_iuCKuShVcNd5wkbydG7NsZRShaAW1QD_VZ2cq2VGbUBeMineoZxPpZvwRad2yNAx92v2noilX7XdTvvc2zf2xAEFkeELo06mk_Gh1mRP6TE/s320/IMG_2587.JPG" width="240" /></a></div>
<div style="text-align: center;">
上蓋打開,隨即看見『歡迎使用米家IH電子鍋』,這應該是一本說明書。</div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: center;">
、<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtgY-3P_Go2SUOIOrFTBYgz-Zx1wxbh5PRrtrLeBnP2nJXLf6dCIwu7-E15FhdM6e3qSIPU1n9NK_lAbmuhRXTfCbN2eQM8Jx1tqg2HCX5Zp-rZcCP8q_C9kc7gNqg-j5Cl5RIBXdgNyU/s1600/IMG_2588.JPG" imageanchor="1"><img border="0" data-original-height="1600" data-original-width="1200" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtgY-3P_Go2SUOIOrFTBYgz-Zx1wxbh5PRrtrLeBnP2nJXLf6dCIwu7-E15FhdM6e3qSIPU1n9NK_lAbmuhRXTfCbN2eQM8Jx1tqg2HCX5Zp-rZcCP8q_C9kc7gNqg-j5Cl5RIBXdgNyU/s320/IMG_2588.JPG" width="240" /></a></div>
<div style="text-align: center;">
上層放電源線與飯匙。</div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuUCffJOXYAoRnBo6ytE_Ud8afaxmxPsqxvq1_Cp4CGGsKy8k5YPHuUGy0XwHkCXv4TmHlAHOyZ1rHmzo84F5LtKoSJ1Hl0O15QGZzpUh5MXbk_DkVB8xhZ1sMQY1EOMeHk5_ZMYWAhUQ/s1600/IMG_2589.JPG" imageanchor="1"><img border="0" data-original-height="1200" data-original-width="1600" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuUCffJOXYAoRnBo6ytE_Ud8afaxmxPsqxvq1_Cp4CGGsKy8k5YPHuUGy0XwHkCXv4TmHlAHOyZ1rHmzo84F5LtKoSJ1Hl0O15QGZzpUh5MXbk_DkVB8xhZ1sMQY1EOMeHk5_ZMYWAhUQ/s320/IMG_2589.JPG" width="320" /></a></div>
<div style="text-align: center;">
與一般家用飯匙不同的是,下面有凸出來一根,這樣就不怕把飯匙弄髒了,其實蠻方便的。</div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgglOdAXilyrfm4OeGqA3QHswjJBEwYnRYYjd3jRQtQfiMkwI8YooNd5JxNBrl7ODzKOF3hyphenhyphenacxjT_haokVwbneuj9QaM5AGWAVekSB2f86Ml5INvgt4X9nvGBDIY5TDiL0gHb9TDbzVOU/s1600/IMG_2591.JPG" imageanchor="1"><img border="0" data-original-height="1200" data-original-width="1600" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgglOdAXilyrfm4OeGqA3QHswjJBEwYnRYYjd3jRQtQfiMkwI8YooNd5JxNBrl7ODzKOF3hyphenhyphenacxjT_haokVwbneuj9QaM5AGWAVekSB2f86Ml5INvgt4X9nvGBDIY5TDiL0gHb9TDbzVOU/s320/IMG_2591.JPG" width="320" /></a></div>
<div style="text-align: center;">
量杯,一杯大約一人的份量。</div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtxKDIEa6PozRi4cnpOifeR9XFXtYH8lnATi6w1RBMRt00Ybo8lDKyuueITRQTeGL6xZPdrHmR4-KP0BWiwnMhp6HGDUoHC4EeUkDF52CzGTDGZnxzYQL3zFcftrIWIbCuE39iZeNajsc/s1600/IMG_2592.JPG" imageanchor="1"><img border="0" data-original-height="1200" data-original-width="1600" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtxKDIEa6PozRi4cnpOifeR9XFXtYH8lnATi6w1RBMRt00Ybo8lDKyuueITRQTeGL6xZPdrHmR4-KP0BWiwnMhp6HGDUoHC4EeUkDF52CzGTDGZnxzYQL3zFcftrIWIbCuE39iZeNajsc/s320/IMG_2592.JPG" width="320" /></a></div>
<div style="text-align: center;">
將將~這就是電子鍋的主體啦,上面有貼著貼紙,讓你知道每個元件所在處。</div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3-j0uD2VUGsMDTcqfPcfza9lQKEzpO94JEA4Peb-wka-RCoIZQtZ4pSp_jXsHO1WrGjvK6MA6tAi5H3kWllMCm_pxNgp1dWBnZozgKm64KelT9i5jmYXke-bcLudW8RW5l7y12RGmdS8/s1600/IMG_2593.JPG" imageanchor="1"><img border="0" data-original-height="1600" data-original-width="1200" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3-j0uD2VUGsMDTcqfPcfza9lQKEzpO94JEA4Peb-wka-RCoIZQtZ4pSp_jXsHO1WrGjvK6MA6tAi5H3kWllMCm_pxNgp1dWBnZozgKm64KelT9i5jmYXke-bcLudW8RW5l7y12RGmdS8/s320/IMG_2593.JPG" width="240" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgUCok5X9VOyXnBpl9Av1pFigwrlh5burOQEo53YmJejUGsEq0Lj7RjicOqgpksvfK3FsoqqnZKabLj4B1knGt289moL0JzPObO3eVBcC_MvVbjh_jS32Vh49e3jP-bbjUo0gAK2823b-o/s1600/IMG_2594.JPG" imageanchor="1"><img border="0" data-original-height="1200" data-original-width="1600" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgUCok5X9VOyXnBpl9Av1pFigwrlh5burOQEo53YmJejUGsEq0Lj7RjicOqgpksvfK3FsoqqnZKabLj4B1knGt289moL0JzPObO3eVBcC_MvVbjh_jS32Vh49e3jP-bbjUo0gAK2823b-o/s320/IMG_2594.JPG" width="320" /></a></div>
<div style="text-align: center;">
電子鍋上方與前方。</div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiaV7ic6lIbH-2AlIp1RbkgPpmHiMK7Clf_3Fih3t5-3BWnDsay_1ZsmiiT913aEeu5d0pd93Gi-r5i3kE9ZpjvUea2VU8Az-KUFgQFyLOaKWH3WMuLAxULfJTHXqmPmIDWp85SGAx9wRQ/s1600/IMG_2595.JPG" imageanchor="1"><img border="0" data-original-height="1200" data-original-width="1600" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiaV7ic6lIbH-2AlIp1RbkgPpmHiMK7Clf_3Fih3t5-3BWnDsay_1ZsmiiT913aEeu5d0pd93Gi-r5i3kE9ZpjvUea2VU8Az-KUFgQFyLOaKWH3WMuLAxULfJTHXqmPmIDWp85SGAx9wRQ/s320/IMG_2595.JPG" width="320" /></a></div>
<div style="text-align: center;">
電子鍋後方,這款電子鍋可以連接WiFi,早上出門把米放在電子鍋內,下班回家前,就可以用手機APP讓他開始煮飯囉。</div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgI5LxEQX8qgoSXVyENPO__BBZVP-kzSWR2KQSJZU9NCg4GF8DUjbDsfW6Em0EQAWBd5J5ireOTyqQQq_LmvyIj1ftUyCKrlbVrsmTokUQaHCuYTQ0g2gWq0d3T_KQVCrZ7FV8frDYUw5A/s1600/IMG_2596.JPG" imageanchor="1"><img border="0" data-original-height="1600" data-original-width="1200" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgI5LxEQX8qgoSXVyENPO__BBZVP-kzSWR2KQSJZU9NCg4GF8DUjbDsfW6Em0EQAWBd5J5ireOTyqQQq_LmvyIj1ftUyCKrlbVrsmTokUQaHCuYTQ0g2gWq0d3T_KQVCrZ7FV8frDYUw5A/s320/IMG_2596.JPG" width="240" /></a></div>
<div style="text-align: center;">
電子鍋內觀,上面有放一個白色的籃子,應該可以算是蒸籃,如果要蒸饅頭或地瓜之類的都可以放在這裡,只是空間不大,饅頭大概兩三顆就放不下了。</div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0QAs3zxOAuPlb8oo6iu7DlP-aw7xxdlSH1xgNw4R60_pVVKsuej6rfIXZtQ1BYURFGM0-kouWsZFn_1DR9MvGAhYL24vkDdoq7r58OCGCiKOSVx0V1v556iHvRpSYMo353qHX2n2izjg/s1600/IMG_2597.JPG" imageanchor="1"><img border="0" data-original-height="1200" data-original-width="1600" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0QAs3zxOAuPlb8oo6iu7DlP-aw7xxdlSH1xgNw4R60_pVVKsuej6rfIXZtQ1BYURFGM0-kouWsZFn_1DR9MvGAhYL24vkDdoq7r58OCGCiKOSVx0V1v556iHvRpSYMo353qHX2n2izjg/s320/IMG_2597.JPG" width="320" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPYOa9rMv-MZqybB8p_cCRL3O-kQes9Wlqi_mysarJT4xl6rFMDEec4na8ENqVKzB46CQxyXXX_JqVS7IMLl0af5OqFJ8qDS36S-wVrHunjCoTpCAT3F7K_BXt6RkHGFjXFC0X9XlkoSU/s1600/IMG_2598.JPG" imageanchor="1"><img border="0" data-original-height="1600" data-original-width="1200" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPYOa9rMv-MZqybB8p_cCRL3O-kQes9Wlqi_mysarJT4xl6rFMDEec4na8ENqVKzB46CQxyXXX_JqVS7IMLl0af5OqFJ8qDS36S-wVrHunjCoTpCAT3F7K_BXt6RkHGFjXFC0X9XlkoSU/s320/IMG_2598.JPG" width="240" /></a></div>
<div style="text-align: center;">
上蓋是可以拆下清洗的,說明書有說每次使用完畢,需要猜下來清洗唷。</div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibHsz09VTdU5ZHiT7dADQ3FvNAvDm7ER_5x62KEqPO8e7W5DKaEB2sxGjiJNpEhovCJQdOOfcMYKUgPgq-3fWfX90kGtbv0k-banPF_x4Lb1kI2AZOrhXfJOiiTxT0UoirP3D5PwQbCIk/s1600/IMG_2599.JPG" imageanchor="1"><img border="0" data-original-height="1600" data-original-width="1200" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibHsz09VTdU5ZHiT7dADQ3FvNAvDm7ER_5x62KEqPO8e7W5DKaEB2sxGjiJNpEhovCJQdOOfcMYKUgPgq-3fWfX90kGtbv0k-banPF_x4Lb1kI2AZOrhXfJOiiTxT0UoirP3D5PwQbCIk/s320/IMG_2599.JPG" width="240" /></a></div>
<div style="text-align: center;">
電子鍋內部。</div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiAq9EPIeJQY6damNkhkRtZmSYJKgltegrPeQRYh6l86R5LsXNUTa2uPUPEGOOvCHtJFvfjKyYTZCyQXViqQG4SNd0bUcmEaP3UzO_AK8hRnvIWKQ9Yc8U6iNKYRIDUU5fWIHmVzyH9vgU/s1600/IMG_2600.JPG" imageanchor="1"><img border="0" data-original-height="1600" data-original-width="1200" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiAq9EPIeJQY6damNkhkRtZmSYJKgltegrPeQRYh6l86R5LsXNUTa2uPUPEGOOvCHtJFvfjKyYTZCyQXViqQG4SNd0bUcmEaP3UzO_AK8hRnvIWKQ9Yc8U6iNKYRIDUU5fWIHmVzyH9vgU/s320/IMG_2600.JPG" width="240" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgN24R0Zb7Jl-fq2vgVU_ulSB3icWKcMqcd60G7SayGwCtX61s3jzbzP6Cu0NdqmjdqtipGMCLHqH6p0lMZLNjh6Yh3Rbh48F3ocTtZCUijpNVEh2N40HgoSG0gujOW97oRwSoKqsxt2Lc/s1600/IMG_2601.JPG" imageanchor="1"><img border="0" data-original-height="1600" data-original-width="1200" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgN24R0Zb7Jl-fq2vgVU_ulSB3icWKcMqcd60G7SayGwCtX61s3jzbzP6Cu0NdqmjdqtipGMCLHqH6p0lMZLNjh6Yh3Rbh48F3ocTtZCUijpNVEh2N40HgoSG0gujOW97oRwSoKqsxt2Lc/s320/IMG_2601.JPG" width="240" /></a></div>
<div style="text-align: center;">
內鍋有兩種標示,應該跟大部分的電鍋都一樣,讓媽媽們可以加水</div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2fZomM29Avr5gZlfPI2GmsVCmuRv_6Q1So0thgbskyxl4Bk4YBfhdVCKfKgWVXVlQA7L0LCrmlw62kn409mKu82oI2GLJcovvQ_siRwzr8XG-TSNCDYyuWc1u3tY6nRM0oCdoyPDqa_o/s1600/IMG_2602.JPG" imageanchor="1"><img border="0" data-original-height="1200" data-original-width="1600" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2fZomM29Avr5gZlfPI2GmsVCmuRv_6Q1So0thgbskyxl4Bk4YBfhdVCKfKgWVXVlQA7L0LCrmlw62kn409mKu82oI2GLJcovvQ_siRwzr8XG-TSNCDYyuWc1u3tY6nRM0oCdoyPDqa_o/s320/IMG_2602.JPG" width="320" /></a></div>
<div style="text-align: center;">
內鍋的外觀,官網說,這是大金PFA不沾鍋塗層,實際使用,的確蠻不沾鍋的。</div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: center;">
<br /></div>
<script async="" src="//js1.bloggerads.net/contentads.aspx?blogid=20150916000016" type="text/javascript"></script>
JackLiaohttp://www.blogger.com/profile/15196682200013649498noreply@blogger.comtag:blogger.com,1999:blog-9161883088729562959.post-80857282709604327012018-11-12T14:16:00.002+08:002022-04-06T17:38:27.472+08:00 [Android] WebView內嵌Youtube無法全螢幕的解決方式開發WebView的時候,卻發現,網頁上如果有 Youtube的影片,可以正常播放,但卻無法全螢幕,找了許久,找到了解法。<br />
<br />
<a name='more'></a><br />
<br />
<br />
<br />
<br />
<br />
.java<br />
<div>
<br /></div>
<div>
FrameLayout mVideoView; //將播放影片的View丟到LrameLayout來實現全螢幕效果
private View mCustomView; //用於存放目前影片的View
WebChromeClient.CustomViewCallback customViewCallback;<br />
<br />
mWebView.setWebChromeClient(new MyWebChromeClient());<br />
<br />
class MyWebChromeClient extends WebChromeClient {</div>
<div>
@Override <br />
public void onShowCustomView(View view, int requestedOrientation,</div>
<div>
CustomViewCallback callback) {</div>
<div>
onShowCustomView(view, callback);</div>
<div>
}</div>
<div>
<br /></div>
<div>
@Override <br />
public void onShowCustomView(View view,CustomViewCallback callback) {</div>
<div>
if (mCustomView != null) {</div>
<div>
callback.onCustomViewHidden();</div>
<div>
return; </div>
<div>
}</div>
<div>
mCustomView = view;</div>
<div>
mWebView.setVisibility(View.GONE);</div>
<div>
mVideoView.setVisibility(View.VISIBLE);</div>
<div>
mVideoView.addView(view);</div>
<div>
customViewCallback = callback;</div>
<div>
hideSystemUI();</div>
<div>
}</div>
<div>
@Override <br />
public void onHideCustomView() {</div>
<div>
super.onHideCustomView();</div>
<div>
if (mCustomView == null)
return;</div>
<div>
<br /></div>
<div>
mWebView.setVisibility(View.VISIBLE);</div>
<div>
mVideoView.setVisibility(View.GONE);</div>
<div>
// Hide the custom view. </div>
<div>
mCustomView.setVisibility(View.GONE);</div>
<div>
<br /></div>
<div>
// Remove the custom view from its container.<br />
mVideoView.removeView(mCustomView);<br />
customViewCallback.onCustomViewHidden();<br />
showSystemUI();<br />
mCustomView = null;<br />
} </div>
<div>
}</div>
<div>
<br />
//若改Activity被設成垂直顯示時,執行全螢幕將改為水平呈現。<br />
private void hideSystemUI() {</div>
<div>
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);</div>
<div>
View decorView = getWindow().getDecorView();</div>
<div>
decorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_IMMERSIVE<br />
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE</div>
<div>
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION<br />
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN<br />
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION<br />
| View.SYSTEM_UI_FLAG_FULLSCREEN<br />
);<br />
}<br />
<br />
.xml<br />
<?xml version="1.0" encoding="utf-8"?><br />
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"</div>
<div>
xmlns:app="http://schemas.android.com/apk/res-auto"<br />
android:layout_width="match_parent"<br />
android:layout_height="match_parent"<br />
android:background="@color/colorMaster"></div>
<div>
<br />
<WebView<br />
android:id="@+id/webView"<br />
android:layout_width="match_parent"<br />
android:layout_height="match_parent"/></div>
<div>
<FrameLayout<br />
android:id="@+id/video_view"<br />
android:layout_width="match_parent"<br />
android:layout_height="match_parent"<br />
android:visibility="gone" /></div>
<div>
</android.support.constraint.ConstraintLayout><br />
<br />
<br />
<script type="text/javascript" src="//js1.bloggerads.net/contentads.aspx?blogid=20150916000016" async></script>
<pre style="font-family: Menlo; font-size: 9pt;"></pre>
</div>
JackLiaohttp://www.blogger.com/profile/15196682200013649498noreply@blogger.comtag:blogger.com,1999:blog-9161883088729562959.post-58031963696296410352018-05-17T15:53:00.001+08:002022-04-06T17:38:36.324+08:00【開箱文】小米空氣淨化器2S<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhwKDgH7Ym2nSb99OJqqYw3N1BoeOSbIFDhN3XmA6OdyY_uT7o8y2YqfqJVLg7JfJ64vncP7u7tqzz3kGphz7h4whEdcHjyhy9crVF56IXy91knTeK5-l_SFl4kWXRJjOLBJG7LWHhcvnE/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-05-17+14.55.40.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="97" data-original-width="853" height="45" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhwKDgH7Ym2nSb99OJqqYw3N1BoeOSbIFDhN3XmA6OdyY_uT7o8y2YqfqJVLg7JfJ64vncP7u7tqzz3kGphz7h4whEdcHjyhy9crVF56IXy91knTeK5-l_SFl4kWXRJjOLBJG7LWHhcvnE/s400/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-05-17+14.55.40.png" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
收到台灣小米官網的到貨提醒,當下立即上網訂購 ,不到24小時,淨化器已經到手囉。</div>
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpS4hje1JCvkbR0NfU9j6lkbKap99AEASVyy1G0d6ndyNlf77bLCPGcsVWn4bI4FWaI4UtjPBibESjRQQ1g6BcazF9M1EW36TGlaXtnEIvKesAKmqrZSseF0dMR2vsowmYRXAt4ztKHxA/s1600/IMG_2073.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1200" data-original-width="1600" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpS4hje1JCvkbR0NfU9j6lkbKap99AEASVyy1G0d6ndyNlf77bLCPGcsVWn4bI4FWaI4UtjPBibESjRQQ1g6BcazF9M1EW36TGlaXtnEIvKesAKmqrZSseF0dMR2vsowmYRXAt4ztKHxA/s320/IMG_2073.JPG" width="320" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhyMSfYY3p70YWCG5vNoT0A1nQW0v_vUJcM9gfWbV2WNj9B3rWr0x_74S_VYGUl_Mbuj179EZYe8toPNF7WbXiJv_SIHEiXHk0MU_CZ20wgdWZmzxgsHf_dMLKfPLbGVIJxnWOk6NxycmU/s1600/IMG_2072.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1600" data-original-width="1200" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhyMSfYY3p70YWCG5vNoT0A1nQW0v_vUJcM9gfWbV2WNj9B3rWr0x_74S_VYGUl_Mbuj179EZYe8toPNF7WbXiJv_SIHEiXHk0MU_CZ20wgdWZmzxgsHf_dMLKfPLbGVIJxnWOk6NxycmU/s320/IMG_2072.JPG" width="240" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
外箱包裝很簡單,正面提示你配件都放在淨化器裡面。</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGdpzhAJMRvZWuUaCJDgeTDf4NSxFqFjOMkoCgygEBloGdCcVzIF9il02yBN11rqZSk_Wk97b9Kmi7s_4-VtYllfF8wkFuGieggi2Ca0UztiNq66zs14IWveHrBwjUAM7IYyY24I87jRY/s1600/IMG_2074.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1200" data-original-width="1600" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGdpzhAJMRvZWuUaCJDgeTDf4NSxFqFjOMkoCgygEBloGdCcVzIF9il02yBN11rqZSk_Wk97b9Kmi7s_4-VtYllfF8wkFuGieggi2Ca0UztiNq66zs14IWveHrBwjUAM7IYyY24I87jRY/s320/IMG_2074.JPG" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
打開外箱,裡頭就是今天的主角。</div>
<br />
<a name='more'></a><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4wm_e25cGPjeScncBVqHegUA1hOQ_Kz1dCNIrH94oXmXMXzmJrbcyKq6xnPorz8fRH-xQBf7KSXSjl8UyuRCOLwjEQZNvVRjl5DN1gO0HWfRcpB099u8ilgZY6G_GO21zk8XLqxONlVU/s1600/IMG_2076.JPG" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" data-original-height="1600" data-original-width="1200" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4wm_e25cGPjeScncBVqHegUA1hOQ_Kz1dCNIrH94oXmXMXzmJrbcyKq6xnPorz8fRH-xQBf7KSXSjl8UyuRCOLwjEQZNvVRjl5DN1gO0HWfRcpB099u8ilgZY6G_GO21zk8XLqxONlVU/s320/IMG_2076.JPG" width="240" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJkxgmcMnYmzKd26vKpiWcpKIEKuCGq4WlSQoyER8aLLC6oFRwsxS4faFGrsIOapWG4i9YdO7WmBIDDnnmv3t5eXfMenwT8VKOSlrvn7W5idagAuO0fvDrlqgaCpxH4sjsvBKG33R8ni4/s1600/IMG_2075.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1600" data-original-width="1200" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJkxgmcMnYmzKd26vKpiWcpKIEKuCGq4WlSQoyER8aLLC6oFRwsxS4faFGrsIOapWG4i9YdO7WmBIDDnnmv3t5eXfMenwT8VKOSlrvn7W5idagAuO0fvDrlqgaCpxH4sjsvBKG33R8ni4/s320/IMG_2075.JPG" width="240" /></a></div>
<div class="" style="clear: both; text-align: center;">
登愣~ 跟2代比正面好像只是多個螢幕,背面則沒有差太多。</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieZrkOIhG9AYYoqlRNSFPCipBVxKLZ4ZH3KCHWL7K-wMrk042TxHayFFxQkD0Oj11KvNQHoBxk3dZY6unnugOLEVj0LhWmqQ5ypCgTvnw-yLcJCF2GbCNKrPXnPMC5A2dAImMsEqTsLtM/s1600/IMG_2077.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1600" data-original-width="1200" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieZrkOIhG9AYYoqlRNSFPCipBVxKLZ4ZH3KCHWL7K-wMrk042TxHayFFxQkD0Oj11KvNQHoBxk3dZY6unnugOLEVj0LhWmqQ5ypCgTvnw-yLcJCF2GbCNKrPXnPMC5A2dAImMsEqTsLtM/s320/IMG_2077.JPG" width="240" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
背蓋打開,可以看到有濾網與它的電源線。</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgF3uJk8zbXlH6sB8_b8CYhkMuiyvUZQOvqkJ-vFx-9J1Tdri6sCh4wOnK7hZ23aALDw5V1l5BSNEa8LwsFo_MX4YfCYuTC-zJ_FN8xNP1ejUUVoPKfd61uqdvmJIHkzOQIv-bgFqcPPPk/s1600/IMG_2089.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1600" data-original-width="1200" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgF3uJk8zbXlH6sB8_b8CYhkMuiyvUZQOvqkJ-vFx-9J1Tdri6sCh4wOnK7hZ23aALDw5V1l5BSNEa8LwsFo_MX4YfCYuTC-zJ_FN8xNP1ejUUVoPKfd61uqdvmJIHkzOQIv-bgFqcPPPk/s320/IMG_2089.JPG" width="240" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
淨化器ㄕㄤ</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgXHFxG2NB2Be3BCyAyc6JeSy6omNEA_CynyKKaCEPkuf2grvCPBV8ytvlN2ywIqXBDHzY_6pYB-I0_j__O0KasAAnIllFqL0l-NyWoYhQj7_X7BkbCkTQhV6oQOzmDgeN6aI8r6UfZ3I/s1600/IMG_2078.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1600" data-original-width="1200" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgXHFxG2NB2Be3BCyAyc6JeSy6omNEA_CynyKKaCEPkuf2grvCPBV8ytvlN2ywIqXBDHzY_6pYB-I0_j__O0KasAAnIllFqL0l-NyWoYhQj7_X7BkbCkTQhV6oQOzmDgeN6aI8r6UfZ3I/s320/IMG_2078.JPG" width="240" /></a></div>
<div class="" style="clear: both; text-align: center;">
濾網的封膜上提醒你,使用前一定要先拆封膜喔。</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgCDsUNVVSC9BXH9mq_DFwtRJzM3xX6Zyu7Ud06g1tH2cUqe-f650ZueW3ErRSEN239gW_ud598O45XpsFTsDAmblhYl2QT3vYeWkhUslBbWnaOy0q1ynYYTWI59UXEoQPeLNLttyLxvg/s1600/IMG_2079.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1600" data-original-width="1200" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgCDsUNVVSC9BXH9mq_DFwtRJzM3xX6Zyu7Ud06g1tH2cUqe-f650ZueW3ErRSEN239gW_ud598O45XpsFTsDAmblhYl2QT3vYeWkhUslBbWnaOy0q1ynYYTWI59UXEoQPeLNLttyLxvg/s320/IMG_2079.JPG" width="240" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgJCUqHgo41A65t3bMminqL3uZdvC4SAsEcLJdeU-4YWOznCqabKmJkNdTVAU4zJX4jpiRbOcg-5rs9bdwKn7CeQn_jmRmDy16xYC1o69y6eh6gqMcYIUQmJ8Kv3dDrqpuPn2KZRnn9q8/s1600/IMG_2080.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1600" data-original-width="1200" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgJCUqHgo41A65t3bMminqL3uZdvC4SAsEcLJdeU-4YWOznCqabKmJkNdTVAU4zJX4jpiRbOcg-5rs9bdwKn7CeQn_jmRmDy16xYC1o69y6eh6gqMcYIUQmJ8Kv3dDrqpuPn2KZRnn9q8/s320/IMG_2080.JPG" width="240" /></a></div>
<div class="" style="clear: both; text-align: center;">
過濾網的下方有一張RFID貼紙,應該是淨化器用來判斷此濾芯是否為原廠的,如果不是原廠濾心倒是不知道能不能使用。</div>
<div style="text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiS-iNj5l8Zl4up0iTBj7lGbW3DLd4RHXNevXwyqCENdItDFHx0GxGV9DzU-x8heRJusObu-qPY9v6OQKJ9jCS6k8fNkAZQa4OPMZhXgw_OupkxXe_in7FFzJ_VuSKeEjtleZSk6U74ZOY/s1600/IMG_2081.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1600" data-original-width="1200" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiS-iNj5l8Zl4up0iTBj7lGbW3DLd4RHXNevXwyqCENdItDFHx0GxGV9DzU-x8heRJusObu-qPY9v6OQKJ9jCS6k8fNkAZQa4OPMZhXgw_OupkxXe_in7FFzJ_VuSKeEjtleZSk6U74ZOY/s320/IMG_2081.JPG" width="240" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
背蓋裡有濾芯更換與粉塵感應器清潔的方法。</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcBFHVZyCHFLx9qeK9RFXr_oVNV0rVGCeczCbV7yaUldkcWJxWwcs6IVkE1bEz9A5kuaTl2mzlmLeKKUF-3s19O02DdyliPn5-gDxU68FeQaApGOmipsIwvte7eF6rytxQLc3MMtYSrZ4/s1600/IMG_2084.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1600" data-original-width="1200" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcBFHVZyCHFLx9qeK9RFXr_oVNV0rVGCeczCbV7yaUldkcWJxWwcs6IVkE1bEz9A5kuaTl2mzlmLeKKUF-3s19O02DdyliPn5-gDxU68FeQaApGOmipsIwvte7eF6rytxQLc3MMtYSrZ4/s320/IMG_2084.JPG" width="240" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
粉塵感應器在背蓋的上方。</div>
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhxsgL16t33UyyCWSUMKEc_pStSoBQOOoTAZRQWHTD96bWViai4VqmrK3OvLKumfs1P_he-LowbQwsu0wCHXw_hdi-FmNcgeZc5MJrIeW_ljXpuZS9GdGmKHKx99BO5-8PhGyFDY1a1NM/s1600/IMG_2083.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1600" data-original-width="1203" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhxsgL16t33UyyCWSUMKEc_pStSoBQOOoTAZRQWHTD96bWViai4VqmrK3OvLKumfs1P_he-LowbQwsu0wCHXw_hdi-FmNcgeZc5MJrIeW_ljXpuZS9GdGmKHKx99BO5-8PhGyFDY1a1NM/s320/IMG_2083.JPG" width="240" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
從淨化器裡面往上看。</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXpBrEpZ_agKQPiSIjCa6Q2mYKOzzDkCeWSwRlqcVj1xHCYfHu__W__IfJ13bUGF4iNZiDEmfMqP93BXIn7sTEVlicFYDX5wlzbjksQcfbqntSySWVMe10GLYctEerGjKQf74Plt2F2Mk/s1600/IMG_2085.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1600" data-original-width="1200" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXpBrEpZ_agKQPiSIjCa6Q2mYKOzzDkCeWSwRlqcVj1xHCYfHu__W__IfJ13bUGF4iNZiDEmfMqP93BXIn7sTEVlicFYDX5wlzbjksQcfbqntSySWVMe10GLYctEerGjKQf74Plt2F2Mk/s320/IMG_2085.JPG" width="240" /></a></div>
<div class="" style="clear: both; text-align: center;">
放置濾芯的基座有彈簧卡榫,能使濾心卡的更緊,以免髒空氣偷渡跑走。</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMwoEh17Rc3IHbZhjYQyofX62SKQP84nx2HXwfzj7sDD7j8rdBOAMDkNoZ53j4fRgbMSUOCuMgDRVXP9nVNWahcxFX0VBupOhKLZXSZqd1QwFJnlMukpi19hCTkQerh-0JljpVOJZvtrY/s1600/IMG_2088.JPG" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" data-original-height="1600" data-original-width="1200" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMwoEh17Rc3IHbZhjYQyofX62SKQP84nx2HXwfzj7sDD7j8rdBOAMDkNoZ53j4fRgbMSUOCuMgDRVXP9nVNWahcxFX0VBupOhKLZXSZqd1QwFJnlMukpi19hCTkQerh-0JljpVOJZvtrY/s320/IMG_2088.JPG" width="240" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhCnOjesD7TXoIweUz8znclm-VGDn_zqY_kEDgetu8dxGaZ6GuRCY8RZl-9WSsiQnMgU2AjJBHI1virOyGn2R5faxtt5Q5k83EHkjjCU13ZJm2SAOavVEPjNsF5i9ge7SSrZNHCcep86H0/s1600/IMG_2086.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1600" data-original-width="1200" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhCnOjesD7TXoIweUz8znclm-VGDn_zqY_kEDgetu8dxGaZ6GuRCY8RZl-9WSsiQnMgU2AjJBHI1virOyGn2R5faxtt5Q5k83EHkjjCU13ZJm2SAOavVEPjNsF5i9ge7SSrZNHCcep86H0/s320/IMG_2086.JPG" width="240" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
電源線與說明書</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikONnmiwwHRS43pIb2ypowQFxrK9HtCAGd5t_F0hpVUYqbahxWJxxDIR8psbLFzkCtWN7X5R06o0ymN2TRzRM8d5Q99AEmoAZ4Yl7XrtPefCNNVvlBAc-n2qiIdC-tlQvEgTSL65R80I8/s1600/IMG_2091.JPG" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" data-original-height="1600" data-original-width="1200" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikONnmiwwHRS43pIb2ypowQFxrK9HtCAGd5t_F0hpVUYqbahxWJxxDIR8psbLFzkCtWN7X5R06o0ymN2TRzRM8d5Q99AEmoAZ4Yl7XrtPefCNNVvlBAc-n2qiIdC-tlQvEgTSL65R80I8/s320/IMG_2091.JPG" width="240" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOw9aU_OmEeScbbPCb3LGpsVJNm116iLdzvtlpFUIgsJHCMRary00N7mCBwzZ27FQhByIhYCGYsAhSVP1lqlA_-YMFYLT8GNHrsvpKBUNbnx-Z12L3sy7hO2SwnkfCXfPmH_u4VEeB1Yc/s1600/IMG_2090.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1600" data-original-width="1200" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOw9aU_OmEeScbbPCb3LGpsVJNm116iLdzvtlpFUIgsJHCMRary00N7mCBwzZ27FQhByIhYCGYsAhSVP1lqlA_-YMFYLT8GNHrsvpKBUNbnx-Z12L3sy7hO2SwnkfCXfPmH_u4VEeB1Yc/s320/IMG_2090.JPG" width="240" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
濾網上方含有很不明顯的使用日期可填寫。</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
將一切安裝好之後,通電就可以開始使用囉。</div>
<div class="separator" style="clear: both; text-align: center;">
但若在外想要控制開啟淨化器,或觀看家中的空氣品質、溫濕度也可以使用米家APP觀看喔。</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBpdkhrhC_lczQMqpdF1bhodWq0r0bd0S3gckR76EksWTGF5fz5iX2g3QvHvUwYnR1RgcZxaAORrQGU63RzP6u-W2En5Fpe4C4-IvUNu0v7K77fSHqWVdpXj8nYByn6jVagrABlLcGn04/s1600/IMG_2092.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1600" data-original-width="739" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBpdkhrhC_lczQMqpdF1bhodWq0r0bd0S3gckR76EksWTGF5fz5iX2g3QvHvUwYnR1RgcZxaAORrQGU63RzP6u-W2En5Fpe4C4-IvUNu0v7K77fSHqWVdpXj8nYByn6jVagrABlLcGn04/s320/IMG_2092.PNG" width="147" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
米家點選新增裝置,選擇小米空氣淨化器2S。</div>
<div class="separator" style="clear: both; text-align: center;">
(拍攝時選錯了,選到小米空氣淨化器2,但在使用上暫時沒有發現有什麼差別)</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzJLff74ABDz5dZ0GWQyzjtazuVcloM5yBSJLHxj8z9XitW41DhGkTGi4Q9PSDBHtbSrDuNi3iXWNLigXZDTBiHD1vQntkMGMBZFV4FDB3tPZy-sBKR2FoSgcZArRZvbmEgWgKE_Gr52g/s1600/IMG_2093.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1600" data-original-width="739" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzJLff74ABDz5dZ0GWQyzjtazuVcloM5yBSJLHxj8z9XitW41DhGkTGi4Q9PSDBHtbSrDuNi3iXWNLigXZDTBiHD1vQntkMGMBZFV4FDB3tPZy-sBKR2FoSgcZArRZvbmEgWgKE_Gr52g/s320/IMG_2093.PNG" width="147" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
選擇完之後就依照APP指示一步一步的往下操作。</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmeCTdDw8B3NR9WNRX1_9yUj0xkYuxnvb5NToZNV5TUshEgCFOzmtllgUiPIZsfEBaKbSZ_hnbHHZwabOslFk-S8tPwaMS0EZgI-6TjVa_K4fI-bzv3Bcj7ocb2GjDWDmiWEY_QOI5jjA/s1600/IMG_2094.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1600" data-original-width="739" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmeCTdDw8B3NR9WNRX1_9yUj0xkYuxnvb5NToZNV5TUshEgCFOzmtllgUiPIZsfEBaKbSZ_hnbHHZwabOslFk-S8tPwaMS0EZgI-6TjVa_K4fI-bzv3Bcj7ocb2GjDWDmiWEY_QOI5jjA/s320/IMG_2094.PNG" width="147" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
因為是WiFi控制,所以必須先讓他連上你家中的WiFi。</div>
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPz6vdkFi7cn5TQ2CmL_a5TuN-LUjzuLwr4lTlewEBHuHVCICTo4hCYhFpgdTm3o1F92nQXEcCKKHcful6dSBO-6I0NcNNW2Dhd3P8AejEoFZlNoZcrUAhineKDjAce32-XzdAtOl1QsA/s1600/IMG_2095.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1600" data-original-width="739" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPz6vdkFi7cn5TQ2CmL_a5TuN-LUjzuLwr4lTlewEBHuHVCICTo4hCYhFpgdTm3o1F92nQXEcCKKHcful6dSBO-6I0NcNNW2Dhd3P8AejEoFZlNoZcrUAhineKDjAce32-XzdAtOl1QsA/s320/IMG_2095.PNG" width="147" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
淨化器連接到家中的WiFi後,會要你將手機連接到『淨化器』本身的WiFi喔。</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvFnQvgU_gejvoy0WTD29WeDOUHr2ap7ExKcgODnZNnlLJfWbdazB65TaBoYzv4I4V9XEoVpQ_lWuYoBhhISsAVV3T1Hsk7g01TPRh63h6w_z1VTNT8rQ9jiAWb668K9KulzR_QbljwNc/s1600/IMG_2096.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1600" data-original-width="739" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvFnQvgU_gejvoy0WTD29WeDOUHr2ap7ExKcgODnZNnlLJfWbdazB65TaBoYzv4I4V9XEoVpQ_lWuYoBhhISsAVV3T1Hsk7g01TPRh63h6w_z1VTNT8rQ9jiAWb668K9KulzR_QbljwNc/s320/IMG_2096.PNG" width="147" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
連接成功就等初始化設定。</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihS3JB_xZzTGPHCeMe2AsALbjPwlynnwDa8fjYwwVUk90wgGUQuFjULIcEXGq5IZVMDVnd3s5sKpHhGh7U1Vvd3HZpjCSAYm7gXv9s89UWQQrtC8uYylEnUdZEanurl-wxZIWxynX2jSU/s1600/IMG_2097.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1600" data-original-width="739" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihS3JB_xZzTGPHCeMe2AsALbjPwlynnwDa8fjYwwVUk90wgGUQuFjULIcEXGq5IZVMDVnd3s5sKpHhGh7U1Vvd3HZpjCSAYm7gXv9s89UWQQrtC8uYylEnUdZEanurl-wxZIWxynX2jSU/s320/IMG_2097.PNG" width="147" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
設定完成就直接進到畫面中。</div>
<br />
<br />
<br />
<br />
<script type="text/javascript" src="//js1.bloggerads.net/contentads.aspx?blogid=20150916000016" async></script>JackLiaohttp://www.blogger.com/profile/15196682200013649498noreply@blogger.comtag:blogger.com,1999:blog-9161883088729562959.post-29747045349118784152016-07-31T02:26:00.001+08:002022-04-06T17:38:54.863+08:00Laravel 使用 GCS 做為儲存空間<b>前言</b><br />
Laravel 有內建 Filesystem 套件,所以可以用來和例如 Amazon S3, Dropbox, Google Cloud Storage 等等服務串接<br />
<br />
但找了一下發現和 Google Cloud Storage (GCS) 這方面的資料好像滿零散的<br />
所以整理了一下<br />
<br />
<b>正文</b><br />
GCS 使用的 API 和 S3 是相同的,但是目前只有 v2 有支援,所以需要安裝 v2 的 s3 相關套件,於 composer.json 的 require 加上<br />
<br />
<div class="phpCode" style="overflow: auto;">
<pre class="prettyprint" style="border: 1px solid rgb(136, 136, 136); padding: 2px;"><span class="pln"> </span><span class="pun" style="color: #666600;">{</span><span class="pln"> </span><span class="pun" style="color: #666600;">...</span>
<span class="pln"> </span><span class="str" style="color: #008800;">"league/flysystem-aws-s3-v2"</span><span class="pun" style="color: #666600;">:</span><span class="pln"> </span><span class="str" style="color: #008800;">"~1.0"</span>
<span class="pln"> </span><span class="pun" style="color: #666600;">…</span><span class="pln"> </span><span class="pun" style="color: #666600;">}</span>
<span class="pln"> </span></pre>
</div>
<br />
<br />
然後 composer update 或是 install<br />
<br />
<a name='more'></a><br /><br />
<br />
再來是建立 GCS 專用的 Laravel Filesystem Provider Service<br />
於 app\Providers 建立 GCSServiceProvider.php<br />
<br />
<div class="phpCode" style="overflow: auto;">
<pre class="prettyprint" style="border: 1px solid rgb(136, 136, 136); padding: 2px;"><span class="pln"> </span><span class="kwd" style="color: #000088;">namespace</span><span class="pln"> </span><span class="typ" style="color: #660066;">App</span><span class="pln">\Providers</span><span class="pun" style="color: #666600;">;</span>
<span class="pln"> </span>
<span class="pln"> </span><span class="kwd" style="color: #000088;">use</span><span class="pln"> </span><span class="typ" style="color: #660066;">Illuminate</span><span class="pln">\Support\ServiceProvider</span><span class="pun" style="color: #666600;">;</span>
<span class="pln"> </span><span class="kwd" style="color: #000088;">use</span><span class="pln"> </span><span class="typ" style="color: #660066;">Storage</span><span class="pun" style="color: #666600;">;</span>
<span class="pln"> </span><span class="kwd" style="color: #000088;">use</span><span class="pln"> </span><span class="typ" style="color: #660066;">Aws</span><span class="pln">\S</span><span class="lit" style="color: #006666;">3</span><span class="pln">\S</span><span class="lit" style="color: #006666;">3Client</span><span class="pun" style="color: #666600;">;</span>
<span class="pln"> </span><span class="kwd" style="color: #000088;">use</span><span class="pln"> </span><span class="typ" style="color: #660066;">League</span><span class="pln">\Flysystem\AwsS3v2\AwsS3Adapter</span><span class="pun" style="color: #666600;">;</span>
<span class="pln"> </span><span class="kwd" style="color: #000088;">use</span><span class="pln"> </span><span class="typ" style="color: #660066;">League</span><span class="pln">\Flysystem\Filesystem</span><span class="pun" style="color: #666600;">;</span>
<span class="pln"> </span>
<span class="pln"> </span><span class="kwd" style="color: #000088;">class</span><span class="pln"> </span><span class="typ" style="color: #660066;">CloudStorageServiceProvider</span><span class="pln"> </span><span class="kwd" style="color: #000088;">extends</span><span class="pln"> </span><span class="typ" style="color: #660066;">ServiceProvider</span><span class="pun" style="color: #666600;">{</span>
<span class="pln"> </span><span class="kwd" style="color: #000088;">public</span><span class="pln"> </span><span class="kwd" style="color: #000088;">function</span><span class="pln"> boot</span><span class="pun" style="color: #666600;">(){</span>
<span class="pln"> </span><span class="typ" style="color: #660066;">Storage</span><span class="pun" style="color: #666600;">::</span><span class="pln">extend</span><span class="pun" style="color: #666600;">(</span><span class="str" style="color: #008800;">'gcs'</span><span class="pun" style="color: #666600;">,</span><span class="pln"> </span><span class="kwd" style="color: #000088;">function</span><span class="pun" style="color: #666600;">(</span><span class="pln"> $app</span><span class="pun" style="color: #666600;">,</span><span class="pln"> $config </span><span class="pun" style="color: #666600;">)</span>
<span class="pln"> </span><span class="pun" style="color: #666600;">{</span>
<span class="pln"> $client </span><span class="pun" style="color: #666600;">=</span><span class="pln"> S3Client</span><span class="pun" style="color: #666600;">::</span><span class="pln">factory</span><span class="pun" style="color: #666600;">([</span>
<span class="pln"> </span><span class="str" style="color: #008800;">'key'</span><span class="pln"> </span><span class="pun" style="color: #666600;">=></span><span class="pln"> $config</span><span class="pun" style="color: #666600;">[</span><span class="str" style="color: #008800;">'key'</span><span class="pun" style="color: #666600;">],</span>
<span class="pln"> </span><span class="str" style="color: #008800;">'secret'</span><span class="pln"> </span><span class="pun" style="color: #666600;">=></span><span class="pln"> $config</span><span class="pun" style="color: #666600;">[</span><span class="str" style="color: #008800;">'secret'</span><span class="pun" style="color: #666600;">],</span>
<span class="pln"> </span><span class="str" style="color: #008800;">'region'</span><span class="pln"> </span><span class="pun" style="color: #666600;">=></span><span class="pln"> $config</span><span class="pun" style="color: #666600;">[</span><span class="str" style="color: #008800;">'region'</span><span class="pun" style="color: #666600;">],</span>
<span class="pln"> </span><span class="str" style="color: #008800;">'base_url'</span><span class="pln"> </span><span class="pun" style="color: #666600;">=></span><span class="pln"> $config</span><span class="pun" style="color: #666600;">[</span><span class="str" style="color: #008800;">'base_url'</span><span class="pun" style="color: #666600;">],</span>
<span class="pln"> </span><span class="pun" style="color: #666600;">]);</span>
<span class="pln"> </span>
<span class="pln"> </span><span class="kwd" style="color: #000088;">return</span><span class="pln"> </span><span class="kwd" style="color: #000088;">new</span><span class="pln"> </span><span class="typ" style="color: #660066;">Filesystem</span><span class="pun" style="color: #666600;">(</span><span class="kwd" style="color: #000088;">new</span><span class="pln"> </span><span class="typ" style="color: #660066;">AwsS3Adapter</span><span class="pun" style="color: #666600;">(</span><span class="pln">$client</span><span class="pun" style="color: #666600;">,</span><span class="pln"> $config</span><span class="pun" style="color: #666600;">[</span><span class="str" style="color: #008800;">'bucket'</span><span class="pun" style="color: #666600;">]));</span>
<span class="pln"> </span><span class="pun" style="color: #666600;">});</span>
<span class="pln"> </span><span class="pun" style="color: #666600;">}</span>
<span class="pln"> </span>
<span class="pln"> </span><span class="kwd" style="color: #000088;">public</span><span class="pln"> </span><span class="kwd" style="color: #000088;">function</span><span class="pln"> </span><span class="kwd" style="color: #000088;">register</span><span class="pun" style="color: #666600;">(){</span>
<span class="pln"> </span><span class="pun" style="color: #666600;">}</span>
<span class="pln"> </span><span class="pun" style="color: #666600;">}</span>
<span class="pln"> </span></pre>
</div>
<br />
<br />
然後在 config/app.php 載入剛剛建立的 Provider<br />
<div class="javaCode" style="overflow: auto;">
<pre class="prettyprint" style="border: 1px solid rgb(136, 136, 136); padding: 2px;"><span class="pln"> </span><span class="pun" style="color: #666600;">‘</span><span class="pln">providers</span><span class="pun" style="color: #666600;">’</span><span class="pln"> </span><span class="pun" style="color: #666600;">=></span><span class="pln"> </span><span class="pun" style="color: #666600;">[</span>
<span class="pln"> </span><span class="pun" style="color: #666600;">...</span>
<span class="pln"> </span><span class="typ" style="color: #660066;">App</span><span class="pln">\Providers\G</span><span class="typ" style="color: #660066;">CSServiceProvider</span><span class="pun" style="color: #666600;">::</span><span class="kwd" style="color: #000088;">class</span><span class="pun" style="color: #666600;">,</span>
<span class="pln"> </span><span class="pun" style="color: #666600;">...</span>
<span class="pln"> </span><span class="pun" style="color: #666600;">]</span>
<span class="pln"> </span></pre>
</div>
<br />
<br />
<br />
接下來是在 Laravel 中的 config/filesystem.php 加上 GCS 的設定<br />
(這邊要到 Google Cloud Console 取得 Storage 相關的 API Key )<br />
<br />
<div class="javaCode" style="overflow: auto;">
<pre class="prettyprint" style="border: 1px solid rgb(136, 136, 136); padding: 2px;"><span class="pln"> </span><span class="str" style="color: #008800;">'gcs'</span><span class="pln"> </span><span class="pun" style="color: #666600;">=></span><span class="pln"> </span><span class="pun" style="color: #666600;">[</span>
<span class="pln"> </span><span class="str" style="color: #008800;">'driver'</span><span class="pln"> </span><span class="pun" style="color: #666600;">=></span><span class="pln"> </span><span class="str" style="color: #008800;">'gcs'</span><span class="pun" style="color: #666600;">,</span>
<span class="pln"> </span><span class="str" style="color: #008800;">'key'</span><span class="pln"> </span><span class="pun" style="color: #666600;">=></span><span class="pln"> </span><span class="str" style="color: #008800;">'KEYYYYYYY'</span><span class="pun" style="color: #666600;">,</span>
<span class="pln"> </span><span class="str" style="color: #008800;">'secret'</span><span class="pln"> </span><span class="pun" style="color: #666600;">=></span><span class="pln"> </span><span class="str" style="color: #008800;">'SEC_KEY'</span><span class="pun" style="color: #666600;">,</span>
<span class="pln"> </span><span class="str" style="color: #008800;">'region'</span><span class="pln"> </span><span class="pun" style="color: #666600;">=></span><span class="pln"> </span><span class="str" style="color: #008800;">'ASIA-EAST1'</span><span class="pun" style="color: #666600;">,</span>
<span class="pln"> </span><span class="str" style="color: #008800;">'bucket'</span><span class="pln"> </span><span class="pun" style="color: #666600;">=></span><span class="pln"> </span><span class="str" style="color: #008800;">'BUKET_NAME'</span><span class="pun" style="color: #666600;">,</span>
<span class="pln"> </span><span class="str" style="color: #008800;">'base_url'</span><span class="pun" style="color: #666600;">=></span><span class="str" style="color: #008800;">'https://storage.googleapis.com'</span><span class="pun" style="color: #666600;">,</span>
<span class="pln"> </span><span class="pun" style="color: #666600;">],</span>
<span class="pln"> </span></pre>
</div>
<br />
<br />
<br />
接下來就可以使用了,範例:<br />
<div class="javaCode" style="overflow: auto;">
<pre class="prettyprint" style="border: 1px solid rgb(136, 136, 136); padding: 2px;"><span class="pln"> $disk </span><span class="pun" style="color: #666600;">=</span><span class="pln"> </span><span class="typ" style="color: #660066;">Storage</span><span class="pun" style="color: #666600;">::</span><span class="pln">disk</span><span class="pun" style="color: #666600;">(</span><span class="str" style="color: #008800;">'gcs'</span><span class="pun" style="color: #666600;">);</span>
<span class="pln"> </span><span class="com" style="color: #880000;">// public 為將此檔案公開</span>
<span class="pln"> $disk</span><span class="pun" style="color: #666600;">-></span><span class="pln">put</span><span class="pun" style="color: #666600;">(</span><span class="str" style="color: #008800;">'123.txt'</span><span class="pun" style="color: #666600;">,</span><span class="pln"> </span><span class="pun" style="color: #666600;">‘</span><span class="typ" style="color: #660066;">Good</span><span class="pun" style="color: #666600;">,</span><span class="pln"> file content</span><span class="pun" style="color: #666600;">’,</span><span class="pln"> </span><span class="pun" style="color: #666600;">‘</span><span class="kwd" style="color: #000088;">public</span><span class="str" style="color: #008800;">');</span>
<span class="str" style="color: #008800;"> </span>
<span class="str" style="color: #008800;"> // 刪除檔案</span>
<span class="str" style="color: #008800;"> $disk->delete('</span><span class="lit" style="color: #006666;">123.txt</span><span class="str" style="color: #008800;">');</span>
<span class="str" style="color: #008800;"> </span></pre>
</div>
葉建胤http://www.blogger.com/profile/13939608302918631988noreply@blogger.comtag:blogger.com,1999:blog-9161883088729562959.post-61943574487280512872016-07-21T01:07:00.002+08:002018-05-18T08:28:14.706+08:00Laravel Unit Test (上)<div class="ennote">
<div>
<b>前言:</b></div>
<div>
之所以寫這篇教學 ( 筆記 ),是因為希望執行 Unit Test 時可以有個單純的環境,且完整的測試 DB 設計 ( migration )是否正確</div>
<div>
所以找了一下將開發環境和測試環境 DB 分離的方法</div>
<div>
( 參考自 <a href="https://www.evernote.com/OutboundRedirect.action?dest=https%3A%2F%2Flaracasts.com%2Fdiscuss%2Fchannels%2Ftesting%2Fhow-to-specify-a-testing-database-in-laravel-5">https://laracasts.com/discuss/channels/testing/how-to-specify-a-testing-database-in-laravel-5</a> )</div>
<div>
<br /></div>
<div>
<b>正文開始:</b></div>
<div>
<br /></div>
<ol>
<li> 這邊使用 memory 形式的 SQLite 來做為 Laravel 與 PHPUnit 測試時的 DB 設定<br />
於 config/database.php 的 'connections' => [ … 設定 sql_testing 做為 Test 環境使用,如下範例</li>
</ol>
<div>
<br />
<a name='more'></a><br /></div>
<table style="border-collapse: collapse; margin-left: 0px; table-layout: fixed; width: 100%;">
<tbody>
<tr>
<td style="border-color: rgb(219 , 219 , 219); border-style: solid; border-width: 1px; margin: 0px; padding: 10px; width: 100%;"><div>
'connections' => [ ...</div>
<div>
<br /></div>
<div>
'sqlite_testing' => [</div>
<div>
'driver' => 'sqlite',</div>
<div>
'database' => ':memory:',</div>
<div>
'prefix' => '',</div>
<div>
],</div>
<div>
<br /></div>
<div>
… ]</div>
</td>
</tr>
</tbody></table>
<div>
<br /></div>
<ol start="2">
<li>然後於 tests/TestCase.php 加上 putenv('DB_CONNECTION=sqlite_testing'); 變數,使用上步 (1) 建立的 config</li>
</ol>
<div>
<br /></div>
<div>
<br /></div>
<table style="border-collapse: collapse; margin-left: 0px; table-layout: fixed; width: 100%;">
<tbody>
<tr>
<td style="border-color: rgb(219 , 219 , 219); border-style: solid; border-width: 1px; margin: 0px; padding: 10px; width: 100%;"><div>
public function createApplication()</div>
<div>
{</div>
<div>
<span style="-evernote-highlight: true; background-color: #fffaa5;"> putenv('DB_CONNECTION=sqlite_testing');</span></div>
<div>
<br /></div>
<div>
$app = require __DIR__.'/../bootstrap/app.php';</div>
<div>
<br /></div>
<div>
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();</div>
<div>
<br /></div>
<div>
return $app;</div>
<div>
}</div>
</td>
</tr>
</tbody></table>
<div>
<br /></div>
<ol start="3">
<li>再來是 tests/TestCase.php 的 setUp 與 tearDown 加上 DB 的 migrate 與 reset</li>
</ol>
<div>
<br /></div>
<table style="border-collapse: collapse; margin-left: 0px; table-layout: fixed; width: 100%;">
<tbody>
<tr>
<td style="border-color: rgb(219 , 219 , 219); border-style: solid; border-width: 1px; margin: 0px; padding: 10px; width: 100%;"><div>
public function setUp(){</div>
<div>
parent::setUp();</div>
<div>
<span style="-evernote-highlight: true; background-color: #fffaa5;"> Artisan::call('migrate');</span></div>
<div>
<span style="-evernote-highlight: true; background-color: #fffaa5;"> Artisan::call('db:seed');</span></div>
<div>
}</div>
<div>
<br /></div>
<div>
public function tearDown(){</div>
<div>
<span style="-evernote-highlight: true; background-color: #fffaa5;"> Artisan::call('migrate:reset');</span></div>
<div>
parent::tearDown();</div>
<div>
}</div>
</td>
</tr>
</tbody></table>
<div>
<br /></div>
<ol start="4">
<li>接下來就可以開始測試了...</li>
</ol>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
</div>
葉建胤http://www.blogger.com/profile/13939608302918631988noreply@blogger.com0tag:blogger.com,1999:blog-9161883088729562959.post-72486626775312142132016-06-26T20:10:00.002+08:002016-06-26T20:12:38.117+08:00iOS 模擬器 couldn't be completed. (LaunchServicesError ... 解法<br />
<br />
如果有使用 CocoaPods 的 XCode 專案,有時候會遇到一些鬼打牆的問題<br />
例如 無緣無故忽然間就出現什麼 /bin/sh exit code 1<br />
或是<br />
<br />
The operation couldn't be completed. (LaunchServicesError error 0.)<br />
<br />
或<br />
<br />
Command /bin/sh failed with exit code 1<br />
<br />
還是不能 copy 什麼 framework,出現 exit code 之類的<br />
<br />
都有可能是專案沒有 Clean 乾淨 ( 一般的 Product -> Clean 可能無效)<br />
這時候要按 Alt ,再選一次 Product -> Clean Build Folder ( 隱藏功能)<br />
就有可能變正常了<br />
<div>
<br /></div>
<div>
<br /></div>
葉建胤http://www.blogger.com/profile/13939608302918631988noreply@blogger.com0tag:blogger.com,1999:blog-9161883088729562959.post-61920974332169586852016-05-19T00:13:00.001+08:002018-05-18T08:28:35.817+08:00Laravel 客制化登入頁面<br />
<br />
<div style="background-color: white; border: 0px; font-family: Helvetica, Arial, 'Droid Sans', sans-serif; font-size: 14px; line-height: 20px; margin: 0px; padding: 0px;">
這邊使用Laravel內建的User 資料表,可以先加上一些欄位</div>
<div style="background-color: white; border: 0px; font-family: Helvetica, Arial, 'Droid Sans', sans-serif; font-size: 14px; line-height: 20px; margin: 0px; padding: 0px;">
於 <span style="background-color: #fffaa5; line-height: 1.42857em;">database/migrations/xxxx_create_users_table.php</span></div>
<div style="background-color: white; border: 0px; font-family: Helvetica, Arial, 'Droid Sans', sans-serif; font-size: 14px; line-height: 20px; margin: 0px; padding: 0px;">
加上 account 做示範,例如:</div>
<div style="background-color: white; border: 0px; font-family: Helvetica, Arial, 'Droid Sans', sans-serif; font-size: 14px; line-height: 20px; margin: 0px; padding: 0px;">
<br /></div>
<table style="background-color: white; border-collapse: collapse; color: black; font-family: Helvetica, Arial, 'Droid Sans', sans-serif; font-size: 14px; line-height: 20px; margin-left: 0px; table-layout: fixed; width: 661px;"><tbody style="line-height: 1.42857em;">
<tr style="line-height: 1.42857em;"><td style="border: 1px solid rgb(219, 219, 219); line-height: 1.42857em; margin: 0px; padding: 10px; width: 640px;"><div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
public function up()</div>
<div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
{</div>
<div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
Schema::create('users', function (Blueprint $table) {</div>
<div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
$table->increments('id');</div>
<div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
$table->string('name');</div>
<div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
<span style="background-color: #fffaa5; line-height: 1.42857em;">$table->string('account’); // !!</span></div>
<div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
$table->string('email')->unique();</div>
<div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
$table->string('password');</div>
<div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
$table->rememberToken();</div>
<div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
$table->timestamps();</div>
<div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
});</div>
<div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
}</div>
</td></tr>
</tbody></table>
<div style="background-color: white; border: 0px; font-family: Helvetica, Arial, 'Droid Sans', sans-serif; font-size: 14px; line-height: 20px; margin: 0px; padding: 0px;">
<br /></div>
<div style="background-color: white; border: 0px; font-family: Helvetica, Arial, 'Droid Sans', sans-serif; font-size: 14px; line-height: 20px; margin: 0px; padding: 0px;">
然後migrate db, User 的Model fillable 也要填寫</div>
<div style="background-color: white; border: 0px; font-family: Helvetica, Arial, 'Droid Sans', sans-serif; font-size: 14px; line-height: 20px; margin: 0px; padding: 0px;">
<br /></div>
<div style="background-color: white; border: 0px; font-family: Helvetica, Arial, 'Droid Sans', sans-serif; font-size: 14px; line-height: 20px; margin: 0px; padding: 0px;">
先建立認證用的Controller,這邊叫User</div>
<div style="background-color: white; border: 0px; font-family: Helvetica, Arial, 'Droid Sans', sans-serif; font-size: 14px; line-height: 20px; margin: 0px; padding: 0px;">
於終端機輸入</div>
<table style="background-color: white; border-collapse: collapse; color: black; font-family: Helvetica, Arial, 'Droid Sans', sans-serif; font-size: 14px; line-height: 20px; margin-left: 0px; table-layout: fixed; width: 661px;"><tbody style="line-height: 1.42857em;">
<tr style="line-height: 1.42857em;"><td style="border: 1px solid rgb(219, 219, 219); line-height: 1.42857em; margin: 0px; padding: 10px; width: 640px;"><div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
php artisan make:controller UserController</div>
</td></tr>
</tbody></table>
<div style="background-color: white; border: 0px; font-family: Helvetica, Arial, 'Droid Sans', sans-serif; font-size: 14px; line-height: 20px; margin: 0px; padding: 0px;">
<br />
<a name='more'></a><br /></div>
<div style="background-color: white; border: 0px; font-family: Helvetica, Arial, 'Droid Sans', sans-serif; font-size: 14px; line-height: 20px; margin: 0px; padding: 0px;">
<br /></div>
<div style="background-color: white; border: 0px; font-family: Helvetica, Arial, 'Droid Sans', sans-serif; font-size: 14px; line-height: 20px; margin: 0px; padding: 0px;">
<br /></div>
<div style="background-color: white; border: 0px; font-family: Helvetica, Arial, 'Droid Sans', sans-serif; font-size: 14px; line-height: 20px; margin: 0px; padding: 0px;">
再來設定router.php,指定我們的登入頁與Controller</div>
<table style="background-color: white; border-collapse: collapse; color: black; font-family: Helvetica, Arial, 'Droid Sans', sans-serif; font-size: 14px; line-height: 20px; margin-left: 0px; table-layout: fixed; width: 661px;"><tbody style="line-height: 1.42857em;">
<tr style="line-height: 1.42857em;"><td style="border: 1px solid rgb(219, 219, 219); line-height: 1.42857em; margin: 0px; padding: 10px; width: 640px;"><div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
Route::get('/login', 'UserController@login');</div>
<div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
Route::post('/login', 'UserController@login_check');</div>
</td></tr>
</tbody></table>
<div style="background-color: white; border: 0px; font-family: Helvetica, Arial, 'Droid Sans', sans-serif; font-size: 14px; line-height: 20px; margin: 0px; padding: 0px;">
<br /></div>
<div style="background-color: white; border: 0px; font-family: Helvetica, Arial, 'Droid Sans', sans-serif; font-size: 14px; line-height: 20px; margin: 0px; padding: 0px;">
<br /></div>
<div style="background-color: white; border: 0px; font-family: Helvetica, Arial, 'Droid Sans', sans-serif; font-size: 14px; line-height: 20px; margin: 0px; padding: 0px;">
<br /></div>
<div style="background-color: white; border: 0px; font-family: Helvetica, Arial, 'Droid Sans', sans-serif; font-size: 14px; line-height: 20px; margin: 0px; padding: 0px;">
然後透過 Auth::attempt 來檢查使用者,UserController的範例如下:</div>
<div style="background-color: white; border: 0px; font-family: Helvetica, Arial, 'Droid Sans', sans-serif; font-size: 14px; line-height: 20px; margin: 0px; padding: 0px;">
<br /></div>
<table style="background-color: white; border-collapse: collapse; color: black; font-family: Helvetica, Arial, 'Droid Sans', sans-serif; font-size: 14px; line-height: 20px; margin-left: 0px; table-layout: fixed; width: 661px;"><tbody style="line-height: 1.42857em;">
<tr style="line-height: 1.42857em;"><td style="border: 1px solid rgb(219, 219, 219); line-height: 1.42857em; margin: 0px; padding: 10px; width: 640px;"><div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
namespace App\Http\Controllers;</div>
<div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
use Illuminate\Http\Request;</div>
<div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
use Illuminate\Support\Facades\Input;</div>
<div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
use App\Http\Requests;</div>
<div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
use Auth;</div>
<div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
use Redirect;</div>
<div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
<br /></div>
<div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
class UserController extends Controller</div>
<div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
{</div>
<div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
function login(){</div>
<div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
return view('user/login');</div>
<div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
}</div>
<div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
<br /></div>
<div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
function login_check(){</div>
<div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
$account = Input::get('account');</div>
<div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
$password = Input::get('password');</div>
<div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
<span style="background-color: #fffaa5; line-height: 1.42857em;">if (Auth::attempt(array('account' => $account, 'password' => $password))){ </span> <span style="background-color: #fffaa5; line-height: 1.42857em;">// !!</span></div>
<div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
<span style="background-color: #fffaa5; line-height: 1.42857em;"> return Redirect::intended(‘home’); </span></div>
<div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
<span style="background-color: #fffaa5; line-height: 1.42857em;"> }</span></div>
<div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
return view('user/login')->withErrors(array(</div>
<div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
'msg' => 'Account or Password Error.'</div>
<div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
));</div>
<div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
}</div>
<div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
}</div>
<div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
<br /></div>
</td></tr>
</tbody></table>
<div style="background-color: white; border: 0px; font-family: Helvetica, Arial, 'Droid Sans', sans-serif; font-size: 14px; line-height: 20px; margin: 0px; padding: 0px;">
<br /></div>
<div style="background-color: white; border: 0px; font-family: Helvetica, Arial, 'Droid Sans', sans-serif; font-size: 14px; line-height: 20px; margin: 0px; padding: 0px;">
withErrors 是在認證失敗,會將原因透過msg給view</div>
<div style="background-color: white; border: 0px; font-family: Helvetica, Arial, 'Droid Sans', sans-serif; font-size: 14px; line-height: 20px; margin: 0px; padding: 0px;">
<br /></div>
<div style="background-color: white; border: 0px; font-family: Helvetica, Arial, 'Droid Sans', sans-serif; font-size: 14px; line-height: 20px; margin: 0px; padding: 0px;">
view的範例如下:</div>
<div style="background-color: white; border: 0px; font-family: Helvetica, Arial, 'Droid Sans', sans-serif; font-size: 14px; line-height: 20px; margin: 0px; padding: 0px;">
(於 resources/views/user/login.blade.php )</div>
<div style="background-color: white; border: 0px; font-family: Helvetica, Arial, 'Droid Sans', sans-serif; font-size: 14px; line-height: 20px; margin: 0px; padding: 0px;">
<br /></div>
<table style="background-color: white; border-collapse: collapse; color: black; font-family: Helvetica, Arial, 'Droid Sans', sans-serif; font-size: 14px; line-height: 20px; margin-left: 0px; table-layout: fixed; width: 661px;"><tbody style="line-height: 1.42857em;">
<tr style="line-height: 1.42857em;"><td style="border: 1px solid rgb(219, 219, 219); line-height: 1.42857em; margin: 0px; padding: 10px; width: 640px;"><div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
<form action="{{ url('/mlogin') }}"></div>
<div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
{!! csrf_field() !!}</div>
<div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
Account:<input type="text" name="nickname" /><br /></div>
<div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
Password:<input type="password" name="password" /><br /></div>
<div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
@if ($errors->has('msg'))</div>
<div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
<span ></div>
<div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
<strong>{{ $errors->first('msg') }}</strong></div>
<div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
</span></div>
<div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
@endif</div>
<div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
<input type="submit" /></div>
<div style="border: 0px; line-height: 1.42857em; margin: 0px; padding: 0px;">
</form></div>
</td></tr>
</tbody></table>
<div style="background-color: white; border: 0px; font-family: Helvetica, Arial, 'Droid Sans', sans-serif; font-size: 14px; line-height: 20px; margin: 0px; padding: 0px;">
<br /></div>
<div style="background-color: white; border: 0px; font-family: Helvetica, Arial, 'Droid Sans', sans-serif; font-size: 14px; line-height: 20px; margin: 0px; padding: 0px;">
<br /></div>
<div style="background-color: white; border: 0px; font-family: Helvetica, Arial, 'Droid Sans', sans-serif; font-size: 14px; line-height: 20px; margin: 0px; padding: 0px;">
<br /></div>
<div style="background-color: white; border: 0px; font-family: Helvetica, Arial, 'Droid Sans', sans-serif; font-size: 14px; line-height: 20px; margin: 0px; padding: 0px;">
<br /></div>
<div style="background-color: white; border: 0px; font-family: Helvetica, Arial, 'Droid Sans', sans-serif; font-size: 14px; line-height: 20px; margin: 0px; padding: 0px;">
<br /></div>
葉建胤http://www.blogger.com/profile/13939608302918631988noreply@blogger.com0tag:blogger.com,1999:blog-9161883088729562959.post-46914763569691484992016-05-10T12:43:00.003+08:002016-05-10T12:43:50.388+08:00[Android]Android Studio Error:Execution failed for task ':app:mergeDebugResources'. > String index out of range: 0剛剛在編輯文字檔(strings.xml)時,因為先打了一堆的<string name=""></string>,想說直接輸入name跟value值就好了。<br />
結果多餘的<string name=""></string>我既然忘記刪除啦~~<br />
<br />
執行專案Android Studio就跑出這樣的錯誤了。如果你也遇到了,快去檢查你是否跟我遇到同樣的問題呢?<br />
<span style="color: red;">Error:Execution failed for task ':app:mergeDebugResources'. > String index out of range: 0</span><br />
<br />JackLiaohttp://www.blogger.com/profile/15196682200013649498noreply@blogger.com1tag:blogger.com,1999:blog-9161883088729562959.post-47389281277081998252016-05-10T12:01:00.005+08:002022-04-06T17:39:48.381+08:00[Android] Android Studio Error:Execution failed for task ':app:transformClassesWithDexForDebug'.最近使用Android Studio做專案時,忽然出現以下錯誤<br />
<br />
Information:Gradle tasks [:app:assembleDebug]<br />
:app:preBuild UP-TO-DATE<br />
:app:preDebugBuild UP-TO-DATE<br />
:app:checkDebugManifest<br />
:app:preReleaseBuild UP-TO-DATE<br />
:app:prepareComAndroidSupportAppcompatV72300Library UP-TO-DATE<br />
:app:prepareComAndroidSupportCardviewV72321Library UP-TO-DATE<br />
:app:prepareComAndroidSupportCustomtabs2321Library UP-TO-DATE<br />
:app:prepareComAndroidSupportDesign2300Library UP-TO-DATE<br />
:app:prepareComAndroidSupportMediarouterV72300Library UP-TO-DATE<br />
:app:prepareComAndroidSupportPaletteV72320Library UP-TO-DATE<br />
:app:prepareComAndroidSupportRecyclerviewV72320Library UP-TO-DATE<br />
:app:prepareComAndroidSupportSupportV42321Library UP-TO-DATE<br />
:app:prepareComFacebookAndroidFacebookAndroidSdk4110Library UP-TO-DATE<br />
:app:prepareComGoogleAndroidGmsPlayServices840Library UP-TO-DATE<br />
:app:prepareComGoogleAndroidGmsPlayServicesAds840Library UP-TO-DATE<br />
:app:prepareComGoogleAndroidGmsPlayServicesAnalytics840Library UP-TO-DATE<br />
:app:prepareComGoogleAndroidGmsPlayServicesAppindexing840Library UP-TO-DATE<br />
:app:prepareComGoogleAndroidGmsPlayServicesAppinvite840Library UP-TO-DATE<br />
:app:prepareComGoogleAndroidGmsPlayServicesAppstate840Library UP-TO-DATE<br />
:app:prepareComGoogleAndroidGmsPlayServicesAuth840Library UP-TO-DATE<br />
:app:prepareComGoogleAndroidGmsPlayServicesBase840Library UP-TO-DATE<br />
<a name='more'></a><br />
:app:prepareComGoogleAndroidGmsPlayServicesBasement840Library UP-TO-DATE<br />
:app:prepareComGoogleAndroidGmsPlayServicesCast840Library UP-TO-DATE<br />
:app:prepareComGoogleAndroidGmsPlayServicesDrive840Library UP-TO-DATE<br />
:app:prepareComGoogleAndroidGmsPlayServicesFitness840Library UP-TO-DATE<br />
:app:prepareComGoogleAndroidGmsPlayServicesGames840Library UP-TO-DATE<br />
:app:prepareComGoogleAndroidGmsPlayServicesGcm840Library UP-TO-DATE<br />
:app:prepareComGoogleAndroidGmsPlayServicesIdentity840Library UP-TO-DATE<br />
:app:prepareComGoogleAndroidGmsPlayServicesLocation840Library UP-TO-DATE<br />
:app:prepareComGoogleAndroidGmsPlayServicesMaps840Library UP-TO-DATE<br />
:app:prepareComGoogleAndroidGmsPlayServicesMeasurement840Library UP-TO-DATE<br />
:app:prepareComGoogleAndroidGmsPlayServicesNearby840Library UP-TO-DATE<br />
:app:prepareComGoogleAndroidGmsPlayServicesPanorama840Library UP-TO-DATE<br />
:app:prepareComGoogleAndroidGmsPlayServicesPlus840Library UP-TO-DATE<br />
:app:prepareComGoogleAndroidGmsPlayServicesSafetynet840Library UP-TO-DATE<br />
:app:prepareComGoogleAndroidGmsPlayServicesVision840Library UP-TO-DATE<br />
:app:prepareComGoogleAndroidGmsPlayServicesWallet840Library UP-TO-DATE<br />
:app:prepareComGoogleAndroidGmsPlayServicesWearable840Library UP-TO-DATE<br />
:app:prepareComSeachaosHurryporter017Library UP-TO-DATE<br />
:app:prepareEnjoyTpcclientUnspecifiedLibrary UP-TO-DATE<br />
:app:prepareDebugDependencies<br />
:app:compileDebugAidl UP-TO-DATE<br />
:app:compileDebugRenderscript UP-TO-DATE<br />
:app:generateDebugBuildConfig UP-TO-DATE<br />
:app:generateDebugAssets UP-TO-DATE<br />
:app:mergeDebugAssets UP-TO-DATE<br />
:app:generateDebugResValues UP-TO-DATE<br />
:app:generateDebugResources UP-TO-DATE<br />
:app:mergeDebugResources<br />
AAPT: /Users/****/cafe3.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited<br />
AAPT: /Users/****/cafe2.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited<br />
AAPT: /Users/****/cafe1.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited<br />
:app:processDebugManifest<br />
:app:processDebugResources<br />
:app:generateDebugSources<br />
:app:compileDebugJavaWithJavac<br />
Note: Some input files use or override a deprecated API.<br />
Note: Recompile with -Xlint:deprecation for details.<br />
:app:compileDebugNdk UP-TO-DATE<br />
:app:compileDebugSources<br />
:app:transformClassesWithDexForDebug<br />
UNEXPECTED TOP-LEVEL EXCEPTION:<br />
<br />
<span style="color: red;">Error:Execution failed for task ':app:transformClassesWithDexForDebug'.</span><br />
<span style="color: red;">> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2</span><br />
<br />
<br />
<br />
我只不過是監聽了我的Button事件(setOnClickListener),沒有做其他任何事,真讓我搞不懂到底這IDE是發生了什麼事!!<br />
後來查到<span style="color: blue;">只要在 build.gradle(Module: app)中的android{}底下的defaultConfig{}裡面加上multiDexEnabled true</span><br />
<span style="color: blue;">就可以正確運行了</span>。<br />
<br />
不過,這好像不是唯一個解決辦法,而且加入這行會使得每次在build的時候花費很多時間。經過爬文之後發現,原來是method只要大於65k就會有這情況發生,這些method不只是我們自己寫的method,就連你improt的也算喔~~<br />
<br />
所以只好到<span style="color: blue;">build.gradle(Module: app)中的android{}底下的dependencies{}中,找出根本</span><span style="color: red;">沒有使用到的library</span><span style="color: blue;">將它移除,這情況就可以解決了。</span><br />
<span style="color: blue;"><br /></span>
如果每個library都有用到,那只好整理一下你的code吧!
<script type="text/javascript" src="//js1.bloggerads.net/contentads.aspx?blogid=20150916000016" async></script>JackLiaohttp://www.blogger.com/profile/15196682200013649498noreply@blogger.comtag:blogger.com,1999:blog-9161883088729562959.post-28841780923216219702016-04-29T00:20:00.003+08:002018-05-18T08:31:05.189+08:00如何使用Google的圖形驗證碼(reCAPTCHA)防止機器人<br />
<h3>
前言</h3>
<br />
因為MyAndroid這個網站也有一段時間了,開放留言就算有圖形驗證碼還是保受留言機器人騷擾之苦… 索性直接關閉所有人的留言功能<br />
等到有空再來自幹一個防止機器人的驗證程序,但這個過程一拖就是好多年了 (平日上班太忙)<br />
直到最近想說,乾脆就整合Google的圖形驗證碼吧<br />
<br />
順便做個教學<br />
<br />
<br />
<h3>
正文</h3>
<br />
<a name='more'></a><br /><br />
1. 先到 Google reCAPTCHA去註冊一個key<br />
<a href="https://www.google.com/recaptcha/admin" style="color: #660000; cursor: pointer; margin-left: 3px; margin-right: 3px;" target="_blank">CAPTCHA的後臺</a><br />
<br />
在Register a new site輸入網站的資訊<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqW-p0_YQtk04UusmcFQJ7Hn6lOeEfBX3iu84XKXewqFtGzr9C9mMiwZRD1VAN6EI_aTngMx-kAxkEvNMjMpHa0rehW-iByjsn32Yyh0_jFFXnIHQgwhudPHMrc7we6ucNjuZSttwCOCMr/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2016-04-29+%25E4%25B8%258A%25E5%258D%258812.05.29.png" imageanchor="1"><img border="0" height="221" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqW-p0_YQtk04UusmcFQJ7Hn6lOeEfBX3iu84XKXewqFtGzr9C9mMiwZRD1VAN6EI_aTngMx-kAxkEvNMjMpHa0rehW-iByjsn32Yyh0_jFFXnIHQgwhudPHMrc7we6ucNjuZSttwCOCMr/s400/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2016-04-29+%25E4%25B8%258A%25E5%258D%258812.05.29.png" width="400" /></a><br />
Label是標籤,方便自己識別用<br />
Domains可以填多個網址,例如你有 www.myandroid.tw 與 www.airweb.tw<br />
就可以都填上 (一行一個)<br />
<br />
<br />
然後可以取得Key了<br />
接下來其實Google有教學<br />
<br />
不過這邊還是說明一下<br />
在要顯示認證的頁面,加上這個Script<br />
<br />
<div class="javaCode" style="overflow: auto;">
<pre class="prettyprint" style="border: 1px solid rgb(136, 136, 136); padding: 2px;"><span class="pln"> </span><span class="tag" style="color: #000088;"><script</span><span class="pln"> </span><span class="atn" style="color: #660066;">src</span><span class="pun" style="color: #666600;">=</span><span class="atv" style="color: #008800;">'https://www.google.com/recaptcha/api.js'</span><span class="tag" style="color: #000088;">></script></span>
<span class="pln"> </span></pre>
</div>
<br />
<br />
和要顯示的位置放上這個DIV<br />
<div class="javaCode" style="overflow: auto;">
<pre class="prettyprint" style="border: 1px solid rgb(136, 136, 136); padding: 2px;"><span class="pln"> </span><span class="tag" style="color: #000088;"><div</span><span class="pln"> </span><span class="atn" style="color: #660066;">class</span><span class="pun" style="color: #666600;">=</span><span class="atv" style="color: #008800;">"g-recaptcha"</span><span class="pln"> </span><span class="atn" style="color: #660066;">data-sitekey</span><span class="pun" style="color: #666600;">=</span><span class="atv" style="color: #008800;">"Google 給的KEY"</span><span class="tag" style="color: #000088;">></div></span>
<span class="pln"> </span></pre>
</div>
<br />
(注意:是 Site key 不是 Secret Key!!)<br />
<br />
然後你的Server端如果是PHP,可以使用現成的套件來處理<br />
(https://github.com/google/recaptcha)<br />
使用 Composer來取得套件<br />
<div class="javaCode" style="overflow: auto;">
<pre class="prettyprint" style="border: 1px solid rgb(136, 136, 136); padding: 2px;"><span class="pln"> composer </span><span class="kwd" style="color: #000088;">require</span><span class="pln"> google</span><span class="pun" style="color: #666600;">/</span><span class="pln">recaptcha </span><span class="str" style="color: #008800;">"~1.1"</span>
<span class="pln"> </span></pre>
</div>
<br />
<br />
在檢核的PHP頁面加上<br />
<div class="javaCode" style="overflow: auto;">
<pre class="prettyprint" style="border: 1px solid rgb(136, 136, 136); padding: 2px;"><span class="pln"> </span><span class="kwd" style="color: #000088;">require</span><span class="pun" style="color: #666600;">(</span><span class="str" style="color: #008800;">'./vendor/google/recaptcha/src/autoload.php'</span><span class="pun" style="color: #666600;">);</span>
<span class="pln"> </span><span class="com" style="color: #880000;">// _GOOGLE_RECAPTCHA_SEC_KEY 就是 google 給的 Secret Key</span>
<span class="pln"> $recaptcha </span><span class="pun" style="color: #666600;">=</span><span class="pln"> </span><span class="kwd" style="color: #000088;">new</span><span class="pln"> \ReCaptcha\ReCaptcha</span><span class="pun" style="color: #666600;">(</span><span class="pln">_GOOGLE_RECAPTCHA_SEC_KEY</span><span class="pun" style="color: #666600;">);</span>
<span class="pln"> $gRecaptchaResponse </span><span class="pun" style="color: #666600;">=</span><span class="pln"> $_POST</span><span class="pun" style="color: #666600;">[</span><span class="str" style="color: #008800;">'g-recaptcha-response'</span><span class="pun" style="color: #666600;">];</span>
<span class="pln"> $remoteIp </span><span class="pun" style="color: #666600;">=</span><span class="pln"> $_SERVER</span><span class="pun" style="color: #666600;">[</span><span class="str" style="color: #008800;">'REMOTE_ADDR'</span><span class="pun" style="color: #666600;">];</span>
<span class="pln"> $resp </span><span class="pun" style="color: #666600;">=</span><span class="pln"> $recaptcha</span><span class="pun" style="color: #666600;">-></span><span class="pln">verify</span><span class="pun" style="color: #666600;">(</span><span class="pln">$gRecaptchaResponse</span><span class="pun" style="color: #666600;">,</span><span class="pln"> $remoteIp</span><span class="pun" style="color: #666600;">);</span>
<span class="pln"> </span><span class="kwd" style="color: #000088;">if</span><span class="pun" style="color: #666600;">(!</span><span class="pln">$resp</span><span class="pun" style="color: #666600;">-></span><span class="pln">isSuccess</span><span class="pun" style="color: #666600;">()){</span>
<span class="pln"> echo </span><span class="str" style="color: #008800;">'請先證明您不是機器人'</span><span class="pun" style="color: #666600;">;</span>
<span class="pln"> </span><span class="kwd" style="color: #000088;">return</span><span class="pun" style="color: #666600;">;</span>
<span class="pln"> </span><span class="pun" style="color: #666600;">}</span>
<span class="pln"> </span></pre>
</div>
<br />
<br />
其中require請改成自己的路徑葉建胤http://www.blogger.com/profile/13939608302918631988noreply@blogger.com0tag:blogger.com,1999:blog-9161883088729562959.post-73255557598888774272016-04-22T16:40:00.000+08:002016-04-22T16:40:41.917+08:00Android 強制顯示鍵盤之前在實作有關EditText的頁面時,總覺得要強制顯示鍵盤,很困難,叫它出現不出現,真難控制。<br />
<br />
後來才瞭解,原來畫面還沒準備好,就去呼叫強制顯示鍵盤,所以Android根本不理我。<br />
所以必須先讓他等個0.1秒,這樣就可以成功呼叫啦。<br />
<br />
final ImputMethodManager imm =<br />
(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);<br />
<br />
editText.postDelayed(new Runnable(){<br />
@Override<br />
public void run(){<br />
editText.requestFocus();<br />
imm.showSoftInput(editText, 0);<br />
}<br />
}, <span style="color: red;">100</span>);<br />
<br />
<br />
如果要隱藏鍵盤就比較單純了。<br />
ImputMethodManager imm =<br />
(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);<br />
IBinder ib = Activity.this.getCurrentFocus().getWindowToken();<br />
imm.hideSoftInputFromWindow(ib, InputMethodManager.HIDE_NOT_ALWAYS);<br />
<br />JackLiaohttp://www.blogger.com/profile/15196682200013649498noreply@blogger.com0tag:blogger.com,1999:blog-9161883088729562959.post-16559244701901374202015-10-02T14:43:00.000+08:002015-10-02T14:43:38.636+08:00〔飲食〕在台北角落遇見『台北角落』昨日在一如往常的下午茶時刻,走在車來人往的承德路上看見不一樣的風景;讓我多注意一眼。<br />
<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLUvoGC2SMEb4JUgjJ2-k1x-QlxZTBX7wv9hARN2TrT8liOkmQwsKfpsxWE2fAaelhLc5oY0p040vOhk8BsCaFRNX1euy2mA3GXtxhyphenhypheny16Z5ljyCs5SlgV0KjxMAiXD9w87JaWNOWTjMQ/s1600/S__16277512.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLUvoGC2SMEb4JUgjJ2-k1x-QlxZTBX7wv9hARN2TrT8liOkmQwsKfpsxWE2fAaelhLc5oY0p040vOhk8BsCaFRNX1euy2mA3GXtxhyphenhypheny16Z5ljyCs5SlgV0KjxMAiXD9w87JaWNOWTjMQ/s320/S__16277512.jpg" width="240" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-size: x-small; text-align: start;">有一台經過精心改造的三輪車後面載著不明物體</span></td></tr>
</tbody></table>
<a name='more'></a><br /><div style="text-align: center;">
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkzRSh5gSMm4C7ShESC-uNVZOh4Lzcgf7qp2PCPJM1JMX3gHICeP79ymW-xa_LdrznimLzjtAAp1e5Zcnw4lv0T3W5_hCRF65krKRjHqQKH2Ggx2HtPquC_8_oNIib5v0dN323ipmQUcI/s1600/S__16277514.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkzRSh5gSMm4C7ShESC-uNVZOh4Lzcgf7qp2PCPJM1JMX3gHICeP79ymW-xa_LdrznimLzjtAAp1e5Zcnw4lv0T3W5_hCRF65krKRjHqQKH2Ggx2HtPquC_8_oNIib5v0dN323ipmQUcI/s320/S__16277514.jpg" width="240" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-size: small;">車上有一個沒見過的玩意</span></td></tr>
</tbody></table>
原來這東西是用來製造咖啡的!<br />
老闆將研磨好的咖啡加入,擠一擠壓一壓之後,一杯濃醇香的咖啡就出來了。</div>
<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8z9UuIGFrVRLu94_S0jAjhPBZOpwEWPafZeKin8_jJYhUEQSjWwm7nyhyphenhyphenHIEJ6cXkxJI00HCTcURA_VgNnNyEpj7_gphIYAvjpVDuXUCmP864lbnm9fmv_FOsjgTyaWnpRKUbBHI1EZg/s1600/S__16277513.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8z9UuIGFrVRLu94_S0jAjhPBZOpwEWPafZeKin8_jJYhUEQSjWwm7nyhyphenhyphenHIEJ6cXkxJI00HCTcURA_VgNnNyEpj7_gphIYAvjpVDuXUCmP864lbnm9fmv_FOsjgTyaWnpRKUbBHI1EZg/s320/S__16277513.jpg" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-size: small;">老闆說他是專門在做外送的</span></td></tr>
</tbody></table>
<br />
<div style="text-align: center;">
其實這樣的工作好像也不錯,小型行動咖啡車,外送到哪裡賣到哪裡,還可以看看這城市的小角落。</div>
<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh34XGs8sA4_MC3YkMqihyv4AyhNbqwmG9omV7hYs0-IP7ZsINS4j_17Mr0Ph811sv8qaV-NpM-QoL1gz14GgqM-Z4bH23jhcJjkDhtBnrKmH-g5GlyNOJb1ruJnFr0b3hGk-OA9wIs-ug/s1600/S__16277515.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh34XGs8sA4_MC3YkMqihyv4AyhNbqwmG9omV7hYs0-IP7ZsINS4j_17Mr0Ph811sv8qaV-NpM-QoL1gz14GgqM-Z4bH23jhcJjkDhtBnrKmH-g5GlyNOJb1ruJnFr0b3hGk-OA9wIs-ug/s320/S__16277515.jpg" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-size: small;">老闆也是個HIGH咖</span></td></tr>
</tbody></table>
<br />
<div style="text-align: center;">
老闆真的很幽默風趣,也很享受在他的工作中,一直讓我們品他的咖啡香味。</div>
<div style="text-align: center;">
在路上如果有看到這台車,不忘了先買杯咖啡來享受一下。</div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: center;">
<a href="https://www.facebook.com/%E5%8F%B0%E5%8C%97%E8%A7%92%E8%90%BD%E6%A8%93%E4%B8%8B%E5%92%96%E5%95%A1-544434705686063/timeline/" target="_blank"><span style="font-size: large;">記得來看看老闆的FB,別忘了給他一個讚唷</span></a></div>
JackLiaohttp://www.blogger.com/profile/15196682200013649498noreply@blogger.com0tag:blogger.com,1999:blog-9161883088729562959.post-7094332683891749022015-09-29T00:36:00.000+08:002015-09-29T00:37:48.862+08:00簡單介紹Swift 2.0的Guard語法Guard是iOS在Swift 2.0中引入的一種語法<br />
他改善了一些冗長的if寫法問題(下面範例會提到)<br />
一般來說 guard要撘配else來使用,最好的用法(官方建議)是用在方法(method)中的return / break / continue 等流程控制<br />
<br />
Swift的guard語法非常適合用來做optional的判斷<br />
(概念上也可以把guard直接當做 if not 來看)<br />
<br />
以下是簡單的範例:<br />
<br class="Apple-interchange-newline" />
<br style="font-family: monospace; white-space: pre;" />
<span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="com" style="color: #880000; font-family: monospace; white-space: pre;">// userName是個optional的值,可能是使用者輸入,或是網路來的</span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="kwd" style="color: #000088; font-family: monospace; white-space: pre;">var</span><span class="pln" style="font-family: monospace; white-space: pre;"> userName</span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">:</span><span class="typ" style="color: #660066; font-family: monospace; white-space: pre;">String</span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">?</span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> </span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> func checkUserExists</span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">(</span><span class="pln" style="font-family: monospace; white-space: pre;">name</span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">:</span><span class="typ" style="color: #660066; font-family: monospace; white-space: pre;">String</span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">?)-></span><span class="typ" style="color: #660066; font-family: monospace; white-space: pre;">Bool</span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">{</span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="com" style="color: #880000; font-family: monospace; white-space: pre;">// 這裡用 底線(_) 是因為我們不是真的要值,只是想判斷optional是否有值</span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> guard let _ </span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">=</span><span class="pln" style="font-family: monospace; white-space: pre;"> userName </span><span class="kwd" style="color: #000088; font-family: monospace; white-space: pre;">else</span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">{</span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="kwd" style="color: #000088; font-family: monospace; white-space: pre;">return</span><span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="kwd" style="color: #000088; font-family: monospace; white-space: pre;">false</span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">}</span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="kwd" style="color: #000088; font-family: monospace; white-space: pre;">return</span><span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="kwd" style="color: #000088; font-family: monospace; white-space: pre;">true</span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">}</span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> </span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> checkUserExists</span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">(</span><span class="pln" style="font-family: monospace; white-space: pre;">userName</span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">)</span><span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="com" style="color: #880000; font-family: monospace; white-space: pre;">// 輸出 false</span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> userName </span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">=</span><span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="str" style="color: #008800; font-family: monospace; white-space: pre;">"Seachaos"</span><span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="com" style="color: #880000; font-family: monospace; white-space: pre;">// 給予userName有真正的值</span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> checkUserExists</span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">(</span><span class="pln" style="font-family: monospace; white-space: pre;">userName</span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">)</span><span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="com" style="color: #880000; font-family: monospace; white-space: pre;">// 輸出 true</span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> </span><br />
<div>
<span class="pln" style="font-family: monospace; white-space: pre;"><br /></span></div>
<br />
上面範列的checkUserExists就是個簡單的例子<br />
<br />
再來看一個滿常用到的範例,就是Dictionary (不管是Swift的Dictionary還是 NSDictionary 都適用) 的處理<br />
<br />
<a name='more'></a><br />
<br />
<br style="font-family: monospace; white-space: pre;" />
<span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="com" style="color: #880000; font-family: monospace; white-space: pre;">// 假設這是一個是使用者輸入,或是網路來的的Dict</span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="kwd" style="color: #000088; font-family: monospace; white-space: pre;">var</span><span class="pln" style="font-family: monospace; white-space: pre;"> userData</span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">:[</span><span class="typ" style="color: #660066; font-family: monospace; white-space: pre;">String</span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">:</span><span class="typ" style="color: #660066; font-family: monospace; white-space: pre;">String</span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">]</span><span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">=</span><span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">[</span><span class="typ" style="color: #660066; font-family: monospace; white-space: pre;">String</span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">:</span><span class="typ" style="color: #660066; font-family: monospace; white-space: pre;">String</span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">]()</span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> </span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="com" style="color: #880000; font-family: monospace; white-space: pre;">// 檢查method</span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> func checkUserDataCorrect</span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">(</span><span class="pln" style="font-family: monospace; white-space: pre;">data</span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">:[</span><span class="typ" style="color: #660066; font-family: monospace; white-space: pre;">String</span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">:</span><span class="typ" style="color: #660066; font-family: monospace; white-space: pre;">String</span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">])-></span><span class="typ" style="color: #660066; font-family: monospace; white-space: pre;">Bool</span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">{</span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="com" style="color: #880000; font-family: monospace; white-space: pre;">// 沒有Guard以前的做法</span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="kwd" style="color: #000088; font-family: monospace; white-space: pre;">var</span><span class="pln" style="font-family: monospace; white-space: pre;"> firstName</span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">:</span><span class="typ" style="color: #660066; font-family: monospace; white-space: pre;">String</span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">!</span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="kwd" style="color: #000088; font-family: monospace; white-space: pre;">if</span><span class="pln" style="font-family: monospace; white-space: pre;"> let aValue </span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">=</span><span class="pln" style="font-family: monospace; white-space: pre;"> userData</span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">[</span><span class="str" style="color: #008800; font-family: monospace; white-space: pre;">"firstName"</span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">]{</span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> firstName </span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">=</span><span class="pln" style="font-family: monospace; white-space: pre;"> aValue</span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">}</span><span class="kwd" style="color: #000088; font-family: monospace; white-space: pre;">else</span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">{</span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="kwd" style="color: #000088; font-family: monospace; white-space: pre;">return</span><span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="kwd" style="color: #000088; font-family: monospace; white-space: pre;">false</span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">}</span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> </span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="com" style="color: #880000; font-family: monospace; white-space: pre;">// 有了Guard,可以這樣用</span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> guard let lastName </span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">=</span><span class="pln" style="font-family: monospace; white-space: pre;"> userData</span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">[</span><span class="str" style="color: #008800; font-family: monospace; white-space: pre;">"lastName"</span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">]</span><span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="kwd" style="color: #000088; font-family: monospace; white-space: pre;">else</span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">{</span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="kwd" style="color: #000088; font-family: monospace; white-space: pre;">return</span><span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="kwd" style="color: #000088; font-family: monospace; white-space: pre;">false</span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">}</span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> guard let name </span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">=</span><span class="pln" style="font-family: monospace; white-space: pre;"> userData</span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">[</span><span class="str" style="color: #008800; font-family: monospace; white-space: pre;">"name"</span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">]</span><span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="kwd" style="color: #000088; font-family: monospace; white-space: pre;">else</span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">{</span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="kwd" style="color: #000088; font-family: monospace; white-space: pre;">return</span><span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="kwd" style="color: #000088; font-family: monospace; white-space: pre;">false</span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">}</span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="com" style="color: #880000; font-family: monospace; white-space: pre;">// 等效於 if ! ( name == firstName + lastName )</span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> guard name </span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">==</span><span class="pln" style="font-family: monospace; white-space: pre;"> firstName </span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">+</span><span class="pln" style="font-family: monospace; white-space: pre;"> lastName </span><span class="kwd" style="color: #000088; font-family: monospace; white-space: pre;">else</span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">{</span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="kwd" style="color: #000088; font-family: monospace; white-space: pre;">return</span><span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="kwd" style="color: #000088; font-family: monospace; white-space: pre;">false</span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">}</span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="kwd" style="color: #000088; font-family: monospace; white-space: pre;">return</span><span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="kwd" style="color: #000088; font-family: monospace; white-space: pre;">true</span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">}</span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> </span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="com" style="color: #880000; font-family: monospace; white-space: pre;">// 不正確資料 (空資料)</span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> checkUserDataCorrect</span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">(</span><span class="pln" style="font-family: monospace; white-space: pre;">userData</span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">)</span><span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="com" style="color: #880000; font-family: monospace; white-space: pre;">// 輸出 false</span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> </span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="com" style="color: #880000; font-family: monospace; white-space: pre;">// 不正確資料 (少了lastName 錯誤)</span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> userData </span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">=</span><span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">[</span><span class="str" style="color: #008800; font-family: monospace; white-space: pre;">"name"</span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">:</span><span class="str" style="color: #008800; font-family: monospace; white-space: pre;">"大明王"</span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">,</span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="str" style="color: #008800; font-family: monospace; white-space: pre;">"firstName"</span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">:</span><span class="str" style="color: #008800; font-family: monospace; white-space: pre;">"大明"</span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">]</span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> checkUserDataCorrect</span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">(</span><span class="pln" style="font-family: monospace; white-space: pre;">userData</span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">)</span><span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="com" style="color: #880000; font-family: monospace; white-space: pre;">// 輸出 false</span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> </span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="com" style="color: #880000; font-family: monospace; white-space: pre;">// 正確資料</span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> userData </span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">=</span><span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">[</span><span class="str" style="color: #008800; font-family: monospace; white-space: pre;">"name"</span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">:</span><span class="str" style="color: #008800; font-family: monospace; white-space: pre;">"大明王"</span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">,</span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="str" style="color: #008800; font-family: monospace; white-space: pre;">"firstName"</span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">:</span><span class="str" style="color: #008800; font-family: monospace; white-space: pre;">"大明"</span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">,</span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> </span><span class="str" style="color: #008800; font-family: monospace; white-space: pre;">"lastName"</span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">:</span><span class="str" style="color: #008800; font-family: monospace; white-space: pre;">"王"</span><span class="pun" style="color: #666600; font-family: monospace; white-space: pre;">]</span><br />
<span class="pln" style="font-family: monospace; white-space: pre;"> </span><br />
<div>
<span class="pln" style="font-family: monospace; white-space: pre;"><br /></span></div>
<br />
注意到以上 lastName的部份,有了Guard就可以這樣簡潔的寫<br />
而不用像以前只能先用let來處理 (上範例 firstName)<br />
<br />
以上是Swift 2.0加入的Guard語法簡單應用介紹葉建胤http://www.blogger.com/profile/13939608302918631988noreply@blogger.com0tag:blogger.com,1999:blog-9161883088729562959.post-6210773761641007462015-09-24T16:05:00.000+08:002015-09-24T16:05:04.951+08:00Android DatePickerDialog Bug<br />
android 內建的 DatePickerDialog 中<br />
<br />
<br />
<ul>
<li><span style="font-family: Monaco; font-size: 13px;">onDateSet 這個 method 會自動跑兩次,要加 view.isShown 來判斷</span></li>
</ul>
<br />
<br />
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<span style="font-family: Monaco;"><span style="-webkit-text-stroke-width: 0px; color: black; float: none; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px;">private DatePickerDialog.OnDateSetListener startDateListener = new DatePickerDialog.OnDateSetListener() {</span></span></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px; margin-left: 40px;">
<span style="font-family: Monaco;">@Override</span></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px; margin-left: 40px;">
<span style="font-family: Monaco; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal;">public </span><span style="font-family: Monaco; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal;">void </span><span style="font-family: Monaco; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal;">onDateSet</span><span style="font-family: Monaco; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal;">(</span><span style="font-family: Monaco; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal;">DatePicker</span><span style="font-family: Monaco; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal;">view</span><span style="font-family: Monaco; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal;">,</span><span style="font-family: Monaco; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal;">int</span><span style="font-family: Monaco; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal;">year</span><span style="font-family: Monaco; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal;">,</span><span style="font-family: Monaco; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal;">int</span><span style="font-family: Monaco; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal;">monthOfYear</span><span style="font-family: Monaco; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal;">,</span><span style="font-family: Monaco; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal;">int</span><span style="font-family: Monaco; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal;">dayOfMonth</span><span style="font-family: Monaco; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal;">) {</span></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px; margin-left: 40px;">
<span style="font-family: Monaco; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal;">if</span><span style="font-family: Monaco; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal;">(</span><span style="font-family: Monaco; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal;">view</span><span style="font-family: Monaco; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal;">.</span><span style="font-family: Monaco; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal;">isShown</span><span style="font-family: Monaco; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal;">()) {</span></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px; margin-left: 80px;">
<span style="font-size: 13px;"><span style="font-family: Monaco;">//onDateSet() 會跑兩次,需要判斷是否已出現</span></span></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px; margin-left: 40px;">
<span style="font-size: 13px;"><span style="font-family: Monaco;">}</span></span></div>
<div class="p1">
<!--?xml version="1.0" encoding="UTF-8" standalone="no"?-->
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<span style="font-family: Monaco;">}</span></div>
<div>
<ul>
<li><span style="font-family: Monaco;"><span style="font-size: 14px;"><span style="font-family: 'Helvetica Neue';"><span style="font-family: Monaco;">DatePickerDialog background</span> 後面會出現另一個圖層</span></span></span></li>
</ul>
<div>
<span style="font-family: Helvetica Neue;"><span style="font-size: 14px;">要加入 </span></span>dialog.getWindow().setBackgroundDrawable(new ColorDrawable(color.TRANSPARENT));</div>
<!--?xml version="1.0" encoding="UTF-8" standalone="no"?-->
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<span style="font-family: Monaco;"><br /></span></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<span style="font-family: Monaco;"><br /></span></div>
Anonymoushttp://www.blogger.com/profile/05343695923650753764noreply@blogger.com0tag:blogger.com,1999:blog-9161883088729562959.post-54880393336974257292015-09-24T11:55:00.001+08:002015-09-24T15:17:56.901+08:00Android LaunchMode<h4>
</h4>
<div>
<br /></div>
<div>
<!--?xml version="1.0" encoding="UTF-8" standalone="no"?-->
<span style="font-family: 'Helvetica Neue'; font-size: 14px;">Activity 在 singleTask 模式下,若再以</span></div>
<div>
<span style="font-family: 'Helvetica Neue'; font-size: 14px;"><br /></span></div>
<div>
<!--?xml version="1.0" encoding="UTF-8" standalone="no"?-->
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="font-size: 14px; font-stretch: normal;">intent</span><span style="font-size: 14px; font-stretch: normal;">.</span><span style="font-size: 14px; font-stretch: normal;">setFlags</span><span style="font-size: 14px; font-stretch: normal;">(</span><span style="font-size: 14px; font-stretch: normal;">Intent</span><span style="font-size: 14px; font-stretch: normal;">.</span><span style="font-size: 14px; font-stretch: normal;">FLAG_ACTIVITY_NEW_TASK</span><span style="font-size: 14px; font-stretch: normal;">);</span></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="font-size: 14px; font-stretch: normal;"><br /></span></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="font-size: 14px;">的方式喚起 Activity,將無法收到新的 Bundle</span></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="font-size: 14px;"><br /></span></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="font-size: 14px;">必須</span></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="font-size: 14px;"><br /></span></span></div>
<div>
<!--?xml version="1.0" encoding="UTF-8" standalone="no"?-->
<br />
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<span style="font-family: Monaco; font-size: 13px;">@Override</span></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<span style="font-family: Monaco; font-size: 13px;">protected</span> <span style="font-family: Monaco; font-size: 13px;">void</span> <span style="font-family: Monaco; font-size: 13px;">onNewIntent</span><span style="font-family: Monaco; font-size: 13px;">(</span><span style="font-family: Monaco; font-size: 13px;">Intent</span> <span style="font-family: Monaco; font-size: 13px;">intent</span><span style="font-family: Monaco; font-size: 13px;">) {</span>
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<span style="font-family: Monaco; font-size: 13px;"> </span> <span style="font-family: Monaco; font-size: 13px;">super</span><span style="font-family: Monaco; font-size: 13px;">.</span><span style="font-family: Monaco; font-size: 13px;">onNewIntent</span><span style="font-family: Monaco; font-size: 13px;">(</span><span style="font-family: Monaco; font-size: 13px;">intent</span><span style="font-family: Monaco; font-size: 13px;">);</span>
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<span style="font-family: Monaco; font-size: 13px;"> setIntent</span><span style="font-family: Monaco; font-size: 13px;">(</span><span style="font-family: Monaco; font-size: 13px;">intent</span><span style="font-family: Monaco; font-size: 13px;">);</span></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<span style="font-family: Monaco; font-size: 13px;"> </span> <span style="font-family: Monaco; font-size: 13px;">//now getIntent() should always return the last received intent</span>
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<span style="font-family: Monaco; font-size: 13px;">}</span></div>
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<span style="font-family: Monaco; font-size: 13px;"><br /></span></div>
<div>
<span style="font-family: Monaco;"><span style="font-size: 13px;">此 Activity 的生命週期為</span></span></div>
<div>
<br /></div>
<div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<span style="background-color: white; color: #444444; font-family: 'WenQuanYi Micro Hei Mono', 'WenQuanYi Micro Hei', 'Microsoft Yahei Mono', 'Microsoft Yahei', sans-serif;">1.onNewIntent</span></div>
<div style="font-size: 14px;">
<span style="color: #444444; font-family: WenQuanYi Micro Hei Mono, WenQuanYi Micro Hei, Microsoft Yahei Mono, Microsoft Yahei, sans-serif;"> </span><br />
<div style="font-family: 'Helvetica Neue';">
<span style="background-color: white; color: #444444; font-family: 'WenQuanYi Micro Hei Mono', 'WenQuanYi Micro Hei', 'Microsoft Yahei Mono', 'Microsoft Yahei', sans-serif;">2.onRestart</span></div>
<div style="font-family: 'Helvetica Neue';">
<span style="background-color: white; color: #444444; font-family: 'WenQuanYi Micro Hei Mono', 'WenQuanYi Micro Hei', 'Microsoft Yahei Mono', 'Microsoft Yahei', sans-serif;"><br /></span></div>
<div style="font-family: 'Helvetica Neue';">
<span style="background-color: white; color: #444444; font-family: 'WenQuanYi Micro Hei Mono', 'WenQuanYi Micro Hei', 'Microsoft Yahei Mono', 'Microsoft Yahei', sans-serif;">3.onStart</span></div>
<div style="font-family: 'Helvetica Neue';">
<span style="background-color: white; color: #444444; font-family: 'WenQuanYi Micro Hei Mono', 'WenQuanYi Micro Hei', 'Microsoft Yahei Mono', 'Microsoft Yahei', sans-serif;"><br /></span></div>
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<span style="background-color: white; color: #444444; font-family: 'WenQuanYi Micro Hei Mono', 'WenQuanYi Micro Hei', 'Microsoft Yahei Mono', 'Microsoft Yahei', sans-serif;">4.onResume</span></div>
</div>
Anonymoushttp://www.blogger.com/profile/05343695923650753764noreply@blogger.com0tag:blogger.com,1999:blog-9161883088729562959.post-38687000023451303702015-09-22T01:36:00.005+08:002018-11-12T14:41:36.149+08:00iOS測量文字長度, 以Swift和Objective-C為例iOS中,除了用UILabel的SizeToFit來測量文字長度外<br />
NSString其實也有內建提供這個方法<br />
<br />
以下是Objective-C的範例:<br />
<pre class="prettyprint">+ (CGSize)getSizeFromString:(NSString*)str withFont:(UIFont*)font{
return [str sizeWithAttributes:@{
NSFontAttributeName : font
}];
}
</pre>
<br />
這個method只要輸入NSString和UIFont,就可以得到String的尺吋(以CGSize回傳,有該String將要顯示的width或是height)<br />
<br />
而Swift要測量的話,要先轉成NSString,且AttributteName也有所修改<br />
如下<br />
<pre class="prettyprint">func getSizeFromString(string:String, withFont font:UIFont)->CGSize{
let textSize = NSString(string: string ?? "").sizeWithAttributes(
[ NSFontAttributeName:font ])
return textSize
}</pre>
<a name='more'></a>
<br />
<br />
應用上來說可以<br />
var textSize = getSizeFromString(label.text! , withFont: label.font)<br />
然後從 textSize.width 測量出即將顯示的文字長度<br />
這在一些UI的編排或是計算上是滿有用的<br />
<br />
另外此方法UILabel的Size To Fit比較字串的長度其實是差不多的<br />
如下範例(使用Swift為例):<br />
<pre class="prettyprint">label.backgroundColor = UIColor.lightGrayColor()
label.numberOfLines = 0
label.lineBreakMode = NSLineBreakMode.ByClipping
label.text = "中文中文56789 a123456789 a123456789 a123456789"
label.frame = CGRectMake(20, 20, 2000, 200)
label.sizeToFit()
// 使用和label相同的文字(text)和字體(font) 給swift的範例
var textSize = getSizeFromString(label.text! , withFont: label.font)
NSLog("here is swift string width:%f", textSize.width)
// 這是 ObjC的測量文字範例 (get text length or width )
textSize = OBJCViewController.getSizeFromString(label.text!, withFont: label.font)
NSLog("here is objc string width:%f", textSize.width)
NSLog("here is label width:%f", label.frame.size.width)
</pre>
<br />
<br />
XCode輸出的結果如下:<br />
<pre class="prettyprint">2015-09-22 01:23:46.728 test20150922[2432:48542] here is swift string width:423.007812
2015-09-22 01:23:46.729 test20150922[2432:48542] here is objc string width:423.007812
2015-09-22 01:23:46.729 test20150922[2432:48542] here is label width:423.500000
</pre>
<script type="text/javascript" src="//js1.bloggerads.net/contentads.aspx?blogid=20150916000016" async></script>
葉建胤http://www.blogger.com/profile/13939608302918631988noreply@blogger.com0tag:blogger.com,1999:blog-9161883088729562959.post-1769794736807727952015-09-20T05:03:00.002+08:002018-11-12T17:01:53.510+08:00XCode 7 遇到 Bitcode 錯誤的解決辦法<br />
最近Apple Release了 XCode 7<br />
如果在開發iOS的APP 有遇到類以下的錯誤:<br />
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<!--?xml version="1.0" encoding="UTF-8" standalone="no"?-->
<br />
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
</div>
<br />
<table style="-evernote-table: true; border-collapse: collapse; font-family: 'Helvetica Neue'; font-size: 14px; margin-left: 0px; table-layout: fixed; width: 100%;">
<tbody>
<tr><td style="border-color: rgb(219,219,219); border-style: solid; border-width: 1px; margin: 0px; padding: 10px; width: 100%;"><div>
<span style="font: 11.0px Menlo;">ld: '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.0.sdk/usr/lib/dylib1.o' does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. for architecture armv7</span></div>
<div>
<span style="font-size: 11px;"><span style="font-family: Menlo;">clang: error: linker command failed with exit code 1 (use -v to see invocation)</span></span></div>
</td>
</tr>
</tbody></table>
<br />
那就是遇到了BITCODE的問題了<br />
<br />
解決辦法很簡單,就是關掉他,方法如下圖<br />
(到專案的 Build Settings ,搜尋 bitcode)<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEic7Xm0l-sw2bqdNQS_CFrH1z8RIrz3-f7STK8bXyCh2_tRyln19qdJHAiEkqTODrrp_Iu4XKyN6bPb_fRmUsvAgTbSnDc2Dl-pLWG1ECQoe0A2ocT_il3RtUDp0FaxZB-H7mwOMQ6YnxXl/s1600/Screen+Shot+2015-09-17+at+2.08.09+PM.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEic7Xm0l-sw2bqdNQS_CFrH1z8RIrz3-f7STK8bXyCh2_tRyln19qdJHAiEkqTODrrp_Iu4XKyN6bPb_fRmUsvAgTbSnDc2Dl-pLWG1ECQoe0A2ocT_il3RtUDp0FaxZB-H7mwOMQ6YnxXl/s1600/Screen+Shot+2015-09-17+at+2.08.09+PM.png" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
BitCode是什麼呢?</div>
<div class="separator" style="clear: both; text-align: left;">
從Apple的官網說明來看 ( <a href="https://developer.apple.com/library/prerelease/watchos/documentation/IDEs/Conceptual/AppDistributionGuide/AppThinning/AppThinning.html">https://developer.apple.com/library/prerelease/watchos/documentation/IDEs/Conceptual/AppDistributionGuide/AppThinning/AppThinning.html</a> )</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
他是一個有點像是Java Bytecode一樣的東西</div>
<div class="separator" style="clear: both; text-align: left;">
但他是給LLVM (Apple的編譯器)用的,簡單的說就是Apple希望你可以在上傳到App Store時也一起上傳Bitcode,好處就是App Store可以幫你針對不同的 iOS 設備去優化你的App,不用重新上傳或是針對CPU做編譯</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
但會出現以上的錯誤可能就是因為用了沒有Bitcode的Library(通常是C++或是第三方的套件)</div>
<div class="separator" style="clear: both; text-align: left;">
所以XCode在產生Bitcode就會失敗了</div>
<div class="separator" style="clear: both; text-align: left;">
目前看來Bitcode比較適用於純 Swift 或是Objective-C的專案</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<br />
<br />
<script type="text/javascript" src="//js1.bloggerads.net/contentads.aspx?blogid=20150916000016" async></script>葉建胤http://www.blogger.com/profile/13939608302918631988noreply@blogger.com0tag:blogger.com,1999:blog-9161883088729562959.post-89625588741801690912015-09-16T02:09:00.003+08:002018-11-12T17:00:47.539+08:00Mac安裝PostgreSQL與簡單教學<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
PostgreSQL和MySQL一樣都是一種SQL Server
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
以下有些教學是可以提供給會MySQL,也想使用PostgreSQL的使用者看看
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<span style="font-size: 18px;"><b>第零步,安裝PostgreSQL</b></span></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
使用brew來安裝 (Linux的話就看是apt / yum 還是什麼的,以下以Mac為例)
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<table style="-evernote-table: true; border-collapse: collapse; font-family: 'Helvetica Neue'; font-size: 14px; margin-left: 0px; table-layout: fixed; width: 100%;">
<tbody>
<tr><td style="border-color: rgb(219,219,219); border-style: solid; border-width: 1px; margin: 0px; padding: 10px; width: 100%;"><div>
brew install postgresql
</div>
</td>
</tr>
</tbody></table>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
成功的話,會看到最後有段訊息
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<table style="-evernote-table: true; border-collapse: collapse; font-family: 'Helvetica Neue'; font-size: 14px; margin-left: 0px; table-layout: fixed; width: 100%;">
<tbody>
<tr><td style="border-color: rgb(219,219,219); border-style: solid; border-width: 1px; margin: 0px; padding: 10px; width: 100%;"><div>
To have launchd start postgresql at login:
</div>
<div>
ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
</div>
<div>
Then to load postgresql now:
</div>
<div>
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
</div>
<div>
Or, if you don't want/need launchctl, you can just run:
</div>
<div>
postgres -D /usr/local/var/postgres
</div>
</td>
</tr>
</tbody></table>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
主要的重點是說,你想要一登入Mac的使用者,就自動啟動PostgreSQL的話,就在終端機輸入
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<table style="-evernote-table: true; border-collapse: collapse; font-family: 'Helvetica Neue'; font-size: 14px; margin-left: 0px; table-layout: fixed; width: 100%;">
<tbody>
<tr><td style="border-color: rgb(219,219,219); border-style: solid; border-width: 1px; margin: 0px; padding: 10px; width: 100%;"><div>
ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
</div>
</td>
</tr>
</tbody></table>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
要手動啟動 (第一次裝完最好也輸入一次)
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<table style="-evernote-table: true; border-collapse: collapse; font-family: 'Helvetica Neue'; font-size: 14px; margin-left: 0px; table-layout: fixed; width: 100%;">
<tbody>
<tr><td style="border-color: rgb(219,219,219); border-style: solid; border-width: 1px; margin: 0px; padding: 10px; width: 100%;"><div>
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
</div>
</td>
</tr>
</tbody></table>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
如果想要停止的話輸入
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<table style="-evernote-table: true; border-collapse: collapse; font-family: 'Helvetica Neue'; font-size: 14px; margin-left: 0px; table-layout: fixed; width: 100%;">
<tbody>
<tr><td style="border-color: rgb(219,219,219); border-style: solid; border-width: 1px; margin: 0px; padding: 10px; width: 100%;"><div>
postgres -D /usr/local/var/postgres
</div>
</td>
</tr>
</tbody></table>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<span style="font-size: 18px;"><b>第一步,建立Database</b></span></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
createdb 是 postgresql 建立資料庫的指令
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<a name='more'></a><br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
試看看建立資料庫,直接在Terminal中輸入 (此以 test_1 做為範例)
</div>
<table style="-evernote-table: true; border-collapse: collapse; font-family: 'Helvetica Neue'; font-size: 14px; margin-left: 0px; table-layout: fixed; width: 100%;">
<tbody>
<tr><td style="border-color: rgb(219,219,219); border-style: solid; border-width: 1px; margin: 0px; padding: 10px; width: 100%;"><div>
createdb test_1
</div>
</td>
</tr>
</tbody></table>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
註:由於postgresql設計的特性,一般來說執行postgresql ( postmaster )的user就會有直接連入資料庫的功能
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
所以不像MySQL,需要特別指定User
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
註2:postmaster為postgresql的資料庫服務
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<span style="font-size: 18px;"><b>第二步,進入Database</b></span></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
如果成功,就可以開始進入剛剛建立的DB
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<table style="-evernote-table: true; border-collapse: collapse; font-family: 'Helvetica Neue'; font-size: 14px; margin-left: 0px; table-layout: fixed; width: 100%;">
<tbody>
<tr><td style="border-color: rgb(219,219,219); border-style: solid; border-width: 1px; margin: 0px; padding: 10px; width: 100%;"><div>
psql test_1
</div>
</td>
</tr>
</tbody></table>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
如果沒有意外,可以看到終端機變成了
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
test_1=#
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
輸入\q就可以離開此模式 (此模式下按Ctrl + C是無效的)
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
輸入help可以看到一些簡單的說明
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
在PostgreSQL的終端(PSQL) 輸入 \du
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
可以看到現在的使用者,例如:
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<table style="-evernote-table: true; border-collapse: collapse; font-family: 'Helvetica Neue'; font-size: 14px; margin-left: 0px; table-layout: fixed; width: 100%;">
<tbody>
<tr><td style="border-color: rgb(219,219,219); border-style: solid; border-width: 1px; margin: 0px; padding: 10px; width: 100%;"><div>
<span style="font-family: 'Courier New';"> List of roles</span></div>
<div>
<span style="font-family: 'Courier New';"> Role name | Attributes | Member of </span></div>
<div>
<span style="font-family: 'Courier New';">-----------+------------------------------------------------+-----------</span></div>
<div>
<span style="font-family: 'Courier New';"> seachaos | Superuser, Create role, Create DB, Replication | {}</span></div>
</td>
</tr>
</tbody></table>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
這裡現在列出的User Name (Role Name)應該和現在登入Mac的使用者名稱是一樣的
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
PSQL中輸入
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<table style="-evernote-table: true; border-collapse: collapse; font-family: 'Helvetica Neue'; font-size: 14px; margin-left: 0px; table-layout: fixed; width: 100%;">
<tbody>
<tr><td style="border-color: rgb(219,219,219); border-style: solid; border-width: 1px; margin: 0px; padding: 10px; width: 100%;"><div>
SELECT version();
</div>
</td>
</tr>
</tbody></table>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
可以查看到現在的PostgreSQL版本資訊等等
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<span style="font-size: 18px;"><b>第三步,操作Table (Create Table)</b></span></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
建立一個範例Table,可以在PSQL中輸入以下語法
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<table style="-evernote-table: true; border-collapse: collapse; font-family: 'Helvetica Neue'; font-size: 14px; margin-left: 0px; table-layout: fixed; width: 100%;">
<tbody>
<tr><td style="border-color: rgb(219,219,219); border-style: solid; border-width: 1px; margin: 0px; padding: 10px; width: 100%;"><div>
CREATE TABLE mytable
</div>
<div>
( id SERIAL NOT NULL ,
</div>
<div>
name varchar(255) NOT NULL ,
</div>
<div>
value text NOT NULL ,
</div>
<div>
time timestamp NOT NULL ,
</div>
<div>
PRIMARY KEY (id));
</div>
</td>
</tr>
</tbody></table>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
其中建立流水號的id語法,SERIAL相當於MySQL中的 AUTO_INCREMENT
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
(Mysql寫法為 id INT NOT NULL AUTO_INCREMENT , 在PostgreSQL為 id SERIAL NOT NULL )
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
如果要看現在PostgreSQL的Database中有那些Table,可以輸入 \dt
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
(類似MySQL的 show tables )
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
應該可以看到類似以下的結果
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<table style="-evernote-table: true; border-collapse: collapse; font-family: 'Helvetica Neue'; font-size: 14px; margin-left: 0px; table-layout: fixed; width: 100%;">
<tbody>
<tr><td style="border-color: rgb(219,219,219); border-style: solid; border-width: 1px; margin: 0px; padding: 10px; width: 100%;"><div>
<span style="font-family: 'Courier New';">test_1=# \dt</span></div>
<div>
<span style="font-family: 'Courier New';"> List of relations</span></div>
<div>
<span style="font-family: 'Courier New';"> Schema | Name | Type | Owner </span></div>
<div>
<span style="font-family: 'Courier New';">--------+---------+-------+----------</span></div>
<div>
<span style="font-family: 'Courier New';"> public | mytable | table | seachaos</span></div>
<div>
<span style="font-family: 'Courier New';">(1 row)</span></div>
</td>
</tr>
</tbody></table>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
可以試看看插入(insert)一個資料到mytable中,語法如下:
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<table style="-evernote-table: true; border-collapse: collapse; font-family: 'Helvetica Neue'; font-size: 14px; margin-left: 0px; table-layout: fixed; width: 100%;">
<tbody>
<tr><td style="border-color: rgb(219,219,219); border-style: solid; border-width: 1px; margin: 0px; padding: 10px; width: 100%;"><div>
insert into mytable (name,value,time)values(‘Good','this is value',now());
</div>
</td>
</tr>
</tbody></table>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
再來輸入Select語法,看剛才的insert是否成功:
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<table style="-evernote-table: true; border-collapse: collapse; font-family: 'Helvetica Neue'; font-size: 14px; margin-left: 0px; table-layout: fixed; width: 100%;">
<tbody>
<tr><td style="border-color: rgb(219,219,219); border-style: solid; border-width: 1px; margin: 0px; padding: 10px; width: 100%;"><div>
select * from mytable
</div>
</td>
</tr>
</tbody></table>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
結果應該類似
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<table style="-evernote-table: true; border-collapse: collapse; font-family: 'Helvetica Neue'; font-size: 14px; margin-left: 0px; table-layout: fixed; width: 100%;">
<tbody>
<tr><td style="border-color: rgb(219,219,219); border-style: solid; border-width: 1px; margin: 0px; padding: 10px; width: 100%;"><div>
<span style="font-family: 'Courier New';">test_1=# select * from mytable;</span></div>
<div>
<span style="font-family: 'Courier New';"> id | name | value | time </span></div>
<div>
<span style="font-family: 'Courier New';">----+------+---------------+----------------------------</span></div>
<div>
<span style="font-family: 'Courier New';"> 2 | Good | this is value | 2015-09-13 03:51:27.426327</span></div>
<div>
<span style="font-family: 'Courier New';">(1 row)</span></div>
</td>
</tr>
</tbody></table>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
再來其他的應該就和SQL一樣大同小異了
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<!--?xml version="1.0" encoding="UTF-8" standalone="no"?-->
<br />
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
</div>
<br />
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<script type="text/javascript" src="//js1.bloggerads.net/contentads.aspx?blogid=20150916000016" async></script>
葉建胤http://www.blogger.com/profile/13939608302918631988noreply@blogger.com0tag:blogger.com,1999:blog-9161883088729562959.post-75500864042062614412015-09-13T03:01:00.000+08:002015-09-13T03:02:24.206+08:00HVL-F60M 開箱文之前在使用Canon單眼時,用的是副廠閃燈<br />
在跳到SONY家後一直沒有閃燈 (也只有買過雜牌的LED環閃)<br />
<br />
但是有時候發現拍微距或是其他景物時,沒有閃燈真的很不方便<br />
所以就敗下了SONY的神燈了...<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjK01Jbfs4qp2xMQ_NtxkmLV0bHAz_OAM6VvrKbGQMM-JM2g691dYM7dHmQMoMQ_6LOSWk5x5n0glThLXLqoaUcpm0gTOZnrKeFXvVeFEdK7wL3qmq-vevtByU3exxSgwlJjeq3X-Mg85X2/s1600/001" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="425" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjK01Jbfs4qp2xMQ_NtxkmLV0bHAz_OAM6VvrKbGQMM-JM2g691dYM7dHmQMoMQ_6LOSWk5x5n0glThLXLqoaUcpm0gTOZnrKeFXvVeFEdK7wL3qmq-vevtByU3exxSgwlJjeq3X-Mg85X2/s640/001" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
等了好久終於收到了神燈 HVL F60M (人稱60閃)</div>
<div class="separator" style="clear: both; text-align: left;">
</div>
<a name='more'></a><br />
<br />
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhXXY42KFscilLwBJFdGyK75aGH1529Fg0B_KFor2nSiGTxEJJnRV-MhpnoO4Ne8DtdOQlbEX011feK96oqPrOOrofY1wu1-MBhlizIvER7NbWg_xGUHAUbe9zR8m982B5a3C0cfU6Ly1JN/s1600/001" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em; text-align: center;"><img border="0" height="426" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhXXY42KFscilLwBJFdGyK75aGH1529Fg0B_KFor2nSiGTxEJJnRV-MhpnoO4Ne8DtdOQlbEX011feK96oqPrOOrofY1wu1-MBhlizIvER7NbWg_xGUHAUbe9zR8m982B5a3C0cfU6Ly1JN/s640/001" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: left;">
從箱子中拿出閃指,閃燈一開始就裝在保護套中</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNVuFZun6BOu7gGxHjJswuJ6zSi7nao8t65W5TnW-29NQZSRaW87WEVAh5yEYaUYpZvVB1IIaVzkJQq_NPwLvLNcz0LLRKXjjMlmPCBPXKgwgm8ig-dDd6l3KbCOkACqdSHdFfxQPyXPc6/s1600/001" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="426" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNVuFZun6BOu7gGxHjJswuJ6zSi7nao8t65W5TnW-29NQZSRaW87WEVAh5yEYaUYpZvVB1IIaVzkJQq_NPwLvLNcz0LLRKXjjMlmPCBPXKgwgm8ig-dDd6l3KbCOkACqdSHdFfxQPyXPc6/s640/001" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
直立起來的樣子</div>
<div class="separator" style="clear: both; text-align: left;">
這個底坐滿有趣的,他可以對折和閃燈一起放在保護套中</div>
<div class="separator" style="clear: both; text-align: left;">
一開始我還找不到底坐,想說是不是有缺件,結果閃指的保護套壓一壓,發現另有玄機</div>
<div class="separator" style="clear: both; text-align: left;">
是在閃燈保護套中還有一個暗袋,閃光燈底坐就在裡面</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhHTedU00KzjaFRAdZt64AUOvOZ3nosclX69WEY-k-jCGSw1uLgKpAHhtetWvUhxUjs_eBfP4A1FHVzaSatKx-ErxPyC-uaptUnYZtJBLOxSddfmpnMVqOrgkiPcXeaZ-FEURG94PWn6MPs/s1600/001" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img alt="HVL F60M 閃燈背面" border="0" height="426" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhHTedU00KzjaFRAdZt64AUOvOZ3nosclX69WEY-k-jCGSw1uLgKpAHhtetWvUhxUjs_eBfP4A1FHVzaSatKx-ErxPyC-uaptUnYZtJBLOxSddfmpnMVqOrgkiPcXeaZ-FEURG94PWn6MPs/s640/001" title="HVL F60M 閃燈背面" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
其實本來也有想過買43閃 (HVL-F43M) ,但想一想還是攻頂好了</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
SONY神燈果然不是蓋的</div>
<div class="separator" style="clear: both; text-align: left;">
回電快,閃起來也快,不會拖泥帶水 (之前的副廠閃燈的光燈停留時間比較長,會讓人眼感到不適,但60閃不會)</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
唯一缺點就是接上A7,閃燈的輔助對焦燈不會啟用 (聽說是NEX系列以來就有的Bug)</div>
<div class="separator" style="clear: both; text-align: left;">
不過整體真的不錯</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<br />葉建胤http://www.blogger.com/profile/13939608302918631988noreply@blogger.com0tag:blogger.com,1999:blog-9161883088729562959.post-62922393989141739502015-09-02T02:26:00.001+08:002015-09-04T22:51:52.847+08:00將iBeacon變成一顆球<br />
因為同事像皮筋捆在一起,一直不停的重複,就產生了一顆像皮筋球<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiniVuH1OVfg6uF6H9EIaHL5G4EnZgmnJtrAFHUmzCaup5Qir6V6gLbPnt1jxg7GV-nCseHebJwzPYOv-rewubCiHvDhSWlJ5EZSoMf8up_0VEMFoVeH7-WBT5V4EJQmqQsk52k66oDBFKy/s1600/IMG_2779.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="425" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiniVuH1OVfg6uF6H9EIaHL5G4EnZgmnJtrAFHUmzCaup5Qir6V6gLbPnt1jxg7GV-nCseHebJwzPYOv-rewubCiHvDhSWlJ5EZSoMf8up_0VEMFoVeH7-WBT5V4EJQmqQsk52k66oDBFKy/s640/IMG_2779.JPG" width="640" /></a></div>
<br />
<br />
<a name='more'></a><br /><br />
<br />
又剛好老闆有幾顆沒電的Estimote的iBeacon<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgX-hT8D7WuSgEZrRsj_U29RJUkQL201QHq4DqbExp25aiScDjU3r5csNrB8yVd8aT_Ei0JwAyx2oCwosnvJ4dURM0YramwA_wsHdqyj_MxVQA1az7WPZA867nnvyOD3Rtly17s-SWvnDCI/s1600/IMG_2774.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="427" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgX-hT8D7WuSgEZrRsj_U29RJUkQL201QHq4DqbExp25aiScDjU3r5csNrB8yVd8aT_Ei0JwAyx2oCwosnvJ4dURM0YramwA_wsHdqyj_MxVQA1az7WPZA867nnvyOD3Rtly17s-SWvnDCI/s640/IMG_2774.JPG" width="640" /></a></div>
<br />
<br />
在得到老闆的同意後,將Estimote的iBeacon換了新的電池<br />
( Estimote Beacon用的電池是CR2450,網路上買的 )<br />
<br />
將原來的皮割開<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiH0GDk4DXvFYE0cZNzYHSgOjfCPyO7E8tNahbDhV0YuvE8pR32tevgq1ZQiykJty1Vr5t1qD3_8vZBnvYmFj7DNkZTmPBZrjs3qNfGXwk_SnCCOuWjDhMDJdLsevXvP9PADiX2WNTUzg7j/s1600/IMG_2772.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="426" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiH0GDk4DXvFYE0cZNzYHSgOjfCPyO7E8tNahbDhV0YuvE8pR32tevgq1ZQiykJty1Vr5t1qD3_8vZBnvYmFj7DNkZTmPBZrjs3qNfGXwk_SnCCOuWjDhMDJdLsevXvP9PADiX2WNTUzg7j/s640/IMG_2772.JPG" width="640" /></a></div>
<br />
<br />
換上新的電池<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmrJ2ikH6rjmTwbfi00FwFq-rA_wSxrePZk24OAEf-uHK4ct9NzwG-ZEqzVsP84EdoDQbpW4kvEt5ceM0vwhSYoazj-9GOj0bWm2aeTsikAUMmLb50JDaP3eMva7apifHiuM2H91jzRwKH/s1600/IMG_2776.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="426" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmrJ2ikH6rjmTwbfi00FwFq-rA_wSxrePZk24OAEf-uHK4ct9NzwG-ZEqzVsP84EdoDQbpW4kvEt5ceM0vwhSYoazj-9GOj0bWm2aeTsikAUMmLb50JDaP3eMva7apifHiuM2H91jzRwKH/s640/IMG_2776.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">換上新電池的樣子</td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEivYF4gbPaxJjN7K1kv7g8NSNS5GNB75e6PmLLOc9X6j6f1fIbqjVwZWw5Wg7BcEqsBGYkGJTyDdPDOlNttQPQ-ECxMcNZ_iw1YmPBE4Wg8slYjkYrdtFd61qcB8B4m7oZTGyc1j6NnnXtW/s1600/IMG_2775.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="426" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEivYF4gbPaxJjN7K1kv7g8NSNS5GNB75e6PmLLOc9X6j6f1fIbqjVwZWw5Wg7BcEqsBGYkGJTyDdPDOlNttQPQ-ECxMcNZ_iw1YmPBE4Wg8slYjkYrdtFd61qcB8B4m7oZTGyc1j6NnnXtW/s640/IMG_2775.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Estimote 的iBeacon原來內建的電池</td></tr>
</tbody></table>
<br />
然後塞回原來的皮中<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbphwU8yqJ0QDY0wSAdfW80y5ykdWq3ChtNG2FxK0aMfJobtwMLcI9US_PGd4wuwUQGQ5p05J34bUJbTiSwoQR-FMuZYmjTbSWdLW9amxx7pBPSspBKaAs7DuvLSXHYkb80QfErCXQnBdg/s1600/IMG_2773.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="426" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbphwU8yqJ0QDY0wSAdfW80y5ykdWq3ChtNG2FxK0aMfJobtwMLcI9US_PGd4wuwUQGQ5p05J34bUJbTiSwoQR-FMuZYmjTbSWdLW9amxx7pBPSspBKaAs7DuvLSXHYkb80QfErCXQnBdg/s640/IMG_2773.JPG" width="640" /></a></div>
<br />
<br />
<br />
由於球是會滾動且有彈性的,怕iBeacon會因此撞壞,所以先用一層氣泡紙包起來<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVXr40B6tYhFuFZU4itxhbY3Ddjfz6Ht2js6Y4A4UYEIS7ZU1AMGkLL5dxYltPY0ciIvR_wYpHY4AhyphenhyphenEdTuNcwUJpHIKw_3hWOCnKJA5KA-_t5o1rsTz2YQcBrywgi3ekxT95XN7XtEFIN/s1600/IMG_2777.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="426" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVXr40B6tYhFuFZU4itxhbY3Ddjfz6Ht2js6Y4A4UYEIS7ZU1AMGkLL5dxYltPY0ciIvR_wYpHY4AhyphenhyphenEdTuNcwUJpHIKw_3hWOCnKJA5KA-_t5o1rsTz2YQcBrywgi3ekxT95XN7XtEFIN/s640/IMG_2777.JPG" width="640" /></a></div>
<br />
<br />
開始捆像皮筋<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgX4QilnVTx6Kh9nnRC3qbWK5oDJ_P6-ijiAIQSioLaoPt14XzbyIT83M-zvjyDVlNj5D25tdKtllWQhtUAFshX0hiQNGv0BC5MALKQRmDHVpNurLvV7qjJ39DcD5B_hdLUJmKNpo1sPwWR/s1600/IMG_2778.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="425" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgX4QilnVTx6Kh9nnRC3qbWK5oDJ_P6-ijiAIQSioLaoPt14XzbyIT83M-zvjyDVlNj5D25tdKtllWQhtUAFshX0hiQNGv0BC5MALKQRmDHVpNurLvV7qjJ39DcD5B_hdLUJmKNpo1sPwWR/s640/IMG_2778.JPG" width="640" /></a></div>
<br />
<br />
越捆越大,就成了一顆有彈力像皮筋球了<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgH60EYQJ6EYALceyOf3l6tQseuC1JPEeED9BOVlQZlbhvWa2uNXRnkr3TROFK7Zw5EMlNomSZIWYG2mlhn1uiXeOtOzeVnE50G1Xex6u2Pe3YediRVXKsJ7EP75jm-jON2MKt-VeC3CUEB/s1600/IMG_2781.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="426" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgH60EYQJ6EYALceyOf3l6tQseuC1JPEeED9BOVlQZlbhvWa2uNXRnkr3TROFK7Zw5EMlNomSZIWYG2mlhn1uiXeOtOzeVnE50G1Xex6u2Pe3YediRVXKsJ7EP75jm-jON2MKt-VeC3CUEB/s640/IMG_2781.JPG" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhN9P6xzIeZwEvFUKSbJsXRp9ndcHQQzfrifJpPkzb5T1MsSaTrVhQOdRdz1n-UoaCohi1wzN1pxuDYpt4ePDKUiHMl5qjBHbOj9jiduz0bYKS7D5N8C9DWGWhjtckwijn-G7EGB4Qz4DbH/s1600/IMG_2779.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="426" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhN9P6xzIeZwEvFUKSbJsXRp9ndcHQQzfrifJpPkzb5T1MsSaTrVhQOdRdz1n-UoaCohi1wzN1pxuDYpt4ePDKUiHMl5qjBHbOj9jiduz0bYKS7D5N8C9DWGWhjtckwijn-G7EGB4Qz4DbH/s640/IMG_2779.JPG" width="640" /></a></div>
<br />
<br />
放入iBeacon的好處是,球在一定的範圍內不見還找得到 XD<br />
<br />
<br />
<br />
<br />葉建胤http://www.blogger.com/profile/13939608302918631988noreply@blogger.com0tag:blogger.com,1999:blog-9161883088729562959.post-72247169957118777812015-09-01T02:37:00.003+08:002015-09-13T13:41:53.735+08:00Ruby on Rails 連結MAMP的MySQL教學 (Mac適用)<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
Mac要先安裝Mysql (透過brew),指令如下:
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<table style="-evernote-table: true; border-collapse: collapse; font-family: 'Helvetica Neue'; font-size: 14px; margin-left: 0px; table-layout: fixed; width: 100%;">
<tbody>
<tr><td style="border-color: rgb(219,219,219); border-style: solid; border-width: 1px; margin: 0px; padding: 10px; width: 100%;"><div>
brew install mysql
</div>
</td>
</tr>
</tbody></table>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
再來是到Rails中安裝mysql的gem,進到目錄下編輯Gemfile,加入這行
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<table style="-evernote-table: true; border-collapse: collapse; font-family: 'Helvetica Neue'; font-size: 14px; margin-left: 0px; table-layout: fixed; width: 100%;">
<tbody>
<tr><td style="border-color: rgb(219,219,219); border-style: solid; border-width: 1px; margin: 0px; padding: 10px; width: 100%;"><div>
gem 'mysql2'
</div>
</td>
</tr>
</tbody></table>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
然後
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<table style="-evernote-table: true; border-collapse: collapse; font-family: 'Helvetica Neue'; font-size: 14px; margin-left: 0px; table-layout: fixed; width: 100%;">
<tbody>
<tr><td style="border-color: rgb(219,219,219); border-style: solid; border-width: 1px; margin: 0px; padding: 10px; width: 100%;"><div>
bundle install
</div>
</td>
</tr>
</tbody></table>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
可以先到MAMP的phpMyAdmin建立好一個資料庫和User來使用
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
(MAMP預設的phpMyAdmin位置是 <a href="http://localhost:8888/phpMyAdmin/">http://localhost:8888/phpMyAdmin/</a> )
</div>
<!--?xml version="1.0" encoding="UTF-8" standalone="no"?-->
<br />
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
參考以下步驟</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br />
<a name='more'></a><br /></div>
<img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgN-aDUZfcTDpOEUNCJc1nd6mj2mEW1fVuePbGj6LuW9nJIbUX3hQ6BRjdicjHxOGF_lLkZm4edYHatjQYR0lgMqwT5Q73pTzKRm17yXjD2OPe7EkuU1LYtoAFTHyDihDqTibEmUQ6x5LSl/s400/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2015-09-01+%25E4%25B8%258A%25E5%258D%25882.14.52.png" /><br />
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br />
然後建立使用者</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicN-aWx7CZreg3hX02Ma4yRpnfG6mFPmUuuAs23bi6I5JXFeYnOpAnhfTBgLPNF2fgxPcH-cNuhnakvlYC4jwZ2-zqkryeaEjEVk0aLdzUPcOl8pysDXzNOg86kasDTbVVKw3prb77V47S/s400/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2015-09-01+%25E4%25B8%258A%25E5%258D%25882.13.03.png" /><br />
<div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br />
<br />
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
接下來是回到Rails
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
建立個測試用的Model (終端機指令輸入如下)
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<div>
<br /></div>
<table style="-evernote-table: true; border-collapse: collapse; margin-left: 0px; table-layout: fixed; width: 100%;">
<tbody>
<tr><td style="border-color: rgb(219,219,219); border-style: solid; border-width: 1px; margin: 0px; padding: 10px; width: 100%;"><div>
rails g model member account:string password:string name:string email:string
</div>
</td>
</tr>
</tbody></table>
<div>
<br /></div>
<div>
可以看見Rails的異動如下:
</div>
<div>
<br /></div>
<table style="-evernote-table: true; border-collapse: collapse; margin-left: 0px; table-layout: fixed; width: 100%;">
<tbody>
<tr><td style="border-color: rgb(219,219,219); border-style: solid; border-width: 1px; margin: 0px; padding: 10px; width: 100%;"><div>
invoke active_record
</div>
<div>
create db/migrate/20150831180104_create_members.rb
</div>
<div>
create app/models/member.rb
</div>
<div>
invoke test_unit
</div>
<div>
create test/models/member_test.rb
</div>
<div>
create test/fixtures/members.yml
</div>
</td>
</tr>
</tbody></table>
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
最後是設定 config/database.yml ,將原來的 sqlite改成mysql
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
註:MAMP或是某些特別的的MySQL需要另外設定Socket (重要)
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
MAMP的MySQL Socket預設是在 /Applications/MAMP/tmp/mysql/mysql.sock
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
database.yml範例:
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<table style="-evernote-table: true; border-collapse: collapse; font-family: 'Helvetica Neue'; font-size: 14px; margin-left: 0px; table-layout: fixed; width: 100%;">
<tbody>
<tr><td style="border-color: rgb(219,219,219); border-style: solid; border-width: 1px; margin: 0px; padding: 10px; width: 100%;"><div>
… (略)
</div>
<div>
default: &default
</div>
<div>
<span style="color: #ff9300;"> adapter: mysql2</span></div>
<div>
<span style="color: #ff9300;"> encoding: utf8</span></div>
<div>
<span style="color: #ff9300;"> database: test_001</span></div>
<div>
<span style="color: #ff9300;"> host: localhost</span></div>
<div>
<span style="color: #ff9300;"> username: test_001</span></div>
<div>
<span style="color: #ff9300;"> password: **************</span></div>
<div>
<span style="color: #ff9300;"> <span style="color: #ff2600;">socket: </span></span><span style="color: #ff2600;"> /Applications/MAMP/tmp/mysql/mysql.sock</span></div>
<div>
<br /></div>
<div>
development:
</div>
<div>
<<: *default
</div>
<div>
# database: db/development.sqlite3
</div>
<div>
… (略)
</div>
</td>
</tr>
</tbody></table>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
請注意yml的縮排很嚴格,上面的縮排是用二個空白
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
然後所有的 sqlite有關的全部注解掉 ( yml中的#是註解) ,例如
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<table style="-evernote-table: true; border-collapse: collapse; font-family: 'Helvetica Neue'; font-size: 14px; margin-left: 0px; table-layout: fixed; width: 100%;">
<tbody>
<tr><td style="border-color: rgb(219,219,219); border-style: solid; border-width: 1px; margin: 0px; padding: 10px; width: 100%;"><div>
test:
</div>
<div>
<<: *default
</div>
<div>
<span style="-evernote-highlight: true; background-color: #fffaa5;"># database: db/test.sqlite3</span></div>
<div>
<br /></div>
<div>
production:
</div>
<div>
<<: *default
</div>
<div>
<span style="-evernote-highlight: true; background-color: #fffaa5;"># database: db/production.sqlite3</span></div>
</td>
</tr>
</tbody></table>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
然後在Rails中試看看建立db,輸入
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<table style="-evernote-table: true; border-collapse: collapse; font-family: 'Helvetica Neue'; font-size: 14px; margin-left: 0px; table-layout: fixed; width: 100%;">
<tbody>
<tr><td style="border-color: rgb(219,219,219); border-style: solid; border-width: 1px; margin: 0px; padding: 10px; width: 100%;"><div>
rake db:migrate
</div>
</td>
</tr>
</tbody></table>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<!--?xml version="1.0" encoding="UTF-8" standalone="no"?-->
<br />
<div>
</div>
<br />
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
如果沒有錯誤,再到phpMyAdmin就會看到Ruby on Rails幫我們建立的Table 了 :)</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
</div>
<!--?xml version="1.0" encoding="UTF-8" standalone="no"?-->
<br />
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
</div>
<br />
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
</div>
葉建胤http://www.blogger.com/profile/13939608302918631988noreply@blogger.com1tag:blogger.com,1999:blog-9161883088729562959.post-83731124406489876562015-08-30T03:21:00.003+08:002015-08-31T14:08:37.484+08:00地圖龜日記<br />
2015/08/25:<br />
<br />
<br />
這是我房間所養的地圖龜<br />
地圖龜是一種澤龜(需長期在水中生活),所以就將他丟到一個半尺左右的魚缸中<br />
<br />
底砂是珊瑚砂<br />
也因為懶得換水和清理環境,就加掛了一個外掛式的濾水器<br />
幾個月下來水質滿乾淨的 (沒有換過水)<br />
<br />
另外因為另一個魚缸常常會有爆長的珍珠草,所以修剪剩下的草也會丟到這個烏龜缸中<br />
但也不知道是因為珍珠草,還是日照不足? 這缸目前也沒有看到任何澡類生長<br />
<br />
<br />
<a name='more'></a><br /><br />
上岸曬烏龜燈<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqPOVPFdkck0BoR5yuIw4WMTW_r16x1WMzkoGudQ3NN0lOrpFw4hzwq1ZHcmviTVEvGlOHF5wb6N45XV1lVCf2q_iY9S-jj3pe9wqv_DfJfY_aBxAHqObJA_Pm6kfnG6uB5GtCiKS7UkQg/s1600/IMG_2714.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em; text-align: center;"><img border="0" height="426" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqPOVPFdkck0BoR5yuIw4WMTW_r16x1WMzkoGudQ3NN0lOrpFw4hzwq1ZHcmviTVEvGlOHF5wb6N45XV1lVCf2q_iY9S-jj3pe9wqv_DfJfY_aBxAHqObJA_Pm6kfnG6uB5GtCiKS7UkQg/s640/IMG_2714.jpg" width="640" /></a><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSo5_fila1HjaT8RNqrkkL7_FxqwEGZnbRBmyB0wnxm9Zbdlowq4A0U1rroqD3yQayGTxAfxuG5JT_S3Omu1jytKvmFEkJm1t2MsM9oojfy9abiSsRGEccq8J7NseLiLqld9iGyv6xKnFM/s1600/IMG_2712.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="426" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSo5_fila1HjaT8RNqrkkL7_FxqwEGZnbRBmyB0wnxm9Zbdlowq4A0U1rroqD3yQayGTxAfxuG5JT_S3Omu1jytKvmFEkJm1t2MsM9oojfy9abiSsRGEccq8J7NseLiLqld9iGyv6xKnFM/s640/IMG_2712.jpg" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<br />
<br />
<br />
<br />
2015/08/15:<br />
上岸曬烏龜燈<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-9po2Dkj91YubgtV4meNNYAT2Ve42leiM_NX9VvUomwE2H4vflK_-AVVerzfCbEVt-BI0zzTekcvkpVaEwL2deaeS54nPbxA8ETYBU4upeNw2H-4uX-gHcix0yQggfnCFgJyyNm5cHen1/s1600/IMG_2603.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="465" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-9po2Dkj91YubgtV4meNNYAT2Ve42leiM_NX9VvUomwE2H4vflK_-AVVerzfCbEVt-BI0zzTekcvkpVaEwL2deaeS54nPbxA8ETYBU4upeNw2H-4uX-gHcix0yQggfnCFgJyyNm5cHen1/s640/IMG_2603.jpg" width="640" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
2015/07/24:<br />
地圖龜於水中游泳<br />
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjtTUyIRr-VLxblPp7yF2VbdSNu4SKoep4UVstQMr7Pb8t1EfiUiyrWc-rurR0HQt7MCX_JbVRgOsLp7rVnw-0cOfeOj_UfcfSX_fE0B2Ux4lCltu4x3DwPRDTl4xvyA_388yQV8JSt3V_v/s1600/IMG_2455.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="426" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjtTUyIRr-VLxblPp7yF2VbdSNu4SKoep4UVstQMr7Pb8t1EfiUiyrWc-rurR0HQt7MCX_JbVRgOsLp7rVnw-0cOfeOj_UfcfSX_fE0B2Ux4lCltu4x3DwPRDTl4xvyA_388yQV8JSt3V_v/s640/IMG_2455.jpg" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
2015/07/15:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgEt6FPyFKnBzo6zbsuL4wZCPzKWthMms02QanG4UkpLaec90zplK8fqvKbEcz4YpasRcLLzjcpwpIcq8gtxycsaQkuIxOrYmD4bOsab2Cnlovgnq4G_nIrzw_uAiEJ_8eMbKv46ZRI25bH/s1600/IMG_2232.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="426" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgEt6FPyFKnBzo6zbsuL4wZCPzKWthMms02QanG4UkpLaec90zplK8fqvKbEcz4YpasRcLLzjcpwpIcq8gtxycsaQkuIxOrYmD4bOsab2Cnlovgnq4G_nIrzw_uAiEJ_8eMbKv46ZRI25bH/s640/IMG_2232.jpg" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjOVAO5HmbwAhTQNJ6gl2QSH9jPCKtr5Kaw9D8AjKFx6WbvrTJkId0jaHX4tj-Z_RxajoVl24-sym0WO_aLLrHGOfnKwoLIway2aghspQM_qv1WOLyNR0Pmo5KLjRPEibp7cJBx-empPs8/s1600/IMG_2233.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="426" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjOVAO5HmbwAhTQNJ6gl2QSH9jPCKtr5Kaw9D8AjKFx6WbvrTJkId0jaHX4tj-Z_RxajoVl24-sym0WO_aLLrHGOfnKwoLIway2aghspQM_qv1WOLyNR0Pmo5KLjRPEibp7cJBx-empPs8/s640/IMG_2233.jpg" width="640" /></a></div>
<br />
<br />葉建胤http://www.blogger.com/profile/13939608302918631988noreply@blogger.com0tag:blogger.com,1999:blog-9161883088729562959.post-38084684243541668902015-08-27T02:40:00.005+08:002018-11-12T17:01:19.998+08:00Mac之簡單PHP教學入門(使用MAMP與Eclipse PDT)<br />
<br />
<br />
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
1. 至Eclipse官網下載PHP PDT (PHP Development Tools)版的Eclipse
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<a href="https://eclipse.org/pdt/">https://eclipse.org/pdt/</a></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
2. 下載MAMP,這邊用的是Free版
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<a href="https://www.mamp.info/en/">https://www.mamp.info/</a></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
3. 解壓縮Eclipse (沒有裝過JRE的可能在這時候會需要安裝)
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
4. 安裝MAMP
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
5. MAMP裝好後,在Mac的Launchpad就會看到MAMP和MAMP Pro,使用MAMP就好
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
開啟後還會再問一次,一樣選MAMP就好
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
(因為這邊只是練習和測試,所以使用只有本機連線功能的MAMP就好)
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br />
<a name='more'></a><br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
6. MAMP開啟來後就可以起動Server了
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgW4KDCa0FL2484AQfXptmMk2RqJPUAG7FqFIFCn45XC-rys_g4fcwBLh2D-ZS0fca6nZPhFrmgA0eeVotkDu6Dl0NvTppXHVBjcyiXpP_-qJUXMIeWyv06UGOlpL1p9KcIGZa_5kS6anz9/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2015-08-05+%25E4%25B8%258A%25E5%258D%258812.45.06.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="301" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgW4KDCa0FL2484AQfXptmMk2RqJPUAG7FqFIFCn45XC-rys_g4fcwBLh2D-ZS0fca6nZPhFrmgA0eeVotkDu6Dl0NvTppXHVBjcyiXpP_-qJUXMIeWyv06UGOlpL1p9KcIGZa_5kS6anz9/s400/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2015-08-05+%25E4%25B8%258A%25E5%258D%258812.45.06.png" width="400" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
進入偏好設定看一下我們的Port是多少,可以看到MAMP的Apache Port預設是8888 </div>
<div class="separator" style="clear: both; text-align: left;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjv_j9D5UkJKHi4_3FnNB_yQA5wyje9foM_9AhQhn2GSAPIDW3KoiCIlzn1gZoRNGl4mNTc63cGqL1bgrKUsYcIa7uDNtxoHy2x5cD7kWnPcLOtYag8fTb_p07VrIsqgzvA3y-YGCKWyBUz/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2015-08-05+%25E4%25B8%258A%25E5%258D%258812.45.32.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="302" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjv_j9D5UkJKHi4_3FnNB_yQA5wyje9foM_9AhQhn2GSAPIDW3KoiCIlzn1gZoRNGl4mNTc63cGqL1bgrKUsYcIa7uDNtxoHy2x5cD7kWnPcLOtYag8fTb_p07VrIsqgzvA3y-YGCKWyBUz/s400/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2015-08-05+%25E4%25B8%258A%25E5%258D%258812.45.32.png" width="400" /></a></div>
<br />
<br />
<br />
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
7. 打開劉覽器,輸入 http://localhost:8888/ 應該會看到東西
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
(可能是 Index of / 的純文字,有看到表示MAMP一切正常)
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
8. 一般來說MAMP的htdocs (類似Linux中的/var/www 等網頁根目綠) 位置會在
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
/Applications/MAMP/htdocs/
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
可以打開Terminal (終端機) 輸入:
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
open /Applications/MAMP/htdocs/
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
就會打開這個地方
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
9. 打開Eclipse PDT
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
建立workspace,然後要知道你位置在那邊,例如我的是
</div>
<!--?xml version="1.0" encoding="UTF-8" standalone="no"?-->
<br />
<div>
<span style="-evernote-highlight: true; background-color: #fffaa5;">/Users/seachaos/Documents/workspace</span></div>
<div class="separator" style="clear: both; text-align: left;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieqy-Yq40qTYc_MN2uXwOM8548lKDbyR5DLN8Ws_gCUZf_DodycEudejTegpgj467byv1_7n0F1dW7sg4lvQUEvFLPvAq9iVXfhaDduXlN4ySQ9UKKOkXKsuN-iSPeouSaAn8k2pw4JKsg/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2015-08-05+%25E4%25B8%258A%25E5%258D%258812.52.02.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="162" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieqy-Yq40qTYc_MN2uXwOM8548lKDbyR5DLN8Ws_gCUZf_DodycEudejTegpgj467byv1_7n0F1dW7sg4lvQUEvFLPvAq9iVXfhaDduXlN4ySQ9UKKOkXKsuN-iSPeouSaAn8k2pw4JKsg/s400/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2015-08-05+%25E4%25B8%258A%25E5%258D%258812.52.02.png" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<!--?xml version="1.0" encoding="UTF-8" standalone="no"?-->
10. 建立第一個PHP專案</div>
<br />
<div class="separator" style="clear: both; text-align: left;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4_ZrVCNEC1Wb4HU8GpYV6WQ1oiMPHVFdEyvZSWkNstA2BQRk7dhx64zToS9wAgi8eLGMe0JmTS_fctsf-CUPcCjx56ItOd5dBeSvueyFeO0-7O52WcSPJj4v45qmIMBlSlfTG1xDpEEm6/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2015-08-05+%25E4%25B8%258A%25E5%258D%258812.52.59.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="196" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4_ZrVCNEC1Wb4HU8GpYV6WQ1oiMPHVFdEyvZSWkNstA2BQRk7dhx64zToS9wAgi8eLGMe0JmTS_fctsf-CUPcCjx56ItOd5dBeSvueyFeO0-7O52WcSPJj4v45qmIMBlSlfTG1xDpEEm6/s400/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2015-08-05+%25E4%25B8%258A%25E5%258D%258812.52.59.png" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
取專案名稱,例如 testone<br />
<br />
<!--?xml version="1.0" encoding="UTF-8" standalone="no"?-->
<br />
<div class="separator" style="clear: both; text-align: left;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEizKBomZx0SKkeBfaprldhDoY80UnMWyj0cQnB0GGxUgOO1BVI-K3tgAYXupE0_6V_qWuf0DRpr4j7XAbDHP1oOrBWREPzS42uMSXLBqXAUqLH9FfiSsvZZemmeCSaMmediBQ8fEEV7dk2e/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2015-08-05+%25E4%25B8%258A%25E5%258D%258812.54.47.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEizKBomZx0SKkeBfaprldhDoY80UnMWyj0cQnB0GGxUgOO1BVI-K3tgAYXupE0_6V_qWuf0DRpr4j7XAbDHP1oOrBWREPzS42uMSXLBqXAUqLH9FfiSsvZZemmeCSaMmediBQ8fEEV7dk2e/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2015-08-05+%25E4%25B8%258A%25E5%258D%258812.54.47.png" width="537" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<!--?xml version="1.0" encoding="UTF-8" standalone="no"?-->
11. 開好後開始建立第一隻PHP程式</div>
<br />
<div class="separator" style="clear: both; text-align: left;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4ZhyZlLnzGKs1obflovOqYu8j0ZrRV9a0JUM53rofqtRdNVfnRVSj-ZnX2aQDUv69B-_v9HBHJZi16IxXEyXzOtE4hPlAgNhbP2SmLHSmDZQLNBae0GJX4OXmpdNNo00LqlM8eMFXL6wl/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2015-08-05+%25E4%25B8%258A%25E5%258D%258812.55.41.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="280" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4ZhyZlLnzGKs1obflovOqYu8j0ZrRV9a0JUM53rofqtRdNVfnRVSj-ZnX2aQDUv69B-_v9HBHJZi16IxXEyXzOtE4hPlAgNhbP2SmLHSmDZQLNBae0GJX4OXmpdNNo00LqlM8eMFXL6wl/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2015-08-05+%25E4%25B8%258A%25E5%258D%258812.55.41.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
檔名就叫 index.php
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
然後輸入:
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<table style="-evernote-table: true; border-collapse: collapse; font-family: 'Helvetica Neue'; font-size: 14px; margin-left: 0px; table-layout: fixed; width: 100%;">
<tbody>
<tr><td style="border-color: rgb(219,219,219); border-style: solid; border-width: 1px; margin: 0px; padding: 10px; width: 100%;"><div>
<span style="color: #ff2600; font: 11.0px Monaco;"><?php</span><span style="font: 11.0px Monaco;"><br />$value =</span> <span style="color: #0326cc; font: 11.0px Monaco;">"Good"</span><span style="font: 11.0px Monaco;">;</span>
</div>
<div>
<span style="color: #931a68; font: 11.0px Monaco;">echo</span> <span style="color: #0326cc; font: 11.0px Monaco;">"My First PHP:"</span><span style="font: 11.0px Monaco;">.$value;</span>
</div>
</td>
</tr>
</tbody></table>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
12. 再來就是讓網頁可以在瀏覽器中看見
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
再打開Terminal,我們用連結方式讓MAMP可以跑到Eclipse的Workspace中
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
輸入:
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<table style="-evernote-table: true; border-collapse: collapse; font-family: 'Helvetica Neue'; font-size: 14px; margin-left: 0px; table-layout: fixed; width: 100%;">
<tbody>
<tr><td style="border-color: rgb(219,219,219); border-style: solid; border-width: 1px; margin: 0px; padding: 10px; width: 100%;"><div>
ln -s <span style="-evernote-highlight: true; background-color: #fffaa5;">[你的Workspace路徑]</span> /Applications/MAMP/htdocs/pdt
</div>
</td>
</tr>
</tbody></table>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
例如:
</div>
<table style="-evernote-table: true; border-collapse: collapse; font-family: 'Helvetica Neue'; font-size: 14px; margin-left: 0px; table-layout: fixed; width: 100%;">
<tbody>
<tr><td style="border-color: rgb(219,219,219); border-style: solid; border-width: 1px; margin: 0px; padding: 10px; width: 100%;"><div>
ln -s <span style="-evernote-highlight: true; background-color: #fffaa5;">/Users/seachaos/Documents/workspace/</span> /Applications/MAMP/htdocs/pdt
</div>
</td>
</tr>
</tbody></table>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
再打開瀏覽器,輸入:
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
http://localhost:8888/pdt/[專案名稱]
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
例如:
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
http://localhost:8888/pdt/testone/
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
應該就會看到剛剛的網頁了
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<!--?xml version="1.0" encoding="UTF-8" standalone="no"?-->
<br />
<div>
</div>
<br />
<table style="-evernote-table: true; border-collapse: collapse; font-family: 'Helvetica Neue'; font-size: 14px; margin-left: 0px; table-layout: fixed; width: 100%;">
<tbody>
<tr><td style="border-color: rgb(219,219,219); border-style: solid; border-width: 1px; margin: 0px; padding: 10px; width: 100%;"><div>
<span style="-webkit-text-stroke-width: 0px; color: black; float: none; font-family: 'Heiti TC'; font-size: xx-small; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px;">My First PHP:Good</span></div>
</td>
</tr>
</tbody></table>
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<!--?xml version="1.0" encoding="UTF-8" standalone="no"?-->
<br />
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br />
<br /></div>
<script type="text/javascript" src="//js1.bloggerads.net/contentads.aspx?blogid=20150916000016" async></script>
葉建胤http://www.blogger.com/profile/13939608302918631988noreply@blogger.com0