Skip to content

Commit

Permalink
implement icon pack
Browse files Browse the repository at this point in the history
  • Loading branch information
valkriaine committed May 12, 2022
1 parent ef94377 commit 5330e90
Show file tree
Hide file tree
Showing 25 changed files with 965 additions and 91 deletions.
3 changes: 3 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ android {
applicationId "com.factor.launcher"
minSdkVersion 22
targetSdkVersion 31
versionCode 38
versionName "0.66"
versionCode 40
versionName "0.7"

renderscriptTargetApi 31
renderscriptSupportModeEnabled true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ public AppListViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewT
MenuInflater inflater = activity.getMenuInflater();
inflater.inflate(R.menu.app_list_item_menu, menu);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
{
menu.setGroupDividerEnabled(true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -10,7 +11,7 @@
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;
import com.factor.launcher.R;
import com.factor.launcher.databinding.RecentAppsItemBinding;
import com.factor.launcher.databinding.ItemRecentAppsBinding;
import com.factor.launcher.models.UserApp;
import com.factor.launcher.receivers.AppActionReceiver;
import com.factor.launcher.util.Constants;
Expand Down Expand Up @@ -41,7 +42,7 @@ public void addRecentBroadcast()
@Override
public RecentAppViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType)
{
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recent_apps_item, parent, false);
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_recent_apps, parent, false);
return new RecentAppViewHolder(view);
}

Expand Down Expand Up @@ -70,7 +71,7 @@ public int getItemCount()

