1 /* ownCloud Android client application
2 * Copyright (C) 2011 Bartek Przybylski
3 * Copyright (C) 2012-2013 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
;
70 * An Activity that allows the user to change the application's settings.
72 * @author Bartek Przybylski
73 * @author David A. Velasco
75 public class Preferences
extends SherlockPreferenceActivity
76 implements AccountManagerCallback
<Boolean
>, ComponentsGetter
{
78 private static final String TAG
= "OwnCloudPreferences";
80 private static final int ACTION_SELECT_UPLOAD_PATH
= 1;
81 private static final int ACTION_SELECT_UPLOAD_VIDEO_PATH
= 2;
83 private DbHandler mDbHandler
;
84 private CheckBoxPreference pCode
;
85 private Preference pAboutApp
;
87 private PreferenceCategory mAccountsPrefCategory
= null
;
88 private final Handler mHandler
= new Handler();
89 private String mAccountName
;
90 private boolean mShowContextMenu
= false
;
91 private String mUploadPath
;
92 private PreferenceCategory mPrefInstantUploadCategory
;
93 private Preference mPrefInstantUpload
;
94 private Preference mPrefInstantUploadPath
;
95 private Preference mPrefInstantUploadPathWiFi
;
96 private Preference mPrefInstantVideoUpload
;
97 private Preference mPrefInstantVideoUploadPath
;
98 private Preference mPrefInstantVideoUploadPathWiFi
;
99 private String mUploadVideoPath
;
101 protected FileDownloader
.FileDownloaderBinder mDownloaderBinder
= null
;
102 protected FileUploader
.FileUploaderBinder mUploaderBinder
= null
;
103 private ServiceConnection mDownloadServiceConnection
, mUploadServiceConnection
= null
;
105 @SuppressWarnings("deprecation")
107 public void onCreate(Bundle savedInstanceState
) {
108 super.onCreate(savedInstanceState
);
109 mDbHandler
= new DbHandler(getBaseContext());
110 addPreferencesFromResource(R
.xml
.preferences
);
112 ActionBar actionBar
= getSherlock().getActionBar();
113 actionBar
.setIcon(DisplayUtils
.getSeasonalIconId());
114 actionBar
.setDisplayHomeAsUpEnabled(true
);
115 actionBar
.setTitle(R
.string
.actionbar_settings
);
117 // Load the accounts category for adding the list of accounts
118 mAccountsPrefCategory
= (PreferenceCategory
) findPreference("accounts_category");
120 ListView listView
= getListView();
121 listView
.setOnItemLongClickListener(new OnItemLongClickListener() {
123 public boolean onItemLongClick(AdapterView
<?
> parent
, View view
, int position
, long id
) {
124 ListView listView
= (ListView
) parent
;
125 ListAdapter listAdapter
= listView
.getAdapter();
126 Object obj
= listAdapter
.getItem(position
);
128 if (obj
!= null
&& obj
instanceof RadioButtonPreference
) {
129 mShowContextMenu
= true
;
130 mAccountName
= ((RadioButtonPreference
) obj
).getKey();
132 Preferences
.this.openContextMenu(listView
);
134 View
.OnLongClickListener longListener
= (View
.OnLongClickListener
) obj
;
135 return longListener
.onLongClick(view
);
144 PackageInfo pkg
= getPackageManager().getPackageInfo(getPackageName(), 0);
145 temp
= pkg
.versionName
;
146 } catch (NameNotFoundException e
) {
148 Log_OC
.e(TAG
, "Error while showing about dialog", e
);
150 final String appVersion
= temp
;
152 // Register context menu for list of preferences.
153 registerForContextMenu(getListView());
155 pCode
= (CheckBoxPreference
) findPreference("set_pincode");
157 pCode
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
159 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
160 Intent i
= new Intent(getApplicationContext(), PinCodeActivity
.class);
161 i
.putExtra(PinCodeActivity
.EXTRA_ACTIVITY
, "preferences");
162 i
.putExtra(PinCodeActivity
.EXTRA_NEW_STATE
, newValue
.toString());
171 PreferenceCategory preferenceCategory
= (PreferenceCategory
) findPreference("more");
173 boolean helpEnabled
= getResources().getBoolean(R
.bool
.help_enabled
);
174 Preference pHelp
= findPreference("help");
177 pHelp
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
179 public boolean onPreferenceClick(Preference preference
) {
180 String helpWeb
=(String
) getText(R
.string
.url_help
);
181 if (helpWeb
!= null
&& helpWeb
.length() > 0) {
182 Uri uriUrl
= Uri
.parse(helpWeb
);
183 Intent intent
= new Intent(Intent
.ACTION_VIEW
, uriUrl
);
184 startActivity(intent
);
190 preferenceCategory
.removePreference(pHelp
);
196 boolean recommendEnabled
= getResources().getBoolean(R
.bool
.recommend_enabled
);
197 Preference pRecommend
= findPreference("recommend");
198 if (pRecommend
!= null
){
199 if (recommendEnabled
) {
200 pRecommend
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
202 public boolean onPreferenceClick(Preference preference
) {
204 Intent intent
= new Intent(Intent
.ACTION_SENDTO
);
205 intent
.setType("text/plain");
206 intent
.setData(Uri
.parse(getString(R
.string
.mail_recommend
)));
207 intent
.addFlags(Intent
.FLAG_ACTIVITY_NEW_TASK
);
209 String appName
= getString(R
.string
.app_name
);
210 String downloadUrl
= getString(R
.string
.url_app_download
);
211 Account currentAccount
= AccountUtils
.getCurrentOwnCloudAccount(Preferences
.this);
212 String username
= currentAccount
.name
.substring(0, currentAccount
.name
.lastIndexOf('@'));
214 String recommendSubject
= String
.format(getString(R
.string
.recommend_subject
), appName
);
215 String recommendText
= String
.format(getString(R
.string
.recommend_text
),
216 appName
, downloadUrl
, username
);
218 intent
.putExtra(Intent
.EXTRA_SUBJECT
, recommendSubject
);
219 intent
.putExtra(Intent
.EXTRA_TEXT
, recommendText
);
220 startActivity(intent
);
227 preferenceCategory
.removePreference(pRecommend
);
232 boolean feedbackEnabled
= getResources().getBoolean(R
.bool
.feedback_enabled
);
233 Preference pFeedback
= findPreference("feedback");
234 if (pFeedback
!= null
){
235 if (feedbackEnabled
) {
236 pFeedback
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
238 public boolean onPreferenceClick(Preference preference
) {
239 String feedbackMail
=(String
) getText(R
.string
.mail_feedback
);
240 String feedback
=(String
) getText(R
.string
.prefs_feedback
) + " - android v" + appVersion
;
241 Intent intent
= new Intent(Intent
.ACTION_SENDTO
);
242 intent
.setType("text/plain");
243 intent
.putExtra(Intent
.EXTRA_SUBJECT
, feedback
);
245 intent
.setData(Uri
.parse(feedbackMail
));
246 intent
.addFlags(Intent
.FLAG_ACTIVITY_NEW_TASK
);
247 startActivity(intent
);
253 preferenceCategory
.removePreference(pFeedback
);
258 boolean imprintEnabled
= getResources().getBoolean(R
.bool
.imprint_enabled
);
259 Preference pImprint
= findPreference("imprint");
260 if (pImprint
!= null
) {
261 if (imprintEnabled
) {
262 pImprint
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
264 public boolean onPreferenceClick(Preference preference
) {
265 String imprintWeb
= (String
) getText(R
.string
.url_imprint
);
266 if (imprintWeb
!= null
&& imprintWeb
.length() > 0) {
267 Uri uriUrl
= Uri
.parse(imprintWeb
);
268 Intent intent
= new Intent(Intent
.ACTION_VIEW
, uriUrl
);
269 startActivity(intent
);
271 //ImprintDialog.newInstance(true).show(preference.get, "IMPRINT_DIALOG");
276 preferenceCategory
.removePreference(pImprint
);
280 mPrefInstantUploadPath
= findPreference("instant_upload_path");
281 if (mPrefInstantUploadPath
!= null
){
283 mPrefInstantUploadPath
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
285 public boolean onPreferenceClick(Preference preference
) {
286 if (!mUploadPath
.endsWith(OCFile
.PATH_SEPARATOR
)) {
287 mUploadPath
+= OCFile
.PATH_SEPARATOR
;
289 Intent intent
= new Intent(Preferences
.this, UploadPathActivity
.class);
290 intent
.putExtra(UploadPathActivity
.KEY_INSTANT_UPLOAD_PATH
, mUploadPath
);
291 startActivityForResult(intent
, ACTION_SELECT_UPLOAD_PATH
);
297 mPrefInstantUploadCategory
= (PreferenceCategory
) findPreference("instant_uploading_category");
299 mPrefInstantUploadPathWiFi
= findPreference("instant_upload_on_wifi");
300 mPrefInstantUpload
= findPreference("instant_uploading");
302 toggleInstantPictureOptions(((CheckBoxPreference
) mPrefInstantUpload
).isChecked());
304 mPrefInstantUpload
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
307 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
308 toggleInstantPictureOptions((Boolean
) newValue
);
313 mPrefInstantVideoUploadPath
= findPreference("instant_video_upload_path");
314 if (mPrefInstantVideoUploadPath
!= null
){
316 mPrefInstantVideoUploadPath
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
318 public boolean onPreferenceClick(Preference preference
) {
319 if (!mUploadVideoPath
.endsWith(OCFile
.PATH_SEPARATOR
)) {
320 mUploadVideoPath
+= OCFile
.PATH_SEPARATOR
;
322 Intent intent
= new Intent(Preferences
.this, UploadPathActivity
.class);
323 intent
.putExtra(UploadPathActivity
.KEY_INSTANT_UPLOAD_PATH
, mUploadVideoPath
);
324 startActivityForResult(intent
, ACTION_SELECT_UPLOAD_VIDEO_PATH
);
330 mPrefInstantVideoUploadPathWiFi
= findPreference("instant_video_upload_on_wifi");
331 mPrefInstantVideoUpload
= findPreference("instant_video_uploading");
332 toggleInstantVideoOptions(((CheckBoxPreference
) mPrefInstantVideoUpload
).isChecked());
334 mPrefInstantVideoUpload
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
337 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
338 toggleInstantVideoOptions((Boolean
) newValue
);
344 pAboutApp
= (Preference
) findPreference("about_app");
345 if (pAboutApp
!= null
) {
346 pAboutApp
.setTitle(String
.format(getString(R
.string
.about_android
), getString(R
.string
.app_name
)));
347 pAboutApp
.setSummary(String
.format(getString(R
.string
.about_version
), appVersion
));
350 loadInstantUploadPath();
351 loadInstantUploadVideoPath();
353 /* ComponentsGetter */
354 mDownloadServiceConnection
= newTransferenceServiceConnection();
355 if (mDownloadServiceConnection
!= null
) {
356 bindService(new Intent(this, FileDownloader
.class), mDownloadServiceConnection
,
357 Context
.BIND_AUTO_CREATE
);
359 mUploadServiceConnection
= newTransferenceServiceConnection();
360 if (mUploadServiceConnection
!= null
) {
361 bindService(new Intent(this, FileUploader
.class), mUploadServiceConnection
,
362 Context
.BIND_AUTO_CREATE
);
367 private void toggleInstantPictureOptions(Boolean value
){
369 mPrefInstantUploadCategory
.addPreference(mPrefInstantUploadPathWiFi
);
370 mPrefInstantUploadCategory
.addPreference(mPrefInstantUploadPath
);
372 mPrefInstantUploadCategory
.removePreference(mPrefInstantUploadPathWiFi
);
373 mPrefInstantUploadCategory
.removePreference(mPrefInstantUploadPath
);
377 private void toggleInstantVideoOptions(Boolean value
){
379 mPrefInstantUploadCategory
.addPreference(mPrefInstantVideoUploadPathWiFi
);
380 mPrefInstantUploadCategory
.addPreference(mPrefInstantVideoUploadPath
);
382 mPrefInstantUploadCategory
.removePreference(mPrefInstantVideoUploadPathWiFi
);
383 mPrefInstantUploadCategory
.removePreference(mPrefInstantVideoUploadPath
);
388 protected void onPause() {
393 public void onCreateContextMenu(ContextMenu menu
, View v
, ContextMenuInfo menuInfo
) {
395 // Filter for only showing contextual menu when long press on the
397 if (mShowContextMenu
) {
398 getMenuInflater().inflate(R
.menu
.account_picker_long_click
, menu
);
399 mShowContextMenu
= false
;
401 super.onCreateContextMenu(menu
, v
, menuInfo
);
405 * Called when the user clicked on an item into the context menu created at
406 * {@link #onCreateContextMenu(ContextMenu, View, ContextMenuInfo)} for
407 * every ownCloud {@link Account} , containing 'secondary actions' for them.
412 public boolean onContextItemSelected(android
.view
.MenuItem item
) {
413 AccountManager am
= (AccountManager
) getSystemService(ACCOUNT_SERVICE
);
414 Account accounts
[] = am
.getAccountsByType(MainApp
.getAccountType());
415 for (Account a
: accounts
) {
416 if (a
.name
.equals(mAccountName
)) {
417 if (item
.getItemId() == R
.id
.change_password
) {
419 // Change account password
420 Intent updateAccountCredentials
= new Intent(this, AuthenticatorActivity
.class);
421 updateAccountCredentials
.putExtra(AuthenticatorActivity
.EXTRA_ACCOUNT
, a
);
422 updateAccountCredentials
.putExtra(AuthenticatorActivity
.EXTRA_ACTION
,
423 AuthenticatorActivity
.ACTION_UPDATE_TOKEN
);
424 startActivity(updateAccountCredentials
);
426 } else if (item
.getItemId() == R
.id
.delete_account
) {
429 am
.removeAccount(a
, this, mHandler
);
430 Log_OC
.d(TAG
, "Remove an account " + a
.name
);
439 public void run(AccountManagerFuture
<Boolean
> future
) {
440 if (future
.isDone()) {
441 // after remove account
442 Account account
= new Account(mAccountName
, MainApp
.getAccountType());
443 if (!AccountUtils
.exists(account
, MainApp
.getAppContext())) {
445 mUploaderBinder
.cancel(account
);
448 Account a
= AccountUtils
.getCurrentOwnCloudAccount(this);
449 String accountName
= "";
451 Account
[] accounts
= AccountManager
.get(this).getAccountsByType(MainApp
.getAccountType());
452 if (accounts
.length
!= 0)
453 accountName
= accounts
[0].name
;
454 AccountUtils
.setCurrentOwnCloudAccount(this, accountName
);
456 addAccountsCheckboxPreferences();
461 protected void onResume() {
463 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
464 boolean state
= appPrefs
.getBoolean("set_pincode", false
);
465 pCode
.setChecked(state
);
467 // Populate the accounts category with the list of accounts
468 addAccountsCheckboxPreferences();
472 public boolean onCreateOptionsMenu(Menu menu
) {
473 super.onCreateOptionsMenu(menu
);
478 public boolean onMenuItemSelected(int featureId
, MenuItem item
) {
479 super.onMenuItemSelected(featureId
, item
);
482 switch (item
.getItemId()) {
483 case android
.R
.id
.home
:
484 intent
= new Intent(getBaseContext(), FileDisplayActivity
.class);
485 intent
.addFlags(Intent
.FLAG_ACTIVITY_CLEAR_TOP
);
486 startActivity(intent
);
489 Log_OC
.w(TAG
, "Unknown menu item triggered");
496 protected void onActivityResult(int requestCode
, int resultCode
, Intent data
) {
497 super.onActivityResult(requestCode
, resultCode
, data
);
499 if (requestCode
== ACTION_SELECT_UPLOAD_PATH
&& resultCode
== RESULT_OK
){
501 OCFile folderToUpload
= (OCFile
) data
.getParcelableExtra(UploadPathActivity
.EXTRA_FOLDER
);
503 mUploadPath
= folderToUpload
.getRemotePath();
505 mUploadPath
= DisplayUtils
.getPathWithoutLastSlash(mUploadPath
);
507 // Show the path on summary preference
508 mPrefInstantUploadPath
.setSummary(mUploadPath
);
510 saveInstantUploadPathOnPreferences();
512 } else if (requestCode
== ACTION_SELECT_UPLOAD_VIDEO_PATH
&& resultCode
== RESULT_OK
){
514 OCFile folderToUploadVideo
= (OCFile
) data
.getParcelableExtra(UploadPathActivity
.EXTRA_FOLDER
);
516 mUploadVideoPath
= folderToUploadVideo
.getRemotePath();
518 mUploadVideoPath
= DisplayUtils
.getPathWithoutLastSlash(mUploadVideoPath
);
520 // Show the video path on summary preference
521 mPrefInstantVideoUploadPath
.setSummary(mUploadVideoPath
);
523 saveInstantUploadVideoPathOnPreferences();
528 protected void onDestroy() {
531 if (mDownloadServiceConnection
!= null
) {
532 unbindService(mDownloadServiceConnection
);
533 mDownloadServiceConnection
= null
;
535 if (mUploadServiceConnection
!= null
) {
536 unbindService(mUploadServiceConnection
);
537 mUploadServiceConnection
= null
;
544 * Create the list of accounts that has been added into the app
546 @SuppressWarnings("deprecation")
547 private void addAccountsCheckboxPreferences() {
549 // Remove accounts in case list is refreshing for avoiding to have
551 if (mAccountsPrefCategory
.getPreferenceCount() > 0) {
552 mAccountsPrefCategory
.removeAll();
555 AccountManager am
= (AccountManager
) getSystemService(ACCOUNT_SERVICE
);
556 Account accounts
[] = am
.getAccountsByType(MainApp
.getAccountType());
557 Account currentAccount
= AccountUtils
.getCurrentOwnCloudAccount(getApplicationContext());
559 if (am
.getAccountsByType(MainApp
.getAccountType()).length
== 0) {
560 // Show create account screen if there isn't any account
561 am
.addAccount(MainApp
.getAccountType(), null
, null
, null
, this,
567 for (Account a
: accounts
) {
568 RadioButtonPreference accountPreference
= new RadioButtonPreference(this);
569 accountPreference
.setKey(a
.name
);
570 // Handle internationalized domain names
571 accountPreference
.setTitle(DisplayUtils
.convertIdn(a
.name
, false
));
572 mAccountsPrefCategory
.addPreference(accountPreference
);
574 // Check the current account that is being used
575 if (a
.name
.equals(currentAccount
.name
)) {
576 accountPreference
.setChecked(true
);
578 accountPreference
.setChecked(false
);
581 accountPreference
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
583 public boolean onPreferenceChange(Preference preference
, Object newValue
) {
584 String key
= preference
.getKey();
585 AccountManager am
= (AccountManager
) getSystemService(ACCOUNT_SERVICE
);
586 Account accounts
[] = am
.getAccountsByType(MainApp
.getAccountType());
587 for (Account a
: accounts
) {
588 RadioButtonPreference p
= (RadioButtonPreference
) findPreference(a
.name
);
589 if (key
.equals(a
.name
)) {
590 boolean accountChanged
= !p
.isChecked();
592 AccountUtils
.setCurrentOwnCloudAccount(
593 getApplicationContext(),
596 if (accountChanged
) {
597 // restart the main activity
598 Intent i
= new Intent(
600 FileDisplayActivity
.class
602 i
.addFlags(Intent
.FLAG_ACTIVITY_CLEAR_TOP
);
611 return (Boolean
) newValue
;
617 // Add Create Account preference at the end of account list if
618 // Multiaccount is enabled
619 if (getResources().getBoolean(R
.bool
.multiaccount_support
)) {
620 createAddAccountPreference();
627 * Create the preference for allow adding new accounts
629 private void createAddAccountPreference() {
630 Preference addAccountPref
= new Preference(this);
631 addAccountPref
.setKey("add_account");
632 addAccountPref
.setTitle(getString(R
.string
.prefs_add_account
));
633 mAccountsPrefCategory
.addPreference(addAccountPref
);
635 addAccountPref
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
637 public boolean onPreferenceClick(Preference preference
) {
638 AccountManager am
= AccountManager
.get(getApplicationContext());
639 am
.addAccount(MainApp
.getAccountType(), null
, null
, null
, Preferences
.this, null
, null
);
647 * Load upload path set on preferences
649 private void loadInstantUploadPath() {
650 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
651 mUploadPath
= appPrefs
.getString("instant_upload_path", getString(R
.string
.instant_upload_path
));
652 mPrefInstantUploadPath
.setSummary(mUploadPath
);
656 * Save the "Instant Upload Path" on preferences
658 private void saveInstantUploadPathOnPreferences() {
659 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
660 SharedPreferences
.Editor editor
= appPrefs
.edit();
661 editor
.putString("instant_upload_path", mUploadPath
);
666 * Load upload video path set on preferences
668 private void loadInstantUploadVideoPath() {
669 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
670 mUploadVideoPath
= appPrefs
.getString("instant_video_upload_path", getString(R
.string
.instant_upload_path
));
671 mPrefInstantVideoUploadPath
.setSummary(mUploadVideoPath
);
675 * Save the "Instant Video Upload Path" on preferences
677 private void saveInstantUploadVideoPathOnPreferences() {
678 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
679 SharedPreferences
.Editor editor
= appPrefs
.edit();
680 editor
.putString("instant_video_upload_path", mUploadVideoPath
);
684 // Methods for ComponetsGetter
686 public FileDownloader
.FileDownloaderBinder
getFileDownloaderBinder() {
687 return mDownloaderBinder
;
692 public FileUploader
.FileUploaderBinder
getFileUploaderBinder() {
693 return mUploaderBinder
;
697 public OperationsService
.OperationsServiceBinder
getOperationsServiceBinder() {
702 public FileDataStorageManager
getStorageManager() {
707 public FileOperationsHelper
getFileOperationsHelper() {
711 protected ServiceConnection
newTransferenceServiceConnection() {
712 return new PreferencesServiceConnection();
715 /** Defines callbacks for service binding, passed to bindService() */
716 private class PreferencesServiceConnection
implements ServiceConnection
{
719 public void onServiceConnected(ComponentName component
, IBinder service
) {
721 if (component
.equals(new ComponentName(Preferences
.this, FileDownloader
.class))) {
722 mDownloaderBinder
= (FileDownloader
.FileDownloaderBinder
) service
;
724 } else if (component
.equals(new ComponentName(Preferences
.this, FileUploader
.class))) {
725 Log_OC
.d(TAG
, "Upload service connected");
726 mUploaderBinder
= (FileUploader
.FileUploaderBinder
) service
;
734 public void onServiceDisconnected(ComponentName component
) {
735 if (component
.equals(new ComponentName(Preferences
.this, FileDownloader
.class))) {
736 Log_OC
.d(TAG
, "Download service suddenly disconnected");
737 mDownloaderBinder
= null
;
738 } else if (component
.equals(new ComponentName(Preferences
.this, FileUploader
.class))) {
739 Log_OC
.d(TAG
, "Upload service suddenly disconnected");
740 mUploaderBinder
= null
;