Skip to content

Commit

Permalink
overlay logger can expanded/collapsed now
Browse files Browse the repository at this point in the history
  • Loading branch information
MFlisar committed Feb 13, 2017
1 parent 8fe51fb commit 05ba3ef
Show file tree
Hide file tree
Showing 23 changed files with 86 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,10 @@ public int getTextSizeInDp()
{
return textSizeInDp;
}

public int getPriority()
{
return priority;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SnapHelper;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
Expand All @@ -30,10 +31,14 @@ class OverlayView extends FrameLayout
{
private OverlayLoggingSetup mSetup;
private ImageView mCloseButton;
private ImageView mCollapseExpandButton;
private TextView mLabel;
private TextView mLabelErrors;
private RecyclerView mRecyclerView;
private WindowManager mWindowManager;
private int mErrors = 0;
private LogAdapter mAdapter;
private boolean mExpanded = true;

public OverlayView(Context context, OverlayLoggingSetup setup)
{
Expand All @@ -51,11 +56,23 @@ public OverlayView(Context context, OverlayLoggingSetup setup)
// Create layout
View view = LayoutInflater.from(context).inflate(R.layout.overlay, null, false);
mCloseButton = (ImageView)view.findViewById(R.id.btClose);
mCollapseExpandButton = (ImageView)view.findViewById(R.id.btCollapseExpand);
mCollapseExpandButton.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
mExpanded = !mExpanded;
updateLayout(v.getContext());
mCollapseExpandButton.setImageResource(mExpanded ? R.drawable.ic_collapse_circle : R.drawable.ic_expand_circle);
}
});
mRecyclerView = (RecyclerView)view.findViewById(R.id.rvLogs);
mLabel = (TextView)view.findViewById(R.id.tvLabel);
mLabelErrors = (TextView)view.findViewById(R.id.tvLabelError);

// Setup buttons
int buttonHeight = dpToPx(context, 40);
int buttonHeight = dpToPx(context, 36);
mCloseButton.getLayoutParams().height = buttonHeight;

mLabel.setBackgroundColor(setup.getBackgroundColor());
Expand All @@ -76,7 +93,7 @@ public OverlayView(Context context, OverlayLoggingSetup setup)
public void onScrollStateChanged(RecyclerView recyclerView, int newState)
{
if (newState == RecyclerView.SCROLL_STATE_IDLE)
updateLabel(null);
updateLabels(null);
}
});

Expand All @@ -93,19 +110,29 @@ public void onScrollStateChanged(RecyclerView recyclerView, int newState)
mWindowManager.addView(this, windowParams);
}

private void updateLabel(Integer index)
private void updateLabels(Integer index)
{
if (index == null)
index = ((LinearLayoutManager)mRecyclerView.getLayoutManager()).findFirstCompletelyVisibleItemPosition();
mLabel.setText(mLabel.getContext().getString(R.string.lumberjack_overlay_label, index + 1, mAdapter.getItemCount()));
mLabelErrors.setVisibility(mErrors > 0 ? View.VISIBLE : View.GONE);
mLabelErrors.setText(mErrors > 0 ? mLabelErrors.getContext().getString(R.string.lumberjack_overlay_label_errors, mErrors) : "");
}

public void checkOrientation(Context context, int orientation)
{
updateLayout(context);
}

private void updateLayout(Context context)
{
Point windowDimen = new Point();
mWindowManager.getDefaultDisplay().getSize(windowDimen);

int buttonHeight = dpToPx(context, 36);
int desiredLayoutHeight = dpToPx(context, mSetup.getOverlayHeight());
if (!mExpanded)
desiredLayoutHeight = buttonHeight;
int layoutHeight = desiredLayoutHeight < windowDimen.y ? desiredLayoutHeight : windowDimen.y;

// Set View parameters
Expand All @@ -114,6 +141,8 @@ public void checkOrientation(Context context, int orientation)
windowParams.x = 0;
windowParams.y = windowDimen.y - layoutHeight;

mRecyclerView.setVisibility(mExpanded ? View.VISIBLE : View.GONE);

// Update view
mWindowManager.updateViewLayout(this, windowParams);
}
Expand All @@ -126,9 +155,10 @@ private int dpToPx(Context context, int dp)

void addMessage(OverlayLoggingTree.LogEntry msg)
{
mErrors += (msg.getPriority() >= Log.ERROR ? 1 : 0);
mAdapter.add(msg);
mRecyclerView.scrollToPosition(mAdapter.getItemCount() - 1);
updateLabel(mAdapter.getItemCount() - 1);
updateLabels(mAdapter.getItemCount() - 1);
}

void hideView()
Expand Down
Binary file removed library-overlay/src/main/res/drawable-hdpi/ic_close.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed library-overlay/src/main/res/drawable-mdpi/ic_close.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion library-overlay/src/main/res/drawable/ic_close_circle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
</shape>
</item>

<item android:drawable="@drawable/ic_close"/>
<item android:drawable="@drawable/ic_close_white_48dp"/>
</layer-list>
13 changes: 13 additions & 0 deletions library-overlay/src/main/res/drawable/ic_collapse_circle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid
android:color="#666"/>
</shape>
</item>

<item android:drawable="@drawable/ic_keyboard_arrow_down_white_48dp"/>
</layer-list>
13 changes: 13 additions & 0 deletions library-overlay/src/main/res/drawable/ic_expand_circle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid
android:color="#666"/>
</shape>
</item>

<item android:drawable="@drawable/ic_keyboard_arrow_up_white_48dp"/>
</layer-list>
21 changes: 19 additions & 2 deletions library-overlay/src/main/res/layout/overlay.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,18 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<ImageView
android:id="@+id/btCollapseExpand"
android:src="@drawable/ic_collapse_circle"
android:layout_width="36dp"
android:layout_height="36dp"/>

<ImageView
android:id="@+id/btClose"
android:src="@drawable/ic_close_circle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
android:layout_marginLeft="4dp"
android:layout_width="36dp"
android:layout_height="36dp"/>

</LinearLayout>

Expand All @@ -28,6 +35,16 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

<TextView
android:id="@+id/tvLabelError"
android:padding="4dp"
android:layout_alignBottom="@+id/llButtoons"
android:gravity="left|center_vertical"
android:layout_toRightOf="@+id/tvLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>


<android.support.v7.widget.RecyclerView
android:id="@+id/rvLogs"
android:layout_below="@+id/llButtoons"
Expand Down
1 change: 1 addition & 0 deletions library-overlay/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
<resources>

<string name="lumberjack_overlay_label">Log: %1$d/%2$d</string>
<string name="lumberjack_overlay_label_errors">(Errors: %1$d)</string>

</resources>

0 comments on commit 05ba3ef

Please sign in to comment.