version:
update: fix bug:样式优化
This commit is contained in:
@@ -21,6 +21,7 @@ import com.uiui.videoplayer.R;
|
||||
import com.uiui.videoplayer.adapter.TikTokRecyclerViewAdapter;
|
||||
import com.uiui.videoplayer.base.ViewPagerLayoutManager;
|
||||
import com.uiui.videoplayer.listener.OnViewPagerListener;
|
||||
import com.uiui.videoplayer.utils.SPUtils;
|
||||
import com.uiui.videoplayer.utils.ToastUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -63,8 +64,15 @@ public class ActivityTikTok extends AppCompatActivity {
|
||||
if (mCurrentPosition + 1 < videoPath.size()) {
|
||||
rvTiktok.smoothScrollToPosition(mCurrentPosition + 1);
|
||||
} else {
|
||||
ToastUtil.show("播放完成");
|
||||
finish();
|
||||
int singleLoop = (int) SPUtils.get(ActivityTikTok.this, "loop", 0);
|
||||
if (singleLoop == 0) {
|
||||
ToastUtil.show("播放完成");
|
||||
finish();
|
||||
} else {
|
||||
rvTiktok.scrollToPosition(0);
|
||||
mCurrentPosition = 0;
|
||||
ToastUtil.show("列表结束,开始播放第一个视频");
|
||||
}
|
||||
}
|
||||
});
|
||||
mAdapter.setOrientationChangeListener(new TikTokRecyclerViewAdapter.onOrientationChangeListener() {
|
||||
|
||||
@@ -35,6 +35,7 @@ import com.uiui.videoplayer.adapter.VideoAdapter;
|
||||
import com.uiui.videoplayer.base.CustomDialog;
|
||||
import com.uiui.videoplayer.base.RecycleGridLayoutManager;
|
||||
import com.uiui.videoplayer.base.SpacesItemDecoration;
|
||||
import com.uiui.videoplayer.utils.SPUtils;
|
||||
import com.uiui.videoplayer.utils.ToastUtil;
|
||||
|
||||
import java.io.File;
|
||||
@@ -321,7 +322,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
for (String s : permissions) {
|
||||
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED) {
|
||||
mPermissionList.add(s);
|
||||
}else {
|
||||
} else {
|
||||
ScanTask scanTask = new ScanTask();
|
||||
scanTask.execute();
|
||||
}
|
||||
@@ -341,10 +342,10 @@ public class MainActivity extends AppCompatActivity {
|
||||
ScanTask scanTask = new ScanTask();
|
||||
scanTask.execute();
|
||||
} else if (grantResults[0] == PackageManager.PERMISSION_DENIED) {
|
||||
if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE)){
|
||||
if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE)) {
|
||||
ToastUtil.show("需要存储空间权限才能正常使用软件");
|
||||
checkSelfPermission();
|
||||
}else {
|
||||
} else {
|
||||
ToastUtil.show("请打开存储空间权限后使用软件");
|
||||
Intent intent = new Intent();
|
||||
intent.setAction(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
||||
@@ -356,11 +357,15 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private MenuItem refresh, single_loop, loop;
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.main, menu);
|
||||
refresh = menu.findItem(R.id.refresh);
|
||||
single_loop = menu.findItem(R.id.single_loop);
|
||||
loop = menu.findItem(R.id.loop);
|
||||
updateMenuIcon();
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
@@ -375,6 +380,9 @@ public class MainActivity extends AppCompatActivity {
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
//返回按钮点击事件
|
||||
switch (item.getItemId()) {
|
||||
case R.id.setting:
|
||||
|
||||
break;
|
||||
case android.R.id.home:
|
||||
if (System.currentTimeMillis() - mPreClickTime > 1000) {
|
||||
ToastUtil.show("再按一次,退出");
|
||||
@@ -388,12 +396,61 @@ public class MainActivity extends AppCompatActivity {
|
||||
ScanTask scanTask = new ScanTask();
|
||||
scanTask.execute();
|
||||
break;
|
||||
case R.id.single_loop:
|
||||
if (null != single_loop) {
|
||||
int singleLoop = (int) SPUtils.get(MainActivity.this, "single_loop", 0);
|
||||
if (singleLoop == 0) {
|
||||
SPUtils.put(MainActivity.this, "single_loop", 1);
|
||||
SPUtils.put(MainActivity.this, "loop", 0);
|
||||
single_loop.setIcon(R.drawable.menu_selected);
|
||||
} else {
|
||||
SPUtils.put(MainActivity.this, "single_loop", 0);
|
||||
single_loop.setIcon(null);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case R.id.loop:
|
||||
if (null != loop) {
|
||||
int singleLoop = (int) SPUtils.get(MainActivity.this, "loop", 0);
|
||||
if (singleLoop == 0) {
|
||||
SPUtils.put(MainActivity.this, "single_loop", 0);
|
||||
SPUtils.put(MainActivity.this, "loop", 1);
|
||||
loop.setIcon(R.drawable.menu_selected);
|
||||
} else {
|
||||
SPUtils.put(MainActivity.this, "loop", 0);
|
||||
loop.setIcon(null);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
updateMenuIcon();
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
private long mPreClickTime;
|
||||
|
||||
private void updateMenuIcon() {
|
||||
if (null != refresh) {
|
||||
|
||||
}
|
||||
if (null != single_loop) {
|
||||
int singleLoop = (int) SPUtils.get(MainActivity.this, "single_loop", 0);
|
||||
if (singleLoop == 0) {
|
||||
single_loop.setIcon(null);
|
||||
} else {
|
||||
single_loop.setIcon(R.drawable.menu_selected);
|
||||
}
|
||||
}
|
||||
if (null != loop) {
|
||||
int singleLoop = (int) SPUtils.get(MainActivity.this, "loop", 0);
|
||||
if (singleLoop == 0) {
|
||||
loop.setIcon(null);
|
||||
} else {
|
||||
loop.setIcon(R.drawable.menu_selected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.uiui.videoplayer.CustomJzvd.JzvdStdAssert;
|
||||
import com.uiui.videoplayer.R;
|
||||
import com.uiui.videoplayer.activity.MainActivity;
|
||||
import com.uiui.videoplayer.utils.SPUtils;
|
||||
import com.uiui.videoplayer.utils.Utils;
|
||||
|
||||
|
||||
@@ -68,6 +70,7 @@ public class TikTokRecyclerViewAdapter extends RecyclerView.Adapter<TikTokRecycl
|
||||
public interface onOrientationChangeListener {
|
||||
void onOrientationChange();
|
||||
}
|
||||
|
||||
public interface onGotoFullScreenListener {
|
||||
void gotoFullScreen();
|
||||
}
|
||||
@@ -86,7 +89,8 @@ public class TikTokRecyclerViewAdapter extends RecyclerView.Adapter<TikTokRecycl
|
||||
Log.i(TAG, "onBindViewHolder [" + holder.jzvdStdAssert.hashCode() + "] position=" + position);
|
||||
final String path = videoPath.get(position);
|
||||
JZDataSource jzDataSource = new JZDataSource(path, getFileName(path));
|
||||
jzDataSource.looping = false;
|
||||
int singleLoop = (int) SPUtils.get(context, "single_loop", 0);
|
||||
jzDataSource.looping = (singleLoop == 1);
|
||||
holder.jzvdStdAssert.setUp(jzDataSource, Jzvd.SCREEN_NORMAL);
|
||||
// Glide.with(holder.jzvdStd.getContext()).load(UrlsKt.getPl3()[position]).into(holder.jzvdStd.posterImageView);
|
||||
Observable.create((ObservableOnSubscribe<Bitmap>) emitter -> {
|
||||
|
||||
@@ -252,8 +252,8 @@ public class CustomDialog extends Dialog {
|
||||
@Override
|
||||
public void dismiss() {
|
||||
super.dismiss();
|
||||
Intent intent = new Intent(mContext, MainActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
mContext.startActivity(intent);
|
||||
// Intent intent = new Intent(mContext, MainActivity.class);
|
||||
// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
// mContext.startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
||||
194
app/src/main/java/com/uiui/videoplayer/utils/SPUtils.java
Normal file
194
app/src/main/java/com/uiui/videoplayer/utils/SPUtils.java
Normal file
@@ -0,0 +1,194 @@
|
||||
package com.uiui.videoplayer.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.util.Base64;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 作者 mjsheng
|
||||
* 日期 2018/10/9 18:41
|
||||
* 邮箱 501802639@qq.com
|
||||
* 来自:
|
||||
*/
|
||||
|
||||
public class SPUtils {
|
||||
/**
|
||||
* 保存在手机里面的文件名
|
||||
*/
|
||||
public static final String FILE_NAME = "share_data";
|
||||
|
||||
/**
|
||||
* 保存数据的方法,我们需要拿到保存数据的具体类型,然后根据类型调用不同的保存方法
|
||||
*/
|
||||
public static void put(Context context, String key, Object object) {
|
||||
|
||||
SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
|
||||
Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sp.edit();
|
||||
|
||||
if (object instanceof String) {
|
||||
editor.putString(key, (String) object);
|
||||
} else if (object instanceof Integer) {
|
||||
editor.putInt(key, (Integer) object);
|
||||
} else if (object instanceof Boolean) {
|
||||
editor.putBoolean(key, (Boolean) object);
|
||||
} else if (object instanceof Float) {
|
||||
editor.putFloat(key, (Float) object);
|
||||
} else if (object instanceof Long) {
|
||||
editor.putLong(key, (Long) object);
|
||||
} else {
|
||||
editor.putString(key, object.toString());
|
||||
}
|
||||
|
||||
SharedPreferencesCompat.apply(editor);
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到保存数据的方法,我们根据默认值得到保存的数据的具体类型,然后调用相对于的方法获取值
|
||||
*/
|
||||
public static Object get(Context context, String key, Object defaultObject) {
|
||||
SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
|
||||
Context.MODE_PRIVATE);
|
||||
|
||||
if (defaultObject instanceof String) {
|
||||
return sp.getString(key, (String) defaultObject);
|
||||
} else if (defaultObject instanceof Integer) {
|
||||
return sp.getInt(key, (Integer) defaultObject);
|
||||
} else if (defaultObject instanceof Boolean) {
|
||||
return sp.getBoolean(key, (Boolean) defaultObject);
|
||||
} else if (defaultObject instanceof Float) {
|
||||
return sp.getFloat(key, (Float) defaultObject);
|
||||
} else if (defaultObject instanceof Long) {
|
||||
return sp.getLong(key, (Long) defaultObject);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除某个key值已经对应的值
|
||||
*/
|
||||
public static void remove(Context context, String key) {
|
||||
SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
|
||||
Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sp.edit();
|
||||
editor.remove(key);
|
||||
SharedPreferencesCompat.apply(editor);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除所有数据
|
||||
*/
|
||||
public static void clear(Context context) {
|
||||
SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
|
||||
Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sp.edit();
|
||||
editor.clear();
|
||||
SharedPreferencesCompat.apply(editor);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 查询某个key是否已经存在
|
||||
*/
|
||||
public static boolean contains(Context context, String key) {
|
||||
SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
|
||||
Context.MODE_PRIVATE);
|
||||
return sp.contains(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回所有的键值对
|
||||
*/
|
||||
public static Map<String, ?> getAll(Context context) {
|
||||
SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
|
||||
Context.MODE_PRIVATE);
|
||||
return sp.getAll();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 保存图片到SharedPreferences
|
||||
*
|
||||
* @param mContext
|
||||
* @param imageView
|
||||
*/
|
||||
public static void putImage(Context mContext, String key, ImageView imageView) {
|
||||
BitmapDrawable drawable = (BitmapDrawable) imageView.getDrawable();
|
||||
Bitmap bitmap = drawable.getBitmap();
|
||||
// 将Bitmap压缩成字节数组输出流
|
||||
ByteArrayOutputStream byStream = new ByteArrayOutputStream();
|
||||
bitmap.compress(Bitmap.CompressFormat.PNG, 80, byStream);
|
||||
// 利用Base64将我们的字节数组输出流转换成String
|
||||
byte[] byteArray = byStream.toByteArray();
|
||||
String imgString = new String(Base64.encodeToString(byteArray, Base64.DEFAULT));
|
||||
// 将String保存shareUtils
|
||||
SPUtils.put(mContext, key, imgString);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从SharedPreferences读取图片
|
||||
*
|
||||
* @param mContext
|
||||
* @param imageView
|
||||
*/
|
||||
public static Bitmap getImage(Context mContext, String key, ImageView imageView) {
|
||||
String imgString = (String) SPUtils.get(mContext, key, "");
|
||||
if (!imgString.equals("")) {
|
||||
// 利用Base64将我们string转换
|
||||
byte[] byteArray = Base64.decode(imgString, Base64.DEFAULT);
|
||||
ByteArrayInputStream byStream = new ByteArrayInputStream(byteArray);
|
||||
// 生成bitmap
|
||||
return BitmapFactory.decodeStream(byStream);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建一个解决SharedPreferencesCompat.apply方法的一个兼容类
|
||||
*/
|
||||
private static class SharedPreferencesCompat {
|
||||
private static final Method sApplyMethod = findApplyMethod();
|
||||
|
||||
/**
|
||||
* 反射查找apply的方法
|
||||
*/
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
private static Method findApplyMethod() {
|
||||
try {
|
||||
Class clz = SharedPreferences.Editor.class;
|
||||
return clz.getMethod("apply");
|
||||
} catch (NoSuchMethodException e) {
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果找到则使用apply执行,否则使用commit
|
||||
*/
|
||||
public static void apply(SharedPreferences.Editor editor) {
|
||||
try {
|
||||
if (sApplyMethod != null) {
|
||||
sApplyMethod.invoke(editor);
|
||||
return;
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
} catch (IllegalAccessException e) {
|
||||
} catch (InvocationTargetException e) {
|
||||
}
|
||||
editor.commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
app/src/main/res/drawable-hdpi/menu_selected.png
Normal file
BIN
app/src/main/res/drawable-hdpi/menu_selected.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.6 KiB |
BIN
app/src/main/res/drawable-hdpi/menu_settings.png
Normal file
BIN
app/src/main/res/drawable-hdpi/menu_settings.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
@@ -2,7 +2,7 @@
|
||||
<RelativeLayout 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="350dp"
|
||||
android:layout_width="400dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
@@ -76,7 +76,7 @@
|
||||
|
||||
<Button
|
||||
android:id="@+id/positive"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="80dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="48dp"
|
||||
android:layout_weight="1"
|
||||
@@ -102,7 +102,7 @@
|
||||
|
||||
<Button
|
||||
android:id="@+id/negtive"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="80dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="48dp"
|
||||
android:layout_weight="1"
|
||||
|
||||
@@ -2,8 +2,23 @@
|
||||
<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" />
|
||||
android:id="@+id/setting"
|
||||
android:icon="@drawable/menu_settings"
|
||||
android:title="TODO"
|
||||
app:showAsAction="ifRoom">
|
||||
<menu>
|
||||
<item
|
||||
android:id="@+id/refresh"
|
||||
android:icon="@drawable/menu_refresh"
|
||||
android:title="刷新" />
|
||||
<item
|
||||
android:id="@+id/single_loop"
|
||||
android:icon="@drawable/menu_selected"
|
||||
android:title="单循环" />
|
||||
<item
|
||||
android:id="@+id/loop"
|
||||
android:icon="@drawable/menu_selected"
|
||||
android:title="列表循环" />
|
||||
</menu>
|
||||
</item>
|
||||
</menu>
|
||||
Reference in New Issue
Block a user