Skip to content

Instantly share code, notes, and snippets.

View ongakuer's full-sized avatar

relex ongakuer

  • Beijing , China
  • 02:27 (UTC +08:00)
View GitHub Profile
@ongakuer
ongakuer / MainActivity.java
Created September 12, 2016 04:57
Show PopupWindow in Immersive Sticky mode
public class MainActivity extends AppCompatActivity {
private PopupWindow mPopupWindow;
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
int windowWidth = 480;
int windowHeight = 120;
@ongakuer
ongakuer / MathUtil.java
Last active January 16, 2019 15:14
Smooth LinearGradient
public class MathUtil {
public static float constrain(float min, float max, float v) {
return Math.max(min, Math.min(max, v));
}
public static float interpolate(float x1, float x2, float f) {
return x1 + (x2 - x1) * f;
}
public static float uninterpolate(float x1, float x2, float v) {
@ongakuer
ongakuer / NetworkRoundedImageView.java
Last active August 29, 2015 14:16
NetworkRoundedImageView
import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.ViewGroup;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.ImageLoader.ImageContainer;
import com.makeramen.RoundedImageView;
public class NetworkRoundedImageView extends RoundedImageView {
@ongakuer
ongakuer / gist:add32475478360251809
Created July 7, 2014 10:15
SquareFrameLayout (这个版本的测量考虑更全面)
/*
* Copyright (C) 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@ongakuer
ongakuer / gist:b531b3de0d389463e1fe
Last active August 29, 2015 14:02
proguard混淆后导致json解析出错
private void parseJson() {
String json = "{\"school\":{\"classes\": [{\"name\":\"one\",\"count\":1},{\"name\":\"two\",\"count\":2}],\"headMaster\" : \"Einstein\"}}";
ObjectMapper mapper = new ObjectMapper();
try {
ResponseModle response = mapper.readValue(json, ResponseModle.class);
Log.e(this.getClass().getName(), "headMaster : " + response.getSchool().getHeadMaster());
@ongakuer
ongakuer / gist:0ef96ebc7e89288590fd
Last active March 23, 2023 06:45
Android 测量字符宽度的几种方法和场景
mTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
TextPaint textPaint = mTextView.getPaint();
String source = "Lorem ipsum dolor sit amet";
// mTextView的宽度作为参考值
mTextView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
int textViewWidth = mTextView.getMeasuredWidth();