List of usage examples for android.content Intent ACTION_SEND
String ACTION_SEND
To view the source code for android.content Intent ACTION_SEND.
Click Source Link
From source file:ch.luklanis.esscan.history.HistoryActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.history_menu_send_dta_save: case R.id.history_menu_send_dta_other: case R.id.history_menu_send_dta_email: { Message message = Message.obtain(mDataSentHandler, item.getItemId()); createDTAFile(message);/*from w w w . j ava 2 s. c om*/ } break; case R.id.history_menu_send_csv: { CharSequence history = mHistoryManager.buildHistory(); Uri historyFile = HistoryManager.saveHistory(history.toString()); String[] recipients = new String[] { PreferenceManager.getDefaultSharedPreferences(this) .getString(PreferencesActivity.KEY_EMAIL_ADDRESS, "") }; if (historyFile == null) { setOkAlert(R.string.msg_unmount_usb); } else { Intent intent = new Intent(Intent.ACTION_SEND, Uri.parse("mailto:")); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); intent.putExtra(Intent.EXTRA_EMAIL, recipients); String subject = getResources().getString(R.string.history_email_title); intent.putExtra(Intent.EXTRA_SUBJECT, subject); intent.putExtra(Intent.EXTRA_TEXT, subject); intent.putExtra(Intent.EXTRA_STREAM, historyFile); intent.setType("text/csv"); startActivity(intent); } } break; case R.id.history_menu_clear: { new CancelOkDialog(R.string.msg_sure).setOkClickListener(new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { mHistoryManager.clearHistory(); dialogInterface.dismiss(); finish(); } }).show(getFragmentManager(), "HistoryActivity.onOptionsItemSelected"); } break; case android.R.id.home: { int error = PsDetailActivity.savePaymentSlip(this); if (error > 0) { setCancelOkAlert(this, error); return true; } NavUtils.navigateUpTo(this, new Intent(this, CaptureActivity.class)); return true; } case R.id.history_menu_copy_code_row: { PsDetailFragment fragment = (PsDetailFragment) getFragmentManager() .findFragmentById(R.id.ps_detail_container); if (fragment != null) { String completeCode = fragment.getHistoryItem().getResult().getCompleteCode(); addCodeRowToClipboard(completeCode); } } break; case R.id.history_menu_send_code_row: { PsDetailFragment fragment = (PsDetailFragment) getFragmentManager() .findFragmentById(R.id.ps_detail_container); if (fragment != null) { IEsrSender sender = getEsrSender(); if (sender != null) { mSendingProgressDialog.show(); fragment.send(PsDetailFragment.SEND_COMPONENT_CODE_ROW, sender, this.historyFragment.getActivatedPosition()); } else { Message message = Message.obtain(mDataSentHandler, R.id.es_send_failed); message.sendToTarget(); } } } break; default: return super.onOptionsItemSelected(item); } return true; }
From source file:edu.stanford.mobisocial.dungbeetle.ui.fragments.FeedActionsFragment.java
private void sendToExternalFriend() { Intent share = new Intent(Intent.ACTION_SEND); share.putExtra(Intent.EXTRA_TEXT,/* w w w . j a va2s . co m*/ "Join me in a Musubi thread: " + ThreadRequest.getInvitationUri(getActivity(), mExternalFeedUri)); share.putExtra(Intent.EXTRA_SUBJECT, "Join me on Musubi!"); share.setType("text/plain"); startActivity(share); }
From source file:com.andrewshu.android.reddit.submit.SubmitLinkActivity.java
/** * Enable the UI after user is logged in. *//*from www .java 2s . c o m*/ private void start() { // Intents can be external (browser share page) or from Reddit is fun. String intentAction = getIntent().getAction(); if (Intent.ACTION_SEND.equals(intentAction)) { // Share Bundle extras = getIntent().getExtras(); if (extras != null) { String url = extras.getString(Intent.EXTRA_TEXT); final EditText submitLinkUrl = (EditText) findViewById(R.id.submit_link_url); final EditText submitLinkReddit = (EditText) findViewById(R.id.submit_link_reddit); final EditText submitTextReddit = (EditText) findViewById(R.id.submit_text_reddit); submitLinkUrl.setText(url); submitLinkReddit.setText(""); submitTextReddit.setText(""); mSubmitUrl = Constants.REDDIT_BASE_URL + "/submit"; } } else { String submitPath = null; Uri data = getIntent().getData(); if (data != null && Util.isRedditUri(data)) submitPath = data.getPath(); if (submitPath == null) submitPath = "/submit"; // the URL to do HTTP POST to mSubmitUrl = Util.absolutePathToURL(submitPath); // Put the subreddit in the text field final EditText submitLinkReddit = (EditText) findViewById(R.id.submit_link_reddit); final EditText submitTextReddit = (EditText) findViewById(R.id.submit_text_reddit); Matcher m = SUBMIT_PATH_PATTERN.matcher(submitPath); if (m.matches()) { String subreddit = m.group(1); if (StringUtils.isEmpty(subreddit)) { submitLinkReddit.setText(""); submitTextReddit.setText(""); } else { submitLinkReddit.setText(subreddit); submitTextReddit.setText(subreddit); } } } final Button submitLinkButton = (Button) findViewById(R.id.submit_link_button); submitLinkButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (validateLinkForm()) { final EditText submitLinkTitle = (EditText) findViewById(R.id.submit_link_title); final EditText submitLinkUrl = (EditText) findViewById(R.id.submit_link_url); final EditText submitLinkReddit = (EditText) findViewById(R.id.submit_link_reddit); final EditText submitLinkCaptcha = (EditText) findViewById(R.id.submit_link_captcha); new SubmitLinkTask(submitLinkTitle.getText().toString(), submitLinkUrl.getText().toString(), submitLinkReddit.getText().toString(), Constants.SUBMIT_KIND_LINK, submitLinkCaptcha.getText().toString()).execute(); } } }); final Button submitTextButton = (Button) findViewById(R.id.submit_text_button); submitTextButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (validateTextForm()) { final EditText submitTextTitle = (EditText) findViewById(R.id.submit_text_title); final EditText submitTextText = (EditText) findViewById(R.id.submit_text_text); final EditText submitTextReddit = (EditText) findViewById(R.id.submit_text_reddit); final EditText submitTextCaptcha = (EditText) findViewById(R.id.submit_text_captcha); new SubmitLinkTask(submitTextTitle.getText().toString(), submitTextText.getText().toString(), submitTextReddit.getText().toString(), Constants.SUBMIT_KIND_SELF, submitTextCaptcha.getText().toString()).execute(); } } }); // Check the CAPTCHA new MyCaptchaCheckRequiredTask().execute(); }
From source file:in.shick.diode.submit.SubmitLinkActivity.java
/** * Enable the UI after user is logged in. *///from w w w. j av a2s . c o m private void start() { // Intents can be external (browser share page) or from Reddit is fun. String intentAction = getIntent().getAction(); if (Intent.ACTION_SEND.equals(intentAction)) { // Share Bundle extras = getIntent().getExtras(); SubmissionProperties submissionProperties = new SubmissionProperties(); boolean ignored = defaultExtractProperties(extras, submissionProperties) || lastDitchExtractProperties(extras, submissionProperties); final EditText submitLinkUrl = (EditText) findViewById(R.id.submit_link_url); final EditText submitLinkReddit = (EditText) findViewById(R.id.submit_link_reddit); final EditText submitLinkTitle = (EditText) findViewById(R.id.submit_link_title); final EditText submitTextReddit = (EditText) findViewById(R.id.submit_text_reddit); submitLinkUrl.setText(submissionProperties.url); submitLinkReddit.setText(""); submitTextReddit.setText(""); submitLinkTitle.setText(submissionProperties.title); mSubmitUrl = Constants.REDDIT_BASE_URL + "/submit"; } else { String submitPath = null; Uri data = getIntent().getData(); if (data != null && Util.isRedditUri(data)) submitPath = data.getPath(); if (submitPath == null) submitPath = "/submit"; // the URL to do HTTP POST to mSubmitUrl = Util.absolutePathToURL(submitPath); // Put the subreddit in the text field final EditText submitLinkReddit = (EditText) findViewById(R.id.submit_link_reddit); final EditText submitTextReddit = (EditText) findViewById(R.id.submit_text_reddit); Matcher m = SUBMIT_PATH_PATTERN.matcher(submitPath); if (m.matches()) { String subreddit = m.group(1); if (StringUtils.isEmpty(subreddit)) { submitLinkReddit.setText(""); submitTextReddit.setText(""); } else { submitLinkReddit.setText(subreddit); submitTextReddit.setText(subreddit); } } } final Button submitLinkButton = (Button) findViewById(R.id.submit_link_button); submitLinkButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (validateLinkForm()) { final EditText submitLinkTitle = (EditText) findViewById(R.id.submit_link_title); final EditText submitLinkUrl = (EditText) findViewById(R.id.submit_link_url); final EditText submitLinkReddit = (EditText) findViewById(R.id.submit_link_reddit); final EditText submitLinkCaptcha = (EditText) findViewById(R.id.submit_link_captcha); new SubmitLinkTask(submitLinkTitle.getText().toString(), submitLinkUrl.getText().toString(), submitLinkReddit.getText().toString(), Constants.SUBMIT_KIND_LINK, submitLinkCaptcha.getText().toString()).execute(); } } }); final Button submitTextButton = (Button) findViewById(R.id.submit_text_button); submitTextButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (validateTextForm()) { final EditText submitTextTitle = (EditText) findViewById(R.id.submit_text_title); final EditText submitTextText = (EditText) findViewById(R.id.submit_text_text); final EditText submitTextReddit = (EditText) findViewById(R.id.submit_text_reddit); final EditText submitTextCaptcha = (EditText) findViewById(R.id.submit_text_captcha); new SubmitLinkTask(submitTextTitle.getText().toString(), submitTextText.getText().toString(), submitTextReddit.getText().toString(), Constants.SUBMIT_KIND_SELF, submitTextCaptcha.getText().toString()).execute(); } } }); // Check the CAPTCHA new MyCaptchaCheckRequiredTask().execute(); }
From source file:org.tomahawk.tomahawk_android.utils.TomahawkExceptionReporter.java
/** * Pull information from the given {@link CrashReportData} and send it via HTTP to * oops.tomahawk-player.org or sends it as a TEXT intent, if IS_SILENT is true *//* ww w. j a v a2s .c o m*/ @Override public void send(CrashReportData data) throws ReportSenderException { StringBuilder body = new StringBuilder(); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); nameValuePairs.add(new BasicNameValuePair("Version", data.getProperty(ReportField.APP_VERSION_NAME))); nameValuePairs.add(new BasicNameValuePair("BuildID", data.getProperty(ReportField.BUILD))); nameValuePairs.add(new BasicNameValuePair("ProductName", "tomahawk-android")); nameValuePairs.add(new BasicNameValuePair("Vendor", "Tomahawk")); nameValuePairs.add(new BasicNameValuePair("timestamp", data.getProperty(ReportField.USER_CRASH_DATE))); for (NameValuePair pair : nameValuePairs) { body.append("--thkboundary\r\n"); body.append("Content-Disposition: form-data; name=\""); body.append(pair.getName()).append("\"\r\n\r\n").append(pair.getValue()).append("\r\n"); } body.append("--thkboundary\r\n"); body.append("Content-Disposition: form-data; name=\"upload_file_minidump\"; filename=\"") .append(data.getProperty(ReportField.REPORT_ID)).append("\"\r\n"); body.append("Content-Type: application/octet-stream\r\n\r\n"); body.append("============== Tomahawk Exception Report ==============\r\n\r\n"); body.append("Report ID: ").append(data.getProperty(ReportField.REPORT_ID)).append("\r\n"); body.append("App Start Date: ").append(data.getProperty(ReportField.USER_APP_START_DATE)).append("\r\n"); body.append("Crash Date: ").append(data.getProperty(ReportField.USER_CRASH_DATE)).append("\r\n\r\n"); body.append("--------- Phone Details ----------\r\n"); body.append("Phone Model: ").append(data.getProperty(ReportField.PHONE_MODEL)).append("\r\n"); body.append("Brand: ").append(data.getProperty(ReportField.BRAND)).append("\r\n"); body.append("Product: ").append(data.getProperty(ReportField.PRODUCT)).append("\r\n"); body.append("Display: ").append(data.getProperty(ReportField.DISPLAY)).append("\r\n"); body.append("-----------------------------------\r\n\r\n"); body.append("----------- Stack Trace -----------\r\n"); body.append(data.getProperty(ReportField.STACK_TRACE)).append("\r\n"); body.append("-----------------------------------\r\n\r\n"); body.append("------- Operating System ---------\r\n"); body.append("App Version Name: ").append(data.getProperty(ReportField.APP_VERSION_NAME)).append("\r\n"); body.append("Total Mem Size: ").append(data.getProperty(ReportField.TOTAL_MEM_SIZE)).append("\r\n"); body.append("Available Mem Size: ").append(data.getProperty(ReportField.AVAILABLE_MEM_SIZE)).append("\r\n"); body.append("Dumpsys Meminfo: ").append(data.getProperty(ReportField.DUMPSYS_MEMINFO)).append("\r\n"); body.append("-----------------------------------\r\n\r\n"); body.append("-------------- Misc ---------------\r\n"); body.append("Package Name: ").append(data.getProperty(ReportField.PACKAGE_NAME)).append("\r\n"); body.append("File Path: ").append(data.getProperty(ReportField.FILE_PATH)).append("\r\n"); body.append("Android Version: ").append(data.getProperty(ReportField.ANDROID_VERSION)).append("\r\n"); body.append("Build: ").append(data.getProperty(ReportField.BUILD)).append("\r\n"); body.append("Initial Configuration: ").append(data.getProperty(ReportField.INITIAL_CONFIGURATION)) .append("\r\n"); body.append("Crash Configuration: ").append(data.getProperty(ReportField.CRASH_CONFIGURATION)) .append("\r\n"); body.append("Settings Secure: ").append(data.getProperty(ReportField.SETTINGS_SECURE)).append("\r\n"); body.append("User Email: ").append(data.getProperty(ReportField.USER_EMAIL)).append("\r\n"); body.append("User Comment: ").append(data.getProperty(ReportField.USER_COMMENT)).append("\r\n"); body.append("-----------------------------------\r\n\r\n"); body.append("---------------- Logs -------------\r\n"); body.append("Logcat: ").append(data.getProperty(ReportField.LOGCAT)).append("\r\n\r\n"); body.append("Events Log: ").append(data.getProperty(ReportField.EVENTSLOG)).append("\r\n\r\n"); body.append("Radio Log: ").append(data.getProperty(ReportField.RADIOLOG)).append("\r\n"); body.append("-----------------------------------\r\n\r\n"); body.append("=======================================================\r\n\r\n"); body.append("--thkboundary\r\n"); body.append( "Content-Disposition: form-data; name=\"upload_file_tomahawklog\"; filename=\"Tomahawk.log\"\r\n"); body.append("Content-Type: text/plain\r\n\r\n"); body.append(data.getProperty(ReportField.LOGCAT)); body.append("\r\n--thkboundary--\r\n"); if ("true".equals(data.getProperty(ReportField.IS_SILENT))) { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); body.insert(0, "Please tell us why you're sending us this log:\n\n\n\n\n"); intent.putExtra(Intent.EXTRA_TEXT, body.toString()); intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "support@tomahawk-player.org" }); intent.putExtra(Intent.EXTRA_SUBJECT, "Tomahawk Android Log"); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); TomahawkApp.getContext().startActivity(intent); } else { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://oops.tomahawk-player.org/addreport.php"); httppost.setHeader("Content-type", "multipart/form-data; boundary=thkboundary"); try { httppost.setEntity(new StringEntity(body.toString())); httpclient.execute(httppost); } catch (ClientProtocolException e) { Log.e(TAG, "send: " + e.getClass() + ": " + e.getLocalizedMessage()); } catch (IOException e) { Log.e(TAG, "send: " + e.getClass() + ": " + e.getLocalizedMessage()); } } }
From source file:com.richtodd.android.quiltdesign.app.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { int itemId = item.getItemId(); switch (itemId) { case R.id.menu_settings: { Intent intent = new Intent(this, MainPreferenceActivity.class); startActivity(intent);//from ww w.j a va 2 s . c om return true; } case R.id.menu_about: { TextDialogFragment dialog = TextDialogFragment.create("About Quilt Design", getString(R.string.about), "Close"); dialog.show(getFragmentManager(), null); return true; } case R.id.menu_help: { // Intent intent = new Intent(this, BrowserActivity.class); // intent.putExtra(BrowserActivity.ARG_URL, // "http://quiltdesign.richtodd.com"); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://quiltdesign.richtodd.com")); startActivity(intent); return true; } case R.id.menu_backup: { Uri uriFile; try { uriFile = saveRepository(); Intent intent = new Intent(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_STREAM, uriFile); intent.setType("application/vnd.richtodd.quiltdesign"); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); startActivity(Intent.createChooser(intent, "Backup")); } catch (RepositoryException e) { Handle.asRuntimeError(e); } return true; } case R.id.menu_loadSamples: { SampleLoaderTask task = new SampleLoaderTask(); setSampleLoaderTask(task); task.execute(this); return true; } } return super.onOptionsItemSelected(item); }
From source file:com.willhauck.linconnectclient.SettingsActivity.java
@SuppressLint("SimpleDateFormat") private void setupSimplePreferencesScreen() { // Load preferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(SettingsActivity.this); // Add preferences from XML addPreferencesFromResource(R.xml.pref_general); bindPreferenceSummaryToValue(findPreference("pref_ip")); // Preference Categories serverCategory = ((PreferenceCategory) findPreference("cat_servers")); // Preferences refreshPreference = ((Preference) findPreference("pref_refresh")); serverCategory.removePreference(refreshPreference); loadingPreference = ((Preference) findPreference("pref_loading")); serverCategory.removePreference(loadingPreference); Preference prefEnable = findPreference("pref_enable"); prefEnable.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override//from w ww . j a v a2s . co m public boolean onPreferenceClick(Preference arg0) { // If Android 4.3+, open Notification Listener settings, // otherwise open accessibility settings if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) { startActivityForResult(new Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS), 0); } else { Intent intent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"); startActivity(intent); } return true; } }); ((Preference) findPreference("pref_ip")).setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference arg0, Object arg1) { // Update Custom IP address summary arg0.setSummary((String) arg1); refreshServerList(); // Create and send test notification SimpleDateFormat sf = new SimpleDateFormat("HH:mm:ss"); Object[] notif = new Object[3]; notif[0] = "Hello from Android!"; notif[1] = "Test succesful @ " + sf.format(new Date()); notif[2] = SettingsActivity.this.getResources().getDrawable(R.drawable.ic_launcher); new TestTask().execute(notif); return true; } }); Preference prefDownload = findPreference("pref_download"); prefDownload.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference arg0) { // Create share dialog with server download URL Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, "Download LinConnect server @ https://github.com/hauckwill/linconnect-server"); sendIntent.setType("text/plain"); startActivity(sendIntent); return true; } }); Preference prefApplication = findPreference("pref_application"); prefApplication.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference arg0) { // Open application settings screen Intent intent = new Intent(getApplicationContext(), ApplicationSettingsActivity.class); startActivity(intent); return true; } }); Preference prefDonateBitcoin = findPreference("pref_donate_btc"); prefDonateBitcoin.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference arg0) { try { // Open installed Bitcoin wallet if possible Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse( "bitcoin:1125MguyS1feaop99bCDPQG6ukUcMuvVBo?label=Will%20Hauck&message=Donation%20for%20LinConnect")); startActivity(intent); } catch (Exception e) { // Otherwise, show dialog with Bitcoin address EditText input = new EditText(SettingsActivity.this); input.setText("1125MguyS1feaop99bCDPQG6ukUcMuvVBo"); input.setEnabled(false); new AlertDialog.Builder(SettingsActivity.this).setTitle("Bitcoin Address") .setMessage( "Please donate to the following Bitcoin address. Thank you for the support.") .setView(input) .setPositiveButton("Copy Address", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService( Context.CLIPBOARD_SERVICE); clipboard.setText("1125MguyS1feaop99bCDPQG6ukUcMuvVBo"); } }).setNegativeButton("Okay", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }).show(); } return true; } }); Preference prefGooglePlus = findPreference("pref_google_plus"); prefGooglePlus.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference arg0) { // Open Google Plus page Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("https://plus.google.com/114633032648182423928/posts")); startActivity(intent); return true; } }); Preference prefDonatePlay = findPreference("pref_donate_play"); prefDonatePlay.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference arg0) { // Open Donation Key app on Play Store Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("market://details?id=com.willhauck.donation")); startActivity(intent); return true; } }); // Create handler to process a detected server serverFoundHandler = new Handler(new Handler.Callback() { @Override public boolean handleMessage(Message msg) { if (msg.obj != null) { javax.jmdns.ServiceInfo serviceInfo = mJmDNS.getServiceInfo(jmDnsServiceType, (String) msg.obj); // Get info about server String name = serviceInfo.getName(); String port = String.valueOf(serviceInfo.getPort()); String ip = serviceInfo.getHostAddresses()[0]; // Create a preference representing the server Preference p = new Preference(SettingsActivity.this); p.setTitle(name); p.setSummary(ip + ":" + port); p.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference arg0) { refreshServerList(); // Save IP address in preferences Editor e = sharedPreferences.edit(); e.putString("pref_ip", arg0.getSummary().toString()); e.apply(); // Create and send test notification SimpleDateFormat sf = new SimpleDateFormat("HH:mm:ss"); Object[] notif = new Object[3]; notif[0] = "Hello from Android!"; notif[1] = "Test succesful @ " + sf.format(new Date()); notif[2] = SettingsActivity.this.getResources().getDrawable(R.drawable.ic_launcher); new TestTask().execute(notif); return true; } }); // Add preference to server list if it doesn't already exist boolean found = false; for (int i = 0; i < serverCategory.getPreferenceCount(); i++) { if (serverCategory.getPreference(i) != null && serverCategory.getPreference(i).getTitle() != null && serverCategory.getPreference(i).getTitle().equals(p.getTitle())) { found = true; } } if (!found) { serverCategory.addPreference(p); } refreshServerList(); // Remove loading indicator, add refresh indicator if it // isn't already there if (findPreference("pref_loading") != null) serverCategory.removePreference(findPreference("pref_loading")); if (findPreference("pref_refresh") == null) serverCategory.addPreference(refreshPreference); } return true; } }); // Create task to scan for servers class ServerScanTask extends AsyncTask<String, ServiceEvent, Boolean> { @Override protected void onPreExecute() { // Remove refresh preference, add loading preference if (findPreference("pref_refresh") != null) serverCategory.removePreference(refreshPreference); serverCategory.addPreference(loadingPreference); try { mJmDNS.removeServiceListener(jmDnsServiceType, ServerListener); } catch (Exception e) { } refreshServerList(); } @Override protected Boolean doInBackground(String... notif) { WifiInfo wifiinfo = mWifiManager.getConnectionInfo(); int intaddr = wifiinfo.getIpAddress(); // Ensure there is an active Wifi connection if (intaddr != 0) { byte[] byteaddr = new byte[] { (byte) (intaddr & 0xff), (byte) (intaddr >> 8 & 0xff), (byte) (intaddr >> 16 & 0xff), (byte) (intaddr >> 24 & 0xff) }; InetAddress addr = null; try { addr = InetAddress.getByAddress(byteaddr); } catch (UnknownHostException e1) { } // Create Multicast lock (required for JmDNS) mMulticastLock = mWifiManager.createMulticastLock("LinConnect"); mMulticastLock.setReferenceCounted(true); mMulticastLock.acquire(); try { mJmDNS = JmDNS.create(addr, "LinConnect"); } catch (IOException e) { } // Create listener for detected servers ServerListener = new ServiceListener() { @Override public void serviceAdded(ServiceEvent arg0) { final String name = arg0.getName(); // Send the server data to the handler, delayed by // 500ms to ensure all information is read serverFoundHandler.sendMessageDelayed(Message.obtain(serverFoundHandler, -1, name), 500); } @Override public void serviceRemoved(ServiceEvent arg0) { } @Override public void serviceResolved(ServiceEvent arg0) { mJmDNS.requestServiceInfo(arg0.getType(), arg0.getName(), 1); } }; mJmDNS.addServiceListener(jmDnsServiceType, ServerListener); return true; } return false; } @Override protected void onPostExecute(Boolean result) { if (!result) { // Notify user if there is no connection if (findPreference("pref_loading") != null) { serverCategory.removePreference(findPreference("pref_loading")); serverCategory.addPreference(refreshPreference); } Toast.makeText(getApplicationContext(), "Error: no connection.", Toast.LENGTH_LONG).show(); } } } refreshPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference arg0) { new ServerScanTask().execute(); return true; } }); // Start scanning for servers new ServerScanTask().execute(); }
From source file:com.harshad.linconnectclient.SettingsActivity.java
@SuppressLint("SimpleDateFormat") private void setupSimplePreferencesScreen() { // Load preferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(SettingsActivity.this); // Add preferences from XML addPreferencesFromResource(R.xml.pref_general); bindPreferenceSummaryToValue(findPreference("pref_ip")); // Preference Categories serverCategory = ((PreferenceCategory) findPreference("cat_servers")); // Preferences refreshPreference = ((Preference) findPreference("pref_refresh")); serverCategory.removePreference(refreshPreference); loadingPreference = ((Preference) findPreference("pref_loading")); serverCategory.removePreference(loadingPreference); Preference prefEnable = findPreference("pref_enable"); prefEnable.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override// www .ja va2 s.c o m public boolean onPreferenceClick(Preference arg0) { // If Android 4.3+, open Notification Listener settings, // otherwise open accessibility settings if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) { startActivityForResult(new Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS), 0); } else { Intent intent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"); startActivity(intent); } return true; } }); ((Preference) findPreference("pref_ip")).setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference arg0, Object arg1) { // Update Custom IP address summary arg0.setSummary((String) arg1); refreshServerList(); // Create and send test notification SimpleDateFormat sf = new SimpleDateFormat("HH:mm:ss"); Object[] notif = new Object[3]; notif[0] = "Hello from Android!"; notif[1] = "Test succesful @ " + sf.format(new Date()); notif[2] = SettingsActivity.this.getResources().getDrawable(R.drawable.ic_launcher); new TestTask().execute(notif); return true; } }); Preference prefDownload = findPreference("pref_download"); prefDownload.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference arg0) { // Create share dialog with server download URL Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, "Download LinConnect server @ https://github.com/hauckwill/linconnect-server"); sendIntent.setType("text/plain"); startActivity(sendIntent); return true; } }); Preference prefApplication = findPreference("pref_application"); prefApplication.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference arg0) { // Open application settings screen Intent intent = new Intent(getApplicationContext(), ApplicationSettingsActivity.class); startActivity(intent); return true; } }); // Preference prefDonateBitcoin = findPreference("pref_donate_btc"); // prefDonateBitcoin // .setOnPreferenceClickListener(new OnPreferenceClickListener() { // @Override // public boolean onPreferenceClick(Preference arg0) { // try { // Open installed Bitcoin wallet if possible // Intent intent = new Intent(Intent.ACTION_VIEW); // intent.setData(Uri // .parse("bitcoin:1125MguyS1feaop99bCDPQG6ukUcMuvVBo?label=Will%20Hauck&message=Donation%20for%20LinConnect")); // startActivity(intent); // } catch (Exception e) { // Otherwise, show dialog with Bitcoin address // EditText input = new EditText(SettingsActivity.this); // input.setText("1125MguyS1feaop99bCDPQG6ukUcMuvVBo"); // input.setEnabled(false); // new AlertDialog.Builder(SettingsActivity.this) // .setTitle("Bitcoin Address") // .setMessage( // "Please donate to the following Bitcoin address. Thank you for the support.") // .setView(input) // .setPositiveButton( // "Copy Address", // new DialogInterface.OnClickListener() { // public void onClick( // DialogInterface dialog, // int whichButton) { // android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); // clipboard // .setText("1125MguyS1feaop99bCDPQG6ukUcMuvVBo"); // } // }) // .setNegativeButton( // "Okay", // new DialogInterface.OnClickListener() { // public void onClick( // DialogInterface dialog, // int whichButton) { // } // }).show(); // } // return true; // } // }); // Preference prefGooglePlus = findPreference("pref_google_plus"); // prefGooglePlus // .setOnPreferenceClickListener(new OnPreferenceClickListener() { // @Override // public boolean onPreferenceClick(Preference arg0) { // // Open Google Plus page // Intent intent = new Intent(Intent.ACTION_VIEW); // intent.setData(Uri // .parse("https://plus.google.com/114633032648182423928/posts")); // startActivity(intent); // return true; // } // }); // Preference prefDonatePlay = findPreference("pref_donate_play"); // prefDonatePlay // .setOnPreferenceClickListener(new OnPreferenceClickListener() { // @Override // public boolean onPreferenceClick(Preference arg0) { // Open Donation Key app on Play Store // Intent intent = new Intent(Intent.ACTION_VIEW); // intent.setData(Uri // .parse("market://details?id=com.willhauck.donation")); // startActivity(intent); // return true; // } // }); // Create handler to process a detected server serverFoundHandler = new Handler(new Handler.Callback() { @Override public boolean handleMessage(Message msg) { if (msg.obj != null) { javax.jmdns.ServiceInfo serviceInfo = mJmDNS.getServiceInfo(jmDnsServiceType, (String) msg.obj); // Get info about server String name = serviceInfo.getName(); String port = String.valueOf(serviceInfo.getPort()); String ip = serviceInfo.getHostAddresses()[0]; // Create a preference representing the server Preference p = new Preference(SettingsActivity.this); p.setTitle(name); p.setSummary(ip + ":" + port); p.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference arg0) { refreshServerList(); // Save IP address in preferences Editor e = sharedPreferences.edit(); e.putString("pref_ip", arg0.getSummary().toString()); e.apply(); // Create and send test notification SimpleDateFormat sf = new SimpleDateFormat("HH:mm:ss"); Object[] notif = new Object[3]; notif[0] = "Hello from Android!"; notif[1] = "Test succesful @ " + sf.format(new Date()); notif[2] = SettingsActivity.this.getResources().getDrawable(R.drawable.ic_launcher); new TestTask().execute(notif); return true; } }); // Add preference to server list if it doesn't already exist boolean found = false; for (int i = 0; i < serverCategory.getPreferenceCount(); i++) { if (serverCategory.getPreference(i) != null && serverCategory.getPreference(i).getTitle() != null && serverCategory.getPreference(i).getTitle().equals(p.getTitle())) { found = true; } } if (!found) { serverCategory.addPreference(p); } refreshServerList(); // Remove loading indicator, add refresh indicator if it // isn't already there if (findPreference("pref_loading") != null) serverCategory.removePreference(findPreference("pref_loading")); if (findPreference("pref_refresh") == null) serverCategory.addPreference(refreshPreference); } return true; } }); // Create task to scan for servers class ServerScanTask extends AsyncTask<String, ServiceEvent, Boolean> { @Override protected void onPreExecute() { // Remove refresh preference, add loading preference if (findPreference("pref_refresh") != null) serverCategory.removePreference(refreshPreference); serverCategory.addPreference(loadingPreference); try { mJmDNS.removeServiceListener(jmDnsServiceType, ServerListener); } catch (Exception e) { } refreshServerList(); } @Override protected Boolean doInBackground(String... notif) { WifiInfo wifiinfo = mWifiManager.getConnectionInfo(); int intaddr = wifiinfo.getIpAddress(); // Ensure there is an active Wifi connection if (intaddr != 0) { byte[] byteaddr = new byte[] { (byte) (intaddr & 0xff), (byte) (intaddr >> 8 & 0xff), (byte) (intaddr >> 16 & 0xff), (byte) (intaddr >> 24 & 0xff) }; InetAddress addr = null; try { addr = InetAddress.getByAddress(byteaddr); } catch (UnknownHostException e1) { } // Create Multicast lock (required for JmDNS) mMulticastLock = mWifiManager.createMulticastLock("LinConnect"); mMulticastLock.setReferenceCounted(true); mMulticastLock.acquire(); try { mJmDNS = JmDNS.create(addr, "LinConnect"); } catch (IOException e) { } // Create listener for detected servers ServerListener = new ServiceListener() { @Override public void serviceAdded(ServiceEvent arg0) { final String name = arg0.getName(); // Send the server data to the handler, delayed by // 500ms to ensure all information is read serverFoundHandler.sendMessageDelayed(Message.obtain(serverFoundHandler, -1, name), 500); } @Override public void serviceRemoved(ServiceEvent arg0) { } @Override public void serviceResolved(ServiceEvent arg0) { mJmDNS.requestServiceInfo(arg0.getType(), arg0.getName(), 1); } }; mJmDNS.addServiceListener(jmDnsServiceType, ServerListener); return true; } return false; } @Override protected void onPostExecute(Boolean result) { if (!result) { // Notify user if there is no connection if (findPreference("pref_loading") != null) { serverCategory.removePreference(findPreference("pref_loading")); serverCategory.addPreference(refreshPreference); } Toast.makeText(getApplicationContext(), "Error: no connection.", Toast.LENGTH_LONG).show(); } } } refreshPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference arg0) { new ServerScanTask().execute(); return true; } }); // Start scanning for servers new ServerScanTask().execute(); }
From source file:com.z.stproperty.PropertyDetailFragment.java
/** * onClick :: OnClickListener//from w ww .j a va 2 s.co m * * Is common on-click listener for all the buttons and images in home screen * This is grouped into single listener to make easier to alter the code and reduce the * line of code. * * This will check the View ID to match with the predefined View-ID to identify * which view is clicked * * Based on the view id this will perform different functionalities */ private void performClickAction(View v) { try { switch (v.getId()) { case R.id.LoanCalculator: Intent calIntent = new Intent(getActivity(), LoanCalculator.class); calIntent.putExtra("price", price); startActivity(calIntent); break; case R.id.AgentMobile: String url = "tel:" + mobileNoStr; url = url.replace("+65-", ""); Intent callIntent = new Intent(Intent.ACTION_CALL); callIntent.setData(Uri.parse(url)); startActivity(callIntent); break; case R.id.SendEmailBtn: String text = "I'm interested in your property advertised on STProperty\n\n" + "PROPERTY TITLE:" + title + "\n" + "PRICE:" + price + "\n\nClick on the following link to view more details about the property\n\n" + prurl; Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("plain/text"); intent.putExtra(Intent.EXTRA_EMAIL, new String[] { agentEmail }); intent.putExtra(Intent.EXTRA_SUBJECT, "Enquiry"); intent.putExtra(Intent.EXTRA_TEXT, text); SharedFunction.postAnalytics(PropertyDetailFragment.this.getActivity(), "Lead", "Successful Email Enquiry", title); startActivity(Intent.createChooser(intent, "")); break; /**case R.id.SendEnquiryBtn: Intent enqInt = new Intent(getActivity(), SaleEnquiry.class); enqInt.putExtra("propertyId", detailsJson.getString("id")); enqInt.putExtra("agentId", detailsJson.getJSONObject("seller_info").getString("agent_cea_reg_no")); startActivity(enqInt); break;*/ default: break; } } catch (Exception e) { Log.e(this.getClass().getSimpleName(), e.getLocalizedMessage(), e); } }