summaryrefslogtreecommitdiff
path: root/platform/java/src/kankan/wheel/widget/adapters
diff options
context:
space:
mode:
authorfred ross-perry <fredross-perry@Fred-Ross-Perrys-Computer.local>2016-08-26 09:50:48 -0700
committerfred ross-perry <fredross-perry@Fred-Ross-Perrys-Computer.local>2016-09-14 08:53:32 -0700
commitffbe3db71ea0f96b408e22418547a8ff898f380e (patch)
tree2f34407ef3c229a949b0a2b514e307297437a169 /platform/java/src/kankan/wheel/widget/adapters
parente18d11b63af0ca8a302f23b32ffc24578c830989 (diff)
downloadmupdf-ffbe3db71ea0f96b408e22418547a8ff898f380e.tar.xz
Android example - drawing ink annotations
This commit puts in the UI for drawing with color and line thickness. But it does not yet save this to the document.
Diffstat (limited to 'platform/java/src/kankan/wheel/widget/adapters')
-rw-r--r--platform/java/src/kankan/wheel/widget/adapters/AbstractWheelAdapter.java74
-rw-r--r--platform/java/src/kankan/wheel/widget/adapters/AbstractWheelTextAdapter.java268
-rw-r--r--platform/java/src/kankan/wheel/widget/adapters/AdapterWheel.java62
-rw-r--r--platform/java/src/kankan/wheel/widget/adapters/ArrayWheelAdapter.java62
-rw-r--r--platform/java/src/kankan/wheel/widget/adapters/ArrayWheelAdapterColor.java50
-rw-r--r--platform/java/src/kankan/wheel/widget/adapters/NumericWheelAdapter.java85
-rw-r--r--platform/java/src/kankan/wheel/widget/adapters/WheelViewAdapter.java64
7 files changed, 665 insertions, 0 deletions
diff --git a/platform/java/src/kankan/wheel/widget/adapters/AbstractWheelAdapter.java b/platform/java/src/kankan/wheel/widget/adapters/AbstractWheelAdapter.java
new file mode 100644
index 00000000..8d7f1447
--- /dev/null
+++ b/platform/java/src/kankan/wheel/widget/adapters/AbstractWheelAdapter.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2011 Yuri Kanivets
+ *
+ * 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 kankan.wheel.widget.adapters;
+
+import android.database.DataSetObserver;
+import android.view.View;
+import android.view.ViewGroup;
+
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Abstract Wheel adapter.
+ */
+public abstract class AbstractWheelAdapter implements WheelViewAdapter {
+ // Observers
+ private List<DataSetObserver> datasetObservers;
+
+ @Override
+ public View getEmptyItem(View convertView, ViewGroup parent) {
+ return null;
+ }
+
+ @Override
+ public void registerDataSetObserver(DataSetObserver observer) {
+ if (datasetObservers == null) {
+ datasetObservers = new LinkedList<DataSetObserver>();
+ }
+ datasetObservers.add(observer);
+ }
+
+ @Override
+ public void unregisterDataSetObserver(DataSetObserver observer) {
+ if (datasetObservers != null) {
+ datasetObservers.remove(observer);
+ }
+ }
+
+ /**
+ * Notifies observers about data changing
+ */
+ protected void notifyDataChangedEvent() {
+ if (datasetObservers != null) {
+ for (DataSetObserver observer : datasetObservers) {
+ observer.onChanged();
+ }
+ }
+ }
+
+ /**
+ * Notifies observers about invalidating data
+ */
+ protected void notifyDataInvalidatedEvent() {
+ if (datasetObservers != null) {
+ for (DataSetObserver observer : datasetObservers) {
+ observer.onInvalidated();
+ }
+ }
+ }
+}
diff --git a/platform/java/src/kankan/wheel/widget/adapters/AbstractWheelTextAdapter.java b/platform/java/src/kankan/wheel/widget/adapters/AbstractWheelTextAdapter.java
new file mode 100644
index 00000000..620c8e74
--- /dev/null
+++ b/platform/java/src/kankan/wheel/widget/adapters/AbstractWheelTextAdapter.java
@@ -0,0 +1,268 @@
+/*
+ * Copyright 2011 Yuri Kanivets
+ *
+ * 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 kankan.wheel.widget.adapters;
+
+import android.content.Context;
+import android.graphics.Typeface;
+import android.util.Log;
+import android.view.Gravity;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+
+/**
+ * Abstract wheel adapter provides common functionality for adapters.
+ */
+public abstract class AbstractWheelTextAdapter extends AbstractWheelAdapter {
+
+ /** Text view resource. Used as a default view for adapter. */
+ public static final int TEXT_VIEW_ITEM_RESOURCE = -1;
+
+ /** No resource constant. */
+ protected static final int NO_RESOURCE = 0;
+
+ /** Default text color */
+ public static final int DEFAULT_TEXT_COLOR = 0xFF101010;
+
+ /** Default text color */
+ public static final int LABEL_COLOR = 0xFF700070;
+
+ /** Default text size */
+ public static final int DEFAULT_TEXT_SIZE = 24;
+
+ // Text settings
+ private int textColor = DEFAULT_TEXT_COLOR;
+ private int textSize = DEFAULT_TEXT_SIZE;
+
+ // Current context
+ protected Context context;
+ // Layout inflater
+ protected LayoutInflater inflater;
+
+ // Items resources
+ protected int itemResourceId;
+ protected int itemTextResourceId;
+
+ // Empty items resources
+ protected int emptyItemResourceId;
+
+ /**
+ * Constructor
+ * @param context the current context
+ */
+ protected AbstractWheelTextAdapter(Context context) {
+ this(context, TEXT_VIEW_ITEM_RESOURCE);
+ }
+
+ /**
+ * Constructor
+ * @param context the current context
+ * @param itemResource the resource ID for a layout file containing a TextView to use when instantiating items views
+ */
+ protected AbstractWheelTextAdapter(Context context, int itemResource) {
+ this(context, itemResource, NO_RESOURCE);
+ }
+
+ /**
+ * Constructor
+ * @param context the current context
+ * @param itemResource the resource ID for a layout file containing a TextView to use when instantiating items views
+ * @param itemTextResource the resource ID for a text view in the item layout
+ */
+ protected AbstractWheelTextAdapter(Context context, int itemResource, int itemTextResource) {
+ this.context = context;
+ itemResourceId = itemResource;
+ itemTextResourceId = itemTextResource;
+
+ inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ }
+
+ /**
+ * Gets text color
+ * @return the text color
+ */
+ public int getTextColor() {
+ return textColor;
+ }
+
+ /**
+ * Sets text color
+ * @param textColor the text color to set
+ */
+ public void setTextColor(int textColor) {
+ this.textColor = textColor;
+ }
+
+ /**
+ * Gets text size
+ * @return the text size
+ */
+ public int getTextSize() {
+ return textSize;
+ }
+
+ /**
+ * Sets text size
+ * @param textSize the text size to set
+ */
+ public void setTextSize(int textSize) {
+ this.textSize = textSize;
+ }
+
+ /**
+ * Gets resource Id for items views
+ * @return the item resource Id
+ */
+ public int getItemResource() {
+ return itemResourceId;
+ }
+
+ /**
+ * Sets resource Id for items views
+ * @param itemResourceId the resource Id to set
+ */
+ public void setItemResource(int itemResourceId) {
+ this.itemResourceId = itemResourceId;
+ }
+
+ /**
+ * Gets resource Id for text view in item layout
+ * @return the item text resource Id
+ */
+ public int getItemTextResource() {
+ return itemTextResourceId;
+ }
+
+ /**
+ * Sets resource Id for text view in item layout
+ * @param itemTextResourceId the item text resource Id to set
+ */
+ public void setItemTextResource(int itemTextResourceId) {
+ this.itemTextResourceId = itemTextResourceId;
+ }
+
+ /**
+ * Gets resource Id for empty items views
+ * @return the empty item resource Id
+ */
+ public int getEmptyItemResource() {
+ return emptyItemResourceId;
+ }
+
+ /**
+ * Sets resource Id for empty items views
+ * @param emptyItemResourceId the empty item resource Id to set
+ */
+ public void setEmptyItemResource(int emptyItemResourceId) {
+ this.emptyItemResourceId = emptyItemResourceId;
+ }
+
+
+ /**
+ * Returns text for specified item
+ * @param index the item index
+ * @return the text of specified items
+ */
+ protected abstract CharSequence getItemText(int index);
+
+ @Override
+ public View getItem(int index, View convertView, ViewGroup parent) {
+ if (index >= 0 && index < getItemsCount()) {
+ if (convertView == null) {
+ convertView = getView(itemResourceId, parent);
+ }
+ TextView textView = getTextView(convertView, itemTextResourceId);
+ if (textView != null) {
+ CharSequence text = getItemText(index);
+ if (text == null) {
+ text = "";
+ }
+ textView.setText(text);
+
+ if (itemResourceId == TEXT_VIEW_ITEM_RESOURCE) {
+ configureTextView(textView);
+ }
+ }
+ return convertView;
+ }
+ return null;
+ }
+
+ @Override
+ public View getEmptyItem(View convertView, ViewGroup parent) {
+ if (convertView == null) {
+ convertView = getView(emptyItemResourceId, parent);
+ }
+ if (emptyItemResourceId == TEXT_VIEW_ITEM_RESOURCE && convertView instanceof TextView) {
+ configureTextView((TextView)convertView);
+ }
+
+ return convertView;
+ }
+
+ /**
+ * Configures text view. Is called for the TEXT_VIEW_ITEM_RESOURCE views.
+ * @param view the text view to be configured
+ */
+ protected void configureTextView(TextView view) {
+ view.setTextColor(textColor);
+ view.setGravity(Gravity.CENTER);
+ view.setTextSize(textSize);
+ view.setLines(1);
+// view.setTypeface(Typeface.SANS_SERIF, Typeface.BOLD);
+ view.setTypeface(Typeface.SANS_SERIF, Typeface.NORMAL);
+ }
+
+ /**
+ * Loads a text view from view
+ * @param view the text view or layout containing it
+ * @param textResource the text resource Id in layout
+ * @return the loaded text view
+ */
+ private TextView getTextView(View view, int textResource) {
+ TextView text = null;
+ try {
+ if (textResource == NO_RESOURCE && view instanceof TextView) {
+ text = (TextView) view;
+ } else if (textResource != NO_RESOURCE) {
+ text = (TextView) view.findViewById(textResource);
+ }
+ } catch (ClassCastException e) {
+ Log.e("AbstractWheelAdapter", "You must supply a resource ID for a TextView");
+ throw new IllegalStateException(
+ "AbstractWheelAdapter requires the resource ID to be a TextView", e);
+ }
+
+ return text;
+ }
+
+ /**
+ * Loads view from resources
+ * @param resource the resource Id
+ * @return the loaded view or null if resource is not set
+ */
+ private View getView(int resource, ViewGroup parent) {
+ switch (resource) {
+ case NO_RESOURCE:
+ return null;
+ case TEXT_VIEW_ITEM_RESOURCE:
+ return new TextView(context);
+ default:
+ return inflater.inflate(resource, parent, false);
+ }
+ }
+}
diff --git a/platform/java/src/kankan/wheel/widget/adapters/AdapterWheel.java b/platform/java/src/kankan/wheel/widget/adapters/AdapterWheel.java
new file mode 100644
index 00000000..000001cd
--- /dev/null
+++ b/platform/java/src/kankan/wheel/widget/adapters/AdapterWheel.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2011 Yuri Kanivets
+ *
+ * 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 kankan.wheel.widget.adapters;
+
+import android.content.Context;
+
+import kankan.wheel.widget.WheelAdapter;
+
+/**
+ * Adapter class for old wheel adapter (deprecated WheelAdapter class).
+ *
+ * @deprecated Will be removed soon
+ */
+public class AdapterWheel extends AbstractWheelTextAdapter {
+
+ // Source adapter
+ private WheelAdapter adapter;
+
+ /**
+ * Constructor
+ * @param context the current context
+ * @param adapter the source adapter
+ */
+ public AdapterWheel(Context context, WheelAdapter adapter) {
+ super(context);
+
+ this.adapter = adapter;
+ }
+
+ /**
+ * Gets original adapter
+ * @return the original adapter
+ */
+ public WheelAdapter getAdapter() {
+ return adapter;
+ }
+
+ @Override
+ public int getItemsCount() {
+ return adapter.getItemsCount();
+ }
+
+ @Override
+ protected CharSequence getItemText(int index) {
+ return adapter.getItem(index);
+ }
+
+}
diff --git a/platform/java/src/kankan/wheel/widget/adapters/ArrayWheelAdapter.java b/platform/java/src/kankan/wheel/widget/adapters/ArrayWheelAdapter.java
new file mode 100644
index 00000000..c9d430d7
--- /dev/null
+++ b/platform/java/src/kankan/wheel/widget/adapters/ArrayWheelAdapter.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2011 Yuri Kanivets
+ *
+ * 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 kankan.wheel.widget.adapters;
+
+import android.content.Context;
+
+/**
+ * The simple Array wheel adapter
+ * @param <T> the element type
+ */
+public class ArrayWheelAdapter<T> extends AbstractWheelTextAdapter {
+
+ // items
+ private T items[];
+
+ /**
+ * Constructor
+ * @param context the current context
+ * @param items the items
+ */
+ public ArrayWheelAdapter(Context context, T items[]) {
+ super(context);
+
+ //setEmptyItemResource(TEXT_VIEW_ITEM_RESOURCE);
+ this.items = items;
+ }
+
+ public void setItems(T items[])
+ {
+ this.items = items;
+ }
+
+ @Override
+ public CharSequence getItemText(int index) {
+ if (index >= 0 && index < items.length) {
+ T item = items[index];
+ if (item instanceof CharSequence) {
+ return (CharSequence) item;
+ }
+ return item.toString();
+ }
+ return null;
+ }
+
+ @Override
+ public int getItemsCount() {
+ return items.length;
+ }
+}
diff --git a/platform/java/src/kankan/wheel/widget/adapters/ArrayWheelAdapterColor.java b/platform/java/src/kankan/wheel/widget/adapters/ArrayWheelAdapterColor.java
new file mode 100644
index 00000000..cf4a9954
--- /dev/null
+++ b/platform/java/src/kankan/wheel/widget/adapters/ArrayWheelAdapterColor.java
@@ -0,0 +1,50 @@
+package kankan.wheel.widget.adapters;
+
+import android.content.Context;
+import android.graphics.Color;
+import android.widget.TextView;
+
+public class ArrayWheelAdapterColor<T> extends AbstractWheelTextAdapter {
+
+ // items
+ private T items[];
+
+ public ArrayWheelAdapterColor(Context context, T items[]) {
+ super(context);
+
+ this.items = items;
+ }
+
+ @Override
+ public CharSequence getItemText(int index) {
+ if (index >= 0 && index < items.length) {
+ T item = items[index];
+ if (item instanceof CharSequence) {
+ return (CharSequence) item;
+ }
+ return item.toString();
+ }
+ return null;
+ }
+
+ @Override
+ public int getItemsCount() {
+ return items.length;
+ }
+
+ @Override
+ protected void configureTextView(TextView view) {
+ super.configureTextView(view);
+
+ // if the text ends with "(red)"
+ // color it red.
+ String text = view.getText().toString();
+ if (text.endsWith("(red)"))
+ {
+ text = text.replace("(red)","");
+ view.setText(text);
+ view.setTextColor(Color.parseColor("#ff0000"));
+ }
+ }
+
+} \ No newline at end of file
diff --git a/platform/java/src/kankan/wheel/widget/adapters/NumericWheelAdapter.java b/platform/java/src/kankan/wheel/widget/adapters/NumericWheelAdapter.java
new file mode 100644
index 00000000..ec8b9c86
--- /dev/null
+++ b/platform/java/src/kankan/wheel/widget/adapters/NumericWheelAdapter.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2011 Yuri Kanivets
+ *
+ * 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 kankan.wheel.widget.adapters;
+
+import android.content.Context;
+
+/**
+ * Numeric Wheel adapter.
+ */
+public class NumericWheelAdapter extends AbstractWheelTextAdapter {
+
+ /** The default min value */
+ public static final int DEFAULT_MAX_VALUE = 9;
+
+ /** The default max value */
+ private static final int DEFAULT_MIN_VALUE = 0;
+
+ // Values
+ private int minValue;
+ private int maxValue;
+
+ // format
+ private String format;
+
+ /**
+ * Constructor
+ * @param context the current context
+ */
+ public NumericWheelAdapter(Context context) {
+ this(context, DEFAULT_MIN_VALUE, DEFAULT_MAX_VALUE);
+ }
+
+ /**
+ * Constructor
+ * @param context the current context
+ * @param minValue the wheel min value
+ * @param maxValue the wheel max value
+ */
+ public NumericWheelAdapter(Context context, int minValue, int maxValue) {
+ this(context, minValue, maxValue, null);
+ }
+
+ /**
+ * Constructor
+ * @param context the current context
+ * @param minValue the wheel min value
+ * @param maxValue the wheel max value
+ * @param format the format string
+ */
+ public NumericWheelAdapter(Context context, int minValue, int maxValue, String format) {
+ super(context);
+
+ this.minValue = minValue;
+ this.maxValue = maxValue;
+ this.format = format;
+ }
+
+ @Override
+ public CharSequence getItemText(int index) {
+ if (index >= 0 && index < getItemsCount()) {
+ int value = minValue + index;
+ return format != null ? String.format(format, value) : Integer.toString(value);
+ }
+ return null;
+ }
+
+ @Override
+ public int getItemsCount() {
+ return maxValue - minValue + 1;
+ }
+}
diff --git a/platform/java/src/kankan/wheel/widget/adapters/WheelViewAdapter.java b/platform/java/src/kankan/wheel/widget/adapters/WheelViewAdapter.java
new file mode 100644
index 00000000..db256570
--- /dev/null
+++ b/platform/java/src/kankan/wheel/widget/adapters/WheelViewAdapter.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2011 Yuri Kanivets
+ *
+ * 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 kankan.wheel.widget.adapters;
+
+import android.database.DataSetObserver;
+import android.view.View;
+import android.view.ViewGroup;
+
+/**
+ * Wheel items adapter interface
+ */
+public interface WheelViewAdapter {
+ /**
+ * Gets items count
+ * @return the count of wheel items
+ */
+ public int getItemsCount();
+
+ /**
+ * Get a View that displays the data at the specified position in the data set
+ *
+ * @param index the item index
+ * @param convertView the old view to reuse if possible
+ * @param parent the parent that this view will eventually be attached to
+ * @return the wheel item View
+ */
+ public View getItem(int index, View convertView, ViewGroup parent);
+
+ /**
+ * Get a View that displays an empty wheel item placed before the first or after
+ * the last wheel item.
+ *
+ * @param convertView the old view to reuse if possible
+ * @param parent the parent that this view will eventually be attached to
+ * @return the empty item View
+ */
+ public View getEmptyItem(View convertView, ViewGroup parent);
+
+ /**
+ * Register an observer that is called when changes happen to the data used by this adapter.
+ * @param observer the observer to be registered
+ */
+ public void registerDataSetObserver(DataSetObserver observer);
+
+ /**
+ * Unregister an observer that has previously been registered
+ * @param observer the observer to be unregistered
+ */
+ void unregisterDataSetObserver (DataSetObserver observer);
+}