|
| 1 | +package com.github.heyalex.bottomdrawerexample; |
| 2 | + |
| 3 | +import android.os.Bundle; |
| 4 | +import android.view.Gravity; |
| 5 | +import android.view.LayoutInflater; |
| 6 | +import android.view.View; |
| 7 | +import android.view.ViewGroup; |
| 8 | +import android.widget.CompoundButton; |
| 9 | +import android.widget.FrameLayout; |
| 10 | +import android.widget.ImageView; |
| 11 | +import android.widget.SeekBar; |
| 12 | + |
| 13 | +import com.github.heyalex.bottomdrawer.BottomDrawerDialog; |
| 14 | +import com.github.heyalex.bottomdrawer.BottomDrawerFragment; |
| 15 | +import com.github.heyalex.handle.PlainHandleView; |
| 16 | +import com.github.heyalex.utils.BottomDrawerDelegate; |
| 17 | +import com.github.heyalex.utils.DialogFragmentExtensionKt; |
| 18 | +import com.rtugeek.android.colorseekbar.ColorSeekBar; |
| 19 | + |
| 20 | +import org.jetbrains.annotations.NotNull; |
| 21 | + |
| 22 | +import androidx.annotation.NonNull; |
| 23 | +import androidx.annotation.Nullable; |
| 24 | +import androidx.appcompat.widget.AppCompatCheckBox; |
| 25 | +import androidx.appcompat.widget.AppCompatSeekBar; |
| 26 | +import kotlin.Unit; |
| 27 | +import kotlin.jvm.functions.Function1; |
| 28 | +import kotlin.jvm.functions.Function2; |
| 29 | + |
| 30 | +public class GoogleTaskJavaSampleDialog extends BottomDrawerFragment { |
| 31 | + |
| 32 | + float alphaCancelButton = 0f; |
| 33 | + ImageView cancelButton; |
| 34 | + AppCompatSeekBar cornerRadiusSeekBar; |
| 35 | + AppCompatCheckBox navigation; |
| 36 | + AppCompatCheckBox statusBar; |
| 37 | + ColorSeekBar colorSeekBar; |
| 38 | + |
| 39 | + @Nullable |
| 40 | + @Override |
| 41 | + public View onCreateView(@NonNull LayoutInflater inflater, |
| 42 | + @Nullable ViewGroup container, |
| 43 | + @Nullable Bundle savedInstanceState) { |
| 44 | + |
| 45 | + View view = inflater.inflate(R.layout.google_task_example_layout, container, false); |
| 46 | + cancelButton = view.findViewById(R.id.cancel); |
| 47 | + final float percent = 0.65f; |
| 48 | + |
| 49 | + addBottomSheetCallback(new Function1<BottomDrawerDelegate.BottomSheetCallback, Unit>() { |
| 50 | + @Override |
| 51 | + public Unit invoke(BottomDrawerDelegate.BottomSheetCallback bottomSheetCallback) { |
| 52 | + bottomSheetCallback.onSlide(new Function2<View, Float, Unit>() { |
| 53 | + @Override |
| 54 | + public Unit invoke(View view, Float slideOffset) { |
| 55 | + float alphaTemp = (slideOffset - percent) * (1.0F / (1.0F - percent)); |
| 56 | + GoogleTaskJavaSampleDialog.this.alphaCancelButton = alphaTemp >= (float) 0 ? alphaTemp : 0.0F; |
| 57 | + GoogleTaskJavaSampleDialog.this.cancelButton.setAlpha(GoogleTaskJavaSampleDialog.this.alphaCancelButton); |
| 58 | + GoogleTaskJavaSampleDialog.this.cancelButton.setEnabled(GoogleTaskJavaSampleDialog.this.alphaCancelButton > 0); |
| 59 | + return Unit.INSTANCE; |
| 60 | + } |
| 61 | + }); |
| 62 | + return Unit.INSTANCE; |
| 63 | + } |
| 64 | + }); |
| 65 | + cancelButton.setOnClickListener(new View.OnClickListener() { |
| 66 | + @Override |
| 67 | + public void onClick(View v) { |
| 68 | + dismissWithBehavior(); |
| 69 | + } |
| 70 | + }); |
| 71 | + |
| 72 | + cornerRadiusSeekBar = view.findViewById(R.id.corner_radius_seek_bar); |
| 73 | + cornerRadiusSeekBar.setMax(200); |
| 74 | + cornerRadiusSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { |
| 75 | + |
| 76 | + @Override |
| 77 | + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { |
| 78 | + changeCornerRadius(progress); |
| 79 | + } |
| 80 | + |
| 81 | + @Override |
| 82 | + public void onStartTrackingTouch(SeekBar seekBar) { |
| 83 | + |
| 84 | + } |
| 85 | + |
| 86 | + @Override |
| 87 | + public void onStopTrackingTouch(SeekBar seekBar) { |
| 88 | + |
| 89 | + } |
| 90 | + }); |
| 91 | + |
| 92 | + navigation = view.findViewById(R.id.navigation_bar_accent); |
| 93 | + navigation.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { |
| 94 | + @Override |
| 95 | + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { |
| 96 | + DialogFragmentExtensionKt.changeNavigationIconColor(GoogleTaskJavaSampleDialog.this, isChecked); |
| 97 | + } |
| 98 | + }); |
| 99 | + statusBar = view.findViewById(R.id.status_bar_accent); |
| 100 | + statusBar.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { |
| 101 | + @Override |
| 102 | + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { |
| 103 | + DialogFragmentExtensionKt.changeStatusBarIconColor(GoogleTaskJavaSampleDialog.this, isChecked); |
| 104 | + } |
| 105 | + }); |
| 106 | + |
| 107 | + colorSeekBar = view.findViewById(R.id.colorSlider); |
| 108 | + colorSeekBar.setOnColorChangeListener(new ColorSeekBar.OnColorChangeListener() { |
| 109 | + @Override |
| 110 | + public void onColorChangeListener(int colorBarPosition, |
| 111 | + int alphaBarPosition, |
| 112 | + int color) { |
| 113 | + if (!colorSeekBar.isFirstDraw()) { |
| 114 | + changeBackgroundColor(color); |
| 115 | + } |
| 116 | + } |
| 117 | + }); |
| 118 | + |
| 119 | + return view; |
| 120 | + } |
| 121 | + |
| 122 | + @NotNull |
| 123 | + @Override |
| 124 | + public BottomDrawerDialog configureBottomDrawer() { |
| 125 | + BottomDrawerDialog.Builder builder = new BottomDrawerDialog.Builder(requireContext()); |
| 126 | + |
| 127 | + View handleView = new PlainHandleView(requireContext()); |
| 128 | + int widthHandle = getResources().getDimensionPixelSize(R.dimen.bottom_sheet_handle_width); |
| 129 | + int heightHandle = |
| 130 | + getResources().getDimensionPixelSize(R.dimen.bottom_sheet_handle_height); |
| 131 | + FrameLayout.LayoutParams params = |
| 132 | + new FrameLayout.LayoutParams(widthHandle, heightHandle, Gravity.CENTER_HORIZONTAL); |
| 133 | + |
| 134 | + params.topMargin = |
| 135 | + getResources().getDimensionPixelSize(R.dimen.bottom_sheet_handle_top_margin); |
| 136 | + handleView.setLayoutParams(params); |
| 137 | + |
| 138 | + builder.setHandleView(handleView); |
| 139 | + |
| 140 | + return builder.build(); |
| 141 | + } |
| 142 | + |
| 143 | + @Override |
| 144 | + public void onSaveInstanceState(@NonNull @NotNull Bundle outState) { |
| 145 | + super.onSaveInstanceState(outState); |
| 146 | + outState.putFloat("alphaCancelButton", alphaCancelButton); |
| 147 | + } |
| 148 | + |
| 149 | + @Override |
| 150 | + public void onViewStateRestored(@Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) { |
| 151 | + super.onViewStateRestored(savedInstanceState); |
| 152 | + this.alphaCancelButton = savedInstanceState != null ? savedInstanceState.getFloat("alphaCancelButton") : 0.0F; |
| 153 | + cancelButton.setAlpha(this.alphaCancelButton); |
| 154 | + cancelButton.setEnabled(this.alphaCancelButton > 0); |
| 155 | + } |
| 156 | +} |
0 commit comments