86 lines
3.2 KiB
Java
86 lines
3.2 KiB
Java
/* Copyright 2017 Thomas Schneider
|
|
*
|
|
* This file is a part of Mastalab
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
|
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
|
* License, or (at your option) any later version.
|
|
*
|
|
* Mastalab 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 General
|
|
* Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along with Mastalab; if not,
|
|
* see <http://www.gnu.org/licenses>. */
|
|
package fr.gouv.etalab.mastodon.activities;
|
|
|
|
import android.content.DialogInterface;
|
|
import android.content.Intent;
|
|
|
|
import com.google.android.gms.common.GooglePlayServicesUtil;
|
|
import com.google.android.gms.security.ProviderInstaller;
|
|
import com.kobakei.ratethisapp.RateThisApp;
|
|
|
|
|
|
public class MainActivity extends BaseMainActivity
|
|
implements ProviderInstaller.ProviderInstallListener {
|
|
private static final int ERROR_DIALOG_REQUEST_CODE = 97;
|
|
|
|
@Override
|
|
protected void rateThisApp() {
|
|
RateThisApp.onCreate(this);
|
|
RateThisApp.showRateDialogIfNeeded(this);
|
|
}
|
|
|
|
@Override
|
|
protected void installProviders() {
|
|
ProviderInstaller.installIfNeededAsync(this, this);
|
|
}
|
|
|
|
@Override
|
|
public void onProviderInstalled() {
|
|
|
|
}
|
|
|
|
@Override
|
|
protected void onActivityResult(int requestCode, int resultCode,
|
|
Intent data) {
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
if (requestCode == ERROR_DIALOG_REQUEST_CODE) {
|
|
// Adding a fragment via GooglePlayServicesUtil.showErrorDialogFragment
|
|
// before the instance state is restored throws an error. So instead,
|
|
// set a flag here, which will cause the fragment to delay until
|
|
// onPostResume.
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
public void onProviderInstallFailed(int errorCode, Intent recoveryIntent) {
|
|
if (GooglePlayServicesUtil.isUserRecoverableError(errorCode)) {
|
|
// Recoverable error. Show a dialog prompting the user to
|
|
// install/update/enable Google Play services.
|
|
GooglePlayServicesUtil.showErrorDialogFragment(
|
|
errorCode,
|
|
this,
|
|
ERROR_DIALOG_REQUEST_CODE,
|
|
new DialogInterface.OnCancelListener() {
|
|
@Override
|
|
public void onCancel(DialogInterface dialog) {
|
|
// The user chose not to take the recovery action
|
|
onProviderInstallerNotAvailable();
|
|
}
|
|
});
|
|
} else {
|
|
// Google Play services is not available.
|
|
onProviderInstallerNotAvailable();
|
|
}
|
|
}
|
|
|
|
private void onProviderInstallerNotAvailable() {
|
|
// This is reached if the provider cannot be updated for some reason.
|
|
// App should consider all HTTP communication to be vulnerable, and take
|
|
// appropriate action.
|
|
}
|
|
}
|