Example usage for android.database Cursor isNull

List of usage examples for android.database Cursor isNull

Introduction

In this page you can find the example usage for android.database Cursor isNull.

Prototype

boolean isNull(int columnIndex);

Source Link

Document

Returns true if the value in the indicated column is null.

Usage

From source file:com.master.metehan.filtereagle.AdapterAccess.java

@Override
public void bindView(final View view, final Context context, final Cursor cursor) {
    // Get values
    final long id = cursor.getLong(colID);
    final int version = cursor.getInt(colVersion);
    final int protocol = cursor.getInt(colProtocol);
    final String daddr = cursor.getString(colDaddr);
    final int dport = cursor.getInt(colDPort);
    long time = cursor.getLong(colTime);
    int allowed = cursor.getInt(colAllowed);
    int block = cursor.getInt(colBlock);
    long sent = cursor.isNull(colSent) ? -1 : cursor.getLong(colSent);
    long received = cursor.isNull(colReceived) ? -1 : cursor.getLong(colReceived);
    int connections = cursor.isNull(colConnections) ? -1 : cursor.getInt(colConnections);

    // Get views/*from w  ww . j  av  a  2  s.  co m*/
    TextView tvTime = (TextView) view.findViewById(R.id.tvTime);
    ImageView ivBlock = (ImageView) view.findViewById(R.id.ivBlock);
    final TextView tvDest = (TextView) view.findViewById(R.id.tvDest);
    LinearLayout llTraffic = (LinearLayout) view.findViewById(R.id.llTraffic);
    TextView tvConnections = (TextView) view.findViewById(R.id.tvConnections);
    TextView tvTraffic = (TextView) view.findViewById(R.id.tvTraffic);

    // Set values
    tvTime.setText(new SimpleDateFormat("dd HH:mm").format(time));
    if (block < 0)
        ivBlock.setImageDrawable(null);
    else {
        ivBlock.setImageResource(block > 0 ? R.drawable.host_blocked : R.drawable.host_allowed);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            Drawable wrap = DrawableCompat.wrap(ivBlock.getDrawable());
            DrawableCompat.setTint(wrap, block > 0 ? colorOff : colorOn);
        }
    }

    tvDest.setText(
            Util.getProtocolName(protocol, version, true) + " " + daddr + (dport > 0 ? "/" + dport : ""));

    if (Util.isNumericAddress(daddr) && tvDest.getTag() == null)
        new AsyncTask<String, Object, String>() {
            @Override
            protected void onPreExecute() {
                tvDest.setTag(id);
            }

            @Override
            protected String doInBackground(String... args) {
                try {
                    return InetAddress.getByName(args[0]).getHostName();
                } catch (UnknownHostException ignored) {
                    return args[0];
                }
            }

            @Override
            protected void onPostExecute(String addr) {
                Object tag = tvDest.getTag();
                if (tag != null && (Long) tag == id)
                    tvDest.setText(Util.getProtocolName(protocol, version, true) + " >" + addr
                            + (dport > 0 ? "/" + dport : ""));
                tvDest.setTag(null);
            }
        }.execute(daddr);

    if (allowed < 0)
        tvDest.setTextColor(colorText);
    else if (allowed > 0)
        tvDest.setTextColor(colorOn);
    else
        tvDest.setTextColor(colorOff);

    llTraffic.setVisibility(connections > 0 || sent > 0 || received > 0 ? View.VISIBLE : View.GONE);
    if (connections > 0)
        tvConnections.setText(context.getString(R.string.msg_count, connections));

    if (sent > 1024 * 1204 * 1024L || received > 1024 * 1024 * 1024L)
        tvTraffic.setText(context.getString(R.string.msg_gb, (sent > 0 ? sent / (1024 * 1024 * 1024f) : 0),
                (received > 0 ? received / (1024 * 1024 * 1024f) : 0)));
    else if (sent > 1204 * 1024L || received > 1024 * 1024L)
        tvTraffic.setText(context.getString(R.string.msg_mb, (sent > 0 ? sent / (1024 * 1024f) : 0),
                (received > 0 ? received / (1024 * 1024f) : 0)));
    else
        tvTraffic.setText(context.getString(R.string.msg_kb, (sent > 0 ? sent / 1024f : 0),
                (received > 0 ? received / 1024f : 0)));
}

From source file:eu.faircode.netguard.AdapterAccess.java

