List of usage examples for android.app Activity getLayoutInflater
@NonNull
public LayoutInflater getLayoutInflater()
From source file:org.sufficientlysecure.keychain.ui.dialog.AddEmailDialogFragment.java
/** * Creates dialog//from w w w. j av a2 s . c om */ @Override public Dialog onCreateDialog(Bundle savedInstanceState) { final Activity activity = getActivity(); mMessenger = getArguments().getParcelable(ARG_MESSENGER); CustomAlertDialogBuilder alert = new CustomAlertDialogBuilder(activity); alert.setTitle(R.string.create_key_add_email); LayoutInflater inflater = activity.getLayoutInflater(); View view = inflater.inflate(R.layout.add_email_dialog, null); alert.setView(view); mEmail = (EmailEditText) view.findViewById(R.id.add_email_address); alert.setPositiveButton(android.R.string.ok, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { dismiss(); // return new user id back to activity Bundle data = new Bundle(); String email = mEmail.getText().toString(); data.putString(MESSAGE_DATA_EMAIL, email); sendMessageToHandler(MESSAGE_OKAY, data); } }); alert.setNegativeButton(android.R.string.cancel, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); // Hack to open keyboard. // This is the only method that I found to work across all Android versions // http://turbomanage.wordpress.com/2012/05/02/show-soft-keyboard-automatically-when-edittext-receives-focus/ // Notes: * onCreateView can't be used because we want to add buttons to the dialog // * opening in onActivityCreated does not work on Android 4.4 mEmail.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { mEmail.post(new Runnable() { @Override public void run() { if (getActivity() != null) { InputMethodManager imm = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(mEmail, InputMethodManager.SHOW_IMPLICIT); } } }); } }); mEmail.requestFocus(); mEmail.setImeActionLabel(getString(android.R.string.ok), EditorInfo.IME_ACTION_DONE); mEmail.setOnEditorActionListener(this); return alert.show(); }
From source file:com.forrestguice.suntimeswidget.AlarmDialog.java
/** * @param savedInstanceState a Bundle containing dialog state * @return an AlarmDialog ready to be shown */// ww w . j a va 2s . c o m @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final Activity myParent = getActivity(); LayoutInflater inflater = myParent.getLayoutInflater(); @SuppressLint("InflateParams") View dialogContent = inflater.inflate(R.layout.layout_dialog_schedalarm, null); Resources r = getResources(); int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 16, r.getDisplayMetrics()); AlertDialog.Builder builder = new AlertDialog.Builder(myParent); builder.setView(dialogContent, 0, padding, 0, 0); builder.setTitle(myParent.getString(R.string.schedalarm_dialog_title)); AlertDialog dialog = builder.create(); dialog.setCanceledOnTouchOutside(false); dialog.setButton(AlertDialog.BUTTON_NEGATIVE, myParent.getString(R.string.schedalarm_dialog_cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); if (onCanceled != null) { onCanceled.onClick(dialog, which); } } }); dialog.setButton(AlertDialog.BUTTON_POSITIVE, myParent.getString(R.string.schedalarm_dialog_ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { saveSettings(myParent); dialog.dismiss(); if (onAccepted != null) { onAccepted.onClick(dialog, which); } } }); initViews(myParent, dialogContent); if (savedInstanceState != null) { //Log.d("DEBUG", "AlarmDialog onCreate (restoreState)"); loadSettings(savedInstanceState); } else { //Log.d("DEBUG", "AlarmDialog onCreate (newState)"); loadSettings(myParent); } return dialog; }
From source file:com.github.mobile.ui.gist.GistFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); list = finder.find(android.R.id.list); progress = finder.find(id.pb_loading); Activity activity = getActivity(); adapter = new HeaderFooterListAdapter<CommentListAdapter>(list, new CommentListAdapter(activity.getLayoutInflater(), avatars, imageGetter)); list.setAdapter(adapter);//from www . j ava2s . c om }
From source file:droidack.ADialogFragment.java
@NonNull @Override/*from ww w . j a va 2s. co m*/ public Dialog onCreateDialog(Bundle inBundle) { Activity activity = getActivity(); if (mContentLayoutId == 0) { // Not using the AlertDialog setStyle(STYLE_NO_FRAME, 0); mDialog = new Dialog(activity, android.R.style.Theme_Holo_Dialog_NoActionBar); return mDialog; } LayoutInflater inflater = activity.getLayoutInflater(); View mContentView = inflater.inflate(mContentLayoutId, null); AlertDialog.Builder builder = new AlertDialog.Builder(activity); builder.setView(mContentView); if (mTitleTextId != 0) builder.setTitle(mTitleTextId); if (mNegativeTextId != 0) builder.setNegativeButton(mNegativeTextId, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { mDialog.cancel(); } }); if (mNeutralTextId != 0) builder.setNeutralButton(mNeutralTextId, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { getDialogRootModule().onNeutralClick(); } }); if (mPositiveTextId == 0) logAndThrowError("No positiveTextId provided!"); builder.setPositiveButton(mPositiveTextId, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { getDialogRootModule().onPositiveClick(); } }); mDialog = builder.create(); return mDialog; }
From source file:org.sufficientlysecure.keychain.ui.dialog.SetPassphraseDialogFragment.java
/** * Creates dialog/*from www . j a v a 2 s .c o m*/ */ @Override public Dialog onCreateDialog(Bundle savedInstanceState) { final Activity activity = getActivity(); int title = getArguments().getInt(ARG_TITLE); mMessenger = getArguments().getParcelable(ARG_MESSENGER); AlertDialog.Builder alert = new AlertDialog.Builder(activity); alert.setTitle(title); alert.setMessage(R.string.enterPassPhraseTwice); LayoutInflater inflater = activity.getLayoutInflater(); View view = inflater.inflate(R.layout.passphrase_repeat, null); alert.setView(view); mPassphraseEditText = (EditText) view.findViewById(R.id.passphrase_passphrase); mPassphraseAgainEditText = (EditText) view.findViewById(R.id.passphrase_passphrase_again); alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { dismiss(); String passPhrase1 = mPassphraseEditText.getText().toString(); String passPhrase2 = mPassphraseAgainEditText.getText().toString(); if (!passPhrase1.equals(passPhrase2)) { Toast.makeText(activity, getString(R.string.errorMessage, getString(R.string.passPhrasesDoNotMatch)), Toast.LENGTH_SHORT).show(); return; } if (passPhrase1.equals("")) { Toast.makeText(activity, getString(R.string.errorMessage, getString(R.string.passPhraseMustNotBeEmpty)), Toast.LENGTH_SHORT).show(); return; } // return resulting data back to activity Bundle data = new Bundle(); data.putString(MESSAGE_NEW_PASSPHRASE, passPhrase1); sendMessageToHandler(MESSAGE_OKAY, data); } }); alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { dismiss(); } }); return alert.create(); }
From source file:org.thialfihar.android.apg.ui.dialog.SetPassphraseDialogFragment.java
/** * Creates dialog//from w w w . j av a 2s. c o m */ @Override public Dialog onCreateDialog(Bundle savedInstanceState) { final Activity activity = getActivity(); int title = getArguments().getInt(ARG_TITLE); mMessenger = getArguments().getParcelable(ARG_MESSENGER); AlertDialog.Builder alert = new AlertDialog.Builder(activity); alert.setTitle(title); alert.setMessage(R.string.enter_passphrase_twice); LayoutInflater inflater = activity.getLayoutInflater(); View view = inflater.inflate(R.layout.passphrase_repeat_dialog, null); alert.setView(view); mPassphraseEditText = (EditText) view.findViewById(R.id.passphrase_passphrase); mPassphraseAgainEditText = (EditText) view.findViewById(R.id.passphrase_passphrase_again); alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { dismiss(); String passphrase1 = mPassphraseEditText.getText().toString(); String passphrase2 = mPassphraseAgainEditText.getText().toString(); if (!passphrase1.equals(passphrase2)) { Toast.makeText(activity, getString(R.string.error_message, getString(R.string.passphrases_do_not_match)), Toast.LENGTH_SHORT).show(); return; } if (passphrase1.equals("")) { Toast.makeText(activity, getString(R.string.error_message, getString(R.string.passphrase_must_not_be_empty)), Toast.LENGTH_SHORT).show(); return; } // return resulting data back to activity Bundle data = new Bundle(); data.putString(MESSAGE_NEW_PASSPHRASE, passphrase1); sendMessageToHandler(MESSAGE_OKAY, data); } }); alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { dismiss(); } }); return alert.create(); }
From source file:com.forrestguice.suntimeswidget.TimeZoneDialog.java
@NonNull @Override/* w ww .j a va 2s . c o m*/ public Dialog onCreateDialog(final Bundle savedInstanceState) { super.onCreateDialog(savedInstanceState); final Activity myParent = getActivity(); LayoutInflater inflater = myParent.getLayoutInflater(); @SuppressLint("InflateParams") View dialogContent = inflater.inflate(R.layout.layout_dialog_timezone, null); Resources r = getResources(); int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 16, r.getDisplayMetrics()); AlertDialog.Builder builder = new AlertDialog.Builder(myParent); builder.setView(dialogContent, 0, padding, 0, 0); builder.setTitle(myParent.getString(R.string.timezone_dialog_title)); AlertDialog dialog = builder.create(); dialog.setCanceledOnTouchOutside(false); dialog.setButton(AlertDialog.BUTTON_NEGATIVE, myParent.getString(R.string.timezone_dialog_cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); if (onCanceled != null) { onCanceled.onClick(dialog, which); } } }); dialog.setButton(AlertDialog.BUTTON_POSITIVE, myParent.getString(R.string.timezone_dialog_ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { saveSettings(myParent); dialog.dismiss(); if (onAccepted != null) { onAccepted.onClick(dialog, which); } } }); /**dialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialogInterface) {} });*/ /**dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialogInterface) {} });*/ initViews(myParent, dialogContent); WidgetTimezones.TimeZoneSort sortZonesBy = AppSettings.loadTimeZoneSortPref(myParent); WidgetTimezones.TimeZonesLoadTask loadTask = new WidgetTimezones.TimeZonesLoadTask(myParent) { @Override protected void onPreExecute() { super.onPreExecute(); spinner_timezone.setAdapter( new WidgetTimezones.TimeZoneItemAdapter(myParent, R.layout.layout_listitem_timezone)); } @Override protected void onPostExecute(WidgetTimezones.TimeZoneItemAdapter result) { super.onPostExecute(result); spinner_timezone_adapter = result; spinner_timezone.setAdapter(spinner_timezone_adapter); WidgetTimezones.selectTimeZone(spinner_timezone, spinner_timezone_adapter, customTimezoneID); } }; if (savedInstanceState != null) { // saved dialog state; restore it //Log.d("DEBUG", "TimeZoneDialog onCreate (restoreState)"); loadSettings(savedInstanceState); } else { // no saved dialog state; load from preferences //Log.d("DEBUG", "TimeZoneDialog onCreate (newState)"); loadSettings(myParent); } loadTask.execute(sortZonesBy); return dialog; }
From source file:id.nci.stm_9.SetPassphraseDialogFragment.java
/** * Creates dialog/*from www. j a va2 s . c om*/ */ @Override public Dialog onCreateDialog(Bundle savedInstanceState) { final Activity activity = getActivity(); int title = getArguments().getInt(ARG_TITLE); mMessenger = getArguments().getParcelable(ARG_MESSENGER); AlertDialog.Builder alert = new AlertDialog.Builder(activity); alert.setTitle(title); alert.setMessage(R.string.enter_passphrase_twice); LayoutInflater inflater = activity.getLayoutInflater(); View view = inflater.inflate(R.layout.passphrase_repeat, null); alert.setView(view); mPassphraseEditText = (EditText) view.findViewById(R.id.passphrase_passphrase); mPassphraseAgainEditText = (EditText) view.findViewById(R.id.passphrase_passphrase_again); alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { dismiss(); String passPhrase1 = mPassphraseEditText.getText().toString(); String passPhrase2 = mPassphraseAgainEditText.getText().toString(); if (!passPhrase1.equals(passPhrase2)) { Toast.makeText(activity, getString(R.string.error_message, getString(R.string.passphrases_do_not_match)), Toast.LENGTH_SHORT).show(); return; } if (passPhrase1.equals("")) { Toast.makeText(activity, getString(R.string.error_message, getString(R.string.passphrase_must_not_be_empty)), Toast.LENGTH_SHORT).show(); return; } // return resulting data back to activity Bundle data = new Bundle(); data.putString(MESSAGE_NEW_PASSPHRASE, passPhrase1); sendMessageToHandler(MESSAGE_OKAY, data); } }); alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { dismiss(); } }); return alert.create(); }
From source file:dynamite.zafroshops.app.fragment.OpeningsDialogFragment.java
@NonNull @Override//w w w. j a v a2 s.c o m public Dialog onCreateDialog(Bundle savedInstanceState) { data = (ArrayList<MobileOpeningHourData>) getArguments().get(NEW_ZOP_OPENINGS); tempData = new ArrayList(); for (int i = 0; i < data.size(); i++) { tempData.add(data.get(i).Copy()); } // set spinners ArrayAdapter<String> openingsDayAdapter; ArrayAdapter<String> openingsHoursAdapter; ArrayAdapter<String> openingsMinutesAdapter; Activity activity = getActivity(); AlertDialog.Builder builder = new AlertDialog.Builder(activity); final LayoutInflater inflater = activity.getLayoutInflater(); View view = inflater.inflate(R.layout.openings_dialog, null); builder.setView(view).setTitle(R.string.openings_editing) .setPositiveButton(R.string.button_submit, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { data.clear(); for (int i = 0; i < tempData.size(); i++) { data.add(tempData.get(i).Copy()); } Intent intent = new Intent(); intent.putExtra(NEW_ZOP_OPENINGS_COUNT_KEY, OpeningsDialogFragment.this.data.size()); getTargetFragment().onActivityResult(getTargetRequestCode(), NEW_ZOP_OPENINGS_RESULT_CODE, intent); } }).setNegativeButton(R.string.button_cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); final Spinner ohd = (Spinner) view.findViewById(R.id.openingsDay); final Spinner ohsh = (Spinner) view.findViewById(R.id.openingsStartHour); final Spinner ohsm = (Spinner) view.findViewById(R.id.openingsStartMinute); final Spinner oheh = (Spinner) view.findViewById(R.id.openingsEndHour); final Spinner ohem = (Spinner) view.findViewById(R.id.openingsEndMinute); if (days == null) { days = new ArrayList(); for (int i = 0; i < 7; i++) { try { days.add(getString(R.string.class.getField("day" + i).getInt(null))); } catch (IllegalAccessException ignored) { } catch (NoSuchFieldException e) { } } } if (hours == null) { hours = new ArrayList(); for (int i = 0; i < 24; i++) { hours.add(String.format("%02d", i)); } } if (minutes == null) { minutes = new ArrayList(); for (int i = 0; i < 4; i++) { minutes.add(String.format("%02d", i * 15)); } } openingsDayAdapter = new ArrayAdapter<>(activity, android.R.layout.simple_spinner_item, days); openingsDayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); ohd.setAdapter(openingsDayAdapter); openingsHoursAdapter = new ArrayAdapter<>(activity, android.R.layout.simple_spinner_item, hours); openingsHoursAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); ohsh.setAdapter(openingsHoursAdapter); oheh.setAdapter(openingsHoursAdapter); openingsMinutesAdapter = new ArrayAdapter<>(activity, android.R.layout.simple_spinner_item, minutes); openingsMinutesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); ohsm.setAdapter(openingsMinutesAdapter); ohem.setAdapter(openingsMinutesAdapter); // set current openings openingHoursContainer = (LinearLayout) view.findViewById(R.id.openingHours); openingHoursLabel = (TextView) view.findViewById(R.id.openingHoursLabel); openingHoursDeleteButton = (Button) view.findViewById(R.id.openingsHoursDelete); ZopItemFragment.setOpeningsList(tempData, openingHoursContainer, inflater, openingHoursLabel); // set buttons view.findViewById(R.id.openingsHoursAdd).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // get data final int position = ohd.getSelectedItemPosition(); MobileOpeningHourData item = null; try { item = Iterables.find(tempData, new Predicate<MobileOpeningHourData>() { @Override public boolean apply(MobileOpeningHourData input) { return input.Day == position; } }); } catch (NoSuchElementException ignored) { } // update data if (item == null) { item = new MobileOpeningHourData((byte) position); tempData.add(item); } final MobileOpeningHour moh = new MobileOpeningHour(); moh.StartTimeHour = (byte) ohsh.getSelectedItemPosition(); moh.StartTimeMinute = (byte) (ohsm.getSelectedItemPosition() * 15); moh.EndTimeHour = (byte) oheh.getSelectedItemPosition(); moh.EndTimeMinute = (byte) (ohem.getSelectedItemPosition() * 15); MobileOpeningHour temp = null; try { temp = Iterables.find(item.Hours, new Predicate<MobileOpeningHour>() { @Override public boolean apply(MobileOpeningHour input) { return input.compareTo(moh) == 0; } }); } catch (NoSuchElementException ignored) { } if (temp == null) { item.Hours.add(moh); } // sort data Collections.sort(item.Hours); Collections.sort(tempData); // update view ZopItemFragment.setOpeningsList(tempData, openingHoursContainer, inflater, openingHoursLabel); openingHoursDeleteButton.setEnabled(true); } }); openingHoursDeleteButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // get data final int position = ohd.getSelectedItemPosition(); MobileOpeningHourData item = null; try { item = Iterables.find(tempData, new Predicate<MobileOpeningHourData>() { @Override public boolean apply(MobileOpeningHourData input) { return input.Day == position; } }); } catch (NoSuchElementException ignored) { } // update data if (item != null) { tempData.remove(item); openingHoursDeleteButton.setEnabled(false); } // update view ZopItemFragment.setOpeningsList(tempData, openingHoursContainer, inflater, openingHoursLabel); } }); ohd.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, final int position, long id) { MobileOpeningHourData item = null; // get data try { item = Iterables.find(tempData, new Predicate<MobileOpeningHourData>() { @Override public boolean apply(MobileOpeningHourData input) { return input.Day == position; } }); } catch (NoSuchElementException ignored) { } // update view if (item != null) { openingHoursDeleteButton.setEnabled(true); } else { openingHoursDeleteButton.setEnabled(false); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); return builder.create(); }
From source file:com.todoroo.astrid.activity.FilterListFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Activity activity = getActivity(); int layout = getLayout(activity); ViewGroup parent = (ViewGroup) activity.getLayoutInflater().inflate(layout, container, false); return parent; }