zezung27 / api-mymeostore

1 stars 0 forks source link

DisplaySettingActivity #10

Closed zezung27 closed 2 years ago

zezung27 commented 2 years ago

package com.matcos.dynamicislandlight;

import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity;

import android.content.res.Resources; import android.os.Build; import android.os.Bundle; import android.view.View; import android.view.WindowManager; import android.widget.ImageView; import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.SeekBar; import android.widget.TextView; import android.widget.Toast;

import com.matcos.dynamicislandlight.core.service.MainAccessibilityService; import com.matcos.dynamicislandlight.core.service.WindowPopup; import com.matcos.dynamicislandlight.utils.Contanst; import com.matcos.dynamicislandlight.utils.Utils;

import org.w3c.dom.Text;

public class DisplaySettingActivity extends AppCompatActivity { private WindowPopup mWindowPopup; private RadioButton rbLeft, rbCenter, rbRight; private TextView txtTop, txtLeftRight, txtWidth, txtHeight; private ImageView imgBack, imgIncreaseTop, imgDecreaseTop, imgIncreaseLR, imgDecreaseLR, imgIncreaseWidth, imgDecreaseWidth, imgIncreaseHeight, imgDecreaseHeight; private SeekBar topSeekbar, leftRightSeekbar, widthSeekbar, heightSeekbar; private int currentProgressTop, currentProgressLeftRight, currentProgressWidth, currentProgressHeight; private int maxWidthDevice, minW, maxW, minH, maxH;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ActionBar actionBar = getSupportActionBar();
    actionBar.hide();
    getWindow().setStatusBarColor(getColor(R.color.white));
    getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
    mWindowPopup = WindowPopup.getInstance(this);
    setContentView(R.layout.activity_display_setting);
    maxW = Utils.getWidthPopupWindow(Contanst.TYPE_EXPAND_NOTI, getBaseContext());
    maxH = Utils.getHeightPopupWindow(Contanst.TYPE_EXPAND_NOTI, getBaseContext());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        minW = Utils.getWidthPopupWindow(Contanst.TYPE_MINI_NOTI, getBaseContext());
        minH = Utils.getHeightPopupWindow(Contanst.TYPE_MINI_NOTI, getBaseContext());
    }
    maxWidthDevice = Resources.getSystem().getDisplayMetrics().widthPixels;
    initView();
    updateParamPosValue();
    updateDataView();
    handleEventTopPos();
    handleLeftRightPos();
    handleChangeWidth();
    handleChangeHeight();
}
private void initView() {
    imgBack = (ImageView) findViewById(R.id.backIcon);
    imgBack.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            onBackPressed();
        }
    });
    rbLeft = (RadioButton)findViewById(R.id.radio_left);
    rbCenter = (RadioButton)findViewById(R.id.radio_center);
    rbRight = (RadioButton)findViewById(R.id.radio_right);
    imgIncreaseTop = (ImageView) findViewById(R.id.tTop);
    imgDecreaseTop = (ImageView) findViewById(R.id.gTop);
    topSeekbar = (SeekBar) findViewById(R.id.seekBarTop);
    txtTop =(TextView) findViewById(R.id.txtValueTop);

    imgIncreaseLR = (ImageView) findViewById(R.id.tLeftRight);
    imgDecreaseLR = (ImageView) findViewById(R.id.gLeftRight);
    leftRightSeekbar = (SeekBar) findViewById(R.id.seekBarLeftRight);
    txtLeftRight =(TextView) findViewById(R.id.txtValueLeftRight);
    leftRightSeekbar.setMax(maxWidthDevice);

    widthSeekbar = (SeekBar) findViewById(R.id.seekBarWidth) ;
    heightSeekbar = (SeekBar) findViewById(R.id.seekBarHeight);
    txtWidth = (TextView) findViewById(R.id.txtValueWidth);
    txtHeight = (TextView) findViewById(R.id.txtValueHeight);
    imgDecreaseWidth = (ImageView) findViewById(R.id.gWidth);
    imgIncreaseWidth = (ImageView) findViewById(R.id.tWidth);
    imgDecreaseHeight = (ImageView) findViewById(R.id.gHeight);
    imgIncreaseHeight = (ImageView) findViewById(R.id.tHeight);
    widthSeekbar.setMax(maxW);
    heightSeekbar.setMax(maxH);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        leftRightSeekbar.setMin(maxWidthDevice*(-1));
        widthSeekbar.setMin(minW);
        heightSeekbar.setMin(minH);
    }
}

