Tuesday, August 2, 2016
Monday, June 27, 2016
JAVAFX THREAD
JAVAFX THREAD TO CHANGE UI (USER INTERFACE) FORM DYNAMICALLY
import javafx.application.Platform;
Platform.setImplicitExit(false);
Task task = new Task<Void>() {
@Override
public Void call() throws Exception {
int i = 0;
Thread.sleep(100);
Platform.runLater(new Runnable() {
public void run() {
proViewContlr.getProView().getScroll()
.setVvalue(0.70);
}
});
return null;
}
};
Thread th = new Thread(task);
th.setDaemon(true);
th.start();
DESKTOP NOTIFICATION IN JAVA (SWING)
DESKTOP NOTIFICATION IN JAVA (SWING)
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.WindowConstants;
public class Notification
{
public static void init()
{
String message ="ALL POWER IS WITH IN YOU ,YOU CAN DO ANYTHING AND EVERYTHING BELIVE IN THAT";
String header = "NOTIFICATION MESSAGE";
final JFrame frame = new JFrame();
frame.setSize(300,125);
frame.setUndecorated(true);
frame.setLayout(new GridBagLayout());
GridBagConstraints constraints = new GridBagConstraints();
constraints.gridx = 0;
constraints.gridy = 0;
constraints.weightx = 1.0f;
constraints.weighty = 1.0f;
constraints.insets = new Insets(5, 5, 5, 5);
constraints.fill = GridBagConstraints.BOTH;
JLabel headingLabel = new JLabel(header);
ImageIcon img=new ImageIcon("question_icon1.png");
headingLabel .setIcon(img); // --- use image icon you want to be as heading image.
headingLabel.setOpaque(false);
frame.add(headingLabel, constraints);
constraints.gridx++;
constraints.weightx = 0f;
constraints.weighty = 0f;
constraints.fill = GridBagConstraints.NONE;
constraints.anchor = GridBagConstraints.NORTH;
JButton cloesButton = new JButton(new AbstractAction() {
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
frame.dispose();
}
});
cloesButton.setText("X");
cloesButton.setMargin(new Insets(1, 4, 1, 4));
cloesButton.setFocusable(false);
frame.add(cloesButton, constraints);
constraints.gridx = 0;
constraints.gridy++;
constraints.weightx = 1.0f;
constraints.weighty = 1.0f;
constraints.insets = new Insets(5, 5, 5, 5);
constraints.fill = GridBagConstraints.BOTH;
JLabel messageLabel = new JLabel("<HtMl>"+message);
frame.add(messageLabel, constraints);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
Dimension scrSize = Toolkit.getDefaultToolkit().getScreenSize();// size of the screen
Insets toolHeight = Toolkit.getDefaultToolkit().getScreenInsets(frame.getGraphicsConfiguration());// height of the task bar
frame.setLocation(scrSize.width - frame.getWidth(), scrSize.height - toolHeight.bottom - frame.getHeight());
frame.setVisible(true);
}
public static void main(String args[])
{
init();
}
}
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.WindowConstants;
public class Notification
{
public static void init()
{
String message ="ALL POWER IS WITH IN YOU ,YOU CAN DO ANYTHING AND EVERYTHING BELIVE IN THAT";
String header = "NOTIFICATION MESSAGE";
final JFrame frame = new JFrame();
frame.setSize(300,125);
frame.setUndecorated(true);
frame.setLayout(new GridBagLayout());
GridBagConstraints constraints = new GridBagConstraints();
constraints.gridx = 0;
constraints.gridy = 0;
constraints.weightx = 1.0f;
constraints.weighty = 1.0f;
constraints.insets = new Insets(5, 5, 5, 5);
constraints.fill = GridBagConstraints.BOTH;
JLabel headingLabel = new JLabel(header);
ImageIcon img=new ImageIcon("question_icon1.png");
headingLabel .setIcon(img); // --- use image icon you want to be as heading image.
headingLabel.setOpaque(false);
frame.add(headingLabel, constraints);
constraints.gridx++;
constraints.weightx = 0f;
constraints.weighty = 0f;
constraints.fill = GridBagConstraints.NONE;
constraints.anchor = GridBagConstraints.NORTH;
JButton cloesButton = new JButton(new AbstractAction() {
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
frame.dispose();
}
});
cloesButton.setText("X");
cloesButton.setMargin(new Insets(1, 4, 1, 4));
cloesButton.setFocusable(false);
frame.add(cloesButton, constraints);
constraints.gridx = 0;
constraints.gridy++;
constraints.weightx = 1.0f;
constraints.weighty = 1.0f;
constraints.insets = new Insets(5, 5, 5, 5);
constraints.fill = GridBagConstraints.BOTH;
JLabel messageLabel = new JLabel("<HtMl>"+message);
frame.add(messageLabel, constraints);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
Dimension scrSize = Toolkit.getDefaultToolkit().getScreenSize();// size of the screen
Insets toolHeight = Toolkit.getDefaultToolkit().getScreenInsets(frame.getGraphicsConfiguration());// height of the task bar
frame.setLocation(scrSize.width - frame.getWidth(), scrSize.height - toolHeight.bottom - frame.getHeight());
frame.setVisible(true);
}
public static void main(String args[])
{
init();
}
}
Tuesday, June 14, 2016
ANDROID TAB NAVIGATION
ANDROID TAB NAVIGATION
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class AndroidTabLayoutActivity extends TabActivity {
@Override
protected void
onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_android_tab_layout);
TabHost tabHost
= getTabHost();
// Tab for
Insert new Element
TabSpec
photospec = tabHost.newTabSpec("Insert");
// setting
Title and Icon for the Tab
photospec.setIndicator("Insert",
getResources().getDrawable(R.drawable.tick_icon));
Intent
photosIntent = new Intent(this, PhotosActivity.class);
photospec.setContent(photosIntent);
// Tab For to
view
TabSpec
songspec = tabHost.newTabSpec("View");
songspec.setIndicator("View",
getResources().getDrawable(R.drawable.minutes_icon1));
Intent
songsIntent = new Intent(this, SongsActivity.class);
songspec.setContent(songsIntent);
// Tab for
delete
TabSpec
videospec = tabHost.newTabSpec("Delete");
videospec.setIndicator("Delete",
getResources().getDrawable(R.drawable.question_icon1));
Intent
videosIntent = new Intent(this, VideosActivity.class);
videospec.setContent(videosIntent);
// Adding all
TabSpec to TabHost
tabHost.addTab(photospec); // Adding photos tab
tabHost.addTab(songspec); // Adding songs tab
tabHost.addTab(videospec); // Adding videos tab
}
}
Wednesday, May 25, 2016
TELEPHONY BROADCAST RECEIVER IN ANDROID
TELEPHONY BROADCAST RECEIVERS IN ANDROID
INCOMING CALL BROADCAST RECEIVER:
package com.dat.spy.spyroid;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.widget.Toast;
public class MyPhoneReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();
if (extras != null) {
String state = extras.getString(TelephonyManager.EXTRA_STATE);
Log.w("MY_DEBUG_TAG", state);
if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
String phoneNumber = extras
.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
Log.w("MY_DEBUG_TAG", phoneNumber);
Toast.makeText(context,"Call action no.."+phoneNumber,Toast.LENGTH_LONG).show();
}
}
}
}
OUTGOING CALL BROADCAST RECEIVER:
package com.dat.spy.spyroid;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;
public class OutgoingCallReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
String phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
Log.d(OutgoingCallReceiver.class.getSimpleName(), intent.toString() + ", call to: " + phoneNumber);
Toast.makeText(context, "Outgoing call catched: " + phoneNumber, Toast.LENGTH_LONG).show();
}
}
MESSAGE RECEVING BROADCAST RECEIVER:
package com.dat.spy.spyroid;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.widget.Toast;
public class SmsBroadcastReceiver extends BroadcastReceiver {
public static final String SMS_BUNDLE = "pdus";
public void onReceive(Context context, Intent intent) {
Bundle intentExtras = intent.getExtras();
if (intentExtras != null)
{
Object[] sms = (Object[]) intentExtras.get(SMS_BUNDLE);
String smsMessageStr = "";
for (int i = 0; i < sms.length; ++i) {
SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) sms[i]);
String smsBody = smsMessage.getMessageBody().toString();
String address = smsMessage.getOriginatingAddress();
smsMessageStr += "SMS From: " + address + "\n";
smsMessageStr += smsBody + "\n";
}
Toast.makeText(context, smsMessageStr, Toast.LENGTH_LONG).show();
}
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dat.spy.spyroid">
<uses-permission android:name="android.permission.WRITE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".SpyActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".SmsBroadcastReceiver" android:exported="true" >
<intent-filter android:priority="999" >
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
<receiver android:name="MyPhoneReceiver" >
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" >
</action>
</intent-filter>
</receiver>
<receiver android:name=".OutgoingCallReceiver" >
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
</receiver>
</application>
</manifest>
Subscribe to:
Posts (Atom)