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

Commit

Permalink
Merge pull request #311 from amlcurran/fix-clipping-appcomapt
Browse files Browse the repository at this point in the history
Fixes for appcompat
  • Loading branch information
amlcurran committed Nov 2, 2015
2 parents 9b1ced6 + 8779ae5 commit 6917ac0
Show file tree
Hide file tree
Showing 13 changed files with 172 additions and 63 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
# limitations under the License.
#

VERSION_CODE=50204
VERSION_NAME=5.2.4
VERSION_CODE=50300
VERSION_NAME=5.3.0
GROUP=com.github.amlcurran.showcaseview

POM_DESCRIPTION=Highlight the best bits of your app to users quickly, simply, and cool...ly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@

package com.github.amlcurran.showcaseview;

import android.annotation.TargetApi;
import android.os.Build;
import android.view.View;

public class ApiUtils {

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

@TargetApi(14)
public void setFitsSystemWindowsCompat(View view) {
if (isCompatWith(Build.VERSION_CODES.ICE_CREAM_SANDWICH)) {
view.setFitsSystemWindows(true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public class ShowcaseView extends RelativeLayout
private int backgroundColor;
private int showcaseColor;
private boolean blockAllTouches;
private final int[] positionInWindow = new int[2];

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

apiUtils.setFitsSystemWindowsCompat(this);
getViewTreeObserver().addOnPreDrawListener(new CalculateTextOnPreDraw());
getViewTreeObserver().addOnGlobalLayoutListener(new UpdateOnGlobalLayout());

Expand Down Expand Up @@ -155,8 +155,9 @@ void setShowcasePosition(int x, int y) {
if (shotStateStore.hasShot()) {
return;
}
showcaseX = x;
showcaseY = y;
getLocationInWindow(positionInWindow);
showcaseX = x - positionInWindow[0];
showcaseY = y - positionInWindow[1];
//init();
invalidate();
}
Expand Down Expand Up @@ -420,9 +421,8 @@ public Builder(Activity activity, boolean useNewStyle) {
this.activity = activity;
this.showcaseView = new ShowcaseView(activity, useNewStyle);
this.showcaseView.setTarget(Target.NONE);

this.parent = ((ViewGroup) activity.getWindow().getDecorView());
this.parentIndex = -1;
this.parent = (ViewGroup) activity.findViewById(android.R.id.content);
this.parentIndex = parent.getChildCount();
}

/**
Expand Down Expand Up @@ -618,6 +618,15 @@ public Builder blockAllTouches() {
return this;
}

/**
* Uses the android decor view to insert a showcase, this is not recommended
* as then UI elements in showcase view can hide behind the nav bar
*/
public Builder useDecorViewAsParent() {
this.parent = ((ViewGroup) activity.getWindow().getDecorView());
this.parentIndex = -1;
return this;
}
}

private void setEndButton(Button button) {
Expand Down
4 changes: 2 additions & 2 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ apply plugin: 'com.android.application'
dependencies {
compile project(':library')
//compile 'com.github.amlcurran.showcaseview:library:5.0.0-SNAPSHOT'
compile 'com.android.support:support-v4:23.0.1'
compile 'com.android.support:support-v4:23.1.0'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:appcompat-v7:23.1.0'
}

android {
Expand Down
4 changes: 3 additions & 1 deletion sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@

<application
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:icon="@drawable/ic_launcher"
android:allowBackup="true">

<activity
android:name=".SampleActivity"
android:label="@string/app_name"
android:theme="@style/CompatDarkActionBarTheme"
android:logo="@drawable/ic_logo">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand All @@ -42,5 +42,7 @@

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

<activity android:name=".ActionItemsSampleActivity" />

</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.github.amlcurran.showcaseview.sample;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;

import com.github.amlcurran.showcaseview.ShowcaseView;

public class ActionItemsSampleActivity extends AppCompatActivity {

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_action_items);
Toolbar viewById = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(viewById);

new ShowcaseView.Builder(this)
.withMaterialShowcase()
.setTarget(new ToolbarActionItemTarget(viewById, R.id.menu_item1))
.setStyle(R.style.CustomShowcaseTheme2)
.setContentText("Here's how to highlight items on a toolbar")
.build()
.show();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu, menu);
return super.onCreateOptionsMenu(menu);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
package com.github.amlcurran.showcaseview.sample;

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -38,7 +39,7 @@
import com.github.amlcurran.showcaseview.sample.animations.AnimationSampleActivity;
import com.github.amlcurran.showcaseview.targets.ViewTarget;

public class SampleActivity extends Activity implements View.OnClickListener,
public class SampleActivity extends AppCompatActivity implements View.OnClickListener,
OnShowcaseEventListener, AdapterView.OnItemClickListener {

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

HardcodedListAdapter adapter = new HardcodedListAdapter(this);
listView = (ListView) findViewById(R.id.listView);
Expand Down Expand Up @@ -127,7 +129,7 @@ public void onShowcaseViewShow(ShowcaseView showcaseView) {
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
switch (position) {
case 0:
//startActivity(new Intent(this, ActionItemsSampleActivity.class));
startActivity(new Intent(this, ActionItemsSampleActivity.class));
break;
case 1:
startActivity(new Intent(this, AnimationSampleActivity.class));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2014 Alex Curran
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.github.amlcurran.showcaseview.sample;

import android.graphics.Point;
import android.support.annotation.IdRes;
import android.support.v7.widget.Toolbar;

import com.github.amlcurran.showcaseview.targets.Target;
import com.github.amlcurran.showcaseview.targets.ViewTarget;

/**
* Represents an Action item to showcase (e.g., one of the buttons on an ActionBar).
* To showcase specific action views such as the home button, use {@link ToolbarActionItemTarget}
*
* @see ToolbarActionItemTarget
*/
public class ToolbarActionItemTarget implements Target {

private final Toolbar toolbar;
private final int menuItemId;

public ToolbarActionItemTarget(Toolbar toolbar, @IdRes int itemId) {
this.toolbar = toolbar;
this.menuItemId = itemId;
}

@Override
public Point getPoint() {
return new ViewTarget(toolbar.findViewById(menuItemId)).getPoint();
}

}
38 changes: 38 additions & 0 deletions sample/src/main/res/layout/activity_action_items.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!--
~ Copyright 2014 Alex Curran
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">

<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:id="@+id/toolbar"
app:theme="@style/Toolbar"
android:layout_height="wrap_content"/>

<Button
android:id="@+id/buttonBlocked"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:minWidth="96dp"
android:layout_margin="16dp"
android:layout_gravity="center" />

</LinearLayout>
5 changes: 5 additions & 0 deletions sample/src/main/res/layout/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
android:layout_height="fill_parent"
android:orientation="vertical">

<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:id="@+id/toolbar"
android:layout_height="wrap_content"/>

<Button
android:id="@+id/buttonBlocked"
android:layout_width="wrap_content"
Expand Down
20 changes: 12 additions & 8 deletions sample/src/main/res/menu/menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@
~ limitations under the License.
-->

<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/menu_item1"
android:icon="@drawable/ic_edit"
android:title="item1"
android:showAsAction="always"/>
<item android:id="@+id/menu_item2"
android:icon="@drawable/ic_discard"
android:title="Showcase title"/>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_item1"
android:icon="@drawable/ic_edit"
android:title="item1"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/menu_item2"
android:icon="@drawable/ic_discard"
android:title="Showcase title"
app:showAsAction="ifRoom"/>
</menu>
24 changes: 0 additions & 24 deletions sample/src/main/res/values-v14/styles.xml

This file was deleted.

18 changes: 9 additions & 9 deletions sample/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@

<resources>

<style name="CompatDarkActionBarTheme" parent="android:Theme.Holo.Light" />
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#3973cf</item>
<item name="colorPrimaryDark">#3365b5</item>
</style>

<style name="Toolbar">
<item name="android:background">?attr/colorPrimary</item>
<item name="theme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
</style>

<style name="CustomShowcaseTheme" parent="ShowcaseView.Light">
<item name="sv_backgroundColor">#3300A621</item>
Expand All @@ -42,14 +50,6 @@
<item name="sv_titleTextAppearance">@style/CustomTitle</item>
</style>

<style name="SampleTheme" parent="Theme.AppCompat.Light">
<item name="showcaseViewStyle">@style/CustomShowcaseTheme</item>
</style>

<style name="SampleTheme2" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="showcaseViewStyle">@style/CustomShowcaseTheme2</item>
</style>

<style name="CustomTitle" parent="TextAppearance.ShowcaseView.Title">
<item name="android:textColor">#00801A</item>
</style>
Expand Down

0 comments on commit 6917ac0

Please sign in to comment.