Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
CapnAndy
Feb 27, 2004

Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.
I decided to get into Android development and I'm already pretty good at c# and visual studio, so I got MonoDroid. At first glance, it's super neat. But I want that frigging title bar to go away! I did this:
code:
[Activity(Label = "AndroidFirst", MainLauncher = true, Icon = "@drawable/icon")]
public class Activity1 : Activity
{
	int count = 1;

	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
		Button button = FindViewById<Button>(Resource.Id.HelloButton);

		button.Click += delegate { button.Text = string.Format("{0} clicks!", count++); };

		this.Window.AddFlags(WindowManagerFlags.Fullscreen);
		this.RequestWindowFeature(WindowFeatures.NoTitle);
	}
}
But it fails, and the only error I get is the extremely unhelpful "Android.Util.AndroidRuntimeException:". The Fullscreen flag was working, it just started being a pain in the rear end when I tried requesting no title. What stupidly basic newbie mistake am I making?

Adbot
ADBOT LOVES YOU

CapnAndy
Feb 27, 2004

Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.

Geekner posted:

You have to add window flags and request window features before you call setContentView, since it takes those flags into consideration when it creates the layout.
Aha, thank you. I have also discovered themes, which are better I think!

PiotrLegnica posted:

You can use @android:style/Theme.NoTitleBar theme (that Activity attribute seems to have Theme property).
It does, and I can set it programatically too. MonoDroid is keen as poo poo.

CapnAndy
Feb 27, 2004

Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.
Okay, answer another newbie question? I'm still playing with MonoDroid and I want to learn to draw things. I found about making my own view and overriding its OnDraw event, but that's okay for, y'know, drawing something once and then it never moves again, and also I lose Main.axml which would be a shame. I want to do something really basic, like draw a box and have it change colors or resize every time I click a button or on a Timer tick.

It seems like what I need to do is get the canvas object of the current ContentView, right? Then I could just pass that into a function and have it draw on the canvas. Am I right so far, and if I am, how do I friggin' do that?

CapnAndy
Feb 27, 2004

Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.

Geekner posted:

You have to call invalidate() to cause the onDraw to refresh again. If you are animating or drawing anything dynamically you should look into a SurfaceView instead, that will let you grab the canvas whenever you want.
HA! I guessed that! I made a SurfaceView!

I can't figure out how to grab its canvas. :(

CapnAndy
Feb 27, 2004

Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.

Geekner posted:

You'll need to get the surface holder using getHolder(), then you can use the lock canvas method if you are working from a separate thread.
I don't follow. I lock the canvas so nothing else can touch it, but I still don't have access to the canvas itself, so how can I draw on it?

Maybe what I've actually written will help:
code:
public class Activity1 : Activity
{
	int count = 1;

	protected override void OnCreate(Bundle bundle)
	{
		base.OnCreate(bundle);
			
//		this.Window.AddFlags(WindowManagerFlags.Fullscreen);
	//	this.RequestWindowFeature(WindowFeatures.NoTitle);
		SetTheme(Android.Resource.Style.ThemeLightNoTitleBarFullScreen);
		// 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
		Button button = FindViewById<Button>(Resource.Id.HelloButton);
		SurfaceView view = FindViewById<SurfaceView>(Resource.Id.DrawingView);

		button.Click += delegate { button.Text = string.Format("{0} clicks!", count++); view.Invalidate(); };
		view.Draw(drawSquare();
		view.Invalidate();
	}

	public Canvas drawSquare()
	{
		Canvas result = new Canvas();
	
		Paint paint = new Paint();
		paint.Color = Color.Yellow;
		result.DrawRect(0, 0, 250, 250, paint);

		result.Save();

		return result;
	}
}
This doesn't work.

CapnAndy fucked around with this message at 20:43 on Oct 22, 2012

CapnAndy
Feb 27, 2004

Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.

Geekner posted:

You don't create the canvas directly, you let the OS generate the canvas when you call lockCanvas().
Oh poo poo, I didn't realize it did that. I went with the wussy way just to get something working by just making my own custom View so that I could override its OnDraw method, and then pulled a lot of bullshit (giving the view public settable variables that OnDraw paid attention to) to make sure I could manipulate the view with outside events. I'm gonna try that instead, it'll be cleaner.

CapnAndy
Feb 27, 2004

Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.

Geekner posted:

For now you can just check to see if the canvas you get from lockCanvas() is null before you use it.
Okay, it's been a bit because I had actual projects to do and those come before learning new stuff, but I'm back to this, and the canvas I get from lockCanvas() is always null. I tried doing this:
C# code:
SurfaceView surface = new SurfaceView(this);
layout.AddView(surface);
Canvas c = surface.Holder.LockCanvas();
c.DrawColor(Color.Green);
surface.Holder.UnlockCanvasAndPost(c);
But that fails because c is null. If I do this:
C# code:
SurfaceView surface = new SurfaceView(this);
layout.AddView(surface);
Canvas c = surface.Holder.LockCanvas();
c = new Canvas();
c.DrawColor(Color.Green);
surface.Holder.UnlockCanvasAndPost(c);
It fails on the UnlockCanvasAndPost, presumably because c has a Height and Width of 0. I'm guessing about why this one's failing, though. All I get is "Java.Lang.IllegalArgumentException".

Adbot
ADBOT LOVES YOU

CapnAndy
Feb 27, 2004

Some teeth long for ripping, gleaming wet from black dog gums. So you keep your eyes closed at the end. You don't want to see such a mouth up close. before the bite, before its oblivion in the goring of your soft parts, the speckled lips will curl back in a whinny of excitement. You just know it.
Yeah, but on the other hand I need to do it in MonoDroid, because that's what I got told to learn, everything else we do is in Visual Studio, and that way it can be easily ported to iOS with MonoTouch. So MonoDroid it is. I am using an XML layout, though! I think I am! I've got a Main.axml, it's very useful.

Using lockCanvas after OnCreate gets done running does work, so you were right. I'm gonna play with how that works vs. an overrided OnDraw.

I'm sorry I'm a pain in the rear end, by the way.

edit: When I change my SampleView from extending View to extending SurfaceView, suddenly the OnDraw override stops firing. How odd. SurfaceViews don't use OnDraw?
edit edit: Fixed that one on my own. Apparently when you extend a SurfaceView it defaults to WillNotDraw = true. Go figure. At least I'm learning! Unfortunately, OnDraw apparently overrides whatever I did in LockCanvas. So, one step forward, one step right back.

CapnAndy fucked around with this message at 21:40 on Nov 1, 2012

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply