2 * ownCloud Android client application
4 * @author Bartek Przybylski
5 * @author David A. Velasco
6 * Copyright (C) 2011 Bartek Przybylski
7 * Copyright (C) 2015 ownCloud Inc.
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2,
11 * as published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 package com
.owncloud
.android
.ui
.activity
;
24 import android
.accounts
.Account
;
25 import android
.accounts
.AccountManager
;
26 import android
.accounts
.AccountManagerCallback
;
27 import android
.accounts
.AccountManagerFuture
;
28 import android
.content
.ComponentName
;
29 import android
.content
.Context
;
30 import android
.content
.Intent
;
31 import android
.content
.ServiceConnection
;
32 import android
.content
.SharedPreferences
;
33 import android
.content
.pm
.PackageInfo
;
34 import android
.content
.pm
.PackageManager
.NameNotFoundException
;
35 import android
.net
.Uri
;
36 import android
.os
.Bundle
;
37 import android
.os
.Handler
;
38 import android
.os
.IBinder
;
39 import android
.preference
.CheckBoxPreference
;
40 import android
.preference
.Preference
;
41 import android
.preference
.Preference
.OnPreferenceChangeListener
;
42 import android
.preference
.Preference
.OnPreferenceClickListener
;
43 import android
.preference
.PreferenceCategory
;
44 import android
.preference
.PreferenceManager
;
45 import android
.view
.ContextMenu
;
46 import android
.view
.ContextMenu
.ContextMenuInfo
;
47 import android
.view
.View
;
48 import android
.widget
.AdapterView
;
49 import android
.widget
.AdapterView
.OnItemLongClickListener
;
50 import android
.widget
.ListAdapter
;
51 import android
.widget
.ListView
;
53 import com
.actionbarsherlock
.app
.ActionBar
;
54 import com
.actionbarsherlock
.app
.SherlockPreferenceActivity
;
55 import com
.actionbarsherlock
.view
.Menu
;
56 import com
.actionbarsherlock
.view
.MenuItem
;
57 import com
.owncloud
.android
.BuildConfig
;
58 import com
.owncloud
.android
.MainApp
;
59 import com
.owncloud
.android
.R
;
60 import com
.owncloud
.android
.authentication
.AccountUtils
;
61 import com
.owncloud
.android
.authentication
.AuthenticatorActivity
;
62 import com
.owncloud
.android
.datamodel
.FileDataStorageManager
;
63 import com
.owncloud
.android
.datamodel
.OCFile
;
64 import com
.owncloud
.android
.db
.DbHandler
;
65 import com
.owncloud
.android
.files
.FileOperationsHelper
;
66 import com
.owncloud
.android
.files
.services
.FileDownloader
;
67 import com
.owncloud
.android
.files
.services
.FileUploader
;
68 import com
.owncloud
.android
.lib
.common
.utils
.Log_OC
;
69 import com
.owncloud
.android
.services
.OperationsService
;
70 import com
.owncloud
.android
.ui
.RadioButtonPreference
;
71 import com
.owncloud
.android
.utils
.DisplayUtils
;
75 * An Activity that allows the user to change the application's settings.
77 public class Preferences
extends SherlockPreferenceActivity
78 implements AccountManagerCallback
<Boolean
>, ComponentsGetter
{
80 private static final String TAG
= "OwnCloudPreferences";
82 private static final int ACTION_SELECT_UPLOAD_PATH
= 1;
83 private static final int ACTION_SELECT_UPLOAD_VIDEO_PATH
= 2;
85 private DbHandler mDbHandler
;
86 private CheckBoxPreference pCode
;
87 private Preference pAboutApp
;
89 private PreferenceCategory mAccountsPrefCategory
= null
;
90 private final Handler mHandler
= new Handler();
91 private String mAccountName
;
92 private boolean mShowContextMenu
= false
;
93 private String mUploadPath
;
94 private PreferenceCategory mPrefInstantUploadCategory
;
95 private Preference mPrefInstantUpload
;
96 private Preference mPrefInstantUploadPath
;
97 private Preference mPrefInstantUploadPathWiFi
;
98 private Preference mPrefInstantVideoUpload
;
99 private Preference mPrefInstantVideoUploadPath
;
100 private Preference mPrefInstantVideoUploadPathWiFi
;
101 private String mUploadVideoPath
;
103 protected FileDownloader
.FileDownloaderBinder mDownloaderBinder
= null
;
104 protected FileUploader
.FileUploaderBinder mUploaderBinder
= null
;
105 private ServiceConnection mDownloadServiceConnection
, mUploadServiceConnection
= null
;
107 @SuppressWarnings("deprecation")
109 public void onCreate(Bundle savedInstanceState
) {
110 super.onCreate(savedInstanceState
);
111 mDbHandler
= new DbHandler(getBaseContext());
112 addPreferencesFromResource(R
.xml
.preferences
);
114 ActionBar actionBar
= getSherlock().getActionBar();
115 actionBar
.setIcon(DisplayUtils
.getSeasonalIconId());
116 actionBar
.setDisplayHomeAsUpEnabled(true
);
117 actionBar
.setTitle(R
.string
.actionbar_settings
);
119 // For adding content description tag to a title field in the action bar
120 int actionBarTitleId
= getResources().getIdentifier("action_bar_title", "id", "android");
121 View actionBarTitleView
= getWindow().getDecorView().findViewById(actionBarTitleId
);
122 if (actionBarTitleView
!= null
) { // it's null in Android 2.x
123 getWindow().getDecorView().findViewById(actionBarTitleId
).
124 setContentDescription(getString(R
.string
.actionbar_settings
));
127 // Load the accounts category for adding the list of accounts
128 mAccountsPrefCategory
= (PreferenceCategory
) findPreference("accounts_category");
130 ListView listView
= getListView();
131 listView
.setOnItemLongClickListener(new OnItemLongClickListener() {
133 public boolean onItemLongClick(AdapterView
<?
> parent
, View view
, int position
, long id
) {
134 ListView listView
= (ListView
) parent
;
135 ListAdapter listAdapter
= listView
.getAdapter();
136 Object obj
= listAdapter
.getItem(position
);
138 if (obj
!= null
&& obj
instanceof RadioButtonPreference
) {
139 mShowContextMenu
= true
;
140 mAccountName
= ((RadioButtonPreference
) obj
).getKey();
142 Preferences
.this.openContextMenu(listView
);
144 View
.OnLongClickListener longListener
= (View
.OnLongClickListener
) obj
;
145 return longListener
.onLongClick(view
);
154 PackageInfo pkg
= getPackageManager().getPackageInfo(getPackageName(), 0);
155 temp
= pkg
.versionName
;
156 } catch (NameNotFoundException e
) {
158 Log_OC
.e(TAG
, "Error while showing about dialog", e
);
160 final String appVersion
= temp
;
162 // Register context menu for list of preferences.
163 registerForContextMenu(getListView());
165 pCode
= (CheckBoxPreference
) findPreference("set_pincode");
167 pCode
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
169 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
170 Intent i
= new Intent(getApplicationContext(), PassCodeActivity
.class);
171 Boolean enable
= (Boolean
) newValue
;
173 enable
.booleanValue() ? PassCodeActivity
.ACTION_ENABLE
: PassCodeActivity
.ACTION_DISABLE
183 PreferenceCategory preferenceCategory
= (PreferenceCategory
) findPreference("more");
185 boolean helpEnabled
= getResources().getBoolean(R
.bool
.help_enabled
);
186 Preference pHelp
= findPreference("help");
189 pHelp
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
191 public boolean onPreferenceClick(Preference preference
) {
192 String helpWeb
=(String
) getText(R
.string
.url_help
);
193 if (helpWeb
!= null
&& helpWeb
.length() > 0) {
194 Uri uriUrl
= Uri
.parse(helpWeb
);
195 Intent intent
= new Intent(Intent
.ACTION_VIEW
, uriUrl
);
196 startActivity(intent
);
202 preferenceCategory
.removePreference(pHelp
);
207 if (BuildConfig
.DEBUG
) {
208 Preference pLog
= findPreference("log");
210 pLog
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
212 public boolean onPreferenceClick(Preference preference
) {
213 Intent loggerIntent
= new Intent(getApplicationContext(),LogHistoryActivity
.class);
214 startActivity(loggerIntent
);
221 boolean recommendEnabled
= getResources().getBoolean(R
.bool
.recommend_enabled
);
222 Preference pRecommend
= findPreference("recommend");
223 if (pRecommend
!= null
){
224 if (recommendEnabled
) {
225 pRecommend
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
227 public boolean onPreferenceClick(Preference preference
) {
229 Intent intent
= new Intent(Intent
.ACTION_SENDTO
);
230 intent
.setType("text/plain");
231 intent
.setData(Uri
.parse(getString(R
.string
.mail_recommend
)));
232 intent
.addFlags(Intent
.FLAG_ACTIVITY_NEW_TASK
);
234 String appName
= getString(R
.string
.app_name
);
235 String downloadUrl
= getString(R
.string
.url_app_download
);
236 Account currentAccount
= AccountUtils
.getCurrentOwnCloudAccount(Preferences
.this);
237 String username
= currentAccount
.name
.substring(0, currentAccount
.name
.lastIndexOf('@'));
239 String recommendSubject
= String
.format(getString(R
.string
.recommend_subject
), appName
);
240 String recommendText
= String
.format(getString(R
.string
.recommend_text
),
241 appName
, downloadUrl
, username
);
243 intent
.putExtra(Intent
.EXTRA_SUBJECT
, recommendSubject
);
244 intent
.putExtra(Intent
.EXTRA_TEXT
, recommendText
);
245 startActivity(intent
);
252 preferenceCategory
.removePreference(pRecommend
);
257 boolean feedbackEnabled
= getResources().getBoolean(R
.bool
.feedback_enabled
);
258 Preference pFeedback
= findPreference("feedback");
259 if (pFeedback
!= null
){
260 if (feedbackEnabled
) {
261 pFeedback
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
263 public boolean onPreferenceClick(Preference preference
) {
264 String feedbackMail
=(String
) getText(R
.string
.mail_feedback
);
265 String feedback
=(String
) getText(R
.string
.prefs_feedback
) + " - android v" + appVersion
;
266 Intent intent
= new Intent(Intent
.ACTION_SENDTO
);
267 intent
.setType("text/plain");
268 intent
.putExtra(Intent
.EXTRA_SUBJECT
, feedback
);
270 intent
.setData(Uri
.parse(feedbackMail
));
271 intent
.addFlags(Intent
.FLAG_ACTIVITY_NEW_TASK
);
272 startActivity(intent
);
278 preferenceCategory
.removePreference(pFeedback
);
283 boolean imprintEnabled
= getResources().getBoolean(R
.bool
.imprint_enabled
);
284 Preference pImprint
= findPreference("imprint");
285 if (pImprint
!= null
) {
286 if (imprintEnabled
) {
287 pImprint
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
289 public boolean onPreferenceClick(Preference preference
) {
290 String imprintWeb
= (String
) getText(R
.string
.url_imprint
);
291 if (imprintWeb
!= null
&& imprintWeb
.length() > 0) {
292 Uri uriUrl
= Uri
.parse(imprintWeb
);
293 Intent intent
= new Intent(Intent
.ACTION_VIEW
, uriUrl
);
294 startActivity(intent
);
296 //ImprintDialog.newInstance(true).show(preference.get, "IMPRINT_DIALOG");
301 preferenceCategory
.removePreference(pImprint
);
305 mPrefInstantUploadPath
= findPreference("instant_upload_path");
306 if (mPrefInstantUploadPath
!= null
){
308 mPrefInstantUploadPath
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
310 public boolean onPreferenceClick(Preference preference
) {
311 if (!mUploadPath
.endsWith(OCFile
.PATH_SEPARATOR
)) {
312 mUploadPath
+= OCFile
.PATH_SEPARATOR
;
314 Intent intent
= new Intent(Preferences
.this, UploadPathActivity
.class);
315 intent
.putExtra(UploadPathActivity
.KEY_INSTANT_UPLOAD_PATH
, mUploadPath
);
316 startActivityForResult(intent
, ACTION_SELECT_UPLOAD_PATH
);
322 mPrefInstantUploadCategory
= (PreferenceCategory
) findPreference("instant_uploading_category");
324 mPrefInstantUploadPathWiFi
= findPreference("instant_upload_on_wifi");
325 mPrefInstantUpload
= findPreference("instant_uploading");
327 toggleInstantPictureOptions(((CheckBoxPreference
) mPrefInstantUpload
).isChecked());
329 mPrefInstantUpload
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
332 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
333 toggleInstantPictureOptions((Boolean
) newValue
);
338 mPrefInstantVideoUploadPath
= findPreference("instant_video_upload_path");
339 if (mPrefInstantVideoUploadPath
!= null
){
341 mPrefInstantVideoUploadPath
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
343 public boolean onPreferenceClick(Preference preference
) {
344 if (!mUploadVideoPath
.endsWith(OCFile
.PATH_SEPARATOR
)) {
345 mUploadVideoPath
+= OCFile
.PATH_SEPARATOR
;
347 Intent intent
= new Intent(Preferences
.this, UploadPathActivity
.class);
348 intent
.putExtra(UploadPathActivity
.KEY_INSTANT_UPLOAD_PATH
, mUploadVideoPath
);
349 startActivityForResult(intent
, ACTION_SELECT_UPLOAD_VIDEO_PATH
);
355 mPrefInstantVideoUploadPathWiFi
= findPreference("instant_video_upload_on_wifi");
356 mPrefInstantVideoUpload
= findPreference("instant_video_uploading");
357 toggleInstantVideoOptions(((CheckBoxPreference
) mPrefInstantVideoUpload
).isChecked());
359 mPrefInstantVideoUpload
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
362 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
363 toggleInstantVideoOptions((Boolean
) newValue
);
369 pAboutApp
= (Preference
) findPreference("about_app");
370 if (pAboutApp
!= null
) {
371 pAboutApp
.setTitle(String
.format(getString(R
.string
.about_android
), getString(R
.string
.app_name
)));
372 pAboutApp
.setSummary(String
.format(getString(R
.string
.about_version
), appVersion
));
375 loadInstantUploadPath();
376 loadInstantUploadVideoPath();
378 /* ComponentsGetter */
379 mDownloadServiceConnection
= newTransferenceServiceConnection();
380 if (mDownloadServiceConnection
!= null
) {
381 bindService(new Intent(this, FileDownloader
.class), mDownloadServiceConnection
,
382 Context
.BIND_AUTO_CREATE
);
384 mUploadServiceConnection
= newTransferenceServiceConnection();
385 if (mUploadServiceConnection
!= null
) {
386 bindService(new Intent(this, FileUploader
.class), mUploadServiceConnection
,
387 Context
.BIND_AUTO_CREATE
);
392 private void toggleInstantPictureOptions(Boolean value
){
394 mPrefInstantUploadCategory
.addPreference(mPrefInstantUploadPathWiFi
);
395 mPrefInstantUploadCategory
.addPreference(mPrefInstantUploadPath
);
397 mPrefInstantUploadCategory
.removePreference(mPrefInstantUploadPathWiFi
);
398 mPrefInstantUploadCategory
.removePreference(mPrefInstantUploadPath
);
402 private void toggleInstantVideoOptions(Boolean value
){
404 mPrefInstantUploadCategory
.addPreference(mPrefInstantVideoUploadPathWiFi
);
405 mPrefInstantUploadCategory
.addPreference(mPrefInstantVideoUploadPath
);
407 mPrefInstantUploadCategory
.removePreference(mPrefInstantVideoUploadPathWiFi
);
408 mPrefInstantUploadCategory
.removePreference(mPrefInstantVideoUploadPath
);
413 public void onCreateContextMenu(ContextMenu menu
, View v
, ContextMenuInfo menuInfo
) {
415 // Filter for only showing contextual menu when long press on the
417 if (mShowContextMenu
) {
418 getMenuInflater().inflate(R
.menu
.account_picker_long_click
, menu
);
419 mShowContextMenu
= false
;
421 super.onCreateContextMenu(menu
, v
, menuInfo
);
425 * Called when the user clicked on an item into the context menu created at
426 * {@link #onCreateContextMenu(ContextMenu, View, ContextMenuInfo)} for
427 * every ownCloud {@link Account} , containing 'secondary actions' for them.
432 public boolean onContextItemSelected(android
.view
.MenuItem item
) {
433 AccountManager am
= (AccountManager
) getSystemService(ACCOUNT_SERVICE
);
434 Account accounts
[] = am
.getAccountsByType(MainApp
.getAccountType());
435 for (Account a
: accounts
) {
436 if (a
.name
.equals(mAccountName
)) {
437 if (item
.getItemId() == R
.id
.change_password
) {
439 // Change account password
440 Intent updateAccountCredentials
= new Intent(this, AuthenticatorActivity
.class);
441 updateAccountCredentials
.putExtra(AuthenticatorActivity
.EXTRA_ACCOUNT
, a
);
442 updateAccountCredentials
.putExtra(AuthenticatorActivity
.EXTRA_ACTION
,
443 AuthenticatorActivity
.ACTION_UPDATE_TOKEN
);
444 startActivity(updateAccountCredentials
);
446 } else if (item
.getItemId() == R
.id
.delete_account
) {
449 am
.removeAccount(a
, this, mHandler
);
450 Log_OC
.d(TAG
, "Remove an account " + a
.name
);
459 public void run(AccountManagerFuture
<Boolean
> future
) {
460 if (future
.isDone()) {
461 // after remove account
462 Account account
= new Account(mAccountName
, MainApp
.getAccountType());
463 if (!AccountUtils
.exists(account
, MainApp
.getAppContext())) {
465 if (mUploaderBinder
!= null
) {
466 mUploaderBinder
.cancel(account
);
468 if (mDownloaderBinder
!= null
) {
469 mDownloaderBinder
.cancel(account
);
473 Account a
= AccountUtils
.getCurrentOwnCloudAccount(this);
474 String accountName
= "";
476 Account
[] accounts
= AccountManager
.get(this).getAccountsByType(MainApp
.getAccountType());
477 if (accounts
.length
!= 0)
478 accountName
= accounts
[0].name
;
479 AccountUtils
.setCurrentOwnCloudAccount(this, accountName
);
481 addAccountsCheckboxPreferences();
486 protected void onResume() {
488 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
489 boolean state
= appPrefs
.getBoolean("set_pincode", false
);
490 pCode
.setChecked(state
);
492 // Populate the accounts category with the list of accounts
493 addAccountsCheckboxPreferences();
497 public boolean onCreateOptionsMenu(Menu menu
) {
498 super.onCreateOptionsMenu(menu
);
503 public boolean onMenuItemSelected(int featureId
, MenuItem item
) {
504 super.onMenuItemSelected(featureId
, item
);
507 switch (item
.getItemId()) {
508 case android
.R
.id
.home
:
509 intent
= new Intent(getBaseContext(), FileDisplayActivity
.class);
510 intent
.addFlags(Intent
.FLAG_ACTIVITY_CLEAR_TOP
);
511 startActivity(intent
);
514 Log_OC
.w(TAG
, "Unknown menu item triggered");
521 protected void onActivityResult(int requestCode
, int resultCode
, Intent data
) {
522 super.onActivityResult(requestCode
, resultCode
, data
);
524 if (requestCode
== ACTION_SELECT_UPLOAD_PATH
&& resultCode
== RESULT_OK
){
526 OCFile folderToUpload
= (OCFile
) data
.getParcelableExtra(UploadPathActivity
.EXTRA_FOLDER
);
528 mUploadPath
= folderToUpload
.getRemotePath();
530 mUploadPath
= DisplayUtils
.getPathWithoutLastSlash(mUploadPath
);
532 // Show the path on summary preference
533 mPrefInstantUploadPath
.setSummary(mUploadPath
);
535 saveInstantUploadPathOnPreferences();
537 } else if (requestCode
== ACTION_SELECT_UPLOAD_VIDEO_PATH
&& resultCode
== RESULT_OK
){
539 OCFile folderToUploadVideo
= (OCFile
) data
.getParcelableExtra(UploadPathActivity
.EXTRA_FOLDER
);
541 mUploadVideoPath
= folderToUploadVideo
.getRemotePath();
543 mUploadVideoPath
= DisplayUtils
.getPathWithoutLastSlash(mUploadVideoPath
);
545 // Show the video path on summary preference
546 mPrefInstantVideoUploadPath
.setSummary(mUploadVideoPath
);
548 saveInstantUploadVideoPathOnPreferences();
553 protected void onDestroy() {
556 if (mDownloadServiceConnection
!= null
) {
557 unbindService(mDownloadServiceConnection
);
558 mDownloadServiceConnection
= null
;
560 if (mUploadServiceConnection
!= null
) {
561 unbindService(mUploadServiceConnection
);
562 mUploadServiceConnection
= null
;
569 * Create the list of accounts that has been added into the app
571 @SuppressWarnings("deprecation")
572 private void addAccountsCheckboxPreferences() {
574 // Remove accounts in case list is refreshing for avoiding to have
576 if (mAccountsPrefCategory
.getPreferenceCount() > 0) {
577 mAccountsPrefCategory
.removeAll();
580 AccountManager am
= (AccountManager
) getSystemService(ACCOUNT_SERVICE
);
581 Account accounts
[] = am
.getAccountsByType(MainApp
.getAccountType());
582 Account currentAccount
= AccountUtils
.getCurrentOwnCloudAccount(getApplicationContext());
584 if (am
.getAccountsByType(MainApp
.getAccountType()).length
== 0) {
585 // Show create account screen if there isn't any account
586 am
.addAccount(MainApp
.getAccountType(), null
, null
, null
, this,
592 for (Account a
: accounts
) {
593 RadioButtonPreference accountPreference
= new RadioButtonPreference(this);
594 accountPreference
.setKey(a
.name
);
595 // Handle internationalized domain names
596 accountPreference
.setTitle(DisplayUtils
.convertIdn(a
.name
, false
));
597 mAccountsPrefCategory
.addPreference(accountPreference
);
599 // Check the current account that is being used
600 if (a
.name
.equals(currentAccount
.name
)) {
601 accountPreference
.setChecked(true
);
603 accountPreference
.setChecked(false
);
606 accountPreference
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
608 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
609 String key
= preference
.getKey();
610 AccountManager am
= (AccountManager
) getSystemService(ACCOUNT_SERVICE
);
611 Account accounts
[] = am
.getAccountsByType(MainApp
.getAccountType());
612 for (Account a
: accounts
) {
613 RadioButtonPreference p
= (RadioButtonPreference
) findPreference(a
.name
);
614 if (key
.equals(a
.name
)) {
615 boolean accountChanged
= !p
.isChecked();
617 AccountUtils
.setCurrentOwnCloudAccount(
618 getApplicationContext(),
621 if (accountChanged
) {
622 // restart the main activity
623 Intent i
= new Intent(
625 FileDisplayActivity
.class
627 i
.addFlags(Intent
.FLAG_ACTIVITY_CLEAR_TOP
);
628 i
.addFlags(Intent
.FLAG_ACTIVITY_SINGLE_TOP
);
637 return (Boolean
) newValue
;
643 // Add Create Account preference at the end of account list if
644 // Multiaccount is enabled
645 if (getResources().getBoolean(R
.bool
.multiaccount_support
)) {
646 createAddAccountPreference();
653 * Create the preference for allow adding new accounts
655 private void createAddAccountPreference() {
656 Preference addAccountPref
= new Preference(this);
657 addAccountPref
.setKey("add_account");
658 addAccountPref
.setTitle(getString(R
.string
.prefs_add_account
));
659 mAccountsPrefCategory
.addPreference(addAccountPref
);
661 addAccountPref
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
663 public boolean onPreferenceClick(Preference preference
) {
664 AccountManager am
= AccountManager
.get(getApplicationContext());
665 am
.addAccount(MainApp
.getAccountType(), null
, null
, null
, Preferences
.this, null
, null
);
673 * Load upload path set on preferences
675 private void loadInstantUploadPath() {
676 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
677 mUploadPath
= appPrefs
.getString("instant_upload_path", getString(R
.string
.instant_upload_path
));
678 mPrefInstantUploadPath
.setSummary(mUploadPath
);
682 * Save the "Instant Upload Path" on preferences
684 private void saveInstantUploadPathOnPreferences() {
685 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
686 SharedPreferences
.Editor editor
= appPrefs
.edit();
687 editor
.putString("instant_upload_path", mUploadPath
);
692 * Load upload video path set on preferences
694 private void loadInstantUploadVideoPath() {
695 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
696 mUploadVideoPath
= appPrefs
.getString("instant_video_upload_path", getString(R
.string
.instant_upload_path
));
697 mPrefInstantVideoUploadPath
.setSummary(mUploadVideoPath
);
701 * Save the "Instant Video Upload Path" on preferences
703 private void saveInstantUploadVideoPathOnPreferences() {
704 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
705 SharedPreferences
.Editor editor
= appPrefs
.edit();
706 editor
.putString("instant_video_upload_path", mUploadVideoPath
);
710 // Methods for ComponetsGetter
712 public FileDownloader
.FileDownloaderBinder
getFileDownloaderBinder() {
713 return mDownloaderBinder
;
718 public FileUploader
.FileUploaderBinder
getFileUploaderBinder() {
719 return mUploaderBinder
;
723 public OperationsService
.OperationsServiceBinder
getOperationsServiceBinder() {
728 public FileDataStorageManager
getStorageManager() {
733 public FileOperationsHelper
getFileOperationsHelper() {
737 protected ServiceConnection
newTransferenceServiceConnection() {
738 return new PreferencesServiceConnection();
741 /** Defines callbacks for service binding, passed to bindService() */
742 private class PreferencesServiceConnection
implements ServiceConnection
{
745 public void onServiceConnected(ComponentName component
, IBinder service
) {
747 if (component
.equals(new ComponentName(Preferences
.this, FileDownloader
.class))) {
748 mDownloaderBinder
= (FileDownloader
.FileDownloaderBinder
) service
;
750 } else if (component
.equals(new ComponentName(Preferences
.this, FileUploader
.class))) {
751 Log_OC
.d(TAG
, "Upload service connected");
752 mUploaderBinder
= (FileUploader
.FileUploaderBinder
) service
;
760 public void onServiceDisconnected(ComponentName component
) {
761 if (component
.equals(new ComponentName(Preferences
.this, FileDownloader
.class))) {
762 Log_OC
.d(TAG
, "Download service suddenly disconnected");
763 mDownloaderBinder
= null
;
764 } else if (component
.equals(new ComponentName(Preferences
.this, FileUploader
.class))) {
765 Log_OC
.d(TAG
, "Upload service suddenly disconnected");
766 mUploaderBinder
= null
;