diff --git a/README.md b/README.md index 02a6419..bdc006d 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -NoWOL +### NoWOL + +![License](https://img.shields.io/badge/License-GPLv3-blue.svg) + Android application to rule PC power management. A part of NoWOL project. [https://developersu.blogspot.com/2018/04/nowol-2.html](https://developersu.blogspot.com/2018/04/nowol-2.html) -License: GNU GPL v.3. - -Dmitry Isaenko -2017, Russia +2017-2020, Russia diff --git a/app/build.gradle b/app/build.gradle index 4342751..ecbe4d7 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -4,11 +4,11 @@ android { compileSdkVersion 29 buildToolsVersion "29.0.2" defaultConfig { - applicationId "com.blogspot.developersu.nowol.nowol" + applicationId "com.blogspot.developersu.nowol" minSdkVersion 14 targetSdkVersion 29 - versionCode 4 - versionName "4.0" + versionCode 5 + versionName "5.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true } @@ -18,6 +18,10 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } } dependencies { diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index cecac7e..87f3aae 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,6 +1,6 @@ + package="com.blogspot.developersu.nowol"> - + + @@ -41,7 +40,7 @@ android:name=".SendRequestService" android:exported="false" /> - + diff --git a/app/src/main/ic_launcher-web.png b/app/src/main/ic_launcher-web.png new file mode 100644 index 0000000..a19aa44 Binary files /dev/null and b/app/src/main/ic_launcher-web.png differ diff --git a/app/src/main/java/com/blogspot/developersu/nowol/MainActivity.java b/app/src/main/java/com/blogspot/developersu/nowol/MainActivity.java new file mode 100644 index 0000000..e763f21 --- /dev/null +++ b/app/src/main/java/com/blogspot/developersu/nowol/MainActivity.java @@ -0,0 +1,218 @@ +/* + Copyright 2017-2020 Dmitry Isaenko + + This file is part of NoWOL. + + NoWOL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + NoWOL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with NoWOL. If not, see . +*/ +package com.blogspot.developersu.nowol; + +import android.app.Dialog; +import android.appwidget.AppWidgetManager; +import android.content.ComponentName; +import android.content.Intent; +import android.content.SharedPreferences; +import android.os.Handler; +import android.os.ResultReceiver; +import android.os.Bundle; +import android.text.Editable; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.view.WindowManager; +import android.widget.Button; +import android.widget.EditText; +import android.widget.TextView; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; +import androidx.core.content.ContextCompat; +import com.blogspot.developersu.nowol.widget.NoWolWidget; +import com.google.android.material.snackbar.Snackbar; + +import static com.blogspot.developersu.nowol.ServerReplies.*; + +public class MainActivity extends AppCompatActivity { + private TextView hostAddress, + statusLbl; + + private Intent SendRequestIntent; + + private int status = -2; + + private SharedPreferences settings; + + private class MyResultReciever extends ResultReceiver{ + + MyResultReciever(Handler handler) { + super(handler); + } + + @Override + protected void onReceiveResult(int resultCode, Bundle resultData) { + super.onReceiveResult(resultCode, resultData); + status = resultCode; + updateServerStatusText(resultCode); + showSnackBarNotice(resultCode); + } + } + + private void doRequest(String url) { + SendRequestIntent.putExtra("url", url); + startService(SendRequestIntent); + } + + private void inform(String textToShow){ + Snackbar.make(findViewById(android.R.id.content), textToShow, Snackbar.LENGTH_SHORT).show(); + } + + // provide toolbar options + @Override + public boolean onCreateOptionsMenu(Menu menu){ + MenuInflater infMenu = getMenuInflater(); + infMenu.inflate(R.menu.toolbar_main, menu); + return true; + } + + @Override + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + outState.putInt("STATE", status); + } + + @Override + protected void onCreate(final Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + MyResultReciever myReciever = new MyResultReciever(null); + SendRequestIntent = new Intent(this, SendRequestService.class); + SendRequestIntent.putExtra("receiver", myReciever); + + // toolbar setup start + Toolbar toolBar = findViewById(R.id.toolbar); + setSupportActionBar(toolBar); + getSupportActionBar(); + // toolbar setup end + + hostAddress = findViewById(R.id.hostNameStaticMain); + statusLbl = findViewById(R.id.statusTxtMainAct); + + if (savedInstanceState != null){ + status = savedInstanceState.getInt("STATE"); + updateServerStatusText(status); + } + + Button powerBtn = findViewById(R.id.pwrBntMainAct); + Button power5Btn = findViewById(R.id.pwr5BntMainAct); + Button resetBtn = findViewById(R.id.resBntMainAct); + // Set request queue for Volley + + settings = getSharedPreferences("NoWolPreferences", MODE_PRIVATE); + hostAddress.setText(settings.getString("Host", getResources().getString(R.string.hostNameDefault))); + + final Button.OnClickListener ActionButtonsListener = event -> { + switch (event.getId()) { + case R.id.pwrBntMainAct: + doRequest(hostAddress.getText().toString() + "/?POWER0=on"); + break; + case R.id.pwr5BntMainAct: + doRequest(hostAddress.getText().toString() + "/?POWER1=on"); + break; + case R.id.resBntMainAct: + doRequest(hostAddress.getText().toString() + "/?RESET=on"); + } + }; + // RequestQueue + powerBtn.setOnClickListener(ActionButtonsListener); + power5Btn.setOnClickListener(ActionButtonsListener); + resetBtn.setOnClickListener(ActionButtonsListener); + } + + private void updateServerStatusText(int status){ + switch (status) { + case STATE_ON: + statusLbl.setText(getResources().getString(R.string.statusOnline)); + statusLbl.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimaryDark)); + break; + case STATE_OFF: + statusLbl.setText(getResources().getString(R.string.statusOffline)); + statusLbl.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.colorRed)); + break; + case STATE_UNKNOWN: + statusLbl.setText(getResources().getString(R.string.noResponse)); + statusLbl.setTextColor(hostAddress.getTextColors()); + break; + } + } + private void showSnackBarNotice(int status) { + switch (status) { + case STATE_ON: + inform(getResources().getString(R.string.statusOnline)); + break; + case STATE_OFF: + inform(getResources().getString(R.string.statusOffline)); + break; + case STATE_UNKNOWN: + inform(getResources().getString(R.string.noResponse) + hostAddress.getText().toString()); + } + } + + @Override + public boolean onOptionsItemSelected(MenuItem item){ + switch (item.getItemId()){ + case R.id.refreshMenu: /* Button requests status */ + doRequest(hostAddress.getText().toString()); + break; + case R.id.changeHostMenu: /* Button requests pop-up window */ + showSettingsDialog(); + } + return true; + } + + private void showSettingsDialog(){ + final Dialog dialog = new Dialog(this); + dialog.setContentView(R.layout.settings_popup); + dialog.setTitle(getString(R.string.popupTitle)); + EditText input = (EditText) dialog.findViewById(R.id.input); + input.setText(hostAddress.getText()); + Button confirmButton = (Button) dialog.findViewById(R.id.confirm); + confirmButton.setOnClickListener(event -> { + updateAllUsingNewIp(input.getText()); + dialog.dismiss(); + }); + dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); + dialog.show(); + } + private void updateAllUsingNewIp(Editable newIpAddress){ + hostAddress.setText(newIpAddress); + // TODO:fix + inform(getResources().getString(R.string.hostLblMain) + newIpAddress); + settings.edit().putString("Host", newIpAddress.toString()).apply(); + + /* Update widgets by sending broadcast intent */ + Intent updateWidgetIntent = new Intent(this, NoWolWidget.class); + updateWidgetIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE); + + AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this); + int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(this, NoWolWidget.class)); + updateWidgetIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds); + sendBroadcast(updateWidgetIntent); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + stopService(SendRequestIntent); // just in case + } +} diff --git a/app/src/main/java/com/blogspot/developersu/nowol/SendRequestService.java b/app/src/main/java/com/blogspot/developersu/nowol/SendRequestService.java new file mode 100644 index 0000000..5b01036 --- /dev/null +++ b/app/src/main/java/com/blogspot/developersu/nowol/SendRequestService.java @@ -0,0 +1,98 @@ +/* + Copyright 2017-2020 Dmitry Isaenko + + This file is part of NoWOL. + + NoWOL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + NoWOL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with NoWOL. If not, see . +*/ +package com.blogspot.developersu.nowol; + +import android.app.IntentService; +import android.appwidget.AppWidgetManager; +import android.content.Intent; +import android.os.Bundle; +import android.os.ResultReceiver; +import android.widget.RemoteViews; +import androidx.core.content.ContextCompat; +import com.android.volley.Request; +import com.android.volley.RequestQueue; +import com.android.volley.toolbox.StringRequest; +import com.android.volley.toolbox.Volley; + +import static com.blogspot.developersu.nowol.ServerReplies.*; + +public class SendRequestService extends IntentService { + + private ResultReceiver resReceiver; + + public SendRequestService() { + super("MyIntentService"); + } + + @Override + protected void onHandleIntent(Intent intent) { + Bundle bundle = intent.getExtras(); + + if (bundle == null) + return; + + String url = bundle.getString("url"); + resReceiver = bundle.getParcelable("receiver"); + final int appWidgetId = bundle.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID); + + RequestQueue queueStd = Volley.newRequestQueue(this); + + StringRequest strRequest = new StringRequest(Request.Method.GET, url, //will be 4 requests + response -> { + if (response.contains("00c600")) + sendData(STATE_ON, appWidgetId); + else + sendData(STATE_OFF, appWidgetId); + }, error -> sendData(STATE_UNKNOWN, appWidgetId)); + + queueStd.add(strRequest); + } + + private void sendData(int state, int widgetId){ + final int greenColor = ContextCompat.getColor(this, R.color.colorPrimary); + final int redColor = ContextCompat.getColor(this, R.color.colorRed); + final int orangeColor = ContextCompat.getColor(this, R.color.colorOrange); + + // MainActivity requested + if (widgetId == 0){ + resReceiver.send(state, null); + } + + switch (state){ + case STATE_ON: + setWidgetTextColorIndication(widgetId, getResources().getString(R.string.statusOnline), greenColor); + break; + case STATE_OFF: + setWidgetTextColorIndication(widgetId, getResources().getString(R.string.statusOffline), redColor); + break; + case STATE_UNKNOWN: + setWidgetTextColorIndication(widgetId, getResources().getString(R.string.noResponse), orangeColor); + break; + } + } + private void setWidgetTextColorIndication(int widgetId, String text, int color){ + AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this); + RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.no_wol_widget); + + remoteViews.setTextViewText(R.id.widgetStatusText, text); + remoteViews.setInt(R.id.widgetHeaderLayout, "setBackgroundColor", color); + + appWidgetManager.updateAppWidget(widgetId, remoteViews); + } +} diff --git a/app/src/main/java/com/blogspot/developersu/nowol/ServerReplies.java b/app/src/main/java/com/blogspot/developersu/nowol/ServerReplies.java new file mode 100644 index 0000000..25c5256 --- /dev/null +++ b/app/src/main/java/com/blogspot/developersu/nowol/ServerReplies.java @@ -0,0 +1,25 @@ +/* + Copyright 2017-2020 Dmitry Isaenko + + This file is part of NoWOL. + + NoWOL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + NoWOL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with NoWOL. If not, see . +*/ +package com.blogspot.developersu.nowol; + +public class ServerReplies { + public static final int STATE_ON = 1; + public static final int STATE_OFF = 0; + public static final int STATE_UNKNOWN = -1; +} diff --git a/app/src/main/java/com/blogspot/developersu/nowol/nowol/MainActivity.java b/app/src/main/java/com/blogspot/developersu/nowol/nowol/MainActivity.java deleted file mode 100644 index 5d73c63..0000000 --- a/app/src/main/java/com/blogspot/developersu/nowol/nowol/MainActivity.java +++ /dev/null @@ -1,205 +0,0 @@ -package com.blogspot.developersu.nowol.nowol; - -import android.appwidget.AppWidgetManager; -import android.content.ComponentName; -import android.content.Intent; -import android.content.SharedPreferences; -import android.os.Handler; -import android.os.ResultReceiver; -import android.os.Bundle; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; -import android.view.View; -import android.widget.Button; -import android.widget.TextView; -import androidx.appcompat.app.AppCompatActivity; -import androidx.appcompat.widget.Toolbar; -import androidx.core.content.ContextCompat; -import com.blogspot.developersu.nowol.nowol.com.blogspot.developersu.nowol.nowol.widget.NoWolWidget; -import com.google.android.material.snackbar.Snackbar; - -public class MainActivity extends AppCompatActivity implements popUp.pupUpRetuningValueListener { - private TextView hostAddress; - private TextView statusLbl; - - Intent SendRequestIntent; - - private int status = -2; - - SharedPreferences.Editor settingsEditor; - // define reciever for the data we got from service - private class MyResultReciever extends ResultReceiver{ - - MyResultReciever(Handler handler) { - super(handler); - } - - @Override - protected void onReceiveResult(int resultCode, Bundle resultData) { - super.onReceiveResult(resultCode, resultData); - switch (resultCode) { - case 1: - inform(getResources().getString(R.string.statusOnline)); - statusLbl.setText(getResources().getString(R.string.statusOnline)); - statusLbl.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimaryDark)); - break; - case 0: - inform(getResources().getString(R.string.statusOffline)); - statusLbl.setText(getResources().getString(R.string.statusOffline)); - statusLbl.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.colorRed)); - break; - case -1: - inform(getResources().getString(R.string.noResponse) + hostAddress.getText().toString()); - statusLbl.setText(getResources().getString(R.string.noResponse)); - statusLbl.setTextColor(hostAddress.getTextColors()); - break; - default: break; - } - status = resultCode; - } - } - //reciever end - private void doRequest(String url) { - SendRequestIntent.putExtra("url", url); - startService(SendRequestIntent); - } - - private void inform(String textToShow){ - //Toast.makeText(this, textToShow, Toast.LENGTH_SHORT).show(); - // .setGravity(Gravity.TOP|Gravity.BOTTOM,0,0) - Snackbar.make(findViewById(android.R.id.content), textToShow, Snackbar.LENGTH_SHORT).show(); - // SOME GOODS APPEARS SUDDENLY android.R.id.content gives you the root element of a view, without having to know its actual name/type/ID. - } - - // provide toolbar options - @Override - public boolean onCreateOptionsMenu(Menu menu){ - MenuInflater infMenu = getMenuInflater(); - infMenu.inflate(R.menu.toolbar_main, menu); - return true; - } - - @Override - protected void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - outState.putInt("STATE", status); - } - - @Override - protected void onCreate(final Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - - MyResultReciever myReciever = new MyResultReciever(null); - SendRequestIntent = new Intent(this, SendRequestService.class); - SendRequestIntent.putExtra("reciever", myReciever); - - // toolbar setup start - Toolbar toolBar = findViewById(R.id.toolbar); - setSupportActionBar(toolBar); - getSupportActionBar(); - // toolbar setup end - - hostAddress = findViewById(R.id.hostNameStaticMain); - statusLbl = findViewById(R.id.statusTxtMainAct); - - if (savedInstanceState != null){ - status = savedInstanceState.getInt("STATE"); - switch (status) { - case 1: - inform(getResources().getString(R.string.statusOnline)); - statusLbl.setText(getResources().getString(R.string.statusOnline)); - statusLbl.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimaryDark)); - break; - case 0: - inform(getResources().getString(R.string.statusOffline)); - statusLbl.setText(getResources().getString(R.string.statusOffline)); - statusLbl.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.colorRed)); - break; - case -1: - inform(getResources().getString(R.string.noResponse) + hostAddress.getText().toString()); - statusLbl.setText(getResources().getString(R.string.noResponse)); - statusLbl.setTextColor(hostAddress.getTextColors()); - break; - } - } - - Button powerBtn = findViewById(R.id.pwrBntMainAct); - Button power5Btn = findViewById(R.id.pwr5BntMainAct); - Button resetBtn = findViewById(R.id.resBntMainAct); - // Set request queue for Volley - - - SharedPreferences settings = getSharedPreferences("NoWolPreferences", MODE_PRIVATE); - hostAddress.setText(settings.getString("Host", getResources().getString(R.string.hostNameDefault))); - settingsEditor = settings.edit(); - - final Button.OnClickListener ActionButtonsListener = new Button.OnClickListener() { - @Override - public void onClick(View v) { - switch (v.getId()) { - case R.id.pwrBntMainAct: - doRequest(hostAddress.getText().toString() + "/?POWER0=on"); - break; - case R.id.pwr5BntMainAct: - doRequest(hostAddress.getText().toString() + "/?POWER1=on"); - break; - case R.id.resBntMainAct: - doRequest(hostAddress.getText().toString() + "/?RESET=on"); - break; - default: - break; - } - } - }; - // RequestQueue - powerBtn.setOnClickListener(ActionButtonsListener); - power5Btn.setOnClickListener(ActionButtonsListener); - resetBtn.setOnClickListener(ActionButtonsListener); - } - - @Override - public void onFinishEdit (String hostNameReSet){ - hostAddress.setText(hostNameReSet); - inform(getResources().getString(R.string.hostLblMain) + hostNameReSet); - settingsEditor.putString("Host", hostNameReSet); - settingsEditor.commit(); - /* - Update widgets by sending broadcast intent - */ - Intent updateWidgetIntent = new Intent(this, NoWolWidget.class); - updateWidgetIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE); - - AppWidgetManager awm = AppWidgetManager.getInstance(this); - int[] IDs = awm.getAppWidgetIds(new ComponentName(this, NoWolWidget.class)); - updateWidgetIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, IDs); - getApplicationContext().sendBroadcast(updateWidgetIntent); - /* - broadcast end - */ - } - - @Override - public boolean onOptionsItemSelected(MenuItem item){ - switch (item.getItemId()){ - case R.id.refreshMenu: /* Button requests status */ - doRequest(hostAddress.getText().toString()); - break; - case R.id.changeHostMenu: /* Button requests pop-up window */ - popUp N = popUp.newInstance(hostAddress.getText()); - N.show(this.getSupportFragmentManager(), "tst"); - break; - default: - //onOptionsItemSelected(item); - break; - } - return true; - } - - @Override - protected void onDestroy() { - super.onDestroy(); - stopService(SendRequestIntent); // just in case - } -} diff --git a/app/src/main/java/com/blogspot/developersu/nowol/nowol/SendRequestService.java b/app/src/main/java/com/blogspot/developersu/nowol/nowol/SendRequestService.java deleted file mode 100644 index 68fff28..0000000 --- a/app/src/main/java/com/blogspot/developersu/nowol/nowol/SendRequestService.java +++ /dev/null @@ -1,92 +0,0 @@ -package com.blogspot.developersu.nowol.nowol; - -import android.app.IntentService; -import android.appwidget.AppWidgetManager; -import android.content.Intent; -import android.os.Bundle; -import android.os.ResultReceiver; -import android.widget.RemoteViews; -import androidx.core.content.ContextCompat; -import com.android.volley.Request; -import com.android.volley.RequestQueue; -import com.android.volley.Response; -import com.android.volley.VolleyError; -import com.android.volley.toolbox.StringRequest; -import com.android.volley.toolbox.Volley; - - -public class SendRequestService extends IntentService { - - private static final int STATE_ON = 1; - private static final int STATE_OFF = 0; - private static final int STATE_UNKNOWN = -1; - - private ResultReceiver resReceiver; - - public SendRequestService() { - super("MyIntentService"); - } - - private void sendData(int state, int awID){ - // MainActivity requested - if (awID == 0) { - // Log.d("qwerty1212", "MainActivity case. Status = " + Integer.toString(state) + " awID = " + Integer.toString(awID)); - resReceiver.send(state, null); - } - - RemoteViews rv = new RemoteViews(getPackageName(), R.layout.no_wol_widget); - AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this); - - switch (state){ - case STATE_ON: - rv.setTextViewText(R.id.widgetStatusText, getResources().getString(R.string.statusOnline)); - rv.setInt(R.id.widgetHeaderLayout, "setBackgroundColor", ContextCompat.getColor(this, R.color.colorPrimary)); - // Log.d("qwerty1212", "case 1 widget"); - break; - case STATE_OFF: - rv.setTextViewText(R.id.widgetStatusText, getResources().getString(R.string.statusOffline)); - rv.setInt(R.id.widgetHeaderLayout, "setBackgroundColor", ContextCompat.getColor(this, R.color.colorRed)); - // Log.d("qwerty1212", "case 0 widget"); - break; - case STATE_UNKNOWN: - rv.setTextViewText(R.id.widgetStatusText, getResources().getString(R.string.noResponse)); - rv.setInt(R.id.widgetHeaderLayout, "setBackgroundColor", ContextCompat.getColor(this, R.color.colorOrange)); - // Log.d("qwerty1212", "case -1 widget"); - break; - } - appWidgetManager.updateAppWidget(awID, rv); - } - - @Override - protected void onHandleIntent(Intent intent) { - if (intent == null) - return; - - // Log.d("service", "Got intent"); - Bundle bndle = intent.getExtras(); - String url = bndle.getString("url"); - resReceiver = bndle.getParcelable("reciever"); - final int awID = bndle.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID); - - // Log.d("qwerty1212", "got from " + Integer.toString(awID) +" "+ url); - - RequestQueue queueStd = Volley.newRequestQueue(this); - StringRequest strRequest = new StringRequest(Request.Method.GET, url, //will be 4 requests - new Response.Listener() { - @Override - public void onResponse(String response) { - if (response.contains("00c600")){ - sendData(STATE_ON, awID); - } else { - sendData(STATE_OFF, awID); - } - } - }, new Response.ErrorListener() { - @Override - public void onErrorResponse(VolleyError error) { - sendData(STATE_UNKNOWN, awID); - } - }); - queueStd.add(strRequest); - } -} diff --git a/app/src/main/java/com/blogspot/developersu/nowol/nowol/com/blogspot/developersu/nowol/nowol/widget/NoWolWidget.java b/app/src/main/java/com/blogspot/developersu/nowol/nowol/com/blogspot/developersu/nowol/nowol/widget/NoWolWidget.java deleted file mode 100644 index 535b250..0000000 --- a/app/src/main/java/com/blogspot/developersu/nowol/nowol/com/blogspot/developersu/nowol/nowol/widget/NoWolWidget.java +++ /dev/null @@ -1,93 +0,0 @@ -package com.blogspot.developersu.nowol.nowol.com.blogspot.developersu.nowol.nowol.widget; - -import android.app.PendingIntent; -import android.appwidget.AppWidgetManager; -import android.appwidget.AppWidgetProvider; -import android.content.ComponentName; -import android.content.Context; -import android.content.Intent; -import android.content.SharedPreferences; -import android.graphics.Color; -import android.widget.RemoteViews; - -import com.blogspot.developersu.nowol.nowol.R; -import com.blogspot.developersu.nowol.nowol.SendRequestService; - - -public class NoWolWidget extends AppWidgetProvider { - - private void setRequests(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIDs){ - SharedPreferences sharedSettings = context.getSharedPreferences("NoWolPreferences", Context.MODE_PRIVATE); - String hostIP = sharedSettings.getString("Host", context.getResources().getString(R.string.hostNameDefault)); - int bgColor = sharedSettings.getInt("WidgetBgColor", Color.BLACK); - - RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.no_wol_widget); - - rv.setInt(R.id.widgetBasicLayout, "setBackgroundColor", bgColor); - - for (int appWidgetId : appWidgetIDs) { - //refresh - Intent refreshIntent = new Intent(context, SendRequestService.class); - refreshIntent.putExtra("url", hostIP); - refreshIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); - PendingIntent refreshPendingIntent = PendingIntent.getService(context, appWidgetId+1, refreshIntent, PendingIntent.FLAG_UPDATE_CURRENT); - rv.setOnClickPendingIntent(R.id.widgetBntRefresh, refreshPendingIntent); - //reset - Intent resetIntent = new Intent(context, SendRequestService.class); - resetIntent.putExtra("url", hostIP + "/?RESET=on"); - resetIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); - PendingIntent resetPendingIntent = PendingIntent.getService(context, appWidgetId+2, resetIntent, PendingIntent.FLAG_UPDATE_CURRENT); - rv.setOnClickPendingIntent(R.id.widgetBtnReset, resetPendingIntent); - //power - Intent powerIntent = new Intent(context, SendRequestService.class); - powerIntent.putExtra("url", hostIP + "/?POWER0=on"); - powerIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); - PendingIntent powerPendingIntent = PendingIntent.getService(context, appWidgetId+3, powerIntent, PendingIntent.FLAG_UPDATE_CURRENT); - rv.setOnClickPendingIntent(R.id.widgetBtnPwr, powerPendingIntent); - //power5 - Intent power5Intent = new Intent(context, SendRequestService.class); - power5Intent.putExtra("url", hostIP + "/?POWER1=on"); - power5Intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); - PendingIntent power5PendingIntent = PendingIntent.getService(context, appWidgetId+4, power5Intent, PendingIntent.FLAG_UPDATE_CURRENT); - rv.setOnClickPendingIntent(R.id.widgetBtnPwr5, power5PendingIntent); - - appWidgetManager.updateAppWidget(appWidgetId, rv); - - context.startService(refreshIntent); - } - } - - @Override - public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { - super.onUpdate(context, appWidgetManager, appWidgetIds); - - setRequests(context, appWidgetManager, appWidgetIds); - } - - @Override - public void onEnabled(Context context) { - super.onEnabled(context); - - AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); - int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context, NoWolWidget.class)); - - setRequests(context, appWidgetManager, appWidgetIds); - } - - @Override - public void onReceive(Context context, Intent intent) { - super.onReceive(context, intent); - - onEnabled(context); - } - - @Override - public void onDeleted(Context context, int[] appWidgetIds) { - super.onDeleted(context, appWidgetIds); - } - - @Override - public void onDisabled(Context context) { - super.onDisabled(context); - } -} diff --git a/app/src/main/java/com/blogspot/developersu/nowol/nowol/com/blogspot/developersu/nowol/nowol/widget/WidgetConfigurator.java b/app/src/main/java/com/blogspot/developersu/nowol/nowol/com/blogspot/developersu/nowol/nowol/widget/WidgetConfigurator.java deleted file mode 100644 index 8c3eca5..0000000 --- a/app/src/main/java/com/blogspot/developersu/nowol/nowol/com/blogspot/developersu/nowol/nowol/widget/WidgetConfigurator.java +++ /dev/null @@ -1,131 +0,0 @@ -package com.blogspot.developersu.nowol.nowol.com.blogspot.developersu.nowol.nowol.widget; - -import android.app.PendingIntent; -import android.appwidget.AppWidgetManager; -import android.content.Context; -import android.content.Intent; -import android.content.SharedPreferences; -import android.graphics.Color; -import android.os.Bundle; -import android.util.Log; -import android.view.View; -import android.widget.Button; -import android.widget.RemoteViews; -import android.widget.SeekBar; -import android.widget.TextView; -import androidx.appcompat.app.AppCompatActivity; -import com.blogspot.developersu.nowol.nowol.R; -import com.blogspot.developersu.nowol.nowol.SendRequestService; -import com.google.android.material.switchmaterial.SwitchMaterial; - -public class WidgetConfigurator extends AppCompatActivity { - - private SeekBar opacityBar; - private SwitchMaterial bkgoundSwitch; - - private void generateWidgetAndDie(int awID, Context context){ - SharedPreferences.Editor settingsEditor; - - RemoteViews rv = new RemoteViews(this.getPackageName(), R.layout.no_wol_widget); - AppWidgetManager awm = AppWidgetManager.getInstance(this); - - // get shared preferences - SharedPreferences sharedSettings = context.getSharedPreferences("NoWolPreferences", Context.MODE_PRIVATE); - String hostIP = sharedSettings.getString("Host", context.getResources().getString(R.string.hostNameDefault)); - // set setting editor to store background color set for all our widgets - settingsEditor = sharedSettings.edit(); - - // @TODO set pending intents linkage to buttons - Intent refreshIntent = new Intent(context, SendRequestService.class); - refreshIntent.putExtra("url", hostIP); - refreshIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, awID); - PendingIntent refreshPendingIntent = PendingIntent.getService(context, awID+1, refreshIntent, PendingIntent.FLAG_UPDATE_CURRENT); - rv.setOnClickPendingIntent(R.id.widgetBntRefresh, refreshPendingIntent); - //reset - Intent resetIntent = new Intent(context, SendRequestService.class); - resetIntent.putExtra("url", hostIP + "/?RESET=on"); - resetIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, awID); - PendingIntent resetPendingIntent = PendingIntent.getService(context, awID+2, resetIntent, PendingIntent.FLAG_UPDATE_CURRENT); - rv.setOnClickPendingIntent(R.id.widgetBtnReset, resetPendingIntent); - //power - Intent powerIntent = new Intent(context, SendRequestService.class); - powerIntent.putExtra("url", hostIP + "/?POWER0=on"); - powerIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, awID); - PendingIntent powerPendingIntent = PendingIntent.getService(context, awID+3, powerIntent, PendingIntent.FLAG_UPDATE_CURRENT); - rv.setOnClickPendingIntent(R.id.widgetBtnPwr, powerPendingIntent); - //power5 - Intent power5Intent = new Intent(context, SendRequestService.class); - power5Intent.putExtra("url", hostIP + "/?POWER1=on"); - power5Intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, awID); - PendingIntent power5PendingIntent = PendingIntent.getService(context, awID+4, power5Intent, PendingIntent.FLAG_UPDATE_CURRENT); - rv.setOnClickPendingIntent(R.id.widgetBtnPwr5, power5PendingIntent); - - if (bkgoundSwitch.isChecked()){ - rv.setInt(R.id.widgetBasicLayout, "setBackgroundColor", Color.argb(255-opacityBar.getProgress()*255/100, 0xff,0xff,0xff)); - settingsEditor.putInt("WidgetBgColor", Color.argb(255-opacityBar.getProgress()*255/100, 0xff,0xff,0xff)); - Log.d("qwerty1212", Integer.toString(Color.argb(255-opacityBar.getProgress()*255/100, 0xff,0xff,0xff))); - } - else{ - rv.setInt(R.id.widgetBasicLayout, "setBackgroundColor", Color.argb(255-opacityBar.getProgress()*255/100, 0x00,0x00,0x00)); - settingsEditor.putInt("WidgetBgColor", Color.argb(255-opacityBar.getProgress()*255/100, 0x00,0x00,0x00)); - Log.d("qwerty1212", Integer.toString(Color.argb(255-opacityBar.getProgress()*255/100, 0x00,0x00,0x00))); - } - settingsEditor.apply(); - - awm.updateAppWidget(awID,rv); - // Send intent to widget - Intent resultIntent = new Intent(); - resultIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, awID); - setResult(RESULT_OK, resultIntent); - - //send intent to service to request widget status - startService(refreshIntent); - - finish(); - } - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_widget_configurator); - - Button submitBtn = findViewById(R.id.configBtnSubmit); - opacityBar = findViewById(R.id.configSeekBar); - bkgoundSwitch = findViewById(R.id.configSwitch); - final TextView opacityLbl = findViewById(R.id.configOpacityLbl); - - // Prepare seekBar element - opacityLbl.setText(getString(R.string.confOpacity) + " " + opacityBar.getProgress()+"%"); - opacityBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { - @Override - public void onProgressChanged(SeekBar seekBar, int i, boolean b) { - opacityLbl.setText(getString(R.string.confOpacity) + " " + i + "%"); - } - - @Override - public void onStartTrackingTouch(SeekBar seekBar) {} - @Override - public void onStopTrackingTouch(SeekBar seekBar) {} - }); - bkgoundSwitch.setText(getString(R.string.confWhite)); - - // Cover widget intent - Intent initialConfIntent = getIntent(); - Bundle initialConfIntentBundle = initialConfIntent.getExtras(); - - // Set logic - if (initialConfIntentBundle != null){ - final int awID = initialConfIntentBundle.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); - - submitBtn.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - //Log.d("qwerty1212", Integer.toString(opacityBar.getProgress()*255/100)); - generateWidgetAndDie(awID, getApplicationContext()); - } - }); - - } else - finish(); - } -} diff --git a/app/src/main/java/com/blogspot/developersu/nowol/nowol/popUp.java b/app/src/main/java/com/blogspot/developersu/nowol/nowol/popUp.java deleted file mode 100644 index e732955..0000000 --- a/app/src/main/java/com/blogspot/developersu/nowol/nowol/popUp.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.blogspot.developersu.nowol.nowol; - -import android.app.Dialog; -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.view.Window; -import android.widget.Button; -import android.widget.EditText; -import androidx.fragment.app.DialogFragment; - -public class popUp extends DialogFragment { - - private EditText hostName; - private Button submit; - - public interface pupUpRetuningValueListener{ - void onFinishEdit(String hostNameReSet); - } - - public static popUp newInstance(CharSequence ipRecieved){ - popUp f = new popUp(); - Bundle myBundle = new Bundle(); - myBundle.putCharSequence("ipRec", ipRecieved); - f.setArguments(myBundle); - return f; - } - - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - //getDialog().setTitle(R.string.hostChBntMain); - - View v = inflater.inflate(R.layout.popup, container, false); - submit = (Button) v.findViewById(R.id.popupHostBtn); - hostName = (EditText) v.findViewById(R.id.popUpHostText); - - - hostName.setText(getArguments().getCharSequence("ipRec")); - - submit.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - pupUpRetuningValueListener retLs = (pupUpRetuningValueListener)getActivity(); - retLs.onFinishEdit(hostName.getText().toString()); - dismiss(); - } - }); - - return v; - } - public Dialog onCreateDialog(Bundle savedInstanceState) { - Dialog dialog = super.onCreateDialog(savedInstanceState); - dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); - return dialog; - } - - -} \ No newline at end of file diff --git a/app/src/main/java/com/blogspot/developersu/nowol/widget/NoWolWidget.java b/app/src/main/java/com/blogspot/developersu/nowol/widget/NoWolWidget.java new file mode 100644 index 0000000..26e71a7 --- /dev/null +++ b/app/src/main/java/com/blogspot/developersu/nowol/widget/NoWolWidget.java @@ -0,0 +1,101 @@ +/* + Copyright 2017-2020 Dmitry Isaenko + + This file is part of NoWOL. + + NoWOL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + NoWOL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with NoWOL. If not, see . +*/ +package com.blogspot.developersu.nowol.widget; + +import android.app.PendingIntent; +import android.appwidget.AppWidgetManager; +import android.appwidget.AppWidgetProvider; +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.util.Log; +import android.widget.RemoteViews; + +import com.blogspot.developersu.nowol.R; +import com.blogspot.developersu.nowol.SendRequestService; + + +public class NoWolWidget extends AppWidgetProvider { + + @Override + public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { + for (int appWidgetId : appWidgetIds) { + updateAppWidget(context, appWidgetManager, appWidgetId); + } + } + + @Override + public void onReceive(Context context, Intent intent) { + if (intent.hasExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS)){ + int[] widgetIDs = intent.getExtras().getIntArray(AppWidgetManager.EXTRA_APPWIDGET_IDS); + for (int widgetID : widgetIDs){ + updateAppWidget(context, AppWidgetManager.getInstance(context), widgetID); + } + } + else + super.onReceive(context, intent); + } + + @Override + public void onEnabled(Context context) { + super.onEnabled(context); + } + + @Override + public void onDeleted(Context context, int[] appWidgetIds) { + for (int appWidgetId : appWidgetIds) { + WidgetConfigurator.deleteBgColorPref(context, appWidgetId); + } + } + + static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, + int appWidgetId) { + int widgetBgColor = WidgetConfigurator.loadBgColorPref(context, appWidgetId); + RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.no_wol_widget); + + remoteViews.setInt(R.id.widgetBodyLayout, "setBackgroundColor", widgetBgColor); + // + SharedPreferences sharedSettings = context.getSharedPreferences("NoWolPreferences", Context.MODE_PRIVATE); + String hostIP = sharedSettings.getString("Host", context.getResources().getString(R.string.hostNameDefault)); + + remoteViews.setOnClickPendingIntent(R.id.widgetBntRefresh, + createPendingIntent(context, appWidgetId, hostIP, appWidgetId+1)); // Refresh + remoteViews.setOnClickPendingIntent(R.id.widgetBtnReset, + createPendingIntent(context, appWidgetId, hostIP + "/?RESET=on", appWidgetId+2)); + remoteViews.setOnClickPendingIntent(R.id.widgetBtnPwr, + createPendingIntent(context, appWidgetId, hostIP + "/?POWER0=on", appWidgetId+3)); + remoteViews.setOnClickPendingIntent(R.id.widgetBtnPwr5, + createPendingIntent(context, appWidgetId, hostIP + "/?POWER1=on", appWidgetId+4)); + + appWidgetManager.updateAppWidget(appWidgetId, remoteViews); + // Ping serv TODO: FIX + Intent refreshIntent = new Intent(context, SendRequestService.class); + refreshIntent.putExtra("url", hostIP); + refreshIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); + context.startService(refreshIntent); + // Instruct the widget manager to update the widget + appWidgetManager.updateAppWidget(appWidgetId, remoteViews); + } + private static PendingIntent createPendingIntent(Context context, int widgetId, String linkAddress, int code){ + Intent intent = new Intent(context, SendRequestService.class); + intent.putExtra("url", linkAddress); + intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId); + return PendingIntent.getService(context, code, intent, PendingIntent.FLAG_UPDATE_CURRENT); + } +} diff --git a/app/src/main/java/com/blogspot/developersu/nowol/widget/WidgetConfigurator.java b/app/src/main/java/com/blogspot/developersu/nowol/widget/WidgetConfigurator.java new file mode 100644 index 0000000..6f804d5 --- /dev/null +++ b/app/src/main/java/com/blogspot/developersu/nowol/widget/WidgetConfigurator.java @@ -0,0 +1,140 @@ +/* + Copyright 2017-2020 Dmitry Isaenko + + This file is part of NoWOL. + + NoWOL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + NoWOL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with NoWOL. If not, see . +*/ +package com.blogspot.developersu.nowol.widget; + +import android.app.PendingIntent; +import android.appwidget.AppWidgetManager; +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.graphics.Color; +import android.os.Bundle; +import android.util.Log; +import android.widget.Button; +import android.widget.RemoteViews; +import android.widget.SeekBar; +import android.widget.TextView; +import androidx.appcompat.app.AppCompatActivity; +import com.blogspot.developersu.nowol.R; +import com.blogspot.developersu.nowol.SendRequestService; +import com.google.android.material.switchmaterial.SwitchMaterial; + +public class WidgetConfigurator extends AppCompatActivity { + + private SeekBar opacityBar; + private SwitchMaterial bgColorSwitch; + private Context context; + + private int appWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + setResult(RESULT_CANCELED); + + setContentView(R.layout.activity_widget_configurator); + + Button submitBtn = findViewById(R.id.configBtnSubmit); + opacityBar = findViewById(R.id.configSeekBar); + bgColorSwitch = findViewById(R.id.configSwitch); + final TextView opacityLbl = findViewById(R.id.configOpacityLbl); + opacityLbl.setText(getString(R.string.confOpacity, 0)); + opacityBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { + @Override + public void onProgressChanged(SeekBar seekBar, int i, boolean b) { + opacityLbl.setText(getString(R.string.confOpacity, i)); + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) {} + @Override + public void onStopTrackingTouch(SeekBar seekBar) {} + }); + + this.context = getApplicationContext(); + + // Cover widget intent + Intent initialConfIntent = getIntent(); + Bundle initialConfBundle = initialConfIntent.getExtras(); + + if (initialConfBundle != null) { + appWidgetId = initialConfBundle.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, + AppWidgetManager.INVALID_APPWIDGET_ID); + } + if (appWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) { + finish(); + return; + } + + submitBtn.setOnClickListener(view -> createWidget()); + } + + private void createWidget(){ + RemoteViews remoteViews = new RemoteViews(this.getPackageName(), R.layout.no_wol_widget); + + SharedPreferences sharedSettings = context.getSharedPreferences("NoWolPreferences", Context.MODE_PRIVATE); + String hostIP = sharedSettings.getString("Host", context.getResources().getString(R.string.hostNameDefault)); + + SharedPreferences.Editor settingsEditor = sharedSettings.edit(); + + remoteViews.setOnClickPendingIntent(R.id.widgetBntRefresh, + createPendingIntent(hostIP, appWidgetId+1)); // Refresh + remoteViews.setOnClickPendingIntent(R.id.widgetBtnReset, + createPendingIntent(hostIP + "/?RESET=on", appWidgetId+2)); + remoteViews.setOnClickPendingIntent(R.id.widgetBtnPwr, + createPendingIntent(hostIP + "/?POWER0=on", appWidgetId+3)); + remoteViews.setOnClickPendingIntent(R.id.widgetBtnPwr5, + createPendingIntent(hostIP + "/?POWER1=on", appWidgetId+4)); + int bgColor = getBackgoundColor(); + remoteViews.setInt(R.id.widgetBodyLayout, "setBackgroundColor", bgColor); + settingsEditor.putInt("WidgetBgColor" + appWidgetId, bgColor).apply(); + + AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this); + appWidgetManager.updateAppWidget(appWidgetId, remoteViews); + // Send intent to widget + Intent resultIntent = new Intent(); + resultIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); + setResult(RESULT_OK, resultIntent); + finish(); + } + private PendingIntent createPendingIntent(String linkAddress, int code){ + Intent intent = new Intent(context, SendRequestService.class); + intent.putExtra("url", linkAddress); + intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); + return PendingIntent.getService(context, code, intent, PendingIntent.FLAG_UPDATE_CURRENT); + } + private int getBackgoundColor(){ + if (bgColorSwitch.isChecked()) + return Color.argb(255-opacityBar.getProgress()*255/100, 0xff,0xff,0xff); + else + return Color.argb(255-opacityBar.getProgress()*255/100, 0x00,0x00,0x00); + } + + static int loadBgColorPref(Context context, int appWidgetId) { + SharedPreferences prefs = context.getSharedPreferences("NoWolPreferences", Context.MODE_PRIVATE); + return prefs.getInt("WidgetBgColor" + appWidgetId, Color.argb(255, 0x00,0x00,0x00)); + } + + static void deleteBgColorPref(Context context, int appWidgetId) { + SharedPreferences.Editor prefs = context.getSharedPreferences("NoWolPreferences", Context.MODE_PRIVATE).edit(); + prefs.remove("WidgetBgColor" + appWidgetId); + prefs.apply(); + } +} diff --git a/app/src/main/pwr5_widget-web.png b/app/src/main/pwr5_widget-web.png deleted file mode 100644 index de513a7..0000000 Binary files a/app/src/main/pwr5_widget-web.png and /dev/null differ diff --git a/app/src/main/pwrWidget-web.png b/app/src/main/pwrWidget-web.png deleted file mode 100644 index 2db3a8b..0000000 Binary files a/app/src/main/pwrWidget-web.png and /dev/null differ diff --git a/app/src/main/refresh_widget-web.png b/app/src/main/refresh_widget-web.png deleted file mode 100644 index 846544d..0000000 Binary files a/app/src/main/refresh_widget-web.png and /dev/null differ diff --git a/app/src/main/res/drawable-anydpi-v21/ic_launcher.png b/app/src/main/res/drawable-anydpi-v21/ic_launcher.png new file mode 100644 index 0000000..a19aa44 Binary files /dev/null and b/app/src/main/res/drawable-anydpi-v21/ic_launcher.png differ diff --git a/app/src/main/res/drawable-anydpi-v21/w_power.xml b/app/src/main/res/drawable-anydpi-v21/w_power.xml new file mode 100644 index 0000000..f7878bd --- /dev/null +++ b/app/src/main/res/drawable-anydpi-v21/w_power.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable-anydpi-v21/w_power5.xml b/app/src/main/res/drawable-anydpi-v21/w_power5.xml new file mode 100644 index 0000000..22c0354 --- /dev/null +++ b/app/src/main/res/drawable-anydpi-v21/w_power5.xml @@ -0,0 +1,4 @@ + + + diff --git a/app/src/main/res/drawable-anydpi-v21/w_power5_press.xml b/app/src/main/res/drawable-anydpi-v21/w_power5_press.xml new file mode 100644 index 0000000..258f671 --- /dev/null +++ b/app/src/main/res/drawable-anydpi-v21/w_power5_press.xml @@ -0,0 +1,4 @@ + + + diff --git a/app/src/main/res/drawable-anydpi-v21/w_power_press.xml b/app/src/main/res/drawable-anydpi-v21/w_power_press.xml new file mode 100644 index 0000000..3d7911b --- /dev/null +++ b/app/src/main/res/drawable-anydpi-v21/w_power_press.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable-anydpi-v21/w_refresh.xml b/app/src/main/res/drawable-anydpi-v21/w_refresh.xml new file mode 100644 index 0000000..0a595e3 --- /dev/null +++ b/app/src/main/res/drawable-anydpi-v21/w_refresh.xml @@ -0,0 +1,5 @@ + + + + diff --git a/app/src/main/res/drawable-anydpi-v21/w_refresh_press.xml b/app/src/main/res/drawable-anydpi-v21/w_refresh_press.xml new file mode 100644 index 0000000..db1e5bf --- /dev/null +++ b/app/src/main/res/drawable-anydpi-v21/w_refresh_press.xml @@ -0,0 +1,5 @@ + + + + diff --git a/app/src/main/res/drawable-anydpi-v21/w_reset.xml b/app/src/main/res/drawable-anydpi-v21/w_reset.xml new file mode 100644 index 0000000..ba01c9b --- /dev/null +++ b/app/src/main/res/drawable-anydpi-v21/w_reset.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable-anydpi-v21/w_reset_press.xml b/app/src/main/res/drawable-anydpi-v21/w_reset_press.xml new file mode 100644 index 0000000..f8dee9a --- /dev/null +++ b/app/src/main/res/drawable-anydpi-v21/w_reset_press.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable-hdpi/.directory b/app/src/main/res/drawable-hdpi/.directory deleted file mode 100644 index 5d657c4..0000000 --- a/app/src/main/res/drawable-hdpi/.directory +++ /dev/null @@ -1,4 +0,0 @@ -[Dolphin] -PreviewsShown=true -Timestamp=2017,8,6,16,39,33 -Version=3 diff --git a/app/src/main/res/drawable-hdpi/pwr_widget_normal.png b/app/src/main/res/drawable-hdpi/w_power.png similarity index 100% rename from app/src/main/res/drawable-hdpi/pwr_widget_normal.png rename to app/src/main/res/drawable-hdpi/w_power.png diff --git a/app/src/main/res/drawable-hdpi/pwr5_widget_normal.png b/app/src/main/res/drawable-hdpi/w_power5.png similarity index 100% rename from app/src/main/res/drawable-hdpi/pwr5_widget_normal.png rename to app/src/main/res/drawable-hdpi/w_power5.png diff --git a/app/src/main/res/drawable-hdpi/pwr5_widget_pressed.png b/app/src/main/res/drawable-hdpi/w_power5_press.png similarity index 100% rename from app/src/main/res/drawable-hdpi/pwr5_widget_pressed.png rename to app/src/main/res/drawable-hdpi/w_power5_press.png diff --git a/app/src/main/res/drawable-hdpi/pwr_widget_pressed.png b/app/src/main/res/drawable-hdpi/w_power_press.png similarity index 100% rename from app/src/main/res/drawable-hdpi/pwr_widget_pressed.png rename to app/src/main/res/drawable-hdpi/w_power_press.png diff --git a/app/src/main/res/drawable-hdpi/refresh_widget.png b/app/src/main/res/drawable-hdpi/w_refresh.png similarity index 100% rename from app/src/main/res/drawable-hdpi/refresh_widget.png rename to app/src/main/res/drawable-hdpi/w_refresh.png diff --git a/app/src/main/res/drawable-hdpi/refresh_widget_pressed.png b/app/src/main/res/drawable-hdpi/w_refresh_press.png similarity index 100% rename from app/src/main/res/drawable-hdpi/refresh_widget_pressed.png rename to app/src/main/res/drawable-hdpi/w_refresh_press.png diff --git a/app/src/main/res/drawable-hdpi/rst_widget_normal.png b/app/src/main/res/drawable-hdpi/w_reset.png similarity index 100% rename from app/src/main/res/drawable-hdpi/rst_widget_normal.png rename to app/src/main/res/drawable-hdpi/w_reset.png diff --git a/app/src/main/res/drawable-hdpi/rst_widget_pressed.png b/app/src/main/res/drawable-hdpi/w_reset_press.png similarity index 100% rename from app/src/main/res/drawable-hdpi/rst_widget_pressed.png rename to app/src/main/res/drawable-hdpi/w_reset_press.png diff --git a/app/src/main/res/drawable-mdpi/.directory b/app/src/main/res/drawable-mdpi/.directory deleted file mode 100644 index 958cefe..0000000 --- a/app/src/main/res/drawable-mdpi/.directory +++ /dev/null @@ -1,4 +0,0 @@ -[Dolphin] -PreviewsShown=true -Timestamp=2017,8,6,16,39,9 -Version=3 diff --git a/app/src/main/res/drawable-mdpi/pwr_widget_normal.png b/app/src/main/res/drawable-mdpi/w_power.png similarity index 100% rename from app/src/main/res/drawable-mdpi/pwr_widget_normal.png rename to app/src/main/res/drawable-mdpi/w_power.png diff --git a/app/src/main/res/drawable-mdpi/pwr5_widget_normal.png b/app/src/main/res/drawable-mdpi/w_power5.png similarity index 100% rename from app/src/main/res/drawable-mdpi/pwr5_widget_normal.png rename to app/src/main/res/drawable-mdpi/w_power5.png diff --git a/app/src/main/res/drawable-mdpi/pwr5_widget_pressed.png b/app/src/main/res/drawable-mdpi/w_power5_press.png similarity index 100% rename from app/src/main/res/drawable-mdpi/pwr5_widget_pressed.png rename to app/src/main/res/drawable-mdpi/w_power5_press.png diff --git a/app/src/main/res/drawable-mdpi/pwr_widget_pressed.png b/app/src/main/res/drawable-mdpi/w_power_press.png similarity index 100% rename from app/src/main/res/drawable-mdpi/pwr_widget_pressed.png rename to app/src/main/res/drawable-mdpi/w_power_press.png diff --git a/app/src/main/res/drawable-mdpi/refresh_widget.png b/app/src/main/res/drawable-mdpi/w_refresh.png similarity index 100% rename from app/src/main/res/drawable-mdpi/refresh_widget.png rename to app/src/main/res/drawable-mdpi/w_refresh.png diff --git a/app/src/main/res/drawable-mdpi/refresh_widget_pressed.png b/app/src/main/res/drawable-mdpi/w_refresh_press.png similarity index 100% rename from app/src/main/res/drawable-mdpi/refresh_widget_pressed.png rename to app/src/main/res/drawable-mdpi/w_refresh_press.png diff --git a/app/src/main/res/drawable-mdpi/rst_widget_normal.png b/app/src/main/res/drawable-mdpi/w_reset.png similarity index 100% rename from app/src/main/res/drawable-mdpi/rst_widget_normal.png rename to app/src/main/res/drawable-mdpi/w_reset.png diff --git a/app/src/main/res/drawable-mdpi/rst_widget_pressed.png b/app/src/main/res/drawable-mdpi/w_reset_press.png similarity index 100% rename from app/src/main/res/drawable-mdpi/rst_widget_pressed.png rename to app/src/main/res/drawable-mdpi/w_reset_press.png diff --git a/app/src/main/res/drawable-nodpi/widget_preview.png b/app/src/main/res/drawable-nodpi/widget_preview.png index df38e29..f8c6e99 100644 Binary files a/app/src/main/res/drawable-nodpi/widget_preview.png and b/app/src/main/res/drawable-nodpi/widget_preview.png differ diff --git a/app/src/main/res/drawable-xhdpi/.directory b/app/src/main/res/drawable-xhdpi/.directory deleted file mode 100644 index b28a696..0000000 --- a/app/src/main/res/drawable-xhdpi/.directory +++ /dev/null @@ -1,4 +0,0 @@ -[Dolphin] -PreviewsShown=true -Timestamp=2017,8,6,16,37,31 -Version=3 diff --git a/app/src/main/res/drawable-xhdpi/pwr_widget_normal.png b/app/src/main/res/drawable-xhdpi/w_power.png similarity index 100% rename from app/src/main/res/drawable-xhdpi/pwr_widget_normal.png rename to app/src/main/res/drawable-xhdpi/w_power.png diff --git a/app/src/main/res/drawable-xhdpi/pwr5_widget_normal.png b/app/src/main/res/drawable-xhdpi/w_power5.png similarity index 100% rename from app/src/main/res/drawable-xhdpi/pwr5_widget_normal.png rename to app/src/main/res/drawable-xhdpi/w_power5.png diff --git a/app/src/main/res/drawable-xhdpi/pwr5_widget_pressed.png b/app/src/main/res/drawable-xhdpi/w_power5_press.png similarity index 100% rename from app/src/main/res/drawable-xhdpi/pwr5_widget_pressed.png rename to app/src/main/res/drawable-xhdpi/w_power5_press.png diff --git a/app/src/main/res/drawable-xhdpi/pwr_widget_pressed.png b/app/src/main/res/drawable-xhdpi/w_power_press.png similarity index 100% rename from app/src/main/res/drawable-xhdpi/pwr_widget_pressed.png rename to app/src/main/res/drawable-xhdpi/w_power_press.png diff --git a/app/src/main/res/drawable-xhdpi/refresh_widget.png b/app/src/main/res/drawable-xhdpi/w_refresh.png similarity index 100% rename from app/src/main/res/drawable-xhdpi/refresh_widget.png rename to app/src/main/res/drawable-xhdpi/w_refresh.png diff --git a/app/src/main/res/drawable-xhdpi/refresh_widget_pressed.png b/app/src/main/res/drawable-xhdpi/w_refresh_press.png similarity index 100% rename from app/src/main/res/drawable-xhdpi/refresh_widget_pressed.png rename to app/src/main/res/drawable-xhdpi/w_refresh_press.png diff --git a/app/src/main/res/drawable-xhdpi/rst_widget_normal.png b/app/src/main/res/drawable-xhdpi/w_reset.png similarity index 100% rename from app/src/main/res/drawable-xhdpi/rst_widget_normal.png rename to app/src/main/res/drawable-xhdpi/w_reset.png diff --git a/app/src/main/res/drawable-xhdpi/rst_widget_pressed.png b/app/src/main/res/drawable-xhdpi/w_reset_press.png similarity index 100% rename from app/src/main/res/drawable-xhdpi/rst_widget_pressed.png rename to app/src/main/res/drawable-xhdpi/w_reset_press.png diff --git a/app/src/main/res/drawable-xxhdpi/.directory b/app/src/main/res/drawable-xxhdpi/.directory deleted file mode 100644 index e4c7ab7..0000000 --- a/app/src/main/res/drawable-xxhdpi/.directory +++ /dev/null @@ -1,4 +0,0 @@ -[Dolphin] -PreviewsShown=true -Timestamp=2017,8,6,16,36,41 -Version=3 diff --git a/app/src/main/res/drawable-xxhdpi/pwr_widget_normal.png b/app/src/main/res/drawable-xxhdpi/w_power.png similarity index 100% rename from app/src/main/res/drawable-xxhdpi/pwr_widget_normal.png rename to app/src/main/res/drawable-xxhdpi/w_power.png diff --git a/app/src/main/res/drawable-xxhdpi/pwr5_widget_normal.png b/app/src/main/res/drawable-xxhdpi/w_power5.png similarity index 100% rename from app/src/main/res/drawable-xxhdpi/pwr5_widget_normal.png rename to app/src/main/res/drawable-xxhdpi/w_power5.png diff --git a/app/src/main/res/drawable-xxhdpi/pwr5_widget_pressed.png b/app/src/main/res/drawable-xxhdpi/w_power5_press.png similarity index 100% rename from app/src/main/res/drawable-xxhdpi/pwr5_widget_pressed.png rename to app/src/main/res/drawable-xxhdpi/w_power5_press.png diff --git a/app/src/main/res/drawable-xxhdpi/pwr_widget_pressed.png b/app/src/main/res/drawable-xxhdpi/w_power_press.png similarity index 100% rename from app/src/main/res/drawable-xxhdpi/pwr_widget_pressed.png rename to app/src/main/res/drawable-xxhdpi/w_power_press.png diff --git a/app/src/main/res/drawable-xxhdpi/refresh_widget.png b/app/src/main/res/drawable-xxhdpi/w_refresh.png similarity index 100% rename from app/src/main/res/drawable-xxhdpi/refresh_widget.png rename to app/src/main/res/drawable-xxhdpi/w_refresh.png diff --git a/app/src/main/res/drawable-xxhdpi/refresh_widget_pressed.png b/app/src/main/res/drawable-xxhdpi/w_refresh_press.png similarity index 100% rename from app/src/main/res/drawable-xxhdpi/refresh_widget_pressed.png rename to app/src/main/res/drawable-xxhdpi/w_refresh_press.png diff --git a/app/src/main/res/drawable-xxhdpi/rst_widget_normal.png b/app/src/main/res/drawable-xxhdpi/w_reset.png similarity index 100% rename from app/src/main/res/drawable-xxhdpi/rst_widget_normal.png rename to app/src/main/res/drawable-xxhdpi/w_reset.png diff --git a/app/src/main/res/drawable-xxhdpi/rst_widget_pressed.png b/app/src/main/res/drawable-xxhdpi/w_reset_press.png similarity index 100% rename from app/src/main/res/drawable-xxhdpi/rst_widget_pressed.png rename to app/src/main/res/drawable-xxhdpi/w_reset_press.png diff --git a/app/src/main/res/drawable-xxxhdpi/.directory b/app/src/main/res/drawable-xxxhdpi/.directory deleted file mode 100644 index 030c5f6..0000000 --- a/app/src/main/res/drawable-xxxhdpi/.directory +++ /dev/null @@ -1,4 +0,0 @@ -[Dolphin] -PreviewsShown=true -Timestamp=2017,8,6,15,33,9 -Version=3 diff --git a/app/src/main/res/drawable-xxxhdpi/pwr_widget_normal.png b/app/src/main/res/drawable-xxxhdpi/w_power.png similarity index 100% rename from app/src/main/res/drawable-xxxhdpi/pwr_widget_normal.png rename to app/src/main/res/drawable-xxxhdpi/w_power.png diff --git a/app/src/main/res/drawable-xxxhdpi/pwr5_widget_normal.png b/app/src/main/res/drawable-xxxhdpi/w_power5.png similarity index 100% rename from app/src/main/res/drawable-xxxhdpi/pwr5_widget_normal.png rename to app/src/main/res/drawable-xxxhdpi/w_power5.png diff --git a/app/src/main/res/drawable-xxxhdpi/pwr5_widget_pressed.png b/app/src/main/res/drawable-xxxhdpi/w_power5_press.png similarity index 100% rename from app/src/main/res/drawable-xxxhdpi/pwr5_widget_pressed.png rename to app/src/main/res/drawable-xxxhdpi/w_power5_press.png diff --git a/app/src/main/res/drawable-xxxhdpi/pwr_widget_pressed.png b/app/src/main/res/drawable-xxxhdpi/w_power_press.png similarity index 100% rename from app/src/main/res/drawable-xxxhdpi/pwr_widget_pressed.png rename to app/src/main/res/drawable-xxxhdpi/w_power_press.png diff --git a/app/src/main/res/drawable-xxxhdpi/refresh_widget.png b/app/src/main/res/drawable-xxxhdpi/w_refresh.png similarity index 100% rename from app/src/main/res/drawable-xxxhdpi/refresh_widget.png rename to app/src/main/res/drawable-xxxhdpi/w_refresh.png diff --git a/app/src/main/res/drawable-xxxhdpi/refresh_widget_pressed.png b/app/src/main/res/drawable-xxxhdpi/w_refresh_press.png similarity index 100% rename from app/src/main/res/drawable-xxxhdpi/refresh_widget_pressed.png rename to app/src/main/res/drawable-xxxhdpi/w_refresh_press.png diff --git a/app/src/main/res/drawable-xxxhdpi/rst_widget_normal.png b/app/src/main/res/drawable-xxxhdpi/w_reset.png similarity index 100% rename from app/src/main/res/drawable-xxxhdpi/rst_widget_normal.png rename to app/src/main/res/drawable-xxxhdpi/w_reset.png diff --git a/app/src/main/res/drawable-xxxhdpi/rst_widget_pressed.png b/app/src/main/res/drawable-xxxhdpi/w_reset_press.png similarity index 100% rename from app/src/main/res/drawable-xxxhdpi/rst_widget_pressed.png rename to app/src/main/res/drawable-xxxhdpi/w_reset_press.png diff --git a/app/src/main/res/drawable/pwr5_widget_button.xml b/app/src/main/res/drawable/pwr5_widget_button.xml index 307328b..93b7553 100644 --- a/app/src/main/res/drawable/pwr5_widget_button.xml +++ b/app/src/main/res/drawable/pwr5_widget_button.xml @@ -1,7 +1,7 @@ - + android:drawable="@drawable/w_power5_press"/> + \ No newline at end of file diff --git a/app/src/main/res/drawable/pwr_widget_button.xml b/app/src/main/res/drawable/pwr_widget_button.xml index 8f3781d..70d0ae7 100644 --- a/app/src/main/res/drawable/pwr_widget_button.xml +++ b/app/src/main/res/drawable/pwr_widget_button.xml @@ -1,7 +1,7 @@ - + android:drawable="@drawable/w_power_press"/> + \ No newline at end of file diff --git a/app/src/main/res/drawable/refresh_widget_button.xml b/app/src/main/res/drawable/refresh_widget_button.xml index 73b5861..21f3911 100644 --- a/app/src/main/res/drawable/refresh_widget_button.xml +++ b/app/src/main/res/drawable/refresh_widget_button.xml @@ -1,8 +1,6 @@ - - - - - + + \ No newline at end of file diff --git a/app/src/main/res/drawable/reset_widget_button.xml b/app/src/main/res/drawable/reset_widget_button.xml index e21bb01..f036942 100644 --- a/app/src/main/res/drawable/reset_widget_button.xml +++ b/app/src/main/res/drawable/reset_widget_button.xml @@ -1,7 +1,7 @@ - + android:drawable="@drawable/w_reset_press"/> + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 4f43633..88aafab 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -10,6 +10,7 @@ > @@ -18,18 +19,18 @@ android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" - app:elevation="4dp" android:minHeight="?attr/actionBarSize" android:theme="?attr/actionBarTheme" + app:elevation="4dp" app:titleTextColor="@android:color/background_light" /> + tools:layout_editor_absoluteY="98dp" />