Example usage for java.text DateFormat MEDIUM

List of usage examples for java.text DateFormat MEDIUM

Introduction

In this page you can find the example usage for java.text DateFormat MEDIUM.

Prototype

int MEDIUM

To view the source code for java.text DateFormat MEDIUM.

Click Source Link

Document

Constant for medium style pattern.

Usage

From source file:org.robovm.eclipse.internal.AbstractLaunchConfigurationDelegate.java

@Override
public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor)
        throws CoreException {

    if (monitor == null) {
        monitor = new NullProgressMonitor();
    }//from w  w w .j  a v  a2  s.  c  om

    monitor.beginTask(configuration.getName() + "...", 6);
    if (monitor.isCanceled()) {
        return;
    }

    try {
        monitor.subTask("Verifying launch attributes");

        String mainTypeName = getMainTypeName(configuration);
        File workingDir = getWorkingDirectory(configuration);
        String[] envp = getEnvironment(configuration);
        List<String> pgmArgs = splitArgs(getProgramArguments(configuration));
        List<String> vmArgs = splitArgs(getVMArguments(configuration));
        String[] classpath = getClasspath(configuration);
        String[] bootclasspath = getBootpath(configuration);
        IJavaProject javaProject = getJavaProject(configuration);
        int debuggerPort = findFreePort();
        boolean hasDebugPlugin = false;

        if (monitor.isCanceled()) {
            return;
        }

        // Verification done
        monitor.worked(1);

        RoboVMPlugin.consoleInfo("Building executable");

        monitor.subTask("Creating source locator");
        setDefaultSourceLocator(launch, configuration);
        monitor.worked(1);

        monitor.subTask("Creating build configuration");
        Config.Builder configBuilder;
        try {
            configBuilder = new Config.Builder();
        } catch (IOException e) {
            throw new CoreException(new Status(IStatus.ERROR, RoboVMPlugin.PLUGIN_ID,
                    "Launch failed. Check the RoboVM console for more information.", e));
        }
        configBuilder.logger(RoboVMPlugin.getConsoleLogger());

        File projectRoot = getJavaProject(configuration).getProject().getLocation().toFile();
        RoboVMPlugin.loadConfig(configBuilder, projectRoot, isTestConfiguration());

        Arch arch = getArch(configuration, mode);
        OS os = getOS(configuration, mode);

        configBuilder.os(os);
        configBuilder.arch(arch);

        File tmpDir = RoboVMPlugin.getBuildDir(getJavaProjectName(configuration));
        tmpDir = new File(tmpDir, configuration.getName());
        tmpDir = new File(new File(tmpDir, os.toString()), arch.toString());
        if (mainTypeName != null) {
            tmpDir = new File(tmpDir, mainTypeName);
        }

        if (ILaunchManager.DEBUG_MODE.equals(mode)) {
            configBuilder.debug(true);
            String sourcepaths = RoboVMPlugin.getSourcePaths(javaProject);
            configBuilder.addPluginArgument("debug:sourcepath=" + sourcepaths);
            configBuilder.addPluginArgument("debug:jdwpport=" + debuggerPort);
            configBuilder.addPluginArgument(
                    "debug:logdir=" + new File(projectRoot, "robovm-logs").getAbsolutePath());
            // check if we have the debug plugin
            for (Plugin plugin : configBuilder.getPlugins()) {
                if ("DebugLaunchPlugin".equals(plugin.getClass().getSimpleName())) {
                    hasDebugPlugin = true;
                }
            }
        }

        if (bootclasspath != null) {
            configBuilder.skipRuntimeLib(true);
            for (String p : bootclasspath) {
                configBuilder.addBootClasspathEntry(new File(p));
            }
        }
        for (String p : classpath) {
            configBuilder.addClasspathEntry(new File(p));
        }
        if (mainTypeName != null) {
            configBuilder.mainClass(mainTypeName);
        }
        // we need to filter those vm args that belong to plugins
        // in case of iOS run configs, we can only pass program args
        filterPluginArguments(vmArgs, configBuilder);
        filterPluginArguments(pgmArgs, configBuilder);

        configBuilder.tmpDir(tmpDir);
        configBuilder.skipInstall(true);

        Config config = null;
        AppCompiler compiler = null;
        try {
            RoboVMPlugin.consoleInfo("Cleaning output dir " + tmpDir.getAbsolutePath());
            FileUtils.deleteDirectory(tmpDir);
            tmpDir.mkdirs();

            Home home = RoboVMPlugin.getRoboVMHome();
            if (home.isDev()) {
                configBuilder.useDebugLibs(Boolean.getBoolean("robovm.useDebugLibs"));
                configBuilder.dumpIntermediates(true);
            }
            configBuilder.home(home);
            config = configure(configBuilder, configuration, mode).build();
            compiler = new AppCompiler(config);
            if (monitor.isCanceled()) {
                return;
            }
            monitor.worked(1);

            monitor.subTask("Building executable");
            AppCompilerThread thread = new AppCompilerThread(compiler, monitor);
            thread.compile();
            if (monitor.isCanceled()) {
                RoboVMPlugin.consoleInfo("Build canceled");
                return;
            }
            monitor.worked(1);
            RoboVMPlugin.consoleInfo("Build done");
        } catch (InterruptedException e) {
            RoboVMPlugin.consoleInfo("Build canceled");
            return;
        } catch (IOException e) {
            RoboVMPlugin.consoleError("Build failed");
            throw new CoreException(new Status(IStatus.ERROR, RoboVMPlugin.PLUGIN_ID,
                    "Build failed. Check the RoboVM console for more information.", e));
        }

        try {
            RoboVMPlugin.consoleInfo("Launching executable");
            monitor.subTask("Launching executable");
            mainTypeName = config.getMainClass();

            List<String> runArgs = new ArrayList<String>();
            runArgs.addAll(vmArgs);
            runArgs.addAll(pgmArgs);
            LaunchParameters launchParameters = config.getTarget().createLaunchParameters();
            launchParameters.setArguments(runArgs);
            launchParameters.setWorkingDirectory(workingDir);
            launchParameters.setEnvironment(envToMap(envp));
            customizeLaunchParameters(config, launchParameters, configuration, mode);
            String label = String.format("%s (%s)", mainTypeName,
                    DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM).format(new Date()));
            // launch plugin may proxy stdout/stderr fifo, which
            // it then writes to. Need to save the original fifos
            File stdOutFifo = launchParameters.getStdoutFifo();
            File stdErrFifo = launchParameters.getStderrFifo();
            PipedInputStream pipedIn = new PipedInputStream();
            PipedOutputStream pipedOut = new PipedOutputStream(pipedIn);
            Process process = compiler.launchAsync(launchParameters, pipedIn);
            if (stdOutFifo != null || stdErrFifo != null) {
                InputStream stdoutStream = null;
                InputStream stderrStream = null;
                if (launchParameters.getStdoutFifo() != null) {
                    stdoutStream = new OpenOnReadFileInputStream(stdOutFifo);
                }
                if (launchParameters.getStderrFifo() != null) {
                    stderrStream = new OpenOnReadFileInputStream(stdErrFifo);
                }
                process = new ProcessProxy(process, pipedOut, stdoutStream, stderrStream, compiler);
            }

            IProcess iProcess = DebugPlugin.newProcess(launch, process, label);

            // setup the debugger
            if (ILaunchManager.DEBUG_MODE.equals(mode) && hasDebugPlugin) {
                VirtualMachine vm = attachToVm(monitor, debuggerPort);
                // we were canceled
                if (vm == null) {
                    process.destroy();
                    return;
                }
                if (vm instanceof VirtualMachineImpl) {
                    ((VirtualMachineImpl) vm).setRequestTimeout(DEBUGGER_REQUEST_TIMEOUT);
                }
                JDIDebugModel.newDebugTarget(launch, vm, mainTypeName + " at localhost:" + debuggerPort,
                        iProcess, true, false, true);
            }
            RoboVMPlugin.consoleInfo("Launch done");

            if (monitor.isCanceled()) {
                process.destroy();
                return;
            }
            monitor.worked(1);
        } catch (Throwable t) {
            RoboVMPlugin.consoleError("Launch failed");
            throw new CoreException(new Status(IStatus.ERROR, RoboVMPlugin.PLUGIN_ID,
                    "Launch failed. Check the RoboVM console for more information.", t));
        }

    } finally {
        monitor.done();
    }
}

