2015年3月31日 星期二

[Android] how to check edittext's text is email address or not? (轉貼)

reference: http://stackoverflow.com/questions/6119722/how-to-check-edittexts-text-is-email-address-or-not

/** 
 * method is used for checking valid email id format. 
 *  
 * @param email 
 * @return boolean true for valid false for invalid 
 */ 
public static boolean isEmailValid(String email) {
    boolean isValid = false;
 
    String expression = "^[\\w\\.-]+@([\\w\\-]+\\.)+[A-Z]{2,4}$";
    CharSequence inputStr = email;
 
    Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(inputStr);
    if (matcher.matches()) {
        isValid = true;
    } 
    return isValid;
} 

[Android] show messages

Type 1:

 AlertDialog.Builder builder;
 builder = new AlertDialog.Builder(context);
 
 String msgTitle="Success";
 String msgBody="Please go to your email to get your password.";
  
 builder.setMessage(msgBody)
    .setTitle(msgTitle);
 AlertDialog dialog = builder.create();
 dialog.show();

dismiss listener:
reference: http://stackoverflow.com/questions/17544819/how-to-know-if-a-dialog-is-dismissed-in-android
public Dialog createDialog() {
    Dialog d = new Dialog(this);
    d.setOnDismissListener(new OnDismissListener() {
        @Override 
        public void onDismiss(final DialogInterface arg0) {
            // do something 
        } 
    }); 
    return d;
} 

Type 2: 

 Toast.makeText(getApplicationContext(),"The field of e-mail is empty.", Toast.LENGTH_SHORT).show();

2015年3月26日 星期四

[Virtual Box] 讓 Windows 與「VirtualBox 裡的 Ubuntu 系統」共用「分享資料夾」(轉貼)

轉貼來源: http://briian.com/6241/virtualbox-share-folder.html


一、選擇「分享資料夾」

第1步  依序按下VirtualBox軟體的〔裝置〕→【分享資料夾...】,準備設定一個新的分享資料夾。
01

第2步  開啟「分享資料夾」視窗後,請按一下右上角的「+」按鈕,新增一個分享資料夾。
02
第3步  我們可以直接在「Folder Path:」輸入主電腦的資料夾路徑,如「C:\」,或從下拉選單去點選你要分享的資料夾。「Folder Name」請輸入這個分享資料夾的名稱,如「share01」,這名稱會在稍後的步驟中使用到,請注意名稱的英文大小寫不要寫錯。
03

第4步  設定好分享資料夾後,請再按〔OK〕按鈕完成設定。我們可以在視窗中看到目前有多少個分享資料夾,如果有其他需求也可以繼續按〔+〕新增其他資料夾。另外,如果你希望該資料夾只能讀取不可寫入,也可在上面一個步驟勾選「Read-only」,如果你希望主電腦的Windows跟虛擬電腦的Ubuntu系統都可寫入資料、儲存檔案的話,就不要勾選。
04
第5步  先建立data資料夾於桌面,請在終端機視窗中輸入以下指令,再按下〔Enter〕:  
  • 指令:sudo mount -t vboxsf  分享資料夾名稱   掛載路徑
  • 範例:sudo mount -t vboxsf share01 /home/brian/桌面/data
sudo」指的是使用管理員的權限來執行右側指令,按下〔Enter〕後會要你輸入管理員帳號密碼,確認你有權限管理或修改系統設定。指令中的「share01」指的是本文第一段第3步驟「分享資料夾」的名稱,右邊的「/home/brian/桌面/data」則是新磁碟的掛載目的地,也就是前面第二步驟在Ubuntu桌面所新增的資料夾。
08 
注意!資料夾或路徑名稱的英文大小寫視為不同文字,如果資料夾設定為「DATA」,執行的指令卻寫成「data」的話,也會造成掛載失敗。

第6步  如圖,執行完上述的掛載磁碟指令後,我們只要按兩下桌面的「data」資料夾,便可從虛擬電腦中的Ubuntu系統看到主電腦Windows系統裡的檔案與資料夾囉。
09

2015年3月25日 星期三

[Virtual Box] VirtualBox 4.3安裝Ubuntu 14.04(轉貼)

VirtualBox 快捷鍵指令
holt鍵就是右邊的Ctrl鍵,快捷鍵就是右邊的Ctrl+F鍵切换到全螢幕模式,右邊的Ctrl+L鍵切換到無邊模式,右邊的Ctrl+C鍵切換到比例模式,菜單顯示是按右邊的Ctrl+Home鍵。

VirtualBox 4.3安裝Ubuntu 14.04(二)

調整Ubuntu 14.04 screen size 
Ubuntu 安裝 VirtualBox Guest Addition

[Virtual Box] Enlarge a Virtual Disk in VirtualBox (轉貼)

Enlarge a Virtual Disk in VirtualBox


Resize a VirtualBox guest Linux VDI Disk under Windows Host


2015年3月24日 星期二

