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 i
.setAction(PassCodeActivity
.ACTION_TOGGLE
);
171 i
.putExtra(PassCodeActivity
.EXTRA_NEW_STATE
, newValue
.toString());
180 PreferenceCategory preferenceCategory
= (PreferenceCategory
) findPreference("more");
182 boolean helpEnabled
= getResources().getBoolean(R
.bool
.help_enabled
);
183 Preference pHelp
= findPreference("help");
186 pHelp
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
188 public boolean onPreferenceClick(Preference preference
) {
189 String helpWeb
=(String
) getText(R
.string
.url_help
);
190 if (helpWeb
!= null
&& helpWeb
.length() > 0) {
191 Uri uriUrl
= Uri
.parse(helpWeb
);
192 Intent intent
= new Intent(Intent
.ACTION_VIEW
, uriUrl
);
193 startActivity(intent
);
199 preferenceCategory
.removePreference(pHelp
);
205 boolean recommendEnabled
= getResources().getBoolean(R
.bool
.recommend_enabled
);
206 Preference pRecommend
= findPreference("recommend");
207 if (pRecommend
!= null
){
208 if (recommendEnabled
) {
209 pRecommend
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
211 public boolean onPreferenceClick(Preference preference
) {
213 Intent intent
= new Intent(Intent
.ACTION_SENDTO
);
214 intent
.setType("text/plain");
215 intent
.setData(Uri
.parse(getString(R
.string
.mail_recommend
)));
216 intent
.addFlags(Intent
.FLAG_ACTIVITY_NEW_TASK
);
218 String appName
= getString(R
.string
.app_name
);
219 String downloadUrl
= getString(R
.string
.url_app_download
);
220 Account currentAccount
= AccountUtils
.getCurrentOwnCloudAccount(Preferences
.this);
221 String username
= currentAccount
.name
.substring(0, currentAccount
.name
.lastIndexOf('@'));
223 String recommendSubject
= String
.format(getString(R
.string
.recommend_subject
), appName
);
224 String recommendText
= String
.format(getString(R
.string
.recommend_text
),
225 appName
, downloadUrl
, username
);
227 intent
.putExtra(Intent
.EXTRA_SUBJECT
, recommendSubject
);
228 intent
.putExtra(Intent
.EXTRA_TEXT
, recommendText
);
229 startActivity(intent
);
236 preferenceCategory
.removePreference(pRecommend
);
241 boolean feedbackEnabled
= getResources().getBoolean(R
.bool
.feedback_enabled
);
242 Preference pFeedback
= findPreference("feedback");
243 if (pFeedback
!= null
){
244 if (feedbackEnabled
) {
245 pFeedback
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
247 public boolean onPreferenceClick(Preference preference
) {
248 String feedbackMail
=(String
) getText(R
.string
.mail_feedback
);
249 String feedback
=(String
) getText(R
.string
.prefs_feedback
) + " - android v" + appVersion
;
250 Intent intent
= new Intent(Intent
.ACTION_SENDTO
);
251 intent
.setType("text/plain");
252 intent
.putExtra(Intent
.EXTRA_SUBJECT
, feedback
);
254 intent
.setData(Uri
.parse(feedbackMail
));
255 intent
.addFlags(Intent
.FLAG_ACTIVITY_NEW_TASK
);
256 startActivity(intent
);
262 preferenceCategory
.removePreference(pFeedback
);
267 boolean imprintEnabled
= getResources().getBoolean(R
.bool
.imprint_enabled
);
268 Preference pImprint
= findPreference("imprint");
269 if (pImprint
!= null
) {
270 if (imprintEnabled
) {
271 pImprint
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
273 public boolean onPreferenceClick(Preference preference
) {
274 String imprintWeb
= (String
) getText(R
.string
.url_imprint
);
275 if (imprintWeb
!= null
&& imprintWeb
.length() > 0) {
276 Uri uriUrl
= Uri
.parse(imprintWeb
);
277 Intent intent
= new Intent(Intent
.ACTION_VIEW
, uriUrl
);
278 startActivity(intent
);
280 //ImprintDialog.newInstance(true).show(preference.get, "IMPRINT_DIALOG");
285 preferenceCategory
.removePreference(pImprint
);
289 mPrefInstantUploadPath
= findPreference("instant_upload_path");
290 if (mPrefInstantUploadPath
!= null
){
292 mPrefInstantUploadPath
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
294 public boolean onPreferenceClick(Preference preference
) {
295 if (!mUploadPath
.endsWith(OCFile
.PATH_SEPARATOR
)) {
296 mUploadPath
+= OCFile
.PATH_SEPARATOR
;
298 Intent intent
= new Intent(Preferences
.this, UploadPathActivity
.class);
299 intent
.putExtra(UploadPathActivity
.KEY_INSTANT_UPLOAD_PATH
, mUploadPath
);
300 startActivityForResult(intent
, ACTION_SELECT_UPLOAD_PATH
);
306 mPrefInstantUploadCategory
= (PreferenceCategory
) findPreference("instant_uploading_category");
308 mPrefInstantUploadPathWiFi
= findPreference("instant_upload_on_wifi");
309 mPrefInstantUpload
= findPreference("instant_uploading");
311 toggleInstantPictureOptions(((CheckBoxPreference
) mPrefInstantUpload
).isChecked());
313 mPrefInstantUpload
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
316 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
317 toggleInstantPictureOptions((Boolean
) newValue
);
322 mPrefInstantVideoUploadPath
= findPreference("instant_video_upload_path");
323 if (mPrefInstantVideoUploadPath
!= null
){
325 mPrefInstantVideoUploadPath
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
327 public boolean onPreferenceClick(Preference preference
) {
328 if (!mUploadVideoPath
.endsWith(OCFile
.PATH_SEPARATOR
)) {
329 mUploadVideoPath
+= OCFile
.PATH_SEPARATOR
;
331 Intent intent
= new Intent(Preferences
.this, UploadPathActivity
.class);
332 intent
.putExtra(UploadPathActivity
.KEY_INSTANT_UPLOAD_PATH
, mUploadVideoPath
);
333 startActivityForResult(intent
, ACTION_SELECT_UPLOAD_VIDEO_PATH
);
339 mPrefInstantVideoUploadPathWiFi
= findPreference("instant_video_upload_on_wifi");
340 mPrefInstantVideoUpload
= findPreference("instant_video_uploading");
341 toggleInstantVideoOptions(((CheckBoxPreference
) mPrefInstantVideoUpload
).isChecked());
343 mPrefInstantVideoUpload
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
346 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
347 toggleInstantVideoOptions((Boolean
) newValue
);
353 pAboutApp
= (Preference
) findPreference("about_app");
354 if (pAboutApp
!= null
) {
355 pAboutApp
.setTitle(String
.format(getString(R
.string
.about_android
), getString(R
.string
.app_name
)));
356 pAboutApp
.setSummary(String
.format(getString(R
.string
.about_version
), appVersion
));
359 loadInstantUploadPath();
360 loadInstantUploadVideoPath();
362 /* ComponentsGetter */
363 mDownloadServiceConnection
= newTransferenceServiceConnection();
364 if (mDownloadServiceConnection
!= null
) {
365 bindService(new Intent(this, FileDownloader
.class), mDownloadServiceConnection
,
366 Context
.BIND_AUTO_CREATE
);
368 mUploadServiceConnection
= newTransferenceServiceConnection();
369 if (mUploadServiceConnection
!= null
) {
370 bindService(new Intent(this, FileUploader
.class), mUploadServiceConnection
,
371 Context
.BIND_AUTO_CREATE
);
376 private void toggleInstantPictureOptions(Boolean value
){
378 mPrefInstantUploadCategory
.addPreference(mPrefInstantUploadPathWiFi
);
379 mPrefInstantUploadCategory
.addPreference(mPrefInstantUploadPath
);
381 mPrefInstantUploadCategory
.removePreference(mPrefInstantUploadPathWiFi
);
382 mPrefInstantUploadCategory
.removePreference(mPrefInstantUploadPath
);
386 private void toggleInstantVideoOptions(Boolean value
){
388 mPrefInstantUploadCategory
.addPreference(mPrefInstantVideoUploadPathWiFi
);
389 mPrefInstantUploadCategory
.addPreference(mPrefInstantVideoUploadPath
);
391 mPrefInstantUploadCategory
.removePreference(mPrefInstantVideoUploadPathWiFi
);
392 mPrefInstantUploadCategory
.removePreference(mPrefInstantVideoUploadPath
);
397 public void onCreateContextMenu(ContextMenu menu
, View v
, ContextMenuInfo menuInfo
) {
399 // Filter for only showing contextual menu when long press on the
401 if (mShowContextMenu
) {
402 getMenuInflater().inflate(R
.menu
.account_picker_long_click
, menu
);
403 mShowContextMenu
= false
;
405 super.onCreateContextMenu(menu
, v
, menuInfo
);
409 * Called when the user clicked on an item into the context menu created at
410 * {@link #onCreateContextMenu(ContextMenu, View, ContextMenuInfo)} for
411 * every ownCloud {@link Account} , containing 'secondary actions' for them.
416 public boolean onContextItemSelected(android
.view
.MenuItem item
) {
417 AccountManager am
= (AccountManager
) getSystemService(ACCOUNT_SERVICE
);
418 Account accounts
[] = am
.getAccountsByType(MainApp
.getAccountType());
419 for (Account a
: accounts
) {
420 if (a
.name
.equals(mAccountName
)) {
421 if (item
.getItemId() == R
.id
.change_password
) {
423 // Change account password
424 Intent updateAccountCredentials
= new Intent(this, AuthenticatorActivity
.class);
425 updateAccountCredentials
.putExtra(AuthenticatorActivity
.EXTRA_ACCOUNT
, a
);
426 updateAccountCredentials
.putExtra(AuthenticatorActivity
.EXTRA_ACTION
,
427 AuthenticatorActivity
.ACTION_UPDATE_TOKEN
);
428 startActivity(updateAccountCredentials
);
430 } else if (item
.getItemId() == R
.id
.delete_account
) {
433 am
.removeAccount(a
, this, mHandler
);
434 Log_OC
.d(TAG
, "Remove an account " + a
.name
);
443 public void run(AccountManagerFuture
<Boolean
> future
) {
444 if (future
.isDone()) {
445 // after remove account
446 Account account
= new Account(mAccountName
, MainApp
.getAccountType());
447 if (!AccountUtils
.exists(account
, MainApp
.getAppContext())) {
449 if (mUploaderBinder
!= null
) {
450 mUploaderBinder
.cancel(account
);
452 if (mDownloaderBinder
!= null
) {
453 mDownloaderBinder
.cancel(account
);
457 Account a
= AccountUtils
.getCurrentOwnCloudAccount(this);
458 String accountName
= "";
460 Account
[] accounts
= AccountManager
.get(this).getAccountsByType(MainApp
.getAccountType());
461 if (accounts
.length
!= 0)
462 accountName
= accounts
[0].name
;
463 AccountUtils
.setCurrentOwnCloudAccount(this, accountName
);
465 addAccountsCheckboxPreferences();
470 protected void onResume() {
472 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
473 boolean state
= appPrefs
.getBoolean("set_pincode", false
);
474 pCode
.setChecked(state
);
476 // Populate the accounts category with the list of accounts
477 addAccountsCheckboxPreferences();
481 public boolean onCreateOptionsMenu(Menu menu
) {
482 super.onCreateOptionsMenu(menu
);
487 public boolean onMenuItemSelected(int featureId
, MenuItem item
) {
488 super.onMenuItemSelected(featureId
, item
);
491 switch (item
.getItemId()) {
492 case android
.R
.id
.home
:
493 intent
= new Intent(getBaseContext(), FileDisplayActivity
.class);
494 intent
.addFlags(Intent
.FLAG_ACTIVITY_CLEAR_TOP
);
495 startActivity(intent
);
498 Log_OC
.w(TAG
, "Unknown menu item triggered");
505 protected void onActivityResult(int requestCode
, int resultCode
, Intent data
) {
506 super.onActivityResult(requestCode
, resultCode
, data
);
508 if (requestCode
== ACTION_SELECT_UPLOAD_PATH
&& resultCode
== RESULT_OK
){
510 OCFile folderToUpload
= (OCFile
) data
.getParcelableExtra(UploadPathActivity
.EXTRA_FOLDER
);
512 mUploadPath
= folderToUpload
.getRemotePath();
514 mUploadPath
= DisplayUtils
.getPathWithoutLastSlash(mUploadPath
);
516 // Show the path on summary preference
517 mPrefInstantUploadPath
.setSummary(mUploadPath
);
519 saveInstantUploadPathOnPreferences();
521 } else if (requestCode
== ACTION_SELECT_UPLOAD_VIDEO_PATH
&& resultCode
== RESULT_OK
){
523 OCFile folderToUploadVideo
= (OCFile
) data
.getParcelableExtra(UploadPathActivity
.EXTRA_FOLDER
);
525 mUploadVideoPath
= folderToUploadVideo
.getRemotePath();
527 mUploadVideoPath
= DisplayUtils
.getPathWithoutLastSlash(mUploadVideoPath
);
529 // Show the video path on summary preference
530 mPrefInstantVideoUploadPath
.setSummary(mUploadVideoPath
);
532 saveInstantUploadVideoPathOnPreferences();
537 protected void onDestroy() {
540 if (mDownloadServiceConnection
!= null
) {
541 unbindService(mDownloadServiceConnection
);
542 mDownloadServiceConnection
= null
;
544 if (mUploadServiceConnection
!= null
) {
545 unbindService(mUploadServiceConnection
);
546 mUploadServiceConnection
= null
;
553 * Create the list of accounts that has been added into the app
555 @SuppressWarnings("deprecation")
556 private void addAccountsCheckboxPreferences() {
558 // Remove accounts in case list is refreshing for avoiding to have
560 if (mAccountsPrefCategory
.getPreferenceCount() > 0) {
561 mAccountsPrefCategory
.removeAll();
564 AccountManager am
= (AccountManager
) getSystemService(ACCOUNT_SERVICE
);
565 Account accounts
[] = am
.getAccountsByType(MainApp
.getAccountType());
566 Account currentAccount
= AccountUtils
.getCurrentOwnCloudAccount(getApplicationContext());
568 if (am
.getAccountsByType(MainApp
.getAccountType()).length
== 0) {
569 // Show create account screen if there isn't any account
570 am
.addAccount(MainApp
.getAccountType(), null
, null
, null
, this,
576 for (Account a
: accounts
) {
577 RadioButtonPreference accountPreference
= new RadioButtonPreference(this);
578 accountPreference
.setKey(a
.name
);
579 // Handle internationalized domain names
580 accountPreference
.setTitle(DisplayUtils
.convertIdn(a
.name
, false
));
581 mAccountsPrefCategory
.addPreference(accountPreference
);
583 // Check the current account that is being used
584 if (a
.name
.equals(currentAccount
.name
)) {
585 accountPreference
.setChecked(true
);
587 accountPreference
.setChecked(false
);
590 accountPreference
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
592 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
593 String key
= preference
.getKey();
594 AccountManager am
= (AccountManager
) getSystemService(ACCOUNT_SERVICE
);
595 Account accounts
[] = am
.getAccountsByType(MainApp
.getAccountType());
596 for (Account a
: accounts
) {
597 RadioButtonPreference p
= (RadioButtonPreference
) findPreference(a
.name
);
598 if (key
.equals(a
.name
)) {
599 boolean accountChanged
= !p
.isChecked();
601 AccountUtils
.setCurrentOwnCloudAccount(
602 getApplicationContext(),
605 if (accountChanged
) {
606 // restart the main activity
607 Intent i
= new Intent(
609 FileDisplayActivity
.class
611 i
.addFlags(Intent
.FLAG_ACTIVITY_CLEAR_TOP
);
612 i
.addFlags(Intent
.FLAG_ACTIVITY_SINGLE_TOP
);
621 return (Boolean
) newValue
;
627 // Add Create Account preference at the end of account list if
628 // Multiaccount is enabled
629 if (getResources().getBoolean(R
.bool
.multiaccount_support
)) {
630 createAddAccountPreference();
637 * Create the preference for allow adding new accounts
639 private void createAddAccountPreference() {
640 Preference addAccountPref
= new Preference(this);
641 addAccountPref
.setKey("add_account");
642 addAccountPref
.setTitle(getString(R
.string
.prefs_add_account
));
643 mAccountsPrefCategory
.addPreference(addAccountPref
);
645 addAccountPref
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
647 public boolean onPreferenceClick(Preference preference
) {
648 AccountManager am
= AccountManager
.get(getApplicationContext());
649 am
.addAccount(MainApp
.getAccountType(), null
, null
, null
, Preferences
.this, null
, null
);
657 * Load upload path set on preferences
659 private void loadInstantUploadPath() {
660 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
661 mUploadPath
= appPrefs
.getString("instant_upload_path", getString(R
.string
.instant_upload_path
));
662 mPrefInstantUploadPath
.setSummary(mUploadPath
);
666 * Save the "Instant Upload Path" on preferences
668 private void saveInstantUploadPathOnPreferences() {
669 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
670 SharedPreferences
.Editor editor
= appPrefs
.edit();
671 editor
.putString("instant_upload_path", mUploadPath
);
676 * Load upload video path set on preferences
678 private void loadInstantUploadVideoPath() {
679 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
680 mUploadVideoPath
= appPrefs
.getString("instant_video_upload_path", getString(R
.string
.instant_upload_path
));
681 mPrefInstantVideoUploadPath
.setSummary(mUploadVideoPath
);
685 * Save the "Instant Video Upload Path" on preferences
687 private void saveInstantUploadVideoPathOnPreferences() {
688 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
689 SharedPreferences
.Editor editor
= appPrefs
.edit();
690 editor
.putString("instant_video_upload_path", mUploadVideoPath
);
694 // Methods for ComponetsGetter
696 public FileDownloader
.FileDownloaderBinder
getFileDownloaderBinder() {
697 return mDownloaderBinder
;
702 public FileUploader
.FileUploaderBinder
getFileUploaderBinder() {
703 return mUploaderBinder
;
707 public OperationsService
.OperationsServiceBinder
getOperationsServiceBinder() {
712 public FileDataStorageManager
getStorageManager() {
717 public FileOperationsHelper
getFileOperationsHelper() {
721 protected ServiceConnection
newTransferenceServiceConnection() {
722 return new PreferencesServiceConnection();
725 /** Defines callbacks for service binding, passed to bindService() */
726 private class PreferencesServiceConnection
implements ServiceConnection
{
729 public void onServiceConnected(ComponentName component
, IBinder service
) {
731 if (component
.equals(new ComponentName(Preferences
.this, FileDownloader
.class))) {
732 mDownloaderBinder
= (FileDownloader
.FileDownloaderBinder
) service
;
734 } else if (component
.equals(new ComponentName(Preferences
.this, FileUploader
.class))) {
735 Log_OC
.d(TAG
, "Upload service connected");
736 mUploaderBinder
= (FileUploader
.FileUploaderBinder
) service
;
744 public void onServiceDisconnected(ComponentName component
) {
745 if (component
.equals(new ComponentName(Preferences
.this, FileDownloader
.class))) {
746 Log_OC
.d(TAG
, "Download service suddenly disconnected");
747 mDownloaderBinder
= null
;
748 } else if (component
.equals(new ComponentName(Preferences
.this, FileUploader
.class))) {
749 Log_OC
.d(TAG
, "Upload service suddenly disconnected");
750 mUploaderBinder
= null
;