From source file:org.tinymediamanager.core.entities.MediaEntity.java

public String getDateAddedAsString() {
    if (dateAdded == null) {
        return "";
    }/*from   w  w w . java2s.c  o m*/

    return SimpleDateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.getDefault())
            .format(dateAdded);
}

From source file:net.lightbody.bmp.proxy.jetty.util.Resource.java

/** Get the resource list as a HTML directory listing.
 * @param base The base URL// w w w . j a  v  a 2s  .c o  m
 * @param parent True if the parent directory should be included
 * @return String of HTML
 */
public String getListHTML(String base, boolean parent) throws IOException {
    if (!isDirectory())
        return null;

    String[] ls = list();
    if (ls == null)
        return null;
    Arrays.sort(ls);

    String title = "Directory: " + URI.decodePath(base);
    title = StringUtil.replace(StringUtil.replace(title, "<", "&lt;"), ">", "&gt;");
    StringBuffer buf = new StringBuffer(4096);
    buf.append("<HTML><HEAD><TITLE>");
    buf.append(title);
    buf.append("</TITLE></HEAD><BODY>\n<H1>");
    buf.append(title);
    buf.append("</H1><TABLE BORDER=0>");

    if (parent) {
        buf.append("<TR><TD><A HREF=");
        buf.append(URI.encodePath(URI.addPaths(base, "../")));
        buf.append(">Parent Directory</A></TD><TD></TD><TD></TD></TR>\n");
    }

    DateFormat dfmt = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
    for (int i = 0; i < ls.length; i++) {
        String encoded = URI.encodePath(ls[i]);
        Resource item = addPath(encoded);

        buf.append("<TR><TD><A HREF=\"");

        String path = URI.addPaths(base, encoded);

        if (item.isDirectory() && !path.endsWith("/"))
            path = URI.addPaths(path, "/");
        buf.append(path);
        buf.append("\">");
        buf.append(StringUtil.replace(StringUtil.replace(ls[i], "<", "&lt;"), ">", "&gt;"));
        buf.append("&nbsp;");
        buf.append("</TD><TD ALIGN=right>");
        buf.append(item.length());
        buf.append(" bytes&nbsp;</TD><TD>");
        buf.append(dfmt.format(new Date(item.lastModified())));
        buf.append("</TD></TR>\n");
    }
    buf.append("</TABLE>\n");
    buf.append("</BODY></HTML>\n");

    return buf.toString();
}

