Skip to content

Instantly share code, notes, and snippets.

@unclechen
unclechen / PxUtils.java
Last active January 15, 2016 01:47
PxUtils
package com.tiktokview.utils;
import android.content.Context;
/**
* dp,sp和px互转工具类
* Created by noughtchen on 2015/12/2.
*/
public class PxUtils {
@unclechen
unclechen / RoundRectShapeBackground.java
Created February 29, 2016 06:59
动态设置圆角矩形背景,可以给TextView或者ViewGroup绘制圆角矩形背景,并设置颜色
//1. 先新建一个圆角矩形,并包装成一个ShapeDrawable
ShapeDrawable backgroundDrawable = new ShapeDrawable(new RoundRectShape(new float[] {10, 10, 10, 10, 10, 10, 10, 10},
null, null));
//2. 设置背景颜色
backgroundDrawable.getPaint().setColor(Color.parseColor("#1fbaf3"));
//3. 设置透明度
backgroundDrawable.setsetAlpha(100);
/**
* 检查图片是否损坏:通过指定inJustDecodeBounds = true来得到解析图片以后的Options
*
* @param filePath
* @return
*/
public static boolean checkImgDamage(String filePath) {
BitmapFactory.Options options = null;
if (options == null) {
options = new BitmapFactory.Options();
@unclechen
unclechen / workspace.xml
Created March 31, 2016 02:31
通过修改“yourproject/.idea/workspace.xml”来配置ignore文件
/** 手动到项目下的”./idea"文件夹中配置 */
<component name="ChangeListManager">
...
<ignored path="android.iws" />
<ignored path=".idea/workspace.xml" />
<ignored mask="*.iml" />
<ignored path="gradle/" />
<ignored path="build/" />
<ignored path=".idea/" />
<ignored path="YourModuleA/build/" />
/**
* 获取当前连接到的WiFi名称
*
* 注意:当“APILevel >=17”时,返回的字符串会多一对双引号
* https://code.google.com/p/android/issues/detail?id=40144
* http://stackoverflow.com/questions/13563032/jelly-bean-issue-wifimanager-getconnectioninfo-getssid-extra
*/
public String getWifiSsid() {
String ssid = null;
try {
@unclechen
unclechen / AndroidMacAddress.java
Created October 12, 2016 10:27
Android上读取MAC地址的方法,兼容Android M
// hacking mac
public static String getMacAddress(Context context) {
String macAddress = null;
try {
String wifiInterfaceName = "wlan0";
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
while (interfaces.hasMoreElements()) {
NetworkInterface iF = interfaces.nextElement();
if (iF.getName().equalsIgnoreCase(wifiInterfaceName)) {
byte[] addr = iF.getHardwareAddress();
@unclechen
unclechen / getDate.js
Created May 2, 2017 09:12
js获取`yymmdd`格式的日期
var path = require("path");
var currentDate = new Date();
var year = currentDate.getFullYear();
var month = currentDate.getMonth() + 1;
month = month < 10 ? '0' + month : month;
var day = currentDate.getDate();
day = day < 10 ? '0' + day : day;
var date = year + month + day;
console.log(date);