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
.R
;
47 * This activity displays the details of a file like its name, its size and so
50 * @author Bartek Przybylski
53 public class FileDetailActivity
extends SherlockFragmentActivity
implements FileDetailFragment
.ContainerActivity
{
55 public static final int DIALOG_SHORT_WAIT
= 0;
57 public static final String TAG
= FileDetailActivity
.class.getSimpleName();
59 private boolean mConfigurationChangedToLandscape
= false
;
60 private FileDownloaderBinder mDownloaderBinder
= null
;
61 private ServiceConnection mDownloadConnection
, mUploadConnection
= null
;
62 private FileUploaderBinder mUploaderBinder
= null
;
66 protected void onCreate(Bundle savedInstanceState
) {
67 super.onCreate(savedInstanceState
);
69 // check if configuration changed to large-land ; for a tablet being changed from portrait to landscape when in FileDetailActivity
70 Configuration conf
= getResources().getConfiguration();
71 mConfigurationChangedToLandscape
= (conf
.orientation
== Configuration
.ORIENTATION_LANDSCAPE
&&
72 (conf
.screenLayout
& Configuration
.SCREENLAYOUT_SIZE_MASK
) >= Configuration
.SCREENLAYOUT_SIZE_LARGE
75 if (!mConfigurationChangedToLandscape
) {
76 mDownloadConnection
= new DetailsServiceConnection();
77 bindService(new Intent(this, FileDownloader
.class), mDownloadConnection
, Context
.BIND_AUTO_CREATE
);
78 mUploadConnection
= new DetailsServiceConnection();
79 bindService(new Intent(this, FileUploader
.class), mUploadConnection
, Context
.BIND_AUTO_CREATE
);
81 setContentView(R
.layout
.file_activity_details
);
83 ActionBar actionBar
= getSupportActionBar();
84 actionBar
.setDisplayHomeAsUpEnabled(true
);
86 OCFile file
= getIntent().getParcelableExtra(FileDetailFragment
.EXTRA_FILE
);
87 Account account
= getIntent().getParcelableExtra(FileDetailFragment
.EXTRA_ACCOUNT
);
88 FileDetailFragment mFileDetail
= new FileDetailFragment(file
, account
);
90 FragmentTransaction ft
= getSupportFragmentManager().beginTransaction();
91 ft
.replace(R
.id
.fragment
, mFileDetail
, FileDetailFragment
.FTAG
);
95 backToDisplayActivity(); // the 'back' won't be effective until this.onStart() and this.onResume() are completed;
102 /** Defines callbacks for service binding, passed to bindService() */
103 private class DetailsServiceConnection
implements ServiceConnection
{
106 public void onServiceConnected(ComponentName component
, IBinder service
) {
107 if (component
.equals(new ComponentName(FileDetailActivity
.this, FileDownloader
.class))) {
108 Log
.d(TAG
, "Download service connected");
109 mDownloaderBinder
= (FileDownloaderBinder
) service
;
110 } else if (component
.equals(new ComponentName(FileDetailActivity
.this, FileUploader
.class))) {
111 Log
.d(TAG
, "Upload service connected");
112 mUploaderBinder
= (FileUploaderBinder
) service
;
116 FileDetailFragment fragment
= (FileDetailFragment
) getSupportFragmentManager().findFragmentByTag(FileDetailFragment
.FTAG
);
117 if (fragment
!= null
)
118 fragment
.updateFileDetails(false
); // let the fragment gets the mDownloadBinder through getDownloadBinder() (see FileDetailFragment#updateFileDetais())
122 public void onServiceDisconnected(ComponentName component
) {
123 if (component
.equals(new ComponentName(FileDetailActivity
.this, FileDownloader
.class))) {
124 Log
.d(TAG
, "Download service disconnected");
125 mDownloaderBinder
= null
;
126 } else if (component
.equals(new ComponentName(FileDetailActivity
.this, FileUploader
.class))) {
127 Log
.d(TAG
, "Upload service disconnected");
128 mUploaderBinder
= null
;
135 public void onDestroy() {
137 if (mDownloadConnection
!= null
) {
138 unbindService(mDownloadConnection
);
139 mDownloadConnection
= null
;
141 if (mUploadConnection
!= null
) {
142 unbindService(mUploadConnection
);
143 mUploadConnection
= null
;
149 public boolean onOptionsItemSelected(MenuItem item
) {
150 boolean returnValue
= false
;
152 switch(item
.getItemId()){
153 case android
.R
.id
.home
:
154 backToDisplayActivity();
158 returnValue
= super.onOptionsItemSelected(item
);
167 protected void onResume() {
170 if (!mConfigurationChangedToLandscape
) {
171 FileDetailFragment fragment
= (FileDetailFragment
) getSupportFragmentManager().findFragmentByTag(FileDetailFragment
.FTAG
);
172 fragment
.updateFileDetails(false
);
177 private void backToDisplayActivity() {
178 Intent intent
= new Intent(this, FileDisplayActivity
.class);
179 intent
.addFlags(Intent
.FLAG_ACTIVITY_CLEAR_TOP
);
180 intent
.putExtra(FileDetailFragment
.EXTRA_FILE
, getIntent().getParcelableExtra(FileDetailFragment
.EXTRA_FILE
));
181 intent
.putExtra(FileDetailFragment
.EXTRA_ACCOUNT
, getIntent().getParcelableExtra(FileDetailFragment
.EXTRA_ACCOUNT
));
182 startActivity(intent
);
188 protected Dialog
onCreateDialog(int id
) {
189 Dialog dialog
= null
;
191 case DIALOG_SHORT_WAIT
: {
192 ProgressDialog working_dialog
= new ProgressDialog(this);
193 working_dialog
.setMessage(getResources().getString(
194 R
.string
.wait_a_moment
));
195 working_dialog
.setIndeterminate(true
);
196 working_dialog
.setCancelable(false
);
197 dialog
= working_dialog
;
211 public void onFileStateChanged() {
212 // nothing to do here!
220 public FileDownloaderBinder
getFileDownloaderBinder() {
221 return mDownloaderBinder
;
226 public FileUploaderBinder
getFileUploaderBinder() {
227 return mUploaderBinder
;