package com.dwin.DwinTools;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class RotationActivity extends AppCompatActivity implements View.OnClickListener{

    private final String TAG = RotationActivity.class.getSimpleName();
    public static final String DWIN_ROTATION = "android.intent.action.dwin_rotation";
    private Button mButtonRotation0,mButtonRotation90,mButtonRotation180,mButtonRotation270;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rotation);
        mButtonRotation0 = findViewById(R.id.btn_rotation_0);
        mButtonRotation90 = findViewById(R.id.btn_rotation_90);
        mButtonRotation180 = findViewById(R.id.btn_rotation_180);
        mButtonRotation270 = findViewById(R.id.btn_rotation_270);

        mButtonRotation0.setOnClickListener(this);
        mButtonRotation90.setOnClickListener(this);
        mButtonRotation180.setOnClickListener(this);
        mButtonRotation270.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_rotation_0:
                setRotation("0");
                break;
            case R.id.btn_rotation_90:
                setRotation("90");
                break;
            case R.id.btn_rotation_180:
                setRotation("180");
                break;
            case R.id.btn_rotation_270:
                setRotation("270");
                break;
        }
    }

    /**
     * 通过发送广播，系统则会进行屏幕旋转
     * @param value 旋转的值
     */
    private void setRotation(String value){
        Log.v(TAG,"Dwin test sendBroadcast!");
        Intent sr = new Intent(DWIN_ROTATION);
        sr.putExtra("message", value);
        sendBroadcast(sr);
    }
}
