1 /* ownCloud Android client application
2 * Copyright (C) 2011 Bartek Przybylski
3 * Copyright (C) 2012-2015 ownCloud Inc.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2,
7 * as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package com
.owncloud
.android
.ui
.activity
;
20 import android
.accounts
.Account
;
21 import android
.accounts
.AccountManager
;
22 import android
.accounts
.AccountManagerCallback
;
23 import android
.accounts
.AccountManagerFuture
;
24 import android
.content
.ComponentName
;
25 import android
.content
.Context
;
26 import android
.content
.Intent
;
27 import android
.content
.ServiceConnection
;
28 import android
.content
.SharedPreferences
;
29 import android
.content
.pm
.PackageInfo
;
30 import android
.content
.pm
.PackageManager
.NameNotFoundException
;
31 import android
.net
.Uri
;
32 import android
.os
.Bundle
;
33 import android
.os
.Handler
;
34 import android
.os
.IBinder
;
35 import android
.preference
.CheckBoxPreference
;
36 import android
.preference
.Preference
;
37 import android
.preference
.Preference
.OnPreferenceChangeListener
;
38 import android
.preference
.Preference
.OnPreferenceClickListener
;
39 import android
.preference
.PreferenceCategory
;
40 import android
.preference
.PreferenceManager
;
41 import android
.view
.ContextMenu
;
42 import android
.view
.ContextMenu
.ContextMenuInfo
;
43 import android
.view
.View
;
44 import android
.widget
.AdapterView
;
45 import android
.widget
.AdapterView
.OnItemLongClickListener
;
46 import android
.widget
.ListAdapter
;
47 import android
.widget
.ListView
;
49 import com
.actionbarsherlock
.app
.ActionBar
;
50 import com
.actionbarsherlock
.app
.SherlockPreferenceActivity
;
51 import com
.actionbarsherlock
.view
.Menu
;
52 import com
.actionbarsherlock
.view
.MenuItem
;
53 import com
.owncloud
.android
.MainApp
;
54 import com
.owncloud
.android
.R
;
55 import com
.owncloud
.android
.authentication
.AccountUtils
;
56 import com
.owncloud
.android
.authentication
.AuthenticatorActivity
;
57 import com
.owncloud
.android
.datamodel
.FileDataStorageManager
;
58 import com
.owncloud
.android
.datamodel
.OCFile
;
59 import com
.owncloud
.android
.db
.DbHandler
;
60 import com
.owncloud
.android
.files
.FileOperationsHelper
;
61 import com
.owncloud
.android
.files
.services
.FileDownloader
;
62 import com
.owncloud
.android
.files
.services
.FileUploader
;
63 import com
.owncloud
.android
.lib
.common
.utils
.Log_OC
;
64 import com
.owncloud
.android
.services
.OperationsService
;
65 import com
.owncloud
.android
.ui
.RadioButtonPreference
;
66 import com
.owncloud
.android
.utils
.DisplayUtils
;
72 * An Activity that allows the user to change the application's settings.
74 * @author Bartek Przybylski
75 * @author David A. Velasco
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 // Load the accounts category for adding the list of accounts
120 mAccountsPrefCategory
= (PreferenceCategory
) findPreference("accounts_category");
122 ListView listView
= getListView();
123 listView
.setOnItemLongClickListener(new OnItemLongClickListener() {
125 public boolean onItemLongClick(AdapterView
<?
> parent
, View view
, int position
, long id
) {
126 ListView listView
= (ListView
) parent
;
127 ListAdapter listAdapter
= listView
.getAdapter();
128 Object obj
= listAdapter
.getItem(position
);
130 if (obj
!= null
&& obj
instanceof RadioButtonPreference
) {
131 mShowContextMenu
= true
;
132 mAccountName
= ((RadioButtonPreference
) obj
).getKey();
134 Preferences
.this.openContextMenu(listView
);
136 View
.OnLongClickListener longListener
= (View
.OnLongClickListener
) obj
;
137 return longListener
.onLongClick(view
);
146 PackageInfo pkg
= getPackageManager().getPackageInfo(getPackageName(), 0);
147 temp
= pkg
.versionName
;
148 } catch (NameNotFoundException e
) {
150 Log_OC
.e(TAG
, "Error while showing about dialog", e
);
152 final String appVersion
= temp
;
154 // Register context menu for list of preferences.
155 registerForContextMenu(getListView());
157 pCode
= (CheckBoxPreference
) findPreference("set_pincode");
159 pCode
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
161 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
162 Intent i
= new Intent(getApplicationContext(), PinCodeActivity
.class);
163 i
.putExtra(PinCodeActivity
.EXTRA_ACTIVITY
, "preferences");
164 i
.putExtra(PinCodeActivity
.EXTRA_NEW_STATE
, newValue
.toString());
173 PreferenceCategory preferenceCategory
= (PreferenceCategory
) findPreference("more");
175 boolean helpEnabled
= getResources().getBoolean(R
.bool
.help_enabled
);
176 Preference pHelp
= findPreference("help");
179 pHelp
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
181 public boolean onPreferenceClick(Preference preference
) {
182 String helpWeb
=(String
) getText(R
.string
.url_help
);
183 if (helpWeb
!= null
&& helpWeb
.length() > 0) {
184 Uri uriUrl
= Uri
.parse(helpWeb
);
185 Intent intent
= new Intent(Intent
.ACTION_VIEW
, uriUrl
);
186 startActivity(intent
);
192 preferenceCategory
.removePreference(pHelp
);
198 boolean recommendEnabled
= getResources().getBoolean(R
.bool
.recommend_enabled
);
199 Preference pRecommend
= findPreference("recommend");
200 if (pRecommend
!= null
){
201 if (recommendEnabled
) {
202 pRecommend
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
204 public boolean onPreferenceClick(Preference preference
) {
206 Intent intent
= new Intent(Intent
.ACTION_SENDTO
);
207 intent
.setType("text/plain");
208 intent
.setData(Uri
.parse(getString(R
.string
.mail_recommend
)));
209 intent
.addFlags(Intent
.FLAG_ACTIVITY_NEW_TASK
);
211 String appName
= getString(R
.string
.app_name
);
212 String downloadUrl
= getString(R
.string
.url_app_download
);
213 Account currentAccount
= AccountUtils
.getCurrentOwnCloudAccount(Preferences
.this);
214 String username
= currentAccount
.name
.substring(0, currentAccount
.name
.lastIndexOf('@'));
216 String recommendSubject
= String
.format(getString(R
.string
.recommend_subject
), appName
);
217 String recommendText
= String
.format(getString(R
.string
.recommend_text
),
218 appName
, downloadUrl
, username
);
220 intent
.putExtra(Intent
.EXTRA_SUBJECT
, recommendSubject
);
221 intent
.putExtra(Intent
.EXTRA_TEXT
, recommendText
);
222 startActivity(intent
);
229 preferenceCategory
.removePreference(pRecommend
);
234 boolean feedbackEnabled
= getResources().getBoolean(R
.bool
.feedback_enabled
);
235 Preference pFeedback
= findPreference("feedback");
236 if (pFeedback
!= null
){
237 if (feedbackEnabled
) {
238 pFeedback
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
240 public boolean onPreferenceClick(Preference preference
) {
241 String feedbackMail
=(String
) getText(R
.string
.mail_feedback
);
242 String feedback
=(String
) getText(R
.string
.prefs_feedback
) + " - android v" + appVersion
;
243 Intent intent
= new Intent(Intent
.ACTION_SENDTO
);
244 intent
.setType("text/plain");
245 intent
.putExtra(Intent
.EXTRA_SUBJECT
, feedback
);
247 intent
.setData(Uri
.parse(feedbackMail
));
248 intent
.addFlags(Intent
.FLAG_ACTIVITY_NEW_TASK
);
249 startActivity(intent
);
255 preferenceCategory
.removePreference(pFeedback
);
260 boolean imprintEnabled
= getResources().getBoolean(R
.bool
.imprint_enabled
);
261 Preference pImprint
= findPreference("imprint");
262 if (pImprint
!= null
) {
263 if (imprintEnabled
) {
264 pImprint
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
266 public boolean onPreferenceClick(Preference preference
) {
267 String imprintWeb
= (String
) getText(R
.string
.url_imprint
);
268 if (imprintWeb
!= null
&& imprintWeb
.length() > 0) {
269 Uri uriUrl
= Uri
.parse(imprintWeb
);
270 Intent intent
= new Intent(Intent
.ACTION_VIEW
, uriUrl
);
271 startActivity(intent
);
273 //ImprintDialog.newInstance(true).show(preference.get, "IMPRINT_DIALOG");
278 preferenceCategory
.removePreference(pImprint
);
282 mPrefInstantUploadPath
= findPreference("instant_upload_path");
283 if (mPrefInstantUploadPath
!= null
){
285 mPrefInstantUploadPath
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
287 public boolean onPreferenceClick(Preference preference
) {
288 if (!mUploadPath
.endsWith(OCFile
.PATH_SEPARATOR
)) {
289 mUploadPath
+= OCFile
.PATH_SEPARATOR
;
291 Intent intent
= new Intent(Preferences
.this, UploadPathActivity
.class);
292 intent
.putExtra(UploadPathActivity
.KEY_INSTANT_UPLOAD_PATH
, mUploadPath
);
293 startActivityForResult(intent
, ACTION_SELECT_UPLOAD_PATH
);
299 mPrefInstantUploadCategory
= (PreferenceCategory
) findPreference("instant_uploading_category");
301 mPrefInstantUploadPathWiFi
= findPreference("instant_upload_on_wifi");
302 mPrefInstantUpload
= findPreference("instant_uploading");
304 toggleInstantPictureOptions(((CheckBoxPreference
) mPrefInstantUpload
).isChecked());
306 mPrefInstantUpload
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
309 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
310 toggleInstantPictureOptions((Boolean
) newValue
);
315 mPrefInstantVideoUploadPath
= findPreference("instant_video_upload_path");
316 if (mPrefInstantVideoUploadPath
!= null
){
318 mPrefInstantVideoUploadPath
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
320 public boolean onPreferenceClick(Preference preference
) {
321 if (!mUploadVideoPath
.endsWith(OCFile
.PATH_SEPARATOR
)) {
322 mUploadVideoPath
+= OCFile
.PATH_SEPARATOR
;
324 Intent intent
= new Intent(Preferences
.this, UploadPathActivity
.class);
325 intent
.putExtra(UploadPathActivity
.KEY_INSTANT_UPLOAD_PATH
, mUploadVideoPath
);
326 startActivityForResult(intent
, ACTION_SELECT_UPLOAD_VIDEO_PATH
);
332 mPrefInstantVideoUploadPathWiFi
= findPreference("instant_video_upload_on_wifi");
333 mPrefInstantVideoUpload
= findPreference("instant_video_uploading");
334 toggleInstantVideoOptions(((CheckBoxPreference
) mPrefInstantVideoUpload
).isChecked());
336 mPrefInstantVideoUpload
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
339 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
340 toggleInstantVideoOptions((Boolean
) newValue
);
346 pAboutApp
= (Preference
) findPreference("about_app");
347 if (pAboutApp
!= null
) {
348 pAboutApp
.setTitle(String
.format(getString(R
.string
.about_android
), getString(R
.string
.app_name
)));
349 pAboutApp
.setSummary(String
.format(getString(R
.string
.about_version
), appVersion
));
352 loadInstantUploadPath();
353 loadInstantUploadVideoPath();
355 /* ComponentsGetter */
356 mDownloadServiceConnection
= newTransferenceServiceConnection();
357 if (mDownloadServiceConnection
!= null
) {
358 bindService(new Intent(this, FileDownloader
.class), mDownloadServiceConnection
,
359 Context
.BIND_AUTO_CREATE
);
361 mUploadServiceConnection
= newTransferenceServiceConnection();
362 if (mUploadServiceConnection
!= null
) {
363 bindService(new Intent(this, FileUploader
.class), mUploadServiceConnection
,
364 Context
.BIND_AUTO_CREATE
);
369 private void toggleInstantPictureOptions(Boolean value
){
371 mPrefInstantUploadCategory
.addPreference(mPrefInstantUploadPathWiFi
);
372 mPrefInstantUploadCategory
.addPreference(mPrefInstantUploadPath
);
374 mPrefInstantUploadCategory
.removePreference(mPrefInstantUploadPathWiFi
);
375 mPrefInstantUploadCategory
.removePreference(mPrefInstantUploadPath
);
379 private void toggleInstantVideoOptions(Boolean value
){
381 mPrefInstantUploadCategory
.addPreference(mPrefInstantVideoUploadPathWiFi
);
382 mPrefInstantUploadCategory
.addPreference(mPrefInstantVideoUploadPath
);
384 mPrefInstantUploadCategory
.removePreference(mPrefInstantVideoUploadPathWiFi
);
385 mPrefInstantUploadCategory
.removePreference(mPrefInstantVideoUploadPath
);
390 protected void onPause() {
395 public void onCreateContextMenu(ContextMenu menu
, View v
, ContextMenuInfo menuInfo
) {
397 // Filter for only showing contextual menu when long press on the
399 if (mShowContextMenu
) {
400 getMenuInflater().inflate(R
.menu
.account_picker_long_click
, menu
);
401 mShowContextMenu
= false
;
403 super.onCreateContextMenu(menu
, v
, menuInfo
);
407 * Called when the user clicked on an item into the context menu created at
408 * {@link #onCreateContextMenu(ContextMenu, View, ContextMenuInfo)} for
409 * every ownCloud {@link Account} , containing 'secondary actions' for them.
414 public boolean onContextItemSelected(android
.view
.MenuItem item
) {
415 AccountManager am
= (AccountManager
) getSystemService(ACCOUNT_SERVICE
);
416 Account accounts
[] = am
.getAccountsByType(MainApp
.getAccountType());
417 for (Account a
: accounts
) {
418 if (a
.name
.equals(mAccountName
)) {
419 if (item
.getItemId() == R
.id
.change_password
) {
421 // Change account password
422 Intent updateAccountCredentials
= new Intent(this, AuthenticatorActivity
.class);
423 updateAccountCredentials
.putExtra(AuthenticatorActivity
.EXTRA_ACCOUNT
, a
);
424 updateAccountCredentials
.putExtra(AuthenticatorActivity
.EXTRA_ACTION
,
425 AuthenticatorActivity
.ACTION_UPDATE_TOKEN
);
426 startActivity(updateAccountCredentials
);
428 } else if (item
.getItemId() == R
.id
.delete_account
) {
431 am
.removeAccount(a
, this, mHandler
);
432 Log_OC
.d(TAG
, "Remove an account " + a
.name
);
441 public void run(AccountManagerFuture
<Boolean
> future
) {
442 if (future
.isDone()) {
443 // after remove account
444 Account account
= new Account(mAccountName
, MainApp
.getAccountType());
445 if (!AccountUtils
.exists(account
, MainApp
.getAppContext())) {
447 mUploaderBinder
.cancel(account
);
448 mDownloaderBinder
.cancel(account
);
451 Account a
= AccountUtils
.getCurrentOwnCloudAccount(this);
452 String accountName
= "";
454 Account
[] accounts
= AccountManager
.get(this).getAccountsByType(MainApp
.getAccountType());
455 if (accounts
.length
!= 0)
456 accountName
= accounts
[0].name
;
457 AccountUtils
.setCurrentOwnCloudAccount(this, accountName
);
459 addAccountsCheckboxPreferences();
464 protected void onResume() {
466 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
467 boolean state
= appPrefs
.getBoolean("set_pincode", false
);
468 pCode
.setChecked(state
);
470 // Populate the accounts category with the list of accounts
471 addAccountsCheckboxPreferences();
475 public boolean onCreateOptionsMenu(Menu menu
) {
476 super.onCreateOptionsMenu(menu
);
481 public boolean onMenuItemSelected(int featureId
, MenuItem item
) {
482 super.onMenuItemSelected(featureId
, item
);
485 switch (item
.getItemId()) {
486 case android
.R
.id
.home
:
487 intent
= new Intent(getBaseContext(), FileDisplayActivity
.class);
488 intent
.addFlags(Intent
.FLAG_ACTIVITY_CLEAR_TOP
);
489 startActivity(intent
);
492 Log_OC
.w(TAG
, "Unknown menu item triggered");
499 protected void onActivityResult(int requestCode
, int resultCode
, Intent data
) {
500 super.onActivityResult(requestCode
, resultCode
, data
);
502 if (requestCode
== ACTION_SELECT_UPLOAD_PATH
&& resultCode
== RESULT_OK
){
504 OCFile folderToUpload
= (OCFile
) data
.getParcelableExtra(UploadPathActivity
.EXTRA_FOLDER
);
506 mUploadPath
= folderToUpload
.getRemotePath();
508 mUploadPath
= DisplayUtils
.getPathWithoutLastSlash(mUploadPath
);
510 // Show the path on summary preference
511 mPrefInstantUploadPath
.setSummary(mUploadPath
);
513 saveInstantUploadPathOnPreferences();
515 } else if (requestCode
== ACTION_SELECT_UPLOAD_VIDEO_PATH
&& resultCode
== RESULT_OK
){
517 OCFile folderToUploadVideo
= (OCFile
) data
.getParcelableExtra(UploadPathActivity
.EXTRA_FOLDER
);
519 mUploadVideoPath
= folderToUploadVideo
.getRemotePath();
521 mUploadVideoPath
= DisplayUtils
.getPathWithoutLastSlash(mUploadVideoPath
);
523 // Show the video path on summary preference
524 mPrefInstantVideoUploadPath
.setSummary(mUploadVideoPath
);
526 saveInstantUploadVideoPathOnPreferences();
531 protected void onDestroy() {
534 if (mDownloadServiceConnection
!= null
) {
535 unbindService(mDownloadServiceConnection
);
536 mDownloadServiceConnection
= null
;
538 if (mUploadServiceConnection
!= null
) {
539 unbindService(mUploadServiceConnection
);
540 mUploadServiceConnection
= null
;
547 * Create the list of accounts that has been added into the app
549 @SuppressWarnings("deprecation")
550 private void addAccountsCheckboxPreferences() {
552 // Remove accounts in case list is refreshing for avoiding to have
554 if (mAccountsPrefCategory
.getPreferenceCount() > 0) {
555 mAccountsPrefCategory
.removeAll();
558 AccountManager am
= (AccountManager
) getSystemService(ACCOUNT_SERVICE
);
559 Account accounts
[] = am
.getAccountsByType(MainApp
.getAccountType());
560 Account currentAccount
= AccountUtils
.getCurrentOwnCloudAccount(getApplicationContext());
562 if (am
.getAccountsByType(MainApp
.getAccountType()).length
== 0) {
563 // Show create account screen if there isn't any account
564 am
.addAccount(MainApp
.getAccountType(), null
, null
, null
, this,
570 for (Account a
: accounts
) {
571 RadioButtonPreference accountPreference
= new RadioButtonPreference(this);
572 accountPreference
.setKey(a
.name
);
573 // Handle internationalized domain names
574 accountPreference
.setTitle(DisplayUtils
.convertIdn(a
.name
, false
));
575 mAccountsPrefCategory
.addPreference(accountPreference
);
577 // Check the current account that is being used
578 if (a
.name
.equals(currentAccount
.name
)) {
579 accountPreference
.setChecked(true
);
581 accountPreference
.setChecked(false
);
584 accountPreference
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
586 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
587 String key
= preference
.getKey();
588 AccountManager am
= (AccountManager
) getSystemService(ACCOUNT_SERVICE
);
589 Account accounts
[] = am
.getAccountsByType(MainApp
.getAccountType());
590 for (Account a
: accounts
) {
591 RadioButtonPreference p
= (RadioButtonPreference
) findPreference(a
.name
);
592 if (key
.equals(a
.name
)) {
593 boolean accountChanged
= !p
.isChecked();
595 AccountUtils
.setCurrentOwnCloudAccount(
596 getApplicationContext(),
599 if (accountChanged
) {
600 // restart the main activity
601 Intent i
= new Intent(
603 FileDisplayActivity
.class
605 i
.addFlags(Intent
.FLAG_ACTIVITY_CLEAR_TOP
);
614 return (Boolean
) newValue
;
620 // Add Create Account preference at the end of account list if
621 // Multiaccount is enabled
622 if (getResources().getBoolean(R
.bool
.multiaccount_support
)) {
623 createAddAccountPreference();
630 * Create the preference for allow adding new accounts
632 private void createAddAccountPreference() {
633 Preference addAccountPref
= new Preference(this);
634 addAccountPref
.setKey("add_account");
635 addAccountPref
.setTitle(getString(R
.string
.prefs_add_account
));
636 mAccountsPrefCategory
.addPreference(addAccountPref
);
638 addAccountPref
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
640 public boolean onPreferenceClick(Preference preference
) {
641 AccountManager am
= AccountManager
.get(getApplicationContext());
642 am
.addAccount(MainApp
.getAccountType(), null
, null
, null
, Preferences
.this, null
, null
);
650 * Load upload path set on preferences
652 private void loadInstantUploadPath() {
653 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
654 mUploadPath
= appPrefs
.getString("instant_upload_path", getString(R
.string
.instant_upload_path
));
655 mPrefInstantUploadPath
.setSummary(mUploadPath
);
659 * Save the "Instant Upload Path" on preferences
661 private void saveInstantUploadPathOnPreferences() {
662 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
663 SharedPreferences
.Editor editor
= appPrefs
.edit();
664 editor
.putString("instant_upload_path", mUploadPath
);
669 * Load upload video path set on preferences
671 private void loadInstantUploadVideoPath() {
672 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
673 mUploadVideoPath
= appPrefs
.getString("instant_video_upload_path", getString(R
.string
.instant_upload_path
));
674 mPrefInstantVideoUploadPath
.setSummary(mUploadVideoPath
);
678 * Save the "Instant Video Upload Path" on preferences
680 private void saveInstantUploadVideoPathOnPreferences() {
681 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
682 SharedPreferences
.Editor editor
= appPrefs
.edit();
683 editor
.putString("instant_video_upload_path", mUploadVideoPath
);
687 // Methods for ComponetsGetter
689 public FileDownloader
.FileDownloaderBinder
getFileDownloaderBinder() {
690 return mDownloaderBinder
;
695 public FileUploader
.FileUploaderBinder
getFileUploaderBinder() {
696 return mUploaderBinder
;
700 public OperationsService
.OperationsServiceBinder
getOperationsServiceBinder() {
705 public FileDataStorageManager
getStorageManager() {
710 public FileOperationsHelper
getFileOperationsHelper() {
714 protected ServiceConnection
newTransferenceServiceConnection() {
715 return new PreferencesServiceConnection();
718 /** Defines callbacks for service binding, passed to bindService() */
719 private class PreferencesServiceConnection
implements ServiceConnection
{
722 public void onServiceConnected(ComponentName component
, IBinder service
) {
724 if (component
.equals(new ComponentName(Preferences
.this, FileDownloader
.class))) {
725 mDownloaderBinder
= (FileDownloader
.FileDownloaderBinder
) service
;
727 } else if (component
.equals(new ComponentName(Preferences
.this, FileUploader
.class))) {
728 Log_OC
.d(TAG
, "Upload service connected");
729 mUploaderBinder
= (FileUploader
.FileUploaderBinder
) service
;
737 public void onServiceDisconnected(ComponentName component
) {
738 if (component
.equals(new ComponentName(Preferences
.this, FileDownloader
.class))) {
739 Log_OC
.d(TAG
, "Download service suddenly disconnected");
740 mDownloaderBinder
= null
;
741 } else if (component
.equals(new ComponentName(Preferences
.this, FileUploader
.class))) {
742 Log_OC
.d(TAG
, "Upload service suddenly disconnected");
743 mUploaderBinder
= null
;