Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Saturday 25 October 2014

How to use Login Dialog Box in Android Mono C#


For This small demo project we require the following file structure

Main.axml file that contains code for hello world button on which we place button that will further generate the Dialog Box for Login Activity

Main.cs file Now this file will contain the code for Main.axml actions and events

Login.axml file that will contain the code that will contain the style or pattern how the login dialog will look all .axml design code for login form will reside here


AXML Code For Login  Dialog Box  ( login .axml ) file code

Design Look -





It is a simple code that contains a linear layout that will place all controls in linear order as they are placed in it Then we have placed two Edittext for allowing the user to enter username in first and Password in second . Then we have placed two buttons One for login and second for cancellation of login .

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_height="match_parent"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:background="#fff"
    android:layout_width="300dp"
    android:paddingTop="10dp">
    <EditText
        android:layout_height="wrap_content"
        android:id="@+id/txtUsername"
        android:layout_width="match_parent">
        <requestFocus />
    </EditText>
    <EditText
        android:layout_height="wrap_content"
        android:inputType="textPassword"
        android:id="@+id/txtPassword"
        android:layout_width="match_parent" />
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/linearLayout1">
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.5"
            android:id="@+id/btnLogin"
            android:text="Login" />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.5"
            android:id="@+id/btnCancel"
            android:text="Cancel" />
    </LinearLayout>
</LinearLayout>

XAML code for Main .axml file 

Design Look -




<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_height="match_parent"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:background="#fff"
    android:layout_width="300dp"
    android:paddingTop="10dp">
 
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.5"
            android:id="@+id/hello"
            android:text="Hello world!" />
 
</LinearLayout>


C# Code for Main.cs file 


 protected override void OnCreate(Bundle bundle)
{
 base.OnCreate(bundle);
 SetContentView(Resource.Layout.Main);
 TextView hellobtn = FindViewById<TextView>(Resource.Id.hello);
 hellobtn.Click += btnclick;
}

void btnclick(object sender, EventArgs e)
        {

            Dialog login = new Dialog(this);
            login.SetContentView(Resource.Layout.login);
            login.Show();
}

Explanation of Code 

PART I

protected override void OnCreate(Bundle bundle)
{
 base.OnCreate(bundle);
 SetContentView(Resource.Layout.Main);
 TextView hellobtn = FindViewById<TextView>(Resource.Id.hello);
 hellobtn.Click += loginclick;
}

In above code First i have used OnCreate Method that is startup method when an android application starts it first load up everything in OnCreate Method and Create their space in memory

SetContentView(Resource.Layout.Main);

Then at this line i have set what layout will this code is meant for I have choosen Main layout in Resource folder whose design preview is shown in images above

 Button loginbtn = FindViewById<Button>(Resource.Id.btnLogin);

Then at this line i have made instance of button and set that textview to the hello world button that i have placed on Main form I have used FindviewById method to find the button and then assign that button to hellobtn

Then at this line i have assigned click event to button by using following line of code

 hellobtn.Click += btnclick;

Then i have given definition to btnclick funtion in code below

PART I

void btnclick(object sender, EventArgs e)
        {

            Dialog login = new Dialog(this);
            login.SetContentView(Resource.Layout.login);
            login.Show();
}

In this code i have made Instance of Dialog class for showing dialog box on screen i have created new class instance then i have set what view will be shown on dialog that is going to appear i have set the view contentview to login.axml content view that i have designed earlier in this article then i have used show( ) function to show login dialog box


Friday 24 October 2014

Star Pattern Programs Cplusplus

Program To Print Following Star Pattern in Cpluplus


Star Pattern in Cpluplus


#include<iostream.h>
void main()
{
   int i,j,k,n;
   cout<<"\Enter the number of lines to be printed: ";
    cin>>n;
   for(i=0;i<n;i++)
   {
      for(j=0;j<(n-i-1);j++)
 cout<<" ";
      for(k=0;k<(2*i+1);k++)
 cout<<"*";
      cout<<endl;
   }
      for(i=0;i<n-1;i++)
   {
      for(j=0;j<=i;j++)
cout<<" ";
      for(k=(2*n-2*i-3);k>0;k--)
   cout<<"*";
      cout<<endl;
   }
}

 

Program To Print Following Star Pattern in Cpluplus

Star Pattern in Cpluplus

Star Pattern in Cpluplus



#include<iostream.h>
void main()
{
 int i,j,k,n;
 cout<<"\Enter the number of lines to be printed: ";
 cin>>n;
 for(i=0;i<n;i++)
 {
       for(j=n-i-1;j>0;j--)
     cout<<" ";
       cout<<"*";
       for(k=2*i-1;k>0;k--)
     cout<<" ";             //code for upper triangle
       if(i!=0)
     cout<<"*";
       cout<<endl;
  }
  for(i=n-1;i>0;i--)
  {
       for(j=0;j<n-i;j++)
     cout<<" ";
       cout<<"*";                  //code for lower triangle
for(k=2*i-3;k>0;k--)
    cout<<" ";
       if(i!=1)
     cout<<"*";
       cout<<"\n";
    }
}

 

