version:
update:增加刷新,更换背景颜色 fix bug:
This commit is contained in:
@@ -16,7 +16,7 @@ android {
|
||||
multiDexEnabled true
|
||||
ndk {
|
||||
// add support lib
|
||||
abiFilters 'armeabi-v7a' //, 'arm64-v8a'//, "mips" //,'armeabi''x86',, 'x86_64',
|
||||
abiFilters /*"armeabi",*/ "armeabi-v7a", "arm64-v8a", "x86"/*, "x86_64", "mips", "mips64"*/
|
||||
}
|
||||
|
||||
lintOptions {
|
||||
@@ -71,6 +71,7 @@ dependencies {
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
|
||||
implementation 'androidx.recyclerview:recyclerview:1.1.0'
|
||||
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
|
||||
|
||||
implementation 'com.github.bumptech.glide:glide:4.11.0'
|
||||
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
|
||||
@@ -87,11 +88,12 @@ dependencies {
|
||||
implementation 'com.danikula:videocache:2.7.0'
|
||||
implementation 'com.aliyun.sdk.android:AliyunPlayer:4.5.0-full'
|
||||
implementation 'com.alivc.conan:AlivcConan:0.9.5'
|
||||
implementation 'com.scwang.smart:refresh-layout-kernel:2.0.1'
|
||||
implementation 'com.scwang.smart:refresh-header-material:2.0.1'
|
||||
implementation 'com.scwang.smart:refresh-footer-classics:2.0.1'
|
||||
// implementation 'com.scwang.smart:menu_refresh-layout-kernel:2.0.1'
|
||||
// implementation 'com.scwang.smart:menu_refresh-header-material:2.0.1'
|
||||
// implementation 'com.scwang.smart:menu_refresh-footer-classics:2.0.1'
|
||||
implementation 'tv.danmaku.ijk.media:ijkplayer-java:0.8.8'
|
||||
implementation 'tv.danmaku.ijk.media:ijkplayer-armv7a:0.8.4'
|
||||
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.3'
|
||||
implementation 'com.github.SheHuan:NiceImageView:1.0.5'
|
||||
implementation project(path: ':library')
|
||||
}
|
||||
|
||||
@@ -1,26 +1,42 @@
|
||||
package com.uiui.videoplayer.activity;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.recyclerview.widget.DefaultItemAnimator;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.recyclerview.widget.SimpleItemAnimator;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.text.SpannableString;
|
||||
import android.text.Spanned;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.uiui.videoplayer.R;
|
||||
import com.uiui.videoplayer.base.RecycleGridLayoutManager;
|
||||
import com.uiui.videoplayer.base.SpacesItemDecoration;
|
||||
import com.uiui.videoplayer.adapter.VideoAdapter;
|
||||
import com.uiui.videoplayer.utils.ToastUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
@@ -32,9 +48,12 @@ public class MainActivity extends AppCompatActivity {
|
||||
String[] permissions = new String[]{Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE};
|
||||
private RecyclerView recyclerView;
|
||||
private TextView tips;
|
||||
private SwipeRefreshLayout refreshLayout;
|
||||
private VideoAdapter adapter;
|
||||
private RecycleGridLayoutManager mManager;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -68,7 +87,19 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
initActionBar();
|
||||
tips = findViewById(R.id.tips);
|
||||
refreshLayout = findViewById(R.id.swipeRefreshLayout);
|
||||
refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
ScanTask scanTask = new ScanTask();
|
||||
scanTask.execute();
|
||||
}
|
||||
});
|
||||
refreshLayout.setRefreshing(true);
|
||||
recyclerView = findViewById(R.id.recyclerView);
|
||||
((SimpleItemAnimator) recyclerView.getItemAnimator()).setSupportsChangeAnimations(false);
|
||||
int orientation = getResources().getConfiguration().orientation;
|
||||
if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
||||
mManager = new RecycleGridLayoutManager(MainActivity.this, 3);
|
||||
@@ -82,6 +113,34 @@ public class MainActivity extends AppCompatActivity {
|
||||
((DefaultItemAnimator) recyclerView.getItemAnimator()).setSupportsChangeAnimations(false);
|
||||
}
|
||||
|
||||
private void initActionBar() {
|
||||
setToolbarCustomTheme();
|
||||
//显示返回按钮
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
if (actionBar != null) {
|
||||
actionBar.setHomeButtonEnabled(true);
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
SpannableString spannableString = new SpannableString(getString(R.string.app_name));
|
||||
ForegroundColorSpan colorSpan = new ForegroundColorSpan(getResources().getColor(R.color.defaultColor));
|
||||
spannableString.setSpan(colorSpan, 0, spannableString.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
actionBar.setTitle(spannableString);
|
||||
}
|
||||
// 系统 6.0 以上 状态栏白底黑字的实现方法
|
||||
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
|
||||
}
|
||||
|
||||
//自定义颜色返回按钮
|
||||
protected void setToolbarCustomTheme() {
|
||||
Drawable upArrow = ContextCompat.getDrawable(this, R.drawable.abc_ic_ab_back_material);
|
||||
if (upArrow != null) {
|
||||
upArrow.setColorFilter(ContextCompat.getColor(this, R.color.defaultColor), PorterDuff.Mode.SRC_ATOP);
|
||||
if (getSupportActionBar() != null) {
|
||||
getSupportActionBar().setHomeAsUpIndicator(upArrow);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// private String[] getFolder(String folderPath) {
|
||||
//
|
||||
// }
|
||||
@@ -123,7 +182,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private static final String[] extension = new String[]{
|
||||
".3gp", ".avi", ".flv", ".mkv", ".mov", ".mp4", ".webm"
|
||||
".3gp", ".avi", ".flv", ".mkv", ".mov", ".mp4", ".webm"
|
||||
};
|
||||
|
||||
private static boolean isVideoFormat(String filePath) {
|
||||
@@ -186,9 +245,17 @@ public class MainActivity extends AppCompatActivity {
|
||||
protected void onPostExecute(List<String> strings) {
|
||||
super.onPostExecute(strings);
|
||||
Log.e("ScanTask", "onPostExecute: " + strings);
|
||||
adapter = new VideoAdapter(MainActivity.this, strings);
|
||||
if (strings.size() == 0) {
|
||||
tips.setVisibility(View.VISIBLE);
|
||||
recyclerView.setVisibility(View.GONE);
|
||||
} else {
|
||||
tips.setVisibility(View.GONE);
|
||||
recyclerView.setVisibility(View.VISIBLE);
|
||||
adapter = new VideoAdapter(MainActivity.this, strings);
|
||||
// recyclerView.setLayoutManager(new LinearLayoutManager(MainActivity.this));
|
||||
recyclerView.setAdapter(adapter);
|
||||
recyclerView.setAdapter(adapter);
|
||||
}
|
||||
refreshLayout.setRefreshing(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,4 +286,42 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.main, menu);
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 监听标题栏按钮点击事件.
|
||||
*
|
||||
* @param item 按钮
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
//返回按钮点击事件
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
if (System.currentTimeMillis() - mPreClickTime > 1000) {
|
||||
ToastUtil.show("再按一次,退出");
|
||||
mPreClickTime = System.currentTimeMillis();
|
||||
} else {
|
||||
finish();
|
||||
}
|
||||
break;
|
||||
case R.id.refresh:
|
||||
refreshLayout.setRefreshing(true);
|
||||
ScanTask scanTask = new ScanTask();
|
||||
scanTask.execute();
|
||||
break;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
private long mPreClickTime;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.shehuan.niv.NiceImageView;
|
||||
import com.uiui.videoplayer.R;
|
||||
import com.uiui.videoplayer.activity.ActivityTikTok;
|
||||
import com.uiui.videoplayer.utils.ToastUtil;
|
||||
@@ -153,6 +154,11 @@ public class VideoAdapter extends RecyclerView.Adapter<VideoAdapter.VideoHolder>
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断Activity是否Destroy
|
||||
*
|
||||
@@ -168,7 +174,7 @@ public class VideoAdapter extends RecyclerView.Adapter<VideoAdapter.VideoHolder>
|
||||
}
|
||||
|
||||
static class VideoHolder extends RecyclerView.ViewHolder {
|
||||
ImageView video_image;
|
||||
NiceImageView video_image;
|
||||
TextView title, duration;
|
||||
ConstraintLayout root;
|
||||
|
||||
|
||||
BIN
app/src/main/res/drawable-hdpi/menu_back.png
Normal file
BIN
app/src/main/res/drawable-hdpi/menu_back.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.4 KiB |
BIN
app/src/main/res/drawable-hdpi/menu_refresh.png
Normal file
BIN
app/src/main/res/drawable-hdpi/menu_refresh.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.9 KiB |
@@ -1,16 +1,33 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".activity.MainActivity">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recyclerView"
|
||||
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
android:id="@+id/swipeRefreshLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="match_parent"
|
||||
>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recyclerView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
>
|
||||
|
||||
</androidx.recyclerview.widget.RecyclerView>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tips"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:text="没有找到视频文件"
|
||||
android:textColor="@color/defaultColor"
|
||||
android:visibility="gone" />
|
||||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||
|
||||
</androidx.recyclerview.widget.RecyclerView>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -1,16 +1,34 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".activity.MainActivity">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recyclerView"
|
||||
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
android:id="@+id/swipeRefreshLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/white"
|
||||
>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recyclerView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
>
|
||||
|
||||
</androidx.recyclerview.widget.RecyclerView>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tips"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:text="没有找到视频文件"
|
||||
android:textColor="@color/defaultColor"
|
||||
android:visibility="gone" />
|
||||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||
|
||||
</androidx.recyclerview.widget.RecyclerView>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -6,15 +6,18 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center">
|
||||
|
||||
<ImageView
|
||||
<com.shehuan.niv.NiceImageView
|
||||
android:id="@+id/video_image"
|
||||
android:layout_width="288dp"
|
||||
android:layout_height="162dp"
|
||||
android:layout_marginTop="4dp"
|
||||
android:adjustViewBounds="true"
|
||||
android:background="@color/black"
|
||||
android:scaleType="fitCenter"
|
||||
app:is_cover_src="true"
|
||||
app:corner_radius="5dp"
|
||||
android:background="@color/black"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.504"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
|
||||
9
app/src/main/res/menu/main.xml
Normal file
9
app/src/main/res/menu/main.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item
|
||||
android:id="@+id/refresh"
|
||||
android:icon="@drawable/menu_refresh"
|
||||
app:showAsAction="ifRoom"
|
||||
android:title="TODO" />
|
||||
</menu>
|
||||
@@ -5,5 +5,5 @@
|
||||
<color name="colorAccent">#03DAC5</color>
|
||||
<color name="white">#FFFFFF</color>
|
||||
<color name="black">#000000</color>
|
||||
|
||||
<color name="defaultColor">#333333</color>
|
||||
</resources>
|
||||
|
||||
@@ -3,9 +3,11 @@
|
||||
<!-- Base application theme. -->
|
||||
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
|
||||
<!-- Customize your theme here. -->
|
||||
<item name="colorPrimary">@color/colorPrimary</item>
|
||||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||
<item name="colorAccent">@color/colorAccent</item>
|
||||
<item name="colorPrimary">@color/white</item>
|
||||
<item name="colorPrimaryDark">@color/white</item>
|
||||
<item name="colorAccent">@color/defaultColor</item>
|
||||
</style>
|
||||
|
||||
|
||||
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user