Categories
discuss

Missing “/extras/google/google_play_services/libproject” folder after update to revision 30

I updated the Google Play Services version from the revision 29 to 30 using the Android SDK Manager, but after updating the directory "<sdk>/extras/google/google_play_services/libproject" disappeared, leaving only the directories “docs” and ” samples”.

I’ve tried uninstall and reinstall several times but always happens to miss the directory “libproject”.

Anyone had this problem with the update?

I’m using Debian Linux 8.4 (jessie) although not believe it has anything to do with the problem.

Android SDK Manager screen

google_play_services directory screen

Answer

Looks like Google just broke down Google Play Services into multiple libraries. You’ll find them in <sdk>/extras/google/m2repository/com/google/android/gms, if you also updated Google Repository through the SDK Manager.

The individual libraries are in aar format, so you’ll have to extract the jar yourself, if that’s what you’re after.

Categories
discuss

Copy current url button – Javascript

okay it might be something simple or completely wrong however I’m trying to create a button to copy current URL to clipboard, this is what I currently have, I’m not too familiar with javascript so this is from a few sources mixed together and hoping for the best.

<button onclick="CopyLink()">Click me</button>
<script>
function CopyLink() {
window.clipboardData.setData("Text", location.href);
}
</script>

Any help would be great thanks!

Answer

Using the function copyTextToClipboard from this answer, you can copy the link on a button click like so:

function copyTextToClipboard(text) {
  var textArea = document.createElement("textarea");

  //
  // *** This styling is an extra step which is likely not required. ***
  //
  // Why is it here? To ensure:
  // 1. the element is able to have focus and selection.
  // 2. if element was to flash render it has minimal visual impact.
  // 3. less flakyness with selection and copying which **might** occur if
  //    the textarea element is not visible.
  //
  // The likelihood is the element won't even render, not even a flash,
  // so some of these are just precautions. However in IE the element
  // is visible whilst the popup box asking the user for permission for
  // the web page to copy to the clipboard.
  //

  // Place in top-left corner of screen regardless of scroll position.
  textArea.style.position = 'fixed';
  textArea.style.top = 0;
  textArea.style.left = 0;

  // Ensure it has a small width and height. Setting to 1px / 1em
  // doesn't work as this gives a negative w/h on some browsers.
  textArea.style.width = '2em';
  textArea.style.height = '2em';

  // We don't need padding, reducing the size if it does flash render.
  textArea.style.padding = 0;

  // Clean up any borders.
  textArea.style.border = 'none';
  textArea.style.outline = 'none';
  textArea.style.boxShadow = 'none';

  // Avoid flash of white box if rendered for any reason.
  textArea.style.background = 'transparent';


  textArea.value = text;

  document.body.appendChild(textArea);

  textArea.select();

  try {
    var successful = document.execCommand('copy');
    var msg = successful ? 'successful' : 'unsuccessful';
    console.log('Copying text command was ' + msg);
  } catch (err) {
    console.log('Oops, unable to copy');
  }

  document.body.removeChild(textArea);
}

function CopyLink() {
  copyTextToClipboard(location.href);
}
<button onclick="CopyLink()">Click me</button>
Categories
discuss

See all keys of a JS object, even those defined by getters

I would like to JSON.stringify all properties of an object, including those defined via getters. However, when I call JSON.stringify on an object, properties defined via getters are omitted:

> const obj = {key: 'val'}
undefined

> JSON.stringify(obj)
'{"key":"val"}'

> Object.defineProperty(obj, 'getter', {get: () => 'from getter'})
{ key: 'val' }

> obj.getter
'from getter'

> JSON.stringify(obj)
'{"key":"val"}'

I was hoping to see:

> JSON.stringify(obj)
'{"key":"val", "getter": "from getter"}'

Is this possible? Object.keys isn’t detecting the getters either:

> Object.keys(obj)
[ 'key' ]

Can you query for getter keys? Or do you have to know their names ahead of time?

Answer

JSON.stringify only includes enumerable properties in its output.

When enumerable is not specified on the property descriptor passed into Object.defineProperty, it defaults to enumerable: false. Thus, any property definition done by Object.defineProperty (with a getter or not) will be non-enumerable unless you explicitly specify enumerable: true.

