Commits

Bastien Léonard  committed 1eca2c3

Refactored to avoid the huge inner anonymous class

  • Participants
  • Parent commits 29bcb57

Comments (0)

Files changed (1)

File src/net/alwaysdata/bastien_leonard/media_hider/BrowserActivity.java

 
 public class BrowserActivity
     extends ListActivity
-    implements OnItemClickListener
+    implements OnItemClickListener, AdapterView.OnItemLongClickListener
 {
     private static final String TAG = "BrowserActivity";
 
             ListView listView = getListView();
             listView.setTextFilterEnabled(true);
             listView.setOnItemClickListener(this);
-            listView.setOnItemLongClickListener(
-                new android.widget.AdapterView.OnItemLongClickListener()
-                {
-                    public boolean onItemLongClick(AdapterView<?> parent,
-                                                   View view, int position,
-                                                   long id)
-                    {
-                        String message = null;
-                        File dir = items.getFile(position);
-                        File[] files = dir.listFiles();
-
-                        if (files != null && files.length > 0)
-                        {
-                            StringBuilder builder = new StringBuilder();
-                            int i;
-
-                            for (i = 0; i < files.length - 1; ++i)
-                            {
-                                builder.append(files[i].getName());
-
-                                if (files[i].isDirectory())
-                                {
-                                    builder.append('/');
-                                }
-
-                                builder.append('\n');
-                            }
-
-                            builder.append(files[i].getName());
-
-                            if (files[i].isDirectory())
-                            {
-                                builder.append('/');
-                            }
-
-                            message = builder.toString();
-                        }
-
-                        if (message != null)
-                        {
-                            Toast.makeText(getApplicationContext(),
-                                           message,
-                                           Toast.LENGTH_LONG).show();
-                        }
-
-                        return false;
-                    }
-                });
-
+            listView.setOnItemLongClickListener(this);
             Toast.makeText(
                 getApplicationContext(),
                 getString(R.string.starting_tip),
         items.fillList();
     }
 
+    @Override
+    public boolean onItemLongClick(AdapterView<?> parent, View view,
+                                   int position, long id)
+    {
+        String message = null;
+        File dir = items.getFile(position);
+        File[] files = dir.listFiles();
+
+        if (files != null && files.length > 0)
+        {
+            StringBuilder builder = new StringBuilder();
+            int i;
+
+            for (i = 0; i < files.length - 1; ++i)
+            {
+                builder.append(files[i].getName());
+
+                if (files[i].isDirectory())
+                {
+                    builder.append('/');
+                }
+
+                builder.append('\n');
+            }
+
+            builder.append(files[i].getName());
+
+            if (files[i].isDirectory())
+            {
+                builder.append('/');
+            }
+
+            message = builder.toString();
+        }
+
+        if (message != null)
+        {
+            Toast.makeText(getApplicationContext(),
+                           message,
+                           Toast.LENGTH_LONG).show();
+        }
+
+        return false;
+    }
+
     private void errorMessage(String message)
     {
         Toast.makeText(getApplicationContext(), message,