Bug 1033686 - Make sure pre-search and post-search replace each other. r=nalexander

--HG--
rename : mobile/android/search/java/org/mozilla/search/DetailActivity.java => mobile/android/search/java/org/mozilla/search/PostSearchFragment.java
rename : mobile/android/search/java/org/mozilla/search/stream/CardStreamFragment.java => mobile/android/search/java/org/mozilla/search/PreSearchFragment.java
rename : mobile/android/search/java/org/mozilla/search/autocomplete/AutoCompleteFragment.java => mobile/android/search/java/org/mozilla/search/autocomplete/SearchFragment.java
This commit is contained in:
Eric Edens 2014-07-11 11:42:37 -07:00
Родитель facb3c7516
Коммит 387fa5673a
10 изменённых файлов: 66 добавлений и 98 удалений

Просмотреть файл

@ -15,9 +15,10 @@ package org.mozilla.search;
* https://github.com/ericedens/FirefoxSearch/issues/3
*/
public class Constants {
public static final String AUTO_COMPLETE_FRAGMENT = "org.mozilla.search.AUTO_COMPLETE_FRAGMENT";
public static final String CARD_STREAM_FRAGMENT = "org.mozilla.search.CARD_STREAM_FRAGMENT";
public static final String GECKO_VIEW_FRAGMENT = "org.mozilla.search.GECKO_VIEW_FRAGMENT";
public static final String POSTSEARCH_FRAGMENT = "org.mozilla.search.POSTSEARCH_FRAGMENT";
public static final String PRESEARCH_FRAGMENT = "org.mozilla.search.PRESEARCH_FRAGMENT";
public static final String SEARCH_FRAGMENT = "org.mozilla.search.SEARCH_FRAGMENT";
public static final String AUTOCOMPLETE_ROW_LIMIT = "5";
}

Просмотреть файл

