mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-11-14 21:37:52 -07:00
Android: Convert TwoPaneOnBackPressedCallback to Kotlin
This commit is contained in:
parent
6bc4ae7438
commit
3935449ca0
@ -1,56 +0,0 @@
|
|||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
||||||
|
|
||||||
package org.dolphinemu.dolphinemu.ui;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.inputmethod.InputMethodManager;
|
|
||||||
|
|
||||||
import androidx.activity.OnBackPressedCallback;
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.slidingpanelayout.widget.SlidingPaneLayout;
|
|
||||||
|
|
||||||
public class TwoPaneOnBackPressedCallback extends OnBackPressedCallback
|
|
||||||
implements SlidingPaneLayout.PanelSlideListener
|
|
||||||
{
|
|
||||||
private final SlidingPaneLayout mSlidingPaneLayout;
|
|
||||||
|
|
||||||
public TwoPaneOnBackPressedCallback(@NonNull SlidingPaneLayout slidingPaneLayout)
|
|
||||||
{
|
|
||||||
super(slidingPaneLayout.isSlideable() && slidingPaneLayout.isOpen());
|
|
||||||
mSlidingPaneLayout = slidingPaneLayout;
|
|
||||||
slidingPaneLayout.addPanelSlideListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handleOnBackPressed()
|
|
||||||
{
|
|
||||||
mSlidingPaneLayout.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPanelSlide(@NonNull View panel, float slideOffset)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPanelOpened(@NonNull View panel)
|
|
||||||
{
|
|
||||||
setEnabled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPanelClosed(@NonNull View panel)
|
|
||||||
{
|
|
||||||
closeKeyboard();
|
|
||||||
setEnabled(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void closeKeyboard()
|
|
||||||
{
|
|
||||||
InputMethodManager manager = (InputMethodManager) mSlidingPaneLayout.getContext()
|
|
||||||
.getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
||||||
manager.hideSoftInputFromWindow(mSlidingPaneLayout.getRootView().getWindowToken(), 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,38 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
package org.dolphinemu.dolphinemu.ui
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.view.View
|
||||||
|
import android.view.inputmethod.InputMethodManager
|
||||||
|
import androidx.activity.OnBackPressedCallback
|
||||||
|
import androidx.slidingpanelayout.widget.SlidingPaneLayout
|
||||||
|
import androidx.slidingpanelayout.widget.SlidingPaneLayout.PanelSlideListener
|
||||||
|
|
||||||
|
class TwoPaneOnBackPressedCallback(private val slidingPaneLayout: SlidingPaneLayout) :
|
||||||
|
OnBackPressedCallback(slidingPaneLayout.isSlideable && slidingPaneLayout.isOpen),
|
||||||
|
PanelSlideListener {
|
||||||
|
init {
|
||||||
|
slidingPaneLayout.addPanelSlideListener(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun handleOnBackPressed() {
|
||||||
|
slidingPaneLayout.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPanelSlide(panel: View, slideOffset: Float) {}
|
||||||
|
override fun onPanelOpened(panel: View) {
|
||||||
|
isEnabled = true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPanelClosed(panel: View) {
|
||||||
|
closeKeyboard()
|
||||||
|
isEnabled = false
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun closeKeyboard() {
|
||||||
|
val manager = slidingPaneLayout.context
|
||||||
|
.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||||
|
manager.hideSoftInputFromWindow(slidingPaneLayout.rootView.windowToken, 0)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user