diff --git a/app/src/main/java/org/ntlab/amaryllis/client/LockActivity.java b/app/src/main/java/org/ntlab/amaryllis/client/LockActivity.java index 978f843..2bc588f 100644 --- a/app/src/main/java/org/ntlab/amaryllis/client/LockActivity.java +++ b/app/src/main/java/org/ntlab/amaryllis/client/LockActivity.java @@ -1,14 +1,84 @@ package org.ntlab.amaryllis.client; +import androidx.annotation.RequiresApi; import androidx.appcompat.app.AppCompatActivity; +import android.content.ComponentName; +import android.content.Context; +import android.content.Intent; +import android.content.ServiceConnection; +import android.media.RemoteControlClient; +import android.os.Build; import android.os.Bundle; +import android.os.IBinder; +import android.view.TextureView; +import android.view.View; +import android.view.WindowManager; +import android.widget.Button; +import android.widget.TextView; + +import org.w3c.dom.Text; public class LockActivity extends AppCompatActivity { + boolean isPlaying; + Button playButton; + TextView textCount; + TextView textCount2; + RemoteControlClient remoteControlClient; + VoiceService binder; + private ServiceConnection conn=new ServiceConnection() { + @Override + public void onServiceConnected(ComponentName componentName, IBinder iBinder) { + } + + @Override + public void onServiceDisconnected(ComponentName componentName) { + + } + }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_lock); + +// getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON| +//// WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD| +//// WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED| +//// WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); + textCount=findViewById(R.id.textView_count); + textCount2=findViewById(R.id.textView_count2); + + playButton=findViewById(R.id.button_play); + playButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + switchPlaying(); + playButton.setText(getPlayingState()); + startBackgroundService(getApplicationContext()); + } + }); + + + } + public void startBackgroundService(final Context context){ + final Thread thread = new Thread(){ + @RequiresApi(api= Build.VERSION_CODES.O) + public void run(){ + Intent intentservice = new Intent(context, VoiceService.class); + context.startForegroundService(intentservice); + + } + }; + } + private void switchPlaying(){ + isPlaying=isPlaying?false:true; + } + + public void setPlaying(boolean playing) { + isPlaying = playing; + } + private String getPlayingState(){ + return isPlaying?"Stop":"Play"; } } \ No newline at end of file