Fix compount drawable height on save/share buttons.

This commit is contained in:
dosiecki 2015-09-01 04:36:42 -07:00
parent e5e5d043ba
commit e44a0bc365
7 changed files with 31 additions and 20 deletions

View file

@ -13,15 +13,15 @@
android:id="@+id/share_story_button"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_height="44dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
style="?storyButtons"
android:textSize="12sp"
android:textSize="13sp"
android:paddingTop="6dp"
android:paddingBottom="6dp"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:drawableLeft="@drawable/share_icon"
android:text="@string/share_this" />
@ -29,15 +29,15 @@
android:id="@+id/save_story_button"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_height="44dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
style="?storyButtons"
android:textSize="12sp"
android:textSize="13sp"
android:paddingTop="6dp"
android:paddingBottom="6dp"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:drawableLeft="@drawable/clock"
android:text="@string/save_this" />

View file

@ -160,8 +160,8 @@ public abstract class Reading extends NbActivity implements OnPageChangeListener
}
// 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);
this.overlayRangeTopPx = (float) UIUtils.dp2px(this, OVERLAY_RANGE_TOP_DP);
this.overlayRangeBotPx = (float) UIUtils.dp2px(this, OVERLAY_RANGE_BOT_DP);
this.pageHistory = new ArrayList<Story>();
@ -264,7 +264,7 @@ public abstract class Reading extends NbActivity implements OnPageChangeListener
private void setupPager() {
pager = (ViewPager) findViewById(R.id.reading_pager);
pager.setPageMargin(UIUtils.convertDPsToPixels(getApplicationContext(), 1));
pager.setPageMargin(UIUtils.dp2px(getApplicationContext(), 1));
if (PrefsUtils.isLightThemeSelected(this)) {
pager.setPageMarginDrawable(R.drawable.divider_light);
} else {

View file

@ -164,8 +164,8 @@ public class FolderListFragment extends NbFragment implements OnCreateContextMen
Display display = getActivity().getWindowManager().getDefaultDisplay();
list.setIndicatorBounds(
display.getWidth() - UIUtils.convertDPsToPixels(getActivity(), 20),
display.getWidth() - UIUtils.convertDPsToPixels(getActivity(), 10));
display.getWidth() - UIUtils.dp2px(getActivity(), 20),
display.getWidth() - UIUtils.dp2px(getActivity(), 10));
list.setChildDivider(getActivity().getResources().getDrawable(R.drawable.divider_light));
list.setAdapter(adapter);

View file

@ -8,6 +8,7 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.net.Uri;
import android.os.AsyncTask;
@ -194,6 +195,16 @@ public class ReadingItemFragment extends NbFragment implements ClassifierDialogF
view = inflater.inflate(R.layout.fragment_readingitem, null);
ButterKnife.bind(this, view);
// the share/save buttons us compound drawables for layout speed, but they
// cannot correctly compute padding. hard resize the icons to use padding.
int iconSizePx = UIUtils.dp2px(this.activity, 30);
Drawable shareButtonIcon = shareButton.getCompoundDrawables()[0];
shareButtonIcon.setBounds(0, 0, iconSizePx, iconSizePx);
shareButton.setCompoundDrawables(shareButtonIcon, null, null, null);
Drawable saveButtonIcon = saveButton.getCompoundDrawables()[0];
saveButtonIcon.setBounds(0, 0, iconSizePx, iconSizePx);
saveButton.setCompoundDrawables(saveButtonIcon, null, null, null);
registerForContextMenu(web);
web.setCustomViewLayout(webviewCustomViewLayout);
web.setWebviewWrapperLayout(fragmentScrollview);

View file

@ -65,9 +65,9 @@ public class UIUtils {
* used throughout Android.
* See: http://bit.ly/MfsAUZ (Romain Guy's comment)
*/
public static int convertDPsToPixels(Context context, final int dps) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (dps * scale + 0.5f);
public static int dp2px(Context context, int dp) {
float scale = context.getResources().getDisplayMetrics().density;
return (int) (dp * scale + 0.5f);
}
public static float px2dp(Context context, int px) {

View file

@ -48,7 +48,7 @@ public class ViewUtils {
public static ImageView createSharebarImage(final Context context, final ImageLoader imageLoader, final String photoUrl, final String userId) {
ImageView image = new ImageView(context);
int imageLength = UIUtils.convertDPsToPixels(context, 15);
int imageLength = UIUtils.dp2px(context, 15);
image.setMaxHeight(imageLength);
image.setMaxWidth(imageLength);

View file

@ -48,7 +48,7 @@ public class FlowLayout extends ViewGroup {
public FlowLayout(Context context) {
super(context);
defaultImageLength = UIUtils.convertDPsToPixels(context, 25);
defaultImageLength = UIUtils.dp2px(context, 25);
}
public FlowLayout(Context context, AttributeSet attrs) {
@ -57,7 +57,7 @@ public class FlowLayout extends ViewGroup {
TypedArray styledAttributes = context.obtainStyledAttributes(attrs, R.styleable.FlowLayout);
String flowAttribute = styledAttributes.getString(R.styleable.FlowLayout_flow);
int defaultImageSizeAttribute = styledAttributes.getInt(R.styleable.FlowLayout_defaultImageSize, 25);
defaultImageLength = UIUtils.convertDPsToPixels(context, defaultImageSizeAttribute);
defaultImageLength = UIUtils.dp2px(context, defaultImageSizeAttribute);
if (!TextUtils.isEmpty(flowAttribute) && TextUtils.equals(flowAttribute, "left")) {
flowDirection = FLOW_LEFT;
@ -134,7 +134,7 @@ public class FlowLayout extends ViewGroup {
@Override
protected ViewGroup.LayoutParams generateDefaultLayoutParams() {
int defaultPadding = UIUtils.convertDPsToPixels(getContext(), 3);
int defaultPadding = UIUtils.dp2px(getContext(), 3);
return new LayoutParams(defaultPadding, defaultPadding);
}