Skip to content

Commit

Permalink
fixed show called before onAttached
Browse files Browse the repository at this point in the history
  • Loading branch information
Il committed Nov 4, 2015
1 parent b65d359 commit 77ffa50
Show file tree
Hide file tree
Showing 12 changed files with 198 additions and 123 deletions.
36 changes: 12 additions & 24 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,48 +1,36 @@
language: android

jdk:
- openjdk7

branches:
only:
- master

notifications:
email: true

before_install:

# environment info
- ./gradlew -v
- uname -a

# for gradle output style
- export TERM=dumb

# just to test gradle version, against our provided one
- ./gradlew -v

# Install required components.
# For a full list, run `android list sdk -a --extended`
- echo yes | android update sdk --filter platform-tools --no-ui --force > /dev/null
- echo yes | android update sdk --all --filter build-tools-23.0.0 --no-ui --force > /dev/null
- echo yes | android update sdk --filter android-19 --no-ui --force > /dev/null
- echo yes | android update sdk --filter extra-android-m2repository --no-ui --force > /dev/null

# Otherwise
#- echo yes | android update sdk -t tools,platform-tools,extra-android-support,extra-android-m2repository,android-19 --force --no-ui
# Turn off caching to avoid any caching problems
cache: false
# Use the Travis Container-Based Infrastructure (see #203)
sudo: false

android:
components:
- build-tools-23.0.0
- android-22
- extra-google-google_play_services
- extra-google-m2repository
- extra-android-m2repository
- sys-img-armeabi-v7a-android-19
- extra-android-support
licenses:
- android-sdk-license-bcbbd656
- '.*intel.+'


# Let's try to build...
install: ./gradlew clean build
install:
- chmod +x ./gradlew; ls -l gradlew; ./gradlew wrapper -v

script: ./gradlew check
script:
- ./gradlew clean assembleDebug
3 changes: 2 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':library')
compile 'com.android.support:appcompat-v7:22.+'
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:design:22.2.1'

debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@
import android.graphics.Point;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.ActionBarActivity;
import android.support.design.widget.TabLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import it.sephiroth.android.library.tooltip.TooltipManager;

