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:edu.mit.mobile.android.locast.itineraries.ItineraryDetail.java

@Override
public void onItemClick(AdapterView<?> adapter, View v, int position, long id) {

    final Cursor cast = (Cursor) adapter.getItemAtPosition(position);
    final int dratCol = cast.getColumnIndex(Cast._DRAFT);
    final boolean isDraft = !cast.isNull(dratCol) && cast.getInt(dratCol) == 1;

    if (isDraft) {
        startActivity(new Intent(Intent.ACTION_EDIT, ContentUris.withAppendedId(mCastsUri, id)));
    } else {//from w  w  w  .  j  a va2 s.co m
        startActivity(new Intent(Intent.ACTION_VIEW, ContentUris.withAppendedId(mCastsUri, id)));
    }
}

From source file:android_network.hetnet.vpn_service.AdapterLog.java

@Override
public void bindView(final View view, final Context context, final Cursor cursor) {
    // Get values
    final long id = cursor.getLong(colID);
    long time = cursor.getLong(colTime);
    int version = (cursor.isNull(colVersion) ? -1 : cursor.getInt(colVersion));
    int protocol = (cursor.isNull(colProtocol) ? -1 : cursor.getInt(colProtocol));
    String flags = cursor.getString(colFlags);
    String saddr = cursor.getString(colSAddr);
    int sport = (cursor.isNull(colSPort) ? -1 : cursor.getInt(colSPort));
    String daddr = cursor.getString(colDAddr);
    int dport = (cursor.isNull(colDPort) ? -1 : cursor.getInt(colDPort));
    String dname = (cursor.isNull(colDName) ? null : cursor.getString(colDName));
    int uid = (cursor.isNull(colUid) ? -1 : cursor.getInt(colUid));
    String data = cursor.getString(colData);
    int allowed = (cursor.isNull(colAllowed) ? -1 : cursor.getInt(colAllowed));
    int connection = (cursor.isNull(colConnection) ? -1 : cursor.getInt(colConnection));
    int interactive = (cursor.isNull(colInteractive) ? -1 : cursor.getInt(colInteractive));

    // Get views//w w  w  .ja v a  2 s  .co  m
    TextView tvTime = (TextView) view.findViewById(R.id.tvTime);
    TextView tvProtocol = (TextView) view.findViewById(R.id.tvProtocol);
    TextView tvFlags = (TextView) view.findViewById(R.id.tvFlags);
    TextView tvSAddr = (TextView) view.findViewById(R.id.tvSAddr);
    TextView tvSPort = (TextView) view.findViewById(R.id.tvSPort);
    final TextView tvDaddr = (TextView) view.findViewById(R.id.tvDAddr);
    TextView tvDPort = (TextView) view.findViewById(R.id.tvDPort);
    final TextView tvOrganization = (TextView) view.findViewById(R.id.tvOrganization);
    ImageView ivIcon = (ImageView) view.findViewById(R.id.ivIcon);
    TextView tvUid = (TextView) view.findViewById(R.id.tvUid);
    TextView tvData = (TextView) view.findViewById(R.id.tvData);
    ImageView ivConnection = (ImageView) view.findViewById(R.id.ivConnection);
    ImageView ivInteractive = (ImageView) view.findViewById(R.id.ivInteractive);

    // Show time
    tvTime.setText(new SimpleDateFormat("HH:mm:ss").format(time));

    // Show connection type
    if (connection <= 0)
        ivConnection.setImageResource(allowed > 0 ? R.drawable.host_allowed : R.drawable.host_blocked);
    else {
        if (allowed > 0)
            ivConnection.setImageResource(connection == 1 ? R.drawable.wifi_on : R.drawable.other_on);
        else
            ivConnection.setImageResource(connection == 1 ? R.drawable.wifi_off : R.drawable.other_off);
    }
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        Drawable wrap = DrawableCompat.wrap(ivConnection.getDrawable());
        DrawableCompat.setTint(wrap, allowed > 0 ? colorOn : colorOff);
    }

    // Show if screen on
    if (interactive <= 0)
        ivInteractive.setImageDrawable(null);
    else {
        ivInteractive.setImageResource(R.drawable.screen_on);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            Drawable wrap = DrawableCompat.wrap(ivInteractive.getDrawable());
            DrawableCompat.setTint(wrap, colorOn);
        }
    }

    // Show protocol name
    tvProtocol.setText(Util.getProtocolName(protocol, version, false));

    // SHow TCP flags
    tvFlags.setText(flags);
    tvFlags.setVisibility(TextUtils.isEmpty(flags) ? View.GONE : View.VISIBLE);

    // Show source and destination port
    if (protocol == 6 || protocol == 17) {
        tvSPort.setText(sport < 0 ? "" : getKnownPort(sport));
        tvDPort.setText(dport < 0 ? "" : getKnownPort(dport));
    } else {
        tvSPort.setText(sport < 0 ? "" : Integer.toString(sport));
        tvDPort.setText(dport < 0 ? "" : Integer.toString(dport));
    }

    // Application icon
    ApplicationInfo info = null;
    PackageManager pm = context.getPackageManager();
    String[] pkg = pm.getPackagesForUid(uid);
    if (pkg != null && pkg.length > 0)
        try {
            info = pm.getApplicationInfo(pkg[0], 0);
        } catch (PackageManager.NameNotFoundException ignored) {
        }
    if (info == null)
        ivIcon.setImageDrawable(null);
    else if (info.icon == 0)
        Picasso.with(context).load(android.R.drawable.sym_def_app_icon).into(ivIcon);
    else {
        Uri uri = Uri.parse("android.resource://" + info.packageName + "/" + info.icon);
        Picasso.with(context).load(uri).resize(iconSize, iconSize).into(ivIcon);
    }

    // https://android.googlesource.com/platform/system/core/+/master/include/private/android_filesystem_config.h
    uid = uid % 100000; // strip off user ID
    if (uid == -1)
        tvUid.setText("");
    else if (uid == 0)
        tvUid.setText(context.getString(R.string.title_root));
    else if (uid == 9999)
        tvUid.setText("-"); // nobody
    else
        tvUid.setText(Integer.toString(uid));

    // Show source address
    tvSAddr.setText(getKnownAddress(saddr));

    // Show destination address
    if (resolve && !isKnownAddress(daddr))
        if (dname == null) {
            tvDaddr.setText(daddr);
            new AsyncTask<String, Object, String>() {
                @Override
                protected void onPreExecute() {
                    ViewCompat.setHasTransientState(tvDaddr, 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 name) {
                    tvDaddr.setText(">" + name);
                    ViewCompat.setHasTransientState(tvDaddr, false);
                }
            }.execute(daddr);
        } else
            tvDaddr.setText(dname);
    else
        tvDaddr.setText(getKnownAddress(daddr));

    // Show organization
    tvOrganization.setVisibility(View.GONE);
    if (organization) {
        if (!isKnownAddress(daddr))
            new AsyncTask<String, Object, String>() {
                @Override
                protected void onPreExecute() {
                    ViewCompat.setHasTransientState(tvOrganization, true);
                }

                @Override
                protected String doInBackground(String... args) {
                    try {
                        return Util.getOrganization(args[0]);
                    } catch (Throwable ex) {
                        Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                        return null;
                    }
                }

                @Override
                protected void onPostExecute(String organization) {
                    if (organization != null) {
                        tvOrganization.setText(organization);
                        tvOrganization.setVisibility(View.VISIBLE);
                    }
                    ViewCompat.setHasTransientState(tvOrganization, false);
                }
            }.execute(daddr);
    }

    // Show extra data
    if (TextUtils.isEmpty(data)) {
        tvData.setText("");
        tvData.setVisibility(View.GONE);
    } else {
        tvData.setText(data);
        tvData.setVisibility(View.VISIBLE);
    }
}

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

