Monday, 15 August 2022

WHAT'S NEW IN . C# 10

 

Global Using Staments
File Scoped Namespaces

Const Interpolation String

Tuesday, 2 February 2021

ANDROID STUDIO PRACTICAL : LINK ACTIVITIES WITH INTENT : CS619

 




TO DOWNLOAD COMPLETE CODE
CLICK ON LINK BELOW



Screen 1 layout file

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:gravity="center"
    android:layout_margin="15dp"
    android:orientation="vertical">

    <TextView
        android:layout_width="wrap_content"
        android:text="Login Screen"
        android:textSize="30sp"
        android:layout_margin="20dp"
        android:layout_height="wrap_content"></TextView>

    <EditText
        android:layout_margin="15dp"
        android:layout_width="match_parent"
        android:id="@+id/etUsername"
        android:hint="Enter Your ID"
        android:layout_height="wrap_content"></EditText>

    <EditText
        android:inputType="numberPassword"
        android:layout_margin="15dp"
        android:layout_width="match_parent"
        android:id="@+id/etPassword"
        android:hint="Enter Your Password"
        android:layout_height="wrap_content"></EditText>

    <Button
        android:onClick="btnLoginClick"
        android:layout_width="wrap_content"
        android:text="Login"
        android:id="@+id/btnLogin"
        android:layout_height="wrap_content"></Button>
</LinearLayout>

.............
Screen 1 Java File

package com.example.intents;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import javax.xml.transform.Source;

public class Screen1 extends AppCompatActivity
{
    EditText etUsername;
    EditText etPassword;
    String myUsername = "bs130200310";
    String myPassword = "111111111";
    String myName = "Rehan Attari";

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_screen1);

        etUsername = findViewById(R.id.etUsername);
        etPassword = findViewById(R.id.etPassword);

    }

    public void btnLoginClick(View view)
    {
        String inputUsername = etUsername.getText().toString();
        String inputPassword = etPassword.getText().toString();

        if (inputUsername.equals(myUsername) && inputPassword.equals(myPassword))
        {
            Toast.makeText(this, "Login Success", Toast.LENGTH_SHORT).show();
            Intent intent = new Intent(Screen1.this, Screen2.class);
            intent.putExtra("key", myName);
            startActivity(intent);

        } else
        {
            Toast.makeText(this, "Invalid Username Or Password. Please Try again", Toast.LENGTH_SHORT).show();
        }
    }
}

..........
Screen 2 layout file

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:gravity="center"
    android:orientation="vertical">

<TextView
    android:id="@+id/tv"
    android:textSize="30sp"
    android:layout_width="wrap_content"
    android:text="Welcome"
    android:layout_height="wrap_content"></TextView>
</LinearLayout>


......

Screen 2 Java File

package com.example.intents;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

public class Screen2 extends AppCompatActivity
{
    TextView tv;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_screen2);

        tv = findViewById(R.id.tv);

        Intent intent = getIntent();

        String receivedName = intent.getStringExtra("key");

        tv.setText("Welcome : " + receivedName);

    }
}

Monday, 25 January 2021

ANDROID STUDIO APP 2



xml code

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

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:layout_gravity="center"

    android:gravity="center"

    android:padding="20dp"

    android:orientation="vertical">


    <TextView

        android:layout_width="wrap_content"

        android:text="Addition Calcluator"

        android:textSize="30dp"

        android:layout_marginBottom="30dp"

        android:layout_height="wrap_content"></TextView>


    <EditText

        android:id="@+id/et1"

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:hint="Enter Value 1"

        android:inputType="numberSigned"></EditText>


    <EditText

        android:id="@+id/et2"

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:hint="Enter Value 2"

        android:inputType="numberSigned"></EditText>


    <Button

        android:onClick="getAnswer"

        android:id="@+id/btnAdd"

        android:layout_marginTop="20dp"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="Add"></Button>


    <TextView

        android:layout_marginTop="20dp"

        android:textSize="30dp"

        android:layout_width="wrap_content"

        android:id="@+id/tvAnswer"

        android:layout_height="wrap_content"></TextView>

</LinearLayout>



package com.example.additioncalculatorapp2;


import androidx.appcompat.app.AppCompatActivity;


import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import android.widget.TextView;

import android.widget.Toast;


public class MainActivity extends AppCompatActivity

{


    @Override

    protected void onCreate(Bundle savedInstanceState)

    {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

    }


    public void getAnswer(View view)

    {

        // linking to layout xml file

        EditText editText1 = findViewById(R.id.et1);

        EditText editText2 = findViewById(R.id.et2);

        TextView tvAns = findViewById(R.id.tvAnswer);


        int input1 = Integer.parseInt ( editText1.getText().toString() );

        int input2 = Integer.parseInt ( editText2.getText().toString() );


        int answer = input1 + input2;

        

        tvAns.setText(String.valueOf(answer));

        

        Toast.makeText(this, String.valueOf(answer), Toast.LENGTH_SHORT).show();


    }

}

Tuesday, 27 October 2020

Monday, 26 October 2020

HOW TO USE MATERIAL DESIGN IN WPF

 STEPS TO ADD MATERIAL DESIGN UI LIBRARY IN WPF APPLICATION

1.

  • Install MaterialDesignThemes nuget: Install-Package MaterialDesignTheme
2.
  • Edit App.xaml to following:
<Application . . .
    xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <materialDesign:BundledTheme BaseTheme="Light" PrimaryColor="DeepPurple" SecondaryColor="Lime" />
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

3.
<Window . . .
        xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
        TextElement.Foreground="{DynamicResource MaterialDesignBody}"
        TextElement.FontWeight="Regular"
        TextElement.FontSize="13"
        TextOptions.TextFormattingMode="Ideal" 
        TextOptions.TextRenderingMode="Auto"        
        Background="{DynamicResource MaterialDesignPaper}"
        FontFamily="{DynamicResource MaterialDesignFont}">
    <Grid>
        <StackPanel>
            <materialDesign:Card Padding="32" Margin="16">
                <TextBlock Style="{DynamicResource MaterialDesignHeadline6TextBlock}">My First Material Design App</TextBlock>
            </materialDesign:Card>
        </StackPanel>
    </Grid>
</Window>