Posts

Showing posts from October, 2001

Bind Service To Activity In Android

Answer : "If you start an android Service with startService(..) that Service will remain running until you explicitly invoke stopService(..) . There are two reasons that a service can be run by the system. If someone calls Context.startService() then the system will retrieve the service (creating it and calling its onCreate() method if needed) and then call its onStartCommand(Intent, int, int) method with the arguments supplied by the client. The service will at this point continue running until Context.stopService() or stopSelf() is called. Note that multiple calls to Context.startService() do not nest (though they do result in multiple corresponding calls to onStartCommand() ), so no matter how many times it is started a service will be stopped once Context.stopService() or stopSelf() is called; however, services can use their stopSelf(int) method to ensure the service is not stopped until started intents have been processed. Clients can also use Context.bindServ

Bluetooth AptX On Windows 10

Answer : First of all, your bluetooth audio receiver (Philips AEA2700) supports decoding aptX. That's listed in its specification. Then it comes to the transmitter. AFAIK there are two types of transmitter for bluetooth audio. The first type is a USB audio class device (i.e. a USB sound card) with hardware codec. Examples are the ones from Creative, such as BT-W2. For this type of transmitter, you can safely assume that it will automatically use the "best" codec (i.e. aptX Low-Latency > aptX > SBC) available on both itself and the receiver. And I don't suppose you have ways other than checking its specification to know whether aptX is available. The second type is a general bluetooth transmitter that supports the A2DP profile. The ones that are equipped in laptops are pretty much always of this type. This type of transmitter usually relies on software codec(s), which are provided its driver / software stack, such as CSR Harmony . Take CSR Harmony

Android Studio Toast Syntax Code Example

Example 1: how to make toast in android Toast toast = Toast.makeText(this, "message", Toast.LENGTH_LONG;); toast.show(); Example 2: toast.maketext Context context = getApplicationContext(); CharSequence text = "Hello toast!"; int duration = Toast.LENGTH_SHORT; Toast toast = Toast.makeText(context, text, duration); toast.show();

Cannot Install Latest Nodejs Using Conda On Mac

Answer : Currently, the latest version nodejs 14.x requires icu>=65 which is not yet globally available across conda-forge packages. Therefore it can be installed into a new environment with conda create -n new_env_name -c conda-forge nodejs , but most likely will raise package conflicts in existing environments. conda install node-js -c conda-forge installing the very old version 6.13.1 seems to be a solver problem. conda install nodejs -c conda-forge --repodata-fn=repodata.json will install a more current version: nodejs-13.x. Alternative workaround is to use mamba as a conda replacement. Credits go to Wolf Vollprecht. Here's my workaround: I installed nodejs for Mac from the .pkg file from the offical site and then every time I update packages in my conda environments, I force remove the nodejs version conda installs with: conda uninstall --force nodejs and then go about using the environment as if it had nodejs installed. That way when any other package need

Align Bootstrap Toggle Menu Right Code Example

Example: how do i get the toggle menu on the right bootstrap < button type = " button " class = " navbar-toggler ml-auto hidden-sm-up float-xs-right " data-toggle = " collapse " data-target = " #navbarResponsive " aria-expanded = " false " aria-label = " Toggle navigation " > </ button >

Can You Control GIF Animation With Javascript?

Answer : You can use the libgif library. It allows you to start/stop the gif and control which frame the gif is on. <script type="text/javascript" src="./libgif.js"></script> <img src="./example1_preview.gif" rel:animated_src="./example1.gif" width="360" height="360" rel:auto_play="1" rel:rubbable="1" /> <script type="text/javascript"> $$('img').each(function (img_tag) { if (/.*\.gif/.test(img_tag.src)) { var rub = new SuperGif({ gif: img_tag } ); rub.load(function(){ console.log('oh hey, now the gif is loaded'); }); } }); </script> (most of the code is taken directly from their example) I use x-gif it's pretty cool and easy to setup. From Github: <x-gif src="probably_cats.gif"></x-gif> Where you can add the following as attributes

Chalkboard Texture For Tikz Lines

Image
Answer : It takes ages . \documentclass[tikz,border=5]{standalone} \usetikzlibrary{decorations,backgrounds} \pgfkeys{decoration/.cd, iterations/.store in=\pgfdecorationiterations, iterations=75, radius/.store in=\pgfdecorationradius, radius=0.25pt, } \pgfdeclaredecoration{chalk}{draw}{ \state{draw}[width=\pgfdecorationsegmentlength]{ \pgftransformxshift{0.5\pgfdecorationsegmentlength/2} \pgfmathloop \ifnum\pgfmathcounter>\pgfdecorationiterations \else \pgfpathcircle{\pgfpointpolar{rnd*360}{rnd*\pgfdecorationsegmentamplitude}}% {\pgfdecorationradius}% \repeatpgfmathloop }} \begin{document} \begin{tikzpicture}[background rectangle/.style={fill=black}, show background rectangle, chalk/.style={fill=white, decorate, decoration={chalk, segment length=1.5pt, amplitude=3pt} },looseness=0.25] \path [chalk] (1/8,2) -- (0,1/2) arc (180:315:1/2) (-1/2,3/2) to [bend right] (5/8,3/2); \path [chalk, shift=(0:1)] (1/8,1) to [bend left] (0,0); \path [chalk, shift=(0:3/2)] (1/8,2) t

Android - Implementing StartForeground For A Service?

Answer : I'd start by completely filling in the Notification . Here is a sample project demonstrating the use of startForeground() . From your main activity, start the service with the following code: Intent i = new Intent(context, MyService.class); context.startService(i); Then in your service for onCreate() you would build your notification and set it as foreground like so: Intent notificationIntent = new Intent(this, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); Notification notification = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.app_icon) .setContentTitle("My Awesome App") .setContentText("Doing some work...") .setContentIntent(pendingIntent).build(); startForeground(1337, notification); Solution for Oreo 8.1 I've encountered some problems such as RemoteServiceException becau

Android - Android 4.3: How To Get The Notification History

Image
Answer : This is not a rumor: the notification history is a true feature from Android 4.3, although they don't make any mention of it in their What's New page. The following steps will allow you to take advantage from the Notification History in a vanilla Android Jelly Bean 4.3: Go to your app drawer, then tap the Widgets tab. Scroll until you reach Settings shortcut (1x1) widget. Drag and drop this widget to your home screen . You'll see a screen where you can select the type of settings this shortcut will open. Select Notifications . The shortcut Notifications will be in your home screen , tap it. The screen Notifications shows the notification history we are talking about. In this screen currently active notifications appear in full intensity, while dismissed ones are dimmed. Tapping in each notification from this screen will open the corresponding App info screen, where you'll be able to toggle the option Show notifications as you wish. R

Android - ImageView With Rounded Only One Corner

Image
Answer : You can use the Material Components Library. With the version 1.2.0-alpha03 there is the new ShapeableImageView . Just use in your layout: <com.google.android.material.imageview.ShapeableImageView app:srcCompat="@drawable/..." ../> And in your code apply the ShapeAppearanceModel with: float radius = getResources().getDimension(R.dimen.default_corner_radius); imageView.setShapeAppearanceModel(imageView.getShapeAppearanceModel() .toBuilder() .setTopRightCorner(CornerFamily.ROUNDED,radius) .setBottomLeftCorner(CornerFamily.ROUNDED,radius) .build()); You can use this library and put your ImageView inside the Layout https://github.com/JcMinarro/RoundKornerLayouts and can set the radius for specific corners like this containerLayout.setCornerRadius(2f, CornerType.ALL); containerLayout.setCornerRadius(2f, CornerType.BOTTOM_LEFT); Other choices public final enum class CornerType private constructor() : kotli

Can An Html Element Have Multiple Ids?

Answer : No. From the XHTML 1.0 Spec In XML, fragment identifiers are of type ID, and there can only be a single attribute of type ID per element. Therefore, in XHTML 1.0 the id attribute is defined to be of type ID. In order to ensure that XHTML 1.0 documents are well-structured XML documents, XHTML 1.0 documents MUST use the id attribute when defining fragment identifiers on the elements listed above. See the HTML Compatibility Guidelines for information on ensuring such anchors are backward compatible when serving XHTML documents as media type text/html. Contrary to what everyone else said, the correct answer is YES The Selectors spec is very clear about this: If an element has multiple ID attributes, all of them must be treated as IDs for that element for the purposes of the ID selector.Such a situation could be reached using mixtures of xml:id, DOM3 Core, XML DTDs, and namespace-specific knowledge. Edit Just to clarify: Yes, an

Latex Font Size Overleaf Code Example

Example 1: latex font sizes \Huge \huge \LARGE \Large \large \ normalsize ( default ) \small \footnotesize \scriptsize \tiny Example 2: latex font sizes Change global font size : \documentclass [ 12 pt ] { report }

Access To XMLHttpRequest At 'http://localhost:8082/api/propertieses' From Origin 'http://localhost:4200' Has Been Blocked By CORS Policy: No 'Access-Control-Allow-Origin' Header Is Present On The Requested Resource. Code Example

Example: ccess to XMLHttpRequest at 'http://127.0.0.1:5000/ has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. @app . route ( 'your route' , methods = [ 'GET' ] ) def yourMethod ( params ) : response = flask . jsonify ( { 'some' : 'data' } ) response . headers . add ( 'Access-Control-Allow-Origin' , '*' ) return response

Coalesce For Zero Instead Of Null

Answer : You can combine NULLIF with COALESCE : SELECT company, COALESCE(NULLIF(turnover, 0), revenue) AS revenue FROM company_profile; NULLIF returns NULL if it's arguments are equal, and the first argument otherwise.

Execute("java Echo Hello You !"); Code Example

Example: print hello world in java public class Hello { public static void main ( String [ ] args ) { /*Tip System.out.println(); shortcut Type 'sysout'and press Tab */ System . out . println ( "Hello world!" ) ; } }

How To Test Cron Job Code Example

Example: how to test crontab job #!/bin/bash # crontest # See https://github.com/Stabledog/crontest for canonical source. # Test wrapper for cron tasks. The suggested use is: # # 1. When adding your cron job, use all 5 stars to make it run every minute # 2. Wrap the command in crontest # # # Example: # # $ crontab -e # * * * * * /usr/local/bin/crontest $HOME/bin/my-new-script --myparams # # Now, cron will run your job every minute, but crontest will only allow one # instance to run at a time. # # crontest always wraps the command in "screen -d -m" if possible, so you can # use "screen -x" to attach and interact with the job. # # If --bashdb is used, the command line will be passed to bashdb. Thus you # can attach with "screen -x" and debug the remaining command in context. # # NOTES: # - crontest can be used in other contexts, it doesn't have to be a cron job. # Any place where commands

C Program Concatenate Strings Code Example

Example 1: c concatenate strings char str [ 80 ] ; strcpy ( str , "these " ) ; strcat ( str , "strings " ) ; strcat ( str , "are " ) ; strcat ( str , "concatenated." ) ; Example 2: concatenate two strings in c # include <stdio.h> # include <string.h> int main ( ) { char a [ 1000 ] , b [ 1000 ] ; printf ( "Enter the first string\n" ) ; gets ( a ) ; printf ( "Enter the second string\n" ) ; gets ( b ) ; strcat ( a , b ) ; printf ( "String obtained on concatenation: %s\n" , a ) ; return 0 ; } Example 3: program to concatenate two strings in c // this program is to contenate strings without using string function # include <stdio.h> # include <string.h> void concatenate ( char * str1 , char * str2 ) { int i = strlen ( str1 ) , j = 0 ; while ( str2 [ j ] != '\0' ) { str1 [ i ] = str2 [ j ]

How To Print Boolean Value In C Code Example

Example: how to print boolean in c printf ( "%s" , x ? "true" : "false" ) ;

Get Length String Java Code Example

Example 1: length of string java public class Sample_String { public static void main ( String [ ] args ) { //declare the String as an object S1 S2 String S1 = "Hello Java String Method" ; String S2 = "RockStar" ; //length() method of String returns the length of a String S1. int length = S1 . length ( ) ; System . out . println ( "Length of a String is: " + length ) ; //8 Length of a String RockStar System . out . println ( "Length of a String is: " + S2 . length ( ) ) ; } } Example 2: java length of string string . length ( )

Bootstrap4 Modal Popup Code Example

Example 1: bootstrap modal <!-- Button trigger modal --> < button type = " button " class = " btn btn-primary " data-toggle = " modal " data-target = " #exampleModalCenter " > Launch demo modal </ button > <!-- Modal --> < div class = " modal fade " id = " exampleModalCenter " tabindex = " -1 " role = " dialog " aria-labelledby = " exampleModalCenterTitle " aria-hidden = " true " > < div class = " modal-dialog modal-dialog-centered " role = " document " > < div class = " modal-content " > < div class = " modal-header " > < h5 class = " modal-title " id = " exampleModalCenterTitle " > Modal title </ h5 > < button type = " button " class = " close " data-dismiss = " modal " ar