28 January 2015

Parse News RSS 2.0 image in C#

If you want to parse News RSS 2.0 image from link, for example > http://codecanyon.net/feeds/new-codecanyon-items.atom

The following code can be used to match all img src in the source text and to populate list with value of src attribute.

private static IEnumerable<string> GetImagesInHTMLString(string htmlString)
        {
            var images = new List<string>();
            const string pattern = Imgpattern;
            var rgx = new Regex(pattern, RegexOptions.IgnoreCase);
            MatchCollection matches = rgx.Matches(htmlString);

            for (int i = 0, l = matches.Count; i < l; i++)
            {
                if (matches[i].Value.Contains(".jpg") || matches[i].Value.Contains(".png"))
                {
                    var ms = Regex.Matches(matches[i].Value, Urlpattern);
                    if (ms.Count > 0)
                    {
                        if (!string.IsNullOrEmpty(ms[0].Value))
                            images.Add(ms[0].Value.Replace("\"", string.Empty));
                    }
                }
            }

            return images;
        }

Decompiled C# Library : AppStudio.Common.dll

Wonderfull Microsoft Windows AppStudio on adress http://appstudio.windows.com generate Universal Applications for Windows Phone and Windows Store in C# - online.

Downloaded generated source code use closed library AppStudio.Common.dll, which breaks further portability.

Fortunately, the only items being used from this library are the BindableBase, BindableSchemaBase, and IDataSource. 

So I recreated these files in the directly, removing the AppStudio.Common.dll reference entirely from both the  Windows projects.

Here’s the code for the BindableBase:

using System;
using System.Collectionus.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace SoftLabPro.Data
{ public abstract class BindableBase : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;
    protected BindableBase()
    {
    }
    public virtual void Initialize(IDictionary<string, string> parameters)
    {
    }
    protected void OnPropertyChanged(string propertyName = null)
    {
        PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
        if (propertyChanged != null)
        {
            try
            {
                propertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
            catch
            {
            }
        }
    }
    protected bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
    {
        if (object.Equals((T)storage, value))
        {
            return false;
        }
        storage = value;
        this.OnPropertyChanged(propertyName);
        return true;
    }
}
}

Here is BindableSchemaBase:

using System;
using System.Runtime.CompilerServices;
using System.Text;

namespace SoftLabPro.Data
{ public abstract class BindableSchemaBase : BindableBase
{
    public BindableSchemaBase()
    {
        this.Id = Guid.NewGuid().ToString();
    }
    public abstract string GetValue(string propertyName);
    public virtual string GetValues(params string[] propertyNames)
    {
        StringBuilder builder = new StringBuilder();
        foreach (string str in propertyNames)
        {
            builder.AppendLine((this.GetValue(str) ?? string.Empty).ToString());
        }
        return builder.ToString();
    }
    public abstract string DefaultContent { get; }
    public abstract string DefaultImageUrl { get; }
    public abstract string DefaultSummary { get; }
    public abstract string DefaultTitle { get; }
    public string Id { get; set; }
}
}


And finally IDataSource:

using System.Collections.Generic;

using System.Threading.Tasks;

namespace SoftLabPro.Data

{
    public interface IDataSource<T> where T : BindableSchemaBase

{
    Task<IEnumerable<T>> LoadData();
    Task<IEnumerable<T>> Refresh();
}

}

27 January 2015

Parse Google News RSS image in C#

If you want to parse Google News RSS image from link, for example > http://news.google.com/news?hl=us&q=android&output=rss

The following code can be used to match all img src in the source text and to populate list with value of src attribute.

private static IEnumerable<string> GetImagesInGoogleNewsString(string htmlString)
        {
            List<string> imgSrcs = new List<string>();
            //const string pattern = Imgpattern;
            //var rgx = new Regex(pattern, RegexOptions.IgnoreCase);
            var imgSrcMatches = System.Text.RegularExpressions.Regex.Matches(htmlString, string.Format(@"<\s*img\s*src\s*=\s*{0}\s*([^{0}]+)\s*{0}", "\""),
               RegexOptions.CultureInvariant | RegexOptions.IgnoreCase | 
               RegexOptions.Multiline);

            foreach (Match match in imgSrcMatches)
                imgSrcs.Add("http:" + match.Groups[1].Value);

            return imgSrcs;
        }

16 January 2015

Android Splash Screen sizes

For drawable resolutions I found these most suitable :


Density

Resolution

Format

Color

ldpi

240x320

png

24bit

mdpi

320x480

png

24bit

hdpi

480x800

png

24bit

xdpi

720x1280

png

24bit

xxdpi

1080x1920

png

24bit

xxxdpi

?







05 January 2015

Making money with Android

Follow one developer's journey to making an income from Android apps. The goal: $1000 a month.