@Override
public void bindView(final View view, final Context context, final Cursor cursor) {
    // Get values
    final int version = cursor.getInt(colVersion);
    final int protocol = cursor.getInt(colProtocol);
    final String daddr = cursor.getString(colDaddr);
    final int dport = cursor.getInt(colDPort);
    long time = cursor.getLong(colTime);
    int allowed = cursor.getInt(colAllowed);
    int block = cursor.getInt(colBlock);
    int count = cursor.getInt(colCount);
    long sent = cursor.isNull(colSent) ? -1 : cursor.getLong(colSent);
    long received = cursor.isNull(colReceived) ? -1 : cursor.getLong(colReceived);
    int connections = cursor.isNull(colConnections) ? -1 : cursor.getInt(colConnections);

    // Get views/*from   www .j  a v  a 2s  .  c o  m*/
    TextView tvTime = view.findViewById(R.id.tvTime);
    ImageView ivBlock = view.findViewById(R.id.ivBlock);
    final TextView tvDest = view.findViewById(R.id.tvDest);
    LinearLayout llTraffic = view.findViewById(R.id.llTraffic);
    TextView tvConnections = view.findViewById(R.id.tvConnections);
    TextView tvTraffic = view.findViewById(R.id.tvTraffic);

    // Set values
    tvTime.setText(new SimpleDateFormat("dd HH:mm").format(time));
    if (block < 0)
        ivBlock.setImageDrawable(null);
    else {
        ivBlock.setImageResource(block > 0 ? R.drawable.host_blocked : R.drawable.host_allowed);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            Drawable wrap = DrawableCompat.wrap(ivBlock.getDrawable());
            DrawableCompat.setTint(wrap, block > 0 ? colorOff : colorOn);
        }
    }

    String dest = Util.getProtocolName(protocol, version, true) + " " + daddr + (dport > 0 ? "/" + dport : "")
            + (count > 1 ? " ?" + count : "");
    SpannableString span = new SpannableString(dest);
    span.setSpan(new UnderlineSpan(), 0, dest.length(), 0);
    tvDest.setText(span);

    if (Util.isNumericAddress(daddr))
        new AsyncTask<String, Object, String>() {
            @Override
            protected void onPreExecute() {
                ViewCompat.setHasTransientState(tvDest, true);
            }

            @Override
            protected String doInBackground(String... args) {
                try {
                    return InetAddress.getByName(args[0]).getHostName();
                } catch (UnknownHostException ignored) {
                    return args[0];
                }
            }

            @Override
            protected void onPostExecute(String addr) {
                tvDest.setText(Util.getProtocolName(protocol, version, true) + " >" + addr
                        + (dport > 0 ? "/" + dport : ""));
                ViewCompat.setHasTransientState(tvDest, false);
            }
        }.execute(daddr);

    if (allowed < 0)
        tvDest.setTextColor(colorText);
    else if (allowed > 0)
        tvDest.setTextColor(colorOn);
    else
        tvDest.setTextColor(colorOff);

    llTraffic.setVisibility(connections > 0 || sent > 0 || received > 0 ? View.VISIBLE : View.GONE);
    if (connections > 0)
        tvConnections.setText(context.getString(R.string.msg_count, connections));

    if (sent > 1024 * 1204 * 1024L || received > 1024 * 1024 * 1024L)
        tvTraffic.setText(context.getString(R.string.msg_gb, (sent > 0 ? sent / (1024 * 1024 * 1024f) : 0),
                (received > 0 ? received / (1024 * 1024 * 1024f) : 0)));
    else if (sent > 1204 * 1024L || received > 1024 * 1024L)
        tvTraffic.setText(context.getString(R.string.msg_mb, (sent > 0 ? sent / (1024 * 1024f) : 0),
                (received > 0 ? received / (1024 * 1024f) : 0)));
    else
        tvTraffic.setText(context.getString(R.string.msg_kb, (sent > 0 ? sent / 1024f : 0),
                (received > 0 ? received / 1024f : 0)));
}

From source file:edu.mit.mobile.android.livingpostcards.CardViewActivity.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor c) {
    if (c.moveToFirst()) {

        // don't show deleted cards. This just confuses things.
        if (Card.isDeleted(c)) {
            finish();/*from  w ww .  j  ava 2  s.c o  m*/
            return;
        }
        final int videoCol = c.getColumnIndexOrThrow(Card.COL_VIDEO_RENDER);

        // if the card has a video render, show that
        mHasVideo = !c.isNull(videoCol) && c.getString(videoCol).length() > 0;

        mHandler.sendEmptyMessage(MSG_LOAD_CARD_MEDIA);

        setTitle(Card.getTitle(this, c));
        mSherlock.getActionBar().setSubtitle(c.getString(c.getColumnIndexOrThrow(Card.COL_AUTHOR)));

        mIsEditable = PrivatelyAuthorable.canEdit(mUserUri, c);
        mIsOwner = mUserUri.equals(c.getString(c.getColumnIndexOrThrow(Card.COL_AUTHOR_URI)));

        final View addPicture = findViewById(R.id.add_frame);

        if (mIsEditable) {
            addPicture.setVisibility(View.VISIBLE);
            addPicture.startAnimation(AnimationUtils.makeInChildBottomAnimation(this));
        } else {
            addPicture.setVisibility(View.GONE);
        }

        mWebUrl = c.getString(c.getColumnIndexOrThrow(Card.COL_WEB_URL));
        // resolve to a full URL
        final NetworkClient nc = LocastApplication.getNetworkClient(this, Authenticator.getFirstAccount(this));
        mWebUrl = mWebUrl != null ? nc.getFullUrlAsString(mWebUrl) : null;
        try {
            mSherlock.dispatchInvalidateOptionsMenu();
        } catch (final OutOfMemoryError oom) {
            // well, damn.
        }
    } else {
        finish();
    }
}

From source file:com.technoxist.fragment.EntryFragment.java

private void refreshUI(Cursor entryCursor) {
    if (entryCursor != null) {
        String feedTitle = entryCursor.isNull(mFeedNamePos) ? entryCursor.getString(mFeedUrlPos)
                : entryCursor.getString(mFeedNamePos);
        BaseActivity activity = (BaseActivity) getActivity();
        activity.setTitle(feedTitle);//from ww  w.j av  a  2 s.  co m

        byte[] iconBytes = entryCursor.getBlob(mFeedIconPos);
        Bitmap bitmap = UiUtils.getScaledBitmap(iconBytes, 24);
        if (bitmap != null) {
            activity.getActionBar().setIcon(new BitmapDrawable(getResources(), bitmap));
        } else {
            activity.getActionBar().setIcon(R.drawable.icon);
        }

        mFavorite = entryCursor.getInt(mIsFavoritePos) == 1;
        activity.invalidateOptionsMenu();

        // Listen the mobilizing task
        if (FetcherService.hasMobilizationTask(mEntriesIds[mCurrentPagerPos])) {
            hideSwipeProgress();

            // Start services here if not already started to avoid an infinite loading
            if (!PrefUtils.getBoolean(PrefUtils.IS_REFRESHING, false)) {
                MainApplication.getContext()
                        .startService(new Intent(MainApplication.getContext(), FetcherService.class)
                                .setAction(FetcherService.ACTION_MOBILIZE_FEEDS));
            }
        } else {
            hideSwipeProgress();
        }

        // Mark the article as read
        if (entryCursor.getInt(mIsReadPos) != 1) {
            final Uri uri = ContentUris.withAppendedId(mBaseUri, mEntriesIds[mCurrentPagerPos]);
            new Thread(new Runnable() {
                @Override
                public void run() {
                    ContentResolver cr = MainApplication.getContext().getContentResolver();
                    cr.update(uri, FeedData.getReadContentValues(), null, null);

                    // Update the cursor
                    Cursor updatedCursor = cr.query(uri, null, null, null, null);
                    updatedCursor.moveToFirst();
                    mEntryPagerAdapter.setUpdatedCursor(mCurrentPagerPos, updatedCursor);
                }
            }).start();
        }
    }
}

From source file:com.app.uafeed.fragment.EntryFragment.java

