騰訊筆試+查漏補缺


1
int main() 2 { 3 // 動態規劃問題之 --- 在所給出的錢裏面湊夠i元最少須要多少個硬幣 或 張數? 4 // 狀態和狀態轉移方程 5 // d(i)=j來表示湊夠i元最少須要j個硬幣 6 int a[3] = {1,3,5}; // 表明 每次可取的錢的個數 7 int sum = 11; // 表明 目標要湊夠的錢數 8 int d[12]; // 表明 表示湊夠最少須要的硬幣個數 9 d[0] = 0; 10 //咱們假設存在1元的硬幣那麼i元最多隻須要i枚1元硬幣,固然最好設置dp[i]等於無窮大 11 for(int i = 1; i <= sum; i++) 12 d[i] = i; // 表明着最多的次數,由於由一塊一塊湊起來的,確定是最多 13 14 for(int i = 1; i <= sum; i++){ // 湊到 11 塊,從 1 開始循環,逐漸到 11 塊的狀況,得出結果 15 for(int j = 0; j < 3; j++){// 第一次可能拿到的錢的面值的可能次數 16 // dp[i - a[j]] , i - a[j] 表明當前的錢減去第一次拿到的這塊剩下的錢 17 // dp[剩下的] , 就表明着 湊夠 剩下的錢,至少須要的硬幣數目 18 if(i >= a[j] && d[i - a[j]] + 1 < d[i]){
// i >= a[j] ,表明當前的錢的值,a[j] 表明當前取到的面值,例如給出的 1 3 5,若是面值 > 當前循環到要湊的總數,就不知足了,因此要加這個限制
19 // dp[i - a[j]] + 1 表明着, 可以湊夠剩下的錢的硬幣數 + 第一次拿到的次數,老是一次,由於題目求的是硬幣的個數 20 // < dp[i],因爲 dp[i] 在上面的逐次的循環中都是表明了最小的硬幣數,因此若是 dp[剩下的] + 1 < dp[i] 21 // 那麼下面就能夠從新賦值, 新的最小的次數,進入下一輪循環 22 d[i] = d[i- a[j] ] + 1; 23 } 24 // 下面的代碼片斷等同於上面的片斷,能夠看出,若是要求最多的硬幣數,咱們只須要改變 > 和 max 25 if(i >= a[j]){ 26 d[i] = min(d[i - a[j]] + 1,d[i]); 27 } 28 } 29 } 30 cout<<d[sum]<<endl; 31 return 0; 32 }
------------------------
Android 本地祕鑰加密
http://drakeet.me/android-security-guide/
------------------------
Loopring
但目前考慮到ETH的成熟和普及程度,因此選擇ETH做爲第一個開發區塊鏈平臺。然而路印協議並非爲ETH量身定作的,它能夠在知足條件的多條異構區塊鏈上得以實施。後續考慮在EOS,ETC,量子鏈,Hyperledger(若是支持ERC20),及ChinaLedger社區版上進行開發。
------------------------
geth 命令比較好的一些文章:
http://www.yaozihao.cn/2017/07/07/geth%E5%91%BD%E4%BB%A4%E9%80%89%E9%A1%B9%E4%BB%8B%E7%BB%8D/
https://blog.csdn.net/weixin_40144050/article/details/79260598
geth --testnet 啓動 以太坊測試鏈
geth --dev 啓動 以太坊開發測試鏈
geth 自動同步以太坊公網
eth.blockNumber結果爲0 解析
https://blog.csdn.net/wo541075754/article/details/78075643?locationNum=10&fps=1
eth.Syncing 解析
https://my.oschina.net/u/3782027/blog/1811152

以太坊 geth 固然命令在 json_rpc 中的體現
https://www.cnblogs.com/liujitao79/p/8441247.html
------------------------
區塊鏈技術性教程文章:https://blog.csdn.net/sportshark/article/details/52249607
-----------------------
虛擬貨幣的免費數據獲取 第三方 API 接口文檔。
能夠獲取常見的市值多少,多少錢一個,周小時,七天的漲幅等
https://coinmarketcap.com/zh/api/
-----------------------
RPC 類 API,如何使用傳統 RSET API 的 GET / POST
https://blog.csdn.net/fjscqjj1/article/details/79279226
-----------------------
非對稱加密中,公鑰 和 私鑰都是能夠用來加密和解密的。
公鑰 加密 私鑰 解密,這個過程咱們習慣稱爲加密
私鑰 加密 公鑰 解密,這個過程咱們習慣稱爲---簽名

1、公鑰加密
假設一下,我找了兩個數字,一個是1,一個是2。我喜歡2這個數字,就保留起來,不告訴大家(私鑰),而後我告訴你們,1是個人公鑰。

我有一個文件,不能讓別人看,我就用1加密了。別人找到了這個文件,可是他不知道2就是解密的私鑰啊,因此他解不開,只有我能夠用
數字2,就是個人私鑰,來解密。這樣我就能夠保護數據了。

個人好朋友x用個人公鑰1加密了字符a,加密後成了b,放在網上。別人偷到了這個文件,可是別人解不開,由於別人不知道2就是個人私鑰,
只有我才能解密,解密後就獲得a。這樣,咱們就能夠傳送加密的數據了。

2、私鑰簽名
若是我用私鑰加密一段數據(固然只有我能夠用私鑰加密,由於只有我知道2是個人私鑰),結果全部的人都看到個人內容了,由於他們都知
道個人公鑰是1,那麼這種加密有什麼用處呢?

可是個人好朋友x說有人冒充我給他發信。怎麼辦呢?我把我要發的信,內容是c,用個人私鑰2,加密,加密後的內容是d,發給x,再告訴他
解密看是否是c。他用個人公鑰1解密,發現果真是c。
這個時候,他會想到,可以用個人公鑰解密的數據,必然是用個人私鑰加的密。只有我知道我得私鑰,所以他就能夠確認確實是我發的東西。
這樣咱們就能確認發送方身份了。這個過程叫作數字簽名。固然具體的過程要稍微複雜一些。用私鑰來加密數據,用途就是數字簽名。

-----------------------
路印協議
https://www.jianshu.com/p/c88270224a80
-----------------------
go net/http/server.go 源碼解析
https://www.zhihu.com/search?type=content&q=Golang%E7%BD%91%E7%BB%9C%3A%E6%A0%B8%E5%BF%83API%E5%AE%9E%E7%8E%B0%E5%89%96%E6%9E%90%28%E4%B8%80%29
-----------------------

在 Kotlin 中有一個約定,若是函數的最後一個參數是一個函數,而且你傳遞一個 lambda 表達式做爲相應的參數,你能夠在圓括號以外指定它
所以能夠實現以下
view.setOnClickListener({v -> viewClicked(v) })
=>
view.setOnClickListener() {v -> viewClicked(v) }php

在 Kotlin中還有另一個約定,若是一個函數的參數只有一個,而且參數也是一個函數,那麼能夠省略圓括號
view.setOnClickListener() {v -> viewClicked(v) }
=>
view.setOnClickListener{v -> viewClicked(v) }html


-----------------------
Golang 高併發性能優化
https://zhuanlan.zhihu.com/p/21514693
-----------------------
解決unix:///tmp/supervisor.sock no such file的問題
https://blog.csdn.net/qq_28885149/article/details/79364685
------------------------
水波紋效果:

   當你使用了Material主題後,波紋動畫會自動應用在全部的控件上,咱們固然能夠來設置其屬性來調整到咱們須要的效果。java

   能夠經過以下代碼設置波紋的背景:mysql

   android:background="?android:attr/selectableItemBackground"波紋有邊界linux

android:background="?android:attr/selectableItemBackgroundBorderless"波紋超出邊界
------------------------
Picasso 具有本地緩存的證據
https://www.cnblogs.com/gdpdroid/p/6226055.html
------------------------
Android 匿名共享內存 Ashmeme,及其在圖片框架的應用 和 各大圖片框架的對比
https://blog.csdn.net/u013134722/article/details/56676078
https://blog.csdn.net/wenyiqingnianiii/article/details/53045528
https://www.jianshu.com/p/d9bc9c668ba6
https://www.cnblogs.com/wytiger/p/5690039.html

tmpfs
https://www.cnblogs.com/wangtao_20/p/4828432.html

------------------------
xshell 過時
https://blog.csdn.net/pingqiwei/article/details/78502144
------------------------
go defer 的執行時機
https://segmentfault.com/a/1190000006823652
------------------------
supervisor Linux 進程管理
https://www.v2ex.com/t/372936
------------------------
Binder 機制一些文章
https://blog.csdn.net/lijizhi19950123/article/details/77920054
https://www.zhihu.com/question/39440766/answer/89210950
------------------------
鏈表的翻轉,圖解
https://blog.csdn.net/feliciafay/article/details/6841115
------------------------
Glide 緩存機制詳解
https://juejin.im/post/5ab9a6b56fb9a028bf0553bd
Glide 自定義緩存key
https://blog.csdn.net/carson_ho/article/details/79256773
------------------------
關於 Android 4.4 及其如下的手機出現以下錯誤的緣由和改法:
android.view.ViewGroup$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
這個錯誤在一些手機上面是不會出現的,一些卻會。緣由是咱們在添加給 ListView 及其子類的 itemView 的時候,
itemView 裏面使用了 new ViewGroup.LayoutParams
改法:
改用
------------------------
Android Studio 同步錯誤
界面顯示這種信息:
gradle project sync failed.Basic functionality(e.g.editing,debugging) will not work properly
而後查看 idea.log,若是出現有下面的信息:new AbsListView.LayoutParams

   8-03-17 08:44:18,041 [se-915-b01] INFO - pl.ProjectRootManagerComponent - project roots have changed
   2018-03-17 08:44:18,067 [thread 102] WARN - ea.IdeaSyncPopulateProjectTask - Sync failed: null
   java.lang.RuntimeException: java.lang.NullPointerExceptionandroid

那麼能夠定位錯誤緣由是。兩個相同的項目可是在不一樣的目錄,都曾被 as 打開過致使的緩存問題。解決方案是刪除其中一個。
例如:
xxx/project/項目A
xxx/project/newDir/項目A
------------------------
爲何 String 不可變。
http://blog.csdn.net/zhangjg_blog/article/details/18319521
------------------------
String StringBuffer StringBuilder 三者區別
http://www.cnblogs.com/su-feng/p/6659064.html
------------------------
top K 問題,XX 億個數中找最大的 y 個,這類題:
http://blog.csdn.net/zyq522376829/article/details/47686867
http://doc.okbase.net/zyq522376829/archive/169290.html
------------------------
阻塞隊列中:
put 和 take 是會阻塞等待的。
offer 和 poll 不會等待,同時也能夠設置必定的等待時間。
------------------------
java runtime 三個計算內存函數:
maxMemory 獲取當前 APP 最大可以申請的內存,超過就會 OOM
totalMemory 獲取當前 APP 已經從系統拿到的內存,包含使用上了的和沒有用上的,由於通常申請會申請多一部分,它老是慢慢按須要從系統拿取
freeMemory 獲取當前 APP 拿到的內存中,還沒用上的,既是能夠被 gc 回收的。
計算此刻 APP 已經使用了的內存是 : totalMemory - freeMemory = usedMemory
------------------------
Synchornous 修飾靜態方法和普通方法的區別:
1,static 是對於 .class 對象而言的,注意這裏不是實例,它還不是一個具體的對象,具體的對象 == 實例。
2,那麼修飾 static 的時候,也就是修飾這個 .class,當使用 Class.function(...) 的時候會產生對應的鎖效果。
3,修飾普通方法的時候,是針對實例而言的,也就是 new XXX().function(...) ,這個時候,會對同一個實例裏面產生對應的鎖效果。
具體什麼鎖效果,查看該博文下面的另一條:java synchronized詳解
------------------------
讓 靜態方法 和 普通方法 都產生互斥。
使用鎖靜態常量,語句塊方法,以下:
public final static Byte[] locks = new Byte[0];

public static void staticX() throws InterruptedException
{
    synchronized (locks)
    {
       ......
    }
}

public void x() throws InterruptedException
{
    synchronized (locks)
    {
        .....
    }
}

   ------------------------nginx

Class.forName(...) 的真正做用:獲取制定的類,若是這個類已經在 jvm 中裝載了,那麼直接返回,引用與已經裝載的同樣,不然便先裝載再返回。
參考文章:http://www.jb51.net/article/113928.htm
同時要注意,它返回的不是類實例,只是類對象,也就不會進行構造函數的調用。
http://blog.csdn.net/xiongmaodeguju/article/details/70854645
------------------------
AlertDialog 實現背景透明,即網易雲音樂的更新對話框,一個圖標所在區域的背景一半透明一半不透明的例子:
http://blog.csdn.net/android_hdh/article/details/75098221
------------------------
Win adb 沒法鏈接手機,在嘗試了在 .android 目錄下添加 xxx.ini 文件後且加入 0xYYYY 以後仍然沒法解決的狀況下,
若是在電腦的設備管理頁面看到 adb interface 有黃色感嘆號就參考這篇文章解決
http://blog.csdn.net/chtnj/article/details/49718809
其中驅動文件能夠在 sdk manager 中下載,也能夠去這裏下載
http://download.csdn.net/download/af913337456/10250732
------------------------
jackson 常見錯誤:
bean 沒定義無參構造函數;
bean 設置成了內部類,這是不容許的。JsonMappingException: No suitable constructor found for type
------------------------
mysql insert into select from 組合使用,適用於數據遷移
https://www.cnblogs.com/jpfss/p/6973048.html
------------------------
Linux ubuntu 若是出現輸入不了中文,去搜索處,搜索 fcitx,點擊一次便可
------------------------
Collections.sort compare :
1 , return 1 指compare方法第一個參數要放在第二個參數的前面,-1 指第一個參數要放在第二個參數後面 , don't return 0
2 , part sort can use ' list.subList '
------------------------
golang 加解密文件 https://segmentfault.com/q/1010000009581717?_ea=1979263
------------------------
java try-catch-finally https://www.cnblogs.com/aigongsi/archive/2012/04/19/2457735.html
------------------------
mysql 併發鎖的問題 https://www.cnblogs.com/leefreeman/p/8286550.html
------------------------
golang exec.Command cmd.Dir參數指定的是當前執行的目錄,若是不設置,那麼默認就是當前可執行程序的
------------------------
APP 鎖屏後,避免被 kill 掉,解決方案之一,使用手Q的一像素方案,成型 demo 參照 非ROOT版微信自動回覆APP。
注意點:
1,targetSdk 最好低於 23
2,LiveAc 的 theme
------------------------
Https 會加密頭部,在瀏覽器裏面查看獲得本地請求的頭部的緣由是,瀏覽器幫咱們處理了。
------------------------
mysql 導出數據庫和恢復數據庫到任意的另一個數據庫。
導出:控制檯命令 mysqldump -u {用戶名} -p {要導出的數據庫名 A}>xxx.sql
恢復:進入另一個服務器的 mysql,create database A,use A,source xxx.sql
------------------------
mysql 錯誤:Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
https://www.cnblogs.com/sunss/p/6245403.html
------------------------
Mysql switch 語句 樣例:
http://blog.csdn.net/djd1234567/article/details/51332267
------------------------
golang clear file content do not use this function --- os.Truncate(xxx,0),it may cause some \00 char problems
------------------------
HttpUrlConnection https 認證 http://blog.csdn.net/u012527802/article/details/70172357
------------------------
landscape 鎖屏拉伸,add this below
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="landscape"

------------------------
TRIM_MEMORY_COMPLETE maybe will be called when the app frist start
------------------------
openSSL 在服務端 生成 可供 Android 使用的祕鑰文件,開啓 Https 用到

 1 openssl req -new -key server.key -subj "/CN=IP地址" -out server.csr
 2 
 3 # 簽發服務端證書
 4 # ca.crt equals xx.pem, ca.key equals xx.pem
 5 openssl x509 -req -in server.csr -CA fullchain.pem -CAkey privkey.pem -CAcreateserial -out server.crt -days 5000
 6 
 7 # 客戶端
 8 openssl genrsa -out client.key 2048
 9 
10 openssl req -new -key client.key -subj "/CN=client" -out client.csr
11 
12 echo extendedKeyUsage=clientAuth > extfile.cnf
13 
14 openssl x509 -req -in client.csr -CA fullchain.pem -CAkey privkey.pem -CAcreateserial -extfile extfile.cnf -out client.crt -days 5000
15 
16 # 生成P12,p12 轉 bks,安卓用
17 openssl pkcs12 -export -in client.crt -inkey client.key -out client.p12
18 
19 # create xxx.cer ,安卓使用
20 openssl x509 -inform pem -in fullchain.pem -outform der -out server_public.cer
------------------------
onTrimMemory http://blog.csdn.net/ithouse/article/details/53319589
------------------------
Wechat service way to keep live : https://www.cnblogs.com/MouTou/p/5607423.html
------------------------
去 Editext 控件的父控件處設置
android:focusable="true"  
android:focusableInTouchMode="true"
這樣,已進入頁面,它就不會得到焦點
------------------------
Android 進程級別及對應的狀況 https://www.cnblogs.com/0616--ataozhijia/p/4323135.html
------------------------
友盟的分享SDK,在分享單圖片的時候,即沒有文字,若是發生失敗,沒權限什麼的之類,能夠在傳入的時候傳入 File,不傳 String
------------------------
四大組件之一 Service 的總結點:
  1,使用 startService 啓動一個 service,即時啓動它的組件已經銷燬了,例如 Activity,這個 service 也不會被銷燬,只有調用了這個 service 自身的 stopSelf() 或 stopService 纔會終止。
  2,使用 bindService 啓動一個 service,顧名思義。這種方式會讓它和啓動它的組件綁在一塊兒,只用當與它綁定的組件銷燬了,它纔會 unBind 銷燬,stopSelf 不能銷燬。
  3,一個 service 能夠被多個組件 bind,這個時候只有所有 bind 了的組件都進行了 unBind,這個 service 纔會被銷燬。
  4,既執行了 startService 又執行了 bindService,onCreate 只會被調用一次,且銷燬的時候以 unBind 爲主。
  5,不一樣的啓動方式,生命週期的 執行流程 也不同。
  6,Service 運行在主線程,intentService 運行在子線程。
------------------------
Serializable 和 Parcelable 的簡介與區別
相同點:
  1,二者均可以進行序列化與反序列化;
不一樣點:
  1,Serializable 的數據最後是存放在硬盤上的,那麼讀的時候也是 I/O 操做,而 Parcelabe 是存放在內存中的。這就致使了下面的一點
  2,Parcelable 的讀寫速度比 Serializable 在數據量大的時候,快不少
  3,Serializable 的實現十分簡單,而 Parcelable 的代碼量卻比較多
引伸:
  1,在使用 bundle 傳遞數據的時候,由於bundle 是使用 binder 機制進行數據傳輸的, 一個 binder的數據緩衝區是有大小限制的;
  2,一個進程的默認 binder 線程是15個。
------------------------
阻塞隊列的 poll offer put 等解析,https://www.cnblogs.com/dolphin0520/p/3932906.html
------------------------
補碼,原碼,反碼複習,https://www.cnblogs.com/zhangziqiu/archive/2011/03/30/ComputerCode.html
------------------------
IM sdk 的設計中,消息的發送到成功態,UI的刷新不要依賴 position,例如 notifyItemChanged(position),若是採用了翻轉類型的 layoutManager,剛發的消息 pos 老是 0,
這樣若是有新的消息到來,而本身剛發的還沒返回成功,這時候,pos 就被佔了,致使錯誤。應該傳入 MessageBean 的引用
------------------------
EventBus 的粘性事件須要注意,可能會屢次接收。例如接收後回到桌面,再次 restart 進入,可能會因爲 EventBus 裏面的粘性事件集合引用還存在,
致使再次分發,接收到上一次的事件。經過源碼能夠得出該結論。由於其在 postSticky 的時候分發一次,等到 register 的時候,由於標明瞭 stick = true 致使再次分發。
源碼分析: http://blog.csdn.net/yanghuinipurean/article/details/51646819
------------------------
聊天頁面若是要實現QQ的回覆的時候消息的頂起效果,便是不回滾到底部,在當前瀏覽的位置頂起。使用 recyclerView,只須要把,linearLayoutManager 設置爲翻轉模式便可。
------------------------
 1 /**
 2      * 狀態欄處理:解決全屏切換非全屏頁面被壓縮問題
 3      * 原理就是,把狀態欄設置爲透明後,自定義添加一個 View 進去
 4      */
 5     public void initStatusBar(int barColor) {
 6         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
 7             getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
 8             int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
 9             // 獲取狀態欄高度
10             int statusBarHeight = getResources().getDimensionPixelSize(resourceId);
11             View rectView = new View(this);
12             // 繪製一個和狀態欄同樣高的矩形,並添加到視圖中
13             LinearLayout.LayoutParams params
14                     = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, statusBarHeight);
15             rectView.setLayoutParams(params);
16             //設置狀態欄顏色
17             rectView.setBackgroundColor(getResources().getColor(barColor));
18             // 添加矩形View到佈局中
19             ViewGroup decorView = (ViewGroup) getWindow().getDecorView();
20             decorView.addView(rectView);
21             ViewGroup rootView = (ViewGroup) ((ViewGroup) this.findViewById(android.R.id.content)).getChildAt(0);
22             // true 使得狀態欄不被 content view 擋住
23             rootView.setFitsSystemWindows(true);
24             rootView.setClipToPadding(true);
25         }
26     }

 ------------------------git

