737c00f28eeabda70f4428b8e7743ce8a140e1b4
[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
36 /**
37 * This activity displays the details of a file like its name, its size and so
38 * on.
39 *
40 * @author Bartek Przybylski
41 *
42 */
43 public class FileDetailActivity extends SherlockFragmentActivity {
44
45 private boolean mConfigurationChangedToLandscape = false;
46
47 @Override
48 protected void onCreate(Bundle savedInstanceState) {
49 super.onCreate(savedInstanceState);
50
51 // check if configuration changed to large-land ; for a tablet being changed from portrait to landscape when in FileDetailActivity
52 Configuration conf = getResources().getConfiguration();
53 mConfigurationChangedToLandscape = (conf.orientation == Configuration.ORIENTATION_LANDSCAPE &&
54 (conf.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE
55 );
56
57 if (!mConfigurationChangedToLandscape) {
58 setContentView(R.layout.file_activity_details);
59
60 ActionBar actionBar = getSupportActionBar();
61 actionBar.setDisplayHomeAsUpEnabled(true);
62
63 OCFile file = getIntent().getParcelableExtra(FileDetailFragment.EXTRA_FILE);
64 Account account = getIntent().getParcelableExtra(FileDownloader.EXTRA_ACCOUNT);
65 FileDetailFragment mFileDetail = new FileDetailFragment(file, account);
66
67 FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
68 ft.replace(R.id.fragment, mFileDetail, FileDetailFragment.FTAG);
69 ft.commit();
70
71 } else {
72 backToDisplayActivity(); // the 'back' won't be effective until this.onStart() and this.onResume() are completed;
73 }
74
75
76 }
77
78 @Override
79 public boolean onOptionsItemSelected(MenuItem item) {
80 boolean returnValue = false;
81
82 switch(item.getItemId()){
83 case android.R.id.home:
84 backToDisplayActivity();
85 returnValue = true;
86 }
87
88 return returnValue;
89 }
90
91
92
93 @Override
94 protected void onResume() {
95
96 super.onResume();
97 if (!mConfigurationChangedToLandscape) {
98 FileDetailFragment fragment = (FileDetailFragment) getSupportFragmentManager().findFragmentByTag(FileDetailFragment.FTAG);
99 fragment.updateFileDetails();
100 }
101 }
102
103
104 private void backToDisplayActivity() {
105 Intent intent = new Intent(this, FileDisplayActivity.class);
106 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
107 intent.putExtra(FileDetailFragment.EXTRA_FILE, getIntent().getParcelableExtra(FileDetailFragment.EXTRA_FILE));
108 startActivity(intent);
109 finish();
110 }
111
112 }