Keyboard replace with icon

pull/21/head
FongMi 3 years ago
parent d285f34240
commit df53e3df95
  1. 41
      app/src/leanback/java/com/fongmi/android/tv/ui/custom/CustomKeyboard.java
  2. 22
      app/src/leanback/java/com/fongmi/android/tv/ui/presenter/KeyboardPresenter.java
  3. BIN
      app/src/leanback/res/drawable-hdpi/ic_keyboard_back.png
  4. BIN
      app/src/leanback/res/drawable-hdpi/ic_keyboard_enter.png
  5. BIN
      app/src/leanback/res/drawable-hdpi/ic_keyboard_left.png
  6. BIN
      app/src/leanback/res/drawable-hdpi/ic_keyboard_right.png
  7. BIN
      app/src/leanback/res/drawable-mdpi/ic_keyboard_back.png
  8. BIN
      app/src/leanback/res/drawable-mdpi/ic_keyboard_enter.png
  9. BIN
      app/src/leanback/res/drawable-mdpi/ic_keyboard_left.png
  10. BIN
      app/src/leanback/res/drawable-mdpi/ic_keyboard_right.png
  11. BIN
      app/src/leanback/res/drawable-xhdpi/ic_keyboard_back.png
  12. BIN
      app/src/leanback/res/drawable-xhdpi/ic_keyboard_enter.png
  13. BIN
      app/src/leanback/res/drawable-xhdpi/ic_keyboard_left.png
  14. BIN
      app/src/leanback/res/drawable-xhdpi/ic_keyboard_right.png
  15. BIN
      app/src/leanback/res/drawable-xxhdpi/ic_keyboard_back.png
  16. BIN
      app/src/leanback/res/drawable-xxhdpi/ic_keyboard_enter.png
  17. BIN
      app/src/leanback/res/drawable-xxhdpi/ic_keyboard_left.png
  18. BIN
      app/src/leanback/res/drawable-xxhdpi/ic_keyboard_right.png
  19. BIN
      app/src/leanback/res/drawable-xxxhdpi/ic_img_error.png
  20. BIN
      app/src/leanback/res/drawable-xxxhdpi/ic_img_loading.png
  21. BIN
      app/src/leanback/res/drawable-xxxhdpi/ic_live.png
  22. BIN
      app/src/leanback/res/drawable-xxxhdpi/ic_push.png
  23. BIN
      app/src/leanback/res/drawable-xxxhdpi/ic_search.png
  24. BIN
      app/src/leanback/res/drawable-xxxhdpi/ic_setting.png
  25. BIN
      app/src/leanback/res/drawable-xxxhdpi/ic_vod.png
  26. 27
      app/src/leanback/res/layout/adapter_keyboard.xml

@ -1,9 +1,12 @@
package com.fongmi.android.tv.ui.custom;
import android.annotation.SuppressLint;
import androidx.leanback.widget.ArrayObjectAdapter;
import androidx.leanback.widget.ItemBridgeAdapter;
import androidx.leanback.widget.ListRow;
import com.fongmi.android.tv.R;
import com.fongmi.android.tv.databinding.ActivitySearchBinding;
import com.fongmi.android.tv.ui.presenter.KeyboardPresenter;
import com.fongmi.android.tv.utils.ResUtil;
@ -15,11 +18,6 @@ import java.util.List;
public class CustomKeyboard implements KeyboardPresenter.OnClickListener {
private static final String LEFT = "◁";
private static final String RIGHT = "▷";
private static final String BACK = "⌫";
private static final String ENTER = "⏎";
private final ActivitySearchBinding binding;
public static void init(ActivitySearchBinding binding) {
@ -40,9 +38,9 @@ public class CustomKeyboard implements KeyboardPresenter.OnClickListener {
}
private List<ListRow> getRows() {
List<String> keys = Arrays.asList("1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", LEFT, RIGHT, BACK, ENTER);
List<Object> keys = Arrays.asList("1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", R.drawable.ic_keyboard_left, R.drawable.ic_keyboard_right, R.drawable.ic_keyboard_back, R.drawable.ic_keyboard_enter);
List<ListRow> rows = new ArrayList<>();
for (List<String> items : Lists.partition(keys, 10)) {
for (List<Object> items : Lists.partition(keys, 10)) {
ArrayObjectAdapter adapter = new ArrayObjectAdapter(new KeyboardPresenter(this));
adapter.addAll(0, items);
rows.add(new ListRow(adapter));
@ -51,31 +49,36 @@ public class CustomKeyboard implements KeyboardPresenter.OnClickListener {
}
@Override
public void onItemClick(String text) {
public void onTextClick(String text) {
StringBuilder sb = new StringBuilder(binding.keyword.getText().toString());
int cursor = binding.keyword.getSelectionStart();
switch (text) {
case ENTER:
if (binding.keyword.length() > 29) return;
sb.insert(cursor, text);
binding.keyword.setText(sb.toString());
binding.keyword.setSelection(cursor + 1);
}
@Override
@SuppressLint("NonConstantResourceId")
public void onIconClick(int resId) {
StringBuilder sb = new StringBuilder(binding.keyword.getText().toString());
int cursor = binding.keyword.getSelectionStart();
switch (resId) {
case R.drawable.ic_keyboard_enter:
binding.search.performClick();
break;
case LEFT:
case R.drawable.ic_keyboard_left:
binding.keyword.setSelection(--cursor < 0 ? 0 : cursor);
break;
case RIGHT:
case R.drawable.ic_keyboard_right:
binding.keyword.setSelection(++cursor > binding.keyword.length() ? binding.keyword.length() : cursor);
break;
case BACK:
case R.drawable.ic_keyboard_back:
if (cursor == 0) return;
sb.deleteCharAt(cursor - 1);
binding.keyword.setText(sb.toString());
binding.keyword.setSelection(cursor - 1);
break;
default:
if (binding.keyword.length() > 29) return;
sb.insert(cursor, text);
binding.keyword.setText(sb.toString());
binding.keyword.setSelection(cursor + 1);
break;
}
}
}

@ -1,6 +1,7 @@
package com.fongmi.android.tv.ui.presenter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
@ -17,7 +18,10 @@ public class KeyboardPresenter extends Presenter {
}
public interface OnClickListener {
void onItemClick(String item);
void onTextClick(String text);
void onIconClick(int resId);
}
@Override
@ -27,10 +31,20 @@ public class KeyboardPresenter extends Presenter {
@Override
public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object object) {
String item = (String) object;
ViewHolder holder = (ViewHolder) viewHolder;
setOnClickListener(holder, view -> mListener.onItemClick(item));
holder.binding.text.setText(item);
if (object instanceof String) {
String text = (String) object;
holder.binding.text.setText(text);
holder.binding.icon.setVisibility(View.GONE);
holder.binding.text.setVisibility(View.VISIBLE);
setOnClickListener(holder, view -> mListener.onTextClick(text));
} else {
int resId = (int) object;
holder.binding.icon.setImageResource(resId);
holder.binding.text.setVisibility(View.GONE);
holder.binding.icon.setVisibility(View.VISIBLE);
setOnClickListener(holder, view -> mListener.onIconClick(resId));
}
}
@Override

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 556 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 613 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 589 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 661 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 339 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 396 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 377 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 522 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 745 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 736 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

@ -1,13 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/text"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="@drawable/selector_item"
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="center"
android:textColor="@color/white"
android:textSize="16sp"
tools:text="0" />
android:focusableInTouchMode="true">
<TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="@color/white"
android:textSize="16sp"
tools:text="0" />
<ImageView
android:id="@+id/icon"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitCenter"
android:src="@drawable/ic_keyboard_back" />
</FrameLayout>
Loading…
Cancel
Save