<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Mr.47&#039;s blog</title>
	<atom:link href="http://www.mr47.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mr47.net</link>
	<description>Just another WordPress site</description>
	<lastBuildDate>Thu, 22 Dec 2011 04:37:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Dịch những bài training từ trang Android Developer</title>
		<link>http://www.mr47.net/chung/d%e1%bb%8bch-nh%e1%bb%afng-bai-training-t%e1%bb%ab-trang-android-developer/#utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=d%25e1%25bb%258bch-nh%25e1%25bb%25afng-bai-training-t%25e1%25bb%25ab-trang-android-developer</link>
		<comments>http://www.mr47.net/chung/d%e1%bb%8bch-nh%e1%bb%afng-bai-training-t%e1%bb%ab-trang-android-developer/#comments</comments>
		<pubDate>Thu, 22 Dec 2011 03:03:33 +0000</pubDate>
		<dc:creator>ngleanh</dc:creator>
				<category><![CDATA[Chung]]></category>

		<guid isPermaLink="false">http://www.mr47.net/?p=64</guid>
		<description><![CDATA[Theo tin từ slashgear.com và tinhte.vn, Google đã cho ra mắt Android Training, một chương trình training những kỹ năng lập trình cơ bản và nâng cao trong Android, để trang bị cho lập trình viên những kỹ năng tốt hơn khi lập trình phần mềm cho hệ điều hành này. Trích tinhte.vn: Android Training [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Theo tin từ <a href="http://www.slashgear.com/google-android-training-initiated-to-educate-the-masses-19203262/" target="_blank">slashgear.com</a> và <a href="http://www.tinhte.vn/f151/google-android-training-ho-tro-viet-ung-dung-cho-lap-trinh-vien-991186/" target="_blank">tinhte.vn</a>, Google đã cho ra mắt Android Training, một chương trình training những kỹ năng lập trình cơ bản và nâng cao trong Android, để trang bị cho lập trình viên những kỹ năng tốt hơn khi lập trình phần mềm cho hệ điều hành này.</strong></p>
<p><img onload="NcodeImageResizer.createOn(this);" alt="" src="https://developer.android.com/images/training/training-prof.png" title="Orientation to Android Training" class="aligncenter" width="400" height="278" /></p>
<p>Trích tinhte.vn:</p>
<blockquote><p>Android Training sẽ bao gồm nhiều bài giảng, được thiết kế từ cơ bản đến nâng cao. Trong những bài nhập môn, người dùng mới làm quen với Android sẽ được hướng dẫn cụ thể để hiểu Android là gì, và những bước đầu tiên để họ đi vào thế giới lập trình ứng dụng. Sau khi đã nắm được kiến thức cơ bản, người học có thể lựa chọn đi sâu vào nhiều lĩnh vực như tối ưu hóa thời lượng pin, ứng dụng nghe nhạc hoặc tìm đường. Google cho biết trong thời gian tới, Android Training sẽ được bổ sung thêm những bài giảng mới, tiếp cận và giải quyết nhiều vấn đề mà lập trình viên có thể gặp phải trong quá trình phát triển phần mềm.</p></blockquote>
<p>Xem sơ qua, tôi thấy những bài này viết này rất hay và là nguồn tư liệu quý để học lập trình Android. Từ post sau, tôi quyết định sẽ lượt dịch những bài này, kèm theo link bài gốc bằng tiếng Anh để dễ hình dung.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mr47.net/chung/d%e1%bb%8bch-nh%e1%bb%afng-bai-training-t%e1%bb%ab-trang-android-developer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Lập trình với cảm biến xoay màn hình</title>
		<link>http://www.mr47.net/coding/android/lap-trinh-voi-cam-bien-xoay-man-hin/#utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=lap-trinh-voi-cam-bien-xoay-man-hin</link>
		<comments>http://www.mr47.net/coding/android/lap-trinh-voi-cam-bien-xoay-man-hin/#comments</comments>
		<pubDate>Fri, 02 Dec 2011 03:21:54 +0000</pubDate>
		<dc:creator>ngleanh</dc:creator>
				<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://www.mr47.net/?p=60</guid>
		<description><![CDATA[Điện thoại Android thường có tích hợp cảm biến xoay màn hình (orientation sensor), dùng để phát hiện việc xoay màn hình trong không gian. Cảm biến xoay màn hình phát hiện việc xoay theo 3 giá trị: Azimtuh in degres: góc giữa trục X của điện thoại và hướng bắc (0 ≤ azimuth ≤ [...]]]></description>
			<content:encoded><![CDATA[<p>Điện thoại Android thường có tích hợp cảm biến xoay màn hình (orientation sensor), dùng để phát hiện việc xoay màn hình trong không gian. Cảm biến xoay màn hình phát hiện việc xoay theo 3 giá trị:</p>
<ul>
<li>Azimtuh in degres: góc giữa trục X của điện thoại và hướng bắc (0 ≤ azimuth ≤ 360)</li>
<li>Pitch in degres: góc giữa trục Y của điện thoại và đường nằm ngang (-180 ≤ pitch ≤ 180)</li>
<li>Roll in degres: góc giữa trục X của điện thoại và đường nằm ngang (-90 ≤ roll ≤ 90)</li>
</ul>
<p>Trong bài này, tôi sẽ trình diễn cách mà cảm biến xoay màn hình trong trong chương trình bắt sự kiện. Chúng ta sẽ dùng những sự kiện này để tạo một listener xử lý khi sự kiện này xảy ra:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">net.androgames.blog.sample.orientation</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> OrientationListener <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onOrientationChanged<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">float</span> azimuth, 
            <span style="color: #000066; font-weight: bold;">float</span> pitch, <span style="color: #000066; font-weight: bold;">float</span> roll<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * Top side of the phone is up
     * The phone is standing on its bottom side
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onTopUp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * Bottom side of the phone is up
     * The phone is standing on its top side
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onBottomUp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * Right side of the phone is up
     * The phone is standing on its left side
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onRightUp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * Left side of the phone is up
     * The phone is standing on its right side
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onLeftUp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Một instance của SensorManager để nhận thông tin từ những cảm biến có trong điện thoại. Không cần yêu cầu thêm permisson gì khi truy cập tới những thông tin cảm biến của điện thoại. Để nhận danh sách những cảm biến xoay màn hình có trong điện thoại, hãy dùng giá trị Sensor.TYPE_ORIENTATION. Nếu có ít nhất 1 cảm biến, ta có thể đăng ký một SensorEventListener. Tỉ lệ trả về của cảm biến xoay có thể được chỉ định và phải là một trong số sau đây:</p>
<ul>
<li>SensorManager.SENSOR_DELAY_FASTEST: nhanh nhất có thể</li>
<li>SensorManager.SENSOR_DELAY_GAME: tỉ lệ thích hợp cho game</li>
<li>SensorManager.SENSOR_DELAY_NORMAL: tỉ lệ thường dùng</li>
<li>SensorManager.SENSOR_DELAY_UI: tỉ lệ thích hợp cho UI Thread</li>
</ul>
<p>Đây là code chỉnh sửa orientation manager:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">net.androgames.blog.sample.orientation</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.content.Context</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.hardware.Sensor</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.hardware.SensorEvent</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.hardware.SensorEventListener</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.hardware.SensorManager</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * Android Orientation Sensor Manager Archetype
 * @author antoine vianey
 * under GPL v3 : http://www.gnu.org/licenses/gpl-3.0.html
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> OrientationManager <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> Sensor sensor<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> SensorManager sensorManager<span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// you could use an OrientationListener array instead</span>
    <span style="color: #666666; font-style: italic;">// if you plans to use more than one listener</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> OrientationListener listener<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/** indicates whether or not Orientation Sensor is supported */</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">Boolean</span> supported<span style="color: #339933;">;</span>
    <span style="color: #008000; font-style: italic; font-weight: bold;">/** indicates whether or not Orientation Sensor is running */</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">boolean</span> running <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/** Sides of the phone */</span>
    <span style="color: #000000; font-weight: bold;">enum</span> Side <span style="color: #009900;">&#123;</span>
        TOP,
        BOTTOM,
        LEFT,
        RIGHT<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * Returns true if the manager is listening to orientation changes
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">boolean</span> isListening<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> running<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * Unregisters listeners
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> stopListening<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        running <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>sensorManager <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">&amp;&amp;</span> sensorEventListener <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                sensorManager.<span style="color: #006633;">unregisterListener</span><span style="color: #009900;">&#40;</span>sensorEventListener<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * Returns true if at least one Orientation sensor is available
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">boolean</span> isSupported<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>supported <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>Orientation.<span style="color: #006633;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                sensorManager <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>SensorManager<span style="color: #009900;">&#41;</span> Orientation.<span style="color: #006633;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
                        .<span style="color: #006633;">getSystemService</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Context</span>.<span style="color: #006633;">SENSOR_SERVICE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                List<span style="color: #339933;">&lt;</span>Sensor<span style="color: #339933;">&gt;</span> sensors <span style="color: #339933;">=</span> sensorManager.<span style="color: #006633;">getSensorList</span><span style="color: #009900;">&#40;</span>
                        Sensor.<span style="color: #006633;">TYPE_ORIENTATION</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                supported <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Boolean</span><span style="color: #009900;">&#40;</span>sensors.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
                supported <span style="color: #339933;">=</span> <span style="color: #003399;">Boolean</span>.<span style="color: #000066; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">return</span> supported<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * Registers a listener and start listening
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> startListening<span style="color: #009900;">&#40;</span>
            OrientationListener orientationListener<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        sensorManager <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>SensorManager<span style="color: #009900;">&#41;</span> Orientation.<span style="color: #006633;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
                .<span style="color: #006633;">getSystemService</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Context</span>.<span style="color: #006633;">SENSOR_SERVICE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        List<span style="color: #339933;">&lt;</span>Sensor<span style="color: #339933;">&gt;</span> sensors <span style="color: #339933;">=</span> sensorManager.<span style="color: #006633;">getSensorList</span><span style="color: #009900;">&#40;</span>
                Sensor.<span style="color: #006633;">TYPE_ORIENTATION</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>sensors.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            sensor <span style="color: #339933;">=</span> sensors.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            running <span style="color: #339933;">=</span> sensorManager.<span style="color: #006633;">registerListener</span><span style="color: #009900;">&#40;</span>
                    sensorEventListener, sensor, 
                    SensorManager.<span style="color: #006633;">SENSOR_DELAY_NORMAL</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            listener <span style="color: #339933;">=</span> orientationListener<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * The listener that listen to events from the orientation listener
     */</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> SensorEventListener sensorEventListener <span style="color: #339933;">=</span> 
        <span style="color: #000000; font-weight: bold;">new</span> SensorEventListener<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #008000; font-style: italic; font-weight: bold;">/** The side that is currently up */</span>
        <span style="color: #000000; font-weight: bold;">private</span> Side currentSide <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">private</span> Side oldSide <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">float</span> azimuth<span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">float</span> pitch<span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">float</span> roll<span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onAccuracyChanged<span style="color: #009900;">&#40;</span>Sensor sensor, <span style="color: #000066; font-weight: bold;">int</span> accuracy<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onSensorChanged<span style="color: #009900;">&#40;</span>SensorEvent event<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
            azimuth <span style="color: #339933;">=</span> event.<span style="color: #006633;">values</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>     <span style="color: #666666; font-style: italic;">// azimuth</span>
            pitch <span style="color: #339933;">=</span> event.<span style="color: #006633;">values</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>     <span style="color: #666666; font-style: italic;">// pitch</span>
            roll <span style="color: #339933;">=</span> event.<span style="color: #006633;">values</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>        <span style="color: #666666; font-style: italic;">// roll</span>
&nbsp;
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>pitch <span style="color: #339933;">&lt;</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">45</span> <span style="color: #339933;">&amp;&amp;</span> pitch <span style="color: #339933;">&gt;</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">135</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #666666; font-style: italic;">// top side up</span>
                currentSide <span style="color: #339933;">=</span> Side.<span style="color: #006633;">TOP</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>pitch <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">45</span> <span style="color: #339933;">&amp;&amp;</span> pitch <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">135</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #666666; font-style: italic;">// bottom side up</span>
                currentSide <span style="color: #339933;">=</span> Side.<span style="color: #006633;">BOTTOM</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>roll <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">45</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #666666; font-style: italic;">// right side up</span>
                currentSide <span style="color: #339933;">=</span> Side.<span style="color: #006633;">RIGHT</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>roll <span style="color: #339933;">&lt;</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">45</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #666666; font-style: italic;">// left side up</span>
                currentSide <span style="color: #339933;">=</span> Side.<span style="color: #006633;">LEFT</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>currentSide <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span>currentSide.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>oldSide<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">switch</span> <span style="color: #009900;">&#40;</span>currentSide<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #000000; font-weight: bold;">case</span> TOP <span style="color: #339933;">:</span> 
                        listener.<span style="color: #006633;">onTopUp</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
                    <span style="color: #000000; font-weight: bold;">case</span> BOTTOM <span style="color: #339933;">:</span> 
                        listener.<span style="color: #006633;">onBottomUp</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
                    <span style="color: #000000; font-weight: bold;">case</span> LEFT<span style="color: #339933;">:</span> 
                        listener.<span style="color: #006633;">onLeftUp</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
                    <span style="color: #000000; font-weight: bold;">case</span> RIGHT<span style="color: #339933;">:</span> 
                        listener.<span style="color: #006633;">onRightUp</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
                oldSide <span style="color: #339933;">=</span> currentSide<span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">// forwards orientation to the OrientationListener</span>
            listener.<span style="color: #006633;">onOrientationChanged</span><span style="color: #009900;">&#40;</span>azimuth, pitch, roll<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>OrientationManager trên có thể được dùng trong bất kỳ Activity hoặc Service nào:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">net.androgames.blog.sample.orientation</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.app.Activity</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.content.Context</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.os.Bundle</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.widget.TextView</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.widget.Toast</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * Android orientation sensor tutorial
 * @author antoine vianey
 * under GPL v3 : http://www.gnu.org/licenses/gpl-3.0.html
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Orientation <span style="color: #000000; font-weight: bold;">extends</span> Activity <span style="color: #000000; font-weight: bold;">implements</span> OrientationListener <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">Context</span> CONTEXT<span style="color: #339933;">;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onCreate<span style="color: #009900;">&#40;</span>Bundle savedInstanceState<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">onCreate</span><span style="color: #009900;">&#40;</span>savedInstanceState<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        setContentView<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">layout</span>.<span style="color: #006633;">main</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        CONTEXT <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">this</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> onResume<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">onResume</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>OrientationManager.<span style="color: #006633;">isSupported</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            OrientationManager.<span style="color: #006633;">startListening</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> onDestroy<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">onDestroy</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>OrientationManager.<span style="color: #006633;">isListening</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            OrientationManager.<span style="color: #006633;">stopListening</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">Context</span> getContext<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> CONTEXT<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onOrientationChanged<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">float</span> azimuth, 
            <span style="color: #000066; font-weight: bold;">float</span> pitch, <span style="color: #000066; font-weight: bold;">float</span> roll<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>TextView<span style="color: #009900;">&#41;</span> findViewById<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">azimuth</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span>
                <span style="color: #003399;">String</span>.<span style="color: #006633;">valueOf</span><span style="color: #009900;">&#40;</span>azimuth<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>TextView<span style="color: #009900;">&#41;</span> findViewById<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">pitch</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span>
                <span style="color: #003399;">String</span>.<span style="color: #006633;">valueOf</span><span style="color: #009900;">&#40;</span>pitch<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>TextView<span style="color: #009900;">&#41;</span> findViewById<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">roll</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span>
                <span style="color: #003399;">String</span>.<span style="color: #006633;">valueOf</span><span style="color: #009900;">&#40;</span>roll<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onBottomUp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        Toast.<span style="color: #006633;">makeText</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>, <span style="color: #0000ff;">&quot;Bottom UP&quot;</span>, <span style="color: #cc66cc;">1000</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onLeftUp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        Toast.<span style="color: #006633;">makeText</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>, <span style="color: #0000ff;">&quot;Left UP&quot;</span>, <span style="color: #cc66cc;">1000</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onRightUp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        Toast.<span style="color: #006633;">makeText</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>, <span style="color: #0000ff;">&quot;Right UP&quot;</span>, <span style="color: #cc66cc;">1000</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onTopUp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        Toast.<span style="color: #006633;">makeText</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>, <span style="color: #0000ff;">&quot;Top UP&quot;</span>, <span style="color: #cc66cc;">1000</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Cách thường được dùng là đăng ký listener trong phương thức onResume() của Activity, và xóa trong phương thức onFinish().<br />
Theo <a href="http://blog.androgames.net/135/android-orientation-tutorial/" target="_blank">Androgames blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mr47.net/coding/android/lap-trinh-voi-cam-bien-xoay-man-hin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sending and playing microphone audio over network</title>
		<link>http://www.mr47.net/coding/csharp/sending-and-playing-microphone-audio-over-network/#utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=sending-and-playing-microphone-audio-over-network</link>
		<comments>http://www.mr47.net/coding/csharp/sending-and-playing-microphone-audio-over-network/#comments</comments>
		<pubDate>Wed, 12 Oct 2011 07:15:47 +0000</pubDate>
		<dc:creator>ngleanh</dc:creator>
				<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://www.mr47.net/?p=44</guid>
		<description><![CDATA[Giới thiệu Ví dụ này sẽ chỉ cho bạn cách nhận tín hiệu từ microphone và truyền (stream) tới một máy khác qua giao thức UDP. Chương trình ví dụ có thể thực hiện như một chiếc điện thoại, nếu cả 2 máy đều có thể nghe và gởi tín hiệu microphone cho nhau. Ngoài [...]]]></description>
			<content:encoded><![CDATA[<p><img onload="NcodeImageResizer.createOn(this);" alt="" src="http://www.codeproject.com/KB/cs/Streaming_wave_audio/view.jpg" title="Wave demo" class="aligncenter" width="418" height="438" /><br />
<strong>Giới thiệu</strong><br />
Ví dụ này sẽ chỉ cho bạn cách nhận tín hiệu từ microphone và truyền (stream) tới một máy khác qua giao thức UDP. Chương trình ví dụ có thể thực hiện như một chiếc điện thoại, nếu cả 2 máy đều có thể nghe và gởi tín hiệu microphone cho nhau. Ngoài ra cũng cần một project tương tự để chứa UDP server mà chúng ta cần để gởi nhậu audio và nén lại với codec g711. Chỉ dùng giao thức UDP thì không phải là cách tốt nhất để truyền dữ liệu dạng audio, RTP là cách tốt hơn. RTP thêm QoS vào việc truyền tải audio, nên bạn có thể biết được bao nhiêu gói (packets) bị mất và có thể sắp xếp lại những gói đó. Tôi sẽ thử thêm một ví dụ về giao thức RTP lúc khác.<br />
The package contains:
<ul>
<li>LumiSoft.Media &#8211; Audio related API (được dùng trong ví dụ)</li>
<li>LumiSoft.Net &#8211; UDP server, G711 codec</li>
<li>Ví dụ mẫu</li>
</ul>
<p><strong>Code</strong><br />
1. <em>WaveIn</em> là lớp cung cấp cách đơn giản để nhận tín hiệu từ microphone.<br />
Tất cả việc bạn phải làm là:<br />
<em>WavIn.Devices</em> trả về tất cả các thiết bị sẵn sàng mà chúng ta có thể nhận dữ liệu.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">/// Application main class.</span>
&nbsp;
<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> Test
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">private</span> WavIn m_pSoundReceiver <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">/// Default constructor.</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> Test<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">// G711 needs 8KHZ 16 bit 1 channel audio, </span>
&nbsp;
        <span style="color: #008080; font-style: italic;">// 400kb buffer gives us 25ms audio frame.</span>
&nbsp;
        m_pSoundReceiver <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> WavIn<span style="color: #008000;">&#40;</span>WavIn<span style="color: #008000;">.</span><span style="color: #0000FF;">Devices</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span>,<span style="color: #FF0000;">8000</span>,<span style="color: #FF0000;">16</span>,<span style="color: #FF0000;">1</span>,<span style="color: #FF0000;">400</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        m_pSoundReceiver<span style="color: #008000;">.</span><span style="color: #0000FF;">BufferFull</span> <span style="color: #008000;">+=</span> <span style="color: #008000;">new</span> BufferFullHandler 
                                         <span style="color: #008000;">&#40;</span>m_pSoundReceiver_BufferFull<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        m_pSoundReceiver<span style="color: #008000;">.</span><span style="color: #0000FF;">Start</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">/// This method is called when recording buffer is full </span>
&nbsp;
    <span style="color: #008080; font-style: italic;">/// and we need to process it.</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;buffer&quot;&gt;Recorded data.&lt;/param&gt;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> m_pSoundReceiver_BufferFull<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> buffer<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">// Just store audio data or stream it over the network ... </span>
&nbsp;
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p><em>WaveOut</em> &#8211;  lớp cung cấp các method cho việc stream audio.<br />
Bạn chỉ cần làm 1 việc đó là gọi method <em>waveoutInstance.Play</em><br />
Lưu ý: Chất lượng âm thanh phụ thuộc vào độ trễ của mạng (network delay).</p>
<p>Theo <a href="http://www.codeproject.com/KB/cs/Streaming_wave_audio.aspx">codeproject.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mr47.net/coding/csharp/sending-and-playing-microphone-audio-over-network/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ubuntu 11.10 sẽ chính thức được phát hành vào thứ 5 (13/10/2011)</title>
		<link>http://www.mr47.net/linux/ubuntu-11-10-s%e1%ba%bd-chinh-th%e1%bb%a9c-d%c6%b0%e1%bb%a3c-phat-hanh-vao-th%e1%bb%a9-5/#utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=ubuntu-11-10-s%25e1%25ba%25bd-chinh-th%25e1%25bb%25a9c-d%25c6%25b0%25e1%25bb%25a3c-phat-hanh-vao-th%25e1%25bb%25a9-5</link>
		<comments>http://www.mr47.net/linux/ubuntu-11-10-s%e1%ba%bd-chinh-th%e1%bb%a9c-d%c6%b0%e1%bb%a3c-phat-hanh-vao-th%e1%bb%a9-5/#comments</comments>
		<pubDate>Tue, 11 Oct 2011 16:53:06 +0000</pubDate>
		<dc:creator>ngleanh</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.mr47.net/?p=40</guid>
		<description><![CDATA[Đúng chu kì 6 tháng 1 lần, sau phiên bản Ubuntu 11.04 (Natty Narwhal) ra mắt hồi tháng 4 thì vào ngày thứ 5 (13/10) tới, Canonical sẽ phát hành phiên bản ổn định tiếp theo của bản phân phối Linux Ubuntu: 11.10 với tên mã Oneiric Ocelot (mèo rừng). Ubuntu 11.10 hứa hẹn sẽ [...]]]></description>
			<content:encoded><![CDATA[<p></p>
<p><strong>Đúng chu kì 6 tháng 1 lần, sau phiên bản Ubuntu 11.04 (Natty Narwhal) ra mắt hồi tháng 4 thì vào ngày thứ 5 (13/10) tới, Canonical sẽ phát hành phiên bản ổn định tiếp theo của bản phân phối Linux Ubuntu: 11.10 với tên mã Oneiric Ocelot (mèo rừng). Ubuntu 11.10 hứa hẹn sẽ là một bản nâng cấp đáng giá dành cho người dùng Ubuntu nói riêng và Linux nói chung.</strong></p>
<p>Bên cạnh việc tối ưu dịch vụ lưu trữ đám mây nền tảng chéo UbuntuOne, Ubuntu 11.10 sẽ nâng cao chất lượng của kho phần mềm Ubuntu Software Center. Giao diện và cách sử dụng của Software Center được cải tiến nhằm tạo tính nhất quán với thiết kế chung của Ubuntu. Bên cạnh đó, kho cũng được bổ sung thêm nhiều ứng dụng đa dạng và bao gồm cả các ứng dụng thương mại. Cách bài trí danh mục ứng dụng cũng được thay đổi để giúp người dùng dễ dàng tìm kiếm và cài đặt ứng dụng.</p>
<p>Đồng thời, Canonical sẽ khai trương trang developer.ubuntu.com để chào đón lập trình viên. Trang web sẽ giải thích cách phát triển và đệ trình ứng dụng lên Software Center. Công ty cũng cho biết sẽ tăng 5 lần số lượng ứng dụng đệ trình lên Software Center trong mỗi 3 tuần kể từ khi cổng thông tin cho lập trình viên được công bố chính thức.</p>
<p>Việc thúc đẩy nền tảng phát triển và nâng cấp kho ứng dụng Software Center sẽ cải thiện chất lượng của ứng dụng cho người dùng cuối. Không chỉ người dùng, Ubuntu cũng quan tâm đến lợi ích của lập trình viên và tạo cơ hội cho giới phát triển thu lợi nhuận từ dịch vụ Ubuntu Pay. Tuy nhiên, đã là một nền tảng nguồn mở thì liệu có người dùng nào sẵn sàng trả tiền cho các ứng dụng? Câu hỏi này đến nay vẫn chưa có câu trả lời xác đáng.</p>
<p>Đối với phiên bản Ubuntu 11.04, hệ thống được trang bị giao diện Unity kèm theo một số tính năng mới. Đây được xem là một nổ lực của Canonical nhằm làm mới giao diện Ubuntu trên các máy tính hiện đại và nâng cao trải nghiệm sử dụng cho các máy tính có màn hình cảm ứng như máy tính bảng hay hybrid PC và tablet. Trên phiên bản mới 11.10, giao diện của Ubuntu một lần nữa được &#8220;tinh chế&#8221; nhưng vẫn chưa rõ liệu Unity còn hiện hữu hay không.</p>
<p>Khi được hỏi về sự chuyển đổi đột ngột từ giao diện truyền thống GNOME sang Unity Dash, giám đốc truyền thông của Canonical &#8211; Gerry Carr cho biết ông đồng ý rằng đây là một bước chuyển có phần đột ngột bởi nó phá vỡ thói quen và cảm nhận của người dùng đối với Ubuntu. Tuy nhiên, cách mà chúng ta sử dụng máy tính đang thay đổi và giao diện cần phải thích ứng theo. Ngày nay, hầu hết công việc của chúng ta trên máy tính đều truy cập vào các tài nguyên Internet. Vì vậy, giao diện cần phải đơn giản hóa các thao tác.</p>
<p>Với giao diện Unity Dash, dữ liệu nội tại trên máy tính và trực tuyến sẽ được tích hợp làm một. Người dùng có thể dễ dàng nhận ra sự cải tiến này với tính năng tìm kiếm trong Dash Menu. Khác với các phiên bản trước, kể từ Ubuntu 11.04, menu không đơn thuần là cây thư mục với các ứng dụng được phân chia và gom nhóm. Thay vào đó, Dash menu bao gồm một khung tìm kiếm lớn và khi tìm một ứng dụng, &#8220;hàng loạt thấu kính&#8221; sẽ tìm các ứng dụng đã cài đặt đồng thời đưa ra gợi ý cho các ứng dụng tương tự trên Software Center, Carr cho biết. Với việc tích hợp tính năng tìm kiếm trực tiếp vào Dash, Ubuntu mang lại một giao diện đơn giản giúp giảm bớt các thao tác phiên toái về trải nghiệm người dùng.</p>
<p>Canonical còn cải tiến tính năng của các &#8220;thấu kính&#8221; để trải nghiệm sử dụng Ubuntu trở nên tốt hơn. Không chỉ ứng dụng, các thấu kính còn cho phép người dùng tìm kiếm các bài hát trên máy và trên kho Ubuntu Music Store. Tất cả dữ liệu tìm kiếm dù là ứng dụng, tập tin hay nội dung số, hệ thống đều hỗ trợ các bộ lọc phù hợp. Khi tìm kiếm một tập tin, bạn có thể lọc bằng dạng file, kích thước hoặc thời điểm sửa đổi (modified date). Khi tìm kiếm nội dung số, bạn có thể lọc theo thể loại và thời điểm của album. Khi tìm kiếm ứng dụng, bạn có thể lọc theo danh mục hoặc đánh giá (rating) của người dùng.</p>
<p>Một tính năng đáng giá trên bản nâng cấp Ubuntu 11.10 là Dej Dup &#8211; một ứng dụng sao lưu phục hồi hoạt động tương tự Apple Time Machine. Các tập tin sao lưu có thể được lưu trữ trên ổ cứng, USB hoặc trên dịch vụ lưu trữ đám mây UbuntuOne. Với các tập tin sao lưu trên UbuntuOne, bạn có thể phục hồi hệ thống của mình trên nhiều phần cứng khác nhau (trên nhiều máy tính khác nhau).</p>
<p>Thêm vào đó, bên cạnh việc chọn trình duyệt Mozilla Firefox làm trình duyệt mặc định thì trên phiên bản Ubuntu 11.10, Canonical đã loại bỏ email client Evolution và chọn Mozilla Thunderbird làm trình duyệt mail mặc định. Evolution là một email client lâu đời trên Ubuntu và nhiều người dùng than phiên rằng Evolution có các bước thiết lập khá phức tạp. Vì vậy, Thunderbird là một sự lựa chọn đáng giá bởi mọi thao tác thiết lập trở nên dễ dàng hơn. Người dùng không phải ghi nhớ các cổng gởi/nhận mail hay các thông số liên quan bởi mọi thứ đã được tự động hóa trên Thunderbird.</p>
<p>Phải đến thứ 5 tuần này thì phiên bản Ubuntu 11.10 mới chính thức xuất hiện trên trang download của Ubuntu. Tuy nhiên, nếu đang sử dụng Ubuntu 11.04 và muốn trải nghiệm trước thì bạn có thể tham khảo tiến trình nâng cấp tại đây. Thông tin thêm về Ubuntu 11.10 (Oneiric Ocelot) tham khảo thêm tại đây.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mr47.net/linux/ubuntu-11-10-s%e1%ba%bd-chinh-th%e1%bb%a9c-d%c6%b0%e1%bb%a3c-phat-hanh-vao-th%e1%bb%a9-5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sử dụng SystemParametersInfo để thay đổi thiết lập giao diện</title>
		<link>http://www.mr47.net/coding/csharp/s%e1%bb%ad-d%e1%bb%a5ng-systemparametersinfo-d%e1%bb%83-thay-d%e1%bb%95i-thi%e1%ba%bft-l%e1%ba%adp-giao-di%e1%bb%87n/#utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=s%25e1%25bb%25ad-d%25e1%25bb%25a5ng-systemparametersinfo-d%25e1%25bb%2583-thay-d%25e1%25bb%2595i-thi%25e1%25ba%25bft-l%25e1%25ba%25adp-giao-di%25e1%25bb%2587n</link>
		<comments>http://www.mr47.net/coding/csharp/s%e1%bb%ad-d%e1%bb%a5ng-systemparametersinfo-d%e1%bb%83-thay-d%e1%bb%95i-thi%e1%ba%bft-l%e1%ba%adp-giao-di%e1%bb%87n/#comments</comments>
		<pubDate>Tue, 11 Oct 2011 16:29:11 +0000</pubDate>
		<dc:creator>ngleanh</dc:creator>
				<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://www.mr47.net/?p=36</guid>
		<description><![CDATA[Hàm SystemParametersInfo cho phép bạn truy cập và thay đổi hầu hết các thiết lập giao diện người sử dụng ở mức thấp (màn hình Display Properties của Windows). Bạn có thể đọc chi tiết trên MSDN, ở đây tôi chỉ đưa một số ví dụ cơ bản: SPI_GETICONTITLELOGFONT giúp bạn lấy thông tin font [...]]]></description>
			<content:encoded><![CDATA[<p>Hàm SystemParametersInfo cho phép bạn truy cập và thay đổi hầu hết các thiết lập giao diện người sử dụng ở mức thấp (màn hình Display Properties của Windows).<br />
Bạn có thể đọc chi tiết trên MSDN, ở đây tôi chỉ đưa một số ví dụ cơ bản:
<ul>
<li>SPI_GETICONTITLELOGFONT giúp bạn lấy thông tin font chữ được sử dụng cho các nhãn icon; SPI_SETICONTITLELOGFONT giúp bạn thay đổi thông tin này.</li>
<li>SPI_GETNONCLIENTMETRICS giúp bạn lấy thông tin về font chữ được sử dụng trong các màn hình của Window bao gồm captions, menus, status bars, và message boxes; SPI_SETNONCLIENTMETRICS giúp bạn thay đổi chúng.</li>
</ul>
<p>Và một số thiết lập trong Control Panel như:
<ul>
<li>SPI_SETKEYBOARDDELAY và SPI_SETKEYBOARDSPEED giúp bạn thiết lập các tham số của keyboard.</li>
<li>SPI_SETDOUBLECLICKTIME giúp bạn thiết lập tốc độ double-click của con chuột.</li>
<li>SPI_SETMENUFADE giúp bạn thiết lập hoặc vô hiệu hóa menu fade animation.</li>
</ul>
<p>Sau đây, tôi sẽ viết một đoạn chương trình demo để thay đổi thiết lập font chữ của MessageBox trên Windows.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> WindowsUISettings
<span style="color: #008000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">// Khai báo sử dụng API SystemParametersInfo</span>
    <span style="color: #008000;">&#91;</span>DllImport<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;user32.dll&quot;</span>, CharSet <span style="color: #008000;">=</span> CharSet<span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Auto</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
    <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">extern</span> <span style="color: #6666cc; font-weight: bold;">bool</span> SystemParametersInfo<span style="color: #008000;">&#40;</span>
        <span style="color: #6666cc; font-weight: bold;">int</span> Action, <span style="color: #6666cc; font-weight: bold;">int</span> uiParam, <span style="color: #008000;">&#91;</span><span style="color: #0600FF; font-weight: bold;">In</span>, <span style="color: #0600FF; font-weight: bold;">Out</span><span style="color: #008000;">&#93;</span> NONCLIENTMETRICS pvParam, <span style="color: #6666cc; font-weight: bold;">int</span> WinIni<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008000;">&#91;</span>StructLayout<span style="color: #008000;">&#40;</span>LayoutKind<span style="color: #008000;">.</span><span style="color: #0000FF;">Sequential</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
    <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">class</span> NONCLIENTMETRICS
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> cbSize <span style="color: #008000;">=</span> Marshal<span style="color: #008000;">.</span><span style="color: #008000;">SizeOf</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>NONCLIENTMETRICS<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> iBorderWidth<span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> iScrollWidth<span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> iScrollHeight<span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> iCaptionWidth<span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> iCaptionHeight<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#91;</span>MarshalAs<span style="color: #008000;">&#40;</span>UnmanagedType<span style="color: #008000;">.</span><span style="color: #6666cc; font-weight: bold;">Struct</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> LOGFONT lfCaptionFont<span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> iSmCaptionWidth<span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> iSmCaptionHeight<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#91;</span>MarshalAs<span style="color: #008000;">&#40;</span>UnmanagedType<span style="color: #008000;">.</span><span style="color: #6666cc; font-weight: bold;">Struct</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> LOGFONT lfSmCaptionFont<span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> iMenuWidth<span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> iMenuHeight<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#91;</span>MarshalAs<span style="color: #008000;">&#40;</span>UnmanagedType<span style="color: #008000;">.</span><span style="color: #6666cc; font-weight: bold;">Struct</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> LOGFONT lfMenuFont<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#91;</span>MarshalAs<span style="color: #008000;">&#40;</span>UnmanagedType<span style="color: #008000;">.</span><span style="color: #6666cc; font-weight: bold;">Struct</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> LOGFONT lfStatusFont<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#91;</span>MarshalAs<span style="color: #008000;">&#40;</span>UnmanagedType<span style="color: #008000;">.</span><span style="color: #6666cc; font-weight: bold;">Struct</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> LOGFONT lfMessageFont<span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">const</span> <span style="color: #6666cc; font-weight: bold;">int</span> LF_FACESIZE <span style="color: #008000;">=</span> <span style="color: #FF0000;">32</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">// A &quot;logical font&quot; used by old-school windows</span>
    <span style="color: #008000;">&#91;</span>StructLayout<span style="color: #008000;">&#40;</span>LayoutKind<span style="color: #008000;">.</span><span style="color: #0000FF;">Sequential</span>, CharSet <span style="color: #008000;">=</span> CharSet<span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Auto</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
    <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">class</span> LOGFONT
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> lfHeight<span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> lfWidth<span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> lfEscapement<span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> lfOrientation<span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> lfWeight<span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">byte</span> lfItalic<span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">byte</span> lfUnderline<span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">byte</span> lfStrikeOut<span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">byte</span> lfCharSet<span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">byte</span> lfOutPrecision<span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">byte</span> lfClipPrecision<span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">byte</span> lfQuality<span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">byte</span> lfPitchAndFamily<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008000;">&#91;</span>MarshalAs<span style="color: #008000;">&#40;</span>UnmanagedType<span style="color: #008000;">.</span><span style="color: #0000FF;">ByValTStr</span>, SizeConst <span style="color: #008000;">=</span> LF_FACESIZE<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> lfFaceName<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">// to shut it up about the warnings</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> LOGFONT<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> lfFaceName<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">lfFaceName</span> <span style="color: #008000;">=</span> lfFaceName<span style="color: #008000;">;</span>
            lfHeight <span style="color: #008000;">=</span> lfWidth <span style="color: #008000;">=</span> lfEscapement <span style="color: #008000;">=</span> lfOrientation <span style="color: #008000;">=</span> lfWeight <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
            lfItalic <span style="color: #008000;">=</span> lfUnderline <span style="color: #008000;">=</span> lfStrikeOut <span style="color: #008000;">=</span> lfCharSet <span style="color: #008000;">=</span> lfOutPrecision
            <span style="color: #008000;">=</span> lfClipPrecision <span style="color: #008000;">=</span> lfQuality <span style="color: #008000;">=</span> lfPitchAndFamily <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">//Khai báo SPI lấy và thay đổi thiết lập về</span>
    <span style="color: #008080; font-style: italic;">//caption, menu, status bar, scroll bar và message box</span>
    <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">const</span> <span style="color: #6666cc; font-weight: bold;">int</span> SPI_GETNONCLIENTMETRICS <span style="color: #008000;">=</span> 0x0029<span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">const</span> <span style="color: #6666cc; font-weight: bold;">int</span> SPI_SETNONCLIENTMETRICS <span style="color: #008000;">=</span> 0x002A<span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">private</span> NONCLIENTMETRICS currentMetrics<span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
    <span style="color: #008080; font-style: italic;">/// Lưu giữ lại các giá trị ngầm định</span>
    <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
    <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> NONCLIENTMETRICS defaultMetrics<span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">private</span> WindowsUISettings<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> WindowsUISettings CurrentMetrics<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">//Lưu giữ lại các giá trị ngầm định</span>
        defaultMetrics <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> NONCLIENTMETRICS<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        SystemParametersInfo<span style="color: #008000;">&#40;</span>SPI_GETNONCLIENTMETRICS, defaultMetrics<span style="color: #008000;">.</span><span style="color: #0000FF;">cbSize</span>, defaultMetrics, <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        NONCLIENTMETRICS pvParam <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> NONCLIENTMETRICS<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        SystemParametersInfo<span style="color: #008000;">&#40;</span>SPI_GETNONCLIENTMETRICS, pvParam<span style="color: #008000;">.</span><span style="color: #0000FF;">cbSize</span>, pvParam, <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        WindowsUISettings instance <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> WindowsUISettings<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        instance<span style="color: #008000;">.</span><span style="color: #0000FF;">currentMetrics</span> <span style="color: #008000;">=</span> pvParam<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">return</span> instance<span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
    <span style="color: #008080; font-style: italic;">/// Lấy/Thiết lập font chữ cho MessageBox</span>
    <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> Font MessageFont
    <span style="color: #008000;">&#123;</span>
        get
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">return</span> Font<span style="color: #008000;">.</span><span style="color: #0000FF;">FromLogFont</span><span style="color: #008000;">&#40;</span>currentMetrics<span style="color: #008000;">.</span><span style="color: #0000FF;">lfMessageFont</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
        set
        <span style="color: #008000;">&#123;</span>
            value<span style="color: #008000;">.</span><span style="color: #0000FF;">ToLogFont</span><span style="color: #008000;">&#40;</span>currentMetrics<span style="color: #008000;">.</span><span style="color: #0000FF;">lfMessageFont</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
    <span style="color: #008080; font-style: italic;">/// Thiết lập các thay đổi</span>
    <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> Apply<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        SystemParametersInfo<span style="color: #008000;">&#40;</span>SPI_SETNONCLIENTMETRICS, currentMetrics<span style="color: #008000;">.</span><span style="color: #0000FF;">cbSize</span>, currentMetrics, <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
    <span style="color: #008080; font-style: italic;">/// Đặt lại các giá trị ngầm định</span>
    <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> RestoreDefault<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        SystemParametersInfo<span style="color: #008000;">&#40;</span>SPI_SETNONCLIENTMETRICS, defaultMetrics<span style="color: #008000;">.</span><span style="color: #0000FF;">cbSize</span>, defaultMetrics, <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Và đây là ví dụ chạy thử:</p>
<p>Hãy tạo 1 form mới, trên đó có 2 button bao gồm, button1 và button2. Double-click vào button1 và sau đó button2, ví dụ xử lý sự kiện Click trên 2 button sẽ như sau:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">partial</span> <span style="color: #6666cc; font-weight: bold;">class</span> Form1 <span style="color: #008000;">:</span> Form
<span style="color: #008000;">&#123;</span>
    WindowsUISettings metrics
        <span style="color: #008000;">=</span> WindowsUISettings<span style="color: #008000;">.</span><span style="color: #0000FF;">CurrentMetrics</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> Form1<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        InitializeComponent<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> button1_Click<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, EventArgs e<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        Font messageFont <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Font<span style="color: #008000;">&#40;</span>
            metrics<span style="color: #008000;">.</span><span style="color: #0000FF;">MessageFont</span><span style="color: #008000;">.</span><span style="color: #0000FF;">FontFamily</span>, <span style="color: #FF0000;">14</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        metrics<span style="color: #008000;">.</span><span style="color: #0000FF;">MessageFont</span> <span style="color: #008000;">=</span> messageFont<span style="color: #008000;">;</span>
        metrics<span style="color: #008000;">.</span><span style="color: #0000FF;">Apply</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        MessageBox<span style="color: #008000;">.</span><span style="color: #0000FF;">Show</span><span style="color: #008000;">&#40;</span>
        <span style="color: #666666;">&quot;MessageBox đã được thay đổi font size thành 14.&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> button2_Click<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, EventArgs e<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        metrics<span style="color: #008000;">.</span><span style="color: #0000FF;">RestoreDefault</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        MessageBox<span style="color: #008000;">.</span><span style="color: #0000FF;">Show</span><span style="color: #008000;">&#40;</span>
        <span style="color: #666666;">&quot;MessageBox đã được trở về font size 8.&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Qua ví dụ này, chắc các bạn đã hiểu cách để lấy thông tin và thay đổi các thông số khác. </p>
<p>Theo <a href="http://thanhhh.blogspot.com/2009/07/su-dung-systemparametersinfo-e-thay-oi.html" title="http://thanhhh.blogspot.com/2009/07/su-dung-systemparametersinfo-e-thay-oi.html" target="_blank">Ho Hai Thanh&#8217;s blog</a> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.mr47.net/coding/csharp/s%e1%bb%ad-d%e1%bb%a5ng-systemparametersinfo-d%e1%bb%83-thay-d%e1%bb%95i-thi%e1%ba%bft-l%e1%ba%adp-giao-di%e1%bb%87n/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

