1. Are you ready for the Galaxy S20? Here is everything we know so far!

Code Port

Discussion in 'Android Development' started by nosenseofhumor, Aug 21, 2012.

  1. nosenseofhumor

    Thread Starter

    hello folks. im not super experienced with java development, and im very new to android development.

    i am trying to create a custom keyboard for android. its mostly for experimental purposes. the keyboard only has 10 buttons, two on the top, 1 all the way to the left, 2 stacked on the left one, three stacked on the 2 on the left, then 2 more in the remaining space. its pretty tricky to explain... kinda like this:

    HTML:
    1. <table border="1">
    2. <tr>
    3. <td colspan="2">a</td><td colspan="2">b</td>
    4. </tr>
    5. <tr>
    6. <td>a</td>
    7. <td><table border="1"><tr><td>a</td></tr>
    8.     <tr><td>b</td></tr></table></td>
    9. <td><table border="1"><tr><td>a</td></tr>
    10.     <tr><td>b</td></tr>
    11.     <tr><td>c</td></tr></table></td>
    12. <td><table border="1"><tr><td>a</td></tr>
    13.     <tr><td>b</td></tr></table></td>
    14. </tr>
    15.  
    i found a great example of a soft keyboard in the android sdk, but im having trouble understanding it and it doesnt seem to compile anyway :(

    i sketched up what im trying to do in c#, if you create these files, compile and run this, youll see exactly what im trying to do. can somebody help me port this to an android soft keyboard?


    program.cs
    Code (Text):
    1.  
    2. using System;
    3. using System.Collections.Generic;
    4. using System.Linq;
    5. using System.Windows.Forms;
    6.  
    7. namespace csip_demo_wfa
    8. {
    9.     static class Program
    10.     {
    11.         /// <summary>
    12.         /// The main entry point for the application.
    13.         /// </summary>
    14.         [STAThread]
    15.         static void Main()
    16.         {
    17.             Application.EnableVisualStyles();
    18.             Application.SetCompatibleTextRenderingDefault(false);
    19.             Application.Run(new Form1());
    20.         }
    21.     }
    22. }
    Form1.Designer.cs
    Code (Text):
    1. namespace csip_demo_wfa
    2. {
    3.     partial class Form1
    4.     {
    5.         /// <summary>
    6.         /// Required designer variable.
    7.         /// </summary>
    8.         private System.ComponentModel.IContainer components = null;
    9.  
    10.         /// <summary>
    11.         /// Clean up any resources being used.
    12.         /// </summary>
    13.         /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    14.         protected override void Dispose(bool disposing)
    15.         {
    16.             if (disposing && (components != null))
    17.             {
    18.                 components.Dispose();
    19.             }
    20.             base.Dispose(disposing);
    21.         }
    22.  
    23.         #region Windows Form Designer generated code
    24.  
    25.         /// <summary>
    26.         /// Required method for Designer support - do not modify
    27.         /// the contents of this method with the code editor.
    28.         /// </summary>
    29.         private void InitializeComponent()
    30.         {
    31.             this.components = new System.ComponentModel.Container();
    32.             this.panel1 = new System.Windows.Forms.Panel();
    33.             this.b8 = new System.Windows.Forms.Button();
    34.             this.b4 = new System.Windows.Forms.Button();
    35.             this.panel2 = new System.Windows.Forms.Panel();
    36.             this.panel3 = new System.Windows.Forms.Panel();
    37.             this.panel4 = new System.Windows.Forms.Panel();
    38.             this.panel5 = new System.Windows.Forms.Panel();
    39.             this.panel6 = new System.Windows.Forms.Panel();
    40.             this.panel7 = new System.Windows.Forms.Panel();
    41.             this.panel8 = new System.Windows.Forms.Panel();
    42.             this.panel9 = new System.Windows.Forms.Panel();
    43.             this.panel10 = new System.Windows.Forms.Panel();
    44.             this.b16 = new System.Windows.Forms.Button();
    45.             this.b32 = new System.Windows.Forms.Button();
    46.             this.b64 = new System.Windows.Forms.Button();
    47.             this.b48 = new System.Windows.Forms.Button();
    48.             this.b96 = new System.Windows.Forms.Button();
    49.             this.b112 = new System.Windows.Forms.Button();
    50.             this.panel11 = new System.Windows.Forms.Panel();
    51.             this.panel12 = new System.Windows.Forms.Panel();
    52.             this.b2 = new System.Windows.Forms.Button();
    53.             this.b1 = new System.Windows.Forms.Button();
    54.             this.timer1 = new System.Windows.Forms.Timer(this.components);
    55.             this.panel1.SuspendLayout();
    56.             this.panel2.SuspendLayout();
    57.             this.panel3.SuspendLayout();
    58.             this.panel4.SuspendLayout();
    59.             this.panel5.SuspendLayout();
    60.             this.panel6.SuspendLayout();
    61.             this.panel7.SuspendLayout();
    62.             this.panel8.SuspendLayout();
    63.             this.panel9.SuspendLayout();
    64.             this.panel10.SuspendLayout();
    65.             this.panel11.SuspendLayout();
    66.             this.panel12.SuspendLayout();
    67.             this.SuspendLayout();
    68.             //
    69.             // panel1
    70.             //
    71.             this.panel1.Controls.Add(this.b4);
    72.             this.panel1.Controls.Add(this.b8);
    73.             this.panel1.Dock = System.Windows.Forms.DockStyle.Top;
    74.             this.panel1.Location = new System.Drawing.Point(0, 0);
    75.             this.panel1.Name = "panel1";
    76.             this.panel1.Size = new System.Drawing.Size(533, 79);
    77.             this.panel1.TabIndex = 0;
    78.             //
    79.             // b8
    80.             //
    81.             this.b8.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(128)))), ((int)(((byte)(255)))));
    82.             this.b8.Dock = System.Windows.Forms.DockStyle.Left;
    83.             this.b8.Enabled = false;
    84.             this.b8.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
    85.             this.b8.Font = new System.Drawing.Font("Microsoft Sans Serif", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
    86.             this.b8.Location = new System.Drawing.Point(0, 0);
    87.             this.b8.Name = "b8";
    88.             this.b8.Size = new System.Drawing.Size(267, 79);
    89.             this.b8.TabIndex = 0;
    90.             this.b8.Text = "9  8  10";
    91.             this.b8.UseVisualStyleBackColor = false;
    92.             //
    93.             // b4
    94.             //
    95.             this.b4.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(255)))));
    96.             this.b4.Dock = System.Windows.Forms.DockStyle.Left;
    97.             this.b4.Enabled = false;
    98.             this.b4.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
    99.             this.b4.Font = new System.Drawing.Font("Microsoft Sans Serif", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
    100.             this.b4.Location = new System.Drawing.Point(267, 0);
    101.             this.b4.Name = "b4";
    102.             this.b4.Size = new System.Drawing.Size(267, 79);
    103.             this.b4.TabIndex = 1;
    104.             this.b4.Text = "5  4  6";
    105.             this.b4.UseVisualStyleBackColor = false;
    106.             //
    107.             // panel2
    108.             //
    109.             this.panel2.Controls.Add(this.panel5);
    110.             this.panel2.Controls.Add(this.panel4);
    111.             this.panel2.Controls.Add(this.panel3);
    112.             this.panel2.Dock = System.Windows.Forms.DockStyle.Left;
    113.             this.panel2.Location = new System.Drawing.Point(0, 79);
    114.             this.panel2.Name = "panel2";
    115.             this.panel2.Size = new System.Drawing.Size(267, 241);
    116.             this.panel2.TabIndex = 1;
    117.             //
    118.             // panel3
    119.             //
    120.             this.panel3.Controls.Add(this.b112);
    121.             this.panel3.Dock = System.Windows.Forms.DockStyle.Left;
    122.             this.panel3.Location = new System.Drawing.Point(0, 0);
    123.             this.panel3.Name = "panel3";
    124.             this.panel3.Size = new System.Drawing.Size(66, 241);
    125.             this.panel3.TabIndex = 0;
    126.             //
    127.             // panel4
    128.             //
    129.             this.panel4.Controls.Add(this.panel10);
    130.             this.panel4.Controls.Add(this.panel6);
    131.             this.panel4.Dock = System.Windows.Forms.DockStyle.Left;
    132.             this.panel4.Location = new System.Drawing.Point(66, 0);
    133.             this.panel4.Name = "panel4";
    134.             this.panel4.Size = new System.Drawing.Size(66, 241);
    135.             this.panel4.TabIndex = 1;
    136.             //
    137.             // panel5
    138.             //
    139.             this.panel5.Controls.Add(this.panel9);
    140.             this.panel5.Controls.Add(this.panel8);
    141.             this.panel5.Controls.Add(this.panel7);
    142.             this.panel5.Dock = System.Windows.Forms.DockStyle.Fill;
    143.             this.panel5.Location = new System.Drawing.Point(132, 0);
    144.             this.panel5.Name = "panel5";
    145.             this.panel5.Size = new System.Drawing.Size(135, 241);
    146.             this.panel5.TabIndex = 2;
    147.             //
    148.             // panel6
    149.             //
    150.             this.panel6.Controls.Add(this.b48);
    151.             this.panel6.Dock = System.Windows.Forms.DockStyle.Top;
    152.             this.panel6.Location = new System.Drawing.Point(0, 0);
    153.             this.panel6.Name = "panel6";
    154.             this.panel6.Size = new System.Drawing.Size(66, 120);
    155.             this.panel6.TabIndex = 0;
    156.             //
    157.             // panel7
    158.             //
    159.             this.panel7.Controls.Add(this.b16);
    160.             this.panel7.Dock = System.Windows.Forms.DockStyle.Top;
    161.             this.panel7.Location = new System.Drawing.Point(0, 0);
    162.             this.panel7.Name = "panel7";
    163.             this.panel7.Size = new System.Drawing.Size(135, 80);
    164.             this.panel7.TabIndex = 0;
    165.             //
    166.             // panel8
    167.             //
    168.             this.panel8.Controls.Add(this.b32);
    169.             this.panel8.Dock = System.Windows.Forms.DockStyle.Top;
    170.             this.panel8.Location = new System.Drawing.Point(0, 80);
    171.             this.panel8.Name = "panel8";
    172.             this.panel8.Size = new System.Drawing.Size(135, 80);
    173.             this.panel8.TabIndex = 1;
    174.             //
    175.             // panel9
    176.             //
    177.             this.panel9.Controls.Add(this.b64);
    178.             this.panel9.Dock = System.Windows.Forms.DockStyle.Top;
    179.             this.panel9.Location = new System.Drawing.Point(0, 160);
    180.             this.panel9.Name = "panel9";
    181.             this.panel9.Size = new System.Drawing.Size(135, 80);
    182.             this.panel9.TabIndex = 2;
    183.             //
    184.             // panel10
    185.             //
    186.             this.panel10.Controls.Add(this.b96);
    187.             this.panel10.Dock = System.Windows.Forms.DockStyle.Top;
    188.             this.panel10.Location = new System.Drawing.Point(0, 120);
    189.             this.panel10.Name = "panel10";
    190.             this.panel10.Size = new System.Drawing.Size(66, 120);
    191.             this.panel10.TabIndex = 1;
    192.             //
    193.             // b16
    194.             //
    195.             this.b16.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(128)))));
    196.             this.b16.Dock = System.Windows.Forms.DockStyle.Fill;
    197.             this.b16.Enabled = false;
    198.             this.b16.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
    199.             this.b16.Font = new System.Drawing.Font("Microsoft Sans Serif", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
    200.             this.b16.Location = new System.Drawing.Point(0, 0);
    201.             this.b16.Name = "b16";
    202.             this.b16.Size = new System.Drawing.Size(135, 80);
    203.             this.b16.TabIndex = 1;
    204.             this.b16.Text = "17 16 18";
    205.             this.b16.UseVisualStyleBackColor = false;
    206.             //
    207.             // b32
    208.             //
    209.             this.b32.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(255)))), ((int)(((byte)(128)))));
    210.             this.b32.Dock = System.Windows.Forms.DockStyle.Fill;
    211.             this.b32.Enabled = false;
    212.             this.b32.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
    213.             this.b32.Font = new System.Drawing.Font("Microsoft Sans Serif", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
    214.             this.b32.Location = new System.Drawing.Point(0, 0);
    215.             this.b32.Name = "b32";
    216.             this.b32.Size = new System.Drawing.Size(135, 80);
    217.             this.b32.TabIndex = 2;
    218.             this.b32.Text = "33 32 34";
    219.             this.b32.UseVisualStyleBackColor = false;
    220.             //
    221.             // b64
    222.             //
    223.             this.b64.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
    224.             this.b64.Dock = System.Windows.Forms.DockStyle.Fill;
    225.             this.b64.Enabled = false;
    226.             this.b64.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
    227.             this.b64.Font = new System.Drawing.Font("Microsoft Sans Serif", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
    228.             this.b64.Location = new System.Drawing.Point(0, 0);
    229.             this.b64.Name = "b64";
    230.             this.b64.Size = new System.Drawing.Size(135, 80);
    231.             this.b64.TabIndex = 3;
    232.             this.b64.Text = "65 64 66";
    233.             this.b64.UseVisualStyleBackColor = false;
    234.             //
    235.             // b48
    236.             //
    237.             this.b48.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(0)))));
    238.             this.b48.Dock = System.Windows.Forms.DockStyle.Fill;
    239.             this.b48.Enabled = false;
    240.             this.b48.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
    241.             this.b48.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
    242.             this.b48.Location = new System.Drawing.Point(0, 0);
    243.             this.b48.Name = "b48";
    244.             this.b48.Size = new System.Drawing.Size(66, 120);
    245.             this.b48.TabIndex = 2;
    246.             this.b48.Text = "49 48 50";
    247.             this.b48.UseVisualStyleBackColor = false;
    248.             //
    249.             // b96
    250.             //
    251.             this.b96.BackColor = System.Drawing.Color.Yellow;
    252.             this.b96.Dock = System.Windows.Forms.DockStyle.Fill;
    253.             this.b96.Enabled = false;
    254.             this.b96.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
    255.             this.b96.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
    256.             this.b96.Location = new System.Drawing.Point(0, 0);
    257.             this.b96.Name = "b96";
    258.             this.b96.Size = new System.Drawing.Size(66, 120);
    259.             this.b96.TabIndex = 2;
    260.             this.b96.Text = "97 96 98";
    261.             this.b96.UseVisualStyleBackColor = false;
    262.             //
    263.             // b112
    264.             //
    265.             this.b112.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(64)))), ((int)(((byte)(0)))));
    266.             this.b112.Dock = System.Windows.Forms.DockStyle.Fill;
    267.             this.b112.Enabled = false;
    268.             this.b112.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
    269.             this.b112.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
    270.             this.b112.Location = new System.Drawing.Point(0, 0);
    271.             this.b112.Name = "b112";
    272.             this.b112.Size = new System.Drawing.Size(66, 241);
    273.             this.b112.TabIndex = 2;
    274.             this.b112.Text = "113 112 114";
    275.             this.b112.UseVisualStyleBackColor = false;
    276.             //
    277.             // panel11
    278.             //
    279.             this.panel11.Controls.Add(this.b2);
    280.             this.panel11.Dock = System.Windows.Forms.DockStyle.Top;
    281.             this.panel11.Location = new System.Drawing.Point(267, 79);
    282.             this.panel11.Name = "panel11";
    283.             this.panel11.Size = new System.Drawing.Size(266, 120);
    284.             this.panel11.TabIndex = 2;
    285.             //
    286.             // panel12
    287.             //
    288.             this.panel12.Controls.Add(this.b1);
    289.             this.panel12.Dock = System.Windows.Forms.DockStyle.Top;
    290.             this.panel12.Location = new System.Drawing.Point(267, 199);
    291.             this.panel12.Name = "panel12";
    292.             this.panel12.Size = new System.Drawing.Size(266, 120);
    293.             this.panel12.TabIndex = 3;
    294.             //
    295.             // b2
    296.             //
    297.             this.b2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(128)))));
    298.             this.b2.Dock = System.Windows.Forms.DockStyle.Fill;
    299.             this.b2.Enabled = false;
    300.             this.b2.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
    301.             this.b2.Font = new System.Drawing.Font("Microsoft Sans Serif", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
    302.             this.b2.Location = new System.Drawing.Point(0, 0);
    303.             this.b2.Name = "b2";
    304.             this.b2.Size = new System.Drawing.Size(266, 120);
    305.             this.b2.TabIndex = 2;
    306.             this.b2.Text = "2";
    307.             this.b2.UseVisualStyleBackColor = false;
    308.             //
    309.             // b1
    310.             //
    311.             this.b1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(128)))));
    312.             this.b1.Dock = System.Windows.Forms.DockStyle.Fill;
    313.             this.b1.Enabled = false;
    314.             this.b1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
    315.             this.b1.Font = new System.Drawing.Font("Microsoft Sans Serif", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
    316.             this.b1.Location = new System.Drawing.Point(0, 0);
    317.             this.b1.Name = "b1";
    318.             this.b1.Size = new System.Drawing.Size(266, 120);
    319.             this.b1.TabIndex = 2;
    320.             this.b1.Text = "1";
    321.             this.b1.UseVisualStyleBackColor = false;
    322.             //
    323.             // timer1
    324.             //
    325.             this.timer1.Enabled = true;
    326.             this.timer1.Interval = 5000;
    327.             this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
    328.             //
    329.             // Form1
    330.             //
    331.             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    332.             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    333.             this.ClientSize = new System.Drawing.Size(533, 320);
    334.             this.Controls.Add(this.panel12);
    335.             this.Controls.Add(this.panel11);
    336.             this.Controls.Add(this.panel2);
    337.             this.Controls.Add(this.panel1);
    338.             this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
    339.             this.Name = "Form1";
    340.             this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
    341.             this.Text = "sip";
    342.             this.TopMost = true;
    343.             this.panel1.ResumeLayout(false);
    344.             this.panel2.ResumeLayout(false);
    345.             this.panel3.ResumeLayout(false);
    346.             this.panel4.ResumeLayout(false);
    347.             this.panel5.ResumeLayout(false);
    348.             this.panel6.ResumeLayout(false);
    349.             this.panel7.ResumeLayout(false);
    350.             this.panel8.ResumeLayout(false);
    351.             this.panel9.ResumeLayout(false);
    352.             this.panel10.ResumeLayout(false);
    353.             this.panel11.ResumeLayout(false);
    354.             this.panel12.ResumeLayout(false);
    355.             this.ResumeLayout(false);
    356.  
    357.         }
    358.  
    359.         #endregion
    360.  
    361.         private System.Windows.Forms.Panel panel1;
    362.         private System.Windows.Forms.Button b4;
    363.         private System.Windows.Forms.Button b8;
    364.         private System.Windows.Forms.Panel panel2;
    365.         private System.Windows.Forms.Panel panel5;
    366.         private System.Windows.Forms.Panel panel9;
    367.         private System.Windows.Forms.Button b64;
    368.         private System.Windows.Forms.Panel panel8;
    369.         private System.Windows.Forms.Button b32;
    370.         private System.Windows.Forms.Panel panel7;
    371.         private System.Windows.Forms.Button b16;
    372.         private System.Windows.Forms.Panel panel4;
    373.         private System.Windows.Forms.Panel panel10;
    374.         private System.Windows.Forms.Button b96;
    375.         private System.Windows.Forms.Panel panel6;
    376.         private System.Windows.Forms.Button b48;
    377.         private System.Windows.Forms.Panel panel3;
    378.         private System.Windows.Forms.Button b112;
    379.         private System.Windows.Forms.Panel panel11;
    380.         private System.Windows.Forms.Button b2;
    381.         private System.Windows.Forms.Panel panel12;
    382.         private System.Windows.Forms.Button b1;
    383.         private System.Windows.Forms.Timer timer1;
    384.     }
    385. }
    386.  
    Form1.cs
    Code (Text):
    1. using System;
    2. using System.Collections.Generic;
    3. using System.ComponentModel;
    4. using System.Data;
    5. using System.Drawing;
    6. using System.Linq;
    7. using System.Text;
    8. using System.Windows.Forms;
    9.  
    10. namespace csip_demo_wfa
    11. {
    12.     public partial class Form1 : Form
    13.     {
    14.         public Form1()
    15.         {
    16.             InitializeComponent();
    17.         }
    18.  
    19.         private int counter = 0;
    20.  
    21.         private void timer1_Tick(object sender, EventArgs e)
    22.         {
    23.             Console.WriteLine(counter.ToString());
    24.  
    25.             displayVal(counter);
    26.  
    27.             if (counter < 128)
    28.             {
    29.                 counter++;
    30.             }
    31.             else
    32.             {
    33.                 counter = 0;
    34.             }
    35.  
    36.         }
    37.  
    38.  
    39.         private void displayVal(int val)
    40.         {
    41.             b1Update(val);
    42.             b2Update(val);
    43.             b4Update(val);
    44.             b8Update(val);
    45.             b16Update(val);
    46.             b32Update(val);
    47.             b64Update(val);
    48.             b48Update(val);
    49.             b96Update(val);
    50.             b112Update(val);
    51.         }
    52.  
    53.         private void b1Update(int val)
    54.         {
    55.             Boolean buttonDepressed = false;
    56.             Byte[] bValA = {System.Convert.ToByte(val)};
    57.             System.Collections.BitArray bVal = new System.Collections.BitArray(bValA);
    58.             buttonDepressed = bVal.Get(0);
    59.             if (buttonDepressed)
    60.             {
    61.                 b1.Text = "";
    62.             }
    63.             else
    64.             {
    65.                 b1.Text = (1 + val).ToString();
    66.             }
    67.             return;
    68.         }
    69.  
    70.         private void b2Update(int val)
    71.         {
    72.             Boolean buttonDepressed = false;
    73.             Byte[] bValA = { System.Convert.ToByte(val) };
    74.             System.Collections.BitArray bVal = new System.Collections.BitArray(bValA);
    75.             buttonDepressed = bVal.Get(1);
    76.             if (buttonDepressed)
    77.             {
    78.                 b2.Text = "";
    79.             }
    80.             else
    81.             {
    82.                 b2.Text = (2 + val).ToString();
    83.             }
    84.             return;
    85.         }
    86.  
    87.  
    88.         private string buttonString(int BVAL, System.Collections.BitArray depressions, int CURVAL)
    89.         {
    90.             string ret = "";
    91.  
    92.             if (depressions.Get(0) && !depressions.Get(1))
    93.             {
    94.                 ret = (BVAL + CURVAL).ToString() + " " + (1 + BVAL + CURVAL).ToString();
    95.             }
    96.             else if (!depressions.Get(0) && depressions.Get(1))
    97.             {
    98.                 ret = (2 + BVAL + CURVAL).ToString() + " " + (BVAL + CURVAL).ToString();
    99.             }
    100.             else if (!depressions.Get(0) && !depressions.Get(1))
    101.             {
    102.                 ret = (2 + BVAL + CURVAL).ToString() + " " + (BVAL + CURVAL).ToString() + " " + (1 + BVAL + CURVAL).ToString();
    103.             }
    104.             else if (depressions.Get(0) && depressions.Get(1))
    105.             {
    106.                 ret = (BVAL + CURVAL).ToString();
    107.             }
    108.             return ret;
    109.         }
    110.  
    111.         private void b4Update(int val)
    112.         {
    113.             Boolean buttonDepressed = false;
    114.             Byte[] bValA = { System.Convert.ToByte(val) };
    115.             System.Collections.BitArray bVal = new System.Collections.BitArray(bValA);
    116.             buttonDepressed = bVal.Get(2);
    117.             if (buttonDepressed)
    118.             {
    119.                 b4.Text = "";
    120.             }
    121.             else
    122.             {                
    123.                 b4.Text = buttonString(4, bVal, val);
    124.             }
    125.             return;
    126.         }
    127.  
    128.         private void b8Update(int val)
    129.         {
    130.             Boolean buttonDepressed = false;
    131.             Byte[] bValA = { System.Convert.ToByte(val) };
    132.             System.Collections.BitArray bVal = new System.Collections.BitArray(bValA);
    133.             buttonDepressed = bVal.Get(3);
    134.             if (buttonDepressed)
    135.             {
    136.                 b8.Text = "";
    137.             }
    138.             else
    139.             {
    140.                 b8.Text = buttonString(8, bVal, val);                
    141.             }
    142.             return;
    143.         }
    144.  
    145.         private void b16Update(int val)
    146.         {
    147.             Boolean buttonDepressed = false;
    148.             Byte[] bValA = { System.Convert.ToByte(val) };
    149.             System.Collections.BitArray bVal = new System.Collections.BitArray(bValA);
    150.             buttonDepressed = bVal.Get(4);
    151.             if (buttonDepressed)
    152.             {
    153.                 b16.Text = "";
    154.             }
    155.             else
    156.             {
    157.                 b16.Text = buttonString(16, bVal, val);                
    158.             }
    159.             return;
    160.         }
    161.  
    162.         private void b32Update(int val)
    163.         {
    164.             Boolean buttonDepressed = false;
    165.             Byte[] bValA = { System.Convert.ToByte(val) };
    166.             System.Collections.BitArray bVal = new System.Collections.BitArray(bValA);
    167.             buttonDepressed = bVal.Get(5);
    168.             if (buttonDepressed)
    169.             {
    170.                 b32.Text = "";
    171.             }
    172.             else
    173.             {
    174.                 b32.Text = buttonString(32, bVal, val);
    175.             }
    176.             return;
    177.         }
    178.  
    179.         private void b64Update(int val)
    180.         {
    181.             Boolean buttonDepressed = false;
    182.             Byte[] bValA = { System.Convert.ToByte(val) };
    183.             System.Collections.BitArray bVal = new System.Collections.BitArray(bValA);
    184.             buttonDepressed = bVal.Get(6);
    185.             if (buttonDepressed)
    186.             {
    187.                 b64.Text = "";
    188.             }
    189.             else
    190.             {
    191.                 b64.Text = buttonString(64, bVal, val);                
    192.             }
    193.             return;
    194.         }
    195.  
    196.         private void b48Update(int val)
    197.         {
    198.             Boolean buttonDepressed = false;
    199.             Byte[] bValA = { System.Convert.ToByte(val) };
    200.             System.Collections.BitArray bVal = new System.Collections.BitArray(bValA);
    201.             buttonDepressed = bVal.Get(4) && bVal.Get(5);
    202.             if (buttonDepressed)
    203.             {
    204.                 b48.Text = "";
    205.             }
    206.             else
    207.             {
    208.                 b48.Text = buttonString(48, bVal, val);                
    209.             }
    210.             return;
    211.         }
    212.  
    213.         private void b96Update(int val)
    214.         {
    215.             Boolean buttonDepressed = false;
    216.             Byte[] bValA = { System.Convert.ToByte(val) };
    217.             System.Collections.BitArray bVal = new System.Collections.BitArray(bValA);
    218.             buttonDepressed = bVal.Get(5) && bVal.Get(6);
    219.             if (buttonDepressed)
    220.             {
    221.                 b96.Text = "";
    222.             }
    223.             else
    224.             {
    225.                 b96.Text = buttonString(96, bVal, val);                
    226.             }
    227.             return;
    228.         }
    229.  
    230.         private void b112Update(int val)
    231.         {
    232.             Boolean buttonDepressed = false;
    233.             Byte[] bValA = { System.Convert.ToByte(val) };
    234.             System.Collections.BitArray bVal = new System.Collections.BitArray(bValA);
    235.             buttonDepressed = bVal.Get(5) && bVal.Get(6) && bVal.Get(4);
    236.             if (buttonDepressed)
    237.             {
    238.                 b112.Text = "";
    239.             }
    240.             else
    241.             {
    242.                 b112.Text = buttonString(112, bVal, val);                
    243.             }
    244.             return;
    245.         }
    246.     }
    247. }
    248.  


    thanks all!
     



    1. Download the Forums for Android™ app!


      Download

       
  2. Unforgiven

    Unforgiven ...eschew obfuscation...
    Moderator

    I moved this over to the Dev 101 forum where I think you will get better answers.:)
     
  3. Tramontana

    Tramontana Newbie

    As a 100% Linux user I can't run c# - or if I can I don't know how. So a picture would have been better than code. But I do know how to make a graphic screen on Android with any conceivable layout of buttons, and attach event handlers to each one. It's fairly complex so I can't separate out usable code from the app it's part of (Easy Coder) but I might be able to give some hints if this is the general area you're looking in.
     
  4. nosenseofhumor

    Thread Starter

    Thanks, any starting point is helpful.
    Sorry about the c#, .net languages are really all im any good for. the html i posted kinda give an indication of what i wanted the keyboard to look like. I cant post a screen shot because im a new user. the rules said i have to wait for a while. Ill give it a shot anyway, sample

    edit: ah, it worked!

    Could you link me to the example you were talking about? I didnt see it on easy coder.

    thanks!
     
  5. nosenseofhumor

    Thread Starter

    Also, it is important that it is a keyboard, it should be installable as a keyboard and, if selected as the default keyboard should persist from app to app... just like any other keyboard
     
  6. Tramontana

    Tramontana Newbie

    I didn't mean to imply I had a layout resembling your (curious but very interesting) one. A graphic array of buttons is quite straightforward, however; the closest Easy Coder example would be the calculator. The size and positioning issues are trivial; the biggest part of the job is that of managing the various buttons so each one reports when it's tapped. For this I create a stack of individual "button" objects each of which knows its own size, position, etc, how to draw itself when passed a Canvas and what to do when tapped. The entire stack is managed by a "stage" object that extends View and overrides onDraw() and onTouch(). In the latter it calls each button in turn from front to back (to allow for overlapping) to see if the tap happened inside its boundary, whether it's a drag gesture etc.

    I hope this helps a little.

    (P.S. I'm not yet experienced enough to know how to set up and install a system keyboard or other services, but you've now got me wondering if I could get Easy Coder to do such things.)
     
Loading...

Share This Page

Loading...