Skip to content

Commit

Permalink
commit the activity_player-layout
Browse files Browse the repository at this point in the history
  • Loading branch information
Wriprin committed Dec 1, 2020
1 parent 6b2ec0d commit 83d1b1e
Show file tree
Hide file tree
Showing 25 changed files with 563 additions and 10 deletions.
4 changes: 4 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@ dependencies {
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

//Glide
implementation 'com.github.bumptech.glide:glide:4.11.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'

}
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.wriprin.android.ipod">

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".PlayerActivity"></activity>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
83 changes: 81 additions & 2 deletions app/src/main/java/io/wriprin/android/ipod/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,70 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.util.Log;
import android.widget.Toast;

import com.google.android.material.tabs.TabLayout;

import java.lang.reflect.Array;
import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

public static final int REQUEST_CODE = 1;
static ArrayList<MusicFiles> musicFiles;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initViewPager();
setContentView(R.layout.activity_player);
permission();

}

private void permission() {
if (ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED)
{
ActivityCompat.requestPermissions(MainActivity.this,new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},REQUEST_CODE);
}
else
{
musicFiles = getAllAudio(this);
initViewPager();
}
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == REQUEST_CODE)
{
if (grantResults[0] == PackageManager.PERMISSION_GRANTED)
{
//Do whatever you want permission related;
musicFiles = getAllAudio(this);
initViewPager();

}
else
{
ActivityCompat.requestPermissions(MainActivity.this,new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},REQUEST_CODE);
}
}
}

private void initViewPager() {
Expand Down Expand Up @@ -67,5 +113,38 @@ public CharSequence getPageTitle(int position) {
}
}

public static ArrayList<MusicFiles> getAllAudio (Context context)
{
ArrayList<MusicFiles> tempAudioList = new ArrayList<>();
Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
String[] projection =
{
MediaStore.Audio.Media.ALBUM,
MediaStore.Audio.Media.TITLE,
MediaStore.Audio.Media.DURATION,
MediaStore.Audio.Media.DATA, //for path
MediaStore.Audio.Media.ARTIST
};
Cursor cursor = context.getContentResolver().query(uri,projection,null,null,null);
if (cursor != null)
{
while (cursor.moveToNext())
{
String album = cursor.getString(0);
String title = cursor.getString(1);
String duration = cursor.getString(2);
String path = cursor.getString(3);
String artist = cursor.getString(4);

MusicFiles musicFiles = new MusicFiles(path,title,artist,album,duration);
//take log.e for check
Log.e("Path:" + path, "Album" + album);
tempAudioList.add(musicFiles);
}
cursor.close();
}
return tempAudioList;
}


}
83 changes: 83 additions & 0 deletions app/src/main/java/io/wriprin/android/ipod/MusicAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package io.wriprin.android.ipod;

import android.content.Context;
import android.media.MediaMetadata;
import android.media.MediaMetadataRetriever;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;

import org.w3c.dom.Text;

import java.lang.reflect.Array;
import java.util.ArrayList;

public class MusicAdapter extends RecyclerView.Adapter<MusicAdapter.MyVieHolder> {

private Context mContext;
private ArrayList<MusicFiles> mFiles;

MusicAdapter(Context mContext, ArrayList<MusicFiles> mFiles)
{
this.mFiles = mFiles;
this.mContext = mContext;
}

@NonNull
@Override
public MyVieHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(mContext).inflate(R.layout.music_items,parent,false);
return new MyVieHolder(view);
}

@Override
public void onBindViewHolder(@NonNull MyVieHolder holder, int position) {
holder.file_name.setText(mFiles.get(position).getTitle());
byte[] image = getAmbumArt(mFiles.get(position).getPath());
if (image != null)
{
Glide.with(mContext).asBitmap()
.load(image)
.into(holder.album_art);
}
else {
Glide.with(mContext)
.load(R.drawable.bewedoc)
.into(holder.album_art);
}
}

@Override
public int getItemCount() {
return mFiles.size();
}

public class MyVieHolder extends RecyclerView.ViewHolder
{
TextView file_name;
ImageView album_art;

public MyVieHolder(@NonNull View itemView) {
super(itemView);
file_name = itemView.findViewById(R.id.music_file_name);
album_art = itemView.findViewById(R.id.music_img);
}
}

private byte[] getAmbumArt(String uri)
{
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(uri);
byte[] art = retriever.getEmbeddedPicture();
retriever.release();
return art;
}
}
60 changes: 60 additions & 0 deletions app/src/main/java/io/wriprin/android/ipod/MusicFiles.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package io.wriprin.android.ipod;

public class MusicFiles {
private String path;
private String title;
private String artist;
private String album;
private String duration;

public MusicFiles(String path, String title, String artist, String album, String duration) {
this.path = path;
this.title = title;
this.artist = artist;
this.album = album;
this.duration = duration;
}

public MusicFiles() {
}

public String getPath() {
return path;
}

public void setPath(String path) {
this.path = path;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public String getArtist() {
return artist;
}

public void setArtist(String artist) {
this.artist = artist;
}

public String getAlbum() {
return album;
}

public void setAlbum(String album) {
this.album = album;
}

public String getDuration() {
return duration;
}

public void setDuration(String duration) {
this.duration = duration;
}
}
14 changes: 14 additions & 0 deletions app/src/main/java/io/wriprin/android/ipod/PlayerActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.wriprin.android.ipod;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class PlayerActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_player);
}
}
14 changes: 14 additions & 0 deletions app/src/main/java/io/wriprin/android/ipod/SongsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@
import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import static io.wriprin.android.ipod.MainActivity.musicFiles;

/**
* A simple {@link Fragment} subclass.
*/
public class SongsFragment extends Fragment {

RecyclerView recyclerView;
MusicAdapter musicAdapter;
public SongsFragment() {
// Required empty public constructor
}
Expand All @@ -23,6 +29,14 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_songs, container, false);
recyclerView = view.findViewById(R.id.recyclerView);
recyclerView.setHasFixedSize(true);
if (!(musicFiles.size() < 1))
{
musicAdapter = new MusicAdapter(getContext(),musicFiles);
recyclerView.setAdapter(musicAdapter);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext(),RecyclerView.VERTICAL,false));
}
return view;
}
}
Binary file added app/src/main/res/drawable/bewedoc.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/gradient_bg.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">

<gradient android:startColor="@color/colorPrimaryDark" android:angle="90"/>
</shape>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_chevron_left.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="#FFFFFF"
android:pathData="M15.41,7.41L14,6l-6,6 6,6 1.41,-1.41L10.83,12z"/>
</vector>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_menu.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="#FFFFFF"
android:pathData="M3,18h18v-2L3,16v2zM3,13h18v-2L3,11v2zM3,6v2h18L21,6L3,6z"/>
</vector>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_pause.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M6,19h4L10,5L6,5v14zM14,5v14h4L18,5h-4z"/>
</vector>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_play.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M8,5v14l11,-7z"/>
</vector>
Loading

0 comments on commit 83d1b1e

Please sign in to comment.