Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 464d13cd authored by Jun Mukai's avatar Jun Mukai
Browse files

Add KeyEvent handler to LauncherClings.

When the longpress clings such like welcome message appears,
the key events should be limited as follows:
- normal keys (generates printable glyphs) should be prevented,
  otherwise they come to the underlying searchbox.
- it should be dismissed on Menu keys, which goes to the overview
  mode.

Bug: 22982955
Change-Id: I7272b0809bfaa3c08ba77b01383cf54f19390d95
parent f0033da0
Loading
Loading
Loading
Loading
+21 −2
Original line number Diff line number Diff line
@@ -27,16 +27,19 @@ import android.os.Build;
import android.os.Bundle;
import android.os.UserManager;
import android.provider.Settings;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.view.View.OnLongClickListener;
import android.view.ViewGroup;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.view.accessibility.AccessibilityManager;

import com.android.launcher3.util.Thunk;

class LauncherClings implements OnClickListener {
class LauncherClings implements OnClickListener, OnKeyListener {
    private static final String MIGRATION_CLING_DISMISSED_KEY = "cling_gel.migration.dismissed";
    private static final String WORKSPACE_CLING_DISMISSED_KEY = "cling_gel.workspace.dismissed";

@@ -83,6 +86,20 @@ class LauncherClings implements OnClickListener {
        }
    }

    @Override
    public boolean onKey(View v, int keyCode, KeyEvent event) {
        if (event.isPrintingKey()) {
            // Should ignore all printing keys, otherwise they come to the search box.
            return true;
        }
        if (keyCode == KeyEvent.KEYCODE_MENU) {
            // Menu key goes to the overview mode similar to longpress, therefore it needs to
            // dismiss the clings.
            dismissLongPressCling();
        }
        return false;
    }

    /**
     * Shows the migration cling.
     *
@@ -133,7 +150,9 @@ class LauncherClings implements OnClickListener {
        final ViewGroup content = (ViewGroup) cling.findViewById(R.id.cling_content);
        mInflater.inflate(showWelcome ? R.layout.longpress_cling_welcome_content
                : R.layout.longpress_cling_content, content);
        content.findViewById(R.id.cling_dismiss_longpress_info).setOnClickListener(this);
        final View button = content.findViewById(R.id.cling_dismiss_longpress_info);
        button.setOnClickListener(this);
        button.setOnKeyListener(this);

        if (TAG_CROP_TOP_AND_SIDES.equals(content.getTag())) {
            Drawable bg = new BorderCropDrawable(mLauncher.getResources().getDrawable(R.drawable.cling_bg),