增加导入音频功能
This commit is contained in:
parent
838114d58d
commit
af051d6f52
@ -3,7 +3,11 @@
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.SET_WALLPAPER" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
|
||||
android:maxSdkVersion="32" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
|
||||
android:maxSdkVersion="32" />
|
||||
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
|
||||
|
||||
<application
|
||||
android:name=".resolve.Sounds"
|
||||
|
||||
@ -0,0 +1,6 @@
|
||||
package com.example.funnysounds.action;
|
||||
|
||||
public interface RecordDialogClickListener {
|
||||
void onImport();
|
||||
void onRecord();
|
||||
}
|
||||
@ -5,6 +5,7 @@ import android.database.ContentObserver;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.media.AudioManager;
|
||||
import android.media.MediaPlayer;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.provider.Settings;
|
||||
@ -12,6 +13,7 @@ import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
@ -19,6 +21,7 @@ import android.widget.Toast;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.lifecycle.Observer;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.DataSource;
|
||||
@ -38,8 +41,7 @@ import com.example.funnysounds.value.StaticValue;
|
||||
import java.io.IOException;
|
||||
|
||||
public class DetailActivity extends AppCompatActivity {
|
||||
private String name;
|
||||
private String image;
|
||||
|
||||
private MyData resource;
|
||||
private String media;
|
||||
private TextView textView;
|
||||
@ -49,6 +51,7 @@ public class DetailActivity extends AppCompatActivity {
|
||||
private boolean play = false;
|
||||
private SeekBar volumeSeekbar;
|
||||
private ImageView imLoop, imAddLove;
|
||||
private ProgressBar pbLoading;
|
||||
|
||||
|
||||
@Override
|
||||
@ -62,6 +65,7 @@ public class DetailActivity extends AppCompatActivity {
|
||||
volumeSeekbar = findViewById(R.id.seekbar);
|
||||
imLoop = findViewById(R.id.im_loop);
|
||||
imAddLove = findViewById(R.id.im_add_love);
|
||||
pbLoading = findViewById(R.id.loading);
|
||||
goGetData();
|
||||
initMediaPlayer();
|
||||
setVolume(volumeSeekbar);
|
||||
@ -110,30 +114,51 @@ public class DetailActivity extends AppCompatActivity {
|
||||
textView.setText(resource.getTitle());
|
||||
media = resource.getMp3Url();
|
||||
Log.d("----", "---media" + media);
|
||||
image = resource.getPreUrl();
|
||||
Glide.with(this).load(image).addListener(new RequestListener<Drawable>() {
|
||||
MyRoom.getInstance().getDataDao().queryAudioIsLove(resource.getId()).observe(this, new Observer<MyData>() {
|
||||
@Override
|
||||
public boolean onLoadFailed(@Nullable GlideException e, @Nullable Object model, @NonNull Target<Drawable> target, boolean isFirstResource) {
|
||||
return false;
|
||||
public void onChanged(MyData myData) {
|
||||
Log.d("----", "---myData.isAddLove()=" + myData.isAddLove());
|
||||
imAddLove.setSelected(myData.isAddLove());
|
||||
}
|
||||
});
|
||||
if(!resource.isSyStem()){
|
||||
imageView.setImageResource(R.mipmap.default_covert);
|
||||
}else {
|
||||
Glide.with(this).load(resource.getPreUrl()).addListener(new RequestListener<Drawable>() {
|
||||
@Override
|
||||
public boolean onLoadFailed(@Nullable GlideException e, @Nullable Object model, @NonNull Target<Drawable> target, boolean isFirstResource) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onResourceReady(@NonNull Drawable resource, @NonNull Object model, Target<Drawable> target, @NonNull DataSource dataSource, boolean isFirstResource) {
|
||||
return false;
|
||||
}
|
||||
}).into(imageView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onResourceReady(@NonNull Drawable resource, @NonNull Object model, Target<Drawable> target, @NonNull DataSource dataSource, boolean isFirstResource) {
|
||||
return false;
|
||||
}
|
||||
}).into(imageView);
|
||||
}
|
||||
|
||||
private void initMediaPlayer() {
|
||||
mediaPlayer = new MediaPlayer();
|
||||
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
|
||||
try {
|
||||
mediaPlayer.reset();
|
||||
mediaPlayer.setDataSource(resource.getMp3Url());
|
||||
String mp3Url = resource.getMp3Url();
|
||||
//content://com.android.providers.media.documents/document/audio%3A1000000468
|
||||
if(resource.isSyStem()){
|
||||
mediaPlayer.setDataSource(mp3Url);
|
||||
}else {
|
||||
Uri parse = Uri.parse(mp3Url);
|
||||
Log.d(Sounds.TAG,"--------Uri--="+parse);
|
||||
mediaPlayer.setDataSource(this,parse);
|
||||
|
||||
}
|
||||
mediaPlayer.prepareAsync();
|
||||
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
|
||||
@Override
|
||||
public void onPrepared(MediaPlayer mp) {
|
||||
// setLoading(false);
|
||||
setLoading(false);
|
||||
}
|
||||
});
|
||||
|
||||
@ -144,8 +169,17 @@ public class DetailActivity extends AppCompatActivity {
|
||||
}
|
||||
});
|
||||
} catch (IOException ioException) {
|
||||
// setLoading(false);
|
||||
Toast.makeText(this, "Prepare Fail", Toast.LENGTH_SHORT).show();
|
||||
setLoading(false);
|
||||
Log.d(Sounds.TAG,"-----------ioException="+ioException.getCause());
|
||||
Toast.makeText(this, getString(R.string.load_fail), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
private void setLoading(boolean isLoading){
|
||||
if(isLoading){
|
||||
pbLoading.setVisibility(View.VISIBLE);
|
||||
}else {
|
||||
pbLoading.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -23,6 +23,7 @@ import com.example.funnysounds.R;
|
||||
import com.example.funnysounds.databinding.ActivityMainBinding;
|
||||
import com.example.funnysounds.fragement.CategoryFragment;
|
||||
import com.example.funnysounds.fragement.LoveFragment;
|
||||
import com.example.funnysounds.fragement.RecordFragment;
|
||||
import com.google.android.material.tabs.TabLayout;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -110,7 +111,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
List<Fragment> fragmentList = new ArrayList<>();
|
||||
fragmentList.add(CategoryFragment.newInstance());
|
||||
fragmentList.add(LoveFragment.newInstance());
|
||||
fragmentList.add(RecordFragment.newInstance());
|
||||
fragmentList.add(LoveFragment.newInstance());
|
||||
|
||||
vb.viewPager.setAdapter(new FragmentStateAdapter(MainActivity.this) {
|
||||
|
||||
@ -82,7 +82,7 @@ public class SpecifisoundsActivity extends AppCompatActivity implements MyDataSo
|
||||
DataAdapter dataAdapter = new DataAdapter( this);
|
||||
dataAdapter.setMyDataSounderListener(this);
|
||||
recyclerview_specific.setAdapter(dataAdapter);
|
||||
MyRoom.getInstance().getDataDao().queryList(name.getCateId()).observe(this, new Observer<List<MyData>>() {
|
||||
MyRoom.getInstance().getDataDao().queryList(name.getCateId(),true).observe(this, new Observer<List<MyData>>() {
|
||||
@Override
|
||||
public void onChanged(List<MyData> myData) {
|
||||
Log.d(Sounds.TAG,"------------myData"+myData.size());
|
||||
|
||||
@ -12,13 +12,13 @@ import com.example.funnysounds.resolve.Sounds;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Entity(tableName = Sounds.TABLE_2, foreignKeys = @ForeignKey(entity = CategoryList.class, parentColumns = "cateId", childColumns = "categoryId", onDelete = ForeignKey.CASCADE),
|
||||
indices = @Index(value = {"id"}, unique = true))
|
||||
indices = {@Index(value = {"id"}, unique = true),@Index(value = {"mp3Url"}, unique = true)} )
|
||||
public class MyData implements Serializable {
|
||||
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
private long id;
|
||||
private long categoryId;
|
||||
|
||||
private boolean isSyStem;
|
||||
private String title;
|
||||
private String mp3Url;
|
||||
private String preUrl;
|
||||
@ -45,6 +45,14 @@ public class MyData implements Serializable {
|
||||
this.preUrl = preUrl;
|
||||
}
|
||||
|
||||
public boolean isSyStem() {
|
||||
return isSyStem;
|
||||
}
|
||||
|
||||
public void setSyStem(boolean syStem) {
|
||||
isSyStem = syStem;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@ -0,0 +1,94 @@
|
||||
package com.example.funnysounds.dialog;
|
||||
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.os.Bundle;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
|
||||
import com.example.funnysounds.R;
|
||||
import com.example.funnysounds.action.RecordDialogClickListener;
|
||||
import com.example.funnysounds.databinding.DialogRecordBinding;
|
||||
|
||||
|
||||
public class RecordDialog extends DialogFragment {
|
||||
|
||||
|
||||
private DialogRecordBinding vb;
|
||||
private RecordDialogClickListener mListener;
|
||||
|
||||
|
||||
public RecordDialog(RecordDialogClickListener listener) {
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
vb = DialogRecordBinding.inflate(inflater, container, false);
|
||||
init();
|
||||
return vb.getRoot();
|
||||
}
|
||||
|
||||
|
||||
private void init() {
|
||||
|
||||
Dialog dialog = getDialog();
|
||||
setCancelable(true);
|
||||
if (dialog != null) {
|
||||
Window window = dialog.getWindow();
|
||||
if (window != null) {
|
||||
window.setBackgroundDrawableResource(R.color.transparent);
|
||||
window.getDecorView().setPadding(0, 0, 0, 0);
|
||||
|
||||
WindowManager.LayoutParams attributes = window.getAttributes();
|
||||
attributes.gravity = Gravity.BOTTOM;
|
||||
attributes.width = WindowManager.LayoutParams.MATCH_PARENT;
|
||||
attributes.height = WindowManager.LayoutParams.WRAP_CONTENT;
|
||||
window.setAttributes(attributes);
|
||||
}
|
||||
}
|
||||
|
||||
vb.btnRecord.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mListener.onRecord();
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
vb.btnImport.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mListener.onImport();
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public void closeDialog() {
|
||||
dismiss();
|
||||
}
|
||||
|
||||
|
||||
public static RecordDialog newInstance(RecordDialogClickListener listener) {
|
||||
|
||||
RecordDialog okDialogFragment = new RecordDialog(listener);
|
||||
return okDialogFragment;
|
||||
}
|
||||
}
|
||||
@ -1,69 +1,197 @@
|
||||
package com.example.funnysounds.fragement;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.activity.result.ActivityResult;
|
||||
import androidx.activity.result.ActivityResultCallback;
|
||||
import androidx.activity.result.ActivityResultLauncher;
|
||||
import androidx.activity.result.contract.ActivityResultContracts;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
|
||||
|
||||
import com.example.funnysounds.action.IOListener;
|
||||
import com.example.funnysounds.action.RecordDialogClickListener;
|
||||
import com.example.funnysounds.data.MyData;
|
||||
import com.example.funnysounds.databinding.FragmentLoveBinding;
|
||||
import com.example.funnysounds.databinding.FragmentRecordBinding;
|
||||
import com.example.funnysounds.dialog.RecordDialog;
|
||||
import com.example.funnysounds.resolve.MySpace;
|
||||
import com.example.funnysounds.resolve.Readfile;
|
||||
import com.example.funnysounds.resolve.Sounds;
|
||||
import com.example.funnysounds.room.MyRoom;
|
||||
import com.example.funnysounds.soundsadapter.LoveAdapter;
|
||||
import com.example.funnysounds.soundsadapter.RecordAdapter;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class RecordFragment extends Fragment {
|
||||
|
||||
private RankViewModel mViewModel;
|
||||
private FragmentRecordBinding vb;
|
||||
|
||||
private RecordDialog dialog;
|
||||
private String[] permission1 = {Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE};
|
||||
private String[] permission2 = {Manifest.permission.READ_MEDIA_AUDIO};
|
||||
private ActivityResultLauncher<Intent> audioSelectLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), new ActivityResultCallback<ActivityResult>() {
|
||||
@Override
|
||||
public void onActivityResult(ActivityResult o) {
|
||||
if (o.getResultCode() == Activity.RESULT_OK) {
|
||||
Intent intent = o.getData();
|
||||
if (intent != null) {
|
||||
Uri audioUri = intent.getData();
|
||||
String name = Readfile.getAudioPathFromUri(audioUri);
|
||||
String decode = Uri.decode(String.valueOf(audioUri));
|
||||
|
||||
MyData myData = new MyData();
|
||||
myData.setCategoryId(1);
|
||||
myData.setSyStem(false);
|
||||
myData.setTitle(name);
|
||||
myData.setMp3Url(String.valueOf(audioUri));
|
||||
|
||||
Readfile.onSwitchIO(new IOListener() {
|
||||
@Override
|
||||
public void onRunIOAction() {
|
||||
MyRoom.getInstance().getDataDao().insertPrank(myData);
|
||||
}
|
||||
});
|
||||
// 处理选中的音频URI
|
||||
Log.d(Sounds.TAG, "--------audioUri=" + audioUri+"---audioPathFromUri="+name +"--------decode-----"+decode);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
private ActivityResultLauncher<String[]> permissionLauncher = registerForActivityResult(new ActivityResultContracts.RequestMultiplePermissions(), new ActivityResultCallback<Map<String, Boolean>>() {
|
||||
@Override
|
||||
public void onActivityResult(Map<String, Boolean> o) {
|
||||
boolean isOK = true;
|
||||
for (String key : o.keySet()) {
|
||||
Boolean aBoolean = o.get(key);
|
||||
Log.d(Sounds.TAG, "-----key="+key+"---aBoolean=" + aBoolean);
|
||||
if (aBoolean != null)
|
||||
isOK = aBoolean;
|
||||
}
|
||||
if(isOK){
|
||||
selectAudio();
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
public static RecordFragment newInstance() {
|
||||
return new RecordFragment();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
vb = FragmentRecordBinding.inflate(inflater, container, false);
|
||||
Log.d(Sounds.TAG, "-------onCreateView");
|
||||
return vb.getRoot();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
Log.d(Sounds.TAG, "-------onActivityCreated");
|
||||
mViewModel = new ViewModelProvider(this).get(RankViewModel.class);
|
||||
|
||||
init();
|
||||
|
||||
vb.addBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (dialog == null) {
|
||||
dialog = RecordDialog.newInstance(new RecordDialogClickListener() {
|
||||
@Override
|
||||
public void onImport() {
|
||||
checkPermissionAudio();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRecord() {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
dialog.show(requireActivity().getSupportFragmentManager(), "");
|
||||
}
|
||||
});
|
||||
}
|
||||
private void checkPermissionAudio() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
int i = ContextCompat.checkSelfPermission(requireActivity(), Manifest.permission.READ_MEDIA_AUDIO);
|
||||
if (i != PackageManager.PERMISSION_GRANTED) {
|
||||
permissionLauncher.launch(permission2);
|
||||
} else {
|
||||
selectAudio();
|
||||
}
|
||||
} else {
|
||||
int i = ContextCompat.checkSelfPermission(requireActivity(), Manifest.permission.READ_EXTERNAL_STORAGE);
|
||||
if (i != PackageManager.PERMISSION_GRANTED) {
|
||||
permissionLauncher.launch(permission1);
|
||||
} else {
|
||||
selectAudio();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void selectAudio() {
|
||||
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
|
||||
intent.setType("audio/*");
|
||||
audioSelectLauncher.launch(Intent.createChooser(intent, "Select Audio"));
|
||||
}
|
||||
|
||||
private void init() {
|
||||
MySpace mySpace = new MySpace(20, 20, 25);
|
||||
LinearLayoutManager layoutManager = new LinearLayoutManager(requireActivity());
|
||||
vb.loveRecycler.setLayoutManager(layoutManager);
|
||||
vb.loveRecycler.addItemDecoration(mySpace);
|
||||
LoveAdapter loveAdapter = new LoveAdapter(requireActivity());
|
||||
vb.recordRecycler.setLayoutManager(layoutManager);
|
||||
vb.recordRecycler.addItemDecoration(mySpace);
|
||||
RecordAdapter recordAdapter = new RecordAdapter(requireActivity());
|
||||
|
||||
vb.loveRecycler.setAdapter(loveAdapter);
|
||||
MyRoom.getInstance().getDataDao().queryLoveList(true).observe(requireActivity(), new Observer<List<MyData>>() {
|
||||
vb.recordRecycler.setAdapter(recordAdapter);
|
||||
MyRoom.getInstance().getDataDao().queryMyAudioList(false).observe(requireActivity(), new Observer<List<MyData>>() {
|
||||
@Override
|
||||
public void onChanged(List<MyData> list) {
|
||||
if (list.size() > 0) {
|
||||
vb.tvNoFavorites.setVisibility(View.GONE);
|
||||
}else {
|
||||
vb.tvNoFavorites.setVisibility(View.VISIBLE);
|
||||
setVisibility(true);
|
||||
} else {
|
||||
setVisibility(false);
|
||||
}
|
||||
loveAdapter.setMyDataList(list);
|
||||
recordAdapter.setMyDataList(list);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void setVisibility(boolean hasData) {
|
||||
if (hasData) {
|
||||
vb.recordRecycler.setVisibility(View.VISIBLE);
|
||||
vb.textNoFile.setVisibility(View.GONE);
|
||||
} else {
|
||||
vb.recordRecycler.setVisibility(View.GONE);
|
||||
vb.textNoFile.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,8 @@
|
||||
package com.example.funnysounds.resolve;
|
||||
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.provider.MediaStore;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
|
||||
@ -21,6 +24,7 @@ import java.io.StringWriter;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class Readfile {
|
||||
public static String getCovertStr(InputStream stream) {
|
||||
@ -75,6 +79,7 @@ public class Readfile {
|
||||
prank.setMp3Url(mp3Url);
|
||||
prank.setTitle(title);
|
||||
prank.setPreUrl(preUrl);
|
||||
prank.setSyStem(true);
|
||||
prank.setCategoryId(id);
|
||||
MyRoom.getInstance().getDataDao().insertPrank(prank);
|
||||
Log.d(Sounds.TAG,"title" + title + "---id=" + id);
|
||||
@ -100,4 +105,27 @@ public class Readfile {
|
||||
thread.start();
|
||||
return thread;
|
||||
}
|
||||
|
||||
|
||||
public static String getAudioPathFromUri(Uri uri) {
|
||||
String name = null;
|
||||
Cursor cursor = Sounds.mAppContext.getContentResolver().query(uri, null, MediaStore.Audio.Media.DATA, null, null);
|
||||
if (cursor != null) {
|
||||
while (cursor.moveToNext()) {
|
||||
for (String columnName : cursor.getColumnNames()) {
|
||||
int columnIndex = cursor.getColumnIndex(columnName);
|
||||
if(columnIndex>=0){
|
||||
String string = cursor.getString(columnIndex);
|
||||
if(Objects.equals(columnName, "_display_name")){
|
||||
name = string;
|
||||
}
|
||||
Log.d(Sounds.TAG,"-----columnName="+columnName+"----string="+string);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
cursor.close();
|
||||
}
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,17 +17,21 @@ public interface DataDao {
|
||||
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||
void insertPrank(MyData data);
|
||||
|
||||
@Query("select * from table_data")
|
||||
List<MyData> queryAll();
|
||||
|
||||
@Query("select * from table_data where categoryId ==:mId")
|
||||
LiveData<List<MyData>> queryList(long mId);
|
||||
|
||||
@Query("select * from table_data where categoryId ==:mId And isSyStem = :isSystem")
|
||||
LiveData<List<MyData>> queryList(long mId,boolean isSystem);
|
||||
|
||||
|
||||
@Query("select * from table_data where addLove ==:love")
|
||||
LiveData<List<MyData>> queryLoveList(boolean love);
|
||||
|
||||
|
||||
@Query("select * from table_data where isSyStem ==:isSystem")
|
||||
LiveData<List<MyData>> queryMyAudioList(boolean isSystem);
|
||||
|
||||
@Query("select * from table_data where id=:mid Limit 1")
|
||||
LiveData<MyData> queryAudioIsLove(long mid);
|
||||
@Update
|
||||
void updatePrank(MyData myData);
|
||||
}
|
||||
|
||||
@ -59,12 +59,17 @@ public class LoveAdapter extends RecyclerView.Adapter<LoveAdapter.VH> {
|
||||
MyData myData = myDataList.get(position);
|
||||
holder.getVb().name.setText(myData.getTitle());
|
||||
|
||||
String preUrl = myData.getPreUrl();
|
||||
if(preUrl!= null&&!preUrl.isEmpty()){
|
||||
Glide.with(myContext)
|
||||
.asDrawable()
|
||||
.load(myData.getPreUrl())
|
||||
.placeholder(R.mipmap.logo)
|
||||
.into(holder.getVb().imSounds);
|
||||
}else {
|
||||
holder.getVb().imSounds.setImageResource(R.mipmap.default_covert);
|
||||
}
|
||||
|
||||
Glide.with(myContext)
|
||||
.asDrawable()
|
||||
.load(myData.getPreUrl())
|
||||
.placeholder(R.mipmap.logo)
|
||||
.into(holder.getVb().imSounds);
|
||||
holder.getVb().getRoot().setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
@ -0,0 +1,103 @@
|
||||
package com.example.funnysounds.soundsadapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.example.funnysounds.R;
|
||||
import com.example.funnysounds.action.IOListener;
|
||||
import com.example.funnysounds.action.MyDataSounderListener;
|
||||
import com.example.funnysounds.activity.DetailActivity;
|
||||
import com.example.funnysounds.data.MyData;
|
||||
import com.example.funnysounds.databinding.ItemLoveBinding;
|
||||
import com.example.funnysounds.databinding.ItemRecordBinding;
|
||||
import com.example.funnysounds.resolve.Readfile;
|
||||
import com.example.funnysounds.resolve.Sounds;
|
||||
import com.example.funnysounds.room.MyRoom;
|
||||
import com.example.funnysounds.value.StaticValue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RecordAdapter extends RecyclerView.Adapter<RecordAdapter.VH> {
|
||||
private List<MyData> myDataList = new ArrayList<>();
|
||||
private Context myContext;
|
||||
private MyDataSounderListener myDataSounderListener;
|
||||
|
||||
public RecordAdapter(Context mycontext) {
|
||||
myContext = mycontext;
|
||||
}
|
||||
|
||||
public void setMyDataList(List<MyData> myDataList) {
|
||||
this.myDataList = myDataList;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void setMyDataSounderListener(MyDataSounderListener dataSounderListener) {
|
||||
this.myDataSounderListener = dataSounderListener;
|
||||
}
|
||||
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public VH onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
|
||||
ItemRecordBinding inflate = ItemRecordBinding.inflate(LayoutInflater.from(myContext), parent, false);
|
||||
|
||||
return new VH(inflate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull VH holder, int position) {
|
||||
MyData myData = myDataList.get(position);
|
||||
holder.getVb().name.setText(myData.getTitle());
|
||||
|
||||
String preUrl = myData.getPreUrl();
|
||||
if(preUrl!= null&&!preUrl.isEmpty()){
|
||||
Glide.with(myContext)
|
||||
.asDrawable()
|
||||
.load(myData.getPreUrl())
|
||||
.placeholder(R.mipmap.logo)
|
||||
.into(holder.getVb().imSounds);
|
||||
}else {
|
||||
holder.getVb().imSounds.setImageResource(R.mipmap.default_covert);
|
||||
}
|
||||
|
||||
holder.getVb().getRoot().setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(myContext, DetailActivity.class);
|
||||
intent.putExtra(StaticValue.key_resourse, myData);
|
||||
myContext.startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return myDataList.size();
|
||||
}
|
||||
|
||||
|
||||
public static class VH extends RecyclerView.ViewHolder {
|
||||
|
||||
private ItemRecordBinding vb;
|
||||
|
||||
public VH(@NonNull ItemRecordBinding itemView) {
|
||||
super(itemView.getRoot());
|
||||
vb = itemView;
|
||||
}
|
||||
|
||||
public ItemRecordBinding getVb() {
|
||||
return vb;
|
||||
}
|
||||
}
|
||||
}
|
||||
8
app/src/main/res/drawable/add_record_bg_button.xml
Normal file
8
app/src/main/res/drawable/add_record_bg_button.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
|
||||
<corners android:radius="8dp"/>
|
||||
<solid android:color="@color/add_btn_bg"/>
|
||||
|
||||
</shape>
|
||||
8
app/src/main/res/drawable/bg_button.xml
Normal file
8
app/src/main/res/drawable/bg_button.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
|
||||
<corners android:radius="8dp"/>
|
||||
<solid android:color="@color/end"/>
|
||||
|
||||
</shape>
|
||||
7
app/src/main/res/drawable/dialog_bg.xml
Normal file
7
app/src/main/res/drawable/dialog_bg.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<solid android:color="@color/white" />
|
||||
<corners android:topLeftRadius="12dp" android:topRightRadius="12dp"/>
|
||||
|
||||
</shape>
|
||||
12
app/src/main/res/drawable/im_add_record.xml
Normal file
12
app/src/main/res/drawable/im_add_record.xml
Normal file
@ -0,0 +1,12 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="20dp"
|
||||
android:height="20dp"
|
||||
android:viewportWidth="20"
|
||||
android:viewportHeight="20">
|
||||
<path
|
||||
android:pathData="M10.001,16.665V9.999M10.001,9.999V3.332M10.001,9.999H16.667M10.001,9.999H3.334"
|
||||
android:strokeWidth="2"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="#ffffff"
|
||||
android:strokeLineCap="round"/>
|
||||
</vector>
|
||||
27
app/src/main/res/drawable/im_export.xml
Normal file
27
app/src/main/res/drawable/im_export.xml
Normal file
@ -0,0 +1,27 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="25dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="25"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:pathData="M21.5,13.5C21.5,16.5 19.5,21.5 12.5,21.5C5.5,21.5 3.5,16.5 3.5,13.5"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="2"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="#ffffff"
|
||||
android:strokeLineCap="round"/>
|
||||
<path
|
||||
android:pathData="M12.504,2.551V16.5"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="2"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="#ffffff"
|
||||
android:strokeLineCap="round"/>
|
||||
<path
|
||||
android:pathData="M6.5,8.5L12.5,2.5L18.5,8.5"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="2"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="#ffffff"
|
||||
android:strokeLineCap="round"/>
|
||||
</vector>
|
||||
@ -1,6 +1,6 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="64dp"
|
||||
android:height="64dp"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="1024"
|
||||
android:viewportHeight="1024">
|
||||
<path
|
||||
|
||||
36
app/src/main/res/drawable/im_record1.xml
Normal file
36
app/src/main/res/drawable/im_record1.xml
Normal file
@ -0,0 +1,36 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="25dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="25"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:pathData="M12.5,8.5V15.5"
|
||||
android:strokeWidth="2"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="#ffffff"
|
||||
android:strokeLineCap="round"/>
|
||||
<path
|
||||
android:pathData="M17,5.5V18.5"
|
||||
android:strokeWidth="2"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="#ffffff"
|
||||
android:strokeLineCap="round"/>
|
||||
<path
|
||||
android:pathData="M3.5,8.5V15.5"
|
||||
android:strokeWidth="2"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="#ffffff"
|
||||
android:strokeLineCap="round"/>
|
||||
<path
|
||||
android:pathData="M21.5,9V15"
|
||||
android:strokeWidth="2"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="#ffffff"
|
||||
android:strokeLineCap="round"/>
|
||||
<path
|
||||
android:pathData="M8,2V22"
|
||||
android:strokeWidth="2"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="#ffffff"
|
||||
android:strokeLineCap="round"/>
|
||||
</vector>
|
||||
@ -130,4 +130,11 @@
|
||||
android:layout_alignParentEnd="true"
|
||||
android:src="@drawable/im_volumehigh" />
|
||||
</RelativeLayout>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/loading"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:indeterminateTint="@color/loading_color" />
|
||||
</RelativeLayout>
|
||||
@ -6,8 +6,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
tools:context=".activity.MainActivity"
|
||||
tools:openDrawer="right">
|
||||
tools:context=".activity.MainActivity">
|
||||
|
||||
|
||||
<RelativeLayout
|
||||
|
||||
78
app/src/main/res/layout/dialog_record.xml
Normal file
78
app/src/main/res/layout/dialog_record.xml
Normal file
@ -0,0 +1,78 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/dialog_bg"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:paddingStart="24dp"
|
||||
android:paddingTop="12dp"
|
||||
android:paddingEnd="24dp"
|
||||
android:paddingBottom="44dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/adding_sound"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="20sp" />
|
||||
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/btn_import"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="25dp"
|
||||
android:layout_marginTop="24dp"
|
||||
android:layout_marginEnd="25dp"
|
||||
android:background="@drawable/bg_button">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="50dp"
|
||||
android:layout_centerInParent="true"
|
||||
android:layout_gravity="center"
|
||||
android:drawableStart="@drawable/im_export"
|
||||
android:drawablePadding="5dp"
|
||||
android:gravity="center"
|
||||
android:paddingStart="10dp"
|
||||
android:paddingEnd="10dp"
|
||||
android:text="@string/import_audio"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="16sp" />
|
||||
</RelativeLayout>
|
||||
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/btn_record"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="25dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginEnd="25dp"
|
||||
android:background="@drawable/bg_button">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_no_favorites"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="50dp"
|
||||
android:layout_centerInParent="true"
|
||||
android:layout_gravity="center"
|
||||
android:drawableStart="@drawable/im_record1"
|
||||
android:drawablePadding="5dp"
|
||||
android:gravity="center"
|
||||
android:paddingStart="10dp"
|
||||
android:paddingEnd="10dp"
|
||||
android:text="@string/record_audio"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="16sp" />
|
||||
</RelativeLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</FrameLayout>
|
||||
@ -1,21 +1,55 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".fragement.LoveFragment">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/love_recycler"
|
||||
android:id="@+id/record_recycler"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingTop="20dp" />
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_no_favorites"
|
||||
android:id="@+id/text_no_file"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:text="@string/no_favorites" />
|
||||
android:layout_centerInParent="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginStart="36dp"
|
||||
android:layout_marginTop="20dp"
|
||||
android:layout_marginEnd="36dp"
|
||||
android:gravity="center"
|
||||
android:lineSpacingExtra="4dp"
|
||||
android:text="@string/no_file"
|
||||
android:textColor="@color/text_color_gray"
|
||||
android:textSize="17sp" />
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/add_btn"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_marginStart="25dp"
|
||||
android:layout_marginEnd="25dp"
|
||||
android:layout_marginBottom="46dp"
|
||||
android:background="@drawable/add_record_bg_button">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="50dp"
|
||||
android:layout_centerInParent="true"
|
||||
android:layout_gravity="center"
|
||||
android:drawableStart="@drawable/im_add_record"
|
||||
android:drawablePadding="5dp"
|
||||
android:gravity="center"
|
||||
android:paddingStart="10dp"
|
||||
android:paddingEnd="10dp"
|
||||
android:text="@string/add_sound"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="16sp" />
|
||||
</RelativeLayout>
|
||||
</RelativeLayout>
|
||||
@ -13,9 +13,7 @@
|
||||
android:layout_marginStart="12dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:layout_marginBottom="12dp"
|
||||
android:background="@drawable/bg_love"
|
||||
android:padding="8dp"
|
||||
android:src="@mipmap/ic_launcher" />
|
||||
android:src="@mipmap/default_covert" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/name"
|
||||
|
||||
34
app/src/main/res/layout/item_record.xml
Normal file
34
app/src/main/res/layout/item_record.xml
Normal file
@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/layout_root"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/list_background"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/im_sounds"
|
||||
android:layout_width="80dp"
|
||||
android:layout_height="80dp"
|
||||
android:layout_marginStart="12dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:layout_marginBottom="12dp"
|
||||
android:src="@mipmap/default_covert" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginStart="43dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginBottom="15dp"
|
||||
android:layout_toEndOf="@id/im_sounds"
|
||||
android:text="@string/app_name"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="15sp" />
|
||||
|
||||
|
||||
|
||||
</RelativeLayout>
|
||||
BIN
app/src/main/res/mipmap-xxxhdpi/default_covert.png
Normal file
BIN
app/src/main/res/mipmap-xxxhdpi/default_covert.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
@ -16,4 +16,9 @@
|
||||
|
||||
<color name="add_love">#DF3737</color>
|
||||
<color name="seekbar_bg">#80A1A2A3</color>
|
||||
<color name="text_color_gray">#A7A7A7</color>
|
||||
<color name="transparent">#00000000</color>
|
||||
<color name="add_btn_bg">#8072C8D5</color>
|
||||
|
||||
<color name="loading_color">#FB310D</color>
|
||||
</resources>
|
||||
@ -8,4 +8,10 @@
|
||||
<string name="remove">Removed from favorite</string>
|
||||
<string name="favorites">My Favorites</string>
|
||||
<string name="no_favorites">No favorites found</string>
|
||||
<string name="add_sound">Add sound</string>
|
||||
<string name="no_file">No files are present at the moment. Let\'s create one now.</string>
|
||||
<string name="adding_sound">Adding sound</string>
|
||||
<string name="import_audio">import audio</string>
|
||||
<string name="record_audio">Record sound</string>
|
||||
<string name="load_fail">Loading failed, please try again</string>
|
||||
</resources>
|
||||
Loading…
Reference in New Issue
Block a user