C#             3GL   4GL  

C#

Mono Android

Android Mono .

Mono Android :


, xml layout ( ) . DroidDraw, . - .
( ) Android. . Android 2.1.1.
Mono Android .

Mono Android



MyFirstMonoAndroidApplication.

: Assets Resources Activity1.
Assets . .
. Drawable , , . Layout xml . Values , .
, , AndroidResource.
Activity1. , Activity. Activity? Activity , . Activity (xml ).

SetContentView(Resource.Layout.Main);
Activity.
Activity.
, Activity.

:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical">
  <Button
  android:id="@+id/FirstExample"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="First Example"></Button>
<Button
  android:id="@+id/SecondExample"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="Second Example"></Button>
</LinearLayout>


* This source code was highlighted with Source Code Highlighter.


. .
[Activity(Label = "My first mono android activity", MainLauncher = true, Icon = "@drawable/icon")]
 public class MyMainActivity : Activity
 {
  protected override void OnCreate(Bundle bundle)
  {
   base.OnCreate(bundle);
   SetContentView(Resource.Layout.Main);
   Button firstExample = FindViewById<Button>(Resource.Id.FirstExample);
   firstExample.Click += firstExample_Click;
   Button secondExample = FindViewById<Button>(Resource.Id.SecondExample);
   secondExample.Click += secondExample_Click;
  }

  void firstExample_Click(object sender, EventArgs e)
  {
   Intent titlesIntent = new Intent(this, typeof(TitlesListActivity));
   StartActivity(titlesIntent);
  }

  void secondExample_Click(object sender, EventArgs e)
  {
   Intent friendlyListIntent = new Intent(this, typeof(MoreFriendlyRssFeedActivity));
   StartActivity(friendlyListIntent);
  }
 }


* This source code was highlighted with Source Code Highlighter.


, Intent.
Intent? . - . , , Activity.
, . Activity TitlesListActivity MoreFriendlyRssFeedActivity.

, Mono Android. , , .
RSS . RSS.
public class RssReader
  {
    private const string _title = "title";
    private const string _link = "link";
    private const string _item = "item";
    private const string _channel = "channel";

    private static Func<XElement, RssListItem> GetTitlesAndLinksFunc = (x => new RssListItem { Title = x.Element(_title).Value, Link = x.Element(_link).Value });

    public static IList<RssListItem> GetRssListItems(params string[] rssUris)
    {
      List<RssListItem> fullList = new List<RssListItem>();

      IEnumerable<XElement> itemsFromConcreteIteration;
      foreach (string rssUri in rssUris)
      {
        itemsFromConcreteIteration = GetRssFeedChannel(rssUri).Elements(_item);
        fullList.AddRange(itemsFromConcreteIteration.Select(GetTitlesAndLinksFunc));
      }

      return fullList;
    }

    public static IEnumerable<string> GetTitles(string rssUri)
    {
      IEnumerable<XElement> items = GetRssFeedChannel(rssUri).Elements(_item);
      return items.Select(x => x.Element(_title).Value);
    }

    public static XElement GetRssFeedChannel(string rssUri)
    {
      XElement feed = XElement.Load(rssUri);
      return feed.Element(_channel);
    }
  }

  public class RssListItem
  {
    public string Title { get; set; }
    public string Link { get; set; }
  }


* This source code was highlighted with Source Code Highlighter.


Activity TitlesListActivity.
ListActivity, ( ) - .
, xml SetContentView.

  [Activity(Label = "List")]
  public class TitlesListActivity : ListActivity
  {
    protected override void OnCreate(Bundle bundle)
    {
      base.OnCreate(bundle);
      
      var titles = RssReader.GetTitles("http://habrahabr.ru/rss/blogs/mono/");
      ListAdapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, titles.ToArray());
    }
  }


* This source code was highlighted with Source Code Highlighter.


: Android.Resource.Layout.SimpleListItem1. , ( ), .

:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@android:id/text1"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:textAppearance="?android:attr/textAppearanceLarge"
  android:gravity="center_vertical"
  android:paddingLeft="6dip"
  android:minHeight="?android:attr/listPreferredItemHeight"
/>


* This source code was highlighted with Source Code Highlighter.


.


Activity RSS .

! , , , - .


RSS .
: Mono .NET Drawable ( !). Strings.xml ( Values) :
<?xml version="1.0" encoding="utf-8"?>
<resources>  
  <string name="ApplicationName">MyFirstMonoAndroidApplication</string>
  <string-array name="frameworks">
    <item>Mono</item>
    <item>.Net</item>
    <item>Mono and .Net</item>
  </string-array>
</resources>


* This source code was highlighted with Source Code Highlighter.


MoreFriendlyRssFeed.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical">
  <Spinner
  android:id="@+id/FrameworkSelector"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content">
  </Spinner>
  <ListView
  android:id="@+id/RssEntries"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content">
  </ListView>
</LinearLayout>


* This source code was highlighted with Source Code Highlighter.


: Spinner ListView . , ListView ( , ), , . , ListView <-> .

. RssRow.xml. - .
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:padding="6dip">
  <ImageButton
  android:id="@+id/LogoButton"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:src="@drawable/mono">
  </ImageButton>
  <TextView
  android:id="@+id/Title"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content">
  </TextView>
