2019年2月17日 星期日

Using firebase google email login for Android

首先,你創好一個專案,在Menu選擇Tools-> firebase -> 跟著tutorial 步驟,就能順利完成以下動作

=>簡單Sign up, Sign in 程式碼
=>Import 一些external libs
=>在Firebase 開了一個專案,名稱是你的專案名稱


------------------------------------------------------------------------------------------------------------------------

再來需要在Firebase上做一些更改

=>Google email 開啟

通常這時候,應該是 可以正常登入的,但!! 如果你修改了package name,你就會大亂 登入不進去了,接下來會一步一步的更改內容
------------------------------------------------------------------------------------------------------------------------


1.得到SHA-1

利用這網址的步驟,可以得到這台電腦的SHA-1
https://stackoverflow.com/questions/27609442/how-to-get-the-sha-1-fingerprint-certificate-in-android-studio-for-debug-mode

2.更改Firebase auth的登入權限,和替換google-service.json
點選->project->Authenticaiton->Sign-in methed->google,會得到下面視窗,然後點選Project Settings,會開啟一個新的視窗


下面有一個Your apps,請點選Add app (如果是之前舊的APP 就直接刪掉,然後新增)

下面有四個步驟

1. Fill in info
Package name => 你專案新的 package name
App nickname =>我隨便打
Debug signing certificate SHA-1=>把剛剛拿到SHA-1貼上去
 Register app

2.Download config file
替換你專案的google-services => 在project -> app 資料夾

3. Add firebase SDK
如果是新的專案,就需要新增,只是換package name 原本你就做完了
4. Run
確認是否正常運作,他會告訴你成不成功


Reference:

https://dotblogs.com.tw/starhao/2016/11/12/160526  =>有些是舊的,已經用不到
https://console.cloud.google.com/apis => Firebase 會自動幫你新增到Credentials 通常用不到
https://blog.yorkxin.org/2013/09/30/oauth2-1-introduction.html => 介紹為什麼要用到Oauth2

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/