From: tobiasKaminsky Date: Mon, 15 Sep 2014 07:41:54 +0000 (+0200) Subject: Beginning gridView X-Git-Tag: oc-android-1.7.0_signed~16^2~38 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/4f1b50795c85bd70c44f8419a095d375d17952ca?ds=inline Beginning gridView --- diff --git a/owncloud-android-library b/owncloud-android-library deleted file mode 160000 index 79d58663..00000000 --- a/owncloud-android-library +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 79d586637ee306fdbefbbc4439eb3b058f6877c9 diff --git a/project.properties b/project.properties index 28edd993..c149c453 100644 --- a/project.properties +++ b/project.properties @@ -10,4 +10,4 @@ # Project target. target=android-19 android.library.reference.1=actionbarsherlock/library -android.library.reference.2=owncloud-android-library +android.library.reference.2=../android-library/android-library diff --git a/res/layout/image_item.xml b/res/layout/image_item.xml new file mode 100644 index 00000000..bd9f8d71 --- /dev/null +++ b/res/layout/image_item.xml @@ -0,0 +1,119 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/res/layout/list_fragment.xml b/res/layout/list_fragment.xml index 4236d070..24dbb49a 100644 --- a/res/layout/list_fragment.xml +++ b/res/layout/list_fragment.xml @@ -1,5 +1,5 @@ - +--> + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="0dp" + android:layout_height="match_parent" + android:layout_weight="1" > - - - - - - + + - + + \ No newline at end of file diff --git a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java b/src/com/owncloud/android/ui/adapter/FileListListAdapter.java index 65a9c83c..c6fc19e4 100644 --- a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java +++ b/src/com/owncloud/android/ui/adapter/FileListListAdapter.java @@ -21,10 +21,14 @@ import java.util.Vector; import android.accounts.Account; import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.media.ThumbnailUtils; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; +import android.widget.GridView; import android.widget.ImageView; import android.widget.ListAdapter; import android.widget.ListView; @@ -38,6 +42,7 @@ import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder; import com.owncloud.android.files.services.FileUploader.FileUploaderBinder; import com.owncloud.android.ui.activity.ComponentsGetter; import com.owncloud.android.utils.DisplayUtils; +import com.owncloud.android.utils.Log_OC; /** @@ -106,16 +111,41 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter { @Override public View getView(int position, View convertView, ViewGroup parent) { + // decide image vs. file view + double count = 0; + + + for (OCFile file : mFiles){ + if (file.isImage()){ + count++; + } + } + + // > 50% Images --> image view + boolean fileView = true; + if ((count / mFiles.size()) >= 0.8){ + fileView = false; + } else { + fileView = true; + } + View view = convertView; - if (view == null) { - LayoutInflater inflator = (LayoutInflater) mContext - .getSystemService(Context.LAYOUT_INFLATER_SERVICE); + LayoutInflater inflator = (LayoutInflater) mContext + .getSystemService(Context.LAYOUT_INFLATER_SERVICE); + if (fileView){ view = inflator.inflate(R.layout.list_item, null); + } else { + view = inflator.inflate(R.layout.image_item, null); + View frame = view.findViewById(R.id.imageItemFrame); + frame.setVisibility(View.GONE); } +// } + view.invalidate(); if (mFiles != null && mFiles.size() > position) { OCFile file = mFiles.get(position); TextView fileName = (TextView) view.findViewById(R.id.Filename); + if (!fileView){fileName.setVisibility(View.GONE);} String name = file.getFileName(); fileName.setText(name); @@ -158,7 +188,7 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter { view.findViewById(R.id.imageView3).setVisibility(View.VISIBLE); } - ListView parentList = (ListView)parent; + GridView parentList = (GridView)parent; if (parentList.getChoiceMode() == ListView.CHOICE_MODE_NONE) { checkBoxV.setVisibility(View.GONE); } else { @@ -170,7 +200,12 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter { checkBoxV.setVisibility(View.VISIBLE); } - fileIcon.setImageResource(DisplayUtils.getResourceId(file.getMimetype(), file.getFileName())); + if (file.isImage() && file.isDown()){ + Bitmap bitmap = BitmapFactory.decodeFile(file.getStoragePath()); + fileIcon.setImageBitmap(ThumbnailUtils.extractThumbnail(bitmap, 100, 100)); + } else { + fileIcon.setImageResource(DisplayUtils.getResourceId(file.getMimetype(), file.getFileName())); + } if (checkIfFileIsSharedWithMe(file)) { sharedWithMeIconV.setVisibility(View.VISIBLE); diff --git a/src/com/owncloud/android/ui/fragment/ExtendedListFragment.java b/src/com/owncloud/android/ui/fragment/ExtendedListFragment.java index abd53d3a..bbf33e57 100644 --- a/src/com/owncloud/android/ui/fragment/ExtendedListFragment.java +++ b/src/com/owncloud/android/ui/fragment/ExtendedListFragment.java @@ -27,6 +27,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; +import android.widget.GridView; import android.widget.ListAdapter; import android.widget.ListView; import android.widget.TextView; @@ -65,25 +66,45 @@ implements OnItemClickListener, SwipeRefreshLayout.OnRefreshListener { private SwipeRefreshLayout.OnRefreshListener mOnRefreshListener = null; + private GridView imageView; + private View fileView; + public void setListAdapter(ListAdapter listAdapter) { - mList.setAdapter(listAdapter); - mList.invalidate(); + imageView.setAdapter(listAdapter); + imageView.invalidate(); } public ListView getListView() { return mList; } + protected void switchImageView(){ + // TODO berechnen, wieviele Spalten + imageView.setNumColumns(3); + mList.invalidate(); + imageView.invalidate(); + } + + protected void switchFileView(){ + imageView.setNumColumns(1); + mList.invalidate(); + imageView.invalidate(); + } + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Log_OC.e(TAG, "onCreateView"); View v = inflater.inflate(R.layout.list_fragment, null); - mEmptyListMessage = (TextView) v.findViewById(R.id.empty_list_view); + + imageView = (GridView) v.findViewById(R.id.grid_list_view); + imageView.setOnItemClickListener(this); + + // mEmptyListMessage = (TextView) v.findViewById(R.id.empty_list_view); mList = (ExtendedListView)(v.findViewById(R.id.list_root)); - mList.setOnItemClickListener(this); + // mList.setOnItemClickListener(this); mList.setDivider(getResources().getDrawable(R.drawable.uploader_list_separator)); mList.setDividerHeight(1); diff --git a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java index c11e864e..209c60a2 100644 --- a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java @@ -18,6 +18,7 @@ package com.owncloud.android.ui.fragment; import java.io.File; +import java.util.Vector; import android.app.Activity; import android.content.Intent; @@ -383,6 +384,25 @@ public class OCFileListFragment extends ExtendedListFragment { mList.setSelectionFromTop(0, 0); } mFile = directory; + + // decide image vs. file view + double count = 0; + + Vector files = storageManager.getFolderContent(directory); + for (OCFile file : files){ + if (file.isImage()){ + count++; + } + } + + // > 50% Images --> image view + if ((count / files.size()) >= 0.5){ + Log_OC.i(TAG, "Image View"); + switchImageView(); + } else { + Log_OC.i(TAG, "Folder View"); + switchFileView(); + } } }