WPF Style Button

20 2020

MainWindow.xaml

<Button x:Name="button17" Style="{StaticResource ProductButtonStyle}" Content="Blue Lagoon" >
<Button.Tag>
<ImageSource>Icons/item_blue_lagoon.png</ImageSource>
</Button.Tag>
</Button>

Application.xaml

<!-- Product Button Style -->

<Style TargetType="{x:Type Button}" x:Key="ProductButtonStyle" >
<Setter Property="Width" Value="100" />
<Setter Property="Height" Value="70" />
<Setter Property="Margin" Value="10" />
<Setter Property="FontSize" Value="15" />
<Setter Property="Background" Value="Yellow" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid
Width="{TemplateBinding Width}"
Height="{TemplateBinding Height}"
ClipToBounds="True">
<Border x:Name="ProductBorder" CornerRadius="5" BorderBrush="red" BorderThickness="0">
<Border.Background>
<LinearGradientBrush>
<GradientStop x:Name="darkblueOffset" Offset="0" Color="red"/>
<GradientStop x:Name="blueOffset" Offset="1" Color="red"/>
</LinearGradientBrush>
</Border.Background>

</Border>

<StackPanel>

<Image x:Name="ProductImage" Source ="{TemplateBinding Tag}"
Height="70"
Stretch="Fill"
HorizontalAlignment="Center"
Margin="0"
VerticalAlignment="Top">
<Image.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleY="1" ScaleX="1"/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Image.RenderTransform>
</Image>

<ContentPresenter x:Name="ProductText" Margin="0,-20,0,0" Width="Auto"
Content="{TemplateBinding Content}"
TextBlock.Foreground="White"
Panel.ZIndex="11"
Opacity="0"
HorizontalAlignment="Center" />

<Rectangle x:Name="TextBGRectagle"
HorizontalAlignment="Stretch"
Height="30"
Panel.ZIndex="10"
StrokeThickness="1" Fill="#FF555555" Opacity="0.6" >
<Rectangle.RenderTransform>
<TransformGroup>
<TranslateTransform X="0" Y="0"/>
<ScaleTransform ScaleY="1" ScaleX="1"/>
<SkewTransform/>
<RotateTransform Angle="0"/>

</TransformGroup>
</Rectangle.RenderTransform>
</Rectangle>
</StackPanel>

</Grid>

<ControlTemplate.Triggers>
<!-- Set properties when mouse pointer is over the button. -->
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Button.Effect">
<Setter.Value>
<DropShadowEffect Color="Black" Direction="270" ShadowDepth="3" BlurRadius="15" Opacity="0.7" />
</Setter.Value>

</Setter>

</Trigger>
<!-- Set properties when button has focus. -->

<!-- Animations that start when mouse enters and leaves button. -->
<EventTrigger RoutedEvent="Mouse.MouseEnter">

<EventTrigger.Actions>
<BeginStoryboard Name="mouseEnterBeginStoryboard">
<Storyboard>
<!-- This animation makes the glass rectangle shrink in the X direction. -->

<DoubleAnimation Storyboard.TargetName="TextBGRectagle"
Storyboard.TargetProperty= "(Rectangle.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.Y)"
To="-25" By="-1"
Duration="0:0:0.2" >
</DoubleAnimation>

<DoubleAnimation Storyboard.TargetName="ProductImage"
Storyboard.TargetProperty= "(Image.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)"
By="0.2"
Duration="0:0:0.2" >

</DoubleAnimation>

<DoubleAnimation Storyboard.TargetName="ProductImage"
Storyboard.TargetProperty= "(Image.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)"
By="0.2"
Duration="0:0:0.2">

</DoubleAnimation>
<DoubleAnimation Storyboard.TargetName="ProductText"
Storyboard.TargetProperty= "Opacity"
From="0" To="1" By="0.1"
Duration="0:0:0.2">

</DoubleAnimation>

</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
<EventTrigger RoutedEvent="Mouse.MouseLeave">
<EventTrigger.Actions>
<BeginStoryboard Name="mouseLeaveBeginStoryboard">
<!-- Stopping the storyboard sets all animated properties back to default. -->

<Storyboard>
<DoubleAnimation Storyboard.TargetName="ProductText"
Storyboard.TargetProperty= "Opacity"
From="1" To="0" By="0.1"
Duration="0:0:0.5">

</DoubleAnimation>
<DoubleAnimation Storyboard.TargetName="TextBGRectagle"
Storyboard.TargetProperty= "(Rectangle.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.Y)"
To="0" By="1"
Duration="0:0:0.5" >
</DoubleAnimation>

