ProgressBar single color gradient - android-studio

I have this code for a shape (it's set as progressDrawable in ProgressBar):
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape
android:shape="ring"
android:thicknessRatio="16"
android:useLevel="false">
<solid android:color="#DDD" />
</shape>
</item>
<item>
<rotate
android:fromDegrees="270"
android:toDegrees="270">
<shape
android:shape="ring"
android:thicknessRatio="16"
android:useLevel="true">
<gradient
android:endColor="#color/red"
android:startColor="#color/blue"
android:type="sweep" />
</shape>
</rotate>
</item>
As it is specified, color changes throughout the circle as gradient from blue to red. For example, at maximum gradient value (100) the start is blue and at the end is red. How can I set so the color is only one? As for example, 100 value would set all circle to be red, 70 (some sort of orange), 50 (some sort of yellow) - the whole circle till the specific value must be single color, not of mixed colors. Thank you.

Related

How can I make a TextView object inherit constraints from a TextView object that turned INVISIBLE?

Text 4 is aligned to Text 3, which is aligned to Text 2, which is aligned to Text 1. Text 1 is autonomously aligned.
PROBLEM: When the app sets Text 3 to "INVISIBLE", Text 4 stays at the same layout position. The only thing that changes is that Text 3 is no longer visible.
How can I make Text 4 inherit the constraints of Text 3, which are:
android:layout_marginTop="8dp"
app:layout_constraintStart_toStartOf="#+id/textView2"
app:layout_constraintTop_toBottomOf="#+id/textView2"
The desired result would therefore be that Text 4 moves to the position of Text 3.
Have a look at goneMarginStart. It reads: "When a position constraint target's visibility is View.GONE, you can also indicate a different margin value to be used..."
So, setting the gone-start-margin of textview4 to 0 and aligning the top of textview4 with top of textview3 (instead of bottom) should work.
For textview4:
android:layout_marginStart="8dp"
app:layout_goneMarginStart="0dp"
app:layout_constraintStart_toEndOf="#+id/textView3"
app:layout_constraintTop_toTopOf="#+id/textView3"

Calculation of PI() and 3.14159265358979 in excel

In Excel while Calculating =SIN(PI()) formula it returns 1.22515E-16.If the PI() Value(3.14159265358979) is directly given like =SIN(3.14159265358979), it returns 3.23114E-15.
Please anyone can share your opinion about how the excel calculates differently, when 'PI' and 3.14159265358979 are passed as parameter.
Let's have the following example:
A2 is formula =PI().
A3 is value 3.14159265358979.
A5 is value copied from A2 and then paste-special: Values only.
Formula in column B is =SIN(A2) ... =SIN(A5).
So what is happening here?
While Microsoft justifies the truncating values to 15 digits with using double floating point precision according IEEE 754, this is not the whole truth. According IEEE 754 the possible count of decimal digits is not exactly 15 but 15.95 in average. So there are more digits possible in some cases. And if so, Excel stores up to 17 digits in its files although it shows only 15 digits in its sheet views and also only 15 digits can be input in its sheet views.
So =PI() will result in 3.1415926535897931 exactly and this value will also be stored. But manual input can only be 3.14159265358979. But if you copy/paste-special:Values the result of =PI(), then also 3.1415926535897931 will be stored although only 3.14159265358979 is shown.
Since *.xlsx files are simply ZIP archives, we can unzip them and look at /xl/worksheets/sheet1.xml. There we will find:
<row r="2" spans="1:2" x14ac:dyDescent="0.25">
<c r="A2" s="1">
<f>PI()</f>
<v>3.1415926535897931</v>
</c>
<c r="B2">
<f>SIN(A2)</f>
<v>1.22514845490862E-16</v>
</c>
</row>
<row r="3" spans="1:2" x14ac:dyDescent="0.25">
<c r="A3" s="1">
<v>3.14159265358979</v>
</c>
<c r="B3">
<f>SIN(A3)</f>
<v>3.2311393144413003E-15</v>
</c>
</row>
<row r="5" spans="1:2" x14ac:dyDescent="0.25">
<c r="A5" s="1">
<v>3.1415926535897931</v>
</c>
<c r="B5">
<f>SIN(A5)</f>
<v>1.22514845490862E-16</v>
</c>
</row>
q.e.d.
The reason you are seeing this is because of a rounding error.
Sin(PI()) is technically 0, as detailed in the Sin function documentation. However, excel returns 1.22515E-16 or 0.0000000000000001225148455
(i.e. approximately 0)
3.14159265358979 is a approximation of PI(), so it returns a different number that it also approximately 0. If you try 3.1415926535897, 3.141592653589 etc, you will get a different number each time.
This is likely related to working with floats, but I don't know enough about Excel and how it stores data to elaborate.
The SIN() function accepts the parameter in radians.
To convert an angle to radians, the value must be multiplied by PI()/180.
If you use =SIN(PI()), the PI is considered as a radian which is equal to RADIANS(180). Both =SIN(PI()) and =SIN(RADIANS(180)) returns the same result 0.
=SIN(3.14159265358979) is not actually equal to =SIN(PI()) because the PI in this context is different. And hence the different result.
The bottom line is to always use radians as a parameter for trigonometric functions.

Using CSS filters to collapse/shift color-mapping in complex, non-rgb way (to 4 hues)

I have a web page I have designed with a specific color scheme, and I want to have 4 specific colors from that scheme to be the only hues present in my images. Essentially, I want to collapse four ranges of hues to four discrete hues. Within one hue I want to maintain the existing tints/brightness variation.
I would like to perform this shift using CSS filters.
I believe I would use feColorMatrix or feComponenentTransfer, however I cannot find an example that shows how to do this kind of shift with 4 or more colors (I only see examples of shifting rgb to either 2 colors, or shifting individually red, green, and blue, so that you go from a certain three color structure to a different three color distribution).
I would like to shift the images so that they only contains these 4 hues:
rgb(82, 79, 161)
rgb(0, 173, 220)
rgb(242,235,22)
rgb(183, 36, 103)
To clarify, this is a visual representation about I would like to see things shift:
You can use this example image:
Here's some basic code/snippet to get you started:
.four_colors {
/*insert filter here */
}
<img class ="four_colors" src="http://i.stack.imgur.com/FGKUX.png">
If you can help, I'd appreciate it greatly!
This is not possible. The SVG Filter primitives that underly CSS Filters do not have HSL-aware primitives (although they should IMHO). Even the hue-rotate filter is a (bad) RGB approximation.
It is not possible to take hue ranges and posterize them. It IS possible to take RGB or brightness ranges and posterize them, so if you want to restate your question in that way, there are solutions. If you really want hue manipulation, you'll have to write that from scratch in Canvas.
By way of inspiration, here is an example of selective color selection using RGB in a filter:
http://codepen.io/mullany/pen/ApInK
<filter id="redselect" color-interpolation-filters="linearRGB">
<feColorMatrix in="SourceGraphic" result="BigRed"type="matrix" values="0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
3.8 -4 -4 0 -0.5" >
</feColorMatrix>
<feColorMatrix type="saturate" values="0" in="SourceGraphic" result="GreySource"/>
<feComposite operator="in" in="SourceGraphic" in2="BigRed" result="RedOriginal"/>
<feComposite operator="atop" in="RedOriginal" in2="GreySource" result="final"/>
</filter>

Changing date format with xslt string functions

I have to solve something with XSLT and am at a loss. I think I need the string-length function, some chose tests, and substring, but I don’t know. The problem is relatively simple.
My xml looks like the sample below. However, I have used YYYY, MM, and DD to represent numbers in the dates.
<date normal=”YYYMMDD”> Month, DD, YYYY</date>
<date normal=”YYYY/YYYY”> YYYY-YYYY</date>
<date normal=”YYYYMM”> Month, YYYY</date>
<date normal=”YYYYMM>MM-YYYY</date>
<name normal=”Smith, John”> John Smith </name>
I need to print all the elements as they are, except for JUST the two elements that have attributes normal=”YYYYMM”. They need to be printed but with attributes in the form normal=YYYY-MM
I cannot rely on the material in the element as it tends to be in a variety of different formats as it is free text.
I keep trying to use string-length function to identify attribute values with 6 characters in the element date. But then I can’t figure out how to split the string in the output with the hyphen. I am guessing it uses one of the substring functions, but I can’t get everything to work together.
Thanks for any advice you can give,
Christine
Something like this?:
<xsl:choose>
<xsl:when text="string-length(#normal) = 6 and number(#normal) = number(#normal)">
<xsl:value-of select="concat(substring(#normal, 1, 4), '-', substring(#normal, 5, 2))" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="#normal" />
</xsl:otherwise>
</xsl:choose>
The number(#normal) = number(#normal) check ensures that #normal is a number, since it looks like you also have some non-date values in the normal attribute. Is there any risk that it might be a 6-digit non-date number?
This complete and short transformation:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|#*">
<xsl:copy>
<xsl:apply-templates select="node()|#*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="#normal[string-length()=6]">
<xsl:attribute name="normal">
<xsl:value-of select="concat(substring(.,1,4),'-',substring(.,5))"/>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
when applied on the following XML document (the provided fragment wrapped into a single top element):
<t>
<date normal="YYYMMDD"> Month, DD, YYYY</date>
<date normal="YYYY/YYYY"> YYYY-YYYY</date>
<date normal="YYYYMM"> Month, YYYY</date>
<date normal="YYYYMM">MM-YYYY</date>
<name normal="Smith, John"> John Smith </name>
</t>
produces the wanted, correct result:
<t>
<date normal="YYYMMDD"> Month, DD, YYYY</date>
<date normal="YYYY/YYYY"> YYYY-YYYY</date>
<date normal="YYYY-MM"> Month, YYYY</date>
<date normal="YYYY-MM">MM-YYYY</date>
<name normal="Smith, John"> John Smith </name>
</t>

iReport (JasperReports) extra row issue

I am getting an extra empty row between data when I am importing it from the database and formatting the report in Excel sheet.
EDIT (clarification from a comment): The output in Excel shows an extra blank row between records and and extra blank column between fields.
Add net.sf.jasperreports.export.xls.remove.empty.space.between.columns and net.sf.jasperreports.export.xls.remove.empty.space.between.rows properties to report template.
net.sf.jasperreports.export.xls.remove.empty.space.between.columns - Specifies whether the empty spacer columns should be removed or not.
net.sf.jasperreports.export.xls.remove.empty.space.between.rows - Specifies whether the empty spacer rows should be removed or not.
The sample:
<jasperReport ...>
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<property name="net.sf.jasperreports.export.xls.remove.empty.space.between.columns" value="true"/>
<property name="net.sf.jasperreports.export.xls.remove.empty.space.between.rows" value="true"/>
The information about configuration properties is here.
You can set isRemoveLineWhenBlank and isBlankWhenNull for textField element for hiding blank row.
The sample how to remove the whole line if the current textField is empty:
<textField isBlankWhenNull="true">
<reportElement x="0" y="0" width="100" height="20" isRemoveLineWhenBlank="true"/>
<textElement/>
<textFieldExpression><![CDATA[$F{field}]]></textFieldExpression>
</textField>
Another assumption is to change the height of all textField (or/and staticText) elements in the Band.
In case this design:
you will have a space between any two rows.
In case this design (textField height is equal to the Band's height):
the each line will be exactly under the other.
Every thing that Alex K states in his Dec 2 '11 answer is correct. But a few other settings may be helpful. These settings help when the text of the report stretches the detail band.
On every field in the detail band set:
positionType="Float"
stretchType="RelativeToTallestObject"
Example:
<detail>
<band height="20" splitType="Prevent">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement positionType="Float" stretchType="RelativeToTallestObject" mode="Transparent" x="372" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{your column name}]]></textFieldExpression>
</textField>
This will force the all fields to be one height. The float setting tells the field to minimize the distance between the previous and next row. The RelativeToTallestObject setting tells all fields in the band to be the same height as the tallest field. These two settings help eliminate 'empty space' which shows up as unwanted cells in Excel.

Resources