Debug: add settings tiles

pull/209/head
M66B 2 years ago
parent 6295f1cbaa
commit 1c58eef4b6

@ -23,16 +23,20 @@ import static android.app.Activity.RESULT_OK;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.StatusBarManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.graphics.Paint;
import android.graphics.drawable.Icon;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.service.quicksettings.TileService;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
@ -56,6 +60,8 @@ import androidx.lifecycle.Lifecycle;
import androidx.preference.PreferenceManager;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.function.Consumer;
public class FragmentOptionsNotifications extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener {
private ImageButton ibHelp;
@ -109,12 +115,18 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
private SwitchCompat swBiometricsNotify;
private SwitchCompat swBackground;
private SwitchCompat swAlertOnce;
private ImageButton ibTileSync;
private ImageButton ibTileUnseen;
private TextView tvNoGrouping;
private TextView tvNoChannels;
private Group grpChannel;
private Group grpProperties;
private Group grpBackground;
private Group grpTiles;
private static final ExecutorService executor =
Helper.getBackgroundExecutor(1, "notifications");
private final static String[] RESET_OPTIONS = new String[]{
"notify_newest_first", "notify_summary",
@ -192,12 +204,15 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
swBiometricsNotify = view.findViewById(R.id.swBiometricsNotify);
swBackground = view.findViewById(R.id.swBackground);
swAlertOnce = view.findViewById(R.id.swAlertOnce);
ibTileSync = view.findViewById(R.id.ibTileSync);
ibTileUnseen = view.findViewById(R.id.ibTileUnseen);
tvNoGrouping = view.findViewById(R.id.tvNoGrouping);
tvNoChannels = view.findViewById(R.id.tvNoChannels);
grpChannel = view.findViewById(R.id.grpChannel);
grpProperties = view.findViewById(R.id.grpProperties);
grpBackground = view.findViewById(R.id.grpBackground);
grpTiles = view.findViewById(R.id.grpTiles);
setOptions();
@ -598,6 +613,22 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
}
});
ibTileSync.setOnClickListener(new View.OnClickListener() {
@Override
@RequiresApi(api = Build.VERSION_CODES.TIRAMISU)
public void onClick(View v) {
addTile(v.getContext(), ServiceTileSynchronize.class, R.string.tile_synchronize, R.drawable.twotone_sync_24);
}
});
ibTileUnseen.setOnClickListener(new View.OnClickListener() {
@Override
@RequiresApi(api = Build.VERSION_CODES.TIRAMISU)
public void onClick(View v) {
addTile(v.getContext(), ServiceTileUnseen.class, R.string.tile_unseen, R.drawable.twotone_mail_outline_24);
}
});
// Initialize
FragmentDialogTheme.setBackground(getContext(), view, false);
@ -618,6 +649,9 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
grpBackground.setVisibility(
Build.VERSION.SDK_INT < Build.VERSION_CODES.O || BuildConfig.DEBUG
? View.VISIBLE : View.GONE);
grpTiles.setVisibility(
Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU || !BuildConfig.DEBUG
? View.GONE : View.VISIBLE);
PreferenceManager.getDefaultSharedPreferences(getContext()).registerOnSharedPreferenceChangeListener(this);
@ -775,4 +809,37 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
prefs.edit().remove("sound").apply();
}
}
@RequiresApi(api = 33)
private void addTile(Context context, Class<? extends TileService> cls, int title, int icon) {
StatusBarManager sbm = Helper.getSystemService(context, StatusBarManager.class);
sbm.requestAddTileService(
ComponentName.createRelative(context, cls.getName()),
context.getString(title),
Icon.createWithResource(context, icon),
executor,
new Consumer<Integer>() {
@Override
public void accept(Integer result) {
Log.i("Tile result=" + result + " class=" + cls.getName());
if (result == null)
return;
switch (result) {
case StatusBarManager.TILE_ADD_REQUEST_RESULT_TILE_ADDED:
case StatusBarManager.TILE_ADD_REQUEST_RESULT_TILE_NOT_ADDED:
break;
case StatusBarManager.TILE_ADD_REQUEST_RESULT_TILE_ALREADY_ADDED:
getMainHandler().post(new Runnable() {
@Override
public void run() {
ToastEx.makeText(context, R.string.tile_already_added, Toast.LENGTH_LONG).show();
}
});
break;
default:
Log.e("Tile result=" + result + " class=" + cls.getName());
}
}
});
}
}

@ -837,6 +837,40 @@
app:layout_constraintTop_toBottomOf="@id/tvBackgroundHint"
app:switchPadding="12dp" />
<TextView
android:id="@+id/tvTiles"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:layout_marginEnd="48dp"
android:text="@string/title_advanced_tiles"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?android:attr/textColorPrimary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swAlertOnce" />
<ImageButton
android:id="@+id/ibTileSync"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/tile_synchronize"
android:tooltipText="@string/tile_synchronize"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvTiles"
app:srcCompat="@drawable/twotone_sync_24" />
<ImageButton
android:id="@+id/ibTileUnseen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:contentDescription="@string/tile_unseen"
android:tooltipText="@string/tile_unseen"
app:layout_constraintStart_toEndOf="@id/ibTileSync"
app:layout_constraintTop_toBottomOf="@id/tvTiles"
app:srcCompat="@drawable/twotone_mail_outline_24" />
<TextView
android:id="@+id/tvNoGrouping"
android:layout_width="0dp"
@ -848,7 +882,7 @@
android:textStyle="italic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swAlertOnce" />
app:layout_constraintTop_toBottomOf="@id/ibTileSync" />
<TextView
android:id="@+id/tvNoChannels"
@ -868,6 +902,12 @@
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="swBackground,tvBackgroundHint" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpTiles"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="tvTiles,ibTileSync,ibTileUnseen" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>

@ -45,6 +45,7 @@
<string name="tile_synchronize">Synchronize</string>
<string name="tile_unseen">New messages</string>
<string name="tile_already_added" translatable="false">Tile was already added</string>
<string name="shortcut_refresh">Refresh</string>
<string name="shortcut_compose">Compose</string>
@ -656,6 +657,7 @@
<string name="title_advanced_notifications_background">Use background service to synchronize messages</string>
<string name="title_advanced_notifications_background_hint">A background service can be stopped by Android at any time, but doesn\'t require a status bar notification</string>
<string name="title_advanced_alert_once" translatable="false">MIUI notification sound workaround</string>
<string name="title_advanced_tiles" translatable="false">Add quick settings tiles</string>
<string name="title_advanced_caption_pgp" translatable="false">PGP</string>
<string name="title_advanced_caption_smime" translatable="false">S/MIME</string>

Loading…
Cancel
Save