</LinearLayout>


* This source code was highlighted with Source Code Highlighter.


: Activity, .
 [Activity(Label = "Friendly List")]
 public class MoreFriendlyRssFeedActivity : Activity
 {
  protected override void OnCreate(Bundle bundle)
  {
   base.OnCreate(bundle);
   SetContentView(Resource.Layout.MoreFriendlyRssFeed);

   Spinner spinner = FindViewById<Spinner>(Resource.Id.FrameworkSelector);
   spinner.ItemSelected += spinner_ItemSelected;
   ArrayAdapter adapter = ArrayAdapter.CreateFromResource(this, Resource.Array.frameworks, Android.Resource.Layout.SimpleSpinnerItem);
   adapter.SetDropDownViewResource(
Android.Resource.Layout.SimpleSpinnerDropDownItem);
   spinner.Adapter = adapter;
  }

  void spinner_ItemSelected(object sender, ItemEventArgs e)
  {}
 }


* This source code was highlighted with Source Code Highlighter.


Android.Resource.Layout.SimpleSpinnerItem. , :
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
style="?android:attr/spinnerItemStyle"
android:singleLine="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />


* This source code was highlighted with Source Code Highlighter.


ArrayAdapter. , , ArrayAdapter, GetView. RssListItemAdapter :
public class RssListItemAdapter: ArrayAdapter<RssListItem>
  {
    private IList <RssListItem> Items;

    public RssListItemAdapter(Context context, int textViewResourceId, IList<RssListItem> items)
      : base(context, textViewResourceId, items)
    {
      Items = items;
    }

    public override View GetView(int position, View convertView, ViewGroup parent)
    {
      View view = convertView;
      if (view == null)
      {
        LayoutInflater inflater = (LayoutInflater)Context.GetSystemService(Context.LayoutInflaterService);
        // , .
        view = inflater.Inflate(Resource.Layout.RssRow, null);
      }

      //
      RssListItem item = Items[position];

      //
      //
      ImageButton btnLogo = (ImageButton)view.FindViewById(Resource.Id.LogoButton);
      btnLogo.Click += delegate
                 {
                   Intent browserIntent = new Intent("android.intent.action.VIEW", Android.Net.Uri.Parse(item.Link));
                   Context.StartActivity(browserIntent);
                 };
      
      // ( )
      btnLogo.SetImageResource(item.Title.StartsWith("Mono") ? Resource.Drawable.mono : Resource.Drawable.net);
      
      //
      TextView txtTitle = (TextView)view.FindViewById(Resource.Id.Title);      
      txtTitle.Text = item.Title;

      //
      return view;
    }
  }


* This source code was highlighted with Source Code Highlighter.


. .
    void spinner_ItemSelected(object sender, ItemEventArgs e)
    {
      ListView view = FindViewById<ListView>(Resource.Id.RssEntries);      

      switch (e.Position)
      {
        case 0:
          view.Adapter = new RssListItemAdapter(this, Resource.Layout.RssRow, RssReader.GetRssListItems("http://habrahabr.ru/rss/blogs/mono/"));
          break;
        case 1:
          view.Adapter = new RssListItemAdapter(this, Resource.Layout.RssRow, RssReader.GetRssListItems("http://habrahabr.ru/rss/blogs/net/"));
          break;
        case 2:
          view.Adapter = new RssListItemAdapter(this, Resource.Layout.RssRow, RssReader.GetRssListItems("http://habrahabr.ru/rss/blogs/mono/", "http://habrahabr.ru/rss/blogs/net/"));
          break;
      }
    }


* This source code was highlighted with Source Code Highlighter.


. RSS ( ).


:


, .


Android


: Android . , apk (Android Package) . , trial Mono Android . , trial, .
AndroidManifest.xml. , .

AndroidManifest.xml :


:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="First.MonoApp" android:versionCode="1" android:versionName="1.0">
  <application android:label="MyMonoApp">
  </application>
  <uses-sdk android:minSdkVersion="4" />
  <uses-permission android:name="android.permission.INTERNET" />
</manifest>


* This source code was highlighted with Source Code Highlighter.


apk . Build -> Package MyFirstMonoAndroidApplication for Android (.apk)
Android . :
Allow this application to: Full access to Internet.
. , . :

          3GL - .   4GL -     DB-


, - - , , , , , .




 10.11.2021 - 12:37: - Personalias -> WHO IS WHO - - _.
10.11.2021 - 12:36: - Conscience -> . ? - _.
10.11.2021 - 12:36: , , - Upbringing, Inlightening, Education -> ... - _.
10.11.2021 - 12:35: - Ecology -> - _.
10.11.2021 - 12:34: , - War, Politics and Science -> - _.
10.11.2021 - 12:34: , - War, Politics and Science -> . - _.
10.11.2021 - 12:34: , , - Upbringing, Inlightening, Education -> , - _.
10.11.2021 - 09:18: - New Technologies -> , 5G- - _.
10.11.2021 - 09:18: - Ecology -> - _.
10.11.2021 - 09:16: - Ecology -> - _.
10.11.2021 - 09:15: , , - Upbringing, Inlightening, Education -> - _.
10.11.2021 - 09:13: , , - Upbringing, Inlightening, Education -> - _.
Bourabai Research -  XXI Bourabai Research Institution