@Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.line_list);

    // Setup the list
    adapter = new IconAdapter<FileWrapper>(this, R.layout.line_list_item);
    ListView list = (ListView) findViewById(R.id.list);
    list.setAdapter(adapter);
    list.setOnItemClickListener(this);

    // Load Directory
    if (savedInstanceState != null) {
      backStack = savedInstanceState.getParcelableArrayList("BACKSTACK");
    }

    if (backStack == null || backStack.size() == 0) {
      backStack = new ArrayList<BackStackItem>();
      String startPath =
          (startDirectory == null || startDirectory.isEmpty())
              ? Environment.getExternalStorageDirectory().getPath()
              : startDirectory;
      backStack.add(new BackStackItem(startPath, false));
    }

    wrapFiles();
    this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
  }
Example #2
0
 public void mOnClick(View v) {
   switch (v.getId()) {
     case R.id.btn3:
       mItem.clear();
       for (int i = 1001; i <= 1003; i++) {
         mItem.add(Integer.toString(i));
       }
       mAdapter.notifyDataSetChanged();
       break;
     case R.id.btn10:
       mItem.clear();
       for (int i = 1001; i <= 1010; i++) {
         mItem.add(Integer.toString(i));
       }
       mAdapter.notifyDataSetChanged();
       break;
     case R.id.btnalways:
       mList.setOverScrollMode(View.OVER_SCROLL_ALWAYS);
       break;
     case R.id.btnnever:
       mList.setOverScrollMode(View.OVER_SCROLL_NEVER);
       break;
     case R.id.btnifscroll:
       mList.setOverScrollMode(View.OVER_SCROLL_IF_CONTENT_SCROLLS);
       break;
   }
 }
  /* Scan the files in the new directory, and store them in the filelist.
   * Update the UI by refreshing the list adapter.
   */
  private void loadDirectory(String newdirectory) {
    if (newdirectory.equals("../")) {
      try {
        directory = new File(directory).getParent();
      } catch (Exception e) {
      }
    } else {
      directory = newdirectory;
    }
    SharedPreferences.Editor editor = getPreferences(0).edit();
    editor.putString("lastBrowsedDirectory", directory);
    editor.commit();
    directoryView.setText(directory);

    filelist = new ArrayList<FileUri>();
    ArrayList<FileUri> sortedDirs = new ArrayList<FileUri>();
    ArrayList<FileUri> sortedFiles = new ArrayList<FileUri>();
    if (!newdirectory.equals(rootdir)) {
      String parentDirectory = new File(directory).getParent() + "/";
      Uri uri = Uri.parse("file://" + parentDirectory);
      sortedDirs.add(new FileUri(uri, parentDirectory));
    }
    try {
      File dir = new File(directory);
      File[] files = dir.listFiles();
      if (files != null) {
        for (File file : files) {
          if (file == null) {
            continue;
          }
          String filename = file.getName();
          if (file.isDirectory()) {
            Uri uri = Uri.parse("file://" + file.getAbsolutePath() + "/");
            FileUri fileuri = new FileUri(uri, uri.getPath());
            sortedDirs.add(fileuri);
          } else if (filename.endsWith(".mid")
              || filename.endsWith(".MID")
              || filename.endsWith(".midi")
              || filename.endsWith(".MIDI")) {

            Uri uri = Uri.parse("file://" + file.getAbsolutePath());
            FileUri fileuri = new FileUri(uri, uri.getLastPathSegment());
            sortedFiles.add(fileuri);
          }
        }
      }
    } catch (Exception e) {
    }

    if (sortedDirs.size() > 0) {
      Collections.sort(sortedDirs, sortedDirs.get(0));
    }
    if (sortedFiles.size() > 0) {
      Collections.sort(sortedFiles, sortedFiles.get(0));
    }
    filelist.addAll(sortedDirs);
    filelist.addAll(sortedFiles);
    adapter = new IconArrayAdapter<FileUri>(this, android.R.layout.simple_list_item_1, filelist);
    this.setListAdapter(adapter);
  }
  public void prioritizeViewRange(int firstVisibleItem, int lastVisibleItem, int prefetchBuffer) {
    if ((lastVisibleItem < firstVisibleItem) || (sectionKeys.size() == 0)) {
      return;
    }

    // We want to prioritize requests for items which are visible but do not have pictures
    // loaded yet. We also want to pre-fetch pictures for items which are not yet visible
    // but are within a buffer on either side of the visible items, on the assumption that
    // they will be visible soon. For these latter items, we'll store the images in memory
    // in the hopes we can immediately populate their image view when needed.

    // Prioritize the requests in reverse order since each call to prioritizeRequest will just
    // move it to the front of the queue. And we want the earliest ones in the range to be at
    // the front of the queue, so all else being equal, the list will appear to populate from
    // the top down.
    for (int i = lastVisibleItem; i >= 0; i--) {
      SectionAndItem<T> sectionAndItem = getSectionAndItem(i);
      if (sectionAndItem.graphObject != null) {
        String id = getIdOfGraphObject(sectionAndItem.graphObject);
        ImageRequest request = pendingRequests.get(id);
        if (request != null) {
          ImageDownloader.prioritizeRequest(request);
        }
      }
    }

    // For items which are not visible, but within the buffer on either side, we want to
    // fetch those items and store them in a small in-memory cache of bitmaps.
    int start = Math.max(0, firstVisibleItem - prefetchBuffer);
    int end = Math.min(lastVisibleItem + prefetchBuffer, getCount() - 1);
    ArrayList<T> graphObjectsToPrefetchPicturesFor = new ArrayList<T>();
    // Add the IDs before and after the visible range.
    for (int i = start; i < firstVisibleItem; ++i) {
      SectionAndItem<T> sectionAndItem = getSectionAndItem(i);
      if (sectionAndItem.graphObject != null) {
        graphObjectsToPrefetchPicturesFor.add(sectionAndItem.graphObject);
      }
    }
    for (int i = lastVisibleItem + 1; i <= end; ++i) {
      SectionAndItem<T> sectionAndItem = getSectionAndItem(i);
      if (sectionAndItem.graphObject != null) {
        graphObjectsToPrefetchPicturesFor.add(sectionAndItem.graphObject);
      }
    }
    for (T graphObject : graphObjectsToPrefetchPicturesFor) {
      URI uri = getPictureUriOfGraphObject(graphObject);
      final String id = getIdOfGraphObject(graphObject);

      // This URL already have been requested for pre-fetching, but we want to act in an LRU manner,
      // so move
      // it to the end of the list regardless.
      boolean alreadyPrefetching = prefetchedProfilePictureIds.remove(id);
      prefetchedProfilePictureIds.add(id);

      // If we've already requested it for pre-fetching, no need to do so again.
      if (!alreadyPrefetching) {
        downloadProfilePicture(id, uri, null);
      }
    }
  }
 private void setResultIds(Item item, int index) {
   if (item != null && item instanceof CatalogItem) {
     CatalogItem catalogItem = (CatalogItem) item;
     if (catalogItem.IsChecked) {
       int insertIndex = index <= 0 ? -1 : (index - 1);
       if (mySelectedItems.contains(catalogItem)) {
         mySelectedItems.remove(catalogItem);
       }
       if (insertIndex >= 0) {
         mySelectedItems.add(insertIndex, catalogItem);
       } else {
         mySelectedItems.add(catalogItem);
       }
     } else {
       mySelectedItems.remove(catalogItem);
     }
     final ArrayList<String> ids = new ArrayList<String>();
     for (Item selectedItem : mySelectedItems) {
       if (selectedItem instanceof CatalogItem) {
         final CatalogItem ci = (CatalogItem) selectedItem;
         if (ci.IsChecked) {
           ids.add(ci.Id);
         }
       }
     }
     setResult(
         RESULT_OK,
         new Intent()
             .putStringArrayListExtra(NetworkLibraryActivity.ENABLED_CATALOG_IDS_KEY, ids));
   }
 }