Android 硬件加速文章 https://tech.meituan.com/hardware-accelerate.html
------------------------
layoutManager.getChildCount 和 lastVisibleItemPosition 同樣,都是添加過的 view 總數。而 layoutManager.getItemCount 是指 adapter 所綁定 list 添加了的總數。
差比在於: 若是咱們沒有自定義 headerView,那麼三者同樣,不然就是 childCount = itemCount + header.size
------------------------
recyclerView 異常 "Called attach on a child which is not detached" 的緣由是,使用了一個還沒被回收緩存的 view 去從新加入到視圖中,致使異常,debug 斷點其內函數 attachViewToParent 便可明瞭。
通常引起的緣由有不少,notifyRemove 和 insert 最容易觸發。解決方案是傳入正確的 postion
------------------------
混淆的時候,各個 library 的混淆文件對應自身目錄的 .pro 文件,互不影響
------------------------
注:當使用混淆打包時可能會出現一個問題
Error:Execution failed for task :transformClassesAndResourcesWithProguardForRelease'. > java.io.IOException: Please correct the above warnings first.
這個問題是在說你在混淆打包的時候有些類有可能找不着,因此會包錯,和warning 
解決的辦法:
找到報warning的類都給他在你的混淆器文件中
添加代碼給取消掉warning就能夠了,若是你不想那個類被混淆,那就添加代碼:
------------------------
android studio error : symbols/androidTest/debug/R.txt (沒有那個文件或目錄)
add this to your gradle:proguard-rules.pro-dontwarn 包名+類名.**-keep class 包名+類名{*;}或者包名.**{*;}
dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})

