Skip to content

Commit

Permalink
Add option to change icon size
Browse files Browse the repository at this point in the history
  • Loading branch information
abdelkader.sellami committed Aug 28, 2019
1 parent d046a50 commit e0c260e
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
db_files
*.iml
.settings
.project
.classpath
.project.properties
Expand Down
35 changes: 35 additions & 0 deletions res/values/arrays.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>

<!-- Copyright (C) 2019
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->

<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">

<!-- Icon size -->
<string-array name="icon_size_names">
<item>@string/icon_size_extra_small</item>
<item>@string/icon_size_small</item>
<item>@string/icon_size_average</item>
<item>@string/icon_size_large</item>
<item>@string/icon_size_extra_large</item>
</string-array>

<string-array name="icon_size_values">
<item>extrasmall</item>
<item>small</item>
<item>average</item>
<item>large</item>
<item>extralarge</item>
</string-array>

</resources>
9 changes: 9 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -351,5 +351,14 @@
<string name="icon_pack_summary">Select a custom icon pack</string>
<string name="icons_category_title">Icons</string>

<!-- Icon size -->
<string name="icon_size_title">Icon size</string>
<string name="icon_size_extra_small">Tiny</string>
<string name="icon_size_small">Small</string>
<string name="icon_size_average">Default</string>
<string name="icon_size_large">Large</string>
<string name="icon_size_extra_large">Extra large</string>

<string name="state_loading">Loading</string>

</resources>
9 changes: 9 additions & 0 deletions res/xml/launcher_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,13 @@
android:defaultValue=""
android:persistent="false" />

<ListPreference
android:key="pref_icon_size"
android:title="@string/icon_size_title"
android:summary="%s"
android:entries="@array/icon_size_names"
android:entryValues="@array/icon_size_values"
android:defaultValue="average"
android:persistent="true" />

</PreferenceScreen>
2 changes: 0 additions & 2 deletions src/com/android/launcher3/IconCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,6 @@ private void updateDBIcons(UserHandle user, List<LauncherActivityInfo> apps,
iconAppSDK = 25;
}
}
Log.w("islem", "icon app sdk is : " + iconAppSDK);

li.createBadgedIconBitmap(iconDrawable, app.getUser(),iconAppSDK).applyTo(entry);
li.recycle();
Expand Down Expand Up @@ -595,7 +594,6 @@ protected CacheEntry cacheLocked(
iconAppSDK = 25;
}
}
Log.w("islem", "icon app sdk is : " + iconAppSDK);

