2018年11月1日 星期四

添加adb功能 on mac


如果沒有.bash_profile

則 touch .bash_profile

之後


vim .bash_profile

新增


#Android adb

export PATH=${PATH}:~/Library/Android/sdk/platform-tools

重啟command line

備註:當Android studio update後,發生問題

1.刪除Android studio全部資料
rm -Rf /Applications/Android\ Studio.app
rm -Rf ~/Library/Preferences/AndroidStudio*
rm ~/Library/Preferences/com.google.android.studio.plist
rm -Rf ~/Library/Application\ Support/AndroidStudio*
rm -Rf ~/Library/Logs/AndroidStudio*
rm -Rf ~/Library/Caches/AndroidStudio*



2.配置



















3.preferences設定

Font=> size 18,Line spacing 1.2
Editor -> General -> Auto Import -> add unambiguous imports on the fly
Editor -> General -> Auto Import -> optimize imports on the fly

2018年10月31日 星期三

Android Callback、Handler 差別


Callback

因為Android 常使用other thread做資料處理的動作(background deal,not UI thread),所以當訊息處理完,時常需要回覆給UI thread處理完畢(但這時候回覆訊息到UI thread的部分,還是other thread負責,所以不能直接更新UI),所以這時候就有callback機制。

專案簡單說明:

1.MainActivity new 一個DownLoadService 準備要下載東西,但我需要一個回應說DownLoadService下載好了。

2.使用interface 做出一個OnDownLoadListener,給MainActivity實作出來方法。

3.MainActivity使用setOnDownLoadListener,將MainActivity實作出來的OnDownLoadListener,給downLoadService。


4.這時候downLoadService可以下載東西,下載完之後使用onDownLoadListener.onComplete("String")回應給mainActivity實作的方法,就可以達到不同trhead但可以異步訊息傳送。

注:加上Looper.prepare() and Looper.loop()

是因為toast.show要有一個Looper把taost(本身用到UI thread)傳遞給message queue,讓handler抓message(toast)出來處理。
而一個new thread沒有Looper,所以要Looper.prepare(),給他一個new looper,之後讓他loop.loop給他插入toast進入 message queue。

github:https://github.com/TakmingMark/PracticeCallback


Handler

主要是當處理完畢的資料,需要和UI講,講完之後就可以更新資料(Handler處理是在UI同一線程,所以可以更新UI)

github:https://github.com/TakmingMark/PracticeHandler

合起來使用的話,來講一下使用情況。

callback就像一個員工A,他要一直處理照片傳輸的問題。

handler就像一個員工B,他要監控員工A,當員工A把照片傳輸做完時,回傳一個訊息給員工B,然後員工B告訴老闆(UI update)說照片傳輸完畢

github:https://github.com/TakmingMark/CallbackAndHandler


參考文章:
https://blog.csdn.net/ErLiangCode/article/details/52117831
http://andy02172001.blogspot.com/2017/10/androidinterfacecall-back.html
https://blog.csdn.net/ErLiangCode/article/details/52117831

2018年10月8日 星期一

對於git一些常用指令紀錄



git reset —mixed 默認值,回歸某標籤,標籤以後檔案依舊會留存在Working directory,但更改內容不在staged Area裡面,要從新add and commit

git reset —hard  回歸某標籤,標籤以後檔案不會留存在Working directory,直接拋棄某標籤以後的修改。

git reset —soft 回歸某標籤,介於mixedhard間操作,標籤以後檔案依舊會留存在Working directory,更改內容也在staged Area裡面,不用從新add,但要commit


git reset [ae3034d] 指定標籤回歸,檔案依舊會留存在Working directory,但不在staged Area裡面,要從新add and commit

git reset [current~2] 當前往前數兩個回歸,檔案依舊會留存在Working directory,但不在staged Area裡面,要從新add and commit


git commit —amend  不會產生新的commit,會依照之前的commit來添加檔案內容,和可修改commit message內容
more fileName 得知檔案內容

git log —oneline 打印 history of commit ,並一個commit 印出一行資訊

git checkout -b [branchName] 創建一個分支,並轉換過去

git branch [branchName] 創建一個分支,不會轉換過去

git branch -a 看全部的分支

git checkout [branchName] 轉換分支

git branch 得知此分支名稱

git branch -D [branchName]刪除某分支

more [fileName] 印出檔案內容

more .git/config 觀看此專案的資訊

git remote -v 顯示遠端服務器的名稱

git diff [branchName] 用此分支和其他分支比較檔案差別。

git merge [branchName] 結合某分支

git fetch [origin] [branchName]獲取遠端服務器某分支的版本 

git merge FETCH_HEAD 本地使用fetch之後,用這個指令才能同步

git pull  直接一次性解決fetch and merge的問題,但通常不推薦,通常一步一步來,先fetch然後diff來了解是否merge

origin 代表服務器的名稱

git [instruction] -h 查看某指令使用方法

git push origin —delete [branchName]刪除遠端的分支

git branch -m [branchName] 更改分支名稱

git tag -l 目前標籤名稱列

git fetch -t 抓取遠端的標籤

git push —tag 本地標籤傳入遠端