[Android] Most popular screen sizes/resolutions on Android phones (轉貼)


來源:http://stackoverflow.com/questions/6272384/most-popular-screen-sizes-resolutions-on-android-phones

First of all, I understand that Android's developer site provides information on this topic. I have already read the following three pages:
They do not give the information/statistics that I am looking for. Judging from the second link, the two most important screen categories to support are normal-hdpi and normal-mdpi.
The problem is that simply knowing that these two categories are the most popular is of no help to me. The website gives me a range of screen sizes and densities that go into these categories, but the ranges are quite large.
I want to know what the most popular phones are in these two categories. More specifically, I am looking for the most popular resolutions in these two categories. Where can I find such information?
shareedit

up vote40down voteaccepted
You can see the resolutions for those categories in the Table 2, in this section:http://developer.android.com/guide/practices/screens_support.html#testing
shareedit

[Android] vlc android compile ubuntu14


1.環境:

主機:Windows 7(64bit)

虛擬機:VirtualBox-Version 4.3.12 Edition

虛擬機系統:ubuntu-14.04-desktop-amd64

環境需求:
在Linux系统上,我安裝的是Ubuntu14.04
===============================================
2. 需要安裝的工具:
apache-ant (or ant), autoconf, automake, autopoint, cmake, gawk (or nawk), gcc, g++, libtool, git,
m4, patch, pkg-config, ragel, subversion, unzip.

ps: 如果是編訪Android-x86設備,需安裝 yasm

開始安裝:
安裝第一個套件:ant, 執行安裝指令# sudo apt-get install ant, 得到結果是,一些網路上位址的檔案無法取得,這時可以下# sudo apt-get update 或是加上--fix-missing 去更新連結位址。(如下圖一)
圖一

更新完下載位址,重新執行 sudo apt-get install ant,便可取得完整的路徑,並可順利安裝,如圖二、三、四。
圖二

圖三
圖四
其它檔案,如 autoconf, automake, autopoint, cmake, gawk (or nawk), gcc, g++, libtool, git,
m4, patch, pkg-config, ragel, subversion, unzip.,依此類推。

protobuf-2.4.1:
https://pixhawk.ethz.ch/installation/ubuntu
=====================================================

3.Android SDK

The Android SDK archive initially contains only the basic SDK tools. It does
not contain an Android platform or any third-party libraries. In fact, it
doesn't even have all the tools you need to develop an application.

In order to start developing applications, you must install the Platform-tools
and at least one version of the Android platform, using the SDK Manager.

Platform-tools contains build tools that are periodically updated to support new
features in the Android platform (which is why they are separate from basic
SDK tools), including adb, dexdump, and others.

To install Platform-tools, Android platforms and other add-ons, you must
have an Internet connection, so if you plan to use the SDK while
offline, please make sure to download the necessary components while online.

To start the SDK Manager, please execute the program "android".

From the command-line you can also directly trigger an update by
executing:

在android-sdk-linux目錄下執行
#  tools/android update sdk --no-ui

Tip: use --help to see the various command-line options.

problem:
Android adb not found
http://stackoverflow.com/questions/13571145/android-adb-not-found

================================================
4.Android NDK
get android ndk from http://developer.android.com/tools/sdk/ndk/index.html

use 7-zip to Decompress the file of android-ndk-r10d-linux-x86_64.bin

檔案解壓縮可下載7-zip

=====================================================
5.配置NDK、SDK、JDK環境變量:

1)终端root帳戶命令:

# sudo gedit ~/.bashrc

待彈出頁面在相面末尾加入下列幾行(具体目錄依自已定義):

export NDK=/home/ken/develop/android-ndk-r10d
export ANDROID_SDK=/home/ken/develop/android-sdk-linux
export ANDROID_NDK=/home/ken/develop/android-ndk-r10d
export ANDROID_ABI=armeabi-v7a
export NO_NEON=1
export JAVA_HOME=/home/ken/jdk/jdk1.8.0_40
export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export PATH=$PATH:$ANDROID_SDK/tools:$ANDROID_SDK/platform-tools:$JAVA_HOME/bin:$JAVA_HOME/jre/bin

2)然後保存,使其生效 终端命令行:

# source ~/.bashrc

3)檢測環境變數配置是否正確:

ndk可以進入ndk下sample目录里的hello-jni进行$NDK/ndk-build 命令編譯。JDK可以在root终端命令下(非root需要在編輯~/.bashrc)執行:java -version 如果顯示JDK相關的

版本號則為安装正確。

來源: http://www.cnblogs.com/wainiwann/p/3849387.html
===================================================
6.編譯

git clone git://git.videolan.org/vlc-ports/android.git  =>time out
http://stackoverflow.com/questions/19808059/unable-to-run-git-clone-from-git-videolan-org

執行 # sh ./compile.sh

問題1、You must define ANDROID_NDK, ANDROID_SDK and ANDROID_ABI before starting
     ANDROID_ABI should match your ABI: armeabi-v7a, armeabi or …