From source file:org.ejbca.core.model.ra.ExtendedInformation.java

/** Implementation of UpgradableDataHashMap function upgrade. */
public void upgrade() {
    if (Float.compare(LATEST_VERSION, getVersion()) != 0) {
        // New version of the class, upgrade
        String msg = intres.getLocalizedMessage("endentity.extendedinfoupgrade", new Float(getVersion()));
        log.info(msg);//w w w .j av a2 s .  com

        if (data.get(SUBJECTDIRATTRIBUTES) == null) {
            data.put(SUBJECTDIRATTRIBUTES, "");
        }
        if (data.get(MAXFAILEDLOGINATTEMPTS) == null) {
            setMaxLoginAttempts(DEFAULT_MAXLOGINATTEMPTS);
        }
        if (data.get(REMAININGLOGINATTEMPTS) == null) {
            setRemainingLoginAttempts(DEFAULT_REMAININGLOGINATTEMPTS);
        }
        // In EJBCA 4.0.0 we changed the date format
        if (getVersion() < 3) {
            final DateFormat oldDateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT,
                    Locale.US);
            final FastDateFormat newDateFormat = FastDateFormat.getInstance("yyyy-MM-dd HH:mm");
            try {
                final String oldCustomStartTime = getCustomData(ExtendedInformation.CUSTOM_STARTTIME);
                if (!isEmptyOrRelative(oldCustomStartTime)) {
                    // We use an absolute time format, so we need to upgrade
                    final String newCustomStartTime = newDateFormat
                            .format(oldDateFormat.parse(oldCustomStartTime));
                    setCustomData(ExtendedInformation.CUSTOM_STARTTIME, newCustomStartTime);
                    if (log.isDebugEnabled()) {
                        log.debug("Upgraded " + ExtendedInformation.CUSTOM_STARTTIME + " from \""
                                + oldCustomStartTime + "\" to \"" + newCustomStartTime
                                + "\" in ExtendedInformation.");
                    }
                }
            } catch (ParseException e) {
                log.error("Unable to upgrade " + ExtendedInformation.CUSTOM_STARTTIME
                        + " in extended user information.", e);
            }
            try {
                final String oldCustomEndTime = getCustomData(ExtendedInformation.CUSTOM_ENDTIME);
                if (!isEmptyOrRelative(oldCustomEndTime)) {
                    // We use an absolute time format, so we need to upgrade
                    final String newCustomEndTime = newDateFormat.format(oldDateFormat.parse(oldCustomEndTime));
                    setCustomData(ExtendedInformation.CUSTOM_ENDTIME, newCustomEndTime);
                    if (log.isDebugEnabled()) {
                        log.debug(
                                "Upgraded " + ExtendedInformation.CUSTOM_ENDTIME + " from \"" + oldCustomEndTime
                                        + "\" to \"" + newCustomEndTime + "\" in ExtendedInformation.");
                    }
                }
            } catch (ParseException e) {
                log.error("Unable to upgrade " + ExtendedInformation.CUSTOM_ENDTIME
                        + " in extended user information.", e);
            }
        }
        // In 4.0.2 we further specify the storage format by saying that UTC TimeZone is implied instead of local server time
        if (getVersion() < 4) {
            final String[] timePatterns = { "yyyy-MM-dd HH:mm" };
            final String oldStartTime = getCustomData(ExtendedInformation.CUSTOM_STARTTIME);
            if (!isEmptyOrRelative(oldStartTime)) {
                try {
                    final String newStartTime = ValidityDate
                            .formatAsUTC(DateUtils.parseDateStrictly(oldStartTime, timePatterns));
                    setCustomData(ExtendedInformation.CUSTOM_STARTTIME, newStartTime);
                    if (log.isDebugEnabled()) {
                        log.debug("Upgraded " + ExtendedInformation.CUSTOM_STARTTIME + " from \"" + oldStartTime
                                + "\" to \"" + newStartTime + "\" in EndEntityProfile.");
                    }
                } catch (ParseException e) {
                    log.error("Unable to upgrade " + ExtendedInformation.CUSTOM_STARTTIME
                            + " to UTC in EndEntityProfile! Manual interaction is required (edit and verify).",
                            e);
                }
            }
            final String oldEndTime = getCustomData(ExtendedInformation.CUSTOM_ENDTIME);
            if (!isEmptyOrRelative(oldEndTime)) {
                // We use an absolute time format, so we need to upgrade
                try {
                    final String newEndTime = ValidityDate
                            .formatAsUTC(DateUtils.parseDateStrictly(oldEndTime, timePatterns));
                    setCustomData(ExtendedInformation.CUSTOM_ENDTIME, newEndTime);
                    if (log.isDebugEnabled()) {
                        log.debug("Upgraded " + ExtendedInformation.CUSTOM_ENDTIME + " from \"" + oldEndTime
                                + "\" to \"" + newEndTime + "\" in EndEntityProfile.");
                    }
                } catch (ParseException e) {
                    log.error("Unable to upgrade " + ExtendedInformation.CUSTOM_ENDTIME
                            + " to UTC in EndEntityProfile! Manual interaction is required (edit and verify).",
                            e);
                }
            }
        }
        data.put(VERSION, new Float(LATEST_VERSION));
    }
}

From source file:tain.kr.test.vfs.v01.Shell.java

/**
 * Does an 'ls' command.//  w w w  .ja v  a2s.c  o  m
 */
private void ls(final String[] cmd) throws FileSystemException {

    int pos = 1;
    final boolean recursive;

    if (cmd.length > pos && cmd[pos].equals("-R")) {
        recursive = true;
        pos++;
    } else {
        recursive = false;
    }

    final FileObject file;
    if (cmd.length > pos) {
        file = mgr.resolveFile(cwd, cmd[pos]);
    } else {
        file = cwd;
    }

    if (file.getType() == FileType.FOLDER) {
        // List the contents
        System.out.println("Contents of " + file.getName());
        listChildren(file, recursive, "");
    } else {
        // Stat the file
        System.out.println(file.getName());
        final FileContent content = file.getContent();
        System.out.println("Size: " + content.getSize() + " bytes.");
        final DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
        final String lastMod = dateFormat.format(new Date(content.getLastModifiedTime()));
        System.out.println("Last modified: " + lastMod);
    }
}

From source file:org.apache.struts2.components.Date.java

public boolean end(Writer writer, String body) {
    String msg = null;//  www  .  j av  a  2s  . c  o  m
    ValueStack stack = getStack();
    java.util.Date date = null;
    // find the name on the valueStack, and cast it to a date
    try {
        date = (java.util.Date) findValue(name);
    } catch (Exception e) {
        LOG.error("Could not convert object with key '" + name + "' to a java.util.Date instance");
        // bad date, return a blank instead ?
        msg = "";
    }

    //try to find the format on the stack
    if (format != null) {
        format = findString(format);
    }
    if (date != null) {
        TextProvider tp = findProviderInStack();
        if (tp != null) {
            if (nice) {
                msg = formatTime(tp, date);
            } else {
                if (format == null) {
                    String globalFormat = null;

                    // if the format is not specified, fall back using the
                    // defined property DATETAG_PROPERTY
                    globalFormat = tp.getText(DATETAG_PROPERTY);

                    // if tp.getText can not find the property then the
                    // returned string is the same as input =
                    // DATETAG_PROPERTY
                    if (globalFormat != null && !DATETAG_PROPERTY.equals(globalFormat)) {
                        msg = new SimpleDateFormat(globalFormat, ActionContext.getContext().getLocale())
                                .format(date);
                    } else {
                        msg = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM,
                                ActionContext.getContext().getLocale()).format(date);
                    }
                } else {
                    msg = new SimpleDateFormat(format, ActionContext.getContext().getLocale()).format(date);
                }
            }
            if (msg != null) {
                try {
                    if (getId() == null) {
                        writer.write(msg);
                    } else {
                        stack.getContext().put(getId(), msg);
                    }
                } catch (IOException e) {
                    LOG.error("Could not write out Date tag", e);
                }
            }
        }
    }
    return super.end(writer, "");
}

