Skip to content

Instantly share code, notes, and snippets.

View hnrainll's full-sized avatar
🎯
Focusing

Hao hnrainll

🎯
Focusing
  • Beijing,China
View GitHub Profile
@hnrainll
hnrainll / mkpw.py
Last active August 29, 2015 14:23 — forked from thalin/mkpw.py
from optparse import OptionParser
from getpass import getpass
import base64, hmac, hashlib
'''
This small script is meant to generate long passwords by hashing a secret
password and a site identifier. The intent is to create a usable interface
for maintaining longer, somewhat more secure (?) passwords.
The idea here is that you remember a 'master' password and use it to generate
@hnrainll
hnrainll / blankTextDrawable.java
Created May 16, 2015 05:44
Android 实现镂空字体
public class BlankTextDrawable extends Drawable {
private Paint mPaint = new Paint();
private RectF mRect = new RectF();
private static final String text = "wenhao";
private static final int TEXT_SIZE = 40; //sps
private Bitmap mBackgroundBitmap;
private Bitmap mTextBitmap;
@hnrainll
hnrainll / drawable-part.java
Created May 14, 2015 07:25
Android XML中声明的drawable类型对应的具体类
//代码节选自:Drawable.java createFromXmlInner()方法
switch (name) {
case "selector":
drawable = new StateListDrawable();
break;
case "animated-selector":
drawable = new AnimatedStateListDrawable();
break;
case "level-list":
@hnrainll
hnrainll / TypedValue.applyDimension-use.md
Created May 14, 2015 03:57
官方提供的各种其他的尺寸转换为px的方法:TypedValue.applyDimension()

TypedValue.applyDimension()

当我们需要将dp转换成px时,一般我们可以自己写,因为也很简单。其实android api当中已经给我们提供了这个方法了。

TypedValue.applyDimension(COMPLEX_UNIT_DIP, 14, context.getResources().getDisplayMetrics());

作用:将14dp转换为px

@hnrainll
hnrainll / android-dp2px
Created May 14, 2015 03:49
Android dp转换到px时为什么需要 +0.5f
将dp转换为px时,我们通常的做法:
public static float convertDpToPixel(float dp, Context context){
final float density = getResources().getDisplayMetrics().density;
return (dp * scale + 0.5f);
}
那么为什么需要+0.5f呢?
在官方文档中:http://developer.android.com/guide/practices/screens_support.html
@hnrainll
hnrainll / hidebottombar.java
Created April 24, 2014 05:29
隐藏android底部栏
//在onCreate当中调用
main = LayoutInflater.from(this).inflate(R.layout.activity_main,
null);
main.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
setContentView(main);
@hnrainll
hnrainll / readFile.py
Created March 4, 2014 01:34
指定文件名,读取其中的内容并显示.其中包含异常的基本使用
fname = raw_input("Enter file name:")
try:
fobj = open(fname,"r")
except IOError, e:
print 'file open error....'
else:
for eachLine in fobj:
print eachLine,
@hnrainll
hnrainll / makeFile.py
Created March 4, 2014 01:32
手动输入文件名称,并循环将输入写入文件
import os
while True:
filename = raw_input("enter filename:")
if(os.path.exists(filename)):
print "%s is already exists" % filename
else:
break