@Override
public void bindView(final View view, final Context context, final Cursor cursor) {
    // Get values
    final long id = cursor.getLong(colID);
    long time = cursor.getLong(colTime);
    int version = (cursor.isNull(colVersion) ? -1 : cursor.getInt(colVersion));
    int protocol = (cursor.isNull(colProtocol) ? -1 : cursor.getInt(colProtocol));
    String flags = cursor.getString(colFlags);
    String saddr = cursor.getString(colSAddr);
    int sport = (cursor.isNull(colSPort) ? -1 : cursor.getInt(colSPort));
    String daddr = cursor.getString(colDAddr);
    int dport = (cursor.isNull(colDPort) ? -1 : cursor.getInt(colDPort));
    String dname = (cursor.isNull(colDName) ? null : cursor.getString(colDName));
    int uid = (cursor.isNull(colUid) ? -1 : cursor.getInt(colUid));
    String data = cursor.getString(colData);
    int allowed = (cursor.isNull(colAllowed) ? -1 : cursor.getInt(colAllowed));
    int connection = (cursor.isNull(colConnection) ? -1 : cursor.getInt(colConnection));
    int interactive = (cursor.isNull(colInteractive) ? -1 : cursor.getInt(colInteractive));

    // Get views/*from  www  .  j  a  v  a2  s . c o m*/
    TextView tvTime = (TextView) view.findViewById(R.id.tvTime);
    TextView tvProtocol = (TextView) view.findViewById(R.id.tvProtocol);
    TextView tvFlags = (TextView) view.findViewById(R.id.tvFlags);
    TextView tvSAddr = (TextView) view.findViewById(R.id.tvSAddr);
    TextView tvSPort = (TextView) view.findViewById(R.id.tvSPort);
    final TextView tvDaddr = (TextView) view.findViewById(R.id.tvDAddr);
    TextView tvDPort = (TextView) view.findViewById(R.id.tvDPort);
    final TextView tvOrganization = (TextView) view.findViewById(R.id.tvOrganization);
    ImageView ivIcon = (ImageView) view.findViewById(R.id.ivIcon);
    TextView tvUid = (TextView) view.findViewById(R.id.tvUid);
    TextView tvData = (TextView) view.findViewById(R.id.tvData);
    ImageView ivConnection = (ImageView) view.findViewById(R.id.ivConnection);
    ImageView ivInteractive = (ImageView) view.findViewById(R.id.ivInteractive);

    // Show time
    tvTime.setText(new SimpleDateFormat("HH:mm:ss").format(time));

    // Show connection type
    if (connection <= 0)
        ivConnection.setImageResource(allowed > 0 ? R.drawable.host_allowed : R.drawable.host_blocked);
    else {
        if (allowed > 0)
            ivConnection.setImageResource(connection == 1 ? R.drawable.wifi_on : R.drawable.other_on);
        else
            ivConnection.setImageResource(connection == 1 ? R.drawable.wifi_off : R.drawable.other_off);
    }
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        Drawable wrap = DrawableCompat.wrap(ivConnection.getDrawable());
        DrawableCompat.setTint(wrap, allowed > 0 ? colorOn : colorOff);
    }

    // Show if screen on
    if (interactive <= 0)
        ivInteractive.setImageDrawable(null);
    else {
        ivInteractive.setImageResource(R.drawable.screen_on);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            Drawable wrap = DrawableCompat.wrap(ivInteractive.getDrawable());
            DrawableCompat.setTint(wrap, colorOn);
        }
    }

    // Show protocol name
    tvProtocol.setText(Util.getProtocolName(protocol, version, false));

    // SHow TCP flags
    tvFlags.setText(flags);
    tvFlags.setVisibility(TextUtils.isEmpty(flags) ? View.GONE : View.VISIBLE);

    // Show source and destination port
    if (protocol == 6 || protocol == 17) {
        tvSPort.setText(sport < 0 ? "" : getKnownPort(sport));
        tvDPort.setText(dport < 0 ? "" : getKnownPort(dport));
    } else {
        tvSPort.setText(sport < 0 ? "" : Integer.toString(sport));
        tvDPort.setText(dport < 0 ? "" : Integer.toString(dport));
    }

    // Application icon
    ApplicationInfo info = null;
    PackageManager pm = context.getPackageManager();
    String[] pkg = pm.getPackagesForUid(uid);
    if (pkg != null && pkg.length > 0)
        try {
            info = pm.getApplicationInfo(pkg[0], 0);
        } catch (PackageManager.NameNotFoundException ignored) {
        }
    if (info == null)
        ivIcon.setImageDrawable(null);
    else if (info.icon == 0)
        Picasso.with(context).load(android.R.drawable.sym_def_app_icon).into(ivIcon);
    else {
        Uri uri = Uri.parse("android.resource://" + info.packageName + "/" + info.icon);
        Picasso.with(context).load(uri).resize(iconSize, iconSize).into(ivIcon);
    }

    // https://android.googlesource.com/platform/system/core/+/master/include/private/android_filesystem_config.h
    uid = uid % 100000; // strip off user ID
    if (uid == -1)
        tvUid.setText("");
    else if (uid == 0)
        tvUid.setText(context.getString(R.string.title_root));
    else if (uid == 9999)
        tvUid.setText("-"); // nobody
    else
        tvUid.setText(Integer.toString(uid));

    // Show source address
    tvSAddr.setText(getKnownAddress(saddr));

    // Show destination address
    if (resolve && !isKnownAddress(daddr))
        if (dname == null) {
            if (tvDaddr.getTag() == null) {
                tvDaddr.setText(daddr);
                new AsyncTask<String, Object, String>() {
                    @Override
                    protected void onPreExecute() {
                        tvDaddr.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 name) {
                        Object tag = tvDaddr.getTag();
                        if (tag != null && (Long) tag == id)
                            tvDaddr.setText(">" + name);
                        tvDaddr.setTag(null);
                    }
                }.execute(daddr);
            }
        } else
            tvDaddr.setText(dname);
    else
        tvDaddr.setText(getKnownAddress(daddr));

    // Show organization
    tvOrganization.setVisibility(View.GONE);
    if (organization) {
        if (!isKnownAddress(daddr) && tvOrganization.getTag() == null)
            new AsyncTask<String, Object, String>() {
                @Override
                protected void onPreExecute() {
                    tvOrganization.setTag(id);
                }

                @Override
                protected String doInBackground(String... args) {
                    try {
                        return Util.getOrganization(args[0]);
                    } catch (Throwable ex) {
                        Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                        return null;
                    }
                }

                @Override
                protected void onPostExecute(String organization) {
                    Object tag = tvOrganization.getTag();
                    if (organization != null && tag != null && (Long) tag == id) {
                        tvOrganization.setText(organization);
                        tvOrganization.setVisibility(View.VISIBLE);
                    }
                    tvOrganization.setTag(null);
                }
            }.execute(daddr);
    }

    // Show extra data
    if (TextUtils.isEmpty(data)) {
        tvData.setText("");
        tvData.setVisibility(View.GONE);
    } else {
        tvData.setText(data);
        tvData.setVisibility(View.VISIBLE);
    }
}

