android: Switch to AppCompat/Material theme for dialogs

There is no AppCompatProgressDialog class as the use of ProgressDialog
is discouraged (instead progress bars should be placed in the layout directly).
To display the current ProgressDialog instances correctly on systems < 21 we
modify the window background color.
This commit is contained in:
Tobias Brunner
2016-04-27 14:24:25 +02:00
parent 6b31828269
commit 77c1c28d74
10 changed files with 117 additions and 61 deletions
@@ -66,7 +66,7 @@
<activity
android:name=".ui.TrustedCertificateImportActivity"
android:label="@string/import_certificate"
android:theme="@style/Theme.AppCompat.Dialog" >
android:theme="@style/AlertDialogTheme" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
@@ -15,20 +15,20 @@
package org.strongswan.android.ui;
import org.strongswan.android.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatDialogFragment;
import org.strongswan.android.R;
/**
* Class that displays a confirmation dialog to delete a selected local
* certificate.
*/
public class CertificateDeleteConfirmationDialog extends DialogFragment
public class CertificateDeleteConfirmationDialog extends AppCompatDialogFragment
{
public static final String ALIAS = "alias";
OnCertificateDeleteListener mListener;
@@ -17,10 +17,7 @@
package org.strongswan.android.ui;
import android.app.Activity;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.app.DialogFragment;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
@@ -35,7 +32,9 @@ import android.os.AsyncTask;
import android.os.Bundle;
import android.os.IBinder;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.app.AppCompatDialogFragment;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
@@ -237,7 +236,7 @@ public class MainActivity extends AppCompatActivity implements OnVpnProfileSelec
ConfirmationDialog dialog = new ConfirmationDialog();
dialog.setArguments(profileInfo);
dialog.show(this.getFragmentManager(), DIALOG_TAG);
dialog.show(this.getSupportFragmentManager(), DIALOG_TAG);
return;
}
startVpnProfile(profileInfo);
@@ -255,7 +254,7 @@ public class MainActivity extends AppCompatActivity implements OnVpnProfileSelec
{
LoginDialog login = new LoginDialog();
login.setArguments(profileInfo);
login.show(getFragmentManager(), DIALOG_TAG);
login.show(getSupportFragmentManager(), DIALOG_TAG);
return;
}
prepareVpnService(profileInfo);
@@ -332,7 +331,7 @@ public class MainActivity extends AppCompatActivity implements OnVpnProfileSelec
* Class that displays a confirmation dialog if a VPN profile is already connected
* and then initiates the selected VPN profile if the user confirms the dialog.
*/
public static class ConfirmationDialog extends DialogFragment
public static class ConfirmationDialog extends AppCompatDialogFragment
{
@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
@@ -351,7 +350,7 @@ public class MainActivity extends AppCompatActivity implements OnVpnProfileSelec
button = R.string.reconnect;
}
return new Builder(getActivity())
return new AlertDialog.Builder(getActivity())
.setIcon(icon)
.setTitle(String.format(getString(title), profileInfo.getString(PROFILE_NAME)))
.setMessage(message)
@@ -379,7 +378,7 @@ public class MainActivity extends AppCompatActivity implements OnVpnProfileSelec
* Class that displays a login dialog and initiates the selected VPN
* profile if the user confirms the dialog.
*/
public static class LoginDialog extends DialogFragment
public static class LoginDialog extends AppCompatDialogFragment
{
@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
@@ -391,7 +390,7 @@ public class MainActivity extends AppCompatActivity implements OnVpnProfileSelec
username.setText(profileInfo.getString(VpnProfileDataSource.KEY_USERNAME));
final EditText password = (EditText)view.findViewById(R.id.password);
Builder adb = new Builder(getActivity());
AlertDialog.Builder adb = new AlertDialog.Builder(getActivity());
adb.setView(view);
adb.setTitle(getString(R.string.login_title));
adb.setPositiveButton(R.string.login_confirm, new DialogInterface.OnClickListener()
@@ -420,17 +419,17 @@ public class MainActivity extends AppCompatActivity implements OnVpnProfileSelec
* Class representing an error message which is displayed if VpnService is
* not supported on the current device.
*/
public static class VpnNotSupportedError extends DialogFragment
public static class VpnNotSupportedError extends AppCompatDialogFragment
{
static final String ERROR_MESSAGE_ID = "org.strongswan.android.VpnNotSupportedError.MessageId";
public static void showWithMessage(Activity activity, int messageId)
public static void showWithMessage(AppCompatActivity activity, int messageId)
{
Bundle bundle = new Bundle();
bundle.putInt(ERROR_MESSAGE_ID, messageId);
VpnNotSupportedError dialog = new VpnNotSupportedError();
dialog.setArguments(bundle);
dialog.show(activity.getFragmentManager(), DIALOG_TAG);
dialog.show(activity.getSupportFragmentManager(), DIALOG_TAG);
}
@Override
@@ -438,7 +437,7 @@ public class MainActivity extends AppCompatActivity implements OnVpnProfileSelec
{
final Bundle arguments = getArguments();
final int messageId = arguments.getInt(ERROR_MESSAGE_ID);
return new Builder(getActivity())
return new AlertDialog.Builder(getActivity())
.setTitle(R.string.vpn_not_supported_title)
.setMessage(messageId)
.setCancelable(false)
@@ -17,16 +17,16 @@ package org.strongswan.android.ui;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.app.FragmentTransaction;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.app.AppCompatDialogFragment;
import android.widget.Toast;
import org.strongswan.android.R;
@@ -119,7 +119,7 @@ public class TrustedCertificateImportActivity extends AppCompatActivity
Bundle args = new Bundle();
args.putSerializable(VpnProfileDataSource.KEY_CERTIFICATE, certificate);
dialog.setArguments(args);
FragmentTransaction ft = getFragmentManager().beginTransaction();
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.add(dialog, DIALOG_TAG);
ft.commit();
}
@@ -179,7 +179,7 @@ public class TrustedCertificateImportActivity extends AppCompatActivity
* Class that displays a confirmation dialog when a certificate should get
* imported. If the user confirms the import we try to store it.
*/
public static class ConfirmImportDialog extends DialogFragment
public static class ConfirmImportDialog extends AppCompatDialogFragment
{
@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
@@ -158,7 +158,7 @@ public class TrustedCertificatesActivity extends AppCompatActivity implements Tr
args.putString(CertificateDeleteConfirmationDialog.ALIAS, selected.getAlias());
CertificateDeleteConfirmationDialog dialog = new CertificateDeleteConfirmationDialog();
dialog.setArguments(args);
dialog.show(this.getFragmentManager(), DIALOG_TAG);
dialog.show(getSupportFragmentManager(), DIALOG_TAG);
}
}
}
@@ -17,9 +17,7 @@
package org.strongswan.android.ui;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
@@ -28,7 +26,9 @@ import android.os.Bundle;
import android.security.KeyChain;
import android.security.KeyChainAliasCallback;
import android.security.KeyChainException;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.app.AppCompatDialogFragment;
import android.text.Html;
import android.util.Log;
import android.view.Menu;
@@ -146,7 +146,7 @@ public class VpnProfileDetailActivity extends AppCompatActivity
@Override
public void onClick(View v)
{
new TncNoticeDialog().show(VpnProfileDetailActivity.this.getFragmentManager(), "TncNotice");
new TncNoticeDialog().show(VpnProfileDetailActivity.this.getSupportFragmentManager(), "TncNotice");
}
});
@@ -633,7 +633,7 @@ public class VpnProfileDetailActivity extends AppCompatActivity
/**
* Dialog with notification message if EAP-TNC is used.
*/
public static class TncNoticeDialog extends DialogFragment
public static class TncNoticeDialog extends AppCompatDialogFragment
{
@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
@@ -17,19 +17,6 @@
package org.strongswan.android.ui;
import java.util.ArrayList;
import java.util.List;
import org.strongswan.android.R;
import org.strongswan.android.data.VpnProfile;
import org.strongswan.android.logic.VpnStateService;
import org.strongswan.android.logic.VpnStateService.ErrorState;
import org.strongswan.android.logic.VpnStateService.State;
import org.strongswan.android.logic.VpnStateService.VpnStateListener;
import org.strongswan.android.logic.imc.ImcState;
import org.strongswan.android.logic.imc.RemediationInstruction;
import android.app.AlertDialog;
import android.app.Fragment;
import android.app.ProgressDialog;
import android.app.Service;
@@ -40,6 +27,7 @@ import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
@@ -47,6 +35,18 @@ import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import org.strongswan.android.R;
import org.strongswan.android.data.VpnProfile;
import org.strongswan.android.logic.VpnStateService;
import org.strongswan.android.logic.VpnStateService.ErrorState;
import org.strongswan.android.logic.VpnStateService.State;
import org.strongswan.android.logic.VpnStateService.VpnStateListener;
import org.strongswan.android.logic.imc.ImcState;
import org.strongswan.android.logic.imc.RemediationInstruction;
import java.util.ArrayList;
import java.util.List;
public class VpnStateFragment extends Fragment implements VpnStateListener
{
private static final String KEY_ERROR_CONNECTION_ID = "error_connection_id";
@@ -64,7 +64,8 @@ public class VpnStateFragment extends Fragment implements VpnStateListener
private long mErrorConnectionID;
private long mDismissedConnectionID;
private VpnStateService mService;
private final ServiceConnection mServiceConnection = new ServiceConnection() {
private final ServiceConnection mServiceConnection = new ServiceConnection()
{
@Override
public void onServiceDisconnected(ComponentName name)
{
@@ -334,18 +335,18 @@ public class VpnStateFragment extends Fragment implements VpnStateListener
mConnectDialog.setIndeterminate(true);
mConnectDialog.setCancelable(false);
mConnectDialog.setButton(DialogInterface.BUTTON_NEGATIVE,
getString(android.R.string.cancel),
new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
if (mService != null)
{
mService.disconnect();
}
}
});
getString(android.R.string.cancel),
new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
if (mService != null)
{
mService.disconnect();
}
}
});
mConnectDialog.show();
mProgressDialog = mConnectDialog;
}
@@ -374,7 +375,8 @@ public class VpnStateFragment extends Fragment implements VpnStateListener
mErrorDialog = new AlertDialog.Builder(getActivity())
.setMessage(getString(R.string.error_introduction) + " " + getString(textid))
.setCancelable(false)
.setNeutralButton(text, new DialogInterface.OnClickListener() {
.setNeutralButton(text, new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
@@ -394,7 +396,8 @@ public class VpnStateFragment extends Fragment implements VpnStateListener
startActivity(intent);
}
})
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int id)
{
@@ -402,7 +405,8 @@ public class VpnStateFragment extends Fragment implements VpnStateListener
dialog.dismiss();
}
}).create();
mErrorDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
mErrorDialog.setOnDismissListener(new DialogInterface.OnDismissListener()
{
@Override
public void onDismiss(DialogInterface dialog)
{
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2016 Tobias Brunner
HSR Hochschule fuer Technik Rapperswil
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 2 of the License, or (at your
option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
This program 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.
-->
<resources>
<style name="ApplicationTheme" parent="ApplicationTheme.Base">
</style>
<style name="AlertDialogTheme" parent="AlertDialogTheme.Base">
<item name="android:windowBackground">@android:color/transparent</item>
</style>
</resources>
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2016 Tobias Brunner
HSR Hochschule fuer Technik Rapperswil
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 2 of the License, or (at your
option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
This program 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.
-->
<resources>
<style name="ApplicationTheme" parent="ApplicationTheme.Base">
</style>
<style name="AlertDialogTheme" parent="AlertDialogTheme.Base">
</style>
</resources>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2012 Tobias Brunner
Hochschule fuer Technik Rapperswil
Copyright (C) 2012-2016 Tobias Brunner
HSR Hochschule fuer Technik Rapperswil
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
@@ -15,7 +15,11 @@
-->
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="ApplicationTheme" parent="Theme.AppCompat">
<style name="ApplicationTheme.Base" parent="Theme.AppCompat">
<item name="android:alertDialogTheme">@style/AlertDialogTheme</item>
</style>
<style name="AlertDialogTheme.Base" parent="Theme.AppCompat.Dialog.Alert">
</style>
</resources>