Fix UI performance issues

This commit is contained in:
Cameron Gutman 2014-11-07 01:18:14 -08:00
parent 94b1c04fa6
commit 6dbb1a0c1f
4 changed files with 14 additions and 43 deletions

View File

@ -109,11 +109,7 @@ public class PcView extends Activity {
public void onItemClick(AdapterView<?> arg0, View arg1, int pos,
long id) {
ComputerObject computer = (ComputerObject) pcGridAdapter.getItem(pos);
if (computer.details == null) {
// Placeholder item; no context menu for it
return;
}
else if (computer.details.reachability == ComputerDetails.Reachability.OFFLINE) {
if (computer.details.reachability == ComputerDetails.Reachability.OFFLINE) {
// Open the context menu if a PC is offline
openContextMenu(arg1);
}
@ -141,13 +137,8 @@ public class PcView extends Activity {
}
});
if (pcGridAdapter.isEmpty()) {
addListPlaceholder();
}
else {
pcGridAdapter.notifyDataSetChanged();
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -176,7 +167,7 @@ public class PcView extends Activity {
PcView.this.runOnUiThread(new Runnable() {
@Override
public void run() {
updateListView(details);
updateComputer(details);
}
});
}
@ -505,7 +496,7 @@ public class PcView extends Activity {
return true;
}
managerBinder.removeComputer(computer.details.name);
removeListView(computer.details);
removeComputer(computer.details);
return true;
case APP_LIST_ID:
@ -517,11 +508,7 @@ public class PcView extends Activity {
}
}
private void addListPlaceholder() {
}
private void removeListView(ComputerDetails details) {
private void removeComputer(ComputerDetails details) {
for (int i = 0; i < pcGridAdapter.getCount(); i++) {
ComputerObject computer = (ComputerObject) pcGridAdapter.getItem(i);
@ -530,26 +517,14 @@ public class PcView extends Activity {
break;
}
}
if (pcGridAdapter.getCount() == 0) {
// Add the placeholder if we're down to 0 computers
addListPlaceholder();
}
}
private void updateListView(ComputerDetails details) {
private void updateComputer(ComputerDetails details) {
ComputerObject existingEntry = null;
boolean placeholderPresent = false;
for (int i = 0; i < pcGridAdapter.getCount(); i++) {
ComputerObject computer = (ComputerObject) pcGridAdapter.getItem(i);
// If there's a placeholder, there's nothing else
if (computer.details == null) {
placeholderPresent = true;
break;
}
// Check if this is the same computer
if (details.equals(computer.details)) {
existingEntry = computer;
@ -562,18 +537,13 @@ public class PcView extends Activity {
existingEntry.details = details;
}
else {
// If the placeholder is the only object, remove it
if (placeholderPresent) {
pcGridAdapter.removeComputer((ComputerObject) pcGridAdapter.getItem(0));
}
// Add a new entry
pcGridAdapter.addComputer(new ComputerObject(details));
}
// Notify the view that the data has changed
pcGridAdapter.notifyDataSetChanged();
}
}
public class ComputerObject {
public ComputerDetails details;

View File

@ -49,7 +49,7 @@ public abstract class GenericGridAdapter<T> extends BaseAdapter {
@Override
public View getView(int i, View convertView, ViewGroup viewGroup) {
if (convertView == null) {
convertView = inflater.inflate(layoutId, null);
convertView = inflater.inflate(layoutId, viewGroup, false);
}
ImageView imgView = (ImageView) convertView.findViewById(R.id.grid_image);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

After

Width:  |  Height:  |  Size: 40 KiB

View File

@ -2,11 +2,11 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp">
android:padding="20dp">
<ImageView
android:id="@+id/grid_image"
android:layout_centerHorizontal="true"
android:layout_width="100dp"
android:layout_width="150dp"
android:layout_height="100dp">
</ImageView>
<TextView
@ -14,6 +14,7 @@
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_below="@id/grid_image"
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true"
android:gravity="center"
android:textSize="20sp" >