Program To Create Circular Loading Bar using Graphics.h


#include<graphics.h>

#include<dos.h>

void main()
{
int gd=DETECT,gm; 
              // variable to detect graphics driver and graphic mode

 int counter;   

//Below is code to initialize the graphics with parameters for graphics initgraph(&gd,&gm,"c:\\turboc3\\bgi");

//Loop to show the loading circle for(counter=0;counter<=360;++counter)
{
circle(300,200,80);
pieslice(300,200,0,counter,80);
outtextxy(200,320,"Loading....Please Wait!");
delay(20);
}
closegraph();
}

OUTPUT :
Program To Create Circular Loading Bar graphics.h cplusplus
Program To Create Circular Loading Bar graphics.h cplusplus




Program To Create Loading Bar using Graphics.h


#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>

void main()
{
 int x=170,i,gdriver=DETECT,gmode;
  // variable to detect graphics driver and graphic mode

//Below is code to initialize the graphics with parameters for graphics
 initgraph(&gdriver,&gmode,"c:\\tc\\bgi");

 settextstyle(DEFAULT_FONT,HORIZ_DIR,2);

//Outtextxy is used to print the given text at specified x and y pixel position 
//It will print given text at pixel position 170,180
 outtextxy(170,180,"LOADING,PLEASE WAIT");

  for(i=0;i<300;++i)
 {
  delay(30);
  line(x,200,x,220);
  x++;
 }
 getch();

//close the graph that was initialized
 closegraph();  

}

OUTPUT :
Program To Create Loading Bar using Graphics.h Cplusplus
Program To Create Loading Bar using Graphics.h Cplusplus


Program To Print Star Triangle Pattern in Cplusplus


#include<iostream.h>
#include<conio.h>

void main()
{
clrscr(); //to clear the screen
int i,j,k,num;

cout<<"Tell How many lines you want";
cin>>num;

num*=2;
for(i=0;i<num;i+=2)
{
cout<<"\n";

for ( j = num; j > i; j -= 2 )
cout<<" ";

for( k=0; k<=i; ++k )
cout<<"*";
}
getch(); //to stop the screen
}
OUTPUT


Program To Print Star Triangle Pattern Cplusplus
Program To Print Star Triangle Pattern Cplusplus

Program To Print Alphabets in Cplusplus ( I have printed A to H ) 


#include<iostream>

using namespace std;