Example #6
0
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.c09_overscroll);

    for (int i = 1001; i <= 1003; i++) {
      mItem.add(Integer.toString(i));
    }

    mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mItem);

    mList = (ListView) findViewById(R.id.list);
    mList.setAdapter(mAdapter);
  }
Example #7
0
  public void addFreeSquares(ArrayList<Point> points) { // add all squares
    for (int i = 0; i < GRID_WIDTH; i++) {
      for (int j = 0; j < GRID_HEIGHT; j++) {
        points.add(new Point(i, j));
      }
    }

    // remove all pieces
    for (Piece piece : game.getPieces()) {
      if (!piece.isOut()) {
        points.remove(piece.getLocation());
      }
    }
  }
  public List<T> getGraphObjectsById(Collection<String> ids) {
    Set<String> idSet = new HashSet<String>();
    idSet.addAll(ids);

    ArrayList<T> result = new ArrayList<T>(idSet.size());
    for (String id : idSet) {
      T graphObject = graphObjectsById.get(id);
      if (graphObject != null) {
        result.add(graphObject);
      }
    }

    return result;
  }
  @Override
  public void onItemClick(AdapterView<?> aListView, View aView, int aPosition, long aID) {
    final FileWrapper item = adapter.getItem(aPosition);

    if (item.parentItem && backStack.get(backStack.size() - 1).parentIsBack) {
      backStack.remove(backStack.size() - 1);
      wrapFiles();
      return;
    } else if (item.dirSelectItem) {
      finishWithPath(listedDirectory.getAbsolutePath());
      return;
    }

    final File selected = item.parentItem ? listedDirectory.getParentFile() : item.file;

    if (selected.isDirectory()) {
      backStack.add(new BackStackItem(selected.getAbsolutePath(), !item.parentItem));
      wrapFiles();
    } else {
      String filePath = selected.getAbsolutePath();
      finishWithPath(filePath);
    }
  }
