[Stajyun also admitted] I want a gourmet spy, but it costs 1103.3543 trillion yen, so I made an android app

Refusal

Mainly for android application development, java language is the first time, so I think that the layout is tattered and there are places to dig in. Browser back is recommended for those who dislike material ⌇ ⌇ ⌇ ⌇ ⌇ ⌇ ⌇ ⌇ ⌇ ⌇ ⌇ ⌇ ⌇ ⌇ ⌇ ⌇

Target audience

・ People who do not have 1103 trillion 354.3 billion yen ・ People who want to easily crush sweets ·Gourmet ・ Stajyun ・ Pon everywhere! crash! crash! Pappappa! Who wants

Video: Explained

https://www.nicovideo.jp/watch/sm37827489 https://www.youtube.com/watch?v=CkE88pO2VAI

Download and install

download

Since it will be a stray application, I think that you can install it if you refer to the article of gumby

Development period

Planning, requirement definition, etc. => 3 seconds Environment construction, programming => about 6 hours 6 hours 3 seconds in total

function

13973 (3).jpg

PON!! CRASH!! UMASOO!! GOURMETSPYZER!!

Press the button and Toriko will speak

The sound of spices When you press the> button, the flashlight shines and you can easily reproduce the example scene.

Press the button again to turn off the flashlight

Operation check

huwei p30 lite

Source

MainActivity.java


import android.media.AudioAttributes;
import android.media.SoundPool;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import android.hardware.camera2.CameraAccessException;
import android.hardware.camera2.CameraManager;
import android.os.Handler;
import android.content.Context;

public class MainActivity extends AppCompatActivity {

    private SoundPool soundPool;
    private int soundPon, soundCresh,soundUmasooo,soundGourmetSpyzer,UfoSoundEffect;
    private Button button1, button2,button3,button4,button5;
    private CameraManager McameraManager;
    private String McameraID;
    private boolean SW;



    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        McameraManager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);

        AudioAttributes audioAttributes = new AudioAttributes.Builder()
                // USAGE_MEDIA
                // USAGE_GAME
                .setUsage(AudioAttributes.USAGE_GAME)
                // CONTENT_TYPE_MUSIC
                // CONTENT_TYPE_SPEECH, etc.
                .setContentType(AudioAttributes.CONTENT_TYPE_SPEECH)
                .build();

        soundPool = new SoundPool.Builder()
                .setAudioAttributes(audioAttributes)
                //Depending on the number of streams
                .setMaxStreams(5)
                .build();

        //load wav
        soundPon = soundPool.load(this, R.raw.pon, 1);

        soundCresh = soundPool.load(this, R.raw.crash, 1);

        soundUmasooo = soundPool.load(this, R.raw.umasooo, 1);

        soundGourmetSpyzer = soundPool.load(this, R.raw.gourmetspyzer, 1);

        UfoSoundEffect = soundPool.load(this, R.raw.ufosoundeffect, 1);

        soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
            @Override
            public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
                Log.d("debug", "sampleId=" + sampleId);
                Log.d("debug", "status=" + status);
            }
        });

        button1 = findViewById(R.id.button1);
        button2 = findViewById(R.id.button2);
        button3 = findViewById(R.id.button3);
        button4 = findViewById(R.id.button4);
        button5 = findViewById(R.id.button5);

        button1.setOnClickListener(v -> {
            // pon.wav playback
            // play(Loaded ID,Left volume,Right volume,priority,loop,Playback speed)
            soundPool.play(soundPon, 1.0f, 1.0f, 0, 0, 1);

        });

        button2.setOnClickListener(v -> {
            // crash.wav playback
            soundPool.play(soundCresh, 1.0f, 1.0f, 1, 0, 1);

        });
        button3.setOnClickListener(v -> {
            // Umasooo.wav playback
            soundPool.play(soundUmasooo, 1.0f, 1.0f, 1, 0, 1);
        });
        button4.setOnClickListener(v -> {
            // gourmetspyzer.wav playback
            soundPool.play(soundGourmetSpyzer, 1.0f, 1.0f, 1, 0, 1);
        });
        button5.setOnClickListener(v -> {
            soundPool.play(UfoSoundEffect, 1.0f, 1.0f, 1, 0, 1);
                //Do nothing if you can't get the camera
                if (McameraID == null) {
                    return;
                }
                try {
                    if (SW == false) {
                        //If SW is false, set torch mode to true and turn on LDE
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                            McameraManager.setTorchMode(McameraID, true);
                        }
                    } else {
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                            McameraManager.setTorchMode(McameraID, false);
                        }
                        //If SW is true, set torch mode to false and turn off LDE
                    }

                } catch (CameraAccessException e) {
                    //Error handling
                    e.printStackTrace();
                }

        });

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            McameraManager.registerTorchCallback(new CameraManager.TorchCallback() {
                //Processing when the torch mode is changed
                @Override
                public void onTorchModeChanged(String cameraId, boolean enabled) {
                    super.onTorchModeChanged(cameraId, enabled);
                    //Set camera ID
                    McameraID = cameraId;
                    //Set the current state to SW
                    SW = enabled;
                }
            }, new Handler());
        }

    }
}


activity_main.xml


<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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">

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginBottom="20dp"
        android:text="pon!!"
        app:backgroundTint="#F44336"
        app:layout_constraintBottom_toBottomOf="@+id/imageView"
        app:layout_constraintEnd_toEndOf="@+id/button5" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginLeft="16dp"
        android:layout_marginBottom="20dp"
        android:text="crash!!"
        app:backgroundTint="#F44336"
        app:layout_constraintBottom_toBottomOf="@+id/imageView"
        app:layout_constraintStart_toEndOf="@+id/button3" />

    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="20dp"
        android:layout_marginLeft="20dp"
        android:layout_marginBottom="20dp"
        android:text="umasoo!!"
        app:backgroundTint="#F44336"
        app:layout_constraintBottom_toBottomOf="@+id/imageView"
        app:layout_constraintStart_toStartOf="parent"
        app:strokeColor="#F44336" />

    <Button
        android:id="@+id/button4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginLeft="16dp"
        android:layout_marginEnd="9dp"
        android:layout_marginRight="9dp"
        android:layout_marginBottom="32dp"
        android:text="GourmetSpyzer!!"
        app:backgroundTint="#F44336"
        app:layout_constraintBottom_toTopOf="@+id/button2"
        app:layout_constraintEnd_toStartOf="@+id/button5"
        app:layout_constraintHorizontal_chainStyle="packed"
        app:layout_constraintStart_toStartOf="parent" />

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="4dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/home" />

    <Button
        android:id="@+id/button5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="24dp"
        android:layout_marginRight="24dp"
        android:text="The sound of spices"
        app:backgroundTint="#F44336"
        app:layout_constraintBaseline_toBaselineOf="@+id/button4"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@+id/button4" />


</androidx.constraintlayout.widget.ConstraintLayout>

Postscript

Return the weekend

Recommended Posts

[Stajyun also admitted] I want a gourmet spy, but it costs 1103.3543 trillion yen, so I made an android app
I made a matching app (Android app)
[Android] I made a pedometer app.
I made a calculator app on Android
I made a rock-paper-scissors app with android
I made an Android app for MiRm service
I want to push an app made with Rails 6 to GitHub
I made a chat app.
Is it an Android app?