List of usage examples for android.database Cursor isLast
boolean isLast();
From source file:com.bilibili.boxing.model.task.impl.ImageTask.java
private void queryThumbnails(ContentResolver cr, String[] projection) { Cursor cur = null; try {/*w ww.jav a2 s .com*/ cur = Images.Thumbnails.queryMiniThumbnails(cr, Images.Thumbnails.EXTERNAL_CONTENT_URI, Images.Thumbnails.MINI_KIND, projection); if (cur != null && cur.moveToFirst()) { do { String imageId = cur.getString(cur.getColumnIndex(Images.Thumbnails.IMAGE_ID)); String imagePath = cur.getString(cur.getColumnIndex(Images.Thumbnails.DATA)); mThumbnailMap.put(imageId, imagePath); } while (cur.moveToNext() && !cur.isLast()); } } finally { if (cur != null) { cur.close(); } } }
From source file:util.CalendarExporter.java
/** * Asks user for Calendar to be exported to ONLY if there are more than one calendar instances available * @return//from w w w.jav a2s .c om */ @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) private void requireCalendarID() { if (fragmentManager == null) { return; } Cursor calendarCursor = null; try { String[] projection = new String[] { CalendarContract.Calendars._ID, CalendarContract.Calendars.ACCOUNT_NAME, CalendarContract.Calendars.CALENDAR_DISPLAY_NAME, CalendarContract.Calendars.NAME, CalendarContract.Calendars.CALENDAR_COLOR }; calendarCursor = contentResolver.query(CalendarContract.Calendars.CONTENT_URI, projection, null, null, null); calendarCursor.moveToFirst(); if (calendarCursor.isFirst() && calendarCursor.isLast()) { //Only one calendar available... nothing to be selected... Log.d("CalendarCursor", "ONLY ONE calendar instance available"); return; } else { final List<Integer> ids = new ArrayList<Integer>(); final List<StringBuilder> sb = new ArrayList<StringBuilder>(); final StringBuilder[] sbArray = new StringBuilder[1]; while (!calendarCursor.isLast()) { //only add calendars with different ids if (!ids.contains(calendarCursor.getInt(0))) { sb.add(new StringBuilder(calendarCursor.getString(3))); ids.add(Integer.parseInt(calendarCursor.getString(0))); } calendarCursor.moveToNext(); } final CalendarPickerDialog cpd = CalendarPickerDialog.newInstance(sb.toArray(sbArray), new CalendarChosenListener() { public void selected(int id) { calendarID = ids.get(id); Thread t = new Thread() { public void run() { doUpdate(); } }; t.start(); } public void canceled() { return; } }); cpd.show(fragmentManager, "chooser"); } } catch (Exception ex) { Log.d("Require Calendar ID", "Error", ex); if (calendarCursor != null) { calendarCursor.close(); } } }
From source file:com.android.server.MaybeDatabaseHelper.java
public void listTableContents() { Cursor cursor = null; try {//from w ww. j av a 2 s . c o m cursor = sDatabase.query(APP_TABLE_NAME, null, null, null, null, null, null, null); if (cursor.moveToFirst()) { while (true) { Log.v(DBTAG, "Row: Package=" + cursor.getString(cursor.getColumnIndex(PACKAGE_COL)) + " | URL=" + cursor.getString(cursor.getColumnIndex(URL_COL)) + " | DATA=" + cursor.getString(cursor.getColumnIndex(DATA_COL))); if (cursor.isLast()) break; cursor.moveToNext(); } } } catch (IllegalStateException e) { Log.e(DBTAG, "getAppDataFromDB failed", e); } finally { if (cursor != null) cursor.close(); } }
From source file:com.annanovas.bestprice.Fragment.DashBoardFragment.java
private void updateDashboard() { int imageDimen = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.size_150dp), getResources().getDisplayMetrics()); myDB.open();/*w w w.ja va 2s. c om*/ Cursor cursor = myDB.getUserInfo(userType, sharedPreferences.getString("user_phone_number", "")); if (userType == AppGlobal.CAR_OWNER) { carLayout.setVisibility(View.VISIBLE); quotationLayout.setVisibility(View.VISIBLE); searchProductLayout.setVisibility(View.VISIBLE); if (myDB.getUserCount() > 1) { buttonUserType.setVisibility(View.VISIBLE); } if (!cursor.isLast()) { while (cursor.moveToNext()) { String name = ""; if (cursor.getString(cursor.getColumnIndex("firstname")) != null && !cursor.getString(cursor.getColumnIndex("firstname")).equals("null")) { name = cursor.getString(cursor.getColumnIndex("firstname")) + " "; } if (cursor.getString(cursor.getColumnIndex("middlename")) != null && !cursor.getString(cursor.getColumnIndex("middlename")).equals("null")) { name = name + cursor.getString(cursor.getColumnIndex("middlename")) + " "; } if (cursor.getString(cursor.getColumnIndex("lastname")) != null && !cursor.getString(cursor.getColumnIndex("lastname")).equals("null")) { name = name + cursor.getString(cursor.getColumnIndex("lastname")); } tvName.setText(name.trim()); tvPhoneNumber.setText(cursor.getString(cursor.getColumnIndex("phone"))); tvEmail.setText(cursor.getString(cursor.getColumnIndex("email"))); if (cursor.getString(cursor.getColumnIndex("image")) != null && !cursor.getString(cursor.getColumnIndex("image")).equals("null")) { //showLog("Image Path: " + AppGlobal.userImagePath + cursor.getString(cursor.getColumnIndex("image"))); Glide.with(getActivity()) .load(AppGlobal.userImagePath + cursor.getString(cursor.getColumnIndex("image"))) .error(R.drawable.ic_car_owner).dontAnimate().override(imageDimen, imageDimen) .into(userImage); } else { userImage.setImageResource(R.drawable.ic_car_owner); } sharedPreferences.edit() .putString("api_token", cursor.getString(cursor.getColumnIndex("api_token"))).apply(); sharedPreferences.edit().putInt("user_id", cursor.getInt(cursor.getColumnIndex("id"))).apply(); } } cursor.close(); tvUserType.setText(getResources().getString(R.string.user_type1)); } else if (userType == AppGlobal.SUPPLIER) { tvAddress.setVisibility(View.VISIBLE); tvDealership.setVisibility(View.VISIBLE); quotationLayout.setVisibility(View.VISIBLE); if (myDB.getUserCount() > 1) { buttonUserType.setVisibility(View.VISIBLE); } if (!cursor.isLast()) { while (cursor.moveToNext()) { String name = ""; if (cursor.getString(cursor.getColumnIndex("firstname")) != null && !cursor.getString(cursor.getColumnIndex("firstname")).equals("null")) { name = name + cursor.getString(cursor.getColumnIndex("firstname")) + " "; } if (cursor.getString(cursor.getColumnIndex("middlename")) != null && !cursor.getString(cursor.getColumnIndex("middlename")).equals("null")) { name = name + cursor.getString(cursor.getColumnIndex("middlename")) + " "; } if (cursor.getString(cursor.getColumnIndex("lastname")) != null && !cursor.getString(cursor.getColumnIndex("lastname")).equals("null")) { name = name + cursor.getString(cursor.getColumnIndex("lastname")); } tvName.setText(name.trim()); tvAddress.setText(cursor.getString(cursor.getColumnIndex("address"))); tvPhoneNumber.setText(cursor.getString(cursor.getColumnIndex("phone"))); tvEmail.setText(cursor.getString(cursor.getColumnIndex("email"))); tvDealership.setText("Dealership With: " + myDB.getBrandsNameFromUserId(cursor.getInt(cursor.getColumnIndex("id")))); if (cursor.getString(cursor.getColumnIndex("image")) != null && !cursor.getString(cursor.getColumnIndex("image")).equals("null")) { Glide.with(getActivity()) .load(AppGlobal.userImagePath + cursor.getString(cursor.getColumnIndex("image"))) .error(R.drawable.ic_supplier).dontAnimate().override(imageDimen, imageDimen) .into(userImage); } else { userImage.setImageResource(R.drawable.ic_supplier); } sharedPreferences.edit() .putString("api_token", cursor.getString(cursor.getColumnIndex("api_token"))).apply(); sharedPreferences.edit().putInt("user_id", cursor.getInt(cursor.getColumnIndex("id"))).apply(); } } cursor.close(); tvUserType.setText(getResources().getString(R.string.user_type2)); } else if (userType == AppGlobal.DRIVER) { tvDrivingLicense.setVisibility(View.VISIBLE); tvNid.setVisibility(View.VISIBLE); tvExperience.setVisibility(View.VISIBLE); pendingTaskLayout.setVisibility(View.VISIBLE); if (!cursor.isLast()) { while (cursor.moveToNext()) { String name = ""; if (cursor.getString(cursor.getColumnIndex("firstname")) != null && !cursor.getString(cursor.getColumnIndex("firstname")).equals("null")) { name = name + cursor.getString(cursor.getColumnIndex("firstname")) + " "; } if (cursor.getString(cursor.getColumnIndex("middlename")) != null && !cursor.getString(cursor.getColumnIndex("middlename")).equals("null")) { name = name + cursor.getString(cursor.getColumnIndex("middlename")) + " "; } if (cursor.getString(cursor.getColumnIndex("lastname")) != null && !cursor.getString(cursor.getColumnIndex("lastname")).equals("null")) { name = name + cursor.getString(cursor.getColumnIndex("lastname")); } tvName.setText(name.trim()); tvPhoneNumber.setText(cursor.getString(cursor.getColumnIndex("phone"))); tvEmail.setText(cursor.getString(cursor.getColumnIndex("email"))); tvDrivingLicense.setText( "Driving License no.: " + cursor.getString(cursor.getColumnIndex("drivinglicence"))); tvNid.setText("NID no.: " + cursor.getString(cursor.getColumnIndex("nid"))); tvExperience.setText( "Years of Experience: " + cursor.getString(cursor.getColumnIndex("yearofexperience"))); if (cursor.getString(cursor.getColumnIndex("image")) != null && !cursor.getString(cursor.getColumnIndex("image")).equals("null")) { Glide.with(getActivity()) .load(AppGlobal.userImagePath + cursor.getString(cursor.getColumnIndex("image"))) .error(R.drawable.ic_driver).dontAnimate().override(imageDimen, imageDimen) .into(userImage); } else { userImage.setImageResource(R.drawable.ic_driver); } sharedPreferences.edit() .putString("api_token", cursor.getString(cursor.getColumnIndex("api_token"))).apply(); sharedPreferences.edit().putInt("user_id", cursor.getInt(cursor.getColumnIndex("id"))).apply(); } } cursor.close(); tvUserType.setText(getResources().getString(R.string.user_type3)); } else if (userType == AppGlobal.SHOP_WORKER) { tvShopName.setVisibility(View.VISIBLE); tvNid.setVisibility(View.VISIBLE); pendingTaskLayout.setVisibility(View.VISIBLE); if (!cursor.isLast()) { while (cursor.moveToNext()) { String name = ""; if (cursor.getString(cursor.getColumnIndex("firstname")) != null && !cursor.getString(cursor.getColumnIndex("firstname")).equals("null")) { name = name + cursor.getString(cursor.getColumnIndex("firstname")) + " "; } if (cursor.getString(cursor.getColumnIndex("middlename")) != null && !cursor.getString(cursor.getColumnIndex("middlename")).equals("null")) { name = name + cursor.getString(cursor.getColumnIndex("middlename")) + " "; } if (cursor.getString(cursor.getColumnIndex("lastname")) != null && !cursor.getString(cursor.getColumnIndex("lastname")).equals("null")) { name = name + cursor.getString(cursor.getColumnIndex("lastname")); } tvName.setText(name.trim()); tvPhoneNumber.setText(cursor.getString(cursor.getColumnIndex("phone"))); tvEmail.setText(cursor.getString(cursor.getColumnIndex("email"))); tvShopName.setText("Shop Name: " + cursor.getString(cursor.getColumnIndex("shopname"))); tvNid.setText("NID no.: " + cursor.getString(cursor.getColumnIndex("nid"))); if (cursor.getString(cursor.getColumnIndex("image")) != null && !cursor.getString(cursor.getColumnIndex("image")).equals("null")) { Glide.with(getActivity()) .load(AppGlobal.userImagePath + cursor.getString(cursor.getColumnIndex("image"))) .error(R.drawable.ic_shop_worker).dontAnimate().override(imageDimen, imageDimen) .into(userImage); } else { userImage.setImageResource(R.drawable.ic_shop_worker); } sharedPreferences.edit() .putString("api_token", cursor.getString(cursor.getColumnIndex("api_token"))).apply(); sharedPreferences.edit().putInt("user_id", cursor.getInt(cursor.getColumnIndex("id"))).apply(); } } cursor.close(); tvUserType.setText(getResources().getString(R.string.user_type4)); } myDB.close(); }
From source file:com.bilibili.boxing.model.task.impl.AlbumTask.java
private void buildAlbumInfo(ContentResolver cr) { String[] distinctBucketColumns = new String[] { Media.BUCKET_ID, Media.BUCKET_DISPLAY_NAME }; Cursor bucketCursor = null; try {//from www .j a v a 2 s . co m bucketCursor = cr.query(Media.EXTERNAL_CONTENT_URI, distinctBucketColumns, "0==0)" + " GROUP BY(" + Media.BUCKET_ID, null, Media.DATE_MODIFIED + " desc"); if (bucketCursor != null && bucketCursor.moveToFirst()) { do { String buckId = bucketCursor.getString(bucketCursor.getColumnIndex(Media.BUCKET_ID)); String name = bucketCursor.getString(bucketCursor.getColumnIndex(Media.BUCKET_DISPLAY_NAME)); AlbumEntity album = buildAlbumInfo(name, buckId); if (!TextUtils.isEmpty(buckId)) { buildAlbumCover(cr, buckId, album); } } while (bucketCursor.moveToNext() && !bucketCursor.isLast()); } } finally { if (bucketCursor != null) { bucketCursor.close(); } } }
From source file:net.simonvt.cathode.ui.fragment.ShowFragment.java
private void updateGenreViews(final Cursor cursor) { if (cursor.getCount() > 0) { StringBuilder sb = new StringBuilder(); final int genreColumnIndex = cursor.getColumnIndex(ShowGenreColumns.GENRE); cursor.moveToPosition(-1);/*from w ww . j a v a 2 s. c om*/ while (cursor.moveToNext()) { sb.append(cursor.getString(genreColumnIndex)); if (!cursor.isLast()) sb.append(", "); } genres = sb.toString(); } else { genres = null; } updateTitle(); }
From source file:com.bilibili.boxing.model.task.impl.ImageTask.java
private void addItem(final int allCount, final List<ImageMedia> result, Cursor cursor, @NonNull final IMediaTaskCallback<ImageMedia> callback) { if (cursor != null && cursor.moveToFirst()) { do {/*w w w . j av a2s .co m*/ String picPath = cursor.getString(cursor.getColumnIndex(Images.Media.DATA)); if (callback.needFilter(picPath)) { BoxingLog.d("path:" + picPath + " has been filter"); } else { String id = cursor.getString(cursor.getColumnIndex(Images.Media._ID)); String size = cursor.getString(cursor.getColumnIndex(Images.Media.SIZE)); String mimeType = cursor.getString(cursor.getColumnIndex(Images.Media.MIME_TYPE)); int width = 0; int height = 0; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { width = cursor.getInt(cursor.getColumnIndex(Images.Media.WIDTH)); height = cursor.getInt(cursor.getColumnIndex(Images.Media.HEIGHT)); } ImageMedia imageItem = new ImageMedia.Builder(id, picPath) .setThumbnailPath(mThumbnailMap.get(id)).setSize(size).setMimeType(mimeType) .setHeight(height).setWidth(width).build(); if (!result.contains(imageItem)) { result.add(imageItem); } } } while (!cursor.isLast() && cursor.moveToNext()); postMedias(result, allCount, callback); } else { postMedias(result, 0, callback); } clear(); }
From source file:com.roamprocess1.roaming4world.syncadapter.SyncAdapter.java
public String[] fetch_contact_list(Cursor c) { String concat_contact_list = ""; String[] allConcat_contact_list = new String[c.getCount()]; phoneContacts = new String[c.getCount()]; allConcat_contact_list_Name = new String[c.getCount()]; allContactsPhone = new String[c.getCount()]; //System.out.println("Cccccc"+c.getCount()); String Country_zip_code = GetCountryZipCode(); int i = 0;/*from w w w . ja v a2 s . c o m*/ while (c.moveToNext()) { String value = c.getString(c.getColumnIndex(Data.DATA1)); String Name = c.getString(c.getColumnIndex(Data.DISPLAY_NAME)); //System.out.println("Data:"+_id+":"+contact_Id +":"+value+":"+Name+":"); value = value.replaceAll("\\s+", ""); value = value.replaceAll("-", ""); //System.out.println("Number =="+value); if (!c.isLast()) { if (!value.startsWith("*") && !value.startsWith("#")) { if (value.startsWith("+")) { allConcat_contact_list[i] = value.substring(1) + ","; allContactsPhone[i] = allConcat_contact_list[i] + Name; } else if (value.startsWith("00")) { String modify_contact_no = value.substring(2); modify_contact_no = Country_zip_code + modify_contact_no; allConcat_contact_list[i] = modify_contact_no.toString() + ","; allContactsPhone[i] = allConcat_contact_list[i] + Name; } else if (value.startsWith("0")) { String modify_contact_no = value.substring(1); modify_contact_no = Country_zip_code + modify_contact_no; allConcat_contact_list[i] = modify_contact_no.toString() + ","; allContactsPhone[i] = allConcat_contact_list[i] + Name; } else if (!value.startsWith("+") && !value.startsWith("0")) { allConcat_contact_list[i] = Country_zip_code + value.toString() + ","; allContactsPhone[i] = allConcat_contact_list[i] + Name; } } } else { if (!value.startsWith("*") && !value.startsWith("#")) { if (value.startsWith("+")) { allConcat_contact_list[i] = value.substring(1); allContactsPhone[i] = allConcat_contact_list[i] + "," + Name; } else if (value.startsWith("00")) { String modify_contact_no = value.substring(2); modify_contact_no = Country_zip_code + modify_contact_no; allConcat_contact_list[i] = modify_contact_no.toString(); allContactsPhone[i] = allConcat_contact_list[i] + "," + Name; } else if (value.startsWith("0")) { String modify_contact_no = value.substring(1); modify_contact_no = Country_zip_code + modify_contact_no; allConcat_contact_list[i] = modify_contact_no.toString(); allContactsPhone[i] = allConcat_contact_list[i] + "," + Name; } else if (!value.startsWith("+") && !value.startsWith("0")) { allConcat_contact_list[i] = Country_zip_code + value.toString(); allContactsPhone[i] = allConcat_contact_list[i] + "," + Name; } } } i++; } c.close(); for (int x = 0; x < allConcat_contact_list.length; x++) { String number; if (allConcat_contact_list[x] != null || allContactsPhone[x] != null) { number = allConcat_contact_list[x].replace(",", ""); phoneContacts[x] = number; //System.out.println("number without ,:"+number+":"+allContactsPhone[x]); } else { phoneContacts[x] = allConcat_contact_list[x]; //System.out.println("number without ,:"+allConcat_contact_list[x]); } concat_contact_list += allConcat_contact_list[x]; } //System.out.println("phoneContacts:length:allConcat_contact_list:length: "+phoneContacts.length+":"+allConcat_contact_list.length+":"+allContactsPhone.length); //System.out.println("allConcat_contact_list:length:"+allConcat_contact_list.length); return allConcat_contact_list; }
From source file:com.android.email.activity.MessageView.java
/** * Update the arrows based on the current position of the older/newer cursor. *//*from w ww . j av a2 s .c o m*/ private void updateNavigationArrows(Cursor cursor) { if (cursor != null) { boolean hasNewer, hasOlder; if (cursor.isAfterLast() || cursor.isBeforeFirst()) { // The cursor not being on a message means that the current message was not found. // While this should not happen, simply disable prev/next arrows in that case. hasNewer = hasOlder = false; } else { hasNewer = !cursor.isFirst(); hasOlder = !cursor.isLast(); } mMoveToNewer.setVisibility(hasNewer ? View.VISIBLE : View.INVISIBLE); mMoveToOlder.setVisibility(hasOlder ? View.VISIBLE : View.INVISIBLE); } }
From source file:com.annanovas.bestprice.DashBoardEditActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_dash_board_edit); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);//w w w.j a v a 2 s .c o m ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setHomeButtonEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true); } // chosenBrandList.add(new ArrayList<String>()); // chosenBrandList.add(new ArrayList<String>()); // chosenBrandList.add(new ArrayList<String>()); etAddress = (EditText) findViewById(R.id.et_address); etEmail = (EditText) findViewById(R.id.et_email); etShopName = (EditText) findViewById(R.id.et_shop_name); etDrivingLicense = (EditText) findViewById(R.id.et_driving_licence); etNid = (EditText) findViewById(R.id.et_nid); etExperience = (EditText) findViewById(R.id.et_experience); etFirstName = (EditText) findViewById(R.id.et_first_name); etMiddleName = (EditText) findViewById(R.id.et_middle_name); etLastName = (EditText) findViewById(R.id.et_last_name); etPhoneNumber = (EditText) findViewById(R.id.et_phone); tvAddress = (TextView) findViewById(R.id.tv_address); tvArea = (TextView) findViewById(R.id.tv_area); tvDealerShip = (LinearLayout) findViewById(R.id.tv_dealership); tvDealerShipWith = (TextView) findViewById(R.id.tv_dealership_content); tvSelectedProduct = (TextView) findViewById(R.id.tv_select_product_content); tvProduct = (LinearLayout) findViewById(R.id.tv_select_product); buttonSubmit = (Button) findViewById(R.id.button_submit); areaLayout = (LinearLayout) findViewById(R.id.layout_area); brandLayout = (LinearLayout) findViewById(R.id.layout_brand); productLayout = (LinearLayout) findViewById(R.id.layout_product); layoutCamera = (LinearLayout) findViewById(R.id.layout_camera); layoutGallery = (LinearLayout) findViewById(R.id.layout_gallery); userImage = (ImageView) findViewById(R.id.iv_user_image); areaRecyclerView = (RecyclerView) findViewById(R.id.recycler_view_area); brandRecyclerView = (RecyclerView) findViewById(R.id.recycler_view_brand); productRecyclerView = (RecyclerView) findViewById(R.id.recycler_view_product); etProductSearch = (EditText) findViewById(R.id.et_product_name); etBrandSearch = (EditText) findViewById(R.id.et_brand_name); etAreaSearch = (EditText) findViewById(R.id.et_area_name); layoutSearchArea = (LinearLayout) findViewById(R.id.layout_search_area); layoutSearchProduct = (LinearLayout) findViewById(R.id.layout_search_product); layoutSearchBrand = (LinearLayout) findViewById(R.id.layout_search_brand); tvSelectedBrand = (TextView) findViewById(R.id.tv_selected_brand); tvSelectedArea = (TextView) findViewById(R.id.tv_setect_area); ivArrow1 = (ImageView) findViewById(R.id.iv_arrow1); ivArrow2 = (ImageView) findViewById(R.id.iv_arrow2); ivArrow3 = (ImageView) findViewById(R.id.iv_arrow3); ivArrow4 = (ImageView) findViewById(R.id.iv_arrow4); myDB = MyDatabaseManager.getInstance(getApplicationContext()); sharedPreferences = getSharedPreferences(AppGlobal.MY_PREFS_NAME, MODE_PRIVATE); userType = sharedPreferences.getInt("user_type", 1); int imageDimen = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.size_150dp), getResources().getDisplayMetrics()); myDB.open(); Cursor cursor = myDB.getUserInfo(userType, sharedPreferences.getString("user_phone_number", "")); if (userType == AppGlobal.CAR_OWNER) { userImage.setImageResource(R.drawable.ic_car_owner); tvAddress.setVisibility(View.VISIBLE); etAddress.setVisibility(View.VISIBLE); tvArea.setVisibility(View.VISIBLE); areaLayout.setVisibility(View.VISIBLE); if (!cursor.isLast()) { while (cursor.moveToNext()) { etFirstName.setText(cursor.getString(cursor.getColumnIndex("firstname"))); etMiddleName.setText(cursor.getString(cursor.getColumnIndex("middlename"))); etLastName.setText(cursor.getString(cursor.getColumnIndex("lastname"))); if (cursor.getString(cursor.getColumnIndex("address")) != null && !cursor.getString(cursor.getColumnIndex("address")).equals("null")) { etAddress.setText(cursor.getString(cursor.getColumnIndex("address"))); } etPhoneNumber.setText(cursor.getString(cursor.getColumnIndex("phone"))); etEmail.setText(cursor.getString(cursor.getColumnIndex("email"))); etShopName.setText(cursor.getString(cursor.getColumnIndex("shopname"))); areaId = cursor.getInt(cursor.getColumnIndex("area_id")); if (areaId != 0) { tvSelectedArea.setText(myDB.getAreaName(areaId)); } else { tvSelectedArea.setText(getResources().getString(R.string.select_area)); } if (cursor.getString(cursor.getColumnIndex("image")) != null && !cursor.getString(cursor.getColumnIndex("image")).equals("null")) { Glide.with(getApplicationContext()) .load(AppGlobal.userImagePath + cursor.getString(cursor.getColumnIndex("image"))) .error(R.drawable.ic_supplier).dontAnimate().override(imageDimen, imageDimen) .into(userImage); } else { userImage.setImageResource(R.drawable.ic_car_owner); } } } cursor.close(); generateAreaRecyclerView(); } else if (userType == AppGlobal.SUPPLIER) { tvAddress.setVisibility(View.VISIBLE); etAddress.setVisibility(View.VISIBLE); tvDealerShip.setVisibility(View.VISIBLE); tvProduct.setVisibility(View.VISIBLE); tvArea.setVisibility(View.VISIBLE); brandLayout.setVisibility(View.VISIBLE); productLayout.setVisibility(View.VISIBLE); areaLayout.setVisibility(View.VISIBLE); etShopName.setVisibility(View.VISIBLE); if (!cursor.isLast()) { while (cursor.moveToNext()) { etFirstName.setText(cursor.getString(cursor.getColumnIndex("firstname"))); etMiddleName.setText(cursor.getString(cursor.getColumnIndex("middlename"))); etLastName.setText(cursor.getString(cursor.getColumnIndex("lastname"))); etPhoneNumber.setText(cursor.getString(cursor.getColumnIndex("phone"))); etEmail.setText(cursor.getString(cursor.getColumnIndex("email"))); etShopName.setText(cursor.getString(cursor.getColumnIndex("shopname"))); etAddress.setText(cursor.getString(cursor.getColumnIndex("address"))); areaId = cursor.getInt(cursor.getColumnIndex("area_id")); if (areaId != 0) { tvSelectedArea.setText(myDB.getAreaName(areaId)); } else { tvSelectedArea.setText(getResources().getString(R.string.select_area)); } selectedProductIdList = myDB.getSelectedProductList(cursor.getInt(cursor.getColumnIndex("id"))); chosenBrandIdList = myDB.getSelectedBrandList(cursor.getInt(cursor.getColumnIndex("id"))); if (cursor.getString(cursor.getColumnIndex("image")) != null && !cursor.getString(cursor.getColumnIndex("image")).equals("null")) { Glide.with(getApplicationContext()) .load(AppGlobal.userImagePath + cursor.getString(cursor.getColumnIndex("image"))) .error(R.drawable.ic_supplier).dontAnimate().override(imageDimen, imageDimen) .into(userImage); } else { userImage.setImageResource(R.drawable.ic_supplier); } } } cursor.close(); generateAreaRecyclerView(); generateProductRecyclerView(); } else if (userType == AppGlobal.DRIVER) { etDrivingLicense.setVisibility(View.VISIBLE); etNid.setVisibility(View.VISIBLE); etExperience.setVisibility(View.VISIBLE); if (!cursor.isLast()) { while (cursor.moveToNext()) { etFirstName.setText(cursor.getString(cursor.getColumnIndex("firstname"))); etMiddleName.setText(cursor.getString(cursor.getColumnIndex("middlename"))); etLastName.setText(cursor.getString(cursor.getColumnIndex("lastname"))); etAddress.setText(cursor.getString(cursor.getColumnIndex("address"))); etPhoneNumber.setText(cursor.getString(cursor.getColumnIndex("phone"))); etEmail.setText(cursor.getString(cursor.getColumnIndex("email"))); etDrivingLicense.setText(cursor.getString(cursor.getColumnIndex("drivinglicence"))); etNid.setText(cursor.getString(cursor.getColumnIndex("nid"))); etExperience.setText(cursor.getString(cursor.getColumnIndex("yearofexperience"))); if (cursor.getString(cursor.getColumnIndex("image")) != null && !cursor.getString(cursor.getColumnIndex("image")).equals("null")) { Glide.with(getApplicationContext()) .load(AppGlobal.userImagePath + cursor.getString(cursor.getColumnIndex("image"))) .error(R.drawable.ic_supplier).dontAnimate().override(imageDimen, imageDimen) .into(userImage); } else { userImage.setImageResource(R.drawable.ic_car_owner); } } } cursor.close(); } else if (userType == AppGlobal.SHOP_WORKER) { etShopName.setVisibility(View.VISIBLE); etNid.setVisibility(View.VISIBLE); if (!cursor.isLast()) { while (cursor.moveToNext()) { etFirstName.setText(cursor.getString(cursor.getColumnIndex("firstname"))); etMiddleName.setText(cursor.getString(cursor.getColumnIndex("middlename"))); etLastName.setText(cursor.getString(cursor.getColumnIndex("lastname"))); etAddress.setText(cursor.getString(cursor.getColumnIndex("address"))); etPhoneNumber.setText(cursor.getString(cursor.getColumnIndex("phone"))); etEmail.setText(cursor.getString(cursor.getColumnIndex("email"))); etShopName.setText(cursor.getString(cursor.getColumnIndex("shopname"))); etNid.setText(cursor.getString(cursor.getColumnIndex("nid"))); if (cursor.getString(cursor.getColumnIndex("image")) != null && !cursor.getString(cursor.getColumnIndex("image")).equals("null")) { Glide.with(getApplicationContext()) .load(AppGlobal.userImagePath + cursor.getString(cursor.getColumnIndex("image"))) .error(R.drawable.ic_supplier).dontAnimate().override(imageDimen, imageDimen) .into(userImage); } else { userImage.setImageResource(R.drawable.ic_car_owner); } } } cursor.close(); } myDB.close(); areaLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (layoutSearchArea.getVisibility() == View.GONE) { layoutSearchArea.setVisibility(View.VISIBLE); areaRecyclerView.setVisibility(View.VISIBLE); ivArrow2.setImageDrawable( ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_up_arrow)); } else { layoutSearchArea.setVisibility(View.GONE); areaRecyclerView.setVisibility(View.GONE); ivArrow2.setImageDrawable( ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_down_arrow)); } } }); brandLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (selectedProductIdList.size() == 0) { Toast.makeText(getApplicationContext(), R.string.add_product, Toast.LENGTH_SHORT).show(); return; } if (layoutSearchBrand.getVisibility() == View.GONE) { layoutSearchBrand.setVisibility(View.VISIBLE); brandRecyclerView.setVisibility(View.VISIBLE); ivArrow3.setImageDrawable( ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_up_arrow)); } else { layoutSearchBrand.setVisibility(View.GONE); brandRecyclerView.setVisibility(View.GONE); ivArrow3.setImageDrawable( ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_down_arrow)); } } }); productLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (layoutSearchProduct.getVisibility() == View.GONE) { layoutSearchProduct.setVisibility(View.VISIBLE); productRecyclerView.setVisibility(View.VISIBLE); ivArrow1.setImageDrawable( ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_up_arrow)); } else { layoutSearchProduct.setVisibility(View.GONE); productRecyclerView.setVisibility(View.GONE); ivArrow1.setImageDrawable( ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_down_arrow)); } } }); layoutCamera.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { try { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); File file = createImageFile(); imageUri = String.valueOf(file); // showLog(imageUri); Uri photoURI = FileProvider.getUriForFile(getApplicationContext(), BuildConfig.APPLICATION_ID + ".provider", file); intent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI); startActivityForResult(intent, REQUEST_CAMERA); } catch (IOException e) { e.printStackTrace(); } } }); layoutGallery.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI); intent.setType("image/*"); startActivityForResult(Intent.createChooser(intent, "Select File"), SELECT_FILE); } }); buttonSubmit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { progressDialog = new ProgressDialog(DashBoardEditActivity.this); progressDialog.setMessage(getResources().getString(R.string.please_wait)); progressDialog.setCancelable(false); progressDialog.show(); UpdateUserInfo updateUserInfo = new UpdateUserInfo(getApplicationContext()); updateUserInfo.signUpListener = DashBoardEditActivity.this; //viewEnable(false); if (userType == AppGlobal.CAR_OWNER) { boolean hasError = false; boolean hasPhoneNoError = false; if (etFirstName.getText().length() == 0) { etFirstName.setError(getResources().getString(R.string.enter_first_name)); hasError = true; } if (etLastName.getText().length() == 0) { etLastName.setError(getResources().getString(R.string.enter_last_name)); hasError = true; } if (etPhoneNumber.getText().length() == 0) { etPhoneNumber.setError(getResources().getString(R.string.enter_phone_no)); hasError = true; hasPhoneNoError = true; } if (!hasPhoneNoError && etPhoneNumber.getText().length() != 11) { etPhoneNumber.setError(getResources().getString(R.string.enter_valid_phone_no)); hasError = true; } if (etEmail.getText().length() != 0 && !Patterns.EMAIL_ADDRESS.matcher(etEmail.getText().toString()).matches()) { etEmail.setError(getResources().getString(R.string.enter_valid_email)); hasError = true; } if (etAddress.getText().length() == 0) { etAddress.setError(getResources().getString(R.string.enter_address)); hasError = true; } if (hasError) { if (progressDialog.isShowing()) progressDialog.dismiss(); return; } HashMap<String, String> params = new HashMap<>(); params.put("authentication", AppGlobal.authentication); params.put("api_token", sharedPreferences.getString("api_token", "")); params.put("phone", etPhoneNumber.getText().toString()); params.put("firstname", etFirstName.getText().toString()); if (!etMiddleName.getText().toString().equals("")) { params.put("middlename", etMiddleName.getText().toString()); } params.put("lastname", etLastName.getText().toString()); params.put("district_id", "1"); params.put("area_id", String.valueOf(areaId)); params.put("address", etAddress.getText().toString()); if (!etEmail.getText().toString().equals("")) { params.put("email", etEmail.getText().toString()); } if (!image.equals("")) { params.put("image", image); } updateUserInfo.parseData(params, "updateCarOwnerInfo"); } else if (userType == AppGlobal.SUPPLIER) { boolean hasError = false; boolean hasPhoneNoError = false; if (etFirstName.getText().length() == 0) { etFirstName.setError(getResources().getString(R.string.enter_first_name)); hasError = true; } if (etLastName.getText().length() == 0) { etLastName.setError(getResources().getString(R.string.enter_last_name)); hasError = true; } if (etPhoneNumber.getText().length() == 0) { etPhoneNumber.setError(getResources().getString(R.string.enter_phone_no)); hasError = true; hasPhoneNoError = true; } if (!hasPhoneNoError && etPhoneNumber.getText().length() != 11) { etPhoneNumber.setError(getResources().getString(R.string.enter_valid_phone_no)); hasError = true; } if (etEmail.getText().length() != 0 && !Patterns.EMAIL_ADDRESS.matcher(etEmail.getText().toString()).matches()) { etEmail.setError(getResources().getString(R.string.enter_valid_email)); hasError = true; } if (etShopName.getText().length() == 0) { etShopName.setError(getResources().getString(R.string.enter_shop_name)); hasError = true; } if (etAddress.getText().length() == 0) { etAddress.setError(getResources().getString(R.string.enter_address)); hasError = true; } if (hasError) { if (progressDialog.isShowing()) progressDialog.dismiss(); return; } HashMap<String, String> params = new HashMap<>(); params.put("authentication", AppGlobal.authentication); params.put("api_token", sharedPreferences.getString("api_token", "")); params.put("phone", etPhoneNumber.getText().toString()); params.put("firstname", etFirstName.getText().toString()); if (!etMiddleName.getText().toString().equals("")) { params.put("middlename", etMiddleName.getText().toString()); } params.put("lastname", etLastName.getText().toString()); params.put("district_id", "1"); params.put("area_id", String.valueOf(areaId)); if (!etEmail.getText().toString().equals("")) { params.put("email", etEmail.getText().toString()); } if (!image.equals("")) { params.put("image", image); } params.put("shopname", etShopName.getText().toString()); params.put("address", etAddress.getText().toString()); for (int i = 0; i < selectedProductIdList.size(); i++) { params.put("products[" + i + "]", selectedProductIdList.get(i)); } for (int i = 0; i < chosenBrandIdList.size(); i++) { params.put("brands[" + i + "]", chosenBrandIdList.get(i)); } updateUserInfo.parseData(params, "updateSupplierInfo"); } else if (userType == AppGlobal.DRIVER) { boolean hasError = false; boolean hasPhoneNoError = false; boolean hasDrivingLicenseNoError = false; boolean hasNidNoError = false; if (etFirstName.getText().length() == 0) { etFirstName.setError(getResources().getString(R.string.enter_first_name)); hasError = true; } if (etLastName.getText().length() == 0) { etLastName.setError(getResources().getString(R.string.enter_last_name)); hasError = true; } if (etPhoneNumber.getText().length() == 0) { etPhoneNumber.setError(getResources().getString(R.string.enter_phone_no)); hasError = true; hasPhoneNoError = true; } if (!hasPhoneNoError && etPhoneNumber.getText().length() != 11) { etPhoneNumber.setError(getResources().getString(R.string.enter_valid_phone_no)); hasError = true; } if (etEmail.getText().length() != 0 && !Patterns.EMAIL_ADDRESS.matcher(etEmail.getText().toString()).matches()) { etEmail.setError(getResources().getString(R.string.enter_valid_email)); hasError = true; } if (etDrivingLicense.getText().length() == 0) { etDrivingLicense.setError(getResources().getString(R.string.enter_driving_licence)); hasError = true; hasDrivingLicenseNoError = true; } if (!hasDrivingLicenseNoError && etDrivingLicense.getText().length() != 15) { etDrivingLicense.setError(getResources().getString(R.string.enter_valid_driving_licence)); hasError = true; } if (etNid.getText().length() == 0) { etNid.setError(getResources().getString(R.string.enter_nid_no)); hasError = true; hasNidNoError = true; } if (!hasNidNoError && etNid.getText().length() != 17) { etNid.setError(getResources().getString(R.string.enter_valid_nid)); hasError = true; } if (etExperience.getText().length() == 0) { etExperience.setError(getResources().getString(R.string.enter_year_of_experience)); hasError = true; } if (hasError) { if (progressDialog.isShowing()) progressDialog.dismiss(); return; } HashMap<String, String> params = new HashMap<>(); params.put("authentication", AppGlobal.authentication); params.put("api_token", sharedPreferences.getString("api_token", "")); params.put("phone", etPhoneNumber.getText().toString()); params.put("firstname", etFirstName.getText().toString()); if (!etMiddleName.getText().toString().equals("")) { params.put("middlename", etMiddleName.getText().toString()); } params.put("lastname", etLastName.getText().toString()); params.put("drivinglicence", etDrivingLicense.getText().toString()); params.put("nid", etNid.getText().toString()); params.put("yearofexperience", etExperience.getText().toString()); if (!etEmail.getText().toString().equals("")) { params.put("email", etEmail.getText().toString()); } if (!image.equals("")) { params.put("image", image); } updateUserInfo.parseData(params, "updateDriverInfo"); } else if (userType == AppGlobal.SHOP_WORKER) { boolean hasError = false; boolean hasPhoneNoError = false; if (etFirstName.getText().length() == 0) { etFirstName.setError(getResources().getString(R.string.enter_first_name)); hasError = true; } if (etLastName.getText().length() == 0) { etLastName.setError(getResources().getString(R.string.enter_last_name)); hasError = true; } if (etPhoneNumber.getText().length() == 0) { etPhoneNumber.setError(getResources().getString(R.string.enter_phone_no)); hasError = true; hasPhoneNoError = true; } if (!hasPhoneNoError && etPhoneNumber.getText().length() != 11) { etPhoneNumber.setError(getResources().getString(R.string.enter_valid_phone_no)); hasError = true; } if (etEmail.getText().length() != 0 && !Patterns.EMAIL_ADDRESS.matcher(etEmail.getText().toString()).matches()) { etEmail.setError(getResources().getString(R.string.enter_valid_email)); hasError = true; } if (etNid.getText().length() == 0) { etNid.setError(getResources().getString(R.string.enter_nid_no)); hasError = true; } if (etShopName.getText().length() == 0) { etShopName.setError(getResources().getString(R.string.enter_shop_name)); hasError = true; } if (hasError) { if (progressDialog.isShowing()) progressDialog.dismiss(); return; } HashMap<String, String> params = new HashMap<>(); params.put("authentication", AppGlobal.authentication); params.put("api_token", sharedPreferences.getString("api_token", "")); params.put("phone", etPhoneNumber.getText().toString()); params.put("firstname", etFirstName.getText().toString()); if (!etMiddleName.getText().toString().equals("")) { params.put("middlename", etMiddleName.getText().toString()); } params.put("lastname", etLastName.getText().toString()); params.put("nid", etNid.getText().toString()); params.put("shopname", etShopName.getText().toString()); if (!etEmail.getText().toString().equals("")) { params.put("email", etEmail.getText().toString()); } if (!image.equals("")) { params.put("image", image); } updateUserInfo.parseData(params, "updateWorkerInfo"); } } }); }