From source file:com.zhengde163.netguard.AdapterLog.java

@Override
public void bindView(final View view, final Context context, final Cursor cursor) {
    // Get values
    final long id = cursor.getLong(colID);
    long time = cursor.getLong(colTime);
    int version = (cursor.isNull(colVersion) ? -1 : cursor.getInt(colVersion));
    int protocol = (cursor.isNull(colProtocol) ? -1 : cursor.getInt(colProtocol));
    String flags = cursor.getString(colFlags);
    String saddr = cursor.getString(colSAddr);
    int sport = (cursor.isNull(colSPort) ? -1 : cursor.getInt(colSPort));
    String daddr = cursor.getString(colDAddr);
    int dport = (cursor.isNull(colDPort) ? -1 : cursor.getInt(colDPort));
    String dname = (cursor.isNull(colDName) ? null : cursor.getString(colDName));
    int uid = (cursor.isNull(colUid) ? -1 : cursor.getInt(colUid));
    String data = cursor.getString(colData);
    int allowed = (cursor.isNull(colAllowed) ? -1 : cursor.getInt(colAllowed));
    int connection = (cursor.isNull(colConnection) ? -1 : cursor.getInt(colConnection));
    int interactive = (cursor.isNull(colInteractive) ? -1 : cursor.getInt(colInteractive));

    // Get views/*from   w  ww .jav  a 2s. c o m*/
    TextView tvTime = (TextView) view.findViewById(R.id.tvTime);
    TextView tvProtocol = (TextView) view.findViewById(R.id.tvProtocol);
    //        TextView tvFlags = (TextView) view.findViewById(R.id.tvFlags);
    TextView tvSAddr = (TextView) view.findViewById(R.id.tvSAddr);
    TextView tvSPort = (TextView) view.findViewById(R.id.tvSPort);
    final TextView tvDaddr = (TextView) view.findViewById(R.id.tvDAddr);
    TextView tvDPort = (TextView) view.findViewById(R.id.tvDPort);
    final TextView tvOrganization = (TextView) view.findViewById(R.id.tvOrganization);
    ImageView ivIcon = (ImageView) view.findViewById(R.id.ivIcon);
    TextView tvUid = (TextView) view.findViewById(R.id.tvUid);
    TextView tvData = (TextView) view.findViewById(R.id.tvData);
    ImageView ivConnection = (ImageView) view.findViewById(R.id.ivConnection);
    ImageView ivInteractive = (ImageView) view.findViewById(R.id.ivInteractive);

    // Show time
    tvTime.setText(new SimpleDateFormat("HH:mm:ss").format(time));

    // Show connection type
    if (connection <= 0)
        ivConnection.setImageResource(allowed > 0 ? R.drawable.host_allowed : R.drawable.host_blocked);
    else {
        if (allowed > 0)
            ivConnection.setImageResource(connection == 1 ? R.drawable.wifi_on : R.drawable.other_on);
        else
            ivConnection.setImageResource(connection == 1 ? R.drawable.wifi_off : R.drawable.other_off);
    }
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        Drawable wrap = DrawableCompat.wrap(ivConnection.getDrawable());
        DrawableCompat.setTint(wrap, allowed > 0 ? colorOn : colorOff);
    }

    // Show if screen on
    if (interactive <= 0)
        ivInteractive.setImageDrawable(null);
    else {
        ivInteractive.setImageResource(R.drawable.screen_on);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            Drawable wrap = DrawableCompat.wrap(ivInteractive.getDrawable());
            DrawableCompat.setTint(wrap, colorOn);
        }
    }

    // Show protocol name
    tvProtocol.setText(Util.getProtocolName(protocol, version, false) + flags);

    // SHow TCP flags
    //        tvFlags.setText(flags);
    //        tvFlags.setVisibility(TextUtils.isEmpty(flags) ? View.GONE : View.VISIBLE);

    // Show source and destination port
    if (protocol == 6 || protocol == 17) {
        tvSPort.setText(sport < 0 ? "" : getKnownPort(sport));
        tvDPort.setText(dport < 0 ? "" : getKnownPort(dport));
    } else {
        tvSPort.setText(sport < 0 ? "" : Integer.toString(sport));
        tvDPort.setText(dport < 0 ? "" : Integer.toString(dport));
    }

    // Application icon
    ApplicationInfo info = null;
    PackageManager pm = context.getPackageManager();
    String[] pkg = pm.getPackagesForUid(uid);
    if (pkg != null && pkg.length > 0)
        try {
            info = pm.getApplicationInfo(pkg[0], 0);
        } catch (PackageManager.NameNotFoundException ignored) {
        }
    if (info == null)
        ivIcon.setImageDrawable(null);
    else if (info.icon == 0)
        Picasso.with(context).load(android.R.drawable.sym_def_app_icon).into(ivIcon);
    else {
        Uri uri = Uri.parse("android.resource://" + info.packageName + "/" + info.icon);
        Picasso.with(context).load(uri).resize(iconSize, iconSize).into(ivIcon);
    }

    // https://android.googlesource.com/platform/system/core/+/master/include/private/android_filesystem_config.h
    uid = uid % 100000; // strip off user ID
    if (uid == -1)
        tvUid.setText("");
    else if (uid == 0)
        tvUid.setText(context.getString(R.string.title_root));
    else if (uid == 9999)
        tvUid.setText("-"); // nobody
    else
        tvUid.setText(Integer.toString(uid));

    // Show source address
    tvSAddr.setText(getKnownAddress(saddr));

    // Show destination address
    if (resolve && !isKnownAddress(daddr))
        if (dname == null) {
            if (tvDaddr.getTag() == null) {
                tvDaddr.setText(daddr);
                new AsyncTask<String, Object, String>() {
                    @Override
                    protected void onPreExecute() {
                        tvDaddr.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 name) {
                        Object tag = tvDaddr.getTag();
                        if (tag != null && (Long) tag == id)
                            tvDaddr.setText(">" + name);
                        tvDaddr.setTag(null);
                    }
                }.execute(daddr);
            }
        } else
            tvDaddr.setText(dname);
    else
        tvDaddr.setText(getKnownAddress(daddr));

    // Show organization
    tvOrganization.setVisibility(View.GONE);
    if (organization) {
        if (!isKnownAddress(daddr) && tvOrganization.getTag() == null)
            new AsyncTask<String, Object, String>() {
                @Override
                protected void onPreExecute() {
                    tvOrganization.setTag(id);
                }

                @Override
                protected String doInBackground(String... args) {
                    try {
                        return Util.getOrganization(args[0]);
                    } catch (Throwable ex) {
                        Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                        return null;
                    }
                }

                @Override
                protected void onPostExecute(String organization) {
                    Object tag = tvOrganization.getTag();
                    if (organization != null && tag != null && (Long) tag == id) {
                        tvOrganization.setText(organization);
                        tvOrganization.setVisibility(View.VISIBLE);
                    }
                    tvOrganization.setTag(null);
                }
            }.execute(daddr);
    }

    // Show extra data
    if (TextUtils.isEmpty(data)) {
        tvData.setText("");
        tvData.setVisibility(View.GONE);
    } else {
        tvData.setText(data);
        tvData.setVisibility(View.VISIBLE);
    }
}

