Search in sources :

Example 81 with KeyEvent

use of android.view.KeyEvent in project android_frameworks_base by ParanoidAndroid.

the class KeyguardTransportControlView method sendMediaButtonClick.

private void sendMediaButtonClick(int keyCode) {
    if (mClientIntent == null) {
        // Shouldn't be possible because this view should be hidden in this case.
        Log.e(TAG, "sendMediaButtonClick(): No client is currently registered");
        return;
    }
    // use the registered PendingIntent that will be processed by the registered
    //    media button event receiver, which is the component of mClientIntent
    KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, keyCode);
    Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON);
    intent.putExtra(Intent.EXTRA_KEY_EVENT, keyEvent);
    try {
        mClientIntent.send(getContext(), 0, intent);
    } catch (CanceledException e) {
        Log.e(TAG, "Error sending intent for media button down: " + e);
        e.printStackTrace();
    }
    keyEvent = new KeyEvent(KeyEvent.ACTION_UP, keyCode);
    intent = new Intent(Intent.ACTION_MEDIA_BUTTON);
    intent.putExtra(Intent.EXTRA_KEY_EVENT, keyEvent);
    try {
        mClientIntent.send(getContext(), 0, intent);
    } catch (CanceledException e) {
        Log.e(TAG, "Error sending intent for media button up: " + e);
        e.printStackTrace();
    }
}
Also used : KeyEvent(android.view.KeyEvent) CanceledException(android.app.PendingIntent.CanceledException) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Example 82 with KeyEvent

use of android.view.KeyEvent in project android_frameworks_base by ParanoidAndroid.

the class AccessibilityInputFilter method onInputEvent.

@Override
public void onInputEvent(InputEvent event, int policyFlags) {
    if (DEBUG) {
        Slog.d(TAG, "Received event: " + event + ", policyFlags=0x" + Integer.toHexString(policyFlags));
    }
    if (event instanceof MotionEvent && event.isFromSource(InputDevice.SOURCE_TOUCHSCREEN)) {
        MotionEvent motionEvent = (MotionEvent) event;
        onMotionEvent(motionEvent, policyFlags);
    } else if (event instanceof KeyEvent && event.isFromSource(InputDevice.SOURCE_KEYBOARD)) {
        KeyEvent keyEvent = (KeyEvent) event;
        onKeyEvent(keyEvent, policyFlags);
    } else {
        super.onInputEvent(event, policyFlags);
    }
}
Also used : KeyEvent(android.view.KeyEvent) MotionEvent(android.view.MotionEvent)

Example 83 with KeyEvent

use of android.view.KeyEvent in project android_frameworks_base by ParanoidAndroid.

the class EventSenderImpl method executeKeyEvent.

private void executeKeyEvent(int action, int keyCode) {
    KeyEvent event = new KeyEvent(action, keyCode);
    mWebView.onKeyDown(event.getKeyCode(), event);
}
Also used : KeyEvent(android.view.KeyEvent)

Example 84 with KeyEvent

use of android.view.KeyEvent in project android_frameworks_base by ParanoidAndroid.

the class ProfileActivity method onCreate.

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    mInspectButton = (Button) findViewById(R.id.inspect);
    mCaptureButton = (ToggleButton) findViewById(R.id.capture);
    mVelocitySpinner = (Spinner) findViewById(R.id.velocity);
    mMovementSpinner = (Spinner) findViewById(R.id.movement);
    mUrl = (EditText) findViewById(R.id.url);
    mWeb = (ProfiledWebView) findViewById(R.id.web);
    setCallback(new ProfileCallback() {

        @SuppressWarnings("unchecked")
        @Override
        public void profileCallback(RunData data) {
            new StoreFileTask().execute(new Pair<String, RunData>(TEMP_FILENAME, data));
            Log.d("ProfileActivity", "stored " + data.frames.length + " frames in file");
            setTestingState(TestingState.STOP_TESTING);
        }
    });
    // Inspect button (opens PlaybackActivity)
    mInspectButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            startActivity(new Intent(ProfileActivity.this, PlaybackActivity.class));
        }
    });
    // Velocity spinner
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.velocity_array, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mVelocitySpinner.setAdapter(adapter);
    mVelocitySpinner.setOnItemSelectedListener(new VelocitySelectedListener());
    mVelocitySpinner.setSelection(3);
    // Movement spinner
    String[] content = { getResources().getString(R.string.movement_auto_scroll), getResources().getString(R.string.movement_manual), getResources().getString(R.string.movement_timed) };
    adapter = new ArrayAdapter<CharSequence>(this, android.R.layout.simple_spinner_item, content);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mMovementSpinner.setAdapter(adapter);
    mMovementSpinner.setOnItemSelectedListener(new MovementSelectedListener());
    mMovementSpinner.setSelection(0);
    // Capture toggle button
    mCaptureButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (mCaptureButton.isChecked()) {
                startViewProfiling(false);
            } else {
                mWeb.stopScrollTest();
            }
        }
    });
    // Custom profiling WebView
    mWeb.init(this);
    mWeb.setWebViewClient(new LoggingWebViewClient());
    // URL text entry
    mUrl.setOnEditorActionListener(new OnEditorActionListener() {

        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            String url = mUrl.getText().toString();
            mWeb.loadUrl(url);
            mWeb.requestFocus();
            return true;
        }
    });
    setTestingState(TestingState.NOT_TESTING);
}
Also used : Intent(android.content.Intent) View(android.view.View) AdapterView(android.widget.AdapterView) WebView(android.webkit.WebView) TextView(android.widget.TextView) KeyEvent(android.view.KeyEvent) OnClickListener(android.view.View.OnClickListener) OnEditorActionListener(android.widget.TextView.OnEditorActionListener) TextView(android.widget.TextView) Pair(android.util.Pair)

Example 85 with KeyEvent

use of android.view.KeyEvent in project Anki-Android by Ramblurr.