------------------------
較好的 OKHttp 源碼分析文章。
http://blog.csdn.net/qq_19431333/article/details/53141013
http://www.jianshu.com/p/9ed2c2f2a52c
http://blog.csdn.net/ethanco/article/details/78268750
http://blog.csdn.net/evan_man/article/details/51182087
緩存 http://blog.csdn.net/qq_21430549/article/details/52069708
Connect() http://blog.csdn.net/chenzujie/article/details/47093723
------------------------
SynchornousQueue 的詳解-----http://www.cnblogs.com/shangxiaofei/p/5707552.html
------------------------
volatile能夠保證變量的內存可見性。連接:http://www.cnblogs.com/yanfengfree/p/6271359.html
------------------------
動態規劃求,最長公共子序列: http://blog.csdn.net/hrn1216/article/details/51534607
------------------------
Intent.putExtra 傳進去在源碼層能夠看到是內存拷貝傳的,也就是深複製.
------------------------
android 實現多點觸控的問題,自己已經支持,在 onTouch 或者 onTouchEvent 等函數裏面,能夠經過 MotionEvent 的 api getPointerCount 來獲取屏幕的觸點數目,
而 getX(...) getY(...) 則能夠根據傳入的 position 來或者對應觸點的座標,而後就能夠寫本身的邏輯來控制了。
------------------------
mysql 修改 root 的權限,http://www.cnblogs.com/kyosusan/p/5198934.html
------------------------
Jni 中 C++ 調用 java 接口,若是沒有返回值的,就必定要不用返回值的 jni 函數,例如 env->CallVoidMethod(...) 不然在循環屢次後會形成內存泄露底層異常,沒法解決!
------------------------
SurfaceView 自身沒有調用 onDraw,須要子 View 手動調用,或者在 xml 配置 bgColor 的時候,設置,這樣會自動調用一次,而後你在 子View 的 onDraw 裏面設置個 loop,loop裏面 postInvalidate 就能一直調用了。
代碼動態設置 bgColor 也能夠,visible 測試不能引發 onDraw 的調用
------------------------
EventBus 3.0.x 中的粘性事件 , 發送端使用 postSticky 是不夠的 , 接收端 , 還要在 @Subscribe 處後面加上 (sticky = true) , ===> @Subscribe(sticky = true)
------------------------
在結合 view.getGlobalVisibleRect(...) 獲取的 rect 和 屬性動畫 ObjectAnimator.ofFloat(...) 的使用中 , 須要注意位置的不一樣 .
1 , getGlobalVisibleRect 獲取的 rect 是從屏幕左上角開始的 , 也就是說 , 把咱們手機頂部顯示時間,電量,wifi等圖標的那一欄給計算進去了
2 , 屬性動畫的開始 標準 , 若是是平移之類的話 , 例如 X或者 Y 這類 , 它的開始是從當前的 decorView 開始的 , 也就是說沒有計算 電量 那一欄 .
結論:
  爲了防止偏差 , 你得把你經過 getGlobalVisibleRect 得出的 rect 減去頂部的高
