Skip to content
This repository has been archived by the owner on Jun 19, 2024. It is now read-only.

Commit

Permalink
Added in MVVMCross seminar example code
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisntr committed Dec 13, 2012
1 parent bf6117b commit ee84f8d
Show file tree
Hide file tree
Showing 239 changed files with 64,078 additions and 0 deletions.
22 changes: 22 additions & 0 deletions 2012-12-13-MVVMCross/SaveTheDinosaurs/1/SaveTheDinosaurs.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TwitterSearch.UI.Droid", "TwitterSearch.UI.Droid\TwitterSearch.UI.Droid.csproj", "{883E6138-CBE1-4B8F-AD86-C38CA08963EA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{883E6138-CBE1-4B8F-AD86-C38CA08963EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{883E6138-CBE1-4B8F-AD86-C38CA08963EA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{883E6138-CBE1-4B8F-AD86-C38CA08963EA}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{883E6138-CBE1-4B8F-AD86-C38CA08963EA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{883E6138-CBE1-4B8F-AD86-C38CA08963EA}.Release|Any CPU.Build.0 = Release|Any CPU
{883E6138-CBE1-4B8F-AD86-C38CA08963EA}.Release|Any CPU.Deploy.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Any raw assets you want to be deployed with your application can be placed in
this directory (and child directories) and given a Build Action of "AndroidAsset".

These files will be deployed with you package and will be accessible using Android's
AssetManager, like this:

public class ReadAsset : Activity
{
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);

InputStream input = Assets.Open ("my_asset.txt");
}
}

Additionally, some Android functions will automatically load asset files:

Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf");
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Xml.Linq;

namespace TwitterSearch.UI.Droid
{
public static class AtomConst
{
private const string AtomNamespace = "http://www.w3.org/2005/Atom";

public static XName Entry = XName.Get("entry", AtomNamespace);
public static XName ID = XName.Get("id", AtomNamespace);
public static XName Link = XName.Get("link", AtomNamespace);
public static XName Published = XName.Get("published", AtomNamespace);
public static XName Name = XName.Get("name", AtomNamespace);
public static XName Title = XName.Get("title", AtomNamespace);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace TwitterSearch.UI.Droid
{
public class Constants
{
public const string SearchKey = "TwitterSearch";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Widget;
using Android.OS;

namespace TwitterSearch.UI.Droid
{
[Activity(Label = "TwitterSearch", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
private Button _goButton;
private EditText _searchEditText;
private TextView _randomLabel;
private TextView _searchLabel;

protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);

// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);

// Get our button from the layout resource,
// and attach an event to it
_goButton = this.FindViewById<Button>(Resource.Id.GoButton);
_searchEditText = this.FindViewById<EditText>(Resource.Id.SearchEdit);
_randomLabel = this.FindViewById<TextView>(Resource.Id.RandomLabel);
_searchLabel = this.FindViewById<TextView>(Resource.Id.SearchLabel);

_searchEditText.Text = "dinosaur";
_randomLabel.Click += RandomLabelOnClick;
_goButton.Click += GoButtonOnClick;
}

private bool ShouldSearch(string word)
{
if (string.IsNullOrEmpty(word))
return false;
if (word.ToLower() == "javascript")
return false;
return true;
}

private void GoButtonOnClick(object sender, EventArgs eventArgs)
{
var text = _searchEditText.Text;
if (!ShouldSearch(text))
return;
var intent = new Intent(this, typeof(ResultsActivity));
intent.PutExtra(Constants.SearchKey, text);
intent.AddFlags(ActivityFlags.NewTask);
this.StartActivity(intent);
}

private void RandomLabelOnClick(object sender, EventArgs eventArgs)
{
var items = new[] { "Dinosaur", "WP7", "MonoTouch", "MonoDroid", "slodge", "kittens" };

var r = new Random();
var originalText = _searchEditText.Text;
var newText = originalText;
while (originalText == newText)
{
var which = r.Next(items.Length);
newText = items[which];
}
_searchEditText.Text = newText;
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Android.App;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("TwitterSearch.UI.Droid")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TwitterSearch.UI.Droid")]
[assembly: AssemblyCopyright("Copyright © 2012")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("a557ce8c-9dbe-4b93-8fc4-95ffc126cf14")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

// Add some common permissions, these can be removed if not needed
[assembly: UsesPermission(Android.Manifest.Permission.Internet)]
[assembly: UsesPermission(Android.Manifest.Permission.WriteExternalStorage)]
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
Images, layout descriptions, binary blobs and string dictionaries can be included
in your application as resource files. Various Android APIs are designed to
operate on the resource IDs instead of dealing with images, strings or binary blobs
directly.

For example, a sample Android app that contains a user interface layout (Main.xml),
an internationalization string table (Strings.xml) and some icons (drawable/Icon.png)
would keep its resources in the "Resources" directory of the application:

Resources/
Drawable/
Icon.png

Layout/
Main.axml

Values/
Strings.xml

In order to get the build system to recognize Android resources, the build action should be set
to "AndroidResource". The native Android APIs do not operate directly with filenames, but
instead operate on resource IDs. When you compile an Android application that uses resources,
the build system will package the resources for distribution and generate a class called
"Resource" that contains the tokens for each one of the resources included. For example,
for the above Resources layout, this is what the Resource class would expose:

public class Resource {
public class Drawable {
public const int Icon = 0x123;
}

public class Layout {
public const int Main = 0x456;
}

public class String {
public const int FirstString = 0xabc;
public const int SecondString = 0xbcd;
}
}

You would then use Resource.Drawable.Icon to reference the Drawable/Icon.png file, or
Resource.Layout.Main to reference the Layout/Main.axml file, or Resource.String.FirstString
to reference the first string in the dictionary file Values/Strings.xml.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#00000000">

<ImageView
android:id="@+id/TwitterImageView"
android:layout_width="48dp"
android:layout_height="48dp"
android:padding="4dp"
android:src="@drawable/icon"
/>

<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/NameTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24dip"
android:textColor="#ffffffff"
/>

<TextView
android:id="@+id/TimeTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10dip"
android:textColor="#ffa0a0a0"
/>

<TextView
android:id="@+id/ContentTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14dip"
android:textColor="#ffffffff"
/>
</LinearLayout>
</LinearLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/SearchLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:text="Search"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:textSize="40dp"
/>
<TextView
android:id="@+id/RandomLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:text="Random"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:textSize="40dp"
/>
<EditText
android:id="@+id/SearchEdit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/SearchLabel"
android:textSize="40dp"
/>
<Button
android:id="@+id/GoButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/SearchEdit"
android:text="Go"
android:textSize="40dp"
/>
</RelativeLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ListView
android:id="@+id/TheList"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:cacheColorHint="#00000000"
/>
<ProgressBar
android:id="@+id/TheProgress"
android:layout_width="60dp"
android:layout_height="60dp"
/>
</FrameLayout>
Loading

0 comments on commit ee84f8d

Please sign in to comment.