Skip to content

Commit

Permalink
server service handling fixes and icon
Browse files Browse the repository at this point in the history
  • Loading branch information
victordiaz committed Jul 2, 2019
1 parent 6c6683b commit 52fa057
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 49 deletions.
1 change: 0 additions & 1 deletion phonk_app/src/main/java/io/phonk/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,6 @@ public void onEventMainThread(Events.AppUiEvent e) {
// recreate();
// finish();
break;

}
}

Expand Down
18 changes: 18 additions & 0 deletions phonk_app/src/main/java/io/phonk/gui/ConnectionInfoFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ public void onEventMainThread(Events.Connection e) {
String type = e.getType();
String address = e.getAddress();

MLog.d("qq", type);

if (type == "wifi") {
mTxtConnectionMessage.setText(getResources().getString(io.phonk.R.string.connection_message_wifi));
mTxtConnectionIp.setText("http://" + address);
Expand All @@ -176,6 +178,22 @@ public void onEventMainThread(Events.Connection e) {
}
}

@Subscribe
public void onEventMainThread(Events.AppUiEvent e) {
String action = e.getAction();
Object value = e.getValue();
MLog.d("qq", "got AppUiEvent 2" + action);

switch (action) {
case "stopServers":
mToggleServers.setChecked(false);
break;
case "startServers":
mToggleServers.setChecked(true);
break;
}
}

public void addTextToConsole(String text) {
mComputerText.append(text + "\n> ");

Expand Down
75 changes: 30 additions & 45 deletions phonk_app/src/main/java/io/phonk/server/PhonkServerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import android.widget.Toast;

import androidx.core.app.NotificationCompat;
import androidx.core.app.TaskStackBuilder;

import com.google.gson.Gson;

Expand All @@ -48,6 +49,7 @@
import java.net.UnknownHostException;
import java.util.HashMap;

import io.phonk.MainActivity;
import io.phonk.R;
import io.phonk.appinterpreter.AppRunnerCustom;
import io.phonk.events.Events;
Expand Down Expand Up @@ -89,7 +91,10 @@ public int onStartCommand(Intent intent, int flags, int startId) {

if (intent != null) {
AndroidUtils.debugIntent(TAG, intent);
if (intent.getAction() == SERVICE_CLOSE) stopSelf();
if (intent.getAction() == SERVICE_CLOSE) {
EventBus.getDefault().postSticky(new Events.AppUiEvent("stopServers", ""));
stopSelf();
}
}

return Service.START_STICKY;
Expand Down Expand Up @@ -150,23 +155,38 @@ public void onCreate() {

EventBus.getDefault().register(this);

/*
// go back to app intent
Intent resultIntent = new Intent(this, MainActivity.class);
// The stack builder object will contain an artificial back stack for
// navigating backward from the Activity leads out your application to the Home screen.
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(MainActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
*/

// close server intent
Intent notificationIntent = new Intent(this, PhonkServerService.class).setAction(SERVICE_CLOSE);
PendingIntent pendingIntent = PendingIntent.getService(this, (int) System.currentTimeMillis(), notificationIntent, 0);
PendingIntent pendingIntentStopService = PendingIntent.getService(this, (int) System.currentTimeMillis(), notificationIntent, 0);
NotificationManager mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

NotificationCompat.Builder builder = new NotificationCompat.Builder(this, PhonkSettings.NOTIFICATION_CHANNEL_ID)
.setSmallIcon(R.drawable.phonk_icon)
.setContentTitle("Phonk").setContentText("Web Editor access is enabled")
.setSmallIcon(R.drawable.icon_phonk_service)
.setContentTitle(this.getString(R.string.app_name))
.setContentText(this.getString(R.string.notification_description))
.setOngoing(false)
.addAction(R.drawable.ic_action_stop, "stop", pendingIntent)
//.setDeleteIntent(pendingIntent)
.setContentInfo("1 Connection");
// .setContentIntent(pendingIntent)
.addAction(R.drawable.ic_action_stop, this.getString(R.string.notification_stop), pendingIntentStopService);
// .setContentInfo("1 Connection");

// damm annoying android pofkjpodsjf0ewiah
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
int importance = NotificationManager.IMPORTANCE_LOW;
mChannel = new NotificationChannel(PhonkSettings.NOTIFICATION_CHANNEL_ID, this.getString(R.string.app_name), importance);
mChannel.setDescription("lalalla");
// mChannel.setDescription("lalalla");
mChannel.enableLights(false);
mNotificationManager.createNotificationChannel(mChannel);
} else {
Expand Down Expand Up @@ -258,7 +278,7 @@ public void run() {
IntentFilter filterWebEditorSend = new IntentFilter();
filterWebEditorSend.addAction("io.phonk.intent.WEBEDITOR_SEND");
registerReceiver(webEditorBroadcastReceiver, filterWebEditorSend);
MLog.d("qq22", "registering receiver");
MLog.d(TAG, "registering receiver");

// register a broadcast to receive the notification commands
IntentFilter filter = new IntentFilter();
Expand Down Expand Up @@ -315,42 +335,7 @@ public void onEvent(int event, String file) {
/*
* Notification that show if the server is ON
*/
private void createNotification() {
/*
//create pending intent that will be triggered if the notification is clicked
IntentFilter filter = new IntentFilter();
filter.addAction(SERVICE_CLOSE);
// registerReceiver(mNotificationReceiver, filter);
Intent stopIntent = new Intent(SERVICE_CLOSE);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, stopIntent, 0);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(org.protocoderrunner.R.drawable.phonk_icon)
.setContentTitle("Protocoder").setContentText("Running service ")
.setOngoing(false)
.addAction(org.protocoderrunner.R.drawable.ic_action_stop, "stop", pendingIntent)
.setDeleteIntent(pendingIntent);
// Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent(this, MainActivity.class);
// The stack builder object will contain an artificial back stack for
// navigating backward from the Activity leads out your application to the Home screen.
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(AppRunnerActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager = (NotificationManager) this.getSystemService(this.NOTIFICATION_SERVICE);
mNotificationManager.notify(NOTIFICATION_SERVER_ID, mBuilder.build());
Thread.setDefaultUncaughtExceptionHandler(handler);
*/
}


/**
* Events
*
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 5 additions & 3 deletions phonk_app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@

<resources>

<string name="app_name">Phonk!</string>
<string name="activity_name">Phonk!</string>
<string name="runner_name">Phonk! Runner</string>
<string name="app_name">Phonk</string>
<string name="activity_name">Phonk</string>
<string name="runner_name">Phonk Runner</string>
<string name="connect_message">Click to connect</string>
<string name="connection_message_connected">Point the web browser in your computer to</string>
<string name="connection_message_wifi">Connected to WIFI. Point your computer\'s web browser to this address</string>
Expand Down Expand Up @@ -138,4 +138,6 @@
<string name="resource">Normal</string>
<string name="licenses_explanation">Phonk includes different open source libraries and without them this project would not be possible. Below you can check each individual license. Click to expand</string>

<string name="notification_description">Web Editor access is enabled</string>
<string name="notification_stop">Stop Server</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,13 @@ public void onNotificationPosted(StatusBarNotification sbn) {
text = getString(extras.getCharSequence("android.text"));
}

/*
Log.i("Package", pack);
Log.i("Ticker", ticker);
Log.i("Title", title);
Log.i("Text", text);
*/

Intent msgrcv = new Intent("Msg");
msgrcv.putExtra("package", pack);
msgrcv.putExtra("ticker", ticker);
Expand Down

0 comments on commit 52fa057

Please sign in to comment.