diff --git a/AndroidManifest.xml b/AndroidManifest.xml index f7033f727..8d65a9591 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -99,7 +99,7 @@ - + + + + + + + + + + + + diff --git a/res/drawable-hdpi/ic_mic_black_24dp.png b/res/drawable-hdpi/ic_mic_black_24dp.png new file mode 100644 index 000000000..74218e1a6 Binary files /dev/null and b/res/drawable-hdpi/ic_mic_black_24dp.png differ diff --git a/res/drawable-hdpi/ic_stars_black_24dp.png b/res/drawable-hdpi/ic_stars_black_24dp.png new file mode 100644 index 000000000..fba38967b Binary files /dev/null and b/res/drawable-hdpi/ic_stars_black_24dp.png differ diff --git a/res/drawable-hdpi/ic_widget_kiwix.png b/res/drawable-hdpi/ic_widget_kiwix.png new file mode 100644 index 000000000..433860f68 Binary files /dev/null and b/res/drawable-hdpi/ic_widget_kiwix.png differ diff --git a/res/drawable-mdpi/ic_mic_black_24dp.png b/res/drawable-mdpi/ic_mic_black_24dp.png new file mode 100644 index 000000000..19a16138f Binary files /dev/null and b/res/drawable-mdpi/ic_mic_black_24dp.png differ diff --git a/res/drawable-mdpi/ic_stars_black_24dp.png b/res/drawable-mdpi/ic_stars_black_24dp.png new file mode 100644 index 000000000..365c321d4 Binary files /dev/null and b/res/drawable-mdpi/ic_stars_black_24dp.png differ diff --git a/res/drawable-mdpi/ic_widget_kiwix.png b/res/drawable-mdpi/ic_widget_kiwix.png new file mode 100644 index 000000000..5585bd5db Binary files /dev/null and b/res/drawable-mdpi/ic_widget_kiwix.png differ diff --git a/res/drawable-xhdpi/ic_mic_black_24dp.png b/res/drawable-xhdpi/ic_mic_black_24dp.png new file mode 100644 index 000000000..cac51c37a Binary files /dev/null and b/res/drawable-xhdpi/ic_mic_black_24dp.png differ diff --git a/res/drawable-xhdpi/ic_stars_black_24dp.png b/res/drawable-xhdpi/ic_stars_black_24dp.png new file mode 100644 index 000000000..ee380e48b Binary files /dev/null and b/res/drawable-xhdpi/ic_stars_black_24dp.png differ diff --git a/res/drawable-xhdpi/ic_widget_kiwix.png b/res/drawable-xhdpi/ic_widget_kiwix.png new file mode 100644 index 000000000..1b05a0faf Binary files /dev/null and b/res/drawable-xhdpi/ic_widget_kiwix.png differ diff --git a/res/drawable-xxhdpi/ic_mic_black_24dp.png b/res/drawable-xxhdpi/ic_mic_black_24dp.png new file mode 100644 index 000000000..ad8299e77 Binary files /dev/null and b/res/drawable-xxhdpi/ic_mic_black_24dp.png differ diff --git a/res/drawable-xxhdpi/ic_stars_black_24dp.png b/res/drawable-xxhdpi/ic_stars_black_24dp.png new file mode 100644 index 000000000..177745993 Binary files /dev/null and b/res/drawable-xxhdpi/ic_stars_black_24dp.png differ diff --git a/res/drawable-xxhdpi/ic_widget_kiwix.png b/res/drawable-xxhdpi/ic_widget_kiwix.png new file mode 100644 index 000000000..70bd56a5a Binary files /dev/null and b/res/drawable-xxhdpi/ic_widget_kiwix.png differ diff --git a/res/drawable-xxxhdpi/ic_mic_black_24dp.png b/res/drawable-xxxhdpi/ic_mic_black_24dp.png new file mode 100644 index 000000000..cf70b63be Binary files /dev/null and b/res/drawable-xxxhdpi/ic_mic_black_24dp.png differ diff --git a/res/drawable-xxxhdpi/ic_stars_black_24dp.png b/res/drawable-xxxhdpi/ic_stars_black_24dp.png new file mode 100644 index 000000000..4746c16e8 Binary files /dev/null and b/res/drawable-xxxhdpi/ic_stars_black_24dp.png differ diff --git a/res/drawable-xxxhdpi/ic_widget_kiwix.png b/res/drawable-xxxhdpi/ic_widget_kiwix.png new file mode 100644 index 000000000..059535311 Binary files /dev/null and b/res/drawable-xxxhdpi/ic_widget_kiwix.png differ diff --git a/res/drawable/search_widget_background.xml b/res/drawable/search_widget_background.xml new file mode 100644 index 000000000..50b760315 --- /dev/null +++ b/res/drawable/search_widget_background.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/res/drawable/search_widget_preview.png b/res/drawable/search_widget_preview.png new file mode 100644 index 000000000..c44b56719 Binary files /dev/null and b/res/drawable/search_widget_preview.png differ diff --git a/res/layout/kiwix_search_widget.xml b/res/layout/kiwix_search_widget.xml new file mode 100644 index 000000000..13ed19c61 --- /dev/null +++ b/res/layout/kiwix_search_widget.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/res/values/colors.xml b/res/values/colors.xml index 87691a16e..112dcbe1e 100644 --- a/res/values/colors.xml +++ b/res/values/colors.xml @@ -9,11 +9,12 @@ #727272 #212121 #B6B6B6 - #FAFAFA + #FAFAFA #0d000000 #ffffff #0F000000 #1E000000 #BDBDBD #212121 + #808080 \ No newline at end of file diff --git a/res/values/dimens.xml b/res/values/dimens.xml index 6d191e608..e44402d7f 100644 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -6,5 +6,6 @@ 4dp 8dp 260dp + 0dp diff --git a/res/values/strings.xml b/res/values/strings.xml index d6b6a2a01..a686030b2 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -51,7 +51,7 @@ Choose a language The language of this page is not supported, or appropriate language data was not installed. The article may not be properly read. Could not find an installed application for this type of file - Your application is corrupted.\nThis might happen when you remove files on the SD Card.\nYou need to uninstall then reinstall the App from the Play Store. + Your application is corrupted.\nThis might happen when you remove files on the SD Card.\nYou need to uninstall then reinstall the App from the Play Store. Go to Play Store No Bookmarks Bookmarks @@ -59,7 +59,7 @@ To access zim files we need access to your storage Are you sure you want to delete your search history? Are you sure you want to delete your search history and reset all active tabs? - Delete this item? + Delete this item? Clear History Clear recent searches and tabs history All History Cleared @@ -71,7 +71,7 @@ Did you know? Undo Tab closed - Deleted + deleted Bookmarks restored Bookmark added Please Rate Us @@ -85,5 +85,8 @@ Open new tab in background When opening a new tab it will open in background Extras - Link opened in new tab + Article opened in new tab + Search Kiwix + Speak to search Kiwix + Sorry! Your device doesn\\\'t support speech input \ No newline at end of file diff --git a/res/xml/kiwix_widget_provider_info.xml b/res/xml/kiwix_widget_provider_info.xml new file mode 100644 index 000000000..e8fa55b3a --- /dev/null +++ b/res/xml/kiwix_widget_provider_info.xml @@ -0,0 +1,15 @@ + + + + + + + \ No newline at end of file diff --git a/src/org/kiwix/kiwixmobile/views/BookmarksActivity.java b/src/org/kiwix/kiwixmobile/BookmarksActivity.java similarity index 73% rename from src/org/kiwix/kiwixmobile/views/BookmarksActivity.java rename to src/org/kiwix/kiwixmobile/BookmarksActivity.java index b4595350b..d9a15ef97 100644 --- a/src/org/kiwix/kiwixmobile/views/BookmarksActivity.java +++ b/src/org/kiwix/kiwixmobile/BookmarksActivity.java @@ -1,4 +1,24 @@ -package org.kiwix.kiwixmobile.views; +/* + * Copyright 2013 Elad Keyshawn + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + + +package org.kiwix.kiwixmobile; import android.content.Intent; import android.os.Bundle; @@ -20,6 +40,7 @@ import android.widget.TextView; import android.widget.Toast; import org.kiwix.kiwixmobile.R; +import org.kiwix.kiwixmobile.utils.HelperClasses.ShortcutUtils; import java.util.ArrayList; @@ -42,14 +63,16 @@ public class BookmarksActivity extends AppCompatActivity setContentView(R.layout.activity_bookmarks); setUpToolbar(); snackbarLayout = (LinearLayout) findViewById(R.id.bookmarks_activity_layout); - contents = getIntent().getStringArrayListExtra("bookmark_contents"); - selected = new ArrayList<>(); - bookmarksList = (ListView) findViewById(R.id.bookmarks_list); - noBookmarksTextView = (TextView) findViewById(R.id.bookmarks_list_nobookmarks); - adapter = new ArrayAdapter(getApplicationContext(), R.layout.bookmarks_row, R.id.bookmark_title, - contents); - bookmarksList.setAdapter(adapter); + selected = new ArrayList<>(); + bookmarksList = (ListView) findViewById(R.id.bookmarks_list); + noBookmarksTextView = (TextView) findViewById(R.id.bookmarks_list_nobookmarks); + if(getIntent().getStringArrayListExtra("bookmark_contents") != null) { + contents = getIntent().getStringArrayListExtra("bookmark_contents"); + adapter = new ArrayAdapter(getApplicationContext(), R.layout.bookmarks_row, R.id.bookmark_title, + contents); + bookmarksList.setAdapter(adapter); + } setNoBookmarksState(); bookmarksList.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL); @@ -117,19 +140,19 @@ public class BookmarksActivity extends AppCompatActivity private void popDeleteBookmarksSnackbar() { Snackbar bookmarkDeleteSnackbar = - Snackbar.make(snackbarLayout, numOfSelected + " " + stringsGetter(R.string.deleted_message), Snackbar.LENGTH_LONG) - .setAction(stringsGetter(R.string.undo), new View.OnClickListener() { + Snackbar.make(snackbarLayout, numOfSelected + " " + ShortcutUtils.stringsGetter(R.string.deleted_message,this), Snackbar.LENGTH_LONG) + .setAction(ShortcutUtils.stringsGetter(R.string.undo,this), new View.OnClickListener() { @Override public void onClick(View v) { contents.clear(); contents.addAll(tempContents); adapter.notifyDataSetChanged(); setNoBookmarksState(); - Toast.makeText(getApplicationContext(), stringsGetter(R.string.bookmarks_restored), Toast.LENGTH_SHORT) + Toast.makeText(getApplicationContext(), ShortcutUtils.stringsGetter(R.string.bookmarks_restored,getBaseContext()), Toast.LENGTH_SHORT) .show(); } }); - bookmarkDeleteSnackbar.setActionTextColor(getResources().getColor(R.color.white_undo)); + bookmarkDeleteSnackbar.setActionTextColor(getResources().getColor(R.color.white)); bookmarkDeleteSnackbar.show(); } @@ -145,7 +168,7 @@ public class BookmarksActivity extends AppCompatActivity private void setUpToolbar() { Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); - toolbar.setTitle(stringsGetter(R.string.menu_bookmarks_list)); + toolbar.setTitle(ShortcutUtils.stringsGetter(R.string.menu_bookmarks_list,this)); setSupportActionBar(toolbar); getSupportActionBar().setHomeButtonEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true); @@ -181,7 +204,4 @@ public class BookmarksActivity extends AppCompatActivity super.onBackPressed(); } - public String stringsGetter(int strId) { - return getResources().getString(strId); - } } diff --git a/src/org/kiwix/kiwixmobile/KiwixMobileActivity.java b/src/org/kiwix/kiwixmobile/KiwixMobileActivity.java index 91279cd1c..f1ab040a6 100644 --- a/src/org/kiwix/kiwixmobile/KiwixMobileActivity.java +++ b/src/org/kiwix/kiwixmobile/KiwixMobileActivity.java @@ -82,14 +82,14 @@ import android.widget.Toast; import org.json.JSONArray; import org.kiwix.kiwixmobile.settings.Constants; import org.kiwix.kiwixmobile.settings.KiwixSettingsActivity; -import org.kiwix.kiwixmobile.utils.HTMLUtils; +import org.kiwix.kiwixmobile.utils.HelperClasses.HTMLUtils; +import org.kiwix.kiwixmobile.utils.HelperClasses.LanguageUtils; +import org.kiwix.kiwixmobile.utils.HelperClasses.ShortcutUtils; import org.kiwix.kiwixmobile.utils.KiwixTextToSpeech; -import org.kiwix.kiwixmobile.utils.LanguageUtils; +import org.kiwix.kiwixmobile.utils.RateAppCounter; import org.kiwix.kiwixmobile.utils.files.FileReader; import org.kiwix.kiwixmobile.utils.files.FileUtils; -import org.kiwix.kiwixmobile.utils.files.RateAppCounter; import org.kiwix.kiwixmobile.views.AnimatedProgressBar; -import org.kiwix.kiwixmobile.views.BookmarksActivity; import org.kiwix.kiwixmobile.views.CompatFindActionModeCallback; import org.kiwix.kiwixmobile.views.KiwixWebView; @@ -306,6 +306,14 @@ public class KiwixMobileActivity extends AppCompatActivity { mProgressBar = (AnimatedProgressBar) findViewById(R.id.progress_view); exitFullscreenButton = (ImageButton) findViewById(R.id.FullscreenControlButton); + boolean IS_WIDGET_SEARCH_INTENT; + boolean IS_WIDGET_VOICE_SEARCH; + boolean IS_WIDGET_STAR; + IS_WIDGET_SEARCH_INTENT = getIntent().getBooleanExtra("isWidgetSearch", false); + IS_WIDGET_VOICE_SEARCH = getIntent().getBooleanExtra("isWidgetVoice", false); + IS_WIDGET_STAR = getIntent().getBooleanExtra("isWidgetStar", false); + + tempForUndo = new KiwixWebView(getApplicationContext()); /** initializing temporary tab value **/ snackbarLayout = @@ -444,18 +452,35 @@ public class KiwixMobileActivity extends AppCompatActivity { setUpExitFullscreenButton(); loadPrefs(); updateTitle(ZimContentProvider.getZimFileTitle()); + if (IS_WIDGET_STAR) { + goToBookmarks(); + } else if (IS_WIDGET_SEARCH_INTENT) { + goToSearch(false); + } else if (IS_WIDGET_VOICE_SEARCH) { + goToSearch(true); + } + } + + private void goToSearch(boolean isVoice) { + final String zimFile = ZimContentProvider.getZimFile(); + Intent i = new Intent(KiwixMobileActivity.this, SearchActivity.class); + i.putExtra("zimFile", zimFile); + if (isVoice) { + i.putExtra("isWidgetVoice", true); + } + startActivityForResult(i, REQUEST_FILE_SEARCH); } public void showRateDialog(final Context mContext, final SharedPreferences.Editor editor) { AlertDialog alertDialog = new AlertDialog.Builder(mContext).create(); - alertDialog.setTitle(stringsGetter(R.string.rate_dialog_title)); + alertDialog.setTitle(ShortcutUtils.stringsGetter(R.string.rate_dialog_title, this)); - alertDialog.setMessage(stringsGetter(R.string.rate_dialog_msg_1) + " " + alertDialog.setMessage(ShortcutUtils.stringsGetter(R.string.rate_dialog_msg_1, this) + " " + getString(R.string.app_name) - + stringsGetter(R.string.rate_dialog_msg_2)); + + ShortcutUtils.stringsGetter(R.string.rate_dialog_msg_2, this)); - alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, stringsGetter(R.string.rate_dialog_positive), + alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, ShortcutUtils.stringsGetter(R.string.rate_dialog_positive, this), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { @@ -464,7 +489,7 @@ public class KiwixMobileActivity extends AppCompatActivity { } }); - alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, stringsGetter(R.string.rate_dialog_negative), + alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, ShortcutUtils.stringsGetter(R.string.rate_dialog_negative, this), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { @@ -473,7 +498,7 @@ public class KiwixMobileActivity extends AppCompatActivity { } }); - alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, stringsGetter(R.string.rate_dialog_neutral), + alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, ShortcutUtils.stringsGetter(R.string.rate_dialog_neutral, this), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { @@ -488,10 +513,6 @@ public class KiwixMobileActivity extends AppCompatActivity { alertDialog.show(); } - private String stringsGetter(int strId) { - return getResources().getString(strId); - } - private void goToRateApp() { Intent goToMarket = new Intent(Intent.ACTION_VIEW, KIWIX_LOCAL_MARKET_URI); @@ -677,8 +698,8 @@ public class KiwixMobileActivity extends AppCompatActivity { } private void undoSnackbar(final int index) { - Snackbar undoSnackbar = Snackbar.make(snackbarLayout, stringsGetter(R.string.tab_closed), Snackbar.LENGTH_LONG) - .setAction(stringsGetter(R.string.undo), new View.OnClickListener() { + Snackbar undoSnackbar = Snackbar.make(snackbarLayout, ShortcutUtils.stringsGetter(R.string.tab_closed, this), Snackbar.LENGTH_LONG) + .setAction(ShortcutUtils.stringsGetter(R.string.undo, this), new View.OnClickListener() { @Override public void onClick(View v) { @@ -691,7 +712,7 @@ public class KiwixMobileActivity extends AppCompatActivity { mLeftDrawerLayout.openDrawer(Gravity.LEFT); } }); - undoSnackbar.setActionTextColor(getResources().getColor(R.color.white_undo)); + undoSnackbar.setActionTextColor(getResources().getColor(R.color.white)); undoSnackbar.show(); } @@ -1078,18 +1099,18 @@ public class KiwixMobileActivity extends AppCompatActivity { private void popBookmarkSnackbar(boolean isBookmark) { if (isBookmark) { Snackbar bookmarkSnackbar = - Snackbar.make(snackbarLayout, stringsGetter(R.string.bookmark_added), Snackbar.LENGTH_LONG) - .setAction(stringsGetter(R.string.open), new View.OnClickListener() { + Snackbar.make(snackbarLayout, ShortcutUtils.stringsGetter(R.string.bookmark_added, this), Snackbar.LENGTH_LONG) + .setAction(ShortcutUtils.stringsGetter(R.string.open, this), new View.OnClickListener() { @Override public void onClick(View v) { goToBookmarks(); } }); - bookmarkSnackbar.setActionTextColor(getResources().getColor(R.color.white_undo)); + bookmarkSnackbar.setActionTextColor(getResources().getColor(R.color.white)); bookmarkSnackbar.show(); } else { Snackbar bookmarkSnackbar = - Snackbar.make(snackbarLayout, stringsGetter(R.string.bookmark_removed), Snackbar.LENGTH_LONG); + Snackbar.make(snackbarLayout, ShortcutUtils.stringsGetter(R.string.bookmark_removed, this), Snackbar.LENGTH_LONG); bookmarkSnackbar.show(); } } @@ -1102,6 +1123,20 @@ public class KiwixMobileActivity extends AppCompatActivity { } } + @Override + protected void onNewIntent(Intent intent) { + super.onNewIntent(intent); + boolean IS_WIDGET_STAR = getIntent().getBooleanExtra("isWidgetStar", false); + boolean IS_WIDGET_SEARCH_INTENT = getIntent().getBooleanExtra("isWidgetSearch", false); + + if (IS_WIDGET_STAR) { + goToBookmarks(); + } else if (IS_WIDGET_SEARCH_INTENT) { + goToSearch(false); + } + + } + private void refreshBookmarks() { bookmarks.clear(); if (ZimContentProvider.getId() != null) { @@ -1154,12 +1189,12 @@ public class KiwixMobileActivity extends AppCompatActivity { }, 500); AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setMessage(stringsGetter(R.string.hint_contents_drawer_message)) - .setPositiveButton(stringsGetter(R.string.got_it), new DialogInterface.OnClickListener() { + builder.setMessage(ShortcutUtils.stringsGetter(R.string.hint_contents_drawer_message, this)) + .setPositiveButton(ShortcutUtils.stringsGetter(R.string.got_it, this), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { } }) - .setTitle(stringsGetter(R.string.did_you_know)) + .setTitle(ShortcutUtils.stringsGetter(R.string.did_you_know, this)) .setIcon(R.drawable.icon_question); AlertDialog alert = builder.create(); alert.show();//showing the dialog @@ -1261,15 +1296,15 @@ public class KiwixMobileActivity extends AppCompatActivity { public void onClick(DialogInterface dialog, int id) { if (isOpenNewTabInBackground) { newTabInBackground(url); - Snackbar snackbar = Snackbar.make(snackbarLayout, stringsGetter(R.string.new_tab_snackbar), Snackbar.LENGTH_LONG) - .setAction(stringsGetter(R.string.open), new View.OnClickListener() { + Snackbar snackbar = Snackbar.make(snackbarLayout, ShortcutUtils.stringsGetter(R.string.new_tab_snackbar, getBaseContext()), Snackbar.LENGTH_LONG) + .setAction(ShortcutUtils.stringsGetter(R.string.open, getBaseContext()), new View.OnClickListener() { @Override public void onClick(View v) { if (mWebViews.size() > 1) selectTab(mWebViews.size() - 1); } }); - snackbar.setActionTextColor(getResources().getColor(R.color.white_undo)); + snackbar.setActionTextColor(getResources().getColor(R.color.white)); snackbar.show(); } else { newTab(url); diff --git a/src/org/kiwix/kiwixmobile/SearchActivity.java b/src/org/kiwix/kiwixmobile/SearchActivity.java index d3f874830..9f261e552 100644 --- a/src/org/kiwix/kiwixmobile/SearchActivity.java +++ b/src/org/kiwix/kiwixmobile/SearchActivity.java @@ -1,9 +1,11 @@ package org.kiwix.kiwixmobile; +import android.content.ActivityNotFoundException; import android.content.DialogInterface; import android.content.Intent; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; +import android.speech.RecognizerIntent; import android.support.v4.view.MenuItemCompat; import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; @@ -18,21 +20,21 @@ import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; -import org.kiwix.kiwixmobile.utils.DatabaseHelper; +import org.kiwix.kiwixmobile.utils.HelperClasses.DatabaseHelper; +import org.kiwix.kiwixmobile.utils.HelperClasses.ShortcutUtils; import org.kiwix.kiwixmobile.views.AutoCompleteAdapter; import java.util.ArrayList; +import java.util.Locale; -public class SearchActivity extends AppCompatActivity implements AdapterView.OnItemClickListener, AdapterView.OnItemLongClickListener { +public class SearchActivity extends AppCompatActivity + implements AdapterView.OnItemClickListener, AdapterView.OnItemLongClickListener { + private final int REQ_CODE_SPEECH_INPUT = 100; private ListView mListView; - private AutoCompleteAdapter mAutoAdapter; - private ArrayAdapter mDefaultAdapter; - private SearchActivity context; - private DatabaseHelper mDatabaseHelper; @Override @@ -45,7 +47,6 @@ public class SearchActivity extends AppCompatActivity implements AdapterView.OnI getSupportActionBar().setHomeButtonEnabled(true); String zimFile = getIntent().getStringExtra("zimFile"); - zimFile = escapeSqlSyntax(zimFile); mListView = (ListView) findViewById(R.id.search_list); mDatabaseHelper = new DatabaseHelper(this, zimFile); SQLiteDatabase db = mDatabaseHelper.getWritableDatabase(); @@ -59,6 +60,11 @@ public class SearchActivity extends AppCompatActivity implements AdapterView.OnI mAutoAdapter = new AutoCompleteAdapter(context); mListView.setOnItemClickListener(context); mListView.setOnItemLongClickListener(context); + + boolean IS_VOICE_SEARCH_INTENT = getIntent().getBooleanExtra("isWidgetVoice", false); + if (IS_VOICE_SEARCH_INTENT) { + promptSpeechInput(); + } } @Override @@ -114,7 +120,6 @@ public class SearchActivity extends AppCompatActivity implements AdapterView.OnI @Override public void onItemClick(AdapterView parent, View view, int position, long id) { String title = ((TextView) view).getText().toString(); - title = escapeSqlSyntax(title); mDatabaseHelper.insertSearch(title); sendMessage(title); } @@ -137,7 +142,7 @@ public class SearchActivity extends AppCompatActivity implements AdapterView.OnI private void deleteSpecificSearchDialog(final String search) { new AlertDialog.Builder(this) - .setMessage(getResources().getString(R.string.deleteRecentSearchItem)) + .setMessage(ShortcutUtils.stringsGetter(R.string.delete_recent_search_item, this)) .setPositiveButton(getResources().getString(R.string.delete), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { deleteSpecificSearchItem(search); @@ -154,22 +159,10 @@ public class SearchActivity extends AppCompatActivity implements AdapterView.OnI private void deleteSpecificSearchItem(String search) { SQLiteDatabase db = mDatabaseHelper.getWritableDatabase(); - mDatabaseHelper.deleteSpecificSearch(db, escapeSqlSyntax(search)); + mDatabaseHelper.deleteSpecificSearch(db, ShortcutUtils.escapeSqlSyntax(search)); resetAdapter(); } - private String escapeSqlSyntax(String search) { //Escapes sql ' if exists - String tempStr = ""; - char[] charArray = search.toCharArray(); - for (char a : charArray) { - if (a != '\'') - tempStr += a; - else - tempStr += "''"; - } - return tempStr; - } - private void resetAdapter() { ArrayList a = mDatabaseHelper.getRecentSearches(); mDefaultAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1); @@ -179,4 +172,51 @@ public class SearchActivity extends AppCompatActivity implements AdapterView.OnI } + private void promptSpeechInput() { + Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); + intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, + RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); + intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault()); // TODO: choose selected lang on kiwix + intent.putExtra(RecognizerIntent.EXTRA_PROMPT, + getString(R.string.speech_prompt_text)); + try { + startActivityForResult(intent, REQ_CODE_SPEECH_INPUT); + } catch (ActivityNotFoundException a) { + Toast.makeText(getApplicationContext(), + getString(R.string.speech_not_supported), + Toast.LENGTH_SHORT).show(); + } + + } + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + + switch (requestCode) { + + case REQ_CODE_SPEECH_INPUT: { + if (resultCode == RESULT_OK && data != null) { + ArrayList result = data + .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS); + searchViaVoice(result.get(0)); + } + break; + } + + + } + } + + + private void searchViaVoice(String search) { + search = capitalizeSearch(search); + mDatabaseHelper.insertSearch(search); + sendMessage(search); + } + + private String capitalizeSearch(String search) { + search = search.substring(0, 1).toUpperCase() + search.substring(1).toLowerCase(); + return search; + } } diff --git a/src/org/kiwix/kiwixmobile/ZimFileSelectActivity.java b/src/org/kiwix/kiwixmobile/ZimFileSelectActivity.java index b54e6c60a..dad2a574c 100644 --- a/src/org/kiwix/kiwixmobile/ZimFileSelectActivity.java +++ b/src/org/kiwix/kiwixmobile/ZimFileSelectActivity.java @@ -55,7 +55,7 @@ import android.widget.Toast; import java.io.File; import java.util.ArrayList; import java.util.List; -import org.kiwix.kiwixmobile.utils.LanguageUtils; +import org.kiwix.kiwixmobile.utils.HelperClasses.LanguageUtils; import org.kiwix.kiwixmobile.utils.files.FileSearch; import org.kiwix.kiwixmobile.utils.files.FileWriter; diff --git a/src/org/kiwix/kiwixmobile/settings/KiwixSettingsActivity.java b/src/org/kiwix/kiwixmobile/settings/KiwixSettingsActivity.java index 5f96ff280..fad96223f 100644 --- a/src/org/kiwix/kiwixmobile/settings/KiwixSettingsActivity.java +++ b/src/org/kiwix/kiwixmobile/settings/KiwixSettingsActivity.java @@ -38,8 +38,8 @@ import android.widget.BaseAdapter; import android.widget.Toast; import org.kiwix.kiwixmobile.R; -import org.kiwix.kiwixmobile.utils.DatabaseHelper; -import org.kiwix.kiwixmobile.utils.LanguageUtils; +import org.kiwix.kiwixmobile.utils.HelperClasses.DatabaseHelper; +import org.kiwix.kiwixmobile.utils.HelperClasses.LanguageUtils; import org.kiwix.kiwixmobile.views.SliderPreference; import java.util.Locale; diff --git a/src/org/kiwix/kiwixmobile/utils/DatabaseHelper.java b/src/org/kiwix/kiwixmobile/utils/HelperClasses/DatabaseHelper.java similarity index 91% rename from src/org/kiwix/kiwixmobile/utils/DatabaseHelper.java rename to src/org/kiwix/kiwixmobile/utils/HelperClasses/DatabaseHelper.java index 42e90d8ca..cc7a5cab8 100644 --- a/src/org/kiwix/kiwixmobile/utils/DatabaseHelper.java +++ b/src/org/kiwix/kiwixmobile/utils/HelperClasses/DatabaseHelper.java @@ -1,4 +1,4 @@ -package org.kiwix.kiwixmobile.utils; +package org.kiwix.kiwixmobile.utils.HelperClasses; import android.content.ContentValues; import android.content.Context; @@ -6,9 +6,8 @@ import android.database.Cursor; import android.database.DatabaseUtils; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; -import android.util.Log; -import org.kiwix.kiwixmobile.KiwixMobileActivity; +import org.kiwix.kiwixmobile.utils.HelperClasses.ShortcutUtils; import java.util.ArrayList; @@ -84,9 +83,9 @@ public class DatabaseHelper extends SQLiteOpenHelper { ArrayList array_list = new ArrayList(); SQLiteDatabase db = this.getReadableDatabase(); //hp = new HashMap(); - Log.d(KiwixMobileActivity.TAG_KIWIX, zimFile); +// Log.d(KiwixMobileActivity.TAG_KIWIX, zimFile); Cursor res = db.rawQuery("select * from " + CONTACTS_TABLE_NAME - + " where " + CONTACTS_COLUMN_ZIM + " = '" + zimFile + "'", null); + + " where " + CONTACTS_COLUMN_ZIM + " = '" + ShortcutUtils.escapeSqlSyntax(zimFile) + "'", null); res.moveToLast(); while (!res.isBeforeFirst()) { diff --git a/src/org/kiwix/kiwixmobile/utils/HTMLUtils.java b/src/org/kiwix/kiwixmobile/utils/HelperClasses/HTMLUtils.java similarity index 98% rename from src/org/kiwix/kiwixmobile/utils/HTMLUtils.java rename to src/org/kiwix/kiwixmobile/utils/HelperClasses/HTMLUtils.java index 6c0be7e06..0789ab867 100644 --- a/src/org/kiwix/kiwixmobile/utils/HTMLUtils.java +++ b/src/org/kiwix/kiwixmobile/utils/HelperClasses/HTMLUtils.java @@ -1,4 +1,4 @@ -package org.kiwix.kiwixmobile.utils; +package org.kiwix.kiwixmobile.utils.HelperClasses; import android.graphics.Color; import android.graphics.Typeface; diff --git a/src/org/kiwix/kiwixmobile/utils/LanguageUtils.java b/src/org/kiwix/kiwixmobile/utils/HelperClasses/LanguageUtils.java similarity index 99% rename from src/org/kiwix/kiwixmobile/utils/LanguageUtils.java rename to src/org/kiwix/kiwixmobile/utils/HelperClasses/LanguageUtils.java index 3d8cf869f..8b91d93d9 100644 --- a/src/org/kiwix/kiwixmobile/utils/LanguageUtils.java +++ b/src/org/kiwix/kiwixmobile/utils/HelperClasses/LanguageUtils.java @@ -17,7 +17,7 @@ * MA 02110-1301, USA. */ -package org.kiwix.kiwixmobile.utils; +package org.kiwix.kiwixmobile.utils.HelperClasses; import android.content.Context; import android.content.SharedPreferences; diff --git a/src/org/kiwix/kiwixmobile/utils/NetworkUtils.java b/src/org/kiwix/kiwixmobile/utils/HelperClasses/NetworkUtils.java old mode 100755 new mode 100644 similarity index 95% rename from src/org/kiwix/kiwixmobile/utils/NetworkUtils.java rename to src/org/kiwix/kiwixmobile/utils/HelperClasses/NetworkUtils.java index 7d4111006..344fcbb00 --- a/src/org/kiwix/kiwixmobile/utils/NetworkUtils.java +++ b/src/org/kiwix/kiwixmobile/utils/HelperClasses/NetworkUtils.java @@ -1,4 +1,4 @@ -package org.kiwix.kiwixmobile.utils; +package org.kiwix.kiwixmobile.utils.HelperClasses; import android.content.Context; import android.net.ConnectivityManager; diff --git a/src/org/kiwix/kiwixmobile/utils/HelperClasses/ShortcutUtils.java b/src/org/kiwix/kiwixmobile/utils/HelperClasses/ShortcutUtils.java new file mode 100644 index 000000000..38122a85a --- /dev/null +++ b/src/org/kiwix/kiwixmobile/utils/HelperClasses/ShortcutUtils.java @@ -0,0 +1,53 @@ +/* + * Copyright 2013 Elad Keyshawn + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + + +package org.kiwix.kiwixmobile.utils.HelperClasses; + +import android.content.Context; + + +/* +Helper class containing basic useful functions +that are meant to make shortcuts and beautifying code. +*/ + +public class ShortcutUtils { + + public static String stringsGetter(int strId, Context context) { + return context.getResources().getString(strId); + } + + public static String escapeSqlSyntax(String search) {//Escapes sql ' if exists + if (search != null) { + String tempStr = ""; + char[] charArray = search.toCharArray(); + for (char a : charArray) { + if (a != '\'') + tempStr += a; + else + tempStr += "''"; + } + return tempStr; + } else { + return search; + } + } + +} diff --git a/src/org/kiwix/kiwixmobile/utils/StorageUtils.java b/src/org/kiwix/kiwixmobile/utils/HelperClasses/StorageUtils.java old mode 100755 new mode 100644 similarity index 97% rename from src/org/kiwix/kiwixmobile/utils/StorageUtils.java rename to src/org/kiwix/kiwixmobile/utils/HelperClasses/StorageUtils.java index a39086768..6e1a174aa --- a/src/org/kiwix/kiwixmobile/utils/StorageUtils.java +++ b/src/org/kiwix/kiwixmobile/utils/HelperClasses/StorageUtils.java @@ -1,4 +1,4 @@ -package org.kiwix.kiwixmobile.utils; +package org.kiwix.kiwixmobile.utils.HelperClasses; import android.os.Build; import android.os.Environment; diff --git a/src/org/kiwix/kiwixmobile/utils/KiwixSearchWidget.java b/src/org/kiwix/kiwixmobile/utils/KiwixSearchWidget.java new file mode 100644 index 000000000..06450201d --- /dev/null +++ b/src/org/kiwix/kiwixmobile/utils/KiwixSearchWidget.java @@ -0,0 +1,96 @@ +/* + * Copyright 2013 Elad Keyshawn + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + + +package org.kiwix.kiwixmobile.utils; + +import android.app.PendingIntent; +import android.appwidget.AppWidgetManager; +import android.appwidget.AppWidgetProvider; +import android.content.Context; +import android.content.Intent; +import android.widget.RemoteViews; + +import org.kiwix.kiwixmobile.KiwixMobileActivity; +import org.kiwix.kiwixmobile.R; + +public class KiwixSearchWidget extends AppWidgetProvider { + + private static final String TEXT_CLICKED = "SearchKiwixActionClicked"; + private static final String ICON_CLICKED = "KiwixIconActionClicked"; + private static final String MIC_CLICKED = "MicSearchActionClicked"; + private static final String STAR_CLICKED = "StarActionClicked"; + + + @Override + public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { + + final int N = appWidgetIds.length; + + for (int i = 0; i < N; i++) { + int appWidgetId = appWidgetIds[i]; + + RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.kiwix_search_widget); + + /** Search Kiwix intent **/ + Intent mainIntent = new Intent(context, KiwixMobileActivity.class); + mainIntent.putExtra("isWidgetSearch", true); + mainIntent.setAction(TEXT_CLICKED); + PendingIntent searchPendingIntent = PendingIntent.getActivity(context, 0, mainIntent, 0); + + /** Kiwix icon intent to main app **/ + Intent kiwixIconIntent = new Intent(context, KiwixMobileActivity.class); + kiwixIconIntent.setAction(ICON_CLICKED); + PendingIntent mainAppPendingIntent = PendingIntent.getActivity(context, 0, kiwixIconIntent, 0); + + /** Star icon intent to bookmarks **/ + Intent starIntent = new Intent(context, KiwixMobileActivity.class); + starIntent.putExtra("isWidgetStar", true); + starIntent.setAction(STAR_CLICKED); + PendingIntent starPendingIntent = PendingIntent.getActivity(context,0,starIntent, 0); + + + /** Microphone icon intent for voice search **/ + Intent voiceIntent = new Intent(context, KiwixMobileActivity.class); + voiceIntent.putExtra("isWidgetVoice", true); + voiceIntent.setAction(MIC_CLICKED); + PendingIntent voicePendingIntent = PendingIntent.getActivity(context, 0, voiceIntent, 0); + + views.setOnClickPendingIntent(R.id.search_widget_text, searchPendingIntent); + views.setOnClickPendingIntent(R.id.search_widget_icon, mainAppPendingIntent); + views.setOnClickPendingIntent(R.id.search_widget_star, starPendingIntent); + views.setOnClickPendingIntent(R.id.search_widget_mic, voicePendingIntent); + + appWidgetManager.updateAppWidget(appWidgetId, views); + } + } + + public void onReceive(Context context, Intent intent) { + super.onReceive(context, intent); + + } + +// protected PendingIntent getPendingSelfIntent(Context context, String action) { +// Intent intent = new Intent(context, getClass()); +// intent.setAction(action); +// return PendingIntent.getBroadcast(context, 0, intent, 0); +// } + + +} diff --git a/src/org/kiwix/kiwixmobile/utils/KiwixTextToSpeech.java b/src/org/kiwix/kiwixmobile/utils/KiwixTextToSpeech.java index 54d722947..16db6f378 100644 --- a/src/org/kiwix/kiwixmobile/utils/KiwixTextToSpeech.java +++ b/src/org/kiwix/kiwixmobile/utils/KiwixTextToSpeech.java @@ -13,6 +13,7 @@ import java.util.HashMap; import java.util.Locale; import org.kiwix.kiwixmobile.R; import org.kiwix.kiwixmobile.ZimContentProvider; +import org.kiwix.kiwixmobile.utils.HelperClasses.LanguageUtils; public class KiwixTextToSpeech { diff --git a/src/org/kiwix/kiwixmobile/utils/files/RateAppCounter.java b/src/org/kiwix/kiwixmobile/utils/RateAppCounter.java similarity index 57% rename from src/org/kiwix/kiwixmobile/utils/files/RateAppCounter.java rename to src/org/kiwix/kiwixmobile/utils/RateAppCounter.java index 26217d4d7..df7646441 100644 --- a/src/org/kiwix/kiwixmobile/utils/files/RateAppCounter.java +++ b/src/org/kiwix/kiwixmobile/utils/RateAppCounter.java @@ -1,4 +1,24 @@ -package org.kiwix.kiwixmobile.utils.files; +/* + * Copyright 2013 Elad Keyshawn + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + + +package org.kiwix.kiwixmobile.utils; import android.content.Context; import android.content.SharedPreferences;