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
.Build
;
37 import android
.os
.Bundle
;
38 import android
.os
.Handler
;
39 import android
.os
.IBinder
;
40 import android
.preference
.CheckBoxPreference
;
41 import android
.preference
.Preference
;
42 import android
.preference
.Preference
.OnPreferenceChangeListener
;
43 import android
.preference
.Preference
.OnPreferenceClickListener
;
44 import android
.preference
.PreferenceActivity
;
45 import android
.preference
.PreferenceCategory
;
46 import android
.preference
.PreferenceManager
;
47 //import android.support.v7.app.ActionBar;
48 import android
.app
.ActionBar
;
49 import android
.view
.ContextMenu
;
50 import android
.view
.ContextMenu
.ContextMenuInfo
;
51 import android
.view
.Menu
;
52 import android
.view
.MenuItem
;
53 import android
.view
.View
;
54 import android
.widget
.AdapterView
;
55 import android
.widget
.AdapterView
.OnItemLongClickListener
;
56 import android
.widget
.ListAdapter
;
57 import android
.widget
.ListView
;
59 import com
.owncloud
.android
.BuildConfig
;
60 import com
.owncloud
.android
.MainApp
;
61 import com
.owncloud
.android
.R
;
62 import com
.owncloud
.android
.authentication
.AccountUtils
;
63 import com
.owncloud
.android
.authentication
.AuthenticatorActivity
;
64 import com
.owncloud
.android
.datamodel
.FileDataStorageManager
;
65 import com
.owncloud
.android
.datamodel
.OCFile
;
66 import com
.owncloud
.android
.db
.DbHandler
;
67 import com
.owncloud
.android
.files
.FileOperationsHelper
;
68 import com
.owncloud
.android
.files
.services
.FileDownloader
;
69 import com
.owncloud
.android
.files
.services
.FileUploader
;
70 import com
.owncloud
.android
.lib
.common
.utils
.Log_OC
;
71 import com
.owncloud
.android
.services
.OperationsService
;
72 import com
.owncloud
.android
.ui
.RadioButtonPreference
;
73 import com
.owncloud
.android
.utils
.DisplayUtils
;
77 * An Activity that allows the user to change the application's settings.
79 public class Preferences
extends PreferenceActivity
80 implements AccountManagerCallback
<Boolean
>, ComponentsGetter
{
82 private static final String TAG
= "OwnCloudPreferences";
84 private static final int ACTION_SELECT_UPLOAD_PATH
= 1;
85 private static final int ACTION_SELECT_UPLOAD_VIDEO_PATH
= 2;
87 private DbHandler mDbHandler
;
88 private CheckBoxPreference pCode
;
89 private Preference pAboutApp
;
91 private PreferenceCategory mAccountsPrefCategory
= null
;
92 private final Handler mHandler
= new Handler();
93 private String mAccountName
;
94 private boolean mShowContextMenu
= false
;
95 private String mUploadPath
;
96 private PreferenceCategory mPrefInstantUploadCategory
;
97 private Preference mPrefInstantUpload
;
98 private Preference mPrefInstantUploadPath
;
99 private Preference mPrefInstantUploadPathWiFi
;
100 private Preference mPrefInstantVideoUpload
;
101 private Preference mPrefInstantVideoUploadPath
;
102 private Preference mPrefInstantVideoUploadPathWiFi
;
103 private String mUploadVideoPath
;
105 protected FileDownloader
.FileDownloaderBinder mDownloaderBinder
= null
;
106 protected FileUploader
.FileUploaderBinder mUploaderBinder
= null
;
107 private ServiceConnection mDownloadServiceConnection
, mUploadServiceConnection
= null
;
109 @SuppressWarnings("deprecation")
111 public void onCreate(Bundle savedInstanceState
) {
112 super.onCreate(savedInstanceState
);
113 mDbHandler
= new DbHandler(getBaseContext());
114 addPreferencesFromResource(R
.xml
.preferences
);
116 // Set properties of Action Bar in an ugly workaround to build correctly without upgrading minSdk
117 // TODO : increase minSdk; scheduled for next realease, don't wont to mix with this US
118 if (Build
.VERSION
.SDK_INT
>= Build
.VERSION_CODES
.HONEYCOMB
) {
119 ActionBar actionBar
= getActionBar();
120 if (Build
.VERSION
.SDK_INT
>= Build
.VERSION_CODES
.ICE_CREAM_SANDWICH
) {
121 actionBar
.setIcon(DisplayUtils
.getSeasonalIconId());
123 actionBar
.setDisplayHomeAsUpEnabled(true
);
124 actionBar
.setTitle(R
.string
.actionbar_settings
);
126 setTitle(R
.string
.actionbar_settings
);
129 // For adding content description tag to a title field in the action bar
130 int actionBarTitleId
= getResources().getIdentifier("action_bar_title", "id", "android");
131 View actionBarTitleView
= getWindow().getDecorView().findViewById(actionBarTitleId
);
132 if (actionBarTitleView
!= null
) { // it's null in Android 2.x
133 getWindow().getDecorView().findViewById(actionBarTitleId
).
134 setContentDescription(getString(R
.string
.actionbar_settings
));
137 // Load the accounts category for adding the list of accounts
138 mAccountsPrefCategory
= (PreferenceCategory
) findPreference("accounts_category");
140 ListView listView
= getListView();
141 listView
.setOnItemLongClickListener(new OnItemLongClickListener() {
143 public boolean onItemLongClick(AdapterView
<?
> parent
, View view
, int position
, long id
) {
144 ListView listView
= (ListView
) parent
;
145 ListAdapter listAdapter
= listView
.getAdapter();
146 Object obj
= listAdapter
.getItem(position
);
148 if (obj
!= null
&& obj
instanceof RadioButtonPreference
) {
149 mShowContextMenu
= true
;
150 mAccountName
= ((RadioButtonPreference
) obj
).getKey();
152 Preferences
.this.openContextMenu(listView
);
154 View
.OnLongClickListener longListener
= (View
.OnLongClickListener
) obj
;
155 return longListener
.onLongClick(view
);
164 PackageInfo pkg
= getPackageManager().getPackageInfo(getPackageName(), 0);
165 temp
= pkg
.versionName
;
166 } catch (NameNotFoundException e
) {
168 Log_OC
.e(TAG
, "Error while showing about dialog", e
);
170 final String appVersion
= temp
;
172 // Register context menu for list of preferences.
173 registerForContextMenu(getListView());
175 pCode
= (CheckBoxPreference
) findPreference("set_pincode");
177 pCode
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
179 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
180 Intent i
= new Intent(getApplicationContext(), PassCodeActivity
.class);
181 Boolean enable
= (Boolean
) newValue
;
183 enable
.booleanValue() ? PassCodeActivity
.ACTION_ENABLE
: PassCodeActivity
.ACTION_DISABLE
193 PreferenceCategory preferenceCategory
= (PreferenceCategory
) findPreference("more");
195 boolean helpEnabled
= getResources().getBoolean(R
.bool
.help_enabled
);
196 Preference pHelp
= findPreference("help");
199 pHelp
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
201 public boolean onPreferenceClick(Preference preference
) {
202 String helpWeb
=(String
) getText(R
.string
.url_help
);
203 if (helpWeb
!= null
&& helpWeb
.length() > 0) {
204 Uri uriUrl
= Uri
.parse(helpWeb
);
205 Intent intent
= new Intent(Intent
.ACTION_VIEW
, uriUrl
);
206 startActivity(intent
);
212 preferenceCategory
.removePreference(pHelp
);
217 if (BuildConfig
.DEBUG
) {
218 Preference pLog
= findPreference("log");
220 pLog
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
222 public boolean onPreferenceClick(Preference preference
) {
223 Intent loggerIntent
= new Intent(getApplicationContext(),LogHistoryActivity
.class);
224 startActivity(loggerIntent
);
231 boolean recommendEnabled
= getResources().getBoolean(R
.bool
.recommend_enabled
);
232 Preference pRecommend
= findPreference("recommend");
233 if (pRecommend
!= null
){
234 if (recommendEnabled
) {
235 pRecommend
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
237 public boolean onPreferenceClick(Preference preference
) {
239 Intent intent
= new Intent(Intent
.ACTION_SENDTO
);
240 intent
.setType("text/plain");
241 intent
.setData(Uri
.parse(getString(R
.string
.mail_recommend
)));
242 intent
.addFlags(Intent
.FLAG_ACTIVITY_NEW_TASK
);
244 String appName
= getString(R
.string
.app_name
);
245 String downloadUrl
= getString(R
.string
.url_app_download
);
246 Account currentAccount
= AccountUtils
.getCurrentOwnCloudAccount(Preferences
.this);
247 String username
= currentAccount
.name
.substring(0, currentAccount
.name
.lastIndexOf('@'));
249 String recommendSubject
= String
.format(getString(R
.string
.recommend_subject
),
251 String recommendText
= String
.format(getString(R
.string
.recommend_text
),
252 appName
, downloadUrl
, username
);
254 intent
.putExtra(Intent
.EXTRA_SUBJECT
, recommendSubject
);
255 intent
.putExtra(Intent
.EXTRA_TEXT
, recommendText
);
256 startActivity(intent
);
263 preferenceCategory
.removePreference(pRecommend
);
268 boolean feedbackEnabled
= getResources().getBoolean(R
.bool
.feedback_enabled
);
269 Preference pFeedback
= findPreference("feedback");
270 if (pFeedback
!= null
){
271 if (feedbackEnabled
) {
272 pFeedback
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
274 public boolean onPreferenceClick(Preference preference
) {
275 String feedbackMail
=(String
) getText(R
.string
.mail_feedback
);
276 String feedback
=(String
) getText(R
.string
.prefs_feedback
) + " - android v" + appVersion
;
277 Intent intent
= new Intent(Intent
.ACTION_SENDTO
);
278 intent
.setType("text/plain");
279 intent
.putExtra(Intent
.EXTRA_SUBJECT
, feedback
);
281 intent
.setData(Uri
.parse(feedbackMail
));
282 intent
.addFlags(Intent
.FLAG_ACTIVITY_NEW_TASK
);
283 startActivity(intent
);
289 preferenceCategory
.removePreference(pFeedback
);
294 boolean imprintEnabled
= getResources().getBoolean(R
.bool
.imprint_enabled
);
295 Preference pImprint
= findPreference("imprint");
296 if (pImprint
!= null
) {
297 if (imprintEnabled
) {
298 pImprint
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
300 public boolean onPreferenceClick(Preference preference
) {
301 String imprintWeb
= (String
) getText(R
.string
.url_imprint
);
302 if (imprintWeb
!= null
&& imprintWeb
.length() > 0) {
303 Uri uriUrl
= Uri
.parse(imprintWeb
);
304 Intent intent
= new Intent(Intent
.ACTION_VIEW
, uriUrl
);
305 startActivity(intent
);
307 //ImprintDialog.newInstance(true).show(preference.get, "IMPRINT_DIALOG");
312 preferenceCategory
.removePreference(pImprint
);
316 mPrefInstantUploadPath
= findPreference("instant_upload_path");
317 if (mPrefInstantUploadPath
!= null
){
319 mPrefInstantUploadPath
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
321 public boolean onPreferenceClick(Preference preference
) {
322 if (!mUploadPath
.endsWith(OCFile
.PATH_SEPARATOR
)) {
323 mUploadPath
+= OCFile
.PATH_SEPARATOR
;
325 Intent intent
= new Intent(Preferences
.this, UploadPathActivity
.class);
326 intent
.putExtra(UploadPathActivity
.KEY_INSTANT_UPLOAD_PATH
, mUploadPath
);
327 startActivityForResult(intent
, ACTION_SELECT_UPLOAD_PATH
);
333 mPrefInstantUploadCategory
= (PreferenceCategory
) findPreference("instant_uploading_category");
335 mPrefInstantUploadPathWiFi
= findPreference("instant_upload_on_wifi");
336 mPrefInstantUpload
= findPreference("instant_uploading");
338 toggleInstantPictureOptions(((CheckBoxPreference
) mPrefInstantUpload
).isChecked());
340 mPrefInstantUpload
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
343 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
344 toggleInstantPictureOptions((Boolean
) newValue
);
349 mPrefInstantVideoUploadPath
= findPreference("instant_video_upload_path");
350 if (mPrefInstantVideoUploadPath
!= null
){
352 mPrefInstantVideoUploadPath
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
354 public boolean onPreferenceClick(Preference preference
) {
355 if (!mUploadVideoPath
.endsWith(OCFile
.PATH_SEPARATOR
)) {
356 mUploadVideoPath
+= OCFile
.PATH_SEPARATOR
;
358 Intent intent
= new Intent(Preferences
.this, UploadPathActivity
.class);
359 intent
.putExtra(UploadPathActivity
.KEY_INSTANT_UPLOAD_PATH
, mUploadVideoPath
);
360 startActivityForResult(intent
, ACTION_SELECT_UPLOAD_VIDEO_PATH
);
366 mPrefInstantVideoUploadPathWiFi
= findPreference("instant_video_upload_on_wifi");
367 mPrefInstantVideoUpload
= findPreference("instant_video_uploading");
368 toggleInstantVideoOptions(((CheckBoxPreference
) mPrefInstantVideoUpload
).isChecked());
370 mPrefInstantVideoUpload
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
373 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
374 toggleInstantVideoOptions((Boolean
) newValue
);
380 pAboutApp
= (Preference
) findPreference("about_app");
381 if (pAboutApp
!= null
) {
382 pAboutApp
.setTitle(String
.format(getString(R
.string
.about_android
), getString(R
.string
.app_name
)));
383 pAboutApp
.setSummary(String
.format(getString(R
.string
.about_version
), appVersion
));
386 loadInstantUploadPath();
387 loadInstantUploadVideoPath();
389 /* ComponentsGetter */
390 mDownloadServiceConnection
= newTransferenceServiceConnection();
391 if (mDownloadServiceConnection
!= null
) {
392 bindService(new Intent(this, FileDownloader
.class), mDownloadServiceConnection
,
393 Context
.BIND_AUTO_CREATE
);
395 mUploadServiceConnection
= newTransferenceServiceConnection();
396 if (mUploadServiceConnection
!= null
) {
397 bindService(new Intent(this, FileUploader
.class), mUploadServiceConnection
,
398 Context
.BIND_AUTO_CREATE
);
403 private void toggleInstantPictureOptions(Boolean value
){
405 mPrefInstantUploadCategory
.addPreference(mPrefInstantUploadPathWiFi
);
406 mPrefInstantUploadCategory
.addPreference(mPrefInstantUploadPath
);
408 mPrefInstantUploadCategory
.removePreference(mPrefInstantUploadPathWiFi
);
409 mPrefInstantUploadCategory
.removePreference(mPrefInstantUploadPath
);
413 private void toggleInstantVideoOptions(Boolean value
){
415 mPrefInstantUploadCategory
.addPreference(mPrefInstantVideoUploadPathWiFi
);
416 mPrefInstantUploadCategory
.addPreference(mPrefInstantVideoUploadPath
);
418 mPrefInstantUploadCategory
.removePreference(mPrefInstantVideoUploadPathWiFi
);
419 mPrefInstantUploadCategory
.removePreference(mPrefInstantVideoUploadPath
);
424 public void onCreateContextMenu(ContextMenu menu
, View v
, ContextMenuInfo menuInfo
) {
426 // Filter for only showing contextual menu when long press on the
428 if (mShowContextMenu
) {
429 getMenuInflater().inflate(R
.menu
.account_picker_long_click
, menu
);
430 mShowContextMenu
= false
;
432 super.onCreateContextMenu(menu
, v
, menuInfo
);
436 * Called when the user clicked on an item into the context menu created at
437 * {@link #onCreateContextMenu(ContextMenu, View, ContextMenuInfo)} for
438 * every ownCloud {@link Account} , containing 'secondary actions' for them.
443 public boolean onContextItemSelected(android
.view
.MenuItem item
) {
444 AccountManager am
= (AccountManager
) getSystemService(ACCOUNT_SERVICE
);
445 Account accounts
[] = am
.getAccountsByType(MainApp
.getAccountType());
446 for (Account a
: accounts
) {
447 if (a
.name
.equals(mAccountName
)) {
448 if (item
.getItemId() == R
.id
.change_password
) {
450 // Change account password
451 Intent updateAccountCredentials
= new Intent(this, AuthenticatorActivity
.class);
452 updateAccountCredentials
.putExtra(AuthenticatorActivity
.EXTRA_ACCOUNT
, a
);
453 updateAccountCredentials
.putExtra(AuthenticatorActivity
.EXTRA_ACTION
,
454 AuthenticatorActivity
.ACTION_UPDATE_TOKEN
);
455 startActivity(updateAccountCredentials
);
457 } else if (item
.getItemId() == R
.id
.delete_account
) {
460 am
.removeAccount(a
, this, mHandler
);
461 Log_OC
.d(TAG
, "Remove an account " + a
.name
);
470 public void run(AccountManagerFuture
<Boolean
> future
) {
471 if (future
.isDone()) {
472 // after remove account
473 Account account
= new Account(mAccountName
, MainApp
.getAccountType());
474 if (!AccountUtils
.exists(account
, MainApp
.getAppContext())) {
476 if (mUploaderBinder
!= null
) {
477 mUploaderBinder
.cancel(account
);
479 if (mDownloaderBinder
!= null
) {
480 mDownloaderBinder
.cancel(account
);
484 Account a
= AccountUtils
.getCurrentOwnCloudAccount(this);
485 String accountName
= "";
487 Account
[] accounts
= AccountManager
.get(this).getAccountsByType(MainApp
.getAccountType());
488 if (accounts
.length
!= 0)
489 accountName
= accounts
[0].name
;
490 AccountUtils
.setCurrentOwnCloudAccount(this, accountName
);
492 addAccountsCheckboxPreferences();
497 protected void onResume() {
499 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
500 boolean state
= appPrefs
.getBoolean("set_pincode", false
);
501 pCode
.setChecked(state
);
503 // Populate the accounts category with the list of accounts
504 addAccountsCheckboxPreferences();
508 public boolean onCreateOptionsMenu(Menu menu
) {
509 super.onCreateOptionsMenu(menu
);
514 public boolean onMenuItemSelected(int featureId
, MenuItem item
) {
515 super.onMenuItemSelected(featureId
, item
);
518 switch (item
.getItemId()) {
519 case android
.R
.id
.home
:
520 intent
= new Intent(getBaseContext(), FileDisplayActivity
.class);
521 intent
.addFlags(Intent
.FLAG_ACTIVITY_CLEAR_TOP
);
522 startActivity(intent
);
525 Log_OC
.w(TAG
, "Unknown menu item triggered");
532 protected void onActivityResult(int requestCode
, int resultCode
, Intent data
) {
533 super.onActivityResult(requestCode
, resultCode
, data
);
535 if (requestCode
== ACTION_SELECT_UPLOAD_PATH
&& resultCode
== RESULT_OK
){
537 OCFile folderToUpload
= (OCFile
) data
.getParcelableExtra(UploadPathActivity
.EXTRA_FOLDER
);
539 mUploadPath
= folderToUpload
.getRemotePath();
541 mUploadPath
= DisplayUtils
.getPathWithoutLastSlash(mUploadPath
);
543 // Show the path on summary preference
544 mPrefInstantUploadPath
.setSummary(mUploadPath
);
546 saveInstantUploadPathOnPreferences();
548 } else if (requestCode
== ACTION_SELECT_UPLOAD_VIDEO_PATH
&& resultCode
== RESULT_OK
){
550 OCFile folderToUploadVideo
= (OCFile
) data
.getParcelableExtra(UploadPathActivity
.EXTRA_FOLDER
);
552 mUploadVideoPath
= folderToUploadVideo
.getRemotePath();
554 mUploadVideoPath
= DisplayUtils
.getPathWithoutLastSlash(mUploadVideoPath
);
556 // Show the video path on summary preference
557 mPrefInstantVideoUploadPath
.setSummary(mUploadVideoPath
);
559 saveInstantUploadVideoPathOnPreferences();
564 protected void onDestroy() {
567 if (mDownloadServiceConnection
!= null
) {
568 unbindService(mDownloadServiceConnection
);
569 mDownloadServiceConnection
= null
;
571 if (mUploadServiceConnection
!= null
) {
572 unbindService(mUploadServiceConnection
);
573 mUploadServiceConnection
= null
;
580 * Create the list of accounts that has been added into the app
582 @SuppressWarnings("deprecation")
583 private void addAccountsCheckboxPreferences() {
585 // Remove accounts in case list is refreshing for avoiding to have
587 if (mAccountsPrefCategory
.getPreferenceCount() > 0) {
588 mAccountsPrefCategory
.removeAll();
591 AccountManager am
= (AccountManager
) getSystemService(ACCOUNT_SERVICE
);
592 Account accounts
[] = am
.getAccountsByType(MainApp
.getAccountType());
593 Account currentAccount
= AccountUtils
.getCurrentOwnCloudAccount(getApplicationContext());
595 if (am
.getAccountsByType(MainApp
.getAccountType()).length
== 0) {
596 // Show create account screen if there isn't any account
597 am
.addAccount(MainApp
.getAccountType(), null
, null
, null
, this,
603 for (Account a
: accounts
) {
604 RadioButtonPreference accountPreference
= new RadioButtonPreference(this);
605 accountPreference
.setKey(a
.name
);
606 // Handle internationalized domain names
607 accountPreference
.setTitle(DisplayUtils
.convertIdn(a
.name
, false
));
608 mAccountsPrefCategory
.addPreference(accountPreference
);
610 // Check the current account that is being used
611 if (a
.name
.equals(currentAccount
.name
)) {
612 accountPreference
.setChecked(true
);
614 accountPreference
.setChecked(false
);
617 accountPreference
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
619 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
620 String key
= preference
.getKey();
621 AccountManager am
= (AccountManager
) getSystemService(ACCOUNT_SERVICE
);
622 Account accounts
[] = am
.getAccountsByType(MainApp
.getAccountType());
623 for (Account a
: accounts
) {
624 RadioButtonPreference p
= (RadioButtonPreference
) findPreference(a
.name
);
625 if (key
.equals(a
.name
)) {
626 boolean accountChanged
= !p
.isChecked();
628 AccountUtils
.setCurrentOwnCloudAccount(
629 getApplicationContext(),
632 if (accountChanged
) {
633 // restart the main activity
634 Intent i
= new Intent(
636 FileDisplayActivity
.class
638 i
.addFlags(Intent
.FLAG_ACTIVITY_CLEAR_TOP
);
639 i
.addFlags(Intent
.FLAG_ACTIVITY_SINGLE_TOP
);
648 return (Boolean
) newValue
;
654 // Add Create Account preference at the end of account list if
655 // Multiaccount is enabled
656 if (getResources().getBoolean(R
.bool
.multiaccount_support
)) {
657 createAddAccountPreference();
664 * Create the preference for allow adding new accounts
666 private void createAddAccountPreference() {
667 Preference addAccountPref
= new Preference(this);
668 addAccountPref
.setKey("add_account");
669 addAccountPref
.setTitle(getString(R
.string
.prefs_add_account
));
670 mAccountsPrefCategory
.addPreference(addAccountPref
);
672 addAccountPref
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
674 public boolean onPreferenceClick(Preference preference
) {
675 AccountManager am
= AccountManager
.get(getApplicationContext());
676 am
.addAccount(MainApp
.getAccountType(), null
, null
, null
, Preferences
.this, null
, null
);
684 * Load upload path set on preferences
686 private void loadInstantUploadPath() {
687 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
688 mUploadPath
= appPrefs
.getString("instant_upload_path", getString(R
.string
.instant_upload_path
));
689 mPrefInstantUploadPath
.setSummary(mUploadPath
);
693 * Save the "Instant Upload Path" on preferences
695 private void saveInstantUploadPathOnPreferences() {
696 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
697 SharedPreferences
.Editor editor
= appPrefs
.edit();
698 editor
.putString("instant_upload_path", mUploadPath
);
703 * Load upload video path set on preferences
705 private void loadInstantUploadVideoPath() {
706 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
707 mUploadVideoPath
= appPrefs
.getString("instant_video_upload_path", getString(R
.string
.instant_upload_path
));
708 mPrefInstantVideoUploadPath
.setSummary(mUploadVideoPath
);
712 * Save the "Instant Video Upload Path" on preferences
714 private void saveInstantUploadVideoPathOnPreferences() {
715 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
716 SharedPreferences
.Editor editor
= appPrefs
.edit();
717 editor
.putString("instant_video_upload_path", mUploadVideoPath
);
721 // Methods for ComponetsGetter
723 public FileDownloader
.FileDownloaderBinder
getFileDownloaderBinder() {
724 return mDownloaderBinder
;
729 public FileUploader
.FileUploaderBinder
getFileUploaderBinder() {
730 return mUploaderBinder
;
734 public OperationsService
.OperationsServiceBinder
getOperationsServiceBinder() {
739 public FileDataStorageManager
getStorageManager() {
744 public FileOperationsHelper
getFileOperationsHelper() {
748 protected ServiceConnection
newTransferenceServiceConnection() {
749 return new PreferencesServiceConnection();
752 /** Defines callbacks for service binding, passed to bindService() */
753 private class PreferencesServiceConnection
implements ServiceConnection
{
756 public void onServiceConnected(ComponentName component
, IBinder service
) {
758 if (component
.equals(new ComponentName(Preferences
.this, FileDownloader
.class))) {
759 mDownloaderBinder
= (FileDownloader
.FileDownloaderBinder
) service
;
761 } else if (component
.equals(new ComponentName(Preferences
.this, FileUploader
.class))) {
762 Log_OC
.d(TAG
, "Upload service connected");
763 mUploaderBinder
= (FileUploader
.FileUploaderBinder
) service
;
771 public void onServiceDisconnected(ComponentName component
) {
772 if (component
.equals(new ComponentName(Preferences
.this, FileDownloader
.class))) {
773 Log_OC
.d(TAG
, "Download service suddenly disconnected");
774 mDownloaderBinder
= null
;
775 } else if (component
.equals(new ComponentName(Preferences
.this, FileUploader
.class))) {
776 Log_OC
.d(TAG
, "Upload service suddenly disconnected");
777 mUploaderBinder
= null
;