List of usage examples for android.app AlertDialog setIcon
public void setIcon(Drawable icon)
From source file:cm.aptoide.pt.ManageRepo.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.repolist);/*from www . ja va 2 s .c om*/ db = new DbHandler(this); Intent i = getIntent(); if (i.hasExtra("empty")) { final String uri = i.getStringExtra("uri"); AlertDialog alrt = new AlertDialog.Builder(this).create(); alrt.setTitle(getString(R.string.title_repo_alrt)); alrt.setIcon(android.R.drawable.ic_dialog_alert); alrt.setMessage(getString(R.string.myrepo_alrt) + uri); alrt.setButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { db.addServer(uri); change = true; redraw(); return; } }); alrt.setButton2("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { return; } }); alrt.show(); } else if (i.hasExtra("uri")) { String uri = i.getStringExtra("uri"); Vector<String> new_serv_lst = getRemoteServLst(uri); for (final String srv : new_serv_lst) { AlertDialog alrt = new AlertDialog.Builder(this).create(); alrt.setTitle(getString(R.string.title_repo_alrt)); alrt.setIcon(android.R.drawable.ic_dialog_alert); alrt.setMessage(getString(R.string.newrepo_alrt) + srv); alrt.setButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { db.addServer(srv); change = true; redraw(); return; } }); alrt.setButton2("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { return; } }); alrt.show(); } } else if (i.hasExtra("newrepo")) { final String repo = i.getStringExtra("newrepo"); AlertDialog alrt = new AlertDialog.Builder(this).create(); alrt.setTitle(getString(R.string.title_repo_alrt)); alrt.setIcon(android.R.drawable.ic_dialog_alert); alrt.setMessage(getString(R.string.newrepo_alrt) + repo); alrt.setButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { db.addServer(repo); change = true; redraw(); return; } }); alrt.setButton2("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { //exit } }); alrt.show(); } }
From source file:goo.TeaTimer.TimerActivity.java
/** { @inheritDoc} */ @Override/*from w w w . j a va 2s .co m*/ public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case PREF: startActivity(new Intent(this, TimerPrefActivity.class)); break; case ABOUT: //new TimerAboutDialog(this).show(); //break; LayoutInflater li = LayoutInflater.from(this); View view = li.inflate(R.layout.about, null); Builder p = new AlertDialog.Builder(this).setView(view); final AlertDialog alrt = p.create(); alrt.setIcon(R.drawable.icon); alrt.setTitle(mImgUrl); alrt.setButton(AlertDialog.BUTTON_NEGATIVE, getString(R.string.close), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }); alrt.show(); return true; default: return false; } return true; }
From source file:org.umit.icm.mobile.gui.ControlActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.controlactivity); WebsiteSuggestButton = (Button) this.findViewById(R.id.suggestWebsite); ServiceSuggestButton = (Button) this.findViewById(R.id.suggestService); scanButton = (Button) this.findViewById(R.id.scanButton); // filterButton = (Button) this.findViewById(R.id.filterButton); // servicesFilterButton = (Button) this.findViewById(R.id.serviceFilterButton); mapSelectionButton = (Button) this.findViewById(R.id.mapSelectionButton); enableTwitterButton = (Button) this.findViewById(R.id.enableTwitterButton); bugReportButton = (Button) this.findViewById(R.id.bugReportButton); aboutButton = (Button) this.findViewById(R.id.aboutButton); scanButton.setText(getString(R.string.scan_text) + " " + getString(R.string.scan_off)); try {//from w w w. j a va 2s . c o m if (Globals.runtimeParameters.getTwitter().equals("Off")) { enableTwitterButton.setText(getString(R.string.enable_twitter_button)); } else { enableTwitterButton.setText(getString(R.string.disable_twitter_button)); } } catch (RuntimeException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } BroadcastReceiver receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals("org.umit.icm.mobile.CONTROL_ACTIVITY")) { scanButton.setText(getString(R.string.scan_text) + " " + getString(R.string.scan_on)); } } }; registerReceiver(receiver, new IntentFilter("org.umit.icm.mobile.CONTROL_ACTIVITY")); WebsiteSuggestButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { WebsiteSuggestionDialog websiteSuggestionDialog = new WebsiteSuggestionDialog(ControlActivity.this, "", new OnReadyListener()); websiteSuggestionDialog.show(); } }); ServiceSuggestButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { ServiceSuggestionDialog suggestionDialog = new ServiceSuggestionDialog(ControlActivity.this, "", new OnReadyListener()); suggestionDialog.show(); } }); enableTwitterButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { try { if (Globals.runtimeParameters.getTwitter().equals("Off")) { progressDialog = ProgressDialog.show(ControlActivity.this, getString(R.string.loading), getString(R.string.retrieving_website), true, false); new LaunchBrowser().execute(); TwitterDialog twitterDialog = new TwitterDialog(ControlActivity.this, ""); twitterDialog.show(); enableTwitterButton.setText(getString(R.string.disable_twitter_button)); } else { Globals.runtimeParameters.setTwitter("Off"); enableTwitterButton.setText(getString(R.string.enable_twitter_button)); } } catch (RuntimeException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); mapSelectionButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { MapSelectionDialog MapSelectionDialog = new MapSelectionDialog(ControlActivity.this, ""); MapSelectionDialog.show(); } }); /* filterButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent intent = new Intent(ControlActivity.this, WebsiteFilterActivity.class); startActivity(intent); } } ); servicesFilterButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent intent = new Intent(ControlActivity.this, ServiceFilterActivity.class); startActivity(intent); } } );*/ bugReportButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent intent = new Intent(ControlActivity.this, BugReportActivity.class); startActivity(intent); } }); aboutButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { String msg = getString(R.string.about_text) + "\n" + getString(R.string.link_to_open_monitor) + "\n" + getString(R.string.link_to_umit) + "\n" + getString(R.string.icons_by); final SpannableString spannableString = new SpannableString(msg); Linkify.addLinks(spannableString, Linkify.ALL); AlertDialog alertDialog = new AlertDialog.Builder(ControlActivity.this).create(); alertDialog.setTitle(getString(R.string.about_button)); alertDialog.setMessage(spannableString); alertDialog.setIcon(R.drawable.umit_128); alertDialog.setButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); alertDialog.show(); } }); scanButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (Globals.scanStatus.equalsIgnoreCase(getString(R.string.scan_on))) { scanButton.setText(getString(R.string.scan_text) + " " + getString(R.string.scan_on)); Globals.scanStatus = getString(R.string.scan_off); stopService(new Intent(ControlActivity.this, ConnectivityService.class)); } else { scanButton.setText(getString(R.string.scan_text) + " " + getString(R.string.scan_off)); Globals.scanStatus = getString(R.string.scan_on); startService(new Intent(ControlActivity.this, ConnectivityService.class)); } try { Globals.runtimeParameters.setScanStatus(Globals.scanStatus); } catch (RuntimeException e) { e.printStackTrace(); } Context context = getApplicationContext(); CharSequence text = getString(R.string.toast_scan_change) + " " + Globals.scanStatus; int duration = Toast.LENGTH_SHORT; Toast toast = Toast.makeText(context, text, duration); toast.show(); } }); }
From source file:net.networksaremadeofstring.cyllell.Search.java
public void MakeHandler() { handler = new Handler() { public void handleMessage(Message msg) { //Once we've checked the data is good to use start processing it if (msg.what == 0) { //TODO ListView population NodeAdapter = new NodeListAdaptor(Search.this, listOfNodes); list.setAdapter(NodeAdapter); //Close the Progress dialog dialog.dismiss();//w ww .j a va 2 s .c o m } else if (msg.what == 200) { dialog.setMessage("Searching for: " + query + "\n\nSending request to Chef..."); } else if (msg.what == 201) { dialog.setMessage("Parsing JSON....."); } else if (msg.what == 202) { dialog.setMessage("Populating UI!"); } else { //Close the Progress dialog dialog.dismiss(); //Alert the user that something went terribly wrong AlertDialog alertDialog = new AlertDialog.Builder(Search.this).create(); alertDialog.setTitle("API Error"); alertDialog.setMessage("There was an error communicating with the API:\n" + msg.getData().getString("exception")); alertDialog.setButton2("Back", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Search.this.finish(); } }); alertDialog.setIcon(R.drawable.error); alertDialog.show(); } } }; }
From source file:group.pals.android.lib.ui.filechooser.utils.ui.bookmark.BookmarkFragment.java
/** * Shows a dialog to let user enter new name or change current name of a * bookmark./*from w w w.jav a 2 s .c om*/ * * @param context * {@link Context} * @param providerId * the provider ID. * @param id * the bookmark ID. * @param uri * the URI to the bookmark. * @param name * the name. To enter new name, this is the suggested name you * provide. To rename, this is the old name. */ public static void doEnterNewNameOrRenameBookmark(final Context context, final String providerId, final int id, final Uri uri, final String name) { final AlertDialog dialog = Dlg.newDlg(context); View view = LayoutInflater.from(context).inflate(R.layout.afc_simple_text_input_view, null); final EditText textName = (EditText) view.findViewById(R.id.afc_text1); textName.setText(name); textName.selectAll(); textName.setHint(R.string.afc_hint_new_name); textName.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE) { Ui.showSoftKeyboard(textName, false); Button btn = dialog.getButton(DialogInterface.BUTTON_POSITIVE); if (btn.isEnabled()) btn.performClick(); return true; } return false; }// onEditorAction() }); dialog.setView(view); dialog.setIcon(R.drawable.afc_bookmarks_dark); dialog.setTitle(id < 0 ? R.string.afc_title_new_bookmark : R.string.afc_title_rename); dialog.setButton(DialogInterface.BUTTON_POSITIVE, context.getString(android.R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String newName = textName.getText().toString().trim(); if (android.text.TextUtils.isEmpty(newName)) { Dlg.toast(context, R.string.afc_msg_bookmark_name_is_invalid, Dlg._LengthShort); return; } Ui.showSoftKeyboard(textName, false); ContentValues values = new ContentValues(); values.put(BookmarkContract.Bookmark._ColumnName, newName); if (id >= 0) { values.put(BookmarkContract.Bookmark._ColumnModificationTime, DbUtils.formatNumber(new Date().getTime())); context.getContentResolver() .update(Uri.withAppendedPath(BookmarkContract.Bookmark._ContentIdUriBase, Uri.encode(Integer.toString(id))), values, null, null); } else { /* * Check if the URI exists or doesn't. If it exists, * update it instead of inserting the new one. */ Cursor cursor = context.getContentResolver().query( BookmarkContract.Bookmark._ContentUri, null, String.format("%s = %s AND %s LIKE %s", BookmarkContract.Bookmark._ColumnProviderId, DatabaseUtils.sqlEscapeString(providerId), BookmarkContract.Bookmark._ColumnUri, DatabaseUtils.sqlEscapeString(uri.toString())), null, null); try { if (cursor != null && cursor.moveToFirst()) { values.put(BookmarkContract.Bookmark._ColumnModificationTime, DbUtils.formatNumber(new Date().getTime())); context.getContentResolver().update( Uri.withAppendedPath(BookmarkContract.Bookmark._ContentIdUriBase, Uri.encode(cursor.getString( cursor.getColumnIndex(BookmarkContract.Bookmark._ID)))), values, null, null); } else { values.put(BookmarkContract.Bookmark._ColumnProviderId, providerId); values.put(BookmarkContract.Bookmark._ColumnUri, uri.toString()); context.getContentResolver().insert(BookmarkContract.Bookmark._ContentUri, values); } } finally { if (cursor != null) cursor.close(); } } Dlg.toast(context, context.getString(R.string.afc_msg_done), Dlg._LengthShort); }// onClick() }); dialog.show(); Ui.showSoftKeyboard(textName, true); final Button buttonOk = dialog.getButton(DialogInterface.BUTTON_POSITIVE); buttonOk.setEnabled(id < 0); textName.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // TODO Auto-generated method stub } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // TODO Auto-generated method stub } @Override public void afterTextChanged(Editable s) { String newName = s.toString().trim(); boolean enabled = !android.text.TextUtils.isEmpty(newName); buttonOk.setEnabled(enabled); /* * If renaming, only enable button OK if new name is not equal * to the old one. */ if (enabled && id >= 0) buttonOk.setEnabled(!newName.equals(name)); } }); }
From source file:cm.aptoide.pt.ScheduledDownloads.java
private void continueLoading() { lv = (ListView) findViewById(android.R.id.list); db = Database.getInstance();/*from w ww .ja v a 2s .c o m*/ adapter = new CursorAdapter(this, null, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER) { @Override public View newView(Context context, Cursor arg1, ViewGroup arg2) { return LayoutInflater.from(context).inflate(R.layout.row_sch_download, null); } @Override public void bindView(View convertView, Context arg1, Cursor c) { // Planet to display ScheduledDownload scheduledDownload = scheduledDownloadsHashMap.get(c.getString(0)); // The child views in each row. CheckBox checkBoxScheduled; TextView textViewName; TextView textViewVersion; ImageView imageViewIcon; // Create a new row view if (convertView.getTag() == null) { // Find the child views. textViewName = (TextView) convertView.findViewById(R.id.name); textViewVersion = (TextView) convertView.findViewById(R.id.appversion); checkBoxScheduled = (CheckBox) convertView.findViewById(R.id.schDwnChkBox); imageViewIcon = (ImageView) convertView.findViewById(R.id.appicon); // Optimization: Tag the row with it's child views, so we don't have to // call findViewById() later when we reuse the row. convertView.setTag(new Holder(textViewName, textViewVersion, checkBoxScheduled, imageViewIcon)); // If CheckBox is toggled, update the planet it is tagged with. checkBoxScheduled.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { CheckBox cb = (CheckBox) v; ScheduledDownload schDownload = (ScheduledDownload) cb.getTag(); schDownload.setChecked(cb.isChecked()); } }); } // Reuse existing row view else { // Because we use a ViewHolder, we avoid having to call findViewById(). Holder viewHolder = (Holder) convertView.getTag(); checkBoxScheduled = viewHolder.checkBoxScheduled; textViewVersion = viewHolder.textViewVersion; textViewName = viewHolder.textViewName; imageViewIcon = viewHolder.imageViewIcon; } // Tag the CheckBox with the Planet it is displaying, so that we can // access the planet in onClick() when the CheckBox is toggled. checkBoxScheduled.setTag(scheduledDownload); // Display planet data checkBoxScheduled.setChecked(scheduledDownload.isChecked()); textViewName.setText(scheduledDownload.getName()); textViewVersion.setText(scheduledDownload.getVername()); // Tag the CheckBox with the Planet it is displaying, so that we can // access the planet in onClick() when the CheckBox is toggled. checkBoxScheduled.setTag(scheduledDownload); // Display planet data checkBoxScheduled.setChecked(scheduledDownload.isChecked()); textViewName.setText(scheduledDownload.getName()); textViewVersion.setText("" + scheduledDownload.getVername()); ImageLoader.getInstance().displayImage(scheduledDownload.getIconPath(), imageViewIcon); } }; lv.setAdapter(adapter); getSupportLoaderManager().initLoader(0, null, this); lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View item, int arg2, long arg3) { ScheduledDownload scheduledDownload = (ScheduledDownload) ((Holder) item.getTag()).checkBoxScheduled .getTag(); scheduledDownload.toggleChecked(); Holder viewHolder = (Holder) item.getTag(); viewHolder.checkBoxScheduled.setChecked(scheduledDownload.isChecked()); } }); IntentFilter filter = new IntentFilter("pt.caixamagica.aptoide.REDRAW"); registerReceiver(receiver, filter); Button installButton = (Button) findViewById(R.id.sch_down); // installButton.setText(getText(R.string.schDown_installselected)); installButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (isAllChecked()) { for (String scheduledDownload : scheduledDownloadsHashMap.keySet()) { if (scheduledDownloadsHashMap.get(scheduledDownload).checked) { ScheduledDownload schDown = scheduledDownloadsHashMap.get(scheduledDownload); ViewApk apk = new ViewApk(); apk.setApkid(schDown.getApkid()); apk.setName(schDown.getName()); apk.setVercode(schDown.getVercode()); apk.setIconPath(schDown.getIconPath()); apk.setVername(schDown.getVername()); apk.setRepoName(schDown.getRepoName()); serviceDownloadManager .startDownloadWithWebservice(serviceDownloadManager.getDownload(apk), apk); Toast toast = Toast.makeText(ScheduledDownloads.this, R.string.starting_download, Toast.LENGTH_SHORT); toast.show(); } } } else { Toast toast = Toast.makeText(ScheduledDownloads.this, R.string.schDown_nodownloadselect, Toast.LENGTH_SHORT); toast.show(); } } }); if (getIntent().hasExtra("downloadAll")) { Builder dialogBuilder = new AlertDialog.Builder(this); final AlertDialog scheduleDownloadDialog = dialogBuilder.create(); scheduleDownloadDialog.setTitle(getText(R.string.schDwnBtn)); scheduleDownloadDialog.setIcon(android.R.drawable.ic_dialog_alert); scheduleDownloadDialog.setCancelable(false); scheduleDownloadDialog.setMessage(getText(R.string.schDown_install)); scheduleDownloadDialog.setButton(Dialog.BUTTON_POSITIVE, getString(android.R.string.yes), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { for (String scheduledDownload : scheduledDownloadsHashMap.keySet()) { ScheduledDownload schDown = scheduledDownloadsHashMap.get(scheduledDownload); ViewApk apk = new ViewApk(); apk.setApkid(schDown.getApkid()); apk.setName(schDown.getName()); apk.setVercode(schDown.getVercode()); apk.setIconPath(schDown.getIconPath()); apk.setVername(schDown.getVername()); apk.setRepoName(schDown.getRepoName()); serviceDownloadManager .startDownloadWithWebservice(serviceDownloadManager.getDownload(apk), apk); Toast toast = Toast.makeText(ScheduledDownloads.this, R.string.starting_download, Toast.LENGTH_SHORT); toast.show(); } finish(); } }); scheduleDownloadDialog.setButton(Dialog.BUTTON_NEGATIVE, getString(android.R.string.no), new Dialog.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { finish(); } }); scheduleDownloadDialog.show(); } }
From source file:com.haibison.android.anhuu.utils.ui.bookmark.BookmarkFragment.java
/** * Shows a dialog to let the user enter new name or change current name of a * bookmark.//from www.ja v a2 s . co m * * @param context * {@link Context} * @param providerId * the provider ID. * @param id * the bookmark ID. * @param uri * the URI to the bookmark. * @param name * the name. To enter new name, this is the suggested name you * provide. To rename, this is the old name. */ public static void doEnterNewNameOrRenameBookmark(final Context context, final String providerId, final int id, final Uri uri, final String name) { final AlertDialog dialog = Dlg.newAlertDlg(context); View view = LayoutInflater.from(context).inflate(R.layout.anhuu_f5be488d_simple_text_input_view, null); final EditText textName = (EditText) view.findViewById(R.id.anhuu_f5be488d_text1); textName.setText(name); textName.selectAll(); textName.setHint(R.string.anhuu_f5be488d_hint_new_name); textName.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE) { UI.showSoftKeyboard(textName, false); Button btn = dialog.getButton(DialogInterface.BUTTON_POSITIVE); if (btn.isEnabled()) btn.performClick(); return true; } return false; }// onEditorAction() }); dialog.setView(view); dialog.setIcon(R.drawable.anhuu_f5be488d_bookmarks_dark); dialog.setTitle(id < 0 ? R.string.anhuu_f5be488d_title_new_bookmark : R.string.anhuu_f5be488d_title_rename); dialog.setButton(DialogInterface.BUTTON_POSITIVE, context.getString(android.R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String newName = textName.getText().toString().trim(); if (android.text.TextUtils.isEmpty(newName)) { Dlg.toast(context, R.string.anhuu_f5be488d_msg_bookmark_name_is_invalid, Dlg.LENGTH_SHORT); return; } UI.showSoftKeyboard(textName, false); ContentValues values = new ContentValues(); values.put(BookmarkContract.COLUMN_NAME, newName); if (id >= 0) { values.put(BookmarkContract.COLUMN_MODIFICATION_TIME, DbUtils.formatNumber(new Date().getTime())); context.getContentResolver().update( ContentUris.withAppendedId(BookmarkContract.genContentIdUriBase(context), id), values, null, null); } else { /* * Check if the URI exists or doesn't. If it exists, * update it instead of inserting the new one. */ Cursor cursor = context.getContentResolver().query( BookmarkContract.genContentUri(context), null, String.format("%s = %s AND %s LIKE %s", BookmarkContract.COLUMN_PROVIDER_ID, DatabaseUtils.sqlEscapeString(providerId), BookmarkContract.COLUMN_URI, DatabaseUtils.sqlEscapeString(uri.toString())), null, null); try { if (cursor != null && cursor.moveToFirst()) { values.put(BookmarkContract.COLUMN_MODIFICATION_TIME, DbUtils.formatNumber(new Date().getTime())); context.getContentResolver().update( Uri.withAppendedPath(BookmarkContract.genContentIdUriBase(context), Uri.encode(cursor.getString( cursor.getColumnIndex(BookmarkContract._ID)))), values, null, null); } else { values.put(BookmarkContract.COLUMN_PROVIDER_ID, providerId); values.put(BookmarkContract.COLUMN_URI, uri.toString()); context.getContentResolver().insert(BookmarkContract.genContentUri(context), values); } } finally { if (cursor != null) cursor.close(); } } Dlg.toast(context, context.getString(R.string.anhuu_f5be488d_msg_done), Dlg.LENGTH_SHORT); }// onClick() }); dialog.show(); UI.showSoftKeyboard(textName, true); final Button buttonOk = dialog.getButton(DialogInterface.BUTTON_POSITIVE); buttonOk.setEnabled(id < 0); textName.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // TODO Auto-generated method stub } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // TODO Auto-generated method stub } @Override public void afterTextChanged(Editable s) { String newName = s.toString().trim(); boolean enabled = !android.text.TextUtils.isEmpty(newName); buttonOk.setEnabled(enabled); /* * If renaming, only enable button OK if new name is not equal * to the old one. */ if (enabled && id >= 0) buttonOk.setEnabled(!newName.equals(name)); } }); }
From source file:net.homelinux.penecoptero.android.citybikes.app.MainActivity.java
private void showAutoNetworkDialog(int method) { AlertDialog alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setIcon(android.R.drawable.ic_dialog_map); final int mth = method; try {//from w ww. j a v a 2s . c om mNDBAdapter.update(); final JSONObject network = mNDBAdapter.getAutomaticNetwork(hOverlay.getPoint(), method); alertDialog.setTitle(R.string.bike_network_alert_success_title); alertDialog.setMessage(getString(R.string.bike_network_alert_success_text0) + ":\n- (" + network.getString("city") + ") " + network.getString("name") + "\n" + getString(R.string.bike_network_alert_success_text1)); alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.sure), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { mNDBAdapter.setManualNetwork(network.getInt("id")); fillData(view_all); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, getString(R.string.try_again), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { showAutoNetworkDialog(0); } }); alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, getString(R.string.manual), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { showBikeNetworks(); } }); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); alertDialog.setTitle(R.string.bike_network_alert_error_title); alertDialog.setMessage(getString(R.string.bike_network_alert_error_text)); alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.try_again), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (mth == 0) showAutoNetworkDialog(1); else showAutoNetworkDialog(0); } }); alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, getString(R.string.manual), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { showBikeNetworks(); } }); } alertDialog.show(); }
From source file:net.homelinux.penecoptero.android.citybikes.donation.app.MainActivity.java
private void fillData(boolean all) { if (mNDBAdapter != null && mNDBAdapter.isConfigured()) { Bundle data = new Bundle(); if (!all) { GeoPoint center = locator.getCurrentGeoPoint(); if (center == null) { //Do something.. int nid = settings.getInt("network_id", -1); //Log.i("CityBikes","Current network is id: "+Integer.toString(nid)); if (nid != -1) { try { mNDBAdapter.load(); JSONObject network = mNDBAdapter.getNetworks(nid); //Log.i("CityBikes",network.toString()); double lat = Integer.parseInt(network.getString("lat")) / 1E6; double lng = Integer.parseInt(network.getString("lng")) / 1E6; Location fallback = new Location("fallback"); fallback.setLatitude(lat); fallback.setLongitude(lng); locator.setFallbackLocation(fallback); locator.unlockCenter(); center = locator.getCurrentGeoPoint(); } catch (Exception e) { //Log.i("CityBikes","We re fucked, that network aint existin"); e.printStackTrace(); }//from www . jav a2 s . c om } else { //Log.i("CityBikes","We re fucked, why re we here?"); } } data.putInt(StationsDBAdapter.CENTER_LAT_KEY, center.getLatitudeE6()); data.putInt(StationsDBAdapter.CENTER_LNG_KEY, center.getLongitudeE6()); data.putInt(StationsDBAdapter.RADIUS_KEY, hOverlay.getRadius()); } progressDialog = new ProgressDialog(this); progressDialog.setTitle(""); progressDialog.setMessage(getString(R.string.loading)); progressDialog.show(); try { mDbHelper.sync(all, data); } catch (Exception e) { ////Log.i("openBicing", "Error Updating?"); e.printStackTrace(); progressDialog.dismiss(); } ; } else { //Log.i("CityBikes","First time!!! :D"); try { mNDBAdapter.update(); AlertDialog alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setIcon(android.R.drawable.ic_dialog_map); alertDialog.setTitle(R.string.bike_network_alert_title); alertDialog.setMessage(getString(R.string.bike_network_alert_text)); alertDialog.setButton(getString(R.string.automatic), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub } }); alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.automatic), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { showAutoNetworkDialog(0); } }); alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, getString(R.string.manual), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { showBikeNetworks(); } }); alertDialog.show(); } catch (Exception e) { e.printStackTrace(); Toast toast = Toast.makeText(getApplicationContext(), getString(R.string.network_error), Toast.LENGTH_LONG); toast.show(); } } }
From source file:net.homelinux.penecoptero.android.citybikes.app.MainActivity.java
private void fillData(boolean all) { if (mNDBAdapter != null && mNDBAdapter.isConfigured()) { Bundle data = new Bundle(); if (!all) { GeoPoint center = locator.getCurrentGeoPoint(); if (center == null) { //Do something.. int nid = settings.getInt("network_id", -1); //Log.i("CityBikes","Current network is id: "+Integer.toString(nid)); if (nid != -1) { try { mNDBAdapter.load(); JSONObject network = mNDBAdapter.getNetworks(nid); //Log.i("CityBikes",network.toString()); double lat = Integer.parseInt(network.getString("lat")) / 1E6; double lng = Integer.parseInt(network.getString("lng")) / 1E6; Location fallback = new Location("fallback"); fallback.setLatitude(lat); fallback.setLongitude(lng); locator.setFallbackLocation(fallback); locator.unlockCenter(); center = locator.getCurrentGeoPoint(); } catch (Exception e) { //Log.i("CityBikes","We re fucked, that network aint existin"); e.printStackTrace(); }//www. j a v a 2 s.c o m } else { //Log.i("CityBikes","We re fucked, why re we here?"); } } data.putInt(StationsDBAdapter.CENTER_LAT_KEY, center.getLatitudeE6()); data.putInt(StationsDBAdapter.CENTER_LNG_KEY, center.getLongitudeE6()); data.putInt(StationsDBAdapter.RADIUS_KEY, hOverlay.getRadius()); } progressDialog = new ProgressDialog(this); progressDialog.setTitle(""); progressDialog.setMessage(getString(R.string.loading)); progressDialog.show(); try { mDbHelper.sync(all, data); } catch (Exception e) { ////Log.i("openBicing", "Error Updating?"); e.printStackTrace(); progressDialog.dismiss(); } ; } else { //Log.i("CityBikes","First time!!! :D"); try { mNDBAdapter.update(); AlertDialog alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setIcon(android.R.drawable.ic_dialog_map); alertDialog.setTitle(R.string.bike_network_alert_title); alertDialog.setMessage(getString(R.string.bike_network_alert_text)); alertDialog.setButton(getString(R.string.automatic), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub } }); alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.automatic), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { showAutoNetworkDialog(0); } }); alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, getString(R.string.manual), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { showBikeNetworks(); } }); alertDialog.show(); } catch (Exception e) { e.printStackTrace(); Toast toast = Toast.makeText(getApplicationContext(), getString(R.string.network_error), Toast.LENGTH_LONG); toast.show(); } } infoLayer.update(); }