What Is Software Design?

程式設計不是 “building software”,而是 “designing software”。

Is Design Dead?

軟體系統的設計是演進來的,不能一步到位,而是要藉由憑繁與使用者互動得到的回饋來修改系統設計。

Programming is Gardening, not Engineering

與其把程式設計比喻成蓋房子,實際上更像是園藝。

Orthogonality and the DRY Principle

所有程式設計活動其實都是維護,因為絕大部分的時間都在改code,寫一點改一點。即使是新專案,也很快需要回頭作修改。

顯示具有 phonegap 標籤的文章。 顯示所有文章
顯示具有 phonegap 標籤的文章。 顯示所有文章

2013年8月20日 星期二

Phonegap LocalNotification 本地推播 Android

step1.
請先請到以下的網址 下載 phonegap-plugins
https://github.com/phonegap/phonegap-plugins/tree/master/Android/LocalNotification

step2.
複製LocalNotification.js 到你的 www資料夾內
並且在index.html 中把他加入進去
<script type="text/javascript" charset="utf-8" src="js/LocalNotification.js"></script>

step3.
創造一個 package  命名為com.phonegap.plugin.localnotification

AlarmHelper
AlarmOptions
AlarmReceiver
AlarmRestoreOnBoot
LocalNotification
以上的java檔加入

step4.
AlarmReceiver 來修改錯誤
將R檔選擇到你自己目前的drawable.ic_launcher

final Notification notification = new Notification(R.drawable.ic_launcher, tickerText,
System.currentTimeMillis());


LocalNotification來修改錯誤
這已經是舊版的
//import com.phonegap.api.Plugin;
//import com.phonegap.api.PluginResult;
改為新版的
import org.apache.cordova.api.CordovaPlugin;

import org.apache.cordova.api.PluginResult;

還有alarm 這 改為以下的Code
alarm = new AlarmHelper(this.cordova.getActivity());

step5.

Update your res/xml/plugins.xml file
加入以下的code


<plugin name="LocalNotification" value="com.phonegap.plugin.localnotification.LocalNotification" />

step6.

 AndroidManifest.xml 檔案裡面 找出<application>標籤
加入以下的code


<receiver android:name="com.phonegap.plugin.localnotification.AlarmReceiver" >
</receiver>

<receiver android:name="com.phonegap.plugin.localnotification.AlarmRestoreOnBoot" >
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
    </intent-filter>
</receiver>

step7.
html 的使用方法

<!DOCTYPE html>

<html>
    <head>
        <meta charset="utf-8" />
        <meta name="format-detection" content="telephone=no" />
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
        <link rel="stylesheet" type="text/css" href="css/index.css" />
        <script type="text/javascript" src="cordova_2.9.js"></script>
        <script type="text/javascript" src="js/index.js"></script>
        <script type="text/javascript" charset="utf-8" src="js/LocalNotification.js"></script>
        <title>Hello World</title>

    <script type="text/javascript">
    document.addEventListener("deviceready", appReady, false);

    function appReady() {
        console.log("Device ready");
        if (typeof plugins !== "undefined") {
            plugins.localNotification
                    .add({
                        date : new Date(),
                        message : "Phonegap - Local Notification\r\nSubtitle comes after linebreak",
                        ticker : "This is a sample ticker text",
                        repeatDaily : false,
                        id : 4
                    });
        }
    }

    document.addEventListener("deviceready", appReady, false);
</script>

    </head>
    <body>


        <div class="app">
            <h1>Apache Cordova</h1>
            <div id="deviceready" class="blink">
                <p class="event listening">Connecting to Device</p>
                <p class="event received">Device is Ready</p>
            </div>
        </div>

         <script type="text/javascript">
             //app.initialize();
         </script>
    </body>

</html>