解決方式:執行# source ~/.bashrc

來源: http://blog.csdn.net/cleanness/article/details/21086965


問題2.
autoreconf: running: autopoint --force
autopoint: *** The AM_GNU_GETTEXT_VERSION declaration in your configure.ac
               file requires the infrastructure from gettext-0.19.3 but this version
               is older. Please upgrade to gettext-0.19.3 or newer.
autopoint: *** Stop.
autoreconf: autopoint failed with exit status: 1
make: *** [.gpg-error] Error 1
contribs: make failed

$ gettext --version
gettext (GNU gettext-runtime) 0.18.3
http://stackoverflow.com/questions/30259182/build-vlc-for-android-project-failed-on-ubuntu-12-04

Unable to run git clone from git.videolan.orghttp://www.videolan.org/vlc/download-sources.html






2015年3月19日 星期四

[IOS] 相關連結


Furnace iOS 程式設計中文學習網站: Auto Layout-

[IOS] Cocoa iOS App 的 Life Cycle 及通知 Controller 目前 App 的狀態 (轉貼)

來源: http://kelp.phate.org/2012/01/cocoa-ios-app-life-cycle-controller-app.html

☆ 最近發現 GitHub 實在太強大了,真的是一個能取代 Blog 的服務,未來大概只會更新到 GitHub 上。
https://github.com/kelp404

2012-01-25


Cocoa iOS App 的 Life Cycle 及通知 Controller 目前 App 的狀態

在開發 iOS App 的時候如果專案選擇 View Application 時 Xcode 會幫我們完成圖形化介面的相關程式,所以一執行就會看到程式的畫面。
在 main.m 中有這樣一段程式用來初始化圖形介面:
1
2
3
4
5
6
int main(int argc, char *argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([ProjectAppDelegate class]));
    }
}
啟動之後接下來都交由 ProjectAppDelegate(ProjectAppDelegate.m) 來掌控程式的執行,當使用者按下 Home 扭讓程式進入背景狀態或是把程式從背景叫回來...等 ProjectAppDelegate 都會收到對應的事件。
官方說明文件 - UIApplicationDelegate Protocol Reference

didFinishLaunchingWithOptions
此事件只會產生一次,在程式第一次被執行的時候
1
2
3
4
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    return YES;
}

applicationDidBecomeActive
發生於 didFinishLaunchingWithOptions 之後,從背景叫回來時也會產生
1
2
3
4
- (void)applicationDidBecomeActive:(UIApplication *)application
{
}

applicationWillResignActive
發生於程式要進入背景狀態前,這時候可能要做儲存狀態、暫停遊戲...等,因為使用者有可能會結束程式
1
2
3
4
- (void)applicationWillResignActive:(UIApplication *)application
{
}

applicationDidEnterBackground
發生於程式進入背景狀態後
1
2
3
4
- (void)applicationDidEnterBackground:(UIApplication *)application
{
}

applicationWillEnterForeground
發生於程式從背景狀態被叫回時,事件結束後會產生 applicationDidBecomeActive
1
2
3
4
- (void)applicationWillEnterForeground:(UIApplication *)application
{
}


這些事件的程式都放在 ProjectAppDelegate.m 中,如果說發生這些事件後 Controller 要執行對應的程式時遇到的第一個問題就是我該怎麼在 ProjectAppDelegate.m 呼叫 Controller 的函數。
這個問題可以透過 Notification Center 機制來解決,Notification Center 是程式中共用的訊息通知中心,一個程式只會有一個,所以我們可以在 ProjectAppDelegate.m 中的事件塞入通知,而在 Controller 中攔截這個通知並執行對應的程式。

首先要在 Controller 中設定攔截通知的程式
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
- (void)viewDidLoad
{
    [super viewDidLoad];
    
    //設定通知對應的函數
    [[NSNotificationCenter defaultCenter] addObserver: self
                                             selector: @selector(notificationHandle:)
                                                 name: @"MainControllerNotificationHandle"
                                               object: nil];
}
- (void)viewDidUnload
{
    [super viewDidUnload];
    //移除通知對應函數
    [[NSNotificationCenter defaultCenter] removeObserver: self];
}
//當 MainControllerNotificationHandle 通知發生時會執行此函數
- (void) notificationHandle: (NSNotification*) sender;
{
    NSLog(@"-notificationHandle");
}

在 ProjectAppDelegate.m 中加入傳送通知的程式,這邊放在 applicationDidBecomeActive 中,也就是程式執行、從背景叫回來時會產生訊息
1
2
3
4
5
- (void)applicationDidBecomeActive:(UIApplication *)application
{
    NSLog(@"%@", @"applicationDidBecomeActive");
    [[NSNotificationCenter defaultCenter] postNotificationName: @"MainControllerNotificationHandle" object: @"DidBecomeActive"];
}

這樣一來 Controller 就能執行對應的程式