File indexing completed on 2024-12-22 04:41:39

0001 /* SPDX-FileCopyrightText: 2018 Nicolas Fella <nicolas.fella@gmx.de>
0002  * SPDX-FileCopyrightText: 2015 David Edmundson <david@davidedmundson.co.uk>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005  */
0006 package org.kde.kdeconnect.Plugins.FindMyPhonePlugin;
0007 
0008 import android.os.Bundle;
0009 import android.util.Log;
0010 import android.view.Window;
0011 import android.view.WindowManager;
0012 
0013 import androidx.appcompat.app.AppCompatActivity;
0014 
0015 import org.kde.kdeconnect.KdeConnect;
0016 import org.kde.kdeconnect_tp.databinding.ActivityFindMyPhoneBinding;
0017 
0018 import java.util.Objects;
0019 
0020 public class FindMyPhoneActivity extends AppCompatActivity {
0021     static final String EXTRA_DEVICE_ID = "deviceId";
0022 
0023     String deviceId;
0024 
0025     @Override
0026     protected void onCreate(Bundle savedInstanceState) {
0027         super.onCreate(savedInstanceState);
0028 
0029         final ActivityFindMyPhoneBinding binding = ActivityFindMyPhoneBinding.inflate(getLayoutInflater());
0030         setContentView(binding.getRoot());
0031 
0032         setSupportActionBar(binding.toolbarLayout.toolbar);
0033         Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);
0034         getSupportActionBar().setDisplayShowHomeEnabled(true);
0035 
0036         if (!getIntent().hasExtra(EXTRA_DEVICE_ID)) {
0037             Log.e("FindMyPhoneActivity", "You must include the deviceId for which this activity is started as an intent EXTRA");
0038             finish();
0039         }
0040 
0041         deviceId = getIntent().getStringExtra(EXTRA_DEVICE_ID);
0042 
0043         Window window = this.getWindow();
0044         window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
0045                 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
0046                 WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
0047                 WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
0048         );
0049 
0050         binding.bFindMyPhone.setOnClickListener(view -> finish());
0051     }
0052 
0053     @Override
0054     protected void onStart() {
0055         super.onStart();
0056         FindMyPhonePlugin plugin = KdeConnect.getInstance().getDevicePlugin(deviceId, FindMyPhonePlugin.class);
0057         if (plugin == null) {
0058             return;
0059         }
0060         plugin.startPlaying();
0061         plugin.hideNotification();
0062     }
0063 
0064     @Override
0065     protected void onStop() {
0066         super.onStop();
0067         FindMyPhonePlugin plugin = KdeConnect.getInstance().getDevicePlugin(deviceId, FindMyPhonePlugin.class);
0068         if (plugin == null) {
0069             return;
0070         }
0071         plugin.stopPlaying();
0072     }
0073 }