Skip to content

Commit 15d8293

Browse files
Merge pull request #113 from Omega-R/feature/search_intent_builder
Feature/search intent builder
2 parents 6af9076 + cd2ee58 commit 15d8293

7 files changed

Lines changed: 66 additions & 2 deletions

File tree

.idea/gradle.xml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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
@@ -135,4 +135,10 @@ object OmegaIntentBuilder {
135135
@JvmStatic
136136
fun speechToText() = SpeechToTextBuilder()
137137

138+
/**
139+
* @return SearchWebIntentBuilder
140+
*/
141+
@JvmStatic
142+
fun searchWeb() = SearchWebIntentBuilder()
143+
138144
}
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
@@ -38,6 +38,7 @@ protected void onCreate(Bundle savedInstanceState) {
3838
findViewById(R.id.button_speech_to_text).setOnClickListener(this);
3939
findViewById(R.id.button_service_extra).setOnClickListener(this);
4040
findViewById(R.id.button_fragment_extra).setOnClickListener(this);
41+
findViewById(R.id.button_search_web).setOnClickListener(this);
4142
}
4243

4344
@Override
@@ -91,6 +92,9 @@ public void onClick(View v) {
9192
case R.id.button_fragment_extra:
9293
onExtrasToFragmentClicked();
9394
break;
95+
case R.id.button_search_web:
96+
onSearchWebClicked();
97+
break;
9498
}
9599
}
96100

@@ -240,4 +244,11 @@ private void onExtrasToFragmentClicked() {
240244
// .startActivity();
241245
}
242246

247+
private void onSearchWebClicked() {
248+
OmegaIntentBuilder
249+
.searchWeb()
250+
.query("How much does an elephant weigh")
251+
.startActivity(this);
252+
}
253+
243254
}

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@
104104
android:id="@+id/button_crop_image"
105105
android:layout_width="match_parent"
106106
android:layout_height="wrap_content"
107-
android:theme="@style/ButtonStyle"
108-
android:text="@string/crop_image"/>
107+
android:text="@string/crop_image"
108+
android:theme="@style/ButtonStyle" />
109109

110110
<Button
111111
android:id="@+id/button_pick_image"
@@ -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
</LinearLayout>
143150

144151
</androidx.core.widget.NestedScrollView>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@
2121
<string name="service_extra">Extras to Service</string>
2222
<string name="title_activity_tab">TabActivity</string>
2323
<string name="fragment_extra">Extras to Fragment</string>
24+
<string name="search_web">Search Web</string>
2425
</resources>

0 commit comments

Comments
 (0)