Skip to content

Commit

Permalink
Merge pull request #3 from Kaiserdragon2/new_features
Browse files Browse the repository at this point in the history
Show second icon
  • Loading branch information
Kaiserdragon2 authored Jan 9, 2022
2 parents 95bc200 + da0c747 commit 9d41dc9
Show file tree
Hide file tree
Showing 11 changed files with 182 additions and 40 deletions.
9 changes: 4 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ apply plugin: 'com.android.application'
android {
compileSdkVersion 31
buildToolsVersion '31.0.0'
buildFeatures {
dataBinding true
}

defaultConfig {
applicationId 'de.kaiserdragon.iconrequest'
minSdkVersion 21
targetSdkVersion 31
versionName "1.2.5"
versionCode 3
versionName "1.5"
versionCode 4

}

buildTypes {
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/de/kaiserdragon/iconrequest/AppInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

public class AppInfo {
public Drawable icon;
public Drawable icon2;
public String label;
String packageName;
String className;
public boolean selected;

AppInfo(Drawable icon, String label, String packageName, String className, boolean selected) {
AppInfo(Drawable icon, Drawable icon2, String label, String packageName, String className, boolean selected) {
this.icon = icon;
this.icon2 = icon2;
this.label = label;
this.packageName = packageName;
this.className = className;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
package de.kaiserdragon.iconrequest;


import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM;
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO;
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES;


import android.content.ComponentName;
import android.content.Intent;
import android.content.SharedPreferences;
Expand Down Expand Up @@ -63,6 +57,6 @@ public boolean onOptionsItemSelected(MenuItem item) {
}
public int loadData() {
SharedPreferences sharedPreferences = getSharedPreferences("SharedPrefs", MODE_PRIVATE);
return sharedPreferences.getInt("DarkModeState", 0);
return sharedPreferences.getInt("DarkModeState", -1);
}
}
58 changes: 49 additions & 9 deletions app/src/main/java/de/kaiserdragon/iconrequest/RequestActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.AssetManager;
Expand All @@ -29,9 +30,11 @@
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ArrayAdapter;

import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;

import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
Expand All @@ -53,9 +56,11 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.text.Collator;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
Expand Down Expand Up @@ -227,6 +232,7 @@ public void onCreate(Bundle savedInstanceState) {
ImgLocation = context.getFilesDir() + "/Icons/IconRequest";
ZipLocation = context.getFilesDir() + "/Icons";


Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);
Expand Down Expand Up @@ -294,7 +300,18 @@ public boolean onOptionsItemSelected(MenuItem item) {
}
}

private boolean visible(Drawable one,Drawable two){
Bitmap bmp1 = getBitmapFromDrawable(one);
Bitmap bmp2 = getBitmapFromDrawable(two);

ByteBuffer buffer1 = ByteBuffer.allocate(bmp1.getHeight() * bmp1.getRowBytes());
bmp1.copyPixelsToBuffer(buffer1);

ByteBuffer buffer2 = ByteBuffer.allocate(bmp2.getHeight() * bmp2.getRowBytes());
bmp2.copyPixelsToBuffer(buffer2);

return Arrays.equals(buffer1.array(), buffer2.array());
}

public void makeToast(String text) {
Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
Expand Down Expand Up @@ -395,14 +412,14 @@ private String[] actionSave() {
if (DEBUG) Log.i(TAG, "iconName: " + iconName);

stringBuilderEmail.append(arrayList.get(i).label).append("\n");
stringBuilderXML.append("<!-- ")
stringBuilderXML.append("\t<!-- ")
.append(arrayList.get(i).label)
.append(" -->\n<item component=\"ComponentInfo{")
.append(" -->\n\t<item component=\"ComponentInfo{")
.append(arrayList.get(i).getCode())
.append("}\" drawable=\"")
.append(iconName)
.append("\"/>")
.append("\n");
.append("\n\n");

try {
Bitmap bitmap = getBitmapFromDrawable(arrayList.get(i).icon);
Expand Down Expand Up @@ -482,7 +499,7 @@ private void parseXML() {
if (xmlCode.length > 1) {
String xmlPackage = xmlCode[0].substring(14);
String xmlClass = xmlCode[1].substring(0, xmlCode[1].length() - 1);
appListAll.add(new AppInfo(null,
appListAll.add(new AppInfo(null,null,
xmlLabel, xmlPackage, xmlClass, false));
if (DEBUG) Log.v(TAG, "XML APP: " + xmlLabel);
}
Expand Down Expand Up @@ -510,15 +527,23 @@ private void prepareData() {
List<ResolveInfo> list = pm.queryIntentActivities(intent, 0);
Iterator<ResolveInfo> localIterator = list.iterator();
if (DEBUG) Log.v(TAG, "list size: " + list.size());

boolean notVisible = loadDataBool("SettingOnlyNew");
for (int i = 0; i < list.size(); i++) {
ResolveInfo resolveInfo = localIterator.next();
AppInfo appInfo = new AppInfo(getHighResIcon(pm, resolveInfo),
Drawable icon1 = getHighResIcon(pm, resolveInfo);
Drawable icon2 = getHighResIcon(pm, resolveInfo);//resolveInfo.loadIcon(pm);
if (DEBUG) Log.v(TAG, String.valueOf(icon2));
AppInfo appInfo = new AppInfo(icon1,
icon2,
resolveInfo.loadLabel(pm).toString(),
resolveInfo.activityInfo.packageName,
resolveInfo.activityInfo.name,
false);
arrayList.add(appInfo);
if (notVisible){
if (DEBUG) Log.v(TAG, "Not Done");
if (visible(icon1,icon2)) arrayList.add(appInfo);
}else arrayList.add(appInfo);

}

//Custom comparator to ensure correct sorting for characters like and apps
Expand Down Expand Up @@ -549,14 +574,17 @@ private Drawable getHighResIcon(PackageManager pm, ResolveInfo resolveInfo) {

if (iconId != 0) {
icon = ResourcesCompat.getDrawable(pm.getResourcesForActivity(componentName), iconId, null);
//Drawable adaptiveDrawable = resolveInfo.loadIcon(pm);
//PackageManager packageManager = getPackageManager();
//icon = resolveInfo.loadIcon(packageManager);
//icon = context.getDrawable(iconId);
return icon;
}
return resolveInfo.loadIcon(pm);
} catch (PackageManager.NameNotFoundException e) {
// fails return the normal icon
//fails return the normal icon
return resolveInfo.loadIcon(pm);
} catch (Resources.NotFoundException e) {
}catch (Resources.NotFoundException e) {
return resolveInfo.loadIcon(pm);
}
}
Expand Down Expand Up @@ -598,6 +626,10 @@ private void populateView(ArrayList<AppInfo> arrayListFinal) {
}
});
}
public boolean loadDataBool(String setting) {
SharedPreferences sharedPreferences = getSharedPreferences("SharedPrefs", MODE_PRIVATE);
return sharedPreferences.getBoolean(setting, false);
}

private class AppAdapter extends ArrayAdapter<AppInfo> {
private final ArrayList<AppInfo> appList = new ArrayList<>();
Expand All @@ -615,6 +647,7 @@ public View getView(int position, View convertView, @NonNull ViewGroup parent) {
.inflate(R.layout.item_request, null);
holder = new ViewHolder();
holder.apkIcon = convertView.findViewById(R.id.IVappIcon);
holder.apkIconnow = convertView.findViewById(R.id.IVappIconnow);
holder.apkName = convertView.findViewById(R.id.TVappName);
holder.apkPackage = convertView.findViewById(R.id.TVappPackage);
holder.apkClass = convertView.findViewById(R.id.TVappClass);
Expand All @@ -632,6 +665,11 @@ public View getView(int position, View convertView, @NonNull ViewGroup parent) {
holder.apkClass.setText(appInfo.className);
holder.apkName.setText(appInfo.label);
holder.apkIcon.setImageDrawable(appInfo.icon);
holder.apkIconnow.setImageDrawable(appInfo.icon2);
if(loadDataBool("SettingRow")==true){
holder.apkIconnow.setVisibility(View.VISIBLE);
}


holder.switcherChecked.setInAnimation(null);
holder.switcherChecked.setOutAnimation(null);
Expand All @@ -655,9 +693,11 @@ private class ViewHolder {
TextView apkPackage;
TextView apkClass;
ImageView apkIcon;
ImageView apkIconnow;
CheckBox checker;
LinearLayout cardBack;
ViewSwitcher switcherChecked;

}
}
}
55 changes: 45 additions & 10 deletions app/src/main/java/de/kaiserdragon/iconrequest/SettingActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.RadioGroup;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
Expand All @@ -17,7 +19,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings);

switch(loadData()) {
switch(loadData("DarkModeState")) {
case -1:
((RadioGroup)findViewById(R.id.radioGroup)).check(R.id.radioDefault);
break;
Expand All @@ -29,34 +31,67 @@ protected void onCreate(Bundle savedInstanceState) {
break;
}

((CheckBox)findViewById(R.id.checkBoxRows)).setChecked(loadDataBool("SettingRow"));
((CheckBox)findViewById(R.id.checkBoxOnly)).setChecked(loadDataBool("SettingOnlyNew"));


Button setDark = findViewById(R.id.radioDark);
setDark.setOnClickListener(view -> start(2));
setDark.setOnClickListener(view -> start(view,2));

Button setLight = findViewById(R.id.radioLight);
setLight.setOnClickListener(view -> start(1));
setLight.setOnClickListener(view -> start(view,1));

Button setDefault = findViewById(R.id.radioDefault);
setDefault.setOnClickListener(view -> start(-1));
setDefault.setOnClickListener(view -> start(view,-1));

CheckBox SecondRow = findViewById(R.id.checkBoxRows);
SecondRow.setOnClickListener(view -> start(view,0));

CheckBox OnlyNew = findViewById(R.id.checkBoxOnly);
OnlyNew.setOnClickListener(view -> start(view,0));

Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);
}

public void start(int update) {
saveData(update);
public void start(View view ,int update) {
if (update != 0){
saveData("DarkModeState",update);
AppCompatDelegate.setDefaultNightMode(update);
} else{
if (view ==(CheckBox) findViewById(R.id.checkBoxRows)){
if (((CheckBox) view).isChecked()) {
saveDataBool("SettingRow", true);
}else saveDataBool("SettingRow", false);
}else if (view ==(CheckBox) findViewById(R.id.checkBoxOnly)){
if (((CheckBox) view).isChecked()) {
saveDataBool("SettingOnlyNew", true);
}else saveDataBool("SettingOnlyNew", false);
}
}

}

public void saveData(int data) {
public void saveData(String setting, int data) {
SharedPreferences sharedPreferences = getSharedPreferences("SharedPrefs", MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putInt("DarkModeState", data);
editor.putInt(setting, data);
editor.apply();
}
public int loadData() {
public void saveDataBool(String setting, boolean data) {
SharedPreferences sharedPreferences = getSharedPreferences("SharedPrefs", MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean(setting, data);
editor.apply();
}
public int loadData(String setting) {
SharedPreferences sharedPreferences = getSharedPreferences("SharedPrefs", MODE_PRIVATE);
return sharedPreferences.getInt(setting, -1);
}
public boolean loadDataBool(String setting) {
SharedPreferences sharedPreferences = getSharedPreferences("SharedPrefs", MODE_PRIVATE);
return sharedPreferences.getInt("DarkModeState", 0);
return sharedPreferences.getBoolean(setting, false);
}
}

Expand Down
8 changes: 4 additions & 4 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:isScrollContainer="false"
android:orientation="vertical"
tools:context="de.kaiserdragon.iconrequest.MainActivity">

Expand All @@ -18,7 +17,7 @@
android:paddingEnd="10dp"
android:paddingBottom="40dp"
android:text="@string/with_this_tool"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textAppearance="@android:style/TextAppearance.Material.Medium"
android:textSize="16sp" />

<TextView
Expand All @@ -27,7 +26,7 @@
android:gravity="center"
android:padding="10dp"
android:text="@string/icon_update"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textAppearance="@android:style/TextAppearance.Material.Medium"
android:textSize="16sp" />

<Button
Expand All @@ -51,7 +50,7 @@
android:gravity="center"
android:padding="10dp"
android:text="@string/icon_new"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textAppearance="@android:style/TextAppearance.Material.Medium"
android:textSize="16sp" />

<Button
Expand All @@ -68,4 +67,5 @@
android:paddingRight="20dp"
android:text="@string/start"
android:textSize="20sp" />

</LinearLayout>
2 changes: 2 additions & 0 deletions app/src/main/res/layout/activity_request.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,7 @@
android:id="@+id/app_list"
android:layout_width="match_parent"
android:layout_height="match_parent" />

</ViewSwitcher>

</LinearLayout>
Loading

0 comments on commit 9d41dc9

Please sign in to comment.