------------------------
onMeasure(最終整個指望的寬,最終整個指望的高) 是表明着控件的最終指望寬高

MeasureSpec.makeMeasureSpec(size,mode) size 是指望的大小 , mode 是模式 . 例如設置 寬 高

1 , 最終指望的寬 width = MeasureSpec.makeMeasureSpec(指望的寬 , mode)
2 , 最終指望的高 height = MeasureSpec.makeMeasureSpec(指望的高 , mode)

mode 的不一樣狀況 :
  MeasureSpec.AT_MOST 這個的狀況 , 就是使用 指望的值 去和 最終控件對應的 size 作比較 , 返回 最小的一個 , 通常咱們都是使它返回控件組的便可,因此咱們能夠傳一個很大的指望, 例如 Integer.MAX_VALUE >> 2
  MeasureSpec.EXACTLY 這個的狀況 , 就是直接使用 指望的值 , 設置多少就是多少
  MeasureSpec.UNSPECIFIED 這個是 , 直接使用 控件組對應的 size , 不管你設置的 指望是多少 .
補充:
  1 所謂的控件組的 size 就是 , layout 的大小 , 就是咱們經過 R.layout.xxx 或者其餘設置時候 , 該 layout 佔的總大小.
  2 上面的 三種 mode 的最終效果 , 還要看當前的 ViewGroup 的內部設置而定 . 例如 GridView 在 UNSPECIFIED 的狀況設置了最終整個 GridView 僅僅返回一行的高 , 也就是老是一組的高 , 此時一組的指望高 = 控件的 size.高
   可是在 AT_MOST 的時候 , 和上面同樣 此時一組的指望的高 = 控件的 size.高 , 可是最終的整個 GridView 的高是所有 組 佈滿後的尺寸
  3 若是 須要 徹底手動 設置 寬高 , 例如處理 bitmap 的時候 , 應該使用函數 setMeasuredDimension(寬 , 高) , 而不是使用 onMeasure , 由於 onMeasure 的狀況是必須是與 32 作了 與或 運算的 , 在內部分解的時候也會和 32 作反操做 ,
   便是說 , 你傳的若是沒和 32 作過 與或 運算的話 , 在內部反操做的時候就會亂掉 . 而 setMeasuredDimension 會在你傳的值以後 幫你完成 32 的 與或操做 , 同時也須要你必須先調用 onMeasure 再 調用 setMeasureDimension ,不然會有錯誤
