Skip to content

Commit

Permalink
Formatting changes, devicehandler changes
Browse files Browse the repository at this point in the history
  • Loading branch information
MihaiBojescu committed Oct 17, 2017
1 parent 8e5c908 commit 7e9a969
Show file tree
Hide file tree
Showing 22 changed files with 173 additions and 130 deletions.
Binary file removed app/Linux notifier.apk
Binary file not shown.
12 changes: 7 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
compileSdkVersion 26
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "dev.mihaibojescu.linuxnotifier"
minSdkVersion 15
targetSdkVersion 25
versionCode 3
versionName "1.2"
versionCode 4
versionName '1.3'
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand All @@ -17,10 +17,12 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
Expand Down
Empty file modified app/src/main/ic_launcher-web.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public enum statuses
WAITING_AUTH,
CONNECTED,
DISCONNECTED
};
}


public Device()
Expand Down
30 changes: 14 additions & 16 deletions app/src/main/java/dev/mihaibojescu/linuxnotifier/DeviceHandlers/DeviceHandler.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ public void run()
break;
}
else
{
device.setStatus(Device.statuses.DISCONNECTED);

this.updateUI();
}
}
catch (InterruptedException e)
{
Expand Down Expand Up @@ -124,18 +126,10 @@ private void authentificateDevice(final Device device)
request.put("pin", device.getPin());

UIHandler.post(new AuthUIRunnable(device, main, communicator, this));
}
catch (JSONException e)
{
e.printStackTrace();
}

communicator.pushMessageToIP(device.getAddress(), 5005, request, true);

try
{
lastInterval = communicator.getInterval();
communicator.setInterval(10000);
communicator.pushMessageToIP(device.getAddress(), 5005, request, true);
JSONObject response = communicator.getResponse();
communicator.setInterval(lastInterval);

Expand All @@ -145,8 +139,9 @@ private void authentificateDevice(final Device device)
this.updateUI();
this.writeDevicesToFile();
}

}
catch(JSONException e)
catch (JSONException e)
{
e.printStackTrace();
}
Expand Down Expand Up @@ -208,7 +203,7 @@ public void writeDevicesToFile()
JSONArray macs = new JSONArray();
JSONArray pins = new JSONArray();

for (Device currentDevice : this.devices)
for (Device currentDevice: this.devices)
{
names.put(currentDevice.getName());
addresses.put(currentDevice.getAddress());
Expand Down Expand Up @@ -238,12 +233,15 @@ public void dispatchMessageToAllDevices(JSONObject message)
{
NetworkCommunicator communicator = NetworkCommunicator.getInstance();

for(Device currentDevice: devices)
if(isDeviceValid(currentDevice))
if(currentDevice.getStatus() == Device.statuses.CONNECTED)
for (Device currentDevice: devices)
if (isDeviceValid(currentDevice))
if (currentDevice.getStatus() == Device.statuses.CONNECTED)
communicator.pushMessageToIP(currentDevice.getAddress(), 5005, message, false);
else
currentDevice.setStatus(Device.statuses.NEW);
{
currentDevice.setStatus(Device.statuses.DISCONNECTED);
updateUI();
}
}

public void addDevice(Device device)
Expand Down
Empty file.
64 changes: 12 additions & 52 deletions app/src/main/java/dev/mihaibojescu/linuxnotifier/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,25 @@
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.SeekBar;
import android.widget.Toast;

import com.google.android.gms.appindexing.Action;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.appindexing.Thing;
import com.google.android.gms.common.api.GoogleApiClient;

import dev.mihaibojescu.linuxnotifier.Crypto.CryptHandler;
import dev.mihaibojescu.linuxnotifier.DeviceHandlers.DeviceHandler;
import dev.mihaibojescu.linuxnotifier.IO.IOClass;
import dev.mihaibojescu.linuxnotifier.NetworkTools.DiscoveryReceiver;
Expand All @@ -50,7 +48,7 @@ public class MainActivity extends AppCompatActivity
private DiscoveryReceiver receiver;
private DiscoverySender sender;


@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
@Override
protected void onCreate(Bundle savedInstanceState)
Expand All @@ -71,11 +69,6 @@ protected void onCreate(Bundle savedInstanceState)

startThreads();

SeekBar seekbar = ((SeekBar)findViewById(R.id.seekBar));
pingService.updateInterval(seekbar.getProgress());
communicatorThread.setInterval(seekbar.getProgress());
seekbar.setOnSeekBarChangeListener(new SeekBarHandler());

checkAndUpdatePermissions();

final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
Expand Down Expand Up @@ -149,22 +142,6 @@ public boolean onOptionsItemSelected(MenuItem item)
deviceHandler.scanSubnet();
return true;

case R.id.renewkeys:
CryptHandler auth = CryptHandler.getInstance();
auth.createNewKeys(2048);

try
{
Toast.makeText(this.getApplicationContext(), auth.getPublicKey().getEncoded().toString(), Toast.LENGTH_LONG).show();
}
catch (Exception e)
{
e.printStackTrace();
}

Toast.makeText(this, "Not implemented yet", Toast.LENGTH_SHORT).show();
return true;

case R.id.cleancache:
this.deviceHandler.clearCache();
this.communicatorThread.clearAll();
Expand All @@ -185,16 +162,21 @@ private void startThreads()

if (this.deviceHandler.getState() == Thread.State.NEW)
{
this.deviceHandler.getAndCheckDevicesFromFile();
// this.deviceHandler.getAndCheckDevicesFromFile();
this.deviceHandler.start();
}

if(this.sender.getState() == Thread.State.NEW)
Log.d("MAINACTIVITY", this.sender.getState().toString());
Log.d("MAINACTIVITY", this.receiver.getState().toString());
if (this.sender.getState() == Thread.State.NEW)
this.sender.start();

if(this.receiver.getState() == Thread.State.NEW)
if (this.receiver.getState() == Thread.State.NEW)
this.receiver.start();

Log.d("MAINACTIVITY", this.sender.getState().toString());
Log.d("MAINACTIVITY", this.receiver.getState().toString());

}

