sample(ui): music file browser
This commit is contained in:
59
app/src/main/assets/sample/复杂界面/音乐浏览器.js
Normal file
59
app/src/main/assets/sample/复杂界面/音乐浏览器.js
Normal file
@@ -0,0 +1,59 @@
|
||||
"ui";
|
||||
|
||||
//音乐文件的后缀名
|
||||
var musicExts = [".mp3", ".wma", ".rm", ".wav", ".mid", ".ape", ".flac"];
|
||||
//扫描路径
|
||||
var path = files.getSdcardPath();
|
||||
//保存音乐文件列表的数组
|
||||
var musicFiles = [];
|
||||
|
||||
ui.layout(
|
||||
<vertical bg="#ffffff">
|
||||
<list id="files" layout_weight="1">
|
||||
<linear bg="?selectableItemBackground">
|
||||
<img src="@drawable/ic_music_note_black_48dp" tint="white" bg="#ff5722" w="50" h="70" margin="16" />
|
||||
<vertical>
|
||||
<text id="name" textSize="16sp" textColor="#000000" text="{{this.name}}" marginTop="16" maxLines="1" ellipsize="end"/>
|
||||
<text id="path" textSize="13sp" textColor="#929292" text="{{this.path}}" marginTop="8" maxLines="1" ellipsize="end"/>
|
||||
</vertical>
|
||||
</linear>
|
||||
</list>
|
||||
<progressbar id="progressbar" indeterminate="true" style="@style/Base.Widget.AppCompat.ProgressBar.Horizontal"/>
|
||||
</vertical>
|
||||
);
|
||||
|
||||
ui.files.setDataSource(musicFiles);
|
||||
|
||||
ui.files.on("item_click", function(item, pos){
|
||||
media.playMusic(item.path, 1);
|
||||
});
|
||||
|
||||
//启动线程来扫描音乐文件
|
||||
threads.start(function () {
|
||||
listMuiscFiles(path, musicFiles);
|
||||
ui.run(()=> {
|
||||
ui.progressbar.setVisility(8);
|
||||
});
|
||||
});
|
||||
|
||||
function listMuiscFiles(dir, list) {
|
||||
//遍历该文件夹的文件
|
||||
files.listDir(dir).forEach(fileName => {
|
||||
var path = files.join(dir, fileName);
|
||||
//如果是子文件夹则继续扫描子文件夹的文件
|
||||
if (files.isDir(path)) {
|
||||
listMuiscFiles(path, list);
|
||||
return;
|
||||
}
|
||||
for (var i = 0; i < musicExts.length; i++) {
|
||||
//如果文件名的后缀是音乐格式
|
||||
if (fileName.endsWith(musicExts[i])) {
|
||||
//则把它添加到列表中
|
||||
list.push({
|
||||
name: fileName,
|
||||
path: path
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package android.workground;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/2/13.
|
||||
* http://stackoverflow.com/questions/31759171/recyclerview-and-java-lang-indexoutofboundsexception-inconsistency-detected-in
|
||||
*/
|
||||
|
||||
public class WrapContentLinearLayoutManager extends LinearLayoutManager {
|
||||
public WrapContentLinearLayoutManager(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public WrapContentLinearLayoutManager(Context context, int orientation, boolean reverseLayout) {
|
||||
super(context, orientation, reverseLayout);
|
||||
}
|
||||
|
||||
public WrapContentLinearLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
|
||||
try {
|
||||
super.onLayoutChildren(recycler, state);
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
Log.e("LinearLayoutManager", "Android bug ", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
import android.workground.WrapContentLinearLayoutManager;
|
||||
import com.stardust.autojs.workground.WrapContentLinearLayoutManager;
|
||||
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.model.autocomplete.CodeCompletions;
|
||||
|
||||
@@ -12,7 +12,7 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.workground.WrapContentLinearLayoutManager;
|
||||
import com.stardust.autojs.workground.WrapContentLinearLayoutManager;
|
||||
|
||||
import com.bignerdranch.expandablerecyclerview.ChildViewHolder;
|
||||
import com.bignerdranch.expandablerecyclerview.ExpandableRecyclerAdapter;
|
||||
|
||||
Reference in New Issue
Block a user