Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2022 – 144
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ganepola G.A.S.L IT19050386
2022 – 144
Commits
e12e5bf8
Commit
e12e5bf8
authored
Nov 18, 2022
by
Ravishani W.M.S
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
6334b47e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
164 additions
and
0 deletions
+164
-0
MusicTherapyF.java
MusicTherapyF.java
+164
-0
No files found.
MusicTherapyF.java
0 → 100644
View file @
e12e5bf8
package
com.example.smartpillow
;
import
androidx.appcompat.app.AppCompatActivity
;
import
android.Manifest
;
import
android.content.ContentProviderClient
;
import
android.content.Intent
;
import
android.os.Bundle
;
import
android.os.Environment
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.widget.AdapterView
;
import
android.widget.ArrayAdapter
;
import
android.widget.BaseAdapter
;
import
android.widget.Button
;
import
android.widget.ListView
;
import
android.widget.TextView
;
import
android.widget.Toast
;
import
com.karumi.dexter.Dexter
;
import
com.karumi.dexter.PermissionToken
;
import
com.karumi.dexter.listener.PermissionDeniedResponse
;
import
com.karumi.dexter.listener.PermissionGrantedResponse
;
import
com.karumi.dexter.listener.PermissionRequest
;
import
com.karumi.dexter.listener.single.PermissionListener
;
import
java.io.File
;
import
java.util.ArrayList
;
import
java.util.Enumeration
;
public
class
MusicTherapyF
extends
AppCompatActivity
{
ListView
listView
;
String
[]
items
;
Button
webView
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_music_therapy_f
);
listView
=
findViewById
(
R
.
id
.
listViewSong
);
webView
=
findViewById
(
R
.
id
.
youtubelog
);
webView
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
Intent
intent
=
new
Intent
(
MusicTherapyF
.
this
,
MusicTherapyT
.
class
);
startActivity
(
intent
);
}
});
runTimePermission
();
}
public
void
runTimePermission
()
{
Dexter
.
withContext
(
this
).
withPermission
(
Manifest
.
permission
.
READ_EXTERNAL_STORAGE
)
.
withListener
(
new
PermissionListener
()
{
@Override
public
void
onPermissionGranted
(
PermissionGrantedResponse
permissionGrantedResponse
)
{
displaySongs
();
}
@Override
public
void
onPermissionDenied
(
PermissionDeniedResponse
permissionDeniedResponse
)
{
}
@Override
public
void
onPermissionRationaleShouldBeShown
(
PermissionRequest
permissionRequest
,
PermissionToken
permissionToken
)
{
permissionToken
.
continuePermissionRequest
();
}
}).
check
();
}
public
ArrayList
<
File
>
findSong
(
File
file
)
{
ArrayList
<
File
>
arrayList
=
new
ArrayList
<>();
File
[]
files
=
file
.
listFiles
();
if
(
files
!=
null
)
{
for
(
File
singlefile
:
files
)
{
if
(
singlefile
.
isDirectory
()
&&
!
singlefile
.
isHidden
())
{
arrayList
.
addAll
(
findSong
(
singlefile
));
}
else
{
if
(
singlefile
.
getName
().
endsWith
(
".mp3"
)
||
singlefile
.
getName
().
endsWith
(
".wav"
))
{
arrayList
.
add
(
singlefile
);
}
}
}
}
return
arrayList
;
}
void
displaySongs
()
{
final
ArrayList
<
File
>
mySongs
=
findSong
(
Environment
.
getExternalStorageDirectory
());
items
=
new
String
[
mySongs
.
size
()];
for
(
int
i
=
0
;
i
<
mySongs
.
size
();
i
++)
{
items
[
i
]
=
mySongs
.
get
(
i
).
getName
().
toString
().
replace
(
".mp3"
,
""
).
replace
(
".wav"
,
""
);
}
/*ArrayAdapter<String> myAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, items);
listView.setAdapter(myAdapter);*/
customAdapter
customAdapter
=
new
customAdapter
();
listView
.
setAdapter
(
customAdapter
);
listView
.
setOnItemClickListener
(
new
AdapterView
.
OnItemClickListener
()
{
@Override
public
void
onItemClick
(
AdapterView
<?>
adapterView
,
View
view
,
int
i
,
long
l
)
{
String
songName
=
(
String
)
listView
.
getItemAtPosition
(
i
);
startActivity
(
new
Intent
(
getApplicationContext
(),
MusicTherapyS
.
class
)
.
putExtra
(
"songs"
,
mySongs
)
.
putExtra
(
"songname"
,
songName
)
.
putExtra
(
"pos"
,
i
));
}
});
}
class
customAdapter
extends
BaseAdapter
{
@Override
public
int
getCount
()
{
return
items
.
length
;
}
@Override
public
Object
getItem
(
int
i
)
{
return
null
;
}
@Override
public
long
getItemId
(
int
i
)
{
return
0
;
}
@Override
public
View
getView
(
int
i
,
View
view
,
ViewGroup
viewGroup
)
{
View
myView
=
getLayoutInflater
().
inflate
(
R
.
layout
.
list_item
,
null
);
TextView
textSong
=
myView
.
findViewById
(
R
.
id
.
txtsongname
);
textSong
.
setSelected
(
true
);
textSong
.
setText
(
items
[
i
]);
return
myView
;
}
}
@Override
public
void
onBackPressed
()
{
Intent
intent
=
new
Intent
(
MusicTherapyF
.
this
,
MainMenu
.
class
);
startActivity
(
intent
);
finish
();
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment