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 as published by
7 * the Free Software Foundation, either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 package com
.owncloud
.android
.ui
.activity
;
21 import android
.accounts
.Account
;
22 import android
.app
.Dialog
;
23 import android
.app
.ProgressDialog
;
24 import android
.content
.ComponentName
;
25 import android
.content
.Context
;
26 import android
.content
.Intent
;
27 import android
.content
.ServiceConnection
;
28 import android
.content
.res
.Configuration
;
29 import android
.os
.Bundle
;
30 import android
.os
.IBinder
;
31 import android
.support
.v4
.app
.FragmentTransaction
;
32 import android
.util
.Log
;
34 import com
.actionbarsherlock
.app
.ActionBar
;
35 import com
.actionbarsherlock
.app
.SherlockFragmentActivity
;
36 import com
.actionbarsherlock
.view
.MenuItem
;
37 import com
.owncloud
.android
.datamodel
.OCFile
;
38 import com
.owncloud
.android
.files
.services
.FileDownloader
;
39 import com
.owncloud
.android
.files
.services
.FileDownloader
.FileDownloaderBinder
;
40 import com
.owncloud
.android
.files
.services
.FileUploader
;
41 import com
.owncloud
.android
.files
.services
.FileUploader
.FileUploaderBinder
;
42 import com
.owncloud
.android
.ui
.fragment
.FileDetailFragment
;
44 import com
.owncloud
.android
.Log_OC
;
45 import com
.owncloud
.android
.R
;
48 * This activity displays the details of a file like its name, its size and so
51 * @author Bartek Przybylski
54 public class FileDetailActivity
extends SherlockFragmentActivity
implements FileDetailFragment
.ContainerActivity
{
56 public static final int DIALOG_SHORT_WAIT
= 0;
58 public static final String TAG
= FileDetailActivity
.class.getSimpleName();
60 private boolean mConfigurationChangedToLandscape
= false
;
61 private FileDownloaderBinder mDownloaderBinder
= null
;
62 private ServiceConnection mDownloadConnection
, mUploadConnection
= null
;
63 private FileUploaderBinder mUploaderBinder
= null
;
67 protected void onCreate(Bundle savedInstanceState
) {
68 super.onCreate(savedInstanceState
);
70 // check if configuration changed to large-land ; for a tablet being changed from portrait to landscape when in FileDetailActivity
71 Configuration conf
= getResources().getConfiguration();
72 mConfigurationChangedToLandscape
= (conf
.orientation
== Configuration
.ORIENTATION_LANDSCAPE
&&
73 (conf
.screenLayout
& Configuration
.SCREENLAYOUT_SIZE_MASK
) >= Configuration
.SCREENLAYOUT_SIZE_LARGE
76 if (!mConfigurationChangedToLandscape
) {
77 mDownloadConnection
= new DetailsServiceConnection();
78 bindService(new Intent(this, FileDownloader
.class), mDownloadConnection
, Context
.BIND_AUTO_CREATE
);
79 mUploadConnection
= new DetailsServiceConnection();
80 bindService(new Intent(this, FileUploader
.class), mUploadConnection
, Context
.BIND_AUTO_CREATE
);
82 setContentView(R
.layout
.file_activity_details
);
84 ActionBar actionBar
= getSupportActionBar();
85 actionBar
.setDisplayHomeAsUpEnabled(true
);
87 OCFile file
= getIntent().getParcelableExtra(FileDetailFragment
.EXTRA_FILE
);
88 Account account
= getIntent().getParcelableExtra(FileDetailFragment
.EXTRA_ACCOUNT
);
89 FileDetailFragment mFileDetail
= new FileDetailFragment(file
, account
);
91 FragmentTransaction ft
= getSupportFragmentManager().beginTransaction();
92 ft
.replace(R
.id
.fragment
, mFileDetail
, FileDetailFragment
.FTAG
);
96 backToDisplayActivity(); // the 'back' won't be effective until this.onStart() and this.onResume() are completed;
103 /** Defines callbacks for service binding, passed to bindService() */
104 private class DetailsServiceConnection
implements ServiceConnection
{
107 public void onServiceConnected(ComponentName component
, IBinder service
) {
108 if (component
.equals(new ComponentName(FileDetailActivity
.this, FileDownloader
.class))) {
109 Log_OC
.d(TAG
, "Download service connected");
110 mDownloaderBinder
= (FileDownloaderBinder
) service
;
111 } else if (component
.equals(new ComponentName(FileDetailActivity
.this, FileUploader
.class))) {
112 Log_OC
.d(TAG
, "Upload service connected");
113 mUploaderBinder
= (FileUploaderBinder
) service
;
117 FileDetailFragment fragment
= (FileDetailFragment
) getSupportFragmentManager().findFragmentByTag(FileDetailFragment
.FTAG
);
118 if (fragment
!= null
)
119 fragment
.updateFileDetails(false
); // let the fragment gets the mDownloadBinder through getDownloadBinder() (see FileDetailFragment#updateFileDetais())
123 public void onServiceDisconnected(ComponentName component
) {
124 if (component
.equals(new ComponentName(FileDetailActivity
.this, FileDownloader
.class))) {
125 Log_OC
.d(TAG
, "Download service disconnected");
126 mDownloaderBinder
= null
;
127 } else if (component
.equals(new ComponentName(FileDetailActivity
.this, FileUploader
.class))) {
128 Log_OC
.d(TAG
, "Upload service disconnected");
129 mUploaderBinder
= null
;
136 public void onDestroy() {
138 if (mDownloadConnection
!= null
) {
139 unbindService(mDownloadConnection
);
140 mDownloadConnection
= null
;
142 if (mUploadConnection
!= null
) {
143 unbindService(mUploadConnection
);
144 mUploadConnection
= null
;
150 public boolean onOptionsItemSelected(MenuItem item
) {
151 boolean returnValue
= false
;
153 switch(item
.getItemId()){
154 case android
.R
.id
.home
:
155 backToDisplayActivity();
159 returnValue
= super.onOptionsItemSelected(item
);
168 protected void onResume() {
171 if (!mConfigurationChangedToLandscape
) {
172 FileDetailFragment fragment
= (FileDetailFragment
) getSupportFragmentManager().findFragmentByTag(FileDetailFragment
.FTAG
);
173 fragment
.updateFileDetails(false
);
178 private void backToDisplayActivity() {
179 Intent intent
= new Intent(this, FileDisplayActivity
.class);
180 intent
.addFlags(Intent
.FLAG_ACTIVITY_CLEAR_TOP
);
181 intent
.putExtra(FileDetailFragment
.EXTRA_FILE
, getIntent().getParcelableExtra(FileDetailFragment
.EXTRA_FILE
));
182 intent
.putExtra(FileDetailFragment
.EXTRA_ACCOUNT
, getIntent().getParcelableExtra(FileDetailFragment
.EXTRA_ACCOUNT
));
183 startActivity(intent
);
189 protected Dialog
onCreateDialog(int id
) {
190 Dialog dialog
= null
;
192 case DIALOG_SHORT_WAIT
: {
193 ProgressDialog working_dialog
= new ProgressDialog(this);
194 working_dialog
.setMessage(getResources().getString(
195 R
.string
.wait_a_moment
));
196 working_dialog
.setIndeterminate(true
);
197 working_dialog
.setCancelable(false
);
198 dialog
= working_dialog
;
212 public void onFileStateChanged() {
213 // nothing to do here!
221 public FileDownloaderBinder
getFileDownloaderBinder() {
222 return mDownloaderBinder
;
227 public FileUploaderBinder
getFileUploaderBinder() {
228 return mUploaderBinder
;