Skip to content

Commit

Permalink
Added icon search
Browse files Browse the repository at this point in the history
  • Loading branch information
ukanth committed Jul 23, 2019
1 parent fb694c1 commit ff1a03b
Show file tree
Hide file tree
Showing 11 changed files with 339 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ android {
defaultConfig {
applicationId "dev.ukanth.iconmanager"
minSdkVersion 19
targetSdkVersion 27
targetSdkVersion 28
versionCode 3000
versionName "3.0.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
buildConfigField "boolean", "LICENSECHECK", "false"
buildConfigField "boolean", "LICENSECHECK", "true"
}

compileOptions {
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,17 @@
android:value="dev.ukanth.iconmgr.MainActivity" />
</activity>

<activity
android:name=".IconSearchActivity"
android:parentActivityName=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="dev.ukanth.iconmgr.MainActivity" />
</activity>

<receiver android:name=".ApplyActionReceiver">
</receiver>

Expand Down
33 changes: 33 additions & 0 deletions app/src/main/java/dev/ukanth/iconmgr/IconPackUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ public HashMap<String, List<Bitmap>> getIconsList(Context mContext, String packa
return list;
}




public Set<Icon> getListIcons(String packageName) {
Set<Icon> icons = new HashSet<>();
Key key = Key.ACTIVITY;
Expand Down Expand Up @@ -277,6 +280,36 @@ public Set<Icon> getListIcons(String packageName) {
return icons;
}

public Set<Icon> getFilterIcons(String packageName,String query) {
Set<Icon> icons = new HashSet<>();
Key key = Key.ACTIVITY;
List<Attrb> items = new ArrayList<>();
try {
XmlPullParser xpp = getXmlParser(packageName, "appfilter");
while (xpp.getEventType() != XmlPullParser.END_DOCUMENT) {
if (xpp.getEventType() == XmlPullParser.START_TAG) {
if (xpp.getName().equals("item")) {
String sKey = xpp.getAttributeValue(null, key.getKey());
if (sKey != null) {
sKey = sKey.replace("ComponentInfo{", "").replace("}", "");
if (sKey != null) {
String name = xpp.getAttributeValue(null, "drawable");
if (name != null && name.contains(query)) {
items.add(new Attrb(sKey, name));
}
}
}
}
}
xpp.next();
}
icons = processXpp(packageName, items);
} catch (Exception e) {
Log.e("MICO", e.getMessage(), e);
}
return icons;
}

private Bitmap generateBitmap(Bitmap defaultBitmap, List mBackImages, Paint mPaint, Bitmap mMaskImage, Bitmap mFrontImage, String packageName) {
// No need to go through below process id defaultBitmap is null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ private void saveImage(Icon icon, String packageName) {
file.delete();
try {
FileOutputStream out = new FileOutputStream(file);
icon.getIconBitmap().compress(Bitmap.CompressFormat.PNG, 100, out);
icon.getIconBitmap().compress(Bitmap.CompressFormat.PNG, 85, out);
out.flush();
out.close();
Toast.makeText(getApplicationContext(), "Saved successfully: " + file.getAbsolutePath(), Toast.LENGTH_SHORT).show();
Expand Down
232 changes: 232 additions & 0 deletions app/src/main/java/dev/ukanth/iconmgr/IconSearchActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
package dev.ukanth.iconmgr;

import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.DisplayMetrics;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.GridLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.SearchView;

import com.afollestad.materialdialogs.MaterialDialog;
import com.glidebitmappool.GlideBitmapPool;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import dev.ukanth.iconmgr.dao.DaoSession;
import dev.ukanth.iconmgr.dao.IPObj;
import dev.ukanth.iconmgr.dao.IPObjDao;

/**
* Created by ukanth on 3/9/17.
*/

public class IconSearchActivity extends AppCompatActivity {

private MaterialDialog plsWait;

private LinearLayout.LayoutParams params;

private GridLayout gridLayout;
private List<IPObj> objList;

private SearchView mSearchView;

@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);

MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_search, menu);
MenuItem searchItem = menu.findItem(R.id.i_search);
mSearchView = (SearchView) searchItem.getActionView();
setupSearchView(searchItem);

return true;
}

private void setupSearchView(MenuItem searchItem) {
mSearchView.setIconifiedByDefault(false);
mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String s) {
gridLayout.removeAllViews();
searchIcons(s);
return false;
}

@Override
public boolean onQueryTextChange(String s) {
if (s.length() == 0) {
gridLayout.removeAllViews();
}
return false;
}
});
}


