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
.MainApp
;
58 import com
.owncloud
.android
.R
;
59 import com
.owncloud
.android
.authentication
.AccountUtils
;
60 import com
.owncloud
.android
.authentication
.AuthenticatorActivity
;
61 import com
.owncloud
.android
.datamodel
.FileDataStorageManager
;
62 import com
.owncloud
.android
.datamodel
.OCFile
;
63 import com
.owncloud
.android
.db
.DbHandler
;
64 import com
.owncloud
.android
.files
.FileOperationsHelper
;
65 import com
.owncloud
.android
.files
.services
.FileDownloader
;
66 import com
.owncloud
.android
.files
.services
.FileUploader
;
67 import com
.owncloud
.android
.lib
.common
.utils
.Log_OC
;
68 import com
.owncloud
.android
.services
.OperationsService
;
69 import com
.owncloud
.android
.ui
.RadioButtonPreference
;
70 import com
.owncloud
.android
.utils
.DisplayUtils
;
74 * An Activity that allows the user to change the application's settings.
76 public class Preferences
extends SherlockPreferenceActivity
77 implements AccountManagerCallback
<Boolean
>, ComponentsGetter
{
79 private static final String TAG
= "OwnCloudPreferences";
81 private static final int ACTION_SELECT_UPLOAD_PATH
= 1;
82 private static final int ACTION_SELECT_UPLOAD_VIDEO_PATH
= 2;
84 private DbHandler mDbHandler
;
85 private CheckBoxPreference pCode
;
86 private Preference pAboutApp
;
88 private PreferenceCategory mAccountsPrefCategory
= null
;
89 private final Handler mHandler
= new Handler();
90 private String mAccountName
;
91 private boolean mShowContextMenu
= false
;
92 private String mUploadPath
;
93 private PreferenceCategory mPrefInstantUploadCategory
;
94 private Preference mPrefInstantUpload
;
95 private Preference mPrefInstantUploadPath
;
96 private Preference mPrefInstantUploadPathWiFi
;
97 private Preference mPrefInstantVideoUpload
;
98 private Preference mPrefInstantVideoUploadPath
;
99 private Preference mPrefInstantVideoUploadPathWiFi
;
100 private String mUploadVideoPath
;
102 protected FileDownloader
.FileDownloaderBinder mDownloaderBinder
= null
;
103 protected FileUploader
.FileUploaderBinder mUploaderBinder
= null
;
104 private ServiceConnection mDownloadServiceConnection
, mUploadServiceConnection
= null
;
106 @SuppressWarnings("deprecation")
108 public void onCreate(Bundle savedInstanceState
) {
109 super.onCreate(savedInstanceState
);
110 mDbHandler
= new DbHandler(getBaseContext());
111 addPreferencesFromResource(R
.xml
.preferences
);
113 ActionBar actionBar
= getSherlock().getActionBar();
114 actionBar
.setIcon(DisplayUtils
.getSeasonalIconId());
115 actionBar
.setDisplayHomeAsUpEnabled(true
);
116 actionBar
.setTitle(R
.string
.actionbar_settings
);
118 // For adding content description tag to a title field in the action bar
119 int actionBarTitleId
= getResources().getIdentifier("action_bar_title", "id", "android");
120 View actionBarTitleView
= getWindow().getDecorView().findViewById(actionBarTitleId
);
121 if (actionBarTitleView
!= null
) { // it's null in Android 2.x
122 getWindow().getDecorView().findViewById(actionBarTitleId
).
123 setContentDescription(getString(R
.string
.actionbar_settings
));
126 // Load the accounts category for adding the list of accounts
127 mAccountsPrefCategory
= (PreferenceCategory
) findPreference("accounts_category");
129 ListView listView
= getListView();
130 listView
.setOnItemLongClickListener(new OnItemLongClickListener() {
132 public boolean onItemLongClick(AdapterView
<?
> parent
, View view
, int position
, long id
) {
133 ListView listView
= (ListView
) parent
;
134 ListAdapter listAdapter
= listView
.getAdapter();
135 Object obj
= listAdapter
.getItem(position
);
137 if (obj
!= null
&& obj
instanceof RadioButtonPreference
) {
138 mShowContextMenu
= true
;
139 mAccountName
= ((RadioButtonPreference
) obj
).getKey();
141 Preferences
.this.openContextMenu(listView
);
143 View
.OnLongClickListener longListener
= (View
.OnLongClickListener
) obj
;
144 return longListener
.onLongClick(view
);
153 PackageInfo pkg
= getPackageManager().getPackageInfo(getPackageName(), 0);
154 temp
= pkg
.versionName
;
155 } catch (NameNotFoundException e
) {
157 Log_OC
.e(TAG
, "Error while showing about dialog", e
);
159 final String appVersion
= temp
;
161 // Register context menu for list of preferences.
162 registerForContextMenu(getListView());
164 pCode
= (CheckBoxPreference
) findPreference("set_pincode");
166 pCode
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
168 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
169 Intent i
= new Intent(getApplicationContext(), PassCodeActivity
.class);
170 Boolean enable
= (Boolean
) newValue
;
172 enable
.booleanValue() ? PassCodeActivity
.ACTION_ENABLE
: PassCodeActivity
.ACTION_DISABLE
182 PreferenceCategory preferenceCategory
= (PreferenceCategory
) findPreference("more");
184 boolean helpEnabled
= getResources().getBoolean(R
.bool
.help_enabled
);
185 Preference pHelp
= findPreference("help");
188 pHelp
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
190 public boolean onPreferenceClick(Preference preference
) {
191 String helpWeb
=(String
) getText(R
.string
.url_help
);
192 if (helpWeb
!= null
&& helpWeb
.length() > 0) {
193 Uri uriUrl
= Uri
.parse(helpWeb
);
194 Intent intent
= new Intent(Intent
.ACTION_VIEW
, uriUrl
);
195 startActivity(intent
);
201 preferenceCategory
.removePreference(pHelp
);
207 boolean recommendEnabled
= getResources().getBoolean(R
.bool
.recommend_enabled
);
208 Preference pRecommend
= findPreference("recommend");
209 if (pRecommend
!= null
){
210 if (recommendEnabled
) {
211 pRecommend
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
213 public boolean onPreferenceClick(Preference preference
) {
215 Intent intent
= new Intent(Intent
.ACTION_SENDTO
);
216 intent
.setType("text/plain");
217 intent
.setData(Uri
.parse(getString(R
.string
.mail_recommend
)));
218 intent
.addFlags(Intent
.FLAG_ACTIVITY_NEW_TASK
);
220 String appName
= getString(R
.string
.app_name
);
221 String downloadUrl
= getString(R
.string
.url_app_download
);
222 Account currentAccount
= AccountUtils
.getCurrentOwnCloudAccount(Preferences
.this);
223 String username
= currentAccount
.name
.substring(0, currentAccount
.name
.lastIndexOf('@'));
225 String recommendSubject
= String
.format(getString(R
.string
.recommend_subject
), appName
);
226 String recommendText
= String
.format(getString(R
.string
.recommend_text
),
227 appName
, downloadUrl
, username
);
229 intent
.putExtra(Intent
.EXTRA_SUBJECT
, recommendSubject
);
230 intent
.putExtra(Intent
.EXTRA_TEXT
, recommendText
);
231 startActivity(intent
);
238 preferenceCategory
.removePreference(pRecommend
);
243 boolean feedbackEnabled
= getResources().getBoolean(R
.bool
.feedback_enabled
);
244 Preference pFeedback
= findPreference("feedback");
245 if (pFeedback
!= null
){
246 if (feedbackEnabled
) {
247 pFeedback
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
249 public boolean onPreferenceClick(Preference preference
) {
250 String feedbackMail
=(String
) getText(R
.string
.mail_feedback
);
251 String feedback
=(String
) getText(R
.string
.prefs_feedback
) + " - android v" + appVersion
;
252 Intent intent
= new Intent(Intent
.ACTION_SENDTO
);
253 intent
.setType("text/plain");
254 intent
.putExtra(Intent
.EXTRA_SUBJECT
, feedback
);
256 intent
.setData(Uri
.parse(feedbackMail
));
257 intent
.addFlags(Intent
.FLAG_ACTIVITY_NEW_TASK
);
258 startActivity(intent
);
264 preferenceCategory
.removePreference(pFeedback
);
269 boolean imprintEnabled
= getResources().getBoolean(R
.bool
.imprint_enabled
);
270 Preference pImprint
= findPreference("imprint");
271 if (pImprint
!= null
) {
272 if (imprintEnabled
) {
273 pImprint
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
275 public boolean onPreferenceClick(Preference preference
) {
276 String imprintWeb
= (String
) getText(R
.string
.url_imprint
);
277 if (imprintWeb
!= null
&& imprintWeb
.length() > 0) {
278 Uri uriUrl
= Uri
.parse(imprintWeb
);
279 Intent intent
= new Intent(Intent
.ACTION_VIEW
, uriUrl
);
280 startActivity(intent
);
282 //ImprintDialog.newInstance(true).show(preference.get, "IMPRINT_DIALOG");
287 preferenceCategory
.removePreference(pImprint
);
291 mPrefInstantUploadPath
= findPreference("instant_upload_path");
292 if (mPrefInstantUploadPath
!= null
){
294 mPrefInstantUploadPath
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
296 public boolean onPreferenceClick(Preference preference
) {
297 if (!mUploadPath
.endsWith(OCFile
.PATH_SEPARATOR
)) {
298 mUploadPath
+= OCFile
.PATH_SEPARATOR
;
300 Intent intent
= new Intent(Preferences
.this, UploadPathActivity
.class);
301 intent
.putExtra(UploadPathActivity
.KEY_INSTANT_UPLOAD_PATH
, mUploadPath
);
302 startActivityForResult(intent
, ACTION_SELECT_UPLOAD_PATH
);
308 mPrefInstantUploadCategory
= (PreferenceCategory
) findPreference("instant_uploading_category");
310 mPrefInstantUploadPathWiFi
= findPreference("instant_upload_on_wifi");
311 mPrefInstantUpload
= findPreference("instant_uploading");
313 toggleInstantPictureOptions(((CheckBoxPreference
) mPrefInstantUpload
).isChecked());
315 mPrefInstantUpload
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
318 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
319 toggleInstantPictureOptions((Boolean
) newValue
);
324 mPrefInstantVideoUploadPath
= findPreference("instant_video_upload_path");
325 if (mPrefInstantVideoUploadPath
!= null
){
327 mPrefInstantVideoUploadPath
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
329 public boolean onPreferenceClick(Preference preference
) {
330 if (!mUploadVideoPath
.endsWith(OCFile
.PATH_SEPARATOR
)) {
331 mUploadVideoPath
+= OCFile
.PATH_SEPARATOR
;
333 Intent intent
= new Intent(Preferences
.this, UploadPathActivity
.class);
334 intent
.putExtra(UploadPathActivity
.KEY_INSTANT_UPLOAD_PATH
, mUploadVideoPath
);
335 startActivityForResult(intent
, ACTION_SELECT_UPLOAD_VIDEO_PATH
);
341 mPrefInstantVideoUploadPathWiFi
= findPreference("instant_video_upload_on_wifi");
342 mPrefInstantVideoUpload
= findPreference("instant_video_uploading");
343 toggleInstantVideoOptions(((CheckBoxPreference
) mPrefInstantVideoUpload
).isChecked());
345 mPrefInstantVideoUpload
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
348 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
349 toggleInstantVideoOptions((Boolean
) newValue
);
355 pAboutApp
= (Preference
) findPreference("about_app");
356 if (pAboutApp
!= null
) {
357 pAboutApp
.setTitle(String
.format(getString(R
.string
.about_android
), getString(R
.string
.app_name
)));
358 pAboutApp
.setSummary(String
.format(getString(R
.string
.about_version
), appVersion
));
361 loadInstantUploadPath();
362 loadInstantUploadVideoPath();
364 /* ComponentsGetter */
365 mDownloadServiceConnection
= newTransferenceServiceConnection();
366 if (mDownloadServiceConnection
!= null
) {
367 bindService(new Intent(this, FileDownloader
.class), mDownloadServiceConnection
,
368 Context
.BIND_AUTO_CREATE
);
370 mUploadServiceConnection
= newTransferenceServiceConnection();
371 if (mUploadServiceConnection
!= null
) {
372 bindService(new Intent(this, FileUploader
.class), mUploadServiceConnection
,
373 Context
.BIND_AUTO_CREATE
);
378 private void toggleInstantPictureOptions(Boolean value
){
380 mPrefInstantUploadCategory
.addPreference(mPrefInstantUploadPathWiFi
);
381 mPrefInstantUploadCategory
.addPreference(mPrefInstantUploadPath
);
383 mPrefInstantUploadCategory
.removePreference(mPrefInstantUploadPathWiFi
);
384 mPrefInstantUploadCategory
.removePreference(mPrefInstantUploadPath
);
388 private void toggleInstantVideoOptions(Boolean value
){
390 mPrefInstantUploadCategory
.addPreference(mPrefInstantVideoUploadPathWiFi
);
391 mPrefInstantUploadCategory
.addPreference(mPrefInstantVideoUploadPath
);
393 mPrefInstantUploadCategory
.removePreference(mPrefInstantVideoUploadPathWiFi
);
394 mPrefInstantUploadCategory
.removePreference(mPrefInstantVideoUploadPath
);
399 public void onCreateContextMenu(ContextMenu menu
, View v
, ContextMenuInfo menuInfo
) {
401 // Filter for only showing contextual menu when long press on the
403 if (mShowContextMenu
) {
404 getMenuInflater().inflate(R
.menu
.account_picker_long_click
, menu
);
405 mShowContextMenu
= false
;
407 super.onCreateContextMenu(menu
, v
, menuInfo
);
411 * Called when the user clicked on an item into the context menu created at
412 * {@link #onCreateContextMenu(ContextMenu, View, ContextMenuInfo)} for
413 * every ownCloud {@link Account} , containing 'secondary actions' for them.
418 public boolean onContextItemSelected(android
.view
.MenuItem item
) {
419 AccountManager am
= (AccountManager
) getSystemService(ACCOUNT_SERVICE
);
420 Account accounts
[] = am
.getAccountsByType(MainApp
.getAccountType());
421 for (Account a
: accounts
) {
422 if (a
.name
.equals(mAccountName
)) {
423 if (item
.getItemId() == R
.id
.change_password
) {
425 // Change account password
426 Intent updateAccountCredentials
= new Intent(this, AuthenticatorActivity
.class);
427 updateAccountCredentials
.putExtra(AuthenticatorActivity
.EXTRA_ACCOUNT
, a
);
428 updateAccountCredentials
.putExtra(AuthenticatorActivity
.EXTRA_ACTION
,
429 AuthenticatorActivity
.ACTION_UPDATE_TOKEN
);
430 startActivity(updateAccountCredentials
);
432 } else if (item
.getItemId() == R
.id
.delete_account
) {
435 am
.removeAccount(a
, this, mHandler
);
436 Log_OC
.d(TAG
, "Remove an account " + a
.name
);
445 public void run(AccountManagerFuture
<Boolean
> future
) {
446 if (future
.isDone()) {
447 // after remove account
448 Account account
= new Account(mAccountName
, MainApp
.getAccountType());
449 if (!AccountUtils
.exists(account
, MainApp
.getAppContext())) {
451 if (mUploaderBinder
!= null
) {
452 mUploaderBinder
.cancel(account
);
454 if (mDownloaderBinder
!= null
) {
455 mDownloaderBinder
.cancel(account
);
459 Account a
= AccountUtils
.getCurrentOwnCloudAccount(this);
460 String accountName
= "";
462 Account
[] accounts
= AccountManager
.get(this).getAccountsByType(MainApp
.getAccountType());
463 if (accounts
.length
!= 0)
464 accountName
= accounts
[0].name
;
465 AccountUtils
.setCurrentOwnCloudAccount(this, accountName
);
467 addAccountsCheckboxPreferences();
472 protected void onResume() {
474 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
475 boolean state
= appPrefs
.getBoolean("set_pincode", false
);
476 pCode
.setChecked(state
);
478 // Populate the accounts category with the list of accounts
479 addAccountsCheckboxPreferences();
483 public boolean onCreateOptionsMenu(Menu menu
) {
484 super.onCreateOptionsMenu(menu
);
489 public boolean onMenuItemSelected(int featureId
, MenuItem item
) {
490 super.onMenuItemSelected(featureId
, item
);
493 switch (item
.getItemId()) {
494 case android
.R
.id
.home
:
495 intent
= new Intent(getBaseContext(), FileDisplayActivity
.class);
496 intent
.addFlags(Intent
.FLAG_ACTIVITY_CLEAR_TOP
);
497 startActivity(intent
);
500 Log_OC
.w(TAG
, "Unknown menu item triggered");
507 protected void onActivityResult(int requestCode
, int resultCode
, Intent data
) {
508 super.onActivityResult(requestCode
, resultCode
, data
);
510 if (requestCode
== ACTION_SELECT_UPLOAD_PATH
&& resultCode
== RESULT_OK
){
512 OCFile folderToUpload
= (OCFile
) data
.getParcelableExtra(UploadPathActivity
.EXTRA_FOLDER
);
514 mUploadPath
= folderToUpload
.getRemotePath();
516 mUploadPath
= DisplayUtils
.getPathWithoutLastSlash(mUploadPath
);
518 // Show the path on summary preference
519 mPrefInstantUploadPath
.setSummary(mUploadPath
);
521 saveInstantUploadPathOnPreferences();
523 } else if (requestCode
== ACTION_SELECT_UPLOAD_VIDEO_PATH
&& resultCode
== RESULT_OK
){
525 OCFile folderToUploadVideo
= (OCFile
) data
.getParcelableExtra(UploadPathActivity
.EXTRA_FOLDER
);
527 mUploadVideoPath
= folderToUploadVideo
.getRemotePath();
529 mUploadVideoPath
= DisplayUtils
.getPathWithoutLastSlash(mUploadVideoPath
);
531 // Show the video path on summary preference
532 mPrefInstantVideoUploadPath
.setSummary(mUploadVideoPath
);
534 saveInstantUploadVideoPathOnPreferences();
539 protected void onDestroy() {
542 if (mDownloadServiceConnection
!= null
) {
543 unbindService(mDownloadServiceConnection
);
544 mDownloadServiceConnection
= null
;
546 if (mUploadServiceConnection
!= null
) {
547 unbindService(mUploadServiceConnection
);
548 mUploadServiceConnection
= null
;
555 * Create the list of accounts that has been added into the app
557 @SuppressWarnings("deprecation")
558 private void addAccountsCheckboxPreferences() {
560 // Remove accounts in case list is refreshing for avoiding to have
562 if (mAccountsPrefCategory
.getPreferenceCount() > 0) {
563 mAccountsPrefCategory
.removeAll();
566 AccountManager am
= (AccountManager
) getSystemService(ACCOUNT_SERVICE
);
567 Account accounts
[] = am
.getAccountsByType(MainApp
.getAccountType());
568 Account currentAccount
= AccountUtils
.getCurrentOwnCloudAccount(getApplicationContext());
570 if (am
.getAccountsByType(MainApp
.getAccountType()).length
== 0) {
571 // Show create account screen if there isn't any account
572 am
.addAccount(MainApp
.getAccountType(), null
, null
, null
, this,
578 for (Account a
: accounts
) {
579 RadioButtonPreference accountPreference
= new RadioButtonPreference(this);
580 accountPreference
.setKey(a
.name
);
581 // Handle internationalized domain names
582 accountPreference
.setTitle(DisplayUtils
.convertIdn(a
.name
, false
));
583 mAccountsPrefCategory
.addPreference(accountPreference
);
585 // Check the current account that is being used
586 if (a
.name
.equals(currentAccount
.name
)) {
587 accountPreference
.setChecked(true
);
589 accountPreference
.setChecked(false
);
592 accountPreference
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
594 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
595 String key
= preference
.getKey();
596 AccountManager am
= (AccountManager
) getSystemService(ACCOUNT_SERVICE
);
597 Account accounts
[] = am
.getAccountsByType(MainApp
.getAccountType());
598 for (Account a
: accounts
) {
599 RadioButtonPreference p
= (RadioButtonPreference
) findPreference(a
.name
);
600 if (key
.equals(a
.name
)) {
601 boolean accountChanged
= !p
.isChecked();
603 AccountUtils
.setCurrentOwnCloudAccount(
604 getApplicationContext(),
607 if (accountChanged
) {
608 // restart the main activity
609 Intent i
= new Intent(
611 FileDisplayActivity
.class
613 i
.addFlags(Intent
.FLAG_ACTIVITY_CLEAR_TOP
);
614 i
.addFlags(Intent
.FLAG_ACTIVITY_SINGLE_TOP
);
623 return (Boolean
) newValue
;
629 // Add Create Account preference at the end of account list if
630 // Multiaccount is enabled
631 if (getResources().getBoolean(R
.bool
.multiaccount_support
)) {
632 createAddAccountPreference();
639 * Create the preference for allow adding new accounts
641 private void createAddAccountPreference() {
642 Preference addAccountPref
= new Preference(this);
643 addAccountPref
.setKey("add_account");
644 addAccountPref
.setTitle(getString(R
.string
.prefs_add_account
));
645 mAccountsPrefCategory
.addPreference(addAccountPref
);
647 addAccountPref
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
649 public boolean onPreferenceClick(Preference preference
) {
650 AccountManager am
= AccountManager
.get(getApplicationContext());
651 am
.addAccount(MainApp
.getAccountType(), null
, null
, null
, Preferences
.this, null
, null
);
659 * Load upload path set on preferences
661 private void loadInstantUploadPath() {
662 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
663 mUploadPath
= appPrefs
.getString("instant_upload_path", getString(R
.string
.instant_upload_path
));
664 mPrefInstantUploadPath
.setSummary(mUploadPath
);
668 * Save the "Instant Upload Path" on preferences
670 private void saveInstantUploadPathOnPreferences() {
671 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
672 SharedPreferences
.Editor editor
= appPrefs
.edit();
673 editor
.putString("instant_upload_path", mUploadPath
);
678 * Load upload video path set on preferences
680 private void loadInstantUploadVideoPath() {
681 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
682 mUploadVideoPath
= appPrefs
.getString("instant_video_upload_path", getString(R
.string
.instant_upload_path
));
683 mPrefInstantVideoUploadPath
.setSummary(mUploadVideoPath
);
687 * Save the "Instant Video Upload Path" on preferences
689 private void saveInstantUploadVideoPathOnPreferences() {
690 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
691 SharedPreferences
.Editor editor
= appPrefs
.edit();
692 editor
.putString("instant_video_upload_path", mUploadVideoPath
);
696 // Methods for ComponetsGetter
698 public FileDownloader
.FileDownloaderBinder
getFileDownloaderBinder() {
699 return mDownloaderBinder
;
704 public FileUploader
.FileUploaderBinder
getFileUploaderBinder() {
705 return mUploaderBinder
;
709 public OperationsService
.OperationsServiceBinder
getOperationsServiceBinder() {
714 public FileDataStorageManager
getStorageManager() {
719 public FileOperationsHelper
getFileOperationsHelper() {
723 protected ServiceConnection
newTransferenceServiceConnection() {
724 return new PreferencesServiceConnection();
727 /** Defines callbacks for service binding, passed to bindService() */
728 private class PreferencesServiceConnection
implements ServiceConnection
{
731 public void onServiceConnected(ComponentName component
, IBinder service
) {
733 if (component
.equals(new ComponentName(Preferences
.this, FileDownloader
.class))) {
734 mDownloaderBinder
= (FileDownloader
.FileDownloaderBinder
) service
;
736 } else if (component
.equals(new ComponentName(Preferences
.this, FileUploader
.class))) {
737 Log_OC
.d(TAG
, "Upload service connected");
738 mUploaderBinder
= (FileUploader
.FileUploaderBinder
) service
;
746 public void onServiceDisconnected(ComponentName component
) {
747 if (component
.equals(new ComponentName(Preferences
.this, FileDownloader
.class))) {
748 Log_OC
.d(TAG
, "Download service suddenly disconnected");
749 mDownloaderBinder
= null
;
750 } else if (component
.equals(new ComponentName(Preferences
.this, FileUploader
.class))) {
751 Log_OC
.d(TAG
, "Upload service suddenly disconnected");
752 mUploaderBinder
= null
;