diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/AutoLinearLayout.java b/android/src/main/java/com/qliktrialreactnativestraighttable/AutoLinearLayout.java deleted file mode 100644 index c3f8ce53..00000000 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/AutoLinearLayout.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.qliktrialreactnativestraighttable; - -import android.content.Context; -import android.widget.LinearLayout; - -public class AutoLinearLayout extends LinearLayout { - public AutoLinearLayout(Context context) { - super(context); - } - - @Override - public void requestLayout() { - super.requestLayout(); - post(measureAndLayout); - } - - private final Runnable measureAndLayout = new Runnable() { - @Override - public void run() { - measure( - MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.EXACTLY), - MeasureSpec.makeMeasureSpec(getHeight(), MeasureSpec.EXACTLY)); - layout(getLeft(), getTop(), getRight(), getBottom()); - } - }; -} diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/CellContentStyle.java b/android/src/main/java/com/qliktrialreactnativestraighttable/CellContentStyle.java deleted file mode 100644 index a48cde77..00000000 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/CellContentStyle.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.qliktrialreactnativestraighttable; - -import com.facebook.react.bridge.ReadableMap; - -public class CellContentStyle extends HeaderContentStyle { - int rowHeight = 1; - int lineCount = 1; - int themedRowHeight = 1; - CellContentStyle(ReadableMap data) { - super(data); - lineCount = JsonUtils.getInt(data, "rowHeight", 1); - - } -} diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/CellView.java b/android/src/main/java/com/qliktrialreactnativestraighttable/CellView.java deleted file mode 100644 index 7d4b1346..00000000 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/CellView.java +++ /dev/null @@ -1,234 +0,0 @@ -package com.qliktrialreactnativestraighttable; - -import android.annotation.SuppressLint; -import android.content.ClipData; -import android.content.ClipboardManager; -import android.content.Context; -import android.graphics.Canvas; -import android.graphics.Color; -import android.graphics.ImageFormat; -import android.graphics.Rect; -import android.view.GestureDetector; -import android.view.MenuItem; -import android.view.MotionEvent; -import android.view.View; -import android.view.ViewGroup; -import android.view.animation.Animation; -import android.view.animation.AnimationUtils; -import android.widget.FrameLayout; -import android.widget.LinearLayout; -import android.widget.RelativeLayout; -import android.widget.ScrollView; - -@SuppressLint("ViewConstructor") -public class CellView extends RelativeLayout implements SelectionsObserver { - Content content = null; - DataRow row; - DataColumn column; - FrameLayout wrapper = null; - RelativeLayout.LayoutParams wrapperLayout = null; - final DragBoxEventHandler dragBoxEventHandler; - final SelectionsEngine selectionsEngine; - final TableView tableView; - final boolean isInFirstColumnRecyclerView; - final View.OnCreateContextMenuListener onCreateContextMenuListener; - GestureDetector gestureDetector; - static final int PADDING = TableTheme.CellPadding; - static final int PADDING_X_2 = TableTheme.CellPadding * 2; - - @SuppressLint("ClickableViewAccessibility") - CellView(Context context, String type, SelectionsEngine selectionsEngine, TableView tableView, boolean isInFirstColumnRecyclerView, DataColumn dataColumn) { - super(context); - this.tableView = tableView; - this.selectionsEngine = selectionsEngine; - this.isInFirstColumnRecyclerView = isInFirstColumnRecyclerView; - this.dragBoxEventHandler = tableView.dragBoxEventHandler; - - createContent(type, dataColumn); - - dragBoxEventHandler.addDragBoxListener(this::handleDragBoxDrag); - gestureDetector = new GestureDetector(getContext(), new CellView.SingleTapListener()); - - MenuItem.OnMenuItemClickListener handleMenuItemClick = item -> { - switch (item.getItemId()) { - case 0: // Copy - copyCell(); - break; - case 1: // Expand - default: - expandRow(); - } - return true; - }; - String copyString = tableView.getTranslation("menu", content.getCopyMenuString()); - String expandString = tableView.getTranslation("menu", "expand"); - - onCreateContextMenuListener = (contextMenu, view, contextMenuInfo) -> { - contextMenu.add(0, 0, 0, copyString).setOnMenuItemClickListener(handleMenuItemClick); - contextMenu.add(0, 1, 1, expandString).setOnMenuItemClickListener(handleMenuItemClick); - }; - setOnCreateContextMenuListener(onCreateContextMenuListener); - addContentView(type); - } - - private void createContent(String type, DataColumn dataColumn) { - switch (type) { - case "text": - ClickableTextView textView = new ClickableTextView(getContext(), selectionsEngine, tableView, this, dataColumn); - textView.setPadding(PADDING, 0, PADDING, 0); - content = textView; - break; - case "image": - wrapper = new FrameLayout(getContext()); - wrapperLayout = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); - content = new ClickableImageView(getContext(), selectionsEngine, tableView, this); - wrapper.addView((View) content); - break; - case "miniChart": - content = new MiniChartView(getContext()); - this.setPadding(PADDING, 0, PADDING, 0); - break; - } - } - - private void addContentView(String type) { - if(type.equals("image")) { - this.addView(wrapper, wrapperLayout); - } else { - View contentView = (View) content; - this.addView(contentView); - } - } - - public void convertCellContentType(String type, DataColumn dataColumn) { - wrapper = null; - wrapperLayout = null; - column = dataColumn; - removeAllViews(); - createContent(type, dataColumn); - addContentView(type); - } - - @Override - public boolean onTouchEvent(MotionEvent event) { - gestureDetector.onTouchEvent(event); - if(content != null) { - return content.handleTouch(event); - } - return super.onTouchEvent(event); - } - - public void handleDragBoxDrag(Rect dragBoxBounds, int columnId) { - DataCell cell = content.getCell(); - if(cell == null || columnId != cell.rawColIdx) { - return; - } - Rect cellBounds = getBounds(); - boolean hasIntersect = dragBoxBounds.intersect(cellBounds); - if(!this.content.isSelected() && hasIntersect) { - selectCell(); - } - } - - private void expandRow() { - EventUtils.sendOnExpand(tableView, row); - } - - private void copyCell(){ - if(content != null) { - content.copyToClipBoard(); - } - } - - public void setData(DataCell cell, DataRow row, DataColumn column) { - this.row = row; - this.column = column; - content.setCellData(cell, row, column); - if (cell.isDim) { - selectionsEngine.observe(this); - content.setSelected(selectionsEngine.contains(cell)); - content.updateBackgroundColor(false); - postInvalidate(); - } - } - - private void selectCell() { - DataCell cell = content.getCell(); - String selection = SelectionsEngine.getSignatureFrom(cell); - selectionsEngine.selectionsChanged(this.tableView, selection); - } - - private Rect getBounds() { - Rect bounds = new Rect(); - this.getDrawingRect(bounds); - try { - if(isInFirstColumnRecyclerView) { - tableView.offsetDescendantRectToMyCoords(this, bounds); - } else { - tableView.rootLayout.offsetDescendantRectToMyCoords(this, bounds); - } - } catch (IllegalArgumentException e) { - // ignore if cell offscreen - } - return bounds; - } - - public void handleSingleTap() { - DataCell cell = content.getCell(); - if (cell != null && cell.isDim) { - Rect bounds = getBounds(); - if(!content.isSelected()) { - tableView.showDragBox(bounds, cell.rawColIdx); - } else { - tableView.hideDragBoxes(); - } - selectCell(); - } - } - - public void onSelectionsChanged(String s) { - DataCell cell = content.getCell(); - String received = SelectionsEngine.getKeyFrom(s); - String me = SelectionsEngine.getKeyFrom(cell); - if(received.equalsIgnoreCase(me)) { - content.toggleSelected(); - content.updateBackgroundColor(true); - } - } - - public void onClear() { - content.setSelected(false); - content.updateBackgroundColor(false); - } - - public void onRecycled() { - DataCell cell = content.getCell(); - if (cell != null && cell.isDim) { - selectionsEngine.remove(this); - } - } - - @Override - protected void onLayout(boolean changed, int l, int t, int r, int b) { - super.onLayout(changed, l, t, r, b); - LinearLayout.LayoutParams layout = (LinearLayout.LayoutParams) getLayoutParams(); - if(column == null) { - return; - } - layout.width = column.width; - setLayoutParams(layout); - } - - class SingleTapListener extends GestureDetector.SimpleOnGestureListener { - @Override - public boolean onSingleTapConfirmed(MotionEvent motionEvent) { - handleSingleTap(); - return true; - } - - @Override - public void onLongPress(MotionEvent e) { - ((View) content).showContextMenu(e.getX(), e.getY()); - } - } -} diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/ClickableTextView.java b/android/src/main/java/com/qliktrialreactnativestraighttable/ClickableTextView.java deleted file mode 100644 index 4ebdbf81..00000000 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/ClickableTextView.java +++ /dev/null @@ -1,242 +0,0 @@ -package com.qliktrialreactnativestraighttable; - -import android.annotation.SuppressLint; -import android.content.ClipData; -import android.content.ClipboardManager; -import android.content.Context; -import android.graphics.Canvas; -import android.graphics.Color; -import android.text.Html; -import android.util.Log; -import android.graphics.Paint; -import android.graphics.Rect; -import android.graphics.Typeface; -import android.graphics.fonts.Font; -import android.graphics.fonts.FontFamily; -import android.text.Spannable; -import android.text.SpannableString; -import android.text.Spanned; -import android.text.TextPaint; -import android.text.method.LinkMovementMethod; -import android.text.method.MovementMethod; -import android.view.GestureDetector; -import android.view.MotionEvent; -import android.view.ViewGroup; -import android.view.animation.Animation; -import android.view.animation.AnimationUtils; -import android.widget.TextView; - -import java.io.UnsupportedEncodingException; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URLEncoder; -import java.nio.charset.Charset; -import java.util.HashMap; - -import kotlin.text.Charsets; - -@SuppressLint("ViewConstructor") -public class ClickableTextView extends androidx.appcompat.widget.AppCompatTextView implements Content { - DataColumn column; - final CellView cellView; - final SelectionsEngine selectionsEngine; - final TableView tableView; - String linkUrl = null; - String linkLabel = null; - DataCell cell = null; - boolean selected = false; - int defaultTextColor = Color.BLACK; - Animation fadeIn; - ClickableTextWrapper textWrapper; - ClickableTextView(Context context, SelectionsEngine selectionsEngine, TableView tableView, CellView cellView, DataColumn column) { - super(context); - this.tableView = tableView; - this.selectionsEngine = selectionsEngine; - this.cellView = cellView; - this.column = column; - defaultTextColor = getCurrentTextColor(); - fadeIn = AnimationUtils.loadAnimation(context, R.anim.catalyst_fade_in); - textWrapper = new ClickableTextWrapper(tableView, this); - } - - @SuppressLint("ClickableViewAccessibility") - @Override - public boolean handleTouch(MotionEvent e) { - // Checks to see if there's a link, if there is and the user - // tapped on the link text, then forward the event to the movementMethod. - // otherwise forward the event to the gesture detector - MovementMethod movementMethod = this.getMovementMethod(); - if(movementMethod != null ) { - // first check to see if use tapped on text if this is a link - Rect bounds = getMeasuredTextBounds(); - int x = (int)e.getX(); - int y = (int)e.getY(); - boolean insideText = bounds.contains(x, y); - // if user is inside, then forward to the link listener - if(insideText) { - return movementMethod.onTouchEvent(this, new SpannableString(this.getText()), e); - } - } - return true; - } - - private Rect getMeasuredTextBounds() { - String s = this.getText().toString(); - - Rect bounds = new Rect(); - TextPaint textPaint = this.getPaint(); - - textPaint.getTextBounds(s, 0, s.length(), bounds); - int baseline = this.getBaseline(); - bounds.top = baseline + bounds.top; - bounds.bottom = bounds.top + this.getMeasuredHeight() ; - int startPadding = this.getPaddingStart(); - bounds.left += startPadding; - - bounds.right = (int) textPaint.measureText(s, 0, s.length()) + startPadding; - return bounds; - } - - public void updateBackgroundColor(boolean shouldAnimate) { - int bgColor = cell.cellBackgroundColorValid ? cell.cellBackgroundColor : Color.TRANSPARENT; - int fgColor = cell.cellForegroundColorValid ? cell.cellForegroundColor : tableView.cellContentStyle.color; - int color = selected ? TableTheme.selectedBackground : bgColor ; - int textColor = selected ? Color.WHITE : fgColor ; - cellView.setBackgroundColor(color); - setBackgroundColor(color); - setTextColor(textColor); - postInvalidate(); - if(shouldAnimate) { - startAnimation(fadeIn); - } - } - - @Override - public void toggleSelected() { - this.selected = !selected; - } - - private void setupUrl() { - if(column.representation == null || column.stylingInfo == null) { - return; - } - int urlLabelIndex = column.stylingInfo.indexOf("urlLabel"); - String urlLabel = ""; - if(urlLabelIndex != -1) { - String qText = cell.qAttrExpValues.get(urlLabelIndex).qText; - urlLabel = qText != null ? qText : ""; - } else { - if(column.representation.urlPosition != null) { - urlLabel = column.representation.urlPosition.equals("dimension") ? (column.representation.linkUrl != null ? column.representation.linkUrl : "") : (cell.qText != null ? cell.qText : ""); - } else { - urlLabel = cell.qText == null ? "" : cell.qText; - } - } - String urlText = cell.qText; - int attrIndex = column.stylingInfo.indexOf("url"); - if(attrIndex != -1) { - urlText = cell.qAttrExpValues.get(attrIndex).qText; - } - if(urlLabel.isEmpty()) { - urlLabel = cell.qText != null ? cell.qText : "link"; - } - if(urlText != null) { - String spaceEncodedUrl = urlText.replaceAll(" ", "%20"); - this.linkUrl = spaceEncodedUrl; - } else { - this.linkUrl = ""; - } - this.linkLabel = Html.escapeHtml(urlLabel); - } - - @Override - public void setCellData(DataCell cell, DataRow row, DataColumn column) { - this.column = column; - this.cell = cell; - - if(cell.indicator != null) { - buildSpannableText(); - } else { - setText(cell.qText); - textWrapper.countWords(cell.qText); - } - - setTextColor(cell.cellForegroundColorValid ? cell.cellForegroundColor : tableView.cellContentStyle.color); - setBackgroundColor(cell.cellBackgroundColorValid ? cell.cellBackgroundColor : Color.TRANSPARENT); - - if(cell.type.equals("url")) { - setupUrl(); - } - } - - private void buildSpannableText() { - int textColor = cell.indicator.applySegmentColors ? cell.indicator.color : TableTheme.defaultTextColor; - StringBuilder builder = new StringBuilder(cell.qText); - Spannable spannable; - if(cell.indicator.hasIcon) { - if(cell.indicator.position.equals("right")) { - builder.append(" "); - builder.append(cell.indicator.icon); - spannable = new SpannableString(builder.toString()); - spannable.setSpan(new ConditionalTypeFaceSpan(this.getTypeface(), textColor), 0, cell.qText.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - spannable.setSpan(new ConditionalTypeFaceSpan(TableTheme.iconFonts, cell.indicator.color), cell.qText.length(), cell.qText.length() + 2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); - } else { - builder.insert(0, cell.indicator.icon); - builder.insert(1, " "); - spannable = new SpannableString(builder.toString()); - spannable.setSpan(new ConditionalTypeFaceSpan(TableTheme.iconFonts, cell.indicator.color), 0, 2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); - spannable.setSpan(new ConditionalTypeFaceSpan(this.getTypeface(), textColor), 2, cell.qText.length() + 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - } - } else { - spannable = new SpannableString(builder.toString()); - spannable.setSpan(new ConditionalTypeFaceSpan(this.getTypeface(), textColor), 0, cell.qText.length() , Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - } - setText(spannable); - textWrapper.countWords(spannable.toString()); - } - - @Override - public DataCell getCell() { - return this.cell; - } - - @Override - public void setSelected(boolean value) { - selected = value; - } - - public boolean isSelected(){ - return selected; - } - - @Override - public void setMaxLines(int maxLines) { - maxLines = textWrapper.setMaxLines(maxLines); - super.setMaxLines(maxLines); - } - - public void testTextWrap(DataColumn dataColumn) { - if(tableView.cellContentStyle.wrap) { - textWrapper.testTextWrap(dataColumn); - } - } - - public int getMeasuredLineCount() { - return textWrapper.getMeasuredLinedCount(); - } - - public int measureLines(DataColumn dataColumn) { - return textWrapper.getMeasureLinedCount(dataColumn); - } - - public void copyToClipBoard() { - String text = cell != null ? cell.qText : ""; - ClipboardManager clipboard = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE); - ClipData clip = ClipData.newPlainText(text, text); - clipboard.setPrimaryClip(clip); - } - - public String getCopyMenuString() { - return "copy"; - } -} diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/ClickableTextWrapper.java b/android/src/main/java/com/qliktrialreactnativestraighttable/ClickableTextWrapper.java deleted file mode 100644 index b23e44f2..00000000 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/ClickableTextWrapper.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.qliktrialreactnativestraighttable; - -import android.widget.TextView; - -public class ClickableTextWrapper extends TextWrapper{ - ClickableTextWrapper(TableView tableView, TextView textView) { - super(tableView, textView); - } - - @Override - void measureLineCount() { - if(wordCount > 1) { - int lines = calculateLineCount(); - if(lines != lineCount && lines <= wordCount) { - lineCount = lines; - tableView.updateRecyclerViewLineCount(column); - } - } - } - int getMeasureLinedCount(DataColumn column) { - this.column = column; - if(wordCount > 1) { - return calculateLineCount(); - } - return 1; - } -} diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/ColumnWidths.java b/android/src/main/java/com/qliktrialreactnativestraighttable/ColumnWidths.java deleted file mode 100644 index 37cc7e66..00000000 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/ColumnWidths.java +++ /dev/null @@ -1,165 +0,0 @@ -package com.qliktrialreactnativestraighttable; - -import android.content.Context; -import android.content.SharedPreferences; -import android.content.res.Configuration; -import android.graphics.Paint; -import android.util.Log; -import android.widget.TextView; - -import org.json.JSONArray; -import org.json.JSONObject; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public class ColumnWidths { - List dataColumns; - protected SharedPreferences preferences ; - protected List widths = new ArrayList<>(); - protected String name = ""; - protected final Context context; - public final String NATIVE_TABLES_KEY = "native.tables"; - - ColumnWidths(Context context) { - this.context = context; - preferences = context.getSharedPreferences(NATIVE_TABLES_KEY, 0); - } - - public void setName(String value) { - name = value; - } - - public void loadWidths(int frameWidth, List dataColumns, List rows) { - this.dataColumns = dataColumns; - widths.clear(); - if(!loadWidthsFromStorage()) { - loadDefaultWidths(frameWidth, rows); - } - - for(DataColumn col : dataColumns) { - widths.add(col.width); - } - } - - private void loadDefaultWidths(int frameWidth, List rows) { - int runningTotal = 0; - for (DataColumn col : dataColumns) { - col.width = resizeColumnByAverage(col, rows, false); - runningTotal += col.width; - } - - if (runningTotal < frameWidth) { - int defaultWidth = frameWidth / dataColumns.size(); - for (DataColumn column : dataColumns) { - column.width = defaultWidth; - } - } - } - - private boolean loadWidthsFromStorage() { - String key = buildTableKey(); - String value = preferences.getString(key, null); - if(value == null) { - return false; - } - try { - JSONArray jsonArray = new JSONArray(value); - for(int i = 0; i< jsonArray.length(); i++) { - JSONArray jsonWidths = jsonArray.getJSONArray(i); - if(jsonWidths.length() != dataColumns.size()) { - return false; - } - for(int j = 0; j < jsonWidths.length(); j++) { - dataColumns.get(j).width = jsonWidths.getInt(j); - } - } - return true; - } catch (Exception exception) { - Log.e("ColumnWidths", exception.getMessage()); - } - return false; - } - - public int resizeColumnByAverage(DataColumn column, List rows, boolean shouldAddWidth) { - int runningTotal = 0; - Paint paint = new Paint(); - for(DataRow row : rows) { - if (row != null) { - String text = column.columnIndex < row.cells.size() ? row.cells.get(column.columnIndex).qText : null; - if(text != null) { - runningTotal += text.length(); - } else { - // give it something - runningTotal += DataProvider.minWidth; - } - } - } - int averageTextSize = runningTotal / rows.size(); - // Create a string with max text - String tempString = new String(new char[averageTextSize]).replace("\0", "X"); - if(column.representation.type.equals("image")) { - return (int) (DataProvider.minWidth * 1.5f); - } - - float width = paint.measureText(tempString, 0, tempString.length()); - width = Math.max(DataProvider.minWidth * 1.5f, PixelUtils.dpToPx(width)); - if(shouldAddWidth) { - widths.add((int)width); - } - return (int)width; - } - - public void updateWidths(List columns) { - if(dataColumns == null) { - return; - } - dataColumns = columns; - for (int i = 0; i < dataColumns.size(); i++) { - DataColumn column = dataColumns.get(i); - if(i < widths.size()) { - column.width = widths.get(i); - } - } - if(dataColumns.size() < widths.size()) { - widths = widths.subList(0, dataColumns.size()); - } - } - - public void updateWidths() { - for (int i = 0; i < dataColumns.size(); i++) { - DataColumn column = dataColumns.get(i); - if(i < widths.size()) { - widths.set(i, column.width); - } - } - if(dataColumns.size() < widths.size()) { - widths = widths.subList(0, dataColumns.size()); - } - } - - public int getTotalWidth() { - return widths.stream().reduce(0, (a, b) -> a + b); - } - - public void syncWidths() { - String key = buildTableKey(); - SharedPreferences.Editor editor = preferences.edit(); - JSONArray jsonArray = new JSONArray(Arrays.asList(widths)); - String value = jsonArray.toString(); - editor.putString(key, value); - editor.apply(); - } - - private String buildTableKey() { - int orientation = context.getResources().getConfiguration().orientation; - String key = ""; - if (orientation == Configuration.ORIENTATION_LANDSCAPE) { - key = String.format("%s.LANDSCAPE", name); - } else { - key = String.format("%s.PORTRAIT", name); - } - return key; - } -} diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/ConditionalTypeFaceSpan.java b/android/src/main/java/com/qliktrialreactnativestraighttable/ConditionalTypeFaceSpan.java deleted file mode 100644 index b3ed0d6f..00000000 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/ConditionalTypeFaceSpan.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.qliktrialreactnativestraighttable; - -import android.annotation.SuppressLint; -import android.graphics.Paint; -import android.graphics.Typeface; -import android.text.TextPaint; -import android.text.style.TypefaceSpan; - -import androidx.annotation.NonNull; - -public class ConditionalTypeFaceSpan extends TypefaceSpan { - private Typeface newType; - private int textColor = TableTheme.defaultTextColor; - - public ConditionalTypeFaceSpan(Typeface typeface) { - super(typeface); - newType = typeface; - } - public ConditionalTypeFaceSpan(Typeface typeface, int textColor) { - super(typeface); - newType = typeface; - this.textColor = textColor; - } - - public ConditionalTypeFaceSpan(String family, Typeface typeface) { - super(family); - newType = typeface; - } - - public ConditionalTypeFaceSpan(String family, Typeface typeface, int color) { - super(family); - newType = typeface; - textColor = color; - } - - @Override - public void updateDrawState(TextPaint tp) { - apply(tp, newType ); - } - - @Override - public void updateMeasureState(@NonNull TextPaint paint) { - apply(paint, newType); - } - - @SuppressLint("WrongConstant") - private void apply(Paint paint, Typeface tp) { - int oldStyle; - Typeface old = paint.getTypeface(); - if (old == null) { - oldStyle = 0; - } else { - oldStyle = old.getStyle(); - } - - int fake = oldStyle & ~tp.getStyle(); - if ((fake & Typeface.BOLD) != 0) { - paint.setFakeBoldText(true); - } - - paint.setColor(textColor); - paint.setTypeface(tp); - - } -} diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/Content.java b/android/src/main/java/com/qliktrialreactnativestraighttable/Content.java deleted file mode 100644 index 6a266a46..00000000 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/Content.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.qliktrialreactnativestraighttable; - -import android.view.GestureDetector; -import android.view.MotionEvent; - -public interface Content { - void updateBackgroundColor(boolean shouldAnimate); - boolean handleTouch(MotionEvent e); - void setSelected(boolean selected); - void toggleSelected(); - boolean isSelected(); - void setCellData(DataCell cell, DataRow row, DataColumn column); - DataCell getCell(); - String getCopyMenuString(); - void copyToClipBoard(); -} diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/CustomLinearLayoutManger.java b/android/src/main/java/com/qliktrialreactnativestraighttable/CustomLinearLayoutManger.java deleted file mode 100644 index fe5cc741..00000000 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/CustomLinearLayoutManger.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.qliktrialreactnativestraighttable; - -import android.content.Context; - -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - -public class CustomLinearLayoutManger extends LinearLayoutManager { - boolean initialized = false; - CustomRecyclerView recyclerView = null; - CustomLinearLayoutManger(Context context) { - super(context); - } - - @Override - public void onLayoutCompleted(RecyclerView.State state) { - super.onLayoutCompleted(state); - if(!initialized && recyclerView != null) { - if(recyclerView.testTextWrap()) { - recyclerView = null; - initialized = true; - } - } - } -} diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/DataColumn.java b/android/src/main/java/com/qliktrialreactnativestraighttable/DataColumn.java deleted file mode 100644 index 9c17219f..00000000 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/DataColumn.java +++ /dev/null @@ -1,98 +0,0 @@ -package com.qliktrialreactnativestraighttable; - -import android.view.Gravity; -import android.view.View; - -import com.facebook.react.bridge.Arguments; -import com.facebook.react.bridge.ReadableArray; -import com.facebook.react.bridge.ReadableMap; -import com.facebook.react.bridge.WritableMap; -import com.facebook.react.bridge.WritableNativeMap; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import java.util.List; - -public class DataColumn { - - public Boolean isDim = false; - public int width = 0; - public int columnIndex = 0; - public String label; - public String id; - public String sortDirection; - public Representation representation; - public List stylingInfo; - public String align; - public int dataColIdx = 0; - public boolean active = false; - public int textAlignment = Gravity.LEFT; - public int rowHeight = TableTheme.DefaultRowHeight; - public DataColumn(ReadableMap source, int index) { - ReadableMap representationMap = source.getMap("representation"); - representation = new Representation(representationMap); - if(source.hasKey("stylingInfo")) { - stylingInfo = source.getArray("stylingInfo").toArrayList(); - } - align = source.getString("align"); - isDim = source.getBoolean("isDim"); - label = source.getString("label"); - id = source.getString("id"); - sortDirection = source.getString("sortDirection"); - dataColIdx = source.getInt("dataColIdx"); - columnIndex = index; - if (source.hasKey("active")) { - active = source.getBoolean("active"); - } - setupTextAlign(); - } - - private void setupTextAlign() { - if( align == null) { - textAlignment = isDim ? Gravity.LEFT : Gravity.RIGHT; - } else { - switch (align) { - case "left": - textAlignment = Gravity.LEFT; - break; - case "center": - textAlignment = Gravity.CENTER; - break; - case "right": - textAlignment = Gravity.RIGHT; - break; - default: - break; - } - } - } - - public JSONObject toEvent() throws JSONException { - JSONObject column = new JSONObject(); - column.put("isDim", isDim); - column.put("width", width); - column.put("label", label); - column.put("id", id); - column.put("align", align); - column.put("sortDirection", sortDirection); - column.put("dataColIdx", dataColIdx); - column.put("active", active); - if(stylingInfo.size() > 0) { - JSONArray json = new JSONArray(); - stylingInfo.forEach(json::put); - column.put("stylingInfo", json); - } - column.put("representation", representation.toEvent()); - - return column; - } - - public boolean isText() { - if(representation != null) { - return representation.type.equals("text") || representation.type.equals("url"); - } - return true; - } -} diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/DataRow.java b/android/src/main/java/com/qliktrialreactnativestraighttable/DataRow.java deleted file mode 100644 index 6a4fe334..00000000 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/DataRow.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.qliktrialreactnativestraighttable; - -import com.facebook.react.bridge.ReadableMap; -import com.facebook.react.bridge.ReadableMapKeySetIterator; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -public class DataRow { - public List cells = new ArrayList<>(); - public DataRow(ReadableMap source, List columns, ImageLoader imageLoader) { - ReadableMapKeySetIterator iterator = source.keySetIterator(); - while (iterator.hasNextKey()) { - String key = iterator.nextKey(); - if(!key.equalsIgnoreCase("key")) { - ReadableMap cellItem = source.getMap(key); - if(cellItem == null) { - continue; - } - int rawColIdx = cellItem.getInt("rawColIdx"); - DataColumn column = DataProvider.getDataColumnByRawIdx(rawColIdx, columns); - if(column == null) { - continue; - } - cells.add(new DataCell(cellItem, column, imageLoader)); - } - } - Collections.sort(cells, (a, b) -> a.rawColIdx - b.rawColIdx); - } - - public String toEvent() throws JSONException { - JSONObject data = new JSONObject(); - JSONArray cellJson = new JSONArray(); - cells.forEach((DataCell cell) -> { - try { - cellJson.put(cell.toEvent()); - } catch (JSONException e) { - e.printStackTrace(); - } - }); - data.put("cells", cellJson); - return data.toString(); - } -} diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/DataSize.java b/android/src/main/java/com/qliktrialreactnativestraighttable/DataSize.java deleted file mode 100644 index 6e88ea80..00000000 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/DataSize.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.qliktrialreactnativestraighttable; - -import com.facebook.react.bridge.ReadableMap; - -public class DataSize { - public int qcx = 0; - public int qcy = 0; - public DataSize(ReadableMap readableMap) { - qcx = readableMap.getInt("qcx"); - qcy = readableMap.getInt("qcy"); - } -} diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/DragBox.java b/android/src/main/java/com/qliktrialreactnativestraighttable/DragBox.java deleted file mode 100644 index edc78fde..00000000 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/DragBox.java +++ /dev/null @@ -1,156 +0,0 @@ -package com.qliktrialreactnativestraighttable; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.graphics.Canvas; -import android.graphics.Color; -import android.graphics.Paint; -import android.graphics.Rect; -import android.view.MotionEvent; -import android.view.View; -import android.widget.FrameLayout; - -import androidx.annotation.NonNull; -import androidx.recyclerview.widget.RecyclerView; - -@SuppressLint("ViewConstructor") -public class DragBox extends View { - final DragBoxEventHandler dragBoxEventHandler; - final TableView tableView; - final boolean isFirstColumnBox; - boolean shown = false; - boolean pressed = false; - int height; - int columnId; - Rect bounds; - Rect grabberLine; - Rect grabberLineTwo; - Rect drawRect; - Rect drawBottomFill; - Paint paint = new Paint(); - - @SuppressLint("ClickableViewAccessibility") - public DragBox(Context context, TableView tableView, DragBoxEventHandler dragBoxEventHandler, boolean isFirstColumnBox){ - super(context); - this.tableView = tableView; - this.setOnTouchListener(new DragBox.TouchListener()); - this.dragBoxEventHandler = dragBoxEventHandler; - this.isFirstColumnBox = isFirstColumnBox; - FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(1, 1); - setX(-1); - setY(-1); - setZ(PixelUtils.dpToPx(1)); - setLayoutParams(layoutParams); - } - - public void show(Rect bounds, int column) { - this.columnId = column; - this.bounds = bounds; - if(this.bounds == null) { - return; - } - int width = bounds.right - bounds.left; - height = bounds.bottom - bounds.top; - FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(width, height); - setX(bounds.left); - setY(bounds.top); - setAlpha(1); - setLayoutParams(layoutParams); - int inset = width / 4; - drawRect = new Rect(0, 0, layoutParams.width, layoutParams.height); - drawBottomFill = new Rect(0, layoutParams.height - 35, layoutParams.width, layoutParams.height); - grabberLine = new Rect(inset, layoutParams.height - 10, layoutParams.width - inset, layoutParams.height - 10); - grabberLineTwo = new Rect(inset, layoutParams.height - 15, layoutParams.width - inset, layoutParams.height - 15); - shown = true; - } - - public void setScrollListener(CustomRecyclerView recyclerView) { - recyclerView.addOnScrollListener(new OnScrollListener()); - } - - public void hide() { - this.bounds = null; - shown = false; - FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(1, 1); - setX(-1); - setY(-1); - setAlpha(0); - setLayoutParams(layoutParams); - } - - @Override - protected void onDraw(Canvas canvas) { - if(!shown && drawRect == null) { - return; - } - super.onDraw(canvas); - paint.setStyle(Paint.Style.FILL); - paint.setColor(Color.DKGRAY); - canvas.drawRect(drawBottomFill, paint); - - paint.setStyle(Paint.Style.STROKE); - paint.setStrokeWidth(10); - canvas.drawRect(drawRect, paint); - - paint.setStrokeWidth(2); - paint.setColor(Color.WHITE); - canvas.drawRect(grabberLine, paint); - canvas.drawRect(grabberLineTwo, paint); - } - - class TouchListener implements OnTouchListener { - float dY = 0; - - @SuppressLint("ClickableViewAccessibility") - @Override - public boolean onTouch(View view, MotionEvent event) { - if(bounds == null) { - return true; - } - - int action = event.getAction(); - switch (action) { - case MotionEvent.ACTION_DOWN: { - tableView.scrollView.setDisableIntercept(true); - pressed = true; - dY = getY() - event.getRawY(); - return true; - } - case MotionEvent.ACTION_MOVE: { - float y = event.getRawY() + dY; - if(y < tableView.getContentTop()) { - return true; - } - if(y + height > tableView.getContentBottom()) { - return true; - } - bounds.top = (int) y; - bounds.bottom = (int) y + height; - setTranslationY(y); - dragBoxEventHandler.fireEvent("dragged", columnId, isFirstColumnBox); - return true; - } - case MotionEvent.ACTION_UP: { - pressed = false; - hide(); - tableView.scrollView.setDisableIntercept(false); - return true; - } - } - return false; - } - } - - class OnScrollListener extends RecyclerView.OnScrollListener { - @Override - public void onScrolled(@NonNull RecyclerView rv, int dx, int dy) { - if(bounds == null) { - return; - } - int y = (int) getY() - dy; - bounds.top = y; - bounds.bottom = y + height; - setTranslationY(y); - } - } -} diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/DragBoxEventHandler.java b/android/src/main/java/com/qliktrialreactnativestraighttable/DragBoxEventHandler.java deleted file mode 100644 index 28be9e33..00000000 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/DragBoxEventHandler.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.qliktrialreactnativestraighttable; - -import android.graphics.Rect; - -import java.util.ArrayList; - -public class DragBoxEventHandler { - final TableView tableView; - DragBox dragBox, firstColumnDragBox; - ArrayList listeners = new ArrayList (); - - public DragBoxEventHandler(TableView tableView) { - this.tableView = tableView; - } - - public void setDragBoxes (DragBox dragBox, DragBox firstColumnDragBox) { - this.dragBox = dragBox; - this.firstColumnDragBox = firstColumnDragBox; - } - public void addDragBoxListener (DragBoxListener listener) { - this.listeners.add(listener); - } - public void fireEvent(String eventType, int columnId, boolean firstColumn) { - for(DragBoxListener listener : listeners) { - switch(eventType) { - case "dragged": { - if(firstColumn) { - Rect bounds = new Rect(firstColumnDragBox.bounds); - tableView.offsetDescendantRectToMyCoords(firstColumnDragBox, bounds); - listener.onDrag(bounds, columnId); - continue; - } - listener.onDrag(dragBox.bounds, columnId); - } - } - } - } -} diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/DragBoxListener.java b/android/src/main/java/com/qliktrialreactnativestraighttable/DragBoxListener.java deleted file mode 100644 index 435ad0a2..00000000 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/DragBoxListener.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.qliktrialreactnativestraighttable; - -import android.graphics.Rect; - -public interface DragBoxListener { - void onDrag(Rect dragBox, int columnId); -} diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/EventUtils.java b/android/src/main/java/com/qliktrialreactnativestraighttable/EventUtils.java deleted file mode 100644 index f8cbea43..00000000 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/EventUtils.java +++ /dev/null @@ -1,82 +0,0 @@ -package com.qliktrialreactnativestraighttable; - -import android.content.Context; -import android.util.Log; -import android.view.View; -import android.widget.FrameLayout; - -import com.facebook.react.bridge.Arguments; -import com.facebook.react.bridge.ReactContext; -import com.facebook.react.bridge.WritableArray; -import com.facebook.react.bridge.WritableMap; -import com.facebook.react.uimanager.events.RCTEventEmitter; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import java.util.List; - -public class EventUtils { - public static void sendEventToJSFromView(View contextView, String eventName) { - if (contextView != null) { - WritableMap event = Arguments.createMap(); - ReactContext context = (ReactContext) contextView.getContext(); - // here the documentation is still using the old receiveEvent, so not sure what to use???? - context.getJSModule(RCTEventEmitter.class).receiveEvent(contextView.getId(), eventName, event); - } - } - public static void sendEventToJSFromView(View contextView, String eventName, WritableMap event) { - if (contextView != null) { - ReactContext context = (ReactContext) contextView.getContext(); - // here the documentation is still using the old receiveEvent, so not sure what to use???? - context.getJSModule(RCTEventEmitter.class).receiveEvent(contextView.getId(), eventName, event); - } - } - - public static void sendOnHeaderTapped(View contextView, DataColumn column) { - WritableMap event = Arguments.createMap(); - try { - String columnJSONString = column.toEvent().toString(); - event.putString("column", columnJSONString); - EventUtils.sendEventToJSFromView(contextView, "onHeaderPressed", event); - } catch (JSONException e) { - e.printStackTrace(); - } - } - - public static void sendOnExpand(TableView tableView, DataRow row) { - WritableMap event = Arguments.createMap(); - List columns = tableView.dataProvider.getDataColumns(); - try { - JSONArray columnJSONArray = new JSONArray(); - for (DataColumn column : columns) { - JSONObject columnJSONObject = column.toEvent(); - columnJSONArray.put(columnJSONObject); - } - String rowJSONString = row.toEvent(); - event.putString("row", rowJSONString); - event.putString("col", columnJSONArray.toString()); - EventUtils.sendEventToJSFromView(tableView, "onExpandCell", event); - } catch (JSONException e) { - e.printStackTrace(); - } - } - - public static void sendOnSearchColumn(View contextView, DataColumn column) { - WritableMap event = Arguments.createMap(); - try { - String columnJSONString = column.toEvent().toString(); - event.putString("column", columnJSONString); - EventUtils.sendEventToJSFromView(contextView, "onSearchColumn", event); - } catch (JSONException e) { - e.printStackTrace(); - } - } - - public static void sendDragBox(View contextView, boolean dragging) { - WritableMap event = Arguments.createMap(); - event.putBoolean("dragging", dragging); - EventUtils.sendEventToJSFromView(contextView, "onDragBox", event); - } -} diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/GrabberView.java b/android/src/main/java/com/qliktrialreactnativestraighttable/GrabberView.java deleted file mode 100644 index bdf1a3ac..00000000 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/GrabberView.java +++ /dev/null @@ -1,220 +0,0 @@ -package com.qliktrialreactnativestraighttable; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.graphics.Canvas; -import android.graphics.Color; -import android.graphics.Paint; -import android.view.MotionEvent; -import android.view.View; -import android.view.ViewGroup; -import android.widget.LinearLayout; -import android.widget.TextView; - -import androidx.recyclerview.widget.RecyclerView; - -import java.util.List; - -public class GrabberView extends LinearLayout { - GrabberButton grabberButton; - Paint linePaint = new Paint(); - final CustomHorizontalScrollView scrollView; - final TableView tableView; - DataProvider dataProvider = null; - AutoLinearLayout headerView = null; - AutoLinearLayout footerView = null; - List grabbers = null; - CustomRecyclerView recyclerView; - CustomRecyclerView firstColumnRecyclerView; - HeaderCell firstColumnHeader; - TotalsViewCell fixedTotalsCell; - ScreenGuideView screenGuideView = null; - RootLayout rootLayout = null; - private final int column; - private boolean isLastColumn = false; - boolean pressed = false; - - class TouchListener implements OnTouchListener { - float dX = 0; - float lastX = 0; - - @Override - public boolean onTouch(View view, MotionEvent motionEvent) { - int action = motionEvent.getAction(); - switch (action) { - case MotionEvent.ACTION_DOWN: { - tableView.hideDragBoxes(); - GrabberView.this.pressed = true; - GrabberView.this.scrollView.setDisableIntercept(true); - GrabberView.this.scrollView.requestDisallowInterceptTouchEvent(true); - lastX = motionEvent.getRawX(); - dX = GrabberView.this.getX() - motionEvent.getRawX(); - GrabberView.this.resetLinePaint(Color.BLACK); - if( screenGuideView != null) { - screenGuideView.fade(0, 1); - } - return true; - } - case MotionEvent.ACTION_MOVE: { - float motionDx = motionEvent.getRawX() - lastX; - motionDx = (float) Math.round(motionDx); - if (dataProvider.updateWidth(motionDx, GrabberView.this.column)) { - // cast here to avoid drift - - GrabberView.this.updateGrabbers(motionDx); - GrabberView.this.updateTotals(); - GrabberView.this.updateHeader(motionDx); - GrabberView.this.updateFixedTotalsCell(motionDx); - GrabberView.this.updateFirstColumnHeader(motionDx); - GrabberView.this.tableView.tableViewFactory.updateScrollbarBounds(); - lastX = motionEvent.getRawX(); - if(isLastColumn && motionDx > 0) { - GrabberView.this.rootLayout.requestLayout(); - GrabberView.this.recyclerView.requestLayout(); - GrabberView.this.scrollView.updateLayout(); - GrabberView.this.scrollView.scrollBy((int) motionDx, 0); - } - } - return true; - } - case MotionEvent.ACTION_UP: { - GrabberView.this.pressed = false; - GrabberView.this.resetLinePaint(TableTheme.borderBackgroundColor); - GrabberView.this.scrollView.setDisableIntercept(false); - GrabberView.this.scrollView.requestDisallowInterceptTouchEvent(false); - GrabberView.this.scrollView.updateLayout(); - GrabberView.this.recyclerView.requestLayout(); - GrabberView.this.rootLayout.requestLayout(); - if(GrabberView.this.firstColumnRecyclerView != null) { - firstColumnRecyclerView.requestLayout(); - } - GrabberView.this.dataProvider.onEndPan(); - GrabberView.this.postInvalidate(); - if(screenGuideView != null) { - screenGuideView.fade(1, 0); - } - return true; - } - } - return false; - } - } - public class GrabberButton extends View { - public GrabberButton(View parent) { - super(parent.getContext()); - } - } - - @SuppressLint("ClickableViewAccessibility") - public GrabberView(int column, Context context, CustomHorizontalScrollView scrollView, TableView tableView) { - super(context); - this.column = column; - this.scrollView = scrollView; - this.tableView = tableView; - grabberButton = new GrabberButton(this); - grabberButton.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, tableView.headerHeight)); - grabberButton.setBackgroundColor(Color.TRANSPARENT); - grabberButton.setOnTouchListener(new TouchListener()); - linePaint.setColor(TableTheme.borderBackgroundColor); - linePaint.setStrokeWidth(PixelUtils.dpToPx(1)); - this.addView(grabberButton); - } - - public void setHeaderHeight(int height) { - if (grabberButton != null) { - ViewGroup.LayoutParams params = grabberButton.getLayoutParams(); - params.height = height; - grabberButton.setLayoutParams(params); - } - } - - public void resetLinePaint(int color) { - linePaint = new Paint(); - linePaint.setColor(color); - linePaint.setStrokeWidth(PixelUtils.dpToPx(1)); - this.invalidate(); - } - - @Override - protected void onDraw(Canvas canvas) { - super.onDraw(canvas); - int width = getWidth() / 2; - int top = 0; - int height = getHeight() - top; - canvas.drawLine(width, top, width, height, linePaint); - } - - public void setFirstColumnHeader(HeaderCell cell) { - this.firstColumnHeader = cell; - } - - public void setFixedTotalsCell(TotalsViewCell cell) { - this.fixedTotalsCell = cell; - } - - public void setFirstColumnRecyclerView(CustomRecyclerView view) { - this.firstColumnRecyclerView = view; - } - - public void setDataProvider(DataProvider provider) { - this.dataProvider = provider; - } - - public void setHeaderView(AutoLinearLayout headerView) { - this.headerView = headerView; - } - - public void setGrabbers(List grabbers) { - this.grabbers = grabbers; - isLastColumn = (column == grabbers.size() - 1); - } - - public void setRecyclerView(RecyclerView recyclerView) { - this.recyclerView = (CustomRecyclerView) recyclerView; - } - - public void updateHeader(float dxMotion) { - HeaderCell headerCell = (HeaderCell)headerView.getChildAt(column); - resizeView(headerCell, dxMotion); - headerCell.cell.testTextWrap(); - } - - public void updateGrabbers(float dxMotion) { - for(GrabberView grabber : tableView.grabbers) { - if(grabber.getX() >= GrabberView.this.getX()) { - grabber.setTranslationX((int) (grabber.getTranslationX() + dxMotion)); - } - } - } - - public void updateTotals() { - TotalsView totalsView = tableView.getTotalsView(); - if(totalsView != null) { - totalsView.updateLayout(); - totalsView.testTextWrap(); - } - } - - public void updateFixedTotalsCell(float dxMotion) { - if(fixedTotalsCell != null && column == 0) { - resizeView(fixedTotalsCell, dxMotion); - fixedTotalsCell.testTextWrap(); - } - } - - public void updateFirstColumnHeader(float dxMotion) { - if(firstColumnHeader != null && column == 0) { - resizeView(firstColumnHeader, dxMotion); - } - } - - public void resizeView(View view, float dxMotion) { - ViewGroup.LayoutParams layoutParams = view.getLayoutParams(); - layoutParams.width += dxMotion; - view.setLayoutParams(layoutParams); - } - - public void updateLayout() { - this.setElevation(PixelUtils.dpToPx(5)); - } -} diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/HeaderView.java b/android/src/main/java/com/qliktrialreactnativestraighttable/HeaderView.java deleted file mode 100644 index c9785ead..00000000 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/HeaderView.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.qliktrialreactnativestraighttable; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.graphics.Color; -import android.view.ViewGroup; - -import java.util.List; - -@SuppressLint("ViewConstructor") -public class HeaderView extends AutoLinearLayout{ - final TableView tableView; - List dataColumns = null; - HeaderView(Context context, TableView tableView) { - super(context); - this.tableView = tableView; - } - - public void setDataColumns(List dataColumns) { - this.dataColumns = dataColumns; - } - - public void update(List dataColumns) { - this.dataColumns = dataColumns; - for(int i = 0; i < this.dataColumns.size(); i++) { - DataColumn column = this.dataColumns.get(i); - HeaderCell headerCell = (HeaderCell) this.getChildAt(i); - headerCell.setColumn(column); - } - } - - public void updateLayout() { - for (int i = 0; i < this.dataColumns.size(); i++){ - HeaderCell headerCell = (HeaderCell)this.getChildAt(i); - ViewGroup.LayoutParams layoutParams = headerCell.getLayoutParams(); - layoutParams.width = dataColumns.get(i).width; - headerCell.setLayoutParams(layoutParams); - } - } - - public void testTextWrap() { - for (int i = 0; i < this.dataColumns.size(); i++) { - HeaderCell headerCell = (HeaderCell) this.getChildAt(i); - headerCell.cell.testTextWrap(); - } - } - - public int getMaxLineCount() { - int lineCount = 0; - for(int i = 0; i < this.dataColumns.size(); i++) { - HeaderCell headerCell = (HeaderCell)this.getChildAt(i); - lineCount = Math.max(lineCount, headerCell.cell.getMeasuredLinedCount()); - } - - for(int i = 0; i < this.dataColumns.size(); i++) { - HeaderCell headerCell = (HeaderCell)this.getChildAt(i); - headerCell.cell.setMaxLines(lineCount); - } - return lineCount; - } -} diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/HeaderViewFactory.java b/android/src/main/java/com/qliktrialreactnativestraighttable/HeaderViewFactory.java deleted file mode 100644 index dc1b711a..00000000 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/HeaderViewFactory.java +++ /dev/null @@ -1,209 +0,0 @@ -package com.qliktrialreactnativestraighttable; - -import android.content.Context; -import android.graphics.Canvas; -import android.graphics.Color; -import android.graphics.Paint; -import android.graphics.Rect; -import android.graphics.Typeface; -import android.os.Build; -import android.text.TextUtils; -import android.view.Gravity; -import android.view.ViewGroup; -import android.widget.FrameLayout; -import android.widget.LinearLayout; -import android.widget.TextView; - -import androidx.annotation.RequiresApi; - -import com.facebook.react.bridge.ReadableArray; - -import java.util.ArrayList; -import java.util.List; - -public class HeaderViewFactory { - private static final float headerZ = 2; - List totalsCells = new ArrayList<>(); - List dataColumns; - final HeaderContentStyle headerContentStyle; - HeaderViewFactory headerViewFactory; - String totalsLabel; - boolean topPosition; - HeaderView headerView = null; - TotalsView totalsView = null; - TableView tableView; - - public TotalsView getTotalsView() { - return totalsView; - } - - public HeaderView getHeaderView() { - return headerView; - } - - public List getDataColumns() { - return dataColumns; - } - - public HeaderViewFactory(List dataColumns, List totalsCells, String totalsLabel, boolean topPosition, TableView tableView, HeaderContentStyle contentStyle, Context context) { - this.tableView = tableView; - this.dataColumns = dataColumns; - this.totalsCells = totalsCells; - this.totalsLabel = totalsLabel; - this.topPosition = topPosition; - this.headerContentStyle = contentStyle; - buildHeader(context); - if (totalsCells != null) { - buildTotals(context); - } - } - - public static HeaderCell buildFixedColumnCell(FrameLayout rootView, DataColumn column, TableView tableView, boolean topPosition) { - int headerHeight = tableView.headerHeight; - int padding = TableTheme.CellPadding; - - HeaderCell fixedFirstHeaderCell = new HeaderCell(rootView.getContext(), column, tableView); - TextView textView = fixedFirstHeaderCell.cell; - textView.setMaxLines(1); - textView.setTypeface(textView.getTypeface(), Typeface.BOLD); - textView.setTextSize(tableView.headerContentStyle.fontSize); - textView.setEllipsize(TextUtils.TruncateAt.END); - textView.setTextColor(tableView.headerContentStyle.color); - textView.setText(column.label); - textView.setPadding(padding, 0, 0, 0); - LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(column.width, headerHeight); - fixedFirstHeaderCell.setTop(0); - fixedFirstHeaderCell.setLeft(0); - fixedFirstHeaderCell.setZ(PixelUtils.dpToPx(headerZ)); - fixedFirstHeaderCell.setLayoutParams(layoutParams); - fixedFirstHeaderCell.setGravity(Gravity.CENTER_VERTICAL); - fixedFirstHeaderCell.setBackgroundColor(TableTheme.headerBackgroundColor); - - if(topPosition) { - fixedFirstHeaderCell.setOutlineProvider(null); - } - return fixedFirstHeaderCell; - } - - public static TotalsViewCell buildFixedTotalsCell(TableView tableView, DataColumn column, TotalsCell totalsCell, boolean topPosition) { - int headerHeight = tableView.headerHeight; - int padding = (int) PixelUtils.dpToPx(16); - TotalsViewCell text = new TotalsViewCell(tableView.getContext(), column, tableView); - text.setTypeface(text.getTypeface(), Typeface.BOLD); - text.setEllipsize(TextUtils.TruncateAt.END); - if (column.isDim) { - text.setText(tableView.totalsLabel); - text.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL); - } else { - text.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL); - text.setText(totalsCell.qText); - } - text.setPadding(padding, 0, padding, 0); - FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(column.width, tableView.totalsHeight); - if(topPosition) { - params.gravity = Gravity.TOP; - params.topMargin = tableView.headerHeight; - } else { - params.gravity = Gravity.BOTTOM; - params.bottomMargin = TableTheme.DefaultRowHeight; - } - text.setLayoutParams(params); - text.setTextColor(tableView.cellContentStyle.color); - text.setBackgroundColor(Color.WHITE); - text.setZ((int) PixelUtils.dpToPx(headerZ)); - text.setTextSize(tableView.cellContentStyle.fontSize); - text.setMaxLines(1); - if (!topPosition) { - text.setOutlineProvider(null); - } - - return text; - } - - public static HeaderCell createHeaderCell(Context context, DataColumn column, HeaderContentStyle headerContentStyle, TableView tableView) { - int padding = TableTheme.CellPadding; - HeaderCell headerCell = new HeaderCell(context, column, tableView); - headerCell.setPadding(padding, 0, 0, 0); - TextView text = headerCell.cell; - text.setTypeface(text.getTypeface(), Typeface.BOLD); - text.setEllipsize(TextUtils.TruncateAt.END); - text.setTextColor(headerContentStyle.color); - text.setText(column.label); - text.setMaxLines(1); - text.setTextSize(headerContentStyle.fontSize); - text.setBackgroundColor(headerContentStyle.backgroundColor); - return headerCell; - } - - private void buildHeader(Context context) { - int headerHeight = tableView.headerHeight; - headerView = new HeaderView(context, tableView); - headerView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, headerHeight)); - headerView.setOrientation(LinearLayout.HORIZONTAL); - headerView.setElevation((int) PixelUtils.dpToPx(headerZ)); - headerView.setBackgroundColor(TableTheme.headerBackgroundColor); - for (int i = 0; i < dataColumns.size(); i++) { - DataColumn column = dataColumns.get(i); - HeaderCell headerCell = createHeaderCell(headerView.getContext(), column, headerContentStyle, this.tableView); - LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(column.width, ViewGroup.LayoutParams.MATCH_PARENT); - headerView.addView(headerCell, layoutParams); - } - headerView.setDataColumns(dataColumns); - } - - public static TotalsViewCell createTotalsCell(Context context, DataColumn column, TableView tableView) { - TotalsViewCell text = new TotalsViewCell(context, column, tableView); - int padding = (int) PixelUtils.dpToPx(16); - text.setTypeface(text.getTypeface(), Typeface.BOLD); - text.setEllipsize(TextUtils.TruncateAt.END); - text.setTextSize(tableView.cellContentStyle.fontSize); - text.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL); - text.setPadding(padding, 0, padding, 0); - text.setMaxLines(1); - return text; - } - - private void buildTotals(Context context) { - totalsView = new TotalsView(context, tableView); - totalsView.setDataColumns(dataColumns); - - int headerHeight = tableView.headerHeight; - totalsView.setOrientation(LinearLayout.HORIZONTAL); - totalsView.setElevation((int) PixelUtils.dpToPx(headerZ)); - totalsView.setBackgroundColor(Color.WHITE); - FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, tableView.totalsHeight); - layoutParams.topMargin = headerHeight; - layoutParams.gravity = topPosition ? Gravity.TOP : Gravity.BOTTOM; - totalsView.setLayoutParams(layoutParams); - if(!topPosition) { - totalsView.setOutlineProvider(null); - } - // first add all fillers, then populate with the data - int j = 0; - for (int i = 0; i < dataColumns.size(); i++) { - DataColumn column = dataColumns.get(i); - TotalsViewCell text = createTotalsCell(context, column, tableView); - if (column.isDim && i == 0) { - text.setText(totalsLabel); - } - if (!column.isDim) { - if (j < totalsCells.size()) { - text.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL); - text.setText(totalsCells.get(j++).qText); - } - } - LinearLayout.LayoutParams textParams = new LinearLayout.LayoutParams(column.width, ViewGroup.LayoutParams.MATCH_PARENT); - totalsView.addView(text, textParams); - } - - } - - public static List getTotalsCellList(ReadableArray source) { - List totalsCells = new ArrayList<>(); - for (int i = 0; i < source.size(); i++) { - TotalsCell cell = new TotalsCell(source.getMap(i)); - totalsCells.add(cell); - } - return totalsCells; - } -} diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/HttpUtils.java b/android/src/main/java/com/qliktrialreactnativestraighttable/HttpUtils.java deleted file mode 100644 index 09b5af2c..00000000 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/HttpUtils.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.qliktrialreactnativestraighttable; - -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; - -import okhttp3.Call; -import okhttp3.Callback; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.Response; - -public class HttpUtils { - private static final OkHttpClient httpClient = new OkHttpClient(); - - public static void get(String uri, Callback callback) { - Request fetchImage = new Request.Builder() - .url(uri) - .build(); - Call call = httpClient.newCall(fetchImage); - call.enqueue(callback); - } -} diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/ImageShare.java b/android/src/main/java/com/qliktrialreactnativestraighttable/ImageShare.java deleted file mode 100644 index 4a6dffb9..00000000 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/ImageShare.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.qliktrialreactnativestraighttable; - -import android.content.Context; -import android.content.Intent; -import android.graphics.Bitmap; -import android.net.Uri; -import android.provider.MediaStore; - -import java.io.ByteArrayOutputStream; - -public class ImageShare { - - public void share(Bitmap bitmap, Context context) { - Uri uri = getImageUri(bitmap, context); - Intent intent = new Intent(Intent.ACTION_SEND); - intent.setType("image/png"); - intent.putExtra(Intent.EXTRA_STREAM, uri); - try { - context.startActivity(Intent.createChooser(intent, null)); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - private Uri getImageUri(Bitmap bitmap, Context context) { - ByteArrayOutputStream bytes = new ByteArrayOutputStream(); - bitmap.compress(Bitmap.CompressFormat.PNG, 100, bytes); - String path = MediaStore.Images.Media.insertImage(context.getContentResolver(), bitmap, null, null); - return Uri.parse(path); - } -} diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/Indicator.java b/android/src/main/java/com/qliktrialreactnativestraighttable/Indicator.java deleted file mode 100644 index f488cb12..00000000 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/Indicator.java +++ /dev/null @@ -1,110 +0,0 @@ -package com.qliktrialreactnativestraighttable; - -import android.graphics.Color; - -import com.facebook.react.bridge.ReadableMap; - -import org.json.JSONException; -import org.json.JSONObject; - -public class Indicator { - boolean applySegmentColors = false; - int color = Color.BLACK; - int index = -1; - String position = null; - boolean showTextValues = false; - char icon; - String iconKey; - boolean hasIcon = false; - - Indicator(ReadableMap data) { - applySegmentColors = data.hasKey("applySegmentColors") && data.getBoolean("applySegmentColors"); - showTextValues = data.hasKey("showTextValues") && data.getBoolean("showTextValues"); - position = data.hasKey("position") ? data.getString("position") : null; - index = data.hasKey("index") ? data.getInt("index") : -1; - parseColor(data); - } - - private void parseColor(ReadableMap data) { - if (data.hasKey("color")) { - color = Color.parseColor(data.getString("color")); - } - getIcon(data); - } - - public JSONObject toEvent() throws JSONException { - JSONObject json = new JSONObject(); - json.put("applySegmentColors", applySegmentColors); - json.put("showTextValues", showTextValues); - json.put("position", position); - json.put("index", index); - String hexColor = String.format("#%06X", 0xFFFFFF & color); - json.put("color", hexColor); - json.put("icon", iconKey); - return json; - } - - private void getIcon(ReadableMap data) { - if (data.hasKey("icon")) { - hasIcon = true; - iconKey = data.getString("icon"); - switch (iconKey) { - case "m": - icon = 0xe96c; - break; - case "è": - icon = 0xe997; - break; - case "ï": - icon = 0xe951; - break; - case "R": - icon = 0xe97f; - break; - case "S": - icon = 0xe97c; - break; - case "T": - icon = 0xe97d; - break; - case "U": - icon = 0xe97e; - break; - case "P": - icon = 0xe906; - break; - case "Q": - icon = 0xe8e4; - break; - case "¢": - icon = 0xe8a8; - break; - case "©": - icon = 0xe894; - break; - case "23F4": - icon = 0xe8c7; - break; - case "2013": - icon = 0xe954; - break; - case "&": - icon = 0xe8ff; - break; - case "add": - icon = 0xe802; - break; - case "minus-2": - icon = 0xe8e3; - break; - case "dot": - icon = 0xe878; - break; - default: - break; - } - } - } - - -} diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/JsonUtils.java b/android/src/main/java/com/qliktrialreactnativestraighttable/JsonUtils.java deleted file mode 100644 index df60774a..00000000 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/JsonUtils.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.qliktrialreactnativestraighttable; - -import com.facebook.react.bridge.ReadableMap; - -public class JsonUtils { - static String getString(ReadableMap data, String key) { - return data.hasKey(key) ? data.getString(key) : null; - } - - static String getString(ReadableMap data, String key, String defaultValue) { - return data.hasKey(key) ? data.getString(key) : defaultValue; - } - - static int getInt(ReadableMap data, String key, int defaultValue) { - return data.hasKey(key) ? data.getInt(key) : defaultValue; - } - - static boolean getBoolean(ReadableMap data, String key, boolean defaultValue) { - return data.hasKey(key) ? data.getBoolean(key) : defaultValue; - } -} diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/MiniBarChartRenderer.java b/android/src/main/java/com/qliktrialreactnativestraighttable/MiniBarChartRenderer.java deleted file mode 100644 index ccfaf505..00000000 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/MiniBarChartRenderer.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.qliktrialreactnativestraighttable; - -import android.graphics.Canvas; -import android.graphics.Paint; -import android.graphics.Rect; - -public class MiniBarChartRenderer extends MiniChartRenderer { - - Rect bar = new Rect(); - - public MiniBarChartRenderer(qMiniChart chartData, Representation representation) { - super(chartData, representation); - } - - @Override - public void render(Canvas canvas) { - float x = padding + (horizontalPadding / 2.0f); - paint.setColor(miniChartInfo.colors.main.color); - for(int i = 0; i < miniChartData.matrix.rows.size(); i++) { - float value = (float) miniChartData.matrix.rows.get(i).columns.get(1).qNum; - float height = value * scale; - float y = xAxis - height ; - float b = xAxis; - setColor(i, value, miniChartData.matrix.rows.size()); - canvas.drawRect(x, y, x + bandwidth, b, paint); - x += padding * 2.0f + bandwidth; - } - } -} diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/MiniChartInfo.java b/android/src/main/java/com/qliktrialreactnativestraighttable/MiniChartInfo.java deleted file mode 100644 index ed1814cb..00000000 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/MiniChartInfo.java +++ /dev/null @@ -1,110 +0,0 @@ -package com.qliktrialreactnativestraighttable; - -import android.graphics.Color; - -import com.facebook.react.bridge.ReadableMap; - -import org.json.JSONException; -import org.json.JSONObject; - -public class MiniChartInfo { - public String type; - public Boolean showDots; - public YAxis yAxis; - public ChartColors colors; - - class YAxis { - public String position; - public String scale; - public YAxis(ReadableMap data) { - position = data.hasKey("position") ? data.getString("position") : ""; - scale = data.hasKey("scale") ? data.getString("scale") : ""; - } - - public JSONObject toEvent() throws JSONException { - JSONObject json = new JSONObject(); - json.put("position", position); - json.put("scale", scale); - return json; - } - } - - class MiniChartColor { - public String colorValue; - public int index; - int color; - boolean valid = false; - public MiniChartColor(ReadableMap data) { - colorValue = data.hasKey("color") ? data.getString("color") : "none"; - index = data.hasKey("index") ? data.getInt("index") : 0; - if(!colorValue.equals("none")) { - color = Color.parseColor(colorValue); - valid = true; - } - } - - public JSONObject toEvent() throws JSONException { - JSONObject json = new JSONObject(); - json.put("index", index); - json.put("color", colorValue); - json.put("valid", valid); - return json; - } - } - - class ChartColors { - public MiniChartColor first; - public MiniChartColor last; - public MiniChartColor min; - public MiniChartColor max; - public MiniChartColor negative; - public MiniChartColor positive; - public MiniChartColor main; - public ChartColors(ReadableMap data) { - resetChartColors(data); - } - - MiniChartColor getMiniChartColor(String name, ReadableMap data) { - return data.hasKey(name) ? new MiniChartColor(data.getMap(name)) : null; - } - - public void resetChartColors(ReadableMap data) { - first = getMiniChartColor("first", data); - last = getMiniChartColor("last", data); - min = getMiniChartColor("min", data); - max = getMiniChartColor("max", data); - negative = getMiniChartColor("negative", data); - positive = getMiniChartColor("positive", data); - main = getMiniChartColor("main", data); - } - - public JSONObject toEvent() throws JSONException { - JSONObject json = new JSONObject(); - json.put("first", first.toEvent()); - json.put("last", last.toEvent()); - json.put("min", min.toEvent()); - json.put("max", max.toEvent()); - json.put("negative", negative.toEvent()); - json.put("positive", positive.toEvent()); - json.put("main", main.toEvent()); - - return json; - } - } - - MiniChartInfo(ReadableMap data) { - type = data.hasKey("type") ? data.getString("type") : ""; - showDots = data.hasKey("showDots") ? data.getBoolean("showDots") : false; - yAxis = data.hasKey("yAxis") ? new YAxis(data.getMap("yAxis")) : null; - colors = data.hasKey("colors") ? new ChartColors(data.getMap("colors")) : null; - } - - public JSONObject toEvent() throws JSONException { - JSONObject json = new JSONObject(); - json.put("type", type); - json.put("showDots", showDots); - json.put("yAxis", yAxis.toEvent()); - json.put("colors", colors.toEvent()); - return json; - } -} diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/MiniPosNegRenderer.java b/android/src/main/java/com/qliktrialreactnativestraighttable/MiniPosNegRenderer.java deleted file mode 100644 index 429c94cf..00000000 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/MiniPosNegRenderer.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.qliktrialreactnativestraighttable; - -import android.graphics.Canvas; - -public class MiniPosNegRenderer extends MiniChartRenderer{ - public MiniPosNegRenderer(qMiniChart chartData, Representation representation) { - super(chartData, representation); - } - - @Override - public void render(Canvas canvas) { - float x = padding + (horizontalPadding / 2.0f); - float barHeight = (bounds.height() - (verticalPadding*2)) / 2.0f; - xAxis = bounds.height() / 2.0f; - for(int i = 0; i < miniChartData.matrix.rows.size(); i++) { - float value = (float) miniChartData.matrix.rows.get(i).columns.get(1).qNum; - float y = xAxis - barHeight ; - float b = xAxis; - if(value < 0) { - y += barHeight; - b = bounds.height() - verticalPadding; - } - setColor(value); - canvas.drawRect(x, y, x + bandwidth, b, paint); - x += padding * 2.0f + bandwidth; - } - } - - protected void setColor(float value) { - if(value < 0) { - paint.setColor(miniChartInfo.colors.negative.color); - } else { - paint.setColor(miniChartInfo.colors.positive.color); - } - } -} diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/MiniSparkLinesRenderer.java b/android/src/main/java/com/qliktrialreactnativestraighttable/MiniSparkLinesRenderer.java deleted file mode 100644 index 7bec75c9..00000000 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/MiniSparkLinesRenderer.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.qliktrialreactnativestraighttable; - -import android.graphics.Canvas; -import android.graphics.Paint; -import android.graphics.Path; -import android.graphics.Rect; - -public class MiniSparkLinesRenderer extends MiniChartRenderer { - Path path = new Path(); - MiniDotsChartRenderer dots = null; - public MiniSparkLinesRenderer(qMiniChart chartData, Representation representation) { - super(chartData, representation); - dots = new MiniDotsChartRenderer(chartData, representation); - } - - @Override - public void render(Canvas canvas) { - float x = padding + (horizontalPadding / 2.0f); - paint.setColor(miniChartInfo.colors.main.color); - startPath(x, canvas); - - for(int i = 1; i < miniChartData.matrix.rows.size(); i++) { - float value = (float) miniChartData.matrix.rows.get(i).columns.get(1).qNum; - float height = value * scale; - float y = xAxis - height ; - float x2 = x + padding * 2.0f + bandwidth; - path.lineTo(x2, y); - x += padding * 2.0f + bandwidth; - } - paint.setStyle(Paint.Style.STROKE); - paint.setStrokeWidth(2); - canvas.drawPath(path, paint); - if(miniChartInfo.showDots) { - dots.render(canvas); - } else { - dots.renderColorValues(canvas); - } - } - protected void startPath(float x, Canvas canvas) { - path.reset(); - - if(miniChartData.matrix.rows.size() > 0) { - float value = (float) miniChartData.matrix.rows.get(0).columns.get(1).qNum; - float height = value * scale; - float y = xAxis - height ; - path.moveTo(x, y); - } - } - - @Override - public void updateData(qMiniChart chartData, Representation representation) { - super.updateData(chartData, representation); - if(dots != null) { - dots.updateData(chartData, representation); - } - } - - public void resetScales(Rect bounds) { - super.resetScales(bounds); - if(dots != null) { - dots.resetScales(bounds); - } - } -} diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/PixelUtils.java b/android/src/main/java/com/qliktrialreactnativestraighttable/PixelUtils.java deleted file mode 100644 index 60d3d4b0..00000000 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/PixelUtils.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.qliktrialreactnativestraighttable; - -import android.content.res.Resources; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; - -public class PixelUtils { - public static float dpToPx(float dp) { - return (dp * Resources.getSystem().getDisplayMetrics().density); - } - - public static float pxToDp(float px) { - return (px / Resources.getSystem().getDisplayMetrics().density); - } - - public static Bitmap byteStreamToBitmap(InputStream inputStream) { - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - int bufferSize = 2048; - byte[] buffer = new byte[bufferSize]; - int length = 0; - try { - while ((length = inputStream.read(buffer)) != -1) { - outputStream.write(buffer, 0, length); - } - outputStream.close(); - } catch (IOException e) { - e.printStackTrace(); - } - byte[] byteArray = outputStream.toByteArray(); - return BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length); - } -} diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/ReactNativeStraightTablePackage.java b/android/src/main/java/com/qliktrialreactnativestraighttable/ReactNativeStraightTablePackage.java deleted file mode 100644 index a12e26ad..00000000 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/ReactNativeStraightTablePackage.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.qliktrialreactnativestraighttable; - -import com.facebook.react.ReactPackage; -import com.facebook.react.bridge.NativeModule; -import com.facebook.react.bridge.ReactApplicationContext; -import com.facebook.react.uimanager.ViewManager; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -public class ReactNativeStraightTablePackage implements ReactPackage { - @Override - public List createNativeModules(ReactApplicationContext reactContext) { - return Collections.emptyList(); - } - - @Override - public List createViewManagers(ReactApplicationContext reactContext) { - return Arrays.asList(new ReactNativeStraightTableViewManager(), new MiniChartViewManager()); - } -} diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/ReactNativeStraightTableViewManager.java b/android/src/main/java/com/qliktrialreactnativestraighttable/ReactNativeStraightTableViewManager.java deleted file mode 100644 index 3ed34320..00000000 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/ReactNativeStraightTableViewManager.java +++ /dev/null @@ -1,188 +0,0 @@ -package com.qliktrialreactnativestraighttable; - -import android.annotation.SuppressLint; -import android.graphics.Color; -import android.graphics.drawable.GradientDrawable; -import android.os.Build; -import android.view.View; -import android.view.ViewGroup; -import android.widget.FrameLayout; -import android.widget.HorizontalScrollView; -import android.widget.RelativeLayout; -import android.widget.ScrollView; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.annotation.RequiresApi; - -import com.facebook.react.bridge.ReadableArray; -import com.facebook.react.bridge.ReadableMap; -import com.facebook.react.bridge.ReadableNativeMap; -import com.facebook.react.common.MapBuilder; -import com.facebook.react.uimanager.SimpleViewManager; -import com.facebook.react.uimanager.ThemedReactContext; -import com.facebook.react.uimanager.annotations.ReactProp; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.concurrent.CountDownLatch; - -public class ReactNativeStraightTableViewManager extends SimpleViewManager { - - public static final String REACT_CLASS = "ReactNativeStraightTableView"; - @Override - @NonNull - public String getName() { - return REACT_CLASS; - } - - @SuppressLint("NewApi") - @Override - @NonNull - public View createViewInstance(ThemedReactContext reactContext) { - return new TableView(reactContext); - } - - private void processRows(TableView tableView, ReadableMap rows) { - ReadableArray dataRows = rows.getArray("rows"); - if(dataRows != null) { - boolean resetData = rows.getBoolean("reset"); - RowFactory factory = new RowFactory(dataRows, tableView.getColumns(), tableView.imageLoader); - List transformedRows = factory.getRows(); - tableView.setRows(transformedRows, resetData); - } - } - - private List processColumns(TableView tableView, ReadableMap cols) { - String totalsLabel = null, totalsPosition = null; - ReadableArray totalsRows = null; - - ReadableArray columns = cols.getArray("header"); - ReadableMap totals = cols.getMap("totals"); - - if(totals != null) { - totalsPosition = totals.getString("position"); - totalsLabel = totals.getString("label"); - totalsRows = totals.getArray("rows"); - tableView.setTotals(totalsRows, totalsPosition, totalsLabel); - } - - List dataColumns = new ArrayList<>(); - if(columns != null) { - for (int i = 0; i < columns.size(); i++) { - DataColumn column = new DataColumn(columns.getMap(i), i); - dataColumns.add(column); - } - } - - return dataColumns; - } - - @ReactProp(name = "theme") - public void setTheme(View view, ReadableMap theme) { - - } - - @ReactProp(name = "translations") - public void setTranslations(View view, @Nullable ReadableMap translations) { - if(translations == null) { - return; - } - TableView tableView = (TableView) (view); - tableView.setTranslations(translations); - } - - @ReactProp(name = "freezeFirstColumn") - public void setFreezeFirstColumn(View view, Boolean isFreezeFirstColumn) { - TableView tableView = (TableView) (view); - tableView.setFirstColumnFrozen(isFreezeFirstColumn); - } - - @ReactProp(name = "cols") - public void setCols(View view, @Nullable ReadableMap source) { - if(source == null) { - return; - } - TableView tableView = (TableView) (view); - List dataColumns = processColumns(tableView, source); - tableView.setDataColumns(dataColumns); - } - - @ReactProp(name = "isDataView") - public void setDataView(View view, boolean isDataView) { - TableView tableView = (TableView) (view); - tableView.setDataView(isDataView); - } - - @ReactProp(name = "rows") - public void setRows(View view, @Nullable ReadableMap source) { - if(source == null) { - return; - } - - TableView tableView = (TableView) (view); - processRows(tableView, source); - } - - @ReactProp(name = "size") - public void setSize(View view, @Nullable ReadableMap source) { - if(source != null) { - TableView tableView = (TableView) view; - DataSize dataSize = new DataSize(source); - tableView.setDataSize(dataSize); - } - } - - @ReactProp(name = "containerWidth") - public void setContainerWidth(View view, int width) { - // no op - } - - @ReactProp(name = "clearSelections") - public void setClearSelections(View view, String value) { - if (value.equalsIgnoreCase("yes")) { - TableView tableView = (TableView) (view); - tableView.clearSelections(); - } - } - - @ReactProp(name = "name") - public void setName(View view, String value) { - TableView tableView =(TableView) view; - tableView.setName(value); - } - - @ReactProp(name = "headerContentStyle") - public void setHeaderContentStyle(View view, ReadableMap source) { - HeaderContentStyle headerContentStyle = new HeaderContentStyle(source); - TableView tableView = (TableView) view; - tableView.setHeaderStyle(headerContentStyle); - } - - @ReactProp(name = "cellContentStyle") - public void setCellContentStyle(View view, ReadableMap source) { - CellContentStyle cellContentStyle = new CellContentStyle(source); - TableView tableView = (TableView) view; - tableView.setCellContentStyle(cellContentStyle); - } - - @Nullable - @Override - public Map getExportedCustomDirectEventTypeConstants() { - return MapBuilder.builder() - .put("onEndReached", - MapBuilder.of("registrationName", "onEndReached")) - .put("onSelectionsChanged", - MapBuilder.of("registrationName", "onSelectionsChanged")) - .put("onHeaderPressed", - MapBuilder.of("registrationName", "onHeaderPressed")) - .put("onExpandCell", - MapBuilder.of("registrationName", "onExpandCell")) - .put("onSearchColumn", - MapBuilder.of("registrationName", "onSearchColumn")) - .put("onDragBox", - MapBuilder.of("registrationName", "onDragBox")) - .build(); - } -} diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/RootLayout.java b/android/src/main/java/com/qliktrialreactnativestraighttable/RootLayout.java deleted file mode 100644 index ab8bf701..00000000 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/RootLayout.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.qliktrialreactnativestraighttable; - -import android.content.Context; -import android.widget.FrameLayout; -import android.widget.RelativeLayout; - -public class RootLayout extends FrameLayout { - final ColumnWidths columnWidths; - RootLayout(Context context, ColumnWidths columnWidths) { - super(context); - this.columnWidths = columnWidths; - } - - - @Override - public void requestLayout() { - super.requestLayout(); - post(measureAndLayout); - } - - private final Runnable measureAndLayout = new Runnable() { - @Override - public void run() { - - measure( - MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.UNSPECIFIED), - MeasureSpec.makeMeasureSpec(getHeight(), MeasureSpec.EXACTLY)); - int l = getLeft(); - int r = l + columnWidths.getTotalWidth() + getPaddingRight(); - layout(getLeft(), getTop(), r, getBottom()); - } - }; -} diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/RowCountView.java b/android/src/main/java/com/qliktrialreactnativestraighttable/RowCountView.java deleted file mode 100644 index d0873592..00000000 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/RowCountView.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.qliktrialreactnativestraighttable; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.graphics.Color; -import android.text.Layout; -import android.util.TypedValue; -import android.view.Gravity; -import android.view.View; -import android.view.ViewGroup; -import android.widget.FrameLayout; -import android.widget.RelativeLayout; -import android.widget.TextView; - -@SuppressLint("ViewConstructor") -public class RowCountView extends RelativeLayout { - final TableView tableView; - final int margin = (int)PixelUtils.dpToPx(8); - RelativeLayout container; - TextView textView; - - public RowCountView(Context context, TableView tableView) { - super(context); - int height = tableView.getMeasuredHeight(); - int width = tableView.getMeasuredWidth(); - setElevation(PixelUtils.dpToPx(4)); - - this.tableView = tableView; - - textView = new TextView(context); - textView.setSingleLine(); - textView.setMinimumWidth(width / 2); - RelativeLayout.LayoutParams textLayout = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT); - textLayout.rightMargin = margin; - textLayout.topMargin = margin; - textView.setGravity(Gravity.RIGHT); - textView.setLayoutParams(textLayout); - - container = new RelativeLayout(context); - container.setGravity(Gravity.RIGHT); - FrameLayout.LayoutParams frameLayout = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, TableTheme.DefaultRowHeight); - container.setLayoutParams(frameLayout); - container.setY(height - TableTheme.DefaultRowHeight); - container.setBackgroundColor(Color.WHITE); - - container.addView(textView); - addView(container); - } - - public void update(int windowMin, int windowMax, int total) { - String ofString = tableView.getTranslation("misc", "of"); - - String text = windowMin + " - " + windowMax + " " + ofString + " " + total; - textView.setText(text); - textView.postInvalidate(); - } - - @Override - protected void onLayout(boolean changed, int l, int t, int r, int b) { - int height = tableView.getMeasuredHeight(); - int width = tableView.getMeasuredWidth(); - textView.setMinimumWidth(width / 2); - container.setY(height - TableTheme.DefaultRowHeight); - - super.onLayout(changed, l, t, r, b); - } -} diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/RowFactory.java b/android/src/main/java/com/qliktrialreactnativestraighttable/RowFactory.java deleted file mode 100644 index fc044c67..00000000 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/RowFactory.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.qliktrialreactnativestraighttable; - -import android.util.Log; - -import androidx.recyclerview.widget.RecyclerView; - -import com.facebook.react.bridge.ReadableArray; -import com.facebook.react.bridge.ReadableMap; -import com.facebook.react.bridge.ReadableMapKeySetIterator; - -import java.util.ArrayList; -import java.util.List; - -public class RowFactory { - List rows = new ArrayList<>(); - public RowFactory(ReadableArray source, List columns, ImageLoader imageLoader) { - for(int i = 0; i < source.size(); i++ ) { - ReadableMap map = source.getMap(i); - DataRow row = new DataRow(map, columns, imageLoader); - rows.add(row); - } - } - - public List getRows() { - return rows; - } -} diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/ScreenGuideView.java b/android/src/main/java/com/qliktrialreactnativestraighttable/ScreenGuideView.java deleted file mode 100644 index b36e6979..00000000 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/ScreenGuideView.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.qliktrialreactnativestraighttable; - -import android.content.Context; -import android.graphics.Canvas; -import android.graphics.Color; -import android.graphics.DashPathEffect; -import android.graphics.Paint; -import android.graphics.Rect; -import android.view.View; -import android.view.animation.AlphaAnimation; -import android.view.animation.Animation; -import android.view.animation.DecelerateInterpolator; - -public class ScreenGuideView extends View { - Paint paint = new Paint(); - ScreenGuideView(Context context) { - super(context); - paint.setStyle(Paint.Style.STROKE); - paint.setColor(Color.rgb(176, 0, 32)); - paint.setStrokeWidth(PixelUtils.dpToPx(2)); - paint.setPathEffect(new DashPathEffect(new float[] {20f,10f}, 0f)); - setVisibility(INVISIBLE); - } - - public void fade(int from, int to) { - Animation animation = new AlphaAnimation(from, to); - animation.setInterpolator(new DecelerateInterpolator()); - animation.setDuration(800); - animation.setAnimationListener(new Animation.AnimationListener() { - @Override - public void onAnimationStart(Animation animation) { - - } - - @Override - public void onAnimationEnd(Animation animation) { - setVisibility(to == 1 ? VISIBLE : INVISIBLE); - } - - @Override - public void onAnimationRepeat(Animation animation) { - - } - }); - startAnimation(animation); - } - - @Override - public void onDraw(Canvas canvas) { - super.onDraw(canvas); - Rect rect = canvas.getClipBounds(); - int x = rect.left + rect.width(); - int y = rect.height(); - canvas.drawLine(x, 0, x, y, paint); - } -} diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/ScrollBarDrawable.java b/android/src/main/java/com/qliktrialreactnativestraighttable/ScrollBarDrawable.java deleted file mode 100644 index 7a17eb2b..00000000 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/ScrollBarDrawable.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.qliktrialreactnativestraighttable; - -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.Rect; -import android.graphics.RectF; -import android.graphics.drawable.Drawable; -import android.util.Log; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -public class ScrollBarDrawable extends Drawable { - Paint paint = new Paint(); - Path path = new Path(); - final float[] corners = new float[]{ - 80, 80, - 80, 80, - 80, 80, - 80, 80 - }; - - ScrollBarDrawable() { - paint.setColor(Color.LTGRAY); - } - @Override - public void draw(@NonNull Canvas canvas) { - RectF r = new RectF(this.getBounds()); - path.reset(); - path.addRoundRect(r, - corners , - Path.Direction.CW); - canvas.drawPath(path, paint); - } - - @Override - public void setAlpha(int i) { - paint.setAlpha(i); - } - - @Override - public void setColorFilter(@Nullable ColorFilter colorFilter) { - paint.setColorFilter(colorFilter); - } - - @Override - public int getOpacity() { - return PixelFormat.TRANSPARENT; - } -} diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/SearchButton.java b/android/src/main/java/com/qliktrialreactnativestraighttable/SearchButton.java deleted file mode 100644 index 08ee58cc..00000000 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/SearchButton.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.qliktrialreactnativestraighttable; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.graphics.Color; -import android.graphics.drawable.Drawable; -import android.view.MotionEvent; - -@SuppressLint("ViewConstructor") -public class SearchButton extends androidx.appcompat.widget.AppCompatImageButton { - final Drawable icon; - final Context context; - final DataColumn column; - final TableView tableView; - final int defaultColor = Color.TRANSPARENT; - final int pressedColor = Color.parseColor("#595959"); - final int textColor = Color.parseColor("#404040"); - - public SearchButton(Context context, TableView tableView, DataColumn column) { - super(context); - this.context = context; - this.tableView = tableView; - this.column = column; - this.icon = context.getDrawable(R.drawable.ic_searchicon); - this.setImageDrawable(icon); - this.setBackgroundColor(defaultColor); - } - - public void handleTouchDown(){ - this.setBackgroundColor(pressedColor); - - icon.setTint(Color.WHITE); - this.setImageDrawable(icon); - postInvalidate(); - } - - - public void handleTouchUp(){ - this.setBackgroundColor(defaultColor); - - icon.setTint(textColor); - this.setImageDrawable(icon); - } - - @SuppressLint("ClickableViewAccessibility") - @Override - public boolean onTouchEvent(MotionEvent event) { - int action = event.getAction(); - - switch(action) { - case MotionEvent.ACTION_DOWN: - handleTouchDown(); - break; - case MotionEvent.ACTION_CANCEL: - handleTouchUp(); - break; - case MotionEvent.ACTION_UP: - EventUtils.sendOnSearchColumn(tableView, column); - postInvalidate(); - break; - } - return super.onTouchEvent(event); - } -} diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/SelectionsEngine.java b/android/src/main/java/com/qliktrialreactnativestraighttable/SelectionsEngine.java deleted file mode 100644 index 051a20c6..00000000 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/SelectionsEngine.java +++ /dev/null @@ -1,87 +0,0 @@ -package com.qliktrialreactnativestraighttable; - -import android.annotation.SuppressLint; -import android.util.Log; -import android.view.View; -import android.widget.FrameLayout; - -import com.facebook.react.bridge.Arguments; -import com.facebook.react.bridge.WritableArray; -import com.facebook.react.bridge.WritableMap; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -public class SelectionsEngine { - - Set observers = new HashSet<>(); - Map selections = new HashMap<>(); - - public void observe(SelectionsObserver observer) { - observers.add(observer); - } - - public void remove(SelectionsObserver observer) { - observers.remove(observer); - } - - public void selectionsChanged(View contextView, String s) { - String key = getKeyFrom(s); - if(selections.containsKey(key)) { - selections.remove(key); - } else { - String[] components = SelectionsEngine.getComponents(s); - selections.put(components[0], components[1]); - } - for(SelectionsObserver observer : observers ) { - observer.onSelectionsChanged(s); - } - WritableMap args = Arguments.createMap(); - WritableArray array = Arguments.createArray(); - for (Map.Entry entry : selections.entrySet()) { - String selectionsKey = entry.getKey(); - String selectionsValue = entry.getValue(); - String selectionsString = selectionsKey + selectionsValue; - array.pushString(selectionsString); - } - args.putArray("selections", array); - EventUtils.sendEventToJSFromView(contextView, "onSelectionsChanged", args); - } - - public void clearSelections() { - selections.clear(); - for(SelectionsObserver observer : observers ) { - observer.onClear(); - } - } - - public boolean contains(DataCell cell) { - String key = getKeyFrom(cell); - return selections.containsKey(key); - } - - @SuppressLint("DefaultLocale") - static String getSignatureFrom(DataCell cell) { - return String.format("/%d/%d/%d", cell.qElemNumber, cell.colIdx, cell.rowIdx); - } - - static String getKeyFrom(String string) { - int index = string.lastIndexOf("/"); - return string.substring(0, index); - } - - @SuppressLint("DefaultLocale") - static String getKeyFrom(DataCell cell) { - return String.format("/%d/%d", cell.qElemNumber, cell.colIdx); - } - - static String[] getComponents(String s) { - String[] items = s.split("/"); - String key = "/" + items[1] + "/" + items[2]; - String val = "/" + items[3]; - String result [] = {key, val}; - return result; - } -} diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/SelectionsObserver.java b/android/src/main/java/com/qliktrialreactnativestraighttable/SelectionsObserver.java deleted file mode 100644 index 0e00425d..00000000 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/SelectionsObserver.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.qliktrialreactnativestraighttable; - -public interface SelectionsObserver { - void onSelectionsChanged(String s); - void onClear(); - void onRecycled(); -} diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/TableTheme.java b/android/src/main/java/com/qliktrialreactnativestraighttable/TableTheme.java deleted file mode 100644 index 0c41ad83..00000000 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/TableTheme.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.qliktrialreactnativestraighttable; - -import android.annotation.SuppressLint; -import android.graphics.Color; -import android.graphics.Typeface; - -import com.facebook.react.bridge.ReadableMap; - -public class TableTheme { - static int headerBackgroundColor = Color.parseColor("#F0F0F0"); - static int defaultTextColor = Color.parseColor("#404040"); - @SuppressLint("NewApi") - static int borderBackgroundColor = Color.argb(0.1f, 0, 0, 0); - static int selectedBackground = Color.parseColor("#009845"); - static Typeface iconFonts = null; - static int CellPadding = (int)PixelUtils.dpToPx(8); - static int DefaultRowHeight = (int)PixelUtils.dpToPx(40); -} diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/TextWrapper.java b/android/src/main/java/com/qliktrialreactnativestraighttable/TextWrapper.java deleted file mode 100644 index b78940b0..00000000 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/TextWrapper.java +++ /dev/null @@ -1,95 +0,0 @@ -package com.qliktrialreactnativestraighttable; - -import android.text.Layout; -import android.text.StaticLayout; -import android.text.TextPaint; -import android.util.Log; -import android.widget.TextView; - -public class TextWrapper { - final TableView tableView; - final TextView textView; - DataColumn column; - TextPaint measureTextPaint = new TextPaint(); - int lineCount = 1; - int wordCount = 0; - int additionalPadding = 0; - - - TextWrapper(DataColumn column, TableView tableView, TextView textView) { - this.column = column; - this.tableView = tableView; - this.textView = textView; - - measureTextPaint.setTextSize(textView.getTextSize()); - measureTextPaint.setAntiAlias(true); - } - - TextWrapper(TableView tableView, TextView textView) { - this.tableView = tableView; - this.textView = textView; - - measureTextPaint.setTextSize(textView.getTextSize()); - measureTextPaint.setAntiAlias(true); - } - - public void testTextWrap() { - measureLineCount(); - } - - public void testTextWrap(DataColumn dataColumn) { - this.column = dataColumn; - measureLineCount(); - } - - public void testOnlyTextWrap() { - measureLineCountNoUpdate(); - } - void measureLineCount() { - if (wordCount > 1) { - int lines = calculateLineCount(); - if (lines != lineCount) { - lineCount = Math.min(lines, wordCount); - tableView.updateHeaderViewLineCount(); - } - } - } - - void measureLineCountNoUpdate() { - if (wordCount > 1) { - int lines = calculateLineCount(); - if (lines != lineCount) { - lineCount = Math.min(lines, wordCount); - } - } - } - - protected int calculateLineCount() { - int width = column.width - additionalPadding; - measureTextPaint.setTypeface(textView.getTypeface()); - StaticLayout.Builder builder = StaticLayout.Builder.obtain(textView.getText(), 0, textView.getText().length(), measureTextPaint, width); - builder.setIncludePad(true); - builder.setMaxLines(wordCount); - builder.setAlignment(Layout.Alignment.ALIGN_NORMAL); - builder.setLineSpacing(1, 1); - StaticLayout layout = builder.build(); - int lines = layout.getLineCount(); - return lines; - } - - public int getMeasuredLinedCount() { - return lineCount; - } - - public int setMaxLines(int maxLines) { - countWords(textView.getText().toString()); - maxLines = wordCount > 1 ? maxLines : 1; - return maxLines; - } - - public void countWords(String text) { - if(text != null) { - wordCount = text.split("\\s+").length; - } - } -} diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/TotalsCell.java b/android/src/main/java/com/qliktrialreactnativestraighttable/TotalsCell.java deleted file mode 100644 index 4283b218..00000000 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/TotalsCell.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.qliktrialreactnativestraighttable; - -import com.facebook.react.bridge.ReadableMap; - -public class TotalsCell { - String qText = ""; - TotalsCell(ReadableMap map) { - qText = map.getString("qText"); - } -} diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/TotalsView.java b/android/src/main/java/com/qliktrialreactnativestraighttable/TotalsView.java deleted file mode 100644 index ee057859..00000000 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/TotalsView.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.qliktrialreactnativestraighttable; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.view.ViewGroup; -import android.widget.TextView; - -import java.util.List; - -@SuppressLint("ViewConstructor") -public class TotalsView extends AutoLinearLayout{ - List dataColumns = null; - final TableView tableView; - TotalsView(Context context, TableView tableView) { - super(context); - this.tableView = tableView; - } - - public void setDataColumns(List dataColumns) { - this.dataColumns = dataColumns; - } - - public void updateLayout() { - for (int i = 0; i < this.dataColumns.size(); i++){ - TotalsViewCell totalsCell = (TotalsViewCell) this.getChildAt(i); - ViewGroup.LayoutParams layoutParams = totalsCell.getLayoutParams(); - layoutParams.width = dataColumns.get(i).width; - totalsCell.setLayoutParams(layoutParams); - } - } - - public void testTextWrap() { - for (int i = 0; i < this.dataColumns.size(); i++) { - TotalsViewCell totalsCell = (TotalsViewCell) this.getChildAt(i); - totalsCell.testTextWrap(); - } - } - - public int getMaxLineCount() { - if(this.getChildCount() == 0) { - return 1; - } - int lineCount = 0; - for(int i = 0; i < this.dataColumns.size(); i++) { - TotalsViewCell totalsCell = (TotalsViewCell) this.getChildAt(i); - lineCount = Math.max(lineCount, totalsCell.getMeasuredLinedCount()); - } - - for(int i = 0; i < this.dataColumns.size(); i++) { - TotalsViewCell totalsCell = (TotalsViewCell)this.getChildAt(i); - totalsCell.setMaxLines(lineCount); - } - return lineCount; - } -} diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/TotalsViewCell.java b/android/src/main/java/com/qliktrialreactnativestraighttable/TotalsViewCell.java deleted file mode 100644 index 70ed9927..00000000 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/TotalsViewCell.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.qliktrialreactnativestraighttable; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.graphics.Canvas; -import android.graphics.Color; -import android.graphics.Paint; -import android.graphics.Rect; -import android.widget.LinearLayout; - -@SuppressLint("ViewConstructor") -public class TotalsViewCell extends androidx.appcompat.widget.AppCompatTextView { - Paint paint = new Paint(); - DataColumn column; - TextWrapper textWrapper; - Rect bounds = new Rect(); - final TableView tableView; - public TotalsViewCell(Context context, DataColumn dataColumn, TableView tableView) { - super(context); - this.column = dataColumn; - this.tableView = tableView; - textWrapper = new TextWrapper(column, tableView, this); - - int textColor = tableView.cellContentStyle.color; - setTextColor(textColor); - } - - public void setColumn(DataColumn col) { - this.column = col; - } - - public void testTextWrap() { - if(tableView.headerContentStyle.wrap) { - textWrapper.testOnlyTextWrap(); - } - } - - @Override - public void setMaxLines(int maxLines) { - maxLines = textWrapper.setMaxLines(maxLines); - super.setMaxLines(maxLines); - } - - int getMeasuredLinedCount() { - return textWrapper.getMeasuredLinedCount(); - } - - protected void onDraw(Canvas canvas){ - super.onDraw(canvas); - canvas.getClipBounds(bounds); - paint.setColor(TableTheme.borderBackgroundColor); - paint.setStyle(Paint.Style.STROKE); - paint.setStrokeWidth(PixelUtils.dpToPx(2)); - - canvas.drawLine(0, 0, column.width, 0, paint); - canvas.drawLine(0, bounds.height(), column.width, bounds.height(), paint); - } -} diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/qMatrix.java b/android/src/main/java/com/qliktrialreactnativestraighttable/qMatrix.java deleted file mode 100644 index 4fa09811..00000000 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/qMatrix.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.qliktrialreactnativestraighttable; - -import com.facebook.react.bridge.ReadableArray; -import com.facebook.react.bridge.ReadableMap; -import com.facebook.react.bridge.ReadableType; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import java.util.ArrayList; -import java.util.List; - -public class qMatrix { - public List rows = new ArrayList<>(); - - class qMatrixColumn { - public double qElemNumber; - public double qNum = 0.0; - public String qText = null; - public qMatrixColumn(ReadableMap data) { - qElemNumber = data.hasKey("qElemNumber") ? data.getDouble("qElemNumber") : 0.0; - if(data.hasKey("qNum")) { - ReadableType rt = data.getType("qNum"); - if(rt == ReadableType.Number) { - qNum = data.getDouble("qNum"); - } - } - qText = data.hasKey("qText") ? data.getString("qText") : ""; - } - - JSONObject toEvent() throws JSONException { - JSONObject object = new JSONObject(); - object.put("qElemenNumber", qElemNumber); - object.put("qNum", qNum); - if(qText != null){ - object.put("qText", qText); - } - return object; - } - } - - class qMatrixRow { - public List columns = new ArrayList<>(); - public qMatrixRow(ReadableArray dataArray) { - for(int i = 0; i < dataArray.size(); i++) { - columns.add(new qMatrixColumn(dataArray.getMap(i))); - } - } - JSONArray toEvent() throws JSONException { - JSONArray jsonArray = new JSONArray(); - for(qMatrixColumn column : columns) { - jsonArray.put(column.toEvent()); - } - return jsonArray; - } - } - - public qMatrix(ReadableArray dataArray) { - for(int i = 0; i < dataArray.size(); i++) { - ReadableArray da = dataArray.getArray(i); - rows.add(new qMatrixRow(da)); - } - } - - JSONArray toEvent() throws JSONException{ - JSONArray jsonArray = new JSONArray(); - for(qMatrixRow row : rows) { - jsonArray.put(row.toEvent()); - } - return jsonArray; - } - -} diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/qMiniChart.java b/android/src/main/java/com/qliktrialreactnativestraighttable/qMiniChart.java deleted file mode 100644 index b4588e73..00000000 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/qMiniChart.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.qliktrialreactnativestraighttable; - -import com.facebook.react.bridge.ReadableArray; -import com.facebook.react.bridge.ReadableMap; - -import org.json.JSONException; -import org.json.JSONObject; - -public class qMiniChart { - public double qMin; - public double qMax; - public qMatrix matrix; - public qMiniChart(ReadableMap data) { - qMin = data.hasKey("qMin") ? data.getDouble("qMin") : 0.0; - qMax = data.hasKey("qMax") ? data.getDouble("qMax") : 0.0; - ReadableArray dataArray = data.hasKey("qMatrix") ? data.getArray("qMatrix") : null; - if(dataArray != null) { - matrix = new qMatrix(dataArray); - } - } - - public JSONObject toEvent() throws JSONException { - - JSONObject json = new JSONObject(); - json.put("qMin", qMin); - json.put("qMax", qMax); - if(matrix != null) { - String foo = matrix.toEvent().toString(); - json.put("qMatrix", matrix.toEvent()); - } - return json; - } -} diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/qValue.java b/android/src/main/java/com/qliktrialreactnativestraighttable/qValue.java deleted file mode 100644 index 129f17e6..00000000 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/qValue.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.qliktrialreactnativestraighttable; - -import com.facebook.react.bridge.ReadableType; - -import org.json.JSONException; -import org.json.JSONObject; - -import java.util.HashMap; - -public class qValue { - String qNum; - String qText; - - public qValue(HashMap source) { - qNum = "" + source.get("qNum"); - qText = "" + source.get("qText"); - } - - public JSONObject toEvent() throws JSONException { - JSONObject qValue = new JSONObject(); - if(qText != null) { - qValue.put("qText", qText); - } - if(qNum != null) { - qValue.put("qNum", qNum); - } - - return qValue; - } -} diff --git a/android/src/main/java/com/qliktrialreactnativestraighttable/qValues.java b/android/src/main/java/com/qliktrialreactnativestraighttable/qValues.java deleted file mode 100644 index 570a345a..00000000 --- a/android/src/main/java/com/qliktrialreactnativestraighttable/qValues.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.qliktrialreactnativestraighttable; - -import org.json.JSONArray; -import org.json.JSONException; - -import java.util.List; - -public class qValues { - List values; - - public qValues(List values) { - this.values = values; - } - - public qValue get(int index){ - return values.get(index); - } - - public JSONArray toEvent() throws JSONException { - JSONArray qValues = new JSONArray(); - - for(qValue val : values) { - qValues.put(val.toEvent()); - } - - return qValues; - } -}