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
.support
.v4
.app
.Fragment
;
28 import android
.view
.LayoutInflater
;
29 import android
.view
.View
;
30 import android
.view
.ViewGroup
;
31 import android
.view
.View
.OnClickListener
;
32 import android
.widget
.ImageView
;
33 import android
.widget
.TextView
;
34 import android
.widget
.Toast
;
35 import android
.widget
.VideoView
;
36 import eu
.alefzero
.owncloud
.DisplayUtils
;
37 import eu
.alefzero
.owncloud
.FileDownloader
;
38 import eu
.alefzero
.owncloud
.R
;
39 import eu
.alefzero
.owncloud
.db
.ProviderMeta
.ProviderTableMeta
;
42 * This Fragment is used to display the details about a file.
43 * @author Bartek Przybylski
46 public class FileDetail
extends Fragment
implements OnClickListener
{
48 private Intent mIntent
;
51 public void setStuff(Intent intent
) {
56 private void setStuff(View view
) {
58 String id
= mIntent
.getStringExtra("FILE_ID");
59 Account account
= mIntent
.getParcelableExtra("ACCOUNT");
60 String account_name
= account
.name
;
61 Cursor c
= getActivity().managedQuery(
62 Uri
.withAppendedPath(ProviderTableMeta
.CONTENT_URI_FILE
, id
),
64 ProviderTableMeta
.FILE_ACCOUNT_OWNER
+"=?",
65 new String
[]{account_name
},
69 // retrive details from DB
70 String filename
= c
.getString(c
.getColumnIndex(ProviderTableMeta
.FILE_NAME
));
71 String mimetype
= c
.getString(c
.getColumnIndex(ProviderTableMeta
.FILE_CONTENT_TYPE
));
72 String path
= c
.getString(c
.getColumnIndex(ProviderTableMeta
.FILE_STORAGE_PATH
));
73 long filesize
= c
.getLong(c
.getColumnIndex(ProviderTableMeta
.FILE_CONTENT_LENGTH
));
76 setFilename(filename
);
77 setFiletype(DisplayUtils
.convertMIMEtoPrettyPrint(mimetype
));
78 setFilesize(filesize
);
80 // set file preview if available and possible
81 View w
= view
.findViewById(R
.id
.videoView1
);
82 w
.setVisibility(View
.INVISIBLE
);
84 ImageView v
= (ImageView
) getView().findViewById(R
.id
.imageView2
);
85 v
.setImageResource(R
.drawable
.download
);
86 v
.setOnClickListener(this);
88 if (mimetype
.startsWith("image/")) {
89 ImageView v
= (ImageView
) view
.findViewById(R
.id
.imageView2
);
90 Bitmap bmp
= BitmapFactory
.decodeFile(path
);
91 v
.setImageBitmap(bmp
);
92 } else if (mimetype
.startsWith("video/")) {
93 VideoView v
= (VideoView
) view
.findViewById(R
.id
.videoView1
);
94 v
.setVisibility(View
.VISIBLE
);
102 public View
onCreateView(LayoutInflater inflater
, ViewGroup container
,
103 Bundle savedInstanceState
) {
104 View v
= inflater
.inflate(R
.layout
.file_details
, container
, false
);
106 if (getActivity().getIntent() != null
) {
107 mIntent
= getActivity().getIntent();
114 public View
getView() {
115 return mView
== null ?
super.getView() : mView
;
118 public void setFilename(String filename
) {
119 TextView tv
= (TextView
) getView().findViewById(R
.id
.textView1
);
120 if (tv
!= null
) tv
.setText(filename
);
123 public void setFiletype(String mimetype
) {
124 TextView tv
= (TextView
) getView().findViewById(R
.id
.textView2
);
125 if (tv
!= null
) tv
.setText(mimetype
);
128 public void setFilesize(long filesize
) {
129 TextView tv
= (TextView
) getView().findViewById(R
.id
.textView3
);
130 if (tv
!= null
) tv
.setText(DisplayUtils
.bitsToHumanReadable(filesize
));
134 public void onClick(View v
) {
135 Toast
.makeText(getActivity(), "Downloading", Toast
.LENGTH_LONG
).show();
136 Intent i
= new Intent(getActivity(), FileDownloader
.class);
137 i
.putExtra(FileDownloader
.EXTRA_ACCOUNT
, mIntent
.getParcelableExtra("ACCOUNT"));
138 i
.putExtra(FileDownloader
.EXTRA_FILE_PATH
, mIntent
.getStringExtra("FULL_PATH"));
139 getActivity().startService(i
);