Skip to content

Commit

Permalink
Fixing layoutparams issues
Browse files Browse the repository at this point in the history
  • Loading branch information
QuantumBadger committed Nov 26, 2020
1 parent 5959fce commit 3d13649
Show file tree
Hide file tree
Showing 20 changed files with 57 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ private synchronized void reloadAccounts(final SQLiteDatabase db) {
accountsCache = new LinkedList<>();
defaultAccountCache = null;

// TODO handle null? can this even happen?
if(cursor != null) {

while(cursor.moveToNext()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -834,8 +834,6 @@ private void manageAspectRatioIndicator(final DonutProgress progressBar) {
this,
General.getSharedPrefs(this))) {

// TODO Get width and height of loading media when not available from API

if(mImageInfo.width != null
&& mImageInfo.height != null
&& mImageInfo.width > 0
Expand Down Expand Up @@ -1006,7 +1004,6 @@ public void onFailure(
audioUri.toString());

AndroidCommon.runOnUiThread(() -> {
// TODO handle properly
final LinearLayout layout
= new LinearLayout(ImageViewActivity.this);
final ErrorView errorView = new ErrorView(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import android.os.ParcelFileDescriptor;
import android.util.Base64OutputStream;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
Expand Down Expand Up @@ -139,9 +138,7 @@ protected void onCreate(final Bundle savedInstanceState) {
outerLayout.addView(mLoadingOverlay);
mLoadingOverlay.setBackgroundColor(Color.argb(220, 50, 50, 50));

final ViewGroup.LayoutParams layoutParams = mLoadingOverlay.getLayoutParams();
layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
General.setLayoutMatchParent(mLoadingOverlay);

mLoadingOverlay.setOnClickListener(v -> {
// Do nothing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ public RecyclerView.ViewHolder onCreateViewHolder(final ViewGroup viewGroup) {

final RecyclerView.LayoutParams layoutParams
= new RecyclerView.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
view.setLayoutParams(layoutParams);

return new RecyclerView.ViewHolder(view) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import androidx.appcompat.app.AppCompatActivity;
import org.quantumbadger.redreader.common.General;
import org.quantumbadger.redreader.common.LinkHandler;
import org.quantumbadger.redreader.common.RunnableOnce;
import org.quantumbadger.redreader.reddit.api.RedditOAuth;
Expand All @@ -45,10 +45,7 @@ protected void onCreate(final Bundle savedInstanceState) {

setContentView(backgroundView);

final ViewGroup.LayoutParams layoutParams = backgroundView.getLayoutParams();
layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
backgroundView.setLayoutParams(layoutParams);
General.setLayoutMatchParent(backgroundView);

final Intent intent = getIntent();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@

package org.quantumbadger.redreader.adapters;

import androidx.recyclerview.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import androidx.recyclerview.widget.RecyclerView;
import org.quantumbadger.redreader.common.General;

final class GroupedRecyclerViewItemFrameLayout extends GroupedRecyclerViewAdapter.Item {

Expand All @@ -40,11 +41,11 @@ public Class getViewType() {

@Override
public RecyclerView.ViewHolder onCreateViewHolder(final ViewGroup viewGroup) {
viewGroup.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;

General.setLayoutMatchWidthWrapHeight(viewGroup);

final FrameLayout frameLayout = new FrameLayout(viewGroup.getContext());
return new RecyclerView.ViewHolder(frameLayout) {
};
return new RecyclerView.ViewHolder(frameLayout) {};
}

@Override
Expand All @@ -60,7 +61,7 @@ public void onBindViewHolder(final RecyclerView.ViewHolder viewHolder) {
mParent = view;

view.addView(mChildView);
mChildView.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
General.setLayoutMatchWidthWrapHeight(mChildView);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,16 +178,6 @@ public CommentListingFragment(

mRecyclerView.setItemAnimator(null);

/* TODO
{
final RecyclerView.ItemAnimator itemAnimator = mRecyclerView.getItemAnimator();
itemAnimator.setRemoveDuration(80);
itemAnimator.setChangeDuration(80);
itemAnimator.setAddDuration(80);
itemAnimator.setMoveDuration(80);
}
*/

if(!PrefsUtility.pref_appearance_comments_show_floating_toolbar(context, prefs)) {
mFloatingToolbar = null;

Expand Down Expand Up @@ -338,15 +328,8 @@ public boolean onTap() {
mOverlayFrame.addView(bezelOverlay);
mOverlayFrame.addView(toolbarOverlay);

bezelOverlay.getLayoutParams().width
= android.widget.FrameLayout.LayoutParams.MATCH_PARENT;
bezelOverlay.getLayoutParams().height
= android.widget.FrameLayout.LayoutParams.MATCH_PARENT;

toolbarOverlay.getLayoutParams().width
= android.widget.FrameLayout.LayoutParams.MATCH_PARENT;
toolbarOverlay.getLayoutParams().height
= android.widget.FrameLayout.LayoutParams.MATCH_PARENT;
General.setLayoutMatchParent(bezelOverlay);
General.setLayoutMatchParent(toolbarOverlay);

makeNextRequest(context);
}
Expand Down Expand Up @@ -569,7 +552,6 @@ public void onCommentListingRequestPostDownloaded(final RedditPreparedPost post)
RedditPreparedPost.showActionMenu(activity, mPost);
return true;
});
// TODO mListHeaderNotifications.setBackgroundColor(Color.argb(35, 128, 128, 128));

mCommentListingManager.addPostSelfText(paddingLayout);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
Expand Down Expand Up @@ -227,7 +226,7 @@ public void onScrolled(
}
});

mRecyclerView.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT;
General.setLayoutMatchParent(mRecyclerView);

int limit = 50;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,15 +427,8 @@ public boolean onTap() {
outerFrame.addView(bezelOverlay);
outerFrame.addView(toolbarOverlay);

bezelOverlay.getLayoutParams().width
= android.widget.FrameLayout.LayoutParams.MATCH_PARENT;
bezelOverlay.getLayoutParams().height
= android.widget.FrameLayout.LayoutParams.MATCH_PARENT;

toolbarOverlay.getLayoutParams().width
= android.widget.FrameLayout.LayoutParams.MATCH_PARENT;
toolbarOverlay.getLayoutParams().height
= android.widget.FrameLayout.LayoutParams.MATCH_PARENT;
General.setLayoutMatchParent(bezelOverlay);
General.setLayoutMatchParent(toolbarOverlay);
}

return outerFrame;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ public final View generateView(

final ViewGroup.MarginLayoutParams layoutParams
= new ViewGroup.MarginLayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);

layoutParams.setMargins(0, linkMarginPx, 0, linkMarginPx);
ldv.setLayoutParams(layoutParams);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public View generateView(

final ViewGroup.MarginLayoutParams layoutParams
= new ViewGroup.MarginLayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
thicknessPx);
ViewGroup.LayoutParams.MATCH_PARENT,
thicknessPx);

layoutParams.leftMargin = paddingPx;
layoutParams.rightMargin = paddingPx;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,15 @@ public View generateView(
final View quoteIndent = new View(activity);
quoteLayout.addView(quoteIndent);
quoteIndent.setBackgroundColor(Color.rgb(128, 128, 128));
quoteIndent.getLayoutParams().width = quoteBarWidth;
quoteIndent.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT;
((ViewGroup.MarginLayoutParams)quoteIndent.getLayoutParams()).rightMargin
= quoteBarWidth;

{
final ViewGroup.LayoutParams quoteIndentLayoutParams = quoteIndent.getLayoutParams();
quoteIndentLayoutParams.width = quoteBarWidth;
quoteIndentLayoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
((ViewGroup.MarginLayoutParams)quoteIndentLayoutParams).rightMargin
= quoteBarWidth;
quoteIndent.setLayoutParams(quoteIndentLayoutParams);
}

if(mElements.size() == 1) {
quoteLayout.addView(mElements.get(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ public ViewGroup buildView(
paragraphSpacing,
(int)(dpScale * 15),
0);
hLine.setLayoutParams(hLineParams);
hLine.setBackgroundColor(Color.rgb(128, 128, 128));
break;
}
Expand All @@ -179,8 +180,8 @@ public ViewGroup buildView(
quoteIndent.getLayoutParams().height =
ViewGroup.LayoutParams.MATCH_PARENT;
((ViewGroup.MarginLayoutParams)quoteIndent.getLayoutParams()).rightMargin
=
quoteBarWidth;
= quoteBarWidth;
quoteIndent.setLayoutParams(quoteIndent.getLayoutParams());
}

quoteLayout.addView(tv);
Expand Down Expand Up @@ -230,7 +231,8 @@ public ViewGroup buildView(
linkMarginPx,
0,
linkMarginPx);
ldv.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;

General.setLayoutMatchWidthWrapHeight(ldv);

ldv.setOnClickListener(v -> link.onClicked(activity));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
Expand Down Expand Up @@ -77,10 +76,7 @@ public FlingableItemView(@NonNull final Context context) {
.inflate(R.layout.fling_hint, null, false);

addView(mFlingHintOuter);
final ViewGroup.LayoutParams flingHintLayoutParams
= mFlingHintOuter.getLayoutParams();
flingHintLayoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
flingHintLayoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
General.setLayoutMatchWidthWrapHeight(mFlingHintOuter);

mFlingHintLeft
= mFlingHintOuter.findViewById(R.id.reddit_post_fling_text_left);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ public LoadMoreCommentsView(
final View divider = new View(context);
addView(divider);

divider.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
divider.getLayoutParams().height = 1;
General.setLayoutWidthHeight(divider, ViewGroup.LayoutParams.MATCH_PARENT, 1);

final LinearLayout layout = new LinearLayout(context);
layout.setOrientation(HORIZONTAL);
Expand All @@ -68,6 +67,7 @@ public LoadMoreCommentsView(
mIndentView = new IndentView(context);
layout.addView(mIndentView);
mIndentView.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT;
mIndentView.setLayoutParams(mIndentView.getLayoutParams());

final ImageView icon;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;
Expand Down Expand Up @@ -360,7 +359,8 @@ public void reset(
mShowLinkButtons && !hideLinkButtons);

mBodyHolder.addView(commentBody);
commentBody.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
General.setLayoutMatchWidthWrapHeight(commentBody);

((MarginLayoutParams)commentBody.getLayoutParams()).topMargin =
General.dpToPixels(activity, 1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ public RedditInboxItemView(
mDivider = new View(activity);
mDivider.setBackgroundColor(Color.argb(128, 128, 128, 128)); // TODO better
addView(mDivider);

mDivider.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
mDivider.getLayoutParams().height = 1;
General.setLayoutWidthHeight(mDivider, ViewGroup.LayoutParams.MATCH_PARENT, 1);

final LinearLayout inner = new LinearLayout(activity);
inner.setOrientation(VERTICAL);
Expand All @@ -70,12 +68,12 @@ public RedditInboxItemView(
mHeader.setTextSize(11.0f * theme.rrCommentHeaderFontScale);
mHeader.setTextColor(theme.rrCommentHeaderCol);
inner.addView(mHeader);
mHeader.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
General.setLayoutMatchWidthWrapHeight(mHeader);

mBodyHolder = new FrameLayout(activity);
mBodyHolder.setPadding(0, General.dpToPixels(activity, 2), 0, 0);
inner.addView(mBodyHolder);
mBodyHolder.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
General.setLayoutMatchWidthWrapHeight(mBodyHolder);

final int paddingPixels = General.dpToPixels(activity, 8.0f);
inner.setPadding(
Expand All @@ -85,7 +83,7 @@ public RedditInboxItemView(
paddingPixels);

addView(inner);
inner.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
General.setLayoutMatchWidthWrapHeight(mBodyHolder);

setDescendantFocusability(FOCUS_BLOCK_DESCENDANTS);

Expand Down Expand Up @@ -136,7 +134,7 @@ public void reset(

mBodyHolder.removeAllViews();
mBodyHolder.addView(body);
body.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
General.setLayoutMatchWidthWrapHeight(body);
}

public void handleInboxClick(final BaseActivity activity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.quantumbadger.redreader.views.bezelmenu;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
Expand All @@ -43,17 +44,20 @@ public void setContents(final View contents) {
}
}

@SuppressLint("RtlHardcoded")
public void show(final SideToolbarPosition pos) {

removeAllViews();
addView(contents);

((LayoutParams)contents.getLayoutParams()).gravity = (pos
== SideToolbarPosition.LEFT
? Gravity.LEFT
: Gravity.RIGHT);
contents.getLayoutParams().width = ViewGroup.LayoutParams.WRAP_CONTENT;
contents.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT;
final ViewGroup.LayoutParams layoutParams = contents.getLayoutParams();

((LayoutParams)layoutParams).gravity
= (pos == SideToolbarPosition.LEFT ? Gravity.LEFT : Gravity.RIGHT);
layoutParams.width = ViewGroup.LayoutParams.WRAP_CONTENT;
layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;

contents.setLayoutParams(layoutParams);

shownPosition = pos;
}
Expand Down

0 comments on commit 3d13649

Please sign in to comment.