/* 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); }
private void updateLoader() { if (NavigineApp.Navigation == null) return; // Log.d(TAG, String.format(Locale.ENGLISH, "Update loader: %d", mLoader)); long timeNow = DateTimeUtils.currentTimeMillis(); if (mLoader < 0) return; int status = LocationLoader.checkLocationLoader(mLoader); if (status < 100) { if ((Math.abs(timeNow - mLoaderTime) > LOADER_TIMEOUT / 3 && status == 0) || (Math.abs(timeNow - mLoaderTime) > LOADER_TIMEOUT)) { mListView.setVisibility(View.GONE); mStatusLabel.setVisibility(View.VISIBLE); mStatusLabel.setText("Loading timeout!\nPlease, check your internet connection!"); Log.d(TAG, String.format(Locale.ENGLISH, "Load stopped on timeout!")); LocationLoader.stopLocationLoader(mLoader); mLoader = -1; } else { mListView.setVisibility(View.GONE); mStatusLabel.setVisibility(View.VISIBLE); mStatusLabel.setText(String.format(Locale.ENGLISH, "Loading content (%d%%)", status)); } } else { Log.d(TAG, String.format(Locale.ENGLISH, "Load finished with result: %d", status)); LocationLoader.stopLocationLoader(mLoader); mLoader = -1; if (status == 100) { parseMapsXml(); if (mInfoList.isEmpty()) { mListView.setVisibility(View.GONE); mStatusLabel.setVisibility(View.VISIBLE); mStatusLabel.setText("No locations available"); } else { mListView.setVisibility(View.VISIBLE); mStatusLabel.setVisibility(View.GONE); } } else { mListView.setVisibility(View.GONE); mStatusLabel.setVisibility(View.VISIBLE); mStatusLabel.setText("Error loading!\nPlease, check your ID!"); } } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.xiph_copyright); TextView tv = (TextView) findViewById(R.id.text); tv.setText(getXiphCopyright()); tv.setMovementMethod(new ScrollingMovementMethod()); }
private void initPagerItems() { for (int i = 0; i < bitmapList.size(); i++) { View v = LayoutInflater.from(this).inflate(R.layout.call_activity_itempage, null); ImageView imageView = (ImageView) v.findViewById(R.id.contactIv); TextView textView = (TextView) v.findViewById(R.id.contactTv); imageView.setImageBitmap(bitmapList.get(i)); textView.setText(nameList.get(i)); viewArrayList.add(v); } }
protected void onPostExecute(String[] result) { // ("Download complete: " + result + "\nComplete"); if (result.length < 2) { text1.setText("Error: " + result[0]); } else { // text1.setText("Starting download " + result[1] + "... " + result[0]); doDownload(result[0], result[1]); finish(); Toast.makeText(mContext.get(), "Downloading " + result[1] + "...", Toast.LENGTH_LONG) .show(); } }
@Override public View getView(final int position, View convertView, ViewGroup parent) { View view = convertView; if (view == null) { LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); view = inflater.inflate(R.layout.content_list_item, null); } TextView titleTextView = (TextView) view.findViewById(R.id.list_item_title); TextView stateTextView = (TextView) view.findViewById(R.id.list_item_state); TextView downTextView = (TextView) view.findViewById(R.id.list_item_downbar); Button downloadButton = (Button) view.findViewById(R.id.list_item_download_button); Button uploadButton = (Button) view.findViewById(R.id.list_item_upload_button); LocationInfo info = mInfoList.get(position); String titleText = info.title; String stateText = ""; if (titleText.length() > 30) titleText = titleText.substring(0, 28) + "..."; synchronized (mLoaderMap) { if (mLoaderMap.containsKey(info.title)) { LoaderState loader = mLoaderMap.get(info.title); if (loader.state < 100) stateText = String.format(Locale.ENGLISH, "%d%%", loader.state); else if (loader.state == 100) stateText = String.format(Locale.ENGLISH, "Done!"); else stateText = String.format(Locale.ENGLISH, "Failed!"); } } if (info.localVersion < 0) titleText += " (?)"; else { if (info.localModified) titleText += String.format(Locale.ENGLISH, " (v. %d+)", info.localVersion); else titleText += String.format(Locale.ENGLISH, " (v. %d)", info.localVersion); } String mapFile = NavigineApp.Settings.getString("map_file", ""); if (mapFile.equals(info.archiveFile)) { titleTextView.setTypeface(null, Typeface.BOLD); view.setBackgroundColor(Color.parseColor("#590E0E")); } else { titleTextView.setTypeface(null, Typeface.NORMAL); view.setBackgroundColor(Color.BLACK); } titleTextView.setText(titleText); stateTextView.setText(stateText); if (info.localModified) { downloadButton.setVisibility(View.GONE); uploadButton.setVisibility(View.VISIBLE); downTextView.setText("Version is modified. Upload?"); } else if (info.serverVersion > info.localVersion) { downloadButton.setVisibility(View.VISIBLE); uploadButton.setVisibility(View.GONE); String downText = String.format(Locale.ENGLISH, "Version available: %d", info.serverVersion); downTextView.setText(downText); } else { downloadButton.setVisibility(View.INVISIBLE); uploadButton.setVisibility(View.GONE); downTextView.setText("Version is up to date"); } downloadButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { startDownload(position); } }); uploadButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { startUpload(position); } }); return view; }
protected void onProgressUpdate(String... progress) { // setProgressPercent(progress[0]); text1.setText(progress[0]); }