Cannot relate seek bar to text - java

I am trying to relate my seekbar to the text. With assistance, I tried to do so, but my attempt have been unsuccessful.
Also I want to also include a range seek bar in the below is the code, but not sure how to work that out. Any assistance would be greatly appreciated.
public class ProfileCreation extends Activity {
private static final int RESULT_LOAD_IMAGE = 1;
FrameLayout layout;
Button save;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile_creation);
save = (Button) findViewById(R.id.button2);
String picturePath = PreferenceManager.getDefaultSharedPreferences(this).getString("picturePath", "");
if (!picturePath.equals("")) {
ImageView imageView = (ImageView) findViewById(R.id.profilePicturePreview);
imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
}
Button buttonLoadImage = (Button) findViewById(R.id.btnPictureSelect);
buttonLoadImage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
Intent i = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, RESULT_LOAD_IMAGE);
}
});
save.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
// Locate the image in res >
Bitmap bitmap = BitmapFactory.decodeFile("picturePath");
// Convert it to byte
ByteArrayOutputStream stream = new ByteArrayOutputStream();
// Compress image to lower quality scale 1 - 100
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
Object image = null;
try {
String path = null;
image = readInFile(path);
} catch (Exception e) {
e.printStackTrace();
}
// Create the ParseFile
ParseFile file = new ParseFile("picturePath", (byte[]) image);
// Upload the image into Parse Cloud
file.saveInBackground();
// Create a New Class called "ImageUpload" in Parse
ParseObject imgupload = new ParseObject("Image");
// Create a column named "ImageName" and set the string
imgupload.put("Image", "picturePath");
// Create a column named "ImageFile" and insert the image
imgupload.put("ImageFile", file);
// Create the class and the columns
imgupload.saveInBackground();
// Show a simple toast message
SeekBar seekBar = (SeekBar) findViewById(R.id.seekBarDistance);
final TextView seekBarValue = (TextView) findViewById(R.id.seekBarDistanceValue);
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
#Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub
seekBarValue.setText(String.valueOf(progress));
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
});
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK
&& null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
ImageView imageView = (ImageView) findViewById(R.id.profilePicturePreview);
imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
}
}
private byte[] readInFile(String path) throws IOException {
// TODO Auto-generated method stub
byte[] data = null;
File file = new File(path);
InputStream input_stream = new BufferedInputStream(new FileInputStream(
file));
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
data = new byte[16384]; // 16K
int bytes_read;
while ((bytes_read = input_stream.read(data, 0, data.length)) != -1) {
buffer.write(data, 0, bytes_read);
}
input_stream.close();
return buffer.toByteArray();
}
}
Updated code
public class ProfileCreation extends Activity {
private static final int RESULT_LOAD_IMAGE = 1;
FrameLayout layout;
Button save;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile_creation);
save = (Button) findViewById(R.id.button2);
String picturePath = PreferenceManager.getDefaultSharedPreferences(this).getString("picturePath", "");
if (!picturePath.equals("")) {
ImageView imageView = (ImageView) findViewById(R.id.profilePicturePreview);
imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
}
SeekBar seekBar = (SeekBar) findViewById(R.id.seekBarDistance);
final TextView seekBarValue = (TextView) findViewById(R.id.seekBarDistanceValue);
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
#Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub
seekBarValue.setText(String.valueOf(progress));
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
}
Button buttonLoadImage = (Button) findViewById(R.id.btnPictureSelect);
buttonLoadImage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
Intent i = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, RESULT_LOAD_IMAGE);
}
});
save.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
// Locate the image in res >
Bitmap bitmap = BitmapFactory.decodeFile("picturePath");
// Convert it to byte
ByteArrayOutputStream stream = new ByteArrayOutputStream();
// Compress image to lower quality scale 1 - 100
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
Object image = null;
try {
String path = null;
image = readInFile(path);
} catch (Exception e) {
e.printStackTrace();
}
// Create the ParseFile
ParseFile file = new ParseFile("picturePath", (byte[]) image);
// Upload the image into Parse Cloud
file.saveInBackground();
// Create a New Class called "ImageUpload" in Parse
ParseObject imgupload = new ParseObject("Image");
// Create a column named "ImageName" and set the string
imgupload.put("Image", "picturePath");
// Create a column named "ImageFile" and insert the image
imgupload.put("ImageFile", file);
// Create the class and the columns
imgupload.saveInBackground();
// Show a simple toast message
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK
&& null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
ImageView imageView = (ImageView) findViewById(R.id.profilePicturePreview);
imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
}
}
private byte[] readInFile(String path) throws IOException {
// TODO Auto-generated method stub
byte[] data = null;
File file = new File(path);
InputStream input_stream = new BufferedInputStream(new FileInputStream(
file));
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
data = new byte[16384]; // 16K
int bytes_read;
while ((bytes_read = input_stream.read(data, 0, data.length)) != -1) {
buffer.write(data, 0, bytes_read);
}
input_stream.close();
return buffer.toByteArray();
}
}

Below code snippet should be moved out of onClickListener. Write it in onCreate
SeekBar seekBar = (SeekBar) findViewById(R.id.seekBarDistance);
final TextView seekBarValue = (TextView) findViewById(R.id.seekBarDistanceValue);
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
#Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub
seekBarValue.setText(String.valueOf(progress));
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
});

Related

How to upload this gridview of base 64 converted images to firebase?

This is the code I am working on, make a multiple selection of images and the most in a gridview array that calls it ImageList, but I would recommend converting the images to a base64 to have more efficiency when uploading and displaying the images, so I looked for examples and documentation and I found a way to convert them, but I was somewhat confused, because the array where the images are stored was ready List of images I had to pass it to a chain of chains, but I did not understand very well how to upload them to the firebase both the storage and the database, since they are images that will be saved of products that will be shown in the store this is the code
here is the activity where the data will be uploaded, the data as name price and description already uploaded to the database the imagenes not.
public class adminActivity extends AppCompatActivity {
private EditText nombreP, precioP, infoP;
int PICK_IMAGE = 100;
Uri imagenUri;
Button btnCargar;
Button btnEditar;
GridView gvImagenes;
List<Uri> listaImagenes = new ArrayList<>();
List<Uri> listaBase64Imagenes = new ArrayList<>();
GridViewAdapter baseAdapter;
FirebaseDatabase firebaseDatabase;
DatabaseReference databaseReference;
StorageReference mStorageRef;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_admin);
/*INICIALIZAMOS LA CONEXION CON FIREBASE*/
FirebaseApp.initializeApp(this);
firebaseDatabase = FirebaseDatabase.getInstance();
databaseReference = firebaseDatabase.getReference();
mStorageRef = FirebaseStorage.getInstance().getReference();
nombreP = (EditText) findViewById(R.id.nameProducto);
precioP = (EditText) findViewById(R.id.precioProducto);
infoP = (EditText) findViewById(R.id.infoProducto);
gvImagenes = findViewById(R.id.gvImagenes);
btnEditar = findViewById(R.id.editar);
btnCargar = (Button) findViewById(R.id.cargar);
btnEditar.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
abrirGaleria();
}
});
btnCargar.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String nombre = nombreP.getText().toString();
String precio = precioP.getText().toString().trim();
String infor = infoP.getText().toString();
if (!nombre.isEmpty() && !precio.isEmpty() && !infor.isEmpty()){
cargarUsuario();
limpiarCaja();
}else {
Toast.makeText(adminActivity.this,"Deben llenarse todos los campos.",Toast.LENGTH_SHORT).show();
return;
}
}
});
}
private void limpiarCaja() {
nombreP.setText("");
precioP.setText("");
infoP.setText("");
}
public void cargarUsuario() {
listaBase64Imagenes.clear();
for (int i = 0 ; i < listaImagenes.size() ; i++){
try {
InputStream is = getContentResolver().openInputStream(listaImagenes.get(i));
Bitmap bitmap = BitmapFactory.decodeStream(is);
String cadena = convertirUriToBase64(bitmap);
enviarImagen(cadena);
bitmap.recycle();
} catch (IOException e){
}
}
//Toast.makeText(this, "Producto Registrado", Toast.LENGTH_LONG).show();
String nombre = nombreP.getText().toString();
String precio = precioP.getText().toString();
String infor = infoP.getText().toString();
productos p = new productos();
p.setUid(UUID.randomUUID().toString());
p.setNombre(nombre);
p.setPrecio(precio);
p.setInformacion(infor);
databaseReference.child("Productos").child(p.getUid()).setValue(p);
Toast.makeText(adminActivity.this,"Agregado.",Toast.LENGTH_SHORT).show();
}
private void enviarImagen(final String cadena) {
StorageReference folderRef = mStorageRef.child("imagenesProductos");
folderRef.putFile((Uri) listaImagenes).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
#Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Task<Uri> uriTask = taskSnapshot.getStorage().getDownloadUrl();
while (!uriTask.isSuccessful());
Uri downloadUri = uriTask.getResult();
}
});
}
private String convertirUriToBase64(Bitmap bitmap) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
byte[] bytes = baos.toByteArray();
String encode = Base64.encodeToString(bytes, Base64.DEFAULT);
return encode;
}
private void abrirGaleria() {
Intent intent = new Intent();
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE,true);
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "SELECCIONA LAS IMAGENES"),PICK_IMAGE);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, #Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
ClipData clipData = data.getClipData();
if (resultCode == RESULT_OK && requestCode == PICK_IMAGE){
/*PARA UNA SOLA IMAGEN*/
if (clipData == null){
imagenUri = data.getData();
listaImagenes.add(imagenUri);
}
}else {
/*PARA VARIAS IMAGENES*/
for (int i = 0; i < clipData.getItemCount(); i++){
listaImagenes.add(clipData.getItemAt(i).getUri());
}
}
baseAdapter = new GridViewAdapter(adminActivity.this, listaImagenes);
gvImagenes.setAdapter(baseAdapter);
}
}
and here is the gridview adapter code
#Override
public int getCount() {
return listaImagenes.size();
}
#Override
public Object getItem(int position) {
return listaImagenes.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(final int position, View view, ViewGroup parent) {
if (view == null){
layoutInflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
view = layoutInflater.inflate(R.layout.item_carga_imagenes, null);
}
ImageView ivImagen = view.findViewById(R.id.ivImagen);
ImageButton ibtnEliminar = view.findViewById(R.id.ibtnEliminar);
ivImagen.setImageURI(listaImagenes.get(position));
ibtnEliminar.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
listaImagenes.remove(position);
notifyDataSetChanged();
}
});
return view;
}
}
here i point out the method where i try to make the connection to the storage of firebase, they could help to rebuild it in order to be able to upload them to the storage and also to the database with their respective name, price and description
private void enviarImagen(final String cadena) {
StorageReference folderRef = mStorageRef.child("imagenesProductos");
folderRef.putFile((Uri) listaImagenes).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
#Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Task<Uri> uriTask = taskSnapshot.getStorage().getDownloadUrl();
while (!uriTask.isSuccessful());
Uri downloadUri = uriTask.getResult();
}
});
}
Your question is still little bit of confusion, In my case what i understand from you, you want to store images to firebase in BASE64 format.
String encode = Base64.encodeToString(bytes, Base64.DEFAULT);
Now, you don't have you store string, you can simply store byte[] in firbase and retrive it and just converted it to bitmap, here is a example for you:
byte[] byteImage = Base64.decode(encode, Base64.DEFAULT);
Bitmap imageBitmap = BitmapFactory.decodeByteArray(byteImage, 0, decodedString.length);

