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);
}
}
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);
}
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);
}
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();
}
}
use of android.view.KeyEvent in project NewPipe by TeamNewPipe.
the class PlayVideoActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_play_video);
setVolumeControlStream(AudioManager.STREAM_MUSIC);
//set background arrow style
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_arrow_back_white_24dp);
isLandscape = checkIfLandscape();
hasSoftKeys = checkIfHasSoftKeys();
actionBar = getSupportActionBar();
assert actionBar != null;
actionBar.setDisplayHomeAsUpEnabled(true);
Intent intent = getIntent();
if (mediaController == null) {
//prevents back button hiding media controller controls (after showing them)
//instead of exiting video
//see http://stackoverflow.com/questions/6051825
//also solves https://github.com/theScrabi/NewPipe/issues/99
mediaController = new MediaController(this) {
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
int keyCode = event.getKeyCode();
final boolean uniqueDown = event.getRepeatCount() == 0 && event.getAction() == KeyEvent.ACTION_DOWN;
if (keyCode == KeyEvent.KEYCODE_BACK) {
if (uniqueDown) {
if (isShowing()) {
finish();
} else {
hide();
}
}
return true;
}
return super.dispatchKeyEvent(event);
}
};
}
//convert from seconds to milliseconds
position = intent.getIntExtra(START_POSITION, 0) * 1000;
videoView = (VideoView) findViewById(R.id.video_view);
progressBar = (ProgressBar) findViewById(R.id.play_video_progress_bar);
try {
videoView.setMediaController(mediaController);
videoView.setVideoURI(Uri.parse(intent.getStringExtra(STREAM_URL)));
} catch (Exception e) {
e.printStackTrace();
}
videoView.requestFocus();
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
progressBar.setVisibility(View.GONE);
videoView.seekTo(position);
if (position <= 0) {
videoView.start();
showUi();
} else {
videoView.pause();
}
}
});
videoUrl = intent.getStringExtra(VIDEO_URL);
Button button = (Button) findViewById(R.id.content_button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (uiIsHidden) {
showUi();
} else {
hideUi();
}
}
});
decorView = getWindow().getDecorView();
decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
@Override
public void onSystemUiVisibilityChange(int visibility) {
if (visibility == View.VISIBLE && uiIsHidden) {
showUi();
}
}
});
if (android.os.Build.VERSION.SDK_INT >= 17) {
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
}
prefs = getPreferences(Context.MODE_PRIVATE);
if (prefs.getBoolean(PREF_IS_LANDSCAPE, false) && !isLandscape) {
toggleOrientation();
}
}
Aggregations