Skip to content

Commit

Permalink
Use buttons instead of cards for compact UI in editor
Browse files Browse the repository at this point in the history
  • Loading branch information
Xtr126 committed Dec 9, 2024
1 parent dbee202 commit 12e358f
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 82 deletions.
12 changes: 7 additions & 5 deletions app/src/main/java/xtr/keymapper/editor/EditorUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,9 @@ public EditorUI (Context context, OnHideListener onHideListener, String profileN
layoutInflater = context.getSystemService(LayoutInflater.class);


settingsFragment = new SettingsFragment(context);
settingsFragment = new SettingsFragment(context, startMode);
mainView = settingsFragment.createView(layoutInflater);

settingsFragment.init(startMode);
settingsFragment.inflateMenuResource(startMode, layoutInflater);
settingsFragment.setOnActionSelectedListener(this::onActionSelected);
}
Expand Down Expand Up @@ -285,7 +284,10 @@ private void saveKeymap() {

// Keyboard keys
floatingKeysMap.forEach((frameLayout, movableFloatingActionKey) -> linesToWrite.add(movableFloatingActionKey.getData()));
swipeKeyList.stream().map(swipeKeyView -> new SwipeKey(swipeKeyView).getData()).forEach(linesToWrite::add);
swipeKeyList.stream()
.map(SwipeKey::new)
.map(SwipeKey::getData)
.forEach(linesToWrite::add);

// Save Config
KeymapProfiles profiles = new KeymapProfiles(context);
Expand Down Expand Up @@ -391,7 +393,7 @@ public void onSwipeKeyClick(View view) {
}

private void addKey(float x, float y) {
final KeymapProfileKey key = new KeymapProfileKey();
KeymapProfileKey key = new KeymapProfileKey();
key.code = "KEY_X";
key.x = x;
key.y = y;
Expand Down Expand Up @@ -528,7 +530,7 @@ private void getDefaultPivotXY(){
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_MOVE) {
resizeView(rootView, (int) event.getX(), (int) event.getY());
EditorUI.resizeView(rootView, (int) event.getX(), (int) event.getY());
// Resize View from center point
if (defaultPivotX > 0) {
float newPivotX = rootView.getPivotX() - defaultPivotX;
Expand Down
28 changes: 16 additions & 12 deletions app/src/main/java/xtr/keymapper/editor/SettingsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import androidx.annotation.IdRes;
import androidx.annotation.NonNull;

import com.google.android.material.button.MaterialButton;
import com.google.android.material.button.MaterialButtonToggleGroup;

import java.util.Map;
Expand All @@ -33,15 +34,18 @@ public class SettingsFragment {
private Map<String, Integer> touchpadInputModeMap;
private final Context context;
private OnCardItemSelectedListener onCardItemSelectedListener;
private final int startMode;

public SettingsFragment(Context context) {
public SettingsFragment(Context context, int startMode) {
this.context = context;
keymapConfig = new KeymapConfig(context);
this.startMode = startMode;
}

public ViewGroup createView(@NonNull LayoutInflater inflater) {
// Inflate the layout for this fragment
binding = KeymapEditorLayoutBinding.inflate(inflater);
init();
return binding.getRoot();
}

Expand All @@ -56,12 +60,14 @@ public void onButtonChecked(MaterialButtonToggleGroup group, int checkedId, bool
} else if (checkedId == R.id.button_misc) {
binding.misc.setVisibility(isChecked ? View.VISIBLE : View.GONE);
} else if (checkedId == R.id.button_add) {
binding.catalog.setVisibility(isChecked ? View.VISIBLE : View.GONE);
if (EditorUI.START_SETTINGS == startMode)
onCardItemSelected(R.id.save);
else binding.catalog.setVisibility(isChecked ? View.VISIBLE : View.GONE);
}
}
};

public void init(int startMode) {
public void init() {
binding.sliderMouse.setValue(keymapConfig.mouseSensitivity);
binding.sliderScrollSpeed.setValue(keymapConfig.scrollSpeed);
binding.sliderSwipeDelay.setValue(keymapConfig.swipeDelayMs);
Expand Down Expand Up @@ -89,7 +95,7 @@ public void init(int startMode) {
mouseAimActions();
loadTouchpadInputSettings();

final int[] pointerModeCodes = {KeymapConfig.POINTER_COMBINED, KeymapConfig.POINTER_OVERLAY, KeymapConfig.POINTER_SYSTEM};
int[] pointerModeCodes = {KeymapConfig.POINTER_COMBINED, KeymapConfig.POINTER_OVERLAY, KeymapConfig.POINTER_SYSTEM};
String[] pointerModeNames = context.getResources().getStringArray(R.array.pointer_modes);
pointerModeMap = IntStream.range(0, pointerModeCodes.length)
.boxed()
Expand Down Expand Up @@ -251,16 +257,14 @@ public void inflateMenuResource(int startMode, LayoutInflater layoutInflater) {
}

KeymapEditorItemBinding itemBinding = KeymapEditorItemBinding.inflate(layoutInflater, parentView, true);
itemBinding.imageView.setImageDrawable(menuItem.getIcon());
itemBinding.title.setText(menuItem.getTitle());
itemBinding.description.setText(menuItem.getContentDescription());
itemBinding.getRoot().setOnClickListener(v -> onCardItemSelected(menuItem.getItemId()));
MaterialButton button = itemBinding.getRoot();
button.setIcon(menuItem.getIcon());
button.setText(menuItem.getTitle());
button.setContentDescription(menuItem.getContentDescription());
button.setOnClickListener(v -> onCardItemSelected(menuItem.getItemId()));
}
} else if (startMode == EditorUI.START_SETTINGS) {
KeymapEditorItemBinding itemBinding = KeymapEditorItemBinding.inflate(layoutInflater, binding.L1, true);
itemBinding.imageView.setImageResource(R.drawable.ic_baseline_done_36);
itemBinding.title.setText(R.string.save);
itemBinding.getRoot().setOnClickListener(v -> onCardItemSelected(R.id.save));
binding.buttonAdd.setIconResource(R.drawable.ic_baseline_done_36);
}

}
Expand Down
61 changes: 7 additions & 54 deletions app/src/main/res/layout/keymap_editor_item.xml
Original file line number Diff line number Diff line change
@@ -1,57 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView style="@style/Widget.Material3.CardView.Elevated"
android:layout_width="220dp"
<com.google.android.material.button.MaterialButton
style="@style/Widget.Material3.Button.ElevatedButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="24dp"
android:layout_margin="6dp"
android:layout_marginHorizontal="6dp"
tools:text="@string/crosshair"
tools:icon="@drawable/dpad"
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">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<!-- Media -->
<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/image_view"
android:layout_gravity="center"
android:layout_width="100dp"
android:layout_height="100dp"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:padding="24dp"
app:tint="?attr/colorAccent"
tools:srcCompat="@drawable/dpad"
/>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center">

<!-- Title, secondary and supporting text -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="@string/crosshair"
android:id="@+id/title"
android:textAppearance="?attr/textAppearanceTitleMedium"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:id="@+id/description"
tools:text="@string/crosshair"
android:textAppearance="?attr/textAppearanceBodyMedium"
android:textColor="?android:attr/textColorSecondary"
/>

</LinearLayout>

</LinearLayout>

</com.google.android.material.card.MaterialCardView>
xmlns:tools="http://schemas.android.com/tools" />
22 changes: 11 additions & 11 deletions app/src/main/res/layout/keymap_editor_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
<com.google.android.material.card.MaterialCardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:contentPadding="16dp"
app:contentPadding="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintTop_toBottomOf="@id/toggleButtonGroup"
android:id="@+id/catalog"
app:cardBackgroundColor="@color/black"
app:cardCornerRadius="40dp">
Expand Down Expand Up @@ -92,10 +92,10 @@

</com.google.android.material.button.MaterialButtonToggleGroup>

<androidx.cardview.widget.CardView
<com.google.android.material.card.MaterialCardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:contentPadding="8dp"
app:contentPadding="12dp"
style="?attr/materialCardViewStyle"
android:id="@+id/sliders"
app:layout_constraintBottom_toBottomOf="parent"
Expand Down Expand Up @@ -155,12 +155,12 @@
app:trackHeight="10dp" />

</LinearLayout>
</androidx.cardview.widget.CardView>
</com.google.android.material.card.MaterialCardView>

<androidx.cardview.widget.CardView
<com.google.android.material.card.MaterialCardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:contentPadding="8dp"
app:contentPadding="12dp"
style="?attr/materialCardViewStyle"
android:id="@+id/misc"
app:layout_constraintBottom_toBottomOf="parent"
Expand Down Expand Up @@ -294,12 +294,12 @@
</LinearLayout>


</androidx.cardview.widget.CardView>
</com.google.android.material.card.MaterialCardView>

<androidx.cardview.widget.CardView
<com.google.android.material.card.MaterialCardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:contentPadding="8dp"
app:contentPadding="12dp"
style="?attr/materialCardViewStyle"
android:id="@+id/shortcuts"
app:layout_constraintBottom_toBottomOf="parent"
Expand Down Expand Up @@ -478,5 +478,5 @@

</LinearLayout>

</androidx.cardview.widget.CardView>
</com.google.android.material.card.MaterialCardView>
</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit 12e358f

Please sign in to comment.