Skip to content

Instantly share code, notes, and snippets.

@foundkey
foundkey / textBound.java
Created November 5, 2018 04:24
Calc Text bound
String str = "Hello World";
Paint calcTextRect = new Paint();
String familyName = “宋体”;
Typeface font = Typeface.create(familyName,Typeface.BOLD);
calcTextRect.setTypeface(font); // 设置字体
calcTextRect.setColor(Color.RED); // 设置颜色
calcTextRect.setTextSize(22); // 设置字体大小
Rect rect = new Rect();
calcTextRect.getTextBounds(str, 0, 1, rect);
@foundkey
foundkey / traversalXML.java
Last active November 7, 2018 05:37
使用DOM方式,遍历XML文件
public static void traversalXMLFile(String uri) throws Exception {
StringBuilder result = new StringBuilder();
result.append("File: ").append(uri).append("\n");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(uri);
Element rootElement = doc.getDocumentElement();
// check root element
@foundkey
foundkey / backTitle.java
Last active November 27, 2018 10:17
标题栏显示返回按钮
package com.toby.personal.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MenuItem;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
@foundkey
foundkey / filterAPK.bat
Last active December 29, 2018 06:49
copy special type file to targe folder
::复制指定类型的文件到同一个文件夹
::2018-12-19
::FK
@echo off
setlocal enabledelayedexpansion
set DIR=%~pn1
set /p Type= filter file extension:
@foundkey
foundkey / SimpleServer.py
Last active April 10, 2019 08:05
Simple HTTP Server
from http.server import HTTPServer, BaseHTTPRequestHandler
import json
HOST = "127.0.0.1"
PORT = 8081
data = [ { 'a' : 'hello', 'b' : 'world', 'c' : 3, 'd' : 4, 'e' : 5 } ]
class RequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
netsh interface set interface "以太网" disabled
public static void getCurFun() {
Thread thread = Thread.currentThread();
StackTraceElement traceElement[] = thread.getStackTrace();
for (int i = 0; i < traceElement.length; ++i) {
System.out.println(i + ": " + traceElement[i].toString());
}
}
@foundkey
foundkey / ConfigNDKEnv.bat
Last active January 17, 2019 11:13
设置交叉编译arm原生程序的环境
:: 用于cmake编译arm原生程序前设置环境变量
:: 使用Android SDK自带的cmake工具(cmake官网版本不支持Android平台)
@set path=D:\Android\Sdk\cmake\3.6.4111459\bin;%path%
:: 该文件用于配置NDK的编译工具链
@set TOOLCHAIN_FILE=D:\Android\Sdk\ndk-bundle\build\cmake\android.toolchain.cmake
:: 编译工具
@set MAKE_PROGRAM=D:\Android\Sdk\cmake\3.6.4111459\bin\ninja.exe
:: NDK路径
@set ANDROID_NDK=D:\Android\Sdk\ndk-bundle
@echo off
set ToolDir="D:\Android\Sdk\build-tools\27.0.3"
set path=%ToolDir%;%path%
chcp 65001
set /p APK="Input apk full path:"
aapt dump badging %APK%
pause
package com.foundkey.example;
import javax.crypto.*;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.security.*;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.Base64;