public class MainActivity2 extends ActionBarActivity implements View.OnClickListener, TooltipManager.onTooltipClosingCallback {
public class MainActivity2 extends AppCompatActivity implements View.OnClickListener, TooltipManager.onTooltipClosingCallback {
private static final String TAG = MainActivity2.class.getSimpleName();
Button mButton1;
Button mButton2;
Expand All @@ -37,6 +40,43 @@ protected void onCreate(Bundle savedInstanceState) {
mButton3.setOnClickListener(this);
mButton4.setOnClickListener(this);
mButton5.setOnClickListener(this);

setSupportActionBar((Toolbar) findViewById(R.id.toolbar));

TabLayout tablayout = (TabLayout) findViewById(R.id.tabs);
tablayout.addTab(tablayout.newTab().setText("First"));
tablayout.addTab(tablayout.newTab().setText("Second"));

test();
}

private void test() {
TabLayout tablayout = (TabLayout) findViewById(R.id.tabs);
final ViewGroup root = (ViewGroup) tablayout.getChildAt(0);
final View tab = root.getChildAt(1);

// if (tab.getWidth() <= 1) {
//
// tab.getViewTreeObserver().addOnGlobalLayoutListener(
// new ViewTreeObserver.OnGlobalLayoutListener() {
// @Override
// public void onGlobalLayout() {
// test();
// tab.getViewTreeObserver().removeOnGlobalLayoutListener(this);
// }
// });
// return;
// }

TooltipManager.getInstance().create(this, 111222)
.anchor(tab, TooltipManager.Gravity.BOTTOM)
.actionBarSize(Utils.getActionBarSize(getBaseContext()))
.closePolicy(TooltipManager.ClosePolicy.TouchOutside, 0)
.text(R.string.hello_world)
.toggleArrow(true)
.maxWidth(400)
.withStyleId(R.style.ToolTipLayoutDefaultStyle_TextColor1)
.show();
}

@Override
Expand Down
120 changes: 77 additions & 43 deletions app/src/main/res/layout/activity_main_activity2.xml
Original file line number Diff line number Diff line change
@@ -1,44 +1,78 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:gravity="center"
tools:context="it.sephiroth.android.library.mymodule.app.MainActivity2">

<Button
android:id="@+id/button1"
android:text="Touch Outside"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<Button
android:id="@+id/button2"
android:text="Touch Inside"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<Button
android:id="@+id/button3"
android:text="Outside Exclusive"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<Button
android:id="@+id/button4"
android:text="Custom View"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />


<Button
android:id="@+id/button5"
android:text="Custom Background"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

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

<android.support.design.widget.AppBarLayout
android:id="@+id/activity_main_app_bar"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="6dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
tools:ignore="UnusedAttribute">

<!-- The toolbar -->
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:minHeight="?attr/actionBarSize" />

<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed" />

</android.support.design.widget.AppBarLayout>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="it.sephiroth.android.library.mymodule.app.MainActivity2">

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Touch Outside" />

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Touch Inside" />

<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Outside Exclusive" />

<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Custom View" />


<Button
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Custom Background" />

</LinearLayout>
</LinearLayout>
12 changes: 3 additions & 9 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
<resources>

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

<!-- set the default style to be used with all the tooltips -->
<!--
<item name="ttlm_defaultStyle">@style/ToolTipLayoutCustomStyle</item>
-->

<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>

<style name="ToolTipLayoutCustomStyle">
Expand All @@ -17,8 +13,6 @@
<item name="ttlm_cornerRadius">8dip</item>
</style>

<style name="ToolTipLayoutDefaultStyle.TextColor1" parent="ToolTipLayoutDefaultStyle">
<item name="android:textAppearance">@style/TextAppearance.AppCompat.Large.Inverse</item>
</style>
<style name="ToolTipLayoutDefaultStyle.TextColor1" parent="ToolTipLayoutDefaultStyle"></style>

</resources>
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
VERSION_NAME=1.3.0-SNAPSHOT
VERSION_CODE=28
VERSION_NAME=1.3.0
VERSION_CODE=30
GROUP=it.sephiroth.android.library.targettooltip

POM_DESCRIPTION=Custom tooltips for android
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Nov 04 13:15:33 EST 2015
#Wed Nov 04 14:36:14 EST 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PixelFormat;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.RectF;
Expand Down Expand Up @@ -67,7 +69,7 @@ public TooltipTextDrawable(final Context context, final TooltipManager.Builder b

void calculatePath(Rect outBounds) {
if (DBG) {
Log.i(TAG, "calculateBounds, padding: " + padding + ", gravity: " + gravity);
Log.i(TAG, "calculatePath, padding: " + padding + ", gravity: " + gravity + ", bounds: " + getBounds());
}

int left = outBounds.left + padding;
Expand All @@ -81,14 +83,9 @@ void calculatePath(Rect outBounds) {
final float min_x = left + ellipseSize;

if (DBG) {
Log.v(TAG, "left: " + left);
Log.v(TAG, "top: " + top);
Log.v(TAG, "right: " + right);
Log.v(TAG, "bottom: " + bottom);
Log.v(TAG, "min_y: " + min_y);
Log.v(TAG, "max_y: " + max_y);
Log.v(TAG, "arrowWeight: " + arrowWeight);
Log.v(TAG, "point: " + point);
Log.v(TAG, "rect(" + left + ", " + top + ", " + right + ", " + bottom + ")");
Log.v(TAG, "min_y: " + min_y + ", max_y: " + max_y);
Log.v(TAG, "arrowWeight: " + arrowWeight + ", point: " + point);
}

boolean drawPoint = false;
Expand Down Expand Up @@ -187,7 +184,6 @@ void calculatePath(Rect outBounds) {

@Override
public void draw(final Canvas canvas) {

if (null != bgPaint) {
canvas.drawPath(path, bgPaint);
}
Expand All @@ -200,7 +196,7 @@ public void draw(final Canvas canvas) {
@Override
protected void onBoundsChange(final Rect bounds) {
if (DBG) {
Log.i(TAG, "onBoundsChange");
Log.i(TAG, "onBoundsChange: " + bounds);
}
super.onBoundsChange(bounds);
calculatePath(bounds);
Expand All @@ -216,11 +212,15 @@ public void setColorFilter(final ColorFilter cf) {

@Override
public int getOpacity() {
return 0;
return PixelFormat.TRANSLUCENT;
}

public void setAnchor(final TooltipManager.Gravity gravity, int padding, @Nullable Point point) {
if (gravity != this.gravity || padding != this.padding || pointEquals(this.point, point)) {
if (DBG) {
Log.i(TAG, "setAnchor:" + gravity + ", padding: " + padding + ", point: " + point);
}

if (gravity != this.gravity || padding != this.padding || !pointEquals(this.point, point)) {
this.gravity = gravity;
this.padding = padding;
this.arrowWeight = (int) ((float) padding / arrowRatio);
Expand All @@ -232,6 +232,7 @@ public void setAnchor(final TooltipManager.Gravity gravity, int padding, @Nullab
}

calculatePath(getBounds());
invalidateSelf();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import java.util.WeakHashMap;

public class TooltipManager {
static final boolean DBG = false;
public static boolean DBG = false;
private static final String TAG = "TooltipManager";
private volatile static TooltipManager INSTANCE;

Expand Down
Loading

0 comments on commit 77ffa50

Please sign in to comment.