And now even widget works.

This commit is contained in:
Dmitry Isaenko 2020-09-27 21:29:51 +03:00
parent 7ec331baf6
commit f867ddd699
6 changed files with 59 additions and 62 deletions

View file

@ -7,8 +7,8 @@ android {
applicationId "com.blogspot.developersu.nowol.nowol"
minSdkVersion 14
targetSdkVersion 29
versionCode 3
versionName "3.0"
versionCode 4
versionName "4.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}

View file

@ -26,9 +26,6 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".popUp"
android:theme="@android:style/Theme.Dialog" />
<!---->
<receiver android:name=".com.blogspot.developersu.nowol.nowol.widget.NoWolWidget">
<intent-filter>

View file

@ -29,22 +29,26 @@ public class SendRequestService extends IntentService {
private void sendData(int state, int awID){
// 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);
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);
switch (state){
case 1:
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 0:
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 -1:
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");
@ -52,15 +56,12 @@ public class SendRequestService extends IntentService {
}
appWidgetManager.updateAppWidget(awID, rv);
}
else{
// Log.d("qwerty1212", "MainActivity case. Status = " + Integer.toString(state) + " awID = " + Integer.toString(awID));
resReceiver.send(state, null);
}
}
@Override
protected void onHandleIntent(Intent intent) {
if (intent != null) {
if (intent == null)
return;
// Log.d("service", "Got intent");
Bundle bndle = intent.getExtras();
String url = bndle.getString("url");
@ -88,5 +89,4 @@ public class SendRequestService extends IntentService {
});
queueStd.add(strRequest);
}
}
}

View file

@ -12,16 +12,16 @@ import android.view.View;
import android.widget.Button;
import android.widget.RemoteViews;
import android.widget.SeekBar;
import android.widget.Switch;
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 Switch bkgoundSwitch;
private SwitchMaterial bkgoundSwitch;
private void generateWidgetAndDie(int awID, Context context){
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));
Log.d("qwerty1212", Integer.toString(Color.argb(255-opacityBar.getProgress()*255/100, 0x00,0x00,0x00)));
}
settingsEditor.commit();
settingsEditor.apply();
awm.updateAppWidget(awID,rv);
// Send intent to widget
@ -95,11 +95,11 @@ public class WidgetConfigurator extends AppCompatActivity {
final TextView opacityLbl = findViewById(R.id.configOpacityLbl);
// 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() {
@Override
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

View file

@ -32,7 +32,7 @@
android:layout_height="25dp"
android:layout_weight="1" />
<Switch
<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/configSwitch"
android:layout_width="match_parent"
android:layout_height="wrap_content"

View file

@ -3,7 +3,7 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:previewImage="@drawable/widget_preview"
android:minHeight="40dp"
android:minWidth="110dp"
android:minWidth="80dp"
android:updatePeriodMillis="6400000"
android:resizeMode="none"
android:configure="com.blogspot.developersu.nowol.nowol.com.blogspot.developersu.nowol.nowol.widget.WidgetConfigurator"