@ -7,13 +7,9 @@ package org.mozilla.search;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import org.mozilla.search.autocomplete.AcceptsSearchQuery;
import org.mozilla.search.autocomplete.AutoCompleteFragment;
import org.mozilla.search.stream.CardStreamFragment;
/**
* The main entrance for the Android search intent.
@ -23,81 +19,52 @@ import org.mozilla.search.stream.CardStreamFragment;
* now, the only message passing occurs when a user wants to submit a search query. That
* passes through the onSearch method here.
*/
public class MainActivity extends FragmentActivity implements AcceptsSearchQuery,
FragmentManager.OnBackStackChangedListener {
public class MainActivity extends FragmentActivity implements AcceptsSearchQuery {
private DetailActivity detailActivity;
enum State {
START,
PRESEARCH,
POSTSEARCH
}
private State state = State.START;
@Override
protected void onCreate(Bundle stateBundle) {
super.onCreate(stateBundle);
// Sets the content view for the Activity
setContentView(R.layout.search_activity_main);
// Gets an instance of the support library FragmentManager
FragmentManager localFragmentManager = getSupportFragmentManager();
// If the incoming state of the Activity is null, sets the initial view to be thumbnails
if (null == stateBundle) {
// Starts a Fragment transaction to track the stack
FragmentTransaction localFragmentTransaction = localFragmentManager.beginTransaction();
localFragmentTransaction.add(R.id.header_fragments, new AutoCompleteFragment(),
Constants.AUTO_COMPLETE_FRAGMENT);
localFragmentTransaction.add(R.id.presearch_fragments, new CardStreamFragment(),
Constants.CARD_STREAM_FRAGMENT);
// Commits this transaction to display the Fragment
localFragmentTransaction.commit();
// The incoming state of the Activity isn't null.
}
}
@Override
protected void onStart() {
super.onStart();
if (null == detailActivity) {
detailActivity = new DetailActivity();
}
if (null == getSupportFragmentManager().findFragmentByTag(Constants.GECKO_VIEW_FRAGMENT)) {
FragmentTransaction txn = getSupportFragmentManager().beginTransaction();
txn.add(R.id.gecko_fragments, detailActivity, Constants.GECKO_VIEW_FRAGMENT);
txn.hide(detailActivity);
txn.commit();
}
startPresearch();
}
@Override
public void onSearch(String s) {
FragmentManager localFragmentManager = getSupportFragmentManager();
FragmentTransaction localFragmentTransaction = localFragmentManager.beginTransaction();
localFragmentTransaction
.hide(localFragmentManager.findFragmentByTag(Constants.CARD_STREAM_FRAGMENT))
.addToBackStack(null);
localFragmentTransaction
.show(localFragmentManager.findFragmentByTag(Constants.GECKO_VIEW_FRAGMENT))
.addToBackStack(null);
localFragmentTransaction.commit();
((DetailActivity) getSupportFragmentManager()
.findFragmentByTag(Constants.GECKO_VIEW_FRAGMENT))
startPostsearch();
((PostSearchFragment) getSupportFragmentManager().findFragmentById(R.id.gecko))
.setUrl("https://search.yahoo.com/search?p=" + Uri.encode(s));
}
@Override
public void onBackStackChanged() {
private void startPresearch() {
if (state != State.PRESEARCH) {
state = State.PRESEARCH;
findViewById(R.id.gecko).setVisibility(View.INVISIBLE);
findViewById(R.id.presearch).setVisibility(View.VISIBLE);
}
}
private void startPostsearch() {
if (state != State.POSTSEARCH) {
state = State.POSTSEARCH;
findViewById(R.id.presearch).setVisibility(View.INVISIBLE);
findViewById(R.id.gecko).setVisibility(View.VISIBLE);
}
}
@Override
public void onBackPressed() {
if (state == State.POSTSEARCH) {
startPresearch();
} else {
super.onBackPressed();
}
}
}

Просмотреть файл

@ -18,15 +18,15 @@ import org.mozilla.gecko.GeckoViewChrome;
import org.mozilla.gecko.GeckoViewContent;
import org.mozilla.gecko.PrefsHelper;
public class DetailActivity extends Fragment {
public class PostSearchFragment extends Fragment {
private static final String LOGTAG = "DetailActivity";
private static final String LOGTAG = "PostSearchFragment";
private GeckoView geckoView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Bundle savedInstanceState) {
View mainView = inflater.inflate(R.layout.search_activity_detail, container, false);

Просмотреть файл

@ -2,14 +2,14 @@
* 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.stream;
package org.mozilla.search;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.View;
import android.widget.ArrayAdapter;
import org.mozilla.search.R;
import org.mozilla.search.stream.PreloadAgent;
/**
@ -17,7 +17,7 @@ import org.mozilla.search.R;
* we only use this during pre-search, but we could also use it
* during post-search at some point.
*/
public class CardStreamFragment extends ListFragment {
public class PreSearchFragment extends ListFragment {
private ArrayAdapter<PreloadAgent.TmpItem> adapter;
@ -25,7 +25,7 @@ public class CardStreamFragment extends ListFragment {
* Mandatory empty constructor for the fragment manager to instantiate the
* fragment (e.g. upon screen orientation changes).
*/
public CardStreamFragment() {
public PreSearchFragment() {
}
@Override

Просмотреть файл

@ -33,7 +33,7 @@ import org.mozilla.search.R;
* TODO: Add clear button to search input
* TODO: Add more search providers (other than the dictionary)
*/
public class AutoCompleteFragment extends Fragment implements AdapterView.OnItemClickListener,
public class SearchFragment extends Fragment implements AdapterView.OnItemClickListener,
TextView.OnEditorActionListener, AcceptsJumpTaps {
private View mainView;
@ -50,13 +50,13 @@ public class AutoCompleteFragment extends Fragment implements AdapterView.OnItem
RUNNING // The user is in search mode.
}
public AutoCompleteFragment() {
public SearchFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Bundle savedInstanceState) {
mainView = inflater.inflate(R.layout.search_auto_complete, container, false);

Просмотреть файл

@ -12,10 +12,10 @@ import java.util.Map;
/**
* A temporary agent for loading cards into the pre-load card stream.
* <p/>
* When we have more agents, we'll want to put an agent manager between the CardStreamFragment
* When we have more agents, we'll want to put an agent manager between the PreSearchFragment
* and the set of all agents. See autocomplete.AutoCompleteFragmentManager.
*/
class PreloadAgent {
public class PreloadAgent {
public static final List<TmpItem> ITEMS = new ArrayList<TmpItem>();

Просмотреть файл

@ -10,7 +10,7 @@
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="org.mozilla.search.DetailActivity">
tools:context="org.mozilla.search.PostSearchFragment">
<org.mozilla.gecko.GeckoView
android:id="@+id/gecko_view"

Просмотреть файл

@ -10,26 +10,25 @@
android:orientation="vertical"
tools:context=".MainActivity">
<FrameLayout
android:id="@+id/gecko_fragments"
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="45dp"
android:name="org.mozilla.search.PostSearchFragment"
android:id="@+id/gecko"
/>
<FrameLayout
android:id="@+id/presearch_fragments"
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="org.mozilla.search.PreSearchFragment"
android:id="@+id/presearch"
/>
<FrameLayout
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="org.mozilla.search.autocomplete.SearchFragment"
android:id="@+id/header_fragments"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</merge>
</merge>

Просмотреть файл

@ -9,13 +9,13 @@ search_activity_sources = [
'java/org/mozilla/search/autocomplete/AcceptsSearchQuery.java',
'java/org/mozilla/search/autocomplete/AutoCompleteAdapter.java',
'java/org/mozilla/search/autocomplete/AutoCompleteAgentManager.java',
'java/org/mozilla/search/autocomplete/AutoCompleteFragment.java',
'java/org/mozilla/search/autocomplete/AutoCompleteModel.java',
'java/org/mozilla/search/autocomplete/AutoCompleteRowView.java',
'java/org/mozilla/search/autocomplete/AutoCompleteWordListAgent.java',
'java/org/mozilla/search/autocomplete/SearchFragment.java',
'java/org/mozilla/search/Constants.java',
'java/org/mozilla/search/DetailActivity.java',
'java/org/mozilla/search/MainActivity.java',
'java/org/mozilla/search/stream/CardStreamFragment.java',
'java/org/mozilla/search/PostSearchFragment.java',
'java/org/mozilla/search/PreSearchFragment.java',
'java/org/mozilla/search/stream/PreloadAgent.java',
]

Просмотреть файл

@ -19,6 +19,7 @@ extensions = [
'sphinx.ext.graphviz',
'sphinx.ext.todo',
'mozbuild.sphinx',
'javasphinx',
]
templates_path = ['_templates']