</Storyboard>
</BeginStoryboard>
<StopStoryboard BeginStoryboardName="mouseEnterBeginStoryboard"></StopStoryboard>
</EventTrigger.Actions>
</EventTrigger>

</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

<!-- End Product Button Style-->

Simple JSON Response With HTTP Status C# – Web API

03 2020

Here is a simple Snippet for JSON Response with HTTP Status Code for WEB API in C#.

Case 1 :

public class SampleController : ApiController
{
    public IHttpActionResult Post([FromBody] string value)
    {
       return Ok(new {  IntVal = 1  ,  StrVal = "TWO" } );  
    }
}

Case 2 :

public class SampleController : ApiController
{
    public IHttpActionResult Post([FromBody] string value)
    {
        int Obj1_Value = 10;
        List JSON_Return;
        JSONReturn = new List { "Object1", Obj1_Value.ToString() };
        return Ok>(JSON_Return);  
    }
}

findviewbyid in Fragments Android

16 2019

1. Add the following snippet in onCreateView() on Fragments to call the views by findviewbyid in fragments.


// R.layout.fragment_home -> Layout ID
// R.id.preorder_button -> Button ID

View rootView = inflater.inflate(R.layout.fragment_home, container, false);
Button Button_Preorder ;
Button_Preorder = rootView.findViewById(R.id.preorder_button);
return rootView;

Sample Code :

package com.xxx.yyy;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

/**
 * A simple {@link Fragment} subclass.
 * Activities that contain this fragment must implement the
 * {@link HomeFragment.OnFragmentInteractionListener} interface
 * to handle interaction events.
 * Use the {@link HomeFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class HomeFragment extends Fragment  {
    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    // TODO: Rename and change types of parameters
    private String mParam1;
    private String mParam2;

    public static Button Button_Preorder;
    private OnFragmentInteractionListener mListener;

    public HomeFragment() {
        // Required empty public constructor
    }

    /**
     * Use this factory method to create a new instance of
     * this fragment using the provided parameters.
     *
     * @param param1 Parameter 1.
     * @param param2 Parameter 2.
     * @return A new instance of fragment HomeFragment.
     */
    // TODO: Rename and change types and number of parameters
    public static HomeFragment newInstance(String param1, String param2) {
        HomeFragment fragment = new HomeFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View rootView = inflater.inflate(R.layout.fragment_home, container, false);

        Button_Preorder = rootView.findViewById(R.id.preorder_button);
        Button_Preorder.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
             }
           });
       
         return rootView;
}

// TODO: Rename method, update argument and hook method into UI event
public void onButtonPressed(Uri uri) {
if (mListener != null) {
mListener.onFragmentInteraction(uri);
}
}

@Override
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof OnFragmentInteractionListener) {
mListener = (OnFragmentInteractionListener) context;
} else {
throw new RuntimeException(context.toString()
+ " must implement OnFragmentInteractionListener");
}
}

@Override
public void onDetach() {
super.onDetach();
mListener = null;
}

/**
* This interface must be implemented by activities that contain this
* fragment to allow an interaction in this fragment to be communicated
* to the activity and potentially other fragments contained in that
* activity.
* <p>
* See the Android Training lesson <a href=
* "http://developer.android.com/training/basics/fragments/communicating.html"
* >Communicating with Other Fragments</a> for more information.
*/
public interface OnFragmentInteractionListener {
// TODO: Update argument type and name
void onFragmentInteraction(Uri uri);
}


}

Simple Fragments in Android

16 2019

1. Add the Framelayout Container in the layout where you want to show fragments.

<FrameLayout
    android:id="@+id/MainFrameContainer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

2. Import the following library.

import android.support.v4.app.FragmentTransaction;

3. Create the fragment transaction in Main Activity.

public class MainActivity extends AppCompatActivity
implements HomeFragment.OnFragmentInteractionListener {

    public HomeFragment Fragment_Home;
    FragmentTransaction fragmentTransaction;

    protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_main);
       fragmentTransaction = getSupportFragmentManager().beginTransaction();
       Fragment_Home = new HomeFragment();
       fragmentTransaction.replace(R.id.MainFrameContainer,Fragment_Home);
       fragmentTransaction.addToBackStack(null);
       fragmentTransaction.commit();
   }
}

4. Create a fragment layout “fragment_home.xml” and corresponding java class “HomeFragment.java”.

A Simple Listener in Java (Android)

