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,22 +29,26 @@ 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) {
|
||||||
|
// 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);
|
RemoteViews rv = new RemoteViews(getPackageName(), R.layout.no_wol_widget);
|
||||||
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);
|
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);
|
||||||
|
|
||||||
switch (state){
|
switch (state){
|
||||||
case 1:
|
case STATE_ON:
|
||||||
rv.setTextViewText(R.id.widgetStatusText, getResources().getString(R.string.statusOnline));
|
rv.setTextViewText(R.id.widgetStatusText, getResources().getString(R.string.statusOnline));
|
||||||
rv.setInt(R.id.widgetHeaderLayout, "setBackgroundColor", ContextCompat.getColor(this, R.color.colorPrimary));
|
rv.setInt(R.id.widgetHeaderLayout, "setBackgroundColor", ContextCompat.getColor(this, R.color.colorPrimary));
|
||||||
// Log.d("qwerty1212", "case 1 widget");
|
// Log.d("qwerty1212", "case 1 widget");
|
||||||
break;
|
break;
|
||||||
case 0:
|
case STATE_OFF:
|
||||||
rv.setTextViewText(R.id.widgetStatusText, getResources().getString(R.string.statusOffline));
|
rv.setTextViewText(R.id.widgetStatusText, getResources().getString(R.string.statusOffline));
|
||||||
rv.setInt(R.id.widgetHeaderLayout, "setBackgroundColor", ContextCompat.getColor(this, R.color.colorRed));
|
rv.setInt(R.id.widgetHeaderLayout, "setBackgroundColor", ContextCompat.getColor(this, R.color.colorRed));
|
||||||
// Log.d("qwerty1212", "case 0 widget");
|
// Log.d("qwerty1212", "case 0 widget");
|
||||||
break;
|
break;
|
||||||
case -1:
|
case STATE_UNKNOWN:
|
||||||
rv.setTextViewText(R.id.widgetStatusText, getResources().getString(R.string.noResponse));
|
rv.setTextViewText(R.id.widgetStatusText, getResources().getString(R.string.noResponse));
|
||||||
rv.setInt(R.id.widgetHeaderLayout, "setBackgroundColor", ContextCompat.getColor(this, R.color.colorOrange));
|
rv.setInt(R.id.widgetHeaderLayout, "setBackgroundColor", ContextCompat.getColor(this, R.color.colorOrange));
|
||||||
// Log.d("qwerty1212", "case -1 widget");
|
// Log.d("qwerty1212", "case -1 widget");
|
||||||
|
@ -52,15 +56,12 @@ public class SendRequestService extends IntentService {
|
||||||
}
|
}
|
||||||
appWidgetManager.updateAppWidget(awID, rv);
|
appWidgetManager.updateAppWidget(awID, rv);
|
||||||
}
|
}
|
||||||
else{
|
|
||||||
// Log.d("qwerty1212", "MainActivity case. Status = " + Integer.toString(state) + " awID = " + Integer.toString(awID));
|
|
||||||
resReceiver.send(state, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onHandleIntent(Intent intent) {
|
protected void onHandleIntent(Intent intent) {
|
||||||
if (intent != null) {
|
if (intent == null)
|
||||||
|
return;
|
||||||
|
|
||||||
// Log.d("service", "Got intent");
|
// Log.d("service", "Got intent");
|
||||||
Bundle bndle = intent.getExtras();
|
Bundle bndle = intent.getExtras();
|
||||||
String url = bndle.getString("url");
|
String url = bndle.getString("url");
|
||||||
|
@ -88,5 +89,4 @@ public class SendRequestService extends IntentService {
|
||||||
});
|
});
|
||||||
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