| @@ -0,0 +1,195 @@ | ||
| package ru.iammaxim.vkmonitor.RequestGenerator; | ||
|
|
||
| import android.app.AlertDialog; | ||
| import android.content.Context; | ||
| import android.os.AsyncTask; | ||
| import android.os.Bundle; | ||
| import android.support.v7.app.AppCompatActivity; | ||
| import android.support.v7.widget.Toolbar; | ||
| import android.view.View; | ||
| import android.widget.Button; | ||
| import android.widget.EditText; | ||
| import android.widget.LinearLayout; | ||
| import android.widget.ProgressBar; | ||
| import android.widget.TextView; | ||
|
|
||
| import org.json.JSONArray; | ||
| import org.json.JSONException; | ||
| import org.json.JSONObject; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| import ru.iammaxim.vkmonitor.Net; | ||
| import ru.iammaxim.vkmonitor.Objects.ObjectMessage; | ||
| import ru.iammaxim.vkmonitor.R; | ||
| import ru.iammaxim.vkmonitor.RequestGenerator.Views.ViewObject; | ||
|
|
||
|
|
||
| public class RequestGeneratorMain extends AppCompatActivity { | ||
| private EditText et1, et2, et4, et5, et6, et7, et8, et9; | ||
| private Button b1, b2; | ||
| private TextView tv1; | ||
| private LinearLayout objs_container; | ||
| private boolean arg1 = false, arg2 = false, arg3 = false; | ||
| public static Context context; | ||
| private ProgressBar progressBar; | ||
|
|
||
| @Override | ||
| protected void onCreate(Bundle savedInstanceState) { | ||
| super.onCreate(savedInstanceState); | ||
| setContentView(R.layout.request_generator_main); | ||
| context = this; | ||
|
|
||
| Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); | ||
| setSupportActionBar(toolbar); | ||
| getSupportActionBar().setDisplayHomeAsUpEnabled(true); | ||
|
|
||
| et1 = (EditText) findViewById(R.id.et1); | ||
| et2 = (EditText) findViewById(R.id.et2); | ||
| et4 = (EditText) findViewById(R.id.et4); | ||
| et5 = (EditText) findViewById(R.id.et5); | ||
| et6 = (EditText) findViewById(R.id.et6); | ||
| et7 = (EditText) findViewById(R.id.et7); | ||
| et8 = (EditText) findViewById(R.id.et8); | ||
| et9 = (EditText) findViewById(R.id.et9); | ||
| b1 = (Button) findViewById(R.id.b1); | ||
| tv1 = (TextView) findViewById(R.id.tv1); | ||
| b2 = (Button) findViewById(R.id.b2); | ||
| tv1.setOnClickListener(new View.OnClickListener() { | ||
| @Override | ||
| public void onClick(View v) { | ||
| AlertDialog dialog = new AlertDialog.Builder(RequestGeneratorMain.context).create(); | ||
| dialog.setMessage(tv1.getText()); | ||
| dialog.show(); | ||
| } | ||
| }); | ||
| objs_container = (LinearLayout) findViewById(R.id.objs_container); | ||
| b1.setOnClickListener(new View.OnClickListener() { | ||
| @Override | ||
| public void onClick(View v) { | ||
| new RunMethod().execute(); | ||
| } | ||
| }); | ||
| b2.setOnClickListener(new View.OnClickListener() { | ||
| @Override | ||
| public void onClick(View v) { | ||
| objs_container.removeAllViews(); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| String getString(final EditText et) { | ||
| String returnText = et.getText().toString(); | ||
| if (returnText.equals("")) { | ||
| runOnUiThread(new Runnable() { | ||
| @Override | ||
| public void run() { | ||
| tv1.setText("One of specified parameters are invalid! Request failed! " + et.toString()); | ||
| } | ||
| }); | ||
| return null; | ||
| } | ||
| return returnText; | ||
| } | ||
|
|
||
| void sendLogMessage(final String str) { | ||
| if (str != null) | ||
| if (!str.equals("")) | ||
| runOnUiThread(new Runnable() { | ||
| @Override | ||
| public void run() { | ||
| tv1.setText(str); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| private class RunMethod extends AsyncTask { | ||
| private String response; | ||
|
|
||
| //noinspection ResourceType | ||
| @Override | ||
| protected Object doInBackground(Object[] params) { | ||
| arg1 = false; | ||
| arg2 = false; | ||
| arg3 = false; | ||
|
|
||
| //noinspection ResourceType | ||
| if (!et6.getEditableText().toString().equals("")) arg1 = true; | ||
| //noinspection ResourceType | ||
| if (!et8.getEditableText().toString().equals("")) arg2 = true; | ||
| //noinspection ResourceType | ||
| if (!et4.getEditableText().toString().equals("")) arg3 = true; | ||
|
|
||
| ArrayList<String> args = new ArrayList<>(); | ||
|
|
||
| if (arg1) | ||
| args.add(getString(et6) + "=" + getString(et7)); | ||
| if (arg2) | ||
| args.add(getString(et8) + "=" + getString(et9)); | ||
| if (arg3) | ||
| args.add(getString(et4) + "=" + getString(et5)); | ||
|
|
||
| try { | ||
| //noinspection ResourceType | ||
| JSONObject json_obj = new JSONObject(response = Net.processRequest(et1.getText().toString() + "." + et2.getText().toString(), true, args.toArray(new String[args.size()]))); | ||
|
|
||
| //noinspection ResourceType | ||
| switch (et1.getText().toString() + "." + et2.getText().toString()) { | ||
| case "messages.getHistory": | ||
| case "messages.get": | ||
| case "messages.getDialogs": | ||
| addMessages(json_obj); | ||
| break; | ||
| default: | ||
| break; | ||
| } | ||
| } catch (IOException | JSONException e) { | ||
| e.printStackTrace(); | ||
| sendLogMessage("Exception thrown:\n" + e.getMessage()); | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| protected void onPostExecute(Object o) { | ||
| super.onPostExecute(o); | ||
| if (response != null) | ||
| tv1.setText(response); | ||
| } | ||
| } | ||
|
|
||
| public void addMessages(final JSONObject msgs) { | ||
| new Thread(new Runnable() { | ||
| @Override | ||
| public void run() { | ||
| try { | ||
| JSONObject json_obj2 = msgs.getJSONObject("response"); | ||
| final JSONArray json_ar2 = json_obj2.getJSONArray("items"); | ||
| final int count = json_ar2.length(); | ||
| final List<View> messages = new ArrayList<>(count); | ||
| for (int i = 0; i < count; i++) { | ||
| JSONObject tmp_obj = (JSONObject) json_ar2.get(i); | ||
| if (tmp_obj.has("message")) | ||
| tmp_obj = tmp_obj.getJSONObject("message"); | ||
| messages.add(new ViewObject(context, new ObjectMessage(tmp_obj)).getView()); | ||
| } | ||
|
|
||
| runOnUiThread(new Runnable() { | ||
| @Override | ||
| public void run() { | ||
| for (View msg : messages) { | ||
| objs_container.addView(msg, 0); | ||
| } | ||
| } | ||
| }); | ||
| } catch (JSONException e) { | ||
| e.printStackTrace(); | ||
| sendLogMessage(e.getMessage() + "\n" + msgs.toString()); | ||
| } | ||
| } | ||
| } | ||
| ).start(); | ||
| } | ||
| } |
| @@ -0,0 +1,92 @@ | ||
| package ru.iammaxim.vkmonitor.RequestGenerator.Views; | ||
|
|
||
| import android.app.AlertDialog; | ||
| import android.content.Context; | ||
| import android.graphics.Color; | ||
| import android.view.View; | ||
| import android.widget.LinearLayout; | ||
| import android.widget.TextView; | ||
|
|
||
| import org.json.JSONArray; | ||
| import org.json.JSONException; | ||
| import org.json.JSONObject; | ||
|
|
||
| import java.text.SimpleDateFormat; | ||
| import java.util.Date; | ||
|
|
||
| import ru.iammaxim.vkmonitor.Objects.ObjectMessage; | ||
| import ru.iammaxim.vkmonitor.R; | ||
| import ru.iammaxim.vkmonitor.RequestGenerator.RequestGeneratorMain; | ||
| import ru.iammaxim.vkmonitor.Users; | ||
|
|
||
| public class ViewObject { | ||
| public static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | ||
|
|
||
| LinearLayout view; | ||
| public String title, json; | ||
| AlertDialog dialog; | ||
|
|
||
| public ViewObject(Context ctx, ObjectMessage msg) { | ||
| title = msg.title; | ||
| json = msg.json.toString(); | ||
| String tmp_title = " "; | ||
| String user_title = Users.get(msg.from_id).getTitle(); | ||
| System.out.println(title + " " + user_title); | ||
| if (!title.equals(user_title) && !msg.out) tmp_title = " (" + title + ") "; | ||
| String date = null; | ||
| try { | ||
| date = sdf.format(new Date(msg.date * 1000)); | ||
| } catch (NumberFormatException e) { | ||
| e.printStackTrace(); | ||
| } | ||
| try { | ||
| this.title = user_title + tmp_title + date; | ||
| } catch (NullPointerException e) { | ||
| e.printStackTrace(); | ||
| } | ||
| view = new LinearLayout(ctx); | ||
| view.setBackground(ctx.getResources().getDrawable(R.drawable.rg_output_window_bg)); | ||
| view.setOrientation(LinearLayout.VERTICAL); | ||
| TextView user_id_tv = new TextView(ctx); | ||
| TextView body = new TextView(ctx); | ||
| user_id_tv.setText(this.title); | ||
| body.setText(msg.body); | ||
| user_id_tv.setTextColor(Color.WHITE); | ||
| body.setTextColor(Color.WHITE); | ||
| view.addView(user_id_tv); | ||
| view.addView(body); | ||
| view.setOnClickListener(new View.OnClickListener() { | ||
| @Override | ||
| public void onClick(View v) { | ||
| showDetails(); | ||
| } | ||
| }); | ||
|
|
||
| json = msg.json.toString(); | ||
| constructForwards(view, msg.json); | ||
| } | ||
|
|
||
| private void constructForwards(LinearLayout v, JSONObject msg) { | ||
| if (msg.has("fwd_messages")) | ||
| try { | ||
| JSONArray msgs = msg.getJSONArray("fwd_messages"); | ||
| for (int i = 0; i < msgs.length(); i++) { | ||
| JSONObject msg1 = msgs.getJSONObject(i); | ||
| view.addView(new ViewObject(v.getContext(), new ObjectMessage(msg1)).view); | ||
| } | ||
| } catch (JSONException e) { | ||
| e.printStackTrace(); | ||
| } | ||
| } | ||
|
|
||
| public View getView() { | ||
| return view; | ||
| } | ||
|
|
||
| public void showDetails() { | ||
| dialog = new AlertDialog.Builder(RequestGeneratorMain.context).create(); | ||
| dialog.setTitle(this.title); | ||
| dialog.setMessage(json); | ||
| dialog.show(); | ||
| } | ||
| } |
| @@ -0,0 +1,7 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> | ||
| <corners android:radius="5dp"/> | ||
| <solid android:color="#41528c"/> | ||
| <stroke android:width="2dp" android:color="#506bc6"/> | ||
| <padding android:bottom="10dp" android:top="10dp" android:left="10dp" android:right="10dp"/> | ||
| </shape> |
| @@ -0,0 +1,7 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> | ||
| <corners android:radius="5dp"/> | ||
| <solid android:color="#283256"/> | ||
| <stroke android:width="2dp" android:color="#506bc6"/> | ||
| <padding android:bottom="10dp" android:top="10dp" android:left="10dp" android:right="10dp"/> | ||
| </shape> |
| @@ -0,0 +1,5 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <selector xmlns:android="http://schemas.android.com/apk/res/android"> | ||
| <item android:state_pressed="true" android:drawable="@drawable/rg_obj_view_bg_pressed"/> | ||
| <item android:drawable="@drawable/rg_obj_view_bg_normal"/> | ||
| </selector> |
| @@ -0,0 +1,212 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <ScrollView xmlns:tools="http://schemas.android.com/tools" | ||
| xmlns:android="http://schemas.android.com/apk/res/android" | ||
| xmlns:app="http://schemas.android.com/apk/res-auto" | ||
| android:id="@+id/scrollView" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="match_parent" | ||
| app:layout_behavior="@string/appbar_scrolling_view_behavior"> | ||
|
|
||
| <LinearLayout | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:orientation="vertical" | ||
| android:paddingBottom="@dimen/activity_vertical_margin" | ||
| android:paddingLeft="@dimen/activity_horizontal_margin" | ||
| android:paddingRight="@dimen/activity_horizontal_margin" | ||
| android:paddingTop="@dimen/activity_vertical_margin" | ||
| tools:context=".MainActivity"> | ||
|
|
||
| <android.support.design.widget.TextInputLayout | ||
| android:id="@+id/til1" | ||
| android:layout_width="wrap_content" | ||
| android:layout_height="wrap_content" | ||
| android:minWidth="200dp"> | ||
|
|
||
| <EditText | ||
| android:id="@+id/et1" | ||
| android:layout_width="wrap_content" | ||
| android:layout_height="wrap_content" | ||
| android:hint="Method group" | ||
| android:minWidth="200dp" /> | ||
|
|
||
| </android.support.design.widget.TextInputLayout> | ||
|
|
||
| <android.support.design.widget.TextInputLayout | ||
| android:id="@+id/til2" | ||
| android:layout_width="wrap_content" | ||
| android:layout_height="wrap_content" | ||
| android:minWidth="200dp"> | ||
|
|
||
| <EditText | ||
| android:id="@+id/et2" | ||
| android:layout_width="wrap_content" | ||
| android:layout_height="wrap_content" | ||
| android:hint="Method name" | ||
| android:minWidth="200dp" /> | ||
|
|
||
| </android.support.design.widget.TextInputLayout> | ||
|
|
||
| <android.support.design.widget.TextInputLayout | ||
| android:id="@+id/til3" | ||
| android:layout_width="wrap_content" | ||
| android:layout_height="wrap_content" | ||
| android:minWidth="200dp"> | ||
|
|
||
| </android.support.design.widget.TextInputLayout> | ||
|
|
||
| <LinearLayout | ||
| android:id="@+id/ll1" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:baselineAligned="false"> | ||
|
|
||
| <android.support.design.widget.TextInputLayout | ||
| android:id="@+id/til6" | ||
| android:layout_width="wrap_content" | ||
| android:layout_height="wrap_content" | ||
| android:layout_weight="1"> | ||
|
|
||
| <EditText | ||
| android:id="@+id/et6" | ||
| android:layout_width="fill_parent" | ||
| android:layout_height="fill_parent" | ||
| android:hint="Argument name" /> | ||
|
|
||
| </android.support.design.widget.TextInputLayout> | ||
|
|
||
| <android.support.design.widget.TextInputLayout | ||
| android:id="@+id/til7" | ||
| android:layout_width="wrap_content" | ||
| android:layout_height="wrap_content" | ||
| android:layout_weight="1"> | ||
|
|
||
| <EditText | ||
| android:id="@+id/et7" | ||
| android:layout_width="fill_parent" | ||
| android:layout_height="fill_parent" | ||
| android:hint="Argument value" /> | ||
|
|
||
| </android.support.design.widget.TextInputLayout> | ||
|
|
||
| </LinearLayout> | ||
|
|
||
| <LinearLayout | ||
| android:id="@+id/ll2" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:baselineAligned="false"> | ||
|
|
||
| <android.support.design.widget.TextInputLayout | ||
| android:id="@+id/til8" | ||
| android:layout_width="wrap_content" | ||
| android:layout_height="wrap_content" | ||
| android:layout_weight="1"> | ||
|
|
||
| <EditText | ||
| android:id="@+id/et8" | ||
| android:layout_width="fill_parent" | ||
| android:layout_height="fill_parent" | ||
| android:hint="Argument name" /> | ||
|
|
||
| </android.support.design.widget.TextInputLayout> | ||
|
|
||
| <android.support.design.widget.TextInputLayout | ||
| android:id="@+id/til9" | ||
| android:layout_width="wrap_content" | ||
| android:layout_height="wrap_content" | ||
| android:layout_weight="1"> | ||
|
|
||
| <EditText | ||
| android:id="@+id/et9" | ||
| android:layout_width="fill_parent" | ||
| android:layout_height="fill_parent" | ||
| android:hint="Argument value" /> | ||
|
|
||
| </android.support.design.widget.TextInputLayout> | ||
|
|
||
| </LinearLayout> | ||
|
|
||
| <LinearLayout | ||
| android:id="@+id/ll3" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content"> | ||
|
|
||
| <android.support.design.widget.TextInputLayout | ||
| android:id="@+id/til4" | ||
| android:layout_width="wrap_content" | ||
| android:layout_height="wrap_content" | ||
| android:layout_weight="1"> | ||
|
|
||
| <EditText | ||
| android:id="@+id/et4" | ||
| android:layout_width="fill_parent" | ||
| android:layout_height="fill_parent" | ||
| android:hint="Argument name" /> | ||
|
|
||
| </android.support.design.widget.TextInputLayout> | ||
|
|
||
| <android.support.design.widget.TextInputLayout | ||
| android:id="@+id/til5" | ||
| android:layout_width="wrap_content" | ||
| android:layout_height="wrap_content" | ||
| android:layout_weight="1"> | ||
|
|
||
| <EditText | ||
| android:id="@+id/et5" | ||
| android:layout_width="fill_parent" | ||
| android:layout_height="fill_parent" | ||
| android:hint="Argument value" /> | ||
|
|
||
| </android.support.design.widget.TextInputLayout> | ||
|
|
||
| </LinearLayout> | ||
|
|
||
| <Button | ||
| android:id="@+id/b1" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:backgroundTint="#506bc6" | ||
| android:text="Run request!" | ||
| android:textColor="#ffffff" /> | ||
|
|
||
| <LinearLayout | ||
| android:id="@+id/log_container" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="200dp" | ||
| android:background="@drawable/rg_output_window_bg" | ||
| android:orientation="vertical"> | ||
|
|
||
| <TextView | ||
| android:id="@+id/tv1" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:text="Here will be an output log" | ||
| android:textColor="#ffffff" | ||
| android:textIsSelectable="true" /> | ||
|
|
||
| </LinearLayout> | ||
|
|
||
| <LinearLayout | ||
| android:id="@+id/objs_container" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:layout_marginTop="10dp" | ||
| android:background="@drawable/rg_output_window_bg" | ||
| android:minHeight="50dp" | ||
| android:orientation="vertical"> | ||
|
|
||
| </LinearLayout> | ||
|
|
||
| <Button | ||
| android:id="@+id/b2" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:backgroundTint="#506bc6" | ||
| android:elevation="1dp" | ||
| android:text="Clear objects" | ||
| android:textColor="#ffffff" /> | ||
|
|
||
| </LinearLayout> | ||
|
|
||
| </ScrollView> |
| @@ -0,0 +1,22 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="match_parent" | ||
| xmlns:app="http://schemas.android.com/apk/res-auto" | ||
| android:fitsSystemWindows="true"> | ||
|
|
||
| <android.support.design.widget.AppBarLayout | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:theme="@style/AppTheme.AppBarOverlay"> | ||
|
|
||
| <android.support.v7.widget.Toolbar | ||
| android:id="@+id/toolbar" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="?attr/actionBarSize" | ||
| android:background="?attr/colorPrimary" | ||
| app:popupTheme="@style/AppTheme.PopupOverlay" /> | ||
| </android.support.design.widget.AppBarLayout> | ||
|
|
||
| <include layout="@layout/content_request_generator_main"/> | ||
| </android.support.design.widget.CoordinatorLayout> |