aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Brunner <tobias@strongswan.org>2017-06-27 10:12:35 +0200
committerTobias Brunner <tobias@strongswan.org>2017-07-03 10:27:53 +0200
commit0974addf93ed7d2a8ac9215f7cb0cd881d662747 (patch)
treedfeb4e920d54080df1bcd22482f53a9274fbf3a7
parent800f881ad0121ba51f1354e7e357fdea7bc8ebb7 (diff)
downloadstrongswan-0974addf93ed7d2a8ac9215f7cb0cd881d662747.tar.bz2
strongswan-0974addf93ed7d2a8ac9215f7cb0cd881d662747.tar.xz
android: Add a linear layout that is checkable
-rw-r--r--src/frontends/android/app/src/main/java/org/strongswan/android/ui/widget/CheckableLinearLayout.java66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/frontends/android/app/src/main/java/org/strongswan/android/ui/widget/CheckableLinearLayout.java b/src/frontends/android/app/src/main/java/org/strongswan/android/ui/widget/CheckableLinearLayout.java
new file mode 100644
index 000000000..fb5e85b0d
--- /dev/null
+++ b/src/frontends/android/app/src/main/java/org/strongswan/android/ui/widget/CheckableLinearLayout.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+package org.strongswan.android.ui.widget;
+
+import android.content.Context;
+import android.support.annotation.Nullable;
+import android.util.AttributeSet;
+import android.widget.Checkable;
+import android.widget.LinearLayout;
+
+public class CheckableLinearLayout extends LinearLayout implements Checkable
+{
+ private static final int[] CHECKED_STATE_SET = {android.R.attr.state_checked};
+ private boolean mChecked;
+
+ public CheckableLinearLayout(Context context, @Nullable AttributeSet attrs)
+ {
+ super(context, attrs);
+ }
+
+ @Override
+ public void setChecked(boolean checked)
+ {
+ if (mChecked != checked)
+ {
+ mChecked = checked;
+ refreshDrawableState();
+ }
+ }
+
+ @Override
+ public boolean isChecked()
+ {
+ return mChecked;
+ }
+
+ @Override
+ public void toggle()
+ {
+ setChecked(!mChecked);
+ }
+
+ @Override
+ protected int[] onCreateDrawableState(int extraSpace)
+ {
+ final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);
+ if (isChecked())
+ {
+ mergeDrawableStates(drawableState, CHECKED_STATE_SET);
+ }
+ return drawableState;
+ }
+}