aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDanesh M <daneshm90@gmail.com>2015-09-11 16:37:37 -0700
committerGerrit Code Review <gerrit@cyanogenmod.org>2015-09-11 18:06:20 -0700
commit29cfd7e8352459f840444bc7c1d02ed4c6da0a26 (patch)
tree358a4c5c304b52587dce55164bc4aa1e0c6bd456
parent72920bf160977a565603a9547ed0a03b8d18ff59 (diff)
downloadandroid_packages_apps_CMFileManager-29cfd7e8352459f840444bc7c1d02ed4c6da0a26.tar.gz
android_packages_apps_CMFileManager-29cfd7e8352459f840444bc7c1d02ed4c6da0a26.tar.bz2
android_packages_apps_CMFileManager-29cfd7e8352459f840444bc7c1d02ed4c6da0a26.zip
CMFileManager : Switch to checked states
Selected states are not being tracked properly when rotated. Repro: 1. Click to open file 2. Tap on first item in resolver dialog 3. Rotate device 4. Press ok 5. Enjoy crash issue-id: CYNGNOS-991 Change-Id: I9ef5d0571201957eac40edc8bc5e47700752dcc3
-rw-r--r--res/layout/associations_item.xml5
-rw-r--r--src/com/cyanogenmod/filemanager/ui/dialogs/AssociationsDialog.java33
-rw-r--r--src/com/cyanogenmod/filemanager/ui/widgets/CheckableRelativeLayout.java60
3 files changed, 69 insertions, 29 deletions
diff --git a/res/layout/associations_item.xml b/res/layout/associations_item.xml
index 05d8d565..657e7314 100644
--- a/res/layout/associations_item.xml
+++ b/res/layout/associations_item.xml
@@ -14,7 +14,8 @@
limitations under the License.
-->
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<com.cyanogenmod.filemanager.ui.widgets.CheckableRelativeLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="@dimen/grid_width"
android:layout_height="wrap_content"
android:background="@drawable/material_selection"
@@ -43,4 +44,4 @@
android:singleLine="true"
android:ellipsize="end" />
-</RelativeLayout> \ No newline at end of file
+</com.cyanogenmod.filemanager.ui.widgets.CheckableRelativeLayout>
diff --git a/src/com/cyanogenmod/filemanager/ui/dialogs/AssociationsDialog.java b/src/com/cyanogenmod/filemanager/ui/dialogs/AssociationsDialog.java
index 80d05c13..a90281dd 100644
--- a/src/com/cyanogenmod/filemanager/ui/dialogs/AssociationsDialog.java
+++ b/src/com/cyanogenmod/filemanager/ui/dialogs/AssociationsDialog.java
@@ -136,6 +136,7 @@ public class AssociationsDialog implements OnItemClickListener {
this.mRemember.setVisibility(
isPlatformSigned && this.mAllowPreferred ? View.VISIBLE : View.GONE);
this.mGrid = (GridView)v.findViewById(R.id.associations_gridview);
+ mGrid.setChoiceMode(GridView.CHOICE_MODE_SINGLE);
AssociationsAdapter adapter =
new AssociationsAdapter(this.mContext, this.mGrid, this.mIntents, this);
this.mGrid.setAdapter(adapter);
@@ -209,12 +210,11 @@ public class AssociationsDialog implements OnItemClickListener {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// If the item is selected, then just open it like ActivityChooserView
// If there is no parent, that means an internal call. In this case ignore it.
- if (parent != null && ((ViewGroup)view).isSelected()) {
+ if (parent != null && mGrid.isItemChecked(position)) {
this.mDialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
} else {
- deselectAll();
- ((ViewGroup)view).setSelected(true);
+ mGrid.setItemChecked(position, true);
// Internal editors can be associated
boolean isPlatformSigned = AndroidHelper.isAppPlatformSignature(this.mContext);
@@ -252,7 +252,7 @@ public class AssociationsDialog implements OnItemClickListener {
// Select the item
ViewGroup item = (ViewGroup)this.mGrid.getChildAt(i);
if (item != null) {
- if (!item.isSelected()) {
+ if (!mGrid.isItemChecked(i)) {
onItemClick(null, item, i, item.getId());
this.mRemember.setChecked(true);
ret = false;
@@ -292,7 +292,7 @@ public class AssociationsDialog implements OnItemClickListener {
ResolveInfo info = this.mIntents.get(i);
if (info.activityInfo.name.equals(this.mPreferred.activityInfo.name)) {
ViewGroup item = (ViewGroup)this.mGrid.getChildAt(i);
- if (item != null && item.isSelected()) {
+ if (item != null && mGrid.isItemChecked(i)) {
return true;
}
}
@@ -302,19 +302,6 @@ public class AssociationsDialog implements OnItemClickListener {
}
/**
- * Method that deselect all the items of the grid view
- */
- private void deselectAll() {
- int cc = this.mGrid.getChildCount();
- for (int i = 0; i < cc; i++) {
- ViewGroup item = (ViewGroup)this.mGrid.getChildAt(i);
- if (item != null) {
- item.setSelected(false);
- }
- }
- }
-
- /**
* Method that returns the selected item of the grid view
*
* @return ResolveInfo The selected item
@@ -322,15 +309,7 @@ public class AssociationsDialog implements OnItemClickListener {
*/
ResolveInfo getSelected() {
AssociationsAdapter adapter = (AssociationsAdapter)this.mGrid.getAdapter();
- int cc = this.mGrid.getChildCount();
- int firstVisible = this.mGrid.getFirstVisiblePosition();
- for (int i = 0; i < cc; i++) {
- ViewGroup item = (ViewGroup)this.mGrid.getChildAt(i);
- if (item != null && item.isSelected()) {
- return adapter.getItem(i + firstVisible);
- }
- }
- return null;
+ return adapter.getItem(mGrid.getCheckedItemPosition());
}
/**
diff --git a/src/com/cyanogenmod/filemanager/ui/widgets/CheckableRelativeLayout.java b/src/com/cyanogenmod/filemanager/ui/widgets/CheckableRelativeLayout.java
new file mode 100644
index 00000000..71f1c0ae
--- /dev/null
+++ b/src/com/cyanogenmod/filemanager/ui/widgets/CheckableRelativeLayout.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.cyanogenmod.filemanager.ui.widgets;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.widget.Checkable;
+import android.widget.RelativeLayout;
+
+public class CheckableRelativeLayout extends RelativeLayout implements Checkable {
+ private static final int[] CHECKED_STATE_SET = {
+ android.R.attr.state_checked
+ };
+ private boolean mChecked;
+
+ public CheckableRelativeLayout(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ @Override
+ public boolean isChecked() {
+ return mChecked;
+ }
+
+ @Override
+ public void setChecked(boolean checked) {
+ if (mChecked != checked) {
+ mChecked = checked;
+ refreshDrawableState();
+ }
+ }
+
+ @Override
+ public void toggle() {
+ setChecked(!mChecked);
+ }
+
+ @Override
+ public int[] onCreateDrawableState(int extraSpace) {
+ final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);
+ if (mChecked) {
+ mergeDrawableStates(drawableState, CHECKED_STATE_SET);
+ }
+ return drawableState;
+ }
+}