diff --git a/app/build.gradle b/app/build.gradle
index 3bce9ad..6a4feda 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -7,8 +7,8 @@ android {
defaultConfig {
applicationId "org.docrj.smartcard.reader"
- versionCode 12
- versionName "1.2"
+ versionCode 13
+ versionName "1.3"
minSdkVersion 19
targetSdkVersion 21
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index e37c5b7..168831d 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -21,7 +21,6 @@
android:theme="@android:style/Theme.NoDisplay" >
-
@@ -46,9 +45,7 @@
android:theme="@android:style/Theme.NoDisplay" >
-
-
diff --git a/app/src/main/java/org/docrj/smartcard/reader/AnimatedExpandableListView.java b/app/src/main/java/org/docrj/smartcard/reader/AnimatedExpandableListView.java
new file mode 100644
index 0000000..21b723e
--- /dev/null
+++ b/app/src/main/java/org/docrj/smartcard/reader/AnimatedExpandableListView.java
@@ -0,0 +1,640 @@
+/*
+ * Copyright 2015 Ryan Jones
+ * Copyright (C) 2014 Gary Guo
+ *
+ * This file was modified from the original source:
+ * https://github.com/idunnololz/AnimatedExpandableListView
+ *
+ * This file is part of smartcard-reader, package org.docrj.smartcard.reader.
+ *
+ * smartcard-reader 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.
+ *
+ * smartcard-reader 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 smartcard-reader. If not, see .
+ */
+
+package org.docrj.smartcard.reader;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import android.annotation.SuppressLint;
+import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.drawable.Drawable;
+import android.os.Build;
+import android.util.AttributeSet;
+import android.util.SparseArray;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.animation.Animation;
+import android.view.animation.Animation.AnimationListener;
+import android.view.animation.Transformation;
+import android.widget.AbsListView;
+import android.widget.BaseExpandableListAdapter;
+import android.widget.ExpandableListAdapter;
+import android.widget.ExpandableListView;
+
+/**
+ * This class defines an ExpandableListView which supports animations for
+ * collapsing and expanding groups.
+ */
+public class AnimatedExpandableListView extends ExpandableListView {
+ /*
+ * A detailed explanation for how this class works:
+ *
+ * Animating the ExpandableListView was no easy task. The way that this
+ * class does it is by exploiting how an ExpandableListView works.
+ *
+ * Normally when {@link ExpandableListView#collapseGroup(int)} or
+ * {@link ExpandableListView#expandGroup(int)} is called, the view toggles
+ * the flag for a group and calls notifyDataSetChanged to cause the ListView
+ * to refresh all of it's view. This time however, depending on whether a
+ * group is expanded or collapsed, certain childViews will either be ignored
+ * or added to the list.
+ *
+ * Knowing this, we can come up with a way to animate our views. For
+ * instance for group expansion, we tell the adapter to animate the
+ * children of a certain group. We then expand the group which causes the
+ * ExpandableListView to refresh all views on screen. The way that
+ * ExpandableListView does this is by calling getView() in the adapter.
+ * However since the adapter knows that we are animating a certain group,
+ * instead of returning the real views for the children of the group being
+ * animated, it will return a fake dummy view. This dummy view will then
+ * draw the real child views within it's dispatchDraw function. The reason
+ * we do this is so that we can animate all of it's children by simply
+ * animating the dummy view. After we complete the animation, we tell the
+ * adapter to stop animating the group and call notifyDataSetChanged. Now
+ * the ExpandableListView is forced to refresh it's views again, except this
+ * time, it will get the real views for the expanded group.
+ *
+ * So, to list it all out, when {@link #expandGroupWithAnimation(int)} is
+ * called the following happens:
+ *
+ * 1. The ExpandableListView tells the adapter to animate a certain group.
+ * 2. The ExpandableListView calls expandGroup.
+ * 3. ExpandGroup calls notifyDataSetChanged.
+ * 4. As an result, getChildView is called for expanding group.
+ * 5. Since the adapter is in "animating mode", it will return a dummy view.
+ * 6. This dummy view draws the actual children of the expanding group.
+ * 7. This dummy view's height is animated from 0 to it's expanded height.
+ * 8. Once the animation completes, the adapter is notified to stop
+ * animating the group and notifyDataSetChanged is called again.
+ * 9. This forces the ExpandableListView to refresh all of it's views again.
+ * 10.This time when getChildView is called, it will return the actual
+ * child views.
+ *
+ * For animating the collapse of a group is a bit more difficult since we
+ * can't call collapseGroup from the start as it would just ignore the
+ * child memberApps, giving up no chance to do any sort of animation. Instead
+ * what we have to do is play the animation first and call collapseGroup
+ * after the animation is done.
+ *
+ * So, to list it all out, when {@link #collapseGroupWithAnimation(int)} is
+ * called the following happens:
+ *
+ * 1. The ExpandableListView tells the adapter to animate a certain group.
+ * 2. The ExpandableListView calls notifyDataSetChanged.
+ * 3. As an result, getChildView is called for expanding group.
+ * 4. Since the adapter is in "animating mode", it will return a dummy view.
+ * 5. This dummy view draws the actual children of the expanding group.
+ * 6. This dummy view's height is animated from it's current height to 0.
+ * 7. Once the animation completes, the adapter is notified to stop
+ * animating the group and notifyDataSetChanged is called again.
+ * 8. collapseGroup is finally called.
+ * 9. This forces the ExpandableListView to refresh all of it's views again.
+ * 10.This time when the ListView will not get any of the child views for
+ * the collapsed group.
+ */
+
+ @SuppressWarnings("unused")
+ private static final String TAG = AnimatedExpandableListAdapter.class.getSimpleName();
+
+ /**
+ * The duration of the expand/collapse animations
+ */
+ private static final int ANIMATION_DURATION = 300;
+
+ private AnimatedExpandableListAdapter adapter;
+
+ public AnimatedExpandableListView(Context context) {
+ super(context);
+ }
+
+ public AnimatedExpandableListView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public AnimatedExpandableListView(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ }
+
+ /**
+ * @see ExpandableListView#setAdapter(ExpandableListAdapter)
+ */
+ public void setAdapter(ExpandableListAdapter adapter) {
+ super.setAdapter(adapter);
+
+ // Make sure that the adapter extends AnimatedExpandableListAdapter
+ if(adapter instanceof AnimatedExpandableListAdapter) {
+ this.adapter = (AnimatedExpandableListAdapter) adapter;
+ this.adapter.setParent(this);
+ } else {
+ throw new ClassCastException(adapter.toString() + " must implement AnimatedExpandableListAdapter");
+ }
+ }
+
+ /**
+ * Expands the given group with an animation.
+ * @param groupPos The position of the group to expand
+ * @return Returns true if the group was expanded. False if the group was
+ * already expanded.
+ */
+ @SuppressLint("NewApi")
+ public boolean expandGroupWithAnimation(int groupPos) {
+ boolean lastGroup = groupPos == adapter.getGroupCount() - 1;
+ if (lastGroup && Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
+ return expandGroup(groupPos, true);
+ }
+
+ // TODO: removed this block as all seems good without it; it was causing null view
+ // and crash when expanding a group at the bottom of display, when (group - 1) was
+ // expanded with only children showing; in that case, getFirstVisiblePosition() was
+ // larger than groupFlatPos and so childIndex was negative
+ /*
+ int groupFlatPos = getFlatListPosition(getPackedPositionForGroup(groupPos));
+ if (groupFlatPos != -1) {
+ int childIndex = groupFlatPos - getFirstVisiblePosition();
+ if (childIndex < getChildCount()) {
+ // Get the view for the group is it is on screen...
+ View v = getChildAt(childIndex);
+ if (v.getBottom() >= getBottom()) {
+ // If the user is not going to be able to see the animation
+ // we just expand the group without an animation.
+ // This resolves the case where getChildView will not be
+ // called if the children of the group is not on screen
+
+ // We need to notify the adapter that the group was expanded
+ // without it's knowledge
+ adapter.notifyGroupExpanded(groupPos);
+ return expandGroup(groupPos);
+ }
+ }
+ }
+ */
+
+ // Let the adapter know that we are starting the animation...
+ adapter.startExpandAnimation(groupPos, 0);
+ // Finally call expandGroup (note that expandGroup will call
+ // notifyDataSetChanged so we don't need to)
+ return expandGroup(groupPos);
+ }
+
+ /**
+ * Collapses the given group with an animation.
+ * @param groupPos The position of the group to collapse
+ * @return Returns true if the group was collapsed. False if the group was
+ * already collapsed.
+ */
+ public boolean collapseGroupWithAnimation(int groupPos) {
+ int groupFlatPos = getFlatListPosition(getPackedPositionForGroup(groupPos));
+ if (groupFlatPos != -1) {
+ int childIndex = groupFlatPos - getFirstVisiblePosition();
+ if (childIndex >= 0 && childIndex < getChildCount()) {
+ // Get the view for the group is it is on screen...
+ View v = getChildAt(childIndex);
+ if (v.getBottom() >= getBottom()) {
+ // If the user is not going to be able to see the animation
+ // we just collapse the group without an animation.
+ // This resolves the case where getChildView will not be
+ // called if the children of the group is not on screen
+ return collapseGroup(groupPos);
+ }
+ } else {
+ // If the group is offscreen, we can just collapse it without an
+ // animation...
+ return collapseGroup(groupPos);
+ }
+ }
+
+ // Get the position of the firstChild visible from the top of the screen
+ long packedPos = getExpandableListPosition(getFirstVisiblePosition());
+ int firstChildPos = getPackedPositionChild(packedPos);
+ int firstGroupPos = getPackedPositionGroup(packedPos);
+
+ // If the first visible view on the screen is a child view AND it's a
+ // child of the group we are trying to collapse, then set that
+ // as the first child position of the group... see
+ // {@link #startCollapseAnimation(int, int)} for why this is necessary
+ firstChildPos = firstChildPos == -1 || firstGroupPos != groupPos ? 0 : firstChildPos;
+
+ // Let the adapter know that we are going to start animating the
+ // collapse animation.
+ adapter.startCollapseAnimation(groupPos, firstChildPos);
+
+ // Force the listview to refresh it's views
+ adapter.notifyDataSetChanged();
+ return isGroupExpanded(groupPos);
+ }
+
+ private int getAnimationDuration() {
+ return ANIMATION_DURATION;
+ }
+
+ public int getFirstVisibleGroup() {
+ int firstVis = getFirstVisiblePosition();
+ long packedPosition = getExpandableListPosition(firstVis);
+ return ExpandableListView.getPackedPositionGroup(packedPosition);
+ }
+
+ public int getLastVisibleGroup() {
+ int lastVis = getLastVisiblePosition();
+ long packedPosition = getExpandableListPosition(lastVis);
+ return ExpandableListView.getPackedPositionGroup(packedPosition);
+ }
+
+ /**
+ * Used for holding information regarding the group.
+ */
+ private static class GroupInfo {
+ boolean animating = false;
+ boolean expanding = false;
+ int firstChildPosition;
+
+ /**
+ * This variable contains the last known height value of the dummy view.
+ * We save this information so that if the user collapses a group
+ * before it fully expands, the collapse animation will start from the
+ * CURRENT height of the dummy view and not from the full expanded
+ * height.
+ */
+ int dummyHeight = -1;
+ }
+
+ /**
+ * A specialized adapter for use with the AnimatedExpandableListView. All
+ * adapters used with AnimatedExpandableListView MUST extend this class.
+ */
+ public static abstract class AnimatedExpandableListAdapter extends BaseExpandableListAdapter {
+ private SparseArray groupInfo = new SparseArray();
+ private AnimatedExpandableListView parent;
+
+ private static final int STATE_IDLE = 0;
+ private static final int STATE_EXPANDING = 1;
+ private static final int STATE_COLLAPSING = 2;
+
+ private void setParent(AnimatedExpandableListView parent) {
+ this.parent = parent;
+ }
+
+ public int getRealChildType(int groupPosition, int childPosition) {
+ return 0;
+ }
+
+ public int getRealChildTypeCount() {
+ return 1;
+ }
+
+ public abstract View getRealChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent);
+ public abstract int getRealChildrenCount(int groupPosition);
+
+ private GroupInfo getGroupInfo(int groupPosition) {
+ GroupInfo info = groupInfo.get(groupPosition);
+ if (info == null) {
+ info = new GroupInfo();
+ groupInfo.put(groupPosition, info);
+ }
+ return info;
+ }
+
+ public void notifyGroupExpanded(int groupPosition) {
+ GroupInfo info = getGroupInfo(groupPosition);
+ info.dummyHeight = -1;
+ }
+
+ private void startExpandAnimation(int groupPosition, int firstChildPosition) {
+ GroupInfo info = getGroupInfo(groupPosition);
+ info.animating = true;
+ info.firstChildPosition = firstChildPosition;
+ info.expanding = true;
+ }
+
+ private void startCollapseAnimation(int groupPosition, int firstChildPosition) {
+ GroupInfo info = getGroupInfo(groupPosition);
+ info.animating = true;
+ info.firstChildPosition = firstChildPosition;
+ info.expanding = false;
+ }
+
+ private void stopAnimation(int groupPosition) {
+ GroupInfo info = getGroupInfo(groupPosition);
+ info.animating = false;
+ }
+
+ /**
+ * Override {@link #getRealChildType(int, int)} instead.
+ */
+ @Override
+ public final int getChildType(int groupPosition, int childPosition) {
+ GroupInfo info = getGroupInfo(groupPosition);
+ if (info.animating) {
+ // If we are animating this group, then all of it's children
+ // are going to be dummy views which we will say is type 0.
+ return 0;
+ } else {
+ // If we are not animating this group, then we will add 1 to
+ // the type it has so that no type id conflicts will occur
+ // unless getRealChildType() returns MAX_INT
+ return getRealChildType(groupPosition, childPosition) + 1;
+ }
+ }
+
+ /**
+ * Override {@link #getRealChildTypeCount()} instead.
+ */
+ @Override
+ public final int getChildTypeCount() {
+ // Return 1 more than the childTypeCount to account for DummyView
+ return getRealChildTypeCount() + 1;
+ }
+
+ protected ViewGroup.LayoutParams generateDefaultLayoutParams() {
+ return new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.WRAP_CONTENT, 0);
+ }
+
+ /**
+ * Override {@link #getChildView(int, int, boolean, View, ViewGroup)} instead.
+ */
+ @Override
+ public final View getChildView(final int groupPosition, int childPosition, boolean isLastChild, View convertView, final ViewGroup parent) {
+ final GroupInfo info = getGroupInfo(groupPosition);
+
+ if (info.animating) {
+ // If this group is animating, return the a DummyView...
+ if (convertView instanceof DummyView == false) {
+ convertView = new DummyView(parent.getContext());
+ convertView.setLayoutParams(new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT, 0));
+ }
+
+ if (childPosition < info.firstChildPosition) {
+ // The reason why we do this is to support the collapse
+ // this group when the group view is not visible but the
+ // children of this group are. When notifyDataSetChanged
+ // is called, the ExpandableListView tries to keep the
+ // list position the same by saving the first visible item
+ // and jumping back to that item after the views have been
+ // refreshed. Now the problem is, if a group has 2 memberApps
+ // and the first visible item is the 2nd child of the group
+ // and this group is collapsed, then the dummy view will be
+ // used for the group. But now the group only has 1 item
+ // which is the dummy view, thus when the ListView is trying
+ // to restore the scroll position, it will try to jump to
+ // the second item of the group. But this group no longer
+ // has a second item, so it is forced to jump to the next
+ // group. This will cause a very ugly visual glitch. So
+ // the way that we counteract this is by creating as many
+ // dummy views as we need to maintain the scroll position
+ // of the ListView after notifyDataSetChanged has been
+ // called.
+ convertView.getLayoutParams().height = 0;
+ return convertView;
+ }
+
+ final ExpandableListView listView = (ExpandableListView) parent;
+
+ final DummyView dummyView = (DummyView) convertView;
+
+ // Clear the views that the dummy view draws.
+ dummyView.clearViews();
+
+ // Set the style of the divider
+ dummyView.setDivider(listView.getDivider(), parent.getMeasuredWidth(), listView.getDividerHeight());
+
+ // Make measure specs to measure child views
+ final int measureSpecW = MeasureSpec.makeMeasureSpec(parent.getWidth(), MeasureSpec.EXACTLY);
+ final int measureSpecH = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
+
+ int totalHeight = 0;
+ int clipHeight = parent.getHeight();
+
+ final int len = getRealChildrenCount(groupPosition);
+ for (int i = info.firstChildPosition; i < len; i++) {
+ View childView = getRealChildView(groupPosition, i, (i == len - 1), null, parent);
+
+ LayoutParams p = (LayoutParams) childView.getLayoutParams();
+ if (p == null) {
+ p = (AbsListView.LayoutParams) generateDefaultLayoutParams();
+ childView.setLayoutParams(p);
+ }
+
+ int lpHeight = p.height;
+
+ int childHeightSpec;
+ if (lpHeight > 0) {
+ childHeightSpec = MeasureSpec.makeMeasureSpec(lpHeight, MeasureSpec.EXACTLY);
+ } else {
+ childHeightSpec = measureSpecH;
+ }
+
+ childView.measure(measureSpecW, childHeightSpec);
+ totalHeight += childView.getMeasuredHeight();
+
+ if (totalHeight < clipHeight) {
+ // we only need to draw enough views to fool the user...
+ dummyView.addFakeView(childView);
+ } else {
+ dummyView.addFakeView(childView);
+
+ // if this group has too many views, we don't want to
+ // calculate the height of everything... just do a light
+ // approximation and break
+ int averageHeight = totalHeight / (i + 1);
+ totalHeight += (len - i - 1) * averageHeight;
+ break;
+ }
+ }
+
+ Object o;
+ int state = (o = dummyView.getTag()) == null ? STATE_IDLE : (Integer) o;
+
+ if (info.expanding && state != STATE_EXPANDING) {
+ ExpandAnimation ani = new ExpandAnimation(dummyView, 0, totalHeight, info);
+ ani.setDuration(this.parent.getAnimationDuration());
+ ani.setAnimationListener(new AnimationListener() {
+
+ @Override
+ public void onAnimationEnd(Animation animation) {
+ stopAnimation(groupPosition);
+ notifyDataSetChanged();
+ dummyView.setTag(STATE_IDLE);
+ }
+
+ @Override
+ public void onAnimationRepeat(Animation animation) {}
+
+ @Override
+ public void onAnimationStart(Animation animation) {}
+
+ });
+ dummyView.startAnimation(ani);
+ dummyView.setTag(STATE_EXPANDING);
+ } else if (!info.expanding && state != STATE_COLLAPSING) {
+ if (info.dummyHeight == -1) {
+ info.dummyHeight = totalHeight;
+ }
+
+ ExpandAnimation ani = new ExpandAnimation(dummyView, info.dummyHeight, 0, info);
+ ani.setDuration(this.parent.getAnimationDuration());
+ ani.setAnimationListener(new AnimationListener() {
+
+ @Override
+ public void onAnimationEnd(Animation animation) {
+ stopAnimation(groupPosition);
+ listView.collapseGroup(groupPosition);
+ notifyDataSetChanged();
+ info.dummyHeight = -1;
+ dummyView.setTag(STATE_IDLE);
+ }
+
+ @Override
+ public void onAnimationRepeat(Animation animation) {}
+
+ @Override
+ public void onAnimationStart(Animation animation) {}
+
+ });
+ dummyView.startAnimation(ani);
+ dummyView.setTag(STATE_COLLAPSING);
+ }
+
+ return convertView;
+ } else {
+ return getRealChildView(groupPosition, childPosition, isLastChild, convertView, parent);
+ }
+ }
+
+ @Override
+ public final int getChildrenCount(int groupPosition) {
+ GroupInfo info = getGroupInfo(groupPosition);
+ if (info.animating) {
+ return info.firstChildPosition + 1;
+ } else {
+ return getRealChildrenCount(groupPosition);
+ }
+ }
+
+ }
+
+ private static class DummyView extends View {
+ private List views = new ArrayList();
+ private Drawable divider;
+ private int dividerWidth;
+ private int dividerHeight;
+
+ public DummyView(Context context) {
+ super(context);
+ }
+
+ public void setDivider(Drawable divider, int dividerWidth, int dividerHeight) {
+ if(divider != null) {
+ this.divider = divider;
+ this.dividerWidth = dividerWidth;
+ this.dividerHeight = dividerHeight;
+
+ divider.setBounds(0, 0, dividerWidth, dividerHeight);
+ }
+ }
+
+ /**
+ * Add a view for the DummyView to draw.
+ * @param childView View to draw
+ */
+ public void addFakeView(View childView) {
+ childView.layout(0, 0, getWidth(), childView.getMeasuredHeight());
+ views.add(childView);
+ }
+
+ @Override
+ protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
+ super.onLayout(changed, left, top, right, bottom);
+ final int len = views.size();
+ for(int i = 0; i < len; i++) {
+ View v = views.get(i);
+ v.layout(left, top, left + v.getMeasuredWidth(), top + v.getMeasuredHeight());
+ }
+ }
+
+ public void clearViews() {
+ views.clear();
+ }
+
+ @Override
+ public void dispatchDraw(Canvas canvas) {
+ canvas.save();
+ if(divider != null) {
+ divider.setBounds(0, 0, dividerWidth, dividerHeight);
+ }
+
+ final int len = views.size();
+ for(int i = 0; i < len; i++) {
+ View v = views.get(i);
+
+ canvas.save();
+ canvas.clipRect(0, 0, getWidth(), v.getMeasuredHeight());
+ v.draw(canvas);
+ canvas.restore();
+
+ if(divider != null) {
+ divider.draw(canvas);
+ canvas.translate(0, dividerHeight);
+ }
+
+ canvas.translate(0, v.getMeasuredHeight());
+ }
+
+ canvas.restore();
+ }
+ }
+
+ private static class ExpandAnimation extends Animation {
+ private int baseHeight;
+ private int delta;
+ private View view;
+ private GroupInfo groupInfo;
+
+ private ExpandAnimation(View v, int startHeight, int endHeight, GroupInfo info) {
+ baseHeight = startHeight;
+ delta = endHeight - startHeight;
+ view = v;
+ groupInfo = info;
+
+ view.getLayoutParams().height = startHeight;
+ view.requestLayout();
+ }
+
+ @Override
+ protected void applyTransformation(float interpolatedTime, Transformation t) {
+ super.applyTransformation(interpolatedTime, t);
+ if (interpolatedTime < 1.0f) {
+ int val = baseHeight + (int) (delta * interpolatedTime);
+ view.getLayoutParams().height = val;
+ groupInfo.dummyHeight = val;
+ view.requestLayout();
+ } else {
+ int val = baseHeight + delta;
+ view.getLayoutParams().height = val;
+ groupInfo.dummyHeight = val;
+ view.requestLayout();
+ }
+ }
+ }
+}
diff --git a/app/src/main/java/org/docrj/smartcard/reader/AppEditActivity.java b/app/src/main/java/org/docrj/smartcard/reader/AppEditActivity.java
index ebb1d05..546a81d 100644
--- a/app/src/main/java/org/docrj/smartcard/reader/AppEditActivity.java
+++ b/app/src/main/java/org/docrj/smartcard/reader/AppEditActivity.java
@@ -49,8 +49,10 @@ import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashSet;
+import java.util.List;
public class AppEditActivity extends ActionBarActivity {
@@ -73,7 +75,13 @@ public class AppEditActivity extends ActionBarActivity {
private SharedPreferences.Editor mEditor;
private ArrayList mApps;
private String mAction;
- private int mAppPos;
+ private int mAppPos; // app select pos
+
+ private List mSortedAllGroups;
+ private int mSelectedGrpPos; // batch select group idx
+ private String mSelectedGrpName;
+ private int mExpandedGrpPos; // app browse group idx
+ private String mExpandedGrpName;
private EditText mName;
private EditText mAid;
@@ -85,7 +93,7 @@ public class AppEditActivity extends ActionBarActivity {
private HashSet mAppGroups;
private Button mGrpButton;
- // group items for the popup window list adapter
+ // group memberApps for the popup window list adapter
private ArrayList mGrpItems = new ArrayList<>();
private GroupAdapter mGrpAdapter;
private ListPopupWindow mPopup;
@@ -136,14 +144,24 @@ public class AppEditActivity extends ActionBarActivity {
Type collectionType = new TypeToken>() {
}.getType();
mUserGroups = gson.fromJson(json, collectionType);
- // here we do not need the default groups payment/other
- //mUserGroups.removeAll(Arrays.asList(DEFAULT_GROUPS));
}
} else {
mUserGroups =
new LinkedHashSet<>(savedInstanceState.getStringArrayList("user_groups"));
}
+ // alphabetize, case insensitive
+ mSortedAllGroups = new ArrayList<>(mUserGroups);
+ mSortedAllGroups.addAll(Arrays.asList(DEFAULT_GROUPS));
+ Collections.sort(mSortedAllGroups, String.CASE_INSENSITIVE_ORDER);
+
+ // when adding or removing groups, we may need to adjust group position indices for
+ // batch select and app browse activities, which apply to the sorted list of groups
+ mSelectedGrpPos = ss.getInt("selected_grp_pos", 0);
+ mSelectedGrpName = mSortedAllGroups.get(mSelectedGrpPos);
+ mExpandedGrpPos = ss.getInt("expanded_grp_pos", -1);
+ mExpandedGrpName = (mExpandedGrpPos == -1) ? "" : mSortedAllGroups.get(mExpandedGrpPos);
+
Intent intent = getIntent();
mAction = intent.getAction();
mAppPos = intent.getIntExtra(EXTRA_APP_POS, NEW_APP_POS);
@@ -159,6 +177,7 @@ public class AppEditActivity extends ActionBarActivity {
mType.check((app.getType() == SmartcardApp.TYPE_OTHER) ? R.id.radio_other
: R.id.radio_payment);
}
+
if (savedInstanceState == null) {
if (ACTION_EDIT_APP.equals(mAction) || ACTION_COPY_APP.equals(mAction)) {
SmartcardApp app = mApps.get(mAppPos);
@@ -305,6 +324,15 @@ public class AppEditActivity extends ActionBarActivity {
if (!newApp.equals(app)) {
appChanged = true;
mApps.set(mAppPos, newApp);
+
+ if (!newApp.getGroups().equals(app.getGroups())) {
+ for (String group : app.getGroups()) {
+ // remove group if empty
+ if (Util.isGroupEmpty(group, mApps)) {
+ removeGroup(group);
+ }
+ }
+ }
}
}
@@ -327,14 +355,17 @@ public class AppEditActivity extends ActionBarActivity {
}
private void writePrefs() {
- // serialize list of SmartcardApp
+ // serialize list of apps
Gson gson = new Gson();
String json = gson.toJson(mApps);
mEditor.putString("apps", json);
-
- // TODO: check this. shouldn't we store defaults: payment/other
+ // serialize hash set of user-added groups
json = gson.toJson(mUserGroups);
mEditor.putString("groups", json);
+ // selected group in batch select mode
+ mEditor.putInt("selected_grp_pos", mSelectedGrpPos);
+ // expanded group in app browse
+ mEditor.putInt("expanded_grp_pos", mExpandedGrpPos);
mEditor.commit();
}
@@ -378,11 +409,49 @@ public class AppEditActivity extends ActionBarActivity {
}
mAppGroups.add(name);
mUserGroups.add(name);
+ // if inserting alphabetically "smaller" group name,
+ // then adjust the saved group position indices
+ if (name.compareTo(mSelectedGrpName) < 0) {
+ mSelectedGrpPos++;
+ mSelectedGrpName = mSortedAllGroups.get(mSelectedGrpPos);
+ }
+ if (name.compareTo(mExpandedGrpName) < 0) {
+ mExpandedGrpPos++;
+ mExpandedGrpName = mSortedAllGroups.get(mExpandedGrpPos);
+ }
updateGrpButton();
}
});
}
+ private void removeGroup(String name) {
+ // remove from saved hash set
+ mUserGroups.remove(name);
+ // adjust selected group position indices as needed
+ if (name.equals(mSelectedGrpName)) {
+ // always guaranteed at least two groups: other and payment
+ mSelectedGrpName = (mSelectedGrpPos == 0) ?
+ mSortedAllGroups.get(1) : mSortedAllGroups.get(0);
+ mSelectedGrpPos = 0;
+ } else
+ if (name.compareTo(mSelectedGrpName) < 0) {
+ mSelectedGrpPos--;
+ mSelectedGrpName = mSortedAllGroups.get(mSelectedGrpPos);
+ }
+ // adjust expanded group position index as needed
+ if (name.equals(mExpandedGrpName)) {
+ // no expanded group; all collapsed
+ mExpandedGrpPos = -1;
+ mExpandedGrpName = "";
+ } else
+ if (name.compareTo(mExpandedGrpName) < 0) {
+ mExpandedGrpPos--;
+ mExpandedGrpName = mSortedAllGroups.get(mExpandedGrpPos);
+ }
+ // remove from sorted list
+ mSortedAllGroups.remove(name);
+ }
+
public static final class GroupItem {
private final String mName;
private boolean mChecked;
@@ -408,7 +477,7 @@ public class AppEditActivity extends ActionBarActivity {
private class GroupAdapter extends ArrayAdapter {
public GroupAdapter(Activity context, ArrayList groupItems) {
- super(context, R.layout.group_list_item, groupItems);
+ super(context, R.layout.app_edit_group_list_item, groupItems);
}
@Override
@@ -428,15 +497,20 @@ public class AppEditActivity extends ActionBarActivity {
return checkedTextView;
}
+ // list position (count - 2) is reserved for payment/other;
+ // it is informational only and cannot be unchecked
@Override
public boolean isEnabled(int position) {
return position != getCount()-2;
}
+ // list position (count - 1) is reserved for "new group" action item
+ // does not have a checkbox
public boolean hasCheckbox(int position) {
return position != getCount()-1;
}
+ // this is needed for getView() to work as expected
@Override
public int getItemViewType(int position) {
if (hasCheckbox(position)) {
@@ -446,6 +520,7 @@ public class AppEditActivity extends ActionBarActivity {
}
}
+ // this is needed for getView() to work as expected
@Override
public int getViewTypeCount() {
return 3;
@@ -457,10 +532,9 @@ public class AppEditActivity extends ActionBarActivity {
@Override
public void onItemClick(AdapterView> parent, View view, int position, long id) {
ListView list = (ListView) parent;
- int count = mGrpItems.size();
-
- if (list.isItemChecked(count - 1)) {
- list.setItemChecked(count - 1, false);
+ int lastIndex = mGrpItems.size() - 1;
+ if (list.isItemChecked(lastIndex)) {
+ list.setItemChecked(lastIndex, false);
createNewGroup();
return;
}
diff --git a/app/src/main/java/org/docrj/smartcard/reader/AppSelectActivity.java b/app/src/main/java/org/docrj/smartcard/reader/AppSelectActivity.java
index 4113bb3..c94737c 100644
--- a/app/src/main/java/org/docrj/smartcard/reader/AppSelectActivity.java
+++ b/app/src/main/java/org/docrj/smartcard/reader/AppSelectActivity.java
@@ -21,6 +21,8 @@ package org.docrj.smartcard.reader;
import java.lang.reflect.Type;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
import android.app.Dialog;
import android.content.Context;
@@ -69,30 +71,30 @@ public class AppSelectActivity extends ActionBarActivity implements ReaderXcvr.U
private static final String[] GROUPS = SmartcardApp.GROUPS;
- // update all five items below when adding/removing default apps!
+ // update all five memberApps below when adding/removing default apps!
static final int DEFAULT_APP_POS = 0;
static final String[] APP_NAMES = {
"Amex", "Amex 5-Byte", "Amex 7-Byte", // American Express ExpressPay
- "Amex 8-Byte",
+ "Amex 8-Byte", // ""
"Discover", // Discover Zip
"MasterCard", "MasterCard U.S.", // MasterCard PayPass
- "Visa", "Visa Credit", "Visa Debit", // Visa PayWave
- "Test Pay", "Test Other"
+ "Test Other", "Test Pay", // test
+ "Visa", "Visa Credit", "Visa Debit" // Visa PayWave
};
static final String[] APP_AIDS = {
"A00000002501", "A000000025", "A0000000250107",
"A000000025010701",
"A0000003241010",
"A0000000041010", "A0000000042203",
+ "F07465737420414944", "F07465737420414944",
"A0000000031010", "A000000003101001", "A000000003101002",
- "F07465737420414944", "F07465737420414944"
};
// all are payment type except "Test Other"
static final int[] APP_TYPES = {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
+ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0
};
static final int[] APP_READ_ONLY = {
- 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0
+ 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0
};
// dialogs
@@ -280,6 +282,10 @@ public class AppSelectActivity extends ActionBarActivity implements ReaderXcvr.U
Gson gson = new Gson();
Type collectionType = new TypeToken>() {}.getType();
mApps = gson.fromJson(json, collectionType);
+
+ // TODO: remove
+ //Collections.sort(mApps, SmartcardApp.nameComparator);
+
mSelectedAppPos = ss.getInt("selected_app_pos", mSelectedAppPos);
// do not clear messages for this selection on resume;
@@ -300,18 +306,18 @@ public class AppSelectActivity extends ActionBarActivity implements ReaderXcvr.U
@Override
public void onPause() {
- super.onPause();
writePrefs();
releaseSoundPool();
mConsole.onPause();
mNfcManager.onPause();
+ super.onPause();
}
@Override
public void onStop() {
- super.onStop();
// dismiss enable NFC dialog
mNfcManager.onStop();
+ super.onStop();
}
@Override
diff --git a/app/src/main/java/org/docrj/smartcard/reader/AppViewActivity.java b/app/src/main/java/org/docrj/smartcard/reader/AppViewActivity.java
index 9174597..e5e1033 100644
--- a/app/src/main/java/org/docrj/smartcard/reader/AppViewActivity.java
+++ b/app/src/main/java/org/docrj/smartcard/reader/AppViewActivity.java
@@ -45,7 +45,11 @@ import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.List;
public class AppViewActivity extends ActionBarActivity {
@@ -74,6 +78,13 @@ public class AppViewActivity extends ActionBarActivity {
private int mAppPos;
private boolean mReadOnly;
+ private HashSet mUserGroups;
+ private List mSortedAllGroups;
+ private int mSelectedGrpPos; // batch select group idx
+ private String mSelectedGrpName;
+ private int mExpandedGrpPos; // app browse group idx
+ private String mExpandedGrpName;
+
private EditText mName;
private EditText mAid;
private RadioGroup mType;
@@ -81,6 +92,7 @@ public class AppViewActivity extends ActionBarActivity {
private TextView mNote;
private AlertDialog mConfirmDeleteDialog;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -101,6 +113,29 @@ public class AppViewActivity extends ActionBarActivity {
mSelectedAppPos = ss.getInt("selected_app_pos", 0);
+ Gson gson = new Gson();
+ String json = ss.getString("groups", null);
+ if (json == null) {
+ mUserGroups = new LinkedHashSet<>();
+ } else {
+ Type collectionType = new TypeToken>() {
+ }.getType();
+ mUserGroups = gson.fromJson(json, collectionType);
+ }
+
+ // alphabetize, case insensitive
+ mSortedAllGroups = new ArrayList<>(mUserGroups);
+ mSortedAllGroups.addAll(Arrays.asList(DEFAULT_GROUPS));
+ Collections.sort(mSortedAllGroups, String.CASE_INSENSITIVE_ORDER);
+
+ // when deleting an app results in an empty group, we remove the group;
+ // we may need to adjust group position indices for batch select and app
+ // browse activities, which apply to the sorted list of groups
+ mSelectedGrpPos = ss.getInt("selected_grp_pos", 0);
+ mSelectedGrpName = mSortedAllGroups.get(mSelectedGrpPos);
+ mExpandedGrpPos = ss.getInt("expanded_grp_pos", -1);
+ mExpandedGrpName = (mExpandedGrpPos == -1) ? "" : mSortedAllGroups.get(mExpandedGrpPos);
+
Intent intent = getIntent();
mAppPos = intent.getIntExtra(EXTRA_APP_POS, 0);
@@ -255,7 +290,17 @@ public class AppViewActivity extends ActionBarActivity {
} else if (mSelectedAppPos > mAppPos) {
mSelectedAppPos--;
}
- mApps.remove(mAppPos);
+ // remove app from list
+ SmartcardApp app = mApps.remove(mAppPos);
+ HashSet groups = app.getGroups();
+ // only bother if assigned to more than the default other/payment group
+ if (groups.size() > 1) {
+ for (String group : groups) {
+ if (Util.isGroupEmpty(group, mApps)) {
+ removeGroup(group);
+ }
+ }
+ }
writePrefs();
finish();
}
@@ -306,11 +351,47 @@ public class AppViewActivity extends ActionBarActivity {
}
private void writePrefs() {
- // serialize list of SmartcardApp
+ // serialize list of apps
Gson gson = new Gson();
String json = gson.toJson(mApps);
mEditor.putString("apps", json);
+ // selected app in app select mode
mEditor.putInt("selected_app_pos", mSelectedAppPos);
+ // serialize hash set of user-added groups
+ json = gson.toJson(mUserGroups);
+ mEditor.putString("groups", json);
+ // selected group in batch select mode
+ mEditor.putInt("selected_grp_pos", mSelectedGrpPos);
+ // expanded group in app browse
+ mEditor.putInt("expanded_grp_pos", mExpandedGrpPos);
mEditor.commit();
}
+
+ private void removeGroup(String name) {
+ // remove from saved hash set
+ mUserGroups.remove(name);
+ // adjust selected group position indices as needed
+ if (name.equals(mSelectedGrpName)) {
+ // always guaranteed at least two groups: other and payment
+ mSelectedGrpName = (mSelectedGrpPos == 0) ?
+ mSortedAllGroups.get(1) : mSortedAllGroups.get(0);
+ mSelectedGrpPos = 0;
+ } else
+ if (name.compareTo(mSelectedGrpName) < 0) {
+ mSelectedGrpPos--;
+ mSelectedGrpName = mSortedAllGroups.get(mSelectedGrpPos);
+ }
+ // adjust expanded group position index as needed
+ if (name.equals(mExpandedGrpName)) {
+ // no expanded group; all collapsed
+ mExpandedGrpPos = -1;
+ mExpandedGrpName = "";
+ } else
+ if (name.compareTo(mExpandedGrpName) < 0) {
+ mExpandedGrpPos--;
+ mExpandedGrpName = mSortedAllGroups.get(mExpandedGrpPos);
+ }
+ // remove from sorted list
+ mSortedAllGroups.remove(name);
+ }
}
diff --git a/app/src/main/java/org/docrj/smartcard/reader/AppsListActivity.java b/app/src/main/java/org/docrj/smartcard/reader/AppsListActivity.java
index 0d7f2e5..935ede2 100644
--- a/app/src/main/java/org/docrj/smartcard/reader/AppsListActivity.java
+++ b/app/src/main/java/org/docrj/smartcard/reader/AppsListActivity.java
@@ -19,32 +19,49 @@
package org.docrj.smartcard.reader;
-import android.os.Build;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.graphics.drawable.Drawable;
+import android.os.Build;
import android.os.Bundle;
+import android.os.Handler;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.Toolbar;
+import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
+import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
-import android.widget.AdapterView;
-import android.widget.ListView;
+import android.widget.ExpandableListView;
+import android.widget.ExpandableListView.OnGroupClickListener;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import org.docrj.smartcard.reader.AnimatedExpandableListView.AnimatedExpandableListAdapter;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.List;
public class AppsListActivity extends ActionBarActivity {
private static final String TAG = LaunchActivity.TAG;
+ private static final String[] DEFAULT_GROUPS = SmartcardApp.GROUPS;
+
// actions
static final String ACTION_NEW_APP = "org.docrj.smartcard.reader.action_new_app";
static final String ACTION_VIEW_APP = "org.docrj.smartcard.reader.action_view_app";
@@ -54,9 +71,14 @@ public class AppsListActivity extends ActionBarActivity {
// extras
static final String EXTRA_APP_POS = "org.docrj.smartcard.reader.app_pos";
- private ListView mAppListView;
+ private Handler mHandler;
+ private SharedPreferences.Editor mEditor;
+ private AnimatedExpandableListView mGrpListView;
+ // groups created by user (no payment/other)
+ private HashSet mGroups;
private ArrayList mApps;
- private int mSelectedAppPos = 0;
+ private GroupAdapter mGrpAdapter;
+ private int mExpandedGrp = -1;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -72,20 +94,46 @@ public class AppsListActivity extends ActionBarActivity {
}
});
- mAppListView = (ListView) findViewById(R.id.listView);
- mAppListView.setOnItemClickListener(new ListView.OnItemClickListener() {
- @SuppressWarnings("deprecation")
+ mGrpListView = (AnimatedExpandableListView) findViewById(R.id.listView);
+ // custom click handler so we can animate
+ mGrpListView.setOnGroupClickListener(new OnGroupClickListener() {
@Override
- public void onItemClick(AdapterView> parent, View view,
- int pos, long id) {
+ public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
+ if (mGrpListView.isGroupExpanded(groupPosition)) {
+ mGrpListView.collapseGroupWithAnimation(groupPosition);
+ mExpandedGrp = -1;
+ } else {
+ if (mExpandedGrp != groupPosition) {
+ mGrpListView.collapseGroupWithAnimation(mExpandedGrp);
+ }
+ mGrpListView.expandGroupWithAnimation(groupPosition);
+ mExpandedGrp = groupPosition;
+ // removed this as it causes some funky looking effects under
+ // certain conditions
+ //mGrpListView.setSelectedGroup(groupPosition);
+ }
+ return true;
+ }
+ });
+
+ mGrpListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
+ @Override
+ public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
+ SmartcardApp app = mGrpAdapter.getChild(groupPosition, childPosition);
// view app
Intent i = new Intent(AppsListActivity.this, AppViewActivity.class);
i.setAction(ACTION_VIEW_APP);
- i.putExtra(EXTRA_APP_POS, pos);
+ i.putExtra(EXTRA_APP_POS, mGrpAdapter.getGroup(groupPosition).appToPosMap.get(app));
startActivity(i);
+ return true;
}
});
+ mHandler = new Handler();
+ // persistent data in shared prefs
+ SharedPreferences ss = getSharedPreferences("prefs", Context.MODE_PRIVATE);
+ mEditor = ss.edit();
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window w = getWindow();
w.setFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS,
@@ -95,33 +143,69 @@ public class AppsListActivity extends ActionBarActivity {
}
}
+ @Override
+ public void onPause() {
+ writePrefs();
+ super.onPause();
+ }
+
@Override
public void onResume() {
super.onResume();
// restore persistent data
SharedPreferences ss = getSharedPreferences("prefs", Context.MODE_PRIVATE);
- mSelectedAppPos = ss.getInt("selected_app_pos", mSelectedAppPos);
+
+ Gson gson = new Gson();
+ Type collectionType;
String json = ss.getString("apps", null);
if (json != null) {
- // deserialize list of SmartcardApp
- Gson gson = new Gson();
- Type collectionType = new TypeToken>() {
+ collectionType = new TypeToken>() {
}.getType();
mApps = gson.fromJson(json, collectionType);
}
- AppAdapter appAdapter = new AppAdapter(this, mApps, false);
- mAppListView.setAdapter(appAdapter);
- appAdapter.notifyDataSetChanged();
+ json = ss.getString("groups", null);
+ if (json == null) {
+ mGroups = new LinkedHashSet<>();
+ } else {
+ collectionType = new TypeToken>() {
+ }.getType();
+ mGroups = gson.fromJson(json, collectionType);
+ }
+ mGroups.addAll(Arrays.asList(DEFAULT_GROUPS));
+
+ List groupItems = new ArrayList<>();
+ for (String group : mGroups) {
+ GroupItem groupItem = new GroupItem();
+ groupItem.groupName = group;
+ groupItem.appToPosMap = Util.mapGroupMembers(group, mApps);
+ groupItem.memberApps = new ArrayList<>(groupItem.appToPosMap.keySet());
+ // alphabetize member app list for each group
+ Collections.sort(groupItem.memberApps, SmartcardApp.nameComparator);
+ groupItems.add(groupItem);
+ }
+ // alphabetize group list
+ Collections.sort(groupItems, GroupItem.nameComparator);
+
+ mGrpAdapter = new GroupAdapter(this);
+ mGrpAdapter.setData(groupItems);
+ mGrpListView.setAdapter(mGrpAdapter);
+
+ mExpandedGrp = ss.getInt("expanded_grp_pos", -1);
+ if (mExpandedGrp != -1) {
+ mGrpListView.expandGroup(mExpandedGrp);
+ mGrpListView.setSelectedGroup(mExpandedGrp);
+ }
}
@Override
public void onBackPressed() {
+ // collapse; will write to prefs on pause
+ mExpandedGrp = -1;
super.onBackPressed();
- overridePendingTransition(R.anim.abc_fade_in,
- R.anim.abc_fade_out);
+ overridePendingTransition(R.anim.abc_fade_in, R.anim.abc_fade_out);
}
@Override
@@ -141,4 +225,144 @@ public class AppsListActivity extends ActionBarActivity {
}
return super.onOptionsItemSelected(item);
}
+
+ private void writePrefs() {
+ mEditor.putInt("expanded_grp_pos", mExpandedGrp);
+ mEditor.commit();
+ }
+
+ private static class GroupItem {
+ String groupName;
+ HashMap appToPosMap;
+ List memberApps;
+
+ // for static reference
+ static Comparator nameComparator =
+ new Comparator() {
+ @Override
+ public int compare(GroupItem gi1, GroupItem gi2) {
+ // alphabetize in ascending order, case insensitive
+ return gi1.groupName.toLowerCase().compareTo(gi2.groupName.toLowerCase());
+ }
+ };
+ }
+
+ private static class GroupHolder {
+ TextView groupName;
+ TextView memberCount;
+ }
+
+ private static class ChildHolder {
+ ImageView appIcon;
+ TextView appName;
+ TextView appAid;
+ }
+
+ /**
+ * Adapter for our list of {@link GroupItem}s.
+ */
+ private static class GroupAdapter extends AnimatedExpandableListAdapter {
+ private Context context;
+ private LayoutInflater inflater;
+ private List groupItems;
+
+ public GroupAdapter(Context context) {
+ inflater = LayoutInflater.from(context);
+ this.context = context;
+ }
+
+ public void setData(List items) {
+ groupItems = items;
+ }
+
+ @Override
+ public SmartcardApp getChild(int groupPosition, int childPosition) {
+ return groupItems.get(groupPosition).memberApps.get(childPosition);
+ }
+
+ @Override
+ public long getChildId(int groupPosition, int childPosition) {
+ return childPosition;
+ }
+
+ @Override
+ public View getRealChildView(int groupPosition, int childPosition,
+ boolean isLastChild, View convertView, ViewGroup parent) {
+ ChildHolder holder;
+ SmartcardApp app = getChild(groupPosition, childPosition);
+
+ if (convertView == null) {
+ holder = new ChildHolder();
+ convertView = inflater.inflate(R.layout.apps_list_app_item, parent, false);
+ holder.appIcon = (ImageView) convertView.findViewById(R.id.app_icon);
+ holder.appName = (TextView) convertView.findViewById(R.id.app_name);
+ holder.appAid = (TextView) convertView.findViewById(R.id.app_aid);
+ convertView.setTag(holder);
+ } else {
+ holder = (ChildHolder) convertView.getTag();
+ }
+
+ Drawable img;
+ if (app.getType() == SmartcardApp.TYPE_PAYMENT) {
+ img = context.getResources().getDrawable(R.drawable.credit_card_green);
+ } else {
+ img = context.getResources().getDrawable(R.drawable.credit_card_blue);
+ }
+ holder.appIcon.setImageDrawable(img);
+ holder.appName.setText(app.getName());
+ holder.appAid.setText(app.getAid());
+ return convertView;
+ }
+
+ @Override
+ public int getRealChildrenCount(int groupPosition) {
+ return groupItems.get(groupPosition).memberApps.size();
+ }
+
+ @Override
+ public GroupItem getGroup(int groupPosition) {
+ return groupItems.get(groupPosition);
+ }
+
+ @Override
+ public int getGroupCount() {
+ return groupItems.size();
+ }
+
+ @Override
+ public long getGroupId(int groupPosition) {
+ return groupPosition;
+ }
+
+ @Override
+ public View getGroupView(int groupPosition, boolean isExpanded,
+ View convertView, ViewGroup parent) {
+ GroupHolder holder;
+ GroupItem groupItem = getGroup(groupPosition);
+
+ if (convertView == null) {
+ holder = new GroupHolder();
+ convertView = inflater.inflate(R.layout.apps_list_group_item, parent, false);
+ holder.groupName = (TextView) convertView.findViewById(R.id.group_name);
+ holder.memberCount = (TextView) convertView.findViewById(R.id.member_count);
+ convertView.setTag(holder);
+ } else {
+ holder = (GroupHolder) convertView.getTag();
+ }
+
+ holder.groupName.setText(groupItem.groupName);
+ holder.memberCount.setText("(" + groupItem.memberApps.size() + ")");
+ return convertView;
+ }
+
+ @Override
+ public boolean hasStableIds() {
+ return true;
+ }
+
+ @Override
+ public boolean isChildSelectable(int arg0, int arg1) {
+ return true;
+ }
+ }
}
diff --git a/app/src/main/java/org/docrj/smartcard/reader/BatchSelectActivity.java b/app/src/main/java/org/docrj/smartcard/reader/BatchSelectActivity.java
index 03d2848..6b32c83 100644
--- a/app/src/main/java/org/docrj/smartcard/reader/BatchSelectActivity.java
+++ b/app/src/main/java/org/docrj/smartcard/reader/BatchSelectActivity.java
@@ -29,7 +29,6 @@ import android.nfc.NfcAdapter.ReaderCallback;
import android.nfc.Tag;
import android.nfc.tech.IsoDep;
import android.os.Bundle;
-import android.os.Handler;
import android.os.Vibrator;
import android.preference.PreferenceManager;
import android.support.v4.view.MenuItemCompat;
@@ -42,11 +41,9 @@ import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
-import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Spinner;
-import android.widget.TextView;
import android.widget.ViewSwitcher;
import com.afollestad.materialdialogs.AlertDialogWrapper;
@@ -56,6 +53,7 @@ import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
@@ -99,7 +97,7 @@ public class BatchSelectActivity extends ActionBarActivity implements ReaderXcvr
private boolean mSelectInInit;
private ArrayList mGrpMembers;
- private GroupAdapter mGrpAdapter;
+ private BatchSelectGroupAdapter mGrpAdapter;
private Spinner mGrpSpinner;
@Override
@@ -126,7 +124,7 @@ public class BatchSelectActivity extends ActionBarActivity implements ReaderXcvr
// do not clear messages for initial selection
mSelectInInit = true;
- mGrpAdapter = new GroupAdapter(getLayoutInflater());
+ mGrpAdapter = new BatchSelectGroupAdapter(getLayoutInflater());
mGrpSpinner = (Spinner) findViewById(R.id.group);
mGrpSpinner
.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() {
@@ -139,7 +137,7 @@ public class BatchSelectActivity extends ActionBarActivity implements ReaderXcvr
mSelectInInit = false;
mSelectedGrpPos = pos;
String groupName = mGrpAdapter.getGroupName(pos);
- mGrpMembers = findGroupMembers(groupName);
+ mGrpMembers = Util.findGroupMembers(groupName, mApps);
Log.d(TAG, "group: " + groupName + ", size: " + mGrpMembers.size());
}
@@ -194,6 +192,7 @@ public class BatchSelectActivity extends ActionBarActivity implements ReaderXcvr
}.getType();
mApps = gson.fromJson(json, collectionType);
}
+
json = ss.getString("groups", null);
if (json == null) {
mGroups = new LinkedHashSet<>();
@@ -204,6 +203,10 @@ public class BatchSelectActivity extends ActionBarActivity implements ReaderXcvr
}
mGroups.addAll(Arrays.asList(DEFAULT_GROUPS));
+ // alphabetize, case insensitive
+ List groupList = new ArrayList<>(mGroups);
+ Collections.sort(groupList, String.CASE_INSENSITIVE_ORDER);
+
mSelectedGrpPos = ss.getInt("selected_grp_pos", mSelectedGrpPos);
// do not clear messages for this selection on resume;
@@ -211,8 +214,8 @@ public class BatchSelectActivity extends ActionBarActivity implements ReaderXcvr
mSelectInInit = true;
mGrpAdapter.clear();
- for (String group : mGroups) {
- mGrpAdapter.addGroup(group, findGroupMembers(group));
+ for (String group : groupList) {
+ mGrpAdapter.addGroup(group, Util.findGroupMembers(group, mApps));
}
mGrpSpinner.setAdapter(mGrpAdapter);
mGrpSpinner.setSelection(mSelectedGrpPos);
@@ -407,18 +410,4 @@ public class BatchSelectActivity extends ActionBarActivity implements ReaderXcvr
mEditor.putInt("test_mode", TEST_MODE_BATCH_SELECT);
mEditor.commit();
}
-
- private ArrayList findGroupMembers(String groupName) {
- ArrayList apps = new ArrayList<>();
- for (SmartcardApp app : mApps) {
- HashSet groups = app.getGroups();
- for (String group : groups) {
- if (group.equals(groupName)) {
- apps.add(app);
- break;
- }
- }
- }
- return apps;
- }
}
diff --git a/app/src/main/java/org/docrj/smartcard/reader/GroupAdapter.java b/app/src/main/java/org/docrj/smartcard/reader/BatchSelectGroupAdapter.java
similarity index 95%
rename from app/src/main/java/org/docrj/smartcard/reader/GroupAdapter.java
rename to app/src/main/java/org/docrj/smartcard/reader/BatchSelectGroupAdapter.java
index 265b430..ac46117 100644
--- a/app/src/main/java/org/docrj/smartcard/reader/GroupAdapter.java
+++ b/app/src/main/java/org/docrj/smartcard/reader/BatchSelectGroupAdapter.java
@@ -1,176 +1,176 @@
-/*
- * Copyright 2015 Ryan Jones
- *
- * This file is part of smartcard-reader, package org.docrj.smartcard.reader.
- *
- * smartcard-reader 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.
- *
- * smartcard-reader 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 smartcard-reader. If not, see .
- */
-
-package org.docrj.smartcard.reader;
-
-import android.content.Context;
-import android.graphics.drawable.Drawable;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.BaseAdapter;
-import android.widget.TextView;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-public class GroupAdapter extends BaseAdapter {
-
- public static final int GROUP_TYPE_PAYMENT = 0;
- public static final int GROUP_TYPE_OTHER = 1;
- public static final int GROUP_TYPE_MIXED = 2;
-
- private static final String[] DEFAULT_GROUPS = SmartcardApp.GROUPS;
-
- private class Group {
- private String name;
- private int type;
- private int numMembers;
-
- Group(String name, int type, int numMembers) {
- this.name = name;
- this.type = type;
- this.numMembers = numMembers;
- }
-
- public String getName() {
- return name;
- }
-
- public int getType() {
- return type;
- }
-
- public int getNumMembers() {
- return numMembers;
- }
- };
-
- private LayoutInflater mLayoutInflater;
- private Context mContext;
- List mGroups = new ArrayList<>(5);
-
- public GroupAdapter(LayoutInflater layoutInflater) {
- mLayoutInflater = layoutInflater;
- mContext = layoutInflater.getContext();
- }
-
- public void clear() {
- mGroups.clear();
- }
-
- public void addGroup(String name, Collection members) {
- int type;
- if (name.equals(DEFAULT_GROUPS[SmartcardApp.TYPE_PAYMENT])) {
- type = GROUP_TYPE_PAYMENT;
- } else if (name.equals(DEFAULT_GROUPS[SmartcardApp.TYPE_OTHER])) {
- type = GROUP_TYPE_OTHER;
- } else {
- // determine type for user-added group
- int payment = 0;
- int other = 0;
- for (SmartcardApp app : members) {
- if (app.getType() == SmartcardApp.TYPE_PAYMENT) {
- payment++;
- } else {
- other++;
- }
- }
- if (payment > 0 && other > 0) {
- type = GROUP_TYPE_MIXED;
- } else if (payment > 0) {
- type = GROUP_TYPE_PAYMENT;
- } else {
- type = GROUP_TYPE_OTHER;
- }
- }
- addGroup(name, type, members.size());
- }
-
- public void addGroup(String name, int type, int numMembers) {
- Group group = new Group(name, type, numMembers);
- mGroups.add(group);
- notifyDataSetChanged();
- }
-
- public String getGroupName(int position) {
- Group group = mGroups.get(position);
- return group == null ? null : group.getName();
- }
-
- @Override
- public int getCount() {
- return mGroups == null ? 0 : mGroups.size();
- }
-
- @Override
- public Object getItem(int position) {
- return mGroups.get(position);
- }
-
- @Override
- public long getItemId(int position) {
- return 0;
- }
-
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- View item = convertView;
- if (item == null) {
- item = mLayoutInflater.inflate(R.layout.spinner_apps_list, parent, false);
- }
- Group group = mGroups.get(position);
- TextView textView = (TextView) item.findViewById(android.R.id.text1);
- textView.setText(group.getName() + " (" + group.getNumMembers() + ")");
- Drawable img;
- if (group.getType() == GROUP_TYPE_PAYMENT) {
- img = mContext.getResources().getDrawable(R.drawable.credit_card2_green);
- } else
- if (group.getType()== GROUP_TYPE_OTHER) {
- img = mContext.getResources().getDrawable(R.drawable.credit_card2_blue);
- } else {
- img = mContext.getResources().getDrawable(R.drawable.credit_card2_pink);
- }
- textView.setCompoundDrawablesWithIntrinsicBounds(img, null, null, null);
- return item;
- }
-
- @Override
- public View getDropDownView(int position, View convertView, ViewGroup parent) {
- View row = convertView;
- if (row == null) {
- row = mLayoutInflater.inflate(R.layout.spinner_dropdown_apps_list, parent, false);
- }
- Group group = mGroups.get(position);
- TextView textView = (TextView) row.findViewById(android.R.id.text1);
- textView.setText(group.getName() + " (" + group.getNumMembers() + ")");
- Drawable img;
- if (group.getType() == GROUP_TYPE_PAYMENT) {
- img = mContext.getResources().getDrawable(R.drawable.credit_card_green);
- } else
- if (group.getType()== GROUP_TYPE_OTHER) {
- img = mContext.getResources().getDrawable(R.drawable.credit_card_blue);
- } else {
- img = mContext.getResources().getDrawable(R.drawable.credit_card_pink);
- }
- textView.setCompoundDrawablesWithIntrinsicBounds(img, null, null, null);
- return row;
- }
-}
+/*
+ * Copyright 2015 Ryan Jones
+ *
+ * This file is part of smartcard-reader, package org.docrj.smartcard.reader.
+ *
+ * smartcard-reader 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.
+ *
+ * smartcard-reader 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 smartcard-reader. If not, see .
+ */
+
+package org.docrj.smartcard.reader;
+
+import android.content.Context;
+import android.graphics.drawable.Drawable;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseAdapter;
+import android.widget.TextView;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+public class BatchSelectGroupAdapter extends BaseAdapter {
+
+ public static final int GROUP_TYPE_PAYMENT = 0;
+ public static final int GROUP_TYPE_OTHER = 1;
+ public static final int GROUP_TYPE_MIXED = 2;
+
+ private static final String[] DEFAULT_GROUPS = SmartcardApp.GROUPS;
+
+ private class Group {
+ private String name;
+ private int type;
+ private int numMembers;
+
+ Group(String name, int type, int numMembers) {
+ this.name = name;
+ this.type = type;
+ this.numMembers = numMembers;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public int getType() {
+ return type;
+ }
+
+ public int getNumMembers() {
+ return numMembers;
+ }
+ };
+
+ private LayoutInflater mLayoutInflater;
+ private Context mContext;
+ List mGroups = new ArrayList<>(5);
+
+ public BatchSelectGroupAdapter(LayoutInflater layoutInflater) {
+ mLayoutInflater = layoutInflater;
+ mContext = layoutInflater.getContext();
+ }
+
+ public void clear() {
+ mGroups.clear();
+ }
+
+ public void addGroup(String name, Collection members) {
+ int type;
+ if (name.equals(DEFAULT_GROUPS[SmartcardApp.TYPE_PAYMENT])) {
+ type = GROUP_TYPE_PAYMENT;
+ } else if (name.equals(DEFAULT_GROUPS[SmartcardApp.TYPE_OTHER])) {
+ type = GROUP_TYPE_OTHER;
+ } else {
+ // determine type for user-added group
+ int payment = 0;
+ int other = 0;
+ for (SmartcardApp app : members) {
+ if (app.getType() == SmartcardApp.TYPE_PAYMENT) {
+ payment++;
+ } else {
+ other++;
+ }
+ }
+ if (payment > 0 && other > 0) {
+ type = GROUP_TYPE_MIXED;
+ } else if (payment > 0) {
+ type = GROUP_TYPE_PAYMENT;
+ } else {
+ type = GROUP_TYPE_OTHER;
+ }
+ }
+ addGroup(name, type, members.size());
+ }
+
+ public void addGroup(String name, int type, int numMembers) {
+ Group group = new Group(name, type, numMembers);
+ mGroups.add(group);
+ notifyDataSetChanged();
+ }
+
+ public String getGroupName(int position) {
+ Group group = mGroups.get(position);
+ return group == null ? null : group.getName();
+ }
+
+ @Override
+ public int getCount() {
+ return mGroups == null ? 0 : mGroups.size();
+ }
+
+ @Override
+ public Object getItem(int position) {
+ return mGroups.get(position);
+ }
+
+ @Override
+ public long getItemId(int position) {
+ return 0;
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ View item = convertView;
+ if (item == null) {
+ item = mLayoutInflater.inflate(R.layout.spinner_apps_list, parent, false);
+ }
+ Group group = mGroups.get(position);
+ TextView textView = (TextView) item.findViewById(android.R.id.text1);
+ textView.setText(group.getName() + " (" + group.getNumMembers() + ")");
+ Drawable img;
+ if (group.getType() == GROUP_TYPE_PAYMENT) {
+ img = mContext.getResources().getDrawable(R.drawable.credit_card2_green);
+ } else
+ if (group.getType()== GROUP_TYPE_OTHER) {
+ img = mContext.getResources().getDrawable(R.drawable.credit_card2_blue);
+ } else {
+ img = mContext.getResources().getDrawable(R.drawable.credit_card2_pink);
+ }
+ textView.setCompoundDrawablesWithIntrinsicBounds(img, null, null, null);
+ return item;
+ }
+
+ @Override
+ public View getDropDownView(int position, View convertView, ViewGroup parent) {
+ View row = convertView;
+ if (row == null) {
+ row = mLayoutInflater.inflate(R.layout.spinner_dropdown_apps_list, parent, false);
+ }
+ Group group = mGroups.get(position);
+ TextView textView = (TextView) row.findViewById(android.R.id.text1);
+ textView.setText(group.getName() + " (" + group.getNumMembers() + ")");
+ Drawable img;
+ if (group.getType() == GROUP_TYPE_PAYMENT) {
+ img = mContext.getResources().getDrawable(R.drawable.credit_card_green);
+ } else
+ if (group.getType()== GROUP_TYPE_OTHER) {
+ img = mContext.getResources().getDrawable(R.drawable.credit_card_blue);
+ } else {
+ img = mContext.getResources().getDrawable(R.drawable.credit_card_pink);
+ }
+ textView.setCompoundDrawablesWithIntrinsicBounds(img, null, null, null);
+ return row;
+ }
+}
diff --git a/app/src/main/java/org/docrj/smartcard/reader/MsgParseActivity.java b/app/src/main/java/org/docrj/smartcard/reader/MsgParseActivity.java
index 8ea7649..d2a6a37 100644
--- a/app/src/main/java/org/docrj/smartcard/reader/MsgParseActivity.java
+++ b/app/src/main/java/org/docrj/smartcard/reader/MsgParseActivity.java
@@ -1,3 +1,22 @@
+/*
+ * Copyright 2015 Ryan Jones
+ *
+ * This file is part of smartcard-reader, package org.docrj.smartcard.reader.
+ *
+ * smartcard-reader 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.
+ *
+ * smartcard-reader 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 smartcard-reader. If not, see .
+ */
+
package org.docrj.smartcard.reader;
import android.os.Build;
@@ -40,7 +59,7 @@ public class MsgParseActivity extends ActionBarActivity {
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
- // toolbar reference does not work for setting title
+ // toolbar reference does not work for setting groupName
getSupportActionBar().setTitle(mActivityName);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
diff --git a/app/src/main/java/org/docrj/smartcard/reader/NavDrawer.java b/app/src/main/java/org/docrj/smartcard/reader/NavDrawer.java
index 87de66f..5e61f64 100644
--- a/app/src/main/java/org/docrj/smartcard/reader/NavDrawer.java
+++ b/app/src/main/java/org/docrj/smartcard/reader/NavDrawer.java
@@ -75,14 +75,12 @@ public class NavDrawer {
View batchSelect = drawerLayout.findViewById(R.id.batch_select);
View emvRead = drawerLayout.findViewById(R.id.emv_read);
View apps = drawerLayout.findViewById(R.id.apps);
- //View appGroups = drawerLayout.findViewById(R.id.app_groups);
View settings = drawerLayout.findViewById(R.id.settings);
appSelect.setOnClickListener(mClickListener);
batchSelect.setOnClickListener(mClickListener);
emvRead.setOnClickListener(mClickListener);
apps.setOnClickListener(mClickListener);
- //appGroups.setOnClickListener(mClickListener);
settings.setOnClickListener(mClickListener);
if (inState != null) {
@@ -141,7 +139,6 @@ public class NavDrawer {
final Intent intent = new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
- //intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
boolean finishCurrent = false;
final int viewId = view.getId();
switch(viewId) {
@@ -165,13 +162,6 @@ public class NavDrawer {
finishCurrent = false;
break;
- /*
- case R.id.app_groups:
- intent.setClass(mActivity, AppsListActivity.class);
- finishCurrent = false;
- break;
- */
-
case R.id.settings:
intent.setClass(mActivity, SettingsActivity.class);
finishCurrent = false;
diff --git a/app/src/main/java/org/docrj/smartcard/reader/SmartcardApp.java b/app/src/main/java/org/docrj/smartcard/reader/SmartcardApp.java
index cfaebf3..73a54e9 100644
--- a/app/src/main/java/org/docrj/smartcard/reader/SmartcardApp.java
+++ b/app/src/main/java/org/docrj/smartcard/reader/SmartcardApp.java
@@ -22,6 +22,7 @@ package org.docrj.smartcard.reader;
import org.docrj.smartcard.util.Util;
import java.util.ArrayList;
+import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedHashSet;
@@ -42,6 +43,15 @@ public class SmartcardApp {
private HashSet mGroups = new LinkedHashSet<>();
+ public static Comparator nameComparator =
+ new Comparator() {
+ @Override
+ public int compare(SmartcardApp app1, SmartcardApp app2) {
+ // alphabetize in ascending order, case insensitive
+ return app1.mName.toLowerCase().compareTo(app2.mName.toLowerCase());
+ }
+ };
+
public SmartcardApp() {
}
diff --git a/app/src/main/java/org/docrj/smartcard/reader/Util.java b/app/src/main/java/org/docrj/smartcard/reader/Util.java
new file mode 100644
index 0000000..1f12557
--- /dev/null
+++ b/app/src/main/java/org/docrj/smartcard/reader/Util.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2015 Ryan Jones
+ *
+ * This file is part of smartcard-reader, package org.docrj.smartcard.reader.
+ *
+ * smartcard-reader 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.
+ *
+ * smartcard-reader 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 smartcard-reader. If not, see .
+ */
+
+package org.docrj.smartcard.reader;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+
+public class Util {
+ public static ArrayList findGroupMembers(String groupName, List apps) {
+ ArrayList memberApps = new ArrayList<>();
+ for (SmartcardApp app : apps) {
+ HashSet groups = app.getGroups();
+ for (String group : groups) {
+ if (group.equals(groupName)) {
+ memberApps.add(app);
+ break;
+ }
+ }
+ }
+ return memberApps;
+ }
+
+ public static int findNumGroupMembers(String groupName, List apps) {
+ int numMembers = 0;
+ for (SmartcardApp app : apps) {
+ HashSet groups = app.getGroups();
+ for (String group : groups) {
+ if (group.equals(groupName)) {
+ numMembers++;
+ break;
+ }
+ }
+ }
+ return numMembers;
+ }
+
+ public static boolean isGroupEmpty(String groupName, List apps) {
+ for (SmartcardApp app : apps) {
+ HashSet groups = app.getGroups();
+ for (String group : groups) {
+ if (group.equals(groupName)) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ // returns a mapping of group member apps to their position in the mApps list
+ public static HashMap mapGroupMembers(String groupName, List apps) {
+ HashMap memberApps = new LinkedHashMap<>();
+ int i = 0;
+ for (SmartcardApp app : apps) {
+ HashSet groups = app.getGroups();
+ for (String group : groups) {
+ if (group.equals(groupName)) {
+ memberApps.put(app, i);
+ break;
+ }
+ }
+ i++;
+ }
+ return memberApps;
+ }
+}
diff --git a/app/src/main/res/drawable-hdpi/credit_card2_dark.png b/app/src/main/res/drawable-hdpi/credit_card2_dark.png
deleted file mode 100644
index 7b8a9fc..0000000
Binary files a/app/src/main/res/drawable-hdpi/credit_card2_dark.png and /dev/null differ
diff --git a/app/src/main/res/drawable-hdpi/credit_card_dark.png b/app/src/main/res/drawable-hdpi/credit_card_dark.png
deleted file mode 100644
index 50a2000..0000000
Binary files a/app/src/main/res/drawable-hdpi/credit_card_dark.png and /dev/null differ
diff --git a/app/src/main/res/drawable-hdpi/ic_action_done_all.png b/app/src/main/res/drawable-hdpi/ic_action_done_all.png
new file mode 100644
index 0000000..ad61896
Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_action_done_all.png differ
diff --git a/app/src/main/res/drawable-hdpi/ic_action_receipt.png b/app/src/main/res/drawable-hdpi/ic_action_receipt.png
new file mode 100644
index 0000000..f7f48cf
Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_action_receipt.png differ
diff --git a/app/src/main/res/drawable-hdpi/ic_folder.png b/app/src/main/res/drawable-hdpi/ic_folder.png
new file mode 100644
index 0000000..b96ae8a
Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_folder.png differ
diff --git a/app/src/main/res/drawable-mdpi/ic_action_done_all.png b/app/src/main/res/drawable-mdpi/ic_action_done_all.png
new file mode 100644
index 0000000..6d0f4a9
Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_action_done_all.png differ
diff --git a/app/src/main/res/drawable-mdpi/ic_action_receipt.png b/app/src/main/res/drawable-mdpi/ic_action_receipt.png
new file mode 100644
index 0000000..44c4c56
Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_action_receipt.png differ
diff --git a/app/src/main/res/drawable-mdpi/ic_folder.png b/app/src/main/res/drawable-mdpi/ic_folder.png
new file mode 100644
index 0000000..b5e1e0d
Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_folder.png differ
diff --git a/app/src/main/res/drawable-xhdpi/ic_action_done_all.png b/app/src/main/res/drawable-xhdpi/ic_action_done_all.png
new file mode 100644
index 0000000..d0fa830
Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_action_done_all.png differ
diff --git a/app/src/main/res/drawable-xhdpi/ic_action_receipt.png b/app/src/main/res/drawable-xhdpi/ic_action_receipt.png
new file mode 100644
index 0000000..c78b4b7
Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_action_receipt.png differ
diff --git a/app/src/main/res/drawable-xhdpi/ic_folder.png b/app/src/main/res/drawable-xhdpi/ic_folder.png
new file mode 100644
index 0000000..a145271
Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_folder.png differ
diff --git a/app/src/main/res/drawable-xxhdpi/ic_folder.png b/app/src/main/res/drawable-xxhdpi/ic_folder.png
new file mode 100644
index 0000000..f1f1dd3
Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_folder.png differ
diff --git a/app/src/main/res/layout/group_list_item.xml b/app/src/main/res/layout/app_edit_group_list_item.xml
similarity index 97%
rename from app/src/main/res/layout/group_list_item.xml
rename to app/src/main/res/layout/app_edit_group_list_item.xml
index 182d419..73384fc 100644
--- a/app/src/main/res/layout/group_list_item.xml
+++ b/app/src/main/res/layout/app_edit_group_list_item.xml
@@ -1,18 +1,18 @@
-
-
-
+
+
+
diff --git a/app/src/main/res/layout/apps_list_app_item.xml b/app/src/main/res/layout/apps_list_app_item.xml
new file mode 100644
index 0000000..72da806
--- /dev/null
+++ b/app/src/main/res/layout/apps_list_app_item.xml
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/apps_list_group_item.xml b/app/src/main/res/layout/apps_list_group_item.xml
new file mode 100644
index 0000000..eb1caa8
--- /dev/null
+++ b/app/src/main/res/layout/apps_list_group_item.xml
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/incl_activity_apps_list.xml b/app/src/main/res/layout/incl_activity_apps_list.xml
index a12beea..986cd3f 100644
--- a/app/src/main/res/layout/incl_activity_apps_list.xml
+++ b/app/src/main/res/layout/incl_activity_apps_list.xml
@@ -19,11 +19,13 @@
android:text="@string/choose_app"
android:textSize="@dimen/font_medium"
android:paddingTop="10dp"
- android:paddingLeft="10dp" />
+ android:paddingBottom="10dp"
+ android:paddingLeft="8dp" />
-
diff --git a/app/src/main/res/layout/spinner_apps_list.xml b/app/src/main/res/layout/spinner_apps_list.xml
index c31c3bb..1963d3a 100644
--- a/app/src/main/res/layout/spinner_apps_list.xml
+++ b/app/src/main/res/layout/spinner_apps_list.xml
@@ -7,6 +7,6 @@
android:layout_height="fill_parent"
android:gravity="center_vertical|left"
- android:drawableLeft="@drawable/credit_card2_dark"
+ android:drawableLeft="@drawable/credit_card2_green"
android:drawablePadding="3dp" />
diff --git a/app/src/main/res/layout/spinner_dropdown_apps_list.xml b/app/src/main/res/layout/spinner_dropdown_apps_list.xml
index eac6e50..c52c235 100644
--- a/app/src/main/res/layout/spinner_dropdown_apps_list.xml
+++ b/app/src/main/res/layout/spinner_dropdown_apps_list.xml
@@ -7,5 +7,5 @@
android:layout_height="fill_parent"
android:gravity="center_vertical|left"
- android:drawableLeft="@drawable/credit_card2_dark"
+ android:drawableLeft="@drawable/credit_card_green"
android:drawablePadding="4dp" />
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 4bdadb1..ee5735b 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -70,7 +70,7 @@
App name %s exists!
AID %s exists!
P
- Choose a smartcard app for detailed view…
+ Choose a smartcard app for detailed view and edit…
Enable NFC?
This app is useless when NFC is disabled. Reader mode depends on it. Hit OK to go to Settings, where you can enable NFC.
command
@@ -92,6 +92,7 @@
unknown
LaunchActivity
Settings
+ smartcard app groups
smartcard apps
smartcard app
AppEditActivity
diff --git a/docs/tn_screen_apps_list.png b/docs/tn_screen_apps_list.png
index bf1fd4c..b8c4463 100644
Binary files a/docs/tn_screen_apps_list.png and b/docs/tn_screen_apps_list.png differ