2015年6月4日 星期四

Android: Custom Dialogs: Factory Method Sample

在較為注重UI與產品整體風格是否一致的應用程式中,客製化的元件是無可避免的事情,由於我們公司的美術都會設計獨特的Dialog,所以外觀常有不同種類,如Diagram 1 - 4所示:

Diagram 1.
dialogFactory04

Diagram 2.
dialogFactory05

Diagram 3.
dialogFactory06

Diagram 4.
dialogFactory07

在過去的案子中,我會採用DialogFragment來製作,並且在每個DialogFragment內各自新增一個create方法,再透過一個Util類別產生,所以類別圖會變成以下樣子,如Diagram 5:

Diagram 5.
dialogFactory01

覺得這樣的方式並不方便,加上每當新增一個Dialog時,Dialog除了要增加一個create方法外,Util類別也要跟著新增,所以就改用Factory Method的方式重構,只要透過實體化欲產生的Dialog工廠時,就可以依據該工廠生成想要的Dialog,Factory Method和重構後的類別圖如Diagram 6和Diagram 7:

Diagram 6.
dialogFactory02

Diagram 7.
dialogFactory03

Sample Code: [CustomDialogFactoryMethodSampleCode](https://github.com/xavier0507/CustomDialogFactoryMethodSample.git)

2015年4月9日 星期四

Android: How to record the operation of an app via ADB tool

There are many people wanna record the operation of an application, but they don't want to download additional applications or root their mobile to cause many system problems. This article teachs you how to record the operation via ADB tool.

1.You need to download Android SDK and unzip it to the folder you assign. (for example: D:\Software\Android SDK)

2.You can find out ADB tool within the folder named "platform-tools", as the following figure.

record01

3.Confirm the Settings of your mobile, and open Developer options as well as check "USB debugging" option. 4.Connect your device, and intput "adb devices" to check status through command line, as the following figure. Your device will be attached if the step is success. (Note: You shoulde navigate the path named "platform-tools" if you have never set environment variables on your PC.)

adb devices

record02

5.Input the following command. You should assign the path of SD Card if wantting to save your vedio into the SD card.

adb shell screenrecord {the path you wanna save}

For example:

adb shell screenrecord /sdcard/my_app_video.mp4

6.Start to record and execute the operation on your mobile.

7.Pull your video into your PC through the following instructions, as the following diagram.

adb pull {the path you wanna save}

For example:

adb pull /sdcard/my_app_video.mp4

record03

8.Check your file from the folder you assigned, as the following figure.

record04

9.Open your vedio, as the following vedio.