List of usage examples for android.text.format DateUtils getRelativeTimeSpanString
public static CharSequence getRelativeTimeSpanString(Context c, long millis, boolean withPreposition)
From source file:com.kncwallet.wallet.ui.WalletActivity.java
private void prepareImportKeysDialog(final Dialog dialog) { final AlertDialog alertDialog = (AlertDialog) dialog; final List<File> files = new LinkedList<File>(); // external storage if (Constants.EXTERNAL_WALLET_BACKUP_DIR.exists() && Constants.EXTERNAL_WALLET_BACKUP_DIR.isDirectory()) for (final File file : Constants.EXTERNAL_WALLET_BACKUP_DIR.listFiles()) if (WalletUtils.KEYS_FILE_FILTER.accept(file) || Crypto.OPENSSL_FILE_FILTER.accept(file)) files.add(file);//w ww . j a v a 2 s .com // internal storage for (final String filename : fileList()) if (filename.startsWith(Constants.WALLET_KEY_BACKUP_BASE58 + '.')) files.add(new File(getFilesDir(), filename)); // sort Collections.sort(files, new Comparator<File>() { @Override public int compare(final File lhs, final File rhs) { return lhs.getName().compareToIgnoreCase(rhs.getName()); } }); final FileAdapter adapter = new FileAdapter(this, files) { @Override public View getDropDownView(final int position, View row, final ViewGroup parent) { final File file = getItem(position); final boolean isExternal = Constants.EXTERNAL_WALLET_BACKUP_DIR.equals(file.getParentFile()); final boolean isEncrypted = Crypto.OPENSSL_FILE_FILTER.accept(file); if (row == null) row = inflater.inflate(R.layout.wallet_import_keys_file_row, null); final TextView filenameView = (TextView) row .findViewById(R.id.wallet_import_keys_file_row_filename); filenameView.setText(file.getName()); final TextView securityView = (TextView) row .findViewById(R.id.wallet_import_keys_file_row_security); final String encryptedStr = context .getString(isEncrypted ? R.string.import_keys_dialog_file_security_encrypted : R.string.import_keys_dialog_file_security_unencrypted); final String storageStr = context .getString(isExternal ? R.string.import_keys_dialog_file_security_external : R.string.import_keys_dialog_file_security_internal); securityView.setText(encryptedStr + ", " + storageStr); final TextView createdView = (TextView) row.findViewById(R.id.wallet_import_keys_file_row_created); createdView.setText(context.getString( isExternal ? R.string.import_keys_dialog_file_created_manual : R.string.import_keys_dialog_file_created_automatic, DateUtils.getRelativeTimeSpanString(context, file.lastModified(), true))); return row; } }; final Spinner fileView = (Spinner) alertDialog.findViewById(R.id.import_keys_from_storage_file); fileView.setAdapter(adapter); fileView.setEnabled(!adapter.isEmpty()); final EditText passwordView = (EditText) alertDialog.findViewById(R.id.import_keys_from_storage_password); passwordView.setText(null); final ImportDialogButtonEnablerListener dialogButtonEnabler = new ImportDialogButtonEnablerListener( passwordView, alertDialog) { @Override protected boolean hasFile() { return fileView.getSelectedItem() != null; } @Override protected boolean needsPassword() { final File selectedFile = (File) fileView.getSelectedItem(); return selectedFile != null ? Crypto.OPENSSL_FILE_FILTER.accept(selectedFile) : false; } }; passwordView.addTextChangedListener(dialogButtonEnabler); fileView.setOnItemSelectedListener(dialogButtonEnabler); final CheckBox showView = (CheckBox) alertDialog.findViewById(R.id.import_keys_from_storage_show); showView.setOnCheckedChangeListener(new ShowPasswordCheckListener(passwordView)); KnCDialog.fixDialogDivider(alertDialog); }
From source file:com.songcode.materialnotes.ui.NoteEditActivity.java
private String getSubTitle() { String dateStr = DateUtils.formatDateTime(this, mWorkingNote.getModifiedDate(), DateUtils.FORMAT_SHOW_TIME); if (mWorkingNote.hasClockAlert()) { long time = System.currentTimeMillis(); String alertStr = ""; if (time > mWorkingNote.getAlertDate()) { alertStr = getString(R.string.note_alert_expired); } else {/* w ww . jav a 2s . co m*/ alertStr = (String) DateUtils.getRelativeTimeSpanString(mWorkingNote.getAlertDate(), time, DateUtils.MINUTE_IN_MILLIS); } //emoji return dateStr + " | ???" + alertStr; } return dateStr; }
From source file:com.androzic.MapFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.action_add_waypoint: double[] loc = application.getMapCenter(); Waypoint waypoint = new Waypoint("", "", loc[0], loc[1]); waypoint.date = Calendar.getInstance().getTime(); int wpt = application.addWaypoint(waypoint); waypoint.name = "WPT" + wpt; application.saveDefaultWaypoints(); refreshMap();//from w ww. j a v a 2s . c om return true; case R.id.action_follow: setFollowing(!following); return true; case R.id.action_next_nav_point: application.navigationService.nextRouteWaypoint(); return true; case R.id.action_prev_nav_point: application.navigationService.prevRouteWaypoint(); return true; case R.id.action_stop_navigation: application.stopNavigation(); return true; case R.id.action_search: getActivity().onSearchRequested(); return true; case R.id.action_locate: { final Location l = application.getLastKnownSystemLocation(); final long now = System.currentTimeMillis(); final long fixed = l != null ? l.getTime() : 0L; if ((now - fixed) < 1000 * 60 * 60 * 12) // we do not take into account locations older then 12 hours { wait(new Waitable() { @Override public void waitFor() { if (application.ensureVisible(l.getLatitude(), l.getLongitude())) mapChanged(); else conditionsChanged(); getActivity().runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(application, DateUtils.getRelativeTimeSpanString(fixed, now, DateUtils.SECOND_IN_MILLIS), Toast.LENGTH_SHORT).show(); } }); } }); } else { Toast.makeText(application, getString(R.string.msg_nolastknownlocation), Toast.LENGTH_LONG).show(); } return true; } case R.id.action_locating: application.enableLocating(!application.isLocating()); return true; case R.id.action_tracking: application.enableTracking(!application.isTracking()); return true; default: return super.onOptionsItemSelected(item); } }
From source file:com.androzic.vnspeech.MapFragment.java
private void moveToWhereAmI() { final Location l = application.getLastKnownSystemLocation(); final long now = System.currentTimeMillis(); final long fixed = l != null ? l.getTime() : 0L; if ((now - fixed) < 1000 * 60 * 60 * 12) // we do not take into account locations older then 12 hours {//from w w w . j a va 2s.c o m wait(new Waitable() { @Override public void waitFor() { application.ensureVisible(l.getLatitude(), l.getLongitude()); getActivity().runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(application, DateUtils.getRelativeTimeSpanString(fixed, now, DateUtils.SECOND_IN_MILLIS), Toast.LENGTH_SHORT).show(); } }); } }); } else { Toast.makeText(application, getString(R.string.msg_nolastknownlocation), Toast.LENGTH_LONG).show(); } }