$checkers=$checker_model->getCurrentFlowChecker($id,$simple_check_id); $pass=array_count_values(array_column($checkers->toArray(),'status')); //返回数组中status 的值的数量 var_dump($checkers->toArray()); var_dump($pass); exit;
Laravel 使用with 限定条数
$type = Arr::get($data, 'queue_type');
$limit = Arr::get($data, 'limit', 5);
$list = DingProduceQueueWorker::leftJoin('ding_staff', 'ding_staff.id', '=', 'ding_produce_queue_worker.worker_id')
->with(['queue' => function ($q) use ($type) {
$q->where('ding_produce_queue.type', $type);
}])
->selectRaw('ding_produce_queue_worker.worker_id,ding_staff.name,ding_staff.avatar,ding_staff.status as staff_status,ding_produce_queue_worker.num')
->where('type', $type)
// ->where('num','>',0)
->orderByDesc('num')
->get()
->map(function ($item) use($limit){
$item->setRelation('queue', $item->queue->take($limit));
return $item;
});
return $list;
php根据简称获取时间段
/**
* 根据简称获取时间段
* 今天、本周、本月、本季度、本年
* @param $short 'today', 'week', 'lweek', 'month', 'lmonth', 'season','year'
* @return array
*/
public static function getShortDate($short)
{
//'today'今天, 'week'本周, 'lweek'上周, 'month'本月, 'lmonth'上月,'season'本季度, 'year'本年
$short_array = ['today', 'week', 'lweek', 'month', 'lmonth', 'season','year'];
if (!in_array($short, $short_array)) {
return [];
}
$date=date('Y-m-d H:i:s');
$start_time = '';
$end_time = '';
switch ($short) {
case 'today':
$start_time = date("Y-m-d 00:00:00");
$end_time = date("Y-m-d 23:59:59");
break;
case 'week':
$start_time = date("Y-m-d H:i:s", mktime(0, 0, 0, date("m"), date("d") - date("w") + 1, date("Y")));
$end_time = date("Y-m-d H:i:s", mktime(23, 59, 59, date("m"), date("d") - date("w") + 7, date("Y")));
break;
case 'lweek':
$start_time = date("Y-m-d H:i:s", mktime(0, 0, 0, date("m"), date("d") - date("w") + 1 - 7, date("Y")));
$end_time = date("Y-m-d H:i:s", mktime(23, 59, 59, date("m"), date("d") - date("w") + 7 - 7, date("Y")));
break;
case 'month':
$start_time= date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),1,date("Y")));
$end_time= date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("t"),date("Y")));
break;
case 'lmonth':
$start_time= date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m")-1,1,date("Y")));
$end_time= date("Y-m-d H:i:s",mktime(23,59,59,date("m") ,0,date("Y")));
break;
case "season":
$season = ceil(date('n',strtotime($date)) /3); //获取月份的季度
$start_time = date('Y-m-01 00:00:00',mktime(0,0,0,($season - 1) *3 +1,1,date('Y')));
$end_time = date('Y-m-t 23:29:29',mktime(0,0,0,$season * 3,1,date('Y')));
break;
case 'year':
$start_time = date("Y-01-01 00:00:00", strtotime($date));
$end_time = date("Y-12-31 23:59:59", strtotime($date));
break;
default:
break;
}
$bewteen = ['start_time' => $start_time, 'end_time' => $end_time];
return $bewteen;
}
Cannot inline bytecode built with JVM target 1.8 into bytecode that is being built with JVM target 1.6. Please specify proper ‘-jvm-target’ option
在fragment中使用如下代码,报错
import androidx.fragment.app.viewModels
private val levelMapViewModel: LevelMapViewModel by viewModels()
1.添加依赖
implementation 'androidx.navigation:navigation-fragment-ktx:2.2.2'
2.添加设置
kotlinOptions { // work-runtime-ktx 2.1.0 and above now requires Java 8 jvmTarget = "1.8" }
3.查看IDE
更新Gradle,解决!
Processing did not complete. See error above for details
在使用HiltAndroidApp时报错 Processing did not complete. See error above for details 解决方法
Task :app:kaptDebugKotlin FAILED /Users/luchanglong/work/android/Pinpintu/app/build/tmp/kapt3/stubs/debug/com/ppt/pinpintu/PptApp.java:19: 错误: [Hilt] public final class PptApp extends android.app.Application { ^ Expected @HiltAndroidApp to have a value. Did you forget to apply the Gradle Plugin? (dagger.hilt.android.plugin) See https://dagger.dev/hilt/gradle-setup.html [Hilt] Processing did not complete. See error above for details.警告: Binding adapter AK(android.widget.ImageView, java.lang.String) already exists for imageShowUrl! Overriding com.ppt.pinpintu.db.entity.RecordEntity#imageShowUrl with com.ppt.pinpintu.db.entity.ImageEntity#imageShowUrl警告: Binding adapter AK(android.widget.ImageView, java.lang.String) already exists for imageShowUrl! Overriding com.ppt.pinpintu.db.entity.RecordEntity#imageShowUrl with com.ppt.pinpintu.db.entity.ImageEntity#imageShowUrl警告: Binding adapter AK(android.widget.ImageView, java.lang.String) already exists for imageShowUrl! Overriding com.ppt.pinpintu.db.entity.ImageEntity#imageShowUrl with com.ppt.pinpintu.db.entity.Report#imageShowUrl警告: Binding adapter AK(android.widget.ImageView, java.lang.String) already exists for imageShowUrl! Overriding com.ppt.pinpintu.db.entity.ImageEntity#imageShowUrl with com.ppt.pinpintu.db.entity.Report#imageShowUrl[WARN] Incremental annotation processing requested, but support is disabled because the following processors are not incremental: androidx.room.RoomProcessor (DYNAMIC). Execution failed for task ':app:kaptDebugKotlin'. A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution java.lang.reflect.InvocationTargetException (no error message)
解决:在app/build.gradle 中将有arguments =xxxx 改为 arguments +=
如:
javaCompileOptions {
annotationProcessorOptions {
arguments += ["room.schemaLocation":
"$projectDir/schemas".toString()]
}
}
Android Java 使用SoundPool 播放各种音效
import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;
import android.util.SparseArray;
/**
* 点击声音类
*/
public class SoundManager {
private static SoundManager mSoundManager;
private SoundPool mSoundPool;
private AudioManager mAudioManager;
private SparseArray<Integer> mSoundPoolMap;
public static final int maxSounds = 4;
public static SoundManager getInstance(Context context) {
if (mSoundManager == null) {
mSoundManager = new SoundManager(context);
}
return mSoundManager;
}
public SoundManager(Context mContext) {
mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
mSoundPool = new SoundPool(maxSounds, AudioManager.STREAM_MUSIC, 0);
mSoundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
boolean loaded = true;
}
});
mSoundPoolMap = new SparseArray<Integer>();
mSoundPoolMap.put(0, mSoundPool.load(mContext, R.raw.click, 0));
mSoundPoolMap.put(1, mSoundPool.load(mContext, R.raw.success, 1));
mSoundPoolMap.put(2, mSoundPool.load(mContext, R.raw.change, 2));
mSoundPoolMap.put(3, mSoundPool.load(mContext, R.raw.click_up, 3));
mSoundPoolMap.put(4, mSoundPool.load(mContext, R.raw.click_down, 4));
}
public void playSound(int index) {
int streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
mSoundPool.play(mSoundPoolMap.get(index), streamVolume, streamVolume,
1, 0, 1f);
}
public static void clear() {
if (mSoundManager != null) {
mSoundManager.mSoundPool = null;
mSoundManager.mAudioManager = null;
mSoundManager.mSoundPoolMap = null;
}
mSoundManager = null;
}
}
//使用
SoundManager soundManagerr = new SoundManager(getContext());
soundManager.playSound(index);
android java 通过MusicService 播放背景音乐
1.在manifests.xml中添加
<service android:name=".utils.MusicService" android:enabled="true"/>
2.新建一个音乐类
import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Binder;
import android.os.IBinder;
/**
* MusicService 控制后台音乐播放
* 提供控制方法,在Activity中调用
*/
/*
public class MusicService extends Service implements MediaPlayer.OnErrorListener {
private final IBinder mBinder = new ServiceBinder(); //在Activity 使用Ibinder 对象与 MusicService 进行交互
MediaPlayer mediaPlayer;
private int length = 0;
public MusicService() {
//这里可以执行一些初始化
}
public class ServiceBinder extends Binder {
public MusicService getService() {
return MusicService.this;
}
}
@Override
public IBinder onBind(Intent arg0) {
return mBinder;
}
@Override
public void onCreate() {
super.onCreate();
mediaPlayer = MediaPlayer.create(this, R.raw.bg_main);
mediaPlayer.setOnErrorListener(this);
if (mediaPlayer != null) {
mediaPlayer.setLooping(true);
mediaPlayer.setVolume(100, 100);
}
mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
public boolean onError(MediaPlayer mp, int what, int
extra) {
onError(mediaPlayer, what, extra);
return true;
}
});
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
mediaPlayer.start();
return START_STICKY;
}
public void pauseMusic() {
if (mediaPlayer.isPlaying()) {
mediaPlayer.pause();
length = mediaPlayer.getCurrentPosition();
}
}
public void resumeMusic() {
if (mediaPlayer.isPlaying() == false) {
mediaPlayer.seekTo(length);
mediaPlayer.start();
}
}
public void stopMusic() {
if (mediaPlayer != null) {
mediaPlayer.stop();
mediaPlayer.release();
mediaPlayer = null;
}
}
@Override
public boolean stopService(Intent name) {
mediaPlayer.stop();
mediaPlayer.release();
return super.stopService(name);
}
@Override
public void onDestroy() {
super.onDestroy();
if (mediaPlayer != null) {
try {
mediaPlayer.stop();
mediaPlayer.release();
} finally {
mediaPlayer = null;
}
}
}
public boolean onError(MediaPlayer mp, int what, int extra) {
Common.showShort(this,String.valueOf(R.string.music_player_fail));
if (mediaPlayer != null) {
try {
mediaPlayer.stop();
mediaPlayer.release();
} finally {
mediaPlayer = null;
}
}
return false;
}
/*调用说明:
开始、暂停、继续播放、停止 音乐:
step 1:在 activity 的onCreate 中调用 doBindService 来将 service 绑定到 activity
Step 2: 通过Intent 启动service
Intent music = new Intent();
music.setClass(this,MusicService.class);
startService(music);
Step 3: 在 activity中调用 pause, resume 或者 stop 来控制音乐:
mServ.pauseMusic();
mServ.resumeMusic();
mServ.stopMusic();
Step 4: 在Activity 的onDestroy 中调用 doUnbindService
以下内容写在Activity中:
*/
private boolean mIsBound = false;
private MusicService mServ;
private ServiceConnection Scon =new ServiceConnection(){
public void onServiceConnected(ComponentName name, IBinder
binder) {
mServ = ((MusicService.ServiceBinder)binder).getService();
}
public void onServiceDisconnected(ComponentName name) {
mServ = null;
}
};
void doBindService(){
bindService(new Intent(this,MusicService.class),
Scon,Context.BIND_AUTO_CREATE);
mIsBound = true;
}
void doUnbindService()
{
if(mIsBound)
{
unbindService(Scon);
mIsBound = false;
}
}
andorid studio / phpstrom copyright 模板
打开设置面板,在copyright中添加内容:
$file.className
Last modified $file.lastModified
Author Mrluchanglong@163.com
Copyright (c) $today.year. All rights reserved. 版权所有
新建文件就会自动生成声明信息,或在文件中就可以使用「右键」->gnerate->Copyright:
使用 unity 开发游戏
使用 unity 开发游戏
1.下载并安装 Unity Hub。https://store.unity.com/download
2.启动 Unity Hub。在 安装 标签页上,添加支持 64 位应用的 Unity 编辑器版本。请注意,这种版本支持 Android App Bundle,而它可以提供更小且更完善的下载文件包。
之后,点击「学习」 开始学习如何使用。
laravel admin 修改后台侧边栏为默认展开
'layout' => ['sidebar-mini', 'sidebar-collapse'],
//修改为
'layout' => ['sidebar-mini'],