优化搜索体验

This commit is contained in:
muqing 2023-12-28 20:47:57 +08:00
parent 3e0d363f3d
commit 17daa94b94
4 changed files with 32 additions and 26 deletions

View File

@ -106,8 +106,22 @@ public class MediaPlayer extends android.media.MediaPlayer {
}
// 在这里将进度更新到UI上
});
new Thread(){
@Override
public void run() {
super.run();
if (bfqkz.lishi_list.size() >= 100) {
bfqkz.lishi_list.remove(0);
}
bfqkz.lishi_list.remove(bfqkz.xm);
if (!bfqkz.lishi_list.contains(bfqkz.xm)) {
bfqkz.lishi_list.add(0, bfqkz.xm);
wj.xrwb(wj.gd + "mp3_hc.json", new com.google.gson.Gson().toJson(bfqkz.lishi_list));
}
wj.setMP3ToFile(bfqkz.xm);
}
}.start();
}
public void DataSource(String path) throws Exception {
reset();

View File

@ -1,6 +1,7 @@
package com.muqingbfq;
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
@ -114,7 +115,7 @@ public class activity_search extends FragmentActivity {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (TextUtils.isEmpty(s)) {
dismiss();
listPopupWindow.setVisibility(View.GONE);
return;
}
list.clear();
@ -148,10 +149,20 @@ public class activity_search extends FragmentActivity {
public void afterTextChanged(Editable s) {
}
});
inflate.editview.requestFocus();//获取焦点
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
//if (!imm.isActive()) //没有显示键盘弹出
imm.showSoftInput(inflate.editview, 0);
}
public void dismiss() {
inflate.editview.clearFocus();
listPopupWindow.setVisibility(View.GONE);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm.isActive()) //有显示键盘隐藏
imm.hideSoftInputFromWindow(inflate.editview.getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
}
private void addSearchRecord(String name) {

View File

@ -55,9 +55,6 @@ public class bfqkz extends MediaBrowserServiceCompat {
try {
if (TextUtils.isEmpty(id)) {
//针对错误进行相应的处理
if (bfqkz.list.size() < 1) {
return;
}
bfqkz.list.remove(bfqkz.xm);
bfq_an.xyq();
return;
@ -65,14 +62,6 @@ public class bfqkz extends MediaBrowserServiceCompat {
if (TextUtils.isEmpty(xm.picurl)) {
xm.picurl = url.picurl(xm.id);
}
if (bfqkz.lishi_list.size() >= 100) {
bfqkz.lishi_list.remove(0);
}
bfqkz.lishi_list.remove(bfqkz.xm);
if (!bfqkz.lishi_list.contains(bfqkz.xm)) {
bfqkz.lishi_list.add(0, bfqkz.xm);
wj.xrwb(wj.gd + "mp3_hc.json", new com.google.gson.Gson().toJson(bfqkz.lishi_list));
}
mt.setDataSource(id);
} catch (Exception e) {
yc.start(home.appCompatActivity, "bfqkz mp3(" + id + ") :" + e);
@ -97,7 +86,7 @@ public class bfqkz extends MediaBrowserServiceCompat {
public static MediaSessionCompat mSession;
public static PlaybackStateCompat playback;
public PendingIntent pendingIntent;
@Override
public void onCreate() {
super.onCreate();
@ -112,7 +101,7 @@ public class bfqkz extends MediaBrowserServiceCompat {
intent.setComponent(new ComponentName(this, home.class));//用ComponentName得到class对象
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);// 关键的一步设置启动模式两种情况
PendingIntent pendingIntent = com.muqingbfq.mq.NotificationManagerCompat.getActivity(this, intent);
pendingIntent = com.muqingbfq.mq.NotificationManagerCompat.getActivity(this, intent);
mSession = new MediaSessionCompat(this, "MusicService",
home.componentName, pendingIntent);
mSession.setCallback(new callback());

View File

@ -24,12 +24,12 @@ import com.muqingbfq.home;
import com.muqingbfq.yc;
public class NotificationManagerCompat {
MediaBrowserServiceCompat context;
bfqkz context;
public NotificationCompat.Builder notificationBuilder;
public androidx.core.app.NotificationManagerCompat notificationManager;
private String name, zz;
public NotificationManagerCompat(MediaBrowserServiceCompat context) {
public NotificationManagerCompat(bfqkz context) {
this.context = context;
name = context.getString(R.string.app_name);
zz = context.getString(R.string.zz);
@ -47,12 +47,6 @@ public class NotificationManagerCompat {
// 适配12.0及以上
// 设置启动的程序如果存在则找出否则新的启动
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setComponent(new ComponentName(context, home.class));//用ComponentName得到class对象
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);// 关键的一步设置启动模式两种情况
pendingIntent = getActivity(context, intent);
Intent my = new Intent(context, MyButtonClickReceiver.class);
pendingIntent_kg = getBroadcast(context, my.
setAction("kg"));
@ -70,15 +64,13 @@ public class NotificationManagerCompat {
.setPriority(NotificationCompat.PRIORITY_LOW)
.setOngoing(true).setAutoCancel(false).setOnlyAlertOnce(true)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setContentIntent(pendingIntent)
.setContentIntent(context.pendingIntent)
.setStyle(style);
tzl();
} catch (Exception e) {
yc.start(context, e);
}
}
PendingIntent pendingIntent;
androidx.media.app.NotificationCompat.MediaStyle style;
@SuppressLint("RestrictedApi")
public void tzl() {