From source file:net.bible.service.db.bookmark.BookmarkDBAdapter.java

/** return Dto from current cursor position or null
 * @param c//from w  w w.  ja v  a  2s  .  c o m
 * @return
 * @throws NoSuchKeyException
 */
private BookmarkDto getBookmarkDto(Cursor c) {
    BookmarkDto dto = new BookmarkDto();
    try {
        //Id
        Long id = c.getLong(BookmarkQuery.ID);
        dto.setId(id);

        //Verse
        String key = c.getString(BookmarkQuery.KEY);
        Versification v11n = null;
        if (!c.isNull(BookmarkQuery.VERSIFICATION)) {
            String v11nString = c.getString(BookmarkQuery.VERSIFICATION);
            if (!StringUtils.isEmpty(v11nString)) {
                v11n = Versifications.instance().getVersification(v11nString);
            }
        }
        if (v11n == null) {
            // use default v11n
            v11n = Versifications.instance().getVersification(Versifications.DEFAULT_V11N);
        }
        dto.setVerse(VerseFactory.fromString(v11n, key));

        //Created date
        long created = c.getLong(BookmarkQuery.CREATED_ON);
        dto.setCreatedOn(new Date(created));

    } catch (NoSuchKeyException nke) {
        Log.e(TAG, "Key error", nke);
    }

    return dto;
}

