Archive

Archive for February, 2012

Free WallPaper

Categories: Picture

DateTime in Android

First create XML file named it datetimepicker.xml

<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android&#8221;
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:orientation=”vertical”
android:padding=”10px” >

<DatePicker
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_gravity=”center_horizontal” />

<TextView
android:id=”@+id/txtDateTime”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:textColor=”#00ff00″
android:textSize=”20dp” />

<Button
android:id=”@+id/btnDateTime”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:text=”Get change” />

</LinearLayout>

Create new activity named DateTimePicker.java add following code to DateTimePicker.java

package me.google.com;

import java.util.Calendar;

import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.DatePicker;
import android.widget.TextView;
import android.widget.Button;
import android.widget.Toast;

public class DateTimePicker extends Activity implements OnClickListener {
TextView txtDateTime;
Button btnDateTime;
private int mDay;
private int mMonth;
private int mYear;
static final int DATE_DIALOG_ID = 0;

@Override
public void onCreate(Bundle instance) {
super.onCreate(instance);
setContentView(R.layout.datetimepicker);
txtDateTime = (TextView) findViewById(R.id.txtDateTime);
btnDateTime = (Button) findViewById(R.id.btnDateTime);
Calendar c = Calendar.getInstance();
mDay = c.get(Calendar.DAY_OF_MONTH);
mMonth = c.get(Calendar.MONTH);
mYear = c.get(Calendar.YEAR);
String strDateTime = “Today is: ” + String.valueOf(mDay) + “/”
+ String.valueOf(mMonth) + “/” + String.valueOf(mYear);
txtDateTime.setText(strDateTime);
btnDateTime.setOnClickListener(this);
}

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
AlertDialog alert = new AlertDialog.Builder(this).create();
alert.setTitle(“Change Time”);
alert.setMessage(“Do you want to clear DateTime?”);
alert.setIcon(R.drawable.ic_launcher);
alert.setButton(“Yes”, new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
showDialog(DATE_DIALOG_ID);
}
});
alert.setButton2(“No”, new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Toast tNo = Toast.makeText(getApplicationContext(),
“You pressed \”No\” Button”, 20);
tNo.show();
}
});
alert.show();
}

@Override
protected Dialog onCreateDialog(int id) {
// TODO Auto-generated method stub
switch (id) {
case DATE_DIALOG_ID:
return new DatePickerDialog(this, datePickerListener, mYear,
mMonth, mDay);
}
return super.onCreateDialog(id);
}

private DatePickerDialog.OnDateSetListener datePickerListener = new DatePickerDialog.OnDateSetListener() {

// when dialog box is closed, below method will be called.
public void onDateSet(DatePicker view, int selectedYear,
int selectedMonth, int selectedDay) {
mYear = selectedYear;
mMonth = selectedMonth;
mDay = selectedDay;
txtDateTime.setText(new StringBuilder().append(mMonth + 1)
.append(“-“).append(mDay).append(“-“).append(mYear)
.append(” “));
}
};

}

Just so easy.

Categories: Android

How to Speed Up the AVD

disclaimer though. After doing this configuration, do not expect a lightning fast AVD. This will possibly cut 1 to 2 minutes of boot up time depending on your computer specification.

With that said, do the following:

    1. On Eclipse, click Run -> Run Configurations.
    1. Under Android Application, select your current active project (ex: HelloWorld)
    1. Click on the Target tab.
    1. Under Additional Emulator Command Line Options, type-in-scale 0.5 -no-boot-anim
    1. Click Apply and you are done.

No Boot Anim
Setting the No Boot Anim flag will turn of the boot animation. Thus removing the loading of the images used in the animation, the delays used to have a smooth animation, and the transition to and from boot animation.

Scale
Ideally speaking, setting the scale to 50% will lessen the graphic rendering 50%. It might help just a little, but every milliseconds count if all you wanted is to test your app.

With that set, your emulator should look like this.

Posted by   at 2:51 PM
Categories: Android

Formatpastcode numeric

