e481cdbefea93efe1653e55e454651b2aad55cdf
[pub/Android/ownCloud.git] / src / eu / alefzero / owncloud / ui / activity / FileDetailActivity.java
1 /* ownCloud Android client application
2 * Copyright (C) 2011 Bartek Przybylski
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
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.
13 *
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/>.
16 *
17 */
18 package eu.alefzero.owncloud.ui.activity;
19
20 import android.accounts.Account;
21 import android.content.Intent;
22 import android.content.res.Configuration;
23 import android.os.Bundle;
24 import android.support.v4.app.FragmentTransaction;
25 import android.util.Log;
26
27 import com.actionbarsherlock.app.ActionBar;
28 import com.actionbarsherlock.app.SherlockFragmentActivity;
29 import com.actionbarsherlock.view.MenuItem;
30
31 import eu.alefzero.owncloud.R;
32 import eu.alefzero.owncloud.datamodel.OCFile;
33 import eu.alefzero.owncloud.files.services.FileDownloader;
34 import eu.alefzero.owncloud.ui.fragment.FileDetailFragment;
35 import eu.alefzero.owncloud.ui.fragment.FileListFragment;
36
37 /**
38 * This activity displays the details of a file like its name, its size and so
39 * on.
40 *
41 * @author Bartek Przybylski
42 *
43 */
44 public class FileDetailActivity extends SherlockFragmentActivity implements FileDetailFragment.ContainerActivity {
45
46 private boolean mConfigurationChangedToLandscape = false;
47
48 @Override
49 protected void onCreate(Bundle savedInstanceState) {
50 super.onCreate(savedInstanceState);
51
52 // check if configuration changed to large-land ; for a tablet being changed from portrait to landscape when in FileDetailActivity
53 Configuration conf = getResources().getConfiguration();
54 mConfigurationChangedToLandscape = (conf.orientation == Configuration.ORIENTATION_LANDSCAPE &&
55 (conf.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE
56 );
57
58 if (!mConfigurationChangedToLandscape) {
59 setContentView(R.layout.file_activity_details);
60
61 ActionBar actionBar = getSupportActionBar();
62 actionBar.setDisplayHomeAsUpEnabled(true);
63
64 OCFile file = getIntent().getParcelableExtra(FileDetailFragment.EXTRA_FILE);
65 Account account = getIntent().getParcelableExtra(FileDownloader.EXTRA_ACCOUNT);
66 FileDetailFragment mFileDetail = new FileDetailFragment(file, account);
67
68 FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
69 ft.replace(R.id.fragment, mFileDetail, FileDetailFragment.FTAG);
70 ft.commit();
71
72 } else {
73 backToDisplayActivity(); // the 'back' won't be effective until this.onStart() and this.onResume() are completed;
74 }
75
76
77 }
78
79 @Override
80 public boolean onOptionsItemSelected(MenuItem item) {
81 boolean returnValue = false;
82
83 switch(item.getItemId()){
84 case android.R.id.home:
85 backToDisplayActivity();
86 returnValue = true;
87 }
88
89 return returnValue;
90 }
91
92
93
94 @Override
95 protected void onResume() {
96
97 super.onResume();
98 if (!mConfigurationChangedToLandscape) {
99 FileDetailFragment fragment = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
100 fragment.updateFileDetails();
101 }
102 }
103
104
105 private void backToDisplayActivity() {
106 Intent intent = new Intent(this, FileDisplayActivity.class);
107 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
108 intent.putExtra(FileDetailFragment.EXTRA_FILE, getIntent().getParcelableExtra(FileDetailFragment.EXTRA_FILE));
109 startActivity(intent);
110 finish();
111 }
112
113 /**
114 * {@inheritDoc}
115 */
116 @Override
117 public void onFileStateChanged() {
118 // nothing to do here!
119 }
120
121
122 }