measure

What triggers a View's measure() to be called

心已入冬 提交于 2019-12-03 00:56:38
In my application I have an infinite loop on one of my View's onMeasure() overrides. Debugging the source code starting from a break point in my onMeasure, I am able to trace myself all the way up the stack trace up to the PhoneWindow$DecorView's measure() (top most class in my View Hierarchy), which gets called by ViewRoot.performTraversals(). Now from here if I keep stepping over, I eventually get the PhoneWindow$DecorView's measure() called again by a message in the Looper.loop() class. I'm guessing something has queued up a message that it needs to remeasure, like an invalidate. My

Measuring online time on website

女生的网名这么多〃 提交于 2019-12-02 12:45:22
问题 I would like to measure how much time a user spends on my website. It's needed for a community site where you can say: "User X has been spending 1397 minutes here." After reading some documents about this, I know that there is no perfect way to achieve this. You can't measure the exact time. But I'm looking for an approach which gives a good approximation. How could you do this? My ideas: 1) Adding 30 seconds to the online time counter on every page view. 2) On every page view, save the

addOnLayoutChangeListener vs addOnGlobalLayoutListener vs post(Runnable r)

会有一股神秘感。 提交于 2019-12-01 16:35:20
PROBLEM : Suppose we have simple case: we have view and we have to show some data on this view. We use static method showData(View view) to do this. I want to know the exact moment when view layout is measured and I can access getWidth() getHeight() and be sure that this is final width and height of my view. WHAT I KNOW : (not sure I am 100% right): I know 3 different approaches to do this view.addOnLayoutChangeListener - we know when layout is changed, we can get height and width view.getViewTreeObserver().addOnGlobalLayoutListener - for my case almost the same, but we get information later.

addOnLayoutChangeListener vs addOnGlobalLayoutListener vs post(Runnable r)

萝らか妹 提交于 2019-12-01 14:33:58
问题 PROBLEM : Suppose we have simple case: we have view and we have to show some data on this view. We use static method showData(View view) to do this. I want to know the exact moment when view layout is measured and I can access getWidth() getHeight() and be sure that this is final width and height of my view. WHAT I KNOW : (not sure I am 100% right): I know 3 different approaches to do this view.addOnLayoutChangeListener - we know when layout is changed, we can get height and width view

Find how much network traffic other Android apps generate

こ雲淡風輕ζ 提交于 2019-12-01 04:48:56
问题 I am trying to make a background service which should measure traffic usage of various applications so as to be able to show to the user which apps consume most data traffic. I found that Spare Parts app does exactly that, but after installing it on a 1.6 Dell Streak device I always get "No battery usage data available" for "Network usage". Does this function at all work in Spare Parts? Also, I couldn't find a working source code for Spare Parts. https://android.googlesource.com/platform

How do I measure the size of a TextBlock in WPF before it is rendered?

╄→гoц情女王★ 提交于 2019-12-01 02:45:09
I have a WPF DataTemplate with two TextBlock controls (stacked) and then some other elements underneath. Due to some complicated layout code, I need to know the height of the two TextBlock elements so that I can draw some fancy connector lines, and line up other controls, etc. If I know the text that's going into the TextBlocks, and I know the font, etc., is there some way I can compute or measure the height of these TextBlocks without actually rendering them? I think it should be sufficient to call the UIElement.Measure(Size) method and subsequently check the UIElement.DesiredSize property.

How to measure time taken between lines of code in python?

情到浓时终转凉″ 提交于 2019-11-30 10:36:59
问题 So in Java, we can do How to measure time taken by a function to execute But how is it done in python? To measure the time start and end time between lines of codes? Something that does this: import some_time_library starttime = some_time_library.some_module() code_tobe_measured() endtime = some_time_library.some_module() time_taken = endtime - starttime 回答1: If you want to measure CPU time, can use time.process_time() for Python 3.3 and above: import time start = time.process_time() # your

Measure time, milliseconds or microseconds for Windows C++ [duplicate]

隐身守侯 提交于 2019-11-30 09:30:32
This question already has an answer here: How to Calculate Execution Time of a Code Snippet in C++ 16 answers How do you measure the execution time in milliseconds or microseconds in Windows C++? I found many method one calling time(NULL), but it measures time in seconds only and the seconds clock() (clock_t) measure CPU time, not the actual time. I found the function gettimeofday(Calendar time) mentioned in this paper: dropbox.com/s/k0zv8pck7ydbakz/1_7-PDF_thesis_2.pdf This function is for Linux (compute time in milli and microseconds) and not Windows. I found an alternative to it for Windows

How to measure time taken between lines of code in python?

こ雲淡風輕ζ 提交于 2019-11-29 22:03:28
So in Java, we can do How to measure time taken by a function to execute But how is it done in python? To measure the time start and end time between lines of codes? Something that does this: import some_time_library starttime = some_time_library.some_module() code_tobe_measured() endtime = some_time_library.some_module() time_taken = endtime - starttime Yevgen Yampolskiy If you want to measure CPU time, can use time.process_time() for Python 3.3 and above: import time start = time.process_time() # your code here print(time.process_time() - start) First call turns the timer on, and second call

getMeasuredWidth returns totally wrong value

 ̄綄美尐妖づ 提交于 2019-11-29 20:58:40
I have to measure a View for spacing others. I use this code for that: ViewGroup view = ...; view.setPadding(10, 0, 10, 0); int wrapContent = RelativeLayout.LayoutParams.WRAP_CONTENT; int specWidth = MeasureSpec.makeMeasureSpec(wrapContent, MeasureSpec.AT_MOST); view.measure(specWidth, specWidth); int questionWidth = view.getMeasuredWidth(); This works as expected on an Android 4.3 emulator. However the returned measured width on a Samsung Galaxy XCover 2 (S7710) Android 4.1.2 phone, is 16777214 ... I tried everything, masking with View.MEASURED_SIZE_MASK , but nothing helped. Could you