aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlaco0416 <laco0416@gmail.com>2014-09-15 00:44:55 +0900
committerlaco0416 <laco0416@gmail.com>2014-09-15 00:44:55 +0900
commit4290a16f5f51979d67ecdbda62537940ee0a53db (patch)
treeea53553731fc9a0f91b8a98cafb83dcd1b6ac6ad
parent971170051ea6450c6aec08eb0f4f5a281d931deb (diff)
downloadSmileEssence-4290a16f5f51979d67ecdbda62537940ee0a53db.tar.gz
Close #58 Add SearchOnGoogle command
-rw-r--r--res/layout/dialog_search_on_google.xml69
-rw-r--r--res/values-ja/strings.xml1
-rw-r--r--res/values/commands.xml1
-rw-r--r--res/values/strings.xml1
-rw-r--r--src/net/lacolaco/smileessence/command/Command.java1
-rw-r--r--src/net/lacolaco/smileessence/command/status/StatusCommandSearchOnGoogle.java67
-rw-r--r--src/net/lacolaco/smileessence/view/dialog/SearchOnGoogleDialogFragment.java146
7 files changed, 286 insertions, 0 deletions
diff --git a/res/layout/dialog_search_on_google.xml b/res/layout/dialog_search_on_google.xml
new file mode 100644
index 00000000..20fbc5dc
--- /dev/null
+++ b/res/layout/dialog_search_on_google.xml
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+ ~ The MIT License (MIT)
+ ~
+ ~ Copyright (c) 2012-2014 lacolaco.net
+ ~
+ ~ Permission is hereby granted, free of charge, to any person obtaining a copy
+ ~ of this software and associated documentation files (the "Software"), to deal
+ ~ in the Software without restriction, including without limitation the rights
+ ~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ ~ copies of the Software, and to permit persons to whom the Software is
+ ~ furnished to do so, subject to the following conditions:
+ ~
+ ~ The above copyright notice and this permission notice shall be included in all
+ ~ copies or substantial portions of the Software.
+ ~
+ ~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ ~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ ~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ ~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ ~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ ~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ ~ SOFTWARE.
+ -->
+
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:padding="15dp"
+ android:background="?attr/page_background">
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal"
+ android:layout_marginBottom="10dp"
+ android:baselineAligned="false">
+
+ <EditText
+ android:id="@+id/edittext_search_on_google"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:gravity="top"
+ android:inputType="text|textMultiLine">
+
+ <requestFocus/>
+ </EditText>
+ </LinearLayout>
+
+ <FrameLayout
+ android:layout_width="match_parent"
+ android:layout_height="40dp"
+ android:layout_gravity="fill"
+ android:background="?attr/button_round_blue">
+
+ <Button
+ android:id="@+id/button_submit"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:gravity="center"
+ style="?attr/custom_button_transparent"
+ android:text="@string/command_search_on_google"
+ android:textStyle="bold"
+ android:textColor="?attr/button_blue_foreground"/>
+ </FrameLayout>
+</LinearLayout> \ No newline at end of file
diff --git a/res/values-ja/strings.xml b/res/values-ja/strings.xml
index b52275ad..0ac821ae 100644
--- a/res/values-ja/strings.xml
+++ b/res/values-ja/strings.xml
@@ -225,4 +225,5 @@
<string name="command_save_as_template">定型文として保存する</string>
<string name="command_paste_to_post">投稿欄に貼り付ける</string>
<string name="command_search_on_twitter">Twitterで検索する</string>
+ <string name="command_search_on_google">Googleで検索する</string>
</resources>
diff --git a/res/values/commands.xml b/res/values/commands.xml
index d1677a4f..02bfc1f3 100644
--- a/res/values/commands.xml
+++ b/res/values/commands.xml
@@ -46,4 +46,5 @@
<item name="key_command_status_add_to_reply" type="id"/>
<item name="key_command_status_open_chain" type="id"/>
<item name="key_command_status_add_to_ignore" type="id"/>
+ <item name="key_command_status_search_on_google" type="id"/>
</resources> \ No newline at end of file
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 5fa74e6a..a7af3f11 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -226,4 +226,5 @@
<string name="command_create_search_page_dialog">Search page</string>
<string name="command_paste_to_post">Paste to post</string>
<string name="command_search_on_twitter">Search on Twitter</string>
+ <string name="command_search_on_google">Search on Google</string>
</resources>
diff --git a/src/net/lacolaco/smileessence/command/Command.java b/src/net/lacolaco/smileessence/command/Command.java
index c3ea509f..e76fb5e4 100644
--- a/src/net/lacolaco/smileessence/command/Command.java
+++ b/src/net/lacolaco/smileessence/command/Command.java
@@ -94,6 +94,7 @@ public abstract class Command implements IViewModel
commands.add(new StatusCommandShare(activity, status));
commands.add(new StatusCommandOpenInBrowser(activity, status));
commands.add(new StatusCommandClipboard(activity, status));
+ commands.add(new StatusCommandSearchOnGoogle(activity, status));
commands.add(new StatusCommandTofuBuster(activity, status));
commands.add(new StatusCommandNanigaja(activity, status, account));
commands.add(new StatusCommandMakeAnonymous(activity, status, account));
diff --git a/src/net/lacolaco/smileessence/command/status/StatusCommandSearchOnGoogle.java b/src/net/lacolaco/smileessence/command/status/StatusCommandSearchOnGoogle.java
new file mode 100644
index 00000000..b044e5ac
--- /dev/null
+++ b/src/net/lacolaco/smileessence/command/status/StatusCommandSearchOnGoogle.java
@@ -0,0 +1,67 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2012-2014 lacolaco.net
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package net.lacolaco.smileessence.command.status;
+
+import android.app.Activity;
+import net.lacolaco.smileessence.R;
+import net.lacolaco.smileessence.view.dialog.DialogHelper;
+import net.lacolaco.smileessence.view.dialog.SearchOnGoogleDialogFragment;
+import twitter4j.Status;
+
+public class StatusCommandSearchOnGoogle extends StatusCommand
+{
+
+ // --------------------------- CONSTRUCTORS ---------------------------
+
+ public StatusCommandSearchOnGoogle(Activity activity, Status status)
+ {
+ super(R.id.key_command_status_search_on_google, activity, status);
+ }
+
+ // --------------------- GETTER / SETTER METHODS ---------------------
+
+ @Override
+ public String getText()
+ {
+ return getActivity().getString(R.string.command_search_on_google);
+ }
+
+ @Override
+ public boolean isEnabled()
+ {
+ return true;
+ }
+
+ // -------------------------- OTHER METHODS --------------------------
+
+ @Override
+ public boolean execute()
+ {
+ SearchOnGoogleDialogFragment dialogFragment = new SearchOnGoogleDialogFragment();
+ dialogFragment.setText(getOriginalStatus().getText());
+ DialogHelper.showDialog(getActivity(), dialogFragment);
+ return false;
+ }
+}
diff --git a/src/net/lacolaco/smileessence/view/dialog/SearchOnGoogleDialogFragment.java b/src/net/lacolaco/smileessence/view/dialog/SearchOnGoogleDialogFragment.java
new file mode 100644
index 00000000..c31b5316
--- /dev/null
+++ b/src/net/lacolaco/smileessence/view/dialog/SearchOnGoogleDialogFragment.java
@@ -0,0 +1,146 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2012-2014 lacolaco.net
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package net.lacolaco.smileessence.view.dialog;
+
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.app.DialogFragment;
+import android.app.SearchManager;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.text.Editable;
+import android.text.TextUtils;
+import android.text.TextWatcher;
+import android.view.View;
+import android.view.inputmethod.InputMethodManager;
+import android.widget.Button;
+import android.widget.EditText;
+import net.lacolaco.smileessence.R;
+
+public class SearchOnGoogleDialogFragment extends DialogFragment implements TextWatcher, View.OnClickListener
+{
+
+ // ------------------------------ FIELDS ------------------------------
+
+ private static String textKey = "key";
+ private String text;
+ private EditText editText;
+ private Button button;
+
+ // --------------------- GETTER / SETTER METHODS ---------------------
+
+ public void setText(String text)
+ {
+ Bundle args = new Bundle();
+ args.putString(textKey, text);
+ setArguments(args);
+ }
+
+ // ------------------------ INTERFACE METHODS ------------------------
+
+
+ // --------------------- Interface OnClickListener ---------------------
+
+ @Override
+ public void onClick(View v)
+ {
+ int id = v.getId();
+ switch(id)
+ {
+ case R.id.button_submit:
+ {
+ execute();
+ break;
+ }
+ }
+ }
+
+ // --------------------- Interface TextWatcher ---------------------
+
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after)
+ {
+
+ }
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count)
+ {
+ if(TextUtils.isEmpty(text))
+ {
+ button.setEnabled(false);
+ }
+ else
+ {
+ button.setEnabled(true);
+ }
+ }
+
+ @Override
+ public void afterTextChanged(Editable s)
+ {
+
+ }
+
+ // ------------------------ OVERRIDE METHODS ------------------------
+
+ @Override
+ public void onCreate(Bundle savedInstanceState)
+ {
+ super.onCreate(savedInstanceState);
+ Bundle args = getArguments();
+ text = args.getString(textKey);
+ }
+
+ @Override
+ public Dialog onCreateDialog(Bundle savedInstanceState)
+ {
+ View view = getActivity().getLayoutInflater().inflate(R.layout.dialog_search_on_google, null);
+ editText = (EditText) view.findViewById(R.id.edittext_search_on_google);
+ editText.addTextChangedListener(this);
+ button = (Button) view.findViewById(R.id.button_submit);
+ button.setOnClickListener(this);
+ editText.setText(text);
+ return new AlertDialog.Builder(getActivity())
+ .setView(view)
+ .create();
+ }
+
+ private void hideIME()
+ {
+ InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
+ imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
+ }
+
+ private void execute()
+ {
+ hideIME();
+ Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
+ intent.putExtra(SearchManager.QUERY, editText.getText().toString());
+ getActivity().startActivity(intent);
+ DialogHelper.closeAll(getActivity());
+ }
+}