Skip to content
This repository was archived by the owner on Nov 8, 2018. It is now read-only.

Commit fc487cf

Browse files
committed
Moved redundant code to JustUtil
1 parent 261260f commit fc487cf

File tree

9 files changed

+51
-42
lines changed

9 files changed

+51
-42
lines changed

app/src/main/java/com/peacecorps/pcsa/FormattedSingleTextViewFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
6767

6868
ArticleBuilder articleBuilder = new ArticleBuilder();
6969
articleBuilder.append(contentString, true, new RelativeSizeSpan(1f), new JustifiedSpan());
70-
content = util.addDocumentView(Html.toHtml(articleBuilder), DocumentView.FORMATTED_TEXT, false,
70+
content = util.addDocumentView(Html.toHtml(articleBuilder), DocumentView.FORMATTED_TEXT, false,null,
7171
getActivity());
7272
content.getDocumentLayoutParams().setTextAlignment(TextAlignment.JUSTIFIED);
7373
content.getDocumentLayoutParams().setHyphenator(DefaultHyphenator.

app/src/main/java/com/peacecorps/pcsa/JustificationUtil.java

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,13 @@ public JustificationUtil(Context context) {
2020
this.context = context;
2121
}
2222

23-
public static DocumentView addDocumentView(CharSequence article, int type, boolean isOtherStaffContent, Activity activity) {
24-
final DocumentView documentView = new DocumentView(activity, type);
23+
public static DocumentView addDocumentView(CharSequence article, int type, boolean isOtherStaffContent,Context mContext, Activity activity) {
24+
final DocumentView documentView;
25+
if(mContext!=null){
26+
documentView= new DocumentView(mContext, type);
27+
}else {
28+
documentView = new DocumentView(activity, type);
29+
}
2530
documentView.getDocumentLayoutParams().setTextColor(context.getResources().getColor(R.color.primary_text_default_material_dark));
2631
documentView.getDocumentLayoutParams().setTextTypeface(Typeface.DEFAULT);
2732
if (isOtherStaffContent) {
@@ -42,6 +47,28 @@ public static DocumentView addDocumentView(CharSequence article, int type, boole
4247
return documentView;
4348
}
4449

50+
// public static DocumentView addDocumentViewC(CharSequence article, int type, boolean isOtherStaffContent, Context activity) {
51+
// final DocumentView documentView = new DocumentView(activity, type);
52+
// documentView.getDocumentLayoutParams().setTextColor(context.getResources().getColor(R.color.primary_text_default_material_dark));
53+
// documentView.getDocumentLayoutParams().setTextTypeface(Typeface.DEFAULT);
54+
// if (isOtherStaffContent) {
55+
// documentView.getDocumentLayoutParams().setTextSize(16f);
56+
// } else {
57+
// documentView.getDocumentLayoutParams().setTextSize(17f);
58+
// }
59+
// documentView.getDocumentLayoutParams().setTextAlignment(TextAlignment.JUSTIFIED);
60+
// documentView.getDocumentLayoutParams().setInsetPaddingLeft(10);
61+
// documentView.getDocumentLayoutParams().setInsetPaddingRight(10);
62+
// documentView.getDocumentLayoutParams().setAntialias(true);
63+
// documentView.getDocumentLayoutParams().setInsetPaddingTop(10);
64+
// documentView.getDocumentLayoutParams().setInsetPaddingBottom(10);
65+
// documentView.getDocumentLayoutParams().setHyphenator(DefaultHyphenator.
66+
// getInstance(DefaultHyphenator.HyphenPattern.PT));
67+
// documentView.getDocumentLayoutParams().setHyphenated(true);
68+
// documentView.setText(Html.fromHtml(article.toString()));
69+
// return documentView;
70+
// }
71+
4572
// public static DocumentView addDocumentView(CharSequence article, int type,boolean isOtherStaffContent,Activity activity) {
4673
// return addDocumentView(article, type, false,activity);
4774
// }

app/src/main/java/com/peacecorps/pcsa/get_help_now/OtherStaffContent.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
5757
ArticleBuilder articleBuilder = new ArticleBuilder();
5858
articleBuilder.append(details.getString(CONTACT_DESC_PART1), true, new RelativeSizeSpan(1f), new JustifiedSpan());
5959
DocumentView contactDescription = util.addDocumentView(Html.toHtml(articleBuilder),
60-
DocumentView.FORMATTED_TEXT, true, getActivity());
60+
DocumentView.FORMATTED_TEXT, true, null,getActivity());
6161
contactDescription.getDocumentLayoutParams().setTextAlignment(TextAlignment.JUSTIFIED);
6262
contactDescription.getDocumentLayoutParams().setHyphenator(DefaultHyphenator.
6363
getInstance(DefaultHyphenator.HyphenPattern.PT));
@@ -68,7 +68,7 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
6868
ArticleBuilder articleBuilder1 = new ArticleBuilder();
6969
articleBuilder1.append(details.getString(CONTACT_DESC_PART2), true, new RelativeSizeSpan(1f), new JustifiedSpan());
7070
DocumentView contactDescription1 = util.addDocumentView(Html.toHtml(articleBuilder1),
71-
DocumentView.FORMATTED_TEXT, true, getActivity());
71+
DocumentView.FORMATTED_TEXT, true,null, getActivity());
7272
contactDescription1.getDocumentLayoutParams().setTextAlignment(TextAlignment.JUSTIFIED);
7373
contactDescription1.getDocumentLayoutParams().setHyphenator(DefaultHyphenator.
7474
getInstance(DefaultHyphenator.HyphenPattern.PT));
@@ -95,7 +95,7 @@ public void onClick(View v) {
9595
ArticleBuilder articleBuilder2 = new ArticleBuilder();
9696
articleBuilder2.append(details.getString(CONTACT_DESC_PART3), true, new RelativeSizeSpan(1f), new JustifiedSpan());
9797
DocumentView contactDescription2 = util.addDocumentView(Html.toHtml(articleBuilder2),
98-
DocumentView.FORMATTED_TEXT, true, getActivity());
98+
DocumentView.FORMATTED_TEXT, true,null, getActivity());
9999
contactDescription2.getDocumentLayoutParams().setTextAlignment(TextAlignment.JUSTIFIED);
100100
contactDescription2.getDocumentLayoutParams().setHyphenator(DefaultHyphenator.
101101
getInstance(DefaultHyphenator.HyphenPattern.PT));

app/src/main/java/com/peacecorps/pcsa/safety_tools/FormattedSafetyPlanBasicsContentFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
6565
String content = getArguments().getString(CONTENT_KEY);
6666
ArticleBuilder articleBuilder = new ArticleBuilder();
6767
articleBuilder.append(content, true, new RelativeSizeSpan(1f), new JustifiedSpan());
68-
contenttoDisplay = util.addDocumentView(Html.toHtml(articleBuilder), DocumentView.FORMATTED_TEXT, false, getActivity());
68+
contenttoDisplay = util.addDocumentView(Html.toHtml(articleBuilder), DocumentView.FORMATTED_TEXT, false, null,getActivity());
6969
contenttoDisplay.getDocumentLayoutParams().setTextAlignment(TextAlignment.JUSTIFIED);
7070
contenttoDisplay.getDocumentLayoutParams().setHyphenator(DefaultHyphenator.
7171
getInstance(DefaultHyphenator.HyphenPattern.PT));

app/src/main/java/com/peacecorps/pcsa/safety_tools/ScreenSlideCustomPagerAdapter.java

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import com.bluejamesbond.text.style.JustifiedSpan;
1616
import com.bluejamesbond.text.style.TextAlignment;
1717
import com.bluejamesbond.text.util.ArticleBuilder;
18+
import com.peacecorps.pcsa.JustificationUtil;
1819
import com.peacecorps.pcsa.R;
1920

2021
/**
@@ -52,10 +53,12 @@ public boolean isViewFromObject(View view, Object object) {
5253
public Object instantiateItem(ViewGroup container, int position) {
5354
View itemView = mLayoutInflater.inflate(R.layout.fragment_viewpager, container, false);
5455

56+
JustificationUtil util = new JustificationUtil(mContext.getApplicationContext());
5557
ArticleBuilder articleBuilder = new ArticleBuilder();
5658
articleBuilder.append(mContext.getString(steps[position]),
5759
true, new RelativeSizeSpan(1f), new JustifiedSpan());
58-
DocumentView textView = addDocumentView(Html.toHtml(articleBuilder), DocumentView.FORMATTED_TEXT);
60+
DocumentView textView = util.addDocumentView(Html.toHtml(articleBuilder),
61+
DocumentView.FORMATTED_TEXT, false, mContext,null);
5962
textView.getDocumentLayoutParams().setTextAlignment(TextAlignment.JUSTIFIED);
6063
textView.getDocumentLayoutParams().setHyphenator(DefaultHyphenator.
6164
getInstance(DefaultHyphenator.HyphenPattern.PT));
@@ -72,25 +75,4 @@ public void destroyItem(ViewGroup container, int position, Object object) {
7275
container.removeView((View) object);
7376
}
7477

75-
public DocumentView addDocumentView(CharSequence article, int type, boolean rtl) {
76-
final DocumentView documentView = new DocumentView(mContext, type);
77-
documentView.getDocumentLayoutParams().setTextColor(mContext.getResources().getColor(R.color.primary_text_default_material_dark));
78-
documentView.getDocumentLayoutParams().setTextTypeface(Typeface.DEFAULT);
79-
documentView.getDocumentLayoutParams().setTextSize(17f);
80-
documentView.getDocumentLayoutParams().setTextAlignment(TextAlignment.JUSTIFIED);
81-
documentView.getDocumentLayoutParams().setInsetPaddingLeft(10);
82-
documentView.getDocumentLayoutParams().setInsetPaddingRight(10);
83-
documentView.getDocumentLayoutParams().setAntialias(true);
84-
documentView.getDocumentLayoutParams().setInsetPaddingTop(10);
85-
documentView.getDocumentLayoutParams().setInsetPaddingBottom(10);
86-
documentView.getDocumentLayoutParams().setHyphenator(DefaultHyphenator.
87-
getInstance(DefaultHyphenator.HyphenPattern.PT));
88-
documentView.getDocumentLayoutParams().setHyphenated(true);
89-
documentView.setText(Html.fromHtml(article.toString()));
90-
return documentView;
91-
}
92-
93-
public DocumentView addDocumentView(CharSequence article, int type) {
94-
return addDocumentView(article, type, false);
95-
}
9678
}

app/src/main/java/com/peacecorps/pcsa/sexual_assault_awareness/HarassmentFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
5555
ArticleBuilder articleBuilder = new ArticleBuilder();
5656
articleBuilder.append(getString(R.string.harassment_content), true, new RelativeSizeSpan(1f), new JustifiedSpan());
5757
wasContent = util.addDocumentView(Html.toHtml(articleBuilder), DocumentView.PLAIN_TEXT, false,
58-
getActivity());
58+
null,getActivity());
5959
wasContent.getDocumentLayoutParams().setTextAlignment(TextAlignment.JUSTIFIED);
6060
wasContent.getDocumentLayoutParams().setHyphenator(DefaultHyphenator.
6161
getInstance(DefaultHyphenator.HyphenPattern.PT));

app/src/main/java/com/peacecorps/pcsa/sexual_assault_awareness/HelpingFragment.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
4444
articleBuilder1.append(getResources().getString(R.string.helping1),
4545
true, new RelativeSizeSpan(1f), new JustifiedSpan());
4646
DocumentView reporting_step1 = util.addDocumentView(Html.toHtml(articleBuilder1),
47-
DocumentView.FORMATTED_TEXT, false, getActivity());
47+
DocumentView.FORMATTED_TEXT, false,null, getActivity());
4848
reporting_step1.getDocumentLayoutParams().setTextAlignment(TextAlignment.JUSTIFIED);
4949
reporting_step1.getDocumentLayoutParams().setHyphenator(DefaultHyphenator.
5050
getInstance(DefaultHyphenator.HyphenPattern.PT));
@@ -56,7 +56,7 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
5656
articleBuilder2.append(getResources().getString(R.string.helping2),
5757
true, new RelativeSizeSpan(1f), new JustifiedSpan());
5858
DocumentView reporting_step2 = util.addDocumentView(Html.toHtml(articleBuilder2), DocumentView.FORMATTED_TEXT, false,
59-
getActivity());
59+
null,getActivity());
6060
reporting_step2.getDocumentLayoutParams().setTextAlignment(TextAlignment.JUSTIFIED);
6161
reporting_step2.getDocumentLayoutParams().setHyphenator(DefaultHyphenator.
6262
getInstance(DefaultHyphenator.HyphenPattern.PT));
@@ -68,7 +68,7 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
6868
articleBuilder3.append(getResources().getString(R.string.helping3),
6969
true, new RelativeSizeSpan(1f), new JustifiedSpan());
7070
DocumentView reporting_step3 = util.addDocumentView(Html.toHtml(articleBuilder3), DocumentView.FORMATTED_TEXT, false,
71-
getActivity());
71+
null,getActivity());
7272
reporting_step3.getDocumentLayoutParams().setTextAlignment(TextAlignment.JUSTIFIED);
7373
reporting_step3.getDocumentLayoutParams().setHyphenator(DefaultHyphenator.
7474
getInstance(DefaultHyphenator.HyphenPattern.PT));
@@ -80,7 +80,7 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
8080
articleBuilder4.append(getResources().getString(R.string.helping4),
8181
true, new RelativeSizeSpan(1f), new JustifiedSpan());
8282
DocumentView reporting_step4 = util.addDocumentView(Html.toHtml(articleBuilder4), DocumentView.FORMATTED_TEXT, false,
83-
getActivity());
83+
null,getActivity());
8484
reporting_step4.getDocumentLayoutParams().setTextAlignment(TextAlignment.JUSTIFIED);
8585
reporting_step4.getDocumentLayoutParams().setHyphenator(DefaultHyphenator.
8686
getInstance(DefaultHyphenator.HyphenPattern.PT));
@@ -92,7 +92,7 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
9292
articleBuilder5.append(getResources().getString(R.string.helping5),
9393
true, new RelativeSizeSpan(1f), new JustifiedSpan());
9494
DocumentView reporting_step5 = util.addDocumentView(Html.toHtml(articleBuilder5), DocumentView.FORMATTED_TEXT, false,
95-
getActivity());
95+
null,getActivity());
9696
reporting_step5.getDocumentLayoutParams().setTextAlignment(TextAlignment.JUSTIFIED);
9797
reporting_step5.getDocumentLayoutParams().setHyphenator(DefaultHyphenator.
9898
getInstance(DefaultHyphenator.HyphenPattern.PT));

app/src/main/java/com/peacecorps/pcsa/sexual_assault_awareness/WasFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
5050
ArticleBuilder articleBuilder = new ArticleBuilder();
5151
articleBuilder.append(getString(R.string.was_content), true, new RelativeSizeSpan(1f), new JustifiedSpan());
5252
JustificationUtil util = new JustificationUtil(getActivity().getApplicationContext());
53-
wasContent = util.addDocumentView(Html.toHtml(articleBuilder), DocumentView.FORMATTED_TEXT, false,
53+
wasContent = util.addDocumentView(Html.toHtml(articleBuilder), DocumentView.FORMATTED_TEXT, false,null,
5454
getActivity());
5555
wasContent.getDocumentLayoutParams().setTextAlignment(TextAlignment.JUSTIFIED);
5656
wasContent.getDocumentLayoutParams().setHyphenator(DefaultHyphenator.

app/src/main/java/com/peacecorps/pcsa/support_services/StepsFragment.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
4141
articleBuilder1.append(getResources().getString(R.string.reporting_step1),
4242
true, new RelativeSizeSpan(1f), new JustifiedSpan());
4343
DocumentView reporting_step1 = util.addDocumentView(Html.toHtml(articleBuilder1),
44-
DocumentView.FORMATTED_TEXT, false, getActivity());
44+
DocumentView.FORMATTED_TEXT, false,null, getActivity());
4545
reporting_step1.getDocumentLayoutParams().setTextAlignment(TextAlignment.JUSTIFIED);
4646
reporting_step1.getDocumentLayoutParams().setHyphenator(DefaultHyphenator.
4747
getInstance(DefaultHyphenator.HyphenPattern.PT));
@@ -53,7 +53,7 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
5353
articleBuilder2.append(getResources().getString(R.string.reporting_step2),
5454
true, new RelativeSizeSpan(1f), new JustifiedSpan());
5555
DocumentView reporting_step2 = util.addDocumentView(Html.toHtml(articleBuilder2),
56-
DocumentView.FORMATTED_TEXT, false, getActivity());
56+
DocumentView.FORMATTED_TEXT, false, null,getActivity());
5757
reporting_step2.getDocumentLayoutParams().setTextAlignment(TextAlignment.JUSTIFIED);
5858
reporting_step2.getDocumentLayoutParams().setHyphenator(DefaultHyphenator.
5959
getInstance(DefaultHyphenator.HyphenPattern.PT));
@@ -65,7 +65,7 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
6565
articleBuilder3.append(getResources().getString(R.string.reporting_step3),
6666
true, new RelativeSizeSpan(1f), new JustifiedSpan());
6767
DocumentView reporting_step3 = util.addDocumentView(Html.toHtml(articleBuilder3),
68-
DocumentView.FORMATTED_TEXT, false, getActivity());
68+
DocumentView.FORMATTED_TEXT, false, null,getActivity());
6969
reporting_step3.getDocumentLayoutParams().setTextAlignment(TextAlignment.JUSTIFIED);
7070
reporting_step3.getDocumentLayoutParams().setHyphenator(DefaultHyphenator.
7171
getInstance(DefaultHyphenator.HyphenPattern.PT));
@@ -77,7 +77,7 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
7777
articleBuilder4.append(getResources().getString(R.string.reporting_step4),
7878
true, new RelativeSizeSpan(1f), new JustifiedSpan());
7979
DocumentView reporting_step4 = util.addDocumentView(Html.toHtml(articleBuilder4),
80-
DocumentView.FORMATTED_TEXT, false, getActivity());
80+
DocumentView.FORMATTED_TEXT, false,null, getActivity());
8181
reporting_step4.getDocumentLayoutParams().setTextAlignment(TextAlignment.JUSTIFIED);
8282
reporting_step4.getDocumentLayoutParams().setHyphenator(DefaultHyphenator.
8383
getInstance(DefaultHyphenator.HyphenPattern.PT));
@@ -89,7 +89,7 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
8989
articleBuilder5.append(getResources().getString(R.string.reporting_step5),
9090
true, new RelativeSizeSpan(1f), new JustifiedSpan());
9191
DocumentView reporting_step5 = util.addDocumentView(Html.toHtml(articleBuilder5),
92-
DocumentView.FORMATTED_TEXT, false, getActivity());
92+
DocumentView.FORMATTED_TEXT, false, null,getActivity());
9393
reporting_step5.getDocumentLayoutParams().setTextAlignment(TextAlignment.JUSTIFIED);
9494
reporting_step5.getDocumentLayoutParams().setHyphenator(DefaultHyphenator.
9595
getInstance(DefaultHyphenator.HyphenPattern.PT));
@@ -101,7 +101,7 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
101101
articleBuilder6.append(getResources().getString(R.string.reporting_step6),
102102
true, new RelativeSizeSpan(1f), new JustifiedSpan());
103103
DocumentView reporting_step6 = util.addDocumentView(Html.toHtml(articleBuilder6),
104-
DocumentView.FORMATTED_TEXT, false, getActivity());
104+
DocumentView.FORMATTED_TEXT, false, null,getActivity());
105105
reporting_step6.getDocumentLayoutParams().setTextAlignment(TextAlignment.JUSTIFIED);
106106
reporting_step6.getDocumentLayoutParams().setHyphenator(DefaultHyphenator.
107107
getInstance(DefaultHyphenator.HyphenPattern.PT));

0 commit comments

Comments
 (0)