Categories
discuss

CSS3 + Javascript – Will -ms-transition:opacity 1s ease-in-out; work in IE 10 alone?

I have been playing around with some CSS3 + JavaScript today.

Below you have my code, (was trying to make the world’s smallest image fading gallery, don’t know if I succeeded).

I am not quite sure how to set the CSS though. See comment questions below:

-ms-transition:opacity 1s ease-in-out; // Will this allone work in IE 10?       
transition:opacity 1s ease-in-out; // Why do we set this?

Maybe the world’s smallest JS-Gallery:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>HB - CSS3 + JS Gallery</title>
<meta charset="utf-8">
<style type="text/css">
body{margin:0;text-align:center;font:200px/500px georgia}
#g{background:#000;margin:0 auto;width:960px;height:500px;overflow:hidden}
#g div{
-webkit-transition:opacity 1s ease-in-out;
-moz-transition:opacity 1s ease-in-out;
-o-transition:opacity 1s ease-in-out;
-ms-transition:opacity 1s ease-in-out;      
transition:opacity 1s ease-in-out;
opacity:0;position:absolute;height:500px;width:960px;}
</style>
</head>
<body>
<div id="g">
<div style="background:#090">1</div>
<div style="background:#096">2</div>
<div style="background:#963">3</div>
<div style="background:#CC0">4</div>
</div>
<script>
function i(){c[a].style.opacity='1'}function o(){c[a].style.opacity='0'}var g=document.getElementById('g'),c=g.children,l=c.length-1,f=function(){if(a==l){o();a=0;i()}else{o();a++;i()}};a=0;i();setInterval(f,4000);
</script>
</body>
</html>

Answer

-ms-transition:opacity 1s ease-in-out; // Will this allone work in IE 10?

If Microsoft have implemented a vendor-specific implementation of transition in Internet Explorer then this will be triggered by the -ms-transition property declaration, assuming that the arguments meet the specification they’ve implemented.

Can I Use suggests that IE 10 has, indeed, implemented the -ms-transition property, as does the MSDN entry, though it’s non-specific as to which version of IE this is implemented in…

transition:opacity 1s ease-in-out; // Why do we set this?

We set this in order that once the standard implementation of transition is finalised and implemented this will override any interim vendor-specific implementations

Categories
discuss

In Java, is the result of the addition of two chars an int or a char?

When adding 'a' + 'b' it produces 195. Is the output datatype char or int?

Answer

The result of adding Java chars, shorts, or bytes is an int:

Java Language Specification on Binary Numeric Promotion:

  • If any of the operands is of a reference type, unboxing conversion (ยง5.1.8) is performed. Then:
  • If either operand is of type double, the other is converted to double.
  • Otherwise, if either operand is of type float, the other is converted to float.
  • Otherwise, if either operand is of type long, the other is converted to long.
  • Otherwise, both operands are converted to type int.

But note what it says about compound assignment operators (like +=):

The result of the binary operation is converted to the type of the left-hand variable … and the result of the conversion is stored into the variable.

For example:

char x = 1, y = 2;
x = x + y; // compile error: "possible loss of precision (found int, required char)"
x = (char)(x + y); // explicit cast back to char; OK
x += y; // compound operation-assignment; also OK

One way you can find out the type of the result, in general, is to cast it to an Object and ask it what class it is:

System.out.println(((Object)('a' + 'b')).getClass());
// outputs: class java.lang.Integer

If you’re interested in performance, note that the Java bytecode doesn’t even have dedicated instructions for arithmetic with the smaller data types. For example, for adding, there are instructions iadd (for ints), ladd (for longs), fadd (for floats), dadd (for doubles), and that’s it. To simulate x += y with the smaller types, the compiler will use iadd and then zero the upper bytes of the int using an instruction like i2c (“int to char”). If the native CPU has dedicated instructions for 1-byte or 2-byte data, it’s up to the Java virtual machine to optimize for that at run time.

If you want to concatenate characters as a String rather than interpreting them as a numeric type, there are lots of ways to do that. The easiest is adding an empty String to the expression, because adding a char and a String results in a String. All of these expressions result in the String "ab":

  • 'a' + "" + 'b'
  • "" + 'a' + 'b' (this works because "" + 'a' is evaluated first; if the "" were at the end instead you would get "195")
  • new String(new char[] { 'a', 'b' })
  • new StringBuilder().append('a').append('b').toString()
  • String.format("%c%c", 'a', 'b')
Categories
discuss

Error in res values string “Locale it is missing translations for”

