Replace Text With An Image Using CSS

This technique works by pushing the text down inside the header with a rather large line-height (it must be at least twice the height). Then the overflow: hidden hides the text since it’s overflowing. Source

<style type="text/css">
  .ccbnRequired
        {         
            
             width: 13px;
            height: 15px;   
               
            background-image:url("/images/skins/white/forms/form_required.gif");
            background-repeat:no-repeat;

            overflow: hidden;
            line-height: 500px;                  
           
        }
</style>
Advertisements

Launch Activity/Service On Android Boot

OnBootReceiver.java

package com.logicvoid.voguetools;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;

public  class OnBootReceiver extends  BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
         if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
              Log.d("VogueTools", "Got the Boot Event>>>");
              // do your stuff for example, start a background service directly
              // here
              Toast.makeText(context, "Testing From VogueTools", Toast.LENGTH_LONG).show();

         }
    }
}

manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.logicvoid.voguetools"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".MainActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

		<!--   Handling for On Boot Receiver -->
		 <receiver android:name=".OnBootReceiver"  android:enabled="true"  android:exported="false"  android:label="OnBootReceiver">
		    <intent-filter>
		        <action android:name="android.intent.action.BOOT_COMPLETED" />
		    </intent-filter>
		</receiver>
		 <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
		<!-- End Handling for On Boot Receiver -->

    </application>
    <uses-sdk android:minSdkVersion="4" />

</manifest>

For reference. the Context passed in the onReceive is that of the Application, not a specific Activity.

If you’re doing anything that is context sensitive like dealing with preferences in your application, perhaps using appContext.getSharedPreferences. Use getApplicationContext() within your application to ensure the preferences will be read from both the BroadcastReceiver onReceive and the application itself. As the onReceive Context is that of the application, they will be equal.

Easily Remove /r and /n Chars From MultiLine Literal XML String

protected string CreateInfoRequestPackage()
    {

        string RequestPackage = "<inforequest ID=\"90210\">";
        RequestPackage += @"       
       <UserData>
      <salutation>Mr.</salutation> 
      <fname>John</fname> 
      <lname>Doe</lname> 
      <title>Sr Manager</title> 
      <institution>Acme Inc</institution> 
      <addr1>100 Main St</addr1> 
      <addr2>Suite 12</addr2> 
      <city>Anytown</city> 
      <state>MA</state> 
      <zip>02110</zip> 
      <country>USA</country> 
      <telephone>617-603-7000</telephone> 
      <fax>617-603-7001</fax> 
      <email>test@test.com</email> 
      <investor_type>2</investor_type> 
      <carrier>FEX*PO</carrier> 
      <shipment_account>12345531</shipment_account> 
      <comment>Send ASAP</comment> 
      </UserData>
     <Materials>
     <Material>
      <material_id>3434222</material_id> 
      <qty>1</qty> 
      </Material>
     <Material>
      <material_id>2342344</material_id> 
      <qty>1</qty> 
      </Material>
      </Materials>
      </inforequest>";



        // Using the data above create well formed XML (removing the /r /n)
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.LoadXml(RequestPackage);
        return xmlDoc.InnerXml;


        

    }

How To Bind Custom Object To Build Dynamic CheckBoxList

ASPX Page

<%@ Page Language="C#" AutoEventWireup="true" %>

<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Text" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="InvestorDataFeedTest" %>

<script runat="server">
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);

        
        if (!IsPostBack)
        {
            
            CBMaterialItems.DataSource = PrintedMaterialLogic.GetPrintedMaterialCBDataTable();
            CBMaterialItems.DataValueField = "MaterialID";
            CBMaterialItems.DataTextField = "MaterialName";
            CBMaterialItems.DataBind();

        }
        

    }

  
</script>

<html>
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:CheckBoxList ID="CBMaterialItems" runat="server" AutoPostBack="True" />
    </div>
    </form>
</body>
</html>

PrintedMaterialLogic.cs

using System;
using System.Collections.Generic;
using System.Web;

using System.Web.UI;
using System.Xml;
using System.Data;
using System.Reflection;
using System.Net;
using System.IO;
using System.Collections.Specialized;

namespace InvestorDataFeedTest
{
    public class PrintedMaterialLogic
    {

