зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1022105 - Support a menu and settings. r=liuche,margaret
This commit is contained in:
Родитель
7c5b621872
Коммит
06e01b3bd0
|
@ -5,6 +5,7 @@
|
|||
package org.mozilla.search;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
|
@ -76,7 +77,10 @@ public class PreSearchFragment extends Fragment {
|
|||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
|
||||
listView = (ListView) inflater.inflate(R.layout.search_fragment_pre_search, container, false);
|
||||
final View mainView = inflater.inflate(R.layout.search_fragment_pre_search, container, false);
|
||||
|
||||
// Initialize listview.
|
||||
listView = (ListView) mainView.findViewById(R.id.list_view);
|
||||
listView.setAdapter(cursorAdapter);
|
||||
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
|
@ -91,7 +95,15 @@ public class PreSearchFragment extends Fragment {
|
|||
}
|
||||
}
|
||||
});
|
||||
return listView;
|
||||
|
||||
// Apply click handler to settings button.
|
||||
mainView.findViewById(R.id.settings_button).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
startActivity(new Intent(getActivity(), SearchPreferenceActivity.class));
|
||||
}
|
||||
});
|
||||
return mainView;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -3,10 +3,6 @@
|
|||
android:label="@string/search_app_name"
|
||||
android:theme="@style/AppTheme"
|
||||
android:screenOrientation="portrait">
|
||||
|
||||
<!-- Add this to activity declaration to hide keyboard on launch -->
|
||||
<!-- android:windowSoftInputMode="stateHidden" -->
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
|
||||
|
@ -18,3 +14,13 @@
|
|||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name="org.mozilla.search.SearchPreferenceActivity"
|
||||
android:label="@string/search_pref_title"
|
||||
android:parentActivityName="org.mozilla.search.MainActivity"
|
||||
android:theme="@style/SettingsTheme" >
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value="org.mozilla.search.MainActivity"/>
|
||||
</activity>
|
||||
|
|
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 225 B |
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 197 B |
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 267 B |
|
@ -2,9 +2,26 @@
|
|||
- 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/. -->
|
||||
|
||||
<ListView
|
||||
<FrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:divider="@null"
|
||||
android:dividerHeight="0dp"/>
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<ListView
|
||||
android:id="@+id/list_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:divider="@null"
|
||||
android:dividerHeight="0dp"/>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/settings_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@android:color/transparent"
|
||||
android:padding="15dp"
|
||||
android:src="@drawable/ic_action_overflow"
|
||||
android:text="@string/search_settings_icon"
|
||||
android:layout_gravity="bottom|right"/>
|
||||
|
||||
</FrameLayout>
|
||||
|
|
|
@ -10,4 +10,6 @@
|
|||
<item name="android:colorBackground">@color/global_background_color</item>
|
||||
</style>
|
||||
|
||||
<style name="SettingsTheme" parent="@android:style/Theme.Holo.Light"/>
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -10,4 +10,6 @@
|
|||
<item name="android:colorBackground">@color/global_background_color</item>
|
||||
</style>
|
||||
|
||||
<style name="SettingsTheme" parent="@android:style/Theme.Light"/>
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -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>
|
|
@ -15,4 +15,5 @@ search_activity_sources = [
|
|||
'java/org/mozilla/search/MainActivity.java',
|
||||
'java/org/mozilla/search/PostSearchFragment.java',
|
||||
'java/org/mozilla/search/PreSearchFragment.java',
|
||||
'java/org/mozilla/search/SearchPreferenceActivity.java',
|
||||
]
|
||||
|
|
|
@ -3,6 +3,12 @@
|
|||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||
|
||||
<!ENTITY search_jump_arrow '↖'>
|
||||
<!ENTITY search_settings_icon '⋮'>
|
||||
|
||||
<!ENTITY search_app_name 'Firefox Search'>
|
||||
<!ENTITY search_header_image_content_description 'Firefox Search Header Image'>
|
||||
<!ENTITY search_for_something 'Search for something'>
|
||||
|
||||
<!ENTITY search_pref_title 'Settings'>
|
||||
<!ENTITY search_pref_clear_history_confirmation 'History cleared'>
|
||||
<!ENTITY search_pref_clear_history_dialog_message 'Delete all search history from this device?'>
|
||||
<!ENTITY search_pref_clear_history_title 'Clear search history'>
|
||||
|
|
|
@ -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>
|
||||
|
|
Загрузка…
Ссылка в новой задаче