List of usage examples for android.app Dialog Dialog
public Dialog(@NonNull Context context)
From source file:com.nanostuffs.yurdriver.fragment.RegisterFragment.java
private void datepicker() { final Dialog dialog = new Dialog(getActivity()); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCanceledOnTouchOutside(true); dialog.setContentView(R.layout.datepicker_layout); final DatePicker date = (DatePicker) dialog.findViewById(R.id.datePicker1); final Calendar c = Calendar.getInstance(); c.add(Calendar.DAY_OF_YEAR, -1 * (16 * 365)); date.setMaxDate(c.getTimeInMillis()); Button text = (Button) dialog.findViewById(R.id.ok); text.setOnClickListener(new OnClickListener() { @Override/*from w w w . j a v a2s . co m*/ public void onClick(View v) { v.bringToFront(); String dateString = String .valueOf(date.getYear() + "-" + (date.getMonth() + 1) + "-" + date.getDayOfMonth()); etDOB.setText(dateString); dialog.dismiss(); } }); Button cancel = (Button) dialog.findViewById(R.id.cancel); cancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub v.bringToFront(); dialog.dismiss(); } }); dialog.show(); }
From source file:com.kircherelectronics.accelerationexplorer.activity.NoiseActivity.java
private void showHelpDialog() { Dialog helpDialog = new Dialog(this); helpDialog.setCancelable(true);//from ww w . j a va2 s.co m helpDialog.setCanceledOnTouchOutside(true); helpDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); View view = getLayoutInflater().inflate(R.layout.layout_help_noise, null); helpDialog.setContentView(view); helpDialog.show(); }
From source file:com.android.nobadgift.DashboardActivity.java
private void displayConfirmationDialog() { try {// w ww. j av a2 s . com Dialog dialog = new Dialog(this); dialog.setContentView(R.layout.custom_dialog); dialog.setTitle("Successfully Scanned!"); dialog.setCanceledOnTouchOutside(true); dialog.setCancelable(true); dialog.setOnDismissListener(new OnDismissListener() { public void onDismiss(DialogInterface dialog) { displayInfoDialog(); } }); TextView text = (TextView) dialog.findViewById(R.id.dialogText); text.setText("\"" + itemName + "\""); ImageView image = (ImageView) dialog.findViewById(R.id.dialogImage); image.setImageBitmap(retrievedImage); dialog.show(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.commonsdroid.fragmentdialog.AlertFragmentDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { setCancelable(isCancelable);//from www . ja v a2s .c o m if (TextUtils.isEmpty(positiveText)) { positiveText = "OK"; Log.d("CHECK", "" + com.commonsdroid.fragmentdialog.R.string.ok); } if (TextUtils.isEmpty(negativeText)) { negativeText = "Cancel"; } switch (type) { case DIALOG_TYPE_OK: /*show dialog with positive button*/ return new AlertDialog.Builder(getActivity()).setTitle(title).setMessage(message) .setPositiveButton(positiveText, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.dismiss(); if (alertButtonClickListener != null) alertButtonClickListener.onPositiveButtonClick(identifier); } }).create(); case DIALOG_TYPE_YES_NO: /*show dialog with positive and negative button*/ return new AlertDialog.Builder(getActivity()).setTitle(title).setMessage(message) .setPositiveButton(positiveText, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.dismiss(); if (alertButtonClickListener != null) alertButtonClickListener.onPositiveButtonClick(identifier); } }).setNegativeButton(negativeText, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.dismiss(); if (alertButtonClickListener != null) alertButtonClickListener.onNegativeButtonClick(identifier); } }).create(); case DATE_DIALOG: /*show date picker dialog*/ return new DatePickerDialog(getActivity(), AlertFragmentDialog.this, sYear, sMonth, sDate); case TIME_DIALOG: /*show time picker dialog*/ return new TimePickerDialog(getActivity(), AlertFragmentDialog.this, sHour, sMinute, true); case SIMPLE_LIST_DIALOG: /** * show simple list dialog */ return getAlertBuilder(title, dialogList, android.R.layout.select_dialog_item).create(); case SINGLE_CHOICE_LIST_DIALOG: /*show single choice list dialog*/ return getAlertBuilder(title, dialogList, android.R.layout.select_dialog_singlechoice).create(); case MULTI_CHOICE_LIST_DIALOG: /*show multichoice list dialog*/ Dialog multipleChoice = new Dialog(getActivity()); multipleChoice.setContentView(R.layout.list_multichoice); multipleChoice.setTitle(title); ListView listView = (ListView) multipleChoice.findViewById(R.id.lstMultichoiceList); listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // Manage selected items here CheckedTextView textView = (CheckedTextView) view; if (textView.isChecked()) { } else { } Log.e("CHECK", "clicked pos : " + position + " checked : " + textView.isChecked()); } }); final ArrayAdapter<String> arraySingleChoiceAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.select_dialog_multichoice, dialogList); listView.setAdapter(arraySingleChoiceAdapter); multipleChoice.show(); /*multipleChoice.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); multipleChoice.setPositiveButton(R.string.cancel, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dismiss(); sListDialogListener.onMultiChoiceSelected(identifier, alSelectedItem); } });*/ /* multipleChoice.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (alSelectedItem.size() != 0) { sListDialogListener.onMultiChoiceSelected(identifier, alSelectedItem); } } });*/ // multipleChoice.create(); // singleChoiceListDialog.setCancelable(false); /* multipleChoice.setMultiChoiceItems(items, null, new DialogInterface.OnMultiChoiceClickListener() { @Override public void onClick(DialogInterface dialog, int which, boolean isChecked) { if (isChecked) { alSelectedItem.add(items[which]); } else { alSelectedItem.remove(items[which]); } } }); multipleChoice.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); multipleChoice.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (alSelectedItem.size() != 0) { sListDialogListener.onMultiChoiceSelected(identifier, alSelectedItem); } } });*/ return multipleChoice;//.create(); } return null; }
From source file:fi.tuukka.weather.utils.Utils.java
public static void showImage(Activity activity, View view, Bitmap bmp) { final Dialog imageDialog = new Dialog(activity); imageDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); imageDialog.setContentView(R.layout.showimage); imageDialog.setCancelable(true);/*ww w . j a va2 s . c om*/ ImageView imageView = (ImageView) imageDialog.findViewById(R.id.imageView); // Getting width & height of the given image. DisplayMetrics displayMetrics = activity.getResources().getDisplayMetrics(); int wn = displayMetrics.widthPixels; int hn = displayMetrics.heightPixels; int wo = bmp.getWidth(); int ho = bmp.getHeight(); Matrix mtx = new Matrix(); // Setting rotate to 90 mtx.preRotate(90); // Setting resize mtx.postScale(((float) 1.3 * wn) / ho, ((float) 1.3 * hn) / wo); // Rotating Bitmap Bitmap rotatedBMP = Bitmap.createBitmap(bmp, 0, 0, wo, ho, mtx, true); BitmapDrawable bmd = new BitmapDrawable(rotatedBMP); imageView.setImageDrawable(bmd); imageView.setOnClickListener(new View.OnClickListener() { public void onClick(View button) { imageDialog.dismiss(); } }); imageDialog.show(); }
From source file:com.inc.playground.playgroundApp.MainActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED); // Create the adapter that will return a fragment for each of the three primary sections // of the app. mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager()); globalVariables = ((GlobalVariables) getApplication()); // Set up the action bar. final ActionBar actionBar = getActionBar(); setPlayGroundActionBar();//from w ww . j a v a2 s. c o m //set actionBar color actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.primaryColor))); actionBar.setStackedBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.secondaryColor))); // Specify that the Home/Up button should not be enabled, since there is no hierarchical // parent. //actionBar.setHomeButtonEnabled(false); actionBar.setDisplayShowHomeEnabled(false); // Specify that we will be displaying tabs in the action bar. actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // Set up the ViewPager, attaching the adapter and setting up a listener for when the // user swipes between sections. mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mAppSectionsPagerAdapter); mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { // When swiping between different app sections, select the corresponding tab. // We can also use ActionBar.Tab#select() to do this if we have a reference to the // Tab. actionBar.setSelectedNavigationItem(position); } }); // For each of the sections in the app, add a tab to the action bar. for (int i = 0; i < mAppSectionsPagerAdapter.getCount(); i++) { // Create a tab with text corresponding to the page title defined by the adapter. // Also specify this Activity object, which implements the TabListener interface, as the // listener for when this tab is selected. actionBar.addTab(actionBar.newTab().setTabListener(this)); } actionBar.getTabAt(0).setIcon(R.drawable.pg_list_view); actionBar.getTabAt(1).setIcon(R.drawable.pg_map_view); //NavigationDrawer handling (e.g the list from leftside): mTitle = mDrawerTitle = getTitle(); mDrawerLayout = (DrawerLayout) findViewById(R.id.menu_layout); mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ R.drawable.pg_menu, /* nav drawer icon to replace 'Up' caret */ R.string.drawer_open, /* "open drawer" description */ R.string.drawer_close /* "close drawer" description */ ) { /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { super.onDrawerClosed(view); getActionBar().setTitle(mTitle); } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); getActionBar().setTitle(mDrawerTitle); } }; // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); mDrawerLayout.closeDrawers(); getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setHomeButtonEnabled(true); // all linear layout from slider menu /*Home button */ LinearLayout ll_Home = (LinearLayout) findViewById(R.id.ll_home); ll_Home.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub // new changes Intent iv = new Intent(MainActivity.this, MainActivity.class); startActivity(iv); finish(); } }); /*Login button */ LinearLayout ll_Login = (LinearLayout) findViewById(R.id.ll_login); ll_Login.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub // new changes LinearLayout ll_Login = (LinearLayout) v; TextView loginTxt = (TextView) findViewById(R.id.login_txt); if (loginTxt.getText().equals("Login")) { Intent iv = new Intent(MainActivity.this, Login.class); startActivity(iv); finish(); } else if (loginTxt.getText().equals("Logout")) { final Dialog alertDialog = new Dialog(MainActivity.this); alertDialog.setContentView(R.layout.logout_dilaog); alertDialog.setTitle("Logout"); alertDialog.findViewById(R.id.ok_btn).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { SharedPreferences prefs = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE); SharedPreferences.Editor editor = prefs.edit(); editor.clear(); editor.commit(); ImageView loginImg = (ImageView) findViewById(R.id.login_img); TextView loginTxt = (TextView) findViewById(R.id.login_txt); loginTxt.setText("Login"); loginImg.setImageResource(R.drawable.pg_action_lock_open); globalVariables = ((GlobalVariables) getApplication()); globalVariables.SetCurrentUser(null); globalVariables.SetUserPictureBitMap(null); globalVariables.SetUsersList(null); globalVariables.SetUsersImagesMap(null); Util.clearCookies(getApplicationContext()); Intent iv = new Intent(MainActivity.this, MainActivity.class); startActivity(iv); finish(); } }); alertDialog.findViewById(R.id.cancel_btn).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent iv = new Intent(MainActivity.this, MainActivity.class); startActivity(iv); finish(); } }); alertDialog.show(); //<-- See This! } } }); // // /*Setting button*/ // LinearLayout ll_Setting = (LinearLayout) findViewById(R.id.ll_settings); // ll_Setting.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // // TODO Auto-generated method stub // // new changes // Intent iv = new Intent(MainActivity.this, // com.inc.playground.playgroundApp.upLeft3StripesButton. // SettingsActivity.class); // startActivity(iv); // finish(); // } // }); /*My profile button*/ LinearLayout ll_my_profile = (LinearLayout) findViewById(R.id.ll_my_profile); ll_my_profile.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // new changes globalVariables = ((GlobalVariables) getApplication()); User currentUser = globalVariables.GetCurrentUser(); if ((currentUser == null) || (currentUser != null && currentUser.GetUserId() == null)) { Toast.makeText(MainActivity.this, "You are not logged in", Toast.LENGTH_LONG).show(); } else { Intent iv = new Intent(MainActivity.this, com.inc.playground.playgroundApp.upLeft3StripesButton.MyProfile.class); //for my profile iv.putExtra("name", currentUser.getName()); iv.putExtra("createdNumOfEvents", currentUser.getCreatedNumOfEvents()); //pass events iv.putExtra("events", currentUser.getEvents()); iv.putExtra("events_wait4approval", currentUser.getEvents_wait4approval()); iv.putExtra("events_decline", currentUser.getEvents_decline()); iv.putExtra("photoUrl", currentUser.getPhotoUrl()); startActivity(iv); // } } }); LinearLayout ll_aboutUs = (LinearLayout) findViewById(R.id.ll_about); ll_aboutUs.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub // new changes Intent iv = new Intent(MainActivity.this, AboutUs.class); startActivity(iv); finish(); } }); }
From source file:eu.power_switch.gui.dialog.ConfigurationDialogTabbed.java
@NonNull @Override// w w w . j a v a2 s. co m public Dialog onCreateDialog(Bundle savedInstanceState) { // ask to really close Dialog dialog = new Dialog(getActivity()) { @Override public void onBackPressed() { if (modified) { // ask to really close new AlertDialog.Builder(getActivity()).setTitle(R.string.are_you_sure) .setPositiveButton(android.R.string.yes, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { getDialog().cancel(); } }).setNeutralButton(android.R.string.no, null) .setMessage(R.string.all_changes_will_be_lost).show(); } else { getDialog().cancel(); } } }; dialog.setTitle(getDialogTitle()); dialog.setCanceledOnTouchOutside(isCancelableOnTouchOutside()); dialog.getWindow().setSoftInputMode(getSoftInputMode()); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(dialog.getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.MATCH_PARENT; lp.height = WindowManager.LayoutParams.WRAP_CONTENT; dialog.show(); dialog.getWindow().setAttributes(lp); dialog.show(); return dialog; }
From source file:com.sssemil.advancedsettings.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); new Thread(new Runnable() { @Override/*from w w w. java 2s. c om*/ public void run() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { while (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(MainActivity.this, new String[] { Manifest.permission.READ_EXTERNAL_STORAGE }, REQUEST); try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } } while (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(MainActivity.this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, REQUEST); try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } } while (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.WRITE_SETTINGS) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(MainActivity.this, new String[] { Manifest.permission.WRITE_SETTINGS }, REQUEST); try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } } while (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.SYSTEM_ALERT_WINDOW) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(MainActivity.this, new String[] { Manifest.permission.SYSTEM_ALERT_WINDOW }, REQUEST); try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } } /*if (!android.provider.Settings.System.canWrite(MainActivity.this)) { mContinue = false; runOnUiThread(new Runnable() { @Override public void run() { mAlertDialog = new AlertDialog.Builder(MainActivity.this) .setMessage(getString(R.string.grant_access_settings)) .setPositiveButton(getString(android.R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mContinue = true; } }) .create(); mAlertDialog.show(); } }); while (!mContinue) { try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } } Intent intent = new Intent(); intent.setAction(android.provider.Settings.ACTION_MANAGE_WRITE_SETTINGS); intent.setData(Uri.parse("package:" + getPackageName())); // Start Activity startActivityForResult(intent, REQUEST); while (!mContinueActivity) { try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } } }*/ } } }).start(); SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); sharedPreferences.edit().putString("system_language", Locale.getDefault().getLanguage().toLowerCase() + "-" + Locale.getDefault().getCountry().toUpperCase()).apply(); sharedPreferences.registerOnSharedPreferenceChangeListener(this); final View prefsRoot = inflater.inflate(R.layout.preferences, null); final List<Preference> loadedPreferences = new ArrayList<>(); for (int i = 0; i < ((PreferenceScreen) prefsRoot).getChildCount(); i++) { if ((parsePreference(((PreferenceScreen) prefsRoot).getChildAt(i)).getKey()).equals("wifi_settings")) { if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI)) { loadedPreferences.add(parsePreference(((PreferenceScreen) prefsRoot).getChildAt(i))); } } else if ((parsePreference(((PreferenceScreen) prefsRoot).getChildAt(i)).getKey()) .equals("bluetooth_setting")) { if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)) { loadedPreferences.add(parsePreference(((PreferenceScreen) prefsRoot).getChildAt(i))); } } else if ((parsePreference(((PreferenceScreen) prefsRoot).getChildAt(i)).getKey()) .equals("power_settings")) { loadedPreferences.add(parsePreference(((PreferenceScreen) prefsRoot).getChildAt(i))); } else if ((parsePreference(((PreferenceScreen) prefsRoot).getChildAt(i)).getKey()) .equals("system_language")) { if (Utils.isPackageInstalled("sssemil.com.languagesettingsprovider", this, 1)) { loadedPreferences.add(parsePreference(((PreferenceScreen) prefsRoot).getChildAt(i))); } } else { loadedPreferences.add(parsePreference(((PreferenceScreen) prefsRoot).getChildAt(i))); } } addPreferences(loadedPreferences); this.startService(new Intent(this, MainService.class)); if (!Utils.isDeviceRooted()) { Dialog dialog = new Dialog(this); dialog.setTitle("Warning"); dialog.setContentView(R.layout.warning); dialog.show(); } }
From source file:com.amazon.appstream.fireclient.ConnectDialogFragment.java
/** * Create callback; performs initial set-up. *//*from ww w.j ava 2s.com*/ @Override public Dialog onCreateDialog(Bundle savedInstanceState) { mEmpty.setAlpha(0); final Dialog connectDialog = new Dialog(getActivity()); connectDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); connectDialog.setCanceledOnTouchOutside(false); connectDialog.setCancelable(false); connectDialog.setContentView(R.layout.server_address); connectDialog.getWindow().setBackgroundDrawable(mEmpty); mAddressTitle = (TextView) connectDialog.findViewById(R.id.address_title); mAddressField = (TextView) connectDialog.findViewById(R.id.address); mTextEntryFields = connectDialog.findViewById(R.id.text_entry_fields); mProgressBar = (ProgressBar) connectDialog.findViewById(R.id.progress_bar); mUseHardware = (CheckBox) connectDialog.findViewById(R.id.hardware); mUseHardware.setChecked(false); final CheckBox useAppServerBox = (CheckBox) connectDialog.findViewById(R.id.appserver); useAppServerBox.setChecked(mUseAppServer); useAppServerBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { if (!mUseAppServer) { mDESServerAddress = mAddressField.getText().toString(); } } else { if (mUseAppServer) { mServerAddress = mAddressField.getText().toString(); } } mUseAppServer = isChecked; updateFields(); } }); mAppIdField = (TextView) connectDialog.findViewById(R.id.appid); mSpace1 = connectDialog.findViewById(R.id.space1); mSpace2 = connectDialog.findViewById(R.id.space2); mAppIdTitle = connectDialog.findViewById(R.id.appid_title); mUserIdTitle = connectDialog.findViewById(R.id.userid_title); if (mAppId != null) { mAppIdField.setText(mAppId); } mUserIdField = (TextView) connectDialog.findViewById(R.id.userid); if (mUsername != null) { mUserIdField.setText(mUsername); } mErrorMessageField = (TextView) connectDialog.findViewById(R.id.error_message); mReconnect = connectDialog.findViewById(R.id.reconnect_fields); mReconnectMessage = (TextView) connectDialog.findViewById(R.id.reconnect_message); final Button connectButton = (Button) connectDialog.findViewById(R.id.connect); connectButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { onConnect(); } }); TextView.OnEditorActionListener listener = new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_GO) { InputMethodManager imm = (InputMethodManager) mActivity .getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(mUserIdField.getWindowToken(), 0); onConnect(); } return true; } }; View.OnFocusChangeListener focusListener = new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { connectButton.setFocusableInTouchMode(false); } }; mAppIdField.setOnFocusChangeListener(focusListener); mUserIdField.setOnFocusChangeListener(focusListener); mUserIdField.setOnFocusChangeListener(focusListener); mUserIdField.setOnEditorActionListener(listener); updateFields(); if (mAddressField.getText().length() == 0) { mAddressField.requestFocus(); connectButton.setFocusableInTouchMode(false); } else { connectButton.requestFocus(); } if (mReconnectMessageString != null) { reconnecting(mReconnectMessageString); mReconnectMessageString = null; } return connectDialog; }
From source file:com.flowzr.activity.DateFilterActivity.java
@Override protected Dialog onCreateDialog(final int id) { final Dialog d = new Dialog(this); d.setCancelable(true);//from w ww . j av a2 s. c o m d.setTitle(id == 1 ? R.string.period_from : R.string.period_to); d.setContentView(R.layout.filter_period_select); Button bOk = (Button) d.findViewById(R.id.bOK); bOk.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { setDialogResult(d, id == 1 ? cFrom : cTo); d.dismiss(); } }); Button bCancel = (Button) d.findViewById(R.id.bCancel); bCancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { d.cancel(); } }); return d; }