You can get all the properties that exist on an object (N.B: not inherited properties) with Object.getOwnPropertyNames or (in ES2015+) Reflect.ownKeys. (The only difference between these is that Reflect.ownKeys also includes properties defined by a Symbol key.) It is not possible to make JSON.stringify include non-enumerable properties; you must instead make the property enumerable.

Categories
discuss

Why do transitions flicker/stutter when applied in a separate function (D3)

I was messing around with transitions and I noticed some stuttering and flickering when the transitions are applied to the selection in a different function. If, however, the transition is applied with method chaining, it works exactly as prescribed.

Below is small example (Fiddle) of simply moving some text. The first, leftmost, string magically teleports down the page before the transition starts. The second, rightmost, string has a smooth transition from the top to the bottom of the page.

Why does this ‘teleport’ happen? Obviously applying the transitions in a separate function is not the same as chaining it, but is there a way to achieve this? Say, I want to apply the same transition to many different objects – retrieved from different selects – then is there a way to relegate the transition to its own function without getting this stuttering?

var svg = d3.select('svg');
var textElem = svg.append('text')
    .data(['hello world'])
    .attr('x', 30)
    .attr('y', 100)
    .attr('fill', '#000')
    .attr('id', 'a')
    .text(function (d) {
        return d;
    });
var textElem2 = svg.append('text')
    .data(['some text'])
    .attr('x', 230)
    .attr('y', 100)
    .attr('fill', '#000')
    .attr('id', 'a')
    .text(function (d) {
        return d;
    });
setTimeout(foo, 3000);

function foo() {
    textElem.data(['hello world, again!']);
    applyTextTransitions(textElem);
    textElem.attr({
        x: 30,
        y: 150
    });
    textElem.text(function (d) {
        return d;
    });

    textElem2.data(['some more text!'])
        .transition()
        .duration(1000)
        .style('opacity', 0)
        .transition()
        .duration(1000)
        .style('opacity', 1)
        .attr({
            x: 230,
            y: 150
        })
        .text(function (d) {
            return d;
        });
}

function applyTextTransitions(element) {
    element
        .transition()
        .duration(1000)
        .style('opacity', 0)
        .transition()
        .duration(1000)
        .style('opacity', 1);
}

Answer

I haven’t used d3, but do you mean to do this?

applyTextTransitions(textElem, { x: 30, y: 150 }); 

function applyTextTransitions(element, newPos) {
    element
    .transition()
    .duration(1000)
    .style('opacity', 0)
    .transition()
    .duration(1000)
    .attr(newPos)
    .style('opacity', 1)
    .text(function(d){
        return d; 
     }); 
}

https://jsfiddle.net/k8kv4arv/3/

The “jump” happens because the calling functions waits until applyTextTransitions() is finished, then applies the new dimensions.

Categories
discuss

Getting data from TableRow component in Material UI

I’m using a Table component in the newest version of Material UI, and I’m not sure how I’m supposed to be acquiring data from a Table’s row when it’s selected.

The documentation mentions a prop for the Table component called onRowSelection, but it only gives you a RowNumber for the row that was selected, nothing else.

How are you supposed to make any use of this at all? I don’t understand how you’re meant to grab say…the key prop that’s set to the TableRow using nothing but the RowNumber prop of that same TableRow.

Code below shows how I’m rendering the table itself, and assigning the key:

handleSelect(id) {
  console.log(id);
  this.props.dispatch({ type: 'SET_SELECTED_USER', user: id });
}

renderUsers() {
  if (this.props.users && this.props.currentUser) {
    const currUser = this.props.currentUser.username;
    const userList = this.props.users.map((user) => {
      if (currUser !== user.username) {
        return (
          <TableRow key={user._id}>
            <TableRowColumn>{user.username}</TableRowColumn>
            <TableRowColumn>{user.roles[0]}</TableRowColumn>
          </TableRow>
        );
      }
    });
    return userList;
  }
}

I just don’t understand how the RowNumber of the row being selected is supposed to help me whatsoever, when I need to access they key of the row instead.

Any assistance would be really appreciated! Thanks!

Docs for Table: http://www.material-ui.com/#/components/table

Answer

You could use the row number as an index in your users array (this.props.users):

handleSelect(userIndex) {
  const currUser = this.props.currentUser.username;
  const users = this.props.users.filter(user => user.username !== currUser)
  this.props.dispatch({ type: 'SET_SELECTED_USER', user: users[userIndex].id });
}
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..