Search in sources :

Example 31 with Uri

use of android.net.Uri in project cw-omnibus by commonsguy.

the class URLHandler method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    TextView uri = (TextView) findViewById(R.id.uri);
    if (Intent.ACTION_MAIN.equals(getIntent().getAction())) {
        String intentUri = (new Intent("com.commonsware.android.MY_ACTION")).toUri(Intent.URI_INTENT_SCHEME).toString();
        uri.setText(intentUri);
        Log.w("URLHandler", intentUri);
    } else {
        Uri data = getIntent().getData();
        if (data == null) {
            uri.setText("Got com.commonsware.android.MY_ACTION Intent");
        } else {
            uri.setText(getIntent().getData().toString());
        }
    }
}
Also used : TextView(android.widget.TextView) Intent(android.content.Intent) Uri(android.net.Uri)

Example 32 with Uri

use of android.net.Uri in project cw-omnibus by commonsguy.

the class Provider method insert.

@Override
public Uri insert(Uri url, ContentValues initialValues) {
    long rowID = db.insert(TABLE, Constants.TITLE, initialValues);
    if (rowID > 0) {
        Uri uri = ContentUris.withAppendedId(Provider.Constants.CONTENT_URI, rowID);
        getContext().getContentResolver().notifyChange(uri, null);
        return (uri);
    }
    throw new SQLException("Failed to insert row into " + url);
}
Also used : SQLException(net.sqlcipher.SQLException) Uri(android.net.Uri)

Example 33 with Uri

use of android.net.Uri in project materialistic by hidroh.

the class SubmitActivityTest method testSubmitError.

@Test
public void testSubmitError() {
    ((EditText) activity.findViewById(R.id.edittext_title)).setText("title");
    ((EditText) activity.findViewById(R.id.edittext_content)).setText("http://example.com");
    shadowOf(activity).clickMenuItem(R.id.menu_send);
    ShadowAlertDialog.getLatestAlertDialog().getButton(DialogInterface.BUTTON_POSITIVE).performClick();
    verify(userServices).submit(any(Context.class), eq("title"), eq("http://example.com"), eq(true), submitCallback.capture());
    Uri redirect = Uri.parse(BuildConfig.APPLICATION_ID + "://item?id=1234");
    UserServices.Exception exception = new UserServices.Exception(R.string.item_exist);
    exception.data = redirect;
    submitCallback.getValue().onError(exception);
    assertEquals(activity.getString(R.string.item_exist), ShadowToast.getTextOfLatestToast());
    assertThat(shadowOf(activity).getNextStartedActivity()).hasAction(Intent.ACTION_VIEW).hasData(redirect);
}
Also used : EditText(android.widget.EditText) Context(android.content.Context) UserServices(io.github.hidroh.materialistic.accounts.UserServices) Uri(android.net.Uri) IOException(java.io.IOException) Test(org.junit.Test)

Example 34 with Uri

use of android.net.Uri in project materialistic by hidroh.

the class FavoriteManagerTest method setUp.

@Before
public void setUp() {
    resolver = shadowOf(RuntimeEnvironment.application.getContentResolver());
    ContentValues cv = new ContentValues();
    cv.put("itemid", "1");
    cv.put("title", "title");
    cv.put("url", "http://example.com");
    cv.put("time", String.valueOf(System.currentTimeMillis()));
    resolver.insert(MaterialisticProvider.URI_FAVORITE, cv);
    cv = new ContentValues();
    cv.put("itemid", "2");
    cv.put("title", "ask HN");
    cv.put("url", "http://example.com");
    cv.put("time", String.valueOf(System.currentTimeMillis()));
    resolver.insert(MaterialisticProvider.URI_FAVORITE, cv);
    manager = new FavoriteManager(Schedulers.immediate()) {

        @Override
        protected Uri getUriForFile(Context context, File file) {
            return Uri.parse("content://" + FavoriteManager.FILE_AUTHORITY + "/files/saved/materialistic-export.txt");
        }
    };
}
Also used : ContentValues(android.content.ContentValues) Context(android.content.Context) File(java.io.File) Uri(android.net.Uri) Before(org.junit.Before)

Example 35 with Uri

use of android.net.Uri in project AndroidTraining by mixi-inc.

the class TestTargetContentProvider method insert.

@Override
public Uri insert(Uri uri, ContentValues values) {
    if (URI_MATCHER.match(uri) != TYPE_ITEMS) {
        throw new IllegalArgumentException("unable to insert with this uri: " + uri);
    }
    SQLiteDatabase db = null;
    try {
        db = mDatabaseHelper.getWritableDatabase();
        db.beginTransaction();
        final long id = db.insertOrThrow("tests", null, values);
        Uri newUri = ContentUris.withAppendedId(uri, id);
        db.setTransactionSuccessful();
        return newUri;
    } finally {
        if (db != null) {
            db.endTransaction();
        }
    }
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Uri(android.net.Uri)

Aggregations

Uri (android.net.Uri)6747 Intent (android.content.Intent)1547 Cursor (android.database.Cursor)894 File (java.io.File)744 Test (org.junit.Test)632 ContentValues (android.content.ContentValues)614 IOException (java.io.IOException)571 ContentResolver (android.content.ContentResolver)449 ArrayList (java.util.ArrayList)446 Bundle (android.os.Bundle)289 Context (android.content.Context)276 Bitmap (android.graphics.Bitmap)273 InputStream (java.io.InputStream)257 View (android.view.View)251 RemoteException (android.os.RemoteException)228 PendingIntent (android.app.PendingIntent)209 SuppressLint (android.annotation.SuppressLint)180 FileNotFoundException (java.io.FileNotFoundException)177 TextView (android.widget.TextView)175 ActivityNotFoundException (android.content.ActivityNotFoundException)169