Example usage for java.text DateFormat getDateTimeInstance

List of usage examples for java.text DateFormat getDateTimeInstance

Introduction

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

Prototype

public static final DateFormat getDateTimeInstance(int dateStyle, int timeStyle) 

Source Link

Document

Gets the date/time formatter with the given date and time formatting styles for the default java.util.Locale.Category#FORMAT FORMAT locale.

Usage

From source file:org.methodize.nntprss.admin.AdminServlet.java

private void writeChannel(Writer writer, Channel channel, HttpServletRequest request, boolean refresh)
        throws IOException {
    if (channel == null) {
        writer.write("<b>Channel " + channel.getName() + " not found!</b>");
    } else {//from  w w  w .  ja  v a2s.c om
        ChannelManager channelManager = (ChannelManager) getServletContext()
                .getAttribute(AdminServer.SERVLET_CTX_RSS_MANAGER);

        DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL);

        String url = ((!refresh) ? channel.getUrl() : request.getParameter("URL"));
        boolean enabled = ((!refresh) ? channel.isEnabled() : isChecked(request, "enabled"));
        boolean parseAtAllCost = ((!refresh) ? channel.isParseAtAllCost()
                : isChecked(request, "parseAtAllCost"));
        //         boolean historical = ((!refresh) ? channel.isHistorical() : isChecked(request, "historical"));
        boolean postingEnabled = ((!refresh) ? channel.isPostingEnabled()
                : (!request.getParameter("postingEnabled").equals("false")));
        String publishAPI = ((!refresh) ? channel.getPublishAPI() : request.getParameter("publishAPI"));
        //            long pollingIntervalSeconds =
        //                ((!refresh)
        //                    ? channel.getPollingIntervalSeconds()
        //                    : Long.parseLong(request.getParameter("pollingInterval")));
        //            long expiration =
        //                ((!refresh)
        //                    ? channel.getExpiration()
        //                    : Long.parseLong(request.getParameter("expiration")));
        int categoryId = 0;
        if (!refresh) {
            if (channel.getCategory() != null) {
                categoryId = channel.getCategory().getId();
            }
        } else {
            categoryId = Integer.parseInt(request.getParameter("categoryId"));
        }

        writer.write("<form name='channel' action='?action=update' method='POST'>");
        writer.write(
                "<input type='hidden' name='name' value='" + HTMLHelper.escapeString(channel.getName()) + "'>");
        writer.write("<table class='tableborder'>");

        writer.write("<tr><th class='tableHead' colspan='2'>Channel Configuration</th></tr>");

        writer.write("<tr><td class='row1' align='right'>Title</td><td class='row2'>"
                + HTMLHelper.escapeString(channel.getTitle() == null ? "Unknown" : channel.getTitle())
                + "</td></tr>");
        writer.write("<tr><td class='row1' align='right'>Newsgroup Name</td><td class='row2'>"
                + HTMLHelper.escapeString(channel.getName()) + "</td></tr>");
        writer.write(
                "<tr><td class='row1' align='right'>URL</td><td class='row2'><input type='text' name='URL' value='"
                        + HTMLHelper.escapeString(url) + "' size='64'></td></tr>");
        writer.write("<tr><td class='row1' align='right'>Polling</td><td class='row2'>"
                + "<input name='enabled' type='checkbox' value='true' " + (enabled ? "checked>" : ">")
                + "</td></tr>");

        writer.write("<tr><td class='row1' align='right'>Polling Interval</td>");
        writer.write("<td class='row2'><select name='pollingInterval'>");

        if (channel.getPollingIntervalSeconds() == Channel.DEFAULT_POLLING_INTERVAL) {
            writer.write("<option selected value='" + Channel.DEFAULT_POLLING_INTERVAL
                    + "'>Use Default Polling Interval\n");
        } else {
            writer.write("<option selected value='" + channel.getPollingIntervalSeconds() + "'>"
                    + channel.getPollingIntervalSeconds() / 60 + " minutes\n");
        }

        writer.write("<option value='" + Channel.DEFAULT_POLLING_INTERVAL + "'>Use Default Polling Interval\n");
        for (int interval = 10; interval <= 120; interval += 10) {
            writer.write("<option value='" + (interval * 60) + "'>" + interval + " minutes\n");
        }
        writer.write("</select></td></tr>");

        writer.write(
                "<tr><td class='row1' align='right'>Parse-at-all-costs</td><td class='row2'><input name='parseAtAllCost' type='checkbox' value='true' "
                        + (parseAtAllCost ? "checked>" : ">")
                        + "<br><i>This will enable the experimental parse-at-all-costs RSS parser.  This feature supports the parsing of badly-formatted RSS feeds.</i></td></tr>");

        writer.write("<tr><td class='row1' align='right'>Status</td>");

        switch (channel.getStatus()) {
        case Channel.STATUS_NOT_FOUND:
            writer.write(
                    "<td class='chlerror' bgcolor='#FF0000'><font color='#FFFFFF'>Feed Web Server is returning File Not Found.</font>");
            break;
        case Channel.STATUS_INVALID_CONTENT:
            writer.write(
                    "<td class='chlerror' bgcolor='#FF0000'><font color='#FFFFFF'>Last feed document retrieved could not be parsed, <a class='chlerror' target='validate' href='http://feedvalidator.org/check?url="
                            + HTMLHelper.escapeString(url) + "'>check URL</a>.</font>");
            break;
        case Channel.STATUS_UNKNOWN_HOST:
            writer.write(
                    "<td class='chlerror' bgcolor='#FF0000'><font color='#FFFFFF'>Unable to contact Feed Web Server (Unknown Host).  Check URL.</font>");
            break;
        case Channel.STATUS_NO_ROUTE_TO_HOST:
            writer.write(
                    "<td class='chlerror' bgcolor='#FF0000'><font color='#FFFFFF'>Unable to contact Feed Web Server (No Route To Host).  Check URL.</font>");
            break;
        case Channel.STATUS_CONNECTION_TIMEOUT:
            writer.write(
                    "<td class='chlwarning' bgcolor='#FFFF00'><font color='#000000'>Currently unable to contact Feed Web Server (Connection timeout).</font>");
            break;
        case Channel.STATUS_SOCKET_EXCEPTION:
            writer.write(
                    "<td class='chlwarning' bgcolor='#FFFF00'><font color='#000000'>Currently unable to contact Feed Web Server (Socket exception).</font>");
            break;
        case Channel.STATUS_PROXY_AUTHENTICATION_REQUIRED:
            writer.write(
                    "<td class='chlerror' bgcolor='#FFFF00'><font color='#FFFFFF'>Proxy authentication required.  Please configure user name and password in <a class='chlerror' href='?action=showconfig'>System Configuration</a>.</font>");
            break;
        case Channel.STATUS_USER_AUTHENTICATION_REQUIRED:
            writer.write(
                    "<td class='chlerror' bgcolor='#FFFF00'><font color='#FFFFFF'>User authentication required. Please specific user name and password in the URL, e.g.<br>http://username:password@www.myhost.com/feed.xml</font>");
            break;
        default:
            writer.write("<td class='row2'>OK");
        }

        writer.write("</td></tr>");

        writer.write("<tr><td class='row1' align='right'>Last Polled</td><td class='row2'>"
                + ((channel.getLastPolled() == null) ? "Yet to be polled." : df.format(channel.getLastPolled()))
                + "</td></tr>");
        writer.write("<tr><td class='row1' align='right'>Last Modified</td><td class='row2'>");
        if (channel.getLastModified() == 0) {
            writer.write("Last modified not supplied by Feed Web Server");
        } else {
            writer.write(df.format(new Date(channel.getLastModified())));
        }
        writer.write("</td></tr>");
        writer.write("<tr><td class='row1' align='right'>Last ETag</td><td class='row2'>");
        if (channel.getLastETag() == null) {
            writer.write("ETag not supplied by Feed Web Server");
        } else {
            writer.write(channel.getLastETag());
        }
        writer.write("</td></tr>");

        writer.write("<tr><td class='row1' align='right'>Feed Type</td><td class='row2'>");
        if (channel.getRssVersion() == null) {
            writer.write("Unknown");
        } else {
            writer.write(channel.getRssVersion());
        }
        writer.write("</td></tr>");

        //         writer.write("<tr><td class='row1' align='right'>Historical</td><td class='row2'><input name='historical' type='checkbox' value='true' "
        //            + (historical ? "checked>" : ">")
        //            + "</td></tr>");

        writeExpiration(writer, channel);

        writer.write("<tr><td class='row1' align='right'>Category</td>");
        writer.write("<td class='row2'><select name='categoryId'>");

        writeOption(writer, "[No Category]", 0, categoryId);
        Iterator categories = channelManager.categories();
        while (categories.hasNext()) {
            Category category = (Category) categories.next();
            writeOption(writer, category.getName(), category.getId(), categoryId);
        }
        writer.write("</select></td></tr>");

        writer.write("<tr><td class='row1' align='right'>Managing Editor</td><td class='row2'>");
        if (channel.getManagingEditor() != null) {
            writer.write(
                    "<a href='mailto:" + URLEncoder.encode(RSSHelper.parseEmail(channel.getManagingEditor()))
                            + "'>" + HTMLHelper.escapeString(channel.getManagingEditor()) + "</a>");
        } else {
            writer.write("Unknown");
        }

        writer.write("</td></tr>");
        writer.write(
                "<tr><td class='row1' align='right'>Posting</td><td class='row2'><select name='postingEnabled' onChange='this.form.action=\"?action=editchlrefresh\"; this.form.submit();'>"
                        + "<option " + (postingEnabled ? "selected" : "") + ">true" + "<option "
                        + (!postingEnabled ? "selected" : "") + ">false" + "</select></td></tr>");

        if (postingEnabled) {

            writer.write("<tr><th class='subHead' colspan='2' align='center'>Posting Configuration</td></tr>");

            writer.write(
                    "<tr><td class='row1' align='right'>API</td><td class='row2'><select name='publishAPI' onChange='this.form.action=\"?action=editchlrefresh&publishapichange=true\"; this.form.submit();'>"
                            + "<option value='blogger' "
                            + (publishAPI == null || publishAPI.equals("blogger") ? "selected" : "")
                            + ">Blogger" + "<option value='livejournal' "
                            + (publishAPI != null && publishAPI.equals("livejournal") ? "selected" : "")
                            + ">LiveJournal" + "<option value='metaweblog' "
                            + (publishAPI != null && publishAPI.equals("metaweblog") ? "selected" : "")
                            + ">MetaWeblog"
                            //               + "<option " + (!postingEnabled ? "selected" : "") + ">false"
                            + "</select></td></tr>");

            if (publishAPI == null || publishAPI.equals("blogger")) {
                // Default API
                String publishUrl = null;
                String blogId = null;
                String userName = null;
                String password = null;
                boolean autoPublish = true;

                if (refresh) {
                    // If a refresh, get the parameter values from the parameter collection
                    if (request.getParameter("publishapichange") == null) {
                        publishUrl = request.getParameter(BloggerPublisher.PROP_PUBLISHER_URL);
                    }
                    blogId = (String) request.getParameter(BloggerPublisher.PROP_BLOG_ID);
                    userName = (String) request.getParameter(BloggerPublisher.PROP_USERNAME);
                    password = (String) request.getParameter(BloggerPublisher.PROP_PASSWORD);
                    String autoPublishStr = request.getParameter(BloggerPublisher.PROP_PUBLISH);
                    autoPublish = (autoPublishStr != null && autoPublishStr.equals("false")) ? false : true;
                } else {
                    // If a initial channel view, extract parameter from the Channel publish config map
                    Map publishConfig = channel.getPublishConfig();
                    if (publishConfig != null) {
                        publishUrl = (String) publishConfig.get(BloggerPublisher.PROP_PUBLISHER_URL);
                        blogId = (String) publishConfig.get(BloggerPublisher.PROP_BLOG_ID);
                        userName = (String) publishConfig.get(BloggerPublisher.PROP_USERNAME);
                        password = (String) publishConfig.get(BloggerPublisher.PROP_PASSWORD);
                        if (password != null)
                            password = PASSWORD_MAGIC_KEY;
                        String autoPublishStr = (String) publishConfig.get(BloggerPublisher.PROP_PUBLISH);
                        autoPublish = (autoPublishStr != null && autoPublishStr.equals("false")) ? false : true;
                    }
                }

                // Make sure that everything has a value, especially if publish has just been enabled
                if (publishUrl == null)
                    publishUrl = "http://plant.blogger.com/api/RPC2";
                if (blogId == null)
                    blogId = "";
                if (userName == null)
                    userName = "";
                if (password == null)
                    password = "";

                writer.write("<tr><td class='row1' align='right'>URL</td>");
                writer.write("<td class='row2'><input name='" + BloggerPublisher.PROP_PUBLISHER_URL
                        + "' type='text' size='64' value='" + HTMLHelper.escapeString(publishUrl)
                        + "'></td></tr>");

                writer.write("<tr><td class='row1' align='right'>Blog Id</td>");
                writer.write("<td class='row2'><input name='" + BloggerPublisher.PROP_BLOG_ID
                        + "' type='text' value='" + HTMLHelper.escapeString(blogId) + "'></td></tr>");

                writer.write("<tr><td class='row1' align='right'>Username</td>");
                writer.write("<td class='row2'><input name='" + BloggerPublisher.PROP_USERNAME
                        + "' type='text' value='" + HTMLHelper.escapeString(userName) + "'></td></tr>");

                writer.write("<tr><td class='row1' align='right'>Password</td>");
                writer.write("<td class='row2'><input name='" + BloggerPublisher.PROP_PASSWORD
                        + "' type='password' value='" + HTMLHelper.escapeString(password) + "'></td></tr>");

                writer.write("<tr><td class='row1' align='right'>Auto Publish</td>");
                writer.write("<td class='row2'><input name='" + BloggerPublisher.PROP_PUBLISH
                        + "' type='checkbox' value='true' " + (autoPublish ? "checked" : "") + "></td></tr>");

            } else if (publishAPI.equals("metaweblog")) {
                String publishUrl = null;
                String blogId = null;
                String userName = null;
                String password = null;
                boolean autoPublish = true;

                if (refresh) {
                    // If a refresh, get the parameter values from the parameter collection
                    if (request.getParameter("publishapichange") == null) {
                        publishUrl = request.getParameter(MetaWeblogPublisher.PROP_PUBLISHER_URL);
                    }
                    blogId = (String) request.getParameter(BloggerPublisher.PROP_BLOG_ID);
                    if (blogId != null && blogId.length() == 0)
                        blogId = "home";

                    userName = (String) request.getParameter(MetaWeblogPublisher.PROP_USERNAME);
                    password = (String) request.getParameter(MetaWeblogPublisher.PROP_PASSWORD);
                    String autoPublishStr = request.getParameter(MetaWeblogPublisher.PROP_PUBLISH);
                    autoPublish = (autoPublishStr != null && autoPublishStr.equals("false")) ? false : true;
                } else {
                    // If a initial channel view, extract parameter from the Channel publish config map
                    Map publishConfig = channel.getPublishConfig();
                    if (publishConfig != null) {
                        publishUrl = (String) publishConfig.get(MetaWeblogPublisher.PROP_PUBLISHER_URL);
                        userName = (String) publishConfig.get(MetaWeblogPublisher.PROP_USERNAME);
                        password = (String) publishConfig.get(MetaWeblogPublisher.PROP_PASSWORD);
                        if (password != null)
                            password = PASSWORD_MAGIC_KEY;
                        String autoPublishStr = (String) publishConfig.get(MetaWeblogPublisher.PROP_PUBLISH);
                        autoPublish = (autoPublishStr != null && autoPublishStr.equals("false")) ? false : true;
                    }
                }

                // Make sure that everything has a value, especially if publish has just been enabled
                if (publishUrl == null)
                    publishUrl = "http://127.0.0.1:5335/RPC2";
                if (blogId == null)
                    blogId = "home";
                if (userName == null)
                    userName = "";
                if (password == null)
                    password = "";

                writer.write("<tr><td class='row1' align='right'>URL</td>");
                writer.write("<td class='row2'><input name='" + MetaWeblogPublisher.PROP_PUBLISHER_URL
                        + "' type='text' size='64' value='" + HTMLHelper.escapeString(publishUrl)
                        + "'><br><i>Ensure that the URL points to your MetaWeblog (e.g. Radio Userland) host</i></td></tr>");

                writer.write("<tr><td class='row1' align='right'>Blog Id</td>");
                writer.write("<td class='row2'><input name='" + BloggerPublisher.PROP_BLOG_ID
                        + "' type='text' value='" + HTMLHelper.escapeString(blogId) + "'></td></tr>");

                writer.write("<tr><td class='row1' align='right'>Username</td>");
                writer.write("<td class='row2'><input name='" + MetaWeblogPublisher.PROP_USERNAME
                        + "' type='text' value='" + HTMLHelper.escapeString(userName) + "'></td></tr>");

                writer.write("<tr><td class='row1' align='right'>Password</td>");
                writer.write("<td class='row2'><input name='" + MetaWeblogPublisher.PROP_PASSWORD
                        + "' type='password' value='" + HTMLHelper.escapeString(password) + "'></td></tr>");

                writer.write("<tr><td class='row1' align='right'>Auto Publish</td>");
                writer.write("<td class='row2'><input name='" + MetaWeblogPublisher.PROP_PUBLISH
                        + "' type='checkbox' value='true' " + (autoPublish ? "checked" : "") + "></td></tr>");

            } else if (publishAPI.equals("livejournal")) {
                String publishUrl = null;
                String userName = null;
                String password = null;

                if (refresh) {
                    // If a refresh, get the parameter values from the parameter collection
                    if (request.getParameter("publishapichange") == null) {
                        publishUrl = request.getParameter(LiveJournalPublisher.PROP_PUBLISHER_URL);
                    }
                    userName = (String) request.getParameter(LiveJournalPublisher.PROP_USERNAME);
                    password = (String) request.getParameter(LiveJournalPublisher.PROP_PASSWORD);
                } else {
                    // If a initial channel view, extract parameter from the Channel publish config map
                    Map publishConfig = channel.getPublishConfig();
                    if (publishConfig != null) {
                        publishUrl = (String) publishConfig.get(LiveJournalPublisher.PROP_PUBLISHER_URL);
                        userName = (String) publishConfig.get(LiveJournalPublisher.PROP_USERNAME);
                        password = (String) publishConfig.get(LiveJournalPublisher.PROP_PASSWORD);
                        if (password != null)
                            password = PASSWORD_MAGIC_KEY;
                    }
                }

                // Make sure that everything has a value, especially if publish has just been enabled
                if (publishUrl == null)
                    publishUrl = "http://www.livejournal.com/interface/xmlrpc";
                if (userName == null)
                    userName = "";
                if (password == null)
                    password = "";

                writer.write("<tr><td class='row1' align='right'>URL</td>");
                writer.write("<td class='row2'><input name='" + LiveJournalPublisher.PROP_PUBLISHER_URL
                        + "' type='text' size='64' value='" + HTMLHelper.escapeString(publishUrl)
                        + "'><br></td></tr>");

                writer.write("<tr><td class='row1' align='right'>Username</td>");
                writer.write("<td class='row2'><input name='" + LiveJournalPublisher.PROP_USERNAME
                        + "' type='text' value='" + HTMLHelper.escapeString(userName) + "'></td></tr>");

                writer.write("<tr><td class='row1' align='right'>Password</td>");
                writer.write("<td class='row2'><input name='" + LiveJournalPublisher.PROP_PASSWORD
                        + "' type='password' value='" + HTMLHelper.escapeString(password) + "'></td></tr>");

            }
        }

        writer.write(
                "<tr><td class='row2' align='center' colspan='2'><input type='submit' name='update' value='Update'>&nbsp;&nbsp;&nbsp;<input type='submit' name='delete' onClick='return confirm(\"Are you sure you want to delete this channel?\");' value='Delete'></td></tr>");
        writer.write("</table>");
        writer.write("</form>");
    }
}

