LoginSignup
5
1

More than 3 years have passed since last update.

【スタージュンも認めた】グルメスパイザー欲しいけど1103兆3543億円もするのでandroidアプリ作った

Last updated at Posted at 2020-11-16

お断り

主はandroidアプリ開発、java言語が今回が初めてなのでレイアウトがボロボロだったり所々突っ込みどころがあると思います。
ネタが嫌いな方はブラウザバック推奨します















グルメスパイザーとは

バンダイから発売されてしまった赤い腕型のおもちゃ。正式名称は「トリコ 菓子粉砕機グルメスパイザー」。中にスナック菓子を入れてレバーをシャカシャカ動かすと、内部で菓子が粉砕され、ふりかけとなって出てくる仕組み。ぶっちゃけタカラトミーのおかしなフリカケのパクr。
CMも作られており、トリコが嬉しそうにグルメスパイザーをシャカシャカしている。

以下から引用

ニコニコ大百科

対象読者

・1103兆3543億円もってない人
・手軽に菓子粉砕したい人
・美食家
・スタージュン
・どこでもポン!クラッシュ!クラッシュ!パッパッパ!したい人

動画:説明あり

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

ダウンロード、インストール

download

野良アプリになるのでgumbyさんの記事参考にしてもらえればインストールできると思います

開発期間とか

企画、要件定義とか => 3秒
環境構築、プログラミング =>6時間くらい
合計6時間3秒です

機能

13973 (3).jpg

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

ボタンを押下するとトリコが喋ります

スパイスをかける音 

ボタンを押下するとフラッシュライトが光り例のシーンが簡単に再現できます
ボタンを再度押下するとフラッシュライトが消えます

動作確認

huwei p30 lite

ソース

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)
                // ストリーム数に応じて
                .setMaxStreams(5)
                .build();

        // 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 の再生
            // play(ロードしたID, 左音量, 右音量, 優先度, ループ,再生速度)
            soundPool.play(soundPon, 1.0f, 1.0f, 0, 0, 1);

        });

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

        });
        button3.setOnClickListener(v -> {
            // Umasooo.wav の再生
            soundPool.play(soundUmasooo, 1.0f, 1.0f, 1, 0, 1);
        });
        button4.setOnClickListener(v -> {
            // gourmetspyzer.wav の再生
            soundPool.play(soundGourmetSpyzer, 1.0f, 1.0f, 1, 0, 1);
        });
        button5.setOnClickListener(v -> {
            soundPool.play(UfoSoundEffect, 1.0f, 1.0f, 1, 0, 1);
                //カメラを取得できなかった時は何もしない
                if (McameraID == null) {
                    return;
                }
                try {
                    if (SW == false) {
                        //SWがfalseならばトーチモードをtrueにして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);
                        }
                        //SWがtrueならばトーチモードをfalseにしてLDEオフ
                    }

                } catch (CameraAccessException e) {
                    //エラー処理
                    e.printStackTrace();
                }

        });

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            McameraManager.registerTorchCallback(new CameraManager.TorchCallback() {
                //トーチモードが変更された時の処理
                @Override
                public void onTorchModeChanged(String cameraId, boolean enabled) {
                    super.onTorchModeChanged(cameraId, enabled);
                    //カメラIDをセット
                    McameraID = cameraId;
                    //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="スパイスをかける音"
        app:backgroundTint="#F44336"
        app:layout_constraintBaseline_toBaselineOf="@+id/button4"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@+id/button4" />


</androidx.constraintlayout.widget.ConstraintLayout>

後書き

週末を返せ

5
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
1