Search This Blog

Tuesday 12 July 2016

How To Show Circle Progress Bar

<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/dark_grey" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="10dp" android:text="Raw Material Availability" android:layout_marginLeft="10dp" android:textColor="@color/white" android:textSize="20sp" android:textStyle="bold" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#2196f3" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:padding="20dp" android:orientation="horizontal"> <Button android:layout_width="100sp" android:layout_height="100sp" android:background="@drawable/mybutton" android:gravity="center" android:layout_gravity="center" android:text="Full" android:textColor="@color/white"/> </LinearLayout> </LinearLayout>

Monday 11 July 2016

JSON Example

MainActivity.CS:-

using Android.App;
using Android.Widget;
using Android.OS;
using System.Collections.Generic;

namespace JsonServies
{
[Activity (Label = "JsonServies", MainLauncher = true, Icon = "@mipmap/icon")]
public class MainActivity : Activity
{
protected override void OnCreate (Bundle savedInstanceState)
{
base.OnCreate (savedInstanceState);

// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);

ListView lstPersons = (ListView)FindViewById (Resource.Id.lstPersons);

Services obj = new Services ();
obj.GetMovieData (this,lstPersons);
}
}
}


Main.AXML:-

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ListView
        android:id="@+id/lstPersons"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</LinearLayout>


Movies.CS:-

using System;
using System.Collections.Generic;

namespace JsonServies
{
public class Movie
{
public Movie ()
{
}

public string name { get; set; }
public string height { get; set; }
public string mass { get; set; }
public string hair_color { get; set; }
public string skin_color { get; set; }
public string eye_color { get; set; }
public string birth_year { get; set; }
public string gender { get; set; }
public string homeworld { get; set; }
public List<string> films { get; set; }
public List<string> species { get; set; }
public List<object> vehicles { get; set; }
public List<object> starships { get; set; }
public string created { get; set; }
public string edited { get; set; }
public string url { get; set; }
}
}



Services.CS:-

using System;
using System.Net;
using Newtonsoft.Json;
using System.Collections.Generic;
using Android.Widget;
using Android.App;

namespace JsonServies
{
public class Services
{
List<Movie> objList;
public Services ()
{
}
public void GetMovieData(Activity act, ListView lstMovies){

WebClient objWebClient = new WebClient ();
objWebClient.DownloadStringCompleted += async
delegate(object sender, DownloadStringCompletedEventArgs e) {
Activity.RunOnUiThread(() => {
List<Movie> objList=JsonConvert.DeserializeObject<List<Movie>>(e.Result.ToString());
});
};
objWebClient.DownloadStringAsync (new Uri ("http://swapi.co/api/people/2/"));
}
}
}





Navigation,Send Data,Toast Example

-> Toast Message:-
Toast.MakeText(this,"Message",ToastLength.Short).Show();

-> Page Navigation:-
Intent<Obj Name>=new Intent(this,typeof(<Target Activity>));
StartActivity (objintent);

-> Pass The Data From One Page To Another Page:-
<Obj Name>.PutExtra ("<Key>",<Data>.ToString());
 StartActivity (objintent);

-> Recive Data From One Page to This Page:-
String <Obj Name> =Intent.GetStringExtra ("Key");

Sunday 10 July 2016

SQLite Example in Xamarin

LoginAdopter.CS:-

using System;
using Android.Widget;
using System.Collections.Generic;
using Android.App;
using Android.Views;
namespace SQLiteExample
{
public class LoginAdapter:BaseAdapter
{
List<Registration> ObjRegistration;
Activity act;
public LoginAdapter (Activity act,List<Registration> ObjRegistration)
{
this.act = act;
this.ObjRegistration = ObjRegistration;
}
public override Java.Lang.Object GetItem (int position)
{
return position;
}
public override long GetItemId (int position)
{
return position;
}
public override Android.Views.View GetView (int position, Android.Views.View convertView, Android.Views.ViewGroup parent)
{
View rootView = act.LayoutInflater.Inflate (Resource.Layout.LayoutItem, parent, false);
TextView tvUsername = rootView.FindViewById<TextView> (Resource.Id.tvUsername);
TextView tvPassword= rootView.FindViewById<TextView> (Resource.Id.tvPassword);
Registration item = ObjRegistration [position];
tvUsername.Text = item.UserName;
tvPassword.Text = item.Password;
return rootView;
}
public override int Count {
get {
return ObjRegistration.Count;
}
}
}
}


