Categories
discuss

Is it possible to debug an Android library used by a Xamarin.Android binding project?

I’ve written some code in Java, which I’ve compiled into an AAR from Android Studio, that I need to use in my Xamarin.Android app. I’ve done this by following the instructions here to create a bindings library for my Java code.

Now I would like to step into the Java code to investigate an issue. Is it possible to do this from either Visual Studio or Android Studio? Thanks.

edit: For example, would it be possible to somehow attach the Android Studio debugger to my app’s process? It calls the code in the AAR, but I’m not sure if Android Studio would know where to look for the AAR’s sources in order to debug.

Answer

Pleasantly, the answer is yes and it couldn’t be simpler to do so. After you start debugging from Visual Studio, go to your Android Studio project and click this button:

A dialog will come up asking which process you want to attach to. Make sure you have ‘Show all processes’ checked, and you will be able to see one corresponding to your app.

Once you attach to your app’s process, you will be able to set breakpoints in the Java code and have them work like magic.

Categories
discuss

Vue-router error: TypeError: Cannot read property ‘matched’ of undefined

I’m trying to write my first Vuejs app. I’m using vue-cli and simple-webpack boilerplate.

When I add vue-router links to my app component I get this error in console

Error in render function: “TypeError: Cannot read property ‘matched’ of undefined”

Here is my code:

App.vue

<template>
  <div>
    <h2>Links</h2>
    <ul>
      <router-link to='/'>Home</router-link>
      <router-link to='/query'>Query</router-link>

      <router-view></router-view>
    </ul>
  </div>
</template>

<script>
    export default {}
</script>

main.js

import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)
import routes from './routes.js'
import App from './App.vue'

const app = new Vue({
  el: '#app',
  routes,
  render: h => h(App)
})

routes.js

import VueRouter from 'vue-router';
let routes=[
  {
    path: '/',
    component: require('./Components/Home.vue')
  },
  {
    path: '/query',
    component: require('./Components/Query.vue')
  }
];

export default new VueRouter({routes});

Answer

The name when you add it to Vue must be router.

import router from './routes.js'

const app = new Vue({
  el: '#app',
  router,
  render: h => h(App)
})

If, for whatever reason, you want to call the variable routes you could assign it this way.

import routes from './routes.js'

const app = new Vue({
  el: '#app',
  router: routes,
  render: h => h(App)
})
Categories
discuss

window.history.pushState() data, how and when they are retrieved?

window.history.pushState([data], 'Title', '/url');

When I set up data in here, how can I use them and what kind of data this is meant for?

Answer

The data object is meant to store structured data of your choosing associated with the history item, so that when the state is revisited, the application has some data available associated with it. Maybe you can save the location of the page that the user was previously viewing, or some form options they had entered but never submitted.

Browsers will call the popstate() method when a back button is fired, which will pop the most recent state pushed to the stack. Developers should add an event listener to the window object for custom handling of the popstate event (such as using the data associated with the state).

// Below function will get fired for every app-wide popstate
window.addEventListener('popstate', function(event) {
  // Can access state data using event.state.data
});
Categories
discuss

How to use plugins like vue-resource when using Vue.js with Typescript?

I started using Typescript and trying to apply it to my project. However, I can’t get Vue.js plugins like vue-resource to work with it.

When I use

this.$http.post()

I get the error:

error TS2339: Property ‘$http’ does not exist on type ‘typeof Vue’.

which makes sense because I am in a class context. But how can I do that? This is my full component:

<template>
<div>
  <h1>Sign up</h1>

  <form>
    <div class="form-group">
      <label for="name">Name</label>
      <input v-model="name" type="text" class="form-control" name="name" placeholder="Name">
      <small class="form-text text-muted">Please provide a name.</small>
    </div>
    <div class="form-group">
      <label for="name">Password</label>
      <input v-model="password" type="password" class="form-control" name="password" placeholder="Password">
      <small class="form-text text-muted">Please provide a password.</small>
    </div>
    <input type="submit" class="btn btn-primary" value="Submit" @click.prevent="save">
  </form>
</div>
</template>

<script lang="ts">
import Component from 'vue-class-component'

@Component
export default class SignUp extends Vue {
  name: string = ''
  password: string = ''

  save(): void {
    this.$http.post('/api/sign-up', {
        name: this.name,
        password: this.password
      })
      .then((response: any) => {
        console.log(response)
      })
  }
}
</script>

And I register vue-resource in my main.ts like this:

import Vue from "vue"
import router from "./router"
import App from "./app"

const VueResource = require('vue-resource')

Vue.use(VueResource)

new Vue({
  el: "#app",
  router,
  template: "<App/>",
  components: { App },
});

Answer

Use import instead of require for VueResource too.

import VueResource from 'vue-resource'
Categories
discuss

Get only visible element using pure javascript

I have elements like below

<div class="one">send Message</div>

<div class="one">send Message</div>

<div class="one">send Message</div>

I have a web page where there is send Message buttons like above, in which only one button is visible at a time.Other two buttons are hidden via some javascript codes.So for example if 2nd button is visible , I should be able to get only that element.

So my code will be something like

document.querySelector(".one:visible");

In jquery the code is $(".one:visible"); , which works fine , But I need to know how to do this via pure javascript.

Answer

Here’s something you can use, pure Javascript:

// Get all elements on the page (change this to another DOM element if you want)
var all = document.getElementsByTagName("*");

for (var i = 0, max = all.length; i < max; i++) {
    if (isHidden(all[i]))
        // hidden
    else 
        // visible
}

function isHidden(el) {
    var style = window.getComputedStyle(el);
    return ((style.display === 'none') || (style.visibility === 'hidden'))
}
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..