diff --git a/app/build.gradle b/app/build.gradle index 1fc8a9b..1132477 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -18,7 +18,7 @@ android { //noinspection OldTargetApi targetSdk 31 versionCode 1 - versionName "1.7.0" + versionName "1.7.1" } compileOptions { diff --git a/app/debug/Cloud_music-debug-v1.7.0.apk b/app/debug/Cloud_music-debug-v1.7.0.apk deleted file mode 100644 index 3330a55..0000000 Binary files a/app/debug/Cloud_music-debug-v1.7.0.apk and /dev/null differ diff --git a/app/debug/output-metadata.json b/app/debug/output-metadata.json index 3482d42..1318b62 100644 --- a/app/debug/output-metadata.json +++ b/app/debug/output-metadata.json @@ -12,8 +12,8 @@ "filters": [], "attributes": [], "versionCode": 1, - "versionName": "1.7.0", - "outputFile": "Cloud_music-debug-v1.7.0.apk" + "versionName": "1.7.1", + "outputFile": "Cloud_music-debug-v1.7.1.apk" } ], "elementType": "File" diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index c15fb35..8f9a43f 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -52,7 +52,7 @@ diff --git a/app/src/main/java/com/muqingbfq/MediaPlayer.java b/app/src/main/java/com/muqingbfq/MediaPlayer.java index 7e7ef67..0ebc856 100644 --- a/app/src/main/java/com/muqingbfq/MediaPlayer.java +++ b/app/src/main/java/com/muqingbfq/MediaPlayer.java @@ -171,12 +171,7 @@ public class MediaPlayer { } bfq_db.setname(name); bfq_db.setzz(zz); - if (bfqkz.notify.notificationManager != null) { - bfqkz.notify.notificationBuilder.setContentTitle(name); - bfqkz.notify.notificationBuilder.setContentText(zz); - bfqkz.notify.notificationManager_notify(); - } if (com.muqingbfq.fragment.mp3.lbspq != null) { com.muqingbfq.fragment.mp3.lbspq.notifyDataSetChanged(); } diff --git a/app/src/main/java/com/muqingbfq/MyButtonClickReceiver.java b/app/src/main/java/com/muqingbfq/MyButtonClickReceiver.java index 4eca39d..5651396 100644 --- a/app/src/main/java/com/muqingbfq/MyButtonClickReceiver.java +++ b/app/src/main/java/com/muqingbfq/MyButtonClickReceiver.java @@ -135,7 +135,6 @@ public class MyButtonClickReceiver extends BroadcastReceiver { if (bfqkz.mt == null) { return; } - gj.sc(bfqkz.mt); // gj.sc(isMusicServiceBound);播放/暂停按钮点击事件 if (isMusicServiceBound) if (bfqkz.mt.isPlaying()) { bfqkz.mt.pause(); diff --git a/app/src/main/java/com/muqingbfq/activity_search.java b/app/src/main/java/com/muqingbfq/activity_search.java index 608b141..dfab609 100644 --- a/app/src/main/java/com/muqingbfq/activity_search.java +++ b/app/src/main/java/com/muqingbfq/activity_search.java @@ -17,7 +17,6 @@ import android.widget.ListView; import android.widget.TextView; import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; import androidx.recyclerview.widget.RecyclerView; import com.google.android.flexbox.AlignItems; @@ -48,8 +47,7 @@ public class activity_search extends ActivityToolbar { private final List list = new ArrayList<>(); ListView listPopupWindow; ActivitySearchBinding inflate; - - @SuppressLint({"RestrictedApi", "NotifyDataSetChanged"}) + @SuppressLint("NotifyDataSetChanged") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -197,9 +195,13 @@ public class activity_search extends ActivityToolbar { public void start(String name) { dismiss(); if (!TextUtils.isEmpty(name)) { - search search = (com.muqingbfq.fragment.search) getSupportFragmentManager(). - findFragmentById(R.id.search_fragment); - search.setStart(name); + search sea = (search) getSupportFragmentManager().findFragmentById(R.id.search_fragment); + if (!name.equals(sea.name)) { + sea.i = 0; + sea.inflate.tablayout.getTabAt(0).select(); + } + sea.setVisibility(true); + sea.setStart(name); addSearchRecord(name); } } @@ -266,11 +268,15 @@ public class activity_search extends ActivityToolbar { private void end() { search search = (com.muqingbfq.fragment.search) getSupportFragmentManager(). findFragmentById(R.id.search_fragment); - if (search.getVisibility()) { + if (search.isVisible()) { search.setVisibility(false); } else { finish(); } + } + @Override + public void finish() { + super.finish(); com.muqingbfq.fragment.search.lbspq = null; } } \ No newline at end of file diff --git a/app/src/main/java/com/muqingbfq/api/playlist.java b/app/src/main/java/com/muqingbfq/api/playlist.java index 8bc53b9..c77ec23 100644 --- a/app/src/main/java/com/muqingbfq/api/playlist.java +++ b/app/src/main/java/com/muqingbfq/api/playlist.java @@ -64,6 +64,9 @@ public class playlist extends Thread { list.clear(); try { JSONObject json = gd.like; + if (json == null || json.length() < 1) { + return false; + } for (Iterator it = json.keys(); it.hasNext(); ) { String id = it.next(); JSONObject jsonObject = json.getJSONObject(id); @@ -72,7 +75,7 @@ public class playlist extends Thread { String picUrl = jsonObject.getString("picUrl"); list.add(new xm(id, name, zz, picUrl)); } - main.handler.post(new mp3.lbspq_sx()); +// main.handler.post(new mp3.lbspq_sx()); return true; } catch (Exception e) { gj.sc("失败的错误 " + e); diff --git a/app/src/main/java/com/muqingbfq/api/resource.java b/app/src/main/java/com/muqingbfq/api/resource.java index 4d4ab02..47d2ef3 100644 --- a/app/src/main/java/com/muqingbfq/api/resource.java +++ b/app/src/main/java/com/muqingbfq/api/resource.java @@ -61,7 +61,11 @@ public class resource { for (int i = 0; i < length; i++) { JSONObject get = list_array.getJSONObject(i); String id = get.getString("id"); - String name = get.getString("name") + "\n" + get.getString("description"); + String name = get.getString("name") + "\n"; + String description = get.getString("description"); + if (!TextUtils.isEmpty(description) && !description.equals("null")) { + name += description; + } boolean cz = wj.cz(wj.gd + id); String coverImgUrl = get.getString("coverImgUrl"); list.add(new xm(id, name, coverImgUrl, cz)); diff --git a/app/src/main/java/com/muqingbfq/bfq.java b/app/src/main/java/com/muqingbfq/bfq.java index 0657ad8..3488090 100644 --- a/app/src/main/java/com/muqingbfq/bfq.java +++ b/app/src/main/java/com/muqingbfq/bfq.java @@ -1,12 +1,18 @@ package com.muqingbfq; +import android.animation.Animator; +import android.animation.AnimatorListenerAdapter; +import android.animation.ObjectAnimator; import android.annotation.SuppressLint; import android.content.Context; import android.content.Intent; import android.content.res.Configuration; import android.graphics.Bitmap; import android.os.Bundle; -import android.view.View; +import android.util.TypedValue; +import android.view.MotionEvent; +import android.view.WindowManager; +import android.widget.LinearLayout; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -15,18 +21,26 @@ import androidx.appcompat.widget.Toolbar; import com.muqingbfq.databinding.ActivityBfqBinding; import com.muqingbfq.fragment.Media; -import com.muqingbfq.mq.gj; public class bfq extends AppCompatActivity { @SuppressLint("StaticFieldLeak") public static AppCompatActivity context; + ActivityBfqBinding inflate; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); + getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); context = this; - ActivityBfqBinding inflate = ActivityBfqBinding.inflate(getLayoutInflater()); - setContentView(inflate.getRoot()); + inflate = ActivityBfqBinding.inflate(getLayoutInflater()); + LinearLayout root = inflate.getRoot(); + TypedValue typedValue = new TypedValue(); + home.appCompatActivity.getTheme().resolveAttribute(android.R.attr.windowBackground, typedValue, true); + // 设置背景颜色 + root.setBackgroundColor(typedValue.data); + setContentView(root); + Media media = (Media) getSupportFragmentManager().findFragmentById(R.id.fragment_bfq); + media.setBfq(this); Toolbar toolbar = inflate.toolbar; toolbar.setNavigationOnClickListener(view1 -> finish()); toolbar.setOnMenuItemClickListener(item -> { @@ -42,11 +56,22 @@ public class bfq extends AppCompatActivity { Media.setname(bfqkz.xm.name); Media.setzz(bfqkz.xm.zz); } - inflate.name.setOnLongClickListener(view -> { +/* inflate.name.setOnLongClickListener(view -> { gj.fz(bfq.this, inflate.name.getText().toString()); gj.ts(bfq.this, "复制成功"); return false; - }); + });*/ + bfq_an.kz kz = new bfq_an.kz(); + inflate.kg.setOnClickListener(kz); + inflate.xyq.setOnClickListener(kz); + inflate.xyq.setOnClickListener(kz); + inflate.bfqListMp3. + setOnClickListener(view1 -> com.muqingbfq.fragment.bflb_db.start(this)); + inflate.control.setOnClickListener(new bfq_an.control(inflate.control)); + if (bfqkz.mt != null && bfqkz.mt.build.isPlaying()) { + inflate.kg.setImageResource(R.drawable.bf); + } + text(); } public static Bitmap bitmap; @@ -58,9 +83,59 @@ public class bfq extends AppCompatActivity { context.startActivity(intent); } + public void kgsetImageResource(int a) { + if (inflate == null) { + return; + } + inflate.kg.setImageResource(a); + } + @Override public void onConfigurationChanged(@NonNull Configuration newConfig) { super.onConfigurationChanged(newConfig); - Media.view = null; + } + + float downY, moveY; + + @SuppressLint("ClickableViewAccessibility") + public void text() { + inflate.toolbar.setOnTouchListener((view, motionEvent) -> { + LinearLayout root = inflate.getRoot(); + switch (motionEvent.getAction()) { + case MotionEvent.ACTION_DOWN: + downY = motionEvent.getRawY(); + break; + case MotionEvent.ACTION_MOVE: + //长按事件,可以移动 + moveY = motionEvent.getRawY(); + //移动的距离 + float dy = moveY - downY; + //重新设置控件的位置。移动 + if (dy <= 0) { + return true; + } else if (dy > main.g - main.g / 5.0) { + finish(); + return true; + } + root.setTranslationY(dy); + break; + case MotionEvent.ACTION_UP: + if (inflate.getRoot().getY() > main.g - main.g / 1.5) { + finish(); + return true; + } + ObjectAnimator animator = ObjectAnimator.ofFloat(root, "y", root.getY(), 0); + animator.setDuration(300); + animator.addListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + root.setY(0); + } + }); + animator.start(); + break; + } + return true; + }); } } \ No newline at end of file diff --git a/app/src/main/java/com/muqingbfq/bfqkz.java b/app/src/main/java/com/muqingbfq/bfqkz.java index e03a09a..9588618 100644 --- a/app/src/main/java/com/muqingbfq/bfqkz.java +++ b/app/src/main/java/com/muqingbfq/bfqkz.java @@ -3,14 +3,20 @@ package com.muqingbfq; import android.annotation.SuppressLint; import android.app.Service; import android.content.Intent; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.net.Uri; import android.os.Binder; +import android.os.Bundle; import android.os.IBinder; import android.support.v4.media.MediaMetadataCompat; import android.support.v4.media.session.MediaSessionCompat; import android.support.v4.media.session.PlaybackStateCompat; import android.text.TextUtils; +import android.view.KeyEvent; import androidx.annotation.Nullable; +import androidx.media3.common.MediaItem; import com.muqingbfq.api.url; import com.muqingbfq.mq.BluetoothMusicController; @@ -58,6 +64,27 @@ public class bfqkz extends Service { yc.start(home.appCompatActivity, "bfqkz mp3(" + id + ") :" + e); } } + public static void mp3(Uri id) { + try { + if (TextUtils.isEmpty(id.toString())) { + return; + } + gj.sc(xm.picurl); + if (TextUtils.isEmpty(xm.picurl.toString())) { + xm.picurl = url.picurl(xm.id); + } + MediaItem mediaItem = MediaItem.fromUri(id); + main.handler.post(() -> { + mt.build.setMediaItem(mediaItem); + mt.build.prepare(); + mt.build.setPlayWhenReady(true); + mt.start(); + }); + } catch (Exception e) { + yc.start(home.appCompatActivity, "bfqkz mp3(" + id + ") :" + e); + } + } + public static MediaSessionCompat mSession; public static MediaMetadataCompat build; @@ -73,36 +100,76 @@ public class bfqkz extends Service { playback=new PlaybackStateCompat.Builder() .setState(PlaybackStateCompat.STATE_NONE,0,1.0f) .build(); -/* mSession.setCallback(new MediaSessionCompat.Callback() { - @Override - public void onPlay() { - mt.start(); - } - @Override - public void onPause() { - // 处理暂停音乐逻辑 - mt.pause(); - } - @Override - public void onSkipToNext() { - // 处理切换到下一首音乐逻辑 - } + mSession.setCallback(new callback()); + mSession.setFlags(MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS); + mSession.setPlaybackState(playback); + Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icon); - @Override - public void onSkipToPrevious() { - // 处理切换到上一首音乐逻辑 - } - });*/ build = new MediaMetadataCompat.Builder() + .putString(MediaMetadataCompat.METADATA_KEY_TITLE, "Song Title") + .putString(MediaMetadataCompat.METADATA_KEY_ARTIST, "Artist Name") + .putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, bitmap) + .putLong(MediaMetadataCompat.METADATA_KEY_DURATION, 1000) // 单位为毫秒 .build(); mSession.setMetadata(build); - mSession.setPlaybackState(playback); mSession.setActive(true); -// setSessionToken(mSession.getSessionToken()); notify = new com.muqingbfq.mq.NotificationManagerCompat(this); - } + class callback extends MediaSessionCompat.Callback { + @Override + public boolean onMediaButtonEvent(Intent mediaButtonEvent) { + KeyEvent event = (KeyEvent) mediaButtonEvent.getParcelableExtra(Intent.EXTRA_KEY_EVENT); + return true; + } + + @Override + public void onPlay() { + super.onPlay(); + if(playback.getState() == PlaybackStateCompat.STATE_PAUSED){ + mt.start(); + playback = new PlaybackStateCompat.Builder() + .setState(PlaybackStateCompat.STATE_PLAYING,0,1.0f) + .build(); + mSession.setPlaybackState(playback); + } + } + + @Override + public void onPause() { + super.onPause(); + if(playback.getState() == PlaybackStateCompat.STATE_PLAYING){ + mt.pause(); + playback = new PlaybackStateCompat.Builder() + .setState(PlaybackStateCompat.STATE_PAUSED,0,1.0f) + .build(); + mSession.setPlaybackState(playback); + } + } + @Override + public void onPlayFromUri(Uri uri, Bundle extras) { + try { + switch (playback.getState()){ + case PlaybackStateCompat.STATE_PLAYING: + case PlaybackStateCompat.STATE_PAUSED: + case PlaybackStateCompat.STATE_NONE: + mp3(uri); + playback = new PlaybackStateCompat.Builder() + .setState(PlaybackStateCompat.STATE_CONNECTING,0,1.0f) + .build(); + mSession.setPlaybackState(playback); + //我们可以保存当前播放音乐的信息,以便客户端刷新UI + mSession.setMetadata(new MediaMetadataCompat.Builder() + .putString(MediaMetadataCompat.METADATA_KEY_TITLE,extras.getString("title")) + .build() + ); + break; + } + }catch (Exception e){ + e.printStackTrace(); + } + } + } @Nullable @Override public IBinder onBind(Intent intent) { @@ -118,7 +185,7 @@ public class bfqkz extends Service { try { // 更新通知栏的播放状态 if (notify.notificationBuilder != null) { - notify.tzl_an(); + notify.tzl(); } } catch (Exception e) { gj.sc("bfqkz updateNotification:" + e); diff --git a/app/src/main/java/com/muqingbfq/fragment/Media.java b/app/src/main/java/com/muqingbfq/fragment/Media.java index c533063..1db5363 100644 --- a/app/src/main/java/com/muqingbfq/fragment/Media.java +++ b/app/src/main/java/com/muqingbfq/fragment/Media.java @@ -33,6 +33,12 @@ import me.wcy.lrcview.LrcView; public class Media extends Fragment { @SuppressLint("StaticFieldLeak") public static LinearLayout view; + private static bfq bfq; + + public void setBfq(bfq bfq) { + Media.bfq = bfq; + } + @SuppressLint("StaticFieldLeak") private static TextView time_a, time_b; @SuppressLint("StaticFieldLeak") @@ -63,24 +69,19 @@ public class Media extends Fragment { } public static void setbf(boolean bool) { - if (bool) { - //开始 - kgsetImageResource(R.drawable.bf); - } else { - //暂停 - kgsetImageResource(R.drawable.zt); + if (bfq != null) { + if (bool) { + //开始 + bfq.kgsetImageResource(R.drawable.bf); + } else { + //暂停 + bfq.kgsetImageResource(R.drawable.zt); + } } bfq_db.setkg(bool); bfqkz.updateNotification(); } - private static void kgsetImageResource(int a) { - if (view == null) { - return; - } - ImageView imageView = view.findViewById(R.id.kg); - imageView.setImageResource(a); - } @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @@ -90,17 +91,8 @@ public class Media extends Fragment { } FragmentBfqBinding inflate = FragmentBfqBinding.inflate(inflater, container, false); view = inflate.getRoot(); -/* if (home.imageView == null) { - home.imageView = new ImageView(home.appCompatActivity); - home.imageView.setScaleType(ImageView.ScaleType.FIT_XY); - home.imageView.setImageResource(R.drawable.icon); - }*/ inflate.cardview.addView(home.imageView); - bfq_an.kz kz = new bfq_an.kz(); - ImageView kg = view.findViewById(R.id.kg); - kg.setOnClickListener(kz); - view.findViewById(R.id.xyq).setOnClickListener(kz); - view.findViewById(R.id.syq).setOnClickListener(kz); + tdt = inflate.tdt; tdt.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override @@ -130,7 +122,7 @@ public class Media extends Fragment { bfqkz.mt.build.seekTo(Math.toIntExact(time)); return false; }); - if (!isTablet(bfq.context)) { + if (!isTablet(com.muqingbfq.bfq.context)) { lrcview.setOnTapListener((view, x, y) -> { View kp = inflate.kp1; if (kp.getVisibility() == View.VISIBLE) { @@ -141,10 +133,7 @@ public class Media extends Fragment { }); } //初始化播放器列表 - inflate.bfqListMp3. - setOnClickListener(view1 -> com.muqingbfq.fragment.bflb_db.start(bfq.context)); - - inflate.like.setOnClickListener(view1 -> { + bfq.findViewById(R.id.like).setOnClickListener(view1 -> { ImageView like = (ImageView) view1; try { if (bfqkz.like_bool) { @@ -166,22 +155,15 @@ public class Media extends Fragment { e.printStackTrace(); } }); - - inflate.control.setOnClickListener(new bfq_an.control(inflate.control)); if (bfqkz.xm != null) { main.handler.removeCallbacks(bfqkz.mt.updateSeekBar); // 在播放开始时启动更新进度 long duration = bfqkz.mt.build.getDuration(); tdt.setMax((int) bfqkz.mt.build.getDuration()); setTime_a(bfq_an.getTime(duration)); - long position = bfqkz.mt.build.getCurrentPosition(); setProgress((int) position); - main.handler.post(bfqkz.mt.updateSeekBar); // 在播放开始时启动更新进度 - if (bfqkz.mt.build.isPlaying()) { - kg.setImageResource(R.drawable.bf); - } - bfq_an.islike(bfq.context); + bfq_an.islike(com.muqingbfq.bfq.context); new Thread() { @Override public void run() { @@ -209,7 +191,7 @@ public class Media extends Fragment { } public static void setlike(boolean bool) { - ImageView imageView = view.findViewById(R.id.like); + ImageView imageView = bfq.findViewById(R.id.like); int color = R.color.text; if (bool) { color = android.R.color.holo_red_dark; @@ -222,22 +204,22 @@ public class Media extends Fragment { if (home.imageView == null) { return; } - main.handler.post(() -> home.imageView.setImageBitmap(bfq.bitmap)); + main.handler.post(() -> home.imageView.setImageBitmap(com.muqingbfq.bfq.bitmap)); } public static void setname(String str) { - if (bfq.context == null) { + if (com.muqingbfq.bfq.context == null) { return; } - TextView name = bfq.context.findViewById(R.id.name); + TextView name = com.muqingbfq.bfq.context.findViewById(R.id.name); name.setText(str); } public static void setzz(String str) { - if (bfq.context == null) { + if (com.muqingbfq.bfq.context == null) { return; } - TextView zz = bfq.context.findViewById(R.id.zz); + TextView zz = com.muqingbfq.bfq.context.findViewById(R.id.zz); zz.setText(str); } diff --git a/app/src/main/java/com/muqingbfq/fragment/gd.java b/app/src/main/java/com/muqingbfq/fragment/gd.java index 32a58e6..66c3687 100644 --- a/app/src/main/java/com/muqingbfq/fragment/gd.java +++ b/app/src/main/java/com/muqingbfq/fragment/gd.java @@ -102,6 +102,10 @@ public class gd extends Fragment { return new VH(view); } + public void setList(List list) { + this.list = list; + } + @Override public void onBindViewHolder(@NonNull VH holder, int position) { xm xm = list.get(position); diff --git a/app/src/main/java/com/muqingbfq/fragment/mp3.java b/app/src/main/java/com/muqingbfq/fragment/mp3.java index be32e1d..ed6b023 100644 --- a/app/src/main/java/com/muqingbfq/fragment/mp3.java +++ b/app/src/main/java/com/muqingbfq/fragment/mp3.java @@ -30,7 +30,7 @@ import com.muqingbfq.xm; import java.util.ArrayList; import java.util.List; -public class mp3 extends AppCompatActivity { +public class mp3 extends com.muqingbfq.mq.ActivityToolbar { private final List list = new ArrayList<>(); public static RecyclerView.Adapter lbspq; @@ -41,8 +41,6 @@ public class mp3 extends AppCompatActivity { Intent intent = getIntent(); Toolbar toolbar = findViewById(R.id.toolbar); toolbar.setTitle(intent.getStringExtra("name")); - setSupportActionBar(toolbar); - getSupportActionBar().setDisplayHomeAsUpEnabled(true); lbspq = new spq(); RecyclerView lb = findViewById(R.id.lb); LinearLayoutManager layoutManager = new LinearLayoutManager(this); @@ -50,8 +48,6 @@ public class mp3 extends AppCompatActivity { lb.setAdapter(lbspq); String id = intent.getStringExtra("id"); new start(id); -/* getSupportFragmentManager().beginTransaction() - .add(R.id.bfq_db,home.bfq_db).commit();*/ } @SuppressLint("NotifyDataSetChanged") diff --git a/app/src/main/java/com/muqingbfq/fragment/search.java b/app/src/main/java/com/muqingbfq/fragment/search.java index 4085886..25df5e1 100644 --- a/app/src/main/java/com/muqingbfq/fragment/search.java +++ b/app/src/main/java/com/muqingbfq/fragment/search.java @@ -37,22 +37,22 @@ import java.util.List; public class search extends Fragment { public static RecyclerView.Adapter lbspq; List list = new ArrayList<>(); + gd.baseadapter adapter_gd; + public String name; - private String name; - - FragmentSearchBinding inflate; - private int i = 0; - + public FragmentSearchBinding inflate; + public int i = 0; @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { inflate = FragmentSearchBinding.inflate(inflater, container, false); + lbspq = new spq(); View view = inflate.getRoot(); TypedValue typedValue = new TypedValue(); requireContext().getTheme().resolveAttribute(android.R.attr.windowBackground, typedValue, true); // 设置背景颜色 - lbspq = new spq(); + adapter_gd = new gd.baseadapter(getContext(), list); view.setBackgroundColor(typedValue.data); inflate.tablayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Override @@ -86,13 +86,19 @@ public class search extends Fragment { } } - public boolean getVisibility() { - return inflate.getRoot().isShown(); - } - + public int k; public void setStart(String name) { - setVisibility(true); - gj.sc(i); + if (i == 0) { + new spq(); + inflate.recyclerview.setLayoutManager(new LinearLayoutManager(getContext())); + inflate.recyclerview.setAdapter(lbspq); + } else if (i == 1) { + k = (int) (main.k / getResources().getDisplayMetrics().density + 0.5f) / 120; + GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), + k); + inflate.recyclerview.setLayoutManager(gridLayoutManager); + inflate.recyclerview.setAdapter(adapter_gd); + } new start(name); } @@ -100,7 +106,6 @@ public class search extends Fragment { public start(String name) { list.clear(); search.this.name = name; - start(); } @@ -115,13 +120,9 @@ public class search extends Fragment { } main.handler.post(() -> { if (i == 0) { - inflate.recyclerview.setLayoutManager(new LinearLayoutManager(getContext())); - inflate.recyclerview.setAdapter(new spq()); + lbspq.notifyDataSetChanged(); } else if (i == 1) { - int k = (int) (main.k / getResources().getDisplayMetrics().density + 0.5f); - GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), 3); - inflate.recyclerview.setLayoutManager(gridLayoutManager); - inflate.recyclerview.setAdapter(new gd.baseadapter(getContext(), list)); + adapter_gd.notifyDataSetChanged(); } // lbspq.notifyDataSetChanged(); }); @@ -158,7 +159,7 @@ public class search extends Fragment { } private void gd() { - String hq = wl.hq("/search?keywords=" + name + "&type=1000"); + String hq = wl.hq("/search?keywords=" + name + "&limit=" + (k * k) + "&type=1000"); try { JSONArray jsonArray = new JSONObject(hq).getJSONObject("result") .getJSONArray("playlists"); diff --git a/app/src/main/java/com/muqingbfq/home.java b/app/src/main/java/com/muqingbfq/home.java index 949f5ba..d291446 100644 --- a/app/src/main/java/com/muqingbfq/home.java +++ b/app/src/main/java/com/muqingbfq/home.java @@ -14,6 +14,7 @@ import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; import androidx.drawerlayout.widget.DrawerLayout; +import com.google.android.material.card.MaterialCardView; import com.google.android.material.navigation.NavigationView; import com.muqingbfq.fragment.Media; import com.muqingbfq.fragment.bfq_db; @@ -22,9 +23,9 @@ import com.muqingbfq.mq.gj; public class home extends AppCompatActivity { @SuppressLint("StaticFieldLeak") public static AppCompatActivity appCompatActivity; + @SuppressLint("StaticFieldLeak") public static ImageView imageView; - @SuppressLint({"CommitTransaction", "ObsoleteSdkInt"}) @Override protected void onCreate(Bundle savedInstanceState) { setTheme(R.style.Theme_muqing); @@ -35,10 +36,11 @@ public class home extends AppCompatActivity { if (imageView == null) { imageView = new ImageView(this); imageView.setScaleType(ImageView.ScaleType.FIT_XY); - imageView.setImageResource(R.drawable.icon); - } - if (bfq.bitmap != null) { - Media.setImageBitmap(); + if (bfq.bitmap == null) { + imageView.setImageResource(R.drawable.icon); + } else { + Media.setImageBitmap(); + } } try { //初始化工具栏 diff --git a/app/src/main/java/com/muqingbfq/mq/NotificationManagerCompat.java b/app/src/main/java/com/muqingbfq/mq/NotificationManagerCompat.java index 77e9979..d3def04 100644 --- a/app/src/main/java/com/muqingbfq/mq/NotificationManagerCompat.java +++ b/app/src/main/java/com/muqingbfq/mq/NotificationManagerCompat.java @@ -12,11 +12,10 @@ import android.content.Intent; import android.content.pm.PackageManager; import android.graphics.BitmapFactory; import android.os.Build; -import android.support.v4.media.session.PlaybackStateCompat; +import android.support.v4.media.MediaMetadataCompat; import androidx.core.app.ActivityCompat; import androidx.core.app.NotificationCompat; -import androidx.media.session.MediaButtonReceiver; import com.muqingbfq.MyButtonClickReceiver; import com.muqingbfq.R; @@ -30,11 +29,12 @@ public class NotificationManagerCompat { Service context; public NotificationCompat.Builder notificationBuilder; public androidx.core.app.NotificationManagerCompat notificationManager; + private String name, zz; public NotificationManagerCompat(Service context) { this.context = context; - CharSequence name = context.getString(R.string.app_name); - String zz = context.getString(R.string.zz); + name = context.getString(R.string.app_name); + zz = context.getString(R.string.zz); try { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, @@ -54,7 +54,7 @@ public class NotificationManagerCompat { intent.setComponent(new ComponentName(context, home.class));//用ComponentName得到class对象 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);// 关键的一步,设置启动模式,两种情况 - PendingIntent pendingIntent = getActivity(context, intent); + pendingIntent = getActivity(context, intent); Intent my = new Intent(context, MyButtonClickReceiver.class); pendingIntent_kg = getBroadcast(context, my. setAction("kg")); @@ -64,15 +64,14 @@ public class NotificationManagerCompat { setAction("xyq")); // 取消操作的PendingIntent // 取消操作的PendingIntent - PendingIntent cancelIntent = MediaButtonReceiver.buildMediaButtonPendingIntent(context, - PlaybackStateCompat.ACTION_STOP); - androidx.media.app.NotificationCompat.MediaStyle style = - new androidx.media.app.NotificationCompat.MediaStyle() - .setShowActionsInCompactView(0, 1, 2) - .setMediaSession(bfqkz.mSession.getSessionToken()) - .setShowCancelButton(true) - .setCancelButtonIntent(cancelIntent); - +/* PendingIntent cancelIntent = MediaButtonReceiver.buildMediaButtonPendingIntent(context, + PlaybackStateCompat.ACTION_STOP);*/ + style = new androidx.media.app.NotificationCompat.MediaStyle() + .setShowActionsInCompactView(0, 1, 2) + .setMediaSession(bfqkz.mSession.getSessionToken()); +// .setShowCancelButton(true) +// .setCancelButtonIntent(cancelIntent); + notificationManager = androidx.core.app.NotificationManagerCompat.from(context); notificationBuilder = getNotificationBuilder(context) .setSmallIcon(R.drawable.icon) .setContentTitle(name).setContentText(zz) @@ -81,35 +80,43 @@ public class NotificationManagerCompat { .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setContentIntent(pendingIntent) .setStyle(style); - notificationManager = androidx.core.app.NotificationManagerCompat.from(context); - tzl_an(); + tzl(); // context.startForeground(1, notificationBuilder.build()); } catch (Exception e) { yc.start(context, e); } } + PendingIntent pendingIntent; + androidx.media.app.NotificationCompat.MediaStyle style; + + @SuppressLint("RestrictedApi") + public void tzl() { + if (bfqkz.xm != null) { + name = bfqkz.xm.name; + zz = bfqkz.xm.zz; + } + bfqkz.build = new MediaMetadataCompat.Builder() + .putString(MediaMetadataCompat.METADATA_KEY_TITLE, name) + .putString(MediaMetadataCompat.METADATA_KEY_ARTIST, zz) + .build(); + bfqkz.mSession.setMetadata(bfqkz.build); + notificationBuilder.mActions.clear(); + notificationBuilder.addAction(android.R.drawable.ic_media_previous, "syq", pendingIntent_syq) // #0 + .addAction(bfqkz.mt.isPlaying() ? android.R.drawable.ic_media_pause : android.R.drawable.ic_media_play + , "kg", pendingIntent_kg) // #1 + .addAction(android.R.drawable.ic_media_next, "xyq", pendingIntent_xyq) + .setContentTitle(name) + .setContentText(zz) + .setOngoing(bfqkz.mt.isPlaying()); + notificationManager_notify(); + } + private PendingIntent pendingIntent_kg, pendingIntent_syq, pendingIntent_xyq; private final String CHANNEL_ID = "muqing_yy_id"; - @SuppressLint("RestrictedApi") - public void tzl_an() { - notificationBuilder.mActions.clear(); - notificationBuilder -/* .addAction(R.drawable.syq, "syq", pendingIntent_syq) // #0 - .addAction(bfqkz.mt.isPlaying() ? R.drawable.bf : R.drawable.zt - , "kg", pendingIntent_kg) // #1 - .addAction(R.drawable.xyq, "xyq", pendingIntent_xyq);*/ - .addAction(android.R.drawable.ic_media_previous, "syq", pendingIntent_syq) // #0 - .addAction(bfqkz.mt.isPlaying() ? android.R.drawable.ic_media_pause : android.R.drawable.ic_media_play - , "kg", pendingIntent_kg) // #1 - .addAction(android.R.drawable.ic_media_next, "xyq", pendingIntent_xyq); - notificationBuilder.setOngoing(bfqkz.mt.isPlaying()); - notificationManager_notify(); - } - public void notificationManager_notify() { if (ActivityCompat.checkSelfPermission(context, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) { return; @@ -133,7 +140,7 @@ public class NotificationManagerCompat { private NotificationCompat.Builder getNotificationBuilder(Context context) { // 适用于Android 8.0及以上版本 // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) - return new NotificationCompat.Builder(context, CHANNEL_ID); + return new NotificationCompat.Builder(context, CHANNEL_ID); } private PendingIntent getBroadcast(Context context, Intent intent) { diff --git a/app/src/main/java/com/muqingbfq/mq/floating.java b/app/src/main/java/com/muqingbfq/mq/floating.java index 058ec81..02ce87e 100644 --- a/app/src/main/java/com/muqingbfq/mq/floating.java +++ b/app/src/main/java/com/muqingbfq/mq/floating.java @@ -27,9 +27,12 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Locale; public class floating extends Service { - private static RecyclerView.Adapter lbspq = new RecyclerView.Adapter() { + private static RecyclerView.Adapter lbspq; + + class spq extends RecyclerView.Adapter { @NonNull @Override public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { @@ -46,11 +49,10 @@ public class floating extends Service { public int getItemCount() { return list.size(); } - }; + } public static void start(Context context) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && - Settings.canDrawOverlays(context)) { + if (Settings.canDrawOverlays(context)) { context.startService(new Intent(context, floating.class)); } } @@ -60,7 +62,7 @@ public class floating extends Service { context.stopService(serviceIntent); } - public static List list = new ArrayList<>(); + public static List list; private WindowManager windowManager; private View view; private View image, layout; @@ -75,7 +77,7 @@ public class floating extends Service { if (lbspq == null || list == null) { return; } - SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); // 创建一个 SimpleDateFormat 对象,指定时间格式 + SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss", Locale.CHINA); // 创建一个 SimpleDateFormat 对象,指定时间格式 String formattedDate = sdf.format(new Date()); // 格式化当前时间 list.add(0, formattedDate + ": " + str); main.handler.post(lbspq::notifyDataSetChanged); @@ -85,6 +87,8 @@ public class floating extends Service { @Override public void onCreate() { super.onCreate(); + list = new ArrayList<>(); + lbspq = new spq(); view = LayoutInflater.from(this).inflate(R.layout.floating_sc, null); layout = view.findViewById(R.id.view1); ViewGroup.LayoutParams layoutParams = layout.getLayoutParams(); diff --git a/app/src/main/java/com/muqingbfq/mq/wj.java b/app/src/main/java/com/muqingbfq/mq/wj.java index c41cd9e..7a7b940 100644 --- a/app/src/main/java/com/muqingbfq/mq/wj.java +++ b/app/src/main/java/com/muqingbfq/mq/wj.java @@ -19,7 +19,7 @@ public class wj { public static String gd = "gd/"; public static String tx = "image/"; public static String gd_json = "gd.json", mp3_xz = "mp3_xz.json", gd_xz = "gd_xz.json", - gd_phb = "gd_phb.json", mp3_like = "like.json"; + gd_phb = "gd_phb.json", mp3_like = "mp3_like.json"; public wj(Context context) { try { diff --git a/app/src/main/java/com/muqingbfq/sz.java b/app/src/main/java/com/muqingbfq/sz.java index 4ab66b3..bec6aad 100644 --- a/app/src/main/java/com/muqingbfq/sz.java +++ b/app/src/main/java/com/muqingbfq/sz.java @@ -4,11 +4,12 @@ import android.annotation.SuppressLint; import android.content.Intent; import android.content.SharedPreferences; import android.net.Uri; -import android.os.Build; import android.os.Bundle; import android.provider.Settings; import android.view.MenuItem; +import androidx.activity.result.ActivityResultLauncher; +import androidx.activity.result.contract.ActivityResultContracts; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatDelegate; @@ -68,6 +69,8 @@ public class sz extends AppCompatActivity { }); } + + @Override public boolean onOptionsItemSelected(@NonNull MenuItem item) { if (item.getItemId() == android.R.id.home) { @@ -76,15 +79,20 @@ public class sz extends AppCompatActivity { return super.onOptionsItemSelected(item); } + ActivityResultLauncher intent = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), + result -> { + if (Settings.canDrawOverlays(this)) { + com.muqingbfq.mq.floating.start(sz.this); + } + }); public void kaifazhe() { MaterialSwitch materialSwitch = findViewById(R.id.switch_kfz); materialSwitch.setOnCheckedChangeListener((compoundButton, b) -> { if (b) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && - !Settings.canDrawOverlays(this)) { + if (!Settings.canDrawOverlays(this)) { Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName())); - startActivityForResult(intent, 114511); + this.intent.launch(intent); } else { com.muqingbfq.mq.floating.start(sz.this); } @@ -93,15 +101,4 @@ public class sz extends AppCompatActivity { } }); } - - @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data) { - super.onActivityResult(requestCode, resultCode, data); - if (requestCode == 114511) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && Settings.canDrawOverlays(this)) { - com.muqingbfq.mq.floating.start(sz.this); - } - } - } - } \ No newline at end of file diff --git a/app/src/main/java/com/muqingbfq/view/TextView.java b/app/src/main/java/com/muqingbfq/view/Text.java similarity index 69% rename from app/src/main/java/com/muqingbfq/view/TextView.java rename to app/src/main/java/com/muqingbfq/view/Text.java index 5ee4292..652831f 100644 --- a/app/src/main/java/com/muqingbfq/view/TextView.java +++ b/app/src/main/java/com/muqingbfq/view/Text.java @@ -6,19 +6,19 @@ import android.util.AttributeSet; import androidx.annotation.NonNull; -public class TextView extends androidx.appcompat.widget.AppCompatTextView { - public TextView(@NonNull Context context) { +public class Text extends androidx.appcompat.widget.AppCompatTextView { + public Text(@NonNull Context context) { super(context); initView(); } - public TextView(Context context, AttributeSet attrs) { + public Text(Context context, AttributeSet attrs) { super(context, attrs); initView(); } - public TextView(Context context, AttributeSet attrs, int defStyleAttr) { + public Text(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); initView(); } diff --git a/app/src/main/res/drawable/icon.xml b/app/src/main/res/drawable/icon.xml index f51187c..ae0caa1 100644 --- a/app/src/main/res/drawable/icon.xml +++ b/app/src/main/res/drawable/icon.xml @@ -5,8 +5,8 @@ android:viewportHeight="1024"> + android:fillColor="#000000"/> + android:fillColor="#000000"/> diff --git a/app/src/main/res/layout-land/activity_bfq.xml b/app/src/main/res/layout-land/activity_bfq.xml new file mode 100644 index 0000000..cef7ddf --- /dev/null +++ b/app/src/main/res/layout-land/activity_bfq.xml @@ -0,0 +1,134 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout-land/fragment_bfq.xml b/app/src/main/res/layout-land/fragment_bfq.xml index ca5fdb5..c687417 100644 --- a/app/src/main/res/layout-land/fragment_bfq.xml +++ b/app/src/main/res/layout-land/fragment_bfq.xml @@ -67,89 +67,4 @@ android:layout_height="wrap_content" android:text="@string/_00_00" /> - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/activity_bfq.xml b/app/src/main/res/layout/activity_bfq.xml index 009b959..3c9b3fa 100644 --- a/app/src/main/res/layout/activity_bfq.xml +++ b/app/src/main/res/layout/activity_bfq.xml @@ -1,22 +1,25 @@ + + app:menu="@menu/bfq" + app:navigationIcon="@drawable/end"> + - + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_bfq.xml b/app/src/main/res/layout/fragment_bfq.xml index 5bf4afc..e2445a2 100644 --- a/app/src/main/res/layout/fragment_bfq.xml +++ b/app/src/main/res/layout/fragment_bfq.xml @@ -17,7 +17,8 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" - android:gravity="center"> + android:gravity="center" + tools:ignore="NestedWeights"> - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index 9303831..0d0bce8 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -18,6 +18,13 @@