Skip to content

Commit 6917ac0

Browse files
committed
Merge pull request amlcurran#311 from amlcurran/fix-clipping-appcomapt
Fixes for appcompat
2 parents 9b1ced6 + 8779ae5 commit 6917ac0

File tree

13 files changed

+172
-63
lines changed

13 files changed

+172
-63
lines changed

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
# limitations under the License.
1515
#
1616

17-
VERSION_CODE=50204
18-
VERSION_NAME=5.2.4
17+
VERSION_CODE=50300
18+
VERSION_NAME=5.3.0
1919
GROUP=com.github.amlcurran.showcaseview
2020

2121
POM_DESCRIPTION=Highlight the best bits of your app to users quickly, simply, and cool...ly

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616

1717
package com.github.amlcurran.showcaseview;
1818

19-
import android.annotation.TargetApi;
2019
import android.os.Build;
21-
import android.view.View;
2220

2321
public class ApiUtils {
2422

@@ -30,10 +28,4 @@ public boolean isCompatWithHoneycomb() {
3028
return isCompatWith(Build.VERSION_CODES.HONEYCOMB);
3129
}
3230

33-
@TargetApi(14)
34-
public void setFitsSystemWindowsCompat(View view) {
35-
if (isCompatWith(Build.VERSION_CODES.ICE_CREAM_SANDWICH)) {
36-
view.setFitsSystemWindows(true);
37-
}
38-
}
3931
}

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public class ShowcaseView extends RelativeLayout
8484
private int backgroundColor;
8585
private int showcaseColor;
8686
private boolean blockAllTouches;
87+
private final int[] positionInWindow = new int[2];
8788

