2014年5月21日 星期三

CI: Jenkins Introduction

The purpose of the article is let you know what Jenkins for Windows is. Jenkins is an open source continuous integration tool written in Java. The project was forked from Hudson after a dispute with Oracle.

Jenkins provides continuous integration services for software development. It is a server-based system running in a servlet container such as Apache Tomcat. It supports SCM tools including AccuRev, CVS, Subversion, Git, Mercurial, Perforce, Clearcase and RTC, and can execute Apache Ant and Apache Maven based projects as well as arbitrary shell scripts and Windows batch commands.

Work flow likes the following diagram, and they are divided to some stages: 
1.Coding and push into Git remote repository

2.Jenkins gets source code from Git, and runs static analysis, such as lint check, FindBugs, CheckStyle...etc.
3.Run Unit Test or Mokey Test
4.Build Apk
5.Deploy

References - Jenkins: https://jenkins-ci.org/

2014年4月16日 星期三

Tool: Online Tools about UML or Wireframe

The following tools is I think it better, and I wanna recommend. You can try to use them if having needs on your job.

1.UML:http://www.techrepublic.com/pictures/five-free-apps-for-creating-diagrams-in-your-browser/10/
a. ASCII Flow
b. Creately
c. Draw.IO
d. Gliffy
e. yUML

2.wireframe:http://www.sitepoint.com/5-free-wireframe-applications/
a. Moqups.com
b. Lumzy.com
c. Gliffy.com
d. Lovely Charts (web)
e. Google Drive Drawings

2014年3月2日 星期日

OO: UML的基本名詞與關聯

在一些論壇或是討論版,總覺得有些人對於物件導向的以下名詞容易搞混,尤其當看到有人講Delegation是一種模式時,是非常奇妙的事情。這邊整理成一張圖,以及關係的排序(圖中的數字)。另外,圖片中有每種關係在UML的呈現,也附上一個Abstract Facotry(抽象工廠)模式的類別圖,以供比對關聯。

  1. Generalization(一般化): 一個繼承關係,由下往上看時則是一般化。如何記一般化?當把所有子類別提取共同屬性與方法時,這時父類別是大家共同擁有的,既然共同擁有,當然比較一般囉!
  2. Specialization(特殊化): 一個繼承關係,由上往下看時則是特殊化。如何記特殊化?當把父類別產生出不同子類別時,每個子類別都是特別的物件,當然就是特殊囉!
  3. Inheritance(繼承): 在Java程式中使用Extends關鍵字,關係最強,因為父類別的所有,子類別皆該括承受。
  4. Realization(實現) and Implementation(實作|實現): 在Java程式中使用Implements關鍵字,而UML泛指抽象化,包含抽象類別與介面。
  5. Composition(組成): 可以想像成某物件的專屬物件,在Java實作中則是Inner class的概念。
  6. Aggregation(聚合): Whole-Part的概念,也就是產品和零件的關係,泛指通用零件。
  7. Association(關聯): 在UML分為相互關聯與可導覽的關聯,前者是雙方皆知道彼此存在,後者只有一方知道。
  8. Dependency(依賴): 關係最弱的一種,在程式實作中,通常以回傳值或是方法中參數的形式存在。
  9. Delegation(委派): 並非為設計模式,只是物件導向程式中的一種關係或是實作方法。可以想像成一個物件,將部分功能委由另一個物件來做,則是Delegation的概念。
  10. Design pattern(設計模式): 一種程式設計的經驗,根據四人幫一書中的定義,一個Pattern基本具有四個特徵:名稱、問題、解決方案與成效。

2013年11月15日 星期五

Android: Implementing Flurry for Android

1. Flurry Mechanism
The following diagram is a work flow from applying for an API key to implementing a GCM client. The following contents are going to describe the both steps. These steps are divided into two parts, Basic setup and Understanding user behavior through tracking custom events.




1.1. Basic Setup
A. Download the Flurry Android SDK
Open the URL, and then create an account as well as download Flurry SDK.
B. Add the Flurry lib to your project
Add FlurryAgent.jar to your android project
C. Configure your AndroidManifest.xml, as the following diagram.
D. Add calls to onStartSession and onEndSession. The highlighted section is the API Key you applied on Flurry web site, as the following diagram.
1.2. Understanding user behavior through tracking custom events
If you want to understand this part, you can see the document flurry offered through the flurry website.
1.3. Testing result
The first diagram is a result of successfully creating a project named MyFlurryTest and its’ testing result. In addition, the others are the final result on the dashboard of the flurry; however, the red highlight section on the dashboard of the furry is a relative to the event your source code set.


Android: Implementing GCM Server for Android Test

1. Implementing GCM Server
So far the above contents have installed necessary libraries, register our account to the Google Cloud Console, and complete our client side. In this section, we need to create a simple application server with PHP language.

A. Create Table in your database
This application server receives the registration id from the application, stores it in the database and sends the message to the application using GCM connection server. To store the registration id, create a simple MySQL table using following query, as the following diagram.




B. Create a register.php file
When android application runs for first time, it registers the application to the GCM using sender ID (i.e. project ID mentioned above) and gets the registration Id. The application then sends the registration ID to the application server to store in the database. Here is the PHP file register.php which does the above mentioned task i.e. it receives the registration id and stores it in the database. If you want to see the most complete source code, you can refer to sample code about the GCM server.

D. Create a index.php file
If you want to send the message to the application then you write a message and fetch all the registration ids from the database. You then send the registration ids along with the message to the GCM server. The GCM servers gives the response back to the application server. index.php file does the above mentioned task i.e. it sends the message to the application and echo back the response from the GCM server. By the way, you should replace the API Key you appled, as the following diagram. If you want to see the most complete source code, you can refer to sample code about the GCM server.



2.Test result
First, we launched an emulator from Android Virtual Device Manager, and pressed the button named “Register Device” in Figure 9; meanwhile, the system will show a Toast message.


After registration to the server side, your registration id from the client side will be record in the database, as the following diagram.


To open index.php file through your web browser delivers a message, as the following diagram.


Finally, you can see the message from the server side in your emulator, as the following diagram.


3.References
A. GCM: https://developer.android.com/google/gcm/index.html

2013年11月14日 星期四

Android: Implementing GCM Client for Android

If you have no any idea about the topic, you can try to study this article - Introduction for GCM and Flurry.

1. Implementation Steps
The session is divided into two parts, GCM Mechanism for Android as well as Flurry Mechanism. There are two types on Implementation steps for GCM. The first method is deprecated by Google. The other way is the newest implementation method.

1.1. GCM Mechanism for Android
In the beginning, the session will introduce one thing about implementing GCM mechanism. It is the newest way using “google_play_service lib” project. Another way is an older method which Google has not suggested, but it will not be launched in the document. By the way, both ways are the same on applying for an API key, and only implementing GCM Client is different. The following diagram is a work flow from applying for an API key to implementing a GCM client. The following contents are going to describe the both steps.


1.1.1. Applying for an API Key
  • A. Creating a Google API project
    •  Open the Google Developers Console.
    •  If you haven't created an API project yet, click Create Project.
    •  Supply a project name and click Create.
    •  Copy down your project number.
    •  In the sidebar on the left, select APIs & auth.
    •  In the displayed list of APIs, turn the Google Cloud Messaging for Android toggle to ON.
  • B. Obtaining an API Key
    •  In the sidebar on the left, select APIs & auth > Credentials.
    •  Under Public API access, click Create new key.
    •  In the Create a new key dialog, click Server key.
    •  In the refreshed page, copy the API key. You will need the API key later on to perform authentication in your application server.
  • C. Set Up Google Play Services SDK
    •  Set Up a Project that Uses Google Play Services
    •  Using Eclipse or another IDE:
    •  Setting up “google-play-services_lib” Project

1.1.2. Implementing GCM Client
  • A. Edit Your Application's Manifest
    •  You should add the following contents into the Manifest in Android project, as the following diagram.




  • B. Create a simple layout
    • This layout is a simple view which shows a general bottom used to register device to server. Once we register device success, the button will be disabled, as the following diagram.



  • C. Create a GcmBroadcastReceiver.java
    • The GcmBroadcastReceiver needs to extend the WakefulBroadcastReceiver class. A WakefulBroadcastReceiver is a special type of broadcast receiver that takes care of creating and managing a partial wake lock for your app. It passes off the work of processing the GCM message to a Service (typically an IntentService), while ensuring that the device does not go back to sleep in the transition. If you don't hold a wake lock while transitioning the work to a service, you are effectively allowing the device to go back to sleep before the work completes. The net result is that the app might not finish processing the GCM message until some arbitrary point in the future, which is not what you want. If you want to know how to implement this class, you can refer to the sample code.
  • D. Create a GcmIntentService.java
    • The intent service does the actual work of handling the GCM message. When the service is finished, it calls GcmBroadcastReceiver.completeWakefulIntent() to release the wake lock. The completeWakefulIntent() method has as its parameter the same intent that was passed in from the WakefulBroadcastReceiver. If you want to know how to implement this class, you can refer to the sample code.
  • E. Create a RegisterApp.java
    • This class should extend AsyncTask class. We need to complete some important tasks within the class. You should send the registration ID to your server over HTTP, so it can use GCM/HTTP or CCS to send messages to your app. The request to your server should be authenticated if your app is using accounts. You need to pay attention to some things about how to correctly finish these tasks. Setting your “Sender ID” and “URL” in this file is the most principal thing, as the following diagram.


2. References








2013年11月13日 星期三

Android: Introduction for GCM and Flurry

1. Purpose
The purpose of the article is about how to implement Google Cloud Messaging (GCM) for Android, a mechanism for passing messages between clients/devices and servers, and Flurry mechanism, an analytic tool which can help developers or data scientists collect data from mobile devices, such as Iphone, Android or Windows phone, as well as assist those to parse data as available information and analyze them to improve effects on E-Commerce (EC).
1.1. Google Cloud Messaging for Android
Google Cloud Messaging for Android (GCM) is a service that allows you to send data from your server to your users' Android-powered device, and also to receive messages from devices on the same connection. The GCM service handles all aspects of queueing of messages and delivery to the target Android application running on the target device. GCM is completely free no matter how big your messaging needs are, and there are no quotas.
1.2. Flurry for Android
The "Analytics Service" means, collectively, the "Software", the "Analytics Reports" and the "Documentation", all as defined below in this Agreement. Under this Agreement, Flurry may allow you to access the Analytics Service by using Flurry's analytics site code (the “Agent”) and any fixes, updates and upgrades provided to you, provided that you have an active Flurry account. In addition, Flurry may provide you with on-line access to a variety of analytics reports (the " Analytics Reports") generated by Flurry's processing code and any fixes, updates and upgrades. The Agent and Flurry's processing code are defined collectively herein as "Software". The processing code analyzes the data collected by the Agent. This data concerns the characteristics and activities of end users of your applications.