use of android.view.View.OnKeyListener in project double-espresso by JakeWharton.
the class SendActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.send_activity);
EditText editText = (EditText) findViewById(R.id.enter_data_edit_text);
editText.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View view, int keyCode, KeyEvent event) {
if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
EditText editText = (EditText) view;
TextView responseText = (TextView) findViewById(R.id.enter_data_response_text);
responseText.setText(editText.getText());
return true;
} else {
return false;
}
}
});
final EditText searchBox = (EditText) findViewById(R.id.search_box);
searchBox.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
TextView result = (TextView) findViewById(R.id.search_result);
result.setText(getString(R.string.searching_for_label) + " " + v.getText());
result.setVisibility(View.VISIBLE);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(searchBox.getWindowToken(), 0);
return true;
}
return false;
}
});
AutoCompleteTextView autoComplete = (AutoCompleteTextView) findViewById(R.id.auto_complete_text_view);
String[] completions = new String[] { "Pacific Ocean", "Atlantic Ocean", "Indian Ocean", "Southern Ocean", "Artic Ocean", "Mediterranean Sea", "Caribbean Sea", "South China Sea", "Bering Sea", "Gulf of Mexico", "Okhotsk Sea", "East China Sea", "Hudson Bay", "Japan Sea", "Andaman Sea", "North Sea", "Red Sea", "Baltic Sea" };
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, completions);
autoComplete.setAdapter(adapter);
}
use of android.view.View.OnKeyListener in project Jota-Text-Editor-old by jiro-aqua.
the class Main method onCreate.
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
applyBootSetting();
super.onCreate(savedInstanceState);
setContentView(R.layout.textviewer);
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(mOnSharedPreferenceChangeListener);
setVolumeControlStream(AudioManager.STREAM_MUSIC);
mEditor = (jp.sblo.pandora.jota.text.EditText) findViewById(R.id.textedit);
mEditor.setDocumentChangedListener(this);
mEditor.setShortcutListener(this);
mEditor.setChanged(false);
mLlSearch = (LinearLayout) findViewById(R.id.search);
mLlReplace = (LinearLayout) findViewById(R.id.replace);
mEdtSearchWord = (jp.sblo.pandora.jota.text.EditText) findViewById(R.id.edtSearchWord);
mEdtSearchWord.setShortcutListener(null);
mBtnForward = (ImageButton) findViewById(R.id.btnForward);
mBtnBackward = (ImageButton) findViewById(R.id.btnBackward);
mChkReplace = (Button) findViewById(R.id.chkReplace);
mBtnClose = (ImageButton) findViewById(R.id.btnClose);
mEdtReplaceWord = (jp.sblo.pandora.jota.text.EditText) findViewById(R.id.edtReplaceWord);
mEdtReplaceWord.setShortcutListener(null);
mBtnReplace = (Button) findViewById(R.id.btnReplace);
mBtnReplaceAll = (Button) findViewById(R.id.btnReplaceAll);
applySetting();
mEdtSearchWord.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence s, int start, int before, int count) {
boolean enabled = (s.length() > 0);
mBtnForward.setEnabled(enabled);
mBtnBackward.setEnabled(enabled);
mSearchResult = null;
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void afterTextChanged(Editable s) {
}
});
mEdtSearchWord.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_ENTER || keyCode == KeyEvent.KEYCODE_DPAD_CENTER) && event.getAction() == KeyEvent.ACTION_UP) {
if (mBtnForward.isEnabled()) {
mBtnForward.performClick();
return true;
}
}
return false;
}
});
mEdtSearchWord.setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_FULLSCREEN | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
mEdtReplaceWord.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void afterTextChanged(Editable s) {
}
});
mEdtReplaceWord.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
// }
return false;
}
});
mEdtReplaceWord.setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_FULLSCREEN | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
mBtnForward.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
String searchword = mEdtSearchWord.getText().toString();
mSearchForward = true;
doSearch(searchword);
}
});
mBtnBackward.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
String searchword = mEdtSearchWord.getText().toString();
mSearchForward = false;
doSearch(searchword);
}
});
mChkReplace.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mLlReplace.setVisibility(View.VISIBLE);
mChkReplace.setVisibility(View.GONE);
mEdtReplaceWord.requestFocus();
if (mSearchResult == null) {
String searchword = mEdtSearchWord.getText().toString();
doSearch(searchword);
}
}
});
mBtnClose.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mSearchResult = null;
mLlSearch.setVisibility(View.GONE);
mLlReplace.setVisibility(View.GONE);
mChkReplace.setVisibility(View.VISIBLE);
}
});
// edtReplaceWord
// btnSkip
// btnReplaceAll
mBtnReplace.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
String searchword = mEdtSearchWord.getText().toString();
mReplaceWord = mEdtReplaceWord.getText().toString();
doReplace(searchword);
}
});
mBtnReplaceAll.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
String searchword = mEdtSearchWord.getText().toString();
mReplaceWord = mEdtReplaceWord.getText().toString();
doReplaceAll(searchword);
}
});
mProcNew.run();
if (savedInstanceState == null) {
Intent it = getIntent();
if (it != null && (Intent.ACTION_VIEW.equals(it.getAction()) || Intent.ACTION_EDIT.equals(it.getAction()))) {
mLine = -1;
Uri data = it.getData();
String scheme = data.getScheme();
String path = null;
if (ContentResolver.SCHEME_FILE.equals(scheme)) {
path = Uri.decode(data.getEncodedPath());
String lineparam = data.getQueryParameter("line");
if (lineparam != null) {
try {
mLine = Integer.parseInt(lineparam);
} catch (Exception e) {
}
}
} else if (ContentResolver.SCHEME_CONTENT.equals(scheme)) {
ContentResolver cr = getContentResolver();
Cursor cur = null;
try {
cur = cr.query(data, null, null, null, null);
} catch (Exception e) {
}
if (cur != null) {
cur.moveToFirst();
try {
path = cur.getString(cur.getColumnIndex("_data"));
if (path == null || !path.startsWith(Environment.getExternalStorageDirectory().getPath())) {
// from content provider
path = data.toString();
}
} catch (Exception e) {
path = data.toString();
}
} else {
path = data.toString();
}
} else {
}
// }
if (path != null) {
mTask = new TextLoadTask(this, this, mLine);
mTask.execute(path, mSettings.CharsetOpen);
}
} else if (it != null && Intent.ACTION_SEND.equals(it.getAction())) {
Bundle extras = it.getExtras();
String text = extras.getString(Intent.EXTRA_TEXT);
if (text != null) {
mEditor.setText(text);
}
} else if (it != null && ACTION_EDIT_SCRIPT.equals(it.getAction())) {
Bundle extras = it.getExtras();
String path = extras.getString(EXTRA_SCRIPT_PATH);
String contents = getIntent().getStringExtra(EXTRA_SCRIPT_CONTENT);
if (contents != null) {
mEditor.setText(contents);
} else {
if (path != null) {
mTask = new TextLoadTask(this, this, mLine);
mTask.execute(path, mSettings.CharsetOpen);
}
}
} else if (mSettings.rememberlastfile) {
File[] fl = getHistory();
if (fl != null) {
mTask = new TextLoadTask(this, this, -1);
mTask.execute(fl[0].getPath(), mSettings.CharsetOpen);
}
}
} else {
mInstanceState.filename = savedInstanceState.getString("filename");
mInstanceState.charset = savedInstanceState.getString("charset");
// mInstanceState.text = savedInstanceState.getString("text" );
mInstanceState.linebreak = savedInstanceState.getInt("linebreak");
// mInstanceState.selstart = savedInstanceState.getInt("selstart" );
// mInstanceState.selend = savedInstanceState.getInt("selend" );
mInstanceState.changed = savedInstanceState.getBoolean("changed");
// mEditor.setText(mInstanceState.text);
// mEditor.setSelection(mInstanceState.selstart,
// mInstanceState.selend);
mEditor.setChanged(mInstanceState.changed);
}
}
use of android.view.View.OnKeyListener in project LeafPic by HoraApps.
the class PlayerActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(org.horaapps.leafpic.R.layout.activity_player);
FrameLayout root = (FrameLayout) findViewById(org.horaapps.leafpic.R.id.root);
findViewById(R.id.video_frame).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
toggleControlsVisibility();
}
});
root.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
return !(keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_ESCAPE || keyCode == KeyEvent.KEYCODE_MENU) && mediaController.dispatchKeyEvent(event);
}
});
root.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.md_black_1000));
shutterView = findViewById(org.horaapps.leafpic.R.id.shutter);
videoFrame = (AspectRatioFrameLayout) findViewById(org.horaapps.leafpic.R.id.video_frame);
surfaceView = (SurfaceView) findViewById(org.horaapps.leafpic.R.id.surface_view);
surfaceView.getHolder().addCallback(this);
mediaController = new CustomMediaController(this, this);
mediController_anchor = findViewById(org.horaapps.leafpic.R.id.media_player_anchor);
mediaController.setAnchorView(root);
//mediaController.setPaddingRelative(0,0,0,Measure.getNavBarHeight(PlayerActivity.this));
toolbar = (Toolbar) findViewById(org.horaapps.leafpic.R.id.toolbar);
initUI();
CookieHandler currentHandler = CookieHandler.getDefault();
if (currentHandler != defaultCookieManager)
CookieHandler.setDefault(defaultCookieManager);
audioCapabilitiesReceiver = new AudioCapabilitiesReceiver(this, this);
audioCapabilitiesReceiver.register();
}
use of android.view.View.OnKeyListener in project hubroid by EddieRingle.
the class GitHubAuthenticatorActivity method onCreate.
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle, R.layout.login_activity);
mAccountAuthenticatorResponse = getIntent().getParcelableExtra(KEY_ACCOUNT_AUTHENTICATOR_RESPONSE);
if (mAccountAuthenticatorResponse != null) {
mAccountAuthenticatorResponse.onRequestContinued();
}
mAccountManager = AccountManager.get(this);
final Intent intent = getIntent();
mLogin = intent.getStringExtra(PARAM_LOGIN);
mAuthTokenType = intent.getStringExtra(PARAM_AUTHTOKEN_TYPE);
mRequestNewAccount = mLogin == null;
mConfirmCredentials = intent.getBooleanExtra(PARAM_CONFIRMCREDENTIALS, false);
mLoginText.setAdapter(new ArrayAdapter<String>(this, simple_dropdown_item_1line, userLoginAccounts()));
mPasswordText.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (event != null && ACTION_DOWN == event.getAction() && keyCode == KEYCODE_ENTER && mSignInButton.isEnabled()) {
handleLogin(mSignInButton);
return true;
}
return false;
}
});
mPasswordText.setOnEditorActionListener(new OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == IME_ACTION_DONE && mSignInButton.isEnabled()) {
handleLogin(mSignInButton);
return true;
}
return false;
}
});
mSignInButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
handleLogin(mSignInButton);
}
});
mLoginText.addTextChangedListener(mWatcher);
mPasswordText.addTextChangedListener(mWatcher);
TextView signupText = (TextView) findViewById(R.id.tv_auth_link_sign_up);
signupText.setMovementMethod(LinkMovementMethod.getInstance());
signupText.setText(Html.fromHtml(getString(R.string.auth_link_signup)));
}
Aggregations