From source file:org.nuxeo.ecm.webapp.edit.lock.LockActionsBean.java

@Override
public Map<String, Serializable> getLockDetails(DocumentModel document) {
    if (lockDetails == null || !StringUtils.equals(documentId, document.getId())) {
        lockDetails = new HashMap<String, Serializable>();
        documentId = document.getId();//  ww  w  .  ja va  2 s .  com
        Lock lock = documentManager.getLockInfo(document.getRef());
        if (lock == null) {
            return lockDetails;
        }
        lockDetails.put(LOCKER, lock.getOwner());
        lockDetails.put(LOCK_CREATED, lock.getCreated());
        lockDetails.put(LOCK_TIME, DateFormat.getDateInstance(DateFormat.MEDIUM)
                .format(new Date(lock.getCreated().getTimeInMillis())));
    }
    return lockDetails;
}

From source file:org.apache.empire.struts2.jsp.controls.TextInputControl.java

protected DateFormat getDateFormat(DataType dataType, Locale locale, Column column) {
    DateFormat df;/*from  www  .  j a v  a  2s. co  m*/
    if (dataType == DataType.DATE)
        df = DateFormat.getDateInstance(DateFormat.MEDIUM, locale);
    else
        df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, locale);
    return df;
}

From source file:org.agiso.tempel.Tempel.java

