Search in sources :

Example 21 with Formatter

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

the class MainActivity method confirmOpenOfNeo4jDatabase.

private void confirmOpenOfNeo4jDatabase(final String databaseName) {
    AlertDialog dialog = new AlertDialog.Builder(this).create();
    dialog.setTitle(R.string.main_open_database_title);
    Formatter formatter = new Formatter();
    formatter.format(getResources().getString(R.string.main_open_database_question), databaseName);
    dialog.setMessage(formatter.toString());
    dialog.setButton(getResources().getString(android.R.string.yes), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (dbManager.isCurrentNeo4jDatabaseOpen()) {
                shutdownNeo4jDatabase(dbManager.getCurrentNeo4jDatabaseName());
            }
            openOrCreateNeo4jDatabase(databaseName);
        }
    });
    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) Formatter(java.util.Formatter)

Example 22 with Formatter

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

the class RelationshipActivity method askCreateRelationship.

private void askCreateRelationship() {
    List<Long> nodeIds;
    try {
        nodeIds = getAllNodeIds();
    } catch (Exception e) {
        Ln.e(e, "database exception");
        showErrorDialog();
        return;
    }
    View relationshipCreateView = inflater.inflate(R.layout.relationship_create, null);
    final TextView relationshipCreateStartNodeIdText = (TextView) relationshipCreateView.findViewById(R.id.relationshipCreateStartNodeIdText);
    Formatter formatter = new Formatter();
    formatter.format(getResources().getString(R.string.relationship_create_startnode), centerNodeId);
    relationshipCreateStartNodeIdText.setText(formatter.toString());
    formatter.close();
    final EditText relationshipCreateNameText = (EditText) relationshipCreateView.findViewById(R.id.relationshipCreateNameText);
    final Spinner relationshipCreateEndnodeIdSpinner = (Spinner) relationshipCreateView.findViewById(R.id.relationshipCreateEndnodeIdSpinner);
    ArrayAdapter<Long> spinnerAdapter = new ArrayAdapter<Long>(context, android.R.layout.simple_spinner_item, nodeIds);
    spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    relationshipCreateEndnodeIdSpinner.setAdapter(spinnerAdapter);
    AlertDialog dialog = new AlertDialog.Builder(this).create();
    dialog.setTitle(R.string.relationship_create_title);
    dialog.setView(relationshipCreateView);
    dialog.setButton(getResources().getString(android.R.string.ok), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            String name = relationshipCreateNameText.getText().toString();
            long endNodeId = (Long) relationshipCreateEndnodeIdSpinner.getSelectedItem();
            try {
                createRelationship(name, endNodeId);
            } catch (Exception e) {
                Ln.e(e, "could not create relationship");
                showErrorDialog();
            }
            updateRelationshipsList();
        }
    });
    dialog.setButton2(getResources().getString(android.R.string.cancel), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });
    dialog.show();
}
Also used : EditText(android.widget.EditText) AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) Formatter(java.util.Formatter) Spinner(android.widget.Spinner) ContentView(roboguice.inject.ContentView) View(android.view.View) InjectView(roboguice.inject.InjectView) TextView(android.widget.TextView) Neo4jServiceException(org.neo4j.android.client.Neo4jServiceException) RemoteException(android.os.RemoteException) TextView(android.widget.TextView) ArrayAdapter(android.widget.ArrayAdapter)

Example 23 with Formatter

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

the class RelationshipPropertiesActivity 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_relationship_question), key, value, relationshipId);
    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 {
                    ParcelableRelationship relationship = database.getRelationshipById(relationshipId);
                    relationship.removeProperty(key);
                    database.updateRelationship(relationship);
                    database.txSuccess();
                } finally {
                    database.txFinish();
                }
            } catch (Exception e) {
                Ln.e(e, "failed to delete property with key '" + key + "' and value '" + value + "' from relationship with id '" + relationshipId + "'.");
                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) ParcelableRelationship(org.neo4j.android.common.ParcelableRelationship)

Example 24 with Formatter

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

the class RelationshipPropertiesActivity method confirmDeletionOfRelationship.

private void confirmDeletionOfRelationship() {
    AlertDialog dialog = new AlertDialog.Builder(this).create();
    dialog.setTitle(R.string.relationship_delete_title);
    Formatter formatter = new Formatter();
    formatter.format(getResources().getString(R.string.relationship_delete_question), relationshipId);
    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 {
                    ParcelableRelationship relationship = database.getRelationshipById(relationshipId);
                    database.deleteRelationship(relationship.getId());
                    database.txSuccess();
                } finally {
                    database.txFinish();
                }
                Intent data = new Intent();
                data.putExtra(DBInspectorConstants.INTENTEXTRA_RELATIONSHIP_DELETED, true);
                setResult(RESULT_OK, data);
                finish();
            } catch (Exception e) {
                Ln.e(e, "failed to delete relationship with id '" + relationshipId + "'.");
                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) ParcelableRelationship(org.neo4j.android.common.ParcelableRelationship) Intent(android.content.Intent)

Example 25 with Formatter

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

the class RelationshipPropertiesActivity 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)

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