From source file:com.coact.kochzap.CaptureActivity.java

private void handleDecodeInternally(Result rawResult, ResultHandler resultHandler, Bitmap barcode) {

    maybeSetClipboard(resultHandler);/*from  www .  jav a 2s  .co  m*/

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);

    if (resultHandler.getDefaultButtonID() != null
            && prefs.getBoolean(PreferencesActivity.KEY_AUTO_OPEN_WEB, false)) {
        resultHandler.handleButtonPress(resultHandler.getDefaultButtonID());
        return;
    }

    statusView.setVisibility(View.GONE);
    viewfinderView.setVisibility(View.GONE);
    resultView.setVisibility(View.VISIBLE);

    ImageView barcodeImageView = (ImageView) findViewById(R.id.barcode_image_view);
    if (barcode == null) {
        barcodeImageView.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.launcher_icon));
    } else {
        barcodeImageView.setImageBitmap(barcode);
    }

    TextView formatTextView = (TextView) findViewById(R.id.format_text_view);
    formatTextView.setText(rawResult.getBarcodeFormat().toString());

    TextView typeTextView = (TextView) findViewById(R.id.type_text_view);
    typeTextView.setText(resultHandler.getType().toString());

    DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
    TextView timeTextView = (TextView) findViewById(R.id.time_text_view);
    timeTextView.setText(formatter.format(rawResult.getTimestamp()));

    TextView metaTextView = (TextView) findViewById(R.id.meta_text_view);
    View metaTextViewLabel = findViewById(R.id.meta_text_view_label);
    metaTextView.setVisibility(View.GONE);
    metaTextViewLabel.setVisibility(View.GONE);
    Map<ResultMetadataType, Object> metadata = rawResult.getResultMetadata();
    if (metadata != null) {
        StringBuilder metadataText = new StringBuilder(20);
        for (Map.Entry<ResultMetadataType, Object> entry : metadata.entrySet()) {
            if (DISPLAYABLE_METADATA_TYPES.contains(entry.getKey())) {
                metadataText.append(entry.getValue()).append('\n');
            }
        }
        if (metadataText.length() > 0) {
            metadataText.setLength(metadataText.length() - 1);
            metaTextView.setText(metadataText);
            metaTextView.setVisibility(View.VISIBLE);
            metaTextViewLabel.setVisibility(View.VISIBLE);
        }
    }

    CharSequence displayContents = resultHandler.getDisplayContents();
    TextView contentsTextView = (TextView) findViewById(R.id.contents_text_view);
    contentsTextView.setText(displayContents);
    int scaledSize = Math.max(22, 32 - displayContents.length() / 4);
    contentsTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, scaledSize);

    TextView supplementTextView = (TextView) findViewById(R.id.contents_supplement_text_view);
    supplementTextView.setText("");
    supplementTextView.setOnClickListener(null);
    if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(PreferencesActivity.KEY_SUPPLEMENTAL,
            true)) {
        SupplementalInfoRetriever.maybeInvokeRetrieval(supplementTextView, resultHandler.getResult(),
                historyManager, this);
    }

    int buttonCount = resultHandler.getButtonCount();
    ViewGroup buttonView = (ViewGroup) findViewById(R.id.result_button_view);
    buttonView.requestFocus();
    for (int x = 0; x < ResultHandler.MAX_BUTTON_COUNT; x++) {
        TextView button = (TextView) buttonView.getChildAt(x);
        if (x < buttonCount) {
            button.setVisibility(View.VISIBLE);
            button.setText(resultHandler.getButtonText(x));
            button.setOnClickListener(new ResultButtonListener(resultHandler, x));
        } else {
            button.setVisibility(View.GONE);
        }
    }

}