        public PrintedMaterialLogic() { }


        // Public Methods (Business Logic Layer)
        #region public static DataTable GetPrintedMaterialCBDataTable()
        //[DataObjectMethod(DataObjectMethodType.Select)]
        public static DataTable GetPrintedMaterialCBDataTable()
        {

            // Create an object to return
            DataTable datatable = new DataTable();

            try
            {
                List<PrintedMaterialData> entireList = new List<PrintedMaterialData>();

                entireList = GetPrintedMaterialCBData();

                datatable = ListToDataTable(entireList);
            }
            catch (Exception ex)
            {
                // Send error email
                BLL.SendErrorEmail("Get Printed Material CheckBox DataTable Error", "", ex);
            }


            return datatable;

        }
        #endregion    







        // Private Methods (Data Access Layer)
        #region public static List<PrintedMaterialData> GetPrintedMaterialCBData()
        public static List<PrintedMaterialData> GetPrintedMaterialCBData()
        {
            // Create object to return
            List<PrintedMaterialData> list = new List<PrintedMaterialData>();

            // Check cache for value first           
            Page page = (Page)HttpContext.Current.CurrentHandler;
            string cacheKey = "GetPrintedMaterialCBData";

            if (page.Cache[cacheKey] != null)
            {
                // Return cached value if it exists
                return (List<PrintedMaterialData>)page.Cache[cacheKey];
            }
            else
            {
                
                // Fill cache



                // Get XML
                string url = "http://xml.site.net/irxmlclient.asp?compid=343432&reqtype=informationrequest";
                string data = GetScreenScrape(url);

                XmlDocument xmlDoc = new XmlDocument();              
                xmlDoc.LoadXml(data);              


                // Get nodes
                XmlNodeList xmlNodes = xmlDoc.DocumentElement.SelectNodes("/IRXML/InformationRequest/InfoRequestMaterials/InfoRequestMaterial");
                // For each xml node, create the corresponding objects
                foreach (XmlNode xmlNode in xmlNodes)
                {

                    XmlElement elt = (XmlElement)xmlNode;

                    PrintedMaterialData node = PrintedMaterialCBDataCreate(xmlNode);

                    // If node was created, then add to our list
                    if (node != null) { list.Add(node); }
                }
            }


            return list;


        }
        #endregion
        #region public static PrintedMaterialData PrintedMaterialCBDataCreate(XmlNode xmlNode)
        public static PrintedMaterialData PrintedMaterialCBDataCreate(XmlNode xmlNode)
        {
            // Create an object to return
            PrintedMaterialData item = new PrintedMaterialData();

            if (xmlNode != null)
            {
                
                XmlNode materialNameNode = xmlNode.SelectSingleNode("MaterialName");                   
                XmlAttribute materialIDAttribute = xmlNode.Attributes["MaterialID"];

                item.MaterialName = (materialNameNode == null) ? "" : materialNameNode.InnerText.Trim();
                item.MaterialID = (materialIDAttribute == null) ? "" : materialIDAttribute.InnerText.Trim();     

                
                return item;
            }

            return null;
        }
        #endregion



        




        // Methods / Functions already in .COM Solution
        #region public static string GetScreenScrape(string url)
        public static string GetScreenScrape(string url)
        {
            // Create the WebRequest for the URL we are using
            HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
            req.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322)";
            // Get the stream from the returned web response
            StreamReader stream = new StreamReader(req.GetResponse().GetResponseStream());

            //experiment try reading entire thing at once
            string html = stream.ReadToEnd();


            // Finished with the stream so close it now
            stream.Close();

            return html;

        }
        #endregion
        #region private static DataTable ListToDataTable<T>(List<T> list)
        private static DataTable ListToDataTable<T>(List<T> list)
        {
            DataTable dt = new DataTable();

            foreach (PropertyInfo info in typeof(T).GetProperties())
            {
                dt.Columns.Add(new DataColumn(info.Name, info.PropertyType));
            }
            foreach (T t in list)
            {
                DataRow row = dt.NewRow();
                foreach (PropertyInfo info in typeof(T).GetProperties())
                {
                    row[info.Name] = info.GetValue(t, null);
                }
                dt.Rows.Add(row);
            }
            return dt;
        }
        #endregion




    }
}