Skip to content

Instantly share code, notes, and snippets.

@pythoncat1024
pythoncat1024 / decorator_learning
Created July 1, 2017 16:14
python decorator function
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @name : log_args.py
# @author : cat
# @date : 2017/7/1.
import logging
def upper(text):
@pythoncat1024
pythoncat1024 / git_shell
Created August 2, 2017 15:11 — forked from ladder1984/git_shell
python执行git命令并得到结果
def git_shell(git_command):
try:
return os.popen(git_command).read().strip()
except:
return None
@pythoncat1024
pythoncat1024 / ViewFragment.java
Created December 1, 2018 06:54
字母跳动动画
TextView tvChar = view.findViewById(R.id.char_tv);
ValueAnimator animator = ValueAnimator.ofObject((fraction, startValue, endValue) -> {
char start = (Character) startValue;
char end = (Character) endValue;
return (int) (start + (end - start) * fraction);
}, 'A', 'Z');
animator.addUpdateListener(animation -> {
int s = (Integer) animation.getAnimatedValue();
@pythoncat1024
pythoncat1024 / ViewFragment.java
Created December 1, 2018 13:10
对字母的玩弄
CharTextView tvChar = view.findViewById(R.id.char_tv);
tvChar.setCharText('X');
PropertyValuesHolder charHolder = PropertyValuesHolder.ofObject("CharText",
new CharEvaluator(), 'A', 'Z');
charHolder.setKeyframes(Keyframe.ofObject(0, 'A'),
Keyframe.ofObject(0.1f, 'M'),
Keyframe.ofObject(0.5f, 'G'),
Keyframe.ofObject(0.8f, 'M'),
Keyframe.ofObject(1f, 'Z')
);
@pythoncat1024
pythoncat1024 / ViewFragment.java
Created December 1, 2018 13:52
电话响了,左右晃动效果(模拟不到位)
View callRing = view.findViewById(R.id.iv_call_ring);
PropertyValuesHolder rotationH = PropertyValuesHolder.ofFloat("rotation",
-60f, -10f, 0, 60f, 0f);
PropertyValuesHolder scaleXH = PropertyValuesHolder.ofFloat("scaleX",
1.0f, 0.7f, 1.2f, 1, 0.3f, 1f);
scaleXH.setKeyframes(Keyframe.ofFloat(0, 1f),
Keyframe.ofFloat(0.3f, 0.4f),
Keyframe.ofFloat(0.5f, 2f),
Keyframe.ofFloat(0.8f, 0.8f),
Keyframe.ofFloat(1f, 1f)
@pythoncat1024
pythoncat1024 / ViewFragment.java
Created December 1, 2018 15:35
viewgroup item add/remove 时的动画
ListView lv = view.findViewById(R.id.list_view);
ArrayAdapter<String> adapter = new ArrayAdapter<>(lv.getContext(),
android.R.layout.simple_expandable_list_item_1);
adapter.addAll(getResources().getStringArray(android.R.array.postalAddressTypes));
lv.setAdapter(adapter);
view.findViewById(R.id.btn_add)
.setOnClickListener(v -> {
int bound = adapter.getCount() - 1;
bound = bound <= 1 ? 1 : bound;
@pythoncat1024
pythoncat1024 / TextUI.java
Created December 5, 2018 15:21
根据指定中线,居中绘制文字
public class TextUI extends View {
private Paint textPaint;
private Paint ascentPaint;
private Paint descentPaint;
private Paint topPaint;
private Paint bottomPaint;
private Paint basePaint;
private Paint rectPaint;
@pythoncat1024
pythoncat1024 / any.js
Last active December 7, 2018 02:02
清除 csdn 博客页面的右边侧栏
console.clear();
right = document.getElementsByClassName('recommend-fixed-box');
for(var index = right.length-1;index>=0;index--){
right[index].remove();
}
@pythoncat1024
pythoncat1024 / nothing
Created December 7, 2018 02:11
idea 查看 api 快捷键
mac: command + j
win: ctrl + q
@pythoncat1024
pythoncat1024 / FlowLayout.java
Created December 22, 2018 19:36
自定义 viewGroup 在 onMeasure 以及 onLayout 的时候,可以知道 itemView 是否设置了 match_parent 属性
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int ws = MeasureSpec.getSize(widthMeasureSpec);
int wm = MeasureSpec.getMode(widthMeasureSpec);
int hs = MeasureSpec.getSize(heightMeasureSpec);
int hm = MeasureSpec.getMode(heightMeasureSpec);
boolean needMaxWidth = false;
boolean needMaxHeight = false;
this.maxWidth = ws;