Search in sources :

Example 6 with SimpleDateFormat

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());
}
Also used : SimpleDateFormat(android.icu.text.SimpleDateFormat)

Example 7 with SimpleDateFormat

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());
}
Also used : SimpleDateFormat(android.icu.text.SimpleDateFormat)

Example 8 with SimpleDateFormat

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);
}
Also used : SimpleDateFormat(android.icu.text.SimpleDateFormat)

Example 9 with SimpleDateFormat

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());
}
Also used : SimpleDateFormat(android.icu.text.SimpleDateFormat)

Example 10 with SimpleDateFormat

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();
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Calendar(java.util.Calendar) AsyncTask(android.os.AsyncTask) ImageView(android.widget.ImageView) View(android.view.View) ContributionCalendarView(com.suraj.waext.views.ContributionCalendarView) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) Date(java.util.Date) ContributionCalendarDate(com.suraj.waext.data.ContributionCalendarDate) ContributionCalendarDate(com.suraj.waext.data.ContributionCalendarDate) AdapterView(android.widget.AdapterView) SimpleDateFormat(android.icu.text.SimpleDateFormat) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) ArrayAdapter(android.widget.ArrayAdapter)

Aggregations

SimpleDateFormat (android.icu.text.SimpleDateFormat)153 Test (org.junit.Test)113 Date (java.util.Date)103 GregorianCalendar (android.icu.util.GregorianCalendar)59 Calendar (android.icu.util.Calendar)53 ParseException (java.text.ParseException)42 DateFormat (android.icu.text.DateFormat)41 JapaneseCalendar (android.icu.util.JapaneseCalendar)41 ULocale (android.icu.util.ULocale)40 IslamicCalendar (android.icu.util.IslamicCalendar)37 ParsePosition (java.text.ParsePosition)36 FieldPosition (java.text.FieldPosition)29 ChineseCalendar (android.icu.util.ChineseCalendar)27 TimeZone (android.icu.util.TimeZone)27 BuddhistCalendar (android.icu.util.BuddhistCalendar)25 ChineseDateFormat (android.icu.text.ChineseDateFormat)21 HebrewCalendar (android.icu.util.HebrewCalendar)21 IOException (java.io.IOException)19 SimpleTimeZone (android.icu.util.SimpleTimeZone)16 Locale (java.util.Locale)14