How to Display the text in Reverse from char to String - android

I tried to display the text but it is displaying in wrong view. I want to display the Textview in reverse. I tried this code
String subMenuId = (String) key[position];
String subMenuName = subMenuTable.get(subMenuId);
for (int x = 0; x < subMenuName.length(); x++) {
int splitword = subMenuName.charAt(x);
char c = (char) splitword;
TextView product = new TextView(con);
product.setText(String.valueOf(c));
product.setRotation(-90);
holder.tv.setGravity(Gravity.CENTER_VERTICAL);
product.setTextSize(12);
holder.tv.setPadding(5,0,5,0);
product.setTextColor(Color.BLACK);
product.setTypeface(null, Typeface.BOLD);
holder.tv.addView(product);
}

Try the following
String reversedString = new StringBuilder("LIKE").reverse().toString()

Just reverse your loop
i.e.
for (int x = 0; x < subMenuName.length(); x++)
to
for (int x = subMenuName.length() -1; x >=0 ; x--)
Hope it helps
When you iterate from 0 ⇢ n first char get referred first and will be added to top. since you want it in reverse, iterate n ⇢ 0

Related

Collections.fill ArrayList with multiple values, not the same value

I'm using Android Studio where I have an array with a size of 126, and I initially fill them with 0's. Then I have an input with a size of 63, I want it to "replace" the first 126 values, instead of adding 63 to the 126.
For example I have an array of length 5 ( [0,0,0,0,0] ). Then I input 1,2,3 as individuals. I want it to look like [1,2,3,0,0] instead of [0,0,0,0,0,1,2,3]
example code:
ArrayList<Float> list = new ArrayList<Float>(Collections.<Float>nCopies(126, Float.valueOf(0)));
Then I add by (edited):
for (int j = 0; j < loop; j++) {
float xx = result.multiHandLandmarks().get(i).getLandmark(j).getX();
floaat yy = result.multiHandLandmarks().get(i).getLandmark(j).getY();
float zz = result.multiHandLandmarks().get(i).getLandmark(j).getZ();
list.add(xx);
list.add(yy);
list.add(zz);
}
When you use
list.add(x.get(i))
it will be added to the end of the array.
use this :
list.add(i , x.get(i))
the first parameter is index, second is the value;
You don't need to add, that's the problem, you need to set.
For example:
for (int i = 0; i < newList.size(); i++) { //like i < 63
oldList.set(i, newList.get(i)); //your new value
}

Android OpenCV color detection in HSV space

i tried to wrote color(green) detection code for android(live camera view) in OpenCV. first use RGB space and it's half okay but when switch to the HSV space the result is the mess !!!
this is my code
Mat A = src;
Mat B = dst;
Imgproc.cvtColor(A, A, Imgproc.COLOR_RGB2HSV,3);
Size sizeA = A.size();
for (int i = 0; i < sizeA.height; i++)
for (int j = 0; j < sizeA.width; j++) {
double[] data = A.get(i, j);
if (data[0]>=95 && data[0]<=130 & data[1]>=150 && data[1]<=255 & data[2]<=150 && data[2]<=255){
data[0] = 120;
data[1] = 255 ;
data[2] = 255 ;
}
else
data[0] = 100;
data[1] = 255;
data[2] = 255;
B.put(i, j, data);
}
Imgproc.cvtColor(B, B, Imgproc.COLOR_RGB2RGBA, 4);}
}
what's wrong with this code ? and this method run slowly.why?
(i new to android and OpenCV)
Tnx
You should probably convert from BGR (not RGB) to HSV, but that depends on your code before this snippet
Imgproc.cvtColor(A, A, Imgproc.COLOR_BGR2HSV,3);
Check your if statement and use always && (you sometimes use &)
You should convert from HSV to RGB and then to RGBA
Imgproc.cvtColor(B, B, Imgproc.COLOR_HSV2RGB, 3);}
Imgproc.cvtColor(B, B, Imgproc.COLOR_RGB2RGBA, 4);}

how to get pixel color using byte array in Android

In my Android project,
Here is my code.
for (int x = 0; x < targetBitArray.length; x += weight) {
for (int y = 0; y < targetBitArray[x].length; y += weight) {
targetBitArray[x][y] = bmp.getPixel(x, y) == mSearchColor;
}
}
but this code wastes a lot of time.
So I need to find way faster than bitmap.getPixel().
I'm trying to get pixel color using byte array converted from bitmap, but I can't.
How to replace Bitmap.getPixel()?
Each Bitmap.getPixel method invocation requires a lot of resources, so you need to avoid the amount of requests in order to improve the performace of your code.
My suggestion is:
Read the image data row-by-row with Bitmap.getPixels method into a local array
Iterate along your local array
e.g.
int [] rowData= new int [bitmapWidth];
for (int row = 0; row < bitmapHeight; row ++) {
// Load row of pixels
bitmap.getPixels(rowData, 0, bitmapWidth, 0, row, bitmapWidth, 1);
for (int column = 0; column < bitmapWidth; column ++) {
targetBitArray[column][row] = rowData(column) == mSearchColor;
}
}
This will be a great improvement for the performace of your code

How to detect color line in image using android java

If I have an image containing black lines, like the image below. How can I detect the black lines.( to know the x,y of dots on this lines) ?
I want to know how to get started with this topic. What library should I learn to go through
You can use Catalano Framework.
http://code.google.com/p/catalano-framework/
FastBitmap image = new FastBitmap(bitmap);
image.toGrayscale();
int width = image.getWidth();
int height = image.getHeight();
ArrayList<IntPoint> lst = new ArrayList<>();
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
if (image.getGray(i, j) == 0)
lst.add(new IntPoint(i,j));
}
}

get the position of image after shuffle list of Imageview array

int[] images2 = {
R.drawable.wrong, R.drawable.reviewp,
R.drawable.bowl, R.drawable.ic_action_search
};
List<int[]> pic=Arrays.asList(images2);
Collections.shuffle(pic);
Random random = new Random();
for(int i = 0 ; i <= 3 ; i++){
ReciverI[i].setBackgroundResource(images2[ "at here i want to get the image position" ]);
}
help me to get the position of image
this is not working
ReciverI[i].setBackgroundResource(images2[Integer.parseInt(pic.get(i).toString())]);
this give me wrong result
I rewrite the code
Solution 1
Integer[] images2 = {R.drawable.wrong, R.drawable.reviewp, R.drawable.bowl,R.drawable.ic_action_search};
List<Integer> pic=Arrays.asList(images2);
Collections.shuffle(pic);
for(int i = 0 ; i <= pic.size() ; i++){
ReciverI[i].setBackgroundResource(pic.get(i))
}
You want absolutely to conserve the primitiv int then you have to make a little walk around
Solution 2
List<Integer> pic = new ArrayList<Integer>();
for (int index = 0; index < images2.length; index++)
{
pic.add(images2[index]);
}
Collections.shuffle(pic);
for(int i = 0 ; i <= pic.size() ; i++){
ReciverI[i].setBackgroundResource(pic.get(i))
}
ReciverI[i].setBackgroundResource(pic.get(i))
Sorry wasn't paying attention. You should just make your List<int> and it will work.
As your snippet is now, it has no use to have a List of integer arrays.

Categories

Resources