@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
//Initialization of commands when changing volume
mCommandTime = 0;
mSuccessCommand = "";
final View v = inflater.inflate(R.layout.fragment_recording, container, false);
v.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (mCommandTime==0) {
//Once pressed, timer will not start until mCommandTime is reset to 0 after 5 seconds
mCommandTime++;
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
Log.d(TAG, "Initialize openPass after 5 seconds");
mSuccessCommand = "";
//String the value only when the timer is on(mSuccessCommand)Can be added to
Log.d(TAG, "The timer can be started after 5 seconds have passed.");
mCommandTime= 0;
}
}, 5000);
}else{
Log.d(TAG,"comandTime"+mCommandTime+"And I can't use timer because it's been over 5 seconds");
}
if(event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP){
mSuccessCommand=mSuccessCommand+"1";
Log.d(TAG,"To Command+1, the current command is"+mSuccessCommand);
}else if(event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_DOWN){
mSuccessCommand=mSuccessCommand+"0";
Log.d(TAG,"To Command+0, the current command is"+mSuccessCommand);
}
if (mSuccessCommand.equals("01101")) {
Log.i(TAG,"The life command has been lifted");
Toast.makeText(getActivity(), "The lock has been released.", Toast.LENGTH_SHORT).show();
//Here is the process for unlocking
}
});
// View#It is important to set true in setFocusableInTouchMode
v.setFocusableInTouchMode(true);
return v;
}
}
While making SNS etc. in the future, I would like to adjust the transparency of the application by unlocking the volume button. Have fun
Recommended Posts