File tree Expand file tree Collapse file tree
core/src/main/java/com/omega_r/libs/omegaintentbuilder
java/com/omega_r/omegaintentbuilder Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -141,4 +141,10 @@ object OmegaIntentBuilder {
141141 @JvmStatic
142142 fun insertContact () = InsertContactIntentBuilder ()
143143
144+ /* *
145+ * @return SearchWebIntentBuilder
146+ */
147+ @JvmStatic
148+ fun searchWeb () = SearchWebIntentBuilder ()
149+
144150}
Original file line number Diff line number Diff line change 1+ package com.omega_r.libs.omegaintentbuilder.builders
2+
3+ import android.app.SearchManager.QUERY
4+ import android.content.Context
5+ import android.content.Intent
6+
7+ class SearchWebIntentBuilder : BaseActivityBuilder () {
8+ private var query: String? = null
9+
10+ /* *
11+ * Set the query to the web browser
12+ * is the text to search for. If it is a url starts with http or https,
13+ * the site will be opened.
14+ * If it is plain text, Google search will be applied.
15+ *
16+ * @param query String
17+ * @return This SearchWebIntentBuilder for method chaining
18+ */
19+ fun query (query : String ): SearchWebIntentBuilder {
20+ this .query = query
21+ return this
22+ }
23+
24+ override fun createIntent (context : Context ): Intent {
25+ return Intent (Intent .ACTION_WEB_SEARCH ).apply {
26+ query?.let {
27+ putExtra(QUERY , query)
28+ }
29+ }
30+ }
31+
32+ }
Original file line number Diff line number Diff line change @@ -41,6 +41,7 @@ protected void onCreate(Bundle savedInstanceState) {
4141 findViewById (R .id .button_service_extra ).setOnClickListener (this );
4242 findViewById (R .id .button_fragment_extra ).setOnClickListener (this );
4343 findViewById (R .id .button_insert_contact ).setOnClickListener (this );
44+ findViewById (R .id .button_search_web ).setOnClickListener (this );
4445 }
4546
4647 @ Override
@@ -97,6 +98,9 @@ public void onClick(View v) {
9798 case R .id .button_insert_contact :
9899 onInsertContactClicked ();
99100 break ;
101+ case R .id .button_search_web :
102+ onSearchWebClicked ();
103+ break ;
100104 }
101105 }
102106
@@ -276,4 +280,11 @@ private void onInsertContactClicked() {
276280 .startActivity ();
277281 }
278282
283+ private void onSearchWebClicked () {
284+ OmegaIntentBuilder
285+ .searchWeb ()
286+ .query ("How much does an elephant weigh" )
287+ .startActivity (this );
288+ }
289+
279290}
Original file line number Diff line number Diff line change 139139 android : theme =" @style/ButtonStyle"
140140 android : text =" @string/fragment_extra" />
141141
142+ <Button
143+ android : id =" @+id/button_search_web"
144+ android : layout_width =" match_parent"
145+ android : layout_height =" wrap_content"
146+ android : theme =" @style/ButtonStyle"
147+ android : text =" @string/search_web" />
148+
142149 <Button
143150 android : id =" @+id/button_insert_contact"
144151 android : layout_width =" match_parent"
Original file line number Diff line number Diff line change 2222 <string name =" title_activity_tab" >TabActivity</string >
2323 <string name =" fragment_extra" >Extras to Fragment</string >
2424 <string name =" insert_contact" >Insert Contact</string >
25+ <string name =" search_web" >Search Web</string >
2526</resources >
You can’t perform that action at this time.
0 commit comments