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
),
241 String recommendText
= String
.format(getString(R
.string
.recommend_text
),
242 appName
, downloadUrl
, username
);
244 intent
.putExtra(Intent
.EXTRA_SUBJECT
, recommendSubject
);
245 intent
.putExtra(Intent
.EXTRA_TEXT
, recommendText
);
246 startActivity(intent
);
253 preferenceCategory
.removePreference(pRecommend
);
258 boolean feedbackEnabled
= getResources().getBoolean(R
.bool
.feedback_enabled
);
259 Preference pFeedback
= findPreference("feedback");
260 if (pFeedback
!= null
){
261 if (feedbackEnabled
) {
262 pFeedback
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
264 public boolean onPreferenceClick(Preference preference
) {
265 String feedbackMail
=(String
) getText(R
.string
.mail_feedback
);
266 String feedback
=(String
) getText(R
.string
.prefs_feedback
) + " - android v" + appVersion
;
267 Intent intent
= new Intent(Intent
.ACTION_SENDTO
);
268 intent
.setType("text/plain");
269 intent
.putExtra(Intent
.EXTRA_SUBJECT
, feedback
);
271 intent
.setData(Uri
.parse(feedbackMail
));
272 intent
.addFlags(Intent
.FLAG_ACTIVITY_NEW_TASK
);
273 startActivity(intent
);
279 preferenceCategory
.removePreference(pFeedback
);
284 boolean imprintEnabled
= getResources().getBoolean(R
.bool
.imprint_enabled
);
285 Preference pImprint
= findPreference("imprint");
286 if (pImprint
!= null
) {
287 if (imprintEnabled
) {
288 pImprint
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
290 public boolean onPreferenceClick(Preference preference
) {
291 String imprintWeb
= (String
) getText(R
.string
.url_imprint
);
292 if (imprintWeb
!= null
&& imprintWeb
.length() > 0) {
293 Uri uriUrl
= Uri
.parse(imprintWeb
);
294 Intent intent
= new Intent(Intent
.ACTION_VIEW
, uriUrl
);
295 startActivity(intent
);
297 //ImprintDialog.newInstance(true).show(preference.get, "IMPRINT_DIALOG");
302 preferenceCategory
.removePreference(pImprint
);
306 mPrefInstantUploadPath
= findPreference("instant_upload_path");
307 if (mPrefInstantUploadPath
!= null
){
309 mPrefInstantUploadPath
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
311 public boolean onPreferenceClick(Preference preference
) {
312 if (!mUploadPath
.endsWith(OCFile
.PATH_SEPARATOR
)) {
313 mUploadPath
+= OCFile
.PATH_SEPARATOR
;
315 Intent intent
= new Intent(Preferences
.this, UploadPathActivity
.class);
316 intent
.putExtra(UploadPathActivity
.KEY_INSTANT_UPLOAD_PATH
, mUploadPath
);
317 startActivityForResult(intent
, ACTION_SELECT_UPLOAD_PATH
);
323 mPrefInstantUploadCategory
= (PreferenceCategory
) findPreference("instant_uploading_category");
325 mPrefInstantUploadPathWiFi
= findPreference("instant_upload_on_wifi");
326 mPrefInstantUpload
= findPreference("instant_uploading");
328 toggleInstantPictureOptions(((CheckBoxPreference
) mPrefInstantUpload
).isChecked());
330 mPrefInstantUpload
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
333 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
334 toggleInstantPictureOptions((Boolean
) newValue
);
339 mPrefInstantVideoUploadPath
= findPreference("instant_video_upload_path");
340 if (mPrefInstantVideoUploadPath
!= null
){
342 mPrefInstantVideoUploadPath
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
344 public boolean onPreferenceClick(Preference preference
) {
345 if (!mUploadVideoPath
.endsWith(OCFile
.PATH_SEPARATOR
)) {
346 mUploadVideoPath
+= OCFile
.PATH_SEPARATOR
;
348 Intent intent
= new Intent(Preferences
.this, UploadPathActivity
.class);
349 intent
.putExtra(UploadPathActivity
.KEY_INSTANT_UPLOAD_PATH
, mUploadVideoPath
);
350 startActivityForResult(intent
, ACTION_SELECT_UPLOAD_VIDEO_PATH
);
356 mPrefInstantVideoUploadPathWiFi
= findPreference("instant_video_upload_on_wifi");
357 mPrefInstantVideoUpload
= findPreference("instant_video_uploading");
358 toggleInstantVideoOptions(((CheckBoxPreference
) mPrefInstantVideoUpload
).isChecked());
360 mPrefInstantVideoUpload
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
363 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
364 toggleInstantVideoOptions((Boolean
) newValue
);
370 pAboutApp
= (Preference
) findPreference("about_app");
371 if (pAboutApp
!= null
) {
372 pAboutApp
.setTitle(String
.format(getString(R
.string
.about_android
), getString(R
.string
.app_name
)));
373 pAboutApp
.setSummary(String
.format(getString(R
.string
.about_version
), appVersion
));
376 loadInstantUploadPath();
377 loadInstantUploadVideoPath();
379 /* ComponentsGetter */
380 mDownloadServiceConnection
= newTransferenceServiceConnection();
381 if (mDownloadServiceConnection
!= null
) {
382 bindService(new Intent(this, FileDownloader
.class), mDownloadServiceConnection
,
383 Context
.BIND_AUTO_CREATE
);
385 mUploadServiceConnection
= newTransferenceServiceConnection();
386 if (mUploadServiceConnection
!= null
) {
387 bindService(new Intent(this, FileUploader
.class), mUploadServiceConnection
,
388 Context
.BIND_AUTO_CREATE
);
393 private void toggleInstantPictureOptions(Boolean value
){
395 mPrefInstantUploadCategory
.addPreference(mPrefInstantUploadPathWiFi
);
396 mPrefInstantUploadCategory
.addPreference(mPrefInstantUploadPath
);
398 mPrefInstantUploadCategory
.removePreference(mPrefInstantUploadPathWiFi
);
399 mPrefInstantUploadCategory
.removePreference(mPrefInstantUploadPath
);
403 private void toggleInstantVideoOptions(Boolean value
){
405 mPrefInstantUploadCategory
.addPreference(mPrefInstantVideoUploadPathWiFi
);
406 mPrefInstantUploadCategory
.addPreference(mPrefInstantVideoUploadPath
);
408 mPrefInstantUploadCategory
.removePreference(mPrefInstantVideoUploadPathWiFi
);
409 mPrefInstantUploadCategory
.removePreference(mPrefInstantVideoUploadPath
);
414 public void onCreateContextMenu(ContextMenu menu
, View v
, ContextMenuInfo menuInfo
) {
416 // Filter for only showing contextual menu when long press on the
418 if (mShowContextMenu
) {
419 getMenuInflater().inflate(R
.menu
.account_picker_long_click
, menu
);
420 mShowContextMenu
= false
;
422 super.onCreateContextMenu(menu
, v
, menuInfo
);
426 * Called when the user clicked on an item into the context menu created at
427 * {@link #onCreateContextMenu(ContextMenu, View, ContextMenuInfo)} for
428 * every ownCloud {@link Account} , containing 'secondary actions' for them.
433 public boolean onContextItemSelected(android
.view
.MenuItem item
) {
434 AccountManager am
= (AccountManager
) getSystemService(ACCOUNT_SERVICE
);
435 Account accounts
[] = am
.getAccountsByType(MainApp
.getAccountType());
436 for (Account a
: accounts
) {
437 if (a
.name
.equals(mAccountName
)) {
438 if (item
.getItemId() == R
.id
.change_password
) {
440 // Change account password
441 Intent updateAccountCredentials
= new Intent(this, AuthenticatorActivity
.class);
442 updateAccountCredentials
.putExtra(AuthenticatorActivity
.EXTRA_ACCOUNT
, a
);
443 updateAccountCredentials
.putExtra(AuthenticatorActivity
.EXTRA_ACTION
,
444 AuthenticatorActivity
.ACTION_UPDATE_TOKEN
);
445 startActivity(updateAccountCredentials
);
447 } else if (item
.getItemId() == R
.id
.delete_account
) {
450 am
.removeAccount(a
, this, mHandler
);
451 Log_OC
.d(TAG
, "Remove an account " + a
.name
);
460 public void run(AccountManagerFuture
<Boolean
> future
) {
461 if (future
.isDone()) {
462 // after remove account
463 Account account
= new Account(mAccountName
, MainApp
.getAccountType());
464 if (!AccountUtils
.exists(account
, MainApp
.getAppContext())) {
466 if (mUploaderBinder
!= null
) {
467 mUploaderBinder
.cancel(account
);
469 if (mDownloaderBinder
!= null
) {
470 mDownloaderBinder
.cancel(account
);
474 Account a
= AccountUtils
.getCurrentOwnCloudAccount(this);
475 String accountName
= "";
477 Account
[] accounts
= AccountManager
.get(this).getAccountsByType(MainApp
.getAccountType());
478 if (accounts
.length
!= 0)
479 accountName
= accounts
[0].name
;
480 AccountUtils
.setCurrentOwnCloudAccount(this, accountName
);
482 addAccountsCheckboxPreferences();
487 protected void onResume() {
489 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
490 boolean state
= appPrefs
.getBoolean("set_pincode", false
);
491 pCode
.setChecked(state
);
493 // Populate the accounts category with the list of accounts
494 addAccountsCheckboxPreferences();
498 public boolean onCreateOptionsMenu(Menu menu
) {
499 super.onCreateOptionsMenu(menu
);
504 public boolean onMenuItemSelected(int featureId
, MenuItem item
) {
505 super.onMenuItemSelected(featureId
, item
);
508 switch (item
.getItemId()) {
509 case android
.R
.id
.home
:
510 intent
= new Intent(getBaseContext(), FileDisplayActivity
.class);
511 intent
.addFlags(Intent
.FLAG_ACTIVITY_CLEAR_TOP
);
512 startActivity(intent
);
515 Log_OC
.w(TAG
, "Unknown menu item triggered");
522 protected void onActivityResult(int requestCode
, int resultCode
, Intent data
) {
523 super.onActivityResult(requestCode
, resultCode
, data
);
525 if (requestCode
== ACTION_SELECT_UPLOAD_PATH
&& resultCode
== RESULT_OK
){
527 OCFile folderToUpload
= (OCFile
) data
.getParcelableExtra(UploadPathActivity
.EXTRA_FOLDER
);
529 mUploadPath
= folderToUpload
.getRemotePath();
531 mUploadPath
= DisplayUtils
.getPathWithoutLastSlash(mUploadPath
);
533 // Show the path on summary preference
534 mPrefInstantUploadPath
.setSummary(mUploadPath
);
536 saveInstantUploadPathOnPreferences();
538 } else if (requestCode
== ACTION_SELECT_UPLOAD_VIDEO_PATH
&& resultCode
== RESULT_OK
){
540 OCFile folderToUploadVideo
= (OCFile
) data
.getParcelableExtra(UploadPathActivity
.EXTRA_FOLDER
);
542 mUploadVideoPath
= folderToUploadVideo
.getRemotePath();
544 mUploadVideoPath
= DisplayUtils
.getPathWithoutLastSlash(mUploadVideoPath
);
546 // Show the video path on summary preference
547 mPrefInstantVideoUploadPath
.setSummary(mUploadVideoPath
);
549 saveInstantUploadVideoPathOnPreferences();
554 protected void onDestroy() {
557 if (mDownloadServiceConnection
!= null
) {
558 unbindService(mDownloadServiceConnection
);
559 mDownloadServiceConnection
= null
;
561 if (mUploadServiceConnection
!= null
) {
562 unbindService(mUploadServiceConnection
);
563 mUploadServiceConnection
= null
;
570 * Create the list of accounts that has been added into the app
572 @SuppressWarnings("deprecation")
573 private void addAccountsCheckboxPreferences() {
575 // Remove accounts in case list is refreshing for avoiding to have
577 if (mAccountsPrefCategory
.getPreferenceCount() > 0) {
578 mAccountsPrefCategory
.removeAll();
581 AccountManager am
= (AccountManager
) getSystemService(ACCOUNT_SERVICE
);
582 Account accounts
[] = am
.getAccountsByType(MainApp
.getAccountType());
583 Account currentAccount
= AccountUtils
.getCurrentOwnCloudAccount(getApplicationContext());
585 if (am
.getAccountsByType(MainApp
.getAccountType()).length
== 0) {
586 // Show create account screen if there isn't any account
587 am
.addAccount(MainApp
.getAccountType(), null
, null
, null
, this,
593 for (Account a
: accounts
) {
594 RadioButtonPreference accountPreference
= new RadioButtonPreference(this);
595 accountPreference
.setKey(a
.name
);
596 // Handle internationalized domain names
597 accountPreference
.setTitle(DisplayUtils
.convertIdn(a
.name
, false
));
598 mAccountsPrefCategory
.addPreference(accountPreference
);
600 // Check the current account that is being used
601 if (a
.name
.equals(currentAccount
.name
)) {
602 accountPreference
.setChecked(true
);
604 accountPreference
.setChecked(false
);
607 accountPreference
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
609 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
610 String key
= preference
.getKey();
611 AccountManager am
= (AccountManager
) getSystemService(ACCOUNT_SERVICE
);
612 Account accounts
[] = am
.getAccountsByType(MainApp
.getAccountType());
613 for (Account a
: accounts
) {
614 RadioButtonPreference p
= (RadioButtonPreference
) findPreference(a
.name
);
615 if (key
.equals(a
.name
)) {
616 boolean accountChanged
= !p
.isChecked();
618 AccountUtils
.setCurrentOwnCloudAccount(
619 getApplicationContext(),
622 if (accountChanged
) {
623 // restart the main activity
624 Intent i
= new Intent(
626 FileDisplayActivity
.class
628 i
.addFlags(Intent
.FLAG_ACTIVITY_CLEAR_TOP
);
629 i
.addFlags(Intent
.FLAG_ACTIVITY_SINGLE_TOP
);
638 return (Boolean
) newValue
;
644 // Add Create Account preference at the end of account list if
645 // Multiaccount is enabled
646 if (getResources().getBoolean(R
.bool
.multiaccount_support
)) {
647 createAddAccountPreference();
654 * Create the preference for allow adding new accounts
656 private void createAddAccountPreference() {
657 Preference addAccountPref
= new Preference(this);
658 addAccountPref
.setKey("add_account");
659 addAccountPref
.setTitle(getString(R
.string
.prefs_add_account
));
660 mAccountsPrefCategory
.addPreference(addAccountPref
);
662 addAccountPref
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
664 public boolean onPreferenceClick(Preference preference
) {
665 AccountManager am
= AccountManager
.get(getApplicationContext());
666 am
.addAccount(MainApp
.getAccountType(), null
, null
, null
, Preferences
.this, null
, null
);
674 * Load upload path set on preferences
676 private void loadInstantUploadPath() {
677 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
678 mUploadPath
= appPrefs
.getString("instant_upload_path", getString(R
.string
.instant_upload_path
));
679 mPrefInstantUploadPath
.setSummary(mUploadPath
);
683 * Save the "Instant Upload Path" on preferences
685 private void saveInstantUploadPathOnPreferences() {
686 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
687 SharedPreferences
.Editor editor
= appPrefs
.edit();
688 editor
.putString("instant_upload_path", mUploadPath
);
693 * Load upload video path set on preferences
695 private void loadInstantUploadVideoPath() {
696 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
697 mUploadVideoPath
= appPrefs
.getString("instant_video_upload_path", getString(R
.string
.instant_upload_path
));
698 mPrefInstantVideoUploadPath
.setSummary(mUploadVideoPath
);
702 * Save the "Instant Video Upload Path" on preferences
704 private void saveInstantUploadVideoPathOnPreferences() {
705 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
706 SharedPreferences
.Editor editor
= appPrefs
.edit();
707 editor
.putString("instant_video_upload_path", mUploadVideoPath
);
711 // Methods for ComponetsGetter
713 public FileDownloader
.FileDownloaderBinder
getFileDownloaderBinder() {
714 return mDownloaderBinder
;
719 public FileUploader
.FileUploaderBinder
getFileUploaderBinder() {
720 return mUploaderBinder
;
724 public OperationsService
.OperationsServiceBinder
getOperationsServiceBinder() {
729 public FileDataStorageManager
getStorageManager() {
734 public FileOperationsHelper
getFileOperationsHelper() {
738 protected ServiceConnection
newTransferenceServiceConnection() {
739 return new PreferencesServiceConnection();
742 /** Defines callbacks for service binding, passed to bindService() */
743 private class PreferencesServiceConnection
implements ServiceConnection
{
746 public void onServiceConnected(ComponentName component
, IBinder service
) {
748 if (component
.equals(new ComponentName(Preferences
.this, FileDownloader
.class))) {
749 mDownloaderBinder
= (FileDownloader
.FileDownloaderBinder
) service
;
751 } else if (component
.equals(new ComponentName(Preferences
.this, FileUploader
.class))) {
752 Log_OC
.d(TAG
, "Upload service connected");
753 mUploaderBinder
= (FileUploader
.FileUploaderBinder
) service
;
761 public void onServiceDisconnected(ComponentName component
) {
762 if (component
.equals(new ComponentName(Preferences
.this, FileDownloader
.class))) {
763 Log_OC
.d(TAG
, "Download service suddenly disconnected");
764 mDownloaderBinder
= null
;
765 } else if (component
.equals(new ComponentName(Preferences
.this, FileUploader
.class))) {
766 Log_OC
.d(TAG
, "Upload service suddenly disconnected");
767 mUploaderBinder
= null
;