-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a preference dialog and a make-default option
Move the orientation toggle into a preference dialog and also add an option to set the launcher as default.
- Loading branch information
1 parent
135f6b1
commit 62aac5c
Showing
13 changed files
with
200 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
app/src/main/java/de/markusfisch/android/pielauncher/dialog/PreferencesDialog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package de.markusfisch.android.pielauncher.dialog; | ||
|
||
import android.app.Activity; | ||
import android.app.AlertDialog; | ||
import android.app.role.RoleManager; | ||
import android.content.ComponentName; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.content.IntentFilter; | ||
import android.content.pm.ActivityInfo; | ||
import android.content.pm.PackageManager; | ||
import android.os.Build; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.widget.TextView; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import de.markusfisch.android.pielauncher.R; | ||
import de.markusfisch.android.pielauncher.app.PieLauncherApp; | ||
|
||
public class PreferencesDialog { | ||
public static void create(Context context) { | ||
Activity activity = (Activity) context; | ||
LayoutInflater inflater = activity.getLayoutInflater(); | ||
View view = inflater.inflate(R.layout.dialog_preferences, null); | ||
|
||
TextView orientationView = view.findViewById(R.id.orientation); | ||
orientationView.setOnClickListener( | ||
v -> setOrientation(activity, orientationView)); | ||
setOrientationText(orientationView, | ||
PieLauncherApp.prefs.getOrientation()); | ||
|
||
TextView defaultLauncherView = view.findViewById( | ||
R.id.make_default_launcher); | ||
|
||
AlertDialog dialog = new AlertDialog.Builder(context) | ||
.setTitle(R.string.preferences) | ||
.setView(view) | ||
.setPositiveButton(android.R.string.ok, null) | ||
.show(); | ||
|
||
if (isDefault( | ||
activity.getPackageManager(), | ||
activity.getPackageName())) { | ||
defaultLauncherView.setVisibility(View.GONE); | ||
} else { | ||
defaultLauncherView.setOnClickListener(v -> { | ||
setAsDefault(activity); | ||
dialog.dismiss(); | ||
}); | ||
} | ||
} | ||
|
||
private static void setOrientation(Activity activity, | ||
TextView orientationView) { | ||
int newOrientation = PieLauncherApp.prefs.getOrientation() == | ||
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT | ||
? ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE | ||
: ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; | ||
PieLauncherApp.prefs.setOrientation(newOrientation); | ||
setOrientationText(orientationView, newOrientation); | ||
activity.setRequestedOrientation(newOrientation); | ||
} | ||
|
||
private static void setOrientationText(TextView tv, int orientation) { | ||
tv.setText(getOrientationResId(orientation)); | ||
} | ||
|
||
private static int getOrientationResId(int orientation) { | ||
switch (orientation) { | ||
default: | ||
return R.string.orientation_default; | ||
case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: | ||
return R.string.orientation_landscape; | ||
case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: | ||
return R.string.orientation_portrait; | ||
} | ||
} | ||
|
||
private static void setAsDefault(Activity activity) { | ||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { | ||
Intent intent = new Intent("android.intent.action.MAIN"); | ||
intent.addCategory("android.intent.category.HOME"); | ||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | ||
activity.startActivity(intent); | ||
} else { | ||
RoleManager roleManager = (RoleManager) activity.getSystemService( | ||
Context.ROLE_SERVICE); | ||
if (roleManager.isRoleAvailable(RoleManager.ROLE_HOME) && | ||
!roleManager.isRoleHeld(RoleManager.ROLE_HOME)) { | ||
activity.startActivityForResult( | ||
roleManager.createRequestRoleIntent( | ||
RoleManager.ROLE_HOME), | ||
1); | ||
} | ||
} | ||
} | ||
|
||
private static boolean isDefault(PackageManager packageManager, | ||
String packageName) { | ||
IntentFilter filter = new IntentFilter(Intent.ACTION_MAIN); | ||
filter.addCategory(Intent.CATEGORY_HOME); | ||
|
||
List<IntentFilter> filters = new ArrayList<>(); | ||
filters.add(filter); | ||
|
||
List<ComponentName> activities = new ArrayList<>(); | ||
packageManager.getPreferredActivities(filters, activities, null); | ||
|
||
for (ComponentName activity : activities) { | ||
if (packageName.equals(activity.getPackageName())) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="64dp" android:height="64dp" android:viewportWidth="64" android:viewportHeight="64"> | ||
<path android:pathData="M39.14 32.94c0.04-0.3 0.06-0.61 0.06-0.94 0-0.32-0.02-0.64-0.07-0.94l2.03-1.58c0.18-0.14 0.23-0.41 0.12-0.61l-1.92-3.32c-0.12-0.22-0.37-0.29-0.59-0.22l-2.39 0.96c-0.5-0.38-1.03-0.7-1.62-0.94l-0.36-2.54c-0.04-0.24-0.24-0.41-0.48-0.41h-3.84c-0.24 0-0.43 0.17-0.47 0.41l-0.36 2.54c-0.59 0.24-1.13 0.57-1.62 0.94l-2.39-0.96c-0.22-0.08-0.47 0-0.59 0.22l-1.91 3.32c-0.12 0.21-0.08 0.47 0.12 0.61l2.03 1.58c-0.05 0.3-0.09 0.63-0.09 0.94 0 0.31 0.02 0.64 0.07 0.94l-2.03 1.58c-0.18 0.14-0.23 0.41-0.12 0.61l1.92 3.32c0.12 0.22 0.37 0.29 0.59 0.22l2.39-0.96c0.5 0.38 1.03 0.7 1.62 0.94l0.36 2.54c0.05 0.24 0.24 0.41 0.48 0.41h3.84c0.24 0 0.44-0.17 0.47-0.41l0.36-2.54c0.59-0.24 1.13-0.56 1.62-0.94l2.39 0.96c0.22 0.08 0.47 0 0.59-0.22l1.92-3.32c0.12-0.22 0.07-0.47-0.12-0.61l-2.01-1.58zM32 35.6c-1.98 0-3.6-1.62-3.6-3.6s1.62-3.6 3.6-3.6 3.6 1.62 3.6 3.6-1.62 3.6-3.6 3.6z" android:fillColor="#FFFFFF"/> | ||
</vector> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<ScrollView | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:fillViewport="true"> | ||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="vertical" | ||
android:padding="24dp"> | ||
<TextView | ||
style="@style/Preference" | ||
android:id="@+id/orientation" | ||
android:text="@string/orientation_default"/> | ||
<TextView | ||
style="@style/Preference" | ||
android:id="@+id/make_default_launcher" | ||
android:text="@string/make_default_launcher"/> | ||
</LinearLayout> | ||
</ScrollView> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<string name="app_name">Pie Launcher</string> | ||
<string name="tip_number_of_icons">Essayer 4, 6 ou 8 symboles pour une utilisation optimale</string> | ||
<string name="tip_pinch_zoom">Pincer et écarter pour redimensionner le menu</string> | ||
<string name="tip_drag_to_order">Faire glisser pour organiser</string> | ||
<string name="please_ignore_battery_optimization">Merci de désactiver les optimisations de batterie pour Pie Launcher afin d\'économiser de l\'énergie et le faire fonctionner plus rapidement.\n\nPie Launcher ne consomme pas de batterie quand il n\'est pas utilisé. Un lanceur d\'application est une exception parce qu\'il devrait être disponible en permanence et immédiatement, ce qui est empêché par les optimisations de batterie.\n\nPour cette raison, le lanceur d\'application par défaut est aussi déjà exclu des optimisations de batterie.</string> | ||
<string name="disable_battery_optimization">DÉSACTIVER LES OPTIMISATIONS DE BATTERIE</string> | ||
<string name="preferences">Préférences</string> | ||
<string name="orientation_default"><big>Orientation</big>\nDefault</string> | ||
<string name="orientation_portrait"><big>Orientation</big>\nPortrait</string> | ||
<string name="orientation_landscape"><big>Orientation</big>\nPaysage</string> | ||
<string name="make_default_launcher"><big>Créer un lanceur par défaut</big>\nDéfinir comme lanceur par défaut</string> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.