mirror of
https://github.com/emanuele-f/PCAPdroid.git
synced 2026-07-03 21:21:12 +08:00
Fix log view navigation in Android TV
This commit is contained in:
parent
f6c46324f3
commit
95901cc9da
@ -20,9 +20,11 @@
|
||||
package com.emanuelef.remote_capture.activities;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.view.MenuProvider;
|
||||
@ -35,6 +37,7 @@ import com.emanuelef.remote_capture.Log;
|
||||
import com.emanuelef.remote_capture.R;
|
||||
import com.emanuelef.remote_capture.Utils;
|
||||
import com.emanuelef.remote_capture.fragments.LogviewFragment;
|
||||
import com.google.android.material.tabs.TabLayout;
|
||||
import com.google.android.material.tabs.TabLayoutMediator;
|
||||
|
||||
public class LogviewActivity extends BaseActivity implements MenuProvider {
|
||||
@ -107,6 +110,33 @@ public class LogviewActivity extends BaseActivity implements MenuProvider {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
// This is required to properly handle the DPAD down press on Android TV, to properly
|
||||
// focus the tab content
|
||||
if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
|
||||
View view = getCurrentFocus();
|
||||
|
||||
Log.d(TAG, "onKeyDown focus " + view.getClass().getName());
|
||||
|
||||
if (view instanceof TabLayout.TabView) {
|
||||
int pos = mPager.getCurrentItem();
|
||||
View focusOverride = null;
|
||||
|
||||
Log.d(TAG, "TabLayout.TabView focus pos " + pos);
|
||||
|
||||
focusOverride = findViewById(R.id.scrollView);
|
||||
|
||||
if (focusOverride != null) {
|
||||
focusOverride.requestFocus();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateMenu(@NonNull Menu menu, MenuInflater inflater) {
|
||||
inflater.inflate(R.menu.log_menu, menu);
|
||||
|
||||
@ -31,6 +31,7 @@ import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.emanuelef.remote_capture.R;
|
||||
import com.emanuelef.remote_capture.ReversedLinesFileReader;
|
||||
import com.emanuelef.remote_capture.Utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@ -64,6 +65,13 @@ public class LogviewFragment extends Fragment {
|
||||
mLogPath = args.getString("path");
|
||||
assert(mLogPath != null);
|
||||
|
||||
if(Utils.isTv(view.getContext())) {
|
||||
// necessary to make scroll work on TV
|
||||
// but disables ability to select and copy the textview contents
|
||||
ViewGroup layout = view.findViewById(R.id.scrollView);
|
||||
layout.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
|
||||
}
|
||||
|
||||
mLogView = view.findViewById(R.id.log);
|
||||
reloadLog();
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView
|
||||
android:id="@+id/scrollView"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user