8889
protected ShowcaseView(Context context, boolean newStyle) {
8990
this(context, null, R.styleable.CustomTheme_showcaseViewStyle, newStyle);
@@ -97,7 +98,6 @@ protected ShowcaseView(Context context, AttributeSet attrs, int defStyle, boolea
9798
showcaseAreaCalculator = new ShowcaseAreaCalculator();
9899
shotStateStore = new ShotStateStore(context);
99100

100-
apiUtils.setFitsSystemWindowsCompat(this);
101101
getViewTreeObserver().addOnPreDrawListener(new CalculateTextOnPreDraw());
102102
getViewTreeObserver().addOnGlobalLayoutListener(new UpdateOnGlobalLayout());
103103

@@ -155,8 +155,9 @@ void setShowcasePosition(int x, int y) {
155155
if (shotStateStore.hasShot()) {
156156
return;
157157
}
158-
showcaseX = x;
159-
showcaseY = y;
158+
getLocationInWindow(positionInWindow);
159+
showcaseX = x - positionInWindow[0];
160+
showcaseY = y - positionInWindow[1];
160161
//init();
161162
invalidate();
162163
}
@@ -420,9 +421,8 @@ public Builder(Activity activity, boolean useNewStyle) {
420421
this.activity = activity;
421422
this.showcaseView = new ShowcaseView(activity, useNewStyle);
422423
this.showcaseView.setTarget(Target.NONE);
423-
424-
this.parent = ((ViewGroup) activity.getWindow().getDecorView());
425-
this.parentIndex = -1;
424+
this.parent = (ViewGroup) activity.findViewById(android.R.id.content);
425+
this.parentIndex = parent.getChildCount();
426426
}
427427

428428
/**
@@ -618,6 +618,15 @@ public Builder blockAllTouches() {
618618
return this;
619619
}
620620

621+
/**
622+
* Uses the android decor view to insert a showcase, this is not recommended
623+
* as then UI elements in showcase view can hide behind the nav bar
624+
*/
625+
public Builder useDecorViewAsParent() {
626+
this.parent = ((ViewGroup) activity.getWindow().getDecorView());
627+
this.parentIndex = -1;
628+
return this;
629+
}
621630
}
622631

623632
private void setEndButton(Button button) {

sample/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ apply plugin: 'com.android.application'
3636
dependencies {
3737
compile project(':library')
3838
//compile 'com.github.amlcurran.showcaseview:library:5.0.0-SNAPSHOT'
39-
compile 'com.android.support:support-v4:23.0.1'
39+
compile 'com.android.support:support-v4:23.1.0'
4040
compile 'com.nineoldandroids:library:2.4.0'
41-
compile 'com.android.support:appcompat-v7:23.0.1'
41+
compile 'com.android.support:appcompat-v7:23.1.0'
4242
}
4343

4444
android {

sample/src/main/AndroidManifest.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020

2121
<application
2222
android:label="@string/app_name"
23+
android:theme="@style/AppTheme"
2324
android:icon="@drawable/ic_launcher"
2425
android:allowBackup="true">
2526

2627
<activity
2728
android:name=".SampleActivity"
2829
android:label="@string/app_name"
29-
android:theme="@style/CompatDarkActionBarTheme"
3030
android:logo="@drawable/ic_logo">
3131
<intent-filter>
3232
<action android:name="android.intent.action.MAIN" />
@@ -42,5 +42,7 @@
4242

4343
<activity android:name=".CustomShowcaseActivity" />
4444

45+
<activity android:name=".ActionItemsSampleActivity" />
46+
4547
</application>
4648
</manifest>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.github.amlcurran.showcaseview.sample;
2+
3+
import android.os.Bundle;
4+
import android.support.annotation.Nullable;
5+
import android.support.v7.app.AppCompatActivity;
6+
import android.support.v7.widget.Toolbar;
7+
import android.view.Menu;
8+
9+
import com.github.amlcurran.showcaseview.ShowcaseView;
10+
11+
public class ActionItemsSampleActivity extends AppCompatActivity {
12+
13+
@Override
14+
protected void onCreate(@Nullable Bundle savedInstanceState) {
15+
super.onCreate(savedInstanceState);
16+
setContentView(R.layout.activity_action_items);
17+
Toolbar viewById = (Toolbar) findViewById(R.id.toolbar);
18+
setSupportActionBar(viewById);
19+
20+
new ShowcaseView.Builder(this)
21+
.withMaterialShowcase()
22+
.setTarget(new ToolbarActionItemTarget(viewById, R.id.menu_item1))
23+
.setStyle(R.style.CustomShowcaseTheme2)
24+
.setContentText("Here's how to highlight items on a toolbar")
25+
.build()
26+
.show();
27+
}
28+
29+
@Override
30+
public boolean onCreateOptionsMenu(Menu menu) {
31+
getMenuInflater().inflate(R.menu.menu, menu);
32+
return super.onCreateOptionsMenu(menu);
33+
}
34+
}

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
@@ -17,11 +17,12 @@
1717
package com.github.amlcurran.showcaseview.sample;
1818

1919
import android.annotation.TargetApi;
20-
import android.app.Activity;
2120
import android.content.Context;
2221
import android.content.Intent;
2322
import android.os.Build;
2423
import android.os.Bundle;
24+
import android.support.v7.app.AppCompatActivity;
25+
import android.support.v7.widget.Toolbar;
2526
import android.view.LayoutInflater;
2627
import android.view.View;
2728
import android.view.ViewGroup;
@@ -38,7 +39,7 @@
3839
import com.github.amlcurran.showcaseview.sample.animations.AnimationSampleActivity;
3940
import com.github.amlcurran.showcaseview.targets.ViewTarget;
4041

41-
public class SampleActivity extends Activity implements View.OnClickListener,
42+
public class SampleActivity extends AppCompatActivity implements View.OnClickListener,
4243
OnShowcaseEventListener, AdapterView.OnItemClickListener {
4344

4445
private static final float ALPHA_DIM_VALUE = 0.1f;
@@ -53,6 +54,7 @@ public class SampleActivity extends Activity implements View.OnClickListener,
5354
public void onCreate(Bundle savedInstanceState) {
5455
super.onCreate(savedInstanceState);
5556
setContentView(R.layout.main);
57+
setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
5658

5759
HardcodedListAdapter adapter = new HardcodedListAdapter(this);
5860
listView = (ListView) findViewById(R.id.listView);
@@ -127,7 +129,7 @@ public void onShowcaseViewShow(ShowcaseView showcaseView) {
127129
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
128130
switch (position) {
129131
case 0:
130-
//startActivity(new Intent(this, ActionItemsSampleActivity.class));
132+
startActivity(new Intent(this, ActionItemsSampleActivity.class));
131133
break;
132134
case 1:
133135
startActivity(new Intent(this, AnimationSampleActivity.class));
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2014 Alex Curran
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.github.amlcurran.showcaseview.sample;
18+
19+
import android.graphics.Point;
20+
import android.support.annotation.IdRes;
21+
import android.support.v7.widget.Toolbar;
22+
23+
import com.github.amlcurran.showcaseview.targets.Target;
24+
import com.github.amlcurran.showcaseview.targets.ViewTarget;
25+
26+
/**
27+
* Represents an Action item to showcase (e.g., one of the buttons on an ActionBar).
28+
* To showcase specific action views such as the home button, use {@link ToolbarActionItemTarget}
29+
*
30+
* @see ToolbarActionItemTarget
31+
*/
32+
public class ToolbarActionItemTarget implements Target {
33+
34+
private final Toolbar toolbar;
35+
private final int menuItemId;
36+
37+
public ToolbarActionItemTarget(Toolbar toolbar, @IdRes int itemId) {
38+
this.toolbar = toolbar;
39+
this.menuItemId = itemId;
40+
}
41+
42+
@Override
43+
public Point getPoint() {
44+
return new ViewTarget(toolbar.findViewById(menuItemId)).getPoint();
45+
}
46+
47+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<!--
2+
~ Copyright 2014 Alex Curran
3+
~
4+
~ Licensed under the Apache License, Version 2.0 (the "License");
5+
~ you may not use this file except in compliance with the License.
6+
~ You may obtain a copy of the License at
7+
~
8+
~ http://www.apache.org/licenses/LICENSE-2.0
9+
~
10+
~ Unless required by applicable law or agreed to in writing, software
11+
~ distributed under the License is distributed on an "AS IS" BASIS,
12+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
~ See the License for the specific language governing permissions and
14+
~ limitations under the License.
15+
-->
16+
17+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
18+
android:layout_width="fill_parent"
19+
android:layout_height="fill_parent"
20+
xmlns:app="http://schemas.android.com/apk/res-auto"
21+
android:orientation="vertical">
22+
23+
<android.support.v7.widget.Toolbar
24+
android:layout_width="match_parent"
25+
android:id="@+id/toolbar"
26+
app:theme="@style/Toolbar"
27+
android:layout_height="wrap_content"/>
28+
29+
<Button
30+
android:id="@+id/buttonBlocked"
31+
android:layout_width="wrap_content"
32+
android:layout_height="wrap_content"
33+
android:text="Button"
34+
android:minWidth="96dp"
35+
android:layout_margin="16dp"
36+
android:layout_gravity="center" />
37+
38+
</LinearLayout>

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
android:layout_height="fill_parent"
2020
android:orientation="vertical">
2121

22+
<android.support.v7.widget.Toolbar
23+
android:layout_width="match_parent"
24+
android:id="@+id/toolbar"
25+
android:layout_height="wrap_content"/>
26+
2227
<Button
2328
android:id="@+id/buttonBlocked"
2429
android:layout_width="wrap_content"

0 commit comments

Comments
 (0)