I'm using a screenshot library (in Github) and it is has been written in Kotlin(I don't know Kotlin very well).
<https://github.com/bolteu/screenshotty>
I don't know how to translate to Java a part of code.
in the read me file :
val screenshotResult = screenshotManager.makeScreenshot()
val subscription = screenshotResult.observe(
onSuccess = { processScreenshot(it) },
onError = { onMakeScreenshotFailed(it) }
)
It says that you can get a screenshot object from "it"?
how can I do that?
please help me...
and how can I translate this code to Java :
fun show(screenshot: Screenshot) {
val bitmap = when (screenshot) {
is ScreenshotBitmap -> screenshot.bitmap
}
screenshotPreview.setImageBitmap(bitmap)
}
Related
I try to compress a video using a library and running a FFmpeg command in my android app written in java (although the library is in Kotlin)
I manage to do basic operations but the current one I am going to show you will always fail with the following error code: Unknown encoder 'libx265'
The library expects the input to be a String[] and I assume that there is something going wrong but I cannot find what exactly.
the command line
val query:Array<String> = arrayOf("-i", videoPath , "-c:v" , "libx265" ,"preset", "fast", "-crf", "30", "-tag:v", "hvc1", "-c:a", "eac3", "-b:a", "224k" , "$videoPath.mp4");
the entire code
fun videoCompress(videoPath: String) {
val query:Array<String> = arrayOf("-i", videoPath , "-c:v" , "libx265" ,"-preset", "fast", "-crf", "30", "-tag:v", "hvc1", "-c:a", "eac3", "-b:a", "224k" , "$videoPath.mp4");
CallBackOfQuery().callQuery(query, object : FFmpegCallBack {
override fun statisticsProcess(statistics: Statistics) {
Log.i("FFMPEG LOG : ", statistics.videoFrameNumber.toString())
}
override fun process(logMessage: LogMessage) {
Log.i("FFMPEG LOG : ", logMessage.text)
}
override fun success() {
Log.d("yyyy", "success: ")
}
override fun cancel() {
}
override fun failed() {
}
})
}
The Log from the code
what I added to my build.gradle file
implementation 'com.github.SimformSolutionsPvtLtd:SSffmpegVideoOperation:1.0.8'
the result (exact)
Unknown encoder 'libx265'
Im trying to translate this part of a code to Java, i understand its waiting for a callback from a BLE action, if returns any data will be added to statusReport, only issue is that it seems that is doing a loop somewhere because in the real application gets this callback multiple times but on my side i only get one response.
private val statusReportCallback = DataReceivedCallback { _, data -> convertByteArrayToASCII(data.value)?.let { Endpoint.addToStatusReport(it)
if (nextWillBeICCID) iccid = it.also { notifyDeviceEvent(EventType.ICCID) }.also { nextWillBeICCID = false }
when (it) {
"power off" -> Endpoint.commsTestInProgress.set(false)
"ICCID:" -> nextWillBeICCID = true
"POST: Success" -> Endpoint.onServerConnected.value = Event(true)
}
} }
I am writing a service(Spring Integration + JavaMail API) that automatically replies to a received message and I am having problems with including the previous message body.
How can I handle it correctly? I'd like to keep the same formatting, the one that Gmail/Thunderbird uses. I included code snippets showing how I've done it, but is there perhaps some other solution I could use? Some library, perhaps? Regular expressions? I sweeped through stackoverflow questions, but answers telling me that I have to handle it on my own aren't exactly helpful.
I'm open to suggestions. Thanks in advance!
On Gmail it looks like this:
Thunderbird:
fun prepareReplyFor(mimeMessage: MimeMessage): MimeMessage
{
val response = mimeMessage.reply(SHOULD_REPLY_TO_ALL) as MimeMessage
val mailFormatter = MailFormatter()
val botText = MimeBodyPart()
botText.setContent("This message was generated.\n", "text/plain")
val previousCorrespondence = MimeBodyPart()
previousCorrespondence.setContent(mailFormatter.formatPrevious(mimeMessage), "text/plain")
val responseBody = MimeMultipart()
responseBody.addBodyPart(botText)
responseBody.addBodyPart(previousCorrespondence)
response.setContent(responseBody)
return response
}
MailFormatter:
const val CORRESPONDENCE_FORMAT_REGEX = "(?m)^"
const val FIRST_BODY_PART = 0
class MailFormatter
{
fun formatPrevious(mimeMessage: MimeMessage): String
{
val previousMessage = mimeMessage.content
var formattedQuote = "In reply to:\n\n"
if (previousMessage is String)
{
formattedQuote += previousMessage.replace(CORRESPONDENCE_FORMAT_REGEX.toRegex(), "> ")
}
else if (previousMessage is MimeMultipart)
{
formattedQuote += (previousMessage.getBodyPart(FIRST_BODY_PART).content as String).replace(CORRESPONDENCE_FORMAT_REGEX.toRegex(), "> ")
}
return formattedQuote
}
}
I am trying to implement this code using java and the cloud code option from Parse.
Does anyone know how to implement this code in Java and then correctly call it from my function using PFCloud?
//Search for submissions & groups
var findUsersInGroupData:PFQuery = PFQuery(className: "GameInfo")
findUsersInGroupData.whereKey("Group", equalTo:groupName)
findUsersInGroupData.findObjectsInBackgroundWithBlock{
(objects:[AnyObject]!, error:NSError!)->Void in
if error == nil{
for object in objects{
let usersInGroup:PFObject = object as PFObject
self.timelineData.addObject(usersInGroup)
var findTimelineData:PFQuery = PFQuery(className: "Submissions")
findTimelineData.whereKey("User", equalTo: usersInGroup.objectForKey("User"))
findTimelineData.findObjectsInBackgroundWithBlock{
(objects:[AnyObject]!, error:NSError!)->Void in
if error == nil{
for object in objects{
let submission:PFObject = object as PFObject
self.timelineData.addObject(submission)
}
let array:NSArray = self.timelineData.reverseObjectEnumerator().allObjects
self.timelineData = NSMutableArray(array: array)
self.tableView.reloadData()
}
}
}
}
}
I am developing an android application using JAVA. All I want is to
record a song and generate its hash(CODE), then query the echoprint server for a match.
If a match is not found, then upload it to the server (ingest) for future references.
I have been able to achieve the first part. Can someone suggest me about the second part in JAVA? (P.S. : I've seen how to do it using python codes - but that won't be helpful in my case.)
Another question, may I achieve the second objective with the global echoprint server? Or, do I need to set up one of my own?
The references I've used are:
http://masl.cis.gvsu.edu/2012/01/25/android-echoprint/
https://github.com/gvsumasl/EchoprintForAndroid
To insert a song into the echoprint server database, all you need to do is call the ingest method. Basically, it is only a HTTP POST request with correct json body. Here is a Scala code (Java would be very similar) that I am using for that:
import EasyJSON.JSON
import EasyJSON.ScalaJSON
import dispatch.Defaults.executor
import dispatch._
class EchoprintAPI {
val API_URL = "http://your.api.server"
def queryURL(code: String) = url(s"$API_URL/query?fp_code=$code")
def query(code: String): scala.concurrent.Future[ScalaJSON] = {
jsonResponse(queryURL(code))
}
def ingest(json: ScalaJSON, trackId: String): scala.concurrent.Future[ScalaJSON] = {
val metadata = json("metadata")
val request = url(s"$API_URL/ingest").POST
.addParameter("fp_code", json("code").toString)
.addParameter("artist", metadata("artist").toString)
.addParameter("release", metadata("release").toString)
.addParameter("track", metadata("title").toString)
.addParameter("codever", metadata("version").toString)
.addParameter("length", metadata("duration").toString)
.addParameter("genre", metadata("genre").toString)
.addParameter("bitrate", metadata("bitrate").toString)
.addParameter("source", metadata("filename").toString)
.addParameter("track_id", trackId)
.addParameter("sample_rate", metadata("sample_rate").toString)
jsonResponse(request)
}
def delete(trackId: String): scala.concurrent.Future[ScalaJSON] = {
jsonResponse(url(s"$API_URL/query?track_id=$trackId").DELETE)
}
protected def jsonResponse(request: dispatch.Req): scala.concurrent.Future[EasyJSON.ScalaJSON] = {
val response = Http(request OK as.String)
for (c <- response) yield JSON.parseJSON(c)
}
}
To generate the fingerprint code, you can use echoprint-codegen command line call or use the Java JNI integration with C lib