get rid of old layout hack

This commit is contained in:
Adrian Ulrich 2015-08-10 16:47:56 +02:00
parent 1784b43785
commit 2603aa8f08
2 changed files with 4 additions and 44 deletions

View File

@ -48,16 +48,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
android:maxLines="2"
android:textColor="?android:textColorPrimary"
android:gravity="left|center_vertical"
android:layout_width="wrap_content"
android:layout_width="0px"
android:layout_weight="1"
android:layout_height="match_parent"
android:paddingTop="2dip"
android:paddingBottom="2dip"
android:paddingLeft="4dip" />
<!-- spacer -->
<View
android:layout_height="match_parent"
android:layout_width="0px"
android:layout_weight="1"/>
<CheckedTextView
android:id="@+id/checkbox"
android:visibility="gone"

View File

@ -32,27 +32,15 @@ public class DraggableRow extends LinearLayout implements Checkable {
private boolean mHighlighted;
private boolean mChecked;
private float mDensity;
private static int sWidth = -1;
private TextView mTextView;
private CheckedTextView mCheckBox;
private View mPmark;
private ImageView mDragger;
private LazyCoverView mCoverView;
// Hardcoded sizes of elements in DPI
// MUST match definition in draggable_row
private final int DPI_PMARK = 4;
private final int DPI_CHECKBOX = 44;
private final int DPI_DRAGGER = 44;
private final int DPI_COVER = 44;
private final int DPI_SLACK = 1; // safety margin
public DraggableRow(Context context, AttributeSet attrs) {
super(context, attrs);
mDensity = context.getResources().getDisplayMetrics().density;
}
@ -63,33 +51,10 @@ public class DraggableRow extends LinearLayout implements Checkable {
mPmark = (View)this.findViewById(R.id.pmark);
mDragger = (ImageView)this.findViewById(R.id.dragger);
mCoverView = (LazyCoverView)this.findViewById(R.id.cover);
setupTextView(false);
super.onFinishInflate();
}
@Override
protected void onSizeChanged (int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
if (sWidth != w) {
sWidth = w;
// This view was drawn with an incorrect with
// fix it and force a redraw
setupTextView(true);
}
}
/**
* Resizes our textview to the correct size
* @param redraw invalidates the current view if TRUE
*/
private void setupTextView(boolean redraw) {
int pixelUsed = (int)((DPI_SLACK + DPI_PMARK + DPI_DRAGGER + (mShowCover ? DPI_COVER : 0) + (mShowCheckBox ? DPI_CHECKBOX : 0)) * mDensity);
int pixelFree = sWidth - pixelUsed;
if (pixelFree > 0)
mTextView.setWidth(pixelFree);
if (redraw == true)
this.invalidate();
}
@Override
public boolean isChecked() {
@ -127,7 +92,6 @@ public class DraggableRow extends LinearLayout implements Checkable {
if (mShowCheckBox != state) {
mCheckBox.setVisibility( state ? View.VISIBLE : View.GONE );
mShowCheckBox = state;
setupTextView(true);
}
}
@ -140,7 +104,6 @@ public class DraggableRow extends LinearLayout implements Checkable {
if (mShowCover != state) {
mCoverView.setVisibility( state ? View.VISIBLE : View.GONE );
mShowCover = state;
setupTextView(true);
}
}