How to remember bitmap Uri

i'm trying to do an activity which can show picture from gallery. But my Activity needs to remember bitmap uri for another time so it can always open that picture.
here is my .java
edited
i added something else to convert uri to string then string to uri but it doesn't work. Can someone help?
public class DersProgram extends Activity { private static int RESULT_LOAD_IMAGE = 1;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dersprogrami);
Button buttonLoadImage = (Button) findViewById(R.id.button1);
buttonLoadImage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
Intent i = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, RESULT_LOAD_IMAGE);
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
Uri uri = data.getData();
String BitmapURI;
BitmapURI = uri.toString();
uri = Uri.parse(BitmapURI);
SharedPreferences sharedPreferences = getSharedPreferences("BitmapURI", Context.MODE_PRIVATE);
sharedPreferences.edit().putString("BitmapURI", "your URI as a String").apply();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(uri,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
ImageView imageView = (ImageView) findViewById(R.id.resim);
Bitmap bmp = null;
try {
bmp = getBitmapFromUri(uri);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
imageView.setImageBitmap(bmp);
}
}
private Bitmap getBitmapFromUri(Uri uri) throws IOException {
ParcelFileDescriptor parcelFileDescriptor =
getContentResolver().openFileDescriptor(uri, "r");
FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor();
Bitmap image = BitmapFactory.decodeFileDescriptor(fileDescriptor);
parcelFileDescriptor.close();
return image;
}
}
I want to open picture which is called before. Please help me(also i am a beginner) sorry for my English.
As said, use SharedPreferences.
store your bitmapURI as a String in your Activity:
SharedPreferences sharedPreferences = getSharedPreferences("some string", Context.MODE_PRIVATE);
sharedPreferences.edit().putString("BitmapURI", "your URI as a String").apply();
and retrieve it whenever your want:
String bitmapURI = sharedPreferences.getString("BitmapURI", "default string if BitmapURI is not set");

Retrieving data from Parse

I manage to have the user record information name, headline, age, and even gender selection as well as gender preference in parse. Now I want to be able to retrieve the information, with conditions. For instance, if the current user selected that he is looking for a female, than it would only display queryequal female.
Below is the code where the user enter the information that is submitted to parse:
public class ProfileCreation extends Activity {
private static final int RESULT_LOAD_IMAGE = 1;
FrameLayout layout;
Button save;
protected EditText mName;
protected EditText mAge;
protected EditText mHeadline;
protected ImageView mprofilePicture;
RadioButton male, female;
String gender;
RadioButton lmale, lfemale;
String lgender;
protected Button mConfirm;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile_creation);
RelativeLayout v = (RelativeLayout) findViewById(R.id.main);
v.requestFocus();
Parse.initialize(this, "ID", "ID");
mName = (EditText)findViewById(R.id.etxtname);
mAge = (EditText)findViewById(R.id.etxtage);
mHeadline = (EditText)findViewById(R.id.etxtheadline);
mprofilePicture = (ImageView)findViewById(R.id.profilePicturePreview);
male = (RadioButton)findViewById(R.id.rimale);
female = (RadioButton)findViewById(R.id.rifemale);
lmale = (RadioButton)findViewById(R.id.rlmale);
lfemale = (RadioButton)findViewById(R.id.rlfemale);
mConfirm = (Button)findViewById(R.id.btnConfirm);
mConfirm.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String name = mName.getText().toString();
String age = mAge.getText().toString();
String headline = mHeadline.getText().toString();
age = age.trim();
name = name.trim();
headline = headline.trim();
if (age.isEmpty() || name.isEmpty() || headline.isEmpty()) {
AlertDialog.Builder builder = new AlertDialog.Builder(ProfileCreation.this);
builder.setMessage(R.string.signup_error_message)
.setTitle(R.string.signup_error_title)
.setPositiveButton(android.R.string.ok, null);
AlertDialog dialog = builder.create();
dialog.show();
}
else {
// create the new user!
setProgressBarIndeterminateVisibility(true);
ParseUser currentUser = ParseUser.getCurrentUser();
/* // Locate the image from the ImageView
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
fron image view);
// Convert it to byte
ByteArrayOutputStream stream = new ByteArrayOutputStream();
// Compress image to lower quality scale 1 - 100
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] image = stream.toByteArray();
// Create the ParseFile
ParseFile file = new ParseFile("profilePicture.png", image);
// Upload the image into Parse Cloud
file.saveInBackground();
// Create a column named "ImageName" and set the string
currentUser.put("ImageName", "AndroidBegin Logo");
// Create a column named "ImageFile" and insert the image
currentUser.put("ProfilePicture", file);
// Create the class and the columns
currentUser.saveInBackground(); */
if(male.isChecked())
gender = "Male";
else
gender = "Female";
if(lmale.isChecked())
lgender = "Male";
else
lgender = "Female";
currentUser.put("Name", name);
currentUser.put("Age", age);
currentUser.put("Headline", headline);
currentUser.put("Gender", gender);
currentUser.put("Looking_Gender", lgender);
currentUser.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
setProgressBarIndeterminateVisibility(false);
if (e == null) {
// Success!
Intent intent = new Intent(ProfileCreation.this, MoodActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
}
else {
AlertDialog.Builder builder = new AlertDialog.Builder(ProfileCreation.this);
builder.setMessage(e.getMessage())
.setTitle(R.string.signup_error_title)
.setPositiveButton(android.R.string.ok, null);
AlertDialog dialog = builder.create();
dialog.show();
}
}
});
}
}
});
SeekBar seekBar = (SeekBar) findViewById(R.id.seekBarDistance);
final TextView seekBarValue = (TextView) findViewById(R.id.seekBarDistanceValue);
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
#Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub
seekBarValue.setText(String.valueOf(progress));
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
}); // Add this
Button mcancel = (Button)findViewById(R.id.btnBack);
mcancel.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
ProfileCreation.this.startActivity(new Intent(ProfileCreation.this, LoginActivity.class));
}
});
SeekBar seekBarMinimum = (SeekBar) findViewById(R.id.seekBarMinimumAge);
final TextView txtMinimum = (TextView) findViewById(R.id.tMinAge);
seekBarMinimum.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
#Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub
txtMinimum.setText(String.valueOf(progress));
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
}); // Add this
SeekBar seekBarMaximum = (SeekBar) findViewById(R.id.seekBarMaximumAge);
final TextView txtMaximum = (TextView) findViewById(R.id.tMaxAge);
seekBarMaximum.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
#Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub
txtMaximum.setText(String.valueOf(progress));
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
}); // Add this
Button buttonLoadImage = (Button) findViewById(R.id.btnPictureSelect);
buttonLoadImage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
Intent i = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, RESULT_LOAD_IMAGE);
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK
&& null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
ImageView imageView = (ImageView) findViewById(R.id.profilePicturePreview);
imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
}
}
private byte[] readInFile(String path) throws IOException {
// TODO Auto-generated method stub
byte[] data = null;
File file = new File(path);
InputStream input_stream = new BufferedInputStream(new FileInputStream(
file));
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
data = new byte[16384]; // 16K
int bytes_read;
while ((bytes_read = input_stream.read(data, 0, data.length)) != -1) {
buffer.write(data, 0, bytes_read);
}
input_stream.close();
return buffer.toByteArray();
}
}
Below is the code that I am brainstorming could be used to retrieved information:
currentUserId = ParseUser.getCurrentUser().getObjectId();
names = new ArrayList<String>();
// String userActivitySelectionName = "";
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereNotEqualTo("objectId", currentUserId);
query.whereEqualTo("ActivityName","");
query.whereNotEqualTo("Looking_Gender",currentUserID);
The issue i have now is setting a condition, where if a guy wants to be match with guy so only those guys who want to be match with guys information returns, and vice-versa for women.
Let me know, if this is fine.
Thanks in advance.
The following line will ensure that the Users returned are only users who match the gender for which the current user is looking. That is, if I'm looking for a female, the constraint below will ensure that only females are returned.
query.whereEqualTo("Gender", ParseUser.getCurrentUser().getString("Looking_Gender"));
The following line will ensure that the Users returned are only users who are looking for other users that match the gender for which I am. That is, if I'm a male, the constraint below will ensure that only users who are looking for males will be returned.
query.whereEqualTo("Looking_Gender", ParseUser.getCurrentUser().getString("Gender"));
If I understand your question correctly, using the above two constraints together should achieve what you're looking for.

How to open the camera with more than one button click in Android?

I created camera application in Android. I have created one activity and 3 buttons and 3 image view are included in the same activity. When I have to take snap click on first button that snap will display in first image view, then when I take snap on click second button that snap will display in second image view and same as to third button.
When I run my app camera open success fully and take the snap also done but it can't display in image view same as to another buttons also. Here is my code.
Here is my Activity Code
public class Take_Snap_Page extends Activity
{
ImageView imgPersonalSnap;
ImageView imgAddressProofSnap;
ImageView imgPanCardProofSnap;
ImageView imgHideBitmap;
Button btnPersonal ;
Button btnAddress;
Button btnPanCard;
Button btnSubmitSnap;
Bitmap bp;
Bitmap bitmap ;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.take_snap);
imgPersonalSnap = (ImageView)findViewById(R.id.imagesPersonnalSnap);
imgAddressProofSnap = (ImageView)findViewById(R.id.imageAddressProofSnap);
imgPanCardProofSnap = (ImageView)findViewById(R.id.imagePanCardproofSnap);
imgHideBitmap = (ImageView)findViewById(R.id.imgHide);
btnPersonal = (Button)findViewById(R.id.buttonCapture_Personal_Snap);
btnPersonal.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
open();
imgPersonalSnap.setImageBitmap(bitmap);
}
});
btnAddress = (Button)findViewById(R.id.buttonCapture_AddressSnap);
btnAddress.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
open();
}
});
btnPanCard = (Button)findViewById(R.id.buttonCapture_PanCardSnap);
btnPanCard.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
open();
}
});
}
public void open() {
Intent intent = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 0);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 0)
{
if (resultCode == RESULT_OK && data !=null )
{
// ... now let's see use the picture at data/
bp = (Bitmap) data.getExtras().get("data");
imgHideBitmap.setImageBitmap(bp);
BitmapDrawable drawable = (BitmapDrawable) imgHideBitmap.getDrawable();
bitmap = drawable.getBitmap();
}
}
}
}
Try wit requestCode as like following.
btnAddress.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
open(0);
}
});
btnAddress.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
open(1);
}
});
btnPanCard.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
open(2);
}
});
And
public void open(int requestCode) {
Intent intent = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, requestCode);
}
And
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 0)
{
if (resultCode == RESULT_OK && data !=null )
{
// ... now let's see use the picture at data/
switch(requestCode){
case 0:
bp = (Bitmap) data.getExtras().get("data");
imgPersonalSnap.setImageBitmap(bp);
BitmapDrawable drawable = (BitmapDrawable) imgHideBitmap.getDrawable();
bitmap = drawable.getBitmap();
break;
case 1:
bp = (Bitmap) data.getExtras().get("data");
imgAddressProofSnap.setImageBitmap(bp);
BitmapDrawable drawable = (BitmapDrawable) imgHideBitmap.getDrawable();
bitmap = drawable.getBitmap();
break;
case 2:
bp = (Bitmap) data.getExtras().get("data");
imgPanCardProofSnap.setImageBitmap(bp);
BitmapDrawable drawable = (BitmapDrawable) imgHideBitmap.getDrawable();
bitmap = drawable.getBitmap();
break;
}
}
}
}
I hope this will help you. Let me know what happend
try this,
package com.example.linkedin;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore.MediaColumns;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
public class Take_Snap_Page extends Activity
{
ImageView imgPersonalSnap;
ImageView imgAddressProofSnap;
ImageView imgPanCardProofSnap;
ImageView imgHideBitmap;
Button btnPersonal ;
Button btnAddress;
Button btnPanCard;
Button btnSubmitSnap;
Bitmap bp;
Bitmap bitmap ;
private int FIRSTCLICK=1;
private int SECONDCLICK=2;
private int THIEDCLICK=3;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.take_snap);
imgPersonalSnap = (ImageView)findViewById(R.id.imagesPersonnalSnap);
imgAddressProofSnap = (ImageView)findViewById(R.id.imageAddressProofSnap);
imgPanCardProofSnap = (ImageView)findViewById(R.id.imagePanCardproofSnap);
imgHideBitmap = (ImageView)findViewById(R.id.imgHide);
btnPersonal = (Button)findViewById(R.id.buttonCapture_Personal_Snap);
btnPersonal.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
open(FIRSTCLICK);
}
});
btnAddress = (Button)findViewById(R.id.buttonCapture_AddressSnap);
btnAddress.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
open(SECONDCLICK);
}
});
btnPanCard = (Button)findViewById(R.id.buttonCapture_PanCardSnap);
btnPanCard.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
open(THIEDCLICK);
}
});
}
public void open(int requestCode) {
Intent intent = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, requestCode);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == FIRSTCLICK)
{
if (resultCode == RESULT_OK && data !=null )
{
// ... now let's see use the picture at data/
imgPersonalSnap.setImageBitmap(decodeFile(getAbsolutePath(data.getData())));
}
}else if (requestCode == FIRSTCLICK)
{
if (resultCode == RESULT_OK && data !=null )
{
// ... now let's see use the picture at data/
imgAddressProofSnap.setImageBitmap(decodeFile(getAbsolutePath(data.getData())));
}
}else if (requestCode == FIRSTCLICK)
{
if (resultCode == RESULT_OK && data !=null )
{
// ... now let's see use the picture at data/
imgPanCardProofSnap.setImageBitmap(decodeFile(getAbsolutePath(data.getData())));
}
}
}
public String getAbsolutePath(Uri uri) {
String[] projection = { MediaColumns.DATA };
#SuppressWarnings("deprecation")
Cursor cursor = managedQuery(uri, projection, null, null, null);
if (cursor != null) {
int column_index = cursor.getColumnIndexOrThrow(MediaColumns.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
} else
return null;
}
public Bitmap decodeFile(String path) {
try {
// Decode image size
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeFile(path, o);
// The new size we want to scale to
final int REQUIRED_SIZE = 70;
// Find the correct scale value. It should be the power of 2.
int scale = 1;
while (o.outWidth / scale / 2 >= REQUIRED_SIZE && o.outHeight / scale / 2 >= REQUIRED_SIZE)
scale *= 2;
// Decode with inSampleSize
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize = scale;
return BitmapFactory.decodeFile(path, o2);
} catch (Throwable e) {
e.printStackTrace();
}
return null;
}
}

Zbar Qr Code Reader - crash after qr code reader

I'm trying to do a Qr code reader with Zbar but the app crash after the Qr Code detect (when result != 0)
I'm not getting error message, only a warning:
CHECK surface infomation creating=false formatChanged=false
sizeChanged=false visible=false visibleChanged=true
surfaceChanged=true realSizeChanged=false redrawNeeded=false
left=false top=false
Here is the code which I got the crash
public void onPreviewFrame(byte[] data, Camera camera) {
Camera.Parameters parameters = camera.getParameters();
Camera.Size size = parameters.getPreviewSize();
Image barcode = new Image(size.width, size.height, "Y800");
barcode.setData(data);
int result = mScanner.scanImage(barcode);
if (result != 0) {
mCamera.cancelAutoFocus();
mCamera.setPreviewCallback(null);
mCamera.stopPreview();
mPreviewing = false;
SymbolSet syms = mScanner.getResults();
for (Symbol sym : syms) {
String symData = sym.getData();
if (!TextUtils.isEmpty(symData)) {
Intent dataIntent = new Intent();
dataIntent.putExtra(SCAN_RESULT, symData);
dataIntent.putExtra(SCAN_RESULT_TYPE, sym.getType());
setResult(Activity.RESULT_OK, dataIntent);
finish();
break;
}
}
}
}
I did update my code and it works great! thx all!
public void onPreviewFrame(byte[] data, Camera camera) {
Camera.Parameters parameters = camera.getParameters();
Camera.Size size = parameters.getPreviewSize();
Image barcode = new Image(size.width, size.height, "Y800");
barcode.setData(data);
int result = mScanner.scanImage(barcode);
if (result != 0) {
mCamera.cancelAutoFocus();
mCamera.setPreviewCallback(null);
mCamera.stopPreview();
mPreviewing = false;
SymbolSet syms = mScanner.getResults();
for (Symbol sym : syms) {
String symData = sym.getData();
Log.i("url qr code",symData);
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(symData));
startActivity(browserIntent);
break;
}
}
}
try this... for Qr Reader....
public class QRCodeActivityTest extends Activity implements
OnQRCodeReadListener {
QRCodeReaderView qrView;
TextView tvQr;
Image_Sql sql;
String Description;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.qrtest_layout);
qrView = (QRCodeReaderView) findViewById(R.id.qRCodeReaderView1);
qrView.setOnQRCodeReadListener(this);
tvQr = (TextView) findViewById(R.id.txtqr);
sql= new Image_Sql(this);
sql.Open();
}
#Override
public void onQRCodeRead(String text, PointF[] points) {
// TODO Auto-generated method stub
Cursor desc = sql.fetchNameFromTitle(text);
while (desc.moveToNext()) {
Description = desc.getString(desc
.getColumnIndexOrThrow(Image_Sql.IMAGE_DESCRIPTION));
}
if(text.equals(""))
{
Dialog d = new Dialog(this);
TextView tv = new TextView(this);
tv.setText("Please Sync Catalogue TO Display QRCode Image Information");
d.setContentView(tv);
d.setTitle("Required Syncing..");
d.show();
}else
{
tvQr.setText(Description);
}
}
#Override
public void cameraNotFound() {
// TODO Auto-generated method stub
}
#Override
public void QRCodeNotFoundOnCamImage() {
// TODO Auto-generated method stub
}
#Override
protected void onResume() {
super.onResume();
qrView.getCameraManager().startPreview();
}
#Override
protected void onPause() {
super.onPause();
qrView.getCameraManager().stopPreview();
}
}

Categories