1 @Override
2  public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
3         
4         super.onMeasure(widthMeasureSpec,heightMeasureSpec);
5         
6         setMeasuredDimension(500,600);
7  }
因此:
  在解決 嵌套 問題的時候, 咱們通常
    MeasureSpec.makeMeasureSpec(
      足夠大的值, // 當足夠大的時候 > 一組控件的 size , 就會直接返回 一組控件的
      MeasureSpec.AT_MOST
    );

----------------------------------------golang

OKHttp 若是已經附帶 header 進行過請求,在以後的請求修改 header 是無效的,老是使用第一次的,能夠經過銷燬當前的對象,從新 new 一個設置 header 發起請求解決。算法

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

截屏  getDrawingCache 的陷阱 , 每次在執行這個函數以前 , 先將上一次的給 destroy 掉 , 不然 , 會致使老是同一張 , 哪怕此時你的 View 已經加入了其餘的子 View , 正確流程

gpuImageView.destroyDrawingCache();
gpuImageView.setDrawingCacheEnabled(true);
gpuImageView.buildDrawingCache();
Bitmap editbmp = Bitmap.createBitmap(gpuImageView.getDrawingCache());

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

聊天頁面軟鍵盤把內容頂起

recyclerViewLayoutListener = new View.OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
recyclerView.scrollToPosition(recyclerView.getAdapter().getItemCount()-1);
}
};

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

Android 一些須要用到 Context 來獲取的,若是是全局修改,例如語言的切換,務必使用 getApplicationContext,若是使用單個 Activity 的話,可能有些頁面不會被影響到。

Sql 中 string 類型的採用 order by,順序不是正確的,數字類型會正確

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

scrollTo 是一步到位,scrollBy 是逐漸累加,scrollTo(100,100) 後,想到 120,那麼是 scrollTo(120,120),此時若是換成 scrollBy 就是 scrollBy(20,20),內部在 to 的基礎上累加。

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

在使用 View.getLocationInWindow(int[] ) 函數的時候,要注意,在 ViewPager 的狀況下,例如第二頁的一個控件,x 的座標會把第一頁的計算進去。onScreen 同樣,內部由於調用了 inWindow。

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

Activity 裏面使用 ViewPager 裝載 Fragment 的時候,若是此時的 Fragment 再在裏面裝載其餘 ViewPager + Fragment 的時候,Fragment 裏面的 ViewPager 的 FragmentManager 不要使用 getSupportFragmentManager() ,要使用 getChildFragmentManager(),不然會形成,有些時候, Fragment 裏面的 Fragment 顯示一片空白!緣由是,getSupportFragmentManager 是基於 Activity 的,getChildFragmentManager 是基於 Fragment 的。

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

關於 AlarmManager 在 5.1 先後的不一樣 5.1以前,能夠隨便設置多少秒的間距,5.1以後,<60 秒就會強制變成 1 分鐘,就是至少一分鐘

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

消除 Android App 自身啓動時候的 白屏,以及改成自定義啓動頁的方法:

<item name="android:windowBackground">@mipmap/welcome</item>

Activity 的 style 加上上面一句,可是也要在徹底進入主頁後設置 背景 沒有,不然會一直顯示做爲 WindowBackGround

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

 

WindowManager 若是要在 Activity 添加 View,不能採用 getApplicationContext(...) 來獲取 systemService 不然,會產生異常:Unable to add window -- token null is not valid; is your activity running.

type 要使用 System_Application,flags 使用全屏,no limits

synchronized和ReentrantLock的區別

Java多線程(九)之ReentrantLock與Condition

 

java synchronized詳解  理解 2~3 點的時候要明確:m4t1 和 m4t2 方法都是類 Thead2的代碼部分,Thead2 此時充當 object

 

onStartCommand 和 onBind 的區別 

 

進階 https://juejin.im/entry/58d2d12f2f301e007e674cd1

 

git 提交 pull request http://jingyan.baidu.com/article/358570f64dcdc2ce4724fc32.html

 

代碼鏈接 mysql 出現錯誤: dial tcp 127.0.0.1:3306: getsockopt: connection refused 並且經過sock文件在終端登陸 mysql 使用 show variables like 'port'; 是 0 的話,參照此文章解決, http://blog.csdn.net/shaochenshuo/article/details/50070315 是由於一個 skip-networking 參數

Amh 面板的 mysql 鏈接的時候爆出錯誤找不到 mysql.sock ,先查找下,find / -name "*.sock",再複製一份到 tmp,

ln -s /tmp/mysql-generic-5.5.sock /tmp/mysql.sock , 再鏈接便可。

-------2017-3-8 開始

  針對 Android Studio 狀況的 .so 匹配問題,有以下一個規則:若是測試手機自身是支持 armeabi,armeabi-v7a,x86 的,而此時,項目中 eabi ,v7a,x86 都含有 a.so,可是 eabi 和 v7a 單獨還多有 b.so,此時若是編譯運行到該手機,那麼就會爆出沒法 在x86 找到 b.so 的異常。

  根據不一樣的手機爲準,例如小米就是有一個層次級別加載,它先從本身支持的列表中去找,例如 x86 找,此時你的項目也含有 x86 的庫文件夾,那麼它就認定這個了,此時你代碼裏面須要加載 b.so 可是 x86  沒有,因此報錯。

  解決方法就是,要麼就別建含有 x86 的狀況,或者在每種架構中都編譯全 .so 文件。

------2017-3-8 結束

MySql,對於 select .... where xx in (?) 的預處理語句,若是 ?對應是一組字符串,例如 3,6,8 那麼在傳過來的時候事實是 '3,6,8' ,內部使用了以下方法:CAST('4,3' AS INT),強轉爲 int 後,只能查處一條,便是 3 的。因此對於這種清理,使用 FIND_IN_SET 解決,改成 select .... where FIND_IN_SET(要查詢的字符串,傳過來的)

 

  

java 匿名對象的使用,若非延時調用,那麼不會形成內存泄露,下面舉例子:

 1 /** 沒引發其它,用完便可被回收 */
 2         new Thread(new Runnable() {
 3             @Override
 4             public void run() {
 5                 
 6             }
 7         }).start();
 8         
 9         /** 持有外部 Activty 引用,延時這段時間,沒法被回收 */
10         new Handler(){
11             @Override
12             public void handleMessage(Message msg) {
13                 super.handleMessage(msg);
14             }
15         }.postDelayed(new Runnable() {
16             @Override
17             public void run() {
18                 
19             }
20         },60*1000);  

 

http://blog.csdn.net/jiahui_zhu/article/details/50234311

WINScp 解決常常斷開連接的問題, 選項-》選項-》面板-》遠程-》刷新面板間距,時間調小

啓動 MariaDB: systemctl start mariadb.service

三大手寫算法

 1 /** 冒泡 */
 2     public static void bober(int[] array){
 3         int length = array.length;
 4         for(int i=0;i<length-1;i++){   /** 每兩個比較一次,總次數是 length-1 */
 5             for(int j=0;j<length-1-i;j++){ // 每次總有一個最大的找出 -i
 6                 if(array[j]>array[j+1]){
 7                     int temp = array[j];
 8                     array[j] = array[j+1];
 9                     array[j+1] = temp;
10                 }
11             }
12         }
13     }
14 
15     /** 快排 */
16     public static void quickSort(int[] array,int left,int right){
17         if(array==null){
18             return;
19         }
20         int length = array.length;
21         if(length == right){ // 防止輸入數組的非下標長度,形成越界
22             right = right -1;
23         }
24         if(left > right){
25             return;
26         }
27         int low = left;
28         int hight = right;
29         int key = array[left];
30 
31         while(low<hight){
32             while(low<hight && array[hight]>=key){
33                 hight --;
34             }
35             array[low] = array[hight];
36             while(low<hight && array[low]<=key){
37                 low++;
38             }
39             array[hight] = array[low];
40         }
41         array[low] = key;   /** 被比較的數此時應該回到 low 位置 */
42         quickSort(array,left,low-1);
43         quickSort(array,low+1,right);
44     }
45     /** 二分查找 */
46     public static int binary(int[] array, int value){
47         int low = 0;
48         int high = array.length - 1; // 防止越界
49         while(low <= high){
50             int middle = (low + high) / 2;
51             if(value == array[middle]){
52                 return middle;  // 下標
53             }
54             if(value > array[middle]){
55                 low = middle + 1;
56             }
57             if(value < array[middle]){
58                 high = middle - 1;
59             }
60         }
61         return -1;
62     }
View Code

 

as 修改默認 apk 名稱:

 1 buildTypes {
 2         release {
 3             minifyEnabled false
 4             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
 5             applicationVariants.all { variant ->
 6                 variant.outputs.each { output ->
 7                     output.outputFile = new File(output.outputFile.parent,
 8                             output.outputFile.name.replace("app-release", "AccurMe")
 9                     )
10                 }
11             }
12         }
13         debug{
14             applicationVariants.all { variant ->
15                 variant.outputs.each { output ->
16                     output.outputFile = new File(output.outputFile.parent,
17                             output.outputFile.name.replace("app-debug", "AccurMe")
18                     )
19                 }
20             }
21         }
22     }
View Code

 

android studio,gradle的編譯默認是會找依賴關係最近的覆蓋,若是一個相同的 xml 佈局文件分佈在不通的模塊,此時修改一個,再 findView。。有可能引起空指針,由於就近的若是不是被修改的就會如此

當LinearLayout設置android:orientation="vertical" 時, 只有水平方向的left,right,center_horizontal設置起做用,垂直方向的設置不起做用。

一樣的:

當LinearLayout設置android:orientation="horizontal" 時, 只有垂直方向的top,bottom,center_vertical設置才起做用,水平方向的設置不起做用。

 

IM架構設計中,好友刪除部分,若是當前被刪者在發送消息的頁面,並且斷網期間沒接收到被刪除推送,那麼恢復網絡後,他發消息給刪除者,應該在刪除者端判斷,該人仍是否在好友列表再決定顯示,避免在發送 服務端 每次作查詢操做

android 6.0+ 若是 activity 此時正在用 surfaceView 播放視頻,你卻調用 finish,必定要 surfaceView.getHolder().removeCallback(surfaceViewLis); 和 surfaceView=null,不然爆底層異常,閃退,6.0 如下不會。

Nginx 的 php-fmp 監聽的端口要和nginx.conf 裏面的 fastcgi_pass xxxx:port 的同樣,不然會出現502錯誤

兼容系統自帶的 emoji 的方法是,發送的時候將內容加密,獲取的時候再解密便可,加解密是爲了防止在傳輸的時候編碼被轉成亂碼致使顯示不了,系統是一個表情的編碼,utf8 不存在。 

XRecyclerView 使用  notifyItemChanged 會閃的緣由是:

原做者,沒用重寫:  onBindViewHolder(final RecyclerView.ViewHolder holder, int position,List<Object> payLoads) , 後面的payLoad,默認是null,不爲null 的時候,就是隻更新惟一改了的地方。notifyItemChanged(position,new Object())

 

7linux控制檯啓動程序後,關掉控制檯不讓程序中止, ./test & 加上 & 這樣是將命令放入到一個做業隊列中。若是仍是失敗,安裝 nohup ,nohup ./xxx &

信號量的當前值,N > 0,該值表示有N個可用資源
若是爲 N = 0,沒有進程處於等待狀態
若是 N < 0,有N個進程處於等待狀態。

Win 安裝驅動,若提示哈希值什麼錯之類的,是系統驗證簽名的緣由,開機關掉強制驗證驅動簽名便可

Win cmd 設置環境變量是 set

下面這條寫於2016年9月12日晚,很基礎,但我仍是搞反了,特意放在全部的前面,爲的是警示本身,基礎的若是不經常使用就應該多回頭看看。

ARP協議主要是將IP地址轉化爲物理地址。

TCP的socket自己就是長鏈接

a~y 25個字母編碼,a->0,aa->1,aaa->2,aaaa->3 以此類推,滿25 進一。

 1 public static int getIndex(String str){
 2     int[] numbes = new int[]{
 3         1+25+25*25+25*25*25, // a
 4     1+25+25*25, // ab
 5     1+25,// abb
 6     1 //a
 7     };
 8     char[] chars = str.toCharArray();
 9     int len = chars.length;
10     int result = 0;
11     for(int i=0;i<len;i++){
12         result += (chars[i]-'a')*numbes[i];
13     }
14     return result+(len - 1);
15 }        
View Code

N*N 個方格中有 1^2+2^2+3^2+...+(n-1)^2+n^2 個正方形

InputMetohdManager 單例模式,按鈕事件的監聽、廣播是觀察者模式

AsyncTask 比 handler 更耗資源

SingleTop 不會彈棧

Message提供了消息池,Thread默認不提供資源池,AsynTask是線程池改造的,Looper,沒提供池

Theme類不能夠繼承

一個TextView的style中定義了textColor屬性,TextView自己也設置textColor屬性,那麼TextView自己定義的優先級較高

進程重要性:前臺進程>可見進程>服務進程>後臺進程和空進程;因此銷燬的順序是逆方向。

 繼承 AppCompatActivity 的 Activity , AlertDialog 很難全屏

RadioButton 的 OnCheckedChangeListener 若是另外一個調用了,最近以前點過的也會調用一次,不一樣的是,最近的是 check false

要確保不在子線程中修改Adapter所綁定的 ArrayList 的數據內容,而要在UI Thread中修改,和 notifityDataChange 一塊兒連用

在 Fragment 中採用 startActivityForResult 跳到對應的 Activity,返回時回調的首先是 fragment的onActivityResult 而後是 所傳 context 對應的 Activiy 的 onActivityResult

setResult(...) 要在finish() 以前設置,不然沒效!

調用 onBackPressed,那麼 finish()->onBackPressed(),調用 finish(),只用 finish()

NDK,Jni實現HelloWold 的最簡單代碼:

jstring Java_包名_所在類名_函數名字(JNIEnv *env,jobject thiz){

     return (*env)->newStringUTF(env,"helloWorld");  

}

 

顯示系統的 Emoji 到 textView 的時候,不要 toString 要採用 Spinnable 或者 SpinnableString,再 setText

 

兩道經典算法題

  1 import java.io.*;
  2 import java.util.HashMap;
  3 import java.util.Arrays;
  4 
  5 /**
  6  * Created by 林冠宏 on 2016/8/9.
  7  *
  8  * 1,尋找單詞
  9  * 
 10  * 2,大數相乘,字符串版
 11  *
 12  */
 13 
 14 class test  
 15 {
 16     public static void main (String[] args) throws java.lang.Exception
 17     {
 18         String testText = "I I I I I I Last year,I went to Guilin for travel,+" +
 19             "it was a great trip for me.I not only had a look at the beautiful scenery,+" +
 20             "but also made friends.I knew a lovely girl from America," +
 21             "we met each other on the train.As we were almost at the same age,+" +
 22             "we communicated a lot.We shared our opinion about the culture and learned a lot." +
 23             "When our train reached the destination,+" +
 24             "we needed to separate,we promised to keep in touch by the Internet." +
 25             "Now a year has passed,+" +
 26             "we make our promise and keep in touch all the time." +
 27             "I have improved my English and she is so interested in China.+" +
 28             "It seems that we can never finish our topic," +
 29             "because we always have so much to share with each other.+" +
 30             "I am so lucky to make a good friend.";
 31         
 32         System.out.println("MaxWord is :"+search(testText));
 33         System.out.println("BigNumberMutiply is "+multiply("5991299","998889799"));
 34     }
 35     
 36     /** 文章中找出出現次數最多的單詞 */
 37     /**
 38      * 算法概述,利用 HashMap 的特色
 39      * */
 40     public static String search(String text){
 41         String maxWord = "";
 42         int    maxTime = 0;
 43         String[] words = text.split(" |\\.|,");
 44         int length = words.length;
 45         System.out.println("length is :"+length);
 46         HashMap<String,Integer> one = new HashMap<>(); /** 一個map是能夠put多個的 */
 47         for(int j=0;j<length;j++){
 48             Integer number = one.get(words[j]);
 49             if(number != null){
 50                 number = number + 1;
 51                 /** 找到次數加 1    */
 52                 one.put(words[j],number);
 53                 if(maxTime < number){
 54                     maxTime = number;
 55                     maxWord = words[j];
 56                 }
 57             }else{
 58                 /** 沒找到,賦值 1  */
 59                 one.put(words[j],1);
 60             }
 61         }
 62         System.out.println("maxTime is :"+maxTime);
 63         return maxWord;
 64     }
 65     
 66     /** 大數相乘 */
 67     /**
 68      * 算法概述,就是小學的乘法規則,例如
 69      *    33*44
 70      *    33
 71      * X  44
 72      * -----
 73      *    12 (2 是 n,1 是 n-1)
 74      *   12  (以此類推)
 75      * -----
 76      *   132
 77      *   ......
 78      * */
 79     public static String multiply(String str1,String str2){
 80 
 81         Integer[] resultChar;
 82         char[] strChar1 = str1.toCharArray();
 83         char[] strChar2 = str2.toCharArray();
 84 
 85         int str1Len = strChar1.length;
 86         int str2Len = strChar2.length;
 87         
 88         int n = str1Len+str2Len-1;
 89         resultChar = new Integer[n+1];
 90         /** 初始化 */
 91         for(int i=0;i<=n;i++){
 92             resultChar[i] = 0;
 93         }
 94 
 95         for(int i = str1Len-1;i>=0;i--){
 96             /** 減去 48 是轉爲數字 */
 97             int temp1 = strChar1[i] - 48;
 98             for(int j = str2Len-1;j>=0;j--){
 99                 /** 一輪後的 n--,此時 n 變爲上一輪的 n-1 */
100                 int temp2 = resultChar[n] + (strChar2[j] - 48)*temp1;
101                 if(temp2 >= 10){
102                     /** 取餘數 */
103                     resultChar[n] = temp2 % 10;
104                     /** 進位取整數 */
105                     /** 在一大輪完成後,新n會與上一大輪的n相等,這裏要在n-1位疊加 */
106                     resultChar[n-1] += temp2/10; 
107                 }else{
108                     resultChar[n] = temp2;
109                 }
110                 n--;
111             }
112             /** 跳出一層內循環,證實 1 個數已被乘完,n 要重置 */
113             n = n + str2Len - 1;
114         }
115         /** 返回結果 */
116         StringBuffer result = new StringBuffer("");
117         for(int k=0;k<resultChar.length;k++){
118             result.append(resultChar[k]);
119         }
120         return result.toString();
121     }
122 }
View Code

 

線程池中的任務隊列,併發型阻塞隊列 ArrayBlockingQueue,poll() 和 take() 都是獲取一個任務,內部操做皆有鎖lock,差異是:使用take()函數,若是隊列中沒有數據,則線程wait釋放CPU,而poll()則不會等待,直接返回null;一樣,空間耗盡時offer()函數不會等待,直接返回false,而put()則會wait,所以若是你使用while(true)來得到隊列元素,千萬別用poll(),CPU會100%的。源碼中有一個 allowCoreThreadTimeOut,若是設置爲true,則會進入 poll(),newCacheThreadPool 也會引發poll()。

 

TCP:

握手階段:ack=seq+1

數據傳輸階段:ack=seq+待確認數據包長度

 

Jvm 虛擬機中 類的加載機制最後一步執行初始化 clinit<> 是線程安全的,這也是爲何單例模式中,非餓漢模式中的靜態內部類模式可以達到線程安全的緣由。

 

靜態內部類和非靜態內部類的加載規則都是 在調用的時候才加載,時間是同樣的,會先加載外部類。若是不調用,那麼就不會被加載!

 

handler.removeCallBacksAndMessages(null) 將全部的Callbacks和Messages所有清除掉。能夠防止內存泄漏

 

handler.post() 運行在主線程中,勿作耗時操做!

 

FFmpeg 的裁剪,crop 和改變視頻方向 transpose 不能在 vcode 爲 copy 的狀況下使用,不然沒效,由於是複製,可是能夠進行時間長短的截取

 

OS 安全狀態確定不會致使死鎖,不安全狀態不必定會致使死鎖

 

String str=new String("abc"); 建立了兩個對象, String a = "a"+"b"; 3 個 

 

URL實際上就是是對資源的一種描述:<scheme>://<host>:<port>/[<path>|<pathPrefix>|<pathPattern>]<query-string>

 

  主鍵 惟一索引
個數 有且只有一個 0,1,多個
Allow NULL x
與對方的關係 充分沒必要要 必要不充分
不採用 OnTouch 接口實現 onTouch 對應的背景改變
 1 <?xml version="1.0" encoding="utf-8"?>
 2 <selector xmlns:android="http://schemas.android.com/apk/res/android">
 3     <!-- android:state_pressed 設置點擊時候的屬性 -->
 4     <item android:state_pressed="true">
 5         <shape>
 6             <solid android:color="#0CA5DF" />
 7             <!-- 描邊 -->
 8             <stroke
 9                 android:dashGap="0dp"
10                 android:dashWidth="5dp"
11                 android:width="0dp"
12                 android:color="#0CA5DF" />
13             <!-- 圓角 -->
14             <corners
15                 android:bottomLeftRadius="0dp"
16                 android:bottomRightRadius="0dp"
17                 android:topLeftRadius="0dp"
18                 android:topRightRadius="0dp" />
19 
20            <!--  <padding android:bottom="2dp" android:left="2dp" android:right="2dp" android:top="2dp" /> -->
21         </shape>
22     </item>
23     <!-- android:state_pressed 設置獲取了焦點時候的屬性,也就是onTouch 的 move -->
24     <item android:state_focused="true">
25         <shape>
26             <solid android:color="#0CA5DF" />
27 
28             <stroke android:width="0dp" android:color="#0CA5DF" />
29 
30             <corners android:bottomLeftRadius="0dp" android:bottomRightRadius="0dp" android:topLeftRadius="0dp" android:topRightRadius="0dp" />
31 
32            <!--  <padding android:bottom="2dp" android:left="2dp" android:right="2dp" android:top="2dp" /> -->
33         </shape>
34     </item>
35 
36     <!-- android:state_pressed 設置沒被點擊或者觸摸時候屬性 -->
37     <item android:state_enabled="false">
38         <shape>
39             <solid android:color="#0050AB" />
40 
41             <corners android:bottomLeftRadius="0dp" android:bottomRightRadius="0dp" android:topLeftRadius="0dp" android:topRightRadius="0dp" />
42 
43             <!-- <padding android:bottom="2dp" android:left="2dp" android:right="2dp" android:top="2dp" /> -->
44         </shape>
45     </item>
46 
47     <item>
48         <shape>
49             <!-- <solid android:color="#0a9c89" /> -->
50             <solid android:color="#0050AB" />
51 
52             <!-- <stroke android:width="3dp" android:color="#000000" /> -->
53 
54             <corners android:bottomLeftRadius="0dp" android:bottomRightRadius="0dp" android:topLeftRadius="0dp" android:topRightRadius="0dp" />
55 
56             <!-- <padding android:bottom="2dp" android:left="2dp" android:right="2dp" android:top="2dp" /> -->
57         </shape>
58     </item>
59 
60 </selector>

 

代碼獲取 sha1

 1 public static String sHA1(Context context) {
 2         try {
 3             PackageInfo info = context.getPackageManager().getPackageInfo(
 4                     context.getPackageName(), PackageManager.GET_SIGNATURES);
 5             byte[] cert = info.signatures[0].toByteArray();
 6             MessageDigest md = MessageDigest.getInstance("SHA1");
 7             byte[] publicKey = md.digest(cert);
 8             StringBuffer hexString = new StringBuffer();
 9             for (int i = 0; i < publicKey.length; i++) {
10                 String appendString = Integer.toHexString(0xFF & publicKey[i])
11                         .toUpperCase(Locale.US);
12                 if (appendString.length() == 1)
13                     hexString.append("0");
14                 hexString.append(appendString);
15                 hexString.append(":");
16             }
17             String result = hexString.toString();
18             return result.substring(0, result.length()-1);
19         } catch (Exception e) {
20             e.printStackTrace();
21         }
22         return null;
23     }

 

大於0的就是指compare方法第一個參數要放在第二個參數的前面,小於0就是指第一個參數要放在第二個參數後面
解決unix:///tmp/supervisor.sock no such file的問題
相關文章
相關標籤/搜索