16 2019

1. Create an Interface “Listener”

public interface Listener {
    void Callback_SuccessEvent();
    void Callback_FailedEvent();
}

2. Create a Class “TestListener”

public class TestListener implements Listener {

    // add a private listener variable
    private Listener mListener = null;

    // provide a way for another class to set the listener
    public void SetListener(Listener listener)
    {
        this.mListener = listener;
    }

    public void TestMyListener(int n) 
    {
         if(n%2)
              mListener.Callback_SuccessEvent();
         else
              mListener.Callback_FailedEvent();
    }

 
}

3. Create a Main Class “TestMain”

public class TestMain implements Listener {

    public void MainFunction()
    {
          TestListener.SetListener(new Listener(){
                        @Override
                        public void Callback_SuccessEvent() {
                            Log.i("Callback", "Success");

                        }

                        @Override
                        public void Callback_FailedEvent() {
                            Log.i("Callback", "Failed");
                        
                        }
                    });
         TestListener.TestMyListener(2);
         TestListener.TestMyListener(3);
   } 
}

A Simple Wait / Notify in Java

16 2019
  • Create a object called “lock”.
private Object lock = new Object();
  • Call the wait() where you want to stop the code.
synchronized (lock)
{
    lock.wait();
}
  • Call the notify() in somewhere else in the code to proceed to the next line of wait().
synchronized (lock) {
lock.notify();
}

WPF XAML Round Gradient Animated Button

16 2019

1. Add a Image to the resource “Icons/icon_sett.png”
2. Add a Image source as Tag for the Button XML.

MainWindow.xaml

<Button x:Name="add_button" Style="{StaticResource GrayRoundCorner}" Content="Delivery" Height="80" VerticalAlignment="Top" Margin="212,-165,-290,0" HorizontalAlignment="Left" Width="80">
<Button.Tag>
<ImageSource>Icons/icon_sett.png</ImageSource>
</Button.Tag>
</Button>

Application.xaml

<!-- Gray Round Corner Button Style --> 
<Style x:Key="GrayRoundCorner" TargetType="{x:Type Button}">
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Padding" Value="1"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid x:Name="grid">
<Image Name="pic" Source="{TemplateBinding Tag}" Width="32" Height="32" Panel.ZIndex="1"/>
<Border x:Name="border" CornerRadius="50" BorderBrush="#7FDEDEDE" BorderThickness="1">
<Border.Background>
<RadialGradientBrush GradientOrigin="0.496,1.052">
 
<GradientStop Offset="1" x:Name="grayOffset" Color="#7FBFBFBF"/>
<GradientStop Offset="0" x:Name="whiteOffset" Color="White"/>
</RadialGradientBrush>
</Border.Background>
</Border>
 
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Background" TargetName="border">
<Setter.Value>
<RadialGradientBrush GradientOrigin="0.496,1.052">
<!-- <RadialGradientBrush.RelativeTransform>
<TransformGroup>
<ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="1.5" ScaleY="1.5"/>
<TranslateTransform X="0.02" Y="0.3"/>
</TransformGroup>
</RadialGradientBrush.RelativeTransform> -->
<GradientStop Color="LightGray" Offset="1"/>
<GradientStop Color="White" Offset="0"/>
</RadialGradientBrush>
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="BorderBrush" TargetName="border" Value="#FFBFB8B8"/>
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Opacity" TargetName="grid" Value="0.25"/>
</Trigger>
<!-- Animations that start when mouse enters and leaves button. -->
<EventTrigger RoutedEvent="Mouse.MouseEnter">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard >
<DoubleAnimation
Storyboard.TargetName="whiteOffset"
Storyboard.TargetProperty="Offset"
From="0.0" To="1.0"
Duration="0:0:.2"/>
<DoubleAnimation
Storyboard.TargetName="grayOffset"
Storyboard.TargetProperty="Offset"
From="0.0" To="1.0"
Duration="0:0:.2"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
<EventTrigger RoutedEvent="Border.MouseLeave">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="whiteOffset"
Storyboard.TargetProperty="Offset"
To="0.0"
Duration="0:0:.9"/>
<DoubleAnimation
Storyboard.TargetName="grayOffset"
Storyboard.TargetProperty="Offset"
To="1"
Duration="0:0:.9"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

Tak Bak Lyrics – Thanga Magan (Tamil)

12 2018