@Override
protected void onCreate(Bundle savedInstanceState) {

if (Prefs.isDarkTheme()) {
setTheme(R.style.AppTheme_Dark);
} else {
setTheme(R.style.AppTheme_Light);
}

GlideBitmapPool.initialize(10 * 1024 * 1024);


super.onCreate(savedInstanceState);
setContentView(R.layout.iconsearch);


gridLayout = (GridLayout) findViewById(R.id.iconsearchpreview);
int colNumber = 4;
gridLayout.setColumnCount(colNumber);

DisplayMetrics metrics = getResources().getDisplayMetrics();
int screenWidth = metrics.widthPixels;
params = new LinearLayout.LayoutParams(screenWidth / colNumber, screenWidth / colNumber);

//SearchView searchView = findViewById(R.id.search);


App app = ((App) getApplicationContext());
DaoSession daoSession = app.getDaoSession();
IPObjDao ipObjDao = daoSession.getIPObjDao();

objList = ipObjDao.loadAll();


}

private void searchIcons(String query) {
if (!query.isEmpty()) {
query = query.toLowerCase();
}
IconsPreviewLoader previewLoader = new IconsPreviewLoader(IconSearchActivity.this, query);
if (plsWait == null && (previewLoader.getStatus() == AsyncTask.Status.PENDING ||
previewLoader.getStatus() == AsyncTask.Status.FINISHED)) {
previewLoader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}

@Override
public void onResume() {
super.onResume();
}

@Override
protected void onPause() {
super.onPause();
}

@Override
protected void onDestroy() {
super.onDestroy();
}


private class IconsPreviewLoader extends AsyncTask<Void, Void, Boolean> {

private Context mContext;
private String query;
private List<Icon> themed_icons = new ArrayList<>();

private IconsPreviewLoader(Context context, String query) {
this.query = query;
this.mContext = context;
}

@Override
protected void onPreExecute() {
plsWait = new MaterialDialog.Builder(mContext).cancelable(false).title(mContext.getString(R.string.searching)).content(R.string.please_wait_normal).progress(true, 0).show();
}

@Override
protected Boolean doInBackground(Void... voids) {
while (!isCancelled()) {
try {
IconPackUtil packUtil = new IconPackUtil();
for (IPObj obj : objList) {
themed_icons.addAll(packUtil.getFilterIcons(obj.getIconPkg(), query));
}
return true;
} catch (Exception e) {
return false;
}
}
return false;
}

@Override
protected void onPostExecute(Boolean aBoolean) {
super.onPostExecute(aBoolean);

try {
if (plsWait != null && plsWait.isShowing()) {
plsWait.dismiss();
}
} catch (final IllegalArgumentException e) {
// Handle or log or ignore
} catch (final Exception e) {
// Handle or log or ignore
} finally {
plsWait.dismiss();
plsWait = null;
}

gridLayout.removeAllViews();

if (themed_icons != null) {
List<Icon> list = new ArrayList<Icon>(themed_icons);
if (list != null && list.size() > 0) {
Collections.sort(list, (o1, o2) -> String.CASE_INSENSITIVE_ORDER.compare(o1.getTitle(), o2.getTitle()));

for (final Icon icon : list) {
if (icon.getIconBitmap() != null) {
ImageView image = new ImageView(mContext);
image.setLayoutParams(params);
image.setPadding(15, 15, 15, 15);
image.setScaleType(ImageView.ScaleType.FIT_CENTER);
image.setImageDrawable(new BitmapDrawable(getResources(), icon.getIconBitmap()));
image.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new MaterialDialog.Builder(mContext)
.title(icon.getTitle())
.positiveText(R.string.save)
.onPositive((dialog, which) -> {

})
.negativeText(R.string.close)
.icon(new BitmapDrawable(getResources(), icon.getIconBitmap()))
.show();
}
});
image.setOnLongClickListener(view -> {

return true;
});
gridLayout.addView(image);
}
}
GlideBitmapPool.clearMemory();
//processInputs(list, res, params, gridLayout);
} else {
}
}
}
}
}
9 changes: 9 additions & 0 deletions app/src/main/java/dev/ukanth/iconmgr/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.ukanth.iconmgr;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
Expand Down Expand Up @@ -435,6 +436,9 @@ public boolean onOptionsItemSelected(MenuItem item) {
case R.id.pref:
showPreference();
return true;
case R.id.iconsearch:
showIconSearch();
return true;
case R.id.about:
showAbout();
return true;
Expand Down Expand Up @@ -506,6 +510,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
}
}

private void showIconSearch() {
Intent myIntent = new Intent(MainActivity.this, IconSearchActivity.class);
startActivity(myIntent);
}

private void reload() {
Collections.sort(iconPacksList, new PackageComparator());
adapter = new IconAdapter(iconPacksList, installed);
Expand Down
27 changes: 27 additions & 0 deletions app/src/main/res/layout/iconsearch.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">


<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/iconsearchpreview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="auto_fit"
android:orientation="horizontal"></GridLayout>

</RelativeLayout>
</ScrollView>
</RelativeLayout>
6 changes: 6 additions & 0 deletions app/src/main/res/menu/main_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@
</group>
</menu>
</item>

<item
android:id="@+id/iconsearch"
android:title="@string/icon_search"
app:showAsAction="collapseActionView" />

<item
android:id="@+id/pref"
android:title="@string/preferences"
Expand Down
Loading

0 comments on commit ff1a03b

Please sign in to comment.