Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Preferences extends PreferenceActivity {
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- addPreferencesFromResource(R.xml.preferences);
- Toast.makeText(Preferences.this, "Set your server settings here", Toast.LENGTH_LONG).show();
- }
- }
- *&*@&(&!@^*&#@!^@ IN A DIFFERENT ACTIVITY *&*@&(&!@^*&#@!^@
- dnloadButton.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- getServerSettings();
- if(serverSettings == null)
- {
- Toast.makeText(getApplicationContext(), "Please set your server settings correctly", Toast.LENGTH_LONG).show();
- return;
- }else if(serverSettings.port == -1 || serverSettings.userName == null || serverSettings.hostName == null || serverSettings.passWord == null)
- {
- Toast.makeText(getApplicationContext(), "Please set your server settings correctly", Toast.LENGTH_LONG).show();
- return;
- }else if(DownloadService.downloadQueue.isEmpty())
- {
- 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();
- return;
- }else
- {
- Toast beginDownloadToast = Toast.makeText(getApplicationContext(), " Beginning Download\r\n Check the Status tab for more info", Toast.LENGTH_LONG);
- beginDownloadToast.show();
- DownloadService.serverSettings = serverSettings;
- Intent svc = new Intent(getApplicationContext(),DownloadService.class);
- startService(svc);
- }
- }
- });
- void getServerSettings()
- {
- if(serverSettings == null)
- {
- SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
- serverSettings = new ServerSettings();
- serverSettings.hostName = preferences.getString("serverHostname", null);
- serverSettings.userName = preferences.getString("username", null);
- serverSettings.passWord = preferences.getString("password", null);
- serverSettings.requiresSSL = preferences.getBoolean("useSSL", false);
- serverSettings.connectTimeoutMs = 2000;
- serverSettings.requiresLogin = true;
- try
- {
- serverSettings.port = Integer.parseInt(preferences.getString("portNumber", "N/A"));
- }catch(Exception e)
- {
- serverSettings.port = -1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement