Java Examples for android.text.format.DateFormat

The following java examples will help you to understand the usage of android.text.format.DateFormat. These source code samples are taken from different open source projects.

Example 1
Project: aceim-master  File: MessagesAdapter.java View source code
private void init(MainActivity activity) {
    mDateFormat = android.text.format.DateFormat.getLongDateFormat(activity);
    mTimeFormat = android.text.format.DateFormat.getTimeFormat(activity);
    if (sSmileys == null) {
        sSmileys = Collections.synchronizedSortedMap(new TreeMap<String, Drawable>(activity.getSmileysManager().getManagedSmileys()));
        for (String smiley : new ArrayList<String>(sSmileys.keySet())) {
            if (ViewUtils.isSmileyReadOnly(smiley)) {
                Drawable value = sSmileys.remove(smiley);
                smiley = ViewUtils.escapeOmittableSmiley(smiley);
                sSmileys.put(smiley, value);
            }
        }
        sSmileyBound = (int) (activity.getResources().getDisplayMetrics().density * 10);
    }
}
Example 2
Project: konkamusic-master  File: KkDigitalClock.java View source code
@Override
protected void onAttachedToWindow() {
    // TODO Auto-generated method stub
    //		super.onAttachedToWindow();
    mTickerStopped = false;
    super.onAttachedToWindow();
    mHandler = new Handler();
    /**
	         * requests a tick on the next hard-second boundary
	         */
    mTicker = new Runnable() {

        @Override
        public void run() {
            if (mTickerStopped)
                return;
            mCalendar.setTimeInMillis(System.currentTimeMillis());
            setText(DateFormat.format(mFormat, mCalendar));
            invalidate();
            long now = SystemClock.uptimeMillis();
            long next = now + (1000 - now % 1000);
            mHandler.postAtTime(mTicker, next);
        }
    };
    mTicker.run();
}
Example 3
Project: android-15-master  File: HoloClock.java View source code
private final CharSequence getTimeText() {
    Context context = getContext();
    int res = DateFormat.is24HourFormat(context) ? com.android.internal.R.string.twenty_four_hour_time_format : com.android.internal.R.string.twelve_hour_time_format;
    SimpleDateFormat sdf;
    String format = context.getString(res);
    if (!format.equals(mClockFormatString)) {
        // we don't want AM/PM showing up in our statusbar, even in 12h mode
        format = format.replaceAll("a", "").trim();
        mClockFormat = sdf = new SimpleDateFormat(format);
        mClockFormatString = format;
    } else {
        sdf = mClockFormat;
    }
    String result = sdf.format(mCalendar.getTime());
    return result;
}
Example 4
Project: open-bixi-gpstracker-master  File: DateView.java View source code
/*
    * (non-Javadoc)
    * @see android.widget.TextView#setText(java.lang.CharSequence, android.widget.TextView.BufferType)
    */
@Override
public void setText(CharSequence charSeq, BufferType type) {
    // Behavior for the graphical editor
    if (this.isInEditMode()) {
        super.setText(charSeq, type);
        return;
    }
    long longVal;
    if (charSeq.length() == 0) {
        longVal = 0l;
    } else {
        try {
            longVal = Long.parseLong(charSeq.toString());
        } catch (NumberFormatException e) {
            longVal = 0l;
        }
    }
    this.mDate = new Date(longVal);
    DateFormat dateFormat = android.text.format.DateFormat.getLongDateFormat(this.getContext().getApplicationContext());
    DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(this.getContext().getApplicationContext());
    String text = timeFormat.format(this.mDate) + " " + dateFormat.format(mDate);
    super.setText(text, type);
}
Example 5
Project: property-db-master  File: DateFormat.java View source code
/**
     * Returns true if user preference is set to 24-hour format.
     * @param context the context to use for the content resolver
     * @return true if 24 hour time format is selected, false otherwise.
     */
public static boolean is24HourFormat(Context context) {
    String value = Settings.System.getString(context.getContentResolver(), Settings.System.TIME_12_24);
    if (value == null) {
        Locale locale = context.getResources().getConfiguration().locale;
        synchronized (sLocaleLock) {
            if (sIs24HourLocale != null && sIs24HourLocale.equals(locale)) {
                return sIs24Hour;
            }
        }
        java.text.DateFormat natural = java.text.DateFormat.getTimeInstance(java.text.DateFormat.LONG, locale);
        if (natural instanceof SimpleDateFormat) {
            SimpleDateFormat sdf = (SimpleDateFormat) natural;
            String pattern = sdf.toPattern();
            if (pattern.indexOf('H') >= 0) {
                value = "24";
            } else {
                value = "12";
            }
        } else {
            value = "12";
        }
        synchronized (sLocaleLock) {
            sIs24HourLocale = locale;
            sIs24Hour = value.equals("24");
        }
        return sIs24Hour;
    }
    return value.equals("24");
}
Example 6
Project: WS171-frameworks-base-master  File: WebkitTest.java View source code
@MediumTest
public void testDateSorter() throws Exception {
    /**
         * Note: check the logging output manually to test
         * nothing automated yet, besides object creation
         */
    DateSorter dateSorter = new DateSorter(mContext);
    Date date = new Date();
    for (int i = 0; i < DateSorter.DAY_COUNT; i++) {
        Log.i(LOGTAG, "Boundary " + i + " " + dateSorter.getBoundary(i));
        Log.i(LOGTAG, "Label " + i + " " + dateSorter.getLabel(i));
    }
    Calendar c = Calendar.getInstance();
    long time = c.getTimeInMillis();
    int index;
    Log.i(LOGTAG, "now: " + dateSorter.getIndex(time));
    for (int i = 0; i < 20; i++) {
        // 8 hours
        time -= 8 * 60 * 60 * 1000;
        date.setTime(time);
        c.setTime(date);
        index = dateSorter.getIndex(time);
        Log.i(LOGTAG, "time: " + DateFormat.format("yyyy/MM/dd kk:mm:ss", c).toString() + " " + index + " " + dateSorter.getLabel(index));
    }
}
Example 7
Project: AppCompat-Extension-Library-master  File: DateFormatUtils.java View source code
public static String getBestDateTimePattern(Locale locale, String skeleton) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        return DateFormat.getBestDateTimePattern(locale, skeleton);
    } else {
        // Try to improve the skeleton on older devices
        if (skeleton.equals("EMMMd"))
            return "E, MMM d";
        if (skeleton.equals("MMMMy"))
            return "MMMM yyyy";
        if (skeleton.equals("Hm"))
            return "H:m";
        if (skeleton.equals("hm"))
            return "h:m";
        return skeleton;
    }
}
Example 8
Project: enviroCar-app-master  File: DateUtils.java View source code
public static String getDateString(Context context, long date) {
    Calendar now = Calendar.getInstance();
    now.setTimeZone(TimeZone.getDefault());
    Calendar time = Calendar.getInstance();
    time.setTimeZone(TimeZone.getDefault());
    time.setTimeInMillis(date);
    if (now.get(Calendar.DATE) == time.get(Calendar.DATE)) {
        return context.getString(R.string.today);
    } else if (now.get(Calendar.DATE) - time.get(Calendar.DATE) == 1) {
        return context.getString(R.string.yesterday);
    } else {
        return DateFormat.format("EE, MM yyyy", time).toString();
    //            return DateFormat.format("MMMM dd yyyy, h:mm aa", time).toString();
    }
}
Example 9
Project: arduino-android-master  File: InputController.java View source code
public void handleGeigerMessage(char flag, int reading) {
    Log.d("SRM", "setTemp " + reading);
    if (flag == 'E') {
        mRadiationImage.setVisibility(ImageView.VISIBLE);
        mp.start();
    } else if (flag == 'R') {
        mRadiationImage.setVisibility(ImageView.INVISIBLE);
        mTemperature.setText("" + reading);
    } else if (flag == 'L') {
        String logText = mLogView.getText().toString();
        String timeFormatted = (String) DateFormat.format("hh:mm", new Date());
        mLogView.setText(logText + "\n" + timeFormatted + "\t\t\t" + reading);
    }
}
Example 10
Project: ijoomer-adv-sdk-master  File: IjoomerDataPickerView.java View source code
@Override
public void onDateChanged(final DatePicker view, final int year, final int month, final int day) {
    if (this.isBithDate) {
        Calendar c = Calendar.getInstance();
        c.set(year, month, day);
        c.add(Calendar.YEAR, 18);
        if (c.get(Calendar.YEAR) > (Calendar.getInstance().get(Calendar.YEAR))) {
            view.init(IjoomerDataPickerView.this.year, IjoomerDataPickerView.this.month, IjoomerDataPickerView.this.day, IjoomerDataPickerView.this);
            Calendar calendar = Calendar.getInstance();
            calendar.set(IjoomerDataPickerView.this.year, IjoomerDataPickerView.this.month, IjoomerDataPickerView.this.day);
            setTitle(DateFormat.format(format, calendar));
        } else {
            this.year = year;
            this.month = month;
            this.day = day;
            view.init(year, month, day, IjoomerDataPickerView.this);
            Calendar calendar = Calendar.getInstance();
            calendar.set(year, month, day);
            setTitle(DateFormat.format(format, calendar));
        }
    }
}
Example 11
Project: jdroid-master  File: TimePickerDialogFragment.java View source code
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity());
    View view = inflate(R.layout.jdroid_time_picker_dialog_fragment);
    dialogBuilder.setView(view);
    final TimePicker timePicker = (TimePicker) view.findViewById(R.id.timePicker);
    timePicker.setIs24HourView(DateFormat.is24HourFormat(getActivity()));
    timePicker.setCurrentHour(DateUtils.getHour(defaultTime, true));
    timePicker.setCurrentMinute(DateUtils.getMinute(defaultTime));
    dialogBuilder.setPositiveButton(getString(R.string.jdroid_ok), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int whichButton) {
            Date time = DateUtils.getTime(timePicker.getCurrentHour(), timePicker.getCurrentMinute());
            int requestCode = getTargetRequestCode();
            ((OnTimeSetListener) getTargetFragment()).onTimeSet(time, requestCode);
        }
    });
    dialogBuilder.setNegativeButton(getString(R.string.jdroid_cancel), null);
    return dialogBuilder.create();
}
Example 12
Project: apteryx-master  File: TextFormat.java View source code
public static String formatDateSmart(Context context, long time) {
    Calendar current = Calendar.getInstance();
    Calendar date = Calendar.getInstance();
    date.setTimeInMillis(time);
    int dayToday = current.get(Calendar.DAY_OF_YEAR);
    int day = date.get(Calendar.DAY_OF_YEAR);
    if (day == dayToday)
        return DateFormat.format("kk:mm", time).toString();
    StringBuilder result = new StringBuilder();
    if (dayToday - day == 1)
        result.append(context.getString(R.string.yesterday));
    else if (dayToday - day == -1)
        result.append(context.getString(R.string.tomorrow));
    else {
        if (current.get(Calendar.YEAR) == date.get(Calendar.YEAR))
            result.append("dd MMM");
        else
            result.append("dd MMM yyyy");
    }
    result.append(" kk:mm");
    return DateFormat.format(result.toString(), time).toString();
}
Example 13
Project: btpka3.github.com-master  File: MyTimeIntentService.java View source code
private void handleActionTime(int time) {
    Log.d(TAG, "-------------- handleActionTime : " + time);
    timeRunning = true;
    for (int i = 0; i < time; i++) {
        try {
            Thread.sleep(1000);
            Intent intent = new Intent(MainActivity.TIME_NOTIFY);
            CharSequence timeStr = DateFormat.format("hh:mm:ss", System.currentTimeMillis());
            intent.putExtra(EXTRA_TIME_DATA, timeStr);
            sendBroadcast(intent);
        } catch (InterruptedException e) {
            e.printStackTrace();
            return;
        }
    }
    timeRunning = false;
}
Example 14
Project: xDrip-master  File: DatabaseUtil.java View source code
public static String saveSql(Context context) {
    try {
        final String databaseName = new Configuration.Builder(context).create().getDatabaseName();
        final String dir = getExternalDir();
        makeSureDirectoryExists(dir);
        final StringBuilder sb = new StringBuilder();
        sb.append(dir);
        sb.append("/export");
        sb.append(DateFormat.format("yyyyMMdd-kkmmss", System.currentTimeMillis()));
        sb.append(".sqlite");
        final String filename = sb.toString();
        final File sd = Environment.getExternalStorageDirectory();
        if (sd.canWrite()) {
            final File currentDB = context.getDatabasePath(databaseName);
            final File backupDB = new File(filename);
            if (currentDB.exists()) {
                final FileInputStream srcStream = new FileInputStream(currentDB);
                final FileChannel src = srcStream.getChannel();
                final FileOutputStream destStream = new FileOutputStream(backupDB);
                final FileChannel dst = destStream.getChannel();
                dst.transferFrom(src, 0, src.size());
                src.close();
                srcStream.close();
                dst.close();
                destStream.close();
            }
        }
        return filename;
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}
Example 15
Project: android-sdk-sources-for-api-level-23-master  File: DigitalClock.java View source code
@Override
protected void onAttachedToWindow() {
    mTickerStopped = false;
    super.onAttachedToWindow();
    mHandler = new Handler();
    /**
         * requests a tick on the next hard-second boundary
         */
    mTicker = new Runnable() {

        public void run() {
            if (mTickerStopped)
                return;
            mCalendar.setTimeInMillis(System.currentTimeMillis());
            setText(DateFormat.format(mFormat, mCalendar));
            invalidate();
            long now = SystemClock.uptimeMillis();
            long next = now + (1000 - now % 1000);
            mHandler.postAtTime(mTicker, next);
        }
    };
    mTicker.run();
}
Example 16
Project: Subsonic-master  File: ChatAdapter.java View source code
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ChatMessage message = this.getItem(position);
    ViewHolder holder;
    int layout;
    String messageUser = message.getUsername();
    Date messageTime = new java.util.Date(message.getTime());
    String messageText = message.getMessage();
    String me = UserUtil.getCurrentUsername(activity);
    if (messageUser.equals(me)) {
        layout = R.layout.chat_item_reverse;
    } else {
        layout = R.layout.chat_item;
    }
    if (convertView == null) {
        holder = new ViewHolder();
        convertView = LayoutInflater.from(activity).inflate(layout, parent, false);
        TextView usernameView = (TextView) convertView.findViewById(R.id.chat_username);
        TextView timeView = (TextView) convertView.findViewById(R.id.chat_time);
        TextView messageView = (TextView) convertView.findViewById(R.id.chat_message);
        messageView.setMovementMethod(LinkMovementMethod.getInstance());
        Linkify.addLinks(messageView, Linkify.EMAIL_ADDRESSES);
        Linkify.addLinks(messageView, Linkify.WEB_URLS);
        Linkify.addLinks(messageView, phoneMatcher, "tel:");
        holder.message = messageView;
        holder.username = usernameView;
        holder.time = timeView;
        holder.avatar = (ImageView) convertView.findViewById(R.id.chat_avatar);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(activity);
    String messageTimeFormatted = String.format("[%s]", timeFormat.format(messageTime));
    holder.username.setText(messageUser);
    holder.message.setText(messageText);
    holder.time.setText(messageTimeFormatted);
    imageLoader.loadAvatar(activity, holder.avatar, messageUser);
    return convertView;
}
Example 17
Project: astrid-master  File: TimerActionControlSet.java View source code
private void updateDisplay() {
    final int drawable;
    if (timerActive) {
        drawable = R.drawable.icn_timer_stop;
    } else {
        drawable = R.drawable.icn_edit_timer;
    }
    timerButton.setImageResource(drawable);
    long elapsed = model.getValue(Task.ELAPSED_SECONDS) * 1000L;
    if (timerActive) {
        chronometer.setVisibility(View.VISIBLE);
        elapsed += DateUtilities.now() - model.getValue(Task.TIMER_START);
        chronometer.setBase(SystemClock.elapsedRealtime() - elapsed);
        if (elapsed > DateUtilities.ONE_DAY) {
            chronometer.setOnChronometerTickListener(new OnChronometerTickListener() {

                public void onChronometerTick(Chronometer cArg) {
                    long t = SystemClock.elapsedRealtime() - cArg.getBase();
                    //$NON-NLS-1$
                    cArg.setText(DateFormat.format("d'd' h:mm", t));
                }
            });
        }
        chronometer.start();
    } else {
        chronometer.setVisibility(View.GONE);
        chronometer.stop();
    }
}
Example 18
Project: ARTPart-master  File: LocaleData.java View source code
public String getTimeFormat(int style) {
    switch(style) {
        case DateFormat.SHORT:
            if (DateFormat.is24Hour == null) {
                return shortTimeFormat;
            } else {
                return DateFormat.is24Hour ? timeFormat_Hm : timeFormat_hm;
            }
        case DateFormat.MEDIUM:
            if (DateFormat.is24Hour == null) {
                return mediumTimeFormat;
            } else {
                return DateFormat.is24Hour ? timeFormat_Hms : timeFormat_hms;
            }
        case DateFormat.LONG:
            // CLDR doesn't really have anything we can use to obey the 12-/24-hour preference.
            return longTimeFormat;
        case DateFormat.FULL:
            // CLDR doesn't really have anything we can use to obey the 12-/24-hour preference.
            return fullTimeFormat;
    }
    throw new AssertionError();
}
Example 19
Project: platform_packages_apps_settings-master  File: ZenModeVoiceActivity.java View source code
/**
     * Produce a summary of the Zen mode change to be read aloud as TTS.
     */
private CharSequence getChangeSummary(int mode, int minutes) {
    int indefinite = -1;
    int byMinute = -1;
    int byHour = -1;
    int byTime = -1;
    switch(mode) {
        case Global.ZEN_MODE_ALARMS:
            indefinite = R.string.zen_mode_summary_alarms_only_indefinite;
            byMinute = R.plurals.zen_mode_summary_alarms_only_by_minute;
            byHour = R.plurals.zen_mode_summary_alarms_only_by_hour;
            byTime = R.string.zen_mode_summary_alarms_only_by_time;
            break;
        case Global.ZEN_MODE_OFF:
            indefinite = R.string.zen_mode_summary_always;
            break;
    }
    ;
    if (minutes < 0 || mode == Global.ZEN_MODE_OFF) {
        return getString(indefinite);
    }
    long time = System.currentTimeMillis() + minutes * MINUTES_MS;
    String skeleton = DateFormat.is24HourFormat(this, UserHandle.myUserId()) ? "Hm" : "hma";
    String pattern = DateFormat.getBestDateTimePattern(Locale.getDefault(), skeleton);
    CharSequence formattedTime = DateFormat.format(pattern, time);
    Resources res = getResources();
    if (minutes < 60) {
        return res.getQuantityString(byMinute, minutes, minutes, formattedTime);
    } else if (minutes % 60 != 0) {
        return res.getString(byTime, formattedTime);
    } else {
        int hours = minutes / 60;
        return res.getQuantityString(byHour, hours, hours, formattedTime);
    }
}
Example 20
Project: plusTimer-master  File: Utils.java View source code
/**
     * Returns a String containing the date and time according the device's
     * settings and locale from
     * the timestamp
     *
     * @param context   the context
     * @param timestamp the timestamp to convert into a date & time
     *                  String
     * @return the String converted from the timestamp
     * @see android.text.format.DateFormat
     * @see java.text.DateFormat
     */
public static String dateTimeSecondsStringFromTimestamp(Context context, long timestamp) {
    String timeDate;
    String androidDateTime = dateTimeStringFromTimestamp(context, timestamp);
    String javaDateTime = DateFormat.getDateTimeInstance().format(new Date(timestamp));
    String AmPm = "";
    if (!Character.isDigit(androidDateTime.charAt(androidDateTime.length() - 1))) {
        if (androidDateTime.contains(new SimpleDateFormat().getDateFormatSymbols().getAmPmStrings()[Calendar.AM])) {
            AmPm = " " + new SimpleDateFormat().getDateFormatSymbols().getAmPmStrings()[Calendar.AM];
        } else {
            AmPm = " " + new SimpleDateFormat().getDateFormatSymbols().getAmPmStrings()[Calendar.PM];
        }
        androidDateTime = androidDateTime.replace(AmPm, "");
    }
    if (!Character.isDigit(javaDateTime.charAt(javaDateTime.length() - 1))) {
        javaDateTime = javaDateTime.replace(" " + new SimpleDateFormat().getDateFormatSymbols().getAmPmStrings()[Calendar.AM], "");
        javaDateTime = javaDateTime.replace(" " + new SimpleDateFormat().getDateFormatSymbols().getAmPmStrings()[Calendar.PM], "");
    }
    javaDateTime = javaDateTime.substring(javaDateTime.length() - 3);
    timeDate = androidDateTime.concat(javaDateTime);
    return timeDate.concat(AmPm);
}
Example 21
Project: WS171-development-master  File: RadioIssueReport.java View source code
// Largely stolen from LogViewer.java
private static String getRadioLog() throws IOException {
    Socket sock = new Socket("127.0.0.1", 5040);
    DataInputStream in = new DataInputStream(sock.getInputStream());
    StringBuilder log = new StringBuilder();
    // Set options
    sock.getOutputStream().write(RADIO_BUFFER_OPTIONS.getBytes());
    sock.getOutputStream().write('\n');
    sock.getOutputStream().write('\n');
    // Read in the log
    try {
        Calendar cal = new GregorianCalendar();
        while (true) {
            int length = in.readInt();
            long when = (long) in.readInt();
            byte[] bytes = new byte[length - 4];
            in.readFully(bytes);
            int tagEnd = next0(bytes, HEADER_SIZE - 4);
            int fileEnd = next0(bytes, tagEnd + 1);
            int messageEnd = next0(bytes, fileEnd + 1);
            CharSequence tag = forAsciiBytes(bytes, HEADER_SIZE - 4, tagEnd);
            CharSequence message = forAsciiBytes(bytes, fileEnd + 1, messageEnd);
            cal.setTimeInMillis(when * 1000);
            log.append(DateFormat.format("MM-dd kk:mm:ss ", cal));
            log.append(tag).append(": ").append(message).append("\n");
        }
    } catch (EOFException e) {
        Log.d(TAG, "reached end of stream");
    }
    return log.toString();
}
Example 22
Project: android_packages_apps-master  File: AlertAdapter.java View source code
public static void updateView(Context context, View view, String eventName, String location, long startMillis, long endMillis, boolean allDay) {
    Resources res = context.getResources();
    TextView titleView = (TextView) view.findViewById(R.id.event_title);
    TextView whenView = (TextView) view.findViewById(R.id.when);
    TextView whereView = (TextView) view.findViewById(R.id.where);
    if (mFirstTime) {
        mPastEventColor = res.getColor(R.color.alert_past_event);
        mTitleColor = res.getColor(R.color.alert_event_title);
        mOtherColor = res.getColor(R.color.alert_event_other);
        mFirstTime = false;
    }
    if (endMillis < System.currentTimeMillis()) {
        titleView.setTextColor(mPastEventColor);
        whenView.setTextColor(mPastEventColor);
        whereView.setTextColor(mPastEventColor);
    } else {
        titleView.setTextColor(mTitleColor);
        whenView.setTextColor(mOtherColor);
        whereView.setTextColor(mOtherColor);
    }
    // What
    if (eventName == null || eventName.length() == 0) {
        eventName = res.getString(R.string.no_title_label);
    }
    titleView.setText(eventName);
    // When
    String when;
    int flags;
    String tz = Utils.getTimeZone(context, null);
    if (allDay) {
        flags = DateUtils.FORMAT_UTC | DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_SHOW_DATE;
        tz = Time.TIMEZONE_UTC;
    } else {
        flags = DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE;
    }
    if (DateFormat.is24HourFormat(context)) {
        flags |= DateUtils.FORMAT_24HOUR;
    }
    Time time = new Time(tz);
    time.set(startMillis);
    boolean isDST = time.isDst != 0;
    StringBuilder sb = new StringBuilder(Utils.formatDateRange(context, startMillis, endMillis, flags));
    if (!allDay && tz != Time.getCurrentTimezone()) {
        sb.append(" ").append(TimeZone.getTimeZone(tz).getDisplayName(isDST, TimeZone.SHORT, Locale.getDefault()));
    }
    when = sb.toString();
    whenView.setText(when);
    // Where
    if (location == null || location.length() == 0) {
        whereView.setVisibility(View.GONE);
    } else {
        whereView.setText(location);
        whereView.setVisibility(View.VISIBLE);
    }
}
Example 23
Project: android-betterpickers-master  File: DateView.java View source code
@Override
protected void onFinishInflate() {
    super.onFinishInflate();
    mMonth = (ZeroTopPaddingTextView) findViewById(R.id.month);
    mDate = (ZeroTopPaddingTextView) findViewById(R.id.date);
    mYearLabel = (ZeroTopPaddingTextView) findViewById(R.id.year_label);
    // Reorder based on locale
    char[] dateFormatOrder = DateFormat.getDateFormatOrder(getContext());
    removeAllViews();
    for (int i = 0; i < dateFormatOrder.length; i++) {
        switch(dateFormatOrder[i]) {
            case 'd':
                addView(mDate);
                break;
            case 'M':
                addView(mMonth);
                break;
            case 'y':
                addView(mYearLabel);
                break;
        }
    }
    if (mMonth != null) {
    //mOriginalNumberTypeface = mMonth.getTypeface();
    }
    // Set both TextViews with thin font (for hyphen)
    if (mDate != null) {
        mDate.setTypeface(mAndroidClockMonoThin);
        mDate.updatePadding();
    }
    if (mMonth != null) {
        mMonth.setTypeface(mAndroidClockMonoThin);
        mMonth.updatePadding();
    }
    restyleViews();
}
Example 24
Project: Appsii-master  File: ItemAgendaViewHolder.java View source code
@Override
public boolean bind(Object object) {
    Context context = itemView.getContext();
    if (object instanceof AgendaEvent) {
        AgendaEvent item = (AgendaEvent) object;
        mAgendaEvent = item;
        mTime.set(item.startMillis);
        mPrimaryText.setText(item.title);
        mSecondaryText.setText(item.calendarName);
        EventTimeDrawable drawable = (EventTimeDrawable) mImageView.getDrawable();
        boolean is24 = android.text.format.DateFormat.is24HourFormat(context);
        if (item.allDay) {
            drawable.setTime(true, /* allDay */
            mTime.monthDay, mTime.month, mTime.hour, mTime.minute, EventTimeDrawable.AMPM_NONE);
        } else if (is24 && false) {
            drawable.setTime(false, /* allDay */
            mTime.monthDay, mTime.month, mTime.hour, mTime.minute, EventTimeDrawable.AMPM_NONE);
        } else {
            if (mTime.hour > 12) {
                drawable.setTime(false, /* allDay */
                mTime.monthDay, mTime.month, mTime.hour - 12, mTime.minute, EventTimeDrawable.AMPM_PM);
            } else {
                drawable.setTime(false, /* allDay */
                mTime.monthDay, mTime.month, mTime.hour, mTime.minute, EventTimeDrawable.AMPM_AM);
            }
        }
        return true;
    } else {
        mAgendaEvent = null;
        return false;
    }
}
Example 25
Project: WordPress-Android-master  File: StatsInsightsMostPopularFragment.java View source code
protected void updateUI() {
    super.updateUI();
    if (!isAdded() || !hasDataAvailable()) {
        return;
    }
    LinearLayout ll = (LinearLayout) getActivity().getLayoutInflater().inflate(R.layout.stats_insights_most_popular_item, (ViewGroup) mResultContainer.getRootView(), false);
    int dayOfTheWeek = mInsightsPopularModel.getHighestDayOfWeek();
    Calendar c = Calendar.getInstance();
    c.setFirstDayOfWeek(Calendar.MONDAY);
    c.setTimeInMillis(System.currentTimeMillis());
    switch(dayOfTheWeek) {
        case 0:
            c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
            break;
        case 1:
            c.set(Calendar.DAY_OF_WEEK, Calendar.TUESDAY);
            break;
        case 2:
            c.set(Calendar.DAY_OF_WEEK, Calendar.WEDNESDAY);
            break;
        case 3:
            c.set(Calendar.DAY_OF_WEEK, Calendar.THURSDAY);
            break;
        case 4:
            c.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY);
            break;
        case 5:
            c.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);
            break;
        case 6:
            c.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
            break;
    }
    DateFormat formatter = new SimpleDateFormat("EEEE");
    final TextView mostPopularDayTextView = (TextView) ll.findViewById(R.id.stats_most_popular_day);
    mostPopularDayTextView.setText(formatter.format(c.getTime()));
    final TextView mostPopularDayPercentTextView = (TextView) ll.findViewById(R.id.stats_most_popular_day_percent);
    mostPopularDayPercentTextView.setText(String.format(getString(R.string.stats_insights_most_popular_percent_views), roundToInteger(mInsightsPopularModel.getHighestDayPercent())));
    TextView mostPopularHourTextView = (TextView) ll.findViewById(R.id.stats_most_popular_hour);
    DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(getActivity());
    c.set(Calendar.HOUR_OF_DAY, mInsightsPopularModel.getHighestHour());
    c.set(Calendar.MINUTE, 0);
    mostPopularHourTextView.setText(timeFormat.format(c.getTime()));
    final TextView mostPopularHourPercentTextView = (TextView) ll.findViewById(R.id.stats_most_popular_hour_percent);
    mostPopularHourPercentTextView.setText(String.format(getString(R.string.stats_insights_most_popular_percent_views), roundToInteger(mInsightsPopularModel.getHighestHourPercent())));
    mResultContainer.addView(ll);
}