2015年8月28日 星期五

Youtube影片預覽圖

取得Youtube影片預覽圖

120px * 90px(4:3)
http://img.youtube.com/vi/<video-id>/default.jpg

320px * 180px(16:9,不會有黑邊)
http://img.youtube.com/vi/<video-id>/mqdefault.jpg

480px * 360px(4:3)
http://img.youtube.com/vi/<video-id>/hqdefault.jpg

640px * 480px(4:3)
http://img.youtube.com/vi/<video-id>/sddefault.jpg

1280px * 720px、1920px * 1080px(16:9,不會有黑邊)
http://img.youtube.com/vi/<video-id>/maxresdefault.jpg



※ref1:http://www.zoearthmoon.net/blog/program/item/404-youtube-thumbnail.html
※ref2:http://www.zhihu.com/question/22543683/answer/21721819

2015年2月25日 星期三

[Android] 整理筆記:有關Android裝置的定位

以使用者的角度來說明,會接觸到的定位總共有三種方式
我直接整理成表格,幫助大家快速理解


GPS及Wi-Fi定位並沒有哪個較好,而是在不同的狀況要使用不同的種類
這兩種也能夠相輔相成搭配著使用
​依照不同情境,可在在Android裝置中設定,「設定」->「定位」

1. 高精確度:使用GPS、Wi-Fi和行動網路判斷位置
    >> 需要精確定位可用此,例如導航
2. 節約耗電量:使用Wi-Fi和行動網路判斷位置
    >> 較GPS省電,但Wi-Fi要一直開啟(註1)平常在都市生活可用此就好
3. 僅限裝置:使用GPS判斷您的位置
    >> 不需網路即可定位,但耗電,到山上野外或海邊想看地圖的時候用此



================================================================================

*註1
Android_4.3增加了「為了使定位精準,即使Wi-Fi功能關閉,Google和其他應用程式可能會掃描附近的Wi-Fi網路」

意思是
在以前要用Wi-Fi定位時,必須要一直將Wi-Fi開啟,但現在關閉Wi-Fi後,仍然可以使用Wi-Fi定位
換句話說,即使將Wi-Fi關閉,不代表真正將Wi-Fi關閉,Wi-Fi仍會在背景運作輔助定位

若要真正將Wi-Fi關閉,則到「Wi-Fi」->「進階」->「一律執行掃描」,取消勾選

 







※整理筆記於

2015年2月22日 星期日

[Android][AndroidStudio] 修改自動排版(Reformat code)的規則

滿久沒有更新了
因為工作忙案子趕,即使覺得有不錯的東西或是需要記憶的東西
但沒有時間紀錄在blog

最近改到Android Studio開發,簡直不只是崩潰可以形容
雖然可以將快捷鍵改為原本Eclipse使用的
不過既然都已經換了,所以快捷鍵還是重新背Android Studi版的吧!

--

在Android Studio中要自動排版的快捷鍵是

  • (Win) CTRL + ALT + L
  • (Mac) OPTION + CMD + L

若要修改排版的規則則在
Preference->Code Style

附圖為,我修改了Java的空行部分
原有最大行數為2行,因為習慣的原因改為1行



2014年8月17日 星期日

[Android] 在調整ImageView寬高時保持原比例

今天遇到一個需求
圖片width需與parent相同,height要以等比例放大
於是先將ImageView設定成

<ImageView
    android:id="@+id/picture"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:src="@drwable/pic" >
</ImageView>

但發現他設的height是原圖的height
在width拉到與parent相同時,height並不會跟著改變
因此要在程式中設定

ImageView img = (ImageView) findViewById(R.id.picture);
img.setAdjustViewBounds(true);

這樣height才會動態的調整成,已拉成與parent相同width比例對應的height

2014年8月11日 星期一

[Android] 從keystore取得hash key

用Facebook等SDK
有時需要上傳自己的hash key作為debug用

在Eclispe->Preference->Android->Build可以看到自己的default debug keystore路徑
可使用keytool及openssl從debug keystore取得hash key