static class RecentAppViewHolder extends RecyclerView.ViewHolder
{
private final RecentAppsItemBinding binding;
private final ItemRecentAppsBinding binding;

public RecentAppViewHolder(@NonNull View itemView)
{
Expand All @@ -83,7 +84,13 @@ public void bind(String name, AppListManager appListManager)
binding.setPackageName(name);
try
{
binding.recentIcon.setImageDrawable(appListManager.packageManager.getApplicationIcon(name));
Drawable icon;
if (appListManager.getIconPack() != null)
icon = appListManager.getIconPack().getDrawableIconForPackage(name, appListManager.packageManager.getApplicationIcon(name));
else
icon = appListManager.packageManager.getApplicationIcon(name);

binding.recentIcon.setImageDrawable(icon);
binding.recentIcon.setElevationDp(appListManager.settings.getShowShadowAroundIcon()? 30 : 0);
}
catch (PackageManager.NameNotFoundException ignored){}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase
import com.factor.launcher.models.AppSettings

@Database(entities = [AppSettings::class], exportSchema = false, version = 3)
@Database(entities = [AppSettings::class], exportSchema = false, version = 4)
abstract class AppSettingsDatabase : RoomDatabase()
{
abstract fun appSettingsDao(): AppSettingsDao
Expand All @@ -15,6 +15,7 @@ abstract class AppSettingsDatabase : RoomDatabase()
Room.databaseBuilder(it.applicationContext, AppSettingsDatabase::class.java, "factor_settings")
.addMigrations(SettingsMigrations.MIGRATION_CHANGE_TILE_LIST_RESIZING)
.addMigrations(SettingsMigrations.MIGRATION_STATIC_BLUR)
.addMigrations(SettingsMigrations.MIGRATION_ICON_PACK)
.fallbackToDestructiveMigration()
.allowMainThreadQueries()
.build()
Expand Down Expand Up @@ -56,6 +57,14 @@ abstract class AppSettingsDatabase : RoomDatabase()
database.execSQL("ALTER TABLE AppSettings ADD COLUMN static_blur INTEGER NOT NULL DEFAULT 0")
}
}

val MIGRATION_ICON_PACK = object : Migration(3, 4)
{
override fun migrate(database: SupportSQLiteDatabase)
{
database.execSQL("ALTER TABLE AppSettings ADD COLUMN icon_pack TEXT NOT NULL DEFAULT ''")
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.HapticFeedbackConstants;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.*;
import android.widget.EditText;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
Expand All @@ -27,6 +24,8 @@
import com.factor.launcher.R;
import com.factor.launcher.activities.EmptyHome;
import com.factor.launcher.databinding.FragmentSettingsBinding;
import com.factor.launcher.models.IconPackProvider;
import com.factor.launcher.ui.IconPackPickerView;
import com.factor.launcher.view_models.AppSettingsManager;
import com.factor.launcher.models.AppSettings;
import com.factor.launcher.ui.CustomFlag;
Expand Down Expand Up @@ -59,6 +58,8 @@ public class SettingsFragment extends Fragment implements LifecycleOwner

private Bitmap m;

private String iconPack = "";

public SettingsFragment()
{
// Required empty public constructor
Expand Down Expand Up @@ -305,6 +306,31 @@ public void afterTextChanged(Editable s) {}
binding.tileColorPickerButton.setOnClickListener(v -> showColorPickerDialog("Tile color"));
binding.searchBarColorPickerButton.setOnClickListener(v -> showColorPickerDialog("Search bar color"));


// Icon pack picker
iconPack = settings.getIconPackPackageName();
binding.iconPackPicker.setCurrentIconPack(iconPack);
binding.iconPackPicker.setOnIconPackClickedListener(new IconPackPickerView.OnIconPackClickedListener()
{
@Override
public void onIconPackClicked(IconPackProvider clickedIconPack)
{
if (clickedIconPack.isCurrentIconPack())
{
binding.demoIconPack.setImageDrawable(clickedIconPack.getIcon());
binding.demoIconPack.setVisibility(View.VISIBLE);
iconPack = clickedIconPack.getPackageName();
}
else
{
binding.demoIconPack.setVisibility(View.INVISIBLE);
iconPack = "";
}

binding.tileLabel.setText(binding.iconPackPicker.getCurrentIconPackName());
}
});

setUpUIState();
setUpDemoTile();
}
Expand Down Expand Up @@ -412,6 +438,8 @@ private void updateSettings()
updated.setTileThemeColor(tileColor);
updated.setSearchBarColor(searchColor);

updated.setIconPackPackageName(binding.iconPackPicker.getCurrentIconPackPackageName());


AppSettingsManager.getInstance(getActivity().getApplication()).setAppSettings(updated).updateSettings();
Intent intent = new Intent();
Expand All @@ -433,7 +461,8 @@ private boolean areSettingsChanged()
!tileColor.equals(settings.getTileThemeColor()) ||
!searchColor.equals(settings.getSearchBarColor()) ||
binding.iconShadowToggle.isChecked() != settings.getShowShadowAroundIcon() ||
binding.staticBlurToggle.isChecked() != settings.getStaticBlur();
binding.staticBlurToggle.isChecked() != settings.getStaticBlur() ||
binding.iconPackPicker.getCurrentIconPackPackageName().equals(settings.getIconPackPackageName());
}


Expand Down
14 changes: 14 additions & 0 deletions app/src/main/java/com/factor/launcher/models/AppSettings.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.factor.launcher.models

import android.content.Context
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import com.factor.launcher.util.Constants
import com.factor.launcher.util.IconPackManager


@Entity
Expand Down Expand Up @@ -44,4 +46,16 @@ class AppSettings

@ColumnInfo(name = "static_blur")
var staticBlur = false

@ColumnInfo(name = "icon_pack")
var iconPackPackageName = ""


fun getIconPackProvider(context: Context): IconPackManager.IconPack?
{
val iconPackManager = IconPackManager()
iconPackManager.setContext(context)
iconPackManager.getAvailableIconPacks(true)
return iconPackManager.getIconPackWithName(iconPackPackageName)
}
}
8 changes: 8 additions & 0 deletions app/src/main/java/com/factor/launcher/models/Factor.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.factor.launcher.models

import android.graphics.Bitmap
import android.graphics.drawable.Drawable
import androidx.room.ColumnInfo
import androidx.room.Entity
Expand Down Expand Up @@ -44,11 +45,18 @@ class Factor

fun getIcon() : Drawable? = this.userApp.icon

fun getBitmapIcon() : Bitmap? = this.userApp.bitmapIcon

fun setIcon(icon : Drawable)
{
this.userApp.icon = icon
}

fun setIcon(bitmap: Bitmap)
{
this.userApp.bitmapIcon = bitmap
}

object Size
{
const val small : Int = 1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.factor.launcher.models

class IconPackProvider : UserApp()
{
var isCurrentIconPack = false
}
23 changes: 20 additions & 3 deletions app/src/main/java/com/factor/launcher/models/UserApp.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.factor.launcher.models

import android.graphics.Bitmap
import android.graphics.Color
import android.graphics.drawable.Drawable
import android.view.View
Expand All @@ -14,7 +15,7 @@ import java.util.*
import kotlin.collections.ArrayList

@Entity
class UserApp
open class UserApp
{
@PrimaryKey
var packageName: String = ""
Expand Down Expand Up @@ -69,6 +70,9 @@ class UserApp
@Ignore
var icon: Drawable? = null

@Ignore
var bitmapIcon: Bitmap? = null

@Ignore
var isMediaTile = false

Expand All @@ -90,6 +94,11 @@ class UserApp
//...
}

fun equals(userApp: UserApp) : Boolean
{
return this.packageName.equals(userApp.packageName)
}

//generate new factor
fun toFactor(): Factor
{
Expand All @@ -113,8 +122,16 @@ class UserApp
{
return if (notification.title != notificationHolder.title || notification.text != notificationHolder.text)
{
currentNotifications[currentNotifications.indexOf(notification)] = notificationHolder
true
try
{
currentNotifications[currentNotifications.indexOf(notification)] = notificationHolder
return true
}
catch (e : IndexOutOfBoundsException)
{
return false
}

}
else false
}
Expand Down
Loading

0 comments on commit 5330e90

Please sign in to comment.