How to detect StatusbarNotification large icon possition? - java

I have the following code to get the large icon of a statusbarNotification (sbn):
val extras = sbn.notification.extras
val extraPrsnIcn = if (extras.containsKey(Notification.EXTRA_LARGE_ICON)) extras.get(Notification.EXTRA_LARGE_ICON) else null
It works great, but sometimes this image shown on the left of the statusbarNotification itself such as a Contact icon, or on the right like a weather icon.
How can I check this position (right or left)?

Related

How to get position of a text inside an image and highlight it when image is touched at it's position

In my app i'm having an activity which is having an imageview there i'm basically setting a bitmap into it now here i'm using google vision library to fetch text from images in I've succeeded in that however tricky part is that when imageview is clicked at particular position if it contains any text I want it to get highlighted and again if same is clicked I want to be unhighlighted it's kind of select and unselect effect i tried referring many answers but all of them seem to highlight all texts at runtime but I want only a particular to be highlighted when clicked at that position I guess for that I will need to get text position from images and compare it with touch event but I can't seem to find a way to do it here's my code which i'm using to get text from image:
copyimg.setImageBitmap(ImageCaptureActivity.mbitmap)
val textRecognizer = TextRecognizer.Builder(applicationContext).build()
val imageFrame = Frame.Builder()
.setBitmap(ImageCaptureActivity.mbitmap) // your image bitmap
.build()
var imageText = ""
val textBlocks = textRecognizer.detect(imageFrame)
for (i in 0 until textBlocks.size()) {
val textBlock = textBlocks.get(textBlocks.keyAt(i))
imageText = textBlock.value // return string
Log.i("Okaycheckthis:", imageText)
}
Here's an screenshot of what i'm trying to implement:

return int for the image shows in screen?

I have an android app which i'm building with android studio and I need your help. I will simplify my question:
if we say that the app has two images (image 1 and 2), wheras only one image is displayed on screen and to change the image displayed we use a next button.
I need a code that returns int to the image that is shown on the screen, which
I will use in my if statement:
if (R.id.imageView1 == ) {
Make an index to keep track of it to know what image you are showing.
int currentImage = 1;
In your button labeled next increment the currentImage
currentImage++;
Then you can do
if (currentImage == 1) // We are showing first image
else if(currentImage == 2) // Second image
...

edit text Typeface android

I want to change the Text style on a button click. When the user clicks the button it makes the selected area italic. When the user clicks it again I want the selected area to become non italic. How is this possible. This is my code:
if (id == R.id.italic) {
int startSelection = noteContent.getSelectionStart();
int endSelection = noteContent.getSelectionEnd();
Spannable spannable = noteContent.getText();
StyleSpan[] spans = spannable.getSpans(startSelection, endSelection, StyleSpan.class);
if (spans.length == 0 ) {
spannable.setSpan(new StyleSpan(Typeface.ITALIC), startSelection, endSelection , 0);
} else {
StyleSpanRemover spanRemover = new StyleSpanRemover();
spanRemover.RemoveStyle(spannable, startSelection, endSelection, Typeface.ITALIC);
}
}
When I run this code the selected area becomes Italic on the button click. Then if I were to click the button again the same selected area would become un italic. Sounds like it works fine. But it does not. For some reason if I were to take the same selected area and re italicize it it will not become italic. This is because spans.length is still set to 1. It did not go back to zero when I made the Italicized text normal. Any idea on how to set spans.length back to 0?

can't reduce Bitmap resolution

Hello this question might be a little long but i'm going to explain everything for not
getting the same codes i already tried
i got an app inside of it there's a button contents:
try{
Intent Intent1 = new Intent(MainActivity.this , TheSsecondClass2.class);
Intent1.putExtra("bitmapsent", ImageMap); // from user gallery or camera
startActivityForResult(Intent1, 3);
}
then the app makes "in the new activity" imageview equals ImageMap and scales the Imageview using the code:
Captured.setImageBitmap(ImageMap);
Captured.getLayoutParams().height = 1400;
Captured.getLayoutParams().width = 1200;
then the user edits it a little bit then when he finish it uses button that returns the RESULT_OK and it's code:
overlay(Background, currentleft, currentright, currentTop,currentBottom);
// getting things back when the safr"startactivityforresult" starts
Intent IntentBack = new Intent(TheSsecondClass2.this , MainActivity.class);
IntentBack.putExtra("returnedbitmap", bmOverlay);
IntentBack.putExtras(IntentBack);
setResult(RESULT_OK , IntentBack);
finish();
the overlay method returns bitmap bmoverlay is a mixture of bitmaps for editing purposes like editing left,right
bottom,top and the background or the main picture the issue that bitmaps merge to one image and everything is fine but the problem
that when it's back the bitmap is getting bigger and off the edges of the image view even when adding it to gallery i tried to scale it using:
ScaledBit = Bitmap.createScaledBitmap(ImageMap, 1, 1, true);
ScaledBit = ImageMap;
and used -1 or bigger numbers but it's like making it thousand times bigger or so .
and tried the the two codes below:
CapturedImage.setMaxHeight(200);
CapturedImage.setMaxHeight(200);
Bitmap.setwidth();
Bitmap.setHeight();
i might used more but i forgot about it ,all the variables are declared are below :
Bitmap ImageMap;
ImageView CapturedImage;
static Bitmap currentright,currentleft,currentTop,currentBottom;
static Bitmap bmOverlay ,background;
api level 11.
please help and thanks btw.

How to change a background image of a button in Android without knowing the image name earlier?

I have some image files in drawable folder. The name of the images are like button1, button2, button3......There is also a count variable which increases by one whenever a button is clicked.What I want to do is that whenever someone click on a button image of that button should change to the image corresponding to the current value of count.
I tried
buttons[0][0].setBackground(R.drawable.button+count);
But it is not working
You can't access it directly. You'll have to get the resource using its name:
private Drawable getDrawableResourceByName(int count) {
String packageName = getPackageName();
int resId = getResources().getIdentifier("button" + String.valueOf(count), "drawable", packageName);
return getResources().getDrawable(resId);
}
Then use it as:
buttons[0][0].setBackgroundDrawable(getDrawableResourceByName(count)); //setBackground() only works with drawables from API 16

Categories