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
.PreferenceActivity
;
44 import android
.preference
.PreferenceCategory
;
45 import android
.preference
.PreferenceManager
;
46 import android
.support
.v7
.app
.ActionBar
;
47 import android
.view
.ContextMenu
;
48 import android
.view
.ContextMenu
.ContextMenuInfo
;
49 import android
.view
.Menu
;
50 import android
.view
.MenuItem
;
51 import android
.view
.View
;
52 import android
.widget
.AdapterView
;
53 import android
.widget
.AdapterView
.OnItemLongClickListener
;
54 import android
.widget
.ListAdapter
;
55 import android
.widget
.ListView
;
57 import com
.owncloud
.android
.BuildConfig
;
58 import com
.owncloud
.android
.MainApp
;
59 import com
.owncloud
.android
.R
;
60 import com
.owncloud
.android
.authentication
.AccountUtils
;
61 import com
.owncloud
.android
.authentication
.AuthenticatorActivity
;
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 PreferenceActivity
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
);
115 // ActionBar actionBar = getSherlock().getActionBar();
116 // actionBar.setIcon(DisplayUtils.getSeasonalIconId());
117 // actionBar.setDisplayHomeAsUpEnabled(true);
118 // actionBar.setTitle(R.string.actionbar_settings);
120 // For adding content description tag to a title field in the action bar
121 int actionBarTitleId
= getResources().getIdentifier("action_bar_title", "id", "android");
122 View actionBarTitleView
= getWindow().getDecorView().findViewById(actionBarTitleId
);
123 if (actionBarTitleView
!= null
) { // it's null in Android 2.x
124 getWindow().getDecorView().findViewById(actionBarTitleId
).
125 setContentDescription(getString(R
.string
.actionbar_settings
));
128 // Load the accounts category for adding the list of accounts
129 mAccountsPrefCategory
= (PreferenceCategory
) findPreference("accounts_category");
131 ListView listView
= getListView();
132 listView
.setOnItemLongClickListener(new OnItemLongClickListener() {
134 public boolean onItemLongClick(AdapterView
<?
> parent
, View view
, int position
, long id
) {
135 ListView listView
= (ListView
) parent
;
136 ListAdapter listAdapter
= listView
.getAdapter();
137 Object obj
= listAdapter
.getItem(position
);
139 if (obj
!= null
&& obj
instanceof RadioButtonPreference
) {
140 mShowContextMenu
= true
;
141 mAccountName
= ((RadioButtonPreference
) obj
).getKey();
143 Preferences
.this.openContextMenu(listView
);
145 View
.OnLongClickListener longListener
= (View
.OnLongClickListener
) obj
;
146 return longListener
.onLongClick(view
);
155 PackageInfo pkg
= getPackageManager().getPackageInfo(getPackageName(), 0);
156 temp
= pkg
.versionName
;
157 } catch (NameNotFoundException e
) {
159 Log_OC
.e(TAG
, "Error while showing about dialog", e
);
161 final String appVersion
= temp
;
163 // Register context menu for list of preferences.
164 registerForContextMenu(getListView());
166 pCode
= (CheckBoxPreference
) findPreference("set_pincode");
168 pCode
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
170 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
171 Intent i
= new Intent(getApplicationContext(), PassCodeActivity
.class);
172 Boolean enable
= (Boolean
) newValue
;
174 enable
.booleanValue() ? PassCodeActivity
.ACTION_ENABLE
: PassCodeActivity
.ACTION_DISABLE
184 PreferenceCategory preferenceCategory
= (PreferenceCategory
) findPreference("more");
186 boolean helpEnabled
= getResources().getBoolean(R
.bool
.help_enabled
);
187 Preference pHelp
= findPreference("help");
190 pHelp
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
192 public boolean onPreferenceClick(Preference preference
) {
193 String helpWeb
=(String
) getText(R
.string
.url_help
);
194 if (helpWeb
!= null
&& helpWeb
.length() > 0) {
195 Uri uriUrl
= Uri
.parse(helpWeb
);
196 Intent intent
= new Intent(Intent
.ACTION_VIEW
, uriUrl
);
197 startActivity(intent
);
203 preferenceCategory
.removePreference(pHelp
);
208 if (BuildConfig
.DEBUG
) {
209 Preference pLog
= findPreference("log");
211 pLog
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
213 public boolean onPreferenceClick(Preference preference
) {
214 Intent loggerIntent
= new Intent(getApplicationContext(),LogHistoryActivity
.class);
215 startActivity(loggerIntent
);
222 boolean recommendEnabled
= getResources().getBoolean(R
.bool
.recommend_enabled
);
223 Preference pRecommend
= findPreference("recommend");
224 if (pRecommend
!= null
){
225 if (recommendEnabled
) {
226 pRecommend
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
228 public boolean onPreferenceClick(Preference preference
) {
230 Intent intent
= new Intent(Intent
.ACTION_SENDTO
);
231 intent
.setType("text/plain");
232 intent
.setData(Uri
.parse(getString(R
.string
.mail_recommend
)));
233 intent
.addFlags(Intent
.FLAG_ACTIVITY_NEW_TASK
);
235 String appName
= getString(R
.string
.app_name
);
236 String downloadUrl
= getString(R
.string
.url_app_download
);
237 Account currentAccount
= AccountUtils
.getCurrentOwnCloudAccount(Preferences
.this);
238 String username
= currentAccount
.name
.substring(0, currentAccount
.name
.lastIndexOf('@'));
240 String recommendSubject
= String
.format(getString(R
.string
.recommend_subject
),
242 String recommendText
= String
.format(getString(R
.string
.recommend_text
),
243 appName
, downloadUrl
, username
);
245 intent
.putExtra(Intent
.EXTRA_SUBJECT
, recommendSubject
);
246 intent
.putExtra(Intent
.EXTRA_TEXT
, recommendText
);
247 startActivity(intent
);
254 preferenceCategory
.removePreference(pRecommend
);
259 boolean feedbackEnabled
= getResources().getBoolean(R
.bool
.feedback_enabled
);
260 Preference pFeedback
= findPreference("feedback");
261 if (pFeedback
!= null
){
262 if (feedbackEnabled
) {
263 pFeedback
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
265 public boolean onPreferenceClick(Preference preference
) {
266 String feedbackMail
=(String
) getText(R
.string
.mail_feedback
);
267 String feedback
=(String
) getText(R
.string
.prefs_feedback
) + " - android v" + appVersion
;
268 Intent intent
= new Intent(Intent
.ACTION_SENDTO
);
269 intent
.setType("text/plain");
270 intent
.putExtra(Intent
.EXTRA_SUBJECT
, feedback
);
272 intent
.setData(Uri
.parse(feedbackMail
));
273 intent
.addFlags(Intent
.FLAG_ACTIVITY_NEW_TASK
);
274 startActivity(intent
);
280 preferenceCategory
.removePreference(pFeedback
);
285 boolean imprintEnabled
= getResources().getBoolean(R
.bool
.imprint_enabled
);
286 Preference pImprint
= findPreference("imprint");
287 if (pImprint
!= null
) {
288 if (imprintEnabled
) {
289 pImprint
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
291 public boolean onPreferenceClick(Preference preference
) {
292 String imprintWeb
= (String
) getText(R
.string
.url_imprint
);
293 if (imprintWeb
!= null
&& imprintWeb
.length() > 0) {
294 Uri uriUrl
= Uri
.parse(imprintWeb
);
295 Intent intent
= new Intent(Intent
.ACTION_VIEW
, uriUrl
);
296 startActivity(intent
);
298 //ImprintDialog.newInstance(true).show(preference.get, "IMPRINT_DIALOG");
303 preferenceCategory
.removePreference(pImprint
);
307 mPrefInstantUploadPath
= findPreference("instant_upload_path");
308 if (mPrefInstantUploadPath
!= null
){
310 mPrefInstantUploadPath
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
312 public boolean onPreferenceClick(Preference preference
) {
313 if (!mUploadPath
.endsWith(OCFile
.PATH_SEPARATOR
)) {
314 mUploadPath
+= OCFile
.PATH_SEPARATOR
;
316 Intent intent
= new Intent(Preferences
.this, UploadPathActivity
.class);
317 intent
.putExtra(UploadPathActivity
.KEY_INSTANT_UPLOAD_PATH
, mUploadPath
);
318 startActivityForResult(intent
, ACTION_SELECT_UPLOAD_PATH
);
324 mPrefInstantUploadCategory
= (PreferenceCategory
) findPreference("instant_uploading_category");
326 mPrefInstantUploadPathWiFi
= findPreference("instant_upload_on_wifi");
327 mPrefInstantUpload
= findPreference("instant_uploading");
329 toggleInstantPictureOptions(((CheckBoxPreference
) mPrefInstantUpload
).isChecked());
331 mPrefInstantUpload
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
334 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
335 toggleInstantPictureOptions((Boolean
) newValue
);
340 mPrefInstantVideoUploadPath
= findPreference("instant_video_upload_path");
341 if (mPrefInstantVideoUploadPath
!= null
){
343 mPrefInstantVideoUploadPath
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
345 public boolean onPreferenceClick(Preference preference
) {
346 if (!mUploadVideoPath
.endsWith(OCFile
.PATH_SEPARATOR
)) {
347 mUploadVideoPath
+= OCFile
.PATH_SEPARATOR
;
349 Intent intent
= new Intent(Preferences
.this, UploadPathActivity
.class);
350 intent
.putExtra(UploadPathActivity
.KEY_INSTANT_UPLOAD_PATH
, mUploadVideoPath
);
351 startActivityForResult(intent
, ACTION_SELECT_UPLOAD_VIDEO_PATH
);
357 mPrefInstantVideoUploadPathWiFi
= findPreference("instant_video_upload_on_wifi");
358 mPrefInstantVideoUpload
= findPreference("instant_video_uploading");
359 toggleInstantVideoOptions(((CheckBoxPreference
) mPrefInstantVideoUpload
).isChecked());
361 mPrefInstantVideoUpload
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
364 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
365 toggleInstantVideoOptions((Boolean
) newValue
);
371 pAboutApp
= (Preference
) findPreference("about_app");
372 if (pAboutApp
!= null
) {
373 pAboutApp
.setTitle(String
.format(getString(R
.string
.about_android
), getString(R
.string
.app_name
)));
374 pAboutApp
.setSummary(String
.format(getString(R
.string
.about_version
), appVersion
));
377 loadInstantUploadPath();
378 loadInstantUploadVideoPath();
380 /* ComponentsGetter */
381 mDownloadServiceConnection
= newTransferenceServiceConnection();
382 if (mDownloadServiceConnection
!= null
) {
383 bindService(new Intent(this, FileDownloader
.class), mDownloadServiceConnection
,
384 Context
.BIND_AUTO_CREATE
);
386 mUploadServiceConnection
= newTransferenceServiceConnection();
387 if (mUploadServiceConnection
!= null
) {
388 bindService(new Intent(this, FileUploader
.class), mUploadServiceConnection
,
389 Context
.BIND_AUTO_CREATE
);
394 private void toggleInstantPictureOptions(Boolean value
){
396 mPrefInstantUploadCategory
.addPreference(mPrefInstantUploadPathWiFi
);
397 mPrefInstantUploadCategory
.addPreference(mPrefInstantUploadPath
);
399 mPrefInstantUploadCategory
.removePreference(mPrefInstantUploadPathWiFi
);
400 mPrefInstantUploadCategory
.removePreference(mPrefInstantUploadPath
);
404 private void toggleInstantVideoOptions(Boolean value
){
406 mPrefInstantUploadCategory
.addPreference(mPrefInstantVideoUploadPathWiFi
);
407 mPrefInstantUploadCategory
.addPreference(mPrefInstantVideoUploadPath
);
409 mPrefInstantUploadCategory
.removePreference(mPrefInstantVideoUploadPathWiFi
);
410 mPrefInstantUploadCategory
.removePreference(mPrefInstantVideoUploadPath
);
415 public void onCreateContextMenu(ContextMenu menu
, View v
, ContextMenuInfo menuInfo
) {
417 // Filter for only showing contextual menu when long press on the
419 if (mShowContextMenu
) {
420 getMenuInflater().inflate(R
.menu
.account_picker_long_click
, menu
);
421 mShowContextMenu
= false
;
423 super.onCreateContextMenu(menu
, v
, menuInfo
);
427 * Called when the user clicked on an item into the context menu created at
428 * {@link #onCreateContextMenu(ContextMenu, View, ContextMenuInfo)} for
429 * every ownCloud {@link Account} , containing 'secondary actions' for them.
434 public boolean onContextItemSelected(android
.view
.MenuItem item
) {
435 AccountManager am
= (AccountManager
) getSystemService(ACCOUNT_SERVICE
);
436 Account accounts
[] = am
.getAccountsByType(MainApp
.getAccountType());
437 for (Account a
: accounts
) {
438 if (a
.name
.equals(mAccountName
)) {
439 if (item
.getItemId() == R
.id
.change_password
) {
441 // Change account password
442 Intent updateAccountCredentials
= new Intent(this, AuthenticatorActivity
.class);
443 updateAccountCredentials
.putExtra(AuthenticatorActivity
.EXTRA_ACCOUNT
, a
);
444 updateAccountCredentials
.putExtra(AuthenticatorActivity
.EXTRA_ACTION
,
445 AuthenticatorActivity
.ACTION_UPDATE_TOKEN
);
446 startActivity(updateAccountCredentials
);
448 } else if (item
.getItemId() == R
.id
.delete_account
) {
451 am
.removeAccount(a
, this, mHandler
);
452 Log_OC
.d(TAG
, "Remove an account " + a
.name
);
461 public void run(AccountManagerFuture
<Boolean
> future
) {
462 if (future
.isDone()) {
463 // after remove account
464 Account account
= new Account(mAccountName
, MainApp
.getAccountType());
465 if (!AccountUtils
.exists(account
, MainApp
.getAppContext())) {
467 if (mUploaderBinder
!= null
) {
468 mUploaderBinder
.cancel(account
);
470 if (mDownloaderBinder
!= null
) {
471 mDownloaderBinder
.cancel(account
);
475 Account a
= AccountUtils
.getCurrentOwnCloudAccount(this);
476 String accountName
= "";
478 Account
[] accounts
= AccountManager
.get(this).getAccountsByType(MainApp
.getAccountType());
479 if (accounts
.length
!= 0)
480 accountName
= accounts
[0].name
;
481 AccountUtils
.setCurrentOwnCloudAccount(this, accountName
);
483 addAccountsCheckboxPreferences();
488 protected void onResume() {
490 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
491 boolean state
= appPrefs
.getBoolean("set_pincode", false
);
492 pCode
.setChecked(state
);
494 // Populate the accounts category with the list of accounts
495 addAccountsCheckboxPreferences();
499 public boolean onCreateOptionsMenu(Menu menu
) {
500 super.onCreateOptionsMenu(menu
);
505 public boolean onMenuItemSelected(int featureId
, MenuItem item
) {
506 super.onMenuItemSelected(featureId
, item
);
509 switch (item
.getItemId()) {
510 case android
.R
.id
.home
:
511 intent
= new Intent(getBaseContext(), FileDisplayActivity
.class);
512 intent
.addFlags(Intent
.FLAG_ACTIVITY_CLEAR_TOP
);
513 startActivity(intent
);
516 Log_OC
.w(TAG
, "Unknown menu item triggered");
523 protected void onActivityResult(int requestCode
, int resultCode
, Intent data
) {
524 super.onActivityResult(requestCode
, resultCode
, data
);
526 if (requestCode
== ACTION_SELECT_UPLOAD_PATH
&& resultCode
== RESULT_OK
){
528 OCFile folderToUpload
= (OCFile
) data
.getParcelableExtra(UploadPathActivity
.EXTRA_FOLDER
);
530 mUploadPath
= folderToUpload
.getRemotePath();
532 mUploadPath
= DisplayUtils
.getPathWithoutLastSlash(mUploadPath
);
534 // Show the path on summary preference
535 mPrefInstantUploadPath
.setSummary(mUploadPath
);
537 saveInstantUploadPathOnPreferences();
539 } else if (requestCode
== ACTION_SELECT_UPLOAD_VIDEO_PATH
&& resultCode
== RESULT_OK
){
541 OCFile folderToUploadVideo
= (OCFile
) data
.getParcelableExtra(UploadPathActivity
.EXTRA_FOLDER
);
543 mUploadVideoPath
= folderToUploadVideo
.getRemotePath();
545 mUploadVideoPath
= DisplayUtils
.getPathWithoutLastSlash(mUploadVideoPath
);
547 // Show the video path on summary preference
548 mPrefInstantVideoUploadPath
.setSummary(mUploadVideoPath
);
550 saveInstantUploadVideoPathOnPreferences();
555 protected void onDestroy() {
558 if (mDownloadServiceConnection
!= null
) {
559 unbindService(mDownloadServiceConnection
);
560 mDownloadServiceConnection
= null
;
562 if (mUploadServiceConnection
!= null
) {
563 unbindService(mUploadServiceConnection
);
564 mUploadServiceConnection
= null
;
571 * Create the list of accounts that has been added into the app
573 @SuppressWarnings("deprecation")
574 private void addAccountsCheckboxPreferences() {
576 // Remove accounts in case list is refreshing for avoiding to have
578 if (mAccountsPrefCategory
.getPreferenceCount() > 0) {
579 mAccountsPrefCategory
.removeAll();
582 AccountManager am
= (AccountManager
) getSystemService(ACCOUNT_SERVICE
);
583 Account accounts
[] = am
.getAccountsByType(MainApp
.getAccountType());
584 Account currentAccount
= AccountUtils
.getCurrentOwnCloudAccount(getApplicationContext());
586 if (am
.getAccountsByType(MainApp
.getAccountType()).length
== 0) {
587 // Show create account screen if there isn't any account
588 am
.addAccount(MainApp
.getAccountType(), null
, null
, null
, this,
594 for (Account a
: accounts
) {
595 RadioButtonPreference accountPreference
= new RadioButtonPreference(this);
596 accountPreference
.setKey(a
.name
);
597 // Handle internationalized domain names
598 accountPreference
.setTitle(DisplayUtils
.convertIdn(a
.name
, false
));
599 mAccountsPrefCategory
.addPreference(accountPreference
);
601 // Check the current account that is being used
602 if (a
.name
.equals(currentAccount
.name
)) {
603 accountPreference
.setChecked(true
);
605 accountPreference
.setChecked(false
);
608 accountPreference
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
610 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
611 String key
= preference
.getKey();
612 AccountManager am
= (AccountManager
) getSystemService(ACCOUNT_SERVICE
);
613 Account accounts
[] = am
.getAccountsByType(MainApp
.getAccountType());
614 for (Account a
: accounts
) {
615 RadioButtonPreference p
= (RadioButtonPreference
) findPreference(a
.name
);
616 if (key
.equals(a
.name
)) {
617 boolean accountChanged
= !p
.isChecked();
619 AccountUtils
.setCurrentOwnCloudAccount(
620 getApplicationContext(),
623 if (accountChanged
) {
624 // restart the main activity
625 Intent i
= new Intent(
627 FileDisplayActivity
.class
629 i
.addFlags(Intent
.FLAG_ACTIVITY_CLEAR_TOP
);
630 i
.addFlags(Intent
.FLAG_ACTIVITY_SINGLE_TOP
);
639 return (Boolean
) newValue
;
645 // Add Create Account preference at the end of account list if
646 // Multiaccount is enabled
647 if (getResources().getBoolean(R
.bool
.multiaccount_support
)) {
648 createAddAccountPreference();
655 * Create the preference for allow adding new accounts
657 private void createAddAccountPreference() {
658 Preference addAccountPref
= new Preference(this);
659 addAccountPref
.setKey("add_account");
660 addAccountPref
.setTitle(getString(R
.string
.prefs_add_account
));
661 mAccountsPrefCategory
.addPreference(addAccountPref
);
663 addAccountPref
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
665 public boolean onPreferenceClick(Preference preference
) {
666 AccountManager am
= AccountManager
.get(getApplicationContext());
667 am
.addAccount(MainApp
.getAccountType(), null
, null
, null
, Preferences
.this, null
, null
);
675 * Load upload path set on preferences
677 private void loadInstantUploadPath() {
678 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
679 mUploadPath
= appPrefs
.getString("instant_upload_path", getString(R
.string
.instant_upload_path
));
680 mPrefInstantUploadPath
.setSummary(mUploadPath
);
684 * Save the "Instant Upload Path" on preferences
686 private void saveInstantUploadPathOnPreferences() {
687 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
688 SharedPreferences
.Editor editor
= appPrefs
.edit();
689 editor
.putString("instant_upload_path", mUploadPath
);
694 * Load upload video path set on preferences
696 private void loadInstantUploadVideoPath() {
697 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
698 mUploadVideoPath
= appPrefs
.getString("instant_video_upload_path", getString(R
.string
.instant_upload_path
));
699 mPrefInstantVideoUploadPath
.setSummary(mUploadVideoPath
);
703 * Save the "Instant Video Upload Path" on preferences
705 private void saveInstantUploadVideoPathOnPreferences() {
706 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
707 SharedPreferences
.Editor editor
= appPrefs
.edit();
708 editor
.putString("instant_video_upload_path", mUploadVideoPath
);
712 // Methods for ComponetsGetter
714 public FileDownloader
.FileDownloaderBinder
getFileDownloaderBinder() {
715 return mDownloaderBinder
;
720 public FileUploader
.FileUploaderBinder
getFileUploaderBinder() {
721 return mUploaderBinder
;
725 public OperationsService
.OperationsServiceBinder
getOperationsServiceBinder() {
730 public FileDataStorageManager
getStorageManager() {
735 public FileOperationsHelper
getFileOperationsHelper() {
739 protected ServiceConnection
newTransferenceServiceConnection() {
740 return new PreferencesServiceConnection();
743 /** Defines callbacks for service binding, passed to bindService() */
744 private class PreferencesServiceConnection
implements ServiceConnection
{
747 public void onServiceConnected(ComponentName component
, IBinder service
) {
749 if (component
.equals(new ComponentName(Preferences
.this, FileDownloader
.class))) {
750 mDownloaderBinder
= (FileDownloader
.FileDownloaderBinder
) service
;
752 } else if (component
.equals(new ComponentName(Preferences
.this, FileUploader
.class))) {
753 Log_OC
.d(TAG
, "Upload service connected");
754 mUploaderBinder
= (FileUploader
.FileUploaderBinder
) service
;
762 public void onServiceDisconnected(ComponentName component
) {
763 if (component
.equals(new ComponentName(Preferences
.this, FileDownloader
.class))) {
764 Log_OC
.d(TAG
, "Download service suddenly disconnected");
765 mDownloaderBinder
= null
;
766 } else if (component
.equals(new ComponentName(Preferences
.this, FileUploader
.class))) {
767 Log_OC
.d(TAG
, "Upload service suddenly disconnected");
768 mUploaderBinder
= null
;