List of usage examples for android.app Dialog setOnDismissListener
public void setOnDismissListener(@Nullable OnDismissListener listener)
From source file:com.entertailion.android.launcher.Dialogs.java
/** * Display about dialog to user when invoked from menu option. * /*from w w w. j ava 2 s . c o m*/ * @param context */ public static void displayAbout(final Launcher context) { final Dialog dialog = new Dialog(context); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.about); Typeface lightTypeface = ((LauncherApplication) context.getApplicationContext()).getLightTypeface(context); TextView aboutTextView = (TextView) dialog.findViewById(R.id.about_text1); aboutTextView.setTypeface(lightTypeface); aboutTextView.setText(context.getString(R.string.about_version_title, Utils.getVersion(context))); aboutTextView.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { context.showCover(false); dialog.dismiss(); Intent intent = new Intent(context, EasterEggActivity.class); context.startActivity(intent); Analytics.logEvent(Analytics.EASTER_EGG); return true; } }); TextView copyrightTextView = (TextView) dialog.findViewById(R.id.copyright_text); copyrightTextView.setTypeface(lightTypeface); TextView feedbackTextView = (TextView) dialog.findViewById(R.id.feedback_text); feedbackTextView.setTypeface(lightTypeface); ((Button) dialog.findViewById(R.id.button_web)).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(context.getString(R.string.about_button_web_url))); context.startActivity(intent); Analytics.logEvent(Analytics.ABOUT_WEB_SITE); context.showCover(false); dialog.dismiss(); } }); ((Button) dialog.findViewById(R.id.button_privacy_policy)).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(context.getString(R.string.about_button_privacy_policy_url))); context.startActivity(intent); Analytics.logEvent(Analytics.ABOUT_PRIVACY_POLICY); context.showCover(false); dialog.dismiss(); } }); ((Button) dialog.findViewById(R.id.button_more_apps)).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(context.getString(R.string.about_button_more_apps_url))); context.startActivity(intent); Analytics.logEvent(Analytics.ABOUT_MORE_APPS); context.showCover(false); dialog.dismiss(); } }); dialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { context.showCover(false); } }); context.showCover(true); dialog.show(); Analytics.logEvent(Analytics.DIALOG_ABOUT); }
From source file:com.entertailion.android.launcher.Dialogs.java
/** * Change the order of the favorite rows. * /*from w ww . ja va 2 s . c om*/ * @param context */ public static void displayChangeRowOrder(final Launcher context) { final Dialog dialog = new Dialog(context); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.row_list); final ListView listView = (ListView) dialog.findViewById(R.id.rowList); ArrayList<RowInfo> persistedRows = RowsTable.getRows(context); final ArrayList<RowInfo> rows = new ArrayList<RowInfo>(); // Add in reverse order to match favorite rows order for (RowInfo rowInfo : persistedRows) { rows.add(0, rowInfo); } final RowAdapter rowAdapter = new RowAdapter(context, rows); listView.setAdapter(rowAdapter); listView.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { RowInfo rowInfo = (RowInfo) parent.getAdapter().getItem(position); if (rowInfo.isSelected()) { rowInfo.setSelected(false); // Persist the new row order try { int counter = 0; for (int i = rowAdapter.getCount() - 1; i >= 0; i--) { RowInfo currentRowInfo = (RowInfo) parent.getAdapter().getItem(i); RowsTable.updateRow(context, currentRowInfo.getId(), currentRowInfo.getTitle(), counter, currentRowInfo.getType()); counter++; } } catch (Exception e) { Log.e(LOG_TAG, "displayChangeRowOrder", e); } Analytics.logEvent(Analytics.CHANGE_ROW_ORDER); } else { rowInfo.setSelected(true); } rowAdapter.notifyDataSetChanged(); } }); listView.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { // Swap the selected item in the list int selectedRowIndex = -1; for (int i = 0; i < rows.size(); i++) { RowInfo rowInfo = rows.get(i); if (rowInfo.isSelected()) { selectedRowIndex = i; break; } } if (selectedRowIndex != -1) { try { Collections.swap(rows, position, selectedRowIndex); rowAdapter.notifyDataSetChanged(); } catch (Exception e) { Log.e(LOG_TAG, "displayChangeRowOrder", e); } } } @Override public void onNothingSelected(AdapterView<?> arg0) { } }); listView.setDrawingCacheEnabled(true); listView.setOnKeyListener(onKeyListener); dialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { context.showCover(false); context.reloadAllGalleries(); } }); Button okButton = (Button) dialog.findViewById(R.id.okButton); okButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { context.showCover(false); dialog.dismiss(); context.reloadAllGalleries(); } }); context.showCover(true); dialog.show(); Analytics.logEvent(Analytics.DIALOG_CHANGE_ROW_ORDER); }
From source file:com.adithya321.sharesanalysis.fragments.SharePurchaseFragment.java
@Nullable @Override//from w ww . j a va 2 s . c om public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_share_purchase, container, false); databaseHandler = new DatabaseHandler(getContext()); sharePurchasesRecyclerView = (RecyclerView) root.findViewById(R.id.share_purchases_recycler_view); emptyTV = (TextView) root.findViewById(R.id.empty); arrow = (ImageView) root.findViewById(R.id.arrow); setRecyclerViewAdapter(); FloatingActionButton addPurchaseFab = (FloatingActionButton) root.findViewById(R.id.add_purchase_fab); addPurchaseFab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final Dialog dialog = new Dialog(getContext()); dialog.setTitle("Add Share Purchase"); dialog.setContentView(R.layout.dialog_add_share_purchase); dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT); dialog.show(); final AutoCompleteTextView name = (AutoCompleteTextView) dialog.findViewById(R.id.share_name); List<String> nseList = ShareUtils.getNseList(getContext()); FilterWithSpaceAdapter<String> arrayAdapter = new FilterWithSpaceAdapter<>(getContext(), android.R.layout.simple_dropdown_item_1line, nseList); name.setThreshold(1); name.setAdapter(arrayAdapter); final Spinner spinner = (Spinner) dialog.findViewById(R.id.existing_spinner); ArrayList<String> shares = new ArrayList<>(); for (Share share : sharesList) { shares.add(share.getName()); } ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, shares); spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(spinnerAdapter); final RadioButton newRB = (RadioButton) dialog.findViewById(R.id.radioBtn_new); RadioButton existingRB = (RadioButton) dialog.findViewById(R.id.radioBtn_existing); if (shares.size() == 0) existingRB.setVisibility(View.GONE); (newRB).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { name.setVisibility(View.VISIBLE); spinner.setVisibility(View.GONE); } }); (existingRB).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { name.setVisibility(View.GONE); spinner.setVisibility(View.VISIBLE); } }); Calendar calendar = Calendar.getInstance(); year_start = calendar.get(Calendar.YEAR); month_start = calendar.get(Calendar.MONTH) + 1; day_start = calendar.get(Calendar.DAY_OF_MONTH); final Button selectDate = (Button) dialog.findViewById(R.id.select_date); selectDate.setText(new StringBuilder().append(day_start).append("/").append(month_start).append("/") .append(year_start)); selectDate.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Dialog dialog = new DatePickerDialog(getActivity(), onDateSetListener, year_start, month_start - 1, day_start); dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { selectDate.setText(new StringBuilder().append(day_start).append("/") .append(month_start).append("/").append(year_start)); } }); dialog.show(); } }); Button addPurchaseBtn = (Button) dialog.findViewById(R.id.add_purchase_btn); addPurchaseBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Share share = new Share(); share.setId(databaseHandler.getNextKey("share")); share.setPurchases(new RealmList<Purchase>()); Purchase purchase = new Purchase(); purchase.setId(databaseHandler.getNextKey("purchase")); if (newRB.isChecked()) { String sName = name.getText().toString().trim(); if (sName.equals("")) { Toast.makeText(getActivity(), "Invalid Name", Toast.LENGTH_SHORT).show(); return; } else { share.setName(sName); purchase.setName(sName); } } String stringStartDate = year_start + " " + month_start + " " + day_start; DateFormat format = new SimpleDateFormat("yyyy MM dd", Locale.ENGLISH); try { Date date = format.parse(stringStartDate); share.setDateOfInitialPurchase(date); purchase.setDate(date); } catch (Exception e) { Toast.makeText(getActivity(), "Invalid Date", Toast.LENGTH_SHORT).show(); return; } EditText quantity = (EditText) dialog.findViewById(R.id.no_of_shares); try { purchase.setQuantity(Integer.parseInt(quantity.getText().toString())); } catch (Exception e) { Toast.makeText(getActivity(), "Invalid Number of Shares", Toast.LENGTH_SHORT).show(); return; } EditText price = (EditText) dialog.findViewById(R.id.buying_price); try { purchase.setPrice(Double.parseDouble(price.getText().toString())); } catch (Exception e) { Toast.makeText(getActivity(), "Invalid Buying Price", Toast.LENGTH_SHORT).show(); return; } purchase.setType("buy"); if (newRB.isChecked()) { if (!databaseHandler.addShare(share, purchase)) { Toast.makeText(getActivity(), "Share Already Exists", Toast.LENGTH_SHORT).show(); return; } } else { purchase.setName(spinner.getSelectedItem().toString()); databaseHandler.addPurchase(spinner.getSelectedItem().toString(), purchase); } setRecyclerViewAdapter(); dialog.dismiss(); } }); } }); return root; }
From source file:com.microsoft.live.sample.skydrive.SkyDriveActivity.java
@Override protected Dialog onCreateDialog(final int id, final Bundle bundle) { Dialog dialog = null; switch (id) { case DIALOG_DOWNLOAD_ID: { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Download").setMessage("This file will be downloaded to the sdcard.") .setPositiveButton("OK", new Dialog.OnClickListener() { @Override// w w w . j av a 2 s . c om public void onClick(DialogInterface dialog, int which) { final ProgressDialog progressDialog = new ProgressDialog(SkyDriveActivity.this); progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); progressDialog.setMessage("Downloading..."); progressDialog.setCancelable(true); progressDialog.show(); String fileId = bundle.getString(JsonKeys.ID); String name = bundle.getString(JsonKeys.NAME); File file = new File(Environment.getExternalStorageDirectory(), name); final LiveDownloadOperation operation = mClient.downloadAsync(fileId + "/content", file, new LiveDownloadOperationListener() { @Override public void onDownloadProgress(int totalBytes, int bytesRemaining, LiveDownloadOperation operation) { int percentCompleted = computePrecentCompleted(totalBytes, bytesRemaining); progressDialog.setProgress(percentCompleted); } @Override public void onDownloadFailed(LiveOperationException exception, LiveDownloadOperation operation) { progressDialog.dismiss(); showToast(exception.getMessage()); } @Override public void onDownloadCompleted(LiveDownloadOperation operation) { progressDialog.dismiss(); showToast("File downloaded."); } }); progressDialog.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { operation.cancel(); } }); } }).setNegativeButton("Cancel", new Dialog.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); dialog = builder.create(); break; } } if (dialog != null) { dialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { removeDialog(id); } }); } return dialog; }
From source file:dev.memento.MainActivity.java
@Override protected Dialog onCreateDialog(int id) { Dialog dialog = null; AlertDialog.Builder builder = new AlertDialog.Builder(this); switch (id) { case DIALOG_ERROR: builder.setMessage("error message").setCancelable(false).setPositiveButton("OK", null); dialog = builder.create();// ww w . j ava 2s . c om break; case DIALOG_MEMENTO_YEARS: builder.setTitle(R.string.select_year); final TreeMap<Integer, Integer> yearCount = mMementos.getAllYears(); if (Log.LOG) Log.d(LOG_TAG, "Dialog: num of years = " + yearCount.size()); // This shouldn't happen, but just in case if (yearCount.size() == 0) { showToast("There are no years to choose from... something is wrong."); if (Log.LOG) Log.d(LOG_TAG, "Num of mementos: " + mMementos.size()); return null; } // Build a list that shows how many dates are available for each year final CharSequence[] yearText = new CharSequence[yearCount.size()]; // Parallel arrays used to determine which entry was selected. // Could also have used a regular expression. final int years[] = new int[yearCount.size()]; final int count[] = new int[yearCount.size()]; int selectedYear = -1; int displayYear = mDateDisplayed.getYear(); int i = 0; for (Map.Entry<Integer, Integer> entry : yearCount.entrySet()) { Integer year = entry.getKey(); // Select the year of the Memento currently displayed if (displayYear == year) selectedYear = i; years[i] = year; count[i] = entry.getValue(); yearText[i] = Integer.toString(year) + " (" + entry.getValue() + ")"; i++; } builder.setSingleChoiceItems(yearText, selectedYear, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { dialog.dismiss(); mSelectedYear = years[item]; int numItems = count[item]; if (numItems > MAX_NUM_MEMENTOS_PER_MONTH) showDialog(DIALOG_MEMENTO_MONTHS); else showDialog(DIALOG_MEMENTO_DATES); } }); dialog = builder.create(); // Cause the dialog to be freed whenever it is dismissed. // This is necessary because the items are dynamic. dialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface arg0) { removeDialog(DIALOG_MEMENTO_YEARS); } }); break; case DIALOG_MEMENTO_MONTHS: builder.setTitle(R.string.select_month); final LinkedHashMap<CharSequence, Integer> monthCount = mMementos.getMonthsForYear(mSelectedYear); // This shouldn't happen, but just in case if (monthCount.size() == 0) { showToast("There are no months to choose from... something is wrong."); if (Log.LOG) Log.d(LOG_TAG, "Num of mementos: " + mMementos.size()); return null; } // Build a list that shows how many dates are available for each month final CharSequence[] monthText = new CharSequence[monthCount.size()]; int selectedMonth = mDateDisplayed.getMonth() - 1; i = 0; for (Map.Entry<CharSequence, Integer> entry : monthCount.entrySet()) { CharSequence month = entry.getKey(); monthText[i] = month + " (" + entry.getValue() + ")"; i++; } builder.setSingleChoiceItems(monthText, selectedMonth, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { dialog.dismiss(); // Pull out month name so we can map it back to a number. // This is ugly, but it's necessary because the LinkedHashMap doesn't // give back the order of its keys. Pattern r = Pattern.compile("^(.+) "); Matcher m = r.matcher(monthText[item]); if (m.find()) { String month = m.group(1); mSelectedMonth = Utilities.monthStringToInt(month); showDialog(DIALOG_MEMENTO_DATES); } else { if (Log.LOG) Log.e(LOG_TAG, "Could not find month in [" + monthText[item] + "]"); } } }); dialog = builder.create(); // Cause the dialog to be freed whenever it is dismissed. // This is necessary because the items are dynamic. dialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface arg0) { removeDialog(DIALOG_MEMENTO_MONTHS); } }); break; case DIALOG_MEMENTO_DATES: builder.setTitle(R.string.select_day); // Which radio button is selected? int selected = -1; final CharSequence[] dates; if (Log.LOG) Log.d(LOG_TAG, "mSelectedMonth = " + mSelectedMonth); if (Log.LOG) Log.d(LOG_TAG, "mSelectedYear = " + mSelectedYear); final Memento[] mementoList; // See if there is a month/year filter if (mSelectedMonth != -1 || mSelectedYear != -1) { if (mSelectedMonth != -1) mementoList = mMementos.getByMonthAndYear(mSelectedMonth, mSelectedYear); else mementoList = mMementos.getByYear(mSelectedYear); if (Log.LOG) Log.d(LOG_TAG, "Number of dates = " + mementoList.length); // Get dates for selected mementos dates = new CharSequence[mementoList.length]; i = 0; for (Memento m : mementoList) { dates[i] = m.getDateAndTimeFormatted(); i++; } // See if any of these items match. This could take a little while if // there are a large number of items unfortunately. Memento m = mMementos.getCurrent(); if (m != null) { CharSequence searchDate = m.getDateAndTimeFormatted(); for (i = 0; i < dates.length; i++) { if (searchDate.equals(dates[i])) { selected = i; break; } } } } else { // No filter, so get all available mementos dates = mMementos.getAllDates(); if (Log.LOG) Log.d(LOG_TAG, "Number of dates = " + dates.length); selected = mMementos.getCurrentIndex(); mementoList = mMementos.toArray(new Memento[0]); } if (Log.LOG) Log.d(LOG_TAG, "Selected index = " + selected); // Reset for future selections mSelectedYear = -1; mSelectedMonth = -1; builder.setSingleChoiceItems(dates, selected, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { dialog.dismiss(); // Display this Memento Memento m = mementoList[item]; mCurrentMemento = m; final SimpleDateTime dateSelected = m.getDateTime(); mDateDisplayed = dateSelected; setChosenDate(mDateDisplayed); if (Log.LOG) Log.d(LOG_TAG, "User selected Memento with date " + dateSelected.dateFormatted()); showToast("Time traveling to " + mDateDisplayed.dateFormatted()); refreshDisplayedDate(); // Load memento into the browser String redirectUrl = m.getUrl(); surfToUrl(redirectUrl); setEnableForNextPrevButtons(); mNowButton.setEnabled(true); // Potentially lengthly operation new Thread() { public void run() { int index = mMementos.getIndex(dateSelected); if (index == -1) { // This should never happen if (Log.LOG) Log.e(LOG_TAG, "!! Couldn't find " + dateSelected + " in the memento list!"); } else mMementos.setCurrentIndex(index); } }.start(); } }); dialog = builder.create(); // Cause the dialog to be freed whenever it is dismissed. // This is necessary because the items are dynamic. I couldn't find // a better way to solve this problem. dialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface arg0) { removeDialog(DIALOG_MEMENTO_DATES); } }); break; } return dialog; }
From source file:biz.bokhorst.xprivacy.ActivityMain.java
@SuppressLint("DefaultLocale") private void optionAbout() { // About/* w w w . j a va 2s.c o m*/ Dialog dlgAbout = new Dialog(this); dlgAbout.requestWindowFeature(Window.FEATURE_LEFT_ICON); dlgAbout.setTitle(R.string.menu_about); dlgAbout.setContentView(R.layout.about); dlgAbout.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, getThemed(R.attr.icon_launcher)); // Show version try { int userId = Util.getUserId(Process.myUid()); Version currentVersion = new Version(Util.getSelfVersionName(this)); Version storedVersion = new Version( PrivacyManager.getSetting(userId, PrivacyManager.cSettingVersion, "0.0")); boolean migrated = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingMigrated, false); String versionName = currentVersion.toString(); if (currentVersion.compareTo(storedVersion) != 0) versionName += "/" + storedVersion.toString(); if (!migrated) versionName += "!"; int versionCode = Util.getSelfVersionCode(this); TextView tvVersion = (TextView) dlgAbout.findViewById(R.id.tvVersion); tvVersion.setText(String.format(getString(R.string.app_version), versionName, versionCode)); } catch (Throwable ex) { Util.bug(null, ex); } if (!PrivacyManager.cVersion3 || Hook.isAOSP(19)) ((TextView) dlgAbout.findViewById(R.id.tvCompatibility)).setVisibility(View.GONE); // Show license String licensed = Util.hasProLicense(this); TextView tvLicensed1 = (TextView) dlgAbout.findViewById(R.id.tvLicensed); TextView tvLicensed2 = (TextView) dlgAbout.findViewById(R.id.tvLicensedAlt); if (licensed == null) { tvLicensed1.setText(Environment.getExternalStorageDirectory().getAbsolutePath()); tvLicensed2.setText(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) .getAbsolutePath()); } else { tvLicensed1.setText(String.format(getString(R.string.app_licensed), licensed)); tvLicensed2.setVisibility(View.GONE); } // Show some build properties String android = String.format("%s (%d)", Build.VERSION.RELEASE, Build.VERSION.SDK_INT); ((TextView) dlgAbout.findViewById(R.id.tvAndroid)).setText(android); ((TextView) dlgAbout.findViewById(R.id.build_brand)).setText(Build.BRAND); ((TextView) dlgAbout.findViewById(R.id.build_manufacturer)).setText(Build.MANUFACTURER); ((TextView) dlgAbout.findViewById(R.id.build_model)).setText(Build.MODEL); ((TextView) dlgAbout.findViewById(R.id.build_product)).setText(Build.PRODUCT); ((TextView) dlgAbout.findViewById(R.id.build_device)).setText(Build.DEVICE); ((TextView) dlgAbout.findViewById(R.id.build_host)).setText(Build.HOST); ((TextView) dlgAbout.findViewById(R.id.build_display)).setText(Build.DISPLAY); ((TextView) dlgAbout.findViewById(R.id.build_id)).setText(Build.ID); dlgAbout.setCancelable(true); final int userId = Util.getUserId(Process.myUid()); if (PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFirstRun, true)) dlgAbout.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { Dialog dlgUsage = new Dialog(ActivityMain.this); dlgUsage.requestWindowFeature(Window.FEATURE_LEFT_ICON); dlgUsage.setTitle(R.string.app_name); dlgUsage.setContentView(R.layout.usage); dlgUsage.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, getThemed(R.attr.icon_launcher)); dlgUsage.setCancelable(true); dlgUsage.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { PrivacyManager.setSetting(userId, PrivacyManager.cSettingFirstRun, Boolean.FALSE.toString()); optionLegend(); } }); dlgUsage.show(); } }); dlgAbout.show(); }
From source file:com.entertailion.android.launcher.Dialogs.java
/** * Display dialog to the user for the browser bookmarks. Allow the user to add a * browser bookmark to an existing row or a new row. * /*from w w w .j a va 2s. c o m*/ * @param context */ public static void displayAddBrowserBookmark(final Launcher context) { final Dialog dialog = new Dialog(context); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.add_browser_bookmarks_list); final EditText nameEditText = (EditText) dialog.findViewById(R.id.rowName); final RadioButton currentRadioButton = (RadioButton) dialog.findViewById(R.id.currentRadio); currentRadioButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { // hide the row name edit field if the current row radio button // is selected nameEditText.setVisibility(View.GONE); } }); final RadioButton newRadioButton = (RadioButton) dialog.findViewById(R.id.newRadio); newRadioButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { // show the row name edit field if the new radio button is // selected nameEditText.setVisibility(View.VISIBLE); nameEditText.requestFocus(); } }); ListView listView = (ListView) dialog.findViewById(R.id.list); final ArrayList<BookmarkInfo> bookmarks = loadBookmarks(context); Collections.sort(bookmarks, new Comparator<BookmarkInfo>() { @Override public int compare(BookmarkInfo lhs, BookmarkInfo rhs) { return lhs.getTitle().toLowerCase().compareTo(rhs.getTitle().toLowerCase()); } }); listView.setAdapter(new BookmarkAdapter(context, bookmarks)); listView.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() { @Override public void onItemClick(final AdapterView<?> parent, final View view, final int position, final long id) { // run in thread since network logic needed to get bookmark icon new Thread(new Runnable() { public void run() { // if the new row radio button is selected, the user must enter // a name for the new row String name = nameEditText.getText().toString().trim(); if (newRadioButton.isChecked() && name.length() == 0) { nameEditText.requestFocus(); displayAlert(context, context.getString(R.string.dialog_new_row_name_alert)); return; } boolean currentRow = !newRadioButton.isChecked(); try { BookmarkInfo bookmark = (BookmarkInfo) parent.getAdapter().getItem(position); int rowId = 0; int rowPosition = 0; if (currentRow) { rowId = context.getCurrentGalleryId(); ArrayList<ItemInfo> items = ItemsTable.getItems(context, rowId); rowPosition = items.size(); // in last // position // for selected // row } else { rowId = (int) RowsTable.insertRow(context, name, 0, RowInfo.FAVORITE_TYPE); rowPosition = 0; } Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(bookmark.getUrl())); Uri uri = Uri.parse(bookmark.getUrl()); Log.d(LOG_TAG, "host=" + uri.getScheme() + "://" + uri.getHost()); String icon = Utils.getWebSiteIcon(context, "http://" + uri.getHost()); Log.d(LOG_TAG, "icon1=" + icon); if (icon == null) { // try base host address int count = StringUtils.countMatches(uri.getHost(), "."); if (count > 1) { int index = uri.getHost().indexOf('.'); String baseHost = uri.getHost().substring(index + 1); icon = Utils.getWebSiteIcon(context, "http://" + baseHost); Log.d(LOG_TAG, "icon2=" + icon); } } ItemsTable.insertItem(context, rowId, rowPosition, bookmark.getTitle(), intent, icon, DatabaseHelper.SHORTCUT_TYPE); } catch (Exception e) { Log.e(LOG_TAG, "displayAddBrowserBookmark", e); } // need to do this on UI thread context.getHandler().post(new Runnable() { public void run() { context.showCover(false); dialog.dismiss(); context.reloadAllGalleries(); } }); if (currentRow) { Analytics.logEvent(Analytics.ADD_BROWSER_BOOKMARK); } else { Analytics.logEvent(Analytics.ADD_BROWSER_BOOKMARK_WITH_ROW); } } }).start(); } }); listView.setDrawingCacheEnabled(true); listView.setOnKeyListener(onKeyListener); dialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { context.showCover(false); } }); context.showCover(true); dialog.show(); Analytics.logEvent(Analytics.DIALOG_ADD_BROWSER_BOOKMARK); }
From source file:com.entertailion.android.launcher.Dialogs.java
/** * Display dialog to allow user to select which row to add the shortcut. For * TV channels let the user change the channel name. * /*from ww w.j ava 2s.c om*/ * @see InstallShortcutReceiver * * @param context * @param name * @param icon * @param uri */ public static void displayShortcutsRowSelection(final Launcher context, final String name, final String icon, final String uri) { if (uri == null) { return; } final Dialog dialog = new Dialog(context); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); final boolean isChannel = uri.startsWith("tv"); dialog.setContentView(R.layout.select_row); final TextView channelTextView = (TextView) dialog.findViewById(R.id.channelText); final EditText channelNameEditText = (EditText) dialog.findViewById(R.id.channelName); if (isChannel) { channelTextView.setVisibility(View.VISIBLE); channelNameEditText.setVisibility(View.VISIBLE); channelNameEditText.setText(name); } final TextView selectTextView = (TextView) dialog.findViewById(R.id.selectText); selectTextView.setText(context.getString(R.string.dialog_select_row, name)); final Spinner spinner = (Spinner) dialog.findViewById(R.id.spinner); final EditText nameEditText = (EditText) dialog.findViewById(R.id.rowName); final RadioButton currentRadioButton = (RadioButton) dialog.findViewById(R.id.currentRadio); currentRadioButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // hide the row name edit field if the current row radio button // is selected nameEditText.setVisibility(View.GONE); spinner.setVisibility(View.VISIBLE); } }); final RadioButton newRadioButton = (RadioButton) dialog.findViewById(R.id.newRadio); newRadioButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // show the row name edit field if the new radio button is // selected nameEditText.setVisibility(View.VISIBLE); nameEditText.requestFocus(); spinner.setVisibility(View.GONE); } }); List<String> list = new ArrayList<String>(); final ArrayList<RowInfo> rows = RowsTable.getRows(context); if (rows != null) { for (RowInfo row : rows) { list.add(row.getTitle()); } } ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(context, R.layout.simple_spinner_item, list); dataAdapter.setDropDownViewResource(R.layout.simple_spinner_dropdown_item); spinner.setAdapter(dataAdapter); Button buttonYes = (Button) dialog.findViewById(R.id.buttonOk); buttonYes.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String shortcutName = name; try { if (isChannel) { String channelName = channelNameEditText.getText().toString().trim(); if (channelName.length() == 0) { channelNameEditText.requestFocus(); displayAlert(context, context.getString(R.string.dialog_channel_name_alert)); return; } shortcutName = channelName; } // if the new row radio button is selected, the user must // enter a name for the new row String rowName = nameEditText.getText().toString().trim(); if (newRadioButton.isChecked() && rowName.length() == 0) { nameEditText.requestFocus(); displayAlert(context, context.getString(R.string.dialog_new_row_name_alert)); return; } boolean currentRow = !newRadioButton.isChecked(); int rowId = 0; int rowPosition = 0; if (currentRow) { if (rows != null) { String selectedRow = (String) spinner.getSelectedItem(); for (RowInfo row : rows) { if (row.getTitle().equals(selectedRow)) { rowId = row.getId(); ArrayList<ItemInfo> items = ItemsTable.getItems(context, rowId); rowPosition = items.size(); // in last // position // for selected // row break; } } } } else { rowId = (int) RowsTable.insertRow(context, rowName, 0, RowInfo.FAVORITE_TYPE); rowPosition = 0; } Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(uri)); ItemsTable.insertItem(context, rowId, rowPosition, shortcutName, intent, icon, DatabaseHelper.SHORTCUT_TYPE); Toast.makeText(context, context.getString(R.string.shortcut_installed, shortcutName), Toast.LENGTH_SHORT).show(); context.reloadAllGalleries(); if (currentRow) { Analytics.logEvent(Analytics.ADD_SHORTCUT); } else { Analytics.logEvent(Analytics.ADD_SHORTCUT_WITH_ROW); } } catch (Exception e) { Log.d(LOG_TAG, "onClick", e); } context.showCover(false); dialog.dismiss(); } }); Button buttonNo = (Button) dialog.findViewById(R.id.buttonCancel); buttonNo.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { context.showCover(false); dialog.dismiss(); } }); dialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { context.showCover(false); } }); context.showCover(true); dialog.show(); Analytics.logEvent(Analytics.DIALOG_ADD_SHORTCUT); }