/**
 * //w  ww. j ava2  s  .co m
 * 
 * @param properties
 * @throws Exception 
 */
private Map<String, Object> addRuntimeProperties(Map<String, Object> properties) throws Exception {
    Map<String, Object> props = new HashMap<String, Object>();

    // Okrelanie lokalizacji daty/czasu uywanej do wypenienia paramtrw szablonw
    // zawierajcych dat/czas w formatach DateFormat.SHORT, .MEDIUM, .LONG i .FULL:
    Locale date_locale;
    if (properties.containsKey(UP_DATE_LOCALE)) {
        date_locale = LocaleUtils.toLocale((String) properties.get(UP_DATE_LOCALE));
        Locale.setDefault(date_locale);
    } else {
        date_locale = Locale.getDefault();
    }

    TimeZone time_zone;
    if (properties.containsKey(UP_TIME_ZONE)) {
        time_zone = TimeZone.getTimeZone((String) properties.get(UP_DATE_LOCALE));
        TimeZone.setDefault(time_zone);
    } else {
        time_zone = TimeZone.getDefault();
    }

    // Wyznaczanie daty, na podstawie ktrej zostan wypenione parametry szablonw
    // przechowujce dat/czas w formatach DateFormat.SHORT, .MEDIUM, .LONG i .FULL.
    // Odbywa si w oparciu o wartoci parametrw 'date_format' i 'date'. Parametr
    // 'date_format' definiuje format uywany do parsowania acucha reprezentujcego
    // dat okrelon parametrem 'date'. Parametr 'date_format' moe nie by okrelony.
    // W takiej sytuacji uyty jest format DateFormat.LONG aktywnej lokalizacji (tj.
    // systemowej, ktra moe by przedefiniowana przez parametr 'date_locale'), ktry
    // moe by przedefiniowany przez parametry 'date_format_long' i 'time_format_long':
    Calendar calendar = Calendar.getInstance(date_locale);
    if (properties.containsKey(RP_DATE)) {
        String date_string = (String) properties.get(RP_DATE);
        if (properties.containsKey(RP_DATE_FORMAT)) {
            String date_format = (String) properties.get(RP_DATE_FORMAT);
            DateFormat formatter = new SimpleDateFormat(date_format);
            formatter.setTimeZone(time_zone);
            calendar.setTime(formatter.parse(date_string));
        } else if (properties.containsKey(UP_DATE_FORMAT_LONG) && properties.containsKey(UP_TIME_FORMAT_LONG)) {
            // TODO: Zaoenie, e format data-czas jest zoony z acucha daty i czasu rozdzelonych spacj:
            // 'UP_DATE_FORMAT_LONG UP_TIME_FORMAT_LONG'
            DateFormat formatter = new SimpleDateFormat((String) properties.get(UP_DATE_FORMAT_LONG) + " "
                    + (String) properties.get(UP_TIME_FORMAT_LONG), date_locale);
            formatter.setTimeZone(time_zone);
            calendar.setTime(formatter.parse(date_string));
        } else {
            DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG,
                    date_locale);
            formatter.setTimeZone(time_zone);
            calendar.setTime(formatter.parse(date_string));
        }
    }

    // Jeli nie okrelono, wypenianie parametrw przechowujcych poszczeglne
    // skadniki daty, tj. rok, miesic i dzie:
    if (!properties.containsKey(TP_YEAR)) {
        props.put(TP_YEAR, calendar.get(Calendar.YEAR));
    }
    if (!properties.containsKey(TP_MONTH)) {
        props.put(TP_MONTH, calendar.get(Calendar.MONTH));
    }
    if (!properties.containsKey(TP_DAY)) {
        props.put(TP_DAY, calendar.get(Calendar.DAY_OF_MONTH));
    }

    // Jeli nie okrelono, wypenianie parametrw przechowujcych dat i czas w
    // formatach SHORT, MEDIUM, LONG i FULL (na podstawie wyznaczonej lokalizacji):
    Date date = calendar.getTime();
    if (!properties.containsKey(TP_DATE_SHORT)) {
        DateFormat formatter;
        if (properties.containsKey(UP_DATE_FORMAT_SHORT)) {
            formatter = new SimpleDateFormat((String) properties.get(UP_DATE_FORMAT_SHORT), date_locale);
        } else {
            formatter = DateFormat.getDateInstance(DateFormat.SHORT, date_locale);
        }
        formatter.setTimeZone(time_zone);
        props.put(TP_DATE_SHORT, formatter.format(date));
    }
    if (!properties.containsKey(TP_DATE_MEDIUM)) {
        DateFormat formatter;
        if (properties.containsKey(UP_DATE_FORMAT_MEDIUM)) {
            formatter = new SimpleDateFormat((String) properties.get(UP_DATE_FORMAT_MEDIUM), date_locale);
        } else {
            formatter = DateFormat.getDateInstance(DateFormat.MEDIUM, date_locale);
        }
        formatter.setTimeZone(time_zone);
        props.put(TP_DATE_MEDIUM, formatter.format(date));
    }
    if (!properties.containsKey(TP_DATE_LONG)) {
        DateFormat formatter;
        if (properties.containsKey(UP_DATE_FORMAT_LONG)) {
            formatter = new SimpleDateFormat((String) properties.get(UP_DATE_FORMAT_LONG), date_locale);
        } else {
            formatter = DateFormat.getDateInstance(DateFormat.LONG, date_locale);
        }
        formatter.setTimeZone(time_zone);
        props.put(TP_DATE_LONG, formatter.format(date));
    }
    if (!properties.containsKey(TP_DATE_FULL)) {
        DateFormat formatter;
        if (properties.containsKey(UP_DATE_FORMAT_FULL)) {
            formatter = new SimpleDateFormat((String) properties.get(UP_DATE_FORMAT_FULL), date_locale);
        } else {
            formatter = DateFormat.getDateInstance(DateFormat.FULL, date_locale);
        }
        formatter.setTimeZone(time_zone);
        props.put(TP_DATE_FULL, formatter.format(date));
    }

    if (!properties.containsKey(TP_TIME_SHORT)) {
        DateFormat formatter;
        if (properties.containsKey(UP_TIME_FORMAT_SHORT)) {
            formatter = new SimpleDateFormat((String) properties.get(UP_TIME_FORMAT_SHORT), date_locale);
        } else {
            formatter = DateFormat.getTimeInstance(DateFormat.SHORT, date_locale);
        }
        formatter.setTimeZone(time_zone);
        props.put(TP_TIME_SHORT, formatter.format(date));
    }
    if (!properties.containsKey(TP_TIME_MEDIUM)) {
        DateFormat formatter;
        if (properties.containsKey(UP_TIME_FORMAT_MEDIUM)) {
            formatter = new SimpleDateFormat((String) properties.get(UP_TIME_FORMAT_MEDIUM), date_locale);
        } else {
            formatter = DateFormat.getTimeInstance(DateFormat.MEDIUM, date_locale);
        }
        formatter.setTimeZone(time_zone);
        props.put(TP_TIME_MEDIUM, formatter.format(date));
    }
    if (!properties.containsKey(TP_TIME_LONG)) {
        DateFormat formatter;
        if (properties.containsKey(UP_TIME_FORMAT_LONG)) {
            formatter = new SimpleDateFormat((String) properties.get(UP_TIME_FORMAT_LONG), date_locale);
        } else {
            formatter = DateFormat.getTimeInstance(DateFormat.LONG, date_locale);
        }
        formatter.setTimeZone(time_zone);
        props.put(TP_TIME_LONG, formatter.format(date));
    }
    if (!properties.containsKey(TP_TIME_FULL)) {
        DateFormat formatter;
        if (properties.containsKey(UP_TIME_FORMAT_FULL)) {
            formatter = new SimpleDateFormat((String) properties.get(UP_TIME_FORMAT_FULL), date_locale);
        } else {
            formatter = DateFormat.getTimeInstance(DateFormat.FULL, date_locale);
        }
        formatter.setTimeZone(time_zone);
        props.put(TP_TIME_FULL, formatter.format(date));
    }

    return props;
}

From source file:com.mifos.mifosxdroid.online.ClientDetailsFragment.java

/**
 * Use this method to fetch and inflate client details
 * in the fragment/*from  w  ww . ja  v a  2s .c o m*/
 */
public void getClientDetails() {
    showProgress(true);
    App.apiManager.getClient(clientId, new Callback<Client>() {
        @Override
        public void success(final Client client, Response response) {
            /* Activity is null - Fragment has been detached; no need to do anything. */
            if (getActivity() == null)
                return;

            if (client != null) {
                setToolbarTitle(getString(R.string.client) + " - " + client.getLastname());
                tv_fullName.setText(client.getDisplayName());
                tv_accountNumber.setText(client.getAccountNo());
                tv_externalId.setText(client.getExternalId());
                if (TextUtils.isEmpty(client.getAccountNo()))
                    rowAccount.setVisibility(GONE);

                if (TextUtils.isEmpty(client.getExternalId()))
                    rowExternal.setVisibility(GONE);

                try {
                    List<Integer> dateObj = client.getActivationDate();
                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd MMM yyyy");
                    Date date = simpleDateFormat.parse(DateHelper.getDateAsString(dateObj));
                    Locale currentLocale = getResources().getConfiguration().locale;
                    DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM, currentLocale);
                    String dateString = df.format(date);
                    tv_activationDate.setText(dateString);

                    if (TextUtils.isEmpty(dateString))
                        rowActivation.setVisibility(GONE);

                } catch (IndexOutOfBoundsException e) {
                    Toast.makeText(getActivity(), getString(R.string.error_client_inactive), Toast.LENGTH_SHORT)
                            .show();
                    tv_activationDate.setText("");
                } catch (ParseException e) {
                    Log.d(TAG, e.getLocalizedMessage());
                }
                tv_office.setText(client.getOfficeName());

                if (TextUtils.isEmpty(client.getOfficeName()))
                    rowOffice.setVisibility(GONE);

                if (client.isImagePresent()) {
                    imageLoadingAsyncTask = new ImageLoadingAsyncTask();
                    imageLoadingAsyncTask.execute(client.getId());
                } else {
                    iv_clientImage.setImageDrawable(
                            ResourcesCompat.getDrawable(getResources(), R.drawable.ic_launcher, null));

                    pb_imageProgressBar.setVisibility(GONE);
                }

                iv_clientImage.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        PopupMenu menu = new PopupMenu(getActivity(), view);
                        menu.getMenuInflater().inflate(R.menu.client_image_popup, menu.getMenu());
                        menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                            @Override
                            public boolean onMenuItemClick(MenuItem menuItem) {
                                switch (menuItem.getItemId()) {
                                case R.id.client_image_capture:
                                    captureClientImage();
                                    break;
                                case R.id.client_image_remove:
                                    deleteClientImage();
                                    break;
                                default:
                                    Log.e("ClientDetailsFragment",
                                            "Unrecognized " + "client " + "image menu item");
                                }
                                return true;
                            }
                        });
                        menu.show();
                    }
                });
                showProgress(false);
                inflateClientsAccounts();
            }
        }

        @Override
        public void failure(RetrofitError retrofitError) {
            Toaster.show(rootView, "Client not found.");
            showProgress(false);
        }
    });
}