Support render

pull/102/head
FongMi 4 years ago
parent 491ed61105
commit a977b9464f
  1. 30
      app/src/leanback/java/com/fongmi/android/tv/ui/activity/DetailActivity.java
  2. 10
      app/src/leanback/java/com/fongmi/android/tv/ui/activity/SettingActivity.java
  3. 36
      app/src/leanback/res/layout/activity_detail.xml
  4. 69
      app/src/leanback/res/layout/activity_setting.xml
  5. 8
      app/src/main/java/com/fongmi/android/tv/utils/Prefers.java
  6. 1
      app/src/main/res/values-zh-rCN/strings.xml
  7. 1
      app/src/main/res/values-zh-rTW/strings.xml
  8. 8
      app/src/main/res/values/strings.xml
  9. 4
      settings.gradle

@ -43,6 +43,7 @@ import com.fongmi.android.tv.utils.Notify;
import com.fongmi.android.tv.utils.Prefers;
import com.fongmi.android.tv.utils.ResUtil;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.ui.StyledPlayerView;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
@ -89,6 +90,10 @@ public class DetailActivity extends BaseActivity implements CustomKeyDown.Listen
return 0;
}
private StyledPlayerView getPlayerView() {
return Prefers.getRender() == 0 ? mBinding.surface : mBinding.texture;
}
public static void start(Activity activity, String id) {
start(activity, ApiConfig.get().getHome().getKey(), id);
}
@ -104,7 +109,7 @@ public class DetailActivity extends BaseActivity implements CustomKeyDown.Listen
@Override
protected ViewBinding getBinding() {
mBinding = ActivityDetailBinding.inflate(getLayoutInflater());
mControl = ViewControllerBottomBinding.bind(mBinding.video.findViewById(com.google.android.exoplayer2.ui.R.id.exo_controller));
mControl = ViewControllerBottomBinding.bind(getPlayerView().findViewById(com.google.android.exoplayer2.ui.R.id.exo_controller));
return mBinding;
}
@ -175,9 +180,10 @@ public class DetailActivity extends BaseActivity implements CustomKeyDown.Listen
}
private void setVideoView() {
mBinding.video.setPlayer(Players.get().exo());
mBinding.video.setResizeMode(Prefers.getScale());
mBinding.video.getSubtitleView().setStyle(ExoUtil.getCaptionStyle());
getPlayerView().setVisibility(View.VISIBLE);
getPlayerView().setPlayer(Players.get().exo());
getPlayerView().setResizeMode(Prefers.getScale());
getPlayerView().getSubtitleView().setStyle(ExoUtil.getCaptionStyle());
mControl.speed.setText(Players.get().getSpeed());
mControl.scale.setText(ResUtil.getStringArray(R.array.select_scale)[Prefers.getScale()]);
mControl.interval.setText(ResUtil.getString(R.string.second, Prefers.getInterval()));
@ -309,7 +315,7 @@ public class DetailActivity extends BaseActivity implements CustomKeyDown.Listen
private void enterFullscreen() {
mBinding.video.setForeground(null);
mBinding.video.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT));
mHandler.postDelayed(() -> mBinding.video.setUseController(true), 250);
mHandler.postDelayed(() -> getPlayerView().setUseController(true), 250);
mBinding.flag.setSelectedPosition(mCurrent);
mFullscreen = true;
}
@ -317,7 +323,7 @@ public class DetailActivity extends BaseActivity implements CustomKeyDown.Listen
private void exitFullscreen() {
mBinding.video.setForeground(ResUtil.getDrawable(R.drawable.selector_video));
mBinding.video.setLayoutParams(mFrameParams);
mBinding.video.setUseController(false);
getPlayerView().setUseController(false);
mFullscreen = false;
}
@ -349,8 +355,8 @@ public class DetailActivity extends BaseActivity implements CustomKeyDown.Listen
}
private void onScale() {
int scale = mBinding.video.getResizeMode();
mBinding.video.setResizeMode(scale = scale >= 4 ? 0 : scale + 1);
int scale = getPlayerView().getResizeMode();
getPlayerView().setResizeMode(scale = scale >= 4 ? 0 : scale + 1);
mControl.scale.setText(ResUtil.getStringArray(R.array.select_scale)[scale]);
Prefers.putScale(scale);
}
@ -530,7 +536,7 @@ public class DetailActivity extends BaseActivity implements CustomKeyDown.Listen
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (mFullscreen && !mBinding.video.isControllerFullyVisible() && mKeyDown.hasEvent(event)) return mKeyDown.onKeyDown(event);
if (mFullscreen && !getPlayerView().isControllerFullyVisible() && mKeyDown.hasEvent(event)) return mKeyDown.onKeyDown(event);
else return super.dispatchKeyEvent(event);
}
@ -552,7 +558,7 @@ public class DetailActivity extends BaseActivity implements CustomKeyDown.Listen
@Override
public void onKeyDown() {
mBinding.video.showController();
getPlayerView().showController();
mControl.next.requestFocus();
}
@ -583,8 +589,8 @@ public class DetailActivity extends BaseActivity implements CustomKeyDown.Listen
@Override
public void onBackPressed() {
if (mBinding.video.isControllerFullyVisible()) {
mBinding.video.hideController();
if (getPlayerView().isControllerFullyVisible()) {
getPlayerView().hideController();
} else if (mFullscreen) {
exitFullscreen();
} else {

@ -53,6 +53,7 @@ public class SettingActivity extends BaseActivity implements ConfigCallback, Sit
protected void initView() {
mBinding.url.setText(Prefers.getUrl());
mBinding.home.setText(ApiConfig.getHomeName());
mBinding.type.setText(ResUtil.getStringArray(R.array.select_render)[Prefers.getRender()]);
mBinding.compress.setText(ResUtil.getStringArray(R.array.select_thumbnail)[Prefers.getThumbnail()]);
}
@ -62,6 +63,7 @@ public class SettingActivity extends BaseActivity implements ConfigCallback, Sit
mBinding.config.setOnClickListener(view -> ConfigDialog.show(this));
mBinding.history.setOnClickListener(view -> HistoryDialog.show(this));
mBinding.thumbnail.setOnClickListener(this::setThumbnail);
mBinding.render.setOnClickListener(this::setRender);
}
@Override
@ -129,4 +131,12 @@ public class SettingActivity extends BaseActivity implements ConfigCallback, Sit
mBinding.compress.setText(array[index]);
RefreshEvent.image();
}
public void setRender(View view) {
CharSequence[] array = ResUtil.getStringArray(R.array.select_render);
int index = Prefers.getRender();
index = index == 1 ? 0 : ++index;
Prefers.putRender(index);
mBinding.type.setText(array[index]);
}
}

@ -7,7 +7,7 @@
android:layout_height="match_parent"
android:keepScreenOn="true">
<com.google.android.exoplayer2.ui.StyledPlayerView
<FrameLayout
android:id="@+id/video"
android:layout_width="360dp"
android:layout_height="200dp"
@ -16,13 +16,31 @@
android:background="@color/black"
android:focusable="true"
android:focusableInTouchMode="true"
android:foreground="@drawable/selector_video"
app:animation_enabled="false"
app:auto_show="false"
app:controller_layout_id="@layout/view_controller_bottom"
app:resize_mode="fit"
app:surface_type="surface_view"
app:use_controller="false">
android:foreground="@drawable/selector_video">
<com.google.android.exoplayer2.ui.StyledPlayerView
android:id="@+id/surface"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
app:animation_enabled="false"
app:auto_show="false"
app:controller_layout_id="@layout/view_controller_bottom"
app:resize_mode="fit"
app:surface_type="surface_view"
app:use_controller="false" />
<com.google.android.exoplayer2.ui.StyledPlayerView
android:id="@+id/texture"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
app:animation_enabled="false"
app:auto_show="false"
app:controller_layout_id="@layout/view_controller_bottom"
app:resize_mode="fit"
app:surface_type="texture_view"
app:use_controller="false" />
<include
android:id="@+id/progress"
@ -45,7 +63,7 @@
android:layout_gravity="center"
android:visibility="gone" />
</com.google.android.exoplayer2.ui.StyledPlayerView>
</FrameLayout>
<TextView
android:id="@+id/name"

@ -60,9 +60,8 @@
<TextView
android:id="@+id/url"
android:layout_width="0dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="end"
android:singleLine="true"
android:textColor="@color/white"
@ -86,30 +85,68 @@
</LinearLayout>
<LinearLayout
android:id="@+id/thumbnail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:background="@drawable/selector_item"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="horizontal">
<TextView
<LinearLayout
android:id="@+id/render"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_weight="1"
android:text="@string/setting_thumbnail"
android:textColor="@color/white"
android:textSize="18sp" />
android:background="@drawable/selector_item"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="horizontal">
<TextView
android:id="@+id/compress"
android:layout_width="wrap_content"
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:text="@string/setting_render"
android:textColor="@color/white"
android:textSize="18sp" />
<TextView
android:id="@+id/type"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:textColor="@color/white"
android:textSize="18sp"
tools:text="Surface" />
</LinearLayout>
<LinearLayout
android:id="@+id/thumbnail"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:textSize="18sp"
tools:text="High" />
android:layout_weight="1"
android:background="@drawable/selector_item"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:text="@string/setting_thumbnail"
android:textColor="@color/white"
android:textSize="18sp" />
<TextView
android:id="@+id/compress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:textColor="@color/white"
android:textSize="18sp"
tools:text="High" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

@ -91,6 +91,14 @@ public class Prefers {
Prefers.put("thumbnail", thumbnail);
}
public static int getRender() {
return Prefers.getInt("render", 0);
}
public static void putRender(int render) {
Prefers.put("render", render);
}
public static int getInterval() {
return Prefers.getInt("interval", 15);
}

@ -40,6 +40,7 @@
<!-- Setting -->
<string name="setting_site">首页</string>
<string name="setting_url">配置</string>
<string name="setting_render">渲染</string>
<string name="setting_thumbnail">缩图</string>
<!-- Dialog -->

@ -40,6 +40,7 @@
<!-- Setting -->
<string name="setting_site">首頁</string>
<string name="setting_url">配置</string>
<string name="setting_render">渲染</string>
<string name="setting_thumbnail">縮圖</string>
<!-- Dialog -->

@ -1,4 +1,4 @@
<resources xmlns:xliff="http://schemas.android.com/apk/res-auto">
<resources xmlns:tools="http://schemas.android.com/tools" xmlns:xliff="http://schemas.android.com/apk/res-auto" tools:ignore="MissingTranslation">
<!-- App -->
<string name="app_name">TV</string>
@ -40,6 +40,7 @@
<!-- Setting -->
<string name="setting_site">Home site</string>
<string name="setting_url">Configuration</string>
<string name="setting_render">Render</string>
<string name="setting_thumbnail">Thumbnail</string>
<!-- Dialog -->
@ -68,6 +69,11 @@
<!-- UNIT -->
<string name="second"><xliff:g name="name">%s</xliff:g> s</string>
<string-array name="select_render">
<item>Surface</item>
<item>Texture</item>
</string-array>
<string-array name="select_thumbnail">
<item>Low</item>
<item>Medium</item>

@ -14,8 +14,8 @@ dependencyResolutionManagement {
google()
}
}
include ':app'
include ':catvod'
gradle.ext.exoplayerModulePrefix = 'exoplayer-'
apply from: file("/exo/core_settings.gradle")
rootProject.name = "TV"
include ':app'
include ':catvod'

Loading…
Cancel
Save