Changed references to drawables in src to references to attr

This commit is contained in:
daniel oeh 2012-11-20 20:00:29 +01:00
parent e01a656e9e
commit c1d24edb5f
9 changed files with 66 additions and 23 deletions

View File

@ -7,6 +7,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.ServiceConnection; import android.content.ServiceConnection;
import android.content.res.TypedArray;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.os.IBinder; import android.os.IBinder;
@ -185,7 +186,8 @@ public class DownloadActivity extends SherlockListActivity implements
switch (item.getItemId()) { switch (item.getItemId()) {
case android.R.id.home: case android.R.id.home:
Intent intent = new Intent(this, MainActivity.class); Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent); startActivity(intent);
break; break;
case MENU_SHOW_LOG: case MENU_SHOW_LOG:
@ -201,9 +203,10 @@ public class DownloadActivity extends SherlockListActivity implements
@Override @Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) { public boolean onCreateActionMode(ActionMode mode, Menu menu) {
if (!selectedDownload.isDone()) { if (!selectedDownload.isDone()) {
TypedArray drawables = obtainStyledAttributes(new int[] { R.attr.navigation_cancel });
menu.add(Menu.NONE, R.id.cancel_download_item, Menu.NONE, menu.add(Menu.NONE, R.id.cancel_download_item, Menu.NONE,
R.string.cancel_download_label).setIcon( R.string.cancel_download_label).setIcon(
R.drawable.navigation_cancel); drawables.getDrawable(0));
} }
return true; return true;
} }

View File

@ -3,6 +3,7 @@ package de.danoeh.antennapod.activity;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.res.TypedArray;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction; import android.support.v4.app.FragmentTransaction;
@ -76,8 +77,9 @@ public class FeedItemlistActivity extends SherlockFragmentActivity {
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
TypedArray drawables = obtainStyledAttributes(new int[] { R.attr.action_search });
menu.add(Menu.NONE, R.id.search_item, Menu.NONE, R.string.search_label) menu.add(Menu.NONE, R.id.search_item, Menu.NONE, R.string.search_label)
.setIcon(R.drawable.action_search) .setIcon(drawables.getDrawable(0))
.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); .setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
return FeedMenuHandler return FeedMenuHandler
.onCreateOptionsMenu(new MenuInflater(this), menu); .onCreateOptionsMenu(new MenuInflater(this), menu);
@ -110,7 +112,8 @@ public class FeedItemlistActivity extends SherlockFragmentActivity {
R.string.feed_delete_confirmation_msg) { R.string.feed_delete_confirmation_msg) {
@Override @Override
public void onConfirmButtonPressed(DialogInterface dialog) { public void onConfirmButtonPressed(
DialogInterface dialog) {
dialog.dismiss(); dialog.dismiss();
remover.executeAsync(); remover.executeAsync();
} }
@ -129,7 +132,8 @@ public class FeedItemlistActivity extends SherlockFragmentActivity {
} }
} catch (DownloadRequestException e) { } catch (DownloadRequestException e) {
e.printStackTrace(); e.printStackTrace();
DownloadRequestErrorDialogCreator.newRequestErrorDialog(this, e.getMessage()); DownloadRequestErrorDialogCreator.newRequestErrorDialog(this,
e.getMessage());
} }
return true; return true;
} }

View File

@ -128,7 +128,10 @@ public class MiroGuideMainActivity extends SherlockListActivity {
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
menu.add(Menu.NONE, R.id.search_item, Menu.NONE, R.string.search_label) menu.add(Menu.NONE, R.id.search_item, Menu.NONE, R.string.search_label)
.setIcon(R.drawable.action_search) .setIcon(
obtainStyledAttributes(
new int[] { R.attr.action_search })
.getDrawable(0))
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
return true; return true;
} }

View File