private void refreshUI(Cursor entryCursor) {
    if (entryCursor != null) {
        String feedTitle = entryCursor.isNull(mFeedNamePos) ? entryCursor.getString(mFeedUrlPos)
                : entryCursor.getString(mFeedNamePos);
        BaseActivity activity = (BaseActivity) getActivity();
        activity.setTitle(feedTitle);// w ww.j  a  v  a2 s.  c o  m

        byte[] iconBytes = entryCursor.getBlob(mFeedIconPos);
        Bitmap bitmap = UiUtils.getScaledBitmap(iconBytes, 24);
        if (bitmap != null) {
            activity.getActionBar().setIcon(new BitmapDrawable(getResources(), bitmap));
        } else {
            activity.getActionBar().setIcon(R.drawable.icon);
        }

        mFavorite = entryCursor.getInt(mIsFavoritePos) == 1;
        activity.invalidateOptionsMenu();

        // Listen the mobilizing task
        boolean isRefreshing = FetcherService.hasTasks(mEntriesIds[mCurrentPagerPos]);
        activity.getProgressBar().setVisibility(isRefreshing ? View.VISIBLE : View.GONE);

        // Mark the article as read
        if (entryCursor.getInt(mIsReadPos) != 1) {
            final Uri uri = ContentUris.withAppendedId(mBaseUri, mEntriesIds[mCurrentPagerPos]);
            new Thread(new Runnable() {
                @Override
                public void run() {
                    ContentResolver cr = MainApplication.getContext().getContentResolver();
                    cr.update(uri, FeedData.getReadContentValues(), null, null);

                    // Update the cursor
                    Cursor updatedCursor = cr.query(uri, null, null, null, null);
                    updatedCursor.moveToFirst();
                    mEntryPagerAdapter.setUpdatedCursor(mCurrentPagerPos, updatedCursor);
                }
            }).start();
        }
    }
}

From source file:net.fred.feedex.fragment.EntryFragment.java

private void refreshUI(Cursor entryCursor) {
    if (entryCursor != null) {
        String feedTitle = entryCursor.isNull(mFeedNamePos) ? entryCursor.getString(mFeedUrlPos)
                : entryCursor.getString(mFeedNamePos);
        BaseActivity activity = (BaseActivity) getActivity();
        activity.setTitle(feedTitle);/*from   ww w .  j a va 2  s.  c  o  m*/

        byte[] iconBytes = entryCursor.getBlob(mFeedIconPos);
        Bitmap bitmap = UiUtils.getScaledBitmap(iconBytes, 24);
        if (bitmap != null) {
            activity.getActionBar().setIcon(new BitmapDrawable(getResources(), bitmap));
        } else {
            activity.getActionBar().setIcon(R.drawable.icon);
        }

        mFavorite = entryCursor.getInt(mIsFavoritePos) == 1;
        activity.invalidateOptionsMenu();

        // Listen the mobilizing task
        if (FetcherService.hasMobilizationTask(mEntriesIds[mCurrentPagerPos])) {
            showSwipeProgress();
        } else {
            hideSwipeProgress();
        }

        // Mark the article as read
        if (entryCursor.getInt(mIsReadPos) != 1) {
            final Uri uri = ContentUris.withAppendedId(mBaseUri, mEntriesIds[mCurrentPagerPos]);
            new Thread(new Runnable() {
                @Override
                public void run() {
                    ContentResolver cr = MainApplication.getContext().getContentResolver();
                    cr.update(uri, FeedData.getReadContentValues(), null, null);

                    // Update the cursor
                    Cursor updatedCursor = cr.query(uri, null, null, null, null);
                    updatedCursor.moveToFirst();
                    mEntryPagerAdapter.setUpdatedCursor(mCurrentPagerPos, updatedCursor);
                }
            }).start();
        }
    }
}

From source file:com.app.uafeed.fragment.EntryFragment.java

@Override
public void onClickFullText() {
    final BaseActivity activity = (BaseActivity) getActivity();

    if (activity.getProgressBar().getVisibility() != View.VISIBLE) {
        Cursor cursor = mEntryPagerAdapter.getCursor(mCurrentPagerPos);
        final boolean alreadyMobilized = !cursor.isNull(mMobilizedHtmlPos);

        if (alreadyMobilized) {
            activity.runOnUiThread(new Runnable() {
                @Override/*from w w  w.  j av a  2  s . c  om*/
                public void run() {
                    mPreferFullText = true;
                    mEntryPagerAdapter.displayEntry(mCurrentPagerPos, null, true);
                }
            });
        } else {
            ConnectivityManager connectivityManager = (ConnectivityManager) activity
                    .getSystemService(Context.CONNECTIVITY_SERVICE);
            final NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();

            // since we have acquired the networkInfo, we use it for basic checks
            if (networkInfo != null && networkInfo.getState() == NetworkInfo.State.CONNECTED) {
                FetcherService.addEntriesToMobilize(new long[] { mEntriesIds[mCurrentPagerPos] });
                activity.startService(new Intent(activity, FetcherService.class)
                        .setAction(FetcherService.ACTION_MOBILIZE_FEEDS));
                activity.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        activity.getProgressBar().setVisibility(View.VISIBLE);
                    }
                });
            } else {
                activity.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(activity, R.string.network_error, Toast.LENGTH_LONG).show();
                    }
                });
            }
        }
    }
}

