diff --git a/app/build.gradle b/app/build.gradle index a6745dd..44eac77 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -8,8 +8,8 @@ android { applicationId 'de.kaiserdragon.iconrequest' minSdkVersion 21 targetSdkVersion 31 - versionName "1.8.5" - versionCode 10 + versionName "1.9.3" + versionCode 11 } buildTypes { diff --git a/app/src/main/java/de/kaiserdragon/iconrequest/CompareIPacks.java b/app/src/main/java/de/kaiserdragon/iconrequest/CompareIPacks.java index 91c4e88..e418cd5 100644 --- a/app/src/main/java/de/kaiserdragon/iconrequest/CompareIPacks.java +++ b/app/src/main/java/de/kaiserdragon/iconrequest/CompareIPacks.java @@ -1,5 +1,7 @@ package de.kaiserdragon.iconrequest; +import android.content.ClipData; +import android.content.ClipboardManager; import android.content.ComponentName; import android.content.Context; import android.content.Intent; @@ -14,6 +16,7 @@ import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.view.animation.Animation; @@ -27,10 +30,10 @@ import android.widget.Toast; import android.widget.ViewSwitcher; -import androidx.activity.result.contract.ActivityResultContracts; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; +import androidx.core.app.NavUtils; import androidx.core.content.ContextCompat; import androidx.core.content.res.ResourcesCompat; @@ -53,16 +56,16 @@ public class CompareIPacks extends AppCompatActivity { private static final String TAG = "CompareActivity"; private static final boolean DEBUG = true; - private ViewSwitcher switcherLoad; private static ArrayList IPackListFilter = new ArrayList<>(); - private Context context; private static ArrayList appListFilter = new ArrayList<>(); private static ArrayList appListAll = new ArrayList<>(); private static ArrayList appListPack1 = new ArrayList<>(); private static ArrayList appListPack2 = new ArrayList<>(); + private static String xmlString; String Label1; String Label2; - + private ViewSwitcher switcherLoad; + private Context context; @Override public void onCreate(Bundle savedInstanceState) { @@ -88,27 +91,27 @@ public void onCreate(Bundle savedInstanceState) { ExecutorService executors = Executors.newSingleThreadExecutor(); executors.execute(() -> { try { - // if (OnlyNew | SecondIcon) { - prepareDataIPack(); //show only apps that arent in the selectable Icon Pack - // } else { - // prepareData(); //show all apps - // } + // if (OnlyNew | SecondIcon) { + prepareDataIPack(); //show only apps that arent in the selectable Icon Pack + // } else { + // prepareData(); //show all apps + // } } catch (Exception e) { e.printStackTrace(); } new Handler(Looper.getMainLooper()).post(() -> { - // if (OnlyNew | SecondIcon) { + // if (OnlyNew | SecondIcon) { - TextView chooser = (TextView)findViewById(R.id.text_ipack_chooser); - chooser.setText("Choose your first Icon Pack"); - populateView_Ipack(IPackListFilter,true); + TextView chooser = (TextView) findViewById(R.id.text_ipack_chooser); + chooser.setText("Choose your first Icon Pack"); + populateView_Ipack(IPackListFilter, true); - // } else { - // findViewById(R.id.text_ipack_chooser).setVisibility(View.GONE); - // populateView(appListFilter); - // } + // } else { + // findViewById(R.id.text_ipack_chooser).setVisibility(View.GONE); + // populateView(appListFilter); + // } switcherLoad.showNext(); }); }); @@ -120,11 +123,91 @@ public void onCreate(Bundle savedInstanceState) { // } //activityResultLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> actionSaveext(actionSave(), result)); } + public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_request_update, menu); return true; } + @Override + public boolean onOptionsItemSelected(MenuItem item) { + if (item.getItemId() == R.id.action_sharetext) { + actionSave(); + actionSendText(); + return true; + } else if (item.getItemId() == R.id.action_copy) { + actionSave(); + actionCopy(); + return true; + } else if (item.getItemId() == android.R.id.home) { + NavUtils.navigateUpFromSameTask(this); + return true; + } else { + super.onOptionsItemSelected(item); + return true; + } + } + + + private void actionCopy() { + ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); + ClipData clip = ClipData.newPlainText("Icon Request", xmlString); + clipboard.setPrimaryClip(clip); + makeToast("Your icon request has been saved to the clipboard."); + } + + private void actionSendText() { + Intent intent = new Intent(android.content.Intent.ACTION_SEND); + intent.setType("text/plain"); + intent.putExtra(Intent.EXTRA_TEXT, xmlString); + try { + startActivity(Intent.createChooser(intent, null)); + } catch (Exception e) { + makeToast(getString(R.string.no_email_clients)); + e.printStackTrace(); + } + } + + private String[] actionSave() { + + + + ArrayList arrayList = appListFilter; + StringBuilder stringBuilderEmail = new StringBuilder(); + StringBuilder stringBuilderXML = new StringBuilder(); + stringBuilderEmail.append(getString(R.string.request_email_text)); + int amount = 0; + ArrayList LabelList = new ArrayList<>(); + // process selected apps + for (int i = 0; i < arrayList.size(); i++) { + if (arrayList.get(i).selected) { + String iconName = arrayList.get(i).label + .replaceAll("[^a-zA-Z0-9 ]+", "") + .replaceAll("[ ]+", "_") + .toLowerCase(); + if (DEBUG) Log.i(TAG, "iconName: " + iconName); + + if (DEBUG) Log.i(TAG, "iconName: " + iconName); + //check if icon is in an arraylist if not add else rename and check again + stringBuilderEmail.append(arrayList.get(i).label).append("\n"); + stringBuilderXML.append("\t\n\t") + .append("\n\n"); + + } + } + + xmlString = stringBuilderXML.toString(); + //write files and create zip only when needed + + return new String[]{stringBuilderEmail.toString()}; + } + public void makeToast(String text) { Toast.makeText(context, text, Toast.LENGTH_SHORT).show(); } @@ -138,11 +221,9 @@ private void parseXML(String packageName, boolean firstrun) { iconPackres = pm.getResourcesForApplication(packageName); XmlPullParser xpp = null; int appfilterid = iconPackres.getIdentifier("appfilter", "xml", packageName); - if (appfilterid > 0) - { + if (appfilterid > 0) { xpp = iconPackres.getXml(appfilterid); - } - else { + } else { try { InputStream appfilterstream = iconPackres.getAssets().open("appfilter.xml"); @@ -270,12 +351,8 @@ private void prepareDataIPack() { ResolveInfo resolveInfo = localIterator.next(); iPackInfo ipackinfo = new iPackInfo(getHighResIcon(pm, resolveInfo), - //icon2, resolveInfo.loadLabel(pm).toString(), - resolveInfo.activityInfo.packageName, - // resolveInfo.activityInfo.name, - //todo remove unused data - false); + resolveInfo.activityInfo.packageName); arrayList.add(ipackinfo); } @@ -286,12 +363,8 @@ private void prepareDataIPack() { ResolveInfo resolveInfo = localIterator2.next(); iPackInfo ipackinfo = new iPackInfo(getHighResIcon(pm, resolveInfo), - //icon2, resolveInfo.loadLabel(pm).toString(), - resolveInfo.activityInfo.packageName, - // resolveInfo.activityInfo.name, - //todo remove unused data - false); + resolveInfo.activityInfo.packageName); if (!arrayList.contains(ipackinfo)) arrayList.add(ipackinfo); @@ -354,7 +427,7 @@ public boolean loadDataBool(String setting) { return sharedPreferences.getBoolean(setting, false); } - private void populateView_Ipack(ArrayList arrayListFinal,boolean firstrun) { + private void populateView_Ipack(ArrayList arrayListFinal, boolean firstrun) { ArrayList local_arrayList; local_arrayList = arrayListFinal; @@ -368,14 +441,14 @@ private void populateView_Ipack(ArrayList arrayListFinal,boolean firs ExecutorService executors = Executors.newSingleThreadExecutor(); executors.execute(() -> { try { - parseXML(ipackinfo.packageName,firstrun); + parseXML(ipackinfo.packageName, firstrun); if (DEBUG) Log.v(TAG, ipackinfo.packageName); - populateView_Ipack(IPackListFilter,false); - if (firstrun) Label1 = ipackinfo.label ; + populateView_Ipack(IPackListFilter, false); + if (firstrun) Label1 = ipackinfo.label; if (!firstrun) { - Label2 = ipackinfo.label ; + Label2 = ipackinfo.label; prepareData(); } @@ -384,22 +457,22 @@ private void populateView_Ipack(ArrayList arrayListFinal,boolean firs e.printStackTrace(); } - new Handler(Looper.getMainLooper()).post(() -> { - TextView chooser = (TextView) findViewById(R.id.text_ipack_chooser); - if (!firstrun) { + new Handler(Looper.getMainLooper()).post(() -> { + TextView chooser = (TextView) findViewById(R.id.text_ipack_chooser); + if (!firstrun) { //findViewById(R.id.text_ipack_chooser).setVisibility(View.GONE); populateView(appListFilter); invalidateOptionsMenu(); switcherLoad.showNext(); - chooser.setText("Unique Apps"+"\n"+Label1+": "+appListPack1.size()+"\n"+Label2+": "+appListPack2.size()); - }else { - switcherLoad.showPrevious(); + chooser.setText("Unique Apps" + "\n" + Label1 + ": " + appListPack1.size() + "\n" + Label2 + ": " + appListPack2.size()); + } else { + switcherLoad.showPrevious(); - chooser.setText("Choose your second Icon Pack"); - } + chooser.setText("Choose your second Icon Pack"); + } - }); + }); }); }); diff --git a/app/src/main/java/de/kaiserdragon/iconrequest/MainActivity.java b/app/src/main/java/de/kaiserdragon/iconrequest/MainActivity.java index f125891..6eb3ec0 100644 --- a/app/src/main/java/de/kaiserdragon/iconrequest/MainActivity.java +++ b/app/src/main/java/de/kaiserdragon/iconrequest/MainActivity.java @@ -36,7 +36,7 @@ protected void onCreate(Bundle savedInstanceState) { Button startUpdate = findViewById(R.id.start_update); startUpdate.setOnClickListener(view -> start(true)); - Button CompareIconPacks =findViewById(R.id.CompareIconPacks); + Button CompareIconPacks = findViewById(R.id.CompareIconPacks); CompareIconPacks.setOnClickListener(view -> startcompare()); Toolbar toolbar = findViewById(R.id.toolbar); @@ -58,6 +58,7 @@ public void start(boolean update) { intent.setComponent(new ComponentName(getPackageName(), getPackageName() + ".RequestActivity")); startActivity(intent); } + public void startcompare() { Intent intent = new Intent(Intent.ACTION_MAIN); //if (DEBUG) Log.v(TAG, String.valueOf(getAvailableIconPacks(true))); diff --git a/app/src/main/java/de/kaiserdragon/iconrequest/RequestActivity.java b/app/src/main/java/de/kaiserdragon/iconrequest/RequestActivity.java index 12be70f..a4dfe85 100644 --- a/app/src/main/java/de/kaiserdragon/iconrequest/RequestActivity.java +++ b/app/src/main/java/de/kaiserdragon/iconrequest/RequestActivity.java @@ -78,11 +78,12 @@ public class RequestActivity extends AppCompatActivity { private static final String TAG = "RequestActivity"; private static final int BUFFER = 2048; private static final boolean DEBUG = true; - private static ArrayList appListAll = new ArrayList<>(); + private static final ArrayList appListAll = new ArrayList<>(); private static String xmlString; private static boolean updateOnly; private static boolean OnlyNew; private static boolean SecondIcon; + private static boolean Shortcut; private static ArrayList appListFilter = new ArrayList<>(); private static ArrayList IPackListFilter = new ArrayList<>(); private String ImgLocation; @@ -211,6 +212,7 @@ public void onCreate(Bundle savedInstanceState) { updateOnly = getIntent().getBooleanExtra("update", false); OnlyNew = loadDataBool("SettingOnlyNew"); SecondIcon = loadDataBool("SettingRow"); + Shortcut = loadDataBool("Shortcut"); setContentView(R.layout.activity_request); switcherLoad = findViewById(R.id.viewSwitcherLoadingMain); @@ -220,7 +222,6 @@ public void onCreate(Bundle savedInstanceState) { ZipLocation = context.getFilesDir() + "/Icons"; - Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true); @@ -380,15 +381,17 @@ private String[] actionSave() { // delete old zips and recreate deleteDirectory(zipLocation); - imgLocation.mkdirs(); - zipLocation.mkdirs(); + if (!updateOnly) { + imgLocation.mkdirs(); + zipLocation.mkdirs(); + } ArrayList arrayList = appListFilter; StringBuilder stringBuilderEmail = new StringBuilder(); StringBuilder stringBuilderXML = new StringBuilder(); stringBuilderEmail.append(getString(R.string.request_email_text)); int amount = 0; - ArrayList LabelList = new ArrayList(); + ArrayList LabelList = new ArrayList<>(); // process selected apps for (int i = 0; i < arrayList.size(); i++) { if (arrayList.get(i).selected) { @@ -430,35 +433,33 @@ private String[] actionSave() { } } } -//todo why name it here not static SimpleDateFormat date = new SimpleDateFormat("ddMMyyyy_HHmmss", Locale.US); String zipName = date.format(new Date()); xmlString = stringBuilderXML.toString(); //write files and create zip only when needed if (!updateOnly) { - if (amount == 0) { - // no apps are selected - makeToast(getString(R.string.request_toast_no_apps_selected)); - } else { - // write zip and start email intent - try { - FileWriter fstream = new FileWriter(ImgLocation + "/appfilter.xml"); - BufferedWriter out = new BufferedWriter(fstream); - out.write(stringBuilderXML.toString()); - out.close(); - } catch (Exception e) { - e.printStackTrace(); - } -//todo check what this does keepDirectoryStructure - createZipFile(ImgLocation, true, ZipLocation + "/" + zipName + ".zip"); + if (amount == 0) { + // no apps are selected + makeToast(getString(R.string.request_toast_no_apps_selected)); + } else { + // write zip and start email intent + try { + FileWriter fstream = new FileWriter(ImgLocation + "/appfilter.xml"); + BufferedWriter out = new BufferedWriter(fstream); + out.write(stringBuilderXML.toString()); + out.close(); + } catch (Exception e) { + e.printStackTrace(); + } + createZipFile(ImgLocation, true, ZipLocation + "/" + zipName + ".zip"); - // delete all generated files except the zip - deleteDirectory(imgLocation); - if (updateOnly) { - deleteDirectory(zipLocation); + // delete all generated files except the zip + deleteDirectory(imgLocation); + if (updateOnly) { + deleteDirectory(zipLocation); + } } } - } return new String[]{zipName, stringBuilderEmail.toString()}; } @@ -480,11 +481,9 @@ private void parseXML(String packageName) { iconPackres = pm.getResourcesForApplication(packageName); XmlPullParser xpp = null; int appfilterid = iconPackres.getIdentifier("appfilter", "xml", packageName); - if (appfilterid > 0) - { + if (appfilterid > 0) { xpp = iconPackres.getXml(appfilterid); - } - else { + } else { try { InputStream appfilterstream = iconPackres.getAssets().open("appfilter.xml"); XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); @@ -548,8 +547,15 @@ private void prepareData() { // sort the apps ArrayList arrayList = new ArrayList<>(); PackageManager pm = getPackageManager(); - Intent intent = new Intent("android.intent.action.MAIN", null); - intent.addCategory("android.intent.category.LAUNCHER"); + Intent intent; + if (Shortcut){ + intent = new Intent("android.intent.action.CREATE_SHORTCUT", null); + intent.addCategory("android.intent.category.DEFAULT"); + }else{ + intent = new Intent("android.intent.action.MAIN", null); + intent.addCategory("android.intent.category.LAUNCHER"); + } + List list = pm.queryIntentActivities(intent, 0); Iterator localIterator = list.iterator(); if (DEBUG) Log.v(TAG, "list size: " + list.size()); @@ -566,13 +572,9 @@ private void prepareData() { if (SecondIcon) { Drawable icon2 = null; - if (appListAll.contains(appInfo)) {//check if the list contains the element - //int o = appListAll.indexOf((appInfo)); - //if (DEBUG) Log.v(TAG, String.valueOf(o)); - AppInfo geticon = appListAll.get(appListAll.indexOf(appInfo));//get the element by passing the index of the element - //if (DEBUG) Log.v(TAG, "label" + String.valueOf(geticon.label)); + if (appListAll.contains(appInfo)) { //check if the list contains the element + AppInfo geticon = appListAll.get(appListAll.indexOf(appInfo)); //get the element by passing the index of the element icon2 = geticon.icon; - // if (DEBUG) Log.v(TAG,"iconwert" + String.valueOf(icon2)); } appInfo = new AppInfo(icon1, icon2, @@ -621,12 +623,8 @@ private void prepareDataIPack() { ResolveInfo resolveInfo = localIterator.next(); iPackInfo ipackinfo = new iPackInfo(getHighResIcon(pm, resolveInfo), - //icon2, resolveInfo.loadLabel(pm).toString(), - resolveInfo.activityInfo.packageName, - // resolveInfo.activityInfo.name, - //todo remove unused data - false); + resolveInfo.activityInfo.packageName); arrayList.add(ipackinfo); } @@ -638,12 +636,9 @@ private void prepareDataIPack() { ResolveInfo resolveInfo = localIterator2.next(); iPackInfo ipackinfo = new iPackInfo(getHighResIcon(pm, resolveInfo), - //icon2, resolveInfo.loadLabel(pm).toString(), - resolveInfo.activityInfo.packageName, - // resolveInfo.activityInfo.name, - //todo remove unused data - false); + resolveInfo.activityInfo.packageName + ); if (!arrayList.contains(ipackinfo)) arrayList.add(ipackinfo); @@ -689,8 +684,6 @@ private Drawable getHighResIcon(PackageManager pm, ResolveInfo resolveInfo) { } catch (PackageManager.NameNotFoundException e) { //fails return the normal icon return resolveInfo.loadIcon(pm); - } catch (Resources.NotFoundException e) { - return resolveInfo.loadIcon(pm); } } diff --git a/app/src/main/java/de/kaiserdragon/iconrequest/SettingActivity.java b/app/src/main/java/de/kaiserdragon/iconrequest/SettingActivity.java index 7f47678..1b3d7c3 100644 --- a/app/src/main/java/de/kaiserdragon/iconrequest/SettingActivity.java +++ b/app/src/main/java/de/kaiserdragon/iconrequest/SettingActivity.java @@ -22,13 +22,13 @@ protected void onCreate(Bundle savedInstanceState) { switch (loadData("DarkModeState")) { case -1: - ((RadioGroup) findViewById(R.id.radioGroup)).check(R.id.radioDefault); + ((RadioGroup) findViewById(R.id.RadioTheme)).check(R.id.radioDefault); break; case 1: - ((RadioGroup) findViewById(R.id.radioGroup)).check(R.id.radioLight); + ((RadioGroup) findViewById(R.id.RadioTheme)).check(R.id.radioLight); break; case 2: - ((RadioGroup) findViewById(R.id.radioGroup)).check(R.id.radioDark); + ((RadioGroup) findViewById(R.id.RadioTheme)).check(R.id.radioDark); break; } @@ -51,6 +51,9 @@ protected void onCreate(Bundle savedInstanceState) { CheckBox OnlyNew = findViewById(R.id.checkBoxOnly); OnlyNew.setOnClickListener(view -> start(view, 0)); + CheckBox Shortcut = findViewById(R.id.checkShortcut); + Shortcut.setOnClickListener(view -> start(view, 0)); + Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true); @@ -66,6 +69,9 @@ public void start(View view, int update) { } else if (view == (CheckBox) findViewById(R.id.checkBoxOnly)) { saveDataBool("SettingOnlyNew", ((CheckBox) view).isChecked()); } + else if (view == (CheckBox) findViewById(R.id.checkShortcut)) { + saveDataBool("Shortcut", ((CheckBox) view).isChecked()); + } } } diff --git a/app/src/main/java/de/kaiserdragon/iconrequest/iPackInfo.java b/app/src/main/java/de/kaiserdragon/iconrequest/iPackInfo.java index 4d0bc4a..ac4348a 100644 --- a/app/src/main/java/de/kaiserdragon/iconrequest/iPackInfo.java +++ b/app/src/main/java/de/kaiserdragon/iconrequest/iPackInfo.java @@ -5,28 +5,28 @@ public class iPackInfo { public Drawable icon; public String label; - public boolean selected; String packageName; - String className; - iPackInfo(Drawable icon, String label, String packageName, boolean selected) { + iPackInfo(Drawable icon, String label, String packageName) { this.icon = icon; this.label = label; this.packageName = packageName; - this.selected = selected; } - public String getCode() { - return packageName + "/" + className; - } - @Override - public boolean equals(Object object) { - if (object instanceof iPackInfo) { + + public String getCode() { + return packageName; + } + @Override + public boolean equals(Object object) { + if (object instanceof iPackInfo) { iPackInfo ipackinfo = (iPackInfo) object; return this.getCode().equals(ipackinfo.getCode()); - } - return false; - } + } + return false; + } + + } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index ad3f3a4..86c6d09 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -4,92 +4,103 @@ android:layout_height="match_parent" android:gravity="center_horizontal" android:orientation="vertical" + android:isScrollContainer="true" tools:context="de.kaiserdragon.iconrequest.MainActivity"> + - + - + -