Skip to content

Commit

Permalink
Cleaned up the code; implement #1, fix #11
Browse files Browse the repository at this point in the history
  • Loading branch information
HenriDellal committed Nov 18, 2017
1 parent 38eb443 commit fda6b36
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 128 deletions.
27 changes: 12 additions & 15 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,14 @@

<activity android:name=".AboutActivity" android:label="@string/aboutTitle">
</activity>
<activity android:name=".TutorialActivity" android:label="@string/how_to_use">
</activity>
<activity android:name=".CategoryManagerActivity" android:label="@string/categoryManager">
<!-- android:theme="@style/AppTheme.Preferences.Light"-->
</activity>
<activity android:name=".Options" android:label="@string/launcherSettings">
<!-- android:theme="@style/AppTheme.Preferences.Light"-->
<!--<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>-->
</activity>
<!--
-->
<activity android:name=".Apps"
android:resizeableActivity="false"
android:excludeFromRecents="true"
Expand All @@ -48,15 +46,14 @@
</intent-filter>

</activity>
<receiver android:name="DirtinessReceiver">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_INSTALL"/>
<action android:name="android.intent.action.PACKAGE_ADDED"/>
<action android:name="android.intent.action.PACKAGE_REMOVED"/>
<action android:name="android.intent.action.PACKAGE_REPLACED"/>
<data android:scheme="package"/>
</intent-filter>
<receiver android:name="DirtinessReceiver">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_INSTALL"/>
<action android:name="android.intent.action.PACKAGE_ADDED"/>
<action android:name="android.intent.action.PACKAGE_REMOVED"/>
<action android:name="android.intent.action.PACKAGE_REPLACED"/>
<data android:scheme="package"/>
</intent-filter>
</receiver>

</application>
</manifest>
22 changes: 22 additions & 0 deletions res/layout/tutorial.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:text="@string/tutorial"
android:textColor="#fff"/>
<Button
android:id="@+id/close_tutorial"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/close_tutorial"
/>
</LinearLayout>
</ScrollView>
15 changes: 15 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@
<string name="uninstall">Uninstall</string>

<string name="aboutTitle">About</string>
<string name="how_to_use">How to use</string>
<string name="close_tutorial">Close tutorial</string>
<string name="tutorial">Swipe on the category name to switch to the next/previous category. Click on it to see the full list of categories.
\n
\nOpen Launcher settings/Category manager to edit categories.
\n
\nClick on the search button to search through all apps (except hidden). To search in the web, open search, type ... and click an arrow at the right of the text field.
\n
\nLong-press an app icon to open the popup menu.
\n
\nPress Home button to open home category. Press once again to open all apps list.
\n
\nPress Back button to switch to the previously opened category.
</string>

<string name="about" translatable="false">Emerald Launcher
\n
\nCopyright 2017 Anri Dellal
Expand Down
38 changes: 23 additions & 15 deletions src/ru/henridellal/emerald/Apps.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package ru.henridellal.emerald;

