/* 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 onDraw(Canvas canvas) { // 검정색 배경으로 지운다. 빈 화면이면 지우기만 하고 리턴 canvas.drawColor(Color.BLACK); if (status == BLANK) { return; } // 도형 목록을 순회하면서 도형 정보대로 출력한다. int idx; for (idx = 0; idx < arShape.size(); idx++) { Paint Pnt = new Paint(); Pnt.setAntiAlias(true); Pnt.setColor(arShape.get(idx).color); Rect rt = arShape.get(idx).rt; switch (arShape.get(idx).what) { case Shape.RECT: canvas.drawRect(rt, Pnt); break; case Shape.CIRCLE: canvas.drawCircle( rt.left + rt.width() / 2, rt.top + rt.height() / 2, rt.width() / 2, Pnt); break; case Shape.TRIANGLE: Path path = new Path(); path.moveTo(rt.left + rt.width() / 2, rt.top); path.lineTo(rt.left, rt.bottom); path.lineTo(rt.right, rt.bottom); canvas.drawPath(path, Pnt); break; } } }
// 새로운 도형을 목록에 추가한다. void AddNewShape() { Shape shape = new Shape(); int idx; boolean bFindIntersect; Rect rt = new Rect(); // 기존 도형과 겹치지 않는 새 위치를 찾는다. for (; ; ) { // 크기는 32, 48, 64 중 하나 선택 int Size = 32 + 16 * Rnd.nextInt(3); // 위치는 난수로 선택 rt.left = Rnd.nextInt(getWidth()); rt.top = Rnd.nextInt(getHeight()); rt.right = rt.left + Size; rt.bottom = rt.top + Size; // 화면을 벗어나면 안된다. if (rt.right > getWidth() || rt.bottom > getHeight()) { continue; } // 기존 도형 순회하며 겹치는지 조사한다. bFindIntersect = false; for (idx = 0; idx < arShape.size(); idx++) { if (rt.intersect(arShape.get(idx).rt) == true) { bFindIntersect = true; } } // 겹치지 않을 때 확정한다. 겹치면 계속 새 위치 선정한다. if (bFindIntersect == false) { break; } } // 새 도형 정보 작성. 모양, 색상 등을 난수 선택한다. shape.what = Rnd.nextInt(3); switch (Rnd.nextInt(5)) { case 0: shape.color = Color.WHITE; break; case 1: shape.color = Color.RED; break; case 2: shape.color = Color.GREEN; break; case 3: shape.color = Color.BLUE; break; case 4: shape.color = Color.YELLOW; break; } shape.rt = rt; arShape.add(shape); }
// x, y 위치의 도형 번호를 찾는다. 도형이 없는 위치면 -1 리턴 int FindShapeIdx(int x, int y) { int idx; for (idx = 0; idx < arShape.size(); idx++) { if (arShape.get(idx).rt.contains(x, y)) { return idx; } } return -1; }
public void handleMessage(Message msg) { Ball B; for (int idx = 0; idx < arBall.size(); idx++) { B = arBall.get(idx); B.Move(getWidth(), getHeight()); if (B.count > 4) { arBall.remove(idx); idx--; } } invalidate(); mHandler.sendEmptyMessageDelayed(0, DELAY); }
/** Called when the activity is first created. */ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ArrayList<EntityManager> cachedData = (ArrayList<EntityManager>) getLastNonConfigurationInstance(); if (cachedData != null) { Log.i( getClass().getSimpleName(), "onCreate: ... found a LastNonConfigurationInstance, attempting to load it..."); em = (EntityManager) cachedData.get(0); /** We loaded a cached copy of the ES, so have to manually do this auto-setup */ MetaEntity.defaultEntityManager = em; } Log.i("" + this.getClass(), "activity onCreate"); }
private void wrapFiles() { listedDirectory = new File(backStack.get(backStack.size() - 1).path); if (!listedDirectory.isDirectory()) { throw new IllegalArgumentException("Directory is not valid."); } adapter.clear(); setTitle(listedDirectory.getAbsolutePath()); if (isDirectoryTarget) adapter.add(new FileWrapper(null, FileWrapper.DIRSELECT, true)); if (listedDirectory.getParentFile() != null) adapter.add(new FileWrapper(null, FileWrapper.PARENT, true)); // Copy new items final File[] files = listedDirectory.listFiles(); if (files != null) { for (File file : files) { String path = file.getName(); boolean allowFile = file.isDirectory() || (filterPath(path) && !isDirectoryTarget); if (allowFile) adapter.add(new FileWrapper(file, FileWrapper.FILE, file.isDirectory() || true)); } } // Sort items adapter.sort( new Comparator<FileWrapper>() { @Override public int compare(FileWrapper aLeft, FileWrapper aRight) { return aLeft.compareTo(aRight); }; }); // Update adapter.notifyDataSetChanged(); }
@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); } }
@Override public View getView(int position, View convertView, ViewGroup parent) { View v = convertView; if (v == null) { LayoutInflater vi = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); v = vi.inflate(R.layout.row, null); } Message m = items.get(position); // if (m != null) { m.createColorFromString(m.from); TextView tt = (TextView) v.findViewById(R.id.username); TextView bt = (TextView) v.findViewById(R.id.message); if (isMonospaced) { tt.setTypeface(Typeface.MONOSPACE); bt.setTypeface(Typeface.MONOSPACE); } tt.setText(m.getFrom()); tt.setTextColor(m.color); bt.setText(m.getMessage()); // } return v; }
// 화면 그리기 public void onDraw(Canvas canvas) { canvas.drawBitmap(mBack, 0, 0, null); for (int idx = 0; idx < arBall.size(); idx++) { arBall.get(idx).Draw(canvas); } }