Skip to content

Instantly share code, notes, and snippets.

View haohaozaici's full-sized avatar
🌸working

haohao haohaozaici

🌸working
View GitHub Profile
@haohaozaici
haohaozaici / humanReadableByteCount.java
Last active January 3, 2018 05:29
humanReadableByteCount
public static String humanReadableByteCount(long bytes, boolean si) {
int unit = si ? 1000 : 1024;
if (bytes < unit) return bytes + " B";
int exp = (int) (Math.log(bytes) / Math.log(unit));
String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp-1) + (si ? "" : "i");
return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre);
}
//example outputs
SI BINARY
private final static char[] hexArray = "0123456789ABCDEF".toCharArray();
public static String bytesToHex(byte[] bytes) {
char[] hexChars = new char[bytes.length * 2];
for ( int j = 0; j < bytes.length; j++ ) {
int v = bytes[j] & 0xFF;
hexChars[j * 2] = hexArray[v >>> 4];
hexChars[j * 2 + 1] = hexArray[v & 0x0F];
}
return new String(hexChars);
}
/**
* 用AudioManager获取音频焦点避免音视频声音重叠问题
*/
public class AudioFocusManager {
private static final String TAG = "AudioFocusManager";
private Context mContext;
private AudioManager mAudioManager;
private AudioManager.OnAudioFocusChangeListener mAudioFocusChangeListener;
package fi.veetipaananen.android.disableflagsecure;
import android.os.Build;
import android.view.SurfaceView;
import android.view.Window;
import android.view.WindowManager;
import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedHelpers;
@haohaozaici
haohaozaici / AutoRotationUtil.java
Created December 30, 2019 08:25
android屏幕旋转
import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.os.Build;
import android.provider.Settings;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import android.view.OrientationEventListener;
import android.view.Surface;
// 饿汉式
class Singleton {
private static final Singleton ourInstance = new Singleton();
static Singleton getInstance() {
return ourInstance;
}
private Singleton() {
}