aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2015-01-15 09:17:42 -0800
committerScott Jackson <daneren2005@gmail.com>2015-01-15 09:17:42 -0800
commit719811985eee20c0f98f4740347e8e66b490a4f9 (patch)
treeeb378d6bc821608faad9792d3f6ff8148d998d56 /src
parentf014c1d35b1d7b3d38266f07e7c825a3cc4f8a5b (diff)
downloaddsub-719811985eee20c0f98f4740347e8e66b490a4f9.tar.gz
dsub-719811985eee20c0f98f4740347e8e66b490a4f9.tar.bz2
dsub-719811985eee20c0f98f4740347e8e66b490a4f9.zip
Make text wrap from around image in header
Diffstat (limited to 'src')
-rw-r--r--src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java36
-rw-r--r--src/github/daneren2005/dsub/view/MyLeadingMarginSpan2.java34
2 files changed, 68 insertions, 2 deletions
diff --git a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java
index b19caced..7342fc79 100644
--- a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java
+++ b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java
@@ -5,15 +5,21 @@ import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.graphics.Canvas;
+import android.graphics.Paint;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.text.Html;
+import android.text.Layout;
+import android.text.SpannableString;
import android.text.Spanned;
import android.text.method.LinkMovementMethod;
+import android.text.style.LeadingMarginSpan;
import android.util.Log;
import android.view.ContextMenu;
+import android.view.Display;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
@@ -27,6 +33,7 @@ import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.RatingBar;
+import android.widget.RelativeLayout;
import android.widget.TextView;
import github.daneren2005.dsub.R;
import github.daneren2005.dsub.domain.ArtistInfo;
@@ -55,6 +62,7 @@ import github.daneren2005.dsub.util.UserUtil;
import github.daneren2005.dsub.util.Util;
import github.daneren2005.dsub.view.AlbumListAdapter;
import github.daneren2005.dsub.view.HeaderGridView;
+import github.daneren2005.dsub.view.MyLeadingMarginSpan2;
import java.util.ArrayList;
import java.util.Arrays;
@@ -1320,8 +1328,8 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter
imageLoader.loadImage(coverArtView, albumRep, false, true);
}
}
- private void setupTextDisplay(View header) {
- TextView titleView = (TextView) header.findViewById(R.id.select_album_title);
+ private void setupTextDisplay(final View header) {
+ final TextView titleView = (TextView) header.findViewById(R.id.select_album_title);
if(playlistName != null) {
titleView.setText(playlistName);
} else if(podcastName != null) {
@@ -1370,12 +1378,36 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter
artistView.setLines(5);
artistView.setTextAppearance(context, android.R.style.TextAppearance_Small);
+ final Spanned spannedText = spanned;
artistView.setOnClickListener(new View.OnClickListener() {
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public void onClick(View v) {
if(artistView.getMaxLines() == 5) {
+ // Use LeadingMarginSpan2 to try to make text flow around image
+ Display display = context.getWindowManager().getDefaultDisplay();
+ View coverArtView = header.findViewById(R.id.select_album_art);
+ coverArtView.measure(display.getWidth(), display.getHeight());
+ ViewGroup.MarginLayoutParams vlp = (ViewGroup.MarginLayoutParams) coverArtView.getLayoutParams();
+ int height = coverArtView.getMeasuredHeight() + coverArtView.getPaddingBottom();
+ int width = coverArtView.getWidth() + coverArtView.getPaddingRight();
+ float textLineHeight = artistView.getPaint().getTextSize();
+ int lines = (int) Math.ceil(height / textLineHeight);
+
+ SpannableString ss = new SpannableString(spannedText);
+ ss.setSpan(new MyLeadingMarginSpan2(lines, width), 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+
+ View linearLayout = header.findViewById(R.id.select_album_text_layout);
+ RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) linearLayout.getLayoutParams();
+ int[]rules = params.getRules();
+ rules[RelativeLayout.RIGHT_OF] = 0;
+ params.leftMargin = vlp.rightMargin;
+
+ artistView.setText(ss);
artistView.setMaxLines(100);
+
+ vlp = (ViewGroup.MarginLayoutParams) titleView.getLayoutParams();
+ vlp.leftMargin = width;
} else {
artistView.setMaxLines(5);
}
diff --git a/src/github/daneren2005/dsub/view/MyLeadingMarginSpan2.java b/src/github/daneren2005/dsub/view/MyLeadingMarginSpan2.java
new file mode 100644
index 00000000..20281a28
--- /dev/null
+++ b/src/github/daneren2005/dsub/view/MyLeadingMarginSpan2.java
@@ -0,0 +1,34 @@
+package github.daneren2005.dsub.view;
+
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.text.Layout;
+import android.text.style.LeadingMarginSpan;
+
+/**
+ * Created by Scott on 1/13/2015.
+ */
+public class MyLeadingMarginSpan2 implements LeadingMarginSpan.LeadingMarginSpan2 {
+ private int margin;
+ private int lines;
+
+ public MyLeadingMarginSpan2(int lines, int margin) {
+ this.margin = margin;
+ this.lines = lines;
+ }
+
+ @Override
+ public int getLeadingMargin(boolean first) {
+ return first ? margin : 0;
+ }
+
+ @Override
+ public int getLeadingMarginLineCount() {
+ return lines;
+ }
+
+ @Override
+ public void drawLeadingMargin(Canvas c, Paint p, int x, int dir,
+ int top, int baseline, int bottom, CharSequence text,
+ int start, int end, boolean first, Layout layout) {}
+}