Skip to content

Commit d27a025

Browse files
Merge pull request #114 from Omega-R/feature/search_intent_builder
Feature/search intent builder
2 parents 293eaf6 + b23d99d commit d27a025

5 files changed

Lines changed: 57 additions & 0 deletions

File tree

core/src/main/java/com/omega_r/libs/omegaintentbuilder/OmegaIntentBuilder.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
}

examples/src/main/java/com/omega_r/omegaintentbuilder/MainActivity.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

examples/src/main/res/layout/activity_main.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,13 @@
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"

examples/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@
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>

0 commit comments

Comments
 (0)