Skip to content
owned by jayfeng, android open project... edited this page Mar 8, 2015 · 5 revisions

Welcome to the LessCode wiki!

Usage

####Config

  • Required
$.getInstance()
 .context(getApplicationContext())
 .build();
  • Optional
$.getInstance()
 .context(getApplicationContext())
 .log(BuildConfig.DEBUG, "LESSCODE") // LogLess - debug, tag
 .update(null, 5) // UpdateLess - null means the default value, 5 is the notification frequent, default is 5
 .http(5000, 5000) // HttpLess - default connect and read timeout
 .build();

####Less List

  • $
  • ActivityLess
  • AdapterLess
  • AppLess
  • CacheLess
  • DisplayLess
  • EncodeLess
  • FileLess
  • HttpLess
  • KeyBoardLess
  • LogLess
  • NetworkLess
  • ResourceLess
  • SharedPreferenceLess
  • StorageLess
  • ToastLess
  • UpdateLess
  • ViewLess

####Android VS LessCode

  • ViewLess
// 强制转化View类型
// Before
ListView listView = (ListView) findViewById(R.id.list);
// After
ListView listView = ViewLess.$(this, R.id.list);
  • ActivityLess
// 无标题全屏
// Before
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
            activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
// After
ActivityLess.$noTitle(this);
ActivityLess.$fullScreen(this);
  • AppLess
// 获取app的versionCode,versionName
// Before
String packageName = context.getPackageName();
PackageInfo packageInfo;
try {
    packageInfo = context.getPackageManager().getPackageInfo(packageName, 0); 
    result = packageInfo.versionCode;
} catch (PackageManager.NameNotFoundException e) {
    throw new AssertionError(e);
}
// After
AppLess.$appname(this);
AppLess.$vercode(this);
AppLess.$vername(this);
  • CacheLess
// 以文件形式缓存
// 设置缓存
CacheLess.$set("key", "this is cache string");
// 读取缓存,如果是一天之前的缓存返回为null
CacheLess.$get("key", 1000*60*60*24);
  • DisplayLess
// 获取屏幕宽度,高度
DisplayLess.$width(this);
DisplayLess.$height(this);
// 转换dp为ps
DisplayLess.$dp2px(100);
// 是否为平板
DisplayLess.$tablet(this);
  • EncodeLess
// md5加密字符串
// Before
byte[] hash;

try {
    hash = MessageDigest.getInstance("MD5").digest(string.getBytes("UTF-8"));
} catch (NoSuchAlgorithmException e) {
    e.printStackTrace();
    return null;
} catch (UnsupportedEncodingException e) {
    e.printStackTrace();
    return null;
}

StringBuilder hex = new StringBuilder(hash.length * 2); 
for (byte b : hash) {
    if ((b & 0xFF) < 0x10)
        hex.append("0");
    hex.append(Integer.toHexString(b & 0xFF));
}

result = hex.toString();
// After
EncodeLess.$md5("string");
Clone this wiki locally