Advertisement
Guest User

Untitled

a guest
Jun 14th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. public class Preferences extends PreferenceActivity {
  2.  
  3. /** Called when the activity is first created. */
  4. @Override
  5. public void onCreate(Bundle savedInstanceState) {
  6. super.onCreate(savedInstanceState);
  7. addPreferencesFromResource(R.xml.preferences);
  8. Toast.makeText(Preferences.this, "Set your server settings here", Toast.LENGTH_LONG).show();
  9.  
  10. }
  11.  
  12. }
  13.  
  14.  
  15. *&*@&(&!@^*&#@!^@ IN A DIFFERENT ACTIVITY *&*@&(&!@^*&#@!^@
  16.  
  17. dnloadButton.setOnClickListener(new View.OnClickListener() {
  18. public void onClick(View v) {
  19. getServerSettings();
  20. if(serverSettings == null)
  21. {
  22. Toast.makeText(getApplicationContext(), "Please set your server settings correctly", Toast.LENGTH_LONG).show();
  23. return;
  24. }else if(serverSettings.port == -1 || serverSettings.userName == null || serverSettings.hostName == null || serverSettings.passWord == null)
  25. {
  26. Toast.makeText(getApplicationContext(), "Please set your server settings correctly", Toast.LENGTH_LONG).show();
  27. return;
  28. }else if(DownloadService.downloadQueue.isEmpty())
  29. {
  30. Toast.makeText(getApplicationContext(), " No items in the Download Queue \r\n Add items to the dowload queue from NZB List tab", Toast.LENGTH_LONG).show();
  31. return;
  32. }else
  33. {
  34. Toast beginDownloadToast = Toast.makeText(getApplicationContext(), " Beginning Download\r\n Check the Status tab for more info", Toast.LENGTH_LONG);
  35. beginDownloadToast.show();
  36. DownloadService.serverSettings = serverSettings;
  37. Intent svc = new Intent(getApplicationContext(),DownloadService.class);
  38. startService(svc);
  39. }
  40.  
  41.  
  42. }
  43. });
  44.  
  45. void getServerSettings()
  46. {
  47. if(serverSettings == null)
  48. {
  49. SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
  50.  
  51. serverSettings = new ServerSettings();
  52. serverSettings.hostName = preferences.getString("serverHostname", null);
  53. serverSettings.userName = preferences.getString("username", null);
  54. serverSettings.passWord = preferences.getString("password", null);
  55. serverSettings.requiresSSL = preferences.getBoolean("useSSL", false);
  56. serverSettings.connectTimeoutMs = 2000;
  57. serverSettings.requiresLogin = true;
  58. try
  59. {
  60. serverSettings.port = Integer.parseInt(preferences.getString("portNumber", "N/A"));
  61. }catch(Exception e)
  62. {
  63. serverSettings.port = -1;
  64. }
  65.  
  66.  
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement