2019-02-13 20:43:30 +01:00
|
|
|
/* Copyright (C) 2016-2019 Andreas Shimokawa, Carsten Pfeiffer, Daniele
|
|
|
|
Gobbetti, Johannes Tysiak, Taavi Eomäe
|
2017-03-16 17:36:15 +01:00
|
|
|
|
|
|
|
This file is part of Gadgetbridge.
|
|
|
|
|
|
|
|
Gadgetbridge is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero General Public License as published
|
|
|
|
by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Gadgetbridge is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
2016-10-21 13:01:30 +02:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.activities;
|
|
|
|
|
|
|
|
import android.Manifest;
|
|
|
|
import android.annotation.TargetApi;
|
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.IntentFilter;
|
|
|
|
import android.content.pm.PackageManager;
|
2017-08-18 21:51:12 +02:00
|
|
|
import android.net.Uri;
|
2016-10-21 13:01:30 +02:00
|
|
|
import android.os.Build;
|
|
|
|
import android.os.Bundle;
|
2019-09-21 10:07:58 +02:00
|
|
|
import android.telephony.PhoneStateListener;
|
|
|
|
import android.telephony.TelephonyManager;
|
2016-10-21 13:01:30 +02:00
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.view.View;
|
|
|
|
|
2019-01-26 15:52:40 +01:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.appcompat.app.ActionBarDrawerToggle;
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
import androidx.appcompat.app.AppCompatDelegate;
|
|
|
|
import androidx.appcompat.widget.Toolbar;
|
|
|
|
import androidx.core.app.ActivityCompat;
|
|
|
|
import androidx.core.content.ContextCompat;
|
|
|
|
import androidx.core.view.GravityCompat;
|
|
|
|
import androidx.drawerlayout.widget.DrawerLayout;
|
|
|
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
2019-09-08 12:07:10 +02:00
|
|
|
|
|
|
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
|
|
|
import com.google.android.material.navigation.NavigationView;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Locale;
|
|
|
|
import java.util.Objects;
|
|
|
|
|
2016-10-21 13:01:30 +02:00
|
|
|
import de.cketti.library.changelog.ChangeLog;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.adapter.GBDeviceAdapterv2;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceManager;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
2017-07-31 22:49:05 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.AndroidUtils;
|
2016-10-21 13:01:30 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
|
|
|
|
2017-09-03 01:02:31 +02:00
|
|
|
//TODO: extend AbstractGBActivity, but it requires actionbar that is not available
|
2016-10-21 13:01:30 +02:00
|
|
|
public class ControlCenterv2 extends AppCompatActivity
|
2017-09-03 01:02:31 +02:00
|
|
|
implements NavigationView.OnNavigationItemSelectedListener, GBActivity {
|
2016-10-21 13:01:30 +02:00
|
|
|
|
2016-10-24 17:41:56 +02:00
|
|
|
//needed for KK compatibility
|
|
|
|
static {
|
|
|
|
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
|
|
|
|
}
|
|
|
|
|
2016-10-21 13:01:30 +02:00
|
|
|
private DeviceManager deviceManager;
|
|
|
|
|
|
|
|
private GBDeviceAdapterv2 mGBDeviceAdapter;
|
2016-10-24 17:41:56 +02:00
|
|
|
private RecyclerView deviceListView;
|
2019-09-17 14:02:35 +02:00
|
|
|
private FloatingActionButton fab;
|
2016-10-21 13:01:30 +02:00
|
|
|
|
2017-09-07 23:26:24 +02:00
|
|
|
private boolean isLanguageInvalid = false;
|
|
|
|
|
2019-09-16 17:44:59 +02:00
|
|
|
public static final int MENU_REFRESH_CODE=1;
|
|
|
|
|
2019-09-21 10:07:58 +02:00
|
|
|
private static PhoneStateListener fakeStateListener;
|
2019-09-16 17:44:59 +02:00
|
|
|
|
2016-10-21 13:01:30 +02:00
|
|
|
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
String action = intent.getAction();
|
2018-03-31 16:21:25 +02:00
|
|
|
switch (Objects.requireNonNull(action)) {
|
2017-07-31 22:49:05 +02:00
|
|
|
case GBApplication.ACTION_LANGUAGE_CHANGE:
|
2017-09-03 01:02:31 +02:00
|
|
|
setLanguage(GBApplication.getLanguage(), true);
|
2017-07-31 22:49:05 +02:00
|
|
|
break;
|
2016-10-21 13:01:30 +02:00
|
|
|
case GBApplication.ACTION_QUIT:
|
|
|
|
finish();
|
|
|
|
break;
|
|
|
|
case DeviceManager.ACTION_DEVICES_CHANGED:
|
|
|
|
refreshPairedDevices();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
2017-09-03 01:02:31 +02:00
|
|
|
AbstractGBActivity.init(this, AbstractGBActivity.NO_ACTIONBAR);
|
2016-10-21 23:01:10 +02:00
|
|
|
|
2016-10-21 13:01:30 +02:00
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.activity_controlcenterv2);
|
2018-03-31 16:21:25 +02:00
|
|
|
Toolbar toolbar = findViewById(R.id.toolbar);
|
2016-10-21 13:01:30 +02:00
|
|
|
setSupportActionBar(toolbar);
|
|
|
|
|
2018-03-31 16:21:25 +02:00
|
|
|
DrawerLayout drawer = findViewById(R.id.drawer_layout);
|
2016-10-21 13:01:30 +02:00
|
|
|
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
|
|
|
|
this, drawer, toolbar, R.string.controlcenter_navigation_drawer_open, R.string.controlcenter_navigation_drawer_close);
|
|
|
|
drawer.setDrawerListener(toggle);
|
|
|
|
toggle.syncState();
|
|
|
|
|
2018-03-31 16:21:25 +02:00
|
|
|
NavigationView navigationView = findViewById(R.id.nav_view);
|
2016-10-21 13:01:30 +02:00
|
|
|
navigationView.setNavigationItemSelectedListener(this);
|
|
|
|
|
|
|
|
//end of material design boilerplate
|
2016-12-15 20:59:55 +01:00
|
|
|
deviceManager = ((GBApplication) getApplication()).getDeviceManager();
|
2016-10-24 17:41:56 +02:00
|
|
|
|
2018-03-31 16:21:25 +02:00
|
|
|
deviceListView = findViewById(R.id.deviceListView);
|
2016-10-24 17:41:56 +02:00
|
|
|
deviceListView.setHasFixedSize(true);
|
|
|
|
deviceListView.setLayoutManager(new LinearLayoutManager(this));
|
2016-10-21 13:01:30 +02:00
|
|
|
|
2018-03-31 16:21:25 +02:00
|
|
|
List<GBDevice> deviceList = deviceManager.getDevices();
|
2016-10-21 13:01:30 +02:00
|
|
|
mGBDeviceAdapter = new GBDeviceAdapterv2(this, deviceList);
|
2016-10-24 17:41:56 +02:00
|
|
|
|
2016-10-21 13:01:30 +02:00
|
|
|
deviceListView.setAdapter(this.mGBDeviceAdapter);
|
2016-10-24 17:41:56 +02:00
|
|
|
|
2019-09-17 14:02:35 +02:00
|
|
|
fab = findViewById(R.id.fab);
|
2019-09-08 12:07:10 +02:00
|
|
|
fab.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
launchDiscoveryActivity();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-09-17 14:02:35 +02:00
|
|
|
showFabIfNeccessary();
|
2019-09-08 12:07:10 +02:00
|
|
|
|
2018-03-31 16:21:25 +02:00
|
|
|
/* uncomment to enable fixed-swipe to reveal more actions
|
|
|
|
|
2016-10-24 17:41:56 +02:00
|
|
|
ItemTouchHelper swipeToDismissTouchHelper = new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(
|
|
|
|
ItemTouchHelper.LEFT , ItemTouchHelper.RIGHT) {
|
|
|
|
@Override
|
|
|
|
public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
|
|
|
|
if(dX>50)
|
|
|
|
dX = 50;
|
|
|
|
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
|
|
|
|
GB.toast(getBaseContext(), "onMove", Toast.LENGTH_LONG, GB.ERROR);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
|
|
|
|
GB.toast(getBaseContext(), "onSwiped", Toast.LENGTH_LONG, GB.ERROR);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-10-21 13:01:30 +02:00
|
|
|
@Override
|
2016-10-24 17:41:56 +02:00
|
|
|
public void onChildDrawOver(Canvas c, RecyclerView recyclerView,
|
|
|
|
RecyclerView.ViewHolder viewHolder, float dX, float dY,
|
|
|
|
int actionState, boolean isCurrentlyActive) {
|
2016-10-21 13:01:30 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-03-31 16:21:25 +02:00
|
|
|
swipeToDismissTouchHelper.attachToRecyclerView(deviceListView);
|
|
|
|
*/
|
2016-10-24 17:41:56 +02:00
|
|
|
|
2016-10-21 13:01:30 +02:00
|
|
|
registerForContextMenu(deviceListView);
|
|
|
|
|
|
|
|
IntentFilter filterLocal = new IntentFilter();
|
2017-07-31 22:49:05 +02:00
|
|
|
filterLocal.addAction(GBApplication.ACTION_LANGUAGE_CHANGE);
|
2016-10-21 13:01:30 +02:00
|
|
|
filterLocal.addAction(GBApplication.ACTION_QUIT);
|
|
|
|
filterLocal.addAction(DeviceManager.ACTION_DEVICES_CHANGED);
|
|
|
|
LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, filterLocal);
|
|
|
|
|
|
|
|
refreshPairedDevices();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ask for permission to intercept notifications on first run.
|
|
|
|
*/
|
|
|
|
Prefs prefs = GBApplication.getPrefs();
|
|
|
|
if (prefs.getBoolean("firstrun", true)) {
|
|
|
|
prefs.getPreferences().edit().putBoolean("firstrun", false).apply();
|
|
|
|
Intent enableIntent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
|
|
|
|
startActivity(enableIntent);
|
|
|
|
}
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
|
|
checkAndRequestPermissions();
|
|
|
|
}
|
|
|
|
|
2017-08-14 21:35:34 +02:00
|
|
|
ChangeLog cl = createChangeLog();
|
2016-10-21 13:01:30 +02:00
|
|
|
if (cl.isFirstRun()) {
|
|
|
|
cl.getLogDialog().show();
|
|
|
|
}
|
|
|
|
|
|
|
|
GBApplication.deviceService().start();
|
|
|
|
|
|
|
|
if (GB.isBluetoothEnabled() && deviceList.isEmpty() && Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
|
|
|
|
startActivity(new Intent(this, DiscoveryActivity.class));
|
|
|
|
} else {
|
|
|
|
GBApplication.deviceService().requestDeviceInfo();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-07 23:26:24 +02:00
|
|
|
@Override
|
|
|
|
protected void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
if (isLanguageInvalid) {
|
|
|
|
isLanguageInvalid = false;
|
|
|
|
recreate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-28 00:19:24 +02:00
|
|
|
@Override
|
|
|
|
protected void onDestroy() {
|
|
|
|
unregisterForContextMenu(deviceListView);
|
|
|
|
LocalBroadcastManager.getInstance(this).unregisterReceiver(mReceiver);
|
|
|
|
super.onDestroy();
|
|
|
|
}
|
|
|
|
|
2016-10-21 13:01:30 +02:00
|
|
|
@Override
|
|
|
|
public void onBackPressed() {
|
2018-03-31 16:21:25 +02:00
|
|
|
DrawerLayout drawer = findViewById(R.id.drawer_layout);
|
2016-10-21 13:01:30 +02:00
|
|
|
if (drawer.isDrawerOpen(GravityCompat.START)) {
|
|
|
|
drawer.closeDrawer(GravityCompat.START);
|
|
|
|
} else {
|
|
|
|
super.onBackPressed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-16 17:44:59 +02:00
|
|
|
@Override
|
|
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
|
|
if (requestCode == MENU_REFRESH_CODE) {
|
2019-09-17 14:02:35 +02:00
|
|
|
showFabIfNeccessary();
|
2019-09-16 17:44:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-10-21 13:01:30 +02:00
|
|
|
@Override
|
2017-03-16 17:20:18 +01:00
|
|
|
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
|
2016-10-21 13:01:30 +02:00
|
|
|
|
2018-03-31 16:21:25 +02:00
|
|
|
DrawerLayout drawer = findViewById(R.id.drawer_layout);
|
2016-10-25 17:49:21 +02:00
|
|
|
drawer.closeDrawer(GravityCompat.START);
|
|
|
|
|
2016-10-21 13:01:30 +02:00
|
|
|
switch (item.getItemId()) {
|
|
|
|
case R.id.action_settings:
|
|
|
|
Intent settingsIntent = new Intent(this, SettingsActivity.class);
|
2019-09-16 17:44:59 +02:00
|
|
|
startActivityForResult(settingsIntent, MENU_REFRESH_CODE);
|
2016-10-21 13:01:30 +02:00
|
|
|
return true;
|
|
|
|
case R.id.action_debug:
|
|
|
|
Intent debugIntent = new Intent(this, DebugActivity.class);
|
|
|
|
startActivity(debugIntent);
|
|
|
|
return true;
|
|
|
|
case R.id.action_db_management:
|
|
|
|
Intent dbIntent = new Intent(this, DbManagementActivity.class);
|
|
|
|
startActivity(dbIntent);
|
|
|
|
return true;
|
2018-06-19 18:26:06 +02:00
|
|
|
case R.id.action_blacklist:
|
|
|
|
Intent blIntent = new Intent(this, AppBlacklistActivity.class);
|
|
|
|
startActivity(blIntent);
|
|
|
|
return true;
|
2019-09-08 12:07:10 +02:00
|
|
|
case R.id.device_action_discover:
|
|
|
|
launchDiscoveryActivity();
|
|
|
|
return true;
|
2016-10-21 13:01:30 +02:00
|
|
|
case R.id.action_quit:
|
|
|
|
GBApplication.quit();
|
|
|
|
return true;
|
2017-08-18 21:51:12 +02:00
|
|
|
case R.id.donation_link:
|
|
|
|
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("https://liberapay.com/Gadgetbridge")); //TODO: centralize if ever used somewhere else
|
|
|
|
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
startActivity(i);
|
|
|
|
return true;
|
2017-03-11 17:10:51 +01:00
|
|
|
case R.id.external_changelog:
|
2017-08-14 21:35:34 +02:00
|
|
|
ChangeLog cl = createChangeLog();
|
2017-03-11 17:10:51 +01:00
|
|
|
cl.getFullLogDialog().show();
|
|
|
|
return true;
|
2016-10-21 13:01:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-08-14 21:35:34 +02:00
|
|
|
private ChangeLog createChangeLog() {
|
|
|
|
String css = ChangeLog.DEFAULT_CSS;
|
|
|
|
css += "body { "
|
|
|
|
+ "color: " + AndroidUtils.getTextColorHex(getBaseContext()) + "; "
|
|
|
|
+ "background-color: " + AndroidUtils.getBackgroundColorHex(getBaseContext()) + ";" +
|
|
|
|
"}";
|
2019-09-17 14:02:35 +02:00
|
|
|
return new ChangeLog(this, css);
|
|
|
|
}
|
|
|
|
|
2016-10-21 13:01:30 +02:00
|
|
|
private void launchDiscoveryActivity() {
|
|
|
|
startActivity(new Intent(this, DiscoveryActivity.class));
|
|
|
|
}
|
|
|
|
|
|
|
|
private void refreshPairedDevices() {
|
|
|
|
mGBDeviceAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
|
2019-09-17 14:02:35 +02:00
|
|
|
private void showFabIfNeccessary() {
|
|
|
|
if (GBApplication.getPrefs().getBoolean("display_add_device_fab", true)) {
|
|
|
|
fab.show();
|
|
|
|
} else {
|
|
|
|
if (deviceListView.getChildCount() < 1) {
|
|
|
|
fab.show();
|
|
|
|
} else {
|
|
|
|
fab.hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-21 13:01:30 +02:00
|
|
|
@TargetApi(Build.VERSION_CODES.M)
|
|
|
|
private void checkAndRequestPermissions() {
|
|
|
|
List<String> wantedPermissions = new ArrayList<>();
|
|
|
|
|
|
|
|
if (ContextCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH) == PackageManager.PERMISSION_DENIED)
|
|
|
|
wantedPermissions.add(Manifest.permission.BLUETOOTH);
|
|
|
|
if (ContextCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH_ADMIN) == PackageManager.PERMISSION_DENIED)
|
|
|
|
wantedPermissions.add(Manifest.permission.BLUETOOTH_ADMIN);
|
|
|
|
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_DENIED)
|
|
|
|
wantedPermissions.add(Manifest.permission.READ_CONTACTS);
|
|
|
|
if (ContextCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) == PackageManager.PERMISSION_DENIED)
|
|
|
|
wantedPermissions.add(Manifest.permission.CALL_PHONE);
|
2018-09-05 20:41:01 +02:00
|
|
|
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_CALL_LOG) == PackageManager.PERMISSION_DENIED)
|
|
|
|
wantedPermissions.add(Manifest.permission.READ_CALL_LOG);
|
2016-10-21 13:01:30 +02:00
|
|
|
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_DENIED)
|
|
|
|
wantedPermissions.add(Manifest.permission.READ_PHONE_STATE);
|
|
|
|
if (ContextCompat.checkSelfPermission(this, Manifest.permission.PROCESS_OUTGOING_CALLS) == PackageManager.PERMISSION_DENIED)
|
|
|
|
wantedPermissions.add(Manifest.permission.PROCESS_OUTGOING_CALLS);
|
2018-03-17 15:58:44 +01:00
|
|
|
if (ContextCompat.checkSelfPermission(this, Manifest.permission.RECEIVE_SMS) == PackageManager.PERMISSION_DENIED)
|
|
|
|
wantedPermissions.add(Manifest.permission.RECEIVE_SMS);
|
2016-10-21 13:01:30 +02:00
|
|
|
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_SMS) == PackageManager.PERMISSION_DENIED)
|
|
|
|
wantedPermissions.add(Manifest.permission.READ_SMS);
|
|
|
|
if (ContextCompat.checkSelfPermission(this, Manifest.permission.SEND_SMS) == PackageManager.PERMISSION_DENIED)
|
|
|
|
wantedPermissions.add(Manifest.permission.SEND_SMS);
|
|
|
|
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED)
|
|
|
|
wantedPermissions.add(Manifest.permission.READ_EXTERNAL_STORAGE);
|
|
|
|
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_CALENDAR) == PackageManager.PERMISSION_DENIED)
|
|
|
|
wantedPermissions.add(Manifest.permission.READ_CALENDAR);
|
2018-04-07 00:24:38 +02:00
|
|
|
try {
|
|
|
|
if (ContextCompat.checkSelfPermission(this, Manifest.permission.MEDIA_CONTENT_CONTROL) == PackageManager.PERMISSION_DENIED)
|
|
|
|
wantedPermissions.add(Manifest.permission.MEDIA_CONTENT_CONTROL);
|
|
|
|
} catch (Exception ignored){
|
|
|
|
}
|
2016-10-21 13:01:30 +02:00
|
|
|
|
|
|
|
if (!wantedPermissions.isEmpty())
|
2019-09-17 14:02:35 +02:00
|
|
|
ActivityCompat.requestPermissions(this, wantedPermissions.toArray(new String[0]), 0);
|
2019-09-21 10:07:58 +02:00
|
|
|
|
|
|
|
// HACK: On Lineage we have to do this so that the permission dialog pops up
|
|
|
|
if (fakeStateListener == null) {
|
|
|
|
fakeStateListener = new PhoneStateListener();
|
|
|
|
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
|
|
|
|
telephonyManager.listen(fakeStateListener, PhoneStateListener.LISTEN_CALL_STATE);
|
|
|
|
telephonyManager.listen(fakeStateListener, PhoneStateListener.LISTEN_NONE);
|
|
|
|
}
|
2016-10-21 13:01:30 +02:00
|
|
|
}
|
|
|
|
|
2017-09-07 23:26:24 +02:00
|
|
|
public void setLanguage(Locale language, boolean invalidateLanguage) {
|
|
|
|
if (invalidateLanguage) {
|
|
|
|
isLanguageInvalid = true;
|
|
|
|
}
|
|
|
|
AndroidUtils.setLanguage(this, language);
|
2017-07-31 22:49:05 +02:00
|
|
|
}
|
2016-10-21 13:01:30 +02:00
|
|
|
}
|