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

Commit c013ab8

Browse files
committed
Merge pull request #305 from amlcurran/fit-windows
Adds custom text rendering
2 parents fe2a070 + f86e929 commit c013ab8

File tree

10 files changed

+100
-17
lines changed

10 files changed

+100
-17
lines changed

gradle.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ POM_LICENCE_DIST=repo
2929
POM_DEVELOPER_ID=amlcurran
3030
POM_DEVELOPER_NAME=Alex Curran
3131

32-
BUILD_TOOLS_VERSION=21.0.0
33-
COMPILE_SDK=21
32+
BUILD_TOOLS_VERSION=22.0.1
33+
COMPILE_SDK=23
3434
MIN_SDK_LIBRARY=9
3535
MIN_SDK_SAMPLE=11
36-
TARGET_SDK=21
36+
TARGET_SDK=23

library/src/main/java/com/github/amlcurran/showcaseview/ShowcaseView.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import android.graphics.Color;
2525
import android.graphics.Point;
2626
import android.graphics.PorterDuff;
27+
import android.text.TextPaint;
2728
import android.text.TextUtils;
2829
import android.util.AttributeSet;
2930
import android.view.LayoutInflater;
@@ -504,6 +505,28 @@ public Builder setShowcaseEventListener(OnShowcaseEventListener showcaseEventLis
504505
showcaseView.setOnShowcaseEventListener(showcaseEventListener);
505506
return this;
506507
}
508+
509+
public Builder setContentTextPaint(TextPaint textPaint) {
510+
showcaseView.setContentTextPaint(textPaint);
511+
return this;
512+
}
513+
514+
public Builder setContentTitlePaint(TextPaint textPaint) {
515+
showcaseView.setContentTitlePaint(textPaint);
516+
return this;
517+
}
518+
}
519+
520+
private void setContentTitlePaint(TextPaint textPaint) {
521+
this.textDrawer.setTitlePaint(textPaint);
522+
hasAlteredText = true;
523+
invalidate();
524+
}
525+
526+
private void setContentTextPaint(TextPaint paint) {
527+
this.textDrawer.setContentPaint(paint);
528+
hasAlteredText = true;
529+
invalidate();
507530
}
508531