private void updateTopSeekBarOnChange() {
    topSeekbar.setProgress(currentProgressTop);
    txtTop.setText(String.valueOf(currentProgressTop));
    mWindowPopup.changeY(currentProgressTop);
}

private void handleEventTopPos() {
    imgIncreaseTop.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if(currentProgressTop < 160) {
                currentProgressTop++;
                updateTopSeekBarOnChange();
            }
        }
    });

    imgDecreaseTop.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if(currentProgressTop > 0) {
                currentProgressTop--;
                updateTopSeekBarOnChange();
            }
        }
    });

    topSeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean b) {
            currentProgressTop = progress;
            updateTopSeekBarOnChange();
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }
    });
}
public void updateDataView() {
    // edit
    currentProgressTop = mWindowPopup.getCurrentYPos();
    currentProgressLeftRight = mWindowPopup.getCurrentXPos();
    currentProgressWidth = mWindowPopup.getCurrentWidth();
    currentProgressHeight = mWindowPopup.getCurrentHeight();
    topSeekbar.setProgress(currentProgressTop);
    txtTop.setText(String.valueOf(currentProgressTop));
    leftRightSeekbar.setProgress(currentProgressLeftRight);
    txtLeftRight.setText(String.valueOf(currentProgressLeftRight));
    widthSeekbar.setProgress(currentProgressWidth);
    heightSeekbar.setProgress(currentProgressHeight);
    txtWidth.setText(currentProgressWidth +"");
    txtHeight.setText(currentProgressHeight + "");
}
zezung27 commented 2 years ago

public void handleChangeWidth() { imgIncreaseWidth.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if(currentProgressWidth < maxW) { currentProgressWidth++; txtWidth.setText(currentProgressWidth +""); mWindowPopup.changeWidth(currentProgressWidth); } } });

    imgDecreaseWidth.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if(currentProgressWidth > minW) {
                currentProgressWidth--;
                txtWidth.setText(currentProgressWidth +"");
                mWindowPopup.changeWidth(currentProgressWidth);
            }
        }
    });

    widthSeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
            currentProgressWidth = i;
            txtWidth.setText(currentProgressWidth +"");
            mWindowPopup.changeWidth(currentProgressWidth);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }
    });
}

public void handleChangeHeight() {
    imgIncreaseHeight.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if(currentProgressHeight < maxH) {
                currentProgressHeight++;
                txtHeight.setText(currentProgressHeight +"");
                mWindowPopup.changeHeight(currentProgressHeight);
            }
        }
    });

    imgDecreaseHeight.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if(currentProgressHeight > minH) {
                currentProgressHeight--;
                txtHeight.setText(currentProgressHeight +"");
                mWindowPopup.changeHeight(currentProgressHeight);
            }
        }
    });

    heightSeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
            currentProgressHeight = i;
            txtHeight.setText(currentProgressHeight +"");
            mWindowPopup.changeHeight(currentProgressHeight);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }
    });
}
public void updateParamPosValue() {
    String currentPos = mWindowPopup.getCurrentPosition();
    switch(currentPos) {
        case "LEFT":
            rbLeft.setChecked(true);
            break;
        case "CENTER":
            rbCenter.setChecked(true);
            break;
        case "RIGHT":
            rbRight.setChecked(true);
            break;
        default: break;
    }
}

public void onRadioButtonClicked(View view) {
    boolean checked = ((RadioButton) view).isChecked();
    currentProgressLeftRight = 0;
    updateChangeXPos();
    switch(view.getId()) {
        case R.id.radio_right:
            if (checked)
                mWindowPopup.changeRight();
            break;
        case R.id.radio_left:
            if (checked)
                mWindowPopup.changeLeft();
            break;
        case R.id.radio_center:
            if (checked)
                mWindowPopup.changeCenter();
            break;
        default: break;
    }
}

public  void updateChangeXPos() {
    txtLeftRight.setText(String.valueOf(currentProgressLeftRight));
    leftRightSeekbar.setProgress(currentProgressLeftRight);
    mWindowPopup.changeX(currentProgressLeftRight);
}
public void handleLeftRightPos() {
    imgIncreaseLR.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if(currentProgressLeftRight < maxWidthDevice) {
                currentProgressLeftRight++;
                updateChangeXPos();
            }
        }
    });
    imgDecreaseLR.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if(currentProgressLeftRight > 0 ) {
                currentProgressLeftRight--;
                updateChangeXPos();
            }
        }
    });
    leftRightSeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean b) {
            currentProgressLeftRight = progress;
            updateChangeXPos();
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }
    });
}

}