mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-09-18 21:50:56 +00:00
Override actionbar views for custom icon control.
This commit is contained in:
parent
a2807aa8cd
commit
ad55782686
8 changed files with 55 additions and 40 deletions
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent" >
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/actionbar_icon"
|
||||
android:layout_width="25dp"
|
||||
android:layout_height="25dp"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginRight="4dp"
|
||||
android:src="@drawable/world" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/actionbar_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_toRightOf="@id/actionbar_icon"
|
||||
android:textSize="18sp" />
|
||||
|
||||
</RelativeLayout>
|
|
@ -33,8 +33,7 @@ public class FeedItemsList extends ItemsList {
|
|||
|
||||
super.onCreate(bundle);
|
||||
|
||||
setTitle(feed.title);
|
||||
UIUtils.setActionBarImage(this, feed.faviconUrl);
|
||||
UIUtils.setCustomActionBar(this, feed.faviconUrl, feed.title);
|
||||
|
||||
itemListFragment = (FeedItemListFragment) fragmentManager.findFragmentByTag(FeedItemListFragment.class.getName());
|
||||
if (itemListFragment == null) {
|
||||
|
|
|
@ -20,8 +20,7 @@ public class FeedReading extends Reading {
|
|||
|
||||
Classifier classifier = FeedUtils.dbHelper.getClassifierForFeed(feed.feedId);
|
||||
|
||||
setTitle(feed.title);
|
||||
UIUtils.setActionBarImage(this, feed.faviconUrl);
|
||||
UIUtils.setCustomActionBar(this, feed.faviconUrl, feed.title);
|
||||
|
||||
readingAdapter = new FeedReadingAdapter(fragmentManager, feed, classifier, defaultFeedView);
|
||||
|
||||
|
|
|
@ -54,14 +54,11 @@ public abstract class ItemsList extends NbActivity implements StateChangedListen
|
|||
currentState = (StateFilter) getIntent().getSerializableExtra(EXTRA_STATE);
|
||||
this.fs = createFeedSet();
|
||||
|
||||
requestWindowFeature(Window.FEATURE_PROGRESS);
|
||||
getWindow().setBackgroundDrawableResource(android.R.color.transparent);
|
||||
|
||||
setContentView(R.layout.activity_itemslist);
|
||||
fragmentManager = getFragmentManager();
|
||||
|
||||
getActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
this.overlayStatusText = (TextView) findViewById(R.id.itemlist_sync_status);
|
||||
}
|
||||
|
||||
|
|
|
@ -137,8 +137,6 @@ public abstract class Reading extends NbActivity implements OnPageChangeListener
|
|||
defaultFeedView = (DefaultFeedView) getIntent().getSerializableExtra(EXTRA_DEFAULT_FEED_VIEW);
|
||||
}
|
||||
|
||||
getActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
// this value is expensive to compute but doesn't change during a single runtime
|
||||
this.overlayRangeTopPx = (float) UIUtils.convertDPsToPixels(this, OVERLAY_RANGE_TOP_DP);
|
||||
this.overlayRangeBotPx = (float) UIUtils.convertDPsToPixels(this, OVERLAY_RANGE_BOT_DP);
|
||||
|
|
|
@ -32,8 +32,7 @@ public class SocialFeedItemsList extends ItemsList {
|
|||
socialFeed = (SocialFeed) getIntent().getSerializableExtra(EXTRA_SOCIAL_FEED);
|
||||
super.onCreate(bundle);
|
||||
|
||||
setTitle(socialFeed.feedTitle);
|
||||
UIUtils.setActionBarImage(this, socialFeed.photoUrl);
|
||||
UIUtils.setCustomActionBar(this, socialFeed.photoUrl, socialFeed.feedTitle);
|
||||
|
||||
if (itemListFragment == null) {
|
||||
itemListFragment = SocialFeedItemListFragment.newInstance(socialFeed, currentState, getDefaultFeedView());
|
||||
|
|
|
@ -16,8 +16,7 @@ public class SocialFeedReading extends Reading {
|
|||
|
||||
socialFeed = (SocialFeed) getIntent().getSerializableExtra(EXTRA_SOCIAL_FEED);
|
||||
|
||||
setTitle(socialFeed.feedTitle);
|
||||
UIUtils.setActionBarImage(this, socialFeed.photoUrl);
|
||||
UIUtils.setCustomActionBar(this, socialFeed.photoUrl, socialFeed.feedTitle);
|
||||
|
||||
readingAdapter = new MixedFeedsReadingAdapter(getFragmentManager(), defaultFeedView, socialFeed.userId);
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import static android.graphics.Color.WHITE;
|
|||
import static android.graphics.PorterDuff.Mode.DST_IN;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ActionBar;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.TypedArray;
|
||||
|
@ -17,9 +18,15 @@ import android.graphics.drawable.BitmapDrawable;
|
|||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup.LayoutParams;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.newsblur.R;
|
||||
import com.newsblur.activity.NewsBlurApplication;
|
||||
|
||||
public class UIUtils {
|
||||
|
@ -80,35 +87,28 @@ public class UIUtils {
|
|||
}
|
||||
}
|
||||
|
||||
public static int getActionBarHeight(Context context) {
|
||||
TypedArray atts = context.getTheme().obtainStyledAttributes(new int[] { android.R.attr.actionBarSize });
|
||||
int h = (int) atts.getDimension(0, 0);
|
||||
atts.recycle();
|
||||
return h;
|
||||
}
|
||||
|
||||
public static void setActionBarImage(final Activity activity, final String url) {
|
||||
new AsyncTask<Void, Void, Void>() {
|
||||
public static void setCustomActionBar(final Activity activity, String url, String title) {
|
||||
activity.getActionBar().setDisplayShowCustomEnabled(true);
|
||||
activity.getActionBar().setDisplayShowTitleEnabled(false);
|
||||
activity.getActionBar().setDisplayShowHomeEnabled(false);
|
||||
View v = LayoutInflater.from(activity).inflate(R.layout.actionbar_custom_icon, null);
|
||||
TextView titleView = ((TextView) v.findViewById(R.id.actionbar_text));
|
||||
titleView.setText(title);
|
||||
titleView.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
protected Void doInBackground(Void... arg) {
|
||||
Bitmap icon = ((NewsBlurApplication) activity.getApplicationContext()).getImageLoader().tryGetImage(url);
|
||||
if (icon != null) {
|
||||
// If setLogo() is called with a raw image, it isn't scaled up or down, but drawn raw. Wrapping
|
||||
// the icon in a BitmapDrawable lets it scale up. Note, though, that the iconSize is actually
|
||||
// ignored on virtually all platforms and the actionbar re-resizes it up to full height, so
|
||||
// attempting to add padding will silently fail.
|
||||
int iconSize = getActionBarHeight(activity);
|
||||
Bitmap scaledIcon = Bitmap.createScaledBitmap(icon, iconSize, iconSize, false);
|
||||
final BitmapDrawable draw = new BitmapDrawable(activity.getResources(), scaledIcon);
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
activity.getActionBar().setLogo(draw);
|
||||
}
|
||||
});
|
||||
}
|
||||
return null;
|
||||
public void onClick(View v) {
|
||||
activity.finish();
|
||||
}
|
||||
}.execute();
|
||||
});
|
||||
ImageView iconView = ((ImageView) v.findViewById(R.id.actionbar_icon));
|
||||
((NewsBlurApplication) activity.getApplicationContext()).getImageLoader().displayImage(url, iconView, false);
|
||||
iconView.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
activity.finish();
|
||||
}
|
||||
});
|
||||
activity.getActionBar().setCustomView(v, new ActionBar.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue