优化搜索体验

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,7 +106,21 @@ public class MediaPlayer extends android.media.MediaPlayer {
} }
// 在这里将进度更新到UI上 // 在这里将进度更新到UI上
}); });
wj.setMP3ToFile(bfqkz.xm); 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 { public void DataSource(String path) throws Exception {

View File

@ -1,6 +1,7 @@
package com.muqingbfq; package com.muqingbfq;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.text.Editable; import android.text.Editable;
import android.text.TextUtils; import android.text.TextUtils;
@ -114,7 +115,7 @@ public class activity_search extends FragmentActivity {
@Override @Override
public void onTextChanged(CharSequence s, int start, int before, int count) { public void onTextChanged(CharSequence s, int start, int before, int count) {
if (TextUtils.isEmpty(s)) { if (TextUtils.isEmpty(s)) {
dismiss(); listPopupWindow.setVisibility(View.GONE);
return; return;
} }
list.clear(); list.clear();
@ -148,10 +149,20 @@ public class activity_search extends FragmentActivity {
public void afterTextChanged(Editable s) { 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() { public void dismiss() {
inflate.editview.clearFocus();
listPopupWindow.setVisibility(View.GONE); 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) { private void addSearchRecord(String name) {

View File

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

View File

@ -24,12 +24,12 @@ import com.muqingbfq.home;
import com.muqingbfq.yc; import com.muqingbfq.yc;
public class NotificationManagerCompat { public class NotificationManagerCompat {
MediaBrowserServiceCompat context; bfqkz context;
public NotificationCompat.Builder notificationBuilder; public NotificationCompat.Builder notificationBuilder;
public androidx.core.app.NotificationManagerCompat notificationManager; public androidx.core.app.NotificationManagerCompat notificationManager;
private String name, zz; private String name, zz;
public NotificationManagerCompat(MediaBrowserServiceCompat context) { public NotificationManagerCompat(bfqkz context) {
this.context = context; this.context = context;
name = context.getString(R.string.app_name); name = context.getString(R.string.app_name);
zz = context.getString(R.string.zz); zz = context.getString(R.string.zz);
@ -47,12 +47,6 @@ public class NotificationManagerCompat {
// 适配12.0及以上 // 适配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); Intent my = new Intent(context, MyButtonClickReceiver.class);
pendingIntent_kg = getBroadcast(context, my. pendingIntent_kg = getBroadcast(context, my.
setAction("kg")); setAction("kg"));
@ -70,15 +64,13 @@ public class NotificationManagerCompat {
.setPriority(NotificationCompat.PRIORITY_LOW) .setPriority(NotificationCompat.PRIORITY_LOW)
.setOngoing(true).setAutoCancel(false).setOnlyAlertOnce(true) .setOngoing(true).setAutoCancel(false).setOnlyAlertOnce(true)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setContentIntent(pendingIntent) .setContentIntent(context.pendingIntent)
.setStyle(style); .setStyle(style);
tzl(); tzl();
} catch (Exception e) { } catch (Exception e) {
yc.start(context, e); yc.start(context, e);
} }
} }
PendingIntent pendingIntent;
androidx.media.app.NotificationCompat.MediaStyle style; androidx.media.app.NotificationCompat.MediaStyle style;
@SuppressLint("RestrictedApi") @SuppressLint("RestrictedApi")
public void tzl() { public void tzl() {