diff --git a/app/src/main/java/org/ntlab/amaryllis/client/MainActivity.java b/app/src/main/java/org/ntlab/amaryllis/client/MainActivity.java index ccf7ad7..4b964b2 100644 --- a/app/src/main/java/org/ntlab/amaryllis/client/MainActivity.java +++ b/app/src/main/java/org/ntlab/amaryllis/client/MainActivity.java @@ -13,7 +13,10 @@ import android.app.AlarmManager; import android.app.Notification; import android.app.PendingIntent; +import android.content.ComponentName; +import android.content.Context; import android.content.Intent; +import android.content.ServiceConnection; import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.location.Location; @@ -22,7 +25,10 @@ import android.location.LocationProvider; import android.os.Bundle; import android.os.Debug; +import android.os.IBinder; +import android.os.RemoteException; import android.provider.Settings; +import android.support.v4.media.session.MediaControllerCompat; import android.util.Log; import android.view.Menu; import android.view.MenuItem; @@ -32,10 +38,12 @@ import com.google.android.material.bottomnavigation.BottomNavigationView; +import org.ntlab.amaryllis.client.entities.AmaryllisBackgroundService; import org.ntlab.amaryllis.client.entities.Category; import org.ntlab.amaryllis.client.fragment.MapsFragment; import org.ntlab.amaryllis.client.resources.AccountsRest; import org.ntlab.amaryllis.client.resources.CategoriesRest; +import org.ntlab.amaryllis.client.voiceservice.TestVoiceService; import java.util.ArrayList; import java.util.HashMap; @@ -58,6 +66,28 @@ ImageButton stopbutton; ImageButton skipbutton; + + AmaryllisBackgroundService myService; + MediaControllerCompat mediaController; + ServiceConnection serviceConnection = new ServiceConnection(){ + @Override + public void onServiceConnected(ComponentName name, IBinder service) { + myService = ((AmaryllisBackgroundService.MyBinder)service).getService(); + try { + mediaController=new MediaControllerCompat(MainActivity.this,myService.getToken()); + } catch (RemoteException e) { + e.printStackTrace(); + } + //myService.setMessage("Hello, IBinder!"); + //startService(serviceIntent); + } + + @Override + public void onServiceDisconnected(ComponentName name) { + myService = null; + } + }; + int playfrag=0; int stopfrag=0; @@ -98,8 +128,12 @@ }); + //アクティビティとサービスを接続 + bindService(new Intent(getBaseContext(),AmaryllisBackgroundService.class),serviceConnection, Context.BIND_AUTO_CREATE); + //収音関係のボタンの処理 playbutton = (ImageButton)findViewById(R.id.playbutton); + playbutton.setEnabled(true); playbutton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { playfrag++; @@ -108,6 +142,7 @@ }else{ //こっち側がオン } + mediaController.getTransportControls().play(); } }); stopbutton = (ImageButton)findViewById(R.id.stopbutton); @@ -119,12 +154,14 @@ }else{ //こっち側がオン } + + mediaController.getTransportControls().pause(); } }); skipbutton = (ImageButton)findViewById(R.id.skipbutton); skipbutton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { - + mediaController.getTransportControls().skipToNext(); } }); @@ -134,6 +171,10 @@ return; } manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); + + + + } private void locationStart(){