【Android 】full screen display effect of clicking pictures

 package com.example.explosioneffect;


import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import java.io.InputStream;

public class MainActivity extends AppCompatActivity {
private ImageView imageView;
private Dialog dialog;
private ImageView image;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
//Click event of small picture (pop up big picture)
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.show();
}
});
}

private void init() {
imageView = (ImageView) findViewById(R.id.image);
//The big picture displayed on the dialog
dialog = new Dialog(MainActivity.this, R.style.FullActivity);
WindowManager.LayoutParams attributes = getWindow().getAttributes();
attributes.width = WindowManager.LayoutParams.MATCH_PARENT;
attributes.height = WindowManager.LayoutParams.MATCH_PARENT;
dialog.getWindow().setAttributes(attributes);
image = getImageView();
dialog.setContentView(image);
//The click event of the big picture (click to make him disappear)
image.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
}

//Dynamic ImageView
private ImageView getImageView() {
ImageView imageView = new ImageView(this);
//Width Height
imageView.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
//imageView set picture
@SuppressLint("ResourceType") InputStream is = getResources().openRawResource(R.drawable.ic_launcher_background);
Drawable drawable = BitmapDrawable.createFromStream(is, null);
imageView.setImageDrawable(drawable);
return imageView;
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ImageView
android:id="@+id/image"
android:src="@drawable/ic_launcher_background"
android:layout_centerInParent="true"
android:layout_width="200dp"
android:layout_height="200dp" />
</LinearLayout>

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>

</style>
<style name="FullActivity" parent="AppTheme">
<item name="windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>item>
</style>
</resources>

【C#】 WPF realizes the effect of flashing background lights with the mouse

<Window x:Class="FlashingEffect.MainWindow"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

        xmlns:local="clr-namespace:FlashingEffect"

        mc:Ignorable="d"

        Title="MainWindow" Height="450" Width="800">

    <Grid>

        <Canvas x:Name="container" Width="400" Height="400"></Canvas>

        <GroupBox Header="GroupBox" HorizontalAlignment="Left" Height="388" Margin="10,10,0,0" VerticalAlignment="Top" Width="749"/>

    </Grid>

</Window>

  


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Data;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Imaging;

using System.Windows.Navigation;

using System.Windows.Shapes;


namespace FlashingEffect

{

    /// <summary>

    /// Interaction logic for MainWindow.xaml

    /// </summary>

    public partial class MainWindow : Window

    {

        private Point lastMousePosition = new Point(0, 0);//Mouse position

        private int triangleLength = 100;//Triangle side length

        public MainWindow()

        {

            InitializeComponent();

            this.Loaded += MainWindow_Loaded;

            CompositionTarget.Rendering += UpdateTriangle;

            this.container.PreviewMouseMove += UpdateLastMousePosition;

        }

        private void MainWindow_Loaded(object sender, RoutedEventArgs e)

        {

            //Easily divide the rectangle into combined triangles

            int horizontalCount = (int)(this.container.ActualWidth / triangleLength);

            int verticalCount = (int)(this.container.ActualHeight / triangleLength);

            for (int i = 0; i < horizontalCount; i++)

            {

                for (int j = 0; j < verticalCount; j++)

                {

                    Path trianglePath1 = new Path();

                    var g1 = new StreamGeometry();

                    using (StreamGeometryContext context = g1.Open())

                    {

                        context.BeginFigure(new Point(i * triangleLength, j * triangleLength), true, true);

                        context.LineTo(new Point(i * triangleLength, (j + 1) * triangleLength), true, false);

                        context.LineTo(new Point((i + 1) * triangleLength, (j + 1) * triangleLength), true, false);

                    }

                    trianglePath1.Data = g1;

                    trianglePath1.Fill = new SolidColorBrush(Color.FromArgb(255, 247, 18, 65));

                    this.container.Children.Add(trianglePath1);

                    Path trianglePath2 = new Path();

                    var g2 = new StreamGeometry();

                    using (StreamGeometryContext context = g2.Open())

                    {

                        context.BeginFigure(new Point(i * triangleLength, j * triangleLength), true, true);

                        context.LineTo(new Point((i + 1) * triangleLength, j * triangleLength), true, false);

                        context.LineTo(new Point((i + 1) * triangleLength, (j + 1) * triangleLength), true, false);

                    }

                    trianglePath2.Data = g2;

                    trianglePath2.Fill = new SolidColorBrush(Color.FromArgb(255, 247, 18, 65));

                    this.container.Children.Add(trianglePath2);

                }

            }

        }

        private void UpdateTriangle(object sender, EventArgs e)

        {

            //Get child controls

            List<Path> childList = GetChildObjects<Path>(this.container);

            for (int i = 0; i < childList.Count; i++)

            {

                for (int j = 1; j < childList.Count; j++)

                {

                    string si = childList[i].Data.ToString();

                    string si1 = MidStrEx(si, "M", "L");

                    string si2 = MidStrEx(si, "L", " ");

                    string si3 = MidStrEx(si, " ", "z");

                    string sj = childList[j].Data.ToString();

                    string sj1 = MidStrEx(sj, "M", "L");

                    string sj2 = MidStrEx(sj, "L", " ");

                    string sj3 = MidStrEx(sj, " ", "z");


                    //Left and right triangle judgment

                    if (si1 == sj1 && si3 == sj3)

                    {

                        double x = childList[i].Data.Bounds.X + (1 - Math.Pow(2, 0.5) / 2) * triangleLength - lastMousePosition.X;

                        double y = childList[i].Data.Bounds.Y + (1 - Math.Pow(2, 0.5) / 2) * triangleLength - lastMousePosition.Y;

                        double rRadio = 1 - Math.Pow(x * x + y * y, 0.5) / Math.Pow(this.container.ActualWidth * this.container.ActualWidth + this.container.ActualHeight * this.container.ActualHeight, 0.5);

                        childList[j].Fill = new SolidColorBrush(Color.FromArgb((byte)(255 * rRadio), 247, 18, 65));

                        x = childList[j].Data.Bounds.TopRight.X - (1 - Math.Pow(2, 0.5) / 2) * triangleLength - lastMousePosition.X;

                        rRadio = 1 - Math.Pow(x * x + y * y, 0.5) / Math.Pow(this.container.ActualWidth * this.container.ActualWidth + this.container.ActualHeight * this.container.ActualHeight, 0.5);

                        childList[i].Fill = new SolidColorBrush(Color.FromArgb((byte)(255 * rRadio), 247, 18, 65));

                        break;

                    }

                }

            }

        }

        private void UpdateLastMousePosition(object sender, MouseEventArgs e)

        {

            lastMousePosition = e.GetPosition(this.container);

        }

        private List<T> GetChildObjects<T>(System.Windows.DependencyObject obj) where T : System.Windows.FrameworkElement

        {

            System.Windows.DependencyObject child = null;

            List<T> childList = new List<T>();

            for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++)

            {

                child = VisualTreeHelper.GetChild(obj, i);

                if (child is T)

                {

                    childList.Add((T)child);

                }

                childList.AddRange(GetChildObjects<T>(child));

            }

            return childList;

        }

        public static string MidStrEx(string sourse, string startstr, string endstr)

        {

            string result = string.Empty;

            int startindex, endindex;

            try

            {

                startindex = sourse.IndexOf(startstr);

                if (startindex == -1)

                    return result;

                string tmpstr = sourse.Substring(startindex + startstr.Length);

                endindex = tmpstr.IndexOf(endstr);

                if (endindex == -1)

                    return result;

                result = tmpstr.Remove(endindex);

            }

            catch (Exception ex)

            {

            }

            return result;

        }

    }

}


Win 3 Free Copies of the Book on Forms

To celebrate the recent release of my book, I’m giving away three copies for free. The book is called “Dos and Don’ts for Form Input and Sel...

Contact Form

Name

Email *

Message *