Skip to content

Instantly share code, notes, and snippets.

View lgyjg's full-sized avatar
🎯
Focusing

JianGuo Yang lgyjg

🎯
Focusing
View GitHub Profile
@lgyjg
lgyjg / translation_replace.sh
Created June 12, 2016 03:35
批量替换文件中的字符串的shell脚本命令
#restore_cancel 代表需要过滤的字符串关键字
# <string name="restore_cancel">@android:string\/cancel<\/string>/g 代表含有该关键字字符串的行该替换成什么样.
# res 代表查找路径
sed -i 's/^.*restore_cancel.*$/ <string name="restore_cancel">@android:string\/cancel<\/string>/g' `grep restore_cancel -rl res`
@lgyjg
lgyjg / gist:381b48734a6b8d9fd62fa00898d54d4c
Created April 15, 2017 14:17
获取手机号码\获取手机运营商
public class SIMCardInfo {
/**
* TelephonyManager提供设备上获取通讯服务信息的入口。 应用程序可以使用这个类方法确定的电信服务商和国家以及某些类型的用户访问信息。
* 应用程序也可以注册一个监听器到电话收状态的变化。不需要直接实例化这个类
* 使用Context.getSystemService(Context.TELEPHONY_SERVICE)来获取这个类的实例。
*/
private TelephonyManager telephonyManager;
/**
* 国际移动用户识别码
*/
@lgyjg
lgyjg / FibonacciView.java
Last active April 28, 2017 08:37
用点绘制黄金螺旋线
private void drawWithPoint(Canvas canvas, int deep) {
float x0 = this.getMeasuredWidth() / 2;
float y0 = this.getMeasuredHeight() / 2;
paint.setColor(Color.BLACK);
for (int i = 0; i < 6145; i++) {
double angle = i * Math.PI / 512;
double radius = 0.3 * angle;
int y = (int) Math.round(radius * angle * Math.cos(angle));
int x = (int) Math.round(radius * angle * Math.sin(angle));
canvas.drawPoint(x0 + x, y0 + y, paint);
@lgyjg
lgyjg / SaveBitmap.java
Last active April 28, 2017 10:34
save bitmap object to sdcard to test
// need permission
// <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
// <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
public void saveMyBitmap(Bitmap mBitmap,String bitName) {
File f = new File( "/sdcard/Test/"+bitName + ".jpg");
FileOutputStream fOut = null;
try {
fOut = new FileOutputStream(f);
mBitmap.compress(Bitmap.CompressFormat.JPEG, 100, fOut);
@lgyjg
lgyjg / LogBigBitmap.java
Created May 25, 2017 07:52
加载大图
public static int calculateInSampleSize(
BitmapFactory.Options options, int reqWidth, int reqHeight) {
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
final int halfHeight = height / 2;
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.itextpdf.text.Document;
@lgyjg
lgyjg / gist:c65460bc3c9f17b4fc8a9839a04753ad
Last active October 30, 2017 11:56
java 实现 Bitmap 转 YUV 数据
/**
* YUV420sp
*
* @param inputWidth
* @param inputHeight
* @param scaled
* @return
*/
public static byte[] getYUV420sp(int inputWidth, int inputHeight, Bitmap scaled) {
Log.d(TAG, "getYUV420sp: start");
@lgyjg
lgyjg / CameraStreamConfigurations.java
Last active August 17, 2018 13:03
get CustomStreamConfigurationMap with a custom CameraCharacteristics Key
package com.example.util;
import android.annotation.SuppressLint;
import android.hardware.camera2.CameraCharacteristics;
import android.hardware.camera2.params.StreamConfigurationMap;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
@lgyjg
lgyjg / YUV2RGB.cpp
Created August 20, 2018 04:34
YUV2RGB
static inline uint32_t YUV2RGB(int nY, int nU, int nV) {
nY -= 16;
nU -= 128;
nV -= 128;
if (nY < 0) nY = 0;
// This is the floating point equivalent. We do the conversion in integer
// because some Android devices do not have floating point in hardware.
// nR = (int)(1.164 * nY + 1.596 * nV);
// nG = (int)(1.164 * nY - 0.813 * nV - 0.391 * nU);