List of usage examples for android.app AlertDialog getWindow
public @Nullable Window getWindow()
From source file:com.p3authentication.preferences.Prefs.java
@SuppressWarnings("static-access") public void tolerance_dialog() { // TODO Auto-generated method stub final AlertDialog.Builder tol = new AlertDialog.Builder(Prefs.this); final LayoutInflater inflater = (LayoutInflater) Prefs.this .getSystemService(Prefs.this.LAYOUT_INFLATER_SERVICE); final View Viewlayout = inflater.inflate(R.layout.tolerance_dialog, (ViewGroup) findViewById(R.id.tolerance_layout)); tol.setTitle("Please adjust the tolerance"); tol.setView(Viewlayout);//from w w w . j ava 2s.c o m calibrator = (ImageView) Viewlayout.findViewById(R.id.iv_calibrator); fingsize = (TextView) Viewlayout.findViewById(R.id.tv_size); Largest = (TextView) Viewlayout.findViewById(R.id.tv_largest); CalList = new ArrayList<Float>(); tol.setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { int i = LargeValue.intValue(); int screenWidth = (int) ((getWindowManager().getDefaultDisplay().getWidth()) * 0.055); if (i > screenWidth) { PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit() .putInt("tolerance", i).apply(); } dialog.dismiss(); } }); tol.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub dialog.dismiss(); } }); calibrator.setOnTouchListener(this); final AlertDialog tolDialog = tol.create(); WindowManager.LayoutParams wmlp = tolDialog.getWindow().getAttributes(); wmlp.gravity = Gravity.BOTTOM; tolDialog.show(); }
From source file:fr.forexperts.ui.MarketOverviewFragment.java
public void showAddDialog() { LayoutInflater inflater = LayoutInflater.from(getActivity()); View alertView = inflater.inflate(R.layout.alertdialog_add_value, null); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setView(alertView);/*from w w w . j a v a 2 s.co m*/ final AlertDialog dialog = builder.create(); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); WindowManager.LayoutParams wmlp = dialog.getWindow().getAttributes(); wmlp.gravity = Gravity.TOP | Gravity.CENTER; wmlp.x = 10; wmlp.y = 10; final EditText mStockName = (EditText) alertView.findViewById(R.id.stockName); mListViewStock = (ListView) alertView.findViewById(R.id.listViewStock); mListViewStock.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String text = (String) parent.getItemAtPosition(position); String[] result = text.split(" "); mCallback.onItemSelect(result[0]); dialog.dismiss(); } }); mStockName.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { SuggestStockTask task = new SuggestStockTask(); task.execute(mStockName.getText().toString()); } }); // TODO: Change hard coded width mStockName.setWidth(10000); dialog.show(); }
From source file:ab.util.AbDialogUtil.java
/** * AlertDialog ??/*from w ww.j ava 2 s .com*/ */ public static AlertDialog getAlertDialogWithoutRemove(Context mContext, int layout, double showWidth) { final AlertDialog alerDialog = new AlertDialog.Builder(mContext).create(); alerDialog.show(); alerDialog.setCanceledOnTouchOutside(true); Window window = alerDialog.getWindow(); // ?? int height = ScreenUtils.getScreenHeight(mContext); int width = ScreenUtils.getScreenWidth(mContext); WindowManager.LayoutParams params = window.getAttributes(); params.width = (int) (width * showWidth); params.gravity = Gravity.CENTER_HORIZONTAL; alerDialog.onWindowAttributesChanged(params); window.setContentView(layout); return alerDialog; }
From source file:com.safecell.ManageProfile_Activity.java
void displayDialog(String title, String inputText, final int position) { LayoutInflater li = LayoutInflater.from(this); View dialogView = li.inflate(R.layout.dialog_edittext_input, null); dialogInputEditText = (EditText) dialogView.findViewById(R.id.DialogEditTextInputEditText); dialogInputEditText.setText(inputText); dialogInputEditText.setInputType(setInputTypeKeyBoard(position)); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(title).setInverseBackgroundForced(true).setView(dialogView).setCancelable(false) .setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { String text = dialogInputEditText.getText().toString(); if (!text.equalsIgnoreCase("")) { if (position == 2) { if (validationForEmailAddress(text)) { setDialogValuesListArrayAdapter(position); dialog.cancel(); } else { dialog.cancel(); }//from www . j a va 2s . com } else { setDialogValuesListArrayAdapter(position); dialog.cancel(); } } else { Toast.makeText(context, "Blank not allowed.", Toast.LENGTH_SHORT).show(); } } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog alert = builder.create(); alert.show(); alert.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); }
From source file:fr.forexperts.ui.ArticleListFragment.java
public void showAddDialog() { LayoutInflater inflater = LayoutInflater.from(getActivity()); View alertView = inflater.inflate(R.layout.alertdialog_add_value, null); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setView(alertView);/*from ww w .j a v a 2s .co m*/ final AlertDialog dialog = builder.create(); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); WindowManager.LayoutParams wmlp = dialog.getWindow().getAttributes(); wmlp.gravity = Gravity.TOP | Gravity.CENTER; wmlp.x = 10; wmlp.y = 10; final EditText mStockName = (EditText) alertView.findViewById(R.id.stockName); mListViewStock = (ListView) alertView.findViewById(R.id.listViewStock); mListViewStock.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String text = (String) parent.getItemAtPosition(position); String[] result = text.split(" "); Intent detailIntent = new Intent(getActivity(), GraphActivity.class); detailIntent.putExtra("code", result[0]); startActivity(detailIntent); dialog.dismiss(); } }); mStockName.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { SuggestStockTask task = new SuggestStockTask(); task.execute(mStockName.getText().toString()); } }); // TODO: Change hard coded width mStockName.setWidth(10000); dialog.show(); }
From source file:fr.cph.chicago.core.adapter.FavoritesAdapter.java
private void handleStation(@NonNull final FavoritesViewHolder holder, @NonNull final Station station) { final int stationId = station.getId(); final Set<TrainLine> trainLines = station.getLines(); holder.favoriteImage.setImageResource(R.drawable.ic_train_white_24dp); holder.stationNameTextView.setText(station.getName()); holder.detailsButton.setOnClickListener(v -> { if (!Util.isNetworkAvailable(context)) { Util.showNetworkErrorMessage(activity); } else {//from w w w . j a v a 2s . c o m // Start station activity final Bundle extras = new Bundle(); final Intent intent = new Intent(context, StationActivity.class); extras.putInt(activity.getString(R.string.bundle_train_stationId), stationId); intent.putExtras(extras); activity.startActivity(intent); } }); holder.mapButton.setText(activity.getString(R.string.favorites_view_trains)); holder.mapButton.setOnClickListener(v -> { if (!Util.isNetworkAvailable(context)) { Util.showNetworkErrorMessage(activity); } else { if (trainLines.size() == 1) { startActivity(trainLines.iterator().next()); } else { final List<Integer> colors = new ArrayList<>(); final List<String> values = Stream.of(trainLines).flatMap(line -> { final int color = line != TrainLine.YELLOW ? line.getColor() : ContextCompat.getColor(context, R.color.yellowLine); colors.add(color); return Stream.of(line.toStringWithLine()); }).collect(Collectors.toList()); final PopupFavoritesTrainAdapter ada = new PopupFavoritesTrainAdapter(activity, values, colors); final List<TrainLine> lines = new ArrayList<>(); lines.addAll(trainLines); final AlertDialog.Builder builder = new AlertDialog.Builder(activity); builder.setAdapter(ada, (dialog, position) -> startActivity(lines.get(position))); final int[] screenSize = Util.getScreenSize(context); final AlertDialog dialog = builder.create(); dialog.show(); if (dialog.getWindow() != null) { dialog.getWindow().setLayout((int) (screenSize[0] * 0.7), LayoutParams.WRAP_CONTENT); } } } }); Stream.of(trainLines).forEach(trainLine -> { boolean newLine = true; int i = 0; final Map<String, StringBuilder> etas = favoritesData.getTrainArrivalByLine(stationId, trainLine); for (final Entry<String, StringBuilder> entry : etas.entrySet()) { final LinearLayout.LayoutParams containParam = getInsideParams(newLine, i == etas.size() - 1); final LinearLayout container = new LinearLayout(context); container.setOrientation(LinearLayout.HORIZONTAL); container.setLayoutParams(containParam); // Left final RelativeLayout.LayoutParams leftParam = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); final RelativeLayout left = new RelativeLayout(context); left.setLayoutParams(leftParam); final RelativeLayout lineIndication = LayoutUtil.createColoredRoundForFavorites(context, trainLine); int lineId = Util.generateViewId(); lineIndication.setId(lineId); final RelativeLayout.LayoutParams destinationParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); destinationParams.addRule(RelativeLayout.RIGHT_OF, lineId); destinationParams.setMargins(pixelsHalf, 0, 0, 0); final String destination = entry.getKey(); final TextView destinationTextView = new TextView(context); destinationTextView.setTextColor(grey5); destinationTextView.setText(destination); destinationTextView.setLines(1); destinationTextView.setLayoutParams(destinationParams); left.addView(lineIndication); left.addView(destinationTextView); // Right final LinearLayout.LayoutParams rightParams = new LinearLayout.LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); rightParams.setMargins(marginLeftPixel, 0, 0, 0); final LinearLayout right = new LinearLayout(context); right.setOrientation(LinearLayout.VERTICAL); right.setLayoutParams(rightParams); final StringBuilder currentEtas = entry.getValue(); final TextView arrivalText = new TextView(context); arrivalText.setText(currentEtas); arrivalText.setGravity(Gravity.END); arrivalText.setSingleLine(true); arrivalText.setTextColor(grey5); arrivalText.setEllipsize(TextUtils.TruncateAt.END); right.addView(arrivalText); container.addView(left); container.addView(right); holder.mainLayout.addView(container); newLine = false; i++; } }); }
From source file:com.ADORCE.controls.MainViewActivity.java
private void showThemeChooserDialog() { AlertDialog.Builder b = new AlertDialog.Builder(this); Adapter adapter = new ArrayAdapter<>(this, R.layout.simple_list_item_single_choice, getResources().getStringArray(R.array.theme_items)); b.setTitle(getString(R.string.theme_chooser_dialog_title)).setSingleChoiceItems((ListAdapter) adapter, PreferenceManager.getDefaultSharedPreferences(this).getInt("theme_prefs", 0), new DialogInterface.OnClickListener() { @Override//from w w w.java 2 s. co m public void onClick(DialogInterface dialog, int which) { //Invokes method initTheme(int) - next method based on chosen theme initTheme(which); } }); AlertDialog d = b.create(); d.show(); TypedValue typedValue = new TypedValue(); Resources.Theme theme = this.getTheme(); theme.resolveAttribute(R.attr.colorAccent, typedValue, true); Button cancel = d.getButton(AlertDialog.BUTTON_NEGATIVE); cancel.setTextColor(typedValue.data); Button ok = d.getButton(AlertDialog.BUTTON_POSITIVE); ok.setTextColor(typedValue.data); d.getWindow().setBackgroundDrawableResource(R.drawable.dialog_bg); ListView lv = d.getListView(); int paddingTop = Math.round(this.getResources().getDimension(R.dimen.dialog_listView_top_padding)); int paddingBottom = Math.round(this.getResources().getDimension(R.dimen.dialog_listView_bottom_padding)); lv.setPadding(0, paddingTop, 0, paddingBottom); }
From source file:com.hx.hxchat.activity.ChatHistoryFragment.java
/** * /*from w w w.j a v a2 s . co m*/ * @param title * @param emContact */ private void showMyDialog(String title, final ChatHistoryAdapter adapter, final int position) { final AlertDialog dlg = new AlertDialog.Builder(context).create(); dlg.show(); Window window = dlg.getWindow(); // ??,shrew_exit_dialog.xmlview window.setContentView(R.layout.alertdialog); window.findViewById(R.id.ll_title).setVisibility(View.VISIBLE); TextView tv_title = (TextView) window.findViewById(R.id.tv_title); tv_title.setText(title); TextView tv_content1 = (TextView) window.findViewById(R.id.tv_content1); final String username = adapter.getItem(position).getUsername(); // ?? if (topMap.containsKey(username)) { tv_content1.setText("?"); } else { tv_content1.setText("?"); } tv_content1.setOnClickListener(new View.OnClickListener() { @SuppressLint("SdCardPath") public void onClick(View v) { if (topMap.containsKey(username)) { topMap.remove(username); TopUserDao topUserDao = new TopUserDao(context); topUserDao.deleteTopUser(username); } else { TopUser topUser = new TopUser(); topUser.setTime(System.currentTimeMillis()); // 1--- topUser.setType(1); topUser.setUserName(username); Map<String, TopUser> map = new HashMap<String, TopUser>(); map.put(adapter.getItem(position).getUsername(), topUser); topMap.putAll(map); TopUserDao topUserDao = new TopUserDao(context); topUserDao.saveTopUser(topUser); } refresh(); dlg.cancel(); } }); TextView tv_content2 = (TextView) window.findViewById(R.id.tv_content2); tv_content2.setText("?"); tv_content2.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { EMContact tobeDeleteUser = adapter.getItem(position); EMChatManager.getInstance().deleteConversation(adapter.getItem(position).getUsername()); InviteMessgeDao inviteMessgeDao = new InviteMessgeDao(context); inviteMessgeDao.deleteMessage(tobeDeleteUser.getUsername()); BaseApplication.getApplication().GetLinkerDao().deleteContact(tobeDeleteUser.getUsername()); adapter.remove(tobeDeleteUser); adapter.notifyDataSetChanged(); // ((MainActivity) context).homefragment.refresh(); // boolean isGroup = false; // // // if (tobeDeleteUser instanceof EMGroup) // isGroup = true; // // // ? // boolean deleteConversation = EMChatManager.getInstance().deleteConversation(tobeDeleteUser.getUsername()); // InviteMessgeDao inviteMessgeDao = new InviteMessgeDao(getActivity()); // inviteMessgeDao.deleteMessage(tobeDeleteUser.getUsername()); // // BaseApplication.getApplication().GetLinkerDao().deleteContact(tobeDeleteUser.getUsername()); // adapter.remove(tobeDeleteUser); // adapter.notifyDataSetChanged(); // // // ? // // TODO // // ((MainActivity) getActivity()).updateUnreadLabel(); // // // dlg.cancel(); } }); }
From source file:com.sdrtouch.tools.DialogManager.java
private Dialog createDialog(final dialogs id) { switch (id) { case DIAG_ABOUT: final AlertDialog addd = new AlertDialog.Builder(getActivity()).setTitle(R.string.help) .setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() { @Override/*from w w w. j av a2 s . co m*/ public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }).setMessage(Html.fromHtml(getString(R.string.help_info))).create(); try { addd.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface paramDialogInterface) { try { final TextView tv = (TextView) addd.getWindow().findViewById(android.R.id.message); if (tv != null) tv.setMovementMethod(LinkMovementMethod.getInstance()); } catch (Exception ignored) { } } }); } catch (Exception ignored) { } return addd; case DIAG_LICENSE: return new AlertDialog.Builder(getActivity()).setTitle("License") .setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }).setMessage(readWholeStream(R.raw.license)).create(); } return null; }
From source file:com.example.alyshia.customsimplelauncher.MainActivity.java
void inflateDialog(int type) { AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle("PASSWORD"); LayoutInflater inflater = LayoutInflater.from(this); final View view = inflater.inflate(R.layout.dialoglayout, null); EditText edittext = (EditText) view.findViewById(R.id.pswEditText); alert.setView(R.layout.dialoglayout); if (type == TYPE_EXIT) { alert.setPositiveButton("Enter", new DialogInterface.OnClickListener() { @Override//from w w w . j a v a2 s . c om public void onClick(DialogInterface dialog, int which) { Dialog d = (Dialog) dialog; EditText et = (EditText) d.findViewById(R.id.pswEditText); Log.d(TAG, "TEXT is " + et.getText().toString()); if (et.getText().toString().equals("")) { dialog.dismiss(); Toast.makeText(MainActivity.this, "wrong password", Toast.LENGTH_SHORT).show(); } else if (et.getText().toString().equals(getPW())) { setkioskReceiver(); if (km == null) { km = KioskMode.getInstance(getApplicationContext()); } if (km.isKioskModeEnabled()) { Log.d(TAG, "Kioskmode being disabled bc it is enabled"); km.disableKioskMode(); } } } }); } else if (type == TYPE_ADMIN) { alert.setPositiveButton("Enter", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Dialog d = (Dialog) dialog; EditText et = (EditText) d.findViewById(R.id.pswEditText); Log.d(TAG, "TEXT is " + et.getText().toString()); if (et.getText().toString().equals("")) { dialog.dismiss(); } else if (et.getText().toString().equals(getPW())) { Intent intent = new Intent(MainActivity.this, AdminActivity.class); startActivity(intent); } } }); } alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); alert.setCancelable(true); AlertDialog cdialog = alert.create(); cdialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); cdialog.show(); }