Android: O bubble fruit milk-a prank

The year before last, I don’t know how many college students became victims of "a gift". I also experienced it myself, but I didn’t get the job. Instead, I witnessed the deaths of the people around me. Last year, the O fruit milk incident was all the rage. At that time, someone got the source code through decompilation and found that it was written in Lua. I happened to be learning Android recently, and I want to reproduce it through java. As a beginner, it is still a bit difficult. Fortunately, I saw that some big guys had already written it first, so I used it to make a slight modification. By the way, I can prank my friends.
Original link: https://www.lanzoui.com/b0dw9plxe

I replaced the background music with Stephen Chow’s classic laughter, and the pictures were replaced with ghosts and animals. Let’s put the core code below:
activity_main.xml:

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

    <ImageView
        android:src="@drawable/zhou"
        android:layout_width="match_parent"
        android:layout_height="500dp"
        android:scaleType="fitXY"/>

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="你快乐吗?快乐就和我一起啸吧-v-"
            android:textAppearance="?android:attr/textAppearanceMedium"/>

        <Button
            android:layout_width="wrap_content"
            style="?android:attr/buttonStyleSmall"
            android:layout_height="wrap_content"
            android:text="点击我退出程序"
            android:id="@+id/activitymainButton"/>

    </LinearLayout>

</LinearLayout>

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="cn.edu.cdut.egao">

    <uses-permission android:name="android.permission.DISABLE_KEYGUARD"></uses-permission>
    <application
        android:allowBackup="true"
        android:label="@string/app_name"
        android:icon="@drawable/icon"
        android:theme="@style/AppTheme"
        android:resizeableActivity="false">

        <activity
            android:name=".MainActivity"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>

                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <service android:name="MusicService" />
        <meta-data
            android:name="android.max_aspect"
            android:value="4.0"/>

    </application>

</manifest>

MainActivity.java

package cn.edu.cdut.egao;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import android.app.Activity;
import android.os.Bundle;
import android.view.WindowManager;
import android.view.KeyEvent;
import android.os.Build;
import android.view.View;
import android.widget.Toast;
import android.media.AudioManager;
import android.content.Context;
import android.content.Intent;
import android.view.Window;
import android.widget.Button;

public class MainActivity extends Activity {
    public AudioManager am;
    //需要点击次数满足才会退出
    private int num = 100;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //去掉标题栏
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);
        //防止重新加载
        if (!this.isTaskRoot()) {
            Intent mainIntent = getIntent();
            String action = mainIntent.getAction();
            if (mainIntent.hasCategory(Intent.CATEGORY_LAUNCHER) && action.equals(Intent.ACTION_MAIN)) {
                finish();return;
            }}
        //隐藏状态栏标题栏及导航栏
        hideLaLayout();
        //获取音频服务
        am = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
        //启动线程循环设置音量
        new Thread() {
            public void run() {
                //这儿是耗时操作,完成之后更新UI;
                while(true){
                    final int m = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
                    runOnUiThread(new Runnable(){
                        @Override
                        public void run() {
                            //更新UI
                            am.setStreamVolume(AudioManager.STREAM_MUSIC, m, AudioManager.FLAG_PLAY_SOUND);
                        }
                    });
                    try {
                        sleep(500);
                    } catch (InterruptedException e) {}
                }

            }
        }.start();
        //启动服务播放音乐
        final Intent intent = new Intent(getApplicationContext(),MusicService.class);
        startService(intent);
        //按钮点击事件
        final Button bt = findViewById(R.id.activitymainButton);
        bt.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View p1) {
                if(num != 0){
                    num--;
                    bt.setText("再点"+num+"下就关闭程序");
                }else{
                    //停止服务并关闭音乐退出软件
                    stopService(intent);
                    finish();
                }
            }
        });
    }

    @Override
    protected void onRestart(){
        super.onRestart();
        hideLaLayout();
    }
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if(keyCode==KeyEvent.KEYCODE_HOME|| keyCode == KeyEvent.KEYCODE_BACK || keyCode== KeyEvent.KEYCODE_VOLUME_DOWN || keyCode == KeyEvent.KEYCODE_VOLUME_UP){
            Toast toast = Toast.makeText(this,null,Toast.LENGTH_LONG);
            toast.setText("放弃吧,没用的!");
            toast.show();
            return true;
        }

        return super.onKeyDown(keyCode, event);
    }
    private void hideLaLayout(){
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                // 全屏显示,隐藏状态栏和导航栏,拉出状态栏和导航栏显示一会儿后消失。
                getWindow().getDecorView().setSystemUiVisibility(
                        View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                                | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                                | View.SYSTEM_UI_FLAG_FULLSCREEN
                                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
            } else {
                // 全屏显示,隐藏状态栏
                getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
            }
        }
    }

}

MusicService.java:

package cn.edu.cdut.egao;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.media.MediaPlayer;

public class MusicService extends Service {

    private MediaPlayer player;
    @Override
    public IBinder onBind(Intent p1) {
        return null;
    }

    @Override
    public void onStart(Intent intent, int startId) {
        super.onStart(intent, startId);
        player = MediaPlayer.create(this,R.raw.audio);
        player.setLooping(true);
        player.start();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        player.stop();
    }
}

Effect:
Insert picture description here
Click the button 100 times to exit the program, ah~ it’s really very human (O(∩_∩)O)

Guess you like

Origin blog.csdn.net/qq1198768105/article/details/113855819