Wikipedia:Reference desk/Archives/Computing/2016 December 6

= December 6 =

Working example of Android Studio project importing support-v4 and built using Gradle
Even after installing the Android Support Repository, installing it as a global library in Android Studio, marking it as a dependency for my project's module, enabling Gradle, writing global and module  files, and declaring both   and   in the latter, I'm still getting "Error:(28, 31) java: package android.support.v4.util does not exist". Can anyone link me to a working example of a project that Android Studio can build and that uses Gradle and at least one of the  packages? The only method of troubleshooting left that I can think of is to start with one, transplant my code into it, and then overwrite my existing project with it. Neon Merlin  05:00, 6 December 2016 (UTC)

iPhone screen unusable when charging through mains
I've had an iPhone 5S for nearly three years. Recently, when I've been charging it through the mains (with a British three-pin plug) its screen has become totally unusuable - largely unresponsive, registering taps in the wrong places etc.

But when I charge it through a USB port, using the same lightning cable, it works fine.

What can be causing this? Thanks Amisom (talk) 11:58, 6 December 2016 (UTC)


 * My old phone (a Droid) had the same problem when I was in Europe. I noticed it in England and Spain and suspect the same issue was occurring, but unnoticed, elsewhere. The issue was with ground. The outlets had a floating ground, which messed up the phone's calibration of the screen. In Spain it was so bad that it registered random clicks all over the screen. So, I had to charge the phone with it turned off. The same phone, same charger, but with an American 2-prong outlet didn't have problems in the U.S. 71.85.51.150 (talk) 15:24, 6 December 2016 (UTC)
 * But..... But.... A phone charger does not have a ground pin? Vespine (talk) 21:48, 6 December 2016 (UTC)
 * It could be that the ground pin does not connect (open connection in the plug or the socket). Just out of curiosity, could you look at AC power plugs and sockets: British and related types and tell us exactly what kind you have? --Guy Macon (talk) 23:21, 6 December 2016 (UTC)
 * Blow me down, I stand corrected, a UK iPhone charger] has an earth pin! Vespine (talk) 02:49, 7 December 2016 (UTC)
 * That "earth pin" is actually plastic and serves only to open the covers for the live and neutral pins to enter the socket. No part of the output of the charger should be connected to either input pin (or to earth/ground) but maybe your charger is different? In some older UK installations, the Protective Multiple Earth connections are inadequate, resulting in a significant voltage appearing between neutral and earth.  I recall being able to light a 6v lighbulb quite brightly between these pins years ago.  In modern installations, this should not happen.    D b f i r s   09:11, 7 December 2016 (UTC)
 * On that illustration, the earth pin appears metallic - it's the same texture as the tips of the live and neutral - so it might be a real earth. Without an real life charger or a better photo, I don't think it's possible to be certain.--Phil Holmes (talk) 10:33, 7 December 2016 (UTC)
 * I happen to have an old ipad charger here, and can confirm that the ground is indeed metallic. It's a two-part charger with a plug that can be separated from the part which actually does the power conversion (and has the USB port) - and the connection between the two appears to only have two pins (there's a third structural connection which is metallic on the power convertor side - but there's no matching metal component to connect it to on the plug). Model number on the power convertor is A1357.  I'm at work (and this plug belongs to the office), so not able to take it apart and see if the earth is connected to anything.  Of course, this charger is much older than the lightning connector, so the design may have changed since (especially given that they are now all on piece), but it suggests that Apple include a metal earth pin, even if it is not necessary.  The power convertor has the symbol for a double insulated device (not requiring an earth), the plug does not. MChesterMC (talk) 11:02, 7 December 2016 (UTC)
 * Apologies if I mis-read the illustration. It's unusual to have a metal earth pin on a plug for a double-insulated device these days.  All of mine are plastic.    D b f i r s   11:14, 7 December 2016 (UTC)


 * In reference to the examples described. I have often seen weird electronic issues when using the 2-prong outlets in Europe. I have not seen issues when using a 3-prong outlet. But... I do remember a flickering problem with an LCD television in the US. The problem was caused by bad wiring. The ground on the outlet was not connected to anything. I fixed it by attaching it to earth (the old house has completely run with 2-wire, so an earth stake was cheaper than a complete rewiring). Therefore, the suggestion that it may be a "floating ground" should not apply - unless the original question came from someone who moved and used to have a properly grounded outlet, but now has a 3-prong outlet with no ground. 209.149.113.4 (talk) 15:39, 7 December 2016 (UTC)

JavaScript question
document.getElementById(mw-content-text)

Returns a reference to mw-content-text.

So,

var cont = document.getElementById(mw-content-text)

Makes it so that anything done to cont is done to mw-content-text.

What I need to do is store the state of mw-content-text before I process cont.

And return mw-content-text to that state later in the script.

Or display the contents of a variable holding that content, instead of the altered mw-content-text.

I just don't know how to do it. (I'm a newbie).

I look forward to your replies. The Transhumanist 22:17, 6 December 2016 (UTC)


 * I'm not an expert in JavaScript, but it sounds like you want to do a deep copy or deep clone of the object? There should be a couple of articles or Stack Overflow posts about how to do this using vanilla JS or frameworks/libraries like jQuery or MooTools, e.g. 4 Creative Ways to Clone Objects. --Canley (talk) 03:48, 7 December 2016 (UTC)


 * You can use: var orig = cont.clone_node(true); to clone the element. Then, later, you can use: parent.replaceChild(orig, cont); to replace the adjusted cont with the original. You need to get the parent object for cont first (identified as parent here, but you will use a more descriptive variable name). 209.149.113.4 (talk) 15:27, 7 December 2016 (UTC)


 * Thank you. I tried adding var orig = cont.clone_node(true); and it causes the script not to work. I've posted the problem and the script at Village pump (technical). The Transhumanist 08:39, 8 December 2016 (UTC)


 * "Causes script not to work" ... Does that mean that you didn't look at the console or debugger to see the problem? You stated that you are beginner. As a beginner, your focus should be on learning to debug, not learning to copy and paste other people's code. 209.149.113.4 (talk) 13:16, 8 December 2016 (UTC)


 * The console wasn't very helpful. It just presented messages like "Use of "wgPageName" is deprecated. Use mw.config instead."


 * Scratching my head, I searched for and studied terms suggested above and similar to those suggested.


 * I tried the following...


 * And it didn't cause any errors. The program simply didn't do what I wanted it to do.  It showed the content in the clone once, but when activated a second time, no cigar.   On a hunch that it had something to do with function scope, I created a second generation clone within the function, like so:


 * And now the script works like a charm. The clone within the function dies each time the function is closed. But is reborn each time the function runs again.


 * Thank you Canley, your answer helped solve the problem!


 * User "209.149.113.4", thank you for the tip on debugging. I'm studying a chapter on that now. The Transhumanist 00:31, 11 December 2016 (UTC)