li.createBadgedIconBitmap(iconDrawable, info.getUser(),iconAppSDK).applyTo(entry);
li.recycle();
Expand Down
8 changes: 5 additions & 3 deletions src/com/android/launcher3/InvariantDeviceProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,12 @@ public InvariantDeviceProfile(Context context) {
numFolderRows = closestProfile.numFolderRows;
numFolderColumns = closestProfile.numFolderColumns;

iconSize = interpolatedDeviceProfileOut.iconSize;
landscapeIconSize = interpolatedDeviceProfileOut.landscapeIconSize;
float iconSizeModifier = Utilities.getIconSizeModifier(context);
iconSize = interpolatedDeviceProfileOut.iconSize * iconSizeModifier;
landscapeIconSize = interpolatedDeviceProfileOut.landscapeIconSize * iconSizeModifier;

iconBitmapSize = Utilities.pxFromDp(iconSize, dm);
iconTextSize = interpolatedDeviceProfileOut.iconTextSize;
iconTextSize = interpolatedDeviceProfileOut.iconTextSize * iconSizeModifier;
fillResIconDpi = getLauncherIconDensity(iconBitmapSize);

// If the partner customization apk contains any grid overrides, apply them
Expand Down
4 changes: 2 additions & 2 deletions src/com/android/launcher3/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Point;
import android.os.AsyncTask;
Expand Down Expand Up @@ -131,8 +133,6 @@
import com.android.launcher3.widget.WidgetListRowEntry;
import com.android.launcher3.widget.WidgetsFullSheet;
import com.android.launcher3.widget.custom.CustomWidgetParser;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;

import java.io.FileDescriptor;
import java.io.PrintWriter;
Expand Down
45 changes: 45 additions & 0 deletions src/com/android/launcher3/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@
import android.app.Dialog;
import android.app.DialogFragment;
import android.app.FragmentManager;
import android.app.ProgressDialog;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.SystemClock;
import android.preference.ListPreference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceScreen;
Expand All @@ -41,12 +44,16 @@
import android.view.View;
import android.widget.Adapter;
import android.widget.ListView;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.util.Log;

import com.android.launcher3.graphics.IconShapeOverride;
import com.android.launcher3.notification.NotificationListener;
import com.android.launcher3.util.ListViewHighlighter;
import com.android.launcher3.util.SettingsObserver;
import com.android.launcher3.views.ButtonPreference;
import com.android.launcher3.util.LooperExecutor;

import java.util.Objects;

Expand All @@ -65,6 +72,7 @@ public class SettingsActivity extends Activity {
private static final String EXTRA_SHOW_FRAGMENT_ARGS = ":settings:show_fragment_args";
private static final int DELAY_HIGHLIGHT_DURATION_MILLIS = 600;
private static final String SAVE_HIGHLIGHTED_KEY = "android:preference_highlighted";
private static final long WAIT_BEFORE_RESTART = 250;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -137,6 +145,18 @@ public void onCreate(Bundle savedInstanceState) {
// Initialize the UI once
rotationPref.setDefaultValue(getAllowRotationDefaultValue());
}

final ListPreference iconSizes = (ListPreference) findPreference(Utilities.ICON_SIZE);
iconSizes.setSummary(iconSizes.getEntry());
iconSizes.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
int index = iconSizes.findIndexOfValue((String) newValue);
iconSizes.setSummary(iconSizes.getEntries()[index]);
restart(getActivity());
return true;
}
});

}

@Override
Expand Down Expand Up @@ -297,4 +317,29 @@ public void onClick(DialogInterface dialogInterface, int i) {
getActivity().startActivity(intent);
}
}

public static void restart(final Context context) {
ProgressDialog.show(context, null, context.getString(R.string.state_loading), true, false);
new LooperExecutor(LauncherModel.getWorkerLooper()).execute(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(WAIT_BEFORE_RESTART);
} catch (Exception e) {
Log.e("SettingsActivity", "Error waiting", e);
}

Intent intent = new Intent(Intent.ACTION_MAIN)
.addCategory(Intent.CATEGORY_HOME)
.setPackage(context.getPackageName())
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT);
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarmManager.setExact(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + 50, pendingIntent);

android.os.Process.killProcess(android.os.Process.myPid());
}
});
}
}
28 changes: 28 additions & 0 deletions src/com/android/launcher3/Utilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ public final class Utilities {

public static final int SINGLE_FRAME_MS = 16;

public static final String ICON_SIZE = "pref_icon_size";

/**
* Indicates if the device has a debug build. Should only be used to store additional info or
* add extra logging and not for changing the app behavior.
Expand Down Expand Up @@ -618,4 +620,30 @@ public static void postAsyncCallback(Handler handler, Runnable callback) {
msg.setAsynchronous(true);
handler.sendMessage(msg);
}

public static float getIconSizeModifier(Context context) {
String saved = getPrefs(context).getString(ICON_SIZE, "average");
float offset;
switch (saved) {
case "extrasmall":
offset = 0.75F;
break;
case "small":
offset = 0.90F;
break;
case "average":
offset = 1.00F;
break;
case "large":
offset = 1.10F;
break;
case "extralarge":
offset = 1.25F;
break;
default:
offset = 1.00F;
break;
}
return offset;
}
}

0 comments on commit e0c260e

Please sign in to comment.