Skip to content

Instantly share code, notes, and snippets.

View TedaLIEz's full-sized avatar

Jian Guo TedaLIEz

  • Microsoft, Suzhou
  • Wuhan, Hubei, China
View GitHub Profile
@TedaLIEz
TedaLIEz / DimPopupWIndow.kt
Created April 1, 2020 06:31
Show popupwindow with dim background
fun PopupWindow.dimBehind(dim: Float = 0.3f) {
val container: View = contentView.rootView
val context = contentView.context
val wm = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager;
val p = container.layoutParams as WindowManager.LayoutParams;
p.flags = p.flags or WindowManager.LayoutParams.FLAG_DIM_BEHIND; // add a flag here instead of clear others
p.dimAmount = dim
wm.updateViewLayout(container, p);
}
@TedaLIEz
TedaLIEz / CenterVerticalImageSpan.java
Created January 10, 2020 02:56
center_vertical image span
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.text.style.ImageSpan;
import androidx.annotation.Px;
public class CenterVerticalImageSpan extends ImageSpan {
@TedaLIEz
TedaLIEz / memory_layout.md
Created November 15, 2017 03:13 — forked from CMCDragonkai/memory_layout.md
Linux: Understanding the Memory Layout of Linux Executables

Understanding the Memory Layout of Linux Executables

Required tools for playing around with memory:

  • hexdump
  • objdump
  • readelf
  • xxd
  • gcore
@TedaLIEz
TedaLIEz / f-bounded.java
Created August 31, 2017 03:29
F-bounded style
/**
* If the return type must be the type of the class that implements the interface,
* then what you want is called an F-bounded type
*/
public interface A<T extends A<T>> {
public T b();
}
public class C implements A<C> {
public C b() { ... }
@TedaLIEz
TedaLIEz / build.gradle
Created February 22, 2017 15:11 — forked from vlad-kasatkin/build.gradle
jacoco task for espresso coverage
apply plugin: 'jacoco'
jacoco {
version "0.7.1.201405082137"
}
task jacocoTestReportAndroidTest(type: JacocoReport, dependsOn: "connectedAndroidTest") {
def coverageSourceDirs = [
'src/main/java'
]
group = "Reporting"
@TedaLIEz
TedaLIEz / IjkVideoView.java
Created January 16, 2017 08:33
FFplay *.ffconcat file in android example
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AlertDialog;
@TedaLIEz
TedaLIEz / AdbSocket.java
Created November 17, 2016 15:43
Socket using command adb forward to set up a tcp connection.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
@TedaLIEz
TedaLIEz / adapters_Animal.java
Last active September 26, 2016 09:24
My implementation of multiple type in RecyclerView.Adapter, refering to https://medium.com/@dpreussler/writing-better-adapters-1b09758407d2#.dsmf2nwjg, how to avoid if-else in onCreateViewHolder method?
package com.example.jianguo.handlertest.adapters;
/**
* Created by JianGuo on 9/26/16.
* interface for all kinds of animals.
*/
public interface Animal extends Visitable {
String say();
}
@TedaLIEz
TedaLIEz / CustomTypeAdapter.java
Created August 30, 2016 02:02 — forked from cmelchior/CustomTypeAdapter.java
Realm, GSON and primitive JSON arrays
// Make a custom Gson instance, with a custom TypeAdapter for each wrapper object.
// In this instance we only have RealmList<RealmInt> as a a wrapper for RealmList<Integer>
Type token = new TypeToken<RealmList<RealmInt>>(){}.getType();
Gson gson = new GsonBuilder()
.setExclusionStrategies(new ExclusionStrategy() {
@Override
public boolean shouldSkipField(FieldAttributes f) {
return f.getDeclaringClass().equals(RealmObject.class);
}