int main()
{
int i,j,k=1;
char ch;
cout<<"Input an Alphabet in capital letters that you want to print:";
cin>>ch;
cout<<"\n\n\n\n";
switch(ch)
{
case 'A':
cout<<"\t\t\t    ";
for(i=1;i<=40;++i)
{
for(j=0;j<=22;++j)
{
if(i==1||i==2||i==21||i==20)
cout<<"*";
else
{
if(j==0||j==20)
cout<<"**";
else
cout<<" ";
}
}
cout<<"\n\t\t\t    ";

}
break;



case 'B':
cout<<"\t\t\t\t";

while(k<=2)
{
for(i=1;i<=9;++i)
{
for(j=0;j<=i;++j)
{
if(j==0||j==i)
cout<<"**";
else
cout<<" ";
}

cout<<"\n\t\t\t\t";

}
for(i=1;i<=10;++i)
{
if(i==1||i==10)
cout<<"**";
else
cout<<" ";
}
cout<<"\n\t\t\t\t";

for(i=1;i<=10;++i)
{
if(i==1||i==10)
cout<<"**";
else
cout<<" ";
}
cout<<"\n\t\t\t\t";

for(i=9;i>=1;--i)
{
for(j=0;j<=i;++j)
{
if(j==0||j==i)
cout<<"**";
else
cout<<" ";
}
cout<<"\n\t\t\t\t";
}
++k;
}
 break;

 case'C':
cout<<"\t\t\t    ";

for(i=1;i<=40;++i)
{
for(j=0;j<=22;++j)
{
if(i==1||i==2||i==39||i==40)
cout<<"*";
else
{
if(j==0)
cout<<"**";
else
cout<<" ";
}
}
cout<<"\n\t\t\t    ";

}
break;

 case'D':
 cout<<"\t\t\t\t";
 for(i=1;i<=18;++i)
 {
for(j=0;j<=i;++j)
{
if(j==0||j==i)
cout<<"**";
else
cout<<" ";
}
cout<<"\n\t\t\t\t";
 }
 while(k<=4)
 {
for(i=1;i<=19;++i)
{
if(i==1||i==19)
cout<<"**";
else
cout<<" ";
}
cout<<"\n\t\t\t\t";
 ++k;
 }
 for(i=18;i>=1;--i)
 {
for(j=0;j<=i;++j)
{
if(j==0||j==i)
cout<<"**";
else
cout<<" ";
}
 cout<<"\n\t\t\t\t";
 }
 break;

 case'E':

 cout<<"\t\t\t\t";
 for(i=1;i<=39;++i)
 {
for(j=1;j<=20;++j)
{
if(i==1||i==2||i==20||i==21||i==38||i==39)
cout<<"*";
else
{
if(j==1)
cout<<"**";
else
cout<<" ";
}
}
 cout<<"\n\t\t\t\t";
 }
 break;

 case'F':

 cout<<"\t\t\t\t";

for(i=1;i<=40;++i)
{
for(j=1;j<=20;++j)
{
if(i==1||i==2||i==18||i==19)
cout<<"*";
else
{
if(j==1)
cout<<"**";
else
cout<<" ";
}
}
cout<<"\n\t\t\t\t";
}
break;

 case'G':

cout<<"\t\t\t";
for(i=1;i<=25;++i)
{
for(j=1;j<=20;++j)
{
if(i==1||i==2)
cout<<"*";
else
{
if(j==1)
cout<<"**";
else
cout<<" ";
}
}
cout<<"\n\t\t\t";
}
for(i=1;i<=10;++i)
{
for(j=1;j<=20;++j)
{
if(i==1||i==2)
{ if(j==1||j==14||j==15||j==16)
cout<<"**";
  else
  cout<<" ";
}
else
{
if(i==9||i==10)
cout<<"*";
else
{  if(j==1||j==18)
  cout<<"**";
  else
  cout<<" ";
}
}
}
cout<<"\n\t\t\t";
}
break;


 case'H':

cout<<"\t\t\t";
for(i=1;i<=40;++i)
{
for(j=1;j<=21;++j)
{
if(i==20||i==21)
cout<<"*";
else
{
if(j==1||j==19)
cout<<"**";
else
cout<<" ";
}
}
cout<<"\n\t\t\t";
}
break;

return 0;
}

OUTPUT :



Saturday 4 October 2014

\adt-bundle-windows-x86_64-20130219\sdk\platform-tools\aapt.exe is invalid

When your are using Android with Csharp or when you are using Monoandroid you will be facing some some error related to aapt.exe missing or aapt.exe invalid . These are common error to Monoandroid developer that almost every one that uses Monoandroid will face .

So Today I decided to get the actual reason of this problem and I sit on my chair to find out the reason and possible solution to this error that may work for everyone . I suffered from this error number of times before but i tried the ways to get rid of it But not today this is the day to get solution of this error .

What are Possible Errors :



  • Error MSB6004: The specified task executable location "C:\Program


  • Files\adt-bundle-windows-x86_64-20130219\sdk\platform-tools\aapt.exe" is 


invalid. (MSB6004) (TaskyAndroid)

The specified task executable location "D:\android-sdk\platform-tools

\aapt.exe" is invalid.


Reason of Above Errors 




This issue is caused by Google changing around the directory structure of the Android SDK with their latest updates and due to these updates old directory structures are creating problem Most probably these error comes after you update your android So when you update your android-sdk then it update the directory structure of android-sdk to new structure of google that allows
aapt.exe to be must present in android-sdk/platform-tools/ but that will be not there because in old directory structure that monoandroid is using aapt.exe is in android-sdk/build-tools/ that's why this error is coming and MonoAndroid Team is applying these changes so  before that we need to figure out this issue to continue our development

Error Solution aapt.exe Invalid


Steps :-

1.  Copy the aapt.exe file from folder \android-sdk\build-tools\17.0.0 to \android-sdk\platform-tools . Here 17.0.0 is your android api you have installed in your sdk it will be what version you installed like :- 8.0.0, 18.0.0

2. Now Also Copy \android-sdk\build-tools\17.0.0\lib folder to \android-sdk\platform-tools\ As there is a file in that directory dx.jar which is also Needed by xamarin

3. Now Everything will be fine ........Cheers!


There is one more error which can let you suffer it is :-

java exited with code 1


Reason of Error java exited with code 1

The reason of this error is in our previous error solution When you copy the aapt.exe file from  \android-sdk\build-tools\17.0.0 to \android-sdk\platform-tools .  and forger to copy or don't copy folder  \android-sdk\build-tools\17.0.0\lib folder to \android-sdk\platform-tools\ then this error comes this is main reason of this error

Error Solution java exited with code 1



 Also Copy \android-sdk\build-tools\17.0.0\lib folder to \android-sdk\platform-tools\ As there is a file in that directory dx.jar which is also Needed by xamarin after copying aapt.exe file