use of android.view.View.OnFocusChangeListener in project remote-desktop-clients by iiordanov.
the class GeneratePubkeyActivity method onCreate.
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.act_generatepubkey);
cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
keyTypeGroup = (RadioGroup) findViewById(R.id.key_type);
bitsText = (EditText) findViewById(R.id.bits);
bitsSlider = (SeekBar) findViewById(R.id.bits_slider);
file_name = (EditText) findViewById(R.id.file_name);
password1 = (EditText) findViewById(R.id.password);
generate = (Button) findViewById(R.id.generate);
share = (Button) findViewById(R.id.share);
decrypt = (Button) findViewById(R.id.decrypt);
copy = (Button) findViewById(R.id.copy);
save = (Button) findViewById(R.id.save);
importKey = (Button) findViewById(R.id.importKey);
inflater = LayoutInflater.from(this);
password1.addTextChangedListener(textChecker);
// Get the private key and passphrase from calling activity if added.
sshPrivKey = getIntent().getStringExtra("PrivateKey");
passphrase = password1.getText().toString();
if (sshPrivKey != null && sshPrivKey.length() != 0) {
decryptAndRecoverKey();
} else {
Toast.makeText(getBaseContext(), "Key not generated yet. Set parameters and tap 'Generate New Key'.", Toast.LENGTH_LONG).show();
}
keyTypeGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (checkedId == R.id.rsa) {
minBits = MIN_BITS_RSA;
bitsSlider.setEnabled(true);
bitsSlider.setProgress(DEFAULT_BITS_RSA);
bitsSlider.setMax(MAX_BITS_RSA - minBits);
bitsText.setText(String.valueOf(DEFAULT_BITS_RSA));
bitsText.setEnabled(true);
keyType = PubkeyDatabase.KEY_TYPE_RSA;
} else if (checkedId == R.id.dsa) {
minBits = MIN_BITS_DSA;
bitsSlider.setEnabled(true);
bitsSlider.setProgress(DEFAULT_BITS_DSA);
bitsSlider.setMax(MAX_BITS_DSA - minBits);
bitsText.setText(String.valueOf(DEFAULT_BITS_DSA));
bitsText.setEnabled(true);
keyType = PubkeyDatabase.KEY_TYPE_DSA;
}
}
});
bitsSlider.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch) {
// Stay evenly divisible by 8 because it looks nicer to have
// 2048 than 2043 bits.
int leftover = progress % 8;
int ourProgress = progress;
if (leftover > 0)
ourProgress += 8 - leftover;
bits = minBits + ourProgress;
bitsText.setText(String.valueOf(bits));
}
public void onStartTrackingTouch(SeekBar seekBar) {
// We don't care about the start.
}
public void onStopTrackingTouch(SeekBar seekBar) {
// We don't care about the stop.
}
});
bitsText.setOnFocusChangeListener(new OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
try {
bits = Integer.parseInt(bitsText.getText().toString());
if (bits < minBits) {
bits = minBits;
bitsText.setText(String.valueOf(bits));
}
} catch (NumberFormatException nfe) {
bits = DEFAULT_BITS_RSA;
bitsText.setText(String.valueOf(bits));
}
bitsSlider.setProgress(bits - minBits);
}
}
});
generate.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
hideSoftKeyboard(view);
GeneratePubkeyActivity.this.startEntropyGather();
}
});
decrypt.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
hideSoftKeyboard(view);
decryptAndRecoverKey();
}
});
share.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
hideSoftKeyboard(view);
// This is an UGLY HACK for Blackberry devices which do not transmit the "+" character.
// Remove as soon as the bug is fixed.
String s = android.os.Build.MODEL;
if (s.contains("BlackBerry")) {
Toast.makeText(getBaseContext(), "ERROR: Blackberry devices have problems sharing public keys. " + "The '+' character is not transmitted. Please save as a file and attach in an email, or " + "copy to clipboard and paste when connected to the server with a password.", Toast.LENGTH_LONG).show();
return;
}
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("text/plain");
share.putExtra(Intent.EXTRA_TEXT, publicKeySSHFormat);
startActivity(Intent.createChooser(share, "Share Pubkey"));
}
});
copy.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
hideSoftKeyboard(view);
cm.setText(publicKeySSHFormat);
Toast.makeText(getBaseContext(), "Copied public key in OpenSSH format to clipboard.", Toast.LENGTH_SHORT).show();
}
});
save.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
hideSoftKeyboard(view);
String fname = file_name.getText().toString();
if (fname.length() == 0) {
Toast.makeText(getBaseContext(), "Please enter file name.", Toast.LENGTH_SHORT).show();
return;
}
File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
File file = new File(dir, fname);
fname = dir.getName() + "/" + fname;
try {
dir.mkdirs();
file.createNewFile();
FileOutputStream fout = new FileOutputStream(file);
OutputStreamWriter writer = new OutputStreamWriter(fout);
writer.append(publicKeySSHFormat);
writer.close();
fout.close();
} catch (IOException e) {
Toast.makeText(getBaseContext(), "Failed to write " + fname, Toast.LENGTH_LONG).show();
Log.e(TAG, "Failed to output file " + fname);
e.printStackTrace();
return;
}
Toast.makeText(getBaseContext(), "Successfully wrote public key in OpenSSH format to " + fname, Toast.LENGTH_LONG).show();
}
});
importKey.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
hideSoftKeyboard(view);
String fname = file_name.getText().toString();
if (fname.length() == 0) {
Toast.makeText(getBaseContext(), "Please enter file name (at the bottom) to import PEM formatted " + "encrypted/unencrypted RSA keys, PKCS#8 unencrypted DSA keys. " + "Keys generated with 'ssh-keygen -t rsa' are known to work.", Toast.LENGTH_LONG).show();
return;
}
File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
fname = dir.getAbsolutePath() + "/" + fname;
String data = "";
try {
data = readFile(fname);
} catch (IOException e) {
e.printStackTrace();
Log.e(TAG, "Failed to read key from file: " + fname);
Toast.makeText(getBaseContext(), "Failed to read file: " + fname + ". Please ensure it is present " + "in Download directory.", Toast.LENGTH_LONG).show();
return;
}
try {
passphrase = password1.getText().toString();
KeyPair pair = PubkeyUtils.tryImportingPemAndPkcs8(data, passphrase);
converToBase64AndSendIntent(pair);
} catch (Exception e) {
e.printStackTrace();
Log.e(TAG, "Failed to decode key.");
Toast.makeText(getBaseContext(), e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
return;
}
Toast.makeText(getBaseContext(), "Successfully imported SSH key from file.", Toast.LENGTH_LONG).show();
finish();
}
});
}
use of android.view.View.OnFocusChangeListener in project wechat by motianhuo.
the class ChatActivity method initView.
/**
* initView
*/
protected void initView() {
netClient = new NetClient(this);
recordingContainer = findViewById(R.id.view_talk);
txt_title = (TextView) findViewById(R.id.txt_title);
img_right = (ImageView) findViewById(R.id.img_right);
micImage = (ImageView) findViewById(R.id.mic_image);
animationDrawable = (AnimationDrawable) micImage.getBackground();
animationDrawable.setOneShot(false);
recordingHint = (TextView) findViewById(R.id.recording_hint);
listView = (ListView) findViewById(R.id.list);
mEditTextContent = (PasteEditText) findViewById(R.id.et_sendmessage);
buttonSetModeKeyboard = findViewById(R.id.btn_set_mode_keyboard);
edittext_layout = (RelativeLayout) findViewById(R.id.edittext_layout);
buttonSetModeVoice = findViewById(R.id.btn_set_mode_voice);
buttonSend = findViewById(R.id.btn_send);
buttonPressToSpeak = findViewById(R.id.btn_press_to_speak);
expressionViewpager = (ViewPager) findViewById(R.id.vPager);
emojiIconContainer = (LinearLayout) findViewById(R.id.ll_face_container);
btnContainer = (LinearLayout) findViewById(R.id.ll_btn_container);
// locationImgview = (ImageView) findViewById(R.id.btn_location);
iv_emoticons_normal = (ImageView) findViewById(R.id.iv_emoticons_normal);
iv_emoticons_checked = (ImageView) findViewById(R.id.iv_emoticons_checked);
loadmorePB = (ProgressBar) findViewById(R.id.pb_load_more);
btnMore = (Button) findViewById(R.id.btn_more);
iv_emoticons_normal.setVisibility(View.VISIBLE);
iv_emoticons_checked.setVisibility(View.INVISIBLE);
more = findViewById(R.id.more);
edittext_layout.setBackgroundResource(R.drawable.input_bar_bg_normal);
// 表情list
reslist = getExpressionRes(62);
// 初始化表情viewpager
List<View> views = new ArrayList<View>();
View gv1 = getGridChildView(1);
View gv2 = getGridChildView(2);
View gv3 = getGridChildView(3);
views.add(gv1);
views.add(gv2);
views.add(gv3);
expressionViewpager.setAdapter(new ExpressionPagerAdapter(views));
edittext_layout.requestFocus();
voiceRecorder = new VoiceRecorder(micImageHandler);
buttonPressToSpeak.setOnTouchListener(new PressToSpeakListen());
mEditTextContent.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
edittext_layout.setBackgroundResource(R.drawable.input_bar_bg_active);
} else {
edittext_layout.setBackgroundResource(R.drawable.input_bar_bg_normal);
}
}
});
mEditTextContent.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
edittext_layout.setBackgroundResource(R.drawable.input_bar_bg_active);
more.setVisibility(View.GONE);
iv_emoticons_normal.setVisibility(View.VISIBLE);
iv_emoticons_checked.setVisibility(View.INVISIBLE);
emojiIconContainer.setVisibility(View.GONE);
btnContainer.setVisibility(View.GONE);
}
});
// 监听文字框
mEditTextContent.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (!TextUtils.isEmpty(s)) {
btnMore.setVisibility(View.GONE);
buttonSend.setVisibility(View.VISIBLE);
} else {
btnMore.setVisibility(View.VISIBLE);
buttonSend.setVisibility(View.GONE);
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void afterTextChanged(Editable s) {
}
});
}
use of android.view.View.OnFocusChangeListener in project Android-CollapsibleSearchMenu by johnkil.
the class CollapsibleMenuUtils method addSearchMenuItem.
/**
* Adding collapsible search menu item to the menu.
*
* @param menu
* @param isLightTheme - true if use light them for ActionBar, else false
* @return menu item
*/
public static MenuItem addSearchMenuItem(Menu menu, boolean isLightTheme, final OnQueryTextListener onQueryChangeListener) {
final MenuItem menuItem = menu.add(Menu.NONE, R.id.collapsible_search_menu_item, Menu.NONE, R.string.search_go);
menuItem.setIcon(isLightTheme ? R.drawable.ic_action_search_holo_light : R.drawable.ic_action_search_holo_dark).setActionView(isLightTheme ? R.layout.search_view_holo_light : R.layout.search_view_holo_dark).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
final View searchView = menuItem.getActionView();
final AutoCompleteTextView editText = (AutoCompleteTextView) searchView.findViewById(R.id.search_src_text);
final TextWatcher textWatcher = new TextWatcher() {
@Override
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
onQueryChangeListener.onQueryTextChange(charSequence.toString());
}
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
}
@Override
public void afterTextChanged(Editable editable) {
}
};
final TextView.OnEditorActionListener onEditorActionListener = new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
if (i == EditorInfo.IME_ACTION_SEARCH || keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
onQueryChangeListener.onQueryTextSubmit(textView.getText().toString());
return true;
}
return false;
}
};
menuItem.setOnActionExpandListener(new OnActionExpandListener() {
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
editText.addTextChangedListener(textWatcher);
editText.setOnEditorActionListener(onEditorActionListener);
editText.requestFocus();
showKeyboard(editText);
return true;
}
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
editText.setText(null);
editText.removeTextChangedListener(textWatcher);
// editText.clearFocus();
hideKeyboard(editText);
return true;
}
});
final View searchPlate = searchView.findViewById(R.id.search_plate);
editText.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, final boolean hasFocus) {
searchView.post(new Runnable() {
public void run() {
searchPlate.getBackground().setState(hasFocus ? new int[] { android.R.attr.state_focused } : new int[] { android.R.attr.state_empty });
searchView.invalidate();
}
});
}
});
final ImageView closeBtn = (ImageView) menuItem.getActionView().findViewById(R.id.search_close_btn);
closeBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (!TextUtils.isEmpty(editText.getText())) {
editText.setText(null);
} else {
menuItem.collapseActionView();
}
}
});
return menuItem;
}
use of android.view.View.OnFocusChangeListener in project ETSMobile-Android2 by ApplETS.
the class BandwidthFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View v = inflater.inflate(R.layout.fragment_bandwith, container, false);
textInputLayoutPhase = v.findViewById(R.id.text_input_layout_phase);
editTextPhase = v.findViewById(R.id.bandwidth_editText_phase);
phaseSpinner = v.findViewById(R.id.bandwidth_phase_spinner);
textInputLayoutApp = v.findViewById(R.id.text_input_layout_app);
editTextApp = v.findViewById(R.id.bandwidth_editText_app);
textInputLayoutChambre = v.findViewById(R.id.text_input_layout_chambre);
editTextChambre = v.findViewById(R.id.bandwidth_editText_chambre);
// grid = v.findViewById(R.id.bandwith_grid);
progressBar = v.findViewById(R.id.bandwidth_progress);
progressBarTv = v.findViewById(R.id.bandwidth_progress_tv);
loadProgressBar = v.findViewById(R.id.progressBarLoad);
progressLayout = v.findViewById(R.id.bandwidth_progress_layout);
chart = v.findViewById(R.id.chart);
chart.setVisibility(View.INVISIBLE);
progressLayout.setVisibility(View.GONE);
SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
phase = defaultSharedPreferences.getString(PHASE_PREF_KEY, "");
app = defaultSharedPreferences.getString(APP_PREF_KEY, "");
chambre = defaultSharedPreferences.getString(CHAMBRE_PREF_KEY, "");
if (chambre.length() > 0)
editTextChambre.setText(chambre);
else
editTextChambre.setText(UNE_SEULE_CHAMBRE);
if (phase.length() > 0 && app.length() > 0) {
editTextApp.setText(app);
phaseSpinner.setSelection(Integer.parseInt(phase) - 1);
getBandwidth(phase, app, chambre);
}
editTextPhase.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
phaseSpinner.performClick();
}
});
phaseSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
int phase = position + 1;
editTextPhase.setText(String.valueOf(phase));
if (phase == 3) {
displayPhase3Dialog();
}
verifyInputsAndGetBandwidth();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
TextWatcher textWatcher = new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence cS, int start, int before, int count) {
}
@Override
public void onTextChanged(CharSequence cS, int start, int before, int count) {
verifyInputsAndGetBandwidth();
}
@Override
public void afterTextChanged(Editable editable) {
}
};
editTextApp.addTextChangedListener(textWatcher);
editTextChambre.addTextChangedListener(textWatcher);
OnFocusChangeListener editTextFocusChangeListener = new OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean hasFocus) {
EditText editText = (EditText) view;
TextInputLayout textInputLayout = null;
switch(view.getId()) {
case R.id.bandwidth_editText_phase:
textInputLayout = textInputLayoutPhase;
break;
case R.id.bandwidth_editText_app:
textInputLayout = textInputLayoutApp;
break;
}
if (textInputLayout != null) {
if (!hasFocus && editText.getText().toString().length() == 0)
textInputLayout.setError(getString(R.string.error_field_required));
else
textInputLayout.setError(null);
}
}
};
editTextPhase.setOnFocusChangeListener(editTextFocusChangeListener);
editTextApp.setOnFocusChangeListener(editTextFocusChangeListener);
return v;
}
use of android.view.View.OnFocusChangeListener in project coursera-android by aporter.
the class DialtactsActivity method prepareSearchView.
private void prepareSearchView() {
final View searchViewLayout = getLayoutInflater().inflate(R.layout.dialtacts_custom_action_bar, null);
mSearchView = (SearchView) searchViewLayout.findViewById(R.id.search_view);
mSearchView.setOnQueryTextListener(mPhoneSearchQueryTextListener);
mSearchView.setOnCloseListener(mPhoneSearchCloseListener);
// Since we're using a custom layout for showing SearchView instead of letting the
// search menu icon do that job, we need to manually configure the View so it looks
// "shown via search menu".
// - it should be iconified by default
// - it should not be iconified at this time
// See also comments for onActionViewExpanded()/onActionViewCollapsed()
mSearchView.setIconifiedByDefault(true);
mSearchView.setQueryHint(getString(R.string.hint_findContacts));
mSearchView.setIconified(false);
mSearchView.setOnQueryTextFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean hasFocus) {
if (hasFocus) {
showInputMethod(view.findFocus());
}
}
});
if (!ViewConfiguration.get(this).hasPermanentMenuKey()) {
// Filter option menu should be shown on the right side of SearchView.
final View filterOptionView = searchViewLayout.findViewById(R.id.search_option);
filterOptionView.setVisibility(View.VISIBLE);
filterOptionView.setOnClickListener(mFilterOptionClickListener);
}
getActionBar().setCustomView(searchViewLayout, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
}
Aggregations