App.CS:-

using System;
using SQLite;

namespace SQLiteExample
{
public class App
{
public App ()
{
}

public static SQLiteConnection conn;
}
}
Main.AXML:-

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <EditText
        android:id="@+id/etUserName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Enter User Name" />
    <EditText
        android:id="@+id/etPassword"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:hint="Enter password" />
    <Button
        android:id="@+id/btnSubmit"
        android:layout_marginTop="20dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Submit" />
    <Button
        android:id="@+id/login"
        android:layout_marginTop="20dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="login Page" />
    <ListView
        android:id="@+id/lstLoginDetails"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>


MainActivity.CS:-

using Android.App;
using Android.Widget;
using SQLite;
using System;
using Android.OS;
using Android.Content;
using System.Collections.Generic;
using System.Linq;
namespace SQLiteExample
{
[Activity (Label = "SQLiteExample", MainLauncher = true, Icon = "@mipmap/icon")]
public class MainActivity : Activity
{
protected override void OnCreate (Bundle savedInstanceState)
{
base.OnCreate (savedInstanceState);
SetContentView (Resource.Layout.Main);
CreateDatabase ();
Button btnSubmit = (Button)FindViewById (Resource.Id.btnSubmit);
Button login = (Button)FindViewById (Resource.Id.login);
login.Click += async delegate(object sender, EventArgs e) {
Intent objIntent=new Intent(this,typeof(LoginPage));
StartActivity(objIntent);
};
EditText etUserName = (EditText)FindViewById (Resource.Id.etUserName);
EditText etPassword = (EditText)FindViewById (Resource.Id.etPassword);
btnSubmit.Click += async delegate(object sender, EventArgs e) {
Registration objRegister=new Registration();
objRegister.Id=1;
objRegister.UserName=etUserName.Text;
objRegister.Password=etPassword.Text;
int i= App.conn.Insert(objRegister);
if(i==1){
Toast.MakeText(this,"Successfully Inserted",ToastLength.Long).Show();
}else{
Toast.MakeText(this,"some thing went wrong. Please reinsert once.",ToastLength.Long).Show();
}
List<Registration> results=App.conn.Table<Registration>().ToList();
ListView logindetails = (ListView)FindViewById(Resource.Id.lstLoginDetails);
LoginAdapter ObjLoginAdapter = new LoginAdapter(this,results);
logindetails.Adapter=ObjLoginAdapter;
};
}
private void CreateDatabase(){
string folder = System.Environment.GetFolderPath (System.Environment.SpecialFolder.Personal);
App.conn = new SQLiteConnection (System.IO.Path.Combine (folder, "PersonData.db"));
App.conn.CreateTable<Registration>();
}
}
}

LoginLayout.AXML:-

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <EditText
        android:id="@+id/etUserName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Enter User Name" />
    <EditText
        android:id="@+id/etPassword"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:hint="Enter password" />
    <Button
        android:id="@+id/btnLogin"
        android:layout_marginTop="20dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Login" />
</LinearLayout>

LoginPage.CS:-


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using SQLite;
namespace SQLiteExample
{
[Activity (Label = "LoginPage")]
public class LoginPage : Activity
{
SQLiteConnection con;
protected override void OnCreate (Bundle savedInstanceState)
{
base.OnCreate (savedInstanceState);
SetContentView (Resource.Layout.LoginLayout);
Button btnLogin = (Button)FindViewById (Resource.Id.btnLogin);
EditText etUserName = (EditText)FindViewById (Resource.Id.etUserName);
EditText etPassword = (EditText)FindViewById (Resource.Id.etPassword);
btnLogin.Click += async delegate(object sender, EventArgs e) {
bool isSuccess=false;
List<Registration> results=App.conn.Table<Registration>().ToList();
// foreach(var eachItem in results){
// if(eachItem.UserName==etUserName.Text&&eachItem.Password==etPassword.Text){
// Intent objIntent=new Intent(this,typeof(LoginPage));
// StartActivity(objIntent);
// break;
// isSuccess=true;
// }else{
// isSuccess=false;
//
// }
};
}
}
}
Registration.CS:-

using System;
using SQLite;

namespace SQLiteExample
{
public class Registration
{
public Registration ()
{
}

[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public string UserName { get; set; }
public string Password { get; set; }
}
}