Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

First commit

Initial version. Ready to use :)
  • Loading branch information...
commit 5ac7d369a772b8ae6882a5c3e68c51f1913ee40c 1 parent b6533cd
@lupidan authored
Showing with 1,343 additions and 1 deletion.
  1. BIN  .DS_Store
  2. +20 −0 .gitignore
  3. +23 −0 AndroidManifest.xml
  4. +165 −0 LICENSE.txt
  5. +15 −1 README.md
  6. BIN  Screenshot1.png
  7. BIN  Screenshot2.png
  8. BIN  Screenshot3.png
  9. +40 −0 proguard.cfg
  10. +11 −0 project.properties
  11. BIN  res/.DS_Store
  12. BIN  res/drawable-hdpi/.DS_Store
  13. BIN  res/drawable-hdpi/ic_launcher.png
  14. BIN  res/drawable-ldpi/.DS_Store
  15. BIN  res/drawable-ldpi/ic_launcher.png
  16. BIN  res/drawable-mdpi/.DS_Store
  17. BIN  res/drawable-mdpi/background_popover.9.png
  18. BIN  res/drawable-mdpi/ic_launcher.png
  19. BIN  res/drawable-mdpi/icon_popover_arrow_down.png
  20. BIN  res/drawable-mdpi/icon_popover_arrow_left.png
  21. BIN  res/drawable-mdpi/icon_popover_arrow_right.png
  22. BIN  res/drawable-mdpi/icon_popover_arrow_up.png
  23. BIN  res/layout/.DS_Store
  24. +80 −0 res/layout/main.xml
  25. +21 −0 res/layout/popover_showed_view.xml
  26. BIN  res/values/.DS_Store
  27. +8 −0 res/values/strings.xml
  28. +877 −0 src/com/daniel/lupianez/casares/PopoverView.java
  29. +83 −0 src/com/daniel/lupianez/casares/PopoverViewActivity.java
