mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-13 14:51:51 -04:00
Add: Side dialog system
Contains only the outer shell
This commit is contained in:
parent
d6a6c89657
commit
7481278fb8
139
app_pojavlauncher/src/main/java/com/kdt/SideDialogView.java
Normal file
139
app_pojavlauncher/src/main/java/com/kdt/SideDialogView.java
Normal file
@ -0,0 +1,139 @@
|
||||
package com.kdt;
|
||||
|
||||
import static net.kdt.pojavlaunch.Tools.currentDisplayMetrics;
|
||||
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.animation.AccelerateDecelerateInterpolator;
|
||||
import android.view.animation.Interpolator;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.CallSuper;
|
||||
import androidx.annotation.IntegerRes;
|
||||
import androidx.annotation.LayoutRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.core.content.res.ResourcesCompat;
|
||||
|
||||
import net.kdt.pojavlaunch.R;
|
||||
|
||||
public class SideDialogView<T extends View> {
|
||||
|
||||
private final ConstraintLayout mDialogLayout;
|
||||
private final DefocusableScrollView mScrollView;
|
||||
protected final T mDialogContent;
|
||||
private final int mMargin;
|
||||
private final ObjectAnimator mSideDialogAnimator;
|
||||
private boolean mDisplaying = false;
|
||||
|
||||
private final Button mStartButton, mEndButton;
|
||||
private final TextView mTitleTextview;
|
||||
private final View mTitleDivider;
|
||||
|
||||
public SideDialogView(Context context, ViewGroup parent, @LayoutRes int layoutId) {
|
||||
// Inflate layouts
|
||||
mDialogLayout = (ConstraintLayout) LayoutInflater.from(context).inflate(R.layout.dialog_side_dialog, parent, false);
|
||||
mScrollView = mDialogLayout.findViewById(R.id.side_dialog_scrollview);
|
||||
mStartButton = mDialogLayout.findViewById(R.id.side_dialog_start_button);
|
||||
mEndButton = mDialogLayout.findViewById(R.id.side_dialog_end_button);
|
||||
mTitleTextview = mDialogLayout.findViewById(R.id.side_dialog_title_textview);
|
||||
mTitleDivider = mDialogLayout.findViewById(R.id.side_dialog_title_divider);
|
||||
|
||||
LayoutInflater.from(context).inflate(layoutId, mScrollView, true);
|
||||
mDialogContent = (T) mScrollView.getChildAt(0);
|
||||
|
||||
|
||||
|
||||
// Attach layouts
|
||||
//mScrollView.addView(mDialogContent);
|
||||
parent.addView(mDialogLayout);
|
||||
|
||||
mMargin = context.getResources().getDimensionPixelOffset(R.dimen._20sdp);
|
||||
mSideDialogAnimator = ObjectAnimator.ofFloat(mDialogLayout, "x", 0).setDuration(600);
|
||||
Interpolator decelerate = new AccelerateDecelerateInterpolator();
|
||||
mSideDialogAnimator.setInterpolator(decelerate);
|
||||
|
||||
mDialogLayout.setElevation(10);
|
||||
mDialogLayout.setTranslationZ(10);
|
||||
|
||||
mDialogLayout.setVisibility(View.VISIBLE);
|
||||
mDialogLayout.setBackground(ResourcesCompat.getDrawable(mDialogLayout.getResources(), R.drawable.background_control_editor, null));
|
||||
|
||||
//TODO offset better according to view width
|
||||
mDialogLayout.setX(-mDialogLayout.getResources().getDimensionPixelOffset(R.dimen._280sdp));
|
||||
}
|
||||
|
||||
public void setTitle(@StringRes int textId) {
|
||||
mTitleTextview.setText(textId);
|
||||
mTitleTextview.setVisibility(View.VISIBLE);
|
||||
mTitleDivider.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
public final void setStartButtonListener(@StringRes int textId, @Nullable View.OnClickListener listener) {
|
||||
setButton(mStartButton, textId, listener);
|
||||
}
|
||||
|
||||
public final void setEndButtonListener(@StringRes int textId, @Nullable View.OnClickListener listener) {
|
||||
setButton(mEndButton, textId, listener);
|
||||
}
|
||||
|
||||
private void setButton(@NonNull Button button, @StringRes int textId, @Nullable View.OnClickListener listener) {
|
||||
button.setText(textId);
|
||||
button.setOnClickListener(listener);
|
||||
button.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Slide the layout into the visible screen area
|
||||
* @return Whether the layout position has changed
|
||||
*/
|
||||
@CallSuper
|
||||
public boolean appear(boolean fromRight) {
|
||||
boolean hasChanged = false;
|
||||
if (fromRight) {
|
||||
if (!mDisplaying || !isAtRight()) {
|
||||
mSideDialogAnimator.setFloatValues(currentDisplayMetrics.widthPixels, currentDisplayMetrics.widthPixels - mScrollView.getWidth() - mMargin);
|
||||
mSideDialogAnimator.start();
|
||||
hasChanged = true;
|
||||
}
|
||||
} else {
|
||||
if (!mDisplaying || isAtRight()) {
|
||||
mSideDialogAnimator.setFloatValues(-mDialogLayout.getWidth(), mMargin);
|
||||
mSideDialogAnimator.start();
|
||||
hasChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
mDisplaying = true;
|
||||
return hasChanged;
|
||||
}
|
||||
|
||||
private boolean isAtRight() {
|
||||
return mDialogLayout.getX() > currentDisplayMetrics.widthPixels / 2f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Slide out the layout
|
||||
*/
|
||||
@CallSuper
|
||||
public void disappear() {
|
||||
if (!mDisplaying) return;
|
||||
|
||||
mDisplaying = false;
|
||||
if (isAtRight())
|
||||
mSideDialogAnimator.setFloatValues(currentDisplayMetrics.widthPixels - mDialogLayout.getWidth() - mMargin, currentDisplayMetrics.widthPixels);
|
||||
else
|
||||
mSideDialogAnimator.setFloatValues(mMargin, -mDialogLayout.getWidth());
|
||||
|
||||
mSideDialogAnimator.start();
|
||||
}
|
||||
}
|
79
app_pojavlauncher/src/main/res/layout/dialog_side_dialog.xml
Normal file
79
app_pojavlauncher/src/main/res/layout/dialog_side_dialog.xml
Normal file
@ -0,0 +1,79 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!-- FIXME: If I use wrap content for the scrollview, it goes overboard -->
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
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="@dimen/_280sdp"
|
||||
android:layout_marginVertical="@dimen/padding_heavy"
|
||||
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:background="@drawable/background_control_editor"
|
||||
>
|
||||
|
||||
<com.kdt.DefocusableScrollView
|
||||
android:id="@+id/side_dialog_scrollview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
|
||||
app:layout_constraintBottom_toTopOf="@+id/side_dialog_start_button"
|
||||
app:layout_constraintTop_toBottomOf="@id/side_dialog_title_textview"
|
||||
|
||||
tools:background="@color/background_status_bar">
|
||||
<!-- The content is inflated here -->
|
||||
</com.kdt.DefocusableScrollView>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/side_dialog_title_textview"
|
||||
style="@style/TextAppearance.AppCompat.Large"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="@dimen/padding_moderate"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:text="Quick settings"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<View
|
||||
android:id="@+id/side_dialog_title_divider"
|
||||
style="@style/ThickDivider"
|
||||
android:layout_width="match_parent"
|
||||
android:paddingHorizontal="@dimen/padding_moderate"
|
||||
android:visibility="gone"
|
||||
|
||||
app:layout_constraintTop_toBottomOf="@id/side_dialog_title_textview"
|
||||
|
||||
tools:visibility="visible"
|
||||
/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/side_dialog_start_button"
|
||||
style="@style/Widget.AppCompat.Button.Borderless"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="visible"
|
||||
|
||||
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
tools:visibility="visible"
|
||||
tools:text="Cancel"
|
||||
/>
|
||||
<Button
|
||||
android:id="@+id/side_dialog_end_button"
|
||||
style="@style/Widget.AppCompat.Button.Borderless"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="visible"
|
||||
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
|
||||
tools:visibility="visible"
|
||||
tools:text="Confirm"
|
||||
/>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
x
Reference in New Issue
Block a user