git tag -d [tagName] 刪除某本地標籤

git push origin :refs/tags/[tagName] 刪除遠端標籤

git remote add [remoteName] [remoteLink] 增加一個遠端

產生push遠端不需要一直輸入帳號密碼

step1:ssh-keygen 生成public and private key in /root/.ssh/

step2:GitHub->settings->SSH and GPG keys 把本地電腦id_rsa_pub複製貼過去

step3:vim .git/config 如果使用後還是需要帳號密碼,代表我們走的是https,要更改成ssh(github上複製過來)

額外補充:ssh-copy-id -i /root/.ssh/id_rsa.pub [account]@[IP] 如果對方是linux電腦,可以使用此方法傳遞public key


平行別人專案步驟

step1:git remote add upstream GitHub@IP

step2:git fetch upstream

step3:git merge upstream/master

step4:git push origin master


2018年9月25日 星期二

change terminal color for mac的方法


依照這個網址來做
https://medium.freecodecamp.org/jazz-up-your-bash-terminal-a-step-by-step-guide-with-pictures-80267554cb22


中間會遇到python utf-8的問題
修改:https://coderwall.com/p/-k_93g/mac-os-x-valueerror-unknown-locale-utf-8-in-python

找尋特定檔案位置
https://www.macx.cn/thread-2080254-1-1.html

python路徑
https://blog.csdn.net/a542551042/article/details/47149959

editor on mac
http://www.sublimetext.com/

2018年4月9日 星期一

Re:还在用JSON? Google Protocol Buffers 更快更小 (原理篇)

看了這篇
https://mp.weixin.qq.com/s?__biz=MzUyNzMwMTAwNw==&mid=2247483736&idx=1&sn=247c204880bde06eda8b77fd14e4d93a&chksm=fa00e1b8cd7768aee094020746eda244b26f2bb78332e8c68257f80d7966ed1ba82ed23dfe23&scene=21#wechat_redirect

順便學習了一些程式編碼問題與複習(雖然這篇後段完全看不懂...)

首先先看這篇,先了解原碼、反碼、補碼
http://www.cnblogs.com/en-heng/p/5570609.html

然後 裡面有計算ZigZag

根據int 編碼h(n) = (n << 1) ^ (n >> 31)

依照範例 數值 1,-1來練習

if n=1;

original code=0,0000000000,0000000000,0000000000,1

n<<1= 0,0000000000,0000000000,0000000001,0
n>>31= 0,0000000000,0000000000,0000000000,0

(n << 1) ^ (n >> 31)
^ => 0,0=0 1,0=1 0,1=1 1,1=0

so =  0,0000000000,0000000000,0000000001,0

Decimal=2
---------------------------------------------------------------  
if n=-1;

original code=1,0000000000,0000000000,0000000000,1
反碼=1,1111111111,1111111111,1111111111,0
補碼=1,1111111111,1111111111,1111111111,1
 
n<<1= 1,1111111111,1111111111,1111111111,0
n>>31= 1,1111111111,1111111111,1111111111,1

(n << 1) ^ (n >> 31)
^ => 0,0=0 1,0=1 0,1=1 1,1=0

so =  0,0000000000,0000000000,0000000000,1

Decimal=1

2018年3月8日 星期四

轉傳:用 ConstraintLayout 解決鍵盤擋住輸入框及按鈕

https://medium.com/joe-tsai/%E7%94%A8-constraintlayout-%E8%A7%A3%E6%B1%BA%E9%8D%B5%E7%9B%A4%E6%93%8B%E4%BD%8F%E8%BC%B8%E5%85%A5%E6%A1%86%E5%8F%8A%E6%8C%89%E9%88%95-642fe2a9b855

這個方法太棒了,想在這做個紀錄

2018年2月25日 星期日

關於eclipse主題顏色

我依照這篇更改我的eclipse主題,讓白色主題換成黑色
https://samkuo.me/post/2013/10/eclipse-dark-theme/

但有可能系統不一樣或者是版本差異,我選了Dark Juno,Color Theme則選擇RecognEyes

然後有時候變更主題他不會儲存
我會先依照這個更改
https://github.com/eclipse-color-theme/eclipse-color-theme/issues/223

在依照這個
https://stackoverflow.com/questions/30145776/eclipse-color-theme-reverts-to-default-every-time-i-exit

就成功了

2018年2月1日 星期四

重灌電腦加系統複製

因為我灌了一整天,想說紀錄一整天的經驗

1.別用Acronis True Image WD,我弄了一個下午重開機,都沒跑進去系統複製,結果換了一個軟體力馬就行,我用的是MiniTool Partition Wizard Free

複製教學:http://blog.xuite.net/yh96301/blog/394356641-MiniTool+Partition+Wizard+Free+9.1%E8%A4%87%E8%A3%BDWindows+10

然後如果有不要的硬碟要格式化,如果在[我的電腦] 按右鍵 [管理] -> [磁碟管理] 可以格式化,但如果有系統硬碟的話,要用cmd指令

教學:https://www.techbang.com/posts/6982-a-to-delete-a-stubborn-stick-ji-efi-partition-yang-liwei