And now even widget works.
This commit is contained in:
parent
7ec331baf6
commit
f867ddd699
6 changed files with 59 additions and 62 deletions
|
@ -7,8 +7,8 @@ android {
|
||||||
applicationId "com.blogspot.developersu.nowol.nowol"
|
applicationId "com.blogspot.developersu.nowol.nowol"
|
||||||
minSdkVersion 14
|
minSdkVersion 14
|
||||||
targetSdkVersion 29
|
targetSdkVersion 29
|
||||||
versionCode 3
|
versionCode 4
|
||||||
versionName "3.0"
|
versionName "4.0"
|
||||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||||
vectorDrawables.useSupportLibrary = true
|
vectorDrawables.useSupportLibrary = true
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,9 +26,6 @@
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity android:name=".popUp"
|
|
||||||
android:theme="@android:style/Theme.Dialog" />
|
|
||||||
<!---->
|
<!---->
|
||||||
<receiver android:name=".com.blogspot.developersu.nowol.nowol.widget.NoWolWidget">
|
<receiver android:name=".com.blogspot.developersu.nowol.nowol.widget.NoWolWidget">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
|
|
|
@ -29,64 +29,64 @@ public class SendRequestService extends IntentService {
|
||||||
|
|
||||||
private void sendData(int state, int awID){
|
private void sendData(int state, int awID){
|
||||||
// MainActivity requested
|
// MainActivity requested
|
||||||
if (awID != 0) {
|
if (awID == 0) {
|
||||||
RemoteViews rv = new RemoteViews(getPackageName(), R.layout.no_wol_widget);
|
// Log.d("qwerty1212", "MainActivity case. Status = " + Integer.toString(state) + " awID = " + Integer.toString(awID));
|
||||||
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);
|
resReceiver.send(state, null);
|
||||||
|
}
|
||||||
|
|
||||||
switch (state){
|
RemoteViews rv = new RemoteViews(getPackageName(), R.layout.no_wol_widget);
|
||||||
case 1:
|
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);
|
||||||
rv.setTextViewText(R.id.widgetStatusText, getResources().getString(R.string.statusOnline));
|
|
||||||
rv.setInt(R.id.widgetHeaderLayout, "setBackgroundColor", ContextCompat.getColor(this, R.color.colorPrimary));
|
switch (state){
|
||||||
// Log.d("qwerty1212", "case 1 widget");
|
case STATE_ON:
|
||||||
break;
|
rv.setTextViewText(R.id.widgetStatusText, getResources().getString(R.string.statusOnline));
|
||||||
case 0:
|
rv.setInt(R.id.widgetHeaderLayout, "setBackgroundColor", ContextCompat.getColor(this, R.color.colorPrimary));
|
||||||
rv.setTextViewText(R.id.widgetStatusText, getResources().getString(R.string.statusOffline));
|
// Log.d("qwerty1212", "case 1 widget");
|
||||||
rv.setInt(R.id.widgetHeaderLayout, "setBackgroundColor", ContextCompat.getColor(this, R.color.colorRed));
|
break;
|
||||||
// Log.d("qwerty1212", "case 0 widget");
|
case STATE_OFF:
|
||||||
break;
|
rv.setTextViewText(R.id.widgetStatusText, getResources().getString(R.string.statusOffline));
|
||||||
case -1:
|
rv.setInt(R.id.widgetHeaderLayout, "setBackgroundColor", ContextCompat.getColor(this, R.color.colorRed));
|
||||||
rv.setTextViewText(R.id.widgetStatusText, getResources().getString(R.string.noResponse));
|
// Log.d("qwerty1212", "case 0 widget");
|
||||||
rv.setInt(R.id.widgetHeaderLayout, "setBackgroundColor", ContextCompat.getColor(this, R.color.colorOrange));
|
break;
|
||||||
// Log.d("qwerty1212", "case -1 widget");
|
case STATE_UNKNOWN:
|
||||||
break;
|
rv.setTextViewText(R.id.widgetStatusText, getResources().getString(R.string.noResponse));
|
||||||
}
|
rv.setInt(R.id.widgetHeaderLayout, "setBackgroundColor", ContextCompat.getColor(this, R.color.colorOrange));
|
||||||
appWidgetManager.updateAppWidget(awID, rv);
|
// Log.d("qwerty1212", "case -1 widget");
|
||||||
}
|
break;
|
||||||
else{
|
|
||||||
// Log.d("qwerty1212", "MainActivity case. Status = " + Integer.toString(state) + " awID = " + Integer.toString(awID));
|
|
||||||
resReceiver.send(state, null);
|
|
||||||
}
|
}
|
||||||
|
appWidgetManager.updateAppWidget(awID, rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onHandleIntent(Intent intent) {
|
protected void onHandleIntent(Intent intent) {
|
||||||
if (intent != null) {
|
if (intent == null)
|
||||||
// Log.d("service", "Got intent");
|
return;
|
||||||
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);
|
// 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);
|
||||||
|
|
||||||
RequestQueue queueStd = Volley.newRequestQueue(this);
|
// Log.d("qwerty1212", "got from " + Integer.toString(awID) +" "+ url);
|
||||||
StringRequest strRequest = new StringRequest(Request.Method.GET, url, //will be 4 requests
|
|
||||||
new Response.Listener<String>() {
|
RequestQueue queueStd = Volley.newRequestQueue(this);
|
||||||
@Override
|
StringRequest strRequest = new StringRequest(Request.Method.GET, url, //will be 4 requests
|
||||||
public void onResponse(String response) {
|
new Response.Listener<String>() {
|
||||||
if (response.contains("00c600")){
|
@Override
|
||||||
sendData(STATE_ON, awID);
|
public void onResponse(String response) {
|
||||||
} else {
|
if (response.contains("00c600")){
|
||||||
sendData(STATE_OFF, awID);
|
sendData(STATE_ON, awID);
|
||||||
}
|
} else {
|
||||||
|
sendData(STATE_OFF, awID);
|
||||||
}
|
}
|
||||||
}, new Response.ErrorListener() {
|
}
|
||||||
@Override
|
}, new Response.ErrorListener() {
|
||||||
public void onErrorResponse(VolleyError error) {
|
@Override
|
||||||
sendData(STATE_UNKNOWN, awID);
|
public void onErrorResponse(VolleyError error) {
|
||||||
}
|
sendData(STATE_UNKNOWN, awID);
|
||||||
});
|
}
|
||||||
queueStd.add(strRequest);
|
});
|
||||||
}
|
queueStd.add(strRequest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,16 +12,16 @@ import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.RemoteViews;
|
import android.widget.RemoteViews;
|
||||||
import android.widget.SeekBar;
|
import android.widget.SeekBar;
|
||||||
import android.widget.Switch;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import com.blogspot.developersu.nowol.nowol.R;
|
import com.blogspot.developersu.nowol.nowol.R;
|
||||||
import com.blogspot.developersu.nowol.nowol.SendRequestService;
|
import com.blogspot.developersu.nowol.nowol.SendRequestService;
|
||||||
|
import com.google.android.material.switchmaterial.SwitchMaterial;
|
||||||
|
|
||||||
public class WidgetConfigurator extends AppCompatActivity {
|
public class WidgetConfigurator extends AppCompatActivity {
|
||||||
|
|
||||||
private SeekBar opacityBar;
|
private SeekBar opacityBar;
|
||||||
private Switch bkgoundSwitch;
|
private SwitchMaterial bkgoundSwitch;
|
||||||
|
|
||||||
private void generateWidgetAndDie(int awID, Context context){
|
private void generateWidgetAndDie(int awID, Context context){
|
||||||
SharedPreferences.Editor settingsEditor;
|
SharedPreferences.Editor settingsEditor;
|
||||||
|
@ -70,7 +70,7 @@ public class WidgetConfigurator extends AppCompatActivity {
|
||||||
settingsEditor.putInt("WidgetBgColor", 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)));
|
Log.d("qwerty1212", Integer.toString(Color.argb(255-opacityBar.getProgress()*255/100, 0x00,0x00,0x00)));
|
||||||
}
|
}
|
||||||
settingsEditor.commit();
|
settingsEditor.apply();
|
||||||
|
|
||||||
awm.updateAppWidget(awID,rv);
|
awm.updateAppWidget(awID,rv);
|
||||||
// Send intent to widget
|
// Send intent to widget
|
||||||
|
@ -95,11 +95,11 @@ public class WidgetConfigurator extends AppCompatActivity {
|
||||||
final TextView opacityLbl = findViewById(R.id.configOpacityLbl);
|
final TextView opacityLbl = findViewById(R.id.configOpacityLbl);
|
||||||
|
|
||||||
// Prepare seekBar element
|
// Prepare seekBar element
|
||||||
opacityLbl.setText(getString(R.string.confOpacity) + " " + Integer.toString(opacityBar.getProgress())+"%");
|
opacityLbl.setText(getString(R.string.confOpacity) + " " + opacityBar.getProgress()+"%");
|
||||||
opacityBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
opacityBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
|
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
|
||||||
opacityLbl.setText(getString(R.string.confOpacity) + " " + Integer.toString(i) + "%");
|
opacityLbl.setText(getString(R.string.confOpacity) + " " + i + "%");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
android:layout_height="25dp"
|
android:layout_height="25dp"
|
||||||
android:layout_weight="1" />
|
android:layout_weight="1" />
|
||||||
|
|
||||||
<Switch
|
<com.google.android.material.switchmaterial.SwitchMaterial
|
||||||
android:id="@+id/configSwitch"
|
android:id="@+id/configSwitch"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:previewImage="@drawable/widget_preview"
|
android:previewImage="@drawable/widget_preview"
|
||||||
android:minHeight="40dp"
|
android:minHeight="40dp"
|
||||||
android:minWidth="110dp"
|
android:minWidth="80dp"
|
||||||
android:updatePeriodMillis="6400000"
|
android:updatePeriodMillis="6400000"
|
||||||
android:resizeMode="none"
|
android:resizeMode="none"
|
||||||
android:configure="com.blogspot.developersu.nowol.nowol.com.blogspot.developersu.nowol.nowol.widget.WidgetConfigurator"
|
android:configure="com.blogspot.developersu.nowol.nowol.com.blogspot.developersu.nowol.nowol.widget.WidgetConfigurator"
|
||||||
|
|
Loading…
Reference in a new issue