நீ டக்குனு பாத்தா திக்குனு ஆகும்
பக்குனு மனசு தானா அடிக்கும்
நீ பச்சுன்னு ஒன்னு இச்சுனு குடுத்த
நச்சுனு நரம்பு தானா துடிக்குமே

நீ பட்டுனு திரும்பி பாத்தா
நா டப்புனு ஆப் ஆவேன்
நீ சட்டுனு உரசி போன
நா டக்குனு பியூஸ் ஆவேன்
நீ பொத்துனு விழுந்த
கப்புனு புடிப்பேன்
மப்புல காலு காத்தில் பறக்கும்

நீ ஜல்லுனு நடந்து ஜில்லுனு போன
ஜிவ்வுனு எனக்கு ஷாக்கு அடிக்கும்

தக தகன்னு எறியும் உன் வயசு
வெட வெட பய்யன் எனக்கு இது புதுசு
கடை கட்னு ஏறுது என் Pulse-உ
பட பட்னு இதயத்திலே Drums-உ

தக தகன்னு எறியும் உன் வயசு
வெட வெட பய்யன் எனக்கு இது புதுசு
கடை கட்னு ஏறுது என் Pulse-உ
பட பட்னு இதயத்திலே Drums-உ

பாஷ புரியாத ஒரு வார்த்தை வருதே
பேச முடியாத ஒரு ஏக்கம் தருதே

நீ டக்குனு பாத்தா திக்குனு ஆகும்
பக்குனு மனசு தானா அடிக்கும்
நீ பச்சுன்னு ஒன்னு இச்சுனு குடுத்த
நச்சுனு நரம்பு தானா துடிக்குமே

நீ பட்டுனு திரும்பி பாத்தா
நா டப்புனு ஆப் ஆவேன்
நீ சட்டுனு உரசி போன
நா டக்குனு பியூஸ் ஆவேன்
நீ பொத்துனு விழுந்த
கப்புனு புடிப்பேன்
மப்புல காலு காத்தில் பறக்கும்

நீ ஜல்லுனு நடந்து ஜில்லுனு போன
ஜிவ்வுனு எனக்கு ஷாக்கு அடிக்கும்

Mother ~ Son

15 2018

Son : Give me 20 rupees.
Mother: For what?
Son : I will give it to a poor man.
Mother: Where is your poor man?
Son : He is selling ice cream outside.

VB.NET – Native VC++ DLL

15 2018

VC++ Data Type – VB.NET Implementation :

1. LPBYTE – ByRef results As Byte,
2. INT – ByVal a as Int32
3. DWORD – ByVal statusSize As Int32
4. LPDWORD – ByRef len As Long

Sample 1:

<DllImport(DLL_FILENAME, CallingConvention:=CallingConvention.Cdecl)> _
Public Shared Function Function1 _
(ByVal bool_valueAs Boolean,
ByRef longpointer_byte_valueAs Byte,
ByVal dword_valueAs Int32,
ByRef longpointer_dword_valueAs Int32) As Int32
End Function

Sample 2:

VC++

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
<Serializable()> Public Structure ErrorLog
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=2, ArraySubType:=UnmanagedType.U1)> _
Public Param1() As Byte ' 2 Byte
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=5, ArraySubType:=UnmanagedType.U1)> _
Public Param2() As Byte ' 5 Byte
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=8, ArraySubType:=UnmanagedType.U1)> _
Public Param3() As Byte ' 8 Byte
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=2, ArraySubType:=UnmanagedType.U1)> _
Public Param4() As Byte ' 2 Byte
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=22, ArraySubType:=UnmanagedType.U1)> _
Public Param5() As Byte ' 22 Byte
Public Param6 As Byte</code>

<MarshalAs(UnmanagedType.ByValArray, SizeConst:=28, ArraySubType:=UnmanagedType.U1)> _
Public dummy() As Byte ' 28 Byte
End Structure
typedef struct _fullLog {
ERRORLOG errLog[5];
} FULLLOG;

VB.NET

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
<Serializable()> Public Structure ReadData
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=512, ArraySubType:=UnmanagedType.AsAny)> _
Public Error_Log() As ErrorLog
End Structure

'EXTERN_C_DLL_EXPORT INT SampleAPI(FULLLOG *fullLog);
<DllImport(DLL_FILENAME, CallingConvention:=CallingConvention.Cdecl)> _
Public Shared Function SampleAPI(ByRef FullLog1 As ErrorLog, ByVal Length As UInt32, ByRef lpLen As UInt32, <MarshalAs(UnmanagedType.LPWStr)> Optional lpPathName As String = "") As Int32
End Function