List of usage examples for android.text.format DateFormat getLongDateFormat
public static java.text.DateFormat getLongDateFormat(Context context)
From source file:Main.java
/** * Returns the given timestamp formatted as date and time for the default locale. * @param context context// w ww . j a va2 s. co m * @param timestamp timestamp to format * @return String timestamp formatted as date and time */ public static String getDateTimeString(final Context context, final long timestamp) { Date date = new Date(timestamp); String dateString = DateFormat.getLongDateFormat(context).format(date); String timeString = DateFormat.getTimeFormat(context).format(date); return String.format("%s %s", dateString, timeString); }
From source file:com.koushikdutta.superuser.PolicyFragmentInternal.java
void addPolicy(final UidPolicy up, final int last) { java.text.DateFormat df = DateFormat.getLongDateFormat(getActivity()); String date;/*from www.ja va2s. co m*/ if (last == 0) date = null; else date = df.format(getLastDate(last)); ListItem li = addItem(up.getPolicyResource(), new ListItem(this, up.name, date) { public void onClick(View view) { super.onClick(view); setContent(this, up); }; }); Drawable icon = Helper.loadPackageIcon(getActivity(), up.packageName); if (icon == null) li.setIcon(R.drawable.ic_launcher); else li.setDrawable(icon); }
From source file:in.andres.kandroid.ui.ProjectOverviewFragment.java
@Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); KanboardProject project = ((MainActivity) getActivity()).getProject(); if (project != null) { assert getView() != null : "ProjectOverviewFragment: getView() returned null"; TextView projectDescription = (TextView) getView().findViewById(R.id.project_description); TextView projectNBActiveTasks = (TextView) getView().findViewById(R.id.project_active_tasks); TextView projectNBInactiveTasks = (TextView) getView().findViewById(R.id.project_inactive_tasks); TextView projectNBOverdueTasks = (TextView) getView().findViewById(R.id.project_overdue_tasks); TextView projectNBTotalTasks = (TextView) getView().findViewById(R.id.project_total_tasks); TextView projectModifyDate = (TextView) getView().findViewById(R.id.project_modify_date); TextView projectMembers = (TextView) getView().findViewById(R.id.project_members); TextView projectColumns = (TextView) getView().findViewById(R.id.project_columns); TextView projectSwimlanes = (TextView) getView().findViewById(R.id.project_swimlanes); if (!project.getDescription().contentEquals("")) { projectDescription//from w w w . ja v a 2 s .co m .setText(Utils.fromHtml(mRenderer.render(mParser.parse(project.getDescription())))); } else { getView().findViewById(R.id.card_description).setVisibility(View.GONE); } projectMembers.setText(Utils.fromHtml(TextUtils.join(" <big><b>|</b></big> ", Collections.list(project.getProjectUsers().elements())))); projectColumns.setText(Utils.fromHtml(TextUtils.join(" <big><b>|</b></big> ", project.getColumns()))); projectSwimlanes .setText(Utils.fromHtml(TextUtils.join(" <big><b>|</b></big> ", project.getSwimlanes()))); projectNBActiveTasks .setText(getContext().getResources().getQuantityString(R.plurals.format_nb_active_tasks, project.getActiveTasks().size(), project.getActiveTasks().size())); projectNBInactiveTasks .setText(getContext().getResources().getQuantityString(R.plurals.format_nb_inactive_tasks, project.getInactiveTasks().size(), project.getInactiveTasks().size())); projectNBOverdueTasks .setText(getContext().getResources().getQuantityString(R.plurals.format_nb_overdue_tasks, project.getOverdueTasks().size(), project.getOverdueTasks().size())); projectNBTotalTasks .setText(getContext().getResources().getQuantityString(R.plurals.format_nb_total_tasks, project.getActiveTasks().size() + project.getInactiveTasks().size(), project.getActiveTasks().size() + project.getInactiveTasks().size())); projectModifyDate.setText(DateFormat.getLongDateFormat(getContext()).format(project.getLastModified()) + " " + DateFormat.getTimeFormat(getContext()).format(project.getLastModified())); } }
From source file:com.activiti.android.ui.fragments.process.create.StartSimpleFormDialogFragment.java
private String createDefaultName() { StringBuilder defaultName = new StringBuilder(processDefinitionName); defaultName.append(" - "); defaultName.append(DateFormat.getLongDateFormat(getActivity()).format(new Date())); return defaultName.toString(); }
From source file:com.hyperaware.conference.android.fragment.HomeFragment.java
private void updateBeforeAndAfterEvent() { final TimeZone tz = TimeZone.getTimeZone(event.getTimezoneName()); final Calendar now_day = startOfDay(timeAtUpdate, tz); vBeforeEvent.setVisibility(View.GONE); vAfterEvent.setVisibility(View.GONE); tvDescription.setVisibility(View.GONE); final ArrayList<AgendaItem> items = new ArrayList<>(agenda.getItems().values()); if (items.size() > 0) { Collections.sort(items, AgendaItems.START_TIME_COMPARATOR); final AgendaItem first = items.get(0); Calendar first_day = startOfDay(TimeUnit.SECONDS.toMillis(first.getEpochStartTime()), tz); final AgendaItem last = items.get(items.size() - 1); long end_time = TimeUnit.SECONDS.toMillis(last.getEpochEndTime()); if (now_day.getTimeInMillis() < first_day.getTimeInMillis()) { final TextView msg = (TextView) vBeforeEvent.findViewById(R.id.tv_message); final java.text.DateFormat dfmt = DateFormat.getLongDateFormat(getContext()); dfmt.setTimeZone(tz);// ww w . j a va2s. c o m msg.setText(getString(R.string.fmt_message_before_event, dfmt.format(first_day.getTimeInMillis()))); vBeforeEvent.setVisibility(View.VISIBLE); tvDescription.setVisibility(View.VISIBLE); tvDescription.setText(event.getDescription()); } else if (timeAtUpdate > end_time) { final TextView msg = (TextView) vAfterEvent.findViewById(R.id.tv_message); final java.text.DateFormat dfmt = DateFormat.getLongDateFormat(getContext()); dfmt.setTimeZone(tz); msg.setText(getString(R.string.fmt_message_after_event, dfmt.format(end_time))); vAfterEvent.setVisibility(View.VISIBLE); tvDescription.setVisibility(View.VISIBLE); tvDescription.setText(event.getDescription()); } } }
From source file:com.mattprecious.smsfix.library.FixOld.java
private void updateButtons() { startDateButton.setText(DateFormat.getLongDateFormat(this).format(startCalendar.getTime())); startTimeButton.setText(DateFormat.getTimeFormat(this).format(startCalendar.getTime())); endDateButton.setText(DateFormat.getLongDateFormat(this).format(endCalendar.getTime())); endTimeButton.setText(DateFormat.getTimeFormat(this).format(endCalendar.getTime())); signButton.setText(offset >= 0 ? R.string.fix_old_add : R.string.fix_old_subtract); DecimalFormat df = new DecimalFormat("#.###"); offsetButton.setText(getString(R.string.fix_old_offset_hours, df.format(Math.abs(offset) / 3600000.0))); if (!startCalendar.before(endCalendar)) { goButton.setEnabled(false);/* www . j a va2 s .c o m*/ goButton.setText(R.string.fix_old_invalid_dates); } else if (offset == 0) { goButton.setEnabled(false); goButton.setText(R.string.fix_old_invalid_offset); } else { goButton.setEnabled(true); goButton.setText(R.string.fix_old_go); } if (type == Type.SMS) { typeButton.setText("SMS"); } else { typeButton.setText("MMS"); } }
From source file:com.jetheis.android.makeitrain.billing.googleplay.GooglePlayBillingWrapper.java
public void handleJsonResponse(String response, String signature) { Log.v(Constants.TAG, "Handling JSON response: " + response); if (!GooglePlayBillingSecurity.isCorrectSignature(response, signature)) { Log.e(Constants.TAG, "Bad Google Play signature! Possible security breach!"); return;/*from ww w . java 2 s.c o m*/ } JSONObject responseJson; try { responseJson = new JSONObject(response); long nonce = responseJson.getLong(Constants.GOOGLE_PLAY_JSON_KEY_NONCE); if (!GooglePlayBillingSecurity.isNonceKnown(nonce)) { Log.e(Constants.TAG, "Bad Google Play nonce! Possible security breach!"); return; } Log.v(Constants.TAG, "Signature and nonce OK"); JSONArray orders = responseJson.getJSONArray(Constants.GOOGLE_PLAY_JSON_KEY_ORDERS); if (orders.length() == 0) { Log.v(Constants.TAG, "No orders present in response"); return; } List<String> notificationIds = new ArrayList<String>(orders.length()); for (int i = 0; i < orders.length(); i++) { JSONObject order = orders.getJSONObject(i); String packageName = order.getString(Constants.GOOGLE_PLAY_JSON_KEY_PACKAGE_NAME); if (!packageName.equals(mContext.getPackageName())) { Log.e(Constants.TAG, "Bad Google Play package name! Possible security breach!"); return; } Log.v(Constants.TAG, "Package name OK"); if (order.has(Constants.GOOGLE_PLAY_JSON_KEY_NOTIFICATION_ID)) { notificationIds.add(order.getString(Constants.GOOGLE_PLAY_JSON_KEY_NOTIFICATION_ID)); } String productId = order.getString(Constants.GOOGLE_PLAY_JSON_KEY_PRODUCT_ID); Date purchaseDate = new Date(order.getLong(Constants.GOOGLE_PLAY_JSON_KEY_PURCHASE_TIME)); GooglePlayPurchaseState purchaseState = GooglePlayPurchaseState .fromInt(order.getInt(Constants.GOOGLE_PLAY_JSON_KEY_PURCHASE_STATE)); if (purchaseState == GooglePlayPurchaseState.PURCHASED) { Log.i(Constants.TAG, "Found record of purchase of " + productId + " from " + DateFormat.getLongDateFormat(mContext).format(purchaseDate)); if (productId.equals(Constants.GOOGLE_PLAY_PRODUCT_ID)) { if (mOnPurchaseListnener != null) { mOnPurchaseListnener.onGooglePlayVipModePurchaseFound(); } } else { Log.e(Constants.TAG, "Product id " + productId + " not recognized"); } } else if (purchaseState == GooglePlayPurchaseState.CANCELLED) { Log.i(Constants.TAG, "User cancelled purchase"); } else { Log.e(Constants.TAG, "Google Play refund attempted: unsupported"); } } if (notificationIds.size() > 0) { sendNotificationConformation(notificationIds.toArray(new String[notificationIds.size()])); } } catch (JSONException e) { Log.e(Constants.TAG, "JSONException: " + e.getLocalizedMessage()); } }
From source file:com.jetheis.android.grades.billing.googleplay.GooglePlayBillingWrapper.java
public void handleJsonResponse(String response, String signature) { Log.v(Constants.TAG, "Handling JSON response: " + response); if (!Security.isCorrectSignature(response, signature)) { Log.e(Constants.TAG, "Bad Google Play signature! Possible security breach!"); return;// ww w . j a v a 2 s .c o m } JSONObject responseJson; try { responseJson = new JSONObject(response); long nonce = responseJson.getLong(GooglePlayBillingConstants.GOOGLE_PLAY_JSON_KEY_NONCE); if (!Security.isNonceKnown(nonce)) { Log.e(Constants.TAG, "Bad Google Play nonce! Possible security breach!"); return; } Log.v(Constants.TAG, "Signature and nonce OK"); JSONArray orders = responseJson.getJSONArray(GooglePlayBillingConstants.GOOGLE_PLAY_JSON_KEY_ORDERS); if (orders.length() == 0) { Log.v(Constants.TAG, "No orders present in response"); return; } List<String> notificationIds = new ArrayList<String>(orders.length()); for (int i = 0; i < orders.length(); i++) { JSONObject order = orders.getJSONObject(i); String packageName = order.getString(GooglePlayBillingConstants.GOOGLE_PLAY_JSON_KEY_PACKAGE_NAME); if (!packageName.equals(mContext.getPackageName())) { Log.e(Constants.TAG, "Bad Google Play package name! Possible security breach!"); return; } Log.v(Constants.TAG, "Package name OK"); if (order.has(GooglePlayBillingConstants.GOOGLE_PLAY_JSON_KEY_NOTIFICATION_ID)) { notificationIds .add(order.getString(GooglePlayBillingConstants.GOOGLE_PLAY_JSON_KEY_NOTIFICATION_ID)); } String productId = order.getString(GooglePlayBillingConstants.GOOGLE_PLAY_JSON_KEY_PRODUCT_ID); Date purchaseDate = new Date( order.getLong(GooglePlayBillingConstants.GOOGLE_PLAY_JSON_KEY_PURCHASE_TIME)); GooglePlayPurchaseState purchaseState = GooglePlayPurchaseState .fromInt(order.getInt(GooglePlayBillingConstants.GOOGLE_PLAY_JSON_KEY_PURCHASE_STATE)); if (purchaseState == GooglePlayPurchaseState.PURCHASED) { Log.i(Constants.TAG, "Found record of purchase of " + productId + " from " + DateFormat.getLongDateFormat(mContext).format(purchaseDate)); Security.setFullVersionUnlocked(true, mContext); for (OnPurchaseStateChangedListener listener : mOnPurchaseStateChangedListeners) { listener.onPurchaseSuccessful(productId); } } else if (purchaseState == GooglePlayPurchaseState.CANCELLED) { Log.i(Constants.TAG, "User cancelled purchase"); for (OnPurchaseStateChangedListener listener : mOnPurchaseStateChangedListeners) { listener.onPurchaseCancelled(productId); } } else { Log.e(Constants.TAG, "Google Play purchase refunded"); Security.setFullVersionUnlocked(false, mContext); for (OnPurchaseStateChangedListener listener : mOnPurchaseStateChangedListeners) { listener.onPurchaseReturned(productId); } } } if (notificationIds.size() > 0) { sendNotificationConformation(notificationIds.toArray(new String[notificationIds.size()])); } } catch (JSONException e) { Log.e(Constants.TAG, "JSONException: " + e.getLocalizedMessage()); } }
From source file:org.alfresco.mobile.android.application.fragments.workflow.task.TaskDetailsFragment.java
private void initHeader() { // PRIORITY//from www . java 2 s . c o m ImageView icon = (ImageView) vRoot.findViewById(R.id.task_priority_icon); TextView textValue = (TextView) vRoot.findViewById(R.id.task_priority); icon.setImageDrawable(getResources().getDrawable(TasksFoundationAdapter.getPriorityIconId(priority))); int labelId = R.string.workflow_priority_medium; switch (priority) { case WorkflowModel.PRIORITY_HIGH: labelId = R.string.workflow_priority_high; break; case WorkflowModel.PRIORITY_MEDIUM: labelId = R.string.workflow_priority_medium; break; case WorkflowModel.PRIORITY_LOW: labelId = R.string.workflow_priority_low; break; default: break; } textValue.setText(labelId); // TASK TYPE textValue = (TextView) vRoot.findViewById(R.id.task_type); textValue.setText(type); // DUE DATE StringBuilder builder = new StringBuilder(); if (dueAt != null) { textValue = (TextView) vRoot.findViewById(R.id.task_due_date); if (dueAt.before(new GregorianCalendar())) { builder.append("<b>"); builder.append("<font color='#9F000F'>"); builder.append(DateFormat.getLongDateFormat(getActivity()).format(dueAt.getTime())); builder.append("</font>"); builder.append("</b>"); } else { builder.append(DateFormat.getLongDateFormat(getActivity()).format(dueAt.getTime())); } textValue.setText(builder.toString()); textValue.setText(Html.fromHtml(builder.toString()), TextView.BufferType.SPANNABLE); } else { vRoot.findViewById(R.id.task_due_date_group).setVisibility(View.GONE); vRoot.findViewById(R.id.task_due_date_icon).setVisibility(View.GONE); } }
From source file:com.sweetiepiggy.raspberrybusmalaysia.SubmitTripActivity.java
private void update_date_label(int button_id, Calendar cal) { Button date_button = (Button) findViewById(button_id); String date = translate_day_of_week(DateFormat.format("EEEE", cal.getTime()).toString()) + " " + DateFormat.getLongDateFormat(getApplicationContext()).format(cal.getTime()); date_button.setText(date);//from w w w . j a v a2 s . c o m }