From source file:org.muse.mneme.impl.ImportServiceImpl.java

/**
 * Add a formatted date to a source string, using a message selector.
 * //from  w w w. jav a 2  s .  c o  m
 * @param selector
 *        The message selector.
 * @param source
 *        The original string.
 * @param date
 *        The date to format.
 * @return The source and date passed throught the selector message.
 */
protected String addDate(String selector, String source, Date date) {
    // format the date
    DateFormat format = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
    String fmt = format.format(date);

    // the args
    Object[] args = new Object[2];
    args[0] = source;
    args[1] = fmt;

    // format the works
    String rv = this.messages.getFormattedMessage(selector, args);

    return rv;
}

From source file:com.cleverzone.zhizhi.capture.CaptureActivity.java

private void handleDecodeInternally(Result rawResult, ResultHandler resultHandler, Bitmap barcode) {

    final CharSequence displayContents = resultHandler.getDisplayContents();

    //        if (copyToClipboard && !resultHandler.areContentsSecure()) {
    //            ClipboardInterface.setText(displayContents, this);
    //        }/*www  .j a va  2 s.  co  m*/

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);

    //        if (resultHandler.getDefaultButtonID() != null && prefs.getBoolean(PreferencesActivity.KEY_AUTO_OPEN_WEB, false)) {
    //            resultHandler.handleButtonPress(resultHandler.getDefaultButtonID());
    //            return;
    //        }

    statusView.setVisibility(View.GONE);
    viewfinderView.setVisibility(View.GONE);
    resultView.setVisibility(View.VISIBLE);

    ImageView barcodeImageView = (ImageView) findViewById(R.id.barcode_image_view);
    if (barcode == null) {
        barcodeImageView.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher));
    } else {
        barcodeImageView.setImageBitmap(barcode);
    }

    TextView formatTextView = (TextView) findViewById(R.id.format_text_view);
    formatTextView.setText(rawResult.getBarcodeFormat().toString());

    TextView typeTextView = (TextView) findViewById(R.id.type_text_view);
    typeTextView.setText(resultHandler.getType().toString());

    DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
    TextView timeTextView = (TextView) findViewById(R.id.time_text_view);
    timeTextView.setText(formatter.format(new Date(rawResult.getTimestamp())));

    TextView metaTextView = (TextView) findViewById(R.id.meta_text_view);
    View metaTextViewLabel = findViewById(R.id.meta_text_view_label);
    metaTextView.setVisibility(View.GONE);
    metaTextViewLabel.setVisibility(View.GONE);
    Map<ResultMetadataType, Object> metadata = rawResult.getResultMetadata();
    if (metadata != null) {
        StringBuilder metadataText = new StringBuilder(20);
        for (Map.Entry<ResultMetadataType, Object> entry : metadata.entrySet()) {
            if (DISPLAYABLE_METADATA_TYPES.contains(entry.getKey())) {
                metadataText.append(entry.getValue()).append('\n');
            }
        }
        if (metadataText.length() > 0) {
            metadataText.setLength(metadataText.length() - 1);
            metaTextView.setText(metadataText);
            metaTextView.setVisibility(View.VISIBLE);
            metaTextViewLabel.setVisibility(View.VISIBLE);
        }
    }

    final TextView contentsTextView = (TextView) findViewById(R.id.contents_text_view);
    final String baseUrl = "http://qrk.kuaipai.cn/loganal/base/scan/show-json-advert.action?code=";
    new Thread(new Runnable() {
        @Override
        public void run() {
            HttpGet get = new HttpGet(baseUrl + displayContents);
            Log.e(TAG, "full url = " + baseUrl + displayContents);
            HttpClient client = new DefaultHttpClient();
            try {
                HttpResponse response = client.execute(get);
                String json = EntityUtils.toString(response.getEntity(), "UTF-8");
                JSONObject jsonObject = new JSONObject(json);
                NetScanResult result = new NetScanResult();
                result.name = jsonObject.getString("name");
                result.url = jsonObject.getString("img");
                Message message = new Message();
                message.obj = result;
                message.what = 1;
                mNetHandler.sendMessage(message);

            } catch (Exception e) {
                mNetHandler.sendEmptyMessage(-1);
                e.printStackTrace();
            }
        }
    }).start();
    //        contentsTextView.setText(displayContents);
    int scaledSize = Math.max(22, 32 - displayContents.length() / 4);
    contentsTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, scaledSize);

    TextView supplementTextView = (TextView) findViewById(R.id.contents_supplement_text_view);
    supplementTextView.setText("");
    supplementTextView.setOnClickListener(null);
    //        if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(
    //                PreferencesActivity.KEY_SUPPLEMENTAL, true)) {
    //            SupplementalInfoRetriever.maybeInvokeRetrieval(supplementTextView,
    //                    resultHandler.getResult(),
    //                    historyManager,
    //                    this);
    //        }

    int buttonCount = resultHandler.getButtonCount();
    ViewGroup buttonView = (ViewGroup) findViewById(R.id.result_button_view);
    buttonView.requestFocus();
    for (int x = 0; x < ResultHandler.MAX_BUTTON_COUNT; x++) {
        TextView button = (TextView) buttonView.getChildAt(x);
        if (x < buttonCount) {
            button.setVisibility(View.VISIBLE);
            button.setText(resultHandler.getButtonText(x));
            button.setOnClickListener(new ResultButtonListener(resultHandler, x));
        } else {
            button.setVisibility(View.GONE);
        }
    }

}

