Skip to content

add new property named alignment #90

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Tooltip style can be customized in your style object:
<attr name="android:textAppearance" />
<attr name="ttlm_overlayStyle" format="reference" />
<attr name="ttlm_elevation" format="dimension" />
<attr name="ttlm_margin" format="dimension" />

<!-- font file path inside your assets folder -->
<attr name="ttlm_font" format="string" />
Expand Down
28 changes: 16 additions & 12 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion ANDROID_BUILD_SDK_VERSION as int
buildToolsVersion ANDROID_BUILD_TOOLS_VERSION

defaultConfig {
minSdkVersion 14
minSdkVersion 16
targetSdkVersion ANDROID_BUILD_TARGET_SDK_VERSION as int
versionCode 1
versionName VERSION_NAME

jackOptions {
enabled false
}
// jackOptions {
// enabled false
// }
}
buildTypes {
release {
Expand All @@ -22,8 +23,8 @@ android {
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

lintOptions {
Expand All @@ -38,12 +39,15 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':library')
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.android.support:design:24.1.1'
compile 'com.android.support:recyclerview-v7:24.1.1'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':neofecttooltip')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"

implementation "com.android.support:appcompat-v7:$ANDROID_BUILD_TOOLS_VERSION"
implementation "com.android.support:design:$ANDROID_BUILD_TOOLS_VERSION"
implementation "com.android.support:recyclerview-v7:$ANDROID_BUILD_TOOLS_VERSION"

implementation 'com.jakewharton.timber:timber:4.7.1'
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1'
}
10 changes: 10 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@
android:label="@string/app_name"
android:theme="@style/AppTheme">

<activity
android:name=".MainActivity"
android:label="@string/title_activity_main_activity3"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name=".MainActivity2"
android:label="@string/title_activity_main_activity2"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package it.sephiroth.android.library.mymodule.app;

import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import it.sephiroth.android.library.xtooltip.ClosePolicy
import it.sephiroth.android.library.xtooltip.XTooltip
import it.sephiroth.android.library.xtooltip.Typefaces
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.content_main.*
import timber.log.Timber

class MainActivity : AppCompatActivity() {
var tooltip: XTooltip? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
setSupportActionBar(toolbar)

val metrics = resources.displayMetrics

button1.setOnClickListener { button ->

val gravity = XTooltip.Gravity.valueOf(spinner_gravities.selectedItem.toString())
val closePolicy = getClosePolicy()
val typeface = if (checkbox_font.isChecked) Typefaces[this, "fonts/at.ttc"] else null
val animation = if (checkbox_animation.isChecked) XTooltip.Animation.DEFAULT else null
val showDuration = if (text_duration.text.isNullOrEmpty()) 0 else text_duration.text.toString().toLong()
val fadeDuration = if (text_fade.text.isNullOrEmpty()) 0 else text_fade.text.toString().toLong()
val arrow = checkbox_arrow.isChecked
val overlay = checkbox_overlay.isChecked
val style = if (checkbox_style.isChecked) R.style.ToolTipAltStyle else null
val text =
if (text_tooltip.text.isNullOrEmpty()) "Lorem ipsum dolor" else text_tooltip.text!!.toString()

Timber.v("gravity: $gravity")
Timber.v("closePolicy: $closePolicy")

tooltip = XTooltip.Builder(this)
.anchor(button, 0, 0, false)
.text(text)
.styleId(style)
.typeface(typeface)
.maxWidth(metrics.widthPixels / 2)
.arrow(arrow)
.floatingAnimation(animation)
.closePolicy(closePolicy)
.showDuration(showDuration)
.fadeDuration(fadeDuration)
.overlay(overlay)
.create()

tooltip
?.doOnHidden {
tooltip = null
}
?.doOnFailure { }
?.doOnShown {}
?.show(button, gravity, true)
}

button2.setOnClickListener {
val fragment = TestDialogFragment.newInstance()
fragment.show(supportFragmentManager, "test_dialog_fragment")
}
}

private fun getClosePolicy(): ClosePolicy {
val builder = ClosePolicy.Builder()
builder.inside(switch1.isChecked)
builder.outside(switch3.isChecked)
builder.consume(switch2.isChecked)
return builder.build()
}

override fun onDestroy() {
Timber.i("onDestroy")
super.onDestroy()
tooltip?.dismiss()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ public void onClick(final View v) {
.activateDelay(2000)
.maxWidth(metrics.widthPixels / 2)
.withCallback(this)
.alignment(Tooltip.Alignment.BOTTOM)
.floatingAnimation(AnimationBuilder.DEFAULT)
.build()
).show();
Expand All @@ -262,6 +263,7 @@ public void onClick(final View v) {
.withArrow(true)
.maxWidth(metrics.widthPixels / 2)
.withCallback(this)
.alignment(Tooltip.Alignment.LEFT)
.withStyleId(R.style.ToolTipLayoutDefaultStyle_Custom1)
.build()
).show();
Expand All @@ -276,6 +278,7 @@ public void onClick(final View v) {
.withArrow(true)
.maxWidth((int) (metrics.widthPixels / 2.5))
.withCallback(this)
.alignment(Tooltip.Alignment.RIGHT)
.floatingAnimation(AnimationBuilder.DEFAULT)
.build()
).show();
Expand All @@ -289,6 +292,7 @@ public void onClick(final View v) {
.text("TOP. Touch Inside exclusive.")
.withArrow(true)
.withOverlay(false)
.alignment(Tooltip.Alignment.RIGHT)
.maxWidth(metrics.widthPixels / 3)
.withCallback(this)
.build()
Expand All @@ -308,6 +312,7 @@ public void onClick(final View v) {
.withOverlay(false)
.maxWidth(metrics.widthPixels / 3)
.showDelay(300)
.alignment(Tooltip.Alignment.TOP)
.withCallback(this)
.build()
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package it.sephiroth.android.library.mymodule.app;

import android.content.Context;
import android.support.v7.widget.AppCompatTextView;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView;

/**
* Created by alessandro on 04/09/14.
*/
public class MyTextView extends TextView {
public class MyTextView extends AppCompatTextView {
public static interface OnAttachStatusListener {
void onAttachedtoWindow(View view);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package it.sephiroth.android.library.mymodule.app;

import android.os.Bundle
import android.support.v4.app.DialogFragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import it.sephiroth.android.library.xtooltip.ClosePolicy
import it.sephiroth.android.library.xtooltip.XTooltip
import kotlinx.android.synthetic.main.dialog_fragment.*

class TestDialogFragment : DialogFragment() {

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.dialog_fragment, container, false)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

button1.setOnClickListener { button ->
XTooltip.Builder(context!!)
.anchor(button, 0, 0, false)
.closePolicy(ClosePolicy.TOUCH_ANYWHERE_CONSUME)
.fadeDuration(200)
.showDuration(0)
.text("This is a dialog")
.create()
.show(button, XTooltip.Gravity.TOP, false)
}
}

companion object {
fun newInstance(): TestDialogFragment {
val frag = TestDialogFragment()
return frag
}
}
}
25 changes: 25 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/root_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary" />

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

<include layout="@layout/content_main" />


</android.support.design.widget.CoordinatorLayout>
Loading