1 /* ownCloud Android client application
2 * Copyright (C) 2011 Bartek Przybylski
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.
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 eu
.alefzero
.owncloud
.ui
.fragment
;
20 import android
.accounts
.Account
;
21 import android
.content
.BroadcastReceiver
;
22 import android
.content
.Context
;
23 import android
.content
.Intent
;
24 import android
.content
.IntentFilter
;
25 import android
.database
.Cursor
;
26 import android
.graphics
.Bitmap
;
27 import android
.graphics
.BitmapFactory
;
28 import android
.net
.Uri
;
29 import android
.os
.Bundle
;
30 import android
.view
.LayoutInflater
;
31 import android
.view
.View
;
32 import android
.view
.View
.OnClickListener
;
33 import android
.view
.ViewGroup
;
34 import android
.widget
.ImageView
;
35 import android
.widget
.TextView
;
36 import android
.widget
.Toast
;
37 import android
.widget
.VideoView
;
39 import com
.actionbarsherlock
.app
.SherlockFragment
;
41 import eu
.alefzero
.owncloud
.DisplayUtils
;
42 import eu
.alefzero
.owncloud
.FileDownloader
;
43 import eu
.alefzero
.owncloud
.R
;
44 import eu
.alefzero
.owncloud
.db
.ProviderMeta
.ProviderTableMeta
;
47 * This Fragment is used to display the details about a file.
48 * @author Bartek Przybylski
51 public class FileDetailFragment
extends SherlockFragment
implements OnClickListener
{
53 private Intent mIntent
;
55 private DownloadFinishReceiver dfr
;
58 public void onResume() {
60 dfr
= new DownloadFinishReceiver();
61 IntentFilter filter
= new IntentFilter(FileDownloader
.DOWNLOAD_FINISH_MESSAGE
);
62 getActivity().registerReceiver(dfr
, filter
);
66 public void onPause() {
68 getActivity().unregisterReceiver(dfr
);
72 public void setStuff(Intent intent
) {
77 private void setStuff(View view
) {
79 String id
= mIntent
.getStringExtra("FILE_ID");
80 Account account
= mIntent
.getParcelableExtra("ACCOUNT");
81 String account_name
= account
.name
;
82 Cursor c
= getActivity().managedQuery(
83 Uri
.withAppendedPath(ProviderTableMeta
.CONTENT_URI_FILE
, id
),
85 ProviderTableMeta
.FILE_ACCOUNT_OWNER
+"=?",
86 new String
[]{account_name
},
90 // Retrieve details from DB
91 String filename
= c
.getString(c
.getColumnIndex(ProviderTableMeta
.FILE_NAME
));
92 String mimetype
= c
.getString(c
.getColumnIndex(ProviderTableMeta
.FILE_CONTENT_TYPE
));
93 String path
= c
.getString(c
.getColumnIndex(ProviderTableMeta
.FILE_STORAGE_PATH
));
94 long filesize
= c
.getLong(c
.getColumnIndex(ProviderTableMeta
.FILE_CONTENT_LENGTH
));
97 setFilename(filename
);
98 setFiletype(DisplayUtils
.convertMIMEtoPrettyPrint(mimetype
));
99 setFilesize(filesize
);
101 // set file preview if available and possible
102 View w
= view
.findViewById(R
.id
.videoView1
);
103 w
.setVisibility(View
.INVISIBLE
);
105 ImageView v
= (ImageView
) getView().findViewById(R
.id
.imageView2
);
106 v
.setImageResource(R
.drawable
.download
);
107 v
.setOnClickListener(this);
109 if (mimetype
.startsWith("image/")) {
110 ImageView v
= (ImageView
) view
.findViewById(R
.id
.imageView2
);
111 Bitmap bmp
= BitmapFactory
.decodeFile(path
);
112 v
.setImageBitmap(bmp
);
113 } else if (mimetype
.startsWith("video/")) {
114 VideoView v
= (VideoView
) view
.findViewById(R
.id
.videoView1
);
115 v
.setVisibility(View
.VISIBLE
);
116 v
.setVideoPath(path
);
123 public View
onCreateView(LayoutInflater inflater
, ViewGroup container
,
124 Bundle savedInstanceState
) {
127 if (getActivity().getIntent() != null
&& getActivity().getIntent().getStringExtra("FILE_ID") != null
) {
128 v
= inflater
.inflate(R
.layout
.file_details_fragment
, container
, false
);
129 mIntent
= getActivity().getIntent();
132 v
= inflater
.inflate(R
.layout
.file_details_empty
, container
, false
);
138 public View
getView() {
139 return mView
== null ?
super.getView() : mView
;
142 public void setFilename(String filename
) {
143 TextView tv
= (TextView
) getView().findViewById(R
.id
.textView1
);
144 if (tv
!= null
) tv
.setText(filename
);
147 public void setFiletype(String mimetype
) {
148 TextView tv
= (TextView
) getView().findViewById(R
.id
.textView2
);
149 if (tv
!= null
) tv
.setText(mimetype
);
152 public void setFilesize(long filesize
) {
153 TextView tv
= (TextView
) getView().findViewById(R
.id
.textView3
);
154 if (tv
!= null
) tv
.setText(DisplayUtils
.bitsToHumanReadable(filesize
));
158 public void onClick(View v
) {
159 Toast
.makeText(getActivity(), "Downloading", Toast
.LENGTH_LONG
).show();
160 Intent i
= new Intent(getActivity(), FileDownloader
.class);
161 i
.putExtra(FileDownloader
.EXTRA_ACCOUNT
, mIntent
.getParcelableExtra("ACCOUNT"));
162 i
.putExtra(FileDownloader
.EXTRA_FILE_PATH
, mIntent
.getStringExtra("FULL_PATH"));
163 getActivity().startService(i
);
166 private class DownloadFinishReceiver
extends BroadcastReceiver
{
168 public void onReceive(Context context
, Intent intent
) {