Search in sources :

Example 16 with Formatter

use of java.util.Formatter in project neo4j-mobile-android by neo4j-contrib.

the class NodeActivity method showRelatedStartNodes.

private void showRelatedStartNodes(Set<Long> nodeIdSet) {
    final List<Long> nodeIds = new ArrayList<Long>(nodeIdSet);
    final CharSequence[] items = new CharSequence[nodeIds.size()];
    int index = 0;
    for (Long nodeId : nodeIds) {
        items[index] = nodeId.toString();
        index++;
    }
    Formatter formatter = new Formatter();
    formatter.format(getResources().getString(R.string.node_select_related_node_question), centerNodeId);
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(formatter.toString());
    builder.setItems(items, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int item) {
            showNodeActivity(nodeIds.get(item), true);
        }
    });
    AlertDialog dialog = builder.create();
    dialog.show();
    formatter.close();
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) Formatter(java.util.Formatter) ArrayList(java.util.ArrayList)

Example 17 with Formatter

use of java.util.Formatter in project neo4j-mobile-android by neo4j-contrib.

the class NodePropertiesActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTitle(getResources().getString(R.string.database_title) + " " + dbManager.getCurrentNeo4jDatabaseName());
    nodeCreatePropertyButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            askCreateProperty();
        }
    });
    nodeDeleteButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            confirmDeletionOfNode();
        }
    });
    Formatter formatter = new Formatter();
    formatter.format(getResources().getString(R.string.node_properties_text), nodeId);
    nodePropertiesTitle.setText(formatter.toString());
    formatter.close();
}
Also used : Formatter(java.util.Formatter) ContentView(roboguice.inject.ContentView) View(android.view.View) InjectView(roboguice.inject.InjectView) TextView(android.widget.TextView)

Example 18 with Formatter

use of java.util.Formatter in project neo4j-mobile-android by neo4j-contrib.

the class NodePropertiesActivity method showPropertyKeyValueEmptyError.

private void showPropertyKeyValueEmptyError(String key, String value) {
    AlertDialog dialog = new AlertDialog.Builder(this).create();
    dialog.setTitle(R.string.error_title);
    Formatter formatter = new Formatter();
    formatter.format(getResources().getString(R.string.property_key_or_value_empty_error), key, value);
    dialog.setMessage(formatter.toString());
    dialog.setButton(getResources().getString(android.R.string.yes), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });
    dialog.show();
    formatter.close();
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) Formatter(java.util.Formatter)

Example 19 with Formatter

use of java.util.Formatter in project neo4j-mobile-android by neo4j-contrib.

the class NodePropertiesActivity method confirmDeletionOfNode.

private void confirmDeletionOfNode() {
    AlertDialog dialog = new AlertDialog.Builder(this).create();
    dialog.setTitle(R.string.node_delete_title);
    Formatter formatter = new Formatter();
    formatter.format(getResources().getString(R.string.node_delete_question), nodeId);
    dialog.setMessage(formatter.toString());
    dialog.setButton(getResources().getString(android.R.string.yes), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            try {
                GraphDatabase database = dbManager.getCurrentNeo4jDatabase();
                database.beginTx();
                try {
                    ParcelableNode node = database.getNodeById(nodeId);
                    ParcelableNode referenceNode = database.getReferenceNode();
                    if (nodeId != referenceNode.getId()) {
                        List<ParcelableRelationship> relationships = node.getRelationships();
                        for (ParcelableRelationship relationship : relationships) {
                            database.deleteRelationship(relationship.getId());
                        }
                        database.deleteNode(nodeId);
                        database.txSuccess();
                    } else {
                        showCannotDeleteReferenceNodeError();
                    }
                } finally {
                    database.txFinish();
                }
                Intent data = new Intent();
                data.putExtra(DBInspectorConstants.INTENTEXTRA_NODE_DELETED, true);
                setResult(RESULT_OK, data);
                finish();
            } catch (Exception e) {
                Ln.e(e, "failed to delete node with id '" + nodeId + "'.");
                showErrorDialog();
            }
        }
    });
    dialog.setButton2(getResources().getString(android.R.string.no), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });
    dialog.show();
    formatter.close();
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) GraphDatabase(org.neo4j.android.client.GraphDatabase) Formatter(java.util.Formatter) Intent(android.content.Intent) ParcelableNode(org.neo4j.android.common.ParcelableNode) ParcelableRelationship(org.neo4j.android.common.ParcelableRelationship) List(java.util.List)

Example 20 with Formatter

use of java.util.Formatter in project neo4j-mobile-android by neo4j-contrib.

the class NodePropertiesActivity method confirmDeletionOfProperty.

private void confirmDeletionOfProperty(final String key, final Object value) {
    AlertDialog dialog = new AlertDialog.Builder(this).create();
    dialog.setTitle(R.string.property_delete_title);
    Formatter formatter = new Formatter();
    formatter.format(getResources().getString(R.string.property_delete_from_node_question), key, value, nodeId);
    dialog.setMessage(formatter.toString());
    dialog.setButton(getResources().getString(android.R.string.ok), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            try {
                GraphDatabase database = dbManager.getCurrentNeo4jDatabase();
                database.beginTx();
                try {
                    ParcelableNode node = database.getNodeById(nodeId);
                    node.removeProperty(key);
                    database.updateNode(node);
                    database.txSuccess();
                } finally {
                    database.txFinish();
                }
            } catch (Exception e) {
                Ln.e(e, "failed to delete property with key '" + key + "' and value '" + value + "' from node with id '" + nodeId + "'.");
                showErrorDialog();
            }
        }
    });
    dialog.setButton2(getResources().getString(android.R.string.cancel), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });
    dialog.show();
    formatter.close();
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) GraphDatabase(org.neo4j.android.client.GraphDatabase) Formatter(java.util.Formatter) ParcelableNode(org.neo4j.android.common.ParcelableNode)

Aggregations

Formatter (java.util.Formatter)313 File (java.io.File)18 AlertDialog (android.app.AlertDialog)14 DialogInterface (android.content.DialogInterface)14 Justif (aQute.lib.justif.Justif)12 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)10 Map (java.util.Map)10 Test (org.junit.Test)10 BigInteger (java.math.BigInteger)9 Locale (java.util.Locale)9 IOException (java.io.IOException)8 UnknownFormatConversionException (java.util.UnknownFormatConversionException)8 UnsupportedEncodingException (java.io.UnsupportedEncodingException)7 BigDecimal (java.math.BigDecimal)7 IllegalFormatException (java.util.IllegalFormatException)7 IllegalFormatFlagsException (java.util.IllegalFormatFlagsException)7 Resources (android.content.res.Resources)6 LayoutBuilder (android.text.StaticLayoutTest.LayoutBuilder)6 FormatFlagsConversionMismatchException (java.util.FormatFlagsConversionMismatchException)6