This repository has been archived by the owner on Dec 19, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1022105 - Support a menu and settings.
- Loading branch information
Showing
14 changed files
with
172 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
app/src/main/java/org/mozilla/search/SearchPreferenceActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.mozilla.search; | ||
|
||
import android.app.AlertDialog; | ||
import android.content.DialogInterface; | ||
import android.os.AsyncTask; | ||
import android.os.Build; | ||
import android.os.Bundle; | ||
import android.preference.Preference; | ||
import android.preference.PreferenceActivity; | ||
import android.util.Log; | ||
import android.widget.Toast; | ||
|
||
import org.mozilla.gecko.db.BrowserContract; | ||
|
||
/** | ||
* This activity allows users to modify the settings for the search activity. | ||
* | ||
* A note on implementation: At the moment, we don't have tablet-specific designs. | ||
* Therefore, this implementation uses the old-style PreferenceActivity. When | ||
* we start optimizing for tablets, we can migrate to Fennec's PreferenceFragment | ||
* implementation. | ||
* | ||
* TODO: Change this to PreferenceFragment when we stop supporting devices older than SDK 11. | ||
*/ | ||
public class SearchPreferenceActivity extends PreferenceActivity { | ||
|
||
private static final String LOGTAG = "SearchPreferenceActivity"; | ||
|
||
private static final String CLEAR_SEARCH_HISTORY_BUTTON_KEY = "clear_search_history_button"; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { | ||
if (getActionBar() != null) { | ||
getActionBar().setDisplayHomeAsUpEnabled(true); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
protected void onPostCreate(Bundle savedInstanceState) { | ||
super.onPostCreate(savedInstanceState); | ||
setupPrefsScreen(); | ||
} | ||
|
||
@SuppressWarnings("deprecation") | ||
private void setupPrefsScreen() { | ||
addPreferencesFromResource(R.xml.search_preferences); | ||
|
||
final Preference clearHistoryButton = findPreference(CLEAR_SEARCH_HISTORY_BUTTON_KEY); | ||
clearHistoryButton.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { | ||
@Override | ||
public boolean onPreferenceClick(Preference preference) { | ||
final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(SearchPreferenceActivity.this); | ||
dialogBuilder.setNegativeButton(android.R.string.cancel, null); | ||
dialogBuilder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { | ||
@Override | ||
public void onClick(DialogInterface dialog, int which) { | ||
clearHistory(); | ||
} | ||
}); | ||
dialogBuilder.setMessage(R.string.search_pref_clear_history_dialog_message); | ||
dialogBuilder.show(); | ||
return false; | ||
} | ||
}); | ||
} | ||
|
||
private void clearHistory() { | ||
final AsyncTask<Void, Void, Boolean> clearHistoryTask = new AsyncTask<Void, Void, Boolean>() { | ||
@Override | ||
protected Boolean doInBackground(Void... params) { | ||
final int numDeleted = getContentResolver().delete( | ||
BrowserContract.SearchHistory.CONTENT_URI, null, null); | ||
return numDeleted >= 0; | ||
} | ||
|
||
@Override | ||
protected void onPostExecute(Boolean success) { | ||
if (success) { | ||
getContentResolver().notifyChange(BrowserContract.SearchHistory.CONTENT_URI, null); | ||
Toast.makeText(SearchPreferenceActivity.this, SearchPreferenceActivity.this.getResources() | ||
.getString(R.string.search_pref_clear_history_confirmation), Toast.LENGTH_SHORT).show(); | ||
} else { | ||
Log.e(LOGTAG, "Error clearing search history."); | ||
} | ||
} | ||
}; | ||
clearHistoryTask.execute(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<!-- This Source Code Form is subject to the terms of the Mozilla Public | ||
- License, v. 2.0. If a copy of the MPL was not distributed with this | ||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. --> | ||
|
||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<Preference | ||
android:key="clear_search_history_button" | ||
android:title="@string/search_pref_clear_history_title"/> | ||
</PreferenceScreen> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
<string name="search_app_name">&search_app_name;</string> | ||
<string name="search_jump_arrow">&search_jump_arrow;</string> | ||
<string name="search_header_image_content_description">&search_header_image_content_description;</string> | ||
<string name="search_settings_icon">&search_settings_icon;</string> | ||
|
||
<string name="search_app_name">&search_app_name;</string> | ||
<string name="search_for_something">&search_for_something;</string> | ||
|
||
<string name="search_pref_title">&search_pref_title;</string> | ||
<string name="search_pref_clear_history_confirmation">&search_pref_clear_history_confirmation;</string> | ||
<string name="search_pref_clear_history_dialog_message">&search_pref_clear_history_dialog_message;</string> | ||
<string name="search_pref_clear_history_title">&search_pref_clear_history_title;</string> |