private void checkAndUpdatePermissions()
Expand All @@ -210,7 +192,7 @@ private Boolean isNotificationListenerEnabled()
if (listenerString != null && !listenerString.equals(""))
{
String[] listeners = listenerString.split(":");
for (String listener: listeners)
for (String listener : listeners)
{
ComponentName componentName = ComponentName.unflattenFromString(listener);
if (componentName != null)
Expand Down Expand Up @@ -252,26 +234,4 @@ public void onClick(View view, int position)
deviceHandler.addPriorityDeviceToCheckList(deviceHandler.getHostByIndex(position));
}
}

private class SeekBarHandler implements SeekBar.OnSeekBarChangeListener
{
@Override
public void onProgressChanged(android.widget.SeekBar seekBar, int progress, boolean fromUser)
{
pingService.updateInterval(progress);
communicatorThread.setInterval(progress);
}

@Override
public void onStartTrackingTouch(android.widget.SeekBar seekBar)
{

}

@Override
public void onStopTrackingTouch(android.widget.SeekBar seekBar)
{

}
}
}
Empty file.
3 changes: 3 additions & 0 deletions app/src/main/java/dev/mihaibojescu/linuxnotifier/NetworkTools/DiscoverySender.java
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package dev.mihaibojescu.linuxnotifier.NetworkTools;

import android.util.Log;

import org.json.JSONException;
import org.json.JSONObject;

Expand Down Expand Up @@ -63,6 +65,7 @@ public void run()
{
send.wait();
socket.send(packet);
Log.d("Discovery Service", "Sent discovery");
}
catch (InterruptedException | IOException e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,4 @@ public void clearPingList()
{
pingQueue.clear();
}

public void updateInterval(Integer interval)
{
this.interval = interval;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

import org.json.JSONException;
import org.json.JSONObject;
Expand All @@ -23,7 +24,7 @@ public void onReceive(Context context, Intent intent)
try
{
JSONObject message = Request.createRequest(Request.reasons.NOTIFICATION);
message.put("appName", intent.getStringExtra("appName"));
message.put("app name", intent.getStringExtra("app name"));
message.put("title", intent.getStringExtra("title"));
message.put("data", intent.getStringExtra("data"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import android.service.notification.NotificationListenerService;
import android.service.notification.StatusBarNotification;
import android.support.annotation.RequiresApi;
import android.widget.Toast;

import dev.mihaibojescu.linuxnotifier.R;

/**
Expand All @@ -27,7 +29,8 @@ public enum actions
}

@Override
public IBinder onBind(Intent intent) {
public IBinder onBind(Intent intent)
{
return super.onBind(intent);
}

Expand All @@ -50,11 +53,11 @@ public void onNotificationPosted (StatusBarNotification sbn)
ApplicationInfo applicationInfo;
applicationInfo = packageManager.getApplicationInfo(sbn.getPackageName(), 0);

intent.putExtra("appName", packageManager.getApplicationLabel(applicationInfo));
intent.putExtra("app name", packageManager.getApplicationLabel(applicationInfo));
}
catch(PackageManager.NameNotFoundException e)
{
intent.putExtra("appName", "unknown application");
intent.putExtra("app name", "unknown application");
}

intent.putExtra("title", sbn.getNotification().extras.getString("android.title"));
Expand Down
Empty file.
Empty file.
Empty file.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@ public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapte

private List<Device> dataset;

public static class ViewHolder extends RecyclerView.ViewHolder{

public static class ViewHolder extends RecyclerView.ViewHolder
{
public TextView deviceName;
public TextView deviceMac;
public TextView connectionStatus;
public ViewHolder(View view) {


public ViewHolder(View view)
{
super(view);
deviceName = (TextView) view.findViewById(R.id.devicename);
deviceMac = (TextView) view.findViewById(R.id.devicemac);
Expand All @@ -49,10 +54,21 @@ public void onBindViewHolder(ViewHolder holder, int position)
Device device = dataset.get(position);
holder.deviceName.setText(device.getName());
holder.deviceMac.setText(device.getMac());
if(device.getStatus() == Device.statuses.CONNECTED)
holder.connectionStatus.setVisibility(View.VISIBLE);
else
holder.connectionStatus.setVisibility(View.INVISIBLE);
switch (device.getStatus())
{
case NEW:
holder.connectionStatus.setText("New");
break;
case WAITING_AUTH:
holder.connectionStatus.setText("Waiting authentification");
break;
case CONNECTED:
holder.connectionStatus.setText("Connected");
break;
case DISCONNECTED:
holder.connectionStatus.setText("Disconnected");
break;
}
}

@Override
Expand Down
Loading

0 comments on commit 7e9a969

Please sign in to comment.