Thursday, September 29, 2011

Android: Dial a phone number


import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;

public class DialANumber extends Activity {
      EditText mEditText_number = null;
      LinearLayout mLinearLayout_no_button = null;
      Button mButton_dial = null;
     
      @Override
      public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            mLinearLayout_no_button = new LinearLayout(this);
           
            mEditText_number = new EditText(this);
            mEditText_number.setText("5551222");
            mLinearLayout_no_button.addView(mEditText_number);
            mButton_dial = new Button(this);
            mButton_dial.setText("Dial!");
            mLinearLayout_no_button.addView(mButton_dial);
            mButton_dial.setOnClickListener(new View.OnClickListener() {
                  public void onClick(View v) {
                             performDial();
                  }
            });
           
            setContentView(mLinearLayout_no_button);
      }
     
      public boolean onKeyDown(int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_CALL) {
                  performDial();
                  return true;
            }
            return false;
      }
     
      public void performDial(){
            if(mEditText_number!=null){
                  try {
                        startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + mEditText_number.getText())));
                  }
                  catch (Exception e)
                  {
                        e.printStackTrace();
                  }
            }
      }

Tuesday, September 27, 2011

Android: Load image from web


public Bitmap getRemoteImage(final URL aURL) {
      try {
            final URLConnection conn = aURL.openConnection();
            conn.connect();
            final BufferedInputStream bis = new BufferedInputStream(conn.getInputStream());
            final Bitmap bm = BitmapFactory.decodeStream(bis);
            bis.close();
            return bm;
      } catch (IOException e) {
            [...]
      }
      return null;
}

Tuesday, September 20, 2011

DataTable sorting

Sort a DataTable is a very simple activity:


[VB.Net]
dt.DefaultView.Sort = "ColumnName"  'normal DataTable 

ds.Tables("TableName").DefaultView.Sort = "ColumnName"  'DataTable in DataSet


[C#]
dt.DefaultView.Sort = "ColumnName"  'normal DataTable

ds.Tables["TableName"].DefaultView.Sort = "ColumnName"  'DataTable in DataSet


With this snippet you don't "physically" order the content of the DataTable but it's default view. But for data visualization purpose and other the result is the same.
Using this DataTable, for example, as datasource for a GridView the list will be sorted based of the used criteria (ColumName).

UpdateProgress dinamically centered



<script language="JavaScript" type="text/javascript">
        function adjustDivs() {           
            internal= document.getElementById('divCalculateInt');
            external= document.getElementById('divCalculate');
            dfs = interno.style;
           
            dfs.left = (external.innerWidth - internal.offsetWidth) / 2;
        }

        window.onload = adjustDivs;
        window.onresize = adjustDivs;
        window.onscroll = adjustDivs;
<script>

<asp:UpdatePanel ID="updXXX" runat="server">
<ContentTemplate>
       […]
<ContentTemplate>
<asp:UpdatePanel>

<asp:UpdateProgress ID="updprogXXX" runat="server" AssociatedUpdatePanelID="updXXX" DisplayAfter="150">
<ProgressTemplate>
             <div id="divCalculate" align="center" style="top: 200px; position: absolute; top:0; bottom:0; right:0; left:0;background-color:rgba(0,0,0,0.5)">
                    <div id="divCalculateInt" align="center" style="border: solid 1px #000000; background: #FFFFFF;padding: 5px; width: 320px; height: 50px;margin-top:300px">
                        <asp:Label runat="server" ID="lblLoading2" Text="Computing in progress..."><asp:Label>
                        <asp:Image ID="imgLoading" runat="server" ImageAlign="left" SkinID="imgLoadingBar" /><br /><br />
                        <asp:Label runat="server" ID="lblLoadingInfo" Text="This operation may last some minutes" Font-Size="X-Small" >asp:Label>
                    <div>
                <div>               
        <ProgressTemplate>
<asp:UpdateProgress>