List of usage examples for android.app AlertDialog dismiss
@Override public void dismiss()
From source file:im.neon.activity.VectorHomeActivity.java
/** * Manage the e2e keys export./*from ww w . j av a2 s .c o m*/ */ private void exportKeysAndSignOut() { View dialogLayout = getLayoutInflater().inflate(R.layout.dialog_export_e2e_keys, null); AlertDialog.Builder dialog = new AlertDialog.Builder(this); dialog.setTitle(R.string.encryption_export_room_keys); dialog.setView(dialogLayout); final TextInputEditText passPhrase1EditText = (TextInputEditText) dialogLayout .findViewById(R.id.dialog_e2e_keys_passphrase_edit_text); final TextInputEditText passPhrase2EditText = (TextInputEditText) dialogLayout .findViewById(R.id.dialog_e2e_keys_confirm_passphrase_edit_text); final Button exportButton = (Button) dialogLayout.findViewById(R.id.dialog_e2e_keys_export_button); final TextWatcher textWatcher = 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) { exportButton.setEnabled(!TextUtils.isEmpty(passPhrase1EditText.getText()) && TextUtils.equals(passPhrase1EditText.getText(), passPhrase2EditText.getText())); } @Override public void afterTextChanged(Editable s) { } }; passPhrase1EditText.addTextChangedListener(textWatcher); passPhrase2EditText.addTextChangedListener(textWatcher); exportButton.setEnabled(false); final AlertDialog exportDialog = dialog.show(); exportButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showWaitingView(); CommonActivityUtils.exportKeys(mSession, passPhrase1EditText.getText().toString(), new ApiCallback<String>() { private void onDone(String message) { stopWaitingView(); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder( VectorHomeActivity.this); alertDialogBuilder.setMessage(message); // set dialog message alertDialogBuilder.setCancelable(false).setPositiveButton(R.string.action_sign_out, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { VectorHomeActivity.this.showWaitingView(); CommonActivityUtils.logout(VectorHomeActivity.this); } }) .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); } @Override public void onSuccess(String filename) { onDone(VectorHomeActivity.this.getString(R.string.encryption_export_saved_as, filename)); } @Override public void onNetworkError(Exception e) { onDone(e.getLocalizedMessage()); } @Override public void onMatrixError(MatrixError e) { onDone(e.getLocalizedMessage()); } @Override public void onUnexpectedError(Exception e) { onDone(e.getLocalizedMessage()); } }); exportDialog.dismiss(); } }); }
From source file:im.vector.fragments.VectorSettingsPreferencesFragment.java
/** * Manage the e2e keys export./*from w w w . java2 s .c o m*/ */ private void exportKeys() { View dialogLayout = getActivity().getLayoutInflater().inflate(R.layout.dialog_export_e2e_keys, null); AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity()); dialog.setTitle(R.string.encryption_export_room_keys); dialog.setView(dialogLayout); final TextInputEditText passPhrase1EditText = dialogLayout .findViewById(R.id.dialog_e2e_keys_passphrase_edit_text); final TextInputEditText passPhrase2EditText = dialogLayout .findViewById(R.id.dialog_e2e_keys_confirm_passphrase_edit_text); final Button exportButton = dialogLayout.findViewById(R.id.dialog_e2e_keys_export_button); final TextWatcher textWatcher = 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) { exportButton.setEnabled(!TextUtils.isEmpty(passPhrase1EditText.getText()) && TextUtils.equals(passPhrase1EditText.getText(), passPhrase2EditText.getText())); } @Override public void afterTextChanged(Editable s) { } }; passPhrase1EditText.addTextChangedListener(textWatcher); passPhrase2EditText.addTextChangedListener(textWatcher); exportButton.setEnabled(false); final AlertDialog exportDialog = dialog.show(); exportButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { displayLoadingView(); CommonActivityUtils.exportKeys(mSession, passPhrase1EditText.getText().toString(), new ApiCallback<String>() { @Override public void onSuccess(String filename) { Toast.makeText(VectorApp.getInstance().getApplicationContext(), filename, Toast.LENGTH_SHORT).show(); hideLoadingView(); } @Override public void onNetworkError(Exception e) { hideLoadingView(); } @Override public void onMatrixError(MatrixError e) { hideLoadingView(); } @Override public void onUnexpectedError(Exception e) { hideLoadingView(); } }); exportDialog.dismiss(); } }); }
From source file:com.juick.android.MainActivity.java
public void updateNavigation() { navigationItems = new ArrayList<NavigationItem>(); List<MicroBlog> blogs = new ArrayList<MicroBlog>(microBlogs.values()); Collections.<MicroBlog>sort(blogs, new Comparator<MicroBlog>() { @Override/* ww w .j a v a 2 s .c o m*/ public int compare(MicroBlog microBlog, MicroBlog microBlog2) { return microBlog.getPiority() - microBlog2.getPiority(); } }); for (MicroBlog blog : blogs) { blog.addNavigationSources(navigationItems, this); } navigationItems.add(new NavigationItem(NAVITEM_UNREAD, R.string.navigationUnread, R.drawable.navicon_juickadvanced, "msrcUnread") { @Override public void action() { final NavigationItem thisNi = this; final ProgressDialog pd = new ProgressDialog(MainActivity.this); pd.setIndeterminate(true); pd.setTitle(R.string.navigationUnread); pd.setCancelable(true); pd.show(); UnreadSegmentsView.loadPeriods(MainActivity.this, new Utils.Function<Void, ArrayList<DatabaseService.Period>>() { @Override public Void apply(ArrayList<DatabaseService.Period> periods) { if (pd.isShowing()) { pd.cancel(); AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); final AlertDialog alerDialog; if (periods.size() == 0) { alerDialog = builder.setTitle(getString(R.string.UnreadSegments)) .setMessage(getString(R.string.YouHaveNotEnabledForUnreadSegments)) .setCancelable(true) .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { dialogInterface.dismiss(); restoreLastNavigationPosition(); } }).create(); } else { UnreadSegmentsView unreadSegmentsView = new UnreadSegmentsView( MainActivity.this, periods); final int myIndex = navigationItems.indexOf(thisNi); alerDialog = builder.setTitle(getString(R.string.ChooseUnreadSegment)) .setView(unreadSegmentsView).setCancelable(true) .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { dialogInterface.dismiss(); restoreLastNavigationPosition(); } }) .create(); unreadSegmentsView.setListener(new UnreadSegmentsView.PeriodListener() { @Override public void onPeriodClicked(DatabaseService.Period period) { alerDialog.dismiss(); int beforeMid = period.beforeMid; Bundle args = new Bundle(); args.putSerializable("messagesSource", new UnreadSegmentMessagesSource( getString(R.string.navigationUnread), MainActivity.this, period)); if (getSelectedNavigationIndex() != myIndex) { setSelectedNavigationItem(myIndex); } runDefaultFragmentWithBundle(args, thisNi); } }); } alerDialog.show(); restyleChildrenOrWidget(alerDialog.getWindow().getDecorView()); } return null; } }); return; } }); navigationItems.add(new NavigationItem(NAVITEM_SAVED, R.string.navigationSaved, R.drawable.navicon_juickadvanced, "msrcSaved") { @Override public void action() { final Bundle args = new Bundle(); args.putSerializable("messagesSource", new SavedMessagesSource(MainActivity.this)); runDefaultFragmentWithBundle(args, this); } }); navigationItems.add(new NavigationItem(NAVITEM_RECENT_READ, R.string.navigationRecentlyOpened, R.drawable.navicon_juickadvanced, "msrcRecentOpen") { @Override public void action() { final Bundle args = new Bundle(); args.putSerializable("messagesSource", new RecentlyOpenedMessagesSource(MainActivity.this)); runDefaultFragmentWithBundle(args, this); } }); navigationItems.add(new NavigationItem(NAVITEM_RECENT_WRITE, R.string.navigationRecentlyCommented, R.drawable.navicon_juickadvanced, "msrcRecentComment") { @Override public void action() { final Bundle args = new Bundle(); args.putSerializable("messagesSource", new RecentlyCommentedMessagesSource(MainActivity.this)); runDefaultFragmentWithBundle(args, this); } }); navigationItems.add(new NavigationItem(NAVITEM_ALL_COMBINED, R.string.navigationAllCombined, R.drawable.navicon_juickadvanced, "msrcAllCombined") { @Override public void action() { final Bundle args = new Bundle(); args.putSerializable("messagesSource", new CombinedAllMessagesSource(MainActivity.this, "combined_all")); runDefaultFragmentWithBundle(args, this); } @Override public ArrayList<String> getMenuItems() { String s = getString(R.string.SelectSources); ArrayList<String> strings = new ArrayList<String>(); strings.add(s); return strings; } @Override public void handleMenuAction(int which, String value) { switch (which) { case 0: selectSourcesForAllCombined(); break; } } }); navigationItems.add(new NavigationItem(NAVITEM_SUBS_COMBINED, R.string.navigationSubsCombined, R.drawable.navicon_juickadvanced, "msrcSubsCombined") { @Override public void action() { final NavigationItem thiz = this; new Thread("MessageSource Initializer") { @Override public void run() { final Bundle args = new Bundle(); args.putSerializable("messagesSource", new CombinedSubscriptionMessagesSource(MainActivity.this)); runOnUiThread(new Runnable() { @Override public void run() { runDefaultFragmentWithBundle(args, thiz); } }); } }.start(); final Bundle args = new Bundle(); runDefaultFragmentWithBundle(args, this); } @Override public ArrayList<String> getMenuItems() { String s = getString(R.string.SelectSources); ArrayList<String> strings = new ArrayList<String>(); strings.add(s); return strings; } @Override public void handleMenuAction(int which, String value) { switch (which) { case 0: selectSourcesForAllSubs(); break; } } }); int index = 10000; final SharedPreferences sp_order = getSharedPreferences("messages_source_ordering", MODE_PRIVATE); for (NavigationItem navigationItem : navigationItems) { navigationItem.itemOrder = sp_order.getInt("order_" + navigationItem.id, -1); if (navigationItem.itemOrder == -1) { navigationItem.itemOrder = index; sp_order.edit().putInt("order_" + navigationItem.id, navigationItem.itemOrder).commit(); } index++; } Collections.sort(navigationItems, new Comparator<NavigationItem>() { @Override public int compare(NavigationItem lhs, NavigationItem rhs) { return lhs.itemOrder - rhs.itemOrder; // increasing } }); allNavigationItems = new ArrayList<NavigationItem>(navigationItems); final Iterator<NavigationItem> iterator = navigationItems.iterator(); while (iterator.hasNext()) { NavigationItem next = iterator.next(); if (next.sharedPrefsKey != null) { if (!sp.getBoolean(next.sharedPrefsKey, defaultValues(next.sharedPrefsKey))) { iterator.remove(); } } } sp_order.edit().commit(); // save final boolean compressedMenu = sp.getBoolean("compressedMenu", false); float menuFontScale = 1; try { menuFontScale = Float.parseFloat(sp.getString("menuFontScale", "1.0")); } catch (Exception e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } final float finalMenuFontScale = menuFontScale; navigationList = (DragSortListView) findViewById(R.id.navigation_list); // adapter for old-style navigation final BaseAdapter navigationAdapter = new BaseAdapter() { @Override public int getCount() { return navigationItems.size(); } @Override public Object getItem(int position) { return navigationItems.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { if (position == -1) { // NOOK is funny return convertView; } final int screenHeight = getWindow().getWindowManager().getDefaultDisplay().getHeight(); final int layoutId = R.layout.simple_list_item_1_mine; final PressableLinearLayout retval = convertView != null ? (PressableLinearLayout) convertView : (PressableLinearLayout) getLayoutInflater().inflate(layoutId, null); TextView tv = (TextView) retval.findViewById(android.R.id.text1); if (parent instanceof Spinner) { tv.setTextSize(18 * finalMenuFontScale); tv.setEllipsize(TextUtils.TruncateAt.MARQUEE); } else { tv.setTextSize(22 * finalMenuFontScale); } tv.setText(getString(navigationItems.get(position).labelId)); if (compressedMenu) { int minHeight = (int) ((screenHeight * 0.7) / getCount()); tv.setMinHeight(minHeight); tv.setMinimumHeight(minHeight); } retval.setPressedListener(new PressableLinearLayout.PressedListener() { @Override public void onPressStateChanged(boolean selected) { MainActivity.restyleChildrenOrWidget(retval, false); } @Override public void onSelectStateChanged(boolean selected) { MainActivity.restyleChildrenOrWidget(retval, false); } }); MainActivity.restyleChildrenOrWidget(retval, false); return retval; } }; // adapter for new-style navigation final BaseAdapter navigationListAdapter = new BaseAdapter() { @Override public int getCount() { return getItems().size(); } private ArrayList<NavigationItem> getItems() { if (navigationList.isDragEnabled()) { return allNavigationItems; } else { return navigationItems; } } @Override public Object getItem(int position) { return getItems().get(position); } @Override public long getItemId(int position) { return position; } float textSize = -1; @Override public View getView(int position, View convertView, ViewGroup parent) { if (position == -1) { // NOOK is funny return convertView; } if (textSize < 0) { View inflate = getLayoutInflater().inflate(android.R.layout.simple_list_item_1, null); TextView text = (TextView) inflate.findViewById(android.R.id.text1); textSize = text.getTextSize(); } final int layoutId = R.layout.navigation_list_item; final PressableLinearLayout retval = convertView != null ? (PressableLinearLayout) convertView : (PressableLinearLayout) getLayoutInflater().inflate(layoutId, null); TextView tv = (TextView) retval.findViewById(android.R.id.text1); final ArrayList<NavigationItem> items = getItems(); final NavigationItem theItem = items.get(position); tv.setText(getString(theItem.labelId)); ImageButton menuButton = (ImageButton) retval.findViewById(R.id.menu_button); menuButton.setFocusable(false); ArrayList<String> menuItems = theItem.getMenuItems(); menuButton.setVisibility(menuItems != null && menuItems.size() > 0 ? View.VISIBLE : View.GONE); menuButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { doNavigationItemMenu(theItem); } }); ImageView iv = (ImageView) retval.findViewById(android.R.id.icon); iv.setImageResource(theItem.imageId); retval.findViewById(R.id.draggable) .setVisibility(items != allNavigationItems ? View.GONE : View.VISIBLE); retval.findViewById(R.id.checkbox).setVisibility( items != allNavigationItems || theItem.sharedPrefsKey == null ? View.GONE : View.VISIBLE); CheckBox cb = (CheckBox) retval.findViewById(R.id.checkbox); cb.setOnCheckedChangeListener(null); if (theItem.sharedPrefsKey != null) { cb.setChecked(sp.getBoolean(theItem.sharedPrefsKey, defaultValues(theItem.sharedPrefsKey))); } cb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { sp.edit().putBoolean(theItem.sharedPrefsKey, isChecked).commit(); } }); int spacing = sp.getInt("navigation_spacing", 0); tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize + spacing); retval.setPadding(0, spacing, 0, spacing); return retval; } }; ActionBar bar = getSupportActionBar(); updateActionBarMode(); navigationList.setDragEnabled(false); ((DragSortController) navigationList.getFloatViewManager()).setDragHandleId(R.id.draggable); navigationList.setAdapter(navigationListAdapter); navigationList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, final int position, long id) { setSelectedNavigationItem(position); closeNavigationMenu(true, false); } }); navigationList.setDropListener(new DragSortListView.DropListener() { @Override public void drop(int from, int to) { final NavigationItem item = allNavigationItems.remove(from); allNavigationItems.add(to, item); int index = 0; for (NavigationItem allNavigationItem : allNavigationItems) { if (allNavigationItem.itemOrder != index) { allNavigationItem.itemOrder = index; sp_order.edit().putInt("order_" + allNavigationItem.id, allNavigationItem.itemOrder) .commit(); } index++; } sp_order.edit().commit(); // save navigationListAdapter.notifyDataSetChanged(); //To change body of implemented methods use File | Settings | File Templates. } }); bar.setListNavigationCallbacks(navigationAdapter, this); final View navigationMenuButton = (View) findViewById(R.id.navigation_menu_button); navigationMenuButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new AlertDialog.Builder(MainActivity.this) .setItems(navigationList.isDragEnabled() ? R.array.navigation_menu_end : R.array.navigation_menu_start, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { int spacing = sp.getInt("navigation_spacing", 0); switch (which) { case 0: if (navigationList.isDragEnabled()) { navigationList.setDragEnabled(false); updateNavigation(); } else { navigationList.setDragEnabled(true); } break; case 1: final Map<String, ?> all = sp_order.getAll(); for (String s : all.keySet()) { sp_order.edit().remove(s).commit(); } sp_order.edit().commit(); updateNavigation(); break; case 2: // wider sp.edit().putInt("navigation_spacing", spacing + 1).commit(); ((BaseAdapter) navigationList.getAdapter()).notifyDataSetInvalidated(); break; case 3: // narrower if (spacing > 0) { sp.edit().putInt("navigation_spacing", spacing - 1).commit(); ((BaseAdapter) navigationList.getAdapter()) .notifyDataSetInvalidated(); } break; case 4: // logout from.. logoutFromSomeServices(); break; } navigationListAdapter.notifyDataSetChanged(); } }) .setCancelable(true).create().show(); } }); final SharedPreferences spn = getSharedPreferences("saved_last_navigation_type", MODE_PRIVATE); int restoredLastNavItem = spn.getInt("last_navigation", 0); if (restoredLastNavItem != 0) { NavigationItem allSources = null; for (int i = 0; i < navigationItems.size(); i++) { NavigationItem navigationItem = navigationItems.get(i); if (navigationItem.labelId == restoredLastNavItem) { lastNavigationItem = navigationItem; } if (navigationItem.labelId == R.string.navigationAll) { allSources = navigationItem; } } if (lastNavigationItem == null) { lastNavigationItem = allSources; // could be null if not configured } if (lastNavigationItem == null && navigationItems.size() > 0) { lastNavigationItem = navigationItems.get(0); // last default } if (lastNavigationItem != null) { restoreLastNavigationPosition(); lastNavigationItem.action(); } } }
From source file:no.barentswatch.fiskinfo.BaseActivity.java
/** * This functions creates a dialog which allows the user to export different * map layers./*from w w w . j a v a 2s. c o m*/ * * @param ActivityContext * The context of the current activity. * @return True if the export succeeded, false otherwise. */ public boolean exportMapLayerToUser(Context activityContext) { LayoutInflater layoutInflater = getLayoutInflater(); View view = layoutInflater.inflate(R.layout.dialog_export_metadata, (null)); Button downloadButton = (Button) view.findViewById(R.id.metadataDownloadButton); Button cancelButton = (Button) view.findViewById(R.id.cancel_button); final AlertDialog builder = new AlertDialog.Builder(activityContext).create(); builder.setTitle(R.string.map_export_metadata_title); builder.setView(view); final AtomicReference<String> selectedHeader = new AtomicReference<String>(); final AtomicReference<String> selectedFormat = new AtomicReference<String>(); final ExpandableListView expListView = (ExpandableListView) view .findViewById(R.id.exportMetadataMapServices); final List<String> listDataHeader = new ArrayList<String>(); final HashMap<String, List<String>> listDataChild = new HashMap<String, List<String>>(); final Map<String, String> nameToApiNameResolver = new HashMap<String, String>(); JSONArray availableSubscriptions = getSharedCacheOfAvailableSubscriptions(); if (availableSubscriptions == null) { availableSubscriptions = authenticatedGetRequestToBarentswatchAPIService( getString(R.string.my_page_geo_data_service)); setSharedCacheOfAvailableSubscriptions(availableSubscriptions); } for (int i = 0; i < availableSubscriptions.length(); i++) { try { JSONObject currentSub = availableSubscriptions.getJSONObject(i); nameToApiNameResolver.put(currentSub.getString("Name"), currentSub.getString("ApiName")); listDataHeader.add(currentSub.getString("Name")); List<String> availableDownloadFormatsOfCurrentLayer = new ArrayList<String>(); JSONArray availableFormats = currentSub.getJSONArray("Formats"); for (int j = 0; j < availableFormats.length(); j++) { availableDownloadFormatsOfCurrentLayer.add(availableFormats.getString(j)); } listDataChild.put(listDataHeader.get(i), availableDownloadFormatsOfCurrentLayer); System.out .println("item: " + currentSub.getString("Name") + ", " + currentSub.getString("ApiName")); } catch (JSONException e) { e.printStackTrace(); Log.d("ExportMapLAyerToUser", "Invalid JSON returned from API CALL"); return false; } } final ExpandableListAdapter listAdapter = new ExpandableListAdapter(activityContext, listDataHeader, listDataChild); expListView.setAdapter(listAdapter); // Listview on child click listener expListView.setOnChildClickListener(new OnChildClickListener() { @Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { selectedHeader.set(nameToApiNameResolver.get(listDataHeader.get(groupPosition))); selectedHeader.set(listDataHeader.get(groupPosition)); selectedFormat.set(listDataChild.get(listDataHeader.get(groupPosition)).get(childPosition)); LinearLayout currentlySelected = (LinearLayout) parent.findViewWithTag("currentlySelectedRow"); if (currentlySelected != null) { currentlySelected.getChildAt(0).setBackgroundColor(Color.WHITE); currentlySelected.setTag(null); } ((LinearLayout) v).getChildAt(0).setBackgroundColor(Color.rgb(214, 214, 214)); v.setTag("currentlySelectedRow"); return true; } }); downloadButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { new DownloadMapLayerFromBarentswatchApiInBackground() .execute(nameToApiNameResolver.get(selectedHeader.get()), selectedFormat.get()); builder.dismiss(); } }); cancelButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { builder.dismiss(); } }); builder.setCanceledOnTouchOutside(false); builder.show(); return true; }
From source file:no.barentswatch.fiskinfo.MapActivity.java
/** * //from w w w. j a va2 s . c o m * @param activityContext * The context of the current activity */ @SuppressLint("InflateParams") public void setProximityAlertDialog(Context activityContext) { LayoutInflater layoutInflater = getLayoutInflater(); View view = layoutInflater.inflate(R.layout.dialog_scheduled_task_executor, null); final AlertDialog builder = new AlertDialog.Builder(activityContext).create(); builder.setTitle(R.string.map_set_proximity_alert_title); builder.setView(view); final EditText distanceEditText = (EditText) view.findViewById(R.id.scheduledProximityRangeEditText); final SeekBar seekbar = (SeekBar) view.findViewById(R.id.scheduledSetProximityRangeSeekBar); distanceEditText.setText(String.valueOf(minLenghtMeters)); final Spinner measuringUnitSpinner = (Spinner) view.findViewById(R.id.scheduledMeasuringUnitsSpinner); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.measurement_units, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); measuringUnitSpinner.setAdapter(adapter); seekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { if (fromUser == true) { if (currentlySelected == meterIndex) { distanceEditText .setText(String.valueOf((int) (minLenghtMeters + (stepSizeMeters * progress)))); } else if (currentlySelected == nauticalMileIndex) { distanceEditText.setText( String.valueOf(minLenghtNauticalMiles + (stepSizeNauticalMiles * progress))); } } } }); measuringUnitSpinner.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { double distance = (distanceEditText.length() != 0 ? Double.parseDouble(distanceEditText.getText().toString()) : 0); System.out.println("posistion: " + position); System.out.println("currentlySelected: " + position); if (position == meterIndex) { if (position != currentlySelected) { distance = convertDistance(distance, position); distanceEditText.setText(String.valueOf(distance)); currentlySelected = position; } } else if (position == nauticalMileIndex) { if (position != currentlySelected) { distance = convertDistance(distance, position); distanceEditText.setText(String.valueOf(distance)); currentlySelected = position; } } else { return; } System.out.println("distance: " + distance); int newProgress = findProgress(distance, position); seekbar.setProgress(newProgress); System.out.println("progress: " + newProgress); distanceEditText.setText(String.valueOf(distance)); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); Button setProximityAlertButton = (Button) view.findViewById(R.id.scheduledSetProximityCheckerDialogButton); Button cancelButton = (Button) view.findViewById(R.id.cancel_button); builder.setView(view); builder.setCanceledOnTouchOutside(false); setProximityAlertButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (!alarmSet) { mGpsLocationTracker = new GpsLocationTracker(getContext()); double latitude, longitude = 0; if (mGpsLocationTracker.canGetLocation()) { latitude = mGpsLocationTracker.getLatitude(); cachedLat = latitude; longitude = mGpsLocationTracker.getLongitude(); cachedLon = longitude; } else { mGpsLocationTracker.showSettingsAlert(); return; } String distance = distanceEditText.getText().toString(); cachedDistance = distance; cacheWriter = new DownloadMapLayerFromBarentswatchApiInBackground().execute("fishingfacility", "OLEX", "cachedResults", String.valueOf(longitude), String.valueOf(latitude), distance, "true"); alarmSet = true; runScheduledAlarm(); } builder.dismiss(); } }); cancelButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { builder.cancel(); } }); builder.show(); }
From source file:org.tvbrowser.tvbrowser.TvBrowser.java
private void showDonationInfo() { AlertDialog.Builder alert = new AlertDialog.Builder(TvBrowser.this); alert.setTitle(R.string.donation);// w w w . ja va2 s.c o m View view = getLayoutInflater().inflate(R.layout.donations, getParentViewGroup(), false); alert.setView(view); Button inAppDonation = (Button) view.findViewById(R.id.donation_in_app_button); TextView webInfo = (TextView) view.findViewById(R.id.donation_show_ways); Button openWeb = (Button) view.findViewById(R.id.donation_website_button); if (!Locale.getDefault().getCountry().equals("DE")) { webInfo.setVisibility(View.GONE); openWeb.setVisibility(View.GONE); } alert.setNegativeButton(getString(R.string.not_now).replace("{0}", ""), new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); final AlertDialog d = alert.create(); inAppDonation.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { d.dismiss(); prepareInAppPayment(); } }); openWeb.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { d.dismiss(); startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://android.tvbrowser.org/index.php?id=donations"))); } }); d.show(); }
From source file:org.tvbrowser.tvbrowser.TvBrowser.java
private void showRatingAndDonationInfo() { AlertDialog.Builder alert = new AlertDialog.Builder(TvBrowser.this); alert.setTitle(R.string.you_like_it); View view = getLayoutInflater().inflate(R.layout.rating_and_donation, getParentViewGroup(), false); TextView ratingInfo = (TextView) view.findViewById(R.id.rating_info); Button rate = (Button) view.findViewById(R.id.rating_button); Button donate = (Button) view.findViewById(R.id.donation_button); if (!SettingConstants.GOOGLE_PLAY) { ratingInfo.setVisibility(View.GONE); rate.setVisibility(View.GONE); }//from ww w. jav a 2 s. co m ratingInfo.setText(Html.fromHtml(getString(R.string.rating_text))); ((TextView) view.findViewById(R.id.donation_info)).setText(Html.fromHtml(getString(R.string.donate_text))); final Button cancel = (Button) view.findViewById(R.id.rating_donation_cancel); cancel.setEnabled(false); alert.setView(view); alert.setCancelable(false); final AlertDialog d = alert.create(); cancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { d.dismiss(); setRatingAndDonationInfoShown(); finish(); } }); donate.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { d.dismiss(); setRatingAndDonationInfoShown(); showDonationInfo(); } }); rate.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { d.dismiss(); final String appPackageName = getPackageName(); // getPackageName() from Context or Activity object try { startActivity( new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName))); } catch (android.content.ActivityNotFoundException anfe) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=" + appPackageName))); } setRatingAndDonationInfoShown(); finish(); } }); d.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { new Thread("Cancel wait thread") { @Override public void run() { int count = 10; while (--count >= 0) { final int countValue = count + 1; handler.post(new Runnable() { @Override public void run() { cancel.setText( getString(R.string.not_now).replace("{0}", " (" + countValue + ")")); } }); try { sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } handler.post(new Runnable() { @Override public void run() { cancel.setText(getString(R.string.not_now).replace("{0}", "")); cancel.setEnabled(true); } }); } }.start(); } }); d.show(); }
From source file:im.vector.fragments.VectorSettingsPreferencesFragment.java
/** * Manage the e2e keys import./*from ww w .j a va 2s. c o m*/ * * @param intent the intent result */ private void importKeys(Intent intent) { // sanity check if (null == intent) { return; } ArrayList<RoomMediaMessage> sharedDataItems = new ArrayList<>( RoomMediaMessage.listRoomMediaMessages(intent)); if (sharedDataItems.size() > 0) { final RoomMediaMessage sharedDataItem = sharedDataItems.get(0); View dialogLayout = getActivity().getLayoutInflater().inflate(R.layout.dialog_import_e2e_keys, null); AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity()); dialog.setTitle(R.string.encryption_import_room_keys); dialog.setView(dialogLayout); final TextInputEditText passPhraseEditText = dialogLayout .findViewById(R.id.dialog_e2e_keys_passphrase_edit_text); final Button importButton = dialogLayout.findViewById(R.id.dialog_e2e_keys_import_button); passPhraseEditText.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) { importButton.setEnabled(!TextUtils.isEmpty(passPhraseEditText.getText())); } @Override public void afterTextChanged(Editable s) { } }); importButton.setEnabled(false); final AlertDialog importDialog = dialog.show(); final Context appContext = getActivity().getApplicationContext(); importButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String password = passPhraseEditText.getText().toString(); final ResourceUtils.Resource resource = ResourceUtils.openResource(appContext, sharedDataItem.getUri(), sharedDataItem.getMimeType(appContext)); byte[] data; try { data = new byte[resource.mContentStream.available()]; resource.mContentStream.read(data); resource.mContentStream.close(); } catch (Exception e) { try { resource.mContentStream.close(); } catch (Exception e2) { Log.e(LOG_TAG, "## importKeys() : " + e2.getMessage()); } Toast.makeText(appContext, e.getLocalizedMessage(), Toast.LENGTH_SHORT).show(); return; } displayLoadingView(); mSession.getCrypto().importRoomKeys(data, password, new ApiCallback<Void>() { @Override public void onSuccess(Void info) { hideLoadingView(); } @Override public void onNetworkError(Exception e) { Toast.makeText(appContext, e.getLocalizedMessage(), Toast.LENGTH_SHORT).show(); hideLoadingView(); } @Override public void onMatrixError(MatrixError e) { Toast.makeText(appContext, e.getLocalizedMessage(), Toast.LENGTH_SHORT).show(); hideLoadingView(); } @Override public void onUnexpectedError(Exception e) { Toast.makeText(appContext, e.getLocalizedMessage(), Toast.LENGTH_SHORT).show(); hideLoadingView(); } }); importDialog.dismiss(); } }); } }
From source file:org.tvbrowser.tvbrowser.TvBrowser.java
private void showInAppDonations(final Inventory inv, boolean showIfAlreadyDonated) { updateProgressIcon(false);/* www . ja va 2 s . co m*/ AlertDialog.Builder alert = new AlertDialog.Builder(TvBrowser.this); alert.setTitle(R.string.donation); View view = getLayoutInflater().inflate(R.layout.in_app_donations, getParentViewGroup(), false); LinearLayout layout = (LinearLayout) view.findViewById(R.id.donation_in_app_layout); alert.setView(view); alert.setNegativeButton(getString(R.string.not_now).replace("{0}", ""), null); if (Locale.getDefault().getCountry().equals("DE")) { alert.setPositiveButton(R.string.donation_info_website, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://android.tvbrowser.org/index.php?id=donations"))); } }); } final AlertDialog d = alert.create(); View.OnClickListener onDonationClick = new View.OnClickListener() { @Override public void onClick(View v) { d.dismiss(); openDonation((SkuDetails) v.getTag()); } }; Purchase donated = null; SkuDetails donatedDetails = null; for (String sku : SettingConstants.SKU_LIST) { SkuDetails details = inv.getSkuDetails(sku); Purchase donatedTest = inv.getPurchase(sku); if (donatedTest != null && details != null) { donated = donatedTest; donatedDetails = details; } if (details != null) { if (!details.getSku().equals(SettingConstants.SKU_EPG_DONATE_ONCE) || hasEpgDonateChannelsSubscribed()) { String title = details.getTitle().substring(0, details.getTitle().indexOf("(") - 1); Button donation = new Button(this); donation.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18); donation.setText(title + ": " + details.getPrice()); donation.setTag(details); donation.setOnClickListener(onDonationClick); layout.addView(donation); LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) donation.getLayoutParams(); params.setMargins(5, 0, 5, 5); //left, top, right, bottom donation.setLayoutParams(params); } } } if (donated == null || showIfAlreadyDonated) { d.show(); } else if (donated != null) { AlertDialog.Builder alert2 = new AlertDialog.Builder(TvBrowser.this); alert2.setTitle(R.string.donation); String message = getString(R.string.already_donated) .replace("{1}", DateFormat.getLongDateFormat(this).format(new Date(donated.getPurchaseTime()))) .replace("{0}", donatedDetails.getPrice()); alert2.setMessage(message); final Purchase toConsume = donated; alert2.setPositiveButton(R.string.donate_again, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { updateProgressIcon(true); mHelper.consumeAsync(toConsume, new IabHelper.OnConsumeFinishedListener() { @Override public void onConsumeFinished(Purchase purchase, IabResult result) { updateProgressIcon(false); if (result.isSuccess()) { d.show(); } else { handler.post(new Runnable() { @Override public void run() { Toast.makeText(TvBrowser.this, "", Toast.LENGTH_LONG).show(); } }); } } }); } }); alert2.setNegativeButton(R.string.stop_donation, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); alert2.show(); } }
From source file:pt.aptoide.backupapps.Aptoide.java
@Override public boolean onOptionsItemSelected(MenuItem item) { EnumOptionsMenu menuEntry = EnumOptionsMenu.reverseOrdinal(item.getItemId()); Log.d("Aptoide-OptionsMenu", "menuOption: " + menuEntry + " itemid: " + item.getItemId()); switch (menuEntry) { // case MANAGE_REPO: // availableAdapter.sleep(); // Intent manageRepo = new Intent(this, ManageRepos.class); // startActivity(manageRepo); // return true; case UNINSTALL: try {/* w w w . ja va2 s . com*/ serviceDataCaller.callUninstallApps(installedAdapter.getSelectedIds()); } catch (RemoteException e) { // TODO Auto-generated catch block e.printStackTrace(); } return true; case DELETE: //TODO improve listIds as an extended parcelable array ;) then use it as a carrier for checked hashids list return true; case DISPLAY_OPTIONS: if (!loadingRepos.get()) { //TODO refactor extract dialog management class LayoutInflater displayOptionsInflater = LayoutInflater.from(this); View displayOptions = displayOptionsInflater.inflate(R.layout.dialog_display_options, null); Builder dialogBuilder = new AlertDialog.Builder(theme).setView(displayOptions); final AlertDialog sortDialog = dialogBuilder.create(); sortDialog.setIcon(android.R.drawable.ic_menu_sort_by_size); sortDialog.setTitle(getString(R.string.display_options)); // *********************************************************** // Categories // final RadioButton byCategory = (RadioButton) displayOptions.findViewById(R.id.by_category); // final RadioButton byAll = (RadioButton) displayOptions.findViewById(R.id.by_all); // if(availableByCategory){ // byCategory.setChecked(true); // }else{ // byAll.setChecked(true); // } // // final View spacer = displayOptions.findViewById(R.id.spacer); // // if(currentAppsList != EnumAppsLists.Available){ // spacer.setVisibility(View.GONE); // ((RadioGroup) displayOptions.findViewById(R.id.group_show)).setVisibility(View.GONE); // } // *********************************************************** // Sorting final View group_sort = displayOptions.findViewById(R.id.group_sort); final RadioButton byAlphabetic = (RadioButton) displayOptions.findViewById(R.id.by_alphabetic); final RadioButton byFreshness = (RadioButton) displayOptions.findViewById(R.id.by_freshness); final RadioButton bySize = (RadioButton) displayOptions.findViewById(R.id.by_size); // spacer.setVisibility(View.VISIBLE); group_sort.setVisibility(View.VISIBLE); switch (appsSortingPolicy) { case ALPHABETIC: byAlphabetic.setChecked(true); break; case FRESHNESS: byFreshness.setChecked(true); break; case SIZE: bySize.setChecked(true); break; default: break; } // *********************************************************** final CheckBox showSystemApps = (CheckBox) displayOptions.findViewById(R.id.show_system_apps); boolean showSystemAppsState = false; try { showSystemAppsState = serviceDataCaller.callGetShowSystemApps(); } catch (RemoteException e) { // TODO Auto-generated catch block e.printStackTrace(); } showSystemApps.setChecked(showSystemAppsState); final boolean storedShowSystemAppsState = showSystemAppsState; sortDialog.setButton(getString(R.string.done), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // boolean byCategoryChanged = false; EnumAppsSorting newSortingPolicy = null; // if(byCategory.isChecked() != availableByCategory){ // byCategoryChanged = true; // availableByCategory = byCategory.isChecked(); // setAvailableListBy(availableByCategory); // } if (showSystemApps.isChecked() != storedShowSystemAppsState) { setShowSystemApps(showSystemApps.isChecked()); } if (byAlphabetic.isChecked()) { newSortingPolicy = EnumAppsSorting.ALPHABETIC; } else if (byFreshness.isChecked()) { newSortingPolicy = EnumAppsSorting.FRESHNESS; } else if (bySize.isChecked()) { newSortingPolicy = EnumAppsSorting.SIZE; } if (newSortingPolicy != null && newSortingPolicy != appsSortingPolicy) { // availableAdapter.sleep(); appsSortingPolicy = newSortingPolicy; setAppsSortingPolicy(appsSortingPolicy); } // if(byCategoryChanged){ // if(availableByCategory){ // availableAdapter.sleep(); // categoriesAdapter.resetDisplayCategories(); // }else{ // availableAdapter.resetDisplay(null); // } // } sortDialog.dismiss(); } }); sortDialog.show(); } else { Toast.makeText(Aptoide.this, getString(R.string.option_not_available_while_updating_repos), Toast.LENGTH_SHORT).show(); } return true; // case SEARCH_MENU: // onSearchRequested(); // return true; case UN_SELECT_ALL: switch (currentAppsList) { case RESTORE: if (availableAdapter.isDynamic()) { Toast.makeText(Aptoide.this, getString(R.string.too_many_apps_to_select_at_once), Toast.LENGTH_SHORT).show(); return true; } availableAdapter.toggleSelectAll(); break; case BACKUP: installedAdapter.toggleSelectAll(); break; default: break; } return true; case ABOUT: LayoutInflater aboutInflater = LayoutInflater.from(this); View about = aboutInflater.inflate(R.layout.about, null); TextView info = (TextView) about.findViewById(R.id.credits); info.setText(getString(R.string.credits, versionName)); Builder aboutCreator = new AlertDialog.Builder(theme).setView(about); final AlertDialog aboutDialog = aboutCreator.create(); aboutDialog.setIcon(R.drawable.icon); aboutDialog.setTitle(R.string.self_name); // aboutDialog.setButton(getText(R.string.changelog), new DialogInterface.OnClickListener() { // public void onClick(DialogInterface dialog, int whichButton) { // Uri uri = Uri.parse(getString(R.string.changelog_url)); // startActivity(new Intent( Intent.ACTION_VIEW, uri)); // } // }); aboutDialog.show(); return true; case SETTINGS: // availableAdapter.sleep(); Intent settings = new Intent(this, Settings.class); startActivity(settings); return true; case LOGIN: // boolean insertingRepo = false; // try { // insertingRepo = serviceDataCaller.callIsInsertingRepo(); // } catch (RemoteException e1) { // // TODO Auto-generated catch block // e1.printStackTrace(); // } // if(insertingRepo){ // AptoideLog.d(Aptoide.this, getString(R.string.updating_repo_please_wait)); // Toast.makeText(getApplicationContext(), getResources().getString(R.string.updating_repo_please_wait), Toast.LENGTH_SHORT).show(); // } // else{ Log.d("Aptoide-Settings", "clicked set server login"); String token = null; try { token = serviceDataCaller.callGetServerToken(); } catch (RemoteException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (token == null) { Log.d("Aptoide-Settings", "No login set"); Intent login = new Intent(Aptoide.this, BazaarLogin.class); login.putExtra("InvoqueType", BazaarLogin.InvoqueType.NO_CREDENTIALS_SET.ordinal()); startActivity(login); // DialogLogin dialogLogin = new DialogLogin(Settings.this, serviceDataCaller, DialogLogin.InvoqueType.NO_CREDENTIALS_SET); // loginComments.setOnDismissListener(new OnDismissListener() { // @Override // public void onDismiss(DialogInterface dialog) { // addAppVersionComment(); // } // }); // dialogLogin.show(); } else { Log.d("Aptoide-Settings", "Login edit"); Intent login = new Intent(Aptoide.this, BazaarLogin.class); login.putExtra("InvoqueType", BazaarLogin.InvoqueType.OVERRIDE_CREDENTIALS.ordinal()); startActivity(login); // DialogLogin dialogLogin = new DialogLogin(Settings.this, serviceDataCaller, DialogLogin.InvoqueType.OVERRIDE_CREDENTIALS); // Toast.makeText(Settings.this, "Login already set", Toast.LENGTH_SHORT).show(); // dialogLogin.show(); } // } return true; case FOLLOW: new DialogFollowOnSocialNets(this, serviceDataCaller).show(); return true; // case SCHEDULED_DOWNLOADS: // availableAdapter.sleep(); // Intent manageScheduled = new Intent(this, ManageScheduled.class); // startActivity(manageScheduled); // return true; // case UPDATE_ALL: // if(!loadingRepos.get()){ // AptoideLog.d(this, "Update all"); // try { // serviceDataCaller.callUpdateAll(); // } catch (RemoteException e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } // }else{ // Toast.makeText(Aptoide.this, "Option not available while updating stores!", Toast.LENGTH_SHORT).show(); // } // return true; default: return super.onOptionsItemSelected(item); } }