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
.Intent
;
22 import android
.database
.Cursor
;
23 import android
.graphics
.Bitmap
;
24 import android
.graphics
.BitmapFactory
;
25 import android
.net
.Uri
;
26 import android
.os
.Bundle
;
27 import android
.view
.LayoutInflater
;
28 import android
.view
.View
;
29 import android
.view
.View
.OnClickListener
;
30 import android
.view
.ViewGroup
;
31 import android
.widget
.ImageView
;
32 import android
.widget
.TextView
;
33 import android
.widget
.Toast
;
34 import android
.widget
.VideoView
;
36 import com
.actionbarsherlock
.app
.SherlockFragment
;
38 import eu
.alefzero
.owncloud
.DisplayUtils
;
39 import eu
.alefzero
.owncloud
.FileDownloader
;
40 import eu
.alefzero
.owncloud
.R
;
41 import eu
.alefzero
.owncloud
.db
.ProviderMeta
.ProviderTableMeta
;
44 * This Fragment is used to display the details about a file.
45 * @author Bartek Przybylski
48 public class FileDetail
extends SherlockFragment
implements OnClickListener
{
50 private Intent mIntent
;
53 public void setStuff(Intent intent
) {
58 private void setStuff(View view
) {
60 String id
= mIntent
.getStringExtra("FILE_ID");
61 Account account
= mIntent
.getParcelableExtra("ACCOUNT");
62 String account_name
= account
.name
;
63 Cursor c
= getActivity().managedQuery(
64 Uri
.withAppendedPath(ProviderTableMeta
.CONTENT_URI_FILE
, id
),
66 ProviderTableMeta
.FILE_ACCOUNT_OWNER
+"=?",
67 new String
[]{account_name
},
71 // Retrieve details from DB
72 String filename
= c
.getString(c
.getColumnIndex(ProviderTableMeta
.FILE_NAME
));
73 String mimetype
= c
.getString(c
.getColumnIndex(ProviderTableMeta
.FILE_CONTENT_TYPE
));
74 String path
= c
.getString(c
.getColumnIndex(ProviderTableMeta
.FILE_STORAGE_PATH
));
75 long filesize
= c
.getLong(c
.getColumnIndex(ProviderTableMeta
.FILE_CONTENT_LENGTH
));
78 setFilename(filename
);
79 setFiletype(DisplayUtils
.convertMIMEtoPrettyPrint(mimetype
));
80 setFilesize(filesize
);
82 // set file preview if available and possible
83 View w
= view
.findViewById(R
.id
.videoView1
);
84 w
.setVisibility(View
.INVISIBLE
);
86 ImageView v
= (ImageView
) getView().findViewById(R
.id
.imageView2
);
87 v
.setImageResource(R
.drawable
.download
);
88 v
.setOnClickListener(this);
90 if (mimetype
.startsWith("image/")) {
91 ImageView v
= (ImageView
) view
.findViewById(R
.id
.imageView2
);
92 Bitmap bmp
= BitmapFactory
.decodeFile(path
);
93 v
.setImageBitmap(bmp
);
94 } else if (mimetype
.startsWith("video/")) {
95 VideoView v
= (VideoView
) view
.findViewById(R
.id
.videoView1
);
96 v
.setVisibility(View
.VISIBLE
);
104 public View
onCreateView(LayoutInflater inflater
, ViewGroup container
,
105 Bundle savedInstanceState
) {
108 if (getActivity().getIntent() != null
&& getActivity().getIntent().getStringExtra("FILE_ID") != null
) {
109 v
= inflater
.inflate(R
.layout
.file_details
, container
, false
);
110 mIntent
= getActivity().getIntent();
113 v
= inflater
.inflate(R
.layout
.file_details_empty
, container
, false
);
119 public View
getView() {
120 return mView
== null ?
super.getView() : mView
;
123 public void setFilename(String filename
) {
124 TextView tv
= (TextView
) getView().findViewById(R
.id
.textView1
);
125 if (tv
!= null
) tv
.setText(filename
);
128 public void setFiletype(String mimetype
) {
129 TextView tv
= (TextView
) getView().findViewById(R
.id
.textView2
);
130 if (tv
!= null
) tv
.setText(mimetype
);
133 public void setFilesize(long filesize
) {
134 TextView tv
= (TextView
) getView().findViewById(R
.id
.textView3
);
135 if (tv
!= null
) tv
.setText(DisplayUtils
.bitsToHumanReadable(filesize
));
139 public void onClick(View v
) {
140 Toast
.makeText(getActivity(), "Downloading", Toast
.LENGTH_LONG
).show();
141 Intent i
= new Intent(getActivity(), FileDownloader
.class);
142 i
.putExtra(FileDownloader
.EXTRA_ACCOUNT
, mIntent
.getParcelableExtra("ACCOUNT"));
143 i
.putExtra(FileDownloader
.EXTRA_FILE_PATH
, mIntent
.getStringExtra("FULL_PATH"));
144 getActivity().startService(i
);