List of usage examples for android.text.format DateUtils getRelativeTimeSpanString
public static CharSequence getRelativeTimeSpanString(Context c, long millis, boolean withPreposition)
From source file:org.dmfs.tasks.notification.NotificationActionUtils.java
/** * Returns a string representation for the time, with a relative date and an absolute time *///from w w w.j a v a 2 s. com public static String formatTime(Context context, Time time) { Time now = new Time(); now.setToNow(); String dateString; if (time.allDay) { Time allDayNow = new Time("UTC"); allDayNow.set(now.monthDay, now.month, now.year); dateString = DateUtils.getRelativeTimeSpanString(time.toMillis(false), allDayNow.toMillis(false), DateUtils.DAY_IN_MILLIS).toString(); } else { dateString = DateUtils .getRelativeTimeSpanString(time.toMillis(false), now.toMillis(false), DateUtils.DAY_IN_MILLIS) .toString(); } // return combined date and time String timeString = new DateFormatter(context).format(time, DateFormatContext.NOTIFICATION_VIEW_TIME); return new StringBuilder().append(dateString).append(", ").append(timeString).toString(); }
From source file:systems.soapbox.ombuds.client.ui.WalletActivity.java
private Dialog createRestoreWalletDialog() { final View view = getLayoutInflater().inflate(R.layout.restore_wallet_dialog, null); final TextView messageView = (TextView) view.findViewById(R.id.restore_wallet_dialog_message); final Spinner fileView = (Spinner) view.findViewById(R.id.import_keys_from_storage_file); final EditText passwordView = (EditText) view.findViewById(R.id.import_keys_from_storage_password); final DialogBuilder dialog = new DialogBuilder(this); dialog.setTitle(R.string.import_keys_dialog_title); dialog.setView(view);/* w w w . j a v a2 s . c om*/ dialog.setPositiveButton(R.string.import_keys_dialog_button_import, new OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { final File file = (File) fileView.getSelectedItem(); final String password = passwordView.getText().toString().trim(); passwordView.setText(null); // get rid of it asap if (WalletUtils.BACKUP_FILE_FILTER.accept(file)) restoreWalletFromProtobuf(file); else if (WalletUtils.KEYS_FILE_FILTER.accept(file)) restorePrivateKeysFromBase58(file); else if (Crypto.OPENSSL_FILE_FILTER.accept(file)) restoreWalletFromEncrypted(file, password); } }); dialog.setNegativeButton(R.string.button_cancel, new OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { passwordView.setText(null); // get rid of it asap } }); dialog.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(final DialogInterface dialog) { passwordView.setText(null); // get rid of it asap } }); final FileAdapter adapter = new FileAdapter(this) { @Override public View getDropDownView(final int position, View row, final ViewGroup parent) { final File file = getItem(position); final boolean isExternal = Constants.Files.EXTERNAL_WALLET_BACKUP_DIR.equals(file.getParentFile()); final boolean isEncrypted = Crypto.OPENSSL_FILE_FILTER.accept(file); if (row == null) row = inflater.inflate(R.layout.restore_wallet_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 String path; final String backupPath = Constants.Files.EXTERNAL_WALLET_BACKUP_DIR.getAbsolutePath(); final String storagePath = Constants.Files.EXTERNAL_STORAGE_DIR.getAbsolutePath(); if (backupPath.startsWith(storagePath)) path = backupPath.substring(storagePath.length()); else path = backupPath; messageView.setText(getString(R.string.import_keys_dialog_message, path)); fileView.setAdapter(adapter); return dialog.create(); }
From source file:app.abhijit.iter.data.source.StudentDataSource.java
private Subject generateStudentSubject(JsonObject subject) { String name = subject.get(STUDENT_SUBJECT_NAME_KEY).getAsString(); String code = subject.get(STUDENT_SUBJECT_CODE_KEY).getAsString(); int presentClasses = subject.get(STUDENT_SUBJECT_PRESENT_CLASSES_KEY).getAsInt(); int oldPresentClasses = subject.get(STUDENT_SUBJECT_OLD_PRESENT_CLASSES_KEY).getAsInt(); int totalClasses = subject.get(STUDENT_SUBJECT_TOTAL_CLASSES_KEY).getAsInt(); int oldTotalClasses = subject.get(STUDENT_SUBJECT_OLD_TOTAL_CLASSES_KEY).getAsInt(); long lastUpdated = subject.get(STUDENT_SUBJECT_LAST_UPDATED_KEY).getAsLong(); float attendance = (presentClasses / (float) totalClasses) * 100; float oldAttendance = (oldPresentClasses / (float) oldTotalClasses) * 100; int absentClasses = totalClasses - presentClasses; int oldAbsentClasses = oldTotalClasses - oldPresentClasses; int status;/*w w w .j a v a 2s . c o m*/ if (attendance == oldAttendance) { if (attendance > 85) { status = R.drawable.ic_status_ok; } else if (attendance > 75) { status = R.drawable.ic_status_warning; } else { status = R.drawable.ic_status_critical; } } else { if (attendance > oldAttendance) { status = R.drawable.ic_status_up; } else { status = R.drawable.ic_status_down; } } int subjectAvatar = mSubjectAvatars.get("generic"); if (mSubjectAvatars.containsKey(code)) { subjectAvatar = mSubjectAvatars.get(code); } else if (code.length() >= 3 && mSubjectAvatars.containsKey(code.substring(0, 3))) { subjectAvatar = mSubjectAvatars.get(code.substring(0, 3)); } return new Subject(subjectAvatar, name, attendance == oldAttendance ? null : String.format(Locale.US, "%.2f", oldAttendance) + "%", String.format(Locale.US, "%.2f", attendance) + "%", status, DateUtils.getRelativeTimeSpanString(lastUpdated, new Date().getTime(), 0).toString(), presentClasses == oldPresentClasses && totalClasses == oldTotalClasses ? null : oldPresentClasses + "/" + oldTotalClasses + (oldTotalClasses == 1 ? " class" : " classes"), presentClasses + "/" + totalClasses + (totalClasses == 1 ? " class" : " classes"), absentClasses == oldAbsentClasses ? null : oldAbsentClasses + (oldAbsentClasses == 1 ? " class" : " classes"), absentClasses + (absentClasses == 1 ? " class" : " classes"), generateBunkStats((int) attendance, totalClasses, presentClasses, absentClasses)); }
From source file:com.hivewallet.androidclient.wallet.ui.WalletActivity.java
private Dialog createImportKeysDialog() { final View view = getLayoutInflater().inflate(R.layout.import_keys_from_storage_dialog, null); final Spinner fileView = (Spinner) view.findViewById(R.id.import_keys_from_storage_file); final EditText passwordView = (EditText) view.findViewById(R.id.import_keys_from_storage_password); final DialogBuilder dialog = new DialogBuilder(this); dialog.setTitle(R.string.import_keys_dialog_title); dialog.setView(view);//w w w . j a va 2 s .c o m dialog.setPositiveButton(R.string.import_keys_dialog_button_import, new OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { final File file = (File) fileView.getSelectedItem(); final String password = passwordView.getText().toString().trim(); passwordView.setText(null); // get rid of it asap final boolean isProtobuf = file.getName() .startsWith(Constants.Files.WALLET_KEY_BACKUP_PROTOBUF + '.') || file.getName().startsWith(Constants.Files.EXTERNAL_WALLET_BACKUP + '-') || file.getName().startsWith(Constants.Files.EXTERNAL_WALLET_TMP_FILE); if (isProtobuf) restoreWalletFromProtobuf(file, password); else importPrivateKeysFromBase58(file, password); } }); dialog.setNegativeButton(R.string.button_cancel, new OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { passwordView.setText(null); // get rid of it asap } }); dialog.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(final DialogInterface dialog) { passwordView.setText(null); // get rid of it asap } }); final FileAdapter adapter = new FileAdapter(this) { @Override public View getDropDownView(final int position, View row, final ViewGroup parent) { final File file = getItem(position); File externalWalletBackupDir = new File(getFilesDir(), Constants.Files.EXTERNAL_WALLET_BACKUP_DIR); File selectedExternalWalletBackup = new File(getFilesDir(), Constants.Files.EXTERNAL_WALLET_TMP_FILE); final boolean isExternal = selectedExternalWalletBackup.equals(file); final boolean isManual = externalWalletBackupDir.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 = isExternal ? "" : ", " + context.getString(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); if (isExternal) { createdView.setText(context.getString(R.string.import_keys_dialog_file_just_selected)); } else if (isManual) { createdView.setText(context.getString(R.string.import_keys_dialog_file_created_manual, DateUtils.getRelativeTimeSpanString(context, file.lastModified(), true))); } else { createdView.setText(context.getString(R.string.import_keys_dialog_file_created_automatic, DateUtils.getRelativeTimeSpanString(context, file.lastModified(), true))); } return row; } }; fileView.setAdapter(adapter); return dialog.create(); }
From source file:io.plaidapp.ui.DesignerNewsStory.java
private void bindDescription() { final TextView storyComment = (TextView) header.findViewById(R.id.story_comment); if (!TextUtils.isEmpty(story.comment)) { HtmlUtils.setTextWithNiceLinks(storyComment, markdown.markdownToSpannable(story.comment, storyComment, new Bypass.LoadImageCallback() { @Override//from w ww . j ava 2s .c om public void loadImage(String src, ImageLoadingSpan loadingSpan) { Glide.with(DesignerNewsStory.this).load(src).asBitmap() .diskCacheStrategy(DiskCacheStrategy.ALL) .into(new ImageSpanTarget(storyComment, loadingSpan)); } })); } else { storyComment.setVisibility(View.GONE); } upvoteStory = (Button) header.findViewById(R.id.story_vote_action); upvoteStory.setText(getResources().getQuantityString(R.plurals.upvotes, story.vote_count, NumberFormat.getInstance().format(story.vote_count))); upvoteStory.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { upvoteStory(); } }); Button share = (Button) header.findViewById(R.id.story_share_action); share.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startActivity(ShareCompat.IntentBuilder.from(DesignerNewsStory.this).setText(story.url) .setType("text/plain").setSubject(story.title).getIntent()); } }); TextView storyPosterTime = (TextView) header.findViewById(R.id.story_poster_time); SpannableString poster = new SpannableString("" + story.user_display_name); poster.setSpan(new TextAppearanceSpan(this, R.style.TextAppearance_CommentAuthor), 0, poster.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); CharSequence job = !TextUtils.isEmpty(story.user_job) ? "\n" + story.user_job : ""; CharSequence timeAgo = DateUtils.getRelativeTimeSpanString(story.created_at.getTime(), System.currentTimeMillis(), DateUtils.SECOND_IN_MILLIS); storyPosterTime.setText(TextUtils.concat(poster, job, "\n", timeAgo)); ImageView avatar = (ImageView) header.findViewById(R.id.story_poster_avatar); if (!TextUtils.isEmpty(story.user_portrait_url)) { Glide.with(this).load(story.user_portrait_url).placeholder(R.drawable.avatar_placeholder) .transform(circleTransform).into(avatar); } else { avatar.setVisibility(View.GONE); } }
From source file:io.plaidapp.ui.DesignerNewsStory.java
private void bindDescription() { final TextView storyComment = (TextView) header.findViewById(R.id.story_comment); if (!TextUtils.isEmpty(story.comment)) { HtmlUtils.parseMarkdownAndSetText(storyComment, story.comment, markdown, new Bypass.LoadImageCallback() { @Override/*w w w. jav a 2s . c o m*/ public void loadImage(String src, ImageLoadingSpan loadingSpan) { Glide.with(DesignerNewsStory.this).load(src).asBitmap() .diskCacheStrategy(DiskCacheStrategy.ALL) .into(new ImageSpanTarget(storyComment, loadingSpan)); } }); } else { storyComment.setVisibility(View.GONE); } upvoteStory = (TextView) header.findViewById(R.id.story_vote_action); upvoteStory.setText(getResources().getQuantityString(R.plurals.upvotes, story.vote_count, NumberFormat.getInstance().format(story.vote_count))); upvoteStory.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { upvoteStory(); } }); final TextView share = (TextView) header.findViewById(R.id.story_share_action); share.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ((AnimatedVectorDrawable) share.getCompoundDrawables()[1]).start(); startActivity(ShareCompat.IntentBuilder.from(DesignerNewsStory.this).setText(story.url) .setType("text/plain").setSubject(story.title).getIntent()); } }); TextView storyPosterTime = (TextView) header.findViewById(R.id.story_poster_time); SpannableString poster = new SpannableString(story.user_display_name.toLowerCase()); poster.setSpan(new TextAppearanceSpan(this, R.style.TextAppearance_CommentAuthor), 0, poster.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); CharSequence job = !TextUtils.isEmpty(story.user_job) ? "\n" + story.user_job.toLowerCase() : ""; CharSequence timeAgo = DateUtils.getRelativeTimeSpanString(story.created_at.getTime(), System.currentTimeMillis(), DateUtils.SECOND_IN_MILLIS).toString().toLowerCase(); storyPosterTime.setText(TextUtils.concat(poster, job, "\n", timeAgo)); ImageView avatar = (ImageView) header.findViewById(R.id.story_poster_avatar); if (!TextUtils.isEmpty(story.user_portrait_url)) { Glide.with(this).load(story.user_portrait_url).placeholder(R.drawable.avatar_placeholder) .transform(circleTransform).into(avatar); } else { avatar.setVisibility(View.GONE); } }
From source file:com.landenlabs.all_devtool.ConsoleFragment.java
@SuppressLint("DefaultLocale") private void updateConsole() { if (mSystemViews.isEmpty()) return;// ww w . j a va 2s . c om try { // ----- System ----- int threadCount = Thread.activeCount(); ApplicationInfo appInfo = getActivity().getApplicationInfo(); mSystemViews.get(SYSTEM_PACKAGE).get(1).setText(appInfo.packageName); mSystemViews.get(SYSTEM_MODEL).get(1).setText(Build.MODEL); mSystemViews.get(SYSTEM_ANDROID).get(1).setText(Build.VERSION.RELEASE); if (Build.VERSION.SDK_INT >= 16) { int lines = 0; final StringBuilder permSb = new StringBuilder(); try { PackageInfo pi = getContext().getPackageManager().getPackageInfo(getContext().getPackageName(), PackageManager.GET_PERMISSIONS); for (int i = 0; i < pi.requestedPermissions.length; i++) { if ((pi.requestedPermissionsFlags[i] & PackageInfo.REQUESTED_PERMISSION_GRANTED) != 0) { permSb.append(pi.requestedPermissions[i]).append("\n"); lines++; } } } catch (Exception e) { } final int lineCnt = lines; mSystemViews.get(SYSTEM_PERM).get(1).setText(String.format("%d perms [press]", lines)); mSystemViews.get(SYSTEM_PERM).get(1).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (v.getTag() == null) { String permStr = permSb.toString().replaceAll("android.permission.", "") .replaceAll("\n[^\n]*permission", ""); mSystemViews.get(SYSTEM_PERM).get(1).setText(permStr); mSystemViews.get(SYSTEM_PERM).get(0).setLines(lineCnt); mSystemViews.get(SYSTEM_PERM).get(1).setLines(lineCnt); mSystemViews.get(SYSTEM_PERM).get(1).setTag(lineCnt); } else { mSystemViews.get(SYSTEM_PERM).get(1).setText(String.format("%d perms", lineCnt)); mSystemViews.get(SYSTEM_PERM).get(0).setLines(1); mSystemViews.get(SYSTEM_PERM).get(1).setLines(1); mSystemViews.get(SYSTEM_PERM).get(1).setTag(null); } } }); } else { String permStr = ""; if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) permStr += (" Find Loc"); if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) permStr += (" Coarse Loc"); mSystemViews.get(SYSTEM_PERM).get(1).setText(permStr); } ActivityManager actMgr = (ActivityManager) getActivity().getSystemService(Context.ACTIVITY_SERVICE); int processCnt = actMgr.getRunningAppProcesses().size(); mSystemViews.get(SYSTEM_PROCESSES).get(1).setText(String.format("%d", consoleState.processCnt)); mSystemViews.get(SYSTEM_PROCESSES).get(2).setText(String.format("%d", processCnt)); // mSystemViews.get(SYSTEM_BATTERY).get(1).setText(String.format("%d%%", consoleState.batteryLevel)); mSystemViews.get(SYSTEM_BATTERY).get(2) .setText(String.format("%%%d", calculateBatteryLevel(getActivity()))); // long cpuNano = Debug.threadCpuTimeNanos(); // mSystemViews.get(SYSTEM_CPU).get(2).setText(String.format("%d%%", cpuNano)); } catch (Exception ex) { m_log.e(ex.getMessage()); } try { // ----- Network WiFi----- WifiManager wifiMgr = (WifiManager) getContext().getApplicationContext() .getSystemService(Context.WIFI_SERVICE); if (wifiMgr != null && wifiMgr.isWifiEnabled() && wifiMgr.getDhcpInfo() != null) { DhcpInfo dhcpInfo = wifiMgr.getDhcpInfo(); mNetworkViews.get(NETWORK_WIFI_IP).get(1).setText(Formatter.formatIpAddress(dhcpInfo.ipAddress)); WifiInfo wifiInfo = wifiMgr.getConnectionInfo(); mNetworkViews.get(NETWORK_WIFI_SPEED).get(1).setText(String.valueOf(wifiInfo.getLinkSpeed())); int numberOfLevels = 10; int level = WifiManager.calculateSignalLevel(wifiInfo.getRssi(), numberOfLevels + 1); mNetworkViews.get(NETWORK_WIFI_SIGNAL).get(1) .setText(String.format("%%%d", 100 * level / numberOfLevels)); } } catch (Exception ex) { m_log.e(ex.getMessage()); } try { // ----- Network Traffic----- // int uid = android.os.Process.myUid(); mNetworkViews.get(NETWORK_RCV_BYTES).get(1).setText(String.format("%d", consoleState.netRxBytes)); mNetworkViews.get(NETWORK_RCV_PACK).get(1).setText(String.format("%d", consoleState.netRxPacks)); mNetworkViews.get(NETWORK_SND_BYTES).get(1).setText(String.format("%d", consoleState.netTxBytes)); mNetworkViews.get(NETWORK_SND_PACK).get(1).setText(String.format("%d", consoleState.netTxPacks)); mNetworkViews.get(NETWORK_RCV_BYTES).get(2) .setText(String.format("%d", TrafficStats.getTotalRxBytes())); mNetworkViews.get(NETWORK_RCV_PACK).get(2) .setText(String.format("%d", TrafficStats.getTotalRxPackets())); mNetworkViews.get(NETWORK_SND_BYTES).get(2) .setText(String.format("%d", TrafficStats.getTotalTxBytes())); mNetworkViews.get(NETWORK_SND_PACK).get(2) .setText(String.format("%d", TrafficStats.getTotalRxPackets())); mNetworkViews.get(NETWORK_RCV_BYTES).get(3) .setText(String.format("%d", TrafficStats.getTotalRxBytes() - consoleState.netRxBytes)); mNetworkViews.get(NETWORK_RCV_PACK).get(3) .setText(String.format("%d", TrafficStats.getTotalRxPackets() - consoleState.netRxPacks)); mNetworkViews.get(NETWORK_SND_BYTES).get(3) .setText(String.format("%d", TrafficStats.getTotalTxBytes() - consoleState.netTxBytes)); mNetworkViews.get(NETWORK_SND_PACK).get(3) .setText(String.format("%d", TrafficStats.getTotalRxPackets() - consoleState.netTxPacks)); } catch (Exception ex) { m_log.e(ex.getMessage()); } // ----- Memory ----- try { MemoryInfo mi = new MemoryInfo(); ActivityManager activityManager = (ActivityManager) getActivity() .getSystemService(Context.ACTIVITY_SERVICE); activityManager.getMemoryInfo(mi); long heapUsing = Debug.getNativeHeapSize(); Date now = new Date(); long deltaMsec = now.getTime() - consoleState.lastFreeze.getTime(); List<TextView> timeViews = mMemoryViews.get(MEMORY_TIME); timeViews.get(1).setText(TIMEFORMAT.format(consoleState.lastFreeze)); timeViews.get(2).setText(TIMEFORMAT.format(now)); timeViews.get(3).setText( DateUtils.getRelativeTimeSpanString(consoleState.lastFreeze.getTime(), now.getTime(), 0)); // timeViews.get(3).setText( String.valueOf(deltaMsec)); List<TextView> usingViews = mMemoryViews.get(MEMORY_USING); usingViews.get(1).setText(String.format("%d", consoleState.usingMemory)); usingViews.get(2).setText(String.format("%d", heapUsing)); usingViews.get(3).setText(String.format("%d", heapUsing - consoleState.usingMemory)); List<TextView> freeViews = mMemoryViews.get(MEMORY_FREE); freeViews.get(1).setText(String.format("%d", consoleState.freeMemory)); freeViews.get(2).setText(String.format("%d", mi.availMem)); freeViews.get(3).setText(String.format("%d", mi.availMem - consoleState.freeMemory)); List<TextView> totalViews = mMemoryViews.get(MEMORY_TOTAL); if (Build.VERSION.SDK_INT >= 16) { totalViews.get(1).setText(String.format("%d", consoleState.totalMemory)); totalViews.get(2).setText(String.format("%d", mi.totalMem)); totalViews.get(3).setText(String.format("%d", mi.totalMem - consoleState.totalMemory)); } else { totalViews.get(0).setVisibility(View.GONE); totalViews.get(1).setVisibility(View.GONE); totalViews.get(2).setVisibility(View.GONE); } } catch (Exception ex) { m_log.e(ex.getMessage()); } }
From source file:com.matthewmitchell.peercoin_android_wallet.ui.WalletActivity.java
private Dialog createRestoreWalletDialog() { final View view = getLayoutInflater().inflate(R.layout.restore_wallet_dialog, null); final Spinner fileView = (Spinner) view.findViewById(R.id.import_keys_from_storage_file); final EditText passwordView = (EditText) view.findViewById(R.id.import_keys_from_storage_password); final DialogBuilder dialog = new DialogBuilder(this); dialog.setTitle(R.string.import_keys_dialog_title); dialog.setView(view);//from w w w . ja v a 2 s .com dialog.setPositiveButton(R.string.import_keys_dialog_button_import, new OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { final File file = (File) fileView.getSelectedItem(); final String password = passwordView.getText().toString().trim(); passwordView.setText(null); // get rid of it asap if (WalletUtils.BACKUP_FILE_FILTER.accept(file)) restoreWalletFromProtobuf(file, CloseAction.CLOSE_RECREATE); else if (WalletUtils.KEYS_FILE_FILTER.accept(file)) restorePrivateKeysFromBase58(file, CloseAction.CLOSE_RECREATE); else if (Crypto.OPENSSL_FILE_FILTER.accept(file)) restoreWalletFromEncrypted(file, password, CloseAction.CLOSE_RECREATE); } }); dialog.setNegativeButton(R.string.button_cancel, new OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { passwordView.setText(null); // get rid of it asap } }); dialog.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(final DialogInterface dialog) { passwordView.setText(null); // get rid of it asap } }); final FileAdapter adapter = new FileAdapter(this) { @Override public View getDropDownView(final int position, View row, final ViewGroup parent) { final File file = getItem(position); final boolean isExternal = Constants.Files.EXTERNAL_WALLET_BACKUP_DIR.equals(file.getParentFile()); final boolean isEncrypted = Crypto.OPENSSL_FILE_FILTER.accept(file); if (row == null) row = inflater.inflate(R.layout.restore_wallet_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; } }; fileView.setAdapter(adapter); return dialog.create(); }
From source file:de.schildbach.wallet.ui.WalletActivity.java
private Dialog createRestoreWalletDialog() { final View view = getLayoutInflater().inflate(R.layout.restore_wallet_dialog, null); final Spinner fileView = (Spinner) view.findViewById(R.id.import_keys_from_storage_file); final EditText passwordView = (EditText) view.findViewById(R.id.import_keys_from_storage_password); final DialogBuilder dialog = new DialogBuilder(this); dialog.setTitle(R.string.import_keys_dialog_title); dialog.setView(view);//from www . j av a 2 s . c o m dialog.setPositiveButton(R.string.import_keys_dialog_button_import, new OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { final File file = (File) fileView.getSelectedItem(); final String password = passwordView.getText().toString().trim(); passwordView.setText(null); // get rid of it asap if (WalletUtils.BACKUP_FILE_FILTER.accept(file)) restoreWalletFromProtobuf(file); else if (WalletUtils.KEYS_FILE_FILTER.accept(file)) restorePrivateKeysFromBase58(file); else if (Crypto.OPENSSL_FILE_FILTER.accept(file)) restoreWalletFromEncrypted(file, password); } }); dialog.setNegativeButton(R.string.button_cancel, new OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { passwordView.setText(null); // get rid of it asap } }); dialog.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(final DialogInterface dialog) { passwordView.setText(null); // get rid of it asap } }); fileView.setAdapter(new FileAdapter(this) { @Override public View getDropDownView(final int position, View row, final ViewGroup parent) { final File file = getItem(position); final boolean isExternal = Constants.Files.EXTERNAL_WALLET_BACKUP_DIR.equals(file.getParentFile()); final boolean isEncrypted = Crypto.OPENSSL_FILE_FILTER.accept(file); if (row == null) row = inflater.inflate(R.layout.restore_wallet_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; } }); return dialog.create(); }
From source file:io.plaidapp.designernews.ui.story.StoryActivity.java
private CharSequence getStoryPosterTimeText(String userDisplayName, String userJob, Date createdAt) { SpannableString poster = new SpannableString(userDisplayName.toLowerCase()); poster.setSpan(new TextAppearanceSpan(this, io.plaidapp.R.style.TextAppearance_CommentAuthor), 0, poster.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); CharSequence job = !TextUtils.isEmpty(userJob) ? "\n" + userJob.toLowerCase() : ""; CharSequence timeAgo = DateUtils.getRelativeTimeSpanString(createdAt.getTime(), System.currentTimeMillis(), DateUtils.SECOND_IN_MILLIS).toString().toLowerCase(); return TextUtils.concat(poster, job, "\n", timeAgo); }