$ keytool -exportcert -alias androiddebugkey -keystore [debug.keystore] | openssl sha1 -binary | openssl base64


2014年6月20日 星期五

[Android] 開啟FB app的網址

用FB app開啟特定分頁的網址為

fb://profile/[id]

從普通網頁可尋找到FB專頁的id
若已經改成特殊帳號
可經由此網頁搜尋id
https://graph.facebook.com/[帳號]
在網頁中可尋找到此FB分頁的id


refs:http://im88.tw/?p=18981

--

150527_note:

fb://page/[id]
fb://profile/[id]

[Android] page顯示的包含粉絲團簡要說明、按贊數、置頂文、普通文章,profile顯示的僅有普通文章。
[iOS] page.不吃此網址,profile顯示的包含粉絲團簡要說明、按贊數、置頂文

2014年1月21日 星期二

[Shell] 執行script方式差異 (source, sh, 點, 點斜線)

父程序中執行
-> source及點(.)
子程序中執行
-> 點斜線(./)及sh

在子程序執行的各項變數及動作並不會回傳至父程序
因此像android build code前需initial環境設置
就必須執行
source build/envsetup.sh

. build/envsetup.sh


ref:http://linux.vbird.org/linux_basic/0340bashshell-scripts.php (script 的執行方式差異)

2013年11月20日 星期三