From source file:net.oschina.app.v2.activity.zxing.CaptureActivity.java

private void handleDecodeInternally(Result rawResult, ResultHandler resultHandler, Bitmap barcode) {
    //- ------------------------------------------------------- //
    String text = rawResult.getText();
    if (text != null && StringUtils.isUrl(text)) {
        if (text.contains("scan_login")) {
            statusView.setVisibility(View.GONE);
            viewfinderView.setVisibility(View.GONE);
            showConfirmLogin(text);/*  w  ww  .j  av  a2s  .c  om*/
            return;
        }
        if (text.contains("oschina.net")) {
            UIHelper.showUrlRedirect(CaptureActivity.this, text);
            finish();
            return;
        }
    }
    try {
        BarCode2 bc = BarCode2.parse(text);
        int type = bc.getType();
        switch (type) {
        case BarCode2.SIGN_IN:// 
            handleSignIn(bc);
            return;
        default:
            break;
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
    //- ------------------------------------------------------- //
    CharSequence displayContents = resultHandler.getDisplayContents();

    if (copyToClipboard && !resultHandler.areContentsSecure()) {
        ClipboardInterface.setText(displayContents, this);
    }

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);

    if (resultHandler.getDefaultButtonID() != null
            && prefs.getBoolean(PreferencesActivity.KEY_AUTO_OPEN_WEB, false)) {
        resultHandler.handleButtonPress(resultHandler.getDefaultButtonID());
        return;
    }

    statusView.setVisibility(View.GONE);
    viewfinderView.setVisibility(View.GONE);
    resultView.setVisibility(View.VISIBLE);

    ImageView barcodeImageView = (ImageView) findViewById(R.id.barcode_image_view);
    if (barcode == null) {
        barcodeImageView.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.app_icon));
    } else {
        barcodeImageView.setImageBitmap(barcode);
    }

    TextView formatTextView = (TextView) findViewById(R.id.format_text_view);
    formatTextView.setText(rawResult.getBarcodeFormat().toString());

    TextView typeTextView = (TextView) findViewById(R.id.type_text_view);
    typeTextView.setText(resultHandler.getType().toString());

    DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
    TextView timeTextView = (TextView) findViewById(R.id.time_text_view);
    timeTextView.setText(formatter.format(new Date(rawResult.getTimestamp())));

    TextView metaTextView = (TextView) findViewById(R.id.meta_text_view);
    View metaTextViewLabel = findViewById(R.id.meta_text_view_label);
    metaTextView.setVisibility(View.GONE);
    metaTextViewLabel.setVisibility(View.GONE);
    Map<ResultMetadataType, Object> metadata = rawResult.getResultMetadata();
    if (metadata != null) {
        StringBuilder metadataText = new StringBuilder(20);
        for (Map.Entry<ResultMetadataType, Object> entry : metadata.entrySet()) {
            if (DISPLAYABLE_METADATA_TYPES.contains(entry.getKey())) {
                metadataText.append(entry.getValue()).append('\n');
            }
        }
        if (metadataText.length() > 0) {
            metadataText.setLength(metadataText.length() - 1);
            metaTextView.setText(metadataText);
            metaTextView.setVisibility(View.VISIBLE);
            metaTextViewLabel.setVisibility(View.VISIBLE);
        }
    }

    TextView contentsTextView = (TextView) findViewById(R.id.contents_text_view);
    contentsTextView.setText(displayContents);
    int scaledSize = Math.max(22, 32 - displayContents.length() / 4);
    contentsTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, scaledSize);

    TextView supplementTextView = (TextView) findViewById(R.id.contents_supplement_text_view);
    supplementTextView.setText("");
    supplementTextView.setOnClickListener(null);
    if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(PreferencesActivity.KEY_SUPPLEMENTAL,
            true)) {
        //SupplementalInfoRetriever.maybeInvokeRetrieval(supplementTextView,
        //        resultHandler.getResult(),
        //        historyManager,
        //        this);
    }

    int buttonCount = resultHandler.getButtonCount();
    ViewGroup buttonView = (ViewGroup) findViewById(R.id.result_button_view);
    buttonView.requestFocus();
    for (int x = 0; x < ResultHandler.MAX_BUTTON_COUNT; x++) {
        TextView button = (TextView) buttonView.getChildAt(x);
        if (x < buttonCount) {
            button.setVisibility(View.VISIBLE);
            button.setText(resultHandler.getButtonText(x));
            button.setOnClickListener(new ResultButtonListener(resultHandler, x));
        } else {
            button.setVisibility(View.GONE);
        }
    }
}

