Shubham Ranakoti Shubham Ranakoti - 5 months ago 5
Android Question

Drawing letters in a GridView using cells

I want to draw letters on my gridview(which is basically acting as a led board). I am trying to take input string from user and draw that string in gridview as shown below. The gridview size is fixed with two 6x5 boards. i need to draw that string in such a way that frame appears to move from right to left(basically refresh layout in every 2 seconds interval). I am not able to understand how to draw those letters on gridview cells through input string. Any kind of references and links would work for me too.

Snapshot Link : http://imgur.com/pb3lfCv

On next update the columns should shift left by one column in that case we should be able to see 4/5th of first letter and full 2nd letter and third letter would just start entering from right side..

Snapshot after 2 sec interval : http://imgur.com/Ue8y0OC

Snapshot after 2 sec interval : http://imgur.com/mebRsuM

Answer

Hey i got the solution to above - i myself developed a class which has a function which takes character as an input and returns its pattern of display in 6*6 matrix & length field is there to ensure how much width it will take in display. Use this jar to create a 2-d array for whole string and traverse that array using a window of screen size from one end. here is code for that class:

public class TextPat {
    public int length;
    public int[][] flag;
    public void getFlag(char data) {
        switch (data){
            case 'A':
            {
             length=5;
                flag=new int[][]{
                        {0,1,1,0,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {1,1,1,1,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0}};
            }break;

            case 'B':
            {
                length=5;
                flag=new int[][]{
                        {1,1,1,0,0,0},
                        {1,0,0,1,0,0},
                        {1,1,1,0,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {1,1,1,0,0,0}};
            }break;

            case 'C':
            {
                length=5;
                flag=new int[][]{
                        {0,1,1,0,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,1,0,0},
                        {0,1,1,0,0,0}};
            }break;

            case 'D':
            {
                length=5;
                flag=new int[][]{
                        {1,1,1,0,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {1,1,1,0,0,0}};
            }break;

                case 'E':
            {
                length=5;
                flag=new int[][]{
                        {1,1,1,1,0,0},
                        {1,0,0,0,0,0},
                        {1,1,1,1,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,1,1,1,0,0}};
            }break;
            case 'F':
            {
                length=5;
                flag=new int[][]{
                        {1,1,1,1,0,0},
                        {1,0,0,0,0,0},
                        {1,1,1,0,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0}};
            }break;
            case 'G':
            {
                length=5;
                flag=new int[][]{
                        {0,1,1,0,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,0,0,0},
                        {1,0,1,1,0,0},
                        {1,0,0,1,0,0},
                        {0,1,1,0,0,0}};
            }break;
            case 'H':
            {
                length=5;
                flag=new int[][]{
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {1,1,1,1,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0}};
            }break;
            case 'I':
            {
                length=2;
                flag=new int[][]{
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0}};
            }break;
            case 'J':
            {
                length=5;
                flag=new int[][]{
                        {1,1,1,1,0,0},
                        {0,0,0,1,0,0},
                        {0,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {0,1,1,0,0,0}};
            }break;
            case 'K':
            {
                length=6;
                flag=new int[][]{
                        {1,0,0,1,0,0},
                        {1,0,1,0,0,0},
                        {1,1,0,0,0,0},
                        {1,0,1,0,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,0,1,0}};
            }break;
            case 'L':
            {
                length=4;
                flag=new int[][]{
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,1,1,0,0,0}};
            }break;
            case 'M':
            {
                length=6;
                flag=new int[][]{
                        {1,1,0,1,1,0},
                        {1,1,1,1,1,0},
                        {1,0,1,0,1,0},
                        {1,0,0,0,1,0},
                        {1,0,0,0,1,0},
                        {1,0,0,0,1,0}};
            }break;
            case 'N':
            {
                length=6;
                flag=new int[][]{
                        {1,0,0,0,1,0},
                        {1,1,0,0,1,0},
                        {1,1,1,0,1,0},
                        {1,0,1,1,1,0},
                        {1,0,0,1,1,0},
                        {1,0,0,0,1,0}};
            }break;
            case 'O':
            {
                length=5;
                flag=new int[][]{
                        {0,1,1,0,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {0,1,1,0,0,0}};
            }break;
            case 'P':
            {
                length=5;
                flag=new int[][]{
                        {1,1,1,0,0,0},
                        {1,0,0,1,0,0},
                        {1,1,1,0,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0}};
            }break;

            case 'Q':
            {
                length=6;
                flag=new int[][]{
                        {0,1,1,1,0,0},
                        {1,0,0,0,1,0},
                        {1,0,0,0,1,0},
                        {1,0,0,0,1,0},
                        {0,1,1,1,0,0},
                        {0,0,0,0,1,0}};
            }break;

            case 'R':
            {
                length=5;
                flag=new int[][]{
                        {1,1,1,0,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {1,1,1,0,0,0},
                        {1,0,1,0,0,0},
                        {1,0,0,1,0,0}};
            }break;

            case 'S':
            {
                length=5;
                flag=new int[][]{
                        {0,1,1,1,0,0},
                        {1,0,0,0,0,0},
                        {0,1,1,0,0,0},
                        {0,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {0,1,1,0,0,0}};
            }break;

            case 'T':
            {
                length=4;
                flag=new int[][]{
                        {1,1,1,0,0,0},
                        {0,1,0,0,0,0},
                        {0,1,0,0,0,0},
                        {0,1,0,0,0,0},
                        {0,1,0,0,0,0},
                        {0,1,0,0,0,0}};
            }break;

            case 'U':
            {
                length=5;
                flag=new int[][]{
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {1,1,1,1,0,0}};
            }break;

            case 'V':
            {
                length=6;
                flag=new int[][]{
                        {1,0,0,0,1,0},
                        {1,0,0,0,1,0},
                        {1,0,0,0,1,0},
                        {1,0,0,0,1,0},
                        {0,1,0,1,0,0},
                        {0,0,1,0,0,0}};
            }break;

            case 'W':
            {
                length=6;
                flag=new int[][]{
                        {1,0,0,0,1,0},
                        {1,0,0,0,1,0},
                        {1,0,0,0,1,0},
                        {1,0,1,0,1,0},
                        {1,1,1,1,1,0},
                        {0,1,0,1,0,0}};
            }break;

            case 'X':
            {
                length=6;
                flag=new int[][]{
                        {1,0,0,0,1,0},
                        {0,1,0,1,0,0},
                        {0,0,1,0,0,0},
                        {0,1,0,1,0,0},
                        {1,0,0,0,1,0},
                        {1,0,0,0,1,0}};
            }break;

            case 'Y':
            {
                length=6;
                flag=new int[][]{
                        {1,0,0,0,1,0},
                        {1,0,0,0,1,0},
                        {0,1,0,1,0,0},
                        {0,0,1,0,0,0},
                        {0,0,1,0,0,0},
                        {0,0,1,0,0,0}};
            }break;

            case 'Z':
            {
                length=5;
                flag=new int[][]{
                        {1,1,1,1,0,0},
                        {0,0,0,1,0,0},
                        {0,0,1,0,0,0},
                        {0,1,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,1,1,1,0,0}};
            }break;

            case 'a':
            {
                length=5;
                flag=new int[][]{
                        {0,0,0,0,0,0},
                        {1,1,1,0,0,0},
                        {0,0,0,1,0,0},
                        {0,1,1,1,0,0},
                        {1,0,0,1,0,0},
                        {0,1,1,1,0,0}};
            }break;

            case 'b':
            {
                length=5;
                flag=new int[][]{
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,1,1,0,0,0},
                        {1,0,0,1,0,0},
                        {1,1,1,0,0,0}};
            }break;

            case 'c':
            {
                length=5;
                flag=new int[][]{
                        {0,0,0,0,0,0},
                        {0,0,0,0,0,0},
                        {0,1,1,1,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {0,1,1,1,0,0}};
            }break;

            case 'd':
            {
                length=5;
                flag=new int[][]{
                        {0,0,0,1,0},
                        {0,0,0,1,0,0},
                        {0,0,0,1,0,0},
                        {0,1,1,1,0,0},
                        {1,0,0,1,0,0},
                        {0,1,1,1,0,0}};
            }break;

            case 'e':
            {
                length=5;
                flag=new int[][]{
                        {0,0,0,0,0,0},
                        {0,1,1,0,0,0},
                        {1,0,0,1,0,0},
                        {1,1,1,1,0,0},
                        {1,0,0,0,0,0},
                        {0,1,1,1,0,0}};
            }break;

            case 'f':
            {
                length=5;
                flag=new int[][]{
                        {0,1,1,0,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,0,0,0},
                        {1,1,1,0,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0}};
            }break;

            case 'g':
            {
                length=5;
                flag=new int[][]{
                        {0,1,1,1,0,0},
                        {1,0,0,1,0,0},
                        {0,1,1,1,0,0},
                        {0,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {0,1,1,0,0,0}};
            }break;
            case 'h':
            {
                length=5;
                flag=new int[][]{
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,1,1,0,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0}};
            }break;

            case 'i':
            {
                length=2;
                flag=new int[][]{
                        {0,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {0,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0}};
            }break;

            case 'j':
            {
                length=4;
                flag=new int[][]{
                        {0,0,1,0,0,0},
                        {0,0,0,0,0,0},
                        {0,0,1,0,0,0},
                        {0,0,1,0,0,0},
                        {1,0,1,0,0,0},
                        {0,1,0,0,0,0}};
            }break;

            case 'k':
            {
                length=5;
                flag=new int[][]{
                        {1,0,0,0,0,0},
                        {1,0,0,1,0,0},
                        {1,0,1,0,0,0},
                        {1,1,0,0,0,0},
                        {1,0,1,0,0,0},
                        {1,0,0,1,0,0}};
            }break;
            case 'l':
            {
                length=2;
                flag=new int[][]{
                        {0,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0}};
            }break;

            case 'm':
            {
                length=6;
                flag=new int[][]{
                        {0,0,0,0,0,0},
                        {0,0,0,0,0,0},
                        {0,1,0,1,0,0},
                        {1,0,1,0,1,0},
                        {1,0,1,0,1,0},
                        {1,0,0,0,1,0}};
            }break;

            case 'n':
            {
                length=5;
                flag=new int[][]{
                        {0,0,0,0,0,0},
                        {0,0,0,0,0,0},
                        {1,1,1,0,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0}};
            }break;

            case 'o':
            {
                length=5;
                flag=new int[][]{
                        {0,0,0,0,0,0},
                        {0,0,0,0,0,0},
                        {0,1,1,0,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {0,1,1,0,0,0}};
            }break;
            case 'p':
            {
                length=5;
                flag=new int[][]{
                        {1,0,0,0,0,0},
                        {1,1,1,0,0,0},
                        {1,0,0,1,0,0},
                        {1,1,1,0,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0}};
            }break;

            case 'q':
            {
                length=6;
                flag=new int[][]{
                        {0,1,1,0,0,0},
                        {1,0,0,1,0,0},
                        {0,1,1,1,0,0},
                        {0,0,0,1,0,0},
                        {0,0,0,1,0,0},
                        {0,0,0,1,1,0}};
            }break;

            case 'r':
            {
                length=5;
                flag=new int[][]{
                        {0,0,0,0,0,0},
                        {1,0,1,1,0,0},
                        {1,1,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0}};
            }break;

            case 's':
            {
                length=5;
                flag=new int[][]{
                        {0,0,0,0,0,0},
                        {0,1,1,1,0,0},
                        {1,0,0,0,0,0},
                        {0,1,1,0,0,0},
                        {0,0,0,1,0,0},
                        {1,1,1,0,0,0}};
            }break;
            case 't':
            {
                length=5;
                flag=new int[][]{
                        {0,1,0,0,0,0},
                        {0,1,0,0,0,0},
                        {1,1,1,0,0,0},
                        {0,1,0,0,0,0},
                        {0,1,0,1,0,0},
                        {0,1,1,0,0,0}};
            }break;

            case 'u':
            {
                length=5;
                flag=new int[][]{
                        {0,0,0,0,0,0},
                        {0,0,0,0,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {1,1,1,1,0,0}};
            }break;

            case 'v':
            {
                length=6;
                flag=new int[][]{
                        {0,0,0,0,0,0},
                        {0,0,0,0,0,0},
                        {1,0,0,0,1,0},
                        {1,0,0,0,1,0},
                        {0,1,0,1,0,0},
                        {0,0,1,0,0,0}};
            }break;

            case 'w':
            {
                length=6;
                flag=new int[][]{
                        {0,0,0,0,0,0},
                        {0,0,0,0,0,0},
                        {1,0,0,0,1,0},
                        {1,0,0,0,1,0},
                        {1,0,1,0,1,0},
                        {0,1,0,1,0,0}};
            }break;
            case 'x':
            {
                length=6;
                flag=new int[][]{
                        {0,0,0,0,0,0},
                        {1,0,0,0,1,0},
                        {0,1,0,1,0,0},
                        {0,0,1,0,0,0},
                        {0,1,0,1,0,0},
                        {1,0,0,0,1,0}};
            }break;

            case 'y':
            {
                length=5;
                flag=new int[][]{
                        {1,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {0,1,1,1,0,0},
                        {0,0,0,1,0,0},
                        {1,0,0,1,0,0},
                        {0,1,1,0,0,0}};
            }break;

            case 'z':
            {
                length=5;
                flag=new int[][]{
                        {0,0,0,0,0,0},
                        {0,0,0,0,0,0},
                        {1,1,1,1,0,0},
                        {0,0,1,0,0,0},
                        {0,1,0,0,0,0},
                        {1,1,1,1,0,0}};
            }break;

            case '.':
            {
                length=2;
                flag=new int[][]{
                        {0,0,0,0,0,0},
                        {0,0,0,0,0,0},
                        {0,0,0,0,0,0},
                        {0,0,0,0,0,0},
                        {0,0,0,0,0,0},
                        {1,0,0,0,0,0}};
            }break;
            case ',':
            {
                length=3;
                flag=new int[][]{
                        {0,0,0,0,0,0},
                        {0,0,0,0,0,0},
                        {0,0,0,0,0,0},
                        {0,0,0,0,0,0},
                        {0,1,0,0,0,0},
                        {1,0,0,0,0,0}};
            }break;

            case '!':
            {
                length=2;
                flag=new int[][]{
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {1,0,0,0,0,0},
                        {0,0,0,0,0,0},
                        {1,0,0,0,0,0}};
            }break;

            case '?':
            {
                length=6;
                flag=new int[][]{
                        {0,1,1,1,0,0},
                        {1,0,0,0,1,0},
                        {0,0,1,1,0,0},
                        {0,0,1,0,0,0},
                        {0,0,0,0,0,0},
                        {0,0,1,0,0,0}};
            }break;

            case '1':
            {
                length=6;
                flag=new int[][]{
                        {0,1,1,0,0,0},
                        {1,0,1,0,0,0},
                        {0,0,1,0,0,0},
                        {0,0,1,0,0,0},
                        {0,0,1,0,0,0},
                        {1,1,1,1,1,0}};
            }break;
            case '2':
            {
                length=6;
                flag=new int[][]{
                        {0,1,1,1,0,0},
                        {1,0,0,0,1,0},
                        {0,0,0,0,1,0},
                        {1,1,1,1,0,0},
                        {1,0,0,0,0,0},
                        {1,1,1,1,1,0}};
            }break;

            case '3':
            {
                length=6;
                flag=new int[][]{
                        {0,1,1,1,0,0},
                        {1,0,0,0,1,0},
                        {0,0,1,1,0,0},
                        {0,0,0,0,1,0},
                        {1,0,0,0,1,0},
                        {0,1,1,1,0,0}};
            }break;

            case '4':
            {
                length=6;
                flag=new int[][]{
                        {0,0,0,1,0,0},
                        {0,0,1,1,0,0},
                        {0,1,0,1,0,0},
                        {1,1,1,1,1,0},
                        {0,0,0,1,0,0},
                        {0,0,0,1,0,0}};
            }break;

            case '5':
            {
                length=6;
                flag=new int[][]{
                        {1,1,1,1,1,0},
                        {1,0,0,0,0,0},
                        {1,1,1,1,0,0},
                        {0,0,0,0,1,0},
                        {1,0,0,0,1,0},
                        {0,1,1,1,0,0}};
            }break;

            case '6':
            {
                length=6;
                flag=new int[][]{
                        {0,1,1,1,1,0},
                        {1,0,0,0,0,0},
                        {1,1,1,1,0,0},
                        {1,0,0,0,1,0},
                        {1,0,0,0,1,0},
                        {0,1,1,1,0,0}};
            }break;

            case '7':
            {
                length=6;
                flag=new int[][]{
                        {1,1,1,1,1,0},
                        {0,0,0,0,1,0},
                        {0,0,0,1,0,0},
                        {0,0,1,0,0,0},
                        {0,1,0,0,0,0},
                        {1,0,0,0,0,0}};
            }break;

            case '8':
            {
                length=6;
                flag=new int[][]{
                        {0,1,1,1,0,0},
                        {1,0,0,0,1,0},
                        {0,1,1,1,0,0},
                        {1,0,0,0,1,0},
                        {1,0,0,0,1,0},
                        {0,1,1,1,0,0}};
            }break;

            case '9':
            {
                length=6;
                flag=new int[][]{
                        {0,1,1,1,0,0},
                        {1,0,0,0,1,0},
                        {1,0,0,0,1,0},
                        {0,1,1,1,1,0},
                        {0,0,0,0,1,0},
                        {1,1,1,1,0,0}};
            }break;
            case '0':
            {
                length=6;
                flag=new int[][]{
                        {0,1,1,1,0,0},
                        {1,0,0,0,1,0},
                        {1,0,0,0,1,0},
                        {1,0,0,0,1,0},
                        {1,0,0,0,1,0},
                        {0,1,1,1,0,0}};
            }break;

            default:
            {
                length=5;
                flag=new int[][]{
                        {0,0,0,0,0,0},
                        {0,0,0,0,0,0},
                        {0,0,0,0,0,0},
                        {0,0,0,0,0,0},
                        {0,0,0,0,0,0},
                        {0,0,0,0,0,0}};
            }break;
        }
    }
}