1 /* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 package org
.libreoffice
.ui
;
12 import android
.app
.Activity
;
13 import android
.content
.ComponentName
;
14 import android
.content
.Context
;
15 import android
.content
.Intent
;
16 import android
.content
.SharedPreferences
;
17 import android
.database
.DataSetObserver
;
18 import android
.net
.Uri
;
19 import android
.os
.AsyncTask
;
20 import android
.os
.Bundle
;
21 import android
.os
.Handler
;
22 import android
.preference
.PreferenceManager
;
23 import android
.support
.v4
.widget
.DrawerLayout
;
24 import android
.support
.v7
.app
.ActionBar
;
25 import android
.support
.v7
.app
.ActionBarDrawerToggle
;
26 import android
.support
.v7
.app
.AppCompatActivity
;
27 import android
.support
.v7
.widget
.Toolbar
;
28 import android
.util
.Log
;
29 import android
.view
.ContextMenu
;
30 import android
.view
.ContextMenu
.ContextMenuInfo
;
31 import android
.view
.LayoutInflater
;
32 import android
.view
.Menu
;
33 import android
.view
.MenuInflater
;
34 import android
.view
.MenuItem
;
35 import android
.view
.View
;
36 import android
.view
.View
.OnClickListener
;
37 import android
.view
.View
.OnLongClickListener
;
38 import android
.view
.ViewGroup
;
39 import android
.widget
.AdapterView
;
40 import android
.widget
.AdapterView
.AdapterContextMenuInfo
;
41 import android
.widget
.AdapterView
.OnItemClickListener
;
42 import android
.widget
.ArrayAdapter
;
43 import android
.widget
.GridView
;
44 import android
.widget
.ImageView
;
45 import android
.widget
.LinearLayout
;
46 import android
.widget
.ListAdapter
;
47 import android
.widget
.ListView
;
48 import android
.widget
.TextView
;
49 import android
.widget
.Toast
;
51 import org
.libreoffice
.LOAbout
;
52 import org
.libreoffice
.LibreOfficeMainActivity
;
53 import org
.libreoffice
.R
;
54 import org
.libreoffice
.SettingsActivity
;
55 import org
.libreoffice
.storage
.DocumentProviderFactory
;
56 import org
.libreoffice
.storage
.DocumentProviderSettingsActivity
;
57 import org
.libreoffice
.storage
.IDocumentProvider
;
58 import org
.libreoffice
.storage
.IFile
;
61 import java
.io
.FileFilter
;
62 import java
.io
.FilenameFilter
;
64 import java
.net
.URISyntaxException
;
65 import java
.text
.SimpleDateFormat
;
66 import java
.util
.Date
;
67 import java
.util
.List
;
69 public class LibreOfficeUIActivity
extends AppCompatActivity
implements ActionBar
.OnNavigationListener
{
70 private String LOGTAG
= LibreOfficeUIActivity
.class.getSimpleName();
71 private SharedPreferences prefs
;
72 private int filterMode
= FileUtilities
.ALL
;
76 FileFilter fileFilter
;
77 FilenameFilter filenameFilter
;
78 private List
<IFile
> filePaths
;
79 private DocumentProviderFactory documentProviderFactory
;
80 private IDocumentProvider documentProvider
;
81 private IFile homeDirectory
;
82 private IFile currentDirectory
;
84 private static final String CURRENT_DIRECTORY_KEY
= "CURRENT_DIRECTORY";
85 private static final String DOC_PROIVDER_KEY
= "CURRENT_DOCUMENT_PROVIDER";
86 private static final String FILTER_MODE_KEY
= "FILTER_MODE";
87 public static final String EXPLORER_VIEW_TYPE_KEY
= "EXPLORER_VIEW_TYPE";
88 public static final String EXPLORER_PREFS_KEY
= "EXPLORER_PREFS";
89 public static final String SORT_MODE_KEY
= "SORT_MODE";
91 public static final int GRID_VIEW
= 0;
92 public static final int LIST_VIEW
= 1;
94 private DrawerLayout drawerLayout
;
95 private ListView drawerList
;
96 private ActionBarDrawerToggle drawerToggle
;
100 private final LOAbout mAbout
;
101 private boolean canQuit
= false;
103 public LibreOfficeUIActivity() {
104 mAbout
= new LOAbout(this, true);
108 public void onCreate(Bundle savedInstanceState
) {
109 super.onCreate(savedInstanceState
);
111 // initialize document provider factory
112 DocumentProviderFactory
.initialize(this);
113 documentProviderFactory
= DocumentProviderFactory
.getInstance();
115 PreferenceManager
.setDefaultValues(this, R
.xml
.documentprovider_preferences
, false);
119 // init UI and populate with contents from the provider
121 switchToDocumentProvider(documentProviderFactory
.getDefaultProvider());
124 public void createUI() {
126 setContentView(R
.layout
.activity_document_browser
);
128 Toolbar toolbar
= (Toolbar
) findViewById(R
.id
.toolbar
);
129 setSupportActionBar(toolbar
);
130 ActionBar actionBar
= getSupportActionBar();
131 actionBar
.setDisplayShowTitleEnabled(false); //This should show current directory if anything
132 actionBar
.setDisplayHomeAsUpEnabled(true);
134 //make the navigation spinner
135 Context context
= actionBar
.getThemedContext();
136 ArrayAdapter
<CharSequence
> list
= ArrayAdapter
.createFromResource(context
, R
.array
.file_view_modes
, android
.R
.layout
.simple_spinner_item
);
137 list
.setDropDownViewResource(android
.R
.layout
.simple_spinner_dropdown_item
);
139 actionBar
.setNavigationMode(ActionBar
.NAVIGATION_MODE_LIST
);
140 actionBar
.setListNavigationCallbacks(list
, this);
142 LinearLayout content
= (LinearLayout
) findViewById(R
.id
.browser_main_content
);
144 if (viewMode
== GRID_VIEW
) {
145 // code to make a grid view
146 getLayoutInflater().inflate(R
.layout
.file_grid
, content
);
147 gv
= (GridView
)findViewById(R
.id
.file_explorer_grid_view
);
148 gv
.setOnItemClickListener(new OnItemClickListener() {
149 public void onItemClick(AdapterView
<?
> parent
, View view
,
150 int position
, long id
) {
154 actionBar
.setSelectedNavigationItem(filterMode
+ 1);//This triggers the listener which modifies the view.
155 registerForContextMenu(gv
);
157 getLayoutInflater().inflate(R
.layout
.file_list
, content
);
158 lv
= (ListView
)findViewById(R
.id
.file_explorer_list_view
);
159 lv
.setClickable(true);
160 actionBar
.setSelectedNavigationItem(filterMode
+ 1);
161 registerForContextMenu(lv
);
166 drawerLayout
= (DrawerLayout
) findViewById(R
.id
.drawer_layout
);
167 drawerList
= (ListView
) findViewById(R
.id
.left_drawer
);
168 drawerToggle
= new ActionBarDrawerToggle(this, drawerLayout
,
169 R
.string
.document_locations
, R
.string
.close_document_locations
) {
172 public void onDrawerOpened(View drawerView
) {
173 super.onDrawerOpened(drawerView
);
174 supportInvalidateOptionsMenu();
175 drawerList
.requestFocus(); // Make keypad navigation easier
179 public void onDrawerClosed(View drawerView
) {
180 super.onDrawerClosed(drawerView
);
181 supportInvalidateOptionsMenu();
184 drawerToggle
.setDrawerIndicatorEnabled(true);
185 drawerLayout
.setDrawerListener(drawerToggle
);
186 drawerToggle
.syncState();
188 // Set the adapter for the list view
189 drawerList
.setAdapter(new ArrayAdapter
<String
>(this,
190 R
.layout
.item_in_drawer
, documentProviderFactory
.getNames()));
191 // Set the list's click listener
192 drawerList
.setOnItemClickListener(new ListView
.OnItemClickListener() {
194 public void onItemClick(AdapterView parent
, View view
,
195 int position
, long id
) {
196 switchToDocumentProvider(documentProviderFactory
197 .getProvider(position
));
203 protected void onPostCreate(Bundle savedInstanceState
) {
204 super.onPostCreate(savedInstanceState
);
206 drawerToggle
.syncState();
209 private void refreshView() {
210 // enable home icon as "up" if required
211 if (!currentDirectory
.equals(homeDirectory
)) {
212 drawerToggle
.setDrawerIndicatorEnabled(false);
214 drawerToggle
.setDrawerIndicatorEnabled(true);
217 FileUtilities
.sortFiles(filePaths
, sortMode
);
219 if (viewMode
== GRID_VIEW
) {
220 gv
.setAdapter(new GridItemAdapter(getApplicationContext(),
221 currentDirectory
, filePaths
));
223 lv
.setAdapter(new ListItemAdapter(getApplicationContext(),
226 // close drawer if it was open
227 drawerLayout
.closeDrawer(drawerList
);
231 public void onBackPressed() {
232 if (drawerLayout
.isDrawerOpen(drawerList
)) {
233 drawerLayout
.closeDrawer(drawerList
);
234 } else if (!currentDirectory
.equals(homeDirectory
)) {
235 // navigate upwards in directory hierarchy
236 openParentDirectory();
238 // only exit if warning has been shown
240 super.onBackPressed();
244 // show warning about leaving the app and set a timer
245 Toast
.makeText(this, R
.string
.back_again_to_quit
,
246 Toast
.LENGTH_SHORT
).show();
248 new Handler().postDelayed(new Runnable() {
258 public void onCreateContextMenu(ContextMenu menu
, View v
,
259 ContextMenuInfo menuInfo
) {
260 super.onCreateContextMenu(menu
, v
, menuInfo
);
261 MenuInflater inflater
= getMenuInflater();
262 inflater
.inflate(R
.menu
.context_menu
, menu
);
266 public boolean onContextItemSelected(MenuItem item
) {
267 AdapterContextMenuInfo info
= (AdapterContextMenuInfo
) item
269 switch (item
.getItemId()) {
270 case R
.id
.context_menu_open
:
273 case R
.id
.context_menu_share
:
274 share(info
.position
);
277 return super.onContextItemSelected(item
);
281 private void switchToDocumentProvider(IDocumentProvider provider
) {
283 new AsyncTask
<IDocumentProvider
, Void
, Void
>() {
285 protected Void
doInBackground(IDocumentProvider
... provider
) {
286 // switch document provider:
287 // these operations may imply network access and must be run in
288 // a different thread
290 documentProvider
= provider
[0];
291 homeDirectory
= documentProvider
.getRootDirectory();
292 currentDirectory
= homeDirectory
;
293 filePaths
= currentDirectory
.listFiles(FileUtilities
294 .getFileFilter(filterMode
));
296 catch (final RuntimeException e
) {
297 final Activity activity
= LibreOfficeUIActivity
.this;
298 activity
.runOnUiThread(new Runnable() {
301 Toast
.makeText(activity
, e
.getMessage(),
302 Toast
.LENGTH_SHORT
).show();
305 Log
.e(LOGTAG
, e
.getMessage(), e
.getCause());
311 protected void onPostExecute(Void result
) {
317 public void openDirectory(IFile dir
) {
321 new AsyncTask
<IFile
, Void
, Void
>() {
323 protected Void
doInBackground(IFile
... dir
) {
324 // get list of files:
325 // this operation may imply network access and must be run in
326 // a different thread
327 currentDirectory
= dir
[0];
329 filePaths
= currentDirectory
.listFiles(FileUtilities
330 .getFileFilter(filterMode
));
332 catch (final RuntimeException e
) {
333 final Activity activity
= LibreOfficeUIActivity
.this;
334 activity
.runOnUiThread(new Runnable() {
337 Toast
.makeText(activity
, e
.getMessage(),
338 Toast
.LENGTH_SHORT
).show();
341 Log
.e(LOGTAG
, e
.getMessage(), e
.getCause());
347 protected void onPostExecute(Void result
) {
353 public void open(final IFile document
) {
354 new AsyncTask
<IFile
, Void
, File
>() {
356 protected File
doInBackground(IFile
... document
) {
357 // this operation may imply network access and must be run in
358 // a different thread
360 return document
[0].getDocument();
362 catch (final RuntimeException e
) {
363 final Activity activity
= LibreOfficeUIActivity
.this;
364 activity
.runOnUiThread(new Runnable() {
367 Toast
.makeText(activity
, e
.getMessage(),
368 Toast
.LENGTH_SHORT
).show();
371 Log
.e(LOGTAG
, e
.getMessage(), e
.getCause());
377 protected void onPostExecute(File file
) {
379 Intent i
= new Intent(Intent
.ACTION_VIEW
, Uri
.fromFile(file
));
380 String packageName
= getApplicationContext().getPackageName();
381 ComponentName componentName
= new ComponentName(packageName
,
382 LibreOfficeMainActivity
.class.getName());
383 i
.setComponent(componentName
);
385 // these extras allow to rebuild the IFile object in LOMainActivity
386 i
.putExtra("org.libreoffice.document_provider_id",
387 documentProvider
.getId());
388 i
.putExtra("org.libreoffice.document_uri",
397 private void open(int position
) {
398 IFile file
= filePaths
.get(position
);
399 if (!file
.isDirectory()) {
406 private void openParentDirectory() {
407 new AsyncTask
<Void
, Void
, IFile
>() {
409 protected IFile
doInBackground(Void
... dir
) {
410 // this operation may imply network access and must be run in
411 // a different thread
412 return currentDirectory
.getParent();
416 protected void onPostExecute(IFile result
) {
417 openDirectory(result
);
422 private void share(int position
) {
424 new AsyncTask
<IFile
, Void
, File
>() {
426 protected File
doInBackground(IFile
... document
) {
427 // this operation may imply network access and must be run in
428 // a different thread
430 return document
[0].getDocument();
431 } catch (final RuntimeException e
) {
432 final Activity activity
= LibreOfficeUIActivity
.this;
433 activity
.runOnUiThread(new Runnable() {
436 Toast
.makeText(activity
, e
.getMessage(),
437 Toast
.LENGTH_SHORT
).show();
440 Log
.e(LOGTAG
, e
.getMessage(), e
.getCause());
446 protected void onPostExecute(File file
) {
448 Intent sharingIntent
= new Intent(android
.content
.Intent
.ACTION_SEND
);
449 Uri uri
= Uri
.fromFile(file
);
450 sharingIntent
.setType(FileUtilities
.getMimeType(file
.getName()));
451 sharingIntent
.putExtra(android
.content
.Intent
.EXTRA_STREAM
, uri
);
452 sharingIntent
.putExtra(android
.content
.Intent
.EXTRA_SUBJECT
,
454 startActivity(Intent
.createChooser(sharingIntent
,
455 getString(R
.string
.share_via
)));
458 }.execute(filePaths
.get(position
));
462 public boolean onCreateOptionsMenu(Menu menu
) {
463 MenuInflater inflater
= getMenuInflater();
464 inflater
.inflate(R
.menu
.view_menu
, menu
);
466 MenuItem item
= menu
.findItem(R
.id
.menu_view_toggle
);
467 if (viewMode
== GRID_VIEW
) {
468 item
.setTitle(R
.string
.list_view
);
469 item
.setIcon(R
.drawable
.light_view_as_list
);
471 item
.setTitle(R
.string
.grid_view
);
472 item
.setIcon(R
.drawable
.light_view_as_grid
);
475 item
= menu
.findItem(R
.id
.menu_sort_size
);
476 if (sortMode
== FileUtilities
.SORT_LARGEST
) {
477 item
.setTitle(R
.string
.sort_smallest
);
479 item
.setTitle(R
.string
.sort_largest
);
482 item
= menu
.findItem(R
.id
.menu_sort_az
);
483 if (sortMode
== FileUtilities
.SORT_AZ
) {
484 item
.setTitle(R
.string
.sort_za
);
486 item
.setTitle(R
.string
.sort_az
);
489 item
= menu
.findItem(R
.id
.menu_sort_modified
);
490 if (sortMode
== FileUtilities
.SORT_NEWEST
) {
491 item
.setTitle(R
.string
.sort_oldest
);
493 item
.setTitle(R
.string
.sort_newest
);
500 public boolean onOptionsItemSelected(MenuItem item
) {
501 // Will close the drawer if the home button is pressed
502 if (drawerToggle
.onOptionsItemSelected(item
)) {
506 switch (item
.getItemId()) {
507 case android
.R
.id
.home
:
508 if (!currentDirectory
.equals(homeDirectory
)){
509 openParentDirectory();
512 case R
.id
.menu_view_toggle
:
513 if (viewMode
== GRID_VIEW
){
514 viewMode
= LIST_VIEW
;
515 item
.setTitle(R
.string
.grid_view
); // Button points to next view.
516 item
.setIcon(R
.drawable
.light_view_as_grid
);
518 viewMode
= GRID_VIEW
;
519 item
.setTitle(R
.string
.list_view
); // Button points to next view.
520 item
.setIcon(R
.drawable
.light_view_as_list
);
524 case R
.id
.menu_sort_size
:
525 case R
.id
.menu_sort_az
:
526 case R
.id
.menu_sort_modified
:
529 case R
.id
.action_about
:
532 case R
.id
.action_settings
:
533 startActivity(new Intent(getApplicationContext(), SettingsActivity
.class));
535 case R
.id
.menu_storage_preferences
:
536 startActivity(new Intent(this, DocumentProviderSettingsActivity
.class));
540 return super.onOptionsItemSelected(item
);
545 public void sortFiles(MenuItem item
){
546 switch (item
.getItemId()) {
547 case R
.id
.menu_sort_az
:
548 if (sortMode
== FileUtilities
.SORT_AZ
){
549 sortMode
= FileUtilities
.SORT_ZA
;
550 item
.setTitle(R
.string
.sort_az
);
552 sortMode
= FileUtilities
.SORT_AZ
;
553 item
.setTitle(R
.string
.sort_za
);
556 case R
.id
.menu_sort_modified
:
557 if (sortMode
== FileUtilities
.SORT_NEWEST
){
558 sortMode
= FileUtilities
.SORT_OLDEST
;
559 item
.setTitle(R
.string
.sort_newest
);
561 sortMode
= FileUtilities
.SORT_NEWEST
;
562 item
.setTitle(R
.string
.sort_oldest
);
565 case R
.id
.menu_sort_size
:
566 if (sortMode
== FileUtilities
.SORT_LARGEST
){
567 sortMode
= FileUtilities
.SORT_SMALLEST
;
568 item
.setTitle(R
.string
.sort_largest
);
570 sortMode
= FileUtilities
.SORT_LARGEST
;
571 item
.setTitle(R
.string
.sort_smallest
);
580 public void readPreferences(){
581 prefs
= getSharedPreferences(EXPLORER_PREFS_KEY
, MODE_PRIVATE
);
582 viewMode
= prefs
.getInt(EXPLORER_VIEW_TYPE_KEY
, GRID_VIEW
);
583 sortMode
= prefs
.getInt(SORT_MODE_KEY
, FileUtilities
.SORT_AZ
);
584 SharedPreferences defaultPrefs
= PreferenceManager
.getDefaultSharedPreferences(getBaseContext());
585 filterMode
= Integer
.valueOf(defaultPrefs
.getString(FILTER_MODE_KEY
, "-1"));
587 Intent i
= this.getIntent();
588 if (i
.hasExtra(CURRENT_DIRECTORY_KEY
)) {
590 currentDirectory
= documentProvider
.createFromUri(new URI(
591 i
.getStringExtra(CURRENT_DIRECTORY_KEY
)));
592 } catch (URISyntaxException e
) {
593 currentDirectory
= documentProvider
.getRootDirectory();
595 Log
.d(LOGTAG
, CURRENT_DIRECTORY_KEY
);
598 if (i
.hasExtra(FILTER_MODE_KEY
)) {
599 filterMode
= i
.getIntExtra( FILTER_MODE_KEY
, FileUtilities
.ALL
);
600 Log
.d(LOGTAG
, FILTER_MODE_KEY
);
603 if (i
.hasExtra(EXPLORER_VIEW_TYPE_KEY
)) {
604 viewMode
= i
.getIntExtra( EXPLORER_VIEW_TYPE_KEY
, GRID_VIEW
);
605 Log
.d(LOGTAG
, EXPLORER_VIEW_TYPE_KEY
);
610 protected void onSaveInstanceState(Bundle outState
) {
611 // TODO Auto-generated method stub
612 super.onSaveInstanceState(outState
);
613 outState
.putString(CURRENT_DIRECTORY_KEY
, currentDirectory
.getUri().toString());
614 outState
.putInt(FILTER_MODE_KEY
, filterMode
);
615 outState
.putInt(EXPLORER_VIEW_TYPE_KEY
, viewMode
);
616 outState
.putInt(DOC_PROIVDER_KEY
, documentProvider
.getId());
618 Log
.d(LOGTAG
, currentDirectory
.toString() + Integer
.toString(filterMode
) + Integer
.toString(viewMode
));
619 //prefs.edit().putInt(EXPLORER_VIEW_TYPE, viewType).commit();
620 Log
.d(LOGTAG
, "savedInstanceState");
624 protected void onRestoreInstanceState(Bundle savedInstanceState
) {
625 // TODO Auto-generated method stub
626 super.onRestoreInstanceState(savedInstanceState
);
627 if (savedInstanceState
.isEmpty()){
630 if (documentProvider
== null) {
631 Log
.d(LOGTAG
, "onRestoreInstanceState - documentProvider is null");
632 documentProvider
= DocumentProviderFactory
.getInstance()
633 .getProvider(savedInstanceState
.getInt(DOC_PROIVDER_KEY
));
636 currentDirectory
= documentProvider
.createFromUri(new URI(
637 savedInstanceState
.getString(CURRENT_DIRECTORY_KEY
)));
638 } catch (URISyntaxException e
) {
639 currentDirectory
= documentProvider
.getRootDirectory();
641 filterMode
= savedInstanceState
.getInt(FILTER_MODE_KEY
, FileUtilities
.ALL
);
642 viewMode
= savedInstanceState
.getInt(EXPLORER_VIEW_TYPE_KEY
, GRID_VIEW
);
643 //openDirectory(currentDirectory);
644 Log
.d(LOGTAG
, "onRestoreInstanceState");
645 Log
.d(LOGTAG
, currentDirectory
.toString() + Integer
.toString(filterMode
) + Integer
.toString(viewMode
));
649 protected void onPause() {
650 //prefs.edit().putInt(EXPLORER_VIEW_TYPE, viewType).commit();
652 Log
.d(LOGTAG
, "onPause");
656 protected void onResume() {
658 Log
.d(LOGTAG
, "onResume");
659 Log
.d(LOGTAG
, "sortMode="+ sortMode
+ " filterMode=" + filterMode
);
664 protected void onStart() {
666 Log
.d(LOGTAG
, "onStart");
670 protected void onStop() {
672 Log
.d(LOGTAG
, "onStop");
676 protected void onDestroy() {
678 Log
.d(LOGTAG
, "onDestroy");
681 public boolean onNavigationItemSelected(int itemPosition
, long itemId
) {
682 filterMode
= itemPosition
-1; //bit of a hack, I know. -1 is ALL 0 Docs etc
683 openDirectory(currentDirectory
);// Uses filter mode
687 private int dpToPx(int dp
){
688 final float scale
= getApplicationContext().getResources().getDisplayMetrics().density
;
689 return (int) (dp
* scale
+ 0.5f
);
692 class ListItemAdapter
implements ListAdapter
{
693 private Context mContext
;
694 private List
<IFile
> filePaths
;
695 private final long KB
= 1024;
696 private final long MB
= 1048576;
698 public ListItemAdapter(Context mContext
, List
<IFile
> filePaths
) {
699 this.mContext
= mContext
;
700 this.filePaths
= filePaths
;
703 public int getCount() {
704 return filePaths
!= null ? filePaths
.size() : 0;
707 public Object
getItem(int arg0
) {
711 public long getItemId(int arg0
) {
715 public int getItemViewType(int arg0
) {
719 public View
getView(int position
, View convertView
, ViewGroup parent
) {
720 LayoutInflater inflater
= (LayoutInflater
) mContext
.getSystemService(
721 Context
.LAYOUT_INFLATER_SERVICE
);
725 if (convertView
== null) {
726 listItem
= new View(mContext
);
727 listItem
= inflater
.inflate(R
.layout
.file_list_item
, null);
729 listItem
= convertView
;
731 final int pos
= position
;
732 listItem
.setClickable(true);
733 listItem
.setOnClickListener(new OnClickListener() {
735 public void onClick(View v
) {
739 listItem
.setOnLongClickListener(new OnLongClickListener() {
742 public boolean onLongClick(View v
) {
743 // workaround to show the context menu:
744 // prevent onClickListener from getting this event
752 // set value into textview
753 TextView filename
= (TextView
) listItem
.findViewById(R
.id
.file_list_item_name
);
754 filename
.setText(filePaths
.get(position
).getName());
755 //filename.setClickable(true);
757 TextView fileSize
= (TextView
) listItem
.findViewById(R
.id
.file_list_item_size
);
758 //TODO Give size in KB , MB as appropriate.
760 long length
= filePaths
.get(position
).getSize();
762 size
= Long
.toString(length
) + "B";
764 if (length
>= KB
&& length
< MB
){
765 size
= Long
.toString(length
/KB
) + "KB";
768 size
= Long
.toString(length
/MB
) + "MB";
770 fileSize
.setText(size
);
771 //fileSize.setClickable(true);
773 TextView fileDate
= (TextView
) listItem
.findViewById(R
.id
.file_list_item_date
);
774 SimpleDateFormat df
= new SimpleDateFormat("dd MMM yyyy hh:ss");
775 Date date
= filePaths
.get(position
).getLastModified();
777 fileDate
.setText(df
.format(date
));
779 // set image based on selected text
780 ImageView imageView
= (ImageView
) listItem
.findViewById(R
.id
.file_list_item_icon
);
781 switch (FileUtilities
.getType(filePaths
.get(position
).getName()))
783 case FileUtilities
.DOC
:
784 imageView
.setImageResource(R
.drawable
.writer
);
786 case FileUtilities
.CALC
:
787 imageView
.setImageResource(R
.drawable
.calc
);
789 case FileUtilities
.DRAWING
:
790 imageView
.setImageResource(R
.drawable
.draw
);
792 case FileUtilities
.IMPRESS
:
793 imageView
.setImageResource(R
.drawable
.impress
);
798 if (filePaths
.get(position
).isDirectory()) {
799 //Eventually have thumbnails of each sub file on a black circle
800 //For now just a folder icon
801 imageView
.setImageResource(R
.drawable
.folder
);
803 //imageView.setClickable(true);
807 public int getViewTypeCount() {
811 public boolean hasStableIds() {
815 public boolean isEmpty() {
819 public void registerDataSetObserver(DataSetObserver arg0
) {
823 public void unregisterDataSetObserver(DataSetObserver arg0
) {
827 public boolean areAllItemsEnabled() {
831 public boolean isEnabled(int position
) {
838 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */