List of usage examples for android.widget EditText EditText
public EditText(Context context)
From source file:eu.codeplumbers.cosi.wizards.firstrun.ConnectFragment.java
private void showGiveDevicePasswordDialog() { AlertDialog.Builder alertDialog = new AlertDialog.Builder(getActivity()); alertDialog.setTitle("Register your device"); alertDialog.setMessage("Your device is already registered\n Please type your device token"); final EditText input = new EditText(getActivity()); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); input.setLayoutParams(lp);//from w ww .j a va 2s .c o m alertDialog.setView(input); alertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { String password = input.getText().toString(); if (!password.isEmpty()) { final JSONObject permissionJson = new JSONObject(); final JSONObject desc = new JSONObject(); try { Device device = new Device(); device.setUrl(mUrl.getText().toString()); device.setLogin(mDeviceName.getText().toString()); device.setPassword(password); desc.put("description", "sync all my cozy data"); permissionJson.put("All", desc); device.setPermissions(permissionJson.toString()); device.setFirstSyncDone(false); device.setSyncCalls(false); device.setSyncContacts(false); device.setSyncFiles(false); device.setSyncNotes(false); device.save(); onRegisterSuccess(device); } catch (JSONException e) { e.printStackTrace(); } } else { input.setError("Your device token can not be empty!"); } } }); alertDialog.show(); }
From source file:com.aware.ui.ESM_UI.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { // getActivity().getWindow().setType(WindowManager.LayoutParams.TYPE_PRIORITY_PHONE); // getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); // getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); // getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); builder = new AlertDialog.Builder(getActivity()); inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); inputManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); TAG = Aware.getSetting(getActivity().getApplicationContext(), Aware_Preferences.DEBUG_TAG).length() > 0 ? Aware.getSetting(getActivity().getApplicationContext(), Aware_Preferences.DEBUG_TAG) : TAG;//from w w w . j a v a2s . co m Cursor visible_esm = getActivity().getContentResolver().query(ESM_Data.CONTENT_URI, null, ESM_Data.STATUS + "=" + ESM.STATUS_NEW, null, ESM_Data.TIMESTAMP + " ASC LIMIT 1"); if (visible_esm != null && visible_esm.moveToFirst()) { esm_id = visible_esm.getInt(visible_esm.getColumnIndex(ESM_Data._ID)); //Fixed: set the esm as not new anymore, to avoid displaying the same ESM twice due to changes in orientation ContentValues update_state = new ContentValues(); update_state.put(ESM_Data.STATUS, ESM.STATUS_VISIBLE); getActivity().getContentResolver().update(ESM_Data.CONTENT_URI, update_state, ESM_Data._ID + "=" + esm_id, null); esm_type = visible_esm.getInt(visible_esm.getColumnIndex(ESM_Data.TYPE)); expires_seconds = visible_esm.getInt(visible_esm.getColumnIndex(ESM_Data.EXPIRATION_THREASHOLD)); builder.setTitle(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.TITLE))); View ui = null; switch (esm_type) { case ESM.TYPE_ESM_TEXT: ui = inflater.inflate(R.layout.esm_text, null); break; case ESM.TYPE_ESM_RADIO: ui = inflater.inflate(R.layout.esm_radio, null); break; case ESM.TYPE_ESM_CHECKBOX: ui = inflater.inflate(R.layout.esm_checkbox, null); break; case ESM.TYPE_ESM_LIKERT: ui = inflater.inflate(R.layout.esm_likert, null); break; case ESM.TYPE_ESM_QUICK_ANSWERS: ui = inflater.inflate(R.layout.esm_quick, null); break; } final View layout = ui; builder.setView(layout); current_dialog = builder.create(); sContext = current_dialog.getContext(); TextView esm_instructions = (TextView) layout.findViewById(R.id.esm_instructions); esm_instructions.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.INSTRUCTIONS))); switch (esm_type) { case ESM.TYPE_ESM_TEXT: final EditText feedback = (EditText) layout.findViewById(R.id.esm_feedback); Button cancel_text = (Button) layout.findViewById(R.id.esm_cancel); cancel_text.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { inputManager.hideSoftInputFromWindow(feedback.getWindowToken(), 0); current_dialog.cancel(); } }); Button submit_text = (Button) layout.findViewById(R.id.esm_submit); submit_text.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.SUBMIT))); submit_text.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { inputManager.hideSoftInputFromWindow(feedback.getWindowToken(), 0); if (expires_seconds > 0 && expire_monitor != null) expire_monitor.cancel(true); ContentValues rowData = new ContentValues(); rowData.put(ESM_Data.ANSWER_TIMESTAMP, System.currentTimeMillis()); rowData.put(ESM_Data.ANSWER, feedback.getText().toString()); rowData.put(ESM_Data.STATUS, ESM.STATUS_ANSWERED); sContext.getContentResolver().update(ESM_Data.CONTENT_URI, rowData, ESM_Data._ID + "=" + esm_id, null); Intent answer = new Intent(ESM.ACTION_AWARE_ESM_ANSWERED); getActivity().sendBroadcast(answer); if (Aware.DEBUG) Log.d(TAG, "Answer:" + rowData.toString()); current_dialog.dismiss(); } }); break; case ESM.TYPE_ESM_RADIO: try { final RadioGroup radioOptions = (RadioGroup) layout.findViewById(R.id.esm_radio); final JSONArray radios = new JSONArray( visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.RADIOS))); for (int i = 0; i < radios.length(); i++) { final RadioButton radioOption = new RadioButton(getActivity()); radioOption.setId(i); radioOption.setText(radios.getString(i)); radioOptions.addView(radioOption); if (radios.getString(i).equals("Other")) { radioOption.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final Dialog editOther = new Dialog(getActivity()); editOther.setTitle("Can you be more specific, please?"); editOther.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); editOther.getWindow().setGravity(Gravity.TOP); editOther.getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); LinearLayout editor = new LinearLayout(getActivity()); editor.setOrientation(LinearLayout.VERTICAL); editOther.setContentView(editor); editOther.show(); final EditText otherText = new EditText(getActivity()); editor.addView(otherText); Button confirm = new Button(getActivity()); confirm.setText("OK"); confirm.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (otherText.length() > 0) radioOption.setText(otherText.getText()); inputManager.hideSoftInputFromWindow(otherText.getWindowToken(), 0); editOther.dismiss(); } }); editor.addView(confirm); } }); } } Button cancel_radio = (Button) layout.findViewById(R.id.esm_cancel); cancel_radio.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { current_dialog.cancel(); } }); Button submit_radio = (Button) layout.findViewById(R.id.esm_submit); submit_radio.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.SUBMIT))); submit_radio.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (expires_seconds > 0 && expire_monitor != null) expire_monitor.cancel(true); ContentValues rowData = new ContentValues(); rowData.put(ESM_Data.ANSWER_TIMESTAMP, System.currentTimeMillis()); RadioGroup radioOptions = (RadioGroup) layout.findViewById(R.id.esm_radio); if (radioOptions.getCheckedRadioButtonId() != -1) { RadioButton selected = (RadioButton) radioOptions .getChildAt(radioOptions.getCheckedRadioButtonId()); rowData.put(ESM_Data.ANSWER, selected.getText().toString()); } rowData.put(ESM_Data.STATUS, ESM.STATUS_ANSWERED); sContext.getContentResolver().update(ESM_Data.CONTENT_URI, rowData, ESM_Data._ID + "=" + esm_id, null); Intent answer = new Intent(ESM.ACTION_AWARE_ESM_ANSWERED); getActivity().sendBroadcast(answer); if (Aware.DEBUG) Log.d(TAG, "Answer:" + rowData.toString()); current_dialog.dismiss(); } }); } catch (JSONException e) { e.printStackTrace(); } break; case ESM.TYPE_ESM_CHECKBOX: try { final LinearLayout checkboxes = (LinearLayout) layout.findViewById(R.id.esm_checkboxes); final JSONArray checks = new JSONArray( visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.CHECKBOXES))); for (int i = 0; i < checks.length(); i++) { final CheckBox checked = new CheckBox(getActivity()); checked.setText(checks.getString(i)); checked.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(final CompoundButton buttonView, boolean isChecked) { if (isChecked) { if (buttonView.getText().equals("Other")) { checked.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final Dialog editOther = new Dialog(getActivity()); editOther.setTitle("Can you be more specific, please?"); editOther.getWindow() .setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); editOther.getWindow().setGravity(Gravity.TOP); editOther.getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); LinearLayout editor = new LinearLayout(getActivity()); editor.setOrientation(LinearLayout.VERTICAL); editOther.setContentView(editor); editOther.show(); final EditText otherText = new EditText(getActivity()); editor.addView(otherText); Button confirm = new Button(getActivity()); confirm.setText("OK"); confirm.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (otherText.length() > 0) { inputManager.hideSoftInputFromWindow( otherText.getWindowToken(), 0); selected_options .remove(buttonView.getText().toString()); checked.setText(otherText.getText()); selected_options.add(otherText.getText().toString()); } editOther.dismiss(); } }); editor.addView(confirm); } }); } else { selected_options.add(buttonView.getText().toString()); } } else { selected_options.remove(buttonView.getText().toString()); } } }); checkboxes.addView(checked); } Button cancel_checkbox = (Button) layout.findViewById(R.id.esm_cancel); cancel_checkbox.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { current_dialog.cancel(); } }); Button submit_checkbox = (Button) layout.findViewById(R.id.esm_submit); submit_checkbox.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.SUBMIT))); submit_checkbox.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (expires_seconds > 0 && expire_monitor != null) expire_monitor.cancel(true); ContentValues rowData = new ContentValues(); rowData.put(ESM_Data.ANSWER_TIMESTAMP, System.currentTimeMillis()); if (selected_options.size() > 0) { rowData.put(ESM_Data.ANSWER, selected_options.toString()); } rowData.put(ESM_Data.STATUS, ESM.STATUS_ANSWERED); sContext.getContentResolver().update(ESM_Data.CONTENT_URI, rowData, ESM_Data._ID + "=" + esm_id, null); Intent answer = new Intent(ESM.ACTION_AWARE_ESM_ANSWERED); getActivity().sendBroadcast(answer); if (Aware.DEBUG) Log.d(TAG, "Answer:" + rowData.toString()); current_dialog.dismiss(); } }); } catch (JSONException e) { e.printStackTrace(); } break; case ESM.TYPE_ESM_LIKERT: final RatingBar ratingBar = (RatingBar) layout.findViewById(R.id.esm_likert); ratingBar.setMax(visible_esm.getInt(visible_esm.getColumnIndex(ESM_Data.LIKERT_MAX))); ratingBar.setStepSize( (float) visible_esm.getDouble(visible_esm.getColumnIndex(ESM_Data.LIKERT_STEP))); ratingBar.setNumStars(visible_esm.getInt(visible_esm.getColumnIndex(ESM_Data.LIKERT_MAX))); TextView min_label = (TextView) layout.findViewById(R.id.esm_min); min_label.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.LIKERT_MIN_LABEL))); TextView max_label = (TextView) layout.findViewById(R.id.esm_max); max_label.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.LIKERT_MAX_LABEL))); Button cancel = (Button) layout.findViewById(R.id.esm_cancel); cancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { current_dialog.cancel(); } }); Button submit = (Button) layout.findViewById(R.id.esm_submit); submit.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.SUBMIT))); submit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (expires_seconds > 0 && expire_monitor != null) expire_monitor.cancel(true); ContentValues rowData = new ContentValues(); rowData.put(ESM_Data.ANSWER_TIMESTAMP, System.currentTimeMillis()); rowData.put(ESM_Data.ANSWER, ratingBar.getRating()); rowData.put(ESM_Data.STATUS, ESM.STATUS_ANSWERED); sContext.getContentResolver().update(ESM_Data.CONTENT_URI, rowData, ESM_Data._ID + "=" + esm_id, null); Intent answer = new Intent(ESM.ACTION_AWARE_ESM_ANSWERED); getActivity().sendBroadcast(answer); if (Aware.DEBUG) Log.d(TAG, "Answer:" + rowData.toString()); current_dialog.dismiss(); } }); break; case ESM.TYPE_ESM_QUICK_ANSWERS: try { final JSONArray answers = new JSONArray( visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.QUICK_ANSWERS))); final LinearLayout answersHolder = (LinearLayout) layout.findViewById(R.id.esm_answers); //If we have more than 3 possibilities, better that the UI is vertical for UX if (answers.length() > 3) { answersHolder.setOrientation(LinearLayout.VERTICAL); } for (int i = 0; i < answers.length(); i++) { final Button answer = new Button(getActivity()); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 1.0f); answer.setLayoutParams(params); answer.setText(answers.getString(i)); answer.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (expires_seconds > 0 && expire_monitor != null) expire_monitor.cancel(true); ContentValues rowData = new ContentValues(); rowData.put(ESM_Data.ANSWER_TIMESTAMP, System.currentTimeMillis()); rowData.put(ESM_Data.STATUS, ESM.STATUS_ANSWERED); rowData.put(ESM_Data.ANSWER, (String) answer.getText()); sContext.getContentResolver().update(ESM_Data.CONTENT_URI, rowData, ESM_Data._ID + "=" + esm_id, null); Intent answer = new Intent(ESM.ACTION_AWARE_ESM_ANSWERED); getActivity().sendBroadcast(answer); if (Aware.DEBUG) Log.d(TAG, "Answer:" + rowData.toString()); current_dialog.dismiss(); } }); answersHolder.addView(answer); } } catch (JSONException e) { e.printStackTrace(); } break; } } if (visible_esm != null && !visible_esm.isClosed()) visible_esm.close(); //Start dialog visibility threshold if (expires_seconds > 0) { expire_monitor = new ESMExpireMonitor(System.currentTimeMillis(), expires_seconds, esm_id); expire_monitor.execute(); } //Fixed: doesn't dismiss the dialog if touched outside or ghost touches current_dialog.setCanceledOnTouchOutside(false); return current_dialog; }
From source file:com.polyvi.xface.extension.inappbrowser.XInAppBrowser.java
/** * /*from ww w .j a v a2 s . c om*/ * @param id * @param layoutParams ? * @param isSingleLine ?? * @param text * @param inputType * @param imeOption ime * @param listener ? * @return */ protected EditText createEditText(int id, RelativeLayout.LayoutParams layoutParams, boolean isSingleLine, String text, int inputType, int imeOption, View.OnKeyListener listener) { EditText editText = new EditText(mContext); editText.setLayoutParams(layoutParams); editText.setId(id); editText.setSingleLine(true); editText.setText(text); editText.setInputType(inputType); editText.setImeOptions(imeOption); editText.setOnKeyListener(listener); return editText; }
From source file:com.phonegap.childBrowser.ChildBrowser.java
/** * Display a new browser with the specified URL. * * @param url The url to load. * @param jsonObject /* ww w. j a va 2 s.c om*/ */ public String showWebPage(final String url, JSONObject options) { // Determine if we should hide the location bar. if (options != null) { showLocationBar = options.optBoolean("showLocationBar", true); } // Create dialog in new thread Runnable runnable = new Runnable() { public void run() { dialog = new Dialog(ctx); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCancelable(true); dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { public void onDismiss(DialogInterface dialog) { try { JSONObject obj = new JSONObject(); obj.put("type", CLOSE_EVENT); sendUpdate(obj, false); } catch (JSONException e) { Log.d(LOG_TAG, "Should never happen"); } } }); LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams forwardParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams editParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1.0f); LinearLayout.LayoutParams closeParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams wvParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); LinearLayout main = new LinearLayout(ctx); main.setOrientation(LinearLayout.VERTICAL); LinearLayout toolbar = new LinearLayout(ctx); toolbar.setOrientation(LinearLayout.HORIZONTAL); ImageButton back = new ImageButton(ctx); back.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goBack(); } }); back.setId(1); try { back.setImageBitmap(loadDrawable("www/childbrowser/icon_arrow_left.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } back.setLayoutParams(backParams); ImageButton forward = new ImageButton(ctx); forward.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goForward(); } }); forward.setId(2); try { forward.setImageBitmap(loadDrawable("www/childbrowser/icon_arrow_right.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } forward.setLayoutParams(forwardParams); edittext = new EditText(ctx); edittext.setOnKeyListener(new View.OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" button if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { navigate(edittext.getText().toString()); return true; } return false; } }); edittext.setId(3); edittext.setSingleLine(true); edittext.setText(url); edittext.setLayoutParams(editParams); ImageButton close = new ImageButton(ctx); close.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { closeDialog(); } }); close.setId(4); try { close.setImageBitmap(loadDrawable("www/childbrowser/icon_close.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } close.setLayoutParams(closeParams); webview = new WebView(ctx); webview.getSettings().setJavaScriptEnabled(true); webview.getSettings().setBuiltInZoomControls(true); WebViewClient client = new ChildBrowserClient(ctx, edittext); webview.setWebViewClient(client); webview.loadUrl(url); webview.setId(5); webview.setInitialScale(0); webview.setLayoutParams(wvParams); webview.requestFocus(); webview.requestFocusFromTouch(); toolbar.addView(back); toolbar.addView(forward); toolbar.addView(edittext); toolbar.addView(close); if (getShowLocationBar()) { main.addView(toolbar); } main.addView(webview); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(dialog.getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.FILL_PARENT; lp.height = WindowManager.LayoutParams.FILL_PARENT; dialog.setContentView(main); dialog.show(); dialog.getWindow().setAttributes(lp); } private Bitmap loadDrawable(String filename) throws java.io.IOException { InputStream input = ctx.getAssets().open(filename); return BitmapFactory.decodeStream(input); } }; this.ctx.runOnUiThread(runnable); return ""; }
From source file:gc.david.dfm.ui.activity.ShowInfoActivity.java
private void saveDataToDB(final String defaultText) { wasSavingWhenOrientationChanged = true; final AlertDialog.Builder builder = new AlertDialog.Builder(ShowInfoActivity.this); etAlias = new EditText(appContext); etAlias.setTextColor(Color.BLACK); etAlias.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES); etAlias.setText(defaultText);/*from www . j av a2 s . c o m*/ builder.setMessage(getString(R.string.alias_dialog_message)) .setTitle(getString(R.string.alias_dialog_title)).setView(etAlias) .setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { wasSavingWhenOrientationChanged = false; } }).setPositiveButton(getString(R.string.alias_dialog_accept), new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { showInfoPresenter.saveDistance(etAlias.getText().toString(), distance, positionsList); wasSavingWhenOrientationChanged = false; } }); (savingInDBDialog = builder.create()).show(); }
From source file:at.alladin.rmbt.android.about.RMBTAboutFragment.java
private void handleHiddenCode() { if (++developerFeatureCounter >= 10) { developerFeatureCounter = 0;//from w w w . j a v a 2 s .c o m final EditText input = new EditText(getActivity()); input.setInputType(InputType.TYPE_CLASS_NUMBER); final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setView(input); builder.setTitle(R.string.about_hidden_feature_dialog_title); builder.setMessage(R.string.about_hidden_feature_dialog_enter_code); builder.setPositiveButton(android.R.string.ok, new OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { try { final String data = input.getText().toString(); if (!data.matches("\\d{8}")) { Toast.makeText(getActivity(), R.string.about_hidden_feature_dialog_msg_try_again, Toast.LENGTH_LONG).show(); return; } final int dataInt = Integer.parseInt(data); if (dataInt == 0) // deactivate all features { ConfigHelper.setUserLoopModeState(getActivity(), false); ConfigHelper.setDevModeState(getActivity(), false); ConfigHelper.setServerSelectionState(getActivity(), false); ((RMBTMainActivity) getActivity()).checkSettings(true, null); // refresh server list Toast.makeText(getActivity(), R.string.about_hidden_feature_dialog_msg_deactivated, Toast.LENGTH_LONG).show(); return; } if (ConfigHelper.isValidCheckSum(dataInt)) { // developer mode if (dataInt == AppConstants.DEVELOPER_UNLOCK_CODE) { ConfigHelper.setDevModeState(getActivity(), true); Toast.makeText(getActivity(), R.string.about_dev_mode_activated, Toast.LENGTH_LONG) .show(); } else if (dataInt == AppConstants.DEVELOPER_LOCK_CODE) { ConfigHelper.setDevModeState(getActivity(), false); Toast.makeText(getActivity(), R.string.about_dev_mode_deactivated, Toast.LENGTH_LONG).show(); } // loop mode else if (dataInt == AppConstants.LOOP_MODE_UNLOCK_CODE) { ConfigHelper.setUserLoopModeState(getActivity(), true); Toast.makeText(getActivity(), R.string.about_loop_mode_activated, Toast.LENGTH_LONG) .show(); } else if (dataInt == AppConstants.LOOP_MODE_LOCK_CODE) { ConfigHelper.setUserLoopModeState(getActivity(), false); Toast.makeText(getActivity(), R.string.about_loop_mode_deactivated, Toast.LENGTH_LONG).show(); } // server selection else if (dataInt == AppConstants.SERVER_SELECTION_UNLOCK_CODE) { ConfigHelper.setServerSelectionState(getActivity(), true); ((RMBTMainActivity) getActivity()).checkSettings(true, null); // refresh server list Toast.makeText(getActivity(), R.string.about_server_selection_activated, Toast.LENGTH_LONG).show(); } else if (dataInt == AppConstants.SERVER_SELECTION_LOCK_CODE) { ConfigHelper.setServerSelectionState(getActivity(), false); ((RMBTMainActivity) getActivity()).checkSettings(true, null); // refresh server list Toast.makeText(getActivity(), R.string.about_server_selection_deactivated, Toast.LENGTH_LONG).show(); } // code not used else { Toast.makeText(getActivity(), R.string.about_hidden_feature_dialog_msg_try_again, Toast.LENGTH_LONG).show(); } } else Toast.makeText(getActivity(), R.string.about_hidden_feature_dialog_msg_try_again, Toast.LENGTH_LONG).show(); } catch (Exception e) // ignore errors { e.printStackTrace(); } } }); builder.setNegativeButton(android.R.string.cancel, null); dialog = builder.create(); dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); dialog.show(); } }
From source file:com.HumanDecisionSupportSystemsLaboratory.DD_P2P.OrgProfile.java
@Override protected void onCreate(Bundle arg0) { super.onCreate(arg0); Intent i = this.getIntent(); Bundle b = i.getExtras();/*w w w . jav a2 s .co m*/ __keys = new CipherSuit[3]; __keys[KEY_IDX_ECDSA_BIG] = newCipherSuit(Cipher.ECDSA, Cipher.SHA384, ECDSA.P_521); __keys[KEY_IDX_ECDSA] = newCipherSuit(Cipher.ECDSA, Cipher.SHA1, ECDSA.P_256); __keys[KEY_IDX_RSA] = newCipherSuit(Cipher.RSA, Cipher.SHA512, 1024); // top panel setting organization_position = b.getInt(Orgs.O_ID); organization_LID = b.getString(Orgs.O_LID); organization_GIDH = b.getString(Orgs.O_GIDH); oLID = Util.lval(organization_LID, -1); if (oLID <= 0) return; this.org = D_Organization.getOrgByLID(oLID, true, false); if (org == null) return; try { Identity crt_identity = Identity.getCurrentConstituentIdentity(); if (crt_identity == null) { Log.d(TAG, "No identity"); } else constituent_LID = net.ddp2p.common.config.Identity.getDefaultConstituentIDForOrg(oLID); } catch (P2PDDSQLException e1) { e1.printStackTrace(); } if (constituent_LID > 0) { constituent = D_Constituent.getConstByLID(constituent_LID, true, false); Log.d(TAG, "Got const: " + constituent); } setContentView(R.layout.org_profile); forename = (EditText) findViewById(R.id.profile_furname); surname = (EditText) findViewById(R.id.profile_surname); neiborhood = (Button) findViewById(R.id.profile_neiborhood); submit = (Button) findViewById(R.id.submit_profile); submit_new = (Button) findViewById(R.id.submit_profile_new); if (constituent == null) submit.setVisibility(Button.GONE); else submit.setVisibility(Button.VISIBLE); keys = (Spinner) findViewById(R.id.profile_keys); hasRightToVote = (CheckedTextView) findViewById(R.id.profile_hasRightToVote); email = (EditText) findViewById(R.id.profile_email); slogan = (EditText) findViewById(R.id.profile_slogan); slogan.setActivated(false); profilePic = (TextView) findViewById(R.id.profile_picture); profilePicImg = (ImageView) findViewById(R.id.profile_picture_img); // eligibility = (Spinner) findViewById(R.id.profile_eligibility); if (constituent != null) { forename.setText(constituent.getForename()); surname.setText(constituent.getSurname()); hasRightToVote.setChecked(Util.ival(constituent.getWeight(), 0) > 0); email.setText(constituent.getEmail()); slogan.setText(constituent.getSlogan()); } custom_fields = (LinearLayout) findViewById(R.id.profile_view); custom_index = 8; // custom_fields = (LinearLayout) findViewById(R.id.profile_custom); // custom_index = 0; custom_params = org.params.orgParam; if (custom_params == null || custom_params.length == 0) { custom_params = new D_OrgParam[0];// 3 /* * custom_params[0] = new D_OrgParam(); custom_params[0].label = * "School"; custom_params[0].entry_size = 5; custom_params[1] = new * D_OrgParam(); custom_params[1].label = "Street"; custom_params[2] * = new D_OrgParam(); custom_params[2].label = "Year"; * custom_params[2].list_of_values = new * String[]{"2010","2011","2012"}; */ } D_FieldValue[] field_values = null; if (constituent != null && constituent.address != null) field_values = constituent.address; for (int crt_field = 0; crt_field < custom_params.length; crt_field++) { D_OrgParam field = custom_params[crt_field]; LinearLayout custom_entry = new LinearLayout(this); custom_entry.setOrientation(LinearLayout.HORIZONTAL); custom_entry.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); TextView custom_label = new TextView(this); custom_label.setText(field.label); custom_entry.addView(custom_label); if (field.list_of_values != null && field.list_of_values.length > 0) { Log.d(TAG, "spinner:" + field); Spinner custom_spin = new Spinner(this); ArrayAdapter<String> custom_spin_Adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, field.list_of_values); custom_spin_Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); custom_spin.setAdapter(custom_spin_Adapter); custom_entry.addView(custom_spin); D_FieldValue fv = locateFV(field_values, field); if (fv != null) { int position = 0; for (int k = 0; k <= field.list_of_values.length; k++) { if (Util.equalStrings_null_or_not(field.list_of_values[k], fv.value)) { position = k; break; } } custom_spin.setSelection(position); } } else { Log.d(TAG, "edit: " + field); EditText edit_text = new EditText(this); edit_text.setText(field.default_value); edit_text.setInputType(InputType.TYPE_CLASS_TEXT); if (field.entry_size > 0) edit_text.setMinimumWidth(field.entry_size * 60); Log.d(TAG, "edit: size=" + field.entry_size); custom_entry.addView(edit_text); // Button child = new Button(this); // child.setText("Test"); D_FieldValue fv = locateFV(field_values, field); if (fv != null) edit_text.setText(fv.value); } custom_fields.addView(custom_entry, custom_index++); } ArrayAdapter<String> keysAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, m); keysAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); keys.setAdapter(keysAdapter); keys.setOnItemSelectedListener(new KeysListener()); if (constituent != null) { SK sk = constituent.getSK(); if (sk != null) { Cipher cipher = Cipher.getCipher(sk, null); if (cipher instanceof net.ddp2p.ciphersuits.RSA) { keys.setSelection(KEY_IDX_RSA, true); } if (cipher instanceof net.ddp2p.ciphersuits.ECDSA) { ECDSA ecdsa = (ECDSA) cipher; CipherSuit e = ECDSA.getCipherSuite(ecdsa.getPK()); if (e.hash_alg == Cipher.SHA1) { keys.setSelection(KEY_IDX_ECDSA, true); } else { keys.setSelection(KEY_IDX_ECDSA_BIG, true); } } } } ArrayAdapter<String> eligibilityAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, m); eligibilityAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // eligibility.setAdapter(eligibilityAdapter); // eligibility.setOnItemSelectedListener(new EligibilityListener()); hasRightToVote.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { hasRightToVote.setChecked(!hasRightToVote.isChecked()); } }); setProfilePhoto = (ImageView) findViewById(R.id.org_profile_set_profile_photo); /*TODO this part only make the whole stuff slow if (constituent_LID > 0) { constituent = D_Constituent.getConstByLID(constituent_LID, true, true); Log.d(TAG, "Got const: " + constituent); } */ /* boolean gotIcon = false; if (constituent != null) { if (constituent.getPicture() != null) { byte[] icon = constituent.getPicture(); Bitmap bmp = BitmapFactory.decodeByteArray(icon, 0, icon.length - 1); setProfilePhoto.setImageBitmap(bmp); gotIcon = true; } if (!gotIcon) { int imgPath = R.drawable.constitutent_person_icon; Bitmap bmp = BitmapFactory.decodeResource(getResources(), imgPath); setProfilePhoto.setImageBitmap(bmp); } } else { int imgPath = R.drawable.constitutent_person_icon; Bitmap bmp = BitmapFactory.decodeResource(getResources(), imgPath); setProfilePhoto.setImageBitmap(bmp); } setProfilePhoto.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (Build.VERSION.SDK_INT < 19) { Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(intent, SELECT_PROFILE_PHOTO); } else { Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); intent.setType("image/*"); startActivityForResult(intent, SELECT_PPROFILE_PHOTO_KITKAT); } } });*/ submit.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String _forename = forename.getText().toString(); String _surname = surname.getText().toString(); int _keys = OrgProfile._selectedKey; boolean rightToVote = hasRightToVote.isChecked(); String _weight = rightToVote ? "1" : "0"; String _email = email.getText().toString(); String _slogan = slogan.getText().toString(); boolean external = false; if (constituent == null) { D_Constituent new_const = D_Constituent.createConstituent(_forename, _surname, _email, oLID, external, _weight, _slogan, OrgProfile.__keys[_keys].cipher, OrgProfile.__keys[_keys].hash_alg, OrgProfile.__keys[_keys].ciphersize, null, null); Log.d(TAG, "saved constituent=" + new_const.getNameFull()); try { // Identity.DEBUG = true; Identity.setCurrentConstituentForOrg(new_const.getLID(), oLID); } catch (P2PDDSQLException e) { e.printStackTrace(); } Log.d(TAG, "saved new constituent=" + new_const); constituent = new_const; } else { constituent = D_Constituent.getConstByConst_Keep(constituent); constituent.setEmail(_email); constituent.setForename(_forename); constituent.setSurname(_surname); constituent.setWeight(rightToVote); constituent.setSlogan(_slogan); constituent.setExternal(false); constituent.setCreationDate(); constituent.sign(); if (constituent.dirty_any()) constituent.storeRequest(); constituent.releaseReference(); Log.d(TAG, "saved constituent=" + constituent); try { // Identity.DEBUG = true; Identity.setCurrentConstituentForOrg(constituent.getLID(), oLID); } catch (P2PDDSQLException e) { e.printStackTrace(); } Log.d(TAG, "saved constituent=" + constituent.getLID() + " oLID=" + oLID); } if (constituent != null) { constituent = D_Constituent.getConstByConst_Keep(constituent); if (constituent != null) { if (constituent.getSK() != null) { constituent.setPicture(byteIcon); constituent.setCreationDate(); constituent.sign(); constituent.storeRequest(); constituent.releaseReference(); Log.d(TAG, "saved constituent pic: " + constituent.getPicture()); } } } if (!org.getBroadcasted()) { D_Organization _org = D_Organization.getOrgByOrg_Keep(org); if (_org != null) { _org.setBroadcasting(true); if (_org.dirty_any()) _org.storeRequest(); _org.releaseReference(); org = _org; } } Log.d(TAG, "saved constituent pic: " + constituent.getPicture()); Log.d(TAG, "saved constituent Done"); finish(); } }); submit_new.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String _forename = forename.getText().toString(); String _surname = surname.getText().toString(); int _keys = OrgProfile._selectedKey; boolean rightToVote = hasRightToVote.isChecked(); String _weight = rightToVote ? "1" : "0"; String _email = email.getText().toString(); String _slogan = slogan.getText().toString(); boolean external = false; D_Constituent new_const = D_Constituent.createConstituent(_forename, _surname, _email, oLID, external, _weight, _slogan, OrgProfile.__keys[_keys].cipher, OrgProfile.__keys[_keys].hash_alg, OrgProfile.__keys[_keys].ciphersize, null, null); Log.d(TAG, "saved constituent=" + new_const.getNameFull()); try { // Identity.DEBUG = true; Identity.setCurrentConstituentForOrg(new_const.getLID(), oLID); Log.d("CONST", "No Set: oLID=" + oLID + " c=" + new_const.getLID()); } catch (P2PDDSQLException e) { e.printStackTrace(); } constituent = new_const; constituent_LID = new_const.getLID(); if (constituent_LID > 0) { constituent = D_Constituent.getConstByLID(constituent_LID, true, true); Log.d(TAG, "Got const: " + constituent); } if (constituent != null) { if (constituent.getSK() != null) { constituent.setPicture(byteIcon); constituent.setCreationDate(); constituent.sign(); constituent.storeRequest(); constituent.releaseReference(); Log.d(TAG, "saved constituent pic: " + constituent.getPicture()); } } if (!org.getBroadcasted()) { D_Organization _org = D_Organization.getOrgByOrg_Keep(org); if (_org != null) { _org.setBroadcasting(true); if (_org.dirty_any()) _org.storeRequest(); _org.releaseReference(); org = _org; } } Log.d(TAG, "saved constituent=" + new_const); finish(); } }); }
From source file:butter.droid.activities.MainActivity.java
private void openPlayerTestDialog() { AlertDialog.Builder builder = new AlertDialog.Builder(this); final String[] file_types = getResources().getStringArray(R.array.file_types); final String[] files = getResources().getStringArray(R.array.files); builder.setTitle("Player Tests").setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override/*www.j a va 2s . c o m*/ public void onClick(DialogInterface dialogInterface, int i) { dialogInterface.dismiss(); } }).setSingleChoiceItems(file_types, -1, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int index) { dialogInterface.dismiss(); final String location = files[index]; if (location.equals("dialog")) { final EditText dialogInput = new EditText(MainActivity.this); dialogInput.setText( "http://download.wavetlan.com/SVV/Media/HTTP/MP4/ConvertedFiles/QuickTime/QuickTime_test13_5m19s_AVC_VBR_324kbps_640x480_25fps_AAC-LCv4_CBR_93.4kbps_Stereo_44100Hz.mp4"); AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this).setView(dialogInput) .setPositiveButton("Start", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Movie media = new Movie(new MoviesProvider(), new YSubsProvider()); media.videoId = "dialogtestvideo"; media.title = "User input test video"; String location = dialogInput.getText().toString(); BeamManager bm = BeamManager.getInstance(MainActivity.this); if (bm.isConnected()) { BeamPlayerActivity.startActivity(MainActivity.this, new StreamInfo(media, null, null, null, null, location), 0); } else { VideoPlayerActivity.startActivity(MainActivity.this, new StreamInfo(media, null, null, null, null, location), 0); } } }); builder.show(); } else if (YouTubeData.isYouTubeUrl(location)) { Intent i = new Intent(MainActivity.this, TrailerPlayerActivity.class); Movie media = new Movie(new MoviesProvider(), new YSubsProvider()); media.title = file_types[index]; i.putExtra(TrailerPlayerActivity.DATA, media); i.putExtra(TrailerPlayerActivity.LOCATION, location); startActivity(i); } else { final Movie media = new Movie(new MoviesProvider(), new YSubsProvider()); media.videoId = "bigbucksbunny"; media.title = file_types[index]; media.subtitles = new HashMap<>(); media.subtitles.put("en", "http://sv244.cf/bbb-subs.srt"); SubsProvider.download(MainActivity.this, media, "en", new Callback() { @Override public void onFailure(Request request, IOException e) { BeamManager bm = BeamManager.getInstance(MainActivity.this); if (bm.isConnected()) { BeamPlayerActivity.startActivity(MainActivity.this, new StreamInfo(media, null, null, null, null, location), 0); } else { VideoPlayerActivity.startActivity(MainActivity.this, new StreamInfo(media, null, null, null, null, location), 0); } } @Override public void onResponse(Response response) throws IOException { BeamManager bm = BeamManager.getInstance(MainActivity.this); if (bm.isConnected()) { BeamPlayerActivity.startActivity(MainActivity.this, new StreamInfo(media, null, null, "en", null, location), 0); } else { VideoPlayerActivity.startActivity(MainActivity.this, new StreamInfo(media, null, null, "en", null, location), 0); } } }); } } }); builder.show(); }
From source file:com.examples.abelanav2.ui.PicturesFragment.java
@Override public void onPhotoCardClick(View v, final int position) { ((PhotoAdapter) mRecyclerView.getAdapter()).setPosition(position); switch (v.getId()) { case R.id.imageButtonThumbsUp: int vote = 1; CardView card = (CardView) v.getParent().getParent(); card.findViewById(R.id.imageButtonThumbsDown).setSelected(false); if (card.findViewById(R.id.imageButtonThumbsUp).isSelected()) { vote = 0;// www .j av a2 s . com card.findViewById(R.id.imageButtonThumbsUp).setSelected(false); } else { card.findViewById(R.id.imageButtonThumbsUp).setSelected(true); } new VoteTask().execute(vote); break; case R.id.imageButtonThumbsDown: vote = -1; card = (CardView) v.getParent().getParent(); card.findViewById(R.id.imageButtonThumbsUp).setSelected(false); if (card.findViewById(R.id.imageButtonThumbsDown).isSelected()) { vote = 0; card.findViewById(R.id.imageButtonThumbsDown).setSelected(false); } else { card.findViewById(R.id.imageButtonThumbsDown).setSelected(true); } new VoteTask().execute(vote); break; case R.id.imageButtonWallpaper: new AlertDialog.Builder(getActivity()).setTitle(getString(R.string.photo_list_wallpaper_title)) .setMessage(getString(R.string.photo_list_wallpaper_message)) .setPositiveButton(R.string.set_wallpaper, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { new WallpaperTask().execute(); } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // do nothing } }).setIcon(R.drawable.ic_wallpaper).show(); break; case R.id.imageButtonEdit: final EditText editText = new EditText(getActivity().getApplicationContext()); editText.setText(mPhotoAdapter.getPhotoList().get(position).description); editText.setTextColor(getResources().getColor(android.R.color.black)); new AlertDialog.Builder(getActivity()).setTitle(getString(R.string.photo_list_edit_photo_title)) .setMessage(getString(R.string.photo_list_edit_photo_message)).setView(editText) .setPositiveButton(R.string.edit, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { new EditTask().execute(editText.getText().toString()); } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // do nothing } }).setIcon(R.drawable.ic_edit).show(); break; case R.id.imageButtonDelete: new AlertDialog.Builder(getActivity()).setTitle(getString(R.string.photo_list_delete_photo_title)) .setMessage(getString(R.string.photo_list_delete_photo_message)) .setPositiveButton(R.string.delete, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { new DeleteTask().execute(); } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // do nothing } }).setIcon(R.drawable.ic_delete).show(); break; default: break; } }