Translate

Tuesday 26 February 2013

"The Train" design pattern

If design patterns have emerged or are supposed to emerge from pattern-mining, many of the design patterns, if not all, are like over-worked donkeys and consuming resources like an Elephant in a middle-class family.

Design patterns, in the current, technologically well-established and stable world, needs to be able to enhance its own effectiveness by regrouping itself to make use of available resources.

Design patterns have been regarded as solutions to similar problems with a total disregard to how platform changes, resource managemrnt improvements, hardware improvements, hardware-software collaboration may affect the outcome of a designed solution.

The modern, post-web 2 world of design patterns has to be inherently dynamic enough to accomodate even language enhancements to utilize, optimally, hardware advancements like parallel processing or greater memory addressing powers.

"The Train" pattern that I am talking about here will not only be the basis for all modern artifacts like a computer game, it may also serve as the right solution to serve dynamically changing artifacts in processes.

The model of this pattern is already posted on this blog as a procces model.

I will post this pattern in an Android app, first, and later as the controller of a game.

Monday 18 February 2013

Working software

If a software works and gives the desired result, that is the first successful step in software development.

Refactoring, UI design, 'code smell', object/class design, whether to use a lst or a collection or a dictionary of objects and all the other fancy stuff that are dished out, by the dozen, in training and coaching sessions, do not matter if the software is not working.

Neither does 'working software' or 'software', in this context, means the complete software with all the features. It just means that you have created the 'sufficient' code that is 'stable' and provides a solid base to achieve the requirements set.

Saturday 16 February 2013

Multiple linear layouts

Layout 2 on top belongs to 'Layout 1'
 

 

Tuesday 12 February 2013

ReArrange on the Android tablet

 ReArrange - Signed, uploaded, installed on the Android. :)

If you have an Android device, please do email me and I will mail you the .apk file.

Not yet uploaded to Google Playstore...

Thursday 7 February 2013

The XO 3 - what the child in India wants

The OLPC laptop (XO as it is called) (images are the Concept design)

is a dream for any nation's child education plans and especially for India because of its robustness (unbreakable body), battery that can be charged from solar energy and even through a hand-crank tool and more importantly, it is designed by educationists and targets the education sector making it customizable for any educational requirement with a full-fledged localization projects on different Indian languages.
 
 

"Designed by Yves Behar's Fuseproject, the XO-3's new design features an all plastic tablet screen which is semi-flexible and extremely durable, and just like the original XO, the display can be optimized in both transmissive and reflective modes for indoor and outdoor lighting conditions.

The XO-3 supports many use scenarios to fulfill kids’ learning needs: from horizontal book mode to portrait reading mode to multi-touch--so many hands can play and learn together on the same screen--to a full-touch keyboard and a back facing camera. " onelaptop.org

Existing features (reliable list because I have an XO) - Wi-fi, 3G capability, audio-video, touch screen, open source code, a huge community of Indian techies and a galore of other goodies.

Cost ? Immaterial as OLPC India also provides for an option that is successful in the UK and even the World Bank subscribes - a lending library.

 

At Amity University, Noida

Delivered a talk on "Agile", mindset management etc to Amity university in Noida on the 24th January, 2013.

 

Wednesday 6 February 2013

TicTacToe Simplified - Android game

The UI update, in this basic example, done in the onClick method should be done in a separate thread (in the adapter or any middle layer). I

f you are doing an Android project at school or university, this is the simplest and quickest solution for you.






@TargetApi(Build.VERSION_CODES.HONEYCOMB)

@Override