Private Sub Command1_Click()
FormatPasteCode rtb.Text, 1
End Sub
Private Sub FormatPasteCode(str As String, currentpos As Integer)
Dim i As Integer
Dim oldPos As Integer
Dim str1 As String
i = currentpos
oldPos = currentpos
Do While i <= Len(str)
If i <> Len(str) Then
If Mid(str, i, 1) = ” ” Or Mid(str, i, 1) = vbTab Then
str1 = Mid(str, oldPos, i – oldPos)
If IsNumeric(str1) Then
ColorWord rtb, oldPos, i – oldPos, vbRed
End If
oldPos = i
ElseIf Mid(str, i, 1) = vbCr Then
str1 = Mid(str, oldPos, i – oldPos)
If IsNumeric(str1) Then
ColorWord rtb, oldPos, i – oldPos, vbRed
End If
oldPos = i + 1
End If
i = i + 1
Else
str1 = Mid(str, oldPos, i – oldPos)
If IsNumeric(str1) Then
ColorWord rtb, oldPos, i – oldPos, vbRed
End If
Exit Do
End If
Loop
End Sub

Private Sub ColorWord(rtb As RichTextBox, start As Integer, length As Integer, color As Long)
Dim oldPos As Integer
oldPos = rtb.SelStart
rtb.SelStart = start
rtb.SelLength = length
rtb.SelColor = color
End Sub

Private Sub Form_Resize()
rtb.Width = ScaleWidth – 800
rtb.Height = ScaleHeight – 800
End Sub

Categories: C#

Line numbers in RichTextBox VB6

Option Explicit

Private Declare Function SendMessage Lib “user32” Alias “SendMessageA” ( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any _
) As Long

Private Const EM_GETLINECOUNT = &HBA
Private Const EM_LINEINDEX = &HBB

Private Sub GetLineNumber(rtb As RichTextBox)
Dim lines As Long
Dim i As Long
lines = SendMessage(rtb.hwnd, EM_GETLINECOUNT, 0&, 0&)
lblNumber.Caption = “”
For i = 1 To lines
lblNumber.Caption = lblNumber.Caption & CStr(i) & vbCrLf
Next i
End Sub

Private Sub GetCurrentLine(rtb As RichTextBox)
Dim lines As Long
Dim i, j As Long
Dim LN As Long
Dim curLine As Long

lines = SendMessage(rtb.hwnd, EM_GETLINECOUNT, 0&, 0&)
lblNumber.Caption = “”
For i = 1 To lines
If LN = SendMessage(rtb.hwnd, EM_LINEINDEX, i – 1, 0) Then Exit For
Next i
curLine = LN
For j = 1 To lines
If j = curLine Then
lblNumber.Caption = lblNumber.Caption & “* ” & CStr(j) & vbCrLf
Else
lblNumber.Caption = lblNumber.Caption & CStr(j) & vbCrLf
End If
Next j

End Sub
Private Sub rtb_Change()
GetCurrentLine rtb
End Sub

Private Sub UserControl_Initialize()
lblNumber.Height = rtb.Height
End Sub

Categories: C#

Làm sao để 1 control đang active ko bi mất active khi click 1 control khác

public partial class Form3 : Form,IMessageFilter
{
public Form3()
{
InitializeComponent();
Application.AddMessageFilter(this);
}

private const int WM_LBUTTONDOWN = 0x201;

public bool PreFilterMessage(ref Message m)
{
if (m.Msg == WM_LBUTTONDOWN)
{
//button1 la nut ma ban click nhung ko cho active
if (m.HWnd == button1.Handle)
{
//Tao ham sendkey cua ban o day
return true;
}
}
return false;
}
}

Categories: C#

DataDings

DataTable dt = new DataTable();
dt.Columns.Add(“Code”, typeof(string));
dt.Columns.Add(“Name”, typeof(string));
dt.Rows.Add(“001”, “Mango”);
dt.Rows.Add(“002”, “Android”);
dt.Rows.Add(“003”, “Ginger bread”);
dt.Rows.Add(“004”, “Android 4.0”);
cboUser.DataSource = dt;
cboUser.DisplayMember = “Name”;
cboUser.ValueMember = “Code”;
txtCode.DataBindings.Add(“Text”, dt, “Code”);
txtName.DataBindings.Add(“Text”, dt, “Name”);

Categories: C#