From 9637f640e7a9bdb5bf0420100659c0567a4f0878 Mon Sep 17 00:00:00 2001 From: Kuldeep Singh Dhaka Date: Fri, 9 Oct 2015 03:52:44 +0530 Subject: [PATCH] Convience method to get tag data {type, row, column} from View. --- .../tablefixheaders/TableFixHeaders.java | 55 +++++++++++++++++-- 1 file changed, 49 insertions(+), 6 deletions(-) diff --git a/library/src/main/java/com/inqbarna/tablefixheaders/TableFixHeaders.java b/library/src/main/java/com/inqbarna/tablefixheaders/TableFixHeaders.java index 1421286..193dd49 100644 --- a/library/src/main/java/com/inqbarna/tablefixheaders/TableFixHeaders.java +++ b/library/src/main/java/com/inqbarna/tablefixheaders/TableFixHeaders.java @@ -23,7 +23,7 @@ /** * This view shows a table which can scroll in both directions. Also still * leaves the headers fixed. - * + * * @author Brais GabĂ­n (InQBarna) */ public class TableFixHeaders extends ViewGroup { @@ -69,7 +69,7 @@ public class TableFixHeaders extends ViewGroup { /** * Simple constructor to use when creating a view from code. - * + * * @param context * The Context the view is running in, through which it can * access the current theme, resources, etc. @@ -84,10 +84,10 @@ public TableFixHeaders(Context context) { * that were specified in the XML file. This version uses a default style of * 0, so the only attribute values applied are those in the Context's Theme * and the given AttributeSet. - * + * * The method onFinishInflate() will be called after all children have been * added. - * + * * @param context * The Context the view is running in, through which it can * access the current theme, resources, etc. @@ -125,7 +125,7 @@ public TableFixHeaders(Context context, AttributeSet attrs) { /** * Returns the adapter currently associated with this widget. - * + * * @return The adapter used to provide this view's content. */ public TableAdapter getAdapter() { @@ -134,7 +134,7 @@ public TableAdapter getAdapter() { /** * Sets the data behind this TableFixHeaders. - * + * * @param adapter * The TableAdapter which is responsible for maintaining the data * backing this list and for producing a view to represent an @@ -822,4 +822,47 @@ void forceFinished() { } } } + + /** + * Get tag data from View + * @param view Child view + * @param tag Resource Tag ID + * @return Resource integer value + * @throws IllegalArgumentException + */ + private static int getTagIntValue(View view, int tag) throws IllegalArgumentException { + final Integer value = (Integer) view.getTag(tag); + if(value == null) { + throw new IllegalArgumentException("tag not found"); + } + + return value; + } + + /** + * Extract type from View + * @param view Child View + * @return Type value + */ + public static int getType(View view) throws IllegalArgumentException { + return getTagIntValue(view, R.id.tag_type_view); + } + + /** + * Extract row from View + * @param view Child View + * @return Row value + */ + public static int getRow(View view) throws IllegalArgumentException { + return getTagIntValue(view, R.id.tag_row); + } + + /** + * Extract column from View + * @param view Child View + * @return Column value + */ + public static int getColumn(View view) throws IllegalArgumentException { + return getTagIntValue(view, R.id.tag_column); + } }