Categories
discuss

Debugging Promise call stacks in vscode

Is there a way to get the call stack when debugging nodeJS Promises in vscode? I see that support for async call stacks is supported in this GitHub issue but it looks like it pertains to vanilla JS callbacks.

Right now when I’m paused on a breakpoint, the call stack is tiny, even though I know this function is being called from another (couple) of functions.

I’m running on node v6.9.x

debug break no stack

EDIT: adding the "protocol": "inspector" attribute to the launch.json config adds some more stackframes, but it’s not very helpful: debug break next tick

All of my functions are returning promises, and the function in the screenshot is being called as one of the functions in a Promise.all() call.

Answer

First of all, the callstack as shown is correct in the way that these are the functions that are actually on the stack. When a Promise gets created around an asynchronous callback, and .then handlers get attached, synchronous execution ends and the callstack gets unwrapped. When the callback calls back somewhen, it resolves the Promise and the .then handlers get executed. At that point the callstack only contains the function passed to .then.

Now in a lot of scenarios the Promise chain is flat, and goes the other way it was created:

function a() {
   return Promise.resolve(1).then(it => it + 1); // 1
}

function b() {
   return a().then(it => it + 1); // 2
}

At the point above when the first .then callback (1) executes, the only attached callback is (2), and as such he engine could generate an “async stacktrace”, showing at which functions the Promise chain continues.

Now for plain promises resolving these chains just to generate a stacktrace is a lot of overhead, however for async functions that await Promises it is pretty straightforward. Thus since NodeJS v12 (and in modern browsers) if you write the above like this instead:

async function a() {
  const result = (await 1);
  _log_stack();
  return result + 1;
}

async function b() {
  return (await a()) + 1;
}
     
b();
     
function _log_stack() { console.log((new Error()).stack); }

then your debugger will show a proper async stacktrace (which gets generated as described above). You can find a more in depth explanation here.

Categories
discuss

Does android have a numeric keypad that is arranged like a computer’s numpad?

I’m working on an android app and for some of my EditTexts I am currently using the input type “number” which displays a keypad with the arrangement that you typically see on phones with the “123” on the top row:

enter image description here

However, for reasons specific to the uses of this app, I would prefer a keypad with the style that you see on physical keyboards with the “123” on the bottom row:

enter image description here

Does android have a keypad that looks like what you see on physical keyboards or would I have to make a custom input method if I wanted to achieve this?

Answer

Unfortunately there is no built-in parameter that swap “123” and “789” rows, so you have to make your own keyboard layout and handle the input.

Categories
discuss

Can’t customize the appearance of EditText select handle / anchor on landscape

I am having a hard time customizing the EditText select handle. I am following this thread:

How to change color / appearance of EditText select handle / anchor?

It looks like pretty straight forward. Yet, I can’t get it to work on landscape. Can anyone spot what I am doing wrong? I pretty much pasted the same code on a test activity but the anchor handles’ are always the same. I tried using styles as suggested and programmatically. Still I always get the same default blue anchors 🙁

I am on Nougat not sure if makes any difference.

Test activity:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTheme(R.style.MyCustomTheme);
    setContentView(R.layout.activity_main);
    final EditText editText = (EditText) findViewById(R.id.edit1);
    // tried programatically too and no success
    try {
        final Field fEditor = TextView.class.getDeclaredField("mEditor");
        fEditor.setAccessible(true);
        final Object editor = fEditor.get(editText);
        final Field fSelectHandleLeft = editor.getClass().getDeclaredField("mSelectHandleLeft");
        final Field fSelectHandleRight =
                editor.getClass().getDeclaredField("mSelectHandleRight");
        final Field fSelectHandleCenter =
                editor.getClass().getDeclaredField("mSelectHandleCenter");
        fSelectHandleLeft.setAccessible(true);
        fSelectHandleRight.setAccessible(true);
        fSelectHandleCenter.setAccessible(true);
        fSelectHandleLeft.set(editor, ContextCompat.getDrawable(this, R.drawable.small_rect));
        fSelectHandleRight.set(editor, ContextCompat.getDrawable(this, R.drawable.small_rect));
        fSelectHandleCenter.set(editor, ContextCompat.getDrawable(this, R.drawable.small_rect));
    } catch (final Exception e) {
        Log.d("CUSTOM_ANCHORS", e.toString());
    }
}

Layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <EditText
        android:id="@+id/edit1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="Hello World"
        android:textSize="20sp" />

</LinearLayout>

My styles:

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>


<style name="MyCustomTheme" parent="@style/AppTheme">
    <item name="android:textSelectHandle">@drawable/small_rect</item>
    <item name="android:textSelectHandleLeft">@drawable/small_rect</item>
    <item name="android:textSelectHandleRight">@drawable/small_rect</item>
</style>

the drawable (small_rect.xml)

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <size
        android:width="20dp"
        android:height="20dp" />
    <gradient
        android:angle="90"
        android:centerColor="#D6D6D6"
        android:endColor="#4B6CD6"
        android:startColor="#6586F0" />
    <corners android:radius="0dp" />
</shape>

the result:

enter image description here

Answer

 <EditText
    android:imeOptions="flagNoFullscreen"
 />

You can use android:imeOptions to tell the system not to display editing UI in fullscreen. enter image description here

Categories
discuss

Android architecture components liveData and room – what is minimum requirements?

I realize its in alpha stage, however I’d like to know if the android architecture components like liveData and room have any minimum requirements ? such as min android api/sdk etc. I looked here
but its not showing me if there is any requirement. Can i assume i can use this right back to at least android ICS ?

Answer

Yes, you can assume that it goes back to ICS at least. Also starting support library version 26, minSdk becomes 14. So I assume new architecture libraries will be the same.

According to googlesamples, lowest API version is 14, which is Ice Cream Sandwich.

Here are the links to the gradle files for the minSdk 14 apps:

Github Browser Sample gradle file

Persistent Content Provider Sample

Categories
discuss

Ionic trigger modal open function with ion-searchbar focus – click not working

I have an ion-searchbar that, when clicked, opens a modal. However, currently the click process is actually taking two clicks, one to focus, one to open the modal. I have tried to add the click to the ion-toolbar it is contained in, and have tried to disable the ion-searchbar with [disabled]="true", but the disabled functionality isn’t available to the ion-searchbar. How can I trigger the new modal to open without having to double click, and in such a way that the focus doesn’t happen on the original searchbar?

HTML

<ion-header>
  <ion-toolbar >
    <ion-searchbar (click)="openSearchModal()"></ion-searchbar>
  </ion-toolbar>
</ion-header>

JS

  openSearchModal() {
    let myModal = this.modalCtrl.create(SearchmodalPage); 
    myModal.present(); 
  }

Answer

Like you are saying, ion-searchbar doesn’t have a disabled functionnality.

But you can create your own searchbar, that will use ionic classes to avoid recoding it and you will be able to disable it.

See my code here :

<ion-header>
   <ion-toolbar>
    <div class="searchbar searchbar-ios searchbar-left-aligned searchbar-active" (click)="openSearchModal()">
      <div class="searchbar-input-container">
        <div class="searchbar-search-icon"></div>
        <input class="searchbar-input" placeholder="Search" type="search" autocomplete="off" autocorrect="off" spellcheck="false" disabled="true">
      </div>
    </div>
  </ion-toolbar>
</ion-header>
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..