[C#] 將現有節點從一個文件複製到另一個文件;ImportNode

在C#中,建立xml要先建立XmlDocument,在裡面再建立XmlElement
若想要將其中的節點,複製到其他XmlDocument可不能直接放
需使用ImportNode複製到其他的XmlDocument

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;

namespace qntest1
{
    static class Program
    {
        /// 
        /// 應用程式的主要進入點。
        /// 
        [STAThread]
        static void Main()
        {
            //Application.EnableVisualStyles();
            //Application.SetCompatibleTextRenderingDefault(false);
            //Application.Run(new Form1());
            xml();
        }

        static void xml()
        {
            //建立時間放在檔名
            DateTime dt = DateTime.Now;
            string time = string.Format("{0:yyyyMMddHHmmssffff}", dt);

            //新增第一個xml檔
            XmlDocument doc = new XmlDocument();
            XmlDeclaration xmlDeclaration = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
            doc.AppendChild(xmlDeclaration);
            XmlElement rootElement = doc.CreateElement("Company1");
            doc.AppendChild(rootElement);

            //新增資料
            XmlElement childElement = doc.CreateElement("Employee");
            XmlAttribute childAtrbt = doc.CreateAttribute("Department");
            childAtrbt.Value = "研發部";
            childElement.Attributes.Append(childAtrbt);
            rootElement.AppendChild(childElement);

            doc.Save(@"C:\Users\user\Desktop\test\" + "test_" + time + ".xml");

            //////////////////////////////////////////////////////////////////////////////////////

            //新增第二個xml檔
            XmlDocument doc2 = new XmlDocument();
            XmlDeclaration xmlDeclaration2 = doc2.CreateXmlDeclaration("1.0", "UTF-8", null);
            doc2.AppendChild(xmlDeclaration2);

            XmlElement rootElement2 = doc2.CreateElement("Company2");
            doc2.AppendChild(rootElement2);

            //將第一個xml檔最後的節點複製到第二個xml檔
            XmlNode newNode = doc2.ImportNode(doc.DocumentElement.LastChild, true);
            doc2.DocumentElement.AppendChild(newNode);

            doc2.Save(@"C:\Users\user\Desktop\test\" + "test.copy_" + time + ".xml");
        }
    }
}


test_201311201933485572.xml
   
- 
       
  

test.copy_201311201933485572.xml
   
- 
       
  

[git][cygwin] git config

Git的設定有三種層級,分別是
1. /etc/gitconfig:系統,適用所有使用者及所有repositories;git config --system [command]
2. ~/.gitconfig:使用者,適用於該使用者;git config --global [command]
3. repositories/.git/config:repositories,適用於該repositories;git config [command]

一般用第二個,給自己的帳戶使用

/home/user/.gitonfig
[user]
        name = user
        email = user@email.com
[color]
        diff = auto
        status = auto
        branch = auto
        ui = auto 
[core]
        editor = nano
        autocrlf = false

[user] name, email:name為使用git commit會儲存的name及email
[color] 如果有需要可以填
[core] editor:編輯器若沒有指定會使用系統預設的,通常是vi或vim
[core] autocrlf:在不同作業系統(ex: Windows, Linux)換行字元會不同,若設定true,它會自動切換換行字元(crlf, lf)。
在Windows我使用cygwin,作為使用git的工具,為了避免換行字元會因為不同作業系統而改變,因此我設為false,依照codebase原有的換行字元


※ ref1:http://git-scm.com/book/en/Getting-Started-First-Time-Git-Setup
※ ref2:http://huan-lin.blogspot.com/2011/05/git-coreautocrlf.html

[Linux] 在目錄之下搜尋文件檔名及文件內關鍵字

在目錄之下,搜尋文件檔名
$ find -iname "[file_name]"
EX: $ fine iname "*.txt"

在目錄之下,搜尋文件關鍵字
$ grep -rin "[keyword]" .
EX: $ grep -rin "HelloWord()" .

2013年11月13日 星期三

[Linux] Ubuntu 12.04的下載來源

若是預設的下載來源會讓平時apt-get install下載時找不到檔案
那麼可以將下載來源換成以下
修改/etc/apt/source.list
#deb cdrom:[Ubuntu 12.04.1 LTS _Precise Pangolin_ - Release amd64 (20120823.1)]/ dists/precise/main/binary-i386/

#deb cdrom:[Ubuntu 12.04.1 LTS _Precise Pangolin_ - Release amd64 (20120823.1)]/ dists/precise/restricted/binary-i386/
#deb cdrom:[Ubuntu 12.04.1 LTS _Precise Pangolin_ - Release amd64 (20120823.1)]/ precise main restricted

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://tw.archive.ubuntu.com/ubuntu/ precise main restricted
deb-src http://tw.archive.ubuntu.com/ubuntu/ precise main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://tw.archive.ubuntu.com/ubuntu/ precise-updates main restricted
deb-src http://tw.archive.ubuntu.com/ubuntu/ precise-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://tw.archive.ubuntu.com/ubuntu/ precise universe
deb-src http://tw.archive.ubuntu.com/ubuntu/ precise universe
deb http://tw.archive.ubuntu.com/ubuntu/ precise-updates universe
deb-src http://tw.archive.ubuntu.com/ubuntu/ precise-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu 
## team, and may not be under a free licence. Please satisfy yourself as to 
## your rights to use the software. Also, please note that software in 
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://tw.archive.ubuntu.com/ubuntu/ precise multiverse
deb-src http://tw.archive.ubuntu.com/ubuntu/ precise multiverse
deb http://tw.archive.ubuntu.com/ubuntu/ precise-updates multiverse
deb-src http://tw.archive.ubuntu.com/ubuntu/ precise-updates multiverse

## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://tw.archive.ubuntu.com/ubuntu/ precise-backports main restricted universe multiverse
deb-src http://tw.archive.ubuntu.com/ubuntu/ precise-backports main restricted universe multiverse

deb http://security.ubuntu.com/ubuntu precise-security main restricted
deb-src http://security.ubuntu.com/ubuntu precise-security main restricted
deb http://security.ubuntu.com/ubuntu precise-security universe
deb-src http://security.ubuntu.com/ubuntu precise-security universe
deb http://security.ubuntu.com/ubuntu precise-security multiverse
deb-src http://security.ubuntu.com/ubuntu precise-security multiverse

## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu precise partner
# deb-src http://archive.canonical.com/ubuntu precise partner

## This software is not part of Ubuntu, but is offered by third-party
## developers who want to ship their latest software.
deb http://extras.ubuntu.com/ubuntu precise main
deb-src http://extras.ubuntu.com/ubuntu precise main


2013年11月1日 星期五

[Android][Example] 用SoundPool控制左右聲道

如果需要控制左右聲道的音量,SoundPool有提供這個功能
SoundPool的優點是可以同時撥好幾個音檔
但卻對音檔的大小有限制
因此只適合撥較短的音檔

以下範例UI會有左右聲道的播放及停止按鈕





activity_main.xml


    

        

        

    

        

        



MainActivity.java
package com.qn.leftrightsound;

import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class MainActivity extends Activity {
    private String TAG = "leftrightsound";
    private SoundPool soundPool;
    private Button button_left_play, button_left_pause, button_right_play, button_right_pause;
    private int music_left, music_right;
    private int music_left_temp, music_right_temp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        soundPool = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);
        music_left = soundPool.load(this, R.raw.left_sound, 1);
        music_right = soundPool.load(this, R.raw.right_sound, 1);
        // 音樂檔案放在res/raw底下,預設沒有raw資料夾,要自己建

        button_left_play = (Button) findViewById(R.id.button_left_play);
        button_left_pause = (Button) findViewById(R.id.button_left_pause);
        button_right_play = (Button) findViewById(R.id.button_right_play);
        button_right_pause = (Button) findViewById(R.id.button_right_pause);

        button_left_play.setOnClickListener(ButtonListner);
        button_left_pause.setOnClickListener(ButtonListner);
        button_right_play.setOnClickListener(ButtonListner);
        button_right_pause.setOnClickListener(ButtonListner);
    }

    private Button.OnClickListener ButtonListner = new Button.OnClickListener() {

        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.button_left_play:
                Log.i(TAG, "press left play");
                music_left_temp = soundPool.play(music_left, 1, 1, 0, 0, 1);
                // 由於每次播放的id會不同,為考慮到按下暫停是要暫停剛剛播放的,因此將每次播放的id存起來
                // play()
                // 第一參數為音檔id
                // 第二.三參數為左右聲道的音量,range = 0.0 to 1.0
                // 第四參數為優先權,若不需設定可都設為0,0為最小優先權
                // 第五參數為loop,0 = no loop, -1 = loop forever
                // 第六參數為速度,1.0 = normal playback, range 0.5 to 2.0
                break;
            case R.id.button_left_pause:
                Log.i(TAG, "press left pause");
                soundPool.stop(music_left_temp);
                 break;
            case R.id.button_right_play:
                Log.i(TAG, "press right play");
                music_right_temp = soundPool.play(music_right, 0, 1, 0, 0, 1);
                break;
            case R.id.button_right_pause:
                Log.i(TAG, "press right pause");
                soundPool.stop(music_right_temp);
                break;
            }
        }
    };

    @Override
    protected void onDestroy() {
        this.soundPool.release();
         super.onPause();
    }

}

