List of usage examples for android.app Activity getLayoutInflater
@NonNull
public LayoutInflater getLayoutInflater()
From source file:com.mobicage.rogerthat.util.ui.UIUtils.java
public static boolean showHintWithImage(final Activity activity, final MainService mainService, final SafeRunnable onDismissHandler, final String hintCode, final FontAwesome.Icon hintIcon, final int hintResource, final Object... args) { final ConfigurationProvider configurationProvider = mainService.getConfigurationProvider(); final String configkey = "HINT_REPOSITORY"; final com.mobicage.rogerthat.config.Configuration config = configurationProvider .getConfiguration(configkey); if (config.get(hintCode, false)) return false; LayoutInflater inflater = activity.getLayoutInflater(); final View checkboxLayout = inflater.inflate(R.layout.hint, null); final TextView message = (TextView) checkboxLayout.findViewById(R.id.message); final CheckBox checkBox = (CheckBox) checkboxLayout.findViewById(R.id.checkBox); if (hintIcon != null) { final ImageView icon = (ImageView) checkboxLayout.findViewById(R.id.icon); icon.setImageDrawable(new IconicsDrawable(activity, hintIcon).color(Color.DKGRAY).sizeDp(30)); icon.setVisibility(View.VISIBLE); }/*from w w w. j a v a2 s.com*/ Resources resources = activity.getResources(); message.setText(resources.getString(hintResource, args)); AlertDialog dialog = new AlertDialog.Builder(activity) .setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (onDismissHandler != null) { onDismissHandler.run(); } } }).setTitle(R.string.activity_hint).setView(checkboxLayout).setPositiveButton( resources.getString(R.string.activity_close_hint), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (checkBox.isChecked()) { config.put(hintCode, true); configurationProvider.updateConfigurationNow(configkey, config); } if (onDismissHandler != null) { onDismissHandler.run(); } } }) .create(); dialog.show(); int buttonId = mainService.getResources().getIdentifier("android:id/button1", null, null); ((Button) dialog.findViewById(buttonId)).setTextColor(LookAndFeelConstants.getPrimaryColor(activity)); return true; }
From source file:org.sufficientlysecure.keychain.ui.dialog.AddUserIdDialogFragment.java
/** * Creates dialog//w w w .j a v a 2 s .c o m */ @Override public Dialog onCreateDialog(Bundle savedInstanceState) { final Activity activity = getActivity(); mMessenger = getArguments().getParcelable(ARG_MESSENGER); String predefinedName = getArguments().getString(ARG_NAME); CustomAlertDialogBuilder alert = new CustomAlertDialogBuilder(activity); alert.setTitle(R.string.edit_key_action_add_identity); LayoutInflater inflater = activity.getLayoutInflater(); View view = inflater.inflate(R.layout.add_user_id_dialog, null); alert.setView(view); mName = (NameEditText) view.findViewById(R.id.add_user_id_name); mEmail = (EmailEditText) view.findViewById(R.id.add_user_id_address); mName.setText(predefinedName); 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 userId = KeyRing.createUserId( new OpenPgpUtils.UserId(mName.getText().toString(), mEmail.getText().toString(), null)); data.putString(MESSAGE_DATA_USER_ID, userId); 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() { InputMethodManager imm = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(mEmail, InputMethodManager.SHOW_IMPLICIT); } }); } }); mEmail.requestFocus(); return alert.show(); }
From source file:org.sufficientlysecure.keychain.ui.dialog.AddKeyserverDialogFragment.java
/** * Creates dialog/*w w w . j av a 2 s . c o m*/ */ @Override public Dialog onCreateDialog(Bundle savedInstanceState) { final Activity activity = getActivity(); mMessenger = getArguments().getParcelable(ARG_MESSENGER); CustomAlertDialogBuilder alert = new CustomAlertDialogBuilder(activity); alert.setTitle(R.string.add_keyserver_dialog_title); LayoutInflater inflater = activity.getLayoutInflater(); View view = inflater.inflate(R.layout.add_keyserver_dialog, null); alert.setView(view); mKeyserverEditText = (EditText) view.findViewById(R.id.keyserver_url_edit_text); mVerifyKeyserverCheckBox = (CheckBox) view.findViewById(R.id.verify_keyserver_checkbox); // we don't want dialog to be dismissed on click, thereby requiring the hack seen below // and in onStart alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { // we need to have an empty listener to prevent errors on some devices as mentioned // at http://stackoverflow.com/q/13746412/3000919 // actual listener set in onStart } }); alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { dismiss(); } }); // 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 mKeyserverEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { mKeyserverEditText.post(new Runnable() { @Override public void run() { InputMethodManager imm = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(mKeyserverEditText, InputMethodManager.SHOW_IMPLICIT); } }); } }); mKeyserverEditText.requestFocus(); mKeyserverEditText.setImeActionLabel(getString(android.R.string.ok), EditorInfo.IME_ACTION_DONE); mKeyserverEditText.setOnEditorActionListener(this); return alert.show(); }
From source file:com.affectiva.affdexme.MetricSelectionFragment.java
/** * A method to populate the metricSelectors array using information from either a saved instance bundle (if the activity is being re-created) * or sharedPreferences (if the activity is being created for the first time) *///from w ww . j a v a 2s. c o m void restoreSettings(Bundle bundle) { sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity()); Activity hostActivity = getActivity(); LayoutInflater inflater = hostActivity.getLayoutInflater(); Resources res = getResources(); String packageName = hostActivity.getPackageName(); //populate metricSelectors list with objects for (MetricsManager.Metrics metric : MetricsManager.getAllMetrics()) { metricSelectors.put(metric, new MetricSelector(hostActivity, inflater, res, packageName, metric)); } if (bundle != null) { //if we were passed a bundle, use its data to configure the MetricSelectors for (MetricsManager.Metrics metric : MetricsManager.getAllMetrics()) { if (bundle.getBoolean(metric.toString(), false)) { selectItem(metricSelectors.get(metric), true, false); } } } else { //otherwise, we pull the data from application preferences for (int i = 0; i < NUM_METRICS_DISPLAYED; i++) { MetricsManager.Metrics chosenMetric = PreferencesUtils.getMetricFromPrefs(sharedPreferences, i); selectItem(metricSelectors.get(chosenMetric), true, false); } } }
From source file:com.github.pockethub.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(R.id.pb_loading); Activity activity = getActivity(); User user = gist.user;/* www . j av a 2 s . c o m*/ String userName = null; if (user != null) userName = user.login; adapter = new HeaderFooterListAdapter<>(list, new CommentListAdapter(activity.getLayoutInflater(), null, avatars, imageGetter, editCommentListener, deleteCommentListener, userName, false, null)); list.setAdapter(adapter); }
From source file:com.github.pockethub.android.ui.gist.GistFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); list = (ListView) view.findViewById(android.R.id.list); progress = (ProgressBar) view.findViewById(R.id.pb_loading); Activity activity = getActivity(); User user = gist.owner();/* www . jav a 2s .c o m*/ String userName = null; if (user != null) { userName = user.login(); } adapter = new HeaderFooterListAdapter<>(list, new CommentListAdapter(activity.getLayoutInflater(), null, avatars, imageGetter, editCommentListener, deleteCommentListener, userName, isOwner(), null)); list.setAdapter(adapter); }
From source file:cx.ring.fragments.AccountCreationFragment.java
private AlertDialog showImportDialog() { Activity ownerActivity = getActivity(); AlertDialog.Builder builder = new AlertDialog.Builder(ownerActivity); LayoutInflater inflater = ownerActivity.getLayoutInflater(); ViewGroup v = (ViewGroup) inflater.inflate(R.layout.dialog_account_import, null); final TextView pwd = (TextView) v.findViewById(R.id.pwd_txt); builder.setMessage(R.string.account_import_message).setTitle(R.string.account_import_account) .setPositiveButton(R.string.account_import_account, new DialogInterface.OnClickListener() { @Override// w w w . ja va 2 s. c o m public void onClick(DialogInterface dialog, int which) { if (!TextUtils.isEmpty(mDataPath)) { new ImportAccountTask().execute(mDataPath, pwd.getText().toString()); } } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int whichButton) { /* Terminate with no action */ } }).setView(v); final AlertDialog alertDialog = builder.create(); alertDialog.show(); return alertDialog; }
From source file:de.spiritcroc.ownlog.ui.fragment.LogFilterEditFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { final Activity activity = getActivity(); AlertDialog.Builder builder = new AlertDialog.Builder(activity); final View view = activity.getLayoutInflater().inflate(R.layout.log_filter_edit_item, null); mEditName = (EditText) view.findViewById(R.id.name_edit); mSpinSortOrder = (Spinner) view.findViewById(R.id.sort_order_spin); mCheckStrictFilterTags = (CheckBox) view.findViewById(R.id.tags_strict_check); mStrictFilterTagsInfoNoTags = view.findViewById(R.id.text_view_tags_strict_no_tags); mStrictFilterTagsInfoTags = view.findViewById(R.id.text_view_tags_strict_tags); mEditTagsView = (EditTagsView) view.findViewById(R.id.edit_tags_view); mEditTagsView.setTagsProvider(mTagsProvider); mEditTagsView.setAvailableTagsFilter(mAvailableTagsFilter); mEditExcludedTagsView = (EditTagsView) view.findViewById(R.id.edit_excluded_tags_view); mEditExcludedTagsView.setTagsProvider(mExcludedTagsProvider); mEditExcludedTagsView.setAvailableTagsFilter(mAvailableTagsFilter); View.OnClickListener strictFilterInfoClickListener = new View.OnClickListener() { @Override/*from w w w . ja va 2 s. c om*/ public void onClick(View view) { mCheckStrictFilterTags.toggle(); } }; mStrictFilterTagsInfoNoTags.setOnClickListener(strictFilterInfoClickListener); mStrictFilterTagsInfoTags.setOnClickListener(strictFilterInfoClickListener); mSortOrderValues = getResources().getStringArray(R.array.edit_log_filter_sort_order_values); mSpinSortOrder.setAdapter(ArrayAdapter.createFromResource(activity, R.array.edit_log_filter_sort_order_entries, R.layout.support_simple_spinner_dropdown_item)); mSpinSortOrder.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { mSortOrder = i; } @Override public void onNothingSelected(AdapterView<?> adapterView) { } }); mInitName = getString(R.string.log_filter_default_new_name); mInitSortOrder = mSortOrderValues[0]; boolean restoredValues = restoreValues(savedInstanceState); builder.setTitle(mAddItem ? R.string.title_log_filter_add : R.string.title_log_filter_edit).setView(view) .setPositiveButton(R.string.dialog_ok, null) .setNegativeButton(R.string.dialog_cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Only dismiss } }); if (!mAddItem) { builder.setNeutralButton(R.string.dialog_delete, null); } final AlertDialog alertDialog = builder.create(); alertDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialogInterface) { alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { saveChanges(); } }); if (!mAddItem) { alertDialog.getButton(DialogInterface.BUTTON_NEUTRAL) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { promptDelete(); } }); } } }); if (!restoredValues) { loadContent(); if (mAddItem) { initValues(alertDialog); } } return alertDialog; }
From source file:com.janela.mobile.ui.gist.GistFragment.java
private void updateFiles(Gist gist) { final Activity activity = getActivity(); if (activity == null) return;//from www .j av a 2s . co m for (View header : fileHeaders) adapter.removeHeader(header); fileHeaders.clear(); Map<String, GistFile> files = gist.getFiles(); if (files == null || files.isEmpty()) return; final LayoutInflater inflater = activity.getLayoutInflater(); final Typeface octicons = TypefaceUtils.getOcticons(activity); for (GistFile file : files.values()) { View fileView = inflater.inflate(R.layout.gist_file_item, null); ((TextView) fileView.findViewById(R.id.tv_file)).setText(file.getFilename()); TextView fileIcon = (TextView) fileView.findViewById(R.id.tv_file_icon); fileIcon.setText(TypefaceUtils.ICON_FILE_TEXT); fileIcon.setTypeface(octicons); adapter.addHeader(fileView, file, true); fileHeaders.add(fileView); } }
From source file:com.github.mobile.ui.gist.GistFragment.java
private void updateFiles(Gist gist) { final Activity activity = getActivity(); if (activity == null) return;//ww w .j av a 2 s . c om for (View header : fileHeaders) adapter.removeHeader(header); fileHeaders.clear(); Map<String, GistFile> files = gist.getFiles(); if (files == null || files.isEmpty()) return; final LayoutInflater inflater = activity.getLayoutInflater(); final Typeface octicons = TypefaceUtils.getOcticons(activity); for (GistFile file : files.values()) { View fileView = inflater.inflate(layout.gist_file_item, null); ((TextView) fileView.findViewById(id.tv_file)).setText(file.getFilename()); ((TextView) fileView.findViewById(id.tv_file_icon)).setTypeface(octicons); adapter.addHeader(fileView, file, true); fileHeaders.add(fileView); } }