From source file:edu.mit.mobile.android.locast.data.JsonSyncableItem.java

/**
 * @param context/*from w  w  w  .ja v  a 2 s .c o  m*/
 * @param localItem Will contain the URI of the local item being referenced in the cursor
 * @param c active cursor with the item to sync selected.
 * @param mySyncMap
 * @return a new JSONObject representing the item
 * @throws JSONException
 * @throws NetworkProtocolException
 * @throws IOException
 */
public final static JSONObject toJSON(Context context, Uri localItem, Cursor c, SyncMap mySyncMap)
        throws JSONException, NetworkProtocolException, IOException {
    final JSONObject jo = new JSONObject();

    for (final String lProp : mySyncMap.keySet()) {
        final SyncItem map = mySyncMap.get(lProp);

        if (!map.isDirection(SyncItem.SYNC_TO)) {
            continue;
        }

        final int colIndex = c.getColumnIndex(lProp);
        // if it's a real property that's optional and is null on the local side
        if (!lProp.startsWith("_") && map.isOptional()) {
            if (colIndex == -1) {
                throw new RuntimeException("Programming error: Cursor does not have column '" + lProp
                        + "', though sync map says it should. Sync Map: " + mySyncMap);
            }
            if (c.isNull(colIndex)) {
                continue;
            }
        }

        final Object jsonObject = map.toJSON(context, localItem, c, lProp);
        if (jsonObject instanceof MultipleJsonObjectKeys) {
            for (final Entry<String, Object> entry : ((MultipleJsonObjectKeys) jsonObject).entrySet()) {
                jo.put(entry.getKey(), entry.getValue());
            }

        } else {
            jo.put(map.remoteKey, jsonObject);
        }
    }
    return jo;
}

From source file:com.viktorrudometkin.burramys.fragment.EntryFragment.java

private void refreshUI(Cursor entryCursor) {
    if (entryCursor != null) {
        String feedTitle = entryCursor.isNull(mFeedNamePos) ? entryCursor.getString(mFeedUrlPos)
                : entryCursor.getString(mFeedNamePos);
        BaseActivity activity = (BaseActivity) getActivity();
        activity.setTitle(feedTitle);// w w  w.j  a  va2 s .c o m

        mFavorite = entryCursor.getInt(mIsFavoritePos) == 1;
        activity.invalidateOptionsMenu();

        // Listen the mobilizing task
        if (FetcherService.hasMobilizationTask(mEntriesIds[mCurrentPagerPos])) {
            showSwipeProgress();

            // If the service is not started, start it here to avoid an infinite loading
            if (!PrefUtils.getBoolean(PrefUtils.IS_REFRESHING, false)) {
                MainApplication.getContext()
                        .startService(new Intent(MainApplication.getContext(), FetcherService.class)
                                .setAction(FetcherService.ACTION_MOBILIZE_FEEDS));
            }
        } else {
            hideSwipeProgress();
        }

        // Mark the article as read
        if (entryCursor.getInt(mIsReadPos) != 1) {
            final Uri uri = ContentUris.withAppendedId(mBaseUri, mEntriesIds[mCurrentPagerPos]);
            new Thread(new Runnable() {
                @Override
                public void run() {
                    ContentResolver cr = MainApplication.getContext().getContentResolver();
                    cr.update(uri, FeedData.getReadContentValues(), null, null);

                    // Update the cursor
                    Cursor updatedCursor = cr.query(uri, null, null, null, null);
                    updatedCursor.moveToFirst();
                    mEntryPagerAdapter.setUpdatedCursor(mCurrentPagerPos, updatedCursor);
                }
            }).start();
        }
    }
}

From source file:info.guardianproject.otr.app.im.app.AccountListActivity.java

protected void openAccountAtPosition(int position) {
    Cursor cursor = mAdapter.getCursor();
    cursor.moveToPosition(position);//from w ww .j  a v  a 2 s.  c om

    if (cursor.isNull(ACTIVE_ACCOUNT_ID_COLUMN)) {
        showExistingAccountListDialog();

    } else {

        int state = cursor.getInt(ACCOUNT_CONNECTION_STATUS);
        long accountId = cursor.getLong(ACTIVE_ACCOUNT_ID_COLUMN);

        if (state == Imps.ConnectionStatus.OFFLINE) {

            Intent intent = getEditAccountIntent();
            startActivity(intent);

        } else {
            gotoAccount(accountId);
        }

    }

}