import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
Expand All @@ -26,11 +24,8 @@
import android.content.res.Configuration;
//import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.Bitmap;
import android.graphics.Point;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.AsyncTask.Status;
Expand All @@ -49,7 +44,7 @@
import android.view.Display;
import android.view.inputmethod.InputMethodManager;
import android.view.KeyEvent;
import android.view.KeyCharacterMap;
//import android.view.KeyCharacterMap;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
Expand All @@ -66,7 +61,7 @@
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.SectionIndexer;
//import android.widget.SectionIndexer;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
Expand Down Expand Up @@ -436,7 +431,6 @@ public void onMenuButton(View v) {
public void searchInWeb(String text) {
String site = options.getString(Options.PREF_SEARCH_PROVIDER, "https://duckduckgo.com/?q=");
String url = site + text;
//String url = text;
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
try {
Expand All @@ -458,7 +452,6 @@ public void openSearch() {
final EditText text = (EditText)findViewById(R.id.textField);
text.setVisibility(View.VISIBLE);
findViewById(R.id.webSearchButton).setVisibility(View.VISIBLE);
//grid.setTextFilterEnabled(true);
if (dock.isVisible()) {
dock.hide();
}
Expand Down Expand Up @@ -575,15 +568,27 @@ private void setBarTheme(int theme) {
case Options.DEFAULT_THEME:
case Options.LIGHT:
case Options.WALLPAPER_LIGHT:
menuButton.setBackground(getResources().getDrawable(R.drawable.menu_bg));
searchButton.setBackground(getResources().getDrawable(R.drawable.search_bg));
webSearchButton.setBackground(getResources().getDrawable(R.drawable.web_search_bg));
if (Build.VERSION.SDK_INT >= 16) {
menuButton.setBackground(getResources().getDrawable(R.drawable.menu_bg));
searchButton.setBackground(getResources().getDrawable(R.drawable.search_bg));
webSearchButton.setBackground(getResources().getDrawable(R.drawable.web_search_bg));
} else {
menuButton.setBackgroundDrawable(getResources().getDrawable(R.drawable.menu_bg));
searchButton.setBackgroundDrawable(getResources().getDrawable(R.drawable.search_bg));
webSearchButton.setBackgroundDrawable(getResources().getDrawable(R.drawable.web_search_bg));
}
searchField.setTextColor(Color.WHITE);
break;
default:
menuButton.setBackground(getResources().getDrawable(R.drawable.menu_dark_bg));
searchButton.setBackground(getResources().getDrawable(R.drawable.search_dark_bg));
webSearchButton.setBackground(getResources().getDrawable(R.drawable.web_search_dark_bg));
if (Build.VERSION.SDK_INT >= 16) {
menuButton.setBackground(getResources().getDrawable(R.drawable.menu_dark_bg));
searchButton.setBackground(getResources().getDrawable(R.drawable.search_dark_bg));
webSearchButton.setBackground(getResources().getDrawable(R.drawable.web_search_dark_bg));
} else {
menuButton.setBackgroundDrawable(getResources().getDrawable(R.drawable.menu_dark_bg));
searchButton.setBackgroundDrawable(getResources().getDrawable(R.drawable.search_dark_bg));
webSearchButton.setBackgroundDrawable(getResources().getDrawable(R.drawable.web_search_dark_bg));
}
searchField.setTextColor(Color.BLACK);
}
}
Expand Down Expand Up @@ -676,6 +681,9 @@ public void onCreate(Bundle savedInstanceState) {
//Log.v(APP_TAG, "onCreate");
super.onCreate(savedInstanceState);
options = PreferenceManager.getDefaultSharedPreferences(this);
if (options.getBoolean(Options.SHOW_TUTORIAL, true)) {
startActivity(new Intent(this, TutorialActivity.class));
}
if (Build.VERSION.SDK_INT >= 11 && options.getBoolean("keepInMemory", false)) {
Notification noti = new Notification.Builder(this)
.setContentTitle("Emerald")
Expand Down
2 changes: 1 addition & 1 deletion src/ru/henridellal/emerald/BackupPreference.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public BackupPreference(Context c, AttributeSet attr) {
}
@Override
protected View onCreateDialogView() {
dialog = new FileLoaderDialog(getContext(), getKey().equals("backup")? 0:1);
dialog = new FileLoaderDialog(this, getContext(), getKey().equals("backup")? 0:1);
return(dialog);
}

Expand Down
20 changes: 15 additions & 5 deletions src/ru/henridellal/emerald/FileLoaderDialog.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package ru.henridellal.emerald;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Build;
import android.os.Environment;
import android.view.View;
import android.widget.ListView;
Expand All @@ -16,13 +14,19 @@
import android.widget.Button;
import android.widget.BaseAdapter;
import android.widget.AdapterView;
//required by permissions checker
import android.app.Activity;
import android.Manifest;
import android.content.pm.PackageManager;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.io.File;
import java.io.FileFilter;

import android.preference.DialogPreference;

public class FileLoaderDialog extends ListView
//implements DialogInterface.OnClickListener
{
Expand Down Expand Up @@ -66,10 +70,16 @@ public boolean accept(File f) {
Collections.addAll(files, fileArray);
}

public FileLoaderDialog(Context context, int mode)
public FileLoaderDialog(DialogPreference preference, Context context, int mode)
{
super(context);
//fileList = (ListView)findViewById(R.id.file_list);
// request runtime permissions (Marshmallow+)
if (Build.VERSION.SDK_INT >= 23) {
if ((context.checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED)
|| (context.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED)) {
((Options)context).requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0);
}
}
curDirectory = Environment.getExternalStorageDirectory();
setFileList(curDirectory);
this.mode = mode;
Expand Down
24 changes: 5 additions & 19 deletions src/ru/henridellal/emerald/IconPackManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public Resources getResources() {
}
public IconPackManager(Context context, String iconPack) {
this.context = context;
iconsData = new HashMap<String, String>();
setIconPack(iconPack);
}
public Map<String, String> getIcons() {
Expand All @@ -61,29 +60,12 @@ public void setIconPack(String iconPackName) {
setIcons();
}
private Bitmap loadBitmap(String drawableName) {

int id = iconPackRes.getIdentifier(drawableName, "drawable", iconPackName);
if (id > 0)
/*
return getActivities(null, Process.myUserHandle()).get(0).get();
*/
return ((BitmapDrawable)iconPackRes.getDrawable(id)).getBitmap();
else
return null;
}
/*public Bitmap resizeBitmap(Bitmap b) {
int w = b.getWidth();
int h = b.getHeight();
Bitmap base = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(base);
Bitmap bitmap = Bitmap.createScaledBitmap(b, (int)(w*factor), (int)(h*factor), false);
base.eraseColor(0);
//canvas.drawBitmap(b, w*(1-factor)/2, h*(1-factor)/2, new Paint(Paint.ANTI_ALIAS_FLAG));
canvas.drawBitmap(b, 0, 0, new Paint(Paint.ANTI_ALIAS_FLAG));
return base;
}*/
/* Returns Bitmap for default icon pack.
* Includes code for retrieving Oreo+ adaptive icons.
* Credits to Vishnu Prasad:
Expand Down Expand Up @@ -112,6 +94,9 @@ public Bitmap getDefaultBitmap(Drawable d) {
int defaultHeight = (int)(48* density);
return Bitmap.createBitmap(defaultWidth, defaultHeight, Bitmap.Config.ARGB_8888);
}
/* transforms an Drawable object to Bitmap
* and adds effects from icon pack
*/
public Bitmap transformDrawable(Drawable d) {
Bitmap b = getDefaultBitmap(d);
if ((iconBacks == null && iconMask == null && iconUpon == null && factor == 1.f) || !transformDrawable)
Expand All @@ -134,7 +119,6 @@ public Bitmap transformDrawable(Drawable d) {
}
Bitmap result = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(result);
//Paint paint = new Paint();
if (iconBacks != null) {
if (iconBacks.size() > 0) {
canvas.drawBitmap(iconBacks.get((int)(Math.random()*iconBacks.size())), 0, 0, null);
Expand All @@ -161,6 +145,7 @@ public Bitmap getBitmap(String component) {
return null;
}
}
/* used by Options class to list all icon packs available*/
public Map<String, String> getIconPacks() {
Map<String, String> iconPacks = new HashMap<String, String>();
PackageManager pm = context.getPackageManager();
Expand Down Expand Up @@ -193,6 +178,7 @@ public static void setIcon(Context c, ImageView img, AppData a) {
img.setImageResource(android.R.drawable.sym_def_app_icon);
}
}
/* sets icons data */
public void setIcons() {
iconsData = new HashMap<String, String>();
iconBacks = null;
Expand Down
36 changes: 2 additions & 34 deletions src/ru/henridellal/emerald/MyCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,12 @@
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;

import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.util.Log;

Expand Down Expand Up @@ -66,30 +58,6 @@ static public String genFilename(Context c, String name) {
File dir = c.getCacheDir();
return dir.getPath() + "/" + name + ".MyCache";
}
public static void saveIcon(Context c, String componentName) {
if (componentName.startsWith(" "))
return;

deleteIcon(c, componentName);
try {
ComponentName cn = ComponentName.unflattenFromString(componentName);
String packageName = cn.getPackageName();
PackageManager pm = c.getPackageManager();
Resources res = pm.getResourcesForActivity(cn);
Drawable icon = res.getDrawable(pm.getPackageInfo(packageName, 0).applicationInfo.icon);
if (icon instanceof BitmapDrawable) {
Bitmap bmp = ((BitmapDrawable)icon).getBitmap();
// Log.v("TinyLaunch", "icon "+bmp.getWidth()+"x"+bmp.getHeight());
File iconFile = getIconFile(c, componentName);
FileOutputStream out = new FileOutputStream(iconFile);
bmp.compress(CompressFormat.PNG, 100, out);
out.close();
// Log.v("TinyLaunch", "saved icon");
}
} catch (Exception e) {
deleteIcon(c, componentName);
}
}
public static File getIconFile(Context c, String componentName) {
return new File(c.getCacheDir(),
Uri.encode(componentName)+".icon.png");
Expand All @@ -102,7 +70,7 @@ public static void deleteIcon(Context c, String componentName) {
// Log.v("TinyLaunch", "successful delete of "+componentName+" icon");
}
}

/* removes icons of deleted apps */
public static void cleanIcons(Context c, ArrayList<AppData> data) {
ArrayList<String> components = new ArrayList<String>();
for (AppData a : data)
Expand All @@ -116,7 +84,7 @@ public static void cleanIcons(Context c, ArrayList<AppData> data) {
f.delete();
}
}

/* removes all icons in cache */
public static void deleteIcons(Context c) {
File[] dirs = c.getCacheDir().listFiles();

Expand Down
Loading

0 comments on commit fda6b36

Please sign in to comment.