From source file:net.eledge.android.toolkit.db.abstracts.Dao.java

private List<E> mapToEntities(Cursor cursor) {
    List<E> list = new ArrayList<>();
    if (cursor != null) {
        if (cursor.moveToFirst()) {
            do {/*from w w  w. j  a v  a2 s .  co m*/
                try {
                    E instance = clazz.newInstance();
                    for (Field field : clazz.getFields()) {
                        if (field.isAnnotationPresent(Column.class)) {
                            int columnIndex = cursor.getColumnIndex(SQLBuilder.getFieldName(field));
                            if (!cursor.isNull(columnIndex)) {
                                FieldType fieldType = FieldType.getType(field.getType());
                                fieldType.convertToField(instance, field, cursor, columnIndex);
                            }
                        }
                    }
                    list.add(instance);
                } catch (IllegalArgumentException | IllegalAccessException | InstantiationException e) {
                    Log.e(this.getClass().getName(), e.getMessage(), e);
                }
            } while (cursor.moveToNext());
        }
        cursor.close();
    }
    return list;
}

From source file:com.bellman.bible.service.db.bookmark.BookmarkDBAdapter.java

/**
 * return Dto from current cursor position or null
 *
 * @param c//  ww w . jav  a  2s.c om
 * @return
 * @throws NoSuchKeyException
 */
