diff options
author | daniel oeh <daniel.oeh@gmail.com> | 2012-08-11 15:45:30 +0200 |
---|---|---|
committer | daniel oeh <daniel.oeh@gmail.com> | 2012-08-11 15:45:30 +0200 |
commit | 522d61577b1c8eedf07d7690cee04e447cec51ed (patch) | |
tree | df76ab2ea62857309fa6e244a86c5002fab16424 /src | |
parent | 168d48cd02f14af2a860183785ba4df947910e84 (diff) | |
download | AntennaPod-522d61577b1c8eedf07d7690cee04e447cec51ed.zip |
Implemented GridView in FeedlistFragment
Diffstat (limited to 'src')
4 files changed, 73 insertions, 41 deletions
diff --git a/src/de/danoeh/antennapod/PodcastApp.java b/src/de/danoeh/antennapod/PodcastApp.java index cf9271f8c..9d37bbc56 100644 --- a/src/de/danoeh/antennapod/PodcastApp.java +++ b/src/de/danoeh/antennapod/PodcastApp.java @@ -9,6 +9,7 @@ import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.content.res.Configuration; import android.preference.PreferenceManager; import android.util.Log; import de.danoeh.antennapod.activity.OpmlImportActivity; @@ -113,4 +114,9 @@ public class PodcastApp extends Application implements public static float getLogicalDensity() { return LOGICAL_DENSITY; } + + public boolean isLargeScreen() { + return (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE || (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE; + + } } diff --git a/src/de/danoeh/antennapod/adapter/FeedlistAdapter.java b/src/de/danoeh/antennapod/adapter/FeedlistAdapter.java index 6f72d9e70..ba1ce2864 100644 --- a/src/de/danoeh/antennapod/adapter/FeedlistAdapter.java +++ b/src/de/danoeh/antennapod/adapter/FeedlistAdapter.java @@ -7,6 +7,7 @@ import java.util.List; import de.danoeh.antennapod.asynctask.FeedImageLoader; import de.danoeh.antennapod.feed.Feed; import de.danoeh.antennapod.storage.DownloadRequester; +import de.danoeh.antennapod.PodcastApp; import de.danoeh.antennapod.R; import android.content.Context; import android.net.Uri; @@ -93,9 +94,11 @@ public class FeedlistAdapter extends ArrayAdapter<Feed> { holder.newEpisodes.setVisibility(View.INVISIBLE); } holder.image.setTag(feed.getImage()); - imageLoader.loadThumbnailBitmap(feed.getImage(), holder.image); - - // TODO find new Episodes txtvNewEpisodes.setText(feed) + if (PodcastApp.getInstance().isLargeScreen()) { + imageLoader.loadCoverBitmap(feed.getImage(), holder.image); + } else { + imageLoader.loadThumbnailBitmap(feed.getImage(), holder.image); + } return convertView; } diff --git a/src/de/danoeh/antennapod/asynctask/BitmapDecodeWorkerTask.java b/src/de/danoeh/antennapod/asynctask/BitmapDecodeWorkerTask.java index 10d4d716e..5e99c52af 100644 --- a/src/de/danoeh/antennapod/asynctask/BitmapDecodeWorkerTask.java +++ b/src/de/danoeh/antennapod/asynctask/BitmapDecodeWorkerTask.java @@ -39,7 +39,7 @@ public abstract class BitmapDecodeWorkerTask extends Thread { this.target = target; this.fileUrl = fileUrl; this.baseLength = length; - this.PREFERRED_LENGTH = (int) (length * PodcastApp.getLogicalDensity()); + this.PREFERRED_LENGTH = (int) (length * PodcastApp.getLogicalDensity() + 0.5f); } /** diff --git a/src/de/danoeh/antennapod/fragment/FeedlistFragment.java b/src/de/danoeh/antennapod/fragment/FeedlistFragment.java index d83671a82..68611b242 100644 --- a/src/de/danoeh/antennapod/fragment/FeedlistFragment.java +++ b/src/de/danoeh/antennapod/fragment/FeedlistFragment.java @@ -22,7 +22,11 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.widget.AdapterView; import android.widget.AdapterView.OnItemLongClickListener; +import android.widget.GridView; import android.widget.ListView; +import android.widget.TextView; + +import com.actionbarsherlock.app.SherlockFragment; import com.actionbarsherlock.app.SherlockListFragment; import com.actionbarsherlock.app.SherlockFragmentActivity; import com.actionbarsherlock.view.ActionMode; @@ -31,8 +35,9 @@ import com.actionbarsherlock.view.MenuInflater; import com.actionbarsherlock.view.MenuItem; import android.util.Log; -public class FeedlistFragment extends SherlockListFragment implements - ActionMode.Callback { +public class FeedlistFragment extends SherlockFragment implements + ActionMode.Callback, AdapterView.OnItemClickListener, + AdapterView.OnItemLongClickListener { private static final String TAG = "FeedlistFragment"; public static final String EXTRA_SELECTED_FEED = "extra.de.danoeh.antennapod.activity.selected_feed"; @@ -43,6 +48,10 @@ public class FeedlistFragment extends SherlockListFragment implements private Feed selectedFeed; private ActionMode mActionMode; + private GridView gridView; + private ListView listView; + private TextView txtvEmpty; + @Override public void onAttach(Activity activity) { super.onAttach(activity); @@ -62,49 +71,44 @@ public class FeedlistFragment extends SherlockListFragment implements Log.d(TAG, "Creating"); manager = FeedManager.getInstance(); fla = new FeedlistAdapter(pActivity, 0, manager.getFeeds()); - setListAdapter(fla); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - return inflater.inflate(R.layout.feedlist, container, false); + View result = inflater.inflate(R.layout.feedlist, container, false); + listView = (ListView) result.findViewById(android.R.id.list); + gridView = (GridView) result.findViewById(R.id.grid); + txtvEmpty = (TextView) result.findViewById(android.R.id.empty); + + return result; } @Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); - getListView().setOnItemLongClickListener(new OnItemLongClickListener() { - - @Override - public boolean onItemLongClick(AdapterView<?> parent, View view, - int position, long id) { - Feed selection = fla.getItem(position); - if (AppConfig.DEBUG) - Log.d(TAG, - "Selected Feed with title " + selection.getTitle()); - if (selection != null) { - if (mActionMode != null) { - mActionMode.finish(); - } - fla.setSelectedItemIndex(position); - selectedFeed = selection; - mActionMode = getSherlockActivity().startActionMode( - FeedlistFragment.this); - - } - return true; - } - - }); + if (listView != null) { + listView.setOnItemClickListener(this); + listView.setOnItemLongClickListener(this); + listView.setAdapter(fla); + listView.setEmptyView(txtvEmpty); + if (AppConfig.DEBUG) Log.d(TAG, "Using ListView"); + } else { + gridView.setOnItemClickListener(this); + gridView.setOnItemLongClickListener(this); + gridView.setAdapter(fla); + gridView.setEmptyView(txtvEmpty); + if (AppConfig.DEBUG) Log.d(TAG, "Using GridView"); + } } @Override public void onResume() { super.onResume(); - if (AppConfig.DEBUG) Log.d(TAG, "Resuming"); + if (AppConfig.DEBUG) + Log.d(TAG, "Resuming"); IntentFilter filter = new IntentFilter(); filter.addAction(DownloadRequester.ACTION_DOWNLOAD_QUEUED); filter.addAction(FeedManager.ACTION_UNREAD_ITEMS_UPDATE); @@ -140,15 +144,6 @@ public class FeedlistFragment extends SherlockListFragment implements }; @Override - public void onListItemClick(ListView l, View v, int position, long id) { - Feed selection = fla.getItem(position); - Intent showFeed = new Intent(pActivity, FeedItemlistActivity.class); - showFeed.putExtra(EXTRA_SELECTED_FEED, selection.getId()); - - pActivity.startActivity(showFeed); - } - - @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { FeedMenuHandler.onCreateOptionsMenu(mode.getMenuInflater(), menu); mode.setTitle(selectedFeed.getTitle()); @@ -196,4 +191,32 @@ public class FeedlistFragment extends SherlockListFragment implements fla.setSelectedItemIndex(FeedlistAdapter.SELECTION_NONE); } + @Override + public void onItemClick(AdapterView<?> arg0, View arg1, int position, + long id) { + Feed selection = fla.getItem(position); + Intent showFeed = new Intent(pActivity, FeedItemlistActivity.class); + showFeed.putExtra(EXTRA_SELECTED_FEED, selection.getId()); + + pActivity.startActivity(showFeed); + } + + @Override + public boolean onItemLongClick(AdapterView<?> parent, View view, + int position, long id) { + Feed selection = fla.getItem(position); + if (AppConfig.DEBUG) + Log.d(TAG, "Selected Feed with title " + selection.getTitle()); + if (selection != null) { + if (mActionMode != null) { + mActionMode.finish(); + } + fla.setSelectedItemIndex(position); + selectedFeed = selection; + mActionMode = getSherlockActivity().startActionMode( + FeedlistFragment.this); + + } + return true; + } } |