public void onClick(View v) {

if (gameOver==false){
ImageCell c=(ImageCell)v;

if (playerId==1){
c.cells[c.cellNumber]=1;
gameOver=c.isWinner(c.cellNumber);
c.setImageResource(R.drawable.x);
c.setScaleType(ScaleType.

FIT_XY);
}

if (playerId==2){
c.cells[c.cellNumber]=2;
c.setImageResource(R.drawable.o_tic);
c.setScaleType(ScaleType.FIT_XY);
gameOver=c.isWinner(c.cellNumber);
}

playerId++;

if (playerId>2)playerId=1; 
moveCount++;


Toast.makeText(v.getContext(),

"Player "+ playerId +", your turn !",Toast.LENGTH_SHORT).show();
}

if (gameOver==true || moveCount>=9){
Toast.makeText(v.getContext(),

"Game over!",Toast.LENGTH_SHORT).show();
gameOver=true;
finish();
}

Get image clicked in a grid - Android



I have titled these Android related posts to match Google searches as the many results I found on the web are pretty complicated.

Here is the simple way using the AdapterView. Extend your class with BaseAdapter that gives you a getView() method to implement your view in a Grid.


// The main activity class

import android.os.Build;
import android.os.Bundle;
import android.annotation.TargetApi;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.Toast;
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class MainActivity extends Activity implements OnClickListener {
 ImageView v,v1;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  GridView gv=(GridView) findViewById(R.id.image_grid_view);
  gv.setAdapter(new ImageCellAdapter(this));
       }
  @Override
 public boolean onCreateOptionsMenu(Menu menu) {
  // Inflate the menu; this adds items to the action bar if it is present.
  getMenuInflater().inflate(R.menu.activity_main, menu);
  return true;
 }

 @TargetApi(Build.VERSION_CODES.HONEYCOMB)
 @Override
 public void onClick(View v) {
  String msg=" " + v.getId();
  Toast.makeText(this, "Clicked "+msg,Toast.LENGTH_SHORT).show();
 }
// The adapter class

import android.content.Context;
import android.text.Layout;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.*;
public class ImageCellAdapter extends BaseAdapter
{
public static final int DEFAULT_NUM_IMAGES = 8;
public ViewGroup mParentView = null;
private Context mContext;
public ImageCellAdapter(Context c)
{
    mContext = c;
}
public int getCount()
{
    return mThumbIds.length;
}
public Object getItem(int position)
{
    return mThumbIds[position];
}
public long getItemId(int position) {
    return position;
}
public View getView (int position, View convertView, ViewGroup parent)
{
    mParentView = parent;

    ImageCell v = null;
    if (convertView == null) {
        v = new ImageCell (mContext);       
    } else {
        v = (ImageCell) convertView;
    }
    v.setImageResource (mThumbIds[position]);
    v.cellNumber = position;
    v.setId(position);
   //v.setLayoutParams(LayoutParams.WRAP_CONTENT));
    v.setOnClickListener ((View.OnClickListener) mContext);
    return v;
}
public Integer[] mThumbIds = {
  R.drawable.ic_launcher, R.drawable.re,
        R.drawable.r12, R.drawable.t12,
        R.drawable.b12, R.drawable.k12,
        R.drawable.f12, R.drawable.l12,
        R.drawable.o12, R.drawable.m12,
        R.drawable.p12, R.drawable.s12,
        R.drawable.c12, R.drawable.a12,
        R.drawable.h12, R.drawable.e12,
        R.drawable.g12, R.drawable.d12,
        R.drawable.i12, R.drawable.w12,
        R.drawable.n12, R.drawable.y12,
        R.drawable.z12, R.drawable.u12,
        R.drawable.q12, R.drawable.v12,
        R.drawable.j12, R.drawable.x12,
        };
}
// The image cell class

public class ImageCell extends ImageView
//implements OnClickListener
{
//    public boolean cellEmpty = true;
    public int cellNumber = -1;
  //  public GridView gv;
public ImageCell (Context context) {
 super (context);
}
public ImageCell (Context context, AttributeSet attrs) {
 super (context, attrs);
}
public ImageCell (Context context, AttributeSet attrs, int style) {
 super (context, attrs, style);
}
}
// The activity XML


<

LinearLayout xmlns:android=http://schemas.android.com/apk/res/android

android:layout_width="fill_parent"

android:layout_height="fill_parent" 

>

 

<GridView xmlns:android="http://schemas.android.com/apk/res/android"

android:id="@+id/image_grid_view"

android:layout_width="fill_parent"
android:layout_height="fill_parent"

android:numColumns="9"

/>

 

</LinearLayout>

Get Id of Image clicked in a layout

A simple example of handling a click event on an image in a linear layout. You will need three images in your res/drawable folder of the Android app.

The main activity XML that defines the layout structure and the image view(s).

//mainactivity.xml

<
LinearLayout xmlns:"http://schemas.android.com/apk/res/android

        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
            android:id="@+id/lView1"       
        >   
< ImageView
                    android:id="@+id/imageView1"            
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/re"
            android:tag="0"
            />

<ImageView
                    android:id="@+id/imageView2"            
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_launcher"
            android:tag="1"           
            />

<ImageView
                    android:id="@+id/imageView3"            
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/m12"
            android:tag="2"
            android:onClick="onClick"           
            />
        </LinearLayout>



and the corresponding .java class. Note that the clickhandler is in code as well as in the xml file.
 
// MainActivity.java

import android.os.Build;
import android.os.Bundle;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.ClipData;
import android.content.ClipDescription;
import android.view.DragEvent;
import android.view.Menu;
import android.view.View;
import android.view.View.DragShadowBuilder;
import android.view.View.OnClickListener;
import android.view.View.OnDragListener;
import android.view.View.OnLongClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;
public class MainActivity extends Activity implements OnClickListener,OnDragListener,OnLongClickListener {
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
        LinearLayout l = (LinearLayout) findViewById(R.id.lView1);    
        if (l == null) Toast.makeText(this, "Unable to find GridView",Toast.LENGTH_SHORT).show();
        else {
       
            ImageView v = (ImageView) l.findViewById(R.id.imageView1);
            ImageView v1 = (ImageView) l.findViewById(R.id.imageView2);
            v.setOnClickListener ((View.OnClickListener) this);
            v1.setOnClickListener ((View.OnClickListener) this);
            v.setOnLongClickListener((View.OnLongClickListener) this);
            v1.setOnLongClickListener((View.OnLongClickListener) this);
        }

 }
 public Integer[] mThumbIds = {
         R.drawable.ic_launcher, R.drawable.m12,         
 };
 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
  // Inflate the menu; this adds items to the action bar if it is present.
  getMenuInflater().inflate(R.menu.activity_main, menu);
  return true;
 }
 @TargetApi(Build.VERSION_CODES.HONEYCOMB)
 @Override
 public void onClick(View v) {
  String msg=(String) v.getTag();
  Toast.makeText(this, "Clicked "+msg,Toast.LENGTH_SHORT).show();
 }
 @TargetApi(Build.VERSION_CODES.HONEYCOMB)
 @Override
 public boolean onDrag(View v, DragEvent dragEv) {
  // TODO Auto-generated method stub
  return false;
 }