View
BIN  .DS_Store
Binary file not shown
View
20 .gitignore
@@ -0,0 +1,20 @@
+# built application files
+*.apk
+*.ap_
+
+# files for the dex VM
+*.dex
+
+# Java class files
+*.class
+
+# generated files
+bin/
+gen/
+
+# Local configuration file (sdk path, etc)
+local.properties
+
+# Eclipse project files
+.classpath
+.project
View
23 AndroidManifest.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.daniel.lupianez.casares"
+ android:versionCode="1"
+ android:versionName="1.0" >
+
+ <uses-sdk android:minSdkVersion="11" />
+
+ <application
+ android:icon="@drawable/ic_launcher"
+ android:label="@string/app_name" >
+ <activity
+ android:name=".PopoverViewActivity"
+ android:label="@string/app_name" >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ </application>
+
+</manifest>
View
165 LICENSE.txt
@@ -0,0 +1,165 @@
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+
+ This version of the GNU Lesser General Public License incorporates
+the terms and conditions of version 3 of the GNU General Public
+License, supplemented by the additional permissions listed below.
+
+ 0. Additional Definitions.
+
+ As used herein, "this License" refers to version 3 of the GNU Lesser
+General Public License, and the "GNU GPL" refers to version 3 of the GNU
+General Public License.
+
+ "The Library" refers to a covered work governed by this License,
+other than an Application or a Combined Work as defined below.
+
+ An "Application" is any work that makes use of an interface provided
+by the Library, but which is not otherwise based on the Library.
+Defining a subclass of a class defined by the Library is deemed a mode
+of using an interface provided by the Library.
+
+ A "Combined Work" is a work produced by combining or linking an
+Application with the Library. The particular version of the Library
+with which the Combined Work was made is also called the "Linked
+Version".
+
+ The "Minimal Corresponding Source" for a Combined Work means the
+Corresponding Source for the Combined Work, excluding any source code
+for portions of the Combined Work that, considered in isolation, are
+based on the Application, and not on the Linked Version.
+
+ The "Corresponding Application Code" for a Combined Work means the
+object code and/or source code for the Application, including any data
+and utility programs needed for reproducing the Combined Work from the
+Application, but excluding the System Libraries of the Combined Work.
+
+ 1. Exception to Section 3 of the GNU GPL.
+
+ You may convey a covered work under sections 3 and 4 of this License
+without being bound by section 3 of the GNU GPL.
+
+ 2. Conveying Modified Versions.
+
+ If you modify a copy of the Library, and, in your modifications, a
+facility refers to a function or data to be supplied by an Application
+that uses the facility (other than as an argument passed when the
+facility is invoked), then you may convey a copy of the modified
+version:
+
+ a) under this License, provided that you make a good faith effort to
+ ensure that, in the event an Application does not supply the
+ function or data, the facility still operates, and performs
+ whatever part of its purpose remains meaningful, or
+
+ b) under the GNU GPL, with none of the additional permissions of
+ this License applicable to that copy.
+
+ 3. Object Code Incorporating Material from Library Header Files.
+
+ The object code form of an Application may incorporate material from
+a header file that is part of the Library. You may convey such object
+code under terms of your choice, provided that, if the incorporated
+material is not limited to numerical parameters, data structure
+layouts and accessors, or small macros, inline functions and templates
+(ten or fewer lines in length), you do both of the following:
+
+ a) Give prominent notice with each copy of the object code that the
+ Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the object code with a copy of the GNU GPL and this license
+ document.
+
+ 4. Combined Works.
+
+ You may convey a Combined Work under terms of your choice that,
+taken together, effectively do not restrict modification of the
+portions of the Library contained in the Combined Work and reverse
+engineering for debugging such modifications, if you also do each of
+the following:
+
+ a) Give prominent notice with each copy of the Combined Work that
+ the Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
+ document.
+
+ c) For a Combined Work that displays copyright notices during
+ execution, include the copyright notice for the Library among
+ these notices, as well as a reference directing the user to the
+ copies of the GNU GPL and this license document.
+
+ d) Do one of the following:
+
+ 0) Convey the Minimal Corresponding Source under the terms of this
+ License, and the Corresponding Application Code in a form
+ suitable for, and under terms that permit, the user to
+ recombine or relink the Application with a modified version of
+ the Linked Version to produce a modified Combined Work, in the
+ manner specified by section 6 of the GNU GPL for conveying
+ Corresponding Source.
+
+ 1) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (a) uses at run time
+ a copy of the Library already present on the user's computer
+ system, and (b) will operate properly with a modified version
+ of the Library that is interface-compatible with the Linked
+ Version.
+
+ e) Provide Installation Information, but only if you would otherwise
+ be required to provide such information under section 6 of the
+ GNU GPL, and only to the extent that such information is
+ necessary to install and execute a modified version of the
+ Combined Work produced by recombining or relinking the
+ Application with a modified version of the Linked Version. (If
+ you use option 4d0, the Installation Information must accompany
+ the Minimal Corresponding Source and Corresponding Application
+ Code. If you use option 4d1, you must provide the Installation
+ Information in the manner specified by section 6 of the GNU GPL
+ for conveying Corresponding Source.)
+
+ 5. Combined Libraries.
+
+ You may place library facilities that are a work based on the
+Library side by side in a single library together with other library
+facilities that are not Applications and are not covered by this
+License, and convey such a combined library under terms of your
+choice, if you do both of the following:
+
+ a) Accompany the combined library with a copy of the same work based
+ on the Library, uncombined with any other library facilities,
+ conveyed under the terms of this License.
+
+ b) Give prominent notice with the combined library that part of it
+ is a work based on the Library, and explaining where to find the
+ accompanying uncombined form of the same work.
+
+ 6. Revised Versions of the GNU Lesser General Public License.
+
+ The Free Software Foundation may publish revised and/or new versions
+of the GNU Lesser General Public License from time to time. Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Library as you received it specifies that a certain numbered version
+of the GNU Lesser General Public License "or any later version"
+applies to it, you have the option of following the terms and
+conditions either of that published version or of any later version
+published by the Free Software Foundation. If the Library as you
+received it does not specify a version number of the GNU Lesser
+General Public License, you may choose any version of the GNU Lesser
+General Public License ever published by the Free Software Foundation.
+
+ If the Library as you received it specifies that a proxy can decide
+whether future versions of the GNU Lesser General Public License shall
+apply, that proxy's public statement of acceptance of any version is
+permanent authorization for you to choose that version for the
+Library.
View
16 README.md
@@ -1,4 +1,18 @@
PopoverView
===========
-A Popover Controller for Android Tablets. It's an easy solution to simulate an iOS UIPopoverController
+A Popover Controller for Android Tablets. It's an easy solution to simulate an iOS UIPopoverController
+
+Showing a popover controller is as easy as this
+
+ //get root layout
+ RelativeLayout rootView = (RelativeLayout)findViewById(R.id.rootLayout);
+
+ PopoverView popoverView = new PopoverView(this, R.layout.popover_showed_view);
+ popoverView.setContentSizeForViewInPopover(new Point(320, 340));
+ popoverView.setDelegate(this);
+ popoverView.showPopoverFromRectInViewGroup(rootView, PopoverView.getFrameForView(v), PopoverView.PopoverArrowDirectionAny, true);
+
+![Screenshot 1](https://raw.github.com/lupidan/PopoverController/master/screenshot1.png "Screenshot 1")
+![Screenshot 2](https://raw.github.com/lupidan/PopoverController/master/screenshot2.png "Screenshot 2")
+![Screenshot 3](https://raw.github.com/lupidan/PopoverController/master/screenshot3.png "Screenshot 3")
View
BIN  Screenshot1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  Screenshot2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  Screenshot3.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
40 proguard.cfg
@@ -0,0 +1,40 @@
+-optimizationpasses 5
+-dontusemixedcaseclassnames
+-dontskipnonpubliclibraryclasses
+-dontpreverify
+-verbose
+-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
+
+-keep public class * extends android.app.Activity
+-keep public class * extends android.app.Application
+-keep public class * extends android.app.Service
+-keep public class * extends android.content.BroadcastReceiver
+-keep public class * extends android.content.ContentProvider
+-keep public class * extends android.app.backup.BackupAgentHelper
+-keep public class * extends android.preference.Preference
+-keep public class com.android.vending.licensing.ILicensingService
+
+-keepclasseswithmembernames class * {
+ native <methods>;
+}
+
+-keepclasseswithmembers class * {
+ public <init>(android.content.Context, android.util.AttributeSet);
+}
+
+-keepclasseswithmembers class * {
+ public <init>(android.content.Context, android.util.AttributeSet, int);
+}
+
+-keepclassmembers class * extends android.app.Activity {
+ public void *(android.view.View);
+}
+
+-keepclassmembers enum * {
+ public static **[] values();
+ public static ** valueOf(java.lang.String);
+}
+
+-keep class * implements android.os.Parcelable {
+ public static final android.os.Parcelable$Creator *;
+}
View
11 project.properties
@@ -0,0 +1,11 @@
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must be checked in Version Control Systems.
+#
+# To customize properties used by the Ant build system use,
+# "ant.properties", and override values to adapt the script to your
+# project structure.
+
+# Project target.
+target=android-11
View
BIN  res/.DS_Store
Binary file not shown
View
BIN  res/drawable-hdpi/.DS_Store
Binary file not shown
View
BIN  res/drawable-hdpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  res/drawable-ldpi/.DS_Store
Binary file not shown
View
BIN  res/drawable-ldpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  res/drawable-mdpi/.DS_Store
Binary file not shown
View
BIN  res/drawable-mdpi/background_popover.9.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  res/drawable-mdpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  res/drawable-mdpi/icon_popover_arrow_down.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  res/drawable-mdpi/icon_popover_arrow_left.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  res/drawable-mdpi/icon_popover_arrow_right.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  res/drawable-mdpi/icon_popover_arrow_up.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  res/layout/.DS_Store
Binary file not shown
View
80 res/layout/main.xml
@@ -0,0 +1,80 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/rootLayout"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:orientation="vertical" >
+
+ <Button
+ android:id="@+id/button3"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentBottom="true"
+ android:layout_centerHorizontal="true"
+ android:text="Button" />
+
+ <Button
+ android:id="@+id/button4"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentBottom="true"
+ android:layout_alignParentLeft="true"
+ android:text="Button" />
+
+ <Button
+ android:id="@+id/button1"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentBottom="true"
+ android:layout_alignParentRight="true"
+ android:text="Button" />
+
+ <Button
+ android:id="@+id/button2"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentRight="true"
+ android:layout_centerVertical="true"
+ android:text="Button" />
+
+ <Button
+ android:id="@+id/button5"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_centerVertical="true"
+ android:layout_centerHorizontal="true"
+ android:text="Button" />
+
+ <Button
+ android:id="@+id/button6"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_centerVertical="true"
+ android:layout_alignParentLeft="true"
+ android:text="Button" />
+
+ <Button
+ android:id="@+id/button7"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentRight="true"
+ android:layout_alignParentTop="true"
+ android:text="Button" />
+
+ <Button
+ android:id="@+id/button8"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_centerHorizontal="true"
+ android:layout_alignParentTop="true"
+ android:text="Button" />
+
+ <Button
+ android:id="@+id/button9"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentLeft="true"
+ android:layout_alignParentTop="true"
+ android:text="Button" />
+
+</RelativeLayout>
View
21 res/layout/popover_showed_view.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/mainScrollView"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent" >
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical" android:layout_margin="20dp">
+
+ <TextView
+ android:id="@+id/textView1"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/lore_ipsum"
+ android:textAppearance="?android:attr/textAppearanceMedium" android:textColor="#FF000000"/>
+
+ </LinearLayout>
+
+</ScrollView>
View
BIN  res/values/.DS_Store
Binary file not shown
View
8 res/values/strings.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+ <string name="hello">Hello World, PopoverViewActivity!</string>
+ <string name="app_name">PopoverView</string>
+ <string name="lore_ipsum">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas molestie dignissim augue, eget eleifend quam facilisis sit amet. Donec at leo nibh. Sed bibendum purus vel quam mattis euismod. Donec justo ante, fermentum vel dapibus eu, euismod eu urna. Sed eu libero eros, eu egestas tortor. Duis et ante a erat ultrices interdum non et mi. Aliquam quis nulla non tortor malesuada pharetra vitae ac magna. Sed id felis arcu, ac aliquam tellus. Integer ut turpis enim. Nulla tristique, nisi feugiat placerat vestibulum, mauris urna scelerisque odio, a volutpat mauris nunc ut enim. Praesent vestibulum dolor nec enim rhoncus suscipit. Donec eleifend est quis risus faucibus et suscipit lacus dictum.\n\nVestibulum laoreet elit sagittis purus porta hendrerit auctor augue ultricies. Maecenas odio sem, iaculis id dapibus sed, gravida hendrerit metus. Suspendisse volutpat tincidunt urna et ornare. Nunc risus ipsum, cursus sit amet sodales a, bibendum eu tortor. Aliquam eros mi, pulvinar nec blandit vitae, rutrum sed nisl. Nulla facilisi. In libero nunc, faucibus et suscipit id, porttitor at neque. Donec a sem magna, id suscipit ipsum. Mauris orci ante, mattis sed pharetra vitae, accumsan sit amet dolor. Morbi libero diam, sodales sed suscipit ac, congue eu orci. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Mauris eget velit nibh, eu egestas est. Sed sodales mattis nulla, ac molestie erat gravida at.\n\nCras gravida mi et nisi tristique vitae facilisis metus auctor. Etiam lobortis tincidunt venenatis. Donec eu magna et odio viverra auctor a et erat. Duis volutpat dignissim lectus eu sollicitudin. Sed libero nunc, auctor a auctor vitae, suscipit et ligula. Etiam ut quam diam, id suscipit dui. Nam eget volutpat purus. Vestibulum risus nulla, blandit ac sodales nec, malesuada id enim.\n\nDonec ac odio magna, at rhoncus massa. Maecenas risus orci, sagittis vitae scelerisque quis, condimentum sed ipsum. Maecenas sapien justo, varius consectetur consequat at, facilisis vel est. Vestibulum vulputate felis at purus scelerisque vel elementum lectus molestie. Donec posuere mollis eros vel posuere. Quisque odio velit, consequat nec tristique ac, interdum nec ipsum. Pellentesque fringilla vulputate interdum. Vivamus massa ante, ornare non laoreet sit amet, volutpat nec sapien. Curabitur et ligula metus. Nunc sit amet diam sit amet risus laoreet porta.\n\nSed ultricies aliquam nisi non mollis. Donec justo purus, lacinia sit amet venenatis non, interdum et magna. Mauris gravida sapien a nibh rhoncus eleifend. In feugiat posuere justo suscipit sagittis. Fusce lobortis, turpis at accumsan posuere, metus augue volutpat erat, a luctus ipsum justo sed nisl. Aliquam erat volutpat. In eu felis malesuada erat iaculis laoreet non vitae massa.</string>
+
+</resources>
View
877 src/com/daniel/lupianez/casares/PopoverView.java
@@ -0,0 +1,877 @@
+/**
+ * Popover View
+ *
+ * Copyright 2012 Daniel Lupia–ez Casares <lupidan@gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ **/
+
+package com.daniel.lupianez.casares;
+import com.daniel.lupianez.casares.R;
+import java.util.HashMap;
+import java.util.Map;
+import android.content.Context;
+import android.graphics.Point;
+import android.graphics.Rect;
+import android.graphics.drawable.Drawable;
+import android.util.AttributeSet;
+import android.view.MotionEvent;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.View.OnTouchListener;
+import android.view.animation.AlphaAnimation;
+import android.view.animation.Animation;
+import android.view.animation.Animation.AnimationListener;
+import android.widget.ImageView;
+import android.widget.RelativeLayout;
+
+public class PopoverView extends RelativeLayout implements OnTouchListener{
+
+ //********************************************************************
+ // INTERFACES
+ //********************************************************************
+ /**
+ * Interface to get information from the popover view. Use setDelegate to have access to this methods
+ */
+ public static interface PopoverViewDelegate{
+ /**
+ * Called when the popover is going to show
+ * @param view The whole popover view
+ */
+ void popoverViewWillShow(PopoverView view);
+ /**
+ * Called when the popover did show
+ * @param view The whole popover view
+ */
+ void popoverViewDidShow(PopoverView view);
+ /**
+ * Called when the popover is going to be dismissed
+ * @param view The whole popover view
+ */
+ void popoverViewWillDismiss(PopoverView view);
+ /**
+ * Called when the popover was dismissed
+ * @param view The whole popover view
+ */
+ void popoverViewDidDismiss(PopoverView view);
+ }
+
+
+
+
+
+
+
+ //********************************************************************
+ // STATIC MEMBERS
+ //********************************************************************
+ /**
+ * Popover arrow points up. Integer to use with bit operators to tell the popover where the arrow should appear and from where the popover should appear
+ */
+ public final static int PopoverArrowDirectionUp = 0x00000001;
+ /**
+ * Popover arrow points down. Integer to use with bit operators to tell the popover where the arrow should appear and from where the popover should appear
+ */
+ public final static int PopoverArrowDirectionDown = 0x00000002;
+ /**
+ * Popover arrow points left. Integer to use with bit operators to tell the popover where the arrow should appear and from where the popover should appear
+ */
+ public final static int PopoverArrowDirectionLeft = 0x00000004;
+ /**
+ * Popover arrow points right. Integer to use with bit operators to tell the popover where the arrow should appear and from where the popover should appear
+ */
+ public final static int PopoverArrowDirectionRight = 0x00000008;
+ /**
+ * Popover arrow points any direction. Integer to use with bit operators to tell the popover where the arrow should appear and from where the popover should appear
+ */
+ public final static int PopoverArrowDirectionAny = PopoverArrowDirectionUp|PopoverArrowDirectionDown|PopoverArrowDirectionLeft|PopoverArrowDirectionRight;
+ /**
+ * The default popover background drawable for all the popovers
+ */
+ public static int defaultPopoverBackgroundDrawable = R.drawable.background_popover;
+ /**
+ * The default popover arrow up drawable for all the popovers
+ */
+ public static int defaultPopoverArrowUpDrawable = R.drawable.icon_popover_arrow_up;
+ /**
+ * The default popover arrow down drawable for all the popovers
+ */
+ public static int defaultPopoverArrowDownDrawable = R.drawable.icon_popover_arrow_down;
+ /**
+ * The default popover arrow left drawable for all the popovers
+ */
+ public static int defaultPopoverArrowLeftDrawable = R.drawable.icon_popover_arrow_left;
+ /**
+ * The default popover arrow down drawable for all the popovers
+ */
+ public static int defaultPopoverArrowRightDrawable = R.drawable.icon_popover_arrow_right;
+
+
+
+
+
+
+ //********************************************************************
+ // STATIC METHODS
+ //********************************************************************
+ /**
+ * Get the Rect frame for a view (relative to the Window of the application)
+ * @param v The view to get the rect from
+ * @return The rect of the view, relative to the application window
+ */
+ public static Rect getFrameForView(View v){
+ int location [] = new int [2];
+ v.getLocationOnScreen(location);
+ Rect viewRect = new Rect(location[0], location[1], location[0]+v.getWidth(), location[1]+v.getHeight());
+ return viewRect;
+ }
+
+
+
+
+
+
+
+
+ //********************************************************************
+ // MEMBERS
+ //********************************************************************
+ /**
+ * The delegate of the view
+ */
+ private PopoverViewDelegate delegate;
+ /**
+ * The main popover containing the view we want to show
+ */
+ private RelativeLayout popoverView;
+ /**
+ * The view group storing this popover. We need this so, when we dismiss the popover, we remove it from the view group
+ */
+ private ViewGroup superview;
+ /**
+ * The content size for the view in the popover
+ */
+ private Point contentSizeForViewInPopover = new Point(0, 0);
+ /**
+ * A hash containing
+ */
+ private Map<Integer, Rect> possibleRects;
+ /**
+ * Whether the view is animating or not
+ */
+ private boolean isAnimating = false;
+ /**
+ * The fade animation time in milliseconds
+ */
+ private int fadeAnimationTime = 300;
+ /**
+ * The layout Rect, is the same as the superview rect
+ */
+ private Rect popoverLayoutRect;
+ /**
+ * The popover background drawable
+ */
+ private int popoverBackgroundDrawable;
+ /**
+ * The popover arrow up drawable
+ */
+ private int popoverArrowUpDrawable;
+ /**
+ * The popover arrow down drawable
+ */
+ private int popoverArrowDownDrawable;
+ /**
+ * The popover arrow left drawable
+ */
+ private int popoverArrowLeftDrawable;
+ /**
+ * The popover arrow down drawable
+ */
+ private int popoverArrowRightDrawable;
+
+
+
+
+
+
+
+
+
+
+
+ //********************************************************************
+ // CONSTRUCTORS
+ //********************************************************************
+ /**
+ * Constructor to create a popover with a popover view
+ * @param context The context where we should create the popover view
+ * @param layoutId The ID of the layout we want to put inside the popover
+ */
+ public PopoverView(Context context, int layoutId) {
+ super(context);
+ initPopoverView(inflate(context, layoutId, null));
+ }
+
+ /**
+ * Constructor to create a popover with a popover view
+ * @param context The context where we should create the popover view
+ * @param attrs Attribute set to init the view
+ * @param layoutId The ID of the layout we want to put inside the popover
+ */
+ public PopoverView(Context context, AttributeSet attrs, int layoutId) {
+ super(context, attrs);
+ initPopoverView(inflate(context, layoutId, null));
+ }
+
+ /**
+ * Constructor to create a popover with a popover view
+ * @param context The context where we should create the popover view
+ * @param attrs Attribute set to init the view
+ * @param defStyle The default style for this view
+ * @param layoutId The ID of the layout we want to put inside the popover
+ */
+ public PopoverView(Context context, AttributeSet attrs, int defStyle, int layoutId) {
+ super(context, attrs, defStyle);
+ initPopoverView(inflate(context, layoutId, null));
+ }
+ /**
+ * Constructor to create a popover with a popover view
+ * @param context The context where we should create the popover view
+ * @param popoverView The inner view we want to show in a popover
+ */
+ public PopoverView(Context context, View popoverView) {
+ super(context);
+ initPopoverView(popoverView);
+ }
+
+ /**
+ * Constructor to create a popover with a popover view
+ * @param context The context where we should create the popover view
+ * @param attrs Attribute set to init the view
+ * @param popoverView The inner view we want to show in a popover
+ */
+ public PopoverView(Context context, AttributeSet attrs, View popoverView) {
+ super(context, attrs);
+ initPopoverView(popoverView);
+ }
+
+ /**
+ * Constructor to create a popover with a popover view
+ * @param context The context where we should create the popover view
+ * @param attrs Attribute set to init the view
+ * @param defStyle The default style for this view
+ * @param popoverView The inner view we want to show in a popover
+ */
+ public PopoverView(Context context, AttributeSet attrs, int defStyle, View popoverView) {
+ super(context, attrs, defStyle);
+ initPopoverView(popoverView);
+ }
+
+ /**
+ * Init the popover view
+ * @param viewToEnclose The view we wan to insert inside the popover
+ */
+ private void initPopoverView(View viewToEnclose){
+
+ //Configure self
+ setBackgroundColor(0x00000000);
+ //setOnClickListener(this);
+ setOnTouchListener(this);
+
+ //Set initial drawables
+ popoverBackgroundDrawable = PopoverView.defaultPopoverBackgroundDrawable;
+ popoverArrowUpDrawable = PopoverView.defaultPopoverArrowUpDrawable;
+ popoverArrowDownDrawable = PopoverView.defaultPopoverArrowDownDrawable;
+ popoverArrowLeftDrawable = PopoverView.defaultPopoverArrowLeftDrawable;
+ popoverArrowRightDrawable = PopoverView.defaultPopoverArrowRightDrawable;
+
+ //Init the relative layout
+ popoverView = new RelativeLayout(getContext());
+ popoverView.setBackgroundDrawable(getResources().getDrawable(popoverBackgroundDrawable));
+ popoverView.addView(viewToEnclose,LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
+
+ }
+
+
+
+
+
+
+
+
+
+
+
+ //********************************************************************
+ // PRIVATE METHODS
+ //********************************************************************
+ /**
+ * Add the popover to the view with a defined rect inside the popover
+ * @param insertRect The rect we want to insert the view
+ */
+ private void addPopoverInRect(Rect insertRect){
+ //Set layout params
+ LayoutParams insertParams = new LayoutParams(insertRect.width(), insertRect.height());
+ insertParams.leftMargin = insertRect.left;
+ insertParams.topMargin = insertRect.top;
+ //Add the view
+ addView(popoverView, insertParams);
+
+ }
+
+
+ private void addArrow(Rect originRect, Integer arrowDirection){
+ //Add arrow drawable
+ ImageView arrowImageView = new ImageView(getContext());
+ Drawable arrowDrawable = null;
+ int xPos = 0;
+ int arrowWidth = 0;
+ int yPos = 0;
+ int arrowHeight = 0;
+ //Get correct drawable, and get Width, Height, Xpos and yPos depending on the selected arrow direction
+ if (arrowDirection == PopoverView.PopoverArrowDirectionUp){
+ arrowDrawable = getResources().getDrawable(popoverArrowUpDrawable);
+ arrowWidth = arrowDrawable.getIntrinsicWidth();
+ arrowHeight = arrowDrawable.getIntrinsicHeight();
+ xPos = originRect.centerX() - (arrowWidth/2) - popoverLayoutRect.left;
+ yPos = originRect.bottom - popoverLayoutRect.top;
+ }
+ else if (arrowDirection == PopoverView.PopoverArrowDirectionDown){
+ arrowDrawable = getResources().getDrawable(popoverArrowDownDrawable);
+ arrowWidth = arrowDrawable.getIntrinsicWidth();
+ arrowHeight = arrowDrawable.getIntrinsicHeight();
+ xPos = originRect.centerX() - (arrowWidth/2) - popoverLayoutRect.left;
+ yPos = originRect.top - arrowHeight - popoverLayoutRect.top;
+ }
+ else if (arrowDirection == PopoverView.PopoverArrowDirectionLeft){
+ arrowDrawable = getResources().getDrawable(popoverArrowLeftDrawable);
+ arrowWidth = arrowDrawable.getIntrinsicWidth();
+ arrowHeight = arrowDrawable.getIntrinsicHeight();
+ xPos = originRect.right - popoverLayoutRect.left;
+ yPos = originRect.centerY() - (arrowHeight/2) - popoverLayoutRect.top;
+ }
+ else if (arrowDirection == PopoverView.PopoverArrowDirectionRight){
+ arrowDrawable = getResources().getDrawable(popoverArrowRightDrawable);
+ arrowWidth = arrowDrawable.getIntrinsicWidth();
+ arrowHeight = arrowDrawable.getIntrinsicHeight();
+ xPos = originRect.left - arrowWidth - popoverLayoutRect.left;
+ yPos = originRect.centerY() - (arrowHeight/2) - popoverLayoutRect.top;
+ }
+ //Set drawable
+ arrowImageView.setImageDrawable(arrowDrawable);
+ //Init layout params
+ LayoutParams arrowParams = new LayoutParams(arrowWidth, arrowHeight);
+ arrowParams.leftMargin = xPos;
+ arrowParams.topMargin = yPos;
+ //add view :)
+ addView(arrowImageView, arrowParams);
+ }
+
+
+ /**
+ * Calculates the rect for showing the view with Arrow Up
+ * @param originRect The origin rect
+ * @return The calculated rect to show the view
+ */
+ private Rect getRectForArrowUp(Rect originRect){
+
+ //Get available space
+ int xAvailable = popoverLayoutRect.width();
+ if (xAvailable < 0)
+ xAvailable = 0;
+ int yAvailable = popoverLayoutRect.height() - (originRect.bottom - popoverLayoutRect.top);
+ if (yAvailable < 0)
+ yAvailable = 0;
+
+ //Get final width and height
+ int finalX = xAvailable;
+ if ((contentSizeForViewInPopover.x > 0) && (contentSizeForViewInPopover.x < finalX))
+ finalX = contentSizeForViewInPopover.x;
+ int finalY = yAvailable;
+ if ((contentSizeForViewInPopover.y > 0) && (contentSizeForViewInPopover.y < finalY))
+ finalY = contentSizeForViewInPopover.y;
+
+ //Get final origin X and Y
+ int originX = (originRect.centerX()-popoverLayoutRect.left) - (finalX/2) ;
+ if (originX < 0)
+ originX = 0;
+ else if (originX+finalX > popoverLayoutRect.width())
+ originX = popoverLayoutRect.width() - finalX;
+ int originY = (originRect.bottom - popoverLayoutRect.top);
+
+ //Create rect
+ Rect finalRect = new Rect(originX, originY, originX+finalX, originY+finalY);
+ //And return
+ return finalRect;
+
+ }
+
+ /**
+ * Calculates the rect for showing the view with Arrow Down
+ * @param originRect The origin rect
+ * @return The calculated rect to show the view
+ */
+ private Rect getRectForArrowDown(Rect originRect){
+
+ //Get available space
+ int xAvailable = popoverLayoutRect.width();
+ if (xAvailable < 0)
+ xAvailable = 0;
+ int yAvailable = (originRect.top - popoverLayoutRect.top);
+ if (yAvailable < 0)
+ yAvailable = 0;
+
+ //Get final width and height
+ int finalX = xAvailable;
+ if ((contentSizeForViewInPopover.x > 0) && (contentSizeForViewInPopover.x < finalX))
+ finalX = contentSizeForViewInPopover.x;
+ int finalY = yAvailable;
+ if ((contentSizeForViewInPopover.y > 0) && (contentSizeForViewInPopover.y < finalY))
+ finalY = contentSizeForViewInPopover.y;
+
+ //Get final origin X and Y
+ int originX = (originRect.centerX()-popoverLayoutRect.left) - (finalX/2) ;
+ if (originX < 0)
+ originX = 0;
+ else if (originX+finalX > popoverLayoutRect.width())
+ originX = popoverLayoutRect.width() - finalX;
+ int originY = (originRect.top - popoverLayoutRect.top) - finalY;
+
+ //Create rect
+ Rect finalRect = new Rect(originX, originY, originX+finalX, originY+finalY);
+ //And return
+ return finalRect;
+
+ }
+
+
+ /**
+ * Calculates the rect for showing the view with Arrow Right
+ * @param originRect The origin rect
+ * @return The calculated rect to show the view
+ */
+ private Rect getRectForArrowRight(Rect originRect){
+ //Get available space
+ int xAvailable = (originRect.left - popoverLayoutRect.left);
+ if (xAvailable < 0)
+ xAvailable = 0;
+ int yAvailable = popoverLayoutRect.height();
+ if (yAvailable < 0)
+ yAvailable = 0;
+
+ //Get final width and height
+ int finalX = xAvailable;
+ if ((contentSizeForViewInPopover.x > 0) && (contentSizeForViewInPopover.x < finalX))
+ finalX = contentSizeForViewInPopover.x;
+ int finalY = yAvailable;
+ if ((contentSizeForViewInPopover.y > 0) && (contentSizeForViewInPopover.y < finalY))
+ finalY = contentSizeForViewInPopover.y;
+
+ //Get final origin X and Y
+ int originX = (originRect.left - popoverLayoutRect.left) - finalX;
+ int originY = (originRect.centerY()-popoverLayoutRect.top) - (finalY/2) ;
+ if (originY < 0)
+ originY = 0;
+ else if (originY+finalY > popoverLayoutRect.height())
+ originY = popoverLayoutRect.height() - finalY;
+
+ //Create rect
+ Rect finalRect = new Rect(originX, originY, originX+finalX, originY+finalY);
+ //And return
+ return finalRect;
+ }
+
+ /**
+ * Calculates the rect for showing the view with Arrow Left
+ * @param originRect The origin rect
+ * @return The calculated rect to show the view
+ */
+ private Rect getRectForArrowLeft(Rect originRect){
+ //Get available space
+ int xAvailable = popoverLayoutRect.width() - (originRect.right - popoverLayoutRect.left);
+ if (xAvailable < 0)
+ xAvailable = 0;
+ int yAvailable = popoverLayoutRect.height();
+ if (yAvailable < 0)
+ yAvailable = 0;
+
+ //Get final width and height
+ int finalX = xAvailable;
+ if ((contentSizeForViewInPopover.x > 0) && (contentSizeForViewInPopover.x < finalX))
+ finalX = contentSizeForViewInPopover.x;
+ int finalY = yAvailable;
+ if ((contentSizeForViewInPopover.y > 0) && (contentSizeForViewInPopover.y < finalY))
+ finalY = contentSizeForViewInPopover.y;
+
+ //Get final origin X and Y
+ int originX = (originRect.right - popoverLayoutRect.left);
+ int originY = (originRect.centerY()-popoverLayoutRect.top) - (finalY/2) ;
+ if (originY < 0)
+ originY = 0;
+ else if (originY+finalY > popoverLayoutRect.height())
+ originY = popoverLayoutRect.height() - finalY;
+
+ //Create rect
+ Rect finalRect = new Rect(originX, originY, originX+finalX, originY+finalY);
+ //And return
+ return finalRect;
+ }
+
+
+ /**
+ * Add available rects for each selected arrow direction
+ * @param originRect The rect where the popover will appear from
+ * @param arrowDirections The bit mask for the possible arrow directions
+ */
+ private void addAvailableRects(Rect originRect, int arrowDirections){
+ //Get popover rects for the available directions
+ possibleRects = new HashMap<Integer, Rect>();
+ if ((arrowDirections & PopoverView.PopoverArrowDirectionUp) != 0){
+ possibleRects.put(PopoverView.PopoverArrowDirectionUp, getRectForArrowUp(originRect));
+ }
+ if ((arrowDirections & PopoverView.PopoverArrowDirectionDown) != 0){
+ possibleRects.put(PopoverView.PopoverArrowDirectionDown, getRectForArrowDown(originRect));
+ }
+ if ((arrowDirections & PopoverView.PopoverArrowDirectionRight) != 0){
+ possibleRects.put(PopoverView.PopoverArrowDirectionRight, getRectForArrowRight(originRect));
+ }
+ if ((arrowDirections & PopoverView.PopoverArrowDirectionLeft) != 0){
+ possibleRects.put(PopoverView.PopoverArrowDirectionLeft, getRectForArrowLeft(originRect));
+ }
+
+ }
+
+ /**
+ * Get the best available rect (bigger area)
+ * @return The Integer key to get the Rect from posibleRects (PopoverArrowDirectionUp,PopoverArrowDirectionDown,PopoverArrowDirectionRight or PopoverArrowDirectionLeft)
+ */
+ private Integer getBestRect(){
+ //Get the best one (bigger area)
+ Integer best = null;
+ for (Integer arrowDir : possibleRects.keySet()) {
+ if (best == null){
+ best = arrowDir;
+ }
+ else{
+ Rect bestRect = possibleRects.get(best);
+ Rect checkRect = possibleRects.get(arrowDir);
+ if ((bestRect.width()*bestRect.height()) < (checkRect.width()*checkRect.height()))
+ best = arrowDir;
+ }
+ }
+ return best;
+ }
+
+
+
+
+
+
+
+
+
+
+
+ //********************************************************************
+ // GETTERS AND SETTERS
+ //********************************************************************
+ /**
+ * Gets the current fade animation time
+ * @return The fade animation time, in milliseconds
+ */
+ public int getFadeAnimationTime() {
+ return fadeAnimationTime;
+ }
+
+ /**
+ * Sets the fade animation time
+ * @param fadeAnimationTime The time in milliseconds
+ */
+ public void setFadeAnimationTime(int fadeAnimationTime) {
+ this.fadeAnimationTime = fadeAnimationTime;
+ }
+
+ /**
+ * Get the content size for view in popover
+ * @return The point with the content size
+ */
+ public Point getContentSizeForViewInPopover() {
+ return contentSizeForViewInPopover;
+ }
+
+ /**
+ * Sets the content size for the view in a popover, if point is (0,0) the popover will full the screen
+ * @param contentSizeForViewInPopover
+ */
+ public void setContentSizeForViewInPopover(Point contentSizeForViewInPopover) {
+ this.contentSizeForViewInPopover = contentSizeForViewInPopover;
+ }
+
+ /**
+ * Gets the current delegate
+ * @return The current delegate
+ */
+ public PopoverViewDelegate getDelegate() {
+ return delegate;
+ }
+
+ /**
+ * Sets the popover delegate
+ * @param delegate The new popover delegate
+ */
+ public void setDelegate(PopoverViewDelegate delegate) {
+ this.delegate = delegate;
+ }
+
+ /**
+ * @return Current background drawable
+ */
+ public int getPopoverBackgroundDrawable() {
+ return popoverBackgroundDrawable;
+ }
+
+ /**
+ * @param popoverBackgroundDrawable The new background drawable
+ */
+ public void setPopoverBackgroundDrawable(int popoverBackgroundDrawable) {
+ this.popoverBackgroundDrawable = popoverBackgroundDrawable;
+ }
+
+ /**
+ * @return Current arrow up drawable
+ */
+ public int getPopoverArrowUpDrawable() {
+ return popoverArrowUpDrawable;
+ }
+
+ /**
+ * @param popoverArrowUpDrawable The new arrow up drawable
+ */
+ public void setPopoverArrowUpDrawable(int popoverArrowUpDrawable) {
+ this.popoverArrowUpDrawable = popoverArrowUpDrawable;
+ }
+
+ /**
+ * @return Current arrow down drawable
+ */
+ public int getPopoverArrowDownDrawable() {
+ return popoverArrowDownDrawable;
+ }
+
+ /**
+ * @param popoverArrowDownDrawable The new arrow down drawable
+ */
+ public void setPopoverArrowDownDrawable(int popoverArrowDownDrawable) {
+ this.popoverArrowDownDrawable = popoverArrowDownDrawable;
+ }
+
+ /**
+ * @return Current arrow left drawable
+ */
+ public int getPopoverArrowLeftDrawable() {
+ return popoverArrowLeftDrawable;
+ }
+
+ /**
+ * @param popoverArrowLeftDrawable The new arrow left drawable
+ */
+ public void setPopoverArrowLeftDrawable(int popoverArrowLeftDrawable) {
+ this.popoverArrowLeftDrawable = popoverArrowLeftDrawable;
+ }
+
+ /**
+ * @return Current arrow right drawable
+ */
+ public int getPopoverArrowRightDrawable() {
+ return popoverArrowRightDrawable;
+ }
+
+ /**
+ * @param popoverArrowRightDrawable The new arrow right drawable
+ */
+ public void setPopoverArrowRightDrawable(int popoverArrowRightDrawable) {
+ this.popoverArrowRightDrawable = popoverArrowRightDrawable;
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+ //********************************************************************
+ // PUBLIC METHODS
+ //********************************************************************
+ /**
+ * This method shows a popover in a ViewGroup, from an origin rect (relative to the Application Window)
+ * @param group The group we want to insert the popup. Normally a Relative Layout so it can stand on top of everything
+ * @param originRect The rect we want the popup to appear from (relative to the Application Window!)
+ * @param arrowDirections The mask of bits to tell in which directions we want the popover to be shown
+ * @param animated Whether is animated, or not
+ */
+ public void showPopoverFromRectInViewGroup(ViewGroup group, Rect originRect, int arrowDirections, boolean animated){
+
+ //First, tell delegate we will show
+ if (delegate != null)
+ delegate.popoverViewWillShow(this);
+
+ //Save superview
+ superview = group;
+
+ //First, add the view to the view group. The popover will cover the whole area
+ android.view.ViewGroup.LayoutParams insertParams = new android.view.ViewGroup.LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT, android.view.ViewGroup.LayoutParams.FILL_PARENT);
+ group.addView(this, insertParams);
+
+ //Now, save rect for the layout (is the same as the superview)
+ popoverLayoutRect=PopoverView.getFrameForView(superview);
+
+ //Add available rects
+ addAvailableRects(originRect, arrowDirections);
+ //Get best rect
+ Integer best = getBestRect();
+
+ //Add popover
+ Rect bestRect = possibleRects.get(best);
+ addPopoverInRect(bestRect);
+ //Add arrow image
+ addArrow(originRect, best);
+
+
+ //If we don't want animation, just tell the delegate
+ if (!animated){
+ //Tell delegate we did show
+ if (delegate != null)
+ delegate.popoverViewDidShow(this);
+ }
+ //If we want animation, animate it!
+ else{
+ //Continue only if we are not animating
+ if (!isAnimating){
+
+ //Create alpha animation, with its listener
+ AlphaAnimation animation = new AlphaAnimation(0.0f, 1.0f);
+ animation.setDuration(fadeAnimationTime);
+ animation.setAnimationListener(new AnimationListener() {
+ @Override
+ public void onAnimationStart(Animation animation) {
+ //Nothing to do here
+ }
+
+ @Override
+ public void onAnimationRepeat(Animation animation) {
+ //Nothing to do here
+ }
+
+ @Override
+ public void onAnimationEnd(Animation animation) {
+ //End animation
+ isAnimating = false;
+ //Tell delegate we did show
+ if (delegate != null)
+ delegate.popoverViewDidShow(PopoverView.this);
+ }
+ });
+
+ //Start animation
+ isAnimating = true;
+ startAnimation(animation);
+
+ }
+ }
+
+ }
+
+ /**
+ * Dismiss the current shown popover
+ * @param animated Whether it should be dismissed animated or not
+ */
+ public void dissmissPopover(boolean animated){
+
+ //Tell delegate we will dismiss
+ if (delegate != null)
+ delegate.popoverViewWillDismiss(PopoverView.this);
+
+ //If we don't want animation
+ if (!animated){
+ //Just remove views
+ removeAllViews();
+ superview.removeView(this);
+ //Tell delegate we did dismiss
+ if (delegate != null)
+ delegate.popoverViewDidDismiss(PopoverView.this);
+ }
+ else{
+ //Continue only if there is not an animation in progress
+ if (!isAnimating){
+ //Create alpha animation, with its listener
+ AlphaAnimation animation = new AlphaAnimation(1.0f, 0.0f);
+ animation.setDuration(fadeAnimationTime);
+ animation.setAnimationListener(new AnimationListener() {
+ @Override
+ public void onAnimationStart(Animation animation) {
+ //Nothing to do here
+ }
+
+ @Override
+ public void onAnimationRepeat(Animation animation) {
+ //Nothing to do here
+ }
+
+ @Override
+ public void onAnimationEnd(Animation animation) {
+ //Remove the view
+ removeAllViews();
+ PopoverView.this.superview.removeView(PopoverView.this);
+ //End animation
+ isAnimating = false;
+ //Tell delegate we did dismiss
+ if (delegate != null)
+ delegate.popoverViewDidDismiss(PopoverView.this);
+ }
+ });
+
+ //Start animation
+ isAnimating = true;
+ startAnimation(animation);
+ }
+
+ }
+
+ }
+
+
+
+
+
+ //********************************************************************
+ // ON TOUCH LISTENER
+ //********************************************************************
+ @Override
+ public boolean onTouch(View v, MotionEvent event) {
+ //If we touched over the background popover view (this)
+ if ((!isAnimating) && (v == this)){
+ dissmissPopover(true);
+ }
+ return true;
+ }
+
+
+
+}
View
83 src/com/daniel/lupianez/casares/PopoverViewActivity.java
@@ -0,0 +1,83 @@
+/**
+ * Popover View
+ *
+ * Copyright 2012 Daniel Lupia–ez Casares <lupidan@gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ **/
+
+package com.daniel.lupianez.casares;
+import com.daniel.lupianez.casares.PopoverView.PopoverViewDelegate;
+import com.daniel.lupianez.casares.R;
+import android.app.Activity;
+import android.graphics.Point;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.RelativeLayout;
+
+public class PopoverViewActivity extends Activity implements OnClickListener, PopoverViewDelegate{
+ /** Called when the activity is first created. */
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.main);
+
+ findViewById(R.id.button1).setOnClickListener(this);
+ findViewById(R.id.button2).setOnClickListener(this);
+ findViewById(R.id.button3).setOnClickListener(this);
+ findViewById(R.id.button4).setOnClickListener(this);
+ findViewById(R.id.button5).setOnClickListener(this);
+ findViewById(R.id.button6).setOnClickListener(this);
+ findViewById(R.id.button7).setOnClickListener(this);
+ findViewById(R.id.button8).setOnClickListener(this);
+ findViewById(R.id.button9).setOnClickListener(this);
+ }
+
+ @Override
+ public void onClick(View v) {
+ //get root layout
+ RelativeLayout rootView = (RelativeLayout)findViewById(R.id.rootLayout);
+
+ PopoverView popoverView = new PopoverView(this, R.layout.popover_showed_view);
+ popoverView.setContentSizeForViewInPopover(new Point(320, 340));
+ popoverView.setDelegate(this);
+ popoverView.showPopoverFromRectInViewGroup(rootView, PopoverView.getFrameForView(v), PopoverView.PopoverArrowDirectionAny, true);
+
+ }
+
+
+
+ @Override
+ public void popoverViewWillShow(PopoverView view) {
+ Log.i("POPOVER", "Will show");
+ }
+
+ @Override
+ public void popoverViewDidShow(PopoverView view) {
+ Log.i("POPOVER", "Did show");
+ }
+
+ @Override
+ public void popoverViewWillDismiss(PopoverView view) {
+ Log.i("POPOVER", "Will dismiss");
+ }
+
+ @Override
+ public void popoverViewDidDismiss(PopoverView view) {
+ Log.i("POPOVER", "Did dismiss");
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.