private BookmarkDto getBookmarkDto(Cursor c) {
    BookmarkDto dto = new BookmarkDto();
    try {
        //Id
        Long id = c.getLong(BookmarkQuery.ID);
        dto.setId(id);

        //Verse
        String key = c.getString(BookmarkQuery.KEY);
        Versification v11n = null;
        if (!c.isNull(BookmarkQuery.VERSIFICATION)) {
            String v11nString = c.getString(BookmarkQuery.VERSIFICATION);
            if (!StringUtils.isEmpty(v11nString)) {
                v11n = Versifications.instance().getVersification(v11nString);
            }
        }
        if (v11n == null) {
            // use default v11n
            v11n = Versifications.instance().getVersification(Versifications.DEFAULT_V11N);
        }
        dto.setVerseRange(VerseRangeFactory.fromString(v11n, key));

        //Created date
        long created = c.getLong(BookmarkQuery.CREATED_ON);
        dto.setCreatedOn(new Date(created));

    } catch (NoSuchKeyException nke) {
        Log.e(TAG, "Key error", nke);
    }

    return dto;
}

From source file:com.guess.license.plate.Task.LoadingTaskConn.java

private ServerError insOrUpDB(JSONObject jsObj, String objJS, String[] columns, String whereClause,
        String[] whereArgs, ContentValues values, int serverVersion) throws JSONException {
    ServerError result = ServerError.NO_ERROR;

    Cursor cursor = db.query(objJS, columns, whereClause, whereArgs, null, null, null);
    int count = cursor.getCount();

    if (count > 0) {
        // Getting the version
        int currDBVersion = 0;
        while (cursor.moveToNext()) {
            if (cursor.isNull(0))
                currDBVersion = 0;/*www .j a v  a  2 s .  com*/
            else
                currDBVersion = cursor.getInt(0);
        }

        if (objJS.equals(WebConf.JSON_OBJECTS[0])) {
            if (currDBVersion == serverVersion) {
                return ServerError.OLD_BUILD;
            }

            db.update(objJS, values, whereClause, whereArgs);

        } else if (objJS.equals(WebConf.JSON_OBJECTS[1])) {
            // In case the plate processed is a new version update it in the DB
            if (currDBVersion != serverVersion) {
                db.update(objJS, values, whereClause, whereArgs);
            }
        } else if (objJS.equals(WebConf.JSON_OBJECTS[2])) {
            // In case the language processed is a new version update it in the DB
            if (currDBVersion != serverVersion) {
                db.update(objJS, values, whereClause, whereArgs);
            }
        }
    } else {
        db.insert(objJS, null, values);
    }

    return result;
}

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

@Override
public void bindView(final View view, final Context context, final Cursor cursor) {
    // Get values
    long time = cursor.getLong(colTime);
    int version = (cursor.isNull(colVersion) ? -1 : cursor.getInt(colVersion));
    int protocol = (cursor.isNull(colProtocol) ? -1 : cursor.getInt(colProtocol));
    String flags = cursor.getString(colFlags);
    String saddr = cursor.getString(colSAddr);
    int sport = (cursor.isNull(colSPort) ? -1 : cursor.getInt(colSPort));
    String daddr = cursor.getString(colDAddr);
    int dport = (cursor.isNull(colDPort) ? -1 : cursor.getInt(colDPort));
    String dname = (cursor.isNull(colDName) ? null : cursor.getString(colDName));
    int uid = (cursor.isNull(colUid) ? -1 : cursor.getInt(colUid));
    String data = cursor.getString(colData);
    int allowed = (cursor.isNull(colAllowed) ? -1 : cursor.getInt(colAllowed));
    int connection = (cursor.isNull(colConnection) ? -1 : cursor.getInt(colConnection));
    int interactive = (cursor.isNull(colInteractive) ? -1 : cursor.getInt(colInteractive));

    // Get views//from w  ww  .j a v a  2 s  . c  om
    TextView tvTime = view.findViewById(R.id.tvTime);
    TextView tvProtocol = view.findViewById(R.id.tvProtocol);
    TextView tvFlags = view.findViewById(R.id.tvFlags);
    TextView tvSAddr = view.findViewById(R.id.tvSAddr);
    TextView tvSPort = view.findViewById(R.id.tvSPort);
    final TextView tvDaddr = view.findViewById(R.id.tvDAddr);
    TextView tvDPort = view.findViewById(R.id.tvDPort);
    final TextView tvOrganization = view.findViewById(R.id.tvOrganization);
    final ImageView ivIcon = view.findViewById(R.id.ivIcon);
    TextView tvUid = view.findViewById(R.id.tvUid);
    TextView tvData = view.findViewById(R.id.tvData);
    ImageView ivConnection = view.findViewById(R.id.ivConnection);
    ImageView ivInteractive = view.findViewById(R.id.ivInteractive);

    // Show time
    tvTime.setText(new SimpleDateFormat("HH:mm:ss").format(time));

    // Show connection type
    if (connection <= 0)
        ivConnection.setImageResource(allowed > 0 ? R.drawable.host_allowed : R.drawable.host_blocked);
    else {
        if (allowed > 0)
            ivConnection.setImageResource(connection == 1 ? R.drawable.wifi_on : R.drawable.other_on);
        else
            ivConnection.setImageResource(connection == 1 ? R.drawable.wifi_off : R.drawable.other_off);
    }
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        Drawable wrap = DrawableCompat.wrap(ivConnection.getDrawable());
        DrawableCompat.setTint(wrap, allowed > 0 ? colorOn : colorOff);
    }

    // Show if screen on
    if (interactive <= 0)
        ivInteractive.setImageDrawable(null);
    else {
        ivInteractive.setImageResource(R.drawable.screen_on);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            Drawable wrap = DrawableCompat.wrap(ivInteractive.getDrawable());
            DrawableCompat.setTint(wrap, colorOn);
        }
    }

    // Show protocol name
    tvProtocol.setText(Util.getProtocolName(protocol, version, false));

    // SHow TCP flags
    tvFlags.setText(flags);
    tvFlags.setVisibility(TextUtils.isEmpty(flags) ? View.GONE : View.VISIBLE);

    // Show source and destination port
    if (protocol == 6 || protocol == 17) {
        tvSPort.setText(sport < 0 ? "" : getKnownPort(sport));
        tvDPort.setText(dport < 0 ? "" : getKnownPort(dport));
    } else {
        tvSPort.setText(sport < 0 ? "" : Integer.toString(sport));
        tvDPort.setText(dport < 0 ? "" : Integer.toString(dport));
    }

    // Application icon
    ApplicationInfo info = null;
    PackageManager pm = context.getPackageManager();
    String[] pkg = pm.getPackagesForUid(uid);
    if (pkg != null && pkg.length > 0)
        try {
            info = pm.getApplicationInfo(pkg[0], 0);
        } catch (PackageManager.NameNotFoundException ignored) {
        }

    if (info == null)
        ivIcon.setImageDrawable(null);
    else {
        if (info.icon <= 0)
            ivIcon.setImageResource(android.R.drawable.sym_def_app_icon);
        else {
            ivIcon.setHasTransientState(true);
            final ApplicationInfo finalInfo = info;
            executor.submit(new Runnable() {
                @Override
                public void run() {
                    try {
                        Drawable drawable = context.getPackageManager()
                                .getApplicationIcon(finalInfo.packageName);
                        final Drawable scaledDrawable;
                        if (drawable instanceof BitmapDrawable) {
                            Bitmap original = ((BitmapDrawable) drawable).getBitmap();
                            Bitmap scaled = Bitmap.createScaledBitmap(original, iconSize, iconSize, false);
                            scaledDrawable = new BitmapDrawable(context.getResources(), scaled);
                        } else
                            scaledDrawable = drawable;

                        new Handler(context.getMainLooper()).post(new Runnable() {
                            @Override
                            public void run() {
                                ivIcon.setImageDrawable(scaledDrawable);
                                ivIcon.setHasTransientState(false);
                            }
                        });
                    } catch (Throwable ex) {
                        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                        new Handler(context.getMainLooper()).post(new Runnable() {
                            @Override
                            public void run() {
                                ivIcon.setImageDrawable(null);
                                ivIcon.setHasTransientState(false);
                            }
                        });
                    }
                }
            });
        }
    }

    boolean we = (android.os.Process.myUid() == uid);

    // https://android.googlesource.com/platform/system/core/+/master/include/private/android_filesystem_config.h
    uid = uid % 100000; // strip off user ID
    if (uid == -1)
        tvUid.setText("");
    else if (uid == 0)
        tvUid.setText(context.getString(R.string.title_root));
    else if (uid == 9999)
        tvUid.setText("-"); // nobody
    else
        tvUid.setText(Integer.toString(uid));

    // Show source address
    tvSAddr.setText(getKnownAddress(saddr));

    // Show destination address
    if (!we && resolve && !isKnownAddress(daddr))
        if (dname == null) {
            tvDaddr.setText(daddr);
            new AsyncTask<String, Object, String>() {
                @Override
                protected void onPreExecute() {
                    ViewCompat.setHasTransientState(tvDaddr, 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 name) {
                    tvDaddr.setText(">" + name);
                    ViewCompat.setHasTransientState(tvDaddr, false);
                }
            }.execute(daddr);
        } else
            tvDaddr.setText(dname);
    else
        tvDaddr.setText(getKnownAddress(daddr));

    // Show organization
    tvOrganization.setVisibility(View.GONE);
    if (!we && organization) {
        if (!isKnownAddress(daddr))
            new AsyncTask<String, Object, String>() {
                @Override
                protected void onPreExecute() {
                    ViewCompat.setHasTransientState(tvOrganization, true);
                }

                @Override
                protected String doInBackground(String... args) {
                    try {
                        return Util.getOrganization(args[0]);
                    } catch (Throwable ex) {
                        Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                        return null;
                    }
                }

                @Override
                protected void onPostExecute(String organization) {
                    if (organization != null) {
                        tvOrganization.setText(organization);
                        tvOrganization.setVisibility(View.VISIBLE);
                    }
                    ViewCompat.setHasTransientState(tvOrganization, false);
                }
            }.execute(daddr);
    }

    // Show extra data
    if (TextUtils.isEmpty(data)) {
        tvData.setText("");
        tvData.setVisibility(View.GONE);
    } else {
        tvData.setText(data);
        tvData.setVisibility(View.VISIBLE);
    }
}

From source file:android_network.hetnet.vpn_service.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//w  w  w . ja v  a2s.c o  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))
        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)));
}