From source file:com.farmerbb.notepad.activity.MainActivity.java

@Override
public String loadNoteDate(String filename) {
    Date lastModified = new Date(Long.parseLong(filename));
    return (DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(lastModified));
}

From source file:ca.mudar.parkcatcher.ui.fragments.DetailsFragment.java

/**
 * Handle toggling of starred checkbox.//  ww  w  . j a v  a 2  s . c o m
 */
private void onCheckedChanged(boolean wasFavorite) {
    int message = R.string.toast_favorites_added;

    if (wasFavorite) {
        /**
         * Remove from favorites.
         */
        String[] args = new String[] { Integer.toString(mIdPost) };
        mHandler.startDelete(FavoritesToggleQuery._TOKEN, null, Posts.CONTENT_STARRED_URI,
                Favorites.ID_POST + "=?", args);
        message = R.string.toast_favorites_removed;
    } else {
        /**
         * Add to favorites
         */
        final ContentValues values = new ContentValues();
        values.put(Favorites.ID_POST, mIdPost);
        if ((mFavoriteLabel != null) && (mFavoriteLabel.length() > 0)) {
            values.put(Favorites.LABEL, mFavoriteLabel);
        } else {
            String timestamp = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT)
                    .format(new Date());

            values.put(Favorites.LABEL, timestamp);
        }

        mHandler.startInsert(Posts.CONTENT_STARRED_URI, values);
    }

    parkingApp.showToastText(message, Toast.LENGTH_LONG);
}

