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
118 // TODO : increase minSdk; scheduled for next realease, don't wont to mix with this US
119 if (Build
.VERSION
.SDK_INT
>= Build
.VERSION_CODES
.HONEYCOMB
) {
120 ActionBar actionBar
= getActionBar();
121 if (Build
.VERSION
.SDK_INT
>= Build
.VERSION_CODES
.ICE_CREAM_SANDWICH
) {
122 actionBar
.setIcon(DisplayUtils
.getSeasonalIconId());
124 actionBar
.setDisplayHomeAsUpEnabled(true
);
125 actionBar
.setTitle(R
.string
.actionbar_settings
);
127 setTitle(R
.string
.actionbar_settings
);
130 // For adding content description tag to a title field in the action bar
131 int actionBarTitleId
= getResources().getIdentifier("action_bar_title", "id", "android");
132 View actionBarTitleView
= getWindow().getDecorView().findViewById(actionBarTitleId
);
133 if (actionBarTitleView
!= null
) { // it's null in Android 2.x
134 getWindow().getDecorView().findViewById(actionBarTitleId
).
135 setContentDescription(getString(R
.string
.actionbar_settings
));
138 // Load the accounts category for adding the list of accounts
139 mAccountsPrefCategory
= (PreferenceCategory
) findPreference("accounts_category");
141 ListView listView
= getListView();
142 listView
.setOnItemLongClickListener(new OnItemLongClickListener() {
144 public boolean onItemLongClick(AdapterView
<?
> parent
, View view
, int position
, long id
) {
145 ListView listView
= (ListView
) parent
;
146 ListAdapter listAdapter
= listView
.getAdapter();
147 Object obj
= listAdapter
.getItem(position
);
149 if (obj
!= null
&& obj
instanceof RadioButtonPreference
) {
150 mShowContextMenu
= true
;
151 mAccountName
= ((RadioButtonPreference
) obj
).getKey();
153 Preferences
.this.openContextMenu(listView
);
155 View
.OnLongClickListener longListener
= (View
.OnLongClickListener
) obj
;
156 return longListener
.onLongClick(view
);
165 PackageInfo pkg
= getPackageManager().getPackageInfo(getPackageName(), 0);
166 temp
= pkg
.versionName
;
167 } catch (NameNotFoundException e
) {
169 Log_OC
.e(TAG
, "Error while showing about dialog", e
);
171 final String appVersion
= temp
;
173 // Register context menu for list of preferences.
174 registerForContextMenu(getListView());
176 pCode
= (CheckBoxPreference
) findPreference("set_pincode");
178 pCode
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
180 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
181 Intent i
= new Intent(getApplicationContext(), PassCodeActivity
.class);
182 Boolean enable
= (Boolean
) newValue
;
184 enable
.booleanValue() ? PassCodeActivity
.ACTION_ENABLE
:
185 PassCodeActivity
.ACTION_DISABLE
195 PreferenceCategory preferenceCategory
= (PreferenceCategory
) findPreference("more");
197 boolean helpEnabled
= getResources().getBoolean(R
.bool
.help_enabled
);
198 Preference pHelp
= findPreference("help");
201 pHelp
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
203 public boolean onPreferenceClick(Preference preference
) {
204 String helpWeb
=(String
) getText(R
.string
.url_help
);
205 if (helpWeb
!= null
&& helpWeb
.length() > 0) {
206 Uri uriUrl
= Uri
.parse(helpWeb
);
207 Intent intent
= new Intent(Intent
.ACTION_VIEW
, uriUrl
);
208 startActivity(intent
);
214 preferenceCategory
.removePreference(pHelp
);
219 if (BuildConfig
.DEBUG
) {
220 Preference pLog
= findPreference("log");
222 pLog
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
224 public boolean onPreferenceClick(Preference preference
) {
225 Intent loggerIntent
= new Intent(getApplicationContext(),
226 LogHistoryActivity
.class);
227 startActivity(loggerIntent
);
234 boolean recommendEnabled
= getResources().getBoolean(R
.bool
.recommend_enabled
);
235 Preference pRecommend
= findPreference("recommend");
236 if (pRecommend
!= null
){
237 if (recommendEnabled
) {
238 pRecommend
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
240 public boolean onPreferenceClick(Preference preference
) {
242 Intent intent
= new Intent(Intent
.ACTION_SENDTO
);
243 intent
.setType("text/plain");
244 intent
.setData(Uri
.parse(getString(R
.string
.mail_recommend
)));
245 intent
.addFlags(Intent
.FLAG_ACTIVITY_NEW_TASK
);
247 String appName
= getString(R
.string
.app_name
);
248 String downloadUrl
= getString(R
.string
.url_app_download
);
249 Account currentAccount
= AccountUtils
.
250 getCurrentOwnCloudAccount(Preferences
.this);
251 String username
= currentAccount
.name
.substring(0,
252 currentAccount
.name
.lastIndexOf('@'));
254 String recommendSubject
= String
.format(getString(R
.string
.recommend_subject
),
256 String recommendText
= String
.format(getString(R
.string
.recommend_text
),
257 appName
, downloadUrl
);
259 intent
.putExtra(Intent
.EXTRA_SUBJECT
, recommendSubject
);
260 intent
.putExtra(Intent
.EXTRA_TEXT
, recommendText
);
261 startActivity(intent
);
268 preferenceCategory
.removePreference(pRecommend
);
273 boolean feedbackEnabled
= getResources().getBoolean(R
.bool
.feedback_enabled
);
274 Preference pFeedback
= findPreference("feedback");
275 if (pFeedback
!= null
){
276 if (feedbackEnabled
) {
277 pFeedback
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
279 public boolean onPreferenceClick(Preference preference
) {
280 String feedbackMail
=(String
) getText(R
.string
.mail_feedback
);
281 String feedback
=(String
) getText(R
.string
.prefs_feedback
) + " - android v" + appVersion
;
282 Intent intent
= new Intent(Intent
.ACTION_SENDTO
);
283 intent
.setType("text/plain");
284 intent
.putExtra(Intent
.EXTRA_SUBJECT
, feedback
);
286 intent
.setData(Uri
.parse(feedbackMail
));
287 intent
.addFlags(Intent
.FLAG_ACTIVITY_NEW_TASK
);
288 startActivity(intent
);
294 preferenceCategory
.removePreference(pFeedback
);
299 boolean imprintEnabled
= getResources().getBoolean(R
.bool
.imprint_enabled
);
300 Preference pImprint
= findPreference("imprint");
301 if (pImprint
!= null
) {
302 if (imprintEnabled
) {
303 pImprint
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
305 public boolean onPreferenceClick(Preference preference
) {
306 String imprintWeb
= (String
) getText(R
.string
.url_imprint
);
307 if (imprintWeb
!= null
&& imprintWeb
.length() > 0) {
308 Uri uriUrl
= Uri
.parse(imprintWeb
);
309 Intent intent
= new Intent(Intent
.ACTION_VIEW
, uriUrl
);
310 startActivity(intent
);
312 //ImprintDialog.newInstance(true).show(preference.get, "IMPRINT_DIALOG");
317 preferenceCategory
.removePreference(pImprint
);
321 mPrefInstantUploadPath
= findPreference("instant_upload_path");
322 if (mPrefInstantUploadPath
!= null
){
324 mPrefInstantUploadPath
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
326 public boolean onPreferenceClick(Preference preference
) {
327 if (!mUploadPath
.endsWith(OCFile
.PATH_SEPARATOR
)) {
328 mUploadPath
+= OCFile
.PATH_SEPARATOR
;
330 Intent intent
= new Intent(Preferences
.this, UploadPathActivity
.class);
331 intent
.putExtra(UploadPathActivity
.KEY_INSTANT_UPLOAD_PATH
, mUploadPath
);
332 startActivityForResult(intent
, ACTION_SELECT_UPLOAD_PATH
);
338 mPrefInstantUploadCategory
=
339 (PreferenceCategory
) findPreference("instant_uploading_category");
341 mPrefInstantUploadPathWiFi
= findPreference("instant_upload_on_wifi");
342 mPrefInstantUpload
= findPreference("instant_uploading");
344 toggleInstantPictureOptions(((CheckBoxPreference
) mPrefInstantUpload
).isChecked());
346 mPrefInstantUpload
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
349 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
350 toggleInstantPictureOptions((Boolean
) newValue
);
355 mPrefInstantVideoUploadPath
= findPreference("instant_video_upload_path");
356 if (mPrefInstantVideoUploadPath
!= null
){
358 mPrefInstantVideoUploadPath
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
360 public boolean onPreferenceClick(Preference preference
) {
361 if (!mUploadVideoPath
.endsWith(OCFile
.PATH_SEPARATOR
)) {
362 mUploadVideoPath
+= OCFile
.PATH_SEPARATOR
;
364 Intent intent
= new Intent(Preferences
.this, UploadPathActivity
.class);
365 intent
.putExtra(UploadPathActivity
.KEY_INSTANT_UPLOAD_PATH
,
367 startActivityForResult(intent
, ACTION_SELECT_UPLOAD_VIDEO_PATH
);
373 mPrefInstantVideoUploadPathWiFi
= findPreference("instant_video_upload_on_wifi");
374 mPrefInstantVideoUpload
= findPreference("instant_video_uploading");
375 toggleInstantVideoOptions(((CheckBoxPreference
) mPrefInstantVideoUpload
).isChecked());
377 mPrefInstantVideoUpload
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
380 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
381 toggleInstantVideoOptions((Boolean
) newValue
);
387 pAboutApp
= (Preference
) findPreference("about_app");
388 if (pAboutApp
!= null
) {
389 pAboutApp
.setTitle(String
.format(getString(R
.string
.about_android
), getString(R
.string
.app_name
)));
390 pAboutApp
.setSummary(String
.format(getString(R
.string
.about_version
), appVersion
));
393 loadInstantUploadPath();
394 loadInstantUploadVideoPath();
396 /* ComponentsGetter */
397 mDownloadServiceConnection
= newTransferenceServiceConnection();
398 if (mDownloadServiceConnection
!= null
) {
399 bindService(new Intent(this, FileDownloader
.class), mDownloadServiceConnection
,
400 Context
.BIND_AUTO_CREATE
);
402 mUploadServiceConnection
= newTransferenceServiceConnection();
403 if (mUploadServiceConnection
!= null
) {
404 bindService(new Intent(this, FileUploader
.class), mUploadServiceConnection
,
405 Context
.BIND_AUTO_CREATE
);
410 private void toggleInstantPictureOptions(Boolean value
){
412 mPrefInstantUploadCategory
.addPreference(mPrefInstantUploadPathWiFi
);
413 mPrefInstantUploadCategory
.addPreference(mPrefInstantUploadPath
);
415 mPrefInstantUploadCategory
.removePreference(mPrefInstantUploadPathWiFi
);
416 mPrefInstantUploadCategory
.removePreference(mPrefInstantUploadPath
);
420 private void toggleInstantVideoOptions(Boolean value
){
422 mPrefInstantUploadCategory
.addPreference(mPrefInstantVideoUploadPathWiFi
);
423 mPrefInstantUploadCategory
.addPreference(mPrefInstantVideoUploadPath
);
425 mPrefInstantUploadCategory
.removePreference(mPrefInstantVideoUploadPathWiFi
);
426 mPrefInstantUploadCategory
.removePreference(mPrefInstantVideoUploadPath
);
431 public void onCreateContextMenu(ContextMenu menu
, View v
, ContextMenuInfo menuInfo
) {
433 // Filter for only showing contextual menu when long press on the
435 if (mShowContextMenu
) {
436 getMenuInflater().inflate(R
.menu
.account_picker_long_click
, menu
);
437 mShowContextMenu
= false
;
439 super.onCreateContextMenu(menu
, v
, menuInfo
);
443 * Called when the user clicked on an item into the context menu created at
444 * {@link #onCreateContextMenu(ContextMenu, View, ContextMenuInfo)} for
445 * every ownCloud {@link Account} , containing 'secondary actions' for them.
450 public boolean onContextItemSelected(android
.view
.MenuItem item
) {
451 AccountManager am
= (AccountManager
) getSystemService(ACCOUNT_SERVICE
);
452 Account accounts
[] = am
.getAccountsByType(MainApp
.getAccountType());
453 for (Account a
: accounts
) {
454 if (a
.name
.equals(mAccountName
)) {
455 if (item
.getItemId() == R
.id
.change_password
) {
457 // Change account password
458 Intent updateAccountCredentials
= new Intent(this, AuthenticatorActivity
.class);
459 updateAccountCredentials
.putExtra(AuthenticatorActivity
.EXTRA_ACCOUNT
, a
);
460 updateAccountCredentials
.putExtra(AuthenticatorActivity
.EXTRA_ACTION
,
461 AuthenticatorActivity
.ACTION_UPDATE_TOKEN
);
462 startActivity(updateAccountCredentials
);
464 } else if (item
.getItemId() == R
.id
.delete_account
) {
467 am
.removeAccount(a
, this, mHandler
);
468 Log_OC
.d(TAG
, "Remove an account " + a
.name
);
477 public void run(AccountManagerFuture
<Boolean
> future
) {
478 if (future
.isDone()) {
479 // after remove account
480 Account account
= new Account(mAccountName
, MainApp
.getAccountType());
481 if (!AccountUtils
.exists(account
, MainApp
.getAppContext())) {
483 if (mUploaderBinder
!= null
) {
484 mUploaderBinder
.cancel(account
);
486 if (mDownloaderBinder
!= null
) {
487 mDownloaderBinder
.cancel(account
);
491 Account a
= AccountUtils
.getCurrentOwnCloudAccount(this);
492 String accountName
= "";
494 Account
[] accounts
= AccountManager
.get(this)
495 .getAccountsByType(MainApp
.getAccountType());
496 if (accounts
.length
!= 0)
497 accountName
= accounts
[0].name
;
498 AccountUtils
.setCurrentOwnCloudAccount(this, accountName
);
500 addAccountsCheckboxPreferences();
505 protected void onResume() {
507 SharedPreferences appPrefs
=
508 PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
509 boolean state
= appPrefs
.getBoolean("set_pincode", false
);
510 pCode
.setChecked(state
);
512 // Populate the accounts category with the list of accounts
513 addAccountsCheckboxPreferences();
517 public boolean onCreateOptionsMenu(Menu menu
) {
518 super.onCreateOptionsMenu(menu
);
523 public boolean onMenuItemSelected(int featureId
, MenuItem item
) {
524 super.onMenuItemSelected(featureId
, item
);
527 switch (item
.getItemId()) {
528 case android
.R
.id
.home
:
529 intent
= new Intent(getBaseContext(), FileDisplayActivity
.class);
530 intent
.addFlags(Intent
.FLAG_ACTIVITY_CLEAR_TOP
);
531 startActivity(intent
);
534 Log_OC
.w(TAG
, "Unknown menu item triggered");
541 protected void onActivityResult(int requestCode
, int resultCode
, Intent data
) {
542 super.onActivityResult(requestCode
, resultCode
, data
);
544 if (requestCode
== ACTION_SELECT_UPLOAD_PATH
&& resultCode
== RESULT_OK
){
546 OCFile folderToUpload
=
547 (OCFile
) data
.getParcelableExtra(UploadPathActivity
.EXTRA_FOLDER
);
549 mUploadPath
= folderToUpload
.getRemotePath();
551 mUploadPath
= DisplayUtils
.getPathWithoutLastSlash(mUploadPath
);
553 // Show the path on summary preference
554 mPrefInstantUploadPath
.setSummary(mUploadPath
);
556 saveInstantUploadPathOnPreferences();
558 } else if (requestCode
== ACTION_SELECT_UPLOAD_VIDEO_PATH
&& resultCode
== RESULT_OK
){
560 OCFile folderToUploadVideo
=
561 (OCFile
) data
.getParcelableExtra(UploadPathActivity
.EXTRA_FOLDER
);
563 mUploadVideoPath
= folderToUploadVideo
.getRemotePath();
565 mUploadVideoPath
= DisplayUtils
.getPathWithoutLastSlash(mUploadVideoPath
);
567 // Show the video path on summary preference
568 mPrefInstantVideoUploadPath
.setSummary(mUploadVideoPath
);
570 saveInstantUploadVideoPathOnPreferences();
575 protected void onDestroy() {
578 if (mDownloadServiceConnection
!= null
) {
579 unbindService(mDownloadServiceConnection
);
580 mDownloadServiceConnection
= null
;
582 if (mUploadServiceConnection
!= null
) {
583 unbindService(mUploadServiceConnection
);
584 mUploadServiceConnection
= null
;
591 * Create the list of accounts that has been added into the app
593 @SuppressWarnings("deprecation")
594 private void addAccountsCheckboxPreferences() {
596 // Remove accounts in case list is refreshing for avoiding to have
598 if (mAccountsPrefCategory
.getPreferenceCount() > 0) {
599 mAccountsPrefCategory
.removeAll();
602 AccountManager am
= (AccountManager
) getSystemService(ACCOUNT_SERVICE
);
603 Account accounts
[] = am
.getAccountsByType(MainApp
.getAccountType());
604 Account currentAccount
= AccountUtils
.getCurrentOwnCloudAccount(getApplicationContext());
606 if (am
.getAccountsByType(MainApp
.getAccountType()).length
== 0) {
607 // Show create account screen if there isn't any account
608 am
.addAccount(MainApp
.getAccountType(), null
, null
, null
, this,
614 for (Account a
: accounts
) {
615 RadioButtonPreference accountPreference
= new RadioButtonPreference(this);
616 accountPreference
.setKey(a
.name
);
617 // Handle internationalized domain names
618 accountPreference
.setTitle(DisplayUtils
.convertIdn(a
.name
, false
));
619 mAccountsPrefCategory
.addPreference(accountPreference
);
621 // Check the current account that is being used
622 if (a
.name
.equals(currentAccount
.name
)) {
623 accountPreference
.setChecked(true
);
625 accountPreference
.setChecked(false
);
628 accountPreference
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
630 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
631 String key
= preference
.getKey();
632 AccountManager am
= (AccountManager
) getSystemService(ACCOUNT_SERVICE
);
633 Account accounts
[] = am
.getAccountsByType(MainApp
.getAccountType());
634 for (Account a
: accounts
) {
635 RadioButtonPreference p
=
636 (RadioButtonPreference
) findPreference(a
.name
);
637 if (key
.equals(a
.name
)) {
638 boolean accountChanged
= !p
.isChecked();
640 AccountUtils
.setCurrentOwnCloudAccount(
641 getApplicationContext(),
644 if (accountChanged
) {
645 // restart the main activity
646 Intent i
= new Intent(
648 FileDisplayActivity
.class
650 i
.addFlags(Intent
.FLAG_ACTIVITY_CLEAR_TOP
);
651 i
.addFlags(Intent
.FLAG_ACTIVITY_SINGLE_TOP
);
660 return (Boolean
) newValue
;
666 // Add Create Account preference at the end of account list if
667 // Multiaccount is enabled
668 if (getResources().getBoolean(R
.bool
.multiaccount_support
)) {
669 createAddAccountPreference();
676 * Create the preference for allow adding new accounts
678 private void createAddAccountPreference() {
679 Preference addAccountPref
= new Preference(this);
680 addAccountPref
.setKey("add_account");
681 addAccountPref
.setTitle(getString(R
.string
.prefs_add_account
));
682 mAccountsPrefCategory
.addPreference(addAccountPref
);
684 addAccountPref
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
686 public boolean onPreferenceClick(Preference preference
) {
687 AccountManager am
= AccountManager
.get(getApplicationContext());
688 am
.addAccount(MainApp
.getAccountType(), null
, null
, null
, Preferences
.this,
697 * Load upload path set on preferences
699 private void loadInstantUploadPath() {
700 SharedPreferences appPrefs
=
701 PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
702 mUploadPath
= appPrefs
.getString("instant_upload_path", getString(R
.string
.instant_upload_path
));
703 mPrefInstantUploadPath
.setSummary(mUploadPath
);
707 * Save the "Instant Upload Path" on preferences
709 private void saveInstantUploadPathOnPreferences() {
710 SharedPreferences appPrefs
=
711 PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
712 SharedPreferences
.Editor editor
= appPrefs
.edit();
713 editor
.putString("instant_upload_path", mUploadPath
);
718 * Load upload video path set on preferences
720 private void loadInstantUploadVideoPath() {
721 SharedPreferences appPrefs
=
722 PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
723 mUploadVideoPath
= appPrefs
.getString("instant_video_upload_path", getString(R
.string
.instant_upload_path
));
724 mPrefInstantVideoUploadPath
.setSummary(mUploadVideoPath
);
728 * Save the "Instant Video Upload Path" on preferences
730 private void saveInstantUploadVideoPathOnPreferences() {
731 SharedPreferences appPrefs
=
732 PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
733 SharedPreferences
.Editor editor
= appPrefs
.edit();
734 editor
.putString("instant_video_upload_path", mUploadVideoPath
);
738 // Methods for ComponetsGetter
740 public FileDownloader
.FileDownloaderBinder
getFileDownloaderBinder() {
741 return mDownloaderBinder
;
746 public FileUploader
.FileUploaderBinder
getFileUploaderBinder() {
747 return mUploaderBinder
;
751 public OperationsService
.OperationsServiceBinder
getOperationsServiceBinder() {
756 public FileDataStorageManager
getStorageManager() {
761 public FileOperationsHelper
getFileOperationsHelper() {
765 protected ServiceConnection
newTransferenceServiceConnection() {
766 return new PreferencesServiceConnection();
769 /** Defines callbacks for service binding, passed to bindService() */
770 private class PreferencesServiceConnection
implements ServiceConnection
{
773 public void onServiceConnected(ComponentName component
, IBinder service
) {
775 if (component
.equals(new ComponentName(Preferences
.this, FileDownloader
.class))) {
776 mDownloaderBinder
= (FileDownloader
.FileDownloaderBinder
) service
;
778 } else if (component
.equals(new ComponentName(Preferences
.this, FileUploader
.class))) {
779 Log_OC
.d(TAG
, "Upload service connected");
780 mUploaderBinder
= (FileUploader
.FileUploaderBinder
) service
;
788 public void onServiceDisconnected(ComponentName component
) {
789 if (component
.equals(new ComponentName(Preferences
.this, FileDownloader
.class))) {
790 Log_OC
.d(TAG
, "Download service suddenly disconnected");
791 mDownloaderBinder
= null
;
792 } else if (component
.equals(new ComponentName(Preferences
.this, FileUploader
.class))) {
793 Log_OC
.d(TAG
, "Upload service suddenly disconnected");
794 mUploaderBinder
= null
;