Example #10
0
  String[] getPluginDirectories() {

    ArrayList<String> directories = new ArrayList<String>();
    PackageManager pm = this.mAppContext.getPackageManager();
    List<ResolveInfo> plugins =
        pm.queryIntentServices(
            new Intent(PLUGIN_ACTION), PackageManager.GET_SERVICES | PackageManager.GET_META_DATA);

    synchronized (mPackageInfoCache) {

      // clear the list of existing packageInfo objects
      mPackageInfoCache.clear();

      for (ResolveInfo info : plugins) {

        // retrieve the plugin's service information
        ServiceInfo serviceInfo = info.serviceInfo;
        if (serviceInfo == null) {
          Log.w(LOGTAG, "Ignore bad plugin");
          continue;
        }

        Log.w(LOGTAG, "Loading plugin: " + serviceInfo.packageName);

        // retrieve information from the plugin's manifest
        PackageInfo pkgInfo;
        try {
          pkgInfo =
              pm.getPackageInfo(
                  serviceInfo.packageName,
                  PackageManager.GET_PERMISSIONS | PackageManager.GET_SIGNATURES);
        } catch (Exception e) {
          Log.w(LOGTAG, "Can't find plugin: " + serviceInfo.packageName);
          continue;
        }
        if (pkgInfo == null) {
          Log.w(
              LOGTAG,
              "Loading plugin: "
                  + serviceInfo.packageName
                  + ". Could not load package information.");
          continue;
        }

        /*
         * find the location of the plugin's shared library. The default
         * is to assume the app is either a user installed app or an
         * updated system app. In both of these cases the library is
         * stored in the app's data directory.
         */
        String directory = pkgInfo.applicationInfo.dataDir + "/lib";
        final int appFlags = pkgInfo.applicationInfo.flags;
        final int updatedSystemFlags =
            ApplicationInfo.FLAG_SYSTEM | ApplicationInfo.FLAG_UPDATED_SYSTEM_APP;
        // preloaded system app with no user updates
        if ((appFlags & updatedSystemFlags) == ApplicationInfo.FLAG_SYSTEM) {
          directory = PLUGIN_SYSTEM_LIB + pkgInfo.packageName;
        }

        // check if the plugin has the required permissions
        String permissions[] = pkgInfo.requestedPermissions;
        if (permissions == null) {
          Log.w(
              LOGTAG,
              "Loading plugin: "
                  + serviceInfo.packageName
                  + ". Does not have required permission.");
          continue;
        }
        boolean permissionOk = false;
        for (String permit : permissions) {
          if (PLUGIN_PERMISSION.equals(permit)) {
            permissionOk = true;
            break;
          }
        }
        if (!permissionOk) {
          Log.w(
              LOGTAG,
              "Loading plugin: "
                  + serviceInfo.packageName
                  + ". Does not have required permission (2).");
          continue;
        }

        // check to ensure the plugin is properly signed
        Signature signatures[] = pkgInfo.signatures;
        if (signatures == null) {
          Log.w(LOGTAG, "Loading plugin: " + serviceInfo.packageName + ". Not signed.");
          continue;
        }

        // determine the type of plugin from the manifest
        if (serviceInfo.metaData == null) {
          Log.e(LOGTAG, "The plugin '" + serviceInfo.name + "' has no type defined");
          continue;
        }

        String pluginType = serviceInfo.metaData.getString(PLUGIN_TYPE);
        if (!TYPE_NATIVE.equals(pluginType)) {
          Log.e(LOGTAG, "Unrecognized plugin type: " + pluginType);
          continue;
        }

        try {
          Class<?> cls = getPluginClass(serviceInfo.packageName, serviceInfo.name);

          // TODO implement any requirements of the plugin class here!
          boolean classFound = true;

          if (!classFound) {
            Log.e(
                LOGTAG,
                "The plugin's class' "
                    + serviceInfo.name
                    + "' does not extend the appropriate class.");
            continue;
          }

        } catch (NameNotFoundException e) {
          Log.e(LOGTAG, "Can't find plugin: " + serviceInfo.packageName);
          continue;
        } catch (ClassNotFoundException e) {
          Log.e(LOGTAG, "Can't find plugin's class: " + serviceInfo.name);
          continue;
        }

        // if all checks have passed then make the plugin available
        mPackageInfoCache.add(pkgInfo);
        directories.add(directory);
      }
    }

    return directories.toArray(new String[directories.size()]);
  }
  protected void addDisallowedExt(String ext) {
    if (disallowedExt == null) disallowedExt = new ArrayList<String>();

    disallowedExt.add(ext);
  }
  protected void addAllowedExt(String ext) {
    if (allowedExt == null) allowedExt = new ArrayList<String>();

    allowedExt.add(ext);
  }
  public void showOrder(Order order) {
    currentOrder = order;
    valueList = currentOrder.getOrderValues();
    editFields = new ArrayList<EditText>();

    if (mainLayout != null) {

      Button saveButton = (Button) getActivity().findViewById(R.id.saveButton);
      saveButton.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View view) {
              saveOrder(currentOrder);
              fragmentListener.saveOrderButtonClicked();
            }
          });

      CheckBox execStateCheckBox = (CheckBox) getActivity().findViewById(R.id.execStateCheckBox);
      execStateCheckBox.setChecked(currentOrder.getExecState());
      execStateCheckBox.setOnCheckedChangeListener(
          new CheckBox.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
              currentOrder.setExecState(isChecked);
              valueList.put("execState", isChecked);
            }
          });

      EditText clientNameEdit = (EditText) mainLayout.findViewById(R.id.clientNameEdit);
      clientNameEdit.setOnKeyListener(onTextChanged);
      clientNameEdit.setOnFocusChangeListener(onFocusLost);
      clientNameEdit.setText(currentOrder.getClientName());
      clientNameEdit.setTag("clientName");
      editFields.add(clientNameEdit);

      EditText clientPhoneEdit = (EditText) mainLayout.findViewById(R.id.clientPhoneEdit);
      clientPhoneEdit.setOnKeyListener(onTextChanged);
      clientPhoneEdit.setOnFocusChangeListener(onFocusLost);
      clientPhoneEdit.setText(currentOrder.getClientPhone());
      clientPhoneEdit.setTag("clientPhone");
      editFields.add(clientPhoneEdit);

      EditText carMakerEdit = (EditText) mainLayout.findViewById(R.id.carMakerEdit);
      carMakerEdit.setOnKeyListener(onTextChanged);
      carMakerEdit.setOnFocusChangeListener(onFocusLost);
      carMakerEdit.setText(currentOrder.getCarMaker());
      carMakerEdit.setTag("carMaker");
      editFields.add(carMakerEdit);

      EditText colorCodeEdit = (EditText) mainLayout.findViewById(R.id.colorCodeEdit);
      colorCodeEdit.setOnKeyListener(onTextChanged);
      colorCodeEdit.setOnFocusChangeListener(onFocusLost);
      colorCodeEdit.setText(currentOrder.getColorCode());
      colorCodeEdit.setTag("colorCode");
      editFields.add(colorCodeEdit);

      EditText volumeBaseEdit = (EditText) mainLayout.findViewById(R.id.volumeBaseEdit);
      volumeBaseEdit.setOnKeyListener(onTextChanged);
      volumeBaseEdit.setOnFocusChangeListener(onFocusLost);
      volumeBaseEdit.setFilters(new InputFilter[] {new RealNumberInputFilter()});
      volumeBaseEdit.setText(currentOrder.getVolumeBase().toString());
      volumeBaseEdit.setTag("volumeBase");
      editFields.add(volumeBaseEdit);

      EditText volumeAdditionEdit = (EditText) mainLayout.findViewById(R.id.volumeAdditionEdit);
      volumeAdditionEdit.setOnKeyListener(onTextChanged);
      volumeAdditionEdit.setOnFocusChangeListener(onFocusLost);
      volumeAdditionEdit.setFilters(new InputFilter[] {new RealNumberInputFilter()});
      volumeAdditionEdit.setText(currentOrder.getVolumeAddition().toString());
      volumeAdditionEdit.setTag("volumeAddition");
      editFields.add(volumeAdditionEdit);

      EditText orderDateEdit = (EditText) mainLayout.findViewById(R.id.orderDateEdit);
      orderDateEdit.setOnKeyListener(onTextChanged);
      orderDateEdit.setOnFocusChangeListener(onFocusLost);
      orderDateEdit.setFilters(new InputFilter[] {new DateInputFilter()});
      orderDateEdit.setText(currentOrder.getOrderDate().toString());
      orderDateEdit.setTag("orderDate");
      editFields.add(orderDateEdit);

      EditText execDateEdit = (EditText) mainLayout.findViewById(R.id.execDateEdit);
      execDateEdit.setOnKeyListener(onTextChanged);
      execDateEdit.setOnFocusChangeListener(onFocusLost);
      execDateEdit.setFilters(new InputFilter[] {new DateInputFilter()});
      execDateEdit.setText(currentOrder.getExecDate().toString());
      execDateEdit.setTag("execDate");
      editFields.add(execDateEdit);

      NumberKeyListener realKeyListener =
          new NumberKeyListener() {
            @Override
            protected char[] getAcceptedChars() {
              return new char[] {'.', ',', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
            }

            @Override
            public int getInputType() {
              return TYPE_CLASS_NUMBER | TYPE_NUMBER_FLAG_DECIMAL;
            }
          };
      volumeBaseEdit.setKeyListener(realKeyListener);
      volumeAdditionEdit.setKeyListener(realKeyListener);
    }
  }