use of android.icu.text.SimpleDateFormat in project platform_frameworks_base by android.
the class SimpleMonthView method updateMonthYearLabel.
private void updateMonthYearLabel() {
final String format = DateFormat.getBestDateTimePattern(mLocale, MONTH_YEAR_FORMAT);
final SimpleDateFormat formatter = new SimpleDateFormat(format, mLocale);
formatter.setContext(DisplayContext.CAPITALIZATION_FOR_STANDALONE);
mMonthYearLabel = formatter.format(mCalendar.getTime());
}
use of android.icu.text.SimpleDateFormat in project android_frameworks_base by crdroidandroid.
the class SimpleMonthView method updateMonthYearLabel.
private void updateMonthYearLabel() {
final String format = DateFormat.getBestDateTimePattern(mLocale, MONTH_YEAR_FORMAT);
final SimpleDateFormat formatter = new SimpleDateFormat(format, mLocale);
formatter.setContext(DisplayContext.CAPITALIZATION_FOR_STANDALONE);
mMonthYearLabel = formatter.format(mCalendar.getTime());
}
use of android.icu.text.SimpleDateFormat in project android_frameworks_base by crdroidandroid.
the class DatePickerCalendarDelegate method onPopulateAccessibilityEvent.
@Override
public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
if (mAccessibilityEventFormat == null) {
final String pattern = DateFormat.getBestDateTimePattern(mCurrentLocale, "EMMMMdy");
mAccessibilityEventFormat = new SimpleDateFormat(pattern);
}
final CharSequence text = mAccessibilityEventFormat.format(mCurrentDate.getTime());
event.getText().add(text);
}
use of android.icu.text.SimpleDateFormat in project android_frameworks_base by AOSPA.
the class SimpleMonthView method updateMonthYearLabel.
private void updateMonthYearLabel() {
final String format = DateFormat.getBestDateTimePattern(mLocale, MONTH_YEAR_FORMAT);
final SimpleDateFormat formatter = new SimpleDateFormat(format, mLocale);
formatter.setContext(DisplayContext.CAPITALIZATION_FOR_STANDALONE);
mMonthYearLabel = formatter.format(mCalendar.getTime());
}
use of android.icu.text.SimpleDateFormat in project WhatsappExtensions by suraj0208.
the class StatsActivity method getMessagesTimeSpan.
private void getMessagesTimeSpan(final TextView textview, final String jid) {
(new AsyncTask<Void, Void, Long[]>() {
@TargetApi(Build.VERSION_CODES.N)
@Override
protected Long[] doInBackground(Void... voids) {
String[] arr = WhatsAppDatabaseHelper.execSQL("/data/data/com.whatsapp/databases/msgstore.db", "select timestamp from messages where key_remote_jid like " + '"' + jid + '"' + " and length(data) > 0 order by timestamp;");
Calendar c = Calendar.getInstance(Locale.getDefault());
ArrayList<Integer> medianList = new ArrayList<>();
TreeMap<ContributionCalendarDate, Integer> currentTreeMap = null;
String prevMonthYearName = null;
ContributionCalendarDate prevDate = null;
if (arr != null) {
Long[] timestampsFromDatabase = new Long[arr.length];
for (int i = 0; i < arr.length; i++) {
timestampsFromDatabase[i] = Long.parseLong(arr[i]);
c.setTime(new Date(timestampsFromDatabase[i]));
String monthYearName = new SimpleDateFormat("MMM yyyy").format(c.getTime());
ContributionCalendarDate currentDate = new ContributionCalendarDate(timestampsFromDatabase[i]);
availableMonths.put(monthYearName, new MonthYearPair(c.get(Calendar.MONTH) + 1, c.get(Calendar.YEAR)));
currentTreeMap = dateStringTreeMapHashMap.get(monthYearName);
if (currentTreeMap == null) {
if (i != 0) {
Collections.sort(medianList);
int intervalStart = medianList.size() / 3;
int intervalEnd = intervalStart + intervalStart;
if (medianList.size() > 0 && intervalEnd >= medianList.size() - 1) {
dateStringMedianPairHashMap.put(prevMonthYearName, new DistributionPair(medianList.get(intervalStart), medianList.get(medianList.size() - 1), medianList.get(medianList.size() - 1) + 1));
} else if (medianList.size() > 0)
dateStringMedianPairHashMap.put(prevMonthYearName, new DistributionPair(medianList.get(intervalStart), medianList.get(intervalEnd), medianList.get(medianList.size() - 1)));
else {
dateStringMedianPairHashMap.put(prevMonthYearName, new DistributionPair(1, 1, 1));
}
medianList.clear();
}
currentTreeMap = new TreeMap<>();
currentTreeMap.put(currentDate, 1);
dateStringTreeMapHashMap.put(monthYearName, currentTreeMap);
} else {
Integer current = currentTreeMap.get(currentDate);
if (current == null) {
currentTreeMap.put(currentDate, 1);
medianList.add(currentTreeMap.get(prevDate));
} else
currentTreeMap.put(currentDate, current + 1);
}
prevMonthYearName = monthYearName;
prevDate = currentDate;
}
medianList.add(currentTreeMap.get(prevDate));
Collections.sort(medianList);
int intervalStart = medianList.size() / 3;
int intervalEnd = intervalStart + intervalStart;
if (intervalEnd >= medianList.size() - 1) {
dateStringMedianPairHashMap.put(prevMonthYearName, new DistributionPair(medianList.get(intervalStart), medianList.get(medianList.size() - 1), medianList.get(medianList.size() - 1) + 1));
} else
dateStringMedianPairHashMap.put(prevMonthYearName, new DistributionPair(medianList.get(intervalStart), medianList.get(intervalEnd), medianList.get(medianList.size() - 1)));
ArrayList<HashMap.Entry<String, MonthYearPair>> entries = new ArrayList<>(availableMonths.entrySet());
Collections.sort(entries, new Comparator<HashMap.Entry<String, MonthYearPair>>() {
@Override
public int compare(HashMap.Entry<String, MonthYearPair> left, HashMap.Entry<String, MonthYearPair> right) {
String thisDate = left.getValue().year + "/" + (Integer.toString(left.getValue().month).length() < 2 ? "0" + left.getValue().month : left.getValue().month);
String otherDate = right.getValue().year + "/" + (Integer.toString(right.getValue().month).length() < 2 ? "0" + right.getValue().month : right.getValue().month);
return thisDate.compareTo(otherDate);
}
});
for (Map.Entry<String, MonthYearPair> entry : entries) spinnerData.add(entry.getKey());
return timestampsFromDatabase;
}
return null;
}
@TargetApi(Build.VERSION_CODES.N)
@Override
protected void onPostExecute(Long[] s) {
super.onPostExecute(s);
if (s == null) {
return;
}
if (s.length == 0)
return;
String first;
String second;
try {
first = getDateFromTimeStamp(s[0]);
second = getDateFromTimeStamp(s[s.length - 1]);
textview.setText(getResources().getString(R.string.messagesTimespan, first, second));
String monthYearName = new SimpleDateFormat("MMM yyyy").format(s[0]);
ArrayAdapter<String> adapter = new ArrayAdapter<>(StatsActivity.this, android.R.layout.simple_spinner_dropdown_item, spinnerData);
spinMonths.setAdapter(adapter);
spinMonths.setVisibility(View.VISIBLE);
displayContributionCalendar(monthYearName);
spinMonths.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
displayContributionCalendar(spinMonths.getItemAtPosition(i).toString());
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
imgViewActivities[0].setBackgroundColor(Color.parseColor(contributionCalendarView.getLowColor()));
imgViewActivities[1].setBackgroundColor(Color.parseColor(contributionCalendarView.getMediumColor()));
imgViewActivities[2].setBackgroundColor(Color.parseColor(contributionCalendarView.getHighColor()));
} catch (NumberFormatException | ArrayIndexOutOfBoundsException ex) {
ex.printStackTrace();
}
}
}).execute();
}
Aggregations