Display a custom alert or a view on receiving a notification in Android

Nishtha Thakur
Updated on 30-Jul-2019 22:30:26

379 Views

This example demonstrate about How to display a custom alert or a view on receiving a notification in Android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.     Step 3 − Add the following code to src/MainActivity.package app.tutorialspoint.com.notifyme ; import android.app.NotificationChannel ; import android.app.NotificationManager ; import android.os.Bundle ; import android.support.v4.app.NotificationCompat ; import android.support.v7.app.AppCompatActivity ; import android.view.View ; import android.widget.Toast ; public class MainActivity extends AppCompatActivity {    public static final String NOTIFICATION_CHANNEL_ID = "10001" ... Read More

MongoDB divide aggregation operator?

Anvi Jain
Updated on 30-Jul-2019 22:30:26

212 Views

You can use aggregate framework for this. Let us first create a collection with documents −>db.aggregationOperatorDemo.insertOne({"FirstValue":392883,"SecondValue":10000000000}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd541452cba06f46efe9f01") }Following is the query to display all documents from a collection with the help of find() method −> db.aggregationOperatorDemo.find().pretty();This will produce the following output −{    "_id" : ObjectId("5cd541452cba06f46efe9f01"),    "FirstValue" : 392883,    "SecondValue" : 10000000000 }Following is the query to use divide aggregation operator −> db.aggregationOperatorDemo.aggregate([ ...   { "$project": { "Value": { "$divide": ["$FirstValue", "$SecondValue"] } } } ... ]);This will produce the following output −{ "_id" : ObjectId("5cd541452cba06f46efe9f01"), "Value" : 0.0000392883 }

How to find a node in a JTree Component with Java?

Ankith Reddy
Updated on 30-Jul-2019 22:30:26

558 Views

To find a node in a JTree component, use the getNextMatch() method. Here, wer are trying to find a node that begins with character “A”. The search begins from the node set below with begnRow variable −int begnRow = 0; String prefix = "A"; TreePath treePath = tree.getNextMatch(prefix, begnRow, Position.Bias.Forward);We have displayed the resultant node in the Console −System.out.println("Node = "+treePath);The following is an example to find a node in a JTree Component with Java −package my; import javax.swing.JFrame; import javax.swing.JTree; import javax.swing.text.Position; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreePath; public class SwingDemo {    public static void main(String[] args) throws Exception { ... Read More

How to set raised and lowered SoftBevelBorder for components in Java. Also set the border color.

Arjun Thakur
Updated on 30-Jul-2019 22:30:26

80 Views

Let us see how to set the raised SoftBevelBorder −Border raisedBorder = new SoftBevelBorder(    SoftBevelBorder.RAISED, Color.GREEN, Color.GREEN.darker(), Color.MAGENTA, Color.magenta.brighter());Let us see how to set the lowered SoftBevelBorder −Border loweredBorder = new SoftBevelBorder(    SoftBevelBorder.LOWERED, Color.ORANGE, Color.YELLOW.darker(), Color.BLUE, Color.yellow.brighter());The following is an example to set raised and lowered SoftBevelBorder for components in Java −Examplepackage my; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.border.Border; import javax.swing.border.SoftBevelBorder; public class SwingDemo {    public static void main(String args[]) {       JFrame frame = new JFrame("Demo");       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       Border raisedBorder = ... Read More

MongoDB query to find data from an array inside an object?

Arjun Thakur
Updated on 30-Jul-2019 22:30:26

434 Views

Let us first create a collection with documents −> db.findDataDemo.insertOne(    {       "_id": new ObjectId(),       "CustomerName":"John",       "CustomerDetails" : {          "CountryName" : [             "AUS"          ],          "isMarried" : [             false          ]       }    } ); {    "acknowledged" : true,    "insertedId" : ObjectId("5cefa5eeef71edecf6a1f6a5") } > db.findDataDemo.insertOne(    {       "_id": new ObjectId(),       "CustomerName":"Carol",       ... Read More

Explain Generator functions in JavaScript?

vineeth.mariserla
Updated on 30-Jul-2019 22:30:26

519 Views

GeneratorsJavaScript supports Generator functions and Generator Objects. A generator function is the same as a normal function, but whenever it needs to generate a value it uses the 'yield' keyword rather than 'return'. The 'yield' keyword halts the function execution and sends a value back to the caller. It has an ability that it can resume the functionality from where it is left off. syntaxfunction* generator(){ yeild 1; yeild 2; }ExampleIn the following example, using a generator function, natural numbers 10, 9 and 8 were printed. Instead of printing each number individually we can run ... Read More

How to get the creation time of recently created table in MySQL?

Rama Giri
Updated on 30-Jul-2019 22:30:26

148 Views

Following is the syntax −select table_name, create_time from information_schema.TABLES where table_schema = 'yourDataBaseName' order by CREATE_TIME desc limit 1;Let us create the first table (Time: 2019-06-10 16:40:51) −mysql> create table DemoTable1    -> (    -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> StudentName varchar(100),    -> StudentAge int    -> ); Query OK, 0 rows affected (0.59 sec)We will now create the second table, let’s say after 5 minutes −mysql> create table DemoTable2    -> (    -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> StudentName varchar(100),    -> StudentAge int    -> ); Query ... Read More

Java Program to find all angles of a triangle

Venkata Sai
Updated on 30-Jul-2019 22:30:26

406 Views

To find the angles of a triangle we can use sin/cosine rules according to cosine rule −cos A = (b^2 + c^2 - a^2)/2bcwhere A, B , C are the vertices and a, b, c are the sides of the given triangle then, angles of the triangle when the sides a, b, c given are −angleAtA = acos((b^2 + c^2 - a^2)/(2bc)) angleAtB = acos((a^2 + c^2 - b^2)/(2ac)) angleAtC = acos((a^2 + b^2 - c^2)/(2ab))

Mouse and keyboard automation using Python?

Chandu yadav
Updated on 30-Jul-2019 22:30:26

2K+ Views

In this section, we’ll try to automate the movements of mouse and keyboard using pyautogui module in python.Pyautogui is a library that allows you to control the mouse and keyboard to do various things.It  is a cross-platform GUI automation Python module for human beings.As it is a third party library, we need to install it.pip install pyautoguiMouseBelow is program to automate the movement of your mouse. On running your programme, you can see the mouse movement with every command. I run below command on CLI so as to capture the mouse movement. You can try with others different values too.Example>>> ... Read More

How to set minimum size limit for a JFrame in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:26

2K+ Views

Use the setMinimumSize() method to set the minimum size limit for a JFrame −JFrame frame = new JFrame(); frame.setMinimumSize(new Dimension(500, 300));The following is an example to set minimum size limit for a JFrame −Exampleimport java.awt.Color; import java.awt.Dimension; import javax.swing.JButton; import javax.swing.JFrame; public class SwingDemo {    public static void main(String[] args) {       JFrame frame = new JFrame();       JButton button = new JButton("Close!");       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       frame.setContentPane(button);       button.addActionListener(e -> {          frame.dispose();       });       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       frame.setMinimumSize(new Dimension(500, ... Read More

Advertisements