RSS Feed

The Future Of Android Ios And Microsoft Windows 8 and 8.1

I do believe of you are developing an interesting Android application (which maybe you could share me a copy when you get that far). I will reciprocate. My vision of the future is follows. My predictions, so far, have happened. I can only see a few years into the future. I think that Microsoft has lost it right now. I expect them to buy themselves back into the market in the next 24 months. I think Google is starting to be the Microsoft of our era. I think that apple will over this time hold a solid niche.

I think people are going to realise that Android and iOS (never know which letters are capitals but that is not important) are far better operating systems. I think more and more people will use these. The result will be that people want bigger and bigger screens on their tablets. I see people using a small tablet to move about with and coming home to a big tablet that replaced the PC at home. Software is cheaper and easier to use. Even more importantly they have been designed within the constraints of a better operating system. Furthermore, marketing etc now is breaking through. So I think Google have positioned themselves well for a dynamic future. I think Apple (and we need them for all the innovations) will continue because quality will always have a place. The two words I would like to share with you with all my experience are: INNOVATION (something different that takes things further for man and woman kind), QUALITY (nothing is any good unless it works every time with no problems.) are what you need. There is no point in writing another weight tracking piece of software with dieting advice. That has long gone!

There are so many other words I could use. I keep hearing the word STABILITY – very valid but to me that is part of quality. Would you like to fly in a plane with a dodgy screw somewhere. Do you want to use software that crashes with some cryptic error. Surely those days are soon to be over.

The Canvas Total Control Of Gestures And Painting

I have nothing here right now. But I specialise in writing Java, Android Studio graphic applications. As it is quite a long topic with many samples of code, with some object orientated theory I don’t want to embark on it if noone is interested. Here I am with very few hits on what I write and I expected that. Who am I? I don’t know. Does anyone really want to hear from me? I dont know. Please say and I have code samples I think will take you further. I am not saying everything I write is perfect (I am still learning and I am sure more experienced people will spot errors). At the end of the day – what works works and if it performs well – that is good. If it is not technically the best – well you hope to get there one day. Half of the reason why I am here exposing myself is to learn. Part of why I do what I do is because so many people have contributed their knowledge and helped me. I hope to help a few people back!

Rectangles Inline If Statement Code Tips Performance and Readability

The purpose of this example is using what is called an “inline if statement.” Here I am creating a rectangle and the variable potential determines the downward size of the rectangle. For background only, I am using the whole rectangle to determine how much of the screen to use for drawing. The important bit of the statement is this..

int noOfChildren = 10;
…. (potential ? 1 : noOfChildren)

Here is my full sample code..

int noOfChildren = 10;

bounds.set(  topX,
                     topY,
                     topX + applicationPreference.getCircleSymbolSize()+                                applicationPreference.getLineLength() + joinerLineAllowance,
topY + (applicationPreference.getLineHeight() * (potential ? 1 : noOfChildren)) );

What does the code below mean..

(potential ? 1 : noOfChildren)

It means that if the variable potential is true then multiply
applicationPreference.getLineHeight() BY ONE

If the variable potential is false them multiply BY noOfChildren that is 10 (see I set it earlier..
applicationPreference.getLineHeight() BY TEN

This cuts the amount of code. Makes debugging easier. I think it is more likely to improve performance than not..

applicationPreference.getLineHeight()

Returning A Simple If Else True Or False Statement Android Studio Java

This is covered on my web page http://www.distantworld.com/simpleifelse.html.

Very often you just want to return true or false from a function. Often it is a simple matter of checking an if statement. I think for readability, possible performance gains I think this is the best way.

Take this for example. I have a function called myFunction(int x). All I want to do is determine whether instring = “abc”. A silly example I know but I am illustrating an easy way of returning a value from a one line function.

public boolean myFunction(String inString)

{

if (inString == “abc”)  
         {
             return true;

         } else
        {
             return false;
        }

Better written in my opinion like so..

public boolean myFunction(String inString) { return inString == “abc” ; }

This is a very silly example but you would be surprised how many people write the first bit of code in my example. And there are reasons why you may need this construct. I’ll have to leave you to understand when this might be required but at least you know how you might return a boolean from a simple if else statement..

 

 

 

 

The += ++ — Incremental Operators in Java Performance Readability

This is a very basic tip. Most experienced coders will wonder why I have even written this.

Consider this, something that you do often.

i = i +3;

Experience coders will probably express it differently, as below. This is exactly the same.

i += 3;

Why would you want to write your code like this? Some people think it may perform better.I personally would give credit the compiler and doubt whether there is any performance difference. However, when you get used to these type of statements I think readability improves. The readability improves in more complex statements like below.

drawLinePositionX = drawLinePositionX + previousX +marginX + linePaddingX + etc…

The replacement statement would read.. the key is that it is shorter and in my opinion says more about the type of statement it is.

drawLinePositionX += previousX + marginX + linePaddingX + etc…

Because the line is shorter it is easier to read. Also, it helps statements that can run on a number of lines. So readability is key. Much time is spent debugging and developing code and this is often more important than code optimisation. Code optimisation is a topic I want to cover one day.

By the way. I notice some people are not aware of an even more basic statement and that is the “++”.

If instead of the example consider this..

i = i + 1;

Taking the above example this is the same as..

i += 1;

However with single incrementals like this, they are best expressed like this..

i++;

Anyway, this may help a new person to Java.

 

 

Checking That A Point Or Coordinates Are In A Rectangle

In the example code below I create a rectangle. then I check if two sets of coordinates are within the bounds of this rectangle.

protected Rect bounds = new Rect(0,0,100,100);

if inRectangle(10.0f,10.0,f)   // This will return true
{
              ….. do something
}

if inRectangle(200.0f,10.0,f)   // This will return false
{
           … wont get here
}

 public boolean inRectangle(float x, float y)

{
     boolean result = false;

     if (bounds.contains((int)x,(int)y))            // Note conversion to integer as this is required by contains.
    { 
           result = true;
     }

    return result;
}

Convert Float To Integer Java Android Studio

I have seen people asking how do I convert a float to integer. I have even seen people convert values to strings and back again.

This is an easy way to convert a float to integer. It is a simple matter of casting, like so…

float flt = 2.0f;
int  = 0i;

i = (int) flt;      // <— that is it!

The variable i is now = 2 and an integer.

 

 

Follow

Get every new post delivered to your Inbox.