2013年10月21日 星期一

[Batch] call的用法,call與goto的差別

call可用在執行其他batch檔
也可以執行寫好的function(在batch稱為label)

Ex1:
ECHO CALL example1
CALL test1.bat

Ex2:
ECHO CALL example2
CALL :test2

:test2
ECHO This is test2


goto也可以執行寫好的function
但call與goto兩者最大差別為
call跳到label後,執行完label中的程式碼,會跳回call之後的程式碼
但goto跳到label後,並不會跳回來

此外
call後面可接傳入function的參數

Ex3:
ECHO CALL example3
CALL :test3 100

:test3
ECHO This is test3
ECHO %1%



refs: http://ccd9527.blogspot.tw/2010/11/bat-call-06.html

2013年10月4日 星期五

[Linux] 製作patch;打patch

1. 製作patch
使用linux的diff指令,diff舊檔案及新檔案的差別,並輸出成.patch
$ diff -Naur [old_file] [new_file] > [patch_name].patch

2. 打patch
使用linux的patch指令,將patch內容更新舊檔案
$ patch -p0 < [patch_name].patch
將檔案復原
$ patch -R -p0 < [patch_name].patch

2013年10月3日 星期四

[Linux] 計算資料夾或檔案大小

計算資料夾或檔案大小
後面可以接資料夾或檔案,否則則為當下資料夾
$ du -h

[Android] 檢查apk sign的key

與sign key一樣使用java的指令 -- jarsigner

$ jarsigner -verify -verbose -certs [apk_name]

會列出來像是以下的資訊
sm      3512 Mon Apr 15 00:13:32 CST 2013 AndroidManifest.xml

      X.509, CN=Android Debug, O=Android, C=US
      [certificate is valid from 2013/4/14 下午 3:10 to 2043/4/7 下午 3:10]

sm      5937 Sun Apr 14 15:09:46 CST 2013 res/drawable-xhdpi/ic_launcher.png

      X.509, CN=Android Debug, O=Android, C=US
      [certificate is valid from 2013/4/14 下午 3:10 to 2043/4/7 下午 3:10]

如果用Android test key sign過的apk結果會長這樣
sm      3875 Wed Apr 16 07:40:50 CST 2008 res/drawable-hdpi/rbt_icon.png

      X.509, EMAILADDRESS=android@android.com, CN=Android, OU=Android, O=Android, L=Mountain View, ST=California, C=US
      [certificate is valid from 2008/4/16 上午 6:40 to 2035/9/2 上午 6:40]

sm      1765 Wed Apr 16 07:40:50 CST 2008 res/drawable-ldpi/rbt_icon.png

      X.509, EMAILADDRESS=android@android.com, CN=Android, OU=Android, O=Android, L=Mountain View, ST=California, C=US
      [certificate is valid from 2008/4/16 上午 6:40 to 2035/9/2 上午 6:40]

可以藉此得知apk是用哪一把key sign的

refs:http://www.cnblogs.com/not-code/archive/2011/05/15/2047057.html

2013年9月23日 星期一

2013年9月13日 星期五

[Gerrit][Git] 新增/刪除Branch

1). 在local端新增branch並切換

1.1). 新增branch,再切換到該branch
$ git branch [branch_name]
$ git checkout [branch_name]

1.2). 新增branch並直接切換到該branch
$ git checkout -b [branch_name]

1.2). 以某個tag為基準,新增branch並直接切換到該branch
$ git checkout [tag_name] -b [branch_name]


2). 在remote端新增branch
$ git push origin [local_branch_name]:[remote_branch_name]

3). 在local端刪除branch (-D為強制)
$ git branch -d [branch_name]
$ git branch -D [branch_name]

4). 在remote端刪除branch
$ git push origin :[branch_name]

※在Gerrit要刪除remote端的branch
在push的權限中,必須增加force push才能夠刪除

※新增branch
git branch [branch_name] [base_on_which_branch]
若是[base_on_which_branch]沒有寫,預設是master
若是此git沒有master branch,則後面沒寫會無法新增branch

2013年9月4日 星期三

[Gerrit] [Git] [Repo] 新增/刪除tag

1). 在local端新增tag
$ git tag -a [tag_name] [commit_id]

2). 在remote端新增tag
$ git push origin [tag_name]
$ git push origin --tag (一次將所有tag push上去)

3). 在local端刪除tag
 $ git tag -d [tag_name]

4). 在remote端刪除tag
$ git push origin :refs/tags/[tag_name]

//======================================

9/4新增repo的部份
在repo codebase之下的用法

1). 在local端新增tag
$ repo forall -c 'git tag [tag_name]'

2). 在remote端新增tag
$ repo forall -c 'git push --tags'

3). 在local端刪除tag
$ repo forall -c 'git tag -d [tag_name]'

4). 在remote端刪除tag(需取得gerrit權限,目前沒嘗試過)
$ repo forall -c 'git push origin :refs/tags/[tag_name]'

[Gerrit] 在Gerrit網頁上加客製化修改

Gerrit網頁上方有能夠讓使用者客製化的區域
可藉由修改html檔,加上想要客製化的內容
請在放置gerrit的目錄底下的etc中增加GerritSiteHeader.html檔案
/home/gerrit/review_site/etc/GerritSiteHeader.html

內容請用<pre></pre>夾起來
example:
<pre>
Hello
World
</pre>

區域為底下圖片底色紅色的部份