509532
/**

library/src/main/java/com/github/amlcurran/showcaseview/TextDrawer.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,12 @@ public float[] getBestTextPosition() {
214214
public boolean shouldDrawText() {
215215
return !TextUtils.isEmpty(mTitle) || !TextUtils.isEmpty(mDetails);
216216
}
217+
218+
public void setContentPaint(TextPaint contentPaint) {
219+
textPaint.set(contentPaint);
220+
}
221+
222+
public void setTitlePaint(TextPaint textPaint) {
223+
titlePaint.set(textPaint);
224+
}
217225
}

sample/src/main/AndroidManifest.xml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,12 @@
3333
<category android:name="android.intent.category.LAUNCHER" />
3434
</intent-filter>
3535
</activity>
36-
<activity
37-
android:name=".v14.ActionItemsSampleActivity"
38-
android:theme="@style/SampleTheme" />
39-
<!--<activity-->
40-
<!--android:name=".v14.MultipleActionItemsSampleActivity"-->
41-
<!--android:theme="@style/SampleTheme"/>-->
42-
<!--<activity-->
43-
<!--android:name=".legacy.MultipleShowcaseSampleActivity"/>-->
36+
4437
<activity android:name=".animations.AnimationSampleActivity" />
4538

4639
<activity android:name=".SingleShotActivity" />
4740

48-
<!--<activity android:name=".MemoryManagementTesting" />-->
41+
<activity android:name=".CustomTextActivity" />
42+
4943
</application>
5044
</manifest>
118 KB
Binary file not shown.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.github.amlcurran.showcaseview.sample;
2+
3+
import android.app.Activity;
4+
import android.graphics.Paint;
5+
import android.graphics.Typeface;
6+
import android.os.Bundle;
7+
import android.text.TextPaint;
8+
9+
import com.github.amlcurran.showcaseview.ShowcaseView;
10+
import com.github.amlcurran.showcaseview.targets.ViewTarget;
11+
12+
public class CustomTextActivity extends Activity {
13+
14+
@Override
15+
protected void onCreate(Bundle savedInstanceState) {
16+
super.onCreate(savedInstanceState);
17+
setContentView(R.layout.activity_custom_text);
18+
19+
TextPaint paint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
20+
paint.setTextSize(getResources().getDimension(R.dimen.abc_text_size_body_1_material));
21+
paint.setStrikeThruText(true);
22+
paint.setTypeface(Typeface.createFromAsset(getAssets(), "RobotoSlab-Regular.ttf"));
23+
24+
TextPaint title = new TextPaint(Paint.ANTI_ALIAS_FLAG);
25+
title.setTextSize(getResources().getDimension(R.dimen.abc_text_size_headline_material));
26+
title.setUnderlineText(true);
27+
title.setTypeface(Typeface.createFromAsset(getAssets(), "RobotoSlab-Regular.ttf"));
28+
29+
new ShowcaseView.Builder(this)
30+
.setTarget(new ViewTarget(R.id.imageView, this))
31+
.setContentTitle(R.string.custom_text_painting_title)
32+
.setContentText(R.string.custom_text_painting_text)
33+
.setContentTextPaint(paint)
34+
.setContentTitlePaint(title)
35+
.build();
36+
}
37+
}

sample/src/main/java/com/github/amlcurran/showcaseview/sample/SampleActivity.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public void onItemClick(AdapterView<?> adapterView, View view, int position, lon
139139

140140
// Not currently used
141141
case 3:
142-
startActivity(new Intent(this, MemoryManagementTesting.class));
142+
startActivity(new Intent(this, CustomTextActivity.class));
143143
}
144144
}
145145

@@ -148,13 +148,15 @@ private static class HardcodedListAdapter extends ArrayAdapter {
148148
private static final int[] TITLE_RES_IDS = new int[] {
149149
R.string.title_action_items,
150150
R.string.title_animations,
151-
R.string.title_single_shot//, R.string.title_memory
151+
R.string.title_single_shot,
152+
R.string.custom_text //, R.string.title_memory
152153
};
153154

154155
private static final int[] SUMMARY_RES_IDS = new int[] {
155156
R.string.sum_action_items,
156157
R.string.sum_animations,
157-
R.string.sum_single_shot//, R.string.sum_memory
158+
R.string.sum_single_shot,
159+
R.string.custom_text_summary//, R.string.sum_memory
158160
};
159161

160162
public HardcodedListAdapter(Context context) {

sample/src/main/res/layout/activity_animation.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
~ limitations under the License.
1717
-->
1818

19-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
19+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
2020
android:orientation="vertical" android:layout_width="match_parent"
2121
android:layout_height="match_parent"
2222
android:padding="16dp">
@@ -51,4 +51,4 @@
5151
android:layout_marginBottom="72dp"
5252
android:singleLine="false"
5353
android:layout_alignParentBottom="true" />
54-
</RelativeLayout>
54+
</LinearLayout>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:orientation="vertical"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent">
6+
7+
<ImageView
8+
android:layout_width="wrap_content"
9+
android:layout_height="wrap_content"
10+
android:id="@+id/imageView"
11+
android:layout_gravity="center_horizontal"
12+
android:src="@drawable/ic_launcher"
13+
android:layout_centerVertical="true"
14+
android:layout_centerHorizontal="true"/>
15+
</RelativeLayout>

sample/src/main/res/values/strings.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,8 @@
6161
<string name="title_single_shot">Single shot</string>
6262
<string name="sum_single_shot">Demonstrate how to make a ShowcaseView show only once</string>
6363
<string name="R.string.desc_single_shot">Press the OK button and you\'ll only ever see this ShowcaseView once. To see it again, clear the app\'s cache.</string>
64+
<string name="custom_text">Custom text</string>
65+
<string name="custom_text_summary">See how to create custom text drawing</string>
66+
<string name="custom_text_painting_title">Custom text painting</string>
67+
<string name="custom_text_painting_text">Here\'s an example of custom text painting</string>
6468
</resources>

0 commit comments

Comments
 (0)