2015年12月20日 星期日

[Android] Deep link快速實作:連結你的APP

前言

使用Android手機時,常常會遇到當你點擊一個按鈕或連結(網頁連結...等)後,會跑出對話框詢問你要使用哪一種APP來開啟內容。
這項技術稱為Deep link。使用這一個技術的好處是可以讓你的APP與其他APP做互動。(Twitter,YouTube...等等都有使用)
特別是你所做的服務也包含WEB平台。這樣使用者用手機進入你的網頁瀏覽資料時,透過使用Deep link,當使用者點擊某個連結就可以啟動你的APP來做相關動作(例如展示相關資訊...等等)。
而這項機能的關鍵點就在於你的APP設定與觸發功能的按鈕或連結也要包含特定的內容。
參考: http://developer.android.com/training/app-indexing/deep-linking.html
這篇文章透過快速實作一個範例,來示範這項技術。

2015年12月14日 星期一

Android教學 - Android Studio範例運行並使用模擬器(GENYMOTION)


智慧手機逐漸佔領的生活中各個角落,想要學習與了解、甚至想做自己的APP的人我想應該不勝枚舉。
而我也是感受到它的魅力,兩、三年前自己一個人開始學習Android。
為了讓有興趣來學習Android的人,能夠輕易地認識它並且獲得製作APP的樂趣,
我想開始寫寫簡單的入門文章,希望對其他想接觸Android的人有些幫助。

本文重點:
1. Android Studio 簡介與範例
2. GENYMOTION手機模擬器的簡介。只要有它就可以直接在電腦上運行Android APP。

2015年12月2日 星期三

[Clip] Android SQLite實作方法與管理討論

Android SQLite實作方法與管理討論

APP新版本發布後,出現以下的錯誤報告。
android.database.sqlite.SQLiteDatabaseLockedException: database is locked (code 5):
似乎是SQLite部分有問題,因此對SQLite的實作與使用方式調查了一番,得到以下的結果。

http://stackoverflow.com/questions/8888530/is-it-ok-to-have-one-instance-of-sqliteopenhelper-shared-by-all-activities-in-an

有時間再來仔細探討一下。

2015年11月11日 星期三

[Android] AlertDialog使用方法筆記

[Android] AlertDialog使用方法筆記

前言


在開發Android APP時,AlertDialog是個簡單又常見的功能。但卻有些小地方需要注意,以避免程式出現非預期的動作或發生錯誤導致APP被強制終止。
在本篇筆記中,先簡單地介紹一個AlertDialog的製作方法,然後討論幾個常見的問題。

成果圖

2015年11月3日 星期二

[git] stash的使用筆記

[git] stash的使用筆記

git stash中常用的指令。
  • 儲存現在的作業狀態於stash列表
  • 列表顯示已儲存的stash紀錄
  • 從stash列表中取出作業紀錄,並將其復原於現在的作業上,復原後從stash列表中消除紀錄
  • 將指定stash列表的工作紀錄復原於現在的作業上,復原後stash列表中仍保留該紀錄
  • 從stash列表中消除指定紀錄
  • 清空stash列表中的紀錄

2015年10月29日 星期四

[PHP] 日期,時間計算-DateTime篇

[PHP] 日期,時間計算-DateTime篇

現在時間

$date = new DateTime();

輸出格式轉換

$date = new DateTime('2015-10-30 14:00:00');
時間格式為2015-10-30 14:00:00

echo $date->format('Y/m/d H:i:s');
根據Y/m/d H:i:s設定會輸出2015/10/30 14:00:00

日期變更與計算

$date = new DateTime('+7 days');
echo $date->format('Y-m-d H:i:s'); //現在時間+七天

$date = new DateTime('+7 days');
echo #date->format('Y-m-d H:i:s'); //現在時間-七天

$date = new DateTime('2015-10-01 12:00:00')
$date->modify('+7 days'));
echo  $date->format('Y-m-d H:i:s'); //2015-10-08 12:00:00


日期比較

$date1 = new DateTime('2015-10-01');
$date2 = new DateTime('2015-10-02');
var_dump($date1 < $date2); //true
var_dump($date1 > $date2); //false
var_dump($date1 == $date2); //false

$dateInterval = date1->diff($date2);
參考: [php.net] class.dateinterval
echo dateInterval->d; // output: 1

2015年10月27日 星期二

[Android] Toast使用筆記

[Android] Toast使用筆記


如何判斷Toast是否正在顯示。

可使用toast.getView().getWindowVisibility()來判斷。


if (toast == null || toast.getView().getWindowVisibility() == View.Visibility) {
 //Toast正在顯示
     ...
}

其他待續...

2015年10月25日 星期日

[git] remote操作筆記

[git] remote操作

remote repository clone(複製)

git remote clone <git url>

remote repository add(追加)

git remote add <name> <git url>
        name: 自己命名 


remote repository 列表顯示

git remote -v

變更在local repository中登錄的remote repository位址

git remote set-url <name> <git url>
       name: 已設定的名字 

變更在local repository中登錄的remote repository名稱

git remote rename <old name> <new name>

在local repository指定製作remote repository的某個branch

git branch <branchname> origin/<branch>
        or     git checkout <branch>
       

向remote repository提交local repository的變更內容

git push <repository> <branch>
        repository: 命名的repository名稱或是位址。省略的話,以追蹤的remote repository為對象
        branch: branch名稱。省略的話,以local, remote都存在的branch為反映對象

確認remote repository的變更內容

git fetch <repository> <branch>
        repository: 命名的repository名稱或是位址。省略的話,以追蹤的remote repository為對象
        branch: branch名稱。省略的話,全部branch為對象

向local repository反映(更新)remote repository的變更內容

git pull <repository> <branch>
        repository: 命名的repository名稱或是位址。省略的話,以追蹤的remote repository為對象
        branch: branch名稱。省略的話,全部branch為對象

刪除remote repository的某個branch

git push --delete <repository> <branch>

2015年10月23日 星期五

[Android] SlidingMenu使用筆記

[Android] SlidingMenu使用筆記

說明:

Sliding Menu在手機的應用程式中是相當常見的設計,除了以前提到的
Navigation Drawer作法之外,還可以使用本文所提的Sliding Menu(jfeinstein10)的第三方資源來達成。
該資源提供豐富設定供開發者來使用,甚至有左右兩方的選單可以設定。

成果:

2015年10月14日 星期三

[Google App Script] 如何用Google App Script製作簡易Web API

[Google App Script] 如何用Google App Script製作簡易Web API - GET API 

你可以學到:

★Google App Script(簡稱GAS)的使用。
★簡單Get Web API的製作方式與發佈。

2015年10月7日 星期三

2015年9月29日 星期二

[Android] TextView.getLineCount()の使用例

getLineCount() 永遠返回0 的問題



結論:

在TextView在畫面上尚未被建立出來的狀態下,getLineCount()會返回0。
Return the number of lines of text, or 0 if the internal Layout has not been built.(引用develop.android.com)

為了確保TextView在已建立完成的狀態中,使用View.post()是個可行的方法。
在post函數中,執行getLineCount()可以得到真正的行數值。

實際應用:

Android的TextView中設定文字時,如果高度heigth設定為wrap_content的話,當文字長度超出TextView的寬度(width)時,文字會自動執行換行以防止超出的文字無法顯示。

但下面的設計中,會有高度不一的情況出現。


這邊想要設計是當文字行數超過1行時,換到下一列表示。
因此,如果能偵測到TextView的文字行數的話(使用getLineCount())
,就可以判斷是否需要執行換行處理。

check function的內容大致如下:

成果:


Code(範例程式碼):