xutils使用post上传base64图片的时候的问题

utils的网络部分,其实比较简单,但是也是有坑,比如在post一些比较长的参数值的时候就会报错。

x.http().post 这个会想当然认为就是指定了post,其实不完全,
requestParams.addBodyParameter(key, value)里,默认是GET方式的body,也就是附到url上变成get方式的参数形式,也就导致了长的参数值会报错,比较url不支持那么长的值。

所以解决方法就是:requestParams.setMethod(HttpMethod.POST);
将requestParams变成post方式的键值对。

ps:requestParams.toString也不要随便调,会把参数值附到url上的。

利用BitmapShader来降低自定义view动画效果的难度

基本思路:当遇到某个复杂的动画(基础图片是重复元素)的时候,先分解,把静态的东西写进bitmap,然后利用bitmap生成BitmapShader。此时,可以使用matrix对这个bitmap进行变换,同时也有利于合成更复杂的动画。

代码如下:

Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);

//…把简单元素画进bitmap变成复杂元素

BitmapShader
 mWaveShader = new BitmapShader(bitmap, Shader.TileMode.REPEAT, Shader.TileMode.CLAMP);
Paint mViewPaint.setShader(mWaveShader);

Matrix shaderMaxtrix = new Matrix();//矩阵
shaderMaxtrix.postTranslate(dx, 0);
mWaveShader.setLocalMatrix(shaderMaxtrix); //变换

canvas.drawRect(0, 0, 1440, 300, mViewPaint);

自定义view用到的几种定时刷新方法

1、定时器刷新法,使用timer,timertask,在合适的地方初始化,然后调用

Timer timer = new Timer(); TimerTask timerTask = new TimerTask() { @Override public void run() { //具体处理代码 postInvalidate(); } }; timer.schedule(timerTask, 0, 50);

2、使用view内部的延迟刷新方法

public void draw(Canvas canvas) {
postDelayed(new Runnable() { @Override public void run() { //具体处理代码 postInvalidate(); } }, 50);
super.draw(canvas);
}

3、利用属性动画对view里的某个属性进行赋值来实现动画效果

ObjectAnimator waveShiftAnim = ObjectAnimator.ofFloat( mWaveView, "waveShiftRatio", 0f, 1f); waveShiftAnim.setRepeatCount(ValueAnimator.INFINITE); waveShiftAnim.setDuration(1000); waveShiftAnim.setInterpolator(new LinearInterpolator()); animators.add(waveShiftAnim);

去掉android5.0以上button默认的阴影

1、在button的xml属性里加入
<button
style="?android:attr/borderlessButtonStyle" >
</button

2、如果button已经写成style了,就让button的style继承Widget.AppCompat.Button.Borderless

<style name="btnStyle" parent="Widget.AppCompat.Button.Borderless">
`</style
`

使用viewpager注意几个有用的点

背景:做一个图片切换器
做法:使用普通PagerAdapter 与 view pager来做,配合view集合
要点:以下几个神奇的东西

// 设置一开始初始化的页面个数
mVpCarInfo.setOffscreenPageLimit(Math.min(mPageCarViews.size(), 5));

// 点击延伸到背后的容器 mLlPageCarContainer.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return mVpCarInfo.dispatchTouchEvent(event); } });

// 显示完整,不剪掉子view mLlPageCarContainer.setClipChildren(false); mVpCarInfo.setClipChildren(false);

// 拖动不要出现边界黑色边框 mVpCarInfo.setOverScrollMode(View.OVER_SCROLL_NEVER);

JAVA使用futureTask时候注意的坑

在call里面不要用try catch

FutureTask mListenTask = new FutureTask(new Callable() {
    @Override
    public Object call() throws Exception {
// 注意这里面如有需要用轮询做一些事情的话,使用Thread.sleep的时候要注意不要try catch。不然的话,结果会表现为永远cancel不掉这个线程。因为本事用Exception去结束这个线程,却被我们try catch了。
// 代码
Thread.sleep(1000);
// 代码
   }
});

ThreadPoolUtils.execute(futureTask);
ThreadPoolUtils.cancel(futureTask);

删掉 try catch代码后发现现在可以cancel这个FutureTask了。

nexus6 7.0的root方法

详情请看:

https://dottech.org/202068/how-to-root-google-nexus-6-on-android-7-0-with-supersu/

Download the TWRP Recovery and extract it in the Downloads folder on the computer.
Set up the ADB for Windows on the computer and then come back and continue with this guide when that one is complete.
Install the ADB Driver on the computer so that the ADB commands you run can do so without any trouble.
Download the SuperSU but do not extract it.
Connect the Google Nexus 6 smartphone to the computer with the USB cable that is used for charging the battery of the device.
Open the Downloads folder to find the SuperSU and copy it over to the internal storage SD card folder for the Google Nexus 6 smartphone.
Copy all of the TWRP files from the Downloads folder so the same folder as the ADB, so you have everything available from the same directory.
Hold the Shift key available on the keyboard and right-click the mouse where it is white in the background of the ADB folder and choose to open a new command window here from the menu.
Type the command “adb reboot bootloader” to get the Google Nexus 6 smartphone into the Bootloader Mode that is a required before flashing the custom recovery image on the smartphone.
Type the command “fastboot flash recovery twrp-3.0.2-0-shamu.img” to have the custom recovery image flashed onto the Google Nexus 6 smartphone.
Type the command “adb reboot” to get back into normal mode and as soon as you can see the smartphone reboot you need to hold down the hardware key combination to boot directly into the Recovery Mode now and the custom recovery boots up.
Tap on the Install button and then follow the guidelines to install the SuperSU from the SD card.
Choose the reboot option followed by the System option to reboot the system back into the normal mode and continue using the device as you typically would but this time you now have the root access and the custom recovery image installed.

Read more at https://dottech.org/202068/how-to-root-google-nexus-6-on-android-7-0-with-supersu/#YJoe7U3o84bWIcYg.99

需要下载的文件

SuperSU-v2.78-201609011115.zip

https://www.androidfilehost.com/?w=file-thanks&fid=24694152805484203&mid=140&download_id=32a9d921c010776bda8ffb813a3a2e2b&tid=1481851118&hc=f65965d40223e634e53fc26b41fc7eee873dd1ef17bc87a67e07326856425084

twrp-3.0.2-0-shamu.img

https://www.androidfilehost.com/?w=file-thanks&fid=24499762635998144&mid=150&download_id=32a9d921c010776bda8ffb813a3a2e2b&tid=1481851144&hc=815ecb8f13ffc1df2938c8990071cf7cbe8dd5c7b923ebeb28952c8eeb4ee9a0

关于微信公众号UnionId的认识

公众号或者小程序,在同一个微信开放平台下的UnionId是唯一的。如果没有在开发平台里面绑定公众号或者小程序,是无法获取到UnionId的,只有绑定了后,返回的接口才会出现UnionId。