I use Java and Kotlin for personal projects with little experience and I might use your help with this one. What I am trying to do is to read telemetry data (temperature, pressure, light level) from Estimote beacon. I have already managed to put & update values into textviews.
Now I would like to get IF conditions at this point (later I will try to save & upload them to Firebase database). Basically I want to check if one of the telemetry values is higher or less than Double number. Eg. if the light level is below 6 lux, write "Less then 6!", if more "More than 6!"
val scanner = EstimoteBluetoothScannerFactory(applicationContext).getSimpleScanner()
val scanHandler = scanner.estimoteTelemetryFullScan()
.withBalancedPowerMode()
.withOnPacketFoundAction {
var temperature: TextView = findViewById<TextView>(R.id.temperature)
temperature.setText("Temperature: ${it.temperatureInCelsiusDegrees}")
var magnetometer: TextView = findViewById<TextView>(R.id.magnetometer)
magnetometer.setText("Magnetometer: ${it.magnetometer}")
var pressure: TextView = findViewById<TextView>(R.id.pressure)
pressure.setText("Pressure: ${it.pressure}")
var ambientLight: TextView = findViewById<TextView>(R.id.ambientLight)
ambientLight.setText("Ambient Light: ${it.ambientLightInLux}")
var motionState: TextView = findViewById<TextView>(R.id.motionState)
motionState.setText("Motion State: ${it.motionState}")
}
.start()
if(ambientLight > 6) {
var checkLight: TextView = findViewById<TextView>(R.id.checkLight)
checkLight.setText("More than 6!")
}else{
var checkLight: TextView = findViewById<TextView>(R.id.checkLight)
checkLight.setText("Less than 6!")
}
This code does not update the textview value
Related
When I use BigTextStyle and BigPictureStyle together, only setContentText and BigPictureStyle are shown in the notification drawar. I mean if the text is long, it won't show the full text (BigTextStyle doesn't seem to work at all)
It shows the same on my phone (Android 11),
Does anyone know how I can solve this problem?
private fun sendNotification() {
val intent = Intent(this, MainActivity::class.java)
val pendingIntent: PendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE)
val bitmap = BitmapFactory.decodeResource(applicationContext.resources, R.drawable.wallet)
val bitmapLargeImage = BitmapFactory.decodeResource(applicationContext.resources, R.drawable.sell)
val builder = NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.drawable.ic_baseline_attach_money_24)
.setContentTitle("Purchase")
.setContentText("This is the text I want to show to my users in the notification bar, but it is not fully shown.")
.setContentIntent(pendingIntent)
.setStyle(NotificationCompat.BigTextStyle().bigText("This is the text I want to show to my users in the notification bar, but it is not fully shown."))
.setStyle(NotificationCompat.BigPictureStyle().bigPicture(bitmapLargeImage))
.setLargeIcon(bitmap)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
with(NotificationManagerCompat.from(this)) {
notify(notificationID, builder.build())
}
}
Wanted to post a comment but don't have enough reputation.
As far as I know you cannot use BigTextStyle with BigPictureStyle, by default.
To do that, you need to create a Custom View for your notification
See the documentation on how to create a Custom View for a notification: https://developer.android.com/training/notify-user/custom-notification
Maybe this similar stackoverflow question can help: How to use both BigTextStyle and BigPictureStyle in setStyle Notification?
While this may not be a problem for you, for apps that target Android 12 some behaviours for fully custom notifications change - See https://developer.android.com/about/versions/12/behavior-changes-12#custom-notifications
I have this array
val textViewList = arrayListOf<TextView>()
and I want to add a new textView with code
textViewList.add(TextView)
to do that
textViewList[0].textSize = 20f
textViewList[0].text = "Programmatically created textView "
myLayout.addView(textViewList[0])
but
textViewList.add(TextView)
is not working.
It took some try and error but this
textViewList.add(TextView(this))
worked.
I need to display a few previews of addresses on the map on the same screen. To do that I'm going to display ImageViews with bitmaps instead of making multiple instances of MapView. But for that I need to find a way to capture these bitmaps.
I found snapshot function in MapboxMap (https://github.com/mapbox/mapbox-gl-native/issues/6062), but it requires displaying of the map.
val position = CameraPosition.Builder()
.target(addressLatLng)
.zoom(zoom)
.build()
mapboxMap.cameraPosition = position
mapboxMap.snapshot { bitmap: Bitmap ->
imageView.setImageBitmap(bitmap)
}
So, can I take a snapshot of the map without displaying it on the screen?
I've finally found the solution! The class I needed to use was MapSnapshotter.
val width = imageView.width
val height = imageView.height
val location = CameraPosition.Builder()
.target(LatLng(55.7558, 37.6173))
.zoom(16.0)
.build()
val options = MapSnapshotter.Options(width, height)
.withCameraPosition(location)
MapSnapshotter(context, options).start { snapshot ->
imageView.setImageBitmap(snapshot.bitmap)
}
I'm writing a Photoshop script in extendscript/javascript and I'm trying to verify that the document is using just one color (plus transparency). What I would like to do is change the document mode to Indexed Color and then get the values in the color table.
I have successfully changed the document mode to Indexed Color but can't figure out how to access the color table or the color values inside of it.
My working alternative is to use a colorSampler to compare the values of each pixel, but that can take a couple of minutes to run on larger documents and speed is an issue for this project.
Please let me know if there is a way to access the color table or if you see a way to reduce the time it takes to run this function.
function sample_color(doc, sample_rate) {
var status = 'PASS'
var color_sampler = doc.colorSamplers.add([0,0])
var color_val = false //first (and hopefully only) color value in the document
var broke = false
for (x=1; x < doc.width; x+=sample_rate){
if (broke){
break
}
for (y=1; y < doc.height; y+=sample_rate){
color_sampler.move([UnitValue(x, 'px'), UnitValue(y, 'px')])
try{
var color = color_sampler.color //color of the current pixel
} catch(e) {
var color = false //color_sampler.color fails if the pixel is transparent
}
if (color != false){
if (color_val != false){
if (!color.isEqual(color_val)){
status = 'FAIL'
broke = true
break
}
} else {
color_val = color
}
}
}
}
color_sampler.remove()
return status
}
xbytor has written a couple of scripts for accessing colour tables. This link may be of use to you.
I am implementing an application displaying images and messages obtained from .net server. For that I'm adding LinearLayout's with TextView and ImageView dynamically by using for loop.
At first I am getting messages and I'm adding them to the TextView with dummy images placed in ImageView:
for(int i = 0; i < messages.size(); i++) {
FrameLayout f1 = new FrameLayout(this);
LinearLayout l1 = new LinearLayout(this);
LinearLayout l2 = new LinearLayout(this);
im = new ImageView(this);
TextView tv = new TextView(this);
tv.setText(messages.get(i).getmessage());
im.setImageResource(R.drawable.person);
l1.addView(tv);
l2.addView(im);
f1.addView(l1);
f1.addView(l2);
((LinearLayout)findViewById(R.id.LinearlayoutMessage)).addView(f1);
}
After some time I am getting original images. My intention is to replace the dummy images with original ones. To achieve this I'm using imageview.getid() unfortunately I'm getting last id of the imageview. But I need to get each individual imageview id's.
What is the best way of changing dummy images with real ones?
Looks like you need to store each imageView id in a map from each message -> imageView like so:
Map<Message, Long> messageMapping = new HashMap<Message, Long>();
for(int i = 0; i < messages.size(); i++) {
FrameLayout f1 = new FrameLayout(this);
LinearLayout l1 = new LinearLayout(this);
LinearLayout l2 = new LinearLayout(this);
im = new ImageView(this);
TextView tv = new TextView(this);
//add mapping
messageMapping.put(messages.get(i), im.getId());
tv.setText(messages.get(i).getmessage());
im.setImageResource(R.drawable.person);
l1.addView(tv);
l2.addView(im);
f1.addView(l1);
f1.addView(l2);
((LinearLayout)findViewById(R.id.LinearlayoutMessage)).addView(f1);
}
Then when it comes time to lazy load your images into the existing imageViews you simply need to look up the imageView id reference by message mapping:
(Total guess of what your code could look like)
for(int i = 0; i < messages.size(); i++){
Image image = queryServerForImage(messages.get(i).getImageId());
ImageView imageView = ((ImageView)findViewById(messageMapping.get(messages.get(i))));
//some conversion & seteup may be needed to get image into proper format
imageView.setImageBitmap(image);
}
You may be able to do something similar with async tasks. You could span each one in the message ImageView creation loop with the associated resource id and having each asyc task update the ui from the network response.