In my project I am getting an error that can’t allow me to compiling.
It is reported, as an example:
Description Resource Path Location Type
Locale it is missing translations for: foo, htmlsource1, htmlsource_old values-it /Android_coll/res line 1 Android Lint Problem

” foo, htmlsource1, htmlsource_old ” are old string that now are not any more in the in res->values-it folder.
To be more specific they are no longer present in the whole project

I’ve tried:

  • close and open the project.

  • close and open Eclipse (indingo)

  • clean the project (project-> clean)

  • copy the file string.xml from the folder values and copy it to the folder values-it

but i still have the same error message.

thanks
marco

Answer

I had this same problem when I updated to the 4.0 SDK. The problem was with Android Lint. If you go to project properties->Android->Lint Error Checking and change the severity of “Missing Translation” to be something other than Error, you should be able to build now.

Categories
discuss

Animate Two Layer Drawable Items Pre-Honeycomb

I am trying to animate two layers of a drawable to achieve the effect of the post-Honeycomb indeterminate progress indicator. The XML is very straightforward but it would seem that only one layer will animate when run on platforms prior to Honeycomb.

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <rotate
             android:drawable="@drawable/abs__spinner_48_outer_holo"
             android:pivotX="50%"
             android:pivotY="50%"
             android:fromDegrees="0"
             android:toDegrees="1080" />
    </item>
    <item>
        <rotate
             android:drawable="@drawable/abs__spinner_48_inner_holo"
             android:pivotX="50%"
             android:pivotY="50%"
             android:fromDegrees="720"
             android:toDegrees="0" />
    </item>
</layer-list>

Is this simply a limitation of these platforms or is there an alternate syntax that I can use (either in general or specifically targetted at pre-API11) to achieve the desired functionality?

Answer

There is indeed a platform limitation, although it’s not what you might think. The issue is that pre-API11, RotateDrawable had some crude code in it to require that the animation rotate clockwise by checking if toDegrees was greater than fromDegrees; if not, the two were forced equal to each other. If you modified your example to have the second item move in a forward direction (from 0 to 720, or even -720 to 0), both images would animate fine on all platforms; though I realize that defeats the purpose of what you’re aiming for.

Take a look at the cached version Google Codesearch has of RotateDrawable.inflate(), which is the 2.3 version of the method used to turn the XML into the object, and you’ll see what I mean.

RotateDrawable.java …the offending code is around line 235…

    float fromDegrees = a.getFloat(
            com.android.internal.R.styleable.RotateDrawable_fromDegrees, 0.0f);
    float toDegrees = a.getFloat(
            com.android.internal.R.styleable.RotateDrawable_toDegrees, 360.0f);

    toDegrees = Math.max(fromDegrees, toDegrees); //<--There's the culprit

This takes an XML block like the second item that you have there, and turns it into a RotateDrawable that ends up with the same value for fromDegrees and toDegrees (in your case, 720), causing the image to simply stand still. You can visible test this by setting the start value to some value not a multiple of 360 (like 765). You’ll see that the image still does not animate, but is rotated to the initial coordinate.

This awkward check was removed in the Honeycomb/ICS sources, which is why you can do backwards rotation on those platforms. Also, it doesn’t look like there is a way to set these values from Java code, so a custom RotateDrawableCompat may be in your future ๐Ÿ™‚

HTH

Categories
discuss

Run intent DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN from a service

I have a service and I want the service promote to enable it as Device Admin, until now I launched this kind of UI interactions from the service like

    Intent intent2 = new Intent();
    intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent2.setAction(android.content.Intent.ACTION_VIEW);
    intent2.setDataAndType(uri, "application/vnd.android.package-archive");
    context.startActivity(intent2);

and it works, but with DevicePolicyManager I can’t find the way:

        Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mAdminName);
        intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,  "some text.");
        context.startActivity(intent);

does’t work: do not promote nothing but also do not crash. Without intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); It simply crash because this code is inside a tread inside a service. Ideas?

Answer

I’ve just fixed such issue for myself.

Note, that you need to put this code inside parent in Android Manifest.xml file:

    <receiver
        android:name=".ScreenLockerDeviceAdminReceiver"
        android:permission="android.permission.BIND_DEVICE_ADMIN" >
        <meta-data
            android:name="android.app.device_admin"
            android:resource="@xml/device_admin_policies" />

        <intent-filter>
            <action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
        </intent-filter>
    </receiver>

and it works ๐Ÿ™‚

Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 ยฉ No Copyrights, All Questions are retrived from public domain..