@ -62,7 +62,10 @@ public class MiroGuideSearchActivity extends SherlockFragmentActivity {
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
menu.add(Menu.NONE, R.id.search_item, Menu.NONE, R.string.search_label) menu.add(Menu.NONE, R.id.search_item, Menu.NONE, R.string.search_label)
.setIcon(R.drawable.action_search) .setIcon(
obtainStyledAttributes(
new int[] { R.attr.action_search })
.getDrawable(0))
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
return true; return true;

View File

@ -79,7 +79,10 @@ public class SearchActivity extends SherlockListActivity {
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
menu.add(Menu.NONE, R.id.search_item, Menu.NONE, R.string.search_label) menu.add(Menu.NONE, R.id.search_item, Menu.NONE, R.string.search_label)
.setIcon(R.drawable.action_search) .setIcon(
obtainStyledAttributes(
new int[] { R.attr.action_search })
.getDrawable(0))
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
return true; return true;
} }

View File

@ -4,6 +4,7 @@ import java.text.DateFormat;
import java.util.List; import java.util.List;
import android.content.Context; import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.text.format.DateUtils; import android.text.format.DateUtils;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -160,12 +161,14 @@ public class FeedItemlistAdapter extends ArrayAdapter<FeedItem> {
holder.downloading.setVisibility(View.GONE); holder.downloading.setVisibility(View.GONE);
} }
TypedArray typeDrawables = getContext().obtainStyledAttributes(
new int[] { R.attr.type_audio, R.attr.type_video });
MediaType mediaType = item.getMedia().getMediaType(); MediaType mediaType = item.getMedia().getMediaType();
if (mediaType == MediaType.AUDIO) { if (mediaType == MediaType.AUDIO) {
holder.type.setImageResource(R.drawable.type_audio); holder.type.setImageDrawable(typeDrawables.getDrawable(0));
holder.type.setVisibility(View.VISIBLE); holder.type.setVisibility(View.VISIBLE);
} else if (mediaType == MediaType.VIDEO) { } else if (mediaType == MediaType.VIDEO) {
holder.type.setImageResource(R.drawable.type_video); holder.type.setImageDrawable(typeDrawables.getDrawable(1));
holder.type.setVisibility(View.VISIBLE); holder.type.setVisibility(View.VISIBLE);
} else { } else {
holder.type.setImageBitmap(null); holder.type.setImageBitmap(null);

View File

@ -2,6 +2,7 @@ package de.danoeh.antennapod.asynctask;
import java.io.File; import java.io.File;
import android.content.res.TypedArray;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.os.Handler; import android.os.Handler;
import android.util.Log; import android.util.Log;
@ -25,6 +26,8 @@ public abstract class BitmapDecodeWorkerTask extends Thread {
private Handler handler; private Handler handler;
private final int defaultCoverResource;
public BitmapDecodeWorkerTask(Handler handler, ImageView target, public BitmapDecodeWorkerTask(Handler handler, ImageView target,
String fileUrl, int length, int imageType) { String fileUrl, int length, int imageType) {
super(); super();
@ -33,6 +36,9 @@ public abstract class BitmapDecodeWorkerTask extends Thread {
this.fileUrl = fileUrl; this.fileUrl = fileUrl;
this.PREFERRED_LENGTH = length; this.PREFERRED_LENGTH = length;
this.imageType = imageType; this.imageType = imageType;
TypedArray res = target.getContext().obtainStyledAttributes(new int[] {R.attr.default_cover});
this.defaultCoverResource = res.getResourceId(0, 0);
res.recycle();
} }
/** /**
@ -64,7 +70,7 @@ public abstract class BitmapDecodeWorkerTask extends Thread {
} else { } else {
Log.w(TAG, "Could not load bitmap. Using default image."); Log.w(TAG, "Could not load bitmap. Using default image.");
cBitmap = new CachedBitmap(BitmapFactory.decodeResource(target.getResources(), cBitmap = new CachedBitmap(BitmapFactory.decodeResource(target.getResources(),
R.drawable.default_cover), PREFERRED_LENGTH); defaultCoverResource), PREFERRED_LENGTH);
} }
if (AppConfig.DEBUG) if (AppConfig.DEBUG)
Log.d(TAG, "Finished loading bitmaps"); Log.d(TAG, "Finished loading bitmaps");
@ -93,7 +99,7 @@ public abstract class BitmapDecodeWorkerTask extends Thread {
protected void onInvalidFileUrl() { protected void onInvalidFileUrl() {
Log.e(TAG, "FeedImage has no valid file url. Using default image"); Log.e(TAG, "FeedImage has no valid file url. Using default image");
cBitmap = new CachedBitmap(BitmapFactory.decodeResource(target.getResources(), cBitmap = new CachedBitmap(BitmapFactory.decodeResource(target.getResources(),
R.drawable.default_cover), PREFERRED_LENGTH); defaultCoverResource), PREFERRED_LENGTH);
} }
protected void storeBitmapInCache(CachedBitmap cb) { protected void storeBitmapInCache(CachedBitmap cb) {

View File

@ -7,6 +7,7 @@ import java.util.concurrent.ThreadFactory;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.ActivityManager; import android.app.ActivityManager;
import android.content.Context; import android.content.Context;
import android.content.res.TypedArray;
import android.os.Handler; import android.os.Handler;
import android.support.v4.util.LruCache; import android.support.v4.util.LruCache;
import android.util.Log; import android.util.Log;
@ -102,18 +103,20 @@ public class FeedImageLoader {
* posted to the ImageView's message queue. * posted to the ImageView's message queue.
*/ */
public void loadCoverBitmap(FeedImage image, ImageView target, int length) { public void loadCoverBitmap(FeedImage image, ImageView target, int length) {
final int defaultCoverResource = getDefaultCoverResource(target.getContext());
if (image != null && image.getFile_url() != null) { if (image != null && image.getFile_url() != null) {
CachedBitmap cBitmap = getBitmapFromCoverCache(image.getFile_url()); CachedBitmap cBitmap = getBitmapFromCoverCache(image.getFile_url());
if (cBitmap != null && cBitmap.getLength() >= length) { if (cBitmap != null && cBitmap.getLength() >= length) {
target.setImageBitmap(cBitmap.getBitmap()); target.setImageBitmap(cBitmap.getBitmap());
} else { } else {
target.setImageResource(R.drawable.default_cover); target.setImageResource(defaultCoverResource);
FeedImageDecodeWorkerTask worker = new FeedImageDecodeWorkerTask( FeedImageDecodeWorkerTask worker = new FeedImageDecodeWorkerTask(
handler, target, image, length, IMAGE_TYPE_COVER); handler, target, image, length, IMAGE_TYPE_COVER);
executor.submit(worker); executor.submit(worker);
} }
} else { } else {
target.setImageResource(R.drawable.default_cover); target.setImageResource(defaultCoverResource);
} }
} }
@ -135,18 +138,20 @@ public class FeedImageLoader {
*/ */
public void loadThumbnailBitmap(FeedImage image, ImageView target, public void loadThumbnailBitmap(FeedImage image, ImageView target,
int length) { int length) {
final int defaultCoverResource = getDefaultCoverResource(target.getContext());
if (image != null && image.getFile_url() != null) { if (image != null && image.getFile_url() != null) {
CachedBitmap cBitmap = getBitmapFromThumbnailCache(image.getFile_url()); CachedBitmap cBitmap = getBitmapFromThumbnailCache(image.getFile_url());
if (cBitmap != null && cBitmap.getLength() >= length) { if (cBitmap != null && cBitmap.getLength() >= length) {
target.setImageBitmap(cBitmap.getBitmap()); target.setImageBitmap(cBitmap.getBitmap());
} else { } else {
target.setImageResource(R.drawable.default_cover); target.setImageResource(defaultCoverResource);
FeedImageDecodeWorkerTask worker = new FeedImageDecodeWorkerTask( FeedImageDecodeWorkerTask worker = new FeedImageDecodeWorkerTask(
handler, target, image, length, IMAGE_TYPE_THUMBNAIL); handler, target, image, length, IMAGE_TYPE_THUMBNAIL);
executor.submit(worker); executor.submit(worker);
} }
} else { } else {
target.setImageResource(R.drawable.default_cover); target.setImageResource(defaultCoverResource);
} }
} }
@ -187,6 +192,13 @@ public class FeedImageLoader {
coverCache.put(key, bitmap); coverCache.put(key, bitmap);
} }
private int getDefaultCoverResource(Context context) {
TypedArray res = context.obtainStyledAttributes(new int[] {R.attr.default_cover});
final int defaultCoverResource = res.getResourceId(0, 0);
res.recycle();
return defaultCoverResource;
}
class FeedImageDecodeWorkerTask extends BitmapDecodeWorkerTask { class FeedImageDecodeWorkerTask extends BitmapDecodeWorkerTask {
private static final String TAG = "FeedImageDecodeWorkerTask"; private static final String TAG = "FeedImageDecodeWorkerTask";

View File

@ -15,6 +15,7 @@ import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.ServiceConnection; import android.content.ServiceConnection;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.TypedArray;
import android.os.IBinder; import android.os.IBinder;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.util.Log; import android.util.Log;
@ -354,6 +355,11 @@ public abstract class PlaybackController {
* should be used to update the GUI or start/cancel background threads. * should be used to update the GUI or start/cancel background threads.
*/ */
private void handleStatus() { private void handleStatus() {
TypedArray res = activity.obtainStyledAttributes(new int[] {R.attr.av_play, R.attr.av_pause});
final int playResource = res.getResourceId(0, R.drawable.av_play);
final int pauseResource = res.getResourceId(1, R.drawable.av_pause);
res.recycle();
switch (status) { switch (status) {
case ERROR: case ERROR:
@ -363,22 +369,22 @@ public abstract class PlaybackController {
clearStatusMsg(); clearStatusMsg();
checkMediaInfoLoaded(); checkMediaInfoLoaded();
cancelPositionObserver(); cancelPositionObserver();
updatePlayButtonAppearance(R.drawable.av_play); updatePlayButtonAppearance(playResource);
break; break;
case PLAYING: case PLAYING:
clearStatusMsg(); clearStatusMsg();
checkMediaInfoLoaded(); checkMediaInfoLoaded();
setupPositionObserver(); setupPositionObserver();
updatePlayButtonAppearance(R.drawable.av_pause); updatePlayButtonAppearance(pauseResource);
break; break;
case PREPARING: case PREPARING:
postStatusMsg(R.string.player_preparing_msg); postStatusMsg(R.string.player_preparing_msg);
checkMediaInfoLoaded(); checkMediaInfoLoaded();
if (playbackService != null) { if (playbackService != null) {
if (playbackService.isStartWhenPrepared()) { if (playbackService.isStartWhenPrepared()) {
updatePlayButtonAppearance(R.drawable.av_pause); updatePlayButtonAppearance(pauseResource);
} else { } else {
updatePlayButtonAppearance(R.drawable.av_play); updatePlayButtonAppearance(playResource);
} }
} }
break; break;
@ -388,7 +394,7 @@ public abstract class PlaybackController {
case PREPARED: case PREPARED:
checkMediaInfoLoaded(); checkMediaInfoLoaded();
postStatusMsg(R.string.player_ready_msg); postStatusMsg(R.string.player_ready_msg);
updatePlayButtonAppearance(R.drawable.av_play); updatePlayButtonAppearance(playResource);
break; break;
case SEEKING: case SEEKING:
postStatusMsg(R.string.player_seeking_msg); postStatusMsg(R.string.player_seeking_msg);
@ -399,7 +405,7 @@ public abstract class PlaybackController {
case INITIALIZED: case INITIALIZED:
checkMediaInfoLoaded(); checkMediaInfoLoaded();
clearStatusMsg(); clearStatusMsg();
updatePlayButtonAppearance(R.drawable.av_play); updatePlayButtonAppearance(playResource);
break; break;
} }
} }