From source file:com.anjalimacwan.MainActivity.java

@Override
public String loadNoteDate(String filename) throws IOException {
    Date lastModified = new Date(Long.parseLong(filename));
    return (DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(lastModified));
}

From source file:com.xgf.inspection.qrcode.google.zxing.client.CaptureActivity.java

private void handleDecodeInternally(Result rawResult, ResultHandler resultHandler, Bitmap barcode) {
    statusView.setVisibility(View.GONE);
    viewfinderView.setVisibility(View.GONE);
    resultView.setVisibility(View.VISIBLE);

    ImageView barcodeImageView = (ImageView) findViewById(R.id.barcode_image_view);
    if (barcode == null) {
        barcodeImageView.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.qr_scan));
    } else {/* w w  w  .  j a  va2  s . co m*/
        barcodeImageView.setImageBitmap(barcode);
    }

    TextView formatTextView = (TextView) findViewById(R.id.format_text_view);
    formatTextView.setText(rawResult.getBarcodeFormat().toString());

    TextView typeTextView = (TextView) findViewById(R.id.type_text_view);
    typeTextView.setText(resultHandler.getType().toString());

    DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
    String formattedTime = formatter.format(new Date(rawResult.getTimestamp()));
    TextView timeTextView = (TextView) findViewById(R.id.time_text_view);
    timeTextView.setText(formattedTime);

    TextView metaTextView = (TextView) findViewById(R.id.meta_text_view);
    View metaTextViewLabel = findViewById(R.id.meta_text_view_label);
    metaTextView.setVisibility(View.GONE);
    metaTextViewLabel.setVisibility(View.GONE);
    Map<ResultMetadataType, Object> metadata = rawResult.getResultMetadata();
    if (metadata != null) {
        StringBuilder metadataText = new StringBuilder(20);
        for (Map.Entry<ResultMetadataType, Object> entry : metadata.entrySet()) {
            if (DISPLAYABLE_METADATA_TYPES.contains(entry.getKey())) {
                metadataText.append(entry.getValue()).append('\n');
            }
        }
        if (metadataText.length() > 0) {
            metadataText.setLength(metadataText.length() - 1);
            metaTextView.setText(metadataText);
            metaTextView.setVisibility(View.VISIBLE);
            metaTextViewLabel.setVisibility(View.VISIBLE);
        }
    }

    TextView contentsTextView = (TextView) findViewById(R.id.contents_text_view);
    CharSequence displayContents = resultHandler.getDisplayContents();
    contentsTextView.setText(displayContents);
    // Crudely scale betweeen 22 and 32 -- bigger font for shorter text
    int scaledSize = Math.max(22, 32 - displayContents.length() / 4);
    contentsTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, scaledSize);

    TextView supplementTextView = (TextView) findViewById(R.id.contents_supplement_text_view);
    supplementTextView.setText("");
    supplementTextView.setOnClickListener(null);
    if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(PreferencesActivity.KEY_SUPPLEMENTAL,
            true)) {
        SupplementalInfoRetriever.maybeInvokeRetrieval(supplementTextView, resultHandler.getResult(),
                historyManager, this);
    }

    int buttonCount = resultHandler.getButtonCount();
    ViewGroup buttonView = (ViewGroup) findViewById(R.id.result_button_view);
    buttonView.requestFocus();
    for (int x = 0; x < ResultHandler.MAX_BUTTON_COUNT; x++) {
        TextView button = (TextView) buttonView.getChildAt(x);
        if (x < buttonCount) {
            button.setVisibility(View.VISIBLE);
            button.setText(resultHandler.getButtonText(x));
            button.setOnClickListener(new ResultButtonListener(resultHandler, x));
        } else {
            button.setVisibility(View.GONE);
        }
    }

    if (copyToClipboard && !resultHandler.areContentsSecure()) {
        ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
        if (displayContents != null) {
            clipboard.setText(displayContents);
        }
    }
}