the class CardBrowser method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    Themes.applyTheme(this);
    super.onCreate(savedInstanceState);
    View mainView = getLayoutInflater().inflate(R.layout.card_browser, null);
    setContentView(mainView);
    Themes.setContentStyle(mainView, Themes.CALLER_CARDBROWSER);
    mCol = AnkiDroidApp.getCol();
    if (mCol == null) {
        reloadCollection(savedInstanceState);
        return;
    }
    mDeckNames = new HashMap<String, String>();
    for (long did : mCol.getDecks().allIds()) {
        mDeckNames.put(String.valueOf(did), mCol.getDecks().name(did));
    }
    registerExternalStorageListener();
    Intent i = getIntent();
    mWholeCollection = i.hasExtra("fromDeckpicker") && i.getBooleanExtra("fromDeckpicker", false);
    mBackground = Themes.getCardBrowserBackground();
    SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(getBaseContext());
    int sflRelativeFontSize = preferences.getInt("relativeCardBrowserFontSize", DEFAULT_FONT_SIZE_RATIO);
    String sflCustomFont = preferences.getString("browserEditorFont", "");
    mPrefFixArabic = preferences.getBoolean("fixArabicText", false);
    Resources res = getResources();
    mOrderByFields = res.getStringArray(R.array.card_browser_order_labels);
    try {
        mOrder = CARD_ORDER_NONE;
        String colOrder = mCol.getConf().getString("sortType");
        for (int c = 0; c < fSortTypes.length; ++c) {
            if (fSortTypes[c].equals(colOrder)) {
                mOrder = c;
                break;
            }
        }
        if (mOrder == 1 && preferences.getBoolean("cardBrowserNoSorting", false)) {
            mOrder = 0;
        }
        mOrderAsc = Upgrade.upgradeJSONIfNecessary(mCol, mCol.getConf(), "sortBackwards", false);
        // default to descending for non-text fields
        if (fSortTypes[mOrder].equals("noteFld")) {
            mOrderAsc = !mOrderAsc;
        }
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }
    mCards = new ArrayList<HashMap<String, String>>();
    mCardsListView = (ListView) findViewById(R.id.card_browser_list);
    mCardsAdapter = new SizeControlledListAdapter(this, mCards, R.layout.card_item, new String[] { "sfld", "deck", "flags" }, new int[] { R.id.card_sfld, R.id.card_deck, R.id.card_item }, sflRelativeFontSize, sflCustomFont);
    mCardsAdapter.setViewBinder(new SimpleAdapter.ViewBinder() {

        @Override
        public boolean setViewValue(View view, Object arg1, String text) {
            if (view.getId() == R.id.card_item) {
                int which = BACKGROUND_NORMAL;
                if (text.equals("1")) {
                    which = BACKGROUND_SUSPENDED;
                } else if (text.equals("2")) {
                    which = BACKGROUND_MARKED;
                } else if (text.equals("3")) {
                    which = BACKGROUND_MARKED_SUSPENDED;
                }
                view.setBackgroundResource(mBackground[which]);
                return true;
            } else if (view.getId() == R.id.card_deck && text.length() > 0) {
                view.setVisibility(View.VISIBLE);
            }
            return false;
        }
    });
    mCardsListView.setAdapter(mCardsAdapter);
    mCardsListView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            mPositionInCardsList = position;
            long cardId = Long.parseLong(mCards.get(mPositionInCardsList).get("id"));
            sCardBrowserCard = mCol.getCard(cardId);
            Intent editCard = new Intent(CardBrowser.this, CardEditor.class);
            editCard.putExtra(CardEditor.EXTRA_CALLER, CardEditor.CALLER_CARDBROWSER_EDIT);
            editCard.putExtra(CardEditor.EXTRA_CARD_ID, sCardBrowserCard.getId());
            startActivityForResult(editCard, EDIT_CARD);
            if (AnkiDroidApp.SDK_VERSION > 4) {
                ActivityTransitionAnimation.slide(CardBrowser.this, ActivityTransitionAnimation.LEFT);
            }
        }
    });
    registerForContextMenu(mCardsListView);
    mSearchEditText = (EditText) findViewById(R.id.card_browser_search);
    mSearchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                onSearch();
                return true;
            }
            return false;
        }
    });
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    mSearchButton = (ImageButton) findViewById(R.id.card_browser_search_button);
    mSearchButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            onSearch();
        }
    });
    mSearchTerms = "";
    if (mWholeCollection) {
        mRestrictOnDeck = "";
        setTitle(res.getString(R.string.card_browser_all_decks));
    } else {
        try {
            String deckName = mCol.getDecks().current().getString("name");
            mRestrictOnDeck = "deck:'" + deckName + "' ";
            setTitle(deckName);
        } catch (JSONException e) {
            throw new RuntimeException(e);
        }
    }
    mSelectedTags = new HashSet<String>();
    if (!preferences.getBoolean("cardBrowserNoSearchOnOpen", false)) {
        searchCards();
    }
}
Also used : HashMap(java.util.HashMap) KeyEvent(android.view.KeyEvent) TextView(android.widget.TextView) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) SharedPreferences(android.content.SharedPreferences) JSONException(org.json.JSONException) SimpleAdapter(android.widget.SimpleAdapter) Intent(android.content.Intent) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) Resources(android.content.res.Resources)

Aggregations

KeyEvent (android.view.KeyEvent)513 View (android.view.View)145 TextView (android.widget.TextView)109 Intent (android.content.Intent)53 ImageView (android.widget.ImageView)38 DialogInterface (android.content.DialogInterface)36 EditText (android.widget.EditText)36 KeyCharacterMap (android.view.KeyCharacterMap)35 Editable (android.text.Editable)34 OnEditorActionListener (android.widget.TextView.OnEditorActionListener)32 Instrumentation (android.app.Instrumentation)30 OnClickListener (android.view.View.OnClickListener)30 Paint (android.graphics.Paint)27 Button (android.widget.Button)27 TextWatcher (android.text.TextWatcher)24 InputMethodManager (android.view.inputmethod.InputMethodManager)22 AlertDialog (android.app.AlertDialog)21 Message (android.os.Message)21 LayoutInflater (android.view.LayoutInflater)21 Test (org.junit.Test)20