My goal is to create a custom switch including animated transitions between checked and unchecked state.
I easily achieved a default state and my switch looks as expected in both states and it changes its look when its state is changed.
Problem arises when I attach animated-selector instead of regular one.
I'm gettting an error like this:
android.view.InflateException: Binary XML file line #10: Binary XML
file line #10: Error inflating class android.widget.Switch
Caused by: android.content.res.Resources$NotFoundException: File
res/drawable/switch_track_animation_unchecked_checked.xml from
drawable resource ID #0x7f060072
at android.content.res.Resources.loadDrawableForCookie(Resources.java:2640)
Caused by: android.content.res.Resources$NotFoundException: File
res/drawable/switch_track_animated_selector.xml from drawable resource
ID #0x7f060070
I can assure that I'm properly accessing those drawables etc.
I went through invalidate caches and restart, clean build, rebuild etc. and it won't work.
View sample
<Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:thumb="#drawable/switch_thumb_selector"
android:track="#drawable/switch_track_animated_selector"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:checked="true"
android:id="#+id/switch2"/>
switch_track_animated_selector
<animated-selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/checked"
android:drawable="#drawable/switch_bckg_on"
android:state_checked="true"/>
<item android:id="#+id/unchecked"
android:drawable="#drawable/switch_bckg_off"
android:state_checked="false"/>
<transition
android:fromId="#+id/unchecked"
android:toId="#+id/checked"
android:drawable="#drawable/switch_track_animation_unchecked_checked"/>
<transition
android:fromId="#+id/checked"
android:toId="#+id/unchecked"
android:drawable="#drawable/switch_track_animation_checked_unchecked"/>
</animated-selector>
switch_bckg_on.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#00B05A"/>
<stroke android:width="1dp" android:color="#00B05A" />
<corners android:radius="180dp"/>
<padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" />
</shape>
switch_bckg_off.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#F1F1F1"/>
<stroke android:width="1dp" android:color="#E0E0E0" />
<corners android:radius="180dp"/>
<padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" />
</shape>
switch_track_animation_checked_unchecked.xml
<?xml version="1.0" encoding="utf-8"?>
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:drawable="#drawable/switch_bckg_on">
<target android:name="android:drawable">
<aapt:attr name="android:animation">
<objectAnimator
android:duration="#android:integer/config_shortAnimTime"
android:interpolator="#android:interpolator/accelerate_decelerate"
android:propertyName="strokeColor"
android:valueFrom="#A0A0A0"
android:valueTo="#1E9618"
android:valueType="intType" />
</aapt:attr>
</target>
</animated-vector>
switch_track_animation_unchecked_checked.xml
<?xml version="1.0" encoding="utf-8"?>
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:drawable="#drawable/switch_bckg_off">
<target android:name="android:drawable">
<aapt:attr name="android:animation">
<objectAnimator
android:duration="#android:integer/config_shortAnimTime"
android:interpolator="#android:interpolator/accelerate_decelerate"
android:propertyName="strokeColor"
android:valueFrom="#A0A0A0"
android:valueTo="#1E9618"
android:valueType="intType"/>
</aapt:attr>
</target>
</animated-vector>
I also checked above approach using vector drawable instead of shape and I had the same result.
Example of vectors
ic_thumb_vector_off
<vector android:height="33dp" android:viewportHeight="300"
android:viewportWidth="300" android:width="33dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:name="background_off" android:fillColor="#FFFFFF" android:fillType="nonZero"
android:pathData="M149.926,149.926m-149.176,0a149.176,149.176 0,1 1,298.352 0a149.176,149.176 0,1 1,-298.352 0"
android:strokeAlpha="0.1" android:strokeColor="#000000" android:strokeWidth="0.5"/>
<path android:name="icon_off" android:fillColor="#9B9B9B" android:fillType="evenOdd"
android:pathData="M166.88,146.104C166.13,145.354 166.13,144.228 166.88,143.478L195.019,115.339C195.77,114.588 196.145,113.463 196.145,112.712C196.145,111.962 195.77,110.836 195.019,110.086L189.767,104.833C189.016,104.083 187.891,103.708 187.14,103.708C186.015,103.708 185.264,104.083 184.514,104.833L156.375,132.972C155.624,133.723 154.499,133.723 153.748,132.972L125.609,104.833C124.859,104.083 123.733,103.708 122.983,103.708C122.233,103.708 121.107,104.083 120.357,104.833L115.104,110.086C114.354,110.836 113.979,111.962 113.979,112.712C113.979,113.463 114.354,114.588 115.104,115.339L143.243,143.478C143.994,144.228 143.994,145.354 143.243,146.104L115.104,174.243C114.354,174.993 113.979,176.119 113.979,176.869C113.979,177.62 114.354,178.745 115.104,179.496L120.357,184.748C121.107,185.499 122.233,185.874 122.983,185.874C123.733,185.874 124.859,185.499 125.609,184.748L153.748,156.609C154.499,155.859 155.624,155.859 156.375,156.609L184.514,184.748C185.264,185.499 186.39,185.874 187.14,185.874C187.891,185.874 189.016,185.499 189.767,184.748L195.019,179.496C195.77,178.745 196.145,177.62 196.145,176.869C196.145,176.119 195.77,174.993 195.019,174.243L166.88,146.104Z"
android:strokeColor="#00000000" android:strokeWidth="1"/>
</vector>
ic_thumb_vector_on
<vector android:height="33dp" android:viewportHeight="302"
android:viewportWidth="302" android:width="33dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:name="background_on" android:fillColor="#FFFFFF" android:fillType="nonZero"
android:pathData="M151,151m-150.25,0a150.25,150.25 0,1 1,300.5 0a150.25,150.25 0,1 1,-300.5 0"
android:strokeAlpha="0.1" android:strokeColor="#000000" android:strokeWidth="0.5"/>
<path android:name="icon_on" android:fillColor="#00B05A" android:fillType="evenOdd"
android:pathData="M105.523,153.198C104.806,152.5 104.448,151.453 104.448,150.754C104.448,150.056 104.806,149.009 105.523,148.31L110.536,143.422C111.968,142.026 114.117,142.026 115.549,143.422L115.907,143.772L135.602,164.371C136.318,165.069 137.393,165.069 138.109,164.371L186.093,115.841L186.451,115.841C187.883,114.444 190.032,114.444 191.464,115.841L196.477,120.728C197.91,122.125 197.91,124.22 196.477,125.616L139.183,183.573C138.467,184.272 137.751,184.621 136.676,184.621C135.602,184.621 134.886,184.272 134.17,183.573L106.239,154.246L105.523,153.198Z"
android:strokeColor="#00000000" android:strokeWidth="1"/>
</vector>
Maybe I/m missing something in gradle file?
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
defaultConfig {
applicationId "...customswitch"
minSdkVersion 22
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
I expect this view to load and not to throw an error on view init.
Your issue is that switch_track_animation_unchecked_checked.xml and switch_track_animation_checked_unchecked.xml are animated VectorDrawables, and these animate static VectorDrawable states. You are trying to animate ShapeDrawable, and not VectorDrawable and that's what is causing the exception, I think.
You need to replace switch_bckg_on.xml and switch_bckg_off.xml with <vector>...</vector> implementations to animate them from within an <animated-vector>...</animated-vector> block.
Alternatively you could replace the AnimatedVectorDrawables with StateListAnimator, although I'm not sure that will actually be able to do what you're trying to achieve here.
It seems like your switch_track_animated_selector does not have some default state without any id. You may try to add this state. This helped me in a similar situation
I am currently looking to run multiple test in cucumber in parallel using testng and I successfully managed to do that.
Now my requirement is rather than having multiple Test TAGS in the testNG file with different parameters take it from the maven command line. So I can do automation without editing the testNg.xml file. Is there a way to achieve it? Please find my current testng.xml configuration.
testng.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Testng Cucumber Suite" thread-count="2" parallel="tests">
<!-- In order to run test cases please copy and one test and add make sure you add relevant parameters -->
<test name="Run_Nexus_06">
<parameter name="deviceName" value="Google Nexus 6" />
<parameter name="platformVersion" value="6.0" />
<classes>
<class name="cucumber.mobile.ParallelRunner">
</class>
</classes>
</test>
<test name="Run_Google_Pixel">
<parameter name="deviceName" value="Google Pixel" />
<parameter name="platformVersion" value="7.1" />
<classes>
<class name="cucumber.mobile.ParallelRunner">
</class>
</classes>
</test>
</suite>
Runner Class :
#CucumberOptions(plugin = {"pretty", "html:target/html/", "json:target/cucumber.json", "junit:TEST-all.xml"},
features = "src/test/resources/features/SignUp.feature", glue = {"steps"}, tags = {"#Mobile"})
public class ParallelRunner extends Hook{
List<Object[]> data;
//<parameter name="deviceName" value="Google Pixel" />
// <parameter name="platformVersion" value="7.1" />
#BeforeTest
#Parameters({"deviceName","platformVersion"})
public void bb(String deviceName, String platformVersion){
Device device = new Device();
device.setDeviceName(deviceName);
device.setOsVersion(platformVersion);
DeviceFactory.setDevice(device);
System.out.println("Device" + deviceName + "Os Version" + platformVersion + " " + Thread.currentThread().getId());
}
}
I was glad that I found this post. Very useful if anyone trying to achieve the same thing. Dynamic Test ng IAlterSuiteListener
Maven command :> mvn compile test -DdeviceFlavors="Google Nexus 6","Google Pixel" -DdeviceOsFlavors="6.0","7.1" -Dsurefire.suiteXmlFiles=testng.xml
I'm working on .Net Core 2.0 console application. NLog version 4.5.7.
Here is my config file:
<?xml version="1.0" encoding="utf-8" ?>
<nlog
xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
throwExceptions="false"
internalLogFile="Logs/Internal/log.txt"
internalLogLevel="Warn"
internalLogToConsole="false"
internalLogToConsoleError="false"
internalLogToTrace="false"
internalLogIncludeTimestamp="true">
<targets>
<default-wrapper
xsi:type="AsyncWrapper"
timeToSleepBetweenBatches="0"
overflowAction="Block"/>
<default-target-parameters
xsi:type="File"
layout="${longdate}|${level:uppercase=true}|${message}
${onexception:${newline}}${exception:format=tostring}"
archiveAboveSize="10485760"
maxArchiveFiles="10"
archiveNumbering="DateAndSequence"
archiveOldFileOnStartup="true"
keepFileOpen="true"
cleanupFileName="false"/>
<target
name="driver"
xsi:type="File"
archiveFileName="Logs/Driver/Archives/log.{#####}.txt"
fileName="Logs/Driver/log.txt"/>
</targets>
<rules>
<logger
name="driver"
minlevel="Trace"
writeTo="driver"/>
</rules>
</nlog>
I'm setting this config on startup of my application:
LogManager.Configuration = new XmlLoggingConfiguration(<path>, false);
And then I'm adding file targets to this configuration programmatically:
string
deviceTag = string.Concat("Device_", _id.ToString()),
loggerName = string.Concat("logger_", deviceTag);
LogManager.Configuration.AddRuleForAllLevels(
new FileTarget(string.Concat("target_", deviceTag))
{
FileName = string.Concat("Logs/", deviceTag, "/log.txt"),
ArchiveFileName = string.Concat("Logs/", deviceTag,
"/Archives/log.{#####}.txt")
}, loggerName);
_logger = LogManager.GetLogger(loggerName);
LogManager.ReconfigExistingLoggers();
Target is working, logs are written. But default-target-parameters from xml config are ignored.
This is a bug or a feature?
Or I do something wrong?
I try to use libxmljs with nodejs.
In my sample I want to use the xi:include.
<ord:order xmlns:ord="http://example.org/ord"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://example.org/ord chapter04ord1.xsd"
xmlns:xi="http://www.w3.org/2001/XInclude">
<number>123ABBCC123</number>
<customer>
<name>Priscilla Walmsley</name>
<number>15466</number>
</customer>
<items>
<xi:include href="/Users/mar/ws_e/libxml/test/resources/chapter5prod.xml" />
</items>
</ord:order>
include File:
<ord:product xmlns:ord="http://example.org/ord"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://example.org/ord chapter04ord1.xsd">
<number>557</number>
<name>Short-Sleeved Linen Blouse</name>
<size system="US-DRESS">10</size>
<color value="blue"/>
</ord:product>
This is my code:
var xsdDoc = libxml.parseXml(schemaSource);
var xmlDocValid = libxml.parseXml(docSource);
var xmlDocInvalid = libxml.parseXml(xml_invalid);
xmlDocValid.validate(xsdDoc);
console.dir(xmlDocValid);
console.dir(xmlDocValid.validationErrors);
Then I get the error:
Document {
errors: [],
validationErrors:
[ { Error: Element '{http://www.w3.org/2001/XInclude}include': This element is not expected. Expected is ( product ).
So my question is how to use the x:include right at libxmljs?
Kind regards
Markus
Using Groovy 2.0.5 JVM 1.6.0_31, I have created a script that takes an existing XML-file as input
def root = new XmlParser().parse(new File('filename'))
I parse the file and replaces certain attributes like this
root.Settings.Setting.each {
if (it.'#NAME' =~ 'CASEID_SEQUENCE_SIZE') {
it.'#VALUE' = '100'
And then at the end writes the changes to a new file like this
def outputfile = new File( levelConfig.RESULTFILE )
new XmlNodePrinter(new PrintWriter(outputfile)).print(root)
All this is fine, no problem, except when the XML has CDATA, like this
<HandlerURL>
<![CDATA[admin/MainWindow.jsp]]>
</HandlerURL>
the result is then
<HandlerURL>
admin/MainWindow.jsp
</HandlerURL>
Question is
How can I get my script to not do anything with the CDATA?
Found you can do:
import groovy.xml.*
import groovy.xml.dom.DOMCategory
def xml = '''<root>
| <Settings>
| <Setting name="CASEID_SEQUENCE_SIZE">
| <HandlerURL>
| <![CDATA[ admin/MainWindow.jsp ]]>
| </HandlerURL>
| </Setting>
| <Setting name="SOMETHING_ELSE">
| <HandlerURL>
| <![CDATA[ admin/MainWindow.jsp ]]>
| </HandlerURL>
| </Setting>
| </Settings>
|</root>'''.stripMargin()
def document = DOMBuilder.parse( new StringReader( xml ) )
def root = document.documentElement
use(DOMCategory) {
root.Settings.Setting.each {
if( it.'#name' == 'CASEID_SEQUENCE_SIZE' ) {
it[ '#value' ] = 100
}
}
}
def result = XmlUtil.serialize( root )
println result
To get the output:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<Settings>
<Setting name="CASEID_SEQUENCE_SIZE" value="100">
<HandlerURL>
<![CDATA[ admin/MainWindow.jsp ]]>
</HandlerURL>
</Setting>
<Setting name="SOMETHING_ELSE">
<HandlerURL>
<![CDATA[ admin/MainWindow.jsp ]]>
</HandlerURL>
</Setting>
</Settings>
</root>