app list: open keyboard when X-ing search query
This commit is contained in:
parent
432a7882fd
commit
f7c757bf33
@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2010-12 Ciaran Gultnieks, ciaran@ciarang.com
|
* Copyright (C) 2010-12 Ciaran Gultnieks, ciaran@ciarang.com
|
||||||
|
* Copyright (C) 2019 Michael Pöhn, michael.poehn@fsfe.org
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU General Public License
|
* modify it under the terms of the GNU General Public License
|
||||||
@ -25,6 +26,7 @@ import android.content.pm.Signature;
|
|||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.Rect;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
@ -45,6 +47,8 @@ import android.text.style.TypefaceSpan;
|
|||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewTreeObserver;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
||||||
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
|
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
|
||||||
@ -912,4 +916,35 @@ public final class Utils {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Keep an instance of this class as an field in an Activity for figuring out whether the on
|
||||||
|
* screen keyboard is currently visible or not.
|
||||||
|
*/
|
||||||
|
public static class KeyboardStateMonitor {
|
||||||
|
|
||||||
|
private boolean visible = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param contentView this must be the top most Container of the layout used by the Activity
|
||||||
|
*/
|
||||||
|
public KeyboardStateMonitor(final View contentView) {
|
||||||
|
contentView.getViewTreeObserver().addOnGlobalLayoutListener(
|
||||||
|
new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||||
|
@Override
|
||||||
|
public void onGlobalLayout() {
|
||||||
|
int screenHeight = contentView.getRootView().getHeight();
|
||||||
|
Rect rect = new Rect();
|
||||||
|
contentView.getWindowVisibleDisplayFrame(rect);
|
||||||
|
int keypadHeight = screenHeight - rect.bottom;
|
||||||
|
visible = keypadHeight >= screenHeight * 0.15;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isKeyboardVisible() {
|
||||||
|
return visible;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016-17 Peter Serwylo,
|
||||||
|
* Copyright (C) 2017-18 Hans-Christoph Steiner
|
||||||
|
* Copyright (C) 2019 Michael Pöhn, michael.poehn@fsfe.org
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 3
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
package org.fdroid.fdroid.views.apps;
|
package org.fdroid.fdroid.views.apps;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@ -21,6 +42,7 @@ import android.widget.TextView;
|
|||||||
import com.nostra13.universalimageloader.core.ImageLoader;
|
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||||
import org.fdroid.fdroid.FDroidApp;
|
import org.fdroid.fdroid.FDroidApp;
|
||||||
import org.fdroid.fdroid.R;
|
import org.fdroid.fdroid.R;
|
||||||
|
import org.fdroid.fdroid.Utils;
|
||||||
import org.fdroid.fdroid.data.AppProvider;
|
import org.fdroid.fdroid.data.AppProvider;
|
||||||
import org.fdroid.fdroid.data.Schema;
|
import org.fdroid.fdroid.data.Schema;
|
||||||
|
|
||||||
@ -43,6 +65,7 @@ public class AppListActivity extends AppCompatActivity implements LoaderManager.
|
|||||||
private TextView emptyState;
|
private TextView emptyState;
|
||||||
private EditText searchInput;
|
private EditText searchInput;
|
||||||
private ImageView sortImage;
|
private ImageView sortImage;
|
||||||
|
private Utils.KeyboardStateMonitor keyboardStateMonitor;
|
||||||
|
|
||||||
private interface SortClause {
|
private interface SortClause {
|
||||||
String NAME = Schema.AppMetadataTable.NAME + "." + Schema.AppMetadataTable.Cols.NAME + " asc";
|
String NAME = Schema.AppMetadataTable.NAME + "." + Schema.AppMetadataTable.Cols.NAME + " asc";
|
||||||
@ -57,6 +80,8 @@ public class AppListActivity extends AppCompatActivity implements LoaderManager.
|
|||||||
|
|
||||||
setContentView(R.layout.activity_app_list);
|
setContentView(R.layout.activity_app_list);
|
||||||
|
|
||||||
|
keyboardStateMonitor = new Utils.KeyboardStateMonitor(findViewById(R.id.app_list_root));
|
||||||
|
|
||||||
searchInput = (EditText) findViewById(R.id.search);
|
searchInput = (EditText) findViewById(R.id.search);
|
||||||
searchInput.addTextChangedListener(new CategoryTextWatcher(this, searchInput, this));
|
searchInput.addTextChangedListener(new CategoryTextWatcher(this, searchInput, this));
|
||||||
searchInput.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
searchInput.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
||||||
@ -119,6 +144,13 @@ public class AppListActivity extends AppCompatActivity implements LoaderManager.
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
searchInput.setText("");
|
searchInput.setText("");
|
||||||
|
searchInput.requestFocus();
|
||||||
|
if (!keyboardStateMonitor.isKeyboardVisible()) {
|
||||||
|
InputMethodManager inputMethodManager =
|
||||||
|
(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
|
inputMethodManager.toggleSoftInputFromWindow(v.getApplicationWindowToken(),
|
||||||
|
InputMethodManager.SHOW_FORCED, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:id="@+id/app_list_root"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user