Android播放本地音频

在java同级创建assets文件夹,将音频文件放在里面

/**
 * 播放本地音频
 *
 * @param path "hello.mp3" / "mp3/hello.mp3"
 */
private void startVoice(String path) {
    try {
        AssetFileDescriptor assetFileDescriptor = getAssets().openFd(path);
        MediaPlayer mediaPlayer = new MediaPlayer();
        mediaPlayer.setDataSource(assetFileDescriptor.getFileDescriptor(), assetFileDescriptor.getStartOffset(), assetFileDescriptor.getLength());
        mediaPlayer.prepare();
        mediaPlayer.start();
    } catch (Exception e) {

    }
}

Android Studio git log 中文乱码

输入以下三行命令即可

git config --global i18n.commitencoding utf-8
git config --global i18n.logoutputencoding utf-8
set LESSCHARSET=utf-8

Nginx+PHP

安装nginx 和 php

apt install nginx php-fpm

配置php端口
/etc/php/7.0/fpm/pool.d/www.conf,36行附近

;listen = /run/php/php7.0-fpm.sock
listen = 127.0.0.1:9001

配置nginx,动静分离

- 阅读全文 -

自定义View重新设置大小

使用setMeasure方法是无效的

setMeasuredDimension(width, height);

如果想设置,可以用LayoutParams

ConstraintLayout.LayoutParams layoutParams = (ConstraintLayout.LayoutParams) getLayoutParams();
layoutParams.width = (int) mPaint.measureText("Do you like waht you see?");
setLayoutParams(layoutParams);

现在想是蠢了点,setMeasure是用来测量控件大小的,肯定是没用的

Fragment里onActivityResult()的坑

在Fragment里启动Activity,回来时,会先走Fragment的父Activity的onActivityResult()方法,然后通过父Activity里的onActivityResult()方法里的super(),来调用自己的onActivityResult()方法

简单来说就是Activity里不要屏蔽onActivityResult()的super()方法即可,或者干脆不要重写onActivityResult()

如果没收到看看是不是粗心忘记startActivityForResult()

ScrollView和RecyclerView滑动冲突的坑

重写ScrollView即可

public class MyScrollView extends ScrollView {
    private float mLastXIntercept = 0f;
    private float mLastYIntercept = 0f;

    public MyScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        boolean intercepted = false;
        float x = ev.getX();
        float y = ev.getY();
        int action = ev.getAction() & MotionEvent.ACTION_MASK;
        switch (action) {
            case MotionEvent.ACTION_DOWN: {
                intercepted = false;
                // 初始化mActivePointerId
                super.onInterceptTouchEvent(ev);
                break;
            }
            case MotionEvent.ACTION_MOVE: {
                // 横坐标位移增量
                float deltaX = x - mLastXIntercept;
                // 纵坐标位移增量
                float deltaY = y - mLastYIntercept;
                if (Math.abs(deltaX) < Math.abs(deltaY)) {
                    intercepted = true;
                } else {
                    intercepted = false;
                }
                break;
            }
            case MotionEvent.ACTION_UP: {
                intercepted = false;
                break;
            }
        }
        mLastXIntercept = x;
        mLastYIntercept = y;
        return intercepted;
    }
}

用NestScrollView也可以解决,但是代码截屏时会发现有问题。
用这个,既可以解决滑动冲突,又可以解决截屏出问题。

adb批量安装apk

Windows命令行下是这样的,Linux自己写

@echo off

echo 开始安装...

for /f "delims=" %%i in ('dir/b/a-d %~dp0\*.apk') do (
    echo 正在安装: %%i
    adb install "%~dp0\%%i"
)

echo 全部安装完成

pause

将所有.apk和上面的.bat都放在同一个文件夹下,运行上面的.bat即可