Skip to content

Instantly share code, notes, and snippets.

AppCompat-v7:21 provides a very useful way of dealing with pressed/focused/activated states maintaining backwards compatibility downto API-7, but there's a small issue (big for some) with the default selectableItemBackground: It uses some PNGs and/or default values for API<21.
The main reason is that android drawable resource definitions (prior API 21) CANNOT use theme attributes at all, so there's no way of making something like:
<shape android:shape="rectangle">
<solid android:color="?attr/colorControlHighlight" />
</shape>
For this, I've put this simple mockup on how to give your app better drawables that the appcompat defaults.
@shau-lok
shau-lok / Parcelable.java
Created June 12, 2016 03:52
Parcelable sample
public class MyParcelable implements Parcelable {
private int mData;
public int describeContents() {
return 0;
}
public void writeToParcel(Parcel out, int flags) {
out.writeInt(mData);
}
/**
* @param originalColor color, without alpha
* @param alpha from 0.0 to 1.0
* @return
*/
public static String addAlpha(String originalColor, double alpha) {
long alphaFixed = Math.round(alpha * 255);
String alphaHex = Long.toHexString(alphaFixed);
if (alphaHex.length() == 1) {
alphaHex = "0" + alphaHex;
@shau-lok
shau-lok / time_dealing.py
Last active October 30, 2016 14:09
时间处理
# 2016-10-30T14:02:48.269Z
from datetime import datetime, timedelta
def generate_timestamp(self):
# now = arrow.now()
# now.to('GMT')
# now.format("YYYY-MM-dd'T'HH:mm:ss.SSSZZ")
date_format = "%Y-%m-%dT%H:%M:%S.%f"
now = datetime.utcnow().strftime(date_format)
now = str(now)[0:-3]
return now + "Z"
@shau-lok
shau-lok / aes_python3.py
Created December 26, 2016 14:52
AES/ECB/PKCS#7加密 (python实现)
import base64
import json
from Crypto import Random
from Crypto.Cipher import AES
from star_site import settings
class AESCrypt:
@shau-lok
shau-lok / test_pickle.py
Created January 6, 2017 02:52
python serializer save redis
class TestPickle(unittest.TestCase):
def test_pickle_unpickle(self):
cache_key = 'just_test_pickle'
_redis = redis.StrictRedis(host='localhost', port=6379, db=0)
session = Session()
session.cookies['Heee'] = 'adc'
session.cookies.update({
@shau-lok
shau-lok / Python_requests.md
Created January 19, 2017 03:49
requests的存下来的一些用法

Requests - Python

get请求

r = requests.get('https://api.github.com/events')

post请求

@shau-lok
shau-lok / python_xml.md
Created January 19, 2017 06:20
python xml处理

xml 的处理

1. 解析xml

xml_data

<Response>
    <Body>
@shau-lok
shau-lok / python_byte2str.py
Created May 2, 2017 03:56
python byte to string
# 将byte转换成str
# byte_sample = b'xxxxxxxxxxx' -----> 'xxxxxxxxxxxxxx'
byte_sample = b'abcde'
byte2str = byte_sample.decode("utf-8")
print(byte2str) #abcde
@shau-lok
shau-lok / tornado_unitest_sample.py
Last active May 2, 2017 04:16
tornado单元测试
from tornado.httpclient import AsyncHTTPClient
from tornado.testing import AsyncTestCase, gen_test
URL = 'http://www.tornadoweb.org'
class MyTestCase(AsyncTestCase):
@gen_test
def test_http_fetch(self):
client = AsyncHTTPClient(self.io_loop)