Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.nousappsystems.websitenotification;
- import android.accessibilityservice.AccessibilityService;
- import android.app.AlarmManager;
- import android.app.Notification;
- import android.content.SharedPreferences;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.app.IntentService;
- import android.app.NotificationManager;
- import android.app.PendingIntent;
- import android.app.Service;
- import android.content.Context;
- import android.content.Intent;
- import android.os.HandlerThread;
- import android.os.IBinder;
- import android.os.Looper;
- import android.os.Message;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.app.Activity;
- import android.os.Bundle;
- import android.os.Handler;
- import android.support.v7.app.NotificationCompat;
- import android.util.Log;
- import android.view.View;
- import android.webkit.*;
- import android.widget.Button;
- import android.widget.ImageView;
- import android.widget.ProgressBar;
- import android.widget.TextView;
- import android.widget.Toast;
- import java.text.SimpleDateFormat;
- import java.util.Calendar;
- import java.util.Date;
- import java.util.Random;
- import java.util.Timer;
- import java.util.TimerTask;
- /**
- * Created by NousappSystems on 3/25/2017.
- */
- public class Home extends AppCompatActivity {
- private static final String TAG = Login.class.getSimpleName();
- // public TextintView text2;
- private Button Button2;
- private Button Settings;
- private Button mJavaButton;
- private WebView mWebView;
- private WebView mWebView2;
- private Handler mHandler;
- Handler handler;
- String text = "hello";
- Context pref;
- String User ="test";
- String Pword = "hell";
- String txt1 = null;
- String test = null;
- String ctest = "NORMAL";
- String dtest = "Critical Level Reached";
- String etest = "Variation Level Reached";
- Timer timer;
- TimerTask timerTask;
- int notifyId;
- public static final String MyPREFERENCES = "MyPrefs" ;
- public static final String Name = "nameKey";
- public static final String Password = "Password";
- SharedPreferences sharedpreferences;
- final Context context = this;
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- Toast.makeText(getBaseContext(), "WELCOME TO TEMPMITR", Toast.LENGTH_LONG).show();
- mHandler = new Handler();
- mJavaButton = (Button) findViewById(R.id.bt_javaButton);
- Button2 = (Button) findViewById(R.id.button2);
- Settings = (Button) findViewById(R.id.settings);
- mWebView = (WebView) findViewById(R.id.wv_main);
- mWebView2 = (WebView) findViewById(R.id.wv_main2);
- // Enabling JS
- mWebView.getSettings().setJavaScriptEnabled(true);
- mWebView2.getSettings().setJavaScriptEnabled(true);
- // Java and Javascript interfacing
- mWebView.addJavascriptInterface(new Home.JavascriptInterface(), "JsInterface");
- mWebView2.addJavascriptInterface(new Home.JavascriptInterface(), "JsInterface");
- // for debugging, this will handle the console.log() in javascript
- String n="adminnvh";
- String ph="adminnvh123";
- mWebView.loadUrl("javascript:changeBackgroundColor()");
- mWebView.loadUrl("http://www.nousappsystems.com/framework/index.php/TempMiter?user="+n+"&pword="+ph+"");
- mWebView.setWebChromeClient(new WebChromeClient() {
- @Override
- public boolean onConsoleMessage(ConsoleMessage cm) {
- Log.d(TAG, cm.message() + " ##########" + cm.lineNumber() + " -%%%%%%%%%-" + cm.sourceId());
- // refresh();
- // mWebView.loadUrl("http://www.nousappsystems.com/gprs/TempMitr/TempMitrView.php");
- test = cm.message();
- txt1 = test.toString();
- //
- if (test == text) {
- // Toast.makeText(getBaseContext(), "WELCOME TO TEMPMITR" + test, Toast.LENGTH_LONG).show();
- } else {
- // Toast.makeText(getBaseContext(), "The String is " + test, Toast.LENGTH_LONG).show();
- //
- }
- return true;
- }
- });
- mJavaButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- if(notifyId == 0){
- notifyId =0;
- Toast.makeText(Home.this,"Notification Disabled",Toast.LENGTH_LONG).show();
- ImageView img=(ImageView)findViewById(R.id.move_button);
- img.setVisibility(View.INVISIBLE);
- }else{
- notifyId =1;
- Toast.makeText(Home.this,"Notification Enabled",Toast.LENGTH_LONG).show();
- ImageView img=(ImageView)findViewById(R.id.move_button);
- img.setVisibility(View.VISIBLE);
- }
- }
- });
- Button2.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Intent myIntents = new Intent (context,MainActivity.class);
- startActivity(myIntents);
- }
- });
- Settings.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Intent myIntents = new Intent (context,GeneralSetting.class);
- startActivity(myIntents);
- }
- });
- // mWebView.loadUrl("http://www.nousappsystems.com/gprs/TempMitr/TempMitrView.php");
- // doFakeWork();
- // LoginCredentials();
- }
- private void addNotification(String txt1) {
- //wv1.loadUrl("www.google.com");
- NotificationCompat.Builder builder =
- (NotificationCompat.Builder) new NotificationCompat.Builder(this)
- .setSmallIcon(R.drawable.notification)
- .setContentTitle(txt1)
- .setContentText("Temperature is Exceeded");
- Log.i(TAG, "onClickJavascriptButton entered" + txt1 + ctest);
- if (txt1.equals("NORMAL")) { //txt1.equals("")
- Log.i(TAG, "onClickJavascriptButton entered" + txt1 + ctest);
- } else {
- Log.i(TAG, "onClickJavascriptButton Else entered" + txt1 + ctest);
- builder.setDefaults(Notification.DEFAULT_SOUND);
- }
- Intent notificationIntent = new Intent(this, Login.class);
- PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent,
- PendingIntent.FLAG_UPDATE_CURRENT);
- builder.setContentIntent(contentIntent);
- // Add as notification
- NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
- manager.notify(0, builder.build());
- }
- public void onClickJavaButton(View mView) {
- mWebView.loadUrl("javascript:changeBackgroundColor()");
- }
- class JavascriptInterface {
- JavascriptInterface() {
- }
- public void onClickJavascriptButton() {
- Log.d(TAG, "onClickJavascriptButton entered");
- mHandler.post(new Runnable() {
- public void run() {
- Log.d(TAG, "onClickJavascriptButton inside run");
- if (mJavaButton.getText().toString().compareTo(getResources().getString(R.string.buttonText)) == 0)
- mJavaButton.setText(R.string.buttonText);
- else
- mJavaButton.setText(R.string.buttonText);
- }
- });
- }
- }
- @Override
- protected void onResume() {
- super.onResume();
- //onResume we start our timer so it can start when the app comes from the background
- // String n= sharedpreferences.getString("nameKey", null);
- // String ph= sharedpreferences.getString("Password", null);
- // if(n != null || ph != null){
- // startTimer();//ESSENCE OF THE APP
- // }
- startTimer();
- }
- public void startTimer() {
- //set a new Timer
- timer = new Timer();
- //initialize the TimerTask's job
- initializeTimerTask();
- //schedule the timer, after the first 5000ms the TimerTask will run every 10000ms
- timer.schedule(timerTask, 5000, 10000); //
- }
- public void stoptimertask(View v) {
- //stop the timer, if it's not already null
- if (timer != null) {
- timer.cancel();
- timer = null;
- }
- }
- public void initializeTimerTask() {
- timerTask = new TimerTask() {
- public void run() {
- //use a handler to run a toast that shows the current timestamp
- // handler=new Handler();
- mHandler.post(new Runnable() {
- public void run() {
- String n= sharedpreferences.getString("nameKey", Name);
- String ph= sharedpreferences.getString("Password", Password);
- // String n="test";
- // String ph="test";
- mWebView.loadUrl("javascript:changeBackgroundColor()");
- mWebView.loadUrl("http://www.nousappsystems.com/framework/index.php/TempMiter?user="+n+"&pword="+ph+"");
- mWebView.setWebChromeClient(new WebChromeClient() {
- @Override
- public boolean onConsoleMessage(ConsoleMessage cm) {
- Log.d(TAG, cm.message() + " ##########" + cm.lineNumber() + " -%%%%%%%%%-" + cm.sourceId());
- // refresh();
- // mWebView.loadUrl("http://www.nousappsystems.com/gprs/TempMitr/TempMitrView.php");
- test = cm.message();
- txt1 = test.toString();
- if ((test.equals(ctest))) {
- } else if ((test.startsWith("Uncaught"))) {
- }else if(notifyId != 1) {
- }
- else if ((test.startsWith("SVG's SMIL"))) {
- }
- else {
- addNotification(txt1);
- }
- return true;
- }
- });
- }
- });
- }
- };
- }
- //thread second
- public void startProgress(View view) {
- // do something long
- Runnable runnable = new Runnable() {
- @Override
- public void run() {
- for (int i = 0; i <= 10; i++) {
- final int value = i;
- doFakeWork();
- }
- }
- };
- new Thread(runnable).start();
- }
- // Simulating something timeconsuming
- private void doFakeWork() {
- try {
- Thread.sleep(1); //for 1 sec 1000 need to enter
- Toast.makeText(getBaseContext(), "fake work ", Toast.LENGTH_LONG).show();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement