@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); }
public void handleMessage(Message msg) { AddNewShape(); status = PLAY; invalidate(); String title; title = "MemoryPower - " + arShape.size() + " 단계"; mParent.setTitle(title); }
/* 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); }
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { if (backStack.size() > 1) { backStack.remove(backStack.size() - 1); wrapFiles(); } else { Intent intent = new Intent(); setResult(RESULT_CANCELED, intent); finish(); } return true; } return super.onKeyDown(keyCode, event); }
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); }
@Override public String toString() { StringBuilder colorStr = new StringBuilder("\ncolors:\n"); for (int i = 0; i < colors.size(); i++) { colorStr.append(colors.get(i)); if (i != colors.size() - 1) colorStr.append(", \n"); } StringBuilder plStr = new StringBuilder("\nprofiles:\n"); ProfileLevel[] profiles = getProfileLevels(); for (int i = 0; i < profiles.length; i++) { plStr.append(profiles[i].toString()); if (i != profiles.length - 1) plStr.append(", \n"); } return codecInfo.getName() + "(" + getLibjitsiEncoding() + ")" + colorStr + plStr; }
// 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; }
@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); } }
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); }
public boolean onTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { int sel; sel = FindShapeIdx((int) event.getX(), (int) event.getY()); // 빈 바닥을 찍었으면 무시한다. if (sel == -1) { return true; } // 마지막 추가된 도형을 제대로 찍었으면 다음 단계로 진행. // 빈 화면 잠시 보여준 후 새 도형 추가 if (sel == arShape.size() - 1) { status = BLANK; invalidate(); mHandler.sendEmptyMessageDelayed(0, DELAY); // 엉뚱한 도형을 찍었으면 질문 후 게임 종료 또는 재시작 } else { new AlertDialog.Builder(getContext()) .setMessage("재미있지! 또 할래?") .setTitle("게임 끝") .setPositiveButton( "함더", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { arShape.clear(); status = BLANK; invalidate(); mHandler.sendEmptyMessageDelayed(0, DELAY); } }) .setNegativeButton( "안해", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { mParent.finish(); } }) .show(); } return true; } return false; }
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(); }
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()]); }
// 화면 그리기 public void onDraw(Canvas canvas) { canvas.drawBitmap(mBack, 0, 0, null); for (int idx = 0; idx < arBall.size(); idx++) { arBall.get(idx).Draw(canvas); } }
@Override public int getCount() { return items.size(); }
private void parseResponse(Document document) { // ChumbyLog.i(TAG+".parseResponse()"); // ChumbyLog.i(XMLHelper.nodeToString(document)); Element notificationsNode = XMLUtil.firstChildOfType(document, "notifications"); if (notificationsNode != null) { lastTimeStamp = notificationsNode.getAttribute("timestamp"); // ChumbyLog.i(TAG+".parseResponse(): new lastTimeStamp: "+lastTimeStamp); ArrayList<Element> notificationNodes = XMLUtil.childrenOfType(notificationsNode, "notification"); for (int i = 0; i < notificationNodes.size(); i++) { Element notificationNode = notificationNodes.get(i); NotificationType type = NotificationType.parse(notificationNode.getAttribute("type")); ChumbyLog.i(TAG + ".parseResponse(): processing notification " + type.toString()); if (type == NotificationType.PROFILE) { ChannelNotification notification = new ChannelNotification(); notification.parse(notificationNode); NotificationAction action = notification.action; if (action == NotificationAction.CREATE) { dispatchEvent(new Event(PROFILE_CREATED, notification)); } else if (action == NotificationAction.DELETE) { dispatchEvent(new Event(PROFILE_DELETED, notification)); } else if (action == NotificationAction.UPDATE) { dispatchEvent(new Event(PROFILE_UPDATED, notification)); } else { ChumbyLog.w( TAG + ".parseResponse() unknown action " + action.toString() + " for " + type.toString()); } } else if (type == NotificationType.CHUM) { ChumNotification notification = new ChumNotification(); notification.parse(notificationNode); NotificationAction action = notification.action; if (action == NotificationAction.CREATE) { dispatchEvent(new Event(CHUM_CREATED, notification)); } else if (action == NotificationAction.DELETE) { dispatchEvent(new Event(CHUM_DELETED, notification)); } else if (action == NotificationAction.UPDATE) { dispatchEvent(new Event(CHUM_UPDATED, notification)); } else { ChumbyLog.w( TAG + ".parseResponse() unknown action " + action.toString() + " for " + type.toString()); } } else if (type == NotificationType.DEVICE) { DeviceNotification notification = new DeviceNotification(); notification.parse(notificationNode); NotificationAction action = notification.action; if (notification.id.equals(Chumby.getInstance().guid)) { if (action == NotificationAction.CREATE) { dispatchEvent(new Event(DEVICE_CREATED, notification)); } else if (action == NotificationAction.DELETE) { dispatchEvent(new Event(DEVICE_DELETED, notification)); } else if (action == NotificationAction.UPDATE) { dispatchEvent(new Event(DEVICE_UPDATED, notification)); } else { ChumbyLog.w( TAG + ".parseResponse() unknown action " + action.toString() + " for " + type.toString()); } } else { ChumbyLog.w(TAG + ".parseResponse(): device id mismatch:" + notification.id); } } else if (type == NotificationType.MESSAGE) { MessageNotification notification = new MessageNotification(); notification.parse(notificationNode); NotificationAction action = notification.action; if (action == NotificationAction.CREATE) { dispatchEvent(new Event(MESSAGE_CREATED, notification)); } else if (action == NotificationAction.DELETE) { dispatchEvent(new Event(MESSAGE_DELETED, notification)); } else { ChumbyLog.w( TAG + ".parseResponse() unknown action " + action.toString() + " for " + type.toString()); } } else if (type == NotificationType.WIDGET_INSTANCE) { WidgetNotification notification = new WidgetNotification(); notification.parse(notificationNode); NotificationAction action = notification.action; if (action == NotificationAction.CREATE) { dispatchEvent(new Event(WIDGET_CREATED, notification)); } else if (action == NotificationAction.DELETE) { dispatchEvent(new Event(WIDGET_DELETED, notification)); } else if (action == NotificationAction.UPDATE) { dispatchEvent(new Event(WIDGET_UPDATED, notification)); } else { ChumbyLog.w( TAG + ".parseResponse() unknown action " + action.toString() + " for " + type.toString()); } } else { ChumbyLog.w("NotificationEvents.parseResponse(): unhandled type " + type.toString()); } } } }