Skip to content

Commit

Permalink
Bug fixes and minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
HenriDellal committed Mar 23, 2018
1 parent 6403e90 commit c95a18d
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 94 deletions.
4 changes: 2 additions & 2 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="33"
android:versionName="0.5.6" package="ru.henridellal.emerald"
android:versionCode="34"
android:versionName="0.5.6.1" package="ru.henridellal.emerald"
>

<!--android:configChanges="keyboard|keyboardHidden|orientation|screenSize"-->
Expand Down
2 changes: 1 addition & 1 deletion res/layout/main_bar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:visibility="gone"
android:textSize="14sp"
android:textSize="18sp"
android:layout_alignParentLeft="true"
android:layout_toStartOf="@id/searchBar"
android:layout_toLeftOf="@id/webSearchButton" />
Expand Down
3 changes: 2 additions & 1 deletion res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<string name="launcherSettings">Launcher settings</string>

<string name="createCategory">Create category</string>
<string name="note_rename_error">Name is already in use</string>
<string name="rename">Rename</string>
<string name="editAppList">Edit application list</string>
<string name="findInMarket">Find in app market</string>
Expand Down Expand Up @@ -87,7 +88,7 @@
<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.
<string name="tutorial">Swipe left/right on the apps menu to switch to the next/previous category. Click on the category name to see the categories list.
\n
\nOpen Launcher settings/Category manager to edit categories.
\n
Expand Down
54 changes: 33 additions & 21 deletions src/ru/henridellal/emerald/Apps.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.Configuration;
import android.graphics.Color;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.AsyncTask.Status;
Expand All @@ -31,6 +30,7 @@
import android.text.InputType;
import android.text.TextWatcher;
//import android.util.Log;
import android.view.GestureDetector;
import android.view.inputmethod.InputMethodManager;
import android.view.LayoutInflater;
import android.view.KeyEvent;
Expand All @@ -39,20 +39,18 @@
import android.view.MenuItem;
import android.view.View;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

public class Apps extends Activity
{
private GestureDetector gestureDetector;
private CategoryManager categories;
private ArrayList<AppData> curCatData;
private RelativeLayout mainLayout;
Expand All @@ -62,10 +60,10 @@ public class Apps extends Activity
public SharedPreferences options;
public static final String PREF_APPS = "apps";
public static final String APP_TAG = "Emerald";
private CustomAdapter adapter = null;
private CustomAdapter adapter;
public static final int GRID = 0;
public static final int LIST = 1;
private GetApps scanner = null;
private GetApps scanner;
private OnSharedPreferenceChangeListener prefListener;
private boolean lock, returnToHome, searchIsOpened, homeButtonPressed, modPressed;
private int historySize;
Expand Down Expand Up @@ -158,15 +156,16 @@ private void addInHistory(AppData a) {
//removes app from history if it is already in it
// to avoid duplicating
//Log.v(APP_TAG, "Add app in history");
if (categories.getCategoryData(CategoryManager.HISTORY).indexOf(a) != -1) {
categories.removeFromCategory(CategoryManager.HISTORY, a);
}

categories.addToHistory(a);
//removes old entries if History has maximum size
if (categories.getCategoryData(CategoryManager.HISTORY).size() > historySize) {
categories.removeFromCategory(CategoryManager.HISTORY, categories.getCategoryData(CategoryManager.HISTORY).size()-1);
}
if (!dock.hasApp(a)) {
if (categories.getCategoryData(CategoryManager.HISTORY).indexOf(a) != -1) {
categories.removeFromCategory(CategoryManager.HISTORY, a);
}
categories.addToHistory(a);
//removes old entries if History has maximum size
if (categories.getCategoryData(CategoryManager.HISTORY).size() > historySize) {
categories.removeFromCategory(CategoryManager.HISTORY, categories.getCategoryData(CategoryManager.HISTORY).size()-1);
}
}
}
//launches app and adds it to history
public void launch(AppData a) {
Expand All @@ -190,10 +189,13 @@ private void openCategoriesList() {
builder.setCancelable(true);
final ArrayList<String> cats = new ArrayList<String>(categories.getCategories());
cats.remove(CategoryManager.HIDDEN);
ArrayList<String> toRemove = new ArrayList<String>();
for (String category: cats) {
if (categories.getCategory(category).isHidden())
cats.remove(category);
toRemove.add(category);
}
cats.removeAll(toRemove);
toRemove = null;
final ArrayList<String> categoriesNames = new ArrayList<String>(cats.size());
for (String category: cats) {
categoriesNames.add(categories.getCategory(category).getRepresentName(this));
Expand Down Expand Up @@ -457,6 +459,12 @@ public void onMyClick(View v) {
}
}

@Override
public boolean dispatchTouchEvent(MotionEvent event) {
gestureDetector.onTouchEvent(event);
return super.dispatchTouchEvent(event);
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_MENU) {
Expand Down Expand Up @@ -494,10 +502,10 @@ public boolean onKeyDown(int keyCode, KeyEvent event) {
} else if (keyCode == KeyEvent.KEYCODE_0 && !searchIsOpened) {
openSearch();
} else if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {
categories.setCurCategory(categories.getPrevCategory());
categories.setCurCategory(categories.getCategory(CategoryManager.PREVIOUS));
loadFilteredApps();
} else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
categories.setCurCategory(categories.getNextCategory());
categories.setCurCategory(categories.getCategory(CategoryManager.NEXT));
loadFilteredApps();
} else if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
openCategoriesList();
Expand Down Expand Up @@ -657,7 +665,7 @@ protected void onCreate(Bundle savedInstanceState) {
notiManager.notify(0, noti);
}
//setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setRequestedOrientation(Integer.parseInt(options.getString(Keys.ORIENTATION, "1")));
setRequestedOrientation(Integer.parseInt(options.getString(Keys.ORIENTATION, "2")));
setContentView(mainLayout);
options.edit().putBoolean(Keys.MESSAGE_SHOWN, false).commit();
prefListener = new OnSharedPreferenceChangeListener() {
Expand Down Expand Up @@ -690,8 +698,12 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
Themer.applyTheme(this, options);
dock = new Dock(this);
changePrefsOnRotate();

//grid.setOnTouchListener(new SwipeListener(this));
gestureDetector = new GestureDetector(this, new SwipeListener(this));
grid.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View view, MotionEvent event) {
return gestureDetector.onTouchEvent(event);
}
});
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Expand Down
3 changes: 3 additions & 0 deletions src/ru/henridellal/emerald/Category.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public void removeAll() {
public String getRepresentName(Context context) {
return hasCustomName() ? name : context.getResources().getString(stringResourceId);
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
Expand Down
18 changes: 18 additions & 0 deletions src/ru/henridellal/emerald/CategoryAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package ru.henridellal.emerald;

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

import android.content.Context;
import android.widget.ArrayAdapter;

public class CategoryAdapter extends ArrayAdapter<String> {
public CategoryAdapter(Context context, int resource, List<String> categoryNames) {
super(context, resource, categoryNames);
}
public void update(ArrayList<String> content) {
clear();
addAll(content);
notifyDataSetChanged();
}
}
46 changes: 20 additions & 26 deletions src/ru/henridellal/emerald/CategoryManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public class CategoryManager {
public static final String UNCLASSIFIED = "Unclassified";
public static final String HIDDEN = "Hidden";
public static final String HISTORY = "History";

public static final byte PREVIOUS = 0;
public static final byte NEXT = 1;

private SoftReference<Context> contextRef;
private String home;
private String curCategory;
Expand Down Expand Up @@ -63,39 +67,26 @@ public boolean haveCategory(String s) {
}
/*Functions for spinner. Return names of categories
which are neighbouring to the current*/
public String getPrevCategory() {
int result;
boolean finished = false;
public String getCategory(byte direction) {
if (!curCategory.equals(HIDDEN)) {
result = names.indexOf(curCategory);
int result = names.indexOf(curCategory);
boolean finished = false;
while (!finished) {
result--;
result = (result > -1) ? result : names.size()-2;
if (!categories.get(names.get(result)).isHidden()) {
finished = true;
if (direction == CategoryManager.PREVIOUS) {
result--;
result = (result > -1) ? result : names.size()-2;
} else {
result++;
result = (result < names.size()-1) ? result : 0;
}
}
} else {
result = 0;
}
return names.get(result);
}
public String getNextCategory() {
int result;
boolean finished = false;
if (!curCategory.equals(HIDDEN)) {
result = names.indexOf(curCategory);
while (!finished) {
result++;
result = (result < names.size()-1) ? result : 0;
if (!categories.get(names.get(result)).isHidden()) {
finished = true;
}
}
return names.get(result);
} else {
result = 0;
return null;
}
return names.get(result);
}
public Category getCategory(String categoryName) {
return categories.get(categoryName);
Expand All @@ -117,8 +108,10 @@ public void loadCategories() {
//puts entries from cache to categories
if (isEditable(name)) {
if (isCustom(name)) {
names.add(name);
categories.put(name, new Category(name, getEntries(f)));
if (!names.contains(name)) {
names.add(name);
categories.put(name, new Category(name, getEntries(f)));
}
} else {
int stringResourceId = 0;
if (HISTORY.equals(name)) {
Expand Down Expand Up @@ -557,6 +550,7 @@ public boolean renameCategory(String newName, String cat) {
categories.put(newName, c);
names.remove(cat);
names.add(newName);
c.setName(newName);
sortNames();
writeCategoriesProps();
setCurCategory(ALL);
Expand Down
38 changes: 17 additions & 21 deletions src/ru/henridellal/emerald/CategoryManagerActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
public class CategoryManagerActivity extends Activity{
private CategoryManager cm;
private ArrayList<String> categories, categoriesNames;
private ArrayAdapter<String> adapter;
private CategoryAdapter adapter;
private ListView catListView;

private static final int COMMAND_HIDE = 0;
Expand All @@ -29,8 +29,12 @@ public class CategoryManagerActivity extends Activity{
private static final int COMMAND_RENAME = 4;
private static final int COMMAND_EDIT = 5;

public ArrayAdapter<String> getAdapter() {
return adapter;
public void updateCategoriesList() {
categories = cm.getCategories();
categoriesNames = new ArrayList<String>(categories.size());
for (String category: categories) {
categoriesNames.add(cm.getCategory(category).getRepresentName(this));
}
}

@Override
Expand All @@ -43,12 +47,8 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.categorymanager);
cm = LauncherApp.getInstance().getCategoryManager();
categories = cm.getCategories();
categoriesNames = new ArrayList<String>(categories.size());
for (String category: categories) {
categoriesNames.add(cm.getCategory(category).getRepresentName(this));
}
adapter = new ArrayAdapter<String>(this,
updateCategoriesList();
adapter = new CategoryAdapter(this,
android.R.layout.simple_list_item_1, categoriesNames);
catListView = (ListView)findViewById(R.id.categoryList);
catListView.setAdapter(adapter);
Expand Down Expand Up @@ -111,7 +111,6 @@ public void onClick(DialogInterface di, int which) {
break;
case COMMAND_RENAME:
renameCategory(category);
//Toast.makeText(CategoryManagerActivity.this, "This category name is not editable", Toast.LENGTH_LONG).show();
break;
case COMMAND_EDIT:
appListEditor(category);
Expand Down Expand Up @@ -143,7 +142,8 @@ private void deleteCategory(final String category) {
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
cm.removeCategory(category);
getAdapter().notifyDataSetChanged();
updateCategoriesList();
adapter.update(categoriesNames);
}
}).setNegativeButton(android.R.string.no,
new DialogInterface.OnClickListener() {
Expand Down Expand Up @@ -171,24 +171,19 @@ public void onClick(DialogInterface dialog, int which) {
builder.create().show();
}
private void renameCategory(final String category) {
/*if (! cm.isCustom(catName)) {
Toast.makeText(this, "This category name is not editable", Toast.LENGTH_LONG).show();
return;
}*/
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(getResources().getText(R.string.rename).toString());
builder.setMessage("Edit name of category:");
final EditText inputBox = new EditText(this);
inputBox.setText(category);
builder.setView(inputBox);
builder.setPositiveButton(android.R.string.yes,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
if (cm.renameCategory(inputBox.getText().toString(), category)) {
Toast.makeText(CategoryManagerActivity.this, "Successfully renamed", Toast.LENGTH_LONG).show();
adapter.notifyDataSetChanged();
updateCategoriesList();
adapter.update(categoriesNames);
} else {
Toast.makeText(CategoryManagerActivity.this, "Name already in use", Toast.LENGTH_LONG).show();
Toast.makeText(CategoryManagerActivity.this, getResources().getString(R.string.note_rename_error), Toast.LENGTH_LONG).show();
}
}
}).setNegativeButton(android.R.string.no,
Expand Down Expand Up @@ -271,9 +266,10 @@ private void newCategory() {
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
if (!cm.addCategory(inputBox.getText().toString())) {
Toast.makeText(CategoryManagerActivity.this, "Name already in use", Toast.LENGTH_LONG).show();
Toast.makeText(CategoryManagerActivity.this, getResources().getString(R.string.note_rename_error), Toast.LENGTH_LONG).show();
} else {
adapter.notifyDataSetChanged();
updateCategoriesList();
adapter.update(categoriesNames);
}
}
}).setNegativeButton(android.R.string.cancel,
Expand Down
2 changes: 1 addition & 1 deletion src/ru/henridellal/emerald/GetApps.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected ArrayList<AppData> doInBackground(Boolean... slow) {
// use intent to get apps that can be launched
Intent launchIntent = new Intent(Intent.ACTION_MAIN);
launchIntent.addCategory(Intent.CATEGORY_LAUNCHER);

//TODO access shared preferences the other way
int appShortcut = Integer.parseInt(context.options.getString(Keys.APP_SHORTCUT, "3"));
boolean icons = appShortcut >= CustomAdapter.ICON;
Map<String,AppData> cache = new HashMap<String,AppData>();
Expand Down
Loading

0 comments on commit c95a18d

Please sign in to comment.