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
.authentication
.PinCheck
;
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(), PinCodeActivity
.class);
171 i
.setAction(PinCodeActivity
.ACTION_TOGGLE
);
172 i
.putExtra(PinCodeActivity
.EXTRA_NEW_STATE
, newValue
.toString());
181 PreferenceCategory preferenceCategory
= (PreferenceCategory
) findPreference("more");
183 boolean helpEnabled
= getResources().getBoolean(R
.bool
.help_enabled
);
184 Preference pHelp
= findPreference("help");
187 pHelp
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
189 public boolean onPreferenceClick(Preference preference
) {
190 String helpWeb
=(String
) getText(R
.string
.url_help
);
191 if (helpWeb
!= null
&& helpWeb
.length() > 0) {
192 Uri uriUrl
= Uri
.parse(helpWeb
);
193 Intent intent
= new Intent(Intent
.ACTION_VIEW
, uriUrl
);
194 startActivity(intent
);
200 preferenceCategory
.removePreference(pHelp
);
206 boolean recommendEnabled
= getResources().getBoolean(R
.bool
.recommend_enabled
);
207 Preference pRecommend
= findPreference("recommend");
208 if (pRecommend
!= null
){
209 if (recommendEnabled
) {
210 pRecommend
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
212 public boolean onPreferenceClick(Preference preference
) {
214 Intent intent
= new Intent(Intent
.ACTION_SENDTO
);
215 intent
.setType("text/plain");
216 intent
.setData(Uri
.parse(getString(R
.string
.mail_recommend
)));
217 intent
.addFlags(Intent
.FLAG_ACTIVITY_NEW_TASK
);
219 String appName
= getString(R
.string
.app_name
);
220 String downloadUrl
= getString(R
.string
.url_app_download
);
221 Account currentAccount
= AccountUtils
.getCurrentOwnCloudAccount(Preferences
.this);
222 String username
= currentAccount
.name
.substring(0, currentAccount
.name
.lastIndexOf('@'));
224 String recommendSubject
= String
.format(getString(R
.string
.recommend_subject
), appName
);
225 String recommendText
= String
.format(getString(R
.string
.recommend_text
),
226 appName
, downloadUrl
, username
);
228 intent
.putExtra(Intent
.EXTRA_SUBJECT
, recommendSubject
);
229 intent
.putExtra(Intent
.EXTRA_TEXT
, recommendText
);
230 startActivity(intent
);
237 preferenceCategory
.removePreference(pRecommend
);
242 boolean feedbackEnabled
= getResources().getBoolean(R
.bool
.feedback_enabled
);
243 Preference pFeedback
= findPreference("feedback");
244 if (pFeedback
!= null
){
245 if (feedbackEnabled
) {
246 pFeedback
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
248 public boolean onPreferenceClick(Preference preference
) {
249 String feedbackMail
=(String
) getText(R
.string
.mail_feedback
);
250 String feedback
=(String
) getText(R
.string
.prefs_feedback
) + " - android v" + appVersion
;
251 Intent intent
= new Intent(Intent
.ACTION_SENDTO
);
252 intent
.setType("text/plain");
253 intent
.putExtra(Intent
.EXTRA_SUBJECT
, feedback
);
255 intent
.setData(Uri
.parse(feedbackMail
));
256 intent
.addFlags(Intent
.FLAG_ACTIVITY_NEW_TASK
);
257 startActivity(intent
);
263 preferenceCategory
.removePreference(pFeedback
);
268 boolean imprintEnabled
= getResources().getBoolean(R
.bool
.imprint_enabled
);
269 Preference pImprint
= findPreference("imprint");
270 if (pImprint
!= null
) {
271 if (imprintEnabled
) {
272 pImprint
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
274 public boolean onPreferenceClick(Preference preference
) {
275 String imprintWeb
= (String
) getText(R
.string
.url_imprint
);
276 if (imprintWeb
!= null
&& imprintWeb
.length() > 0) {
277 Uri uriUrl
= Uri
.parse(imprintWeb
);
278 Intent intent
= new Intent(Intent
.ACTION_VIEW
, uriUrl
);
279 startActivity(intent
);
281 //ImprintDialog.newInstance(true).show(preference.get, "IMPRINT_DIALOG");
286 preferenceCategory
.removePreference(pImprint
);
290 mPrefInstantUploadPath
= findPreference("instant_upload_path");
291 if (mPrefInstantUploadPath
!= null
){
293 mPrefInstantUploadPath
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
295 public boolean onPreferenceClick(Preference preference
) {
296 if (!mUploadPath
.endsWith(OCFile
.PATH_SEPARATOR
)) {
297 mUploadPath
+= OCFile
.PATH_SEPARATOR
;
299 Intent intent
= new Intent(Preferences
.this, UploadPathActivity
.class);
300 intent
.putExtra(UploadPathActivity
.KEY_INSTANT_UPLOAD_PATH
, mUploadPath
);
301 startActivityForResult(intent
, ACTION_SELECT_UPLOAD_PATH
);
307 mPrefInstantUploadCategory
= (PreferenceCategory
) findPreference("instant_uploading_category");
309 mPrefInstantUploadPathWiFi
= findPreference("instant_upload_on_wifi");
310 mPrefInstantUpload
= findPreference("instant_uploading");
312 toggleInstantPictureOptions(((CheckBoxPreference
) mPrefInstantUpload
).isChecked());
314 mPrefInstantUpload
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
317 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
318 toggleInstantPictureOptions((Boolean
) newValue
);
323 mPrefInstantVideoUploadPath
= findPreference("instant_video_upload_path");
324 if (mPrefInstantVideoUploadPath
!= null
){
326 mPrefInstantVideoUploadPath
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
328 public boolean onPreferenceClick(Preference preference
) {
329 if (!mUploadVideoPath
.endsWith(OCFile
.PATH_SEPARATOR
)) {
330 mUploadVideoPath
+= OCFile
.PATH_SEPARATOR
;
332 Intent intent
= new Intent(Preferences
.this, UploadPathActivity
.class);
333 intent
.putExtra(UploadPathActivity
.KEY_INSTANT_UPLOAD_PATH
, mUploadVideoPath
);
334 startActivityForResult(intent
, ACTION_SELECT_UPLOAD_VIDEO_PATH
);
340 mPrefInstantVideoUploadPathWiFi
= findPreference("instant_video_upload_on_wifi");
341 mPrefInstantVideoUpload
= findPreference("instant_video_uploading");
342 toggleInstantVideoOptions(((CheckBoxPreference
) mPrefInstantVideoUpload
).isChecked());
344 mPrefInstantVideoUpload
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
347 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
348 toggleInstantVideoOptions((Boolean
) newValue
);
354 pAboutApp
= (Preference
) findPreference("about_app");
355 if (pAboutApp
!= null
) {
356 pAboutApp
.setTitle(String
.format(getString(R
.string
.about_android
), getString(R
.string
.app_name
)));
357 pAboutApp
.setSummary(String
.format(getString(R
.string
.about_version
), appVersion
));
360 loadInstantUploadPath();
361 loadInstantUploadVideoPath();
363 /* ComponentsGetter */
364 mDownloadServiceConnection
= newTransferenceServiceConnection();
365 if (mDownloadServiceConnection
!= null
) {
366 bindService(new Intent(this, FileDownloader
.class), mDownloadServiceConnection
,
367 Context
.BIND_AUTO_CREATE
);
369 mUploadServiceConnection
= newTransferenceServiceConnection();
370 if (mUploadServiceConnection
!= null
) {
371 bindService(new Intent(this, FileUploader
.class), mUploadServiceConnection
,
372 Context
.BIND_AUTO_CREATE
);
377 private void toggleInstantPictureOptions(Boolean value
){
379 mPrefInstantUploadCategory
.addPreference(mPrefInstantUploadPathWiFi
);
380 mPrefInstantUploadCategory
.addPreference(mPrefInstantUploadPath
);
382 mPrefInstantUploadCategory
.removePreference(mPrefInstantUploadPathWiFi
);
383 mPrefInstantUploadCategory
.removePreference(mPrefInstantUploadPath
);
387 private void toggleInstantVideoOptions(Boolean value
){
389 mPrefInstantUploadCategory
.addPreference(mPrefInstantVideoUploadPathWiFi
);
390 mPrefInstantUploadCategory
.addPreference(mPrefInstantVideoUploadPath
);
392 mPrefInstantUploadCategory
.removePreference(mPrefInstantVideoUploadPathWiFi
);
393 mPrefInstantUploadCategory
.removePreference(mPrefInstantVideoUploadPath
);
398 protected void onPause() {
401 PinCheck
.setUnlockTimestamp();
405 public void onCreateContextMenu(ContextMenu menu
, View v
, ContextMenuInfo menuInfo
) {
407 // Filter for only showing contextual menu when long press on the
409 if (mShowContextMenu
) {
410 getMenuInflater().inflate(R
.menu
.account_picker_long_click
, menu
);
411 mShowContextMenu
= false
;
413 super.onCreateContextMenu(menu
, v
, menuInfo
);
417 * Called when the user clicked on an item into the context menu created at
418 * {@link #onCreateContextMenu(ContextMenu, View, ContextMenuInfo)} for
419 * every ownCloud {@link Account} , containing 'secondary actions' for them.
424 public boolean onContextItemSelected(android
.view
.MenuItem item
) {
425 AccountManager am
= (AccountManager
) getSystemService(ACCOUNT_SERVICE
);
426 Account accounts
[] = am
.getAccountsByType(MainApp
.getAccountType());
427 for (Account a
: accounts
) {
428 if (a
.name
.equals(mAccountName
)) {
429 if (item
.getItemId() == R
.id
.change_password
) {
431 // Change account password
432 Intent updateAccountCredentials
= new Intent(this, AuthenticatorActivity
.class);
433 updateAccountCredentials
.putExtra(AuthenticatorActivity
.EXTRA_ACCOUNT
, a
);
434 updateAccountCredentials
.putExtra(AuthenticatorActivity
.EXTRA_ACTION
,
435 AuthenticatorActivity
.ACTION_UPDATE_TOKEN
);
436 startActivity(updateAccountCredentials
);
438 } else if (item
.getItemId() == R
.id
.delete_account
) {
441 am
.removeAccount(a
, this, mHandler
);
442 Log_OC
.d(TAG
, "Remove an account " + a
.name
);
451 public void run(AccountManagerFuture
<Boolean
> future
) {
452 if (future
.isDone()) {
453 // after remove account
454 Account account
= new Account(mAccountName
, MainApp
.getAccountType());
455 if (!AccountUtils
.exists(account
, MainApp
.getAppContext())) {
457 if (mUploaderBinder
!= null
) {
458 mUploaderBinder
.cancel(account
);
460 if (mDownloaderBinder
!= null
) {
461 mDownloaderBinder
.cancel(account
);
465 Account a
= AccountUtils
.getCurrentOwnCloudAccount(this);
466 String accountName
= "";
468 Account
[] accounts
= AccountManager
.get(this).getAccountsByType(MainApp
.getAccountType());
469 if (accounts
.length
!= 0)
470 accountName
= accounts
[0].name
;
471 AccountUtils
.setCurrentOwnCloudAccount(this, accountName
);
473 addAccountsCheckboxPreferences();
478 protected void onResume() {
480 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
481 boolean state
= appPrefs
.getBoolean("set_pincode", false
);
482 pCode
.setChecked(state
);
484 // Populate the accounts category with the list of accounts
485 addAccountsCheckboxPreferences();
489 public boolean onCreateOptionsMenu(Menu menu
) {
490 super.onCreateOptionsMenu(menu
);
495 public boolean onMenuItemSelected(int featureId
, MenuItem item
) {
496 super.onMenuItemSelected(featureId
, item
);
499 switch (item
.getItemId()) {
500 case android
.R
.id
.home
:
501 intent
= new Intent(getBaseContext(), FileDisplayActivity
.class);
502 intent
.addFlags(Intent
.FLAG_ACTIVITY_CLEAR_TOP
);
503 startActivity(intent
);
506 Log_OC
.w(TAG
, "Unknown menu item triggered");
513 protected void onActivityResult(int requestCode
, int resultCode
, Intent data
) {
514 super.onActivityResult(requestCode
, resultCode
, data
);
516 if (requestCode
== ACTION_SELECT_UPLOAD_PATH
&& resultCode
== RESULT_OK
){
518 OCFile folderToUpload
= (OCFile
) data
.getParcelableExtra(UploadPathActivity
.EXTRA_FOLDER
);
520 mUploadPath
= folderToUpload
.getRemotePath();
522 mUploadPath
= DisplayUtils
.getPathWithoutLastSlash(mUploadPath
);
524 // Show the path on summary preference
525 mPrefInstantUploadPath
.setSummary(mUploadPath
);
527 saveInstantUploadPathOnPreferences();
529 } else if (requestCode
== ACTION_SELECT_UPLOAD_VIDEO_PATH
&& resultCode
== RESULT_OK
){
531 OCFile folderToUploadVideo
= (OCFile
) data
.getParcelableExtra(UploadPathActivity
.EXTRA_FOLDER
);
533 mUploadVideoPath
= folderToUploadVideo
.getRemotePath();
535 mUploadVideoPath
= DisplayUtils
.getPathWithoutLastSlash(mUploadVideoPath
);
537 // Show the video path on summary preference
538 mPrefInstantVideoUploadPath
.setSummary(mUploadVideoPath
);
540 saveInstantUploadVideoPathOnPreferences();
545 protected void onDestroy() {
548 if (mDownloadServiceConnection
!= null
) {
549 unbindService(mDownloadServiceConnection
);
550 mDownloadServiceConnection
= null
;
552 if (mUploadServiceConnection
!= null
) {
553 unbindService(mUploadServiceConnection
);
554 mUploadServiceConnection
= null
;
561 * Create the list of accounts that has been added into the app
563 @SuppressWarnings("deprecation")
564 private void addAccountsCheckboxPreferences() {
566 // Remove accounts in case list is refreshing for avoiding to have
568 if (mAccountsPrefCategory
.getPreferenceCount() > 0) {
569 mAccountsPrefCategory
.removeAll();
572 AccountManager am
= (AccountManager
) getSystemService(ACCOUNT_SERVICE
);
573 Account accounts
[] = am
.getAccountsByType(MainApp
.getAccountType());
574 Account currentAccount
= AccountUtils
.getCurrentOwnCloudAccount(getApplicationContext());
576 if (am
.getAccountsByType(MainApp
.getAccountType()).length
== 0) {
577 // Show create account screen if there isn't any account
578 am
.addAccount(MainApp
.getAccountType(), null
, null
, null
, this,
584 for (Account a
: accounts
) {
585 RadioButtonPreference accountPreference
= new RadioButtonPreference(this);
586 accountPreference
.setKey(a
.name
);
587 // Handle internationalized domain names
588 accountPreference
.setTitle(DisplayUtils
.convertIdn(a
.name
, false
));
589 mAccountsPrefCategory
.addPreference(accountPreference
);
591 // Check the current account that is being used
592 if (a
.name
.equals(currentAccount
.name
)) {
593 accountPreference
.setChecked(true
);
595 accountPreference
.setChecked(false
);
598 accountPreference
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
600 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
601 String key
= preference
.getKey();
602 AccountManager am
= (AccountManager
) getSystemService(ACCOUNT_SERVICE
);
603 Account accounts
[] = am
.getAccountsByType(MainApp
.getAccountType());
604 for (Account a
: accounts
) {
605 RadioButtonPreference p
= (RadioButtonPreference
) findPreference(a
.name
);
606 if (key
.equals(a
.name
)) {
607 boolean accountChanged
= !p
.isChecked();
609 AccountUtils
.setCurrentOwnCloudAccount(
610 getApplicationContext(),
613 if (accountChanged
) {
614 // restart the main activity
615 Intent i
= new Intent(
617 FileDisplayActivity
.class
619 i
.addFlags(Intent
.FLAG_ACTIVITY_CLEAR_TOP
);
620 i
.addFlags(Intent
.FLAG_ACTIVITY_SINGLE_TOP
);
629 return (Boolean
) newValue
;
635 // Add Create Account preference at the end of account list if
636 // Multiaccount is enabled
637 if (getResources().getBoolean(R
.bool
.multiaccount_support
)) {
638 createAddAccountPreference();
645 * Create the preference for allow adding new accounts
647 private void createAddAccountPreference() {
648 Preference addAccountPref
= new Preference(this);
649 addAccountPref
.setKey("add_account");
650 addAccountPref
.setTitle(getString(R
.string
.prefs_add_account
));
651 mAccountsPrefCategory
.addPreference(addAccountPref
);
653 addAccountPref
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
655 public boolean onPreferenceClick(Preference preference
) {
656 AccountManager am
= AccountManager
.get(getApplicationContext());
657 am
.addAccount(MainApp
.getAccountType(), null
, null
, null
, Preferences
.this, null
, null
);
665 * Load upload path set on preferences
667 private void loadInstantUploadPath() {
668 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
669 mUploadPath
= appPrefs
.getString("instant_upload_path", getString(R
.string
.instant_upload_path
));
670 mPrefInstantUploadPath
.setSummary(mUploadPath
);
674 * Save the "Instant Upload Path" on preferences
676 private void saveInstantUploadPathOnPreferences() {
677 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
678 SharedPreferences
.Editor editor
= appPrefs
.edit();
679 editor
.putString("instant_upload_path", mUploadPath
);
684 * Load upload video path set on preferences
686 private void loadInstantUploadVideoPath() {
687 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
688 mUploadVideoPath
= appPrefs
.getString("instant_video_upload_path", getString(R
.string
.instant_upload_path
));
689 mPrefInstantVideoUploadPath
.setSummary(mUploadVideoPath
);
693 * Save the "Instant Video Upload Path" on preferences
695 private void saveInstantUploadVideoPathOnPreferences() {
696 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
697 SharedPreferences
.Editor editor
= appPrefs
.edit();
698 editor
.putString("instant_video_upload_path", mUploadVideoPath
);
702 // Methods for ComponetsGetter
704 public FileDownloader
.FileDownloaderBinder
getFileDownloaderBinder() {
705 return mDownloaderBinder
;
710 public FileUploader
.FileUploaderBinder
getFileUploaderBinder() {
711 return mUploaderBinder
;
715 public OperationsService
.OperationsServiceBinder
getOperationsServiceBinder() {
720 public FileDataStorageManager
getStorageManager() {
725 public FileOperationsHelper
getFileOperationsHelper() {
729 protected ServiceConnection
newTransferenceServiceConnection() {
730 return new PreferencesServiceConnection();
733 /** Defines callbacks for service binding, passed to bindService() */
734 private class PreferencesServiceConnection
implements ServiceConnection
{
737 public void onServiceConnected(ComponentName component
, IBinder service
) {
739 if (component
.equals(new ComponentName(Preferences
.this, FileDownloader
.class))) {
740 mDownloaderBinder
= (FileDownloader
.FileDownloaderBinder
) service
;
742 } else if (component
.equals(new ComponentName(Preferences
.this, FileUploader
.class))) {
743 Log_OC
.d(TAG
, "Upload service connected");
744 mUploaderBinder
= (FileUploader
.FileUploaderBinder
) service
;
752 public void onServiceDisconnected(ComponentName component
) {
753 if (component
.equals(new ComponentName(Preferences
.this, FileDownloader
.class))) {
754 Log_OC
.d(TAG
, "Download service suddenly disconnected");
755 mDownloaderBinder
= null
;
756 } else if (component
.equals(new ComponentName(Preferences
.this, FileUploader
.class))) {
757 Log_OC
.d(TAG
, "Upload service suddenly disconnected");
758 mUploaderBinder
= null
;