Skip to content

Commit

Permalink
added api files
Browse files Browse the repository at this point in the history
  • Loading branch information
madhur committed May 17, 2015
1 parent 2cf98e0 commit 486114b
Show file tree
Hide file tree
Showing 36 changed files with 1,638 additions and 68 deletions.
3 changes: 2 additions & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions RabbitMonitor.iml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<module external.linked.project.id="RabbitMonitor" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="java-gradle" name="Java-Gradle">
<configuration>
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
<option name="BUILDABLE" value="false" />
</configuration>
</facet>
</component>
Expand All @@ -15,5 +16,4 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

</module>
8 changes: 8 additions & 0 deletions app/:app.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
4 changes: 2 additions & 2 deletions app/app.iml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="mq-monitor" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="RabbitMonitor" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
Expand Down Expand Up @@ -91,7 +91,7 @@
<orderEntry type="library" exported="" name="appcompat-v7-22.1.1" level="project" />
<orderEntry type="library" exported="" name="volley" level="project" />
<orderEntry type="library" exported="" name="support-v4-22.1.1" level="project" />
<orderEntry type="library" exported="" name="gson-2.3" level="project" />
<orderEntry type="library" exported="" name="support-annotations-22.1.1" level="project" />
<orderEntry type="library" exported="" name="gson-2.3" level="project" />
</component>
</module>
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<uses-permission android:name="android.permission.INTERNET"></uses-permission>

<application
<application android:name=".App"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
Expand Down
47 changes: 47 additions & 0 deletions app/src/main/java/in/co/madhur/rabbitmonitor/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,55 @@

import android.app.Application;

import com.android.volley.Cache;
import com.android.volley.Network;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.BasicNetwork;
import com.android.volley.toolbox.DiskBasedCache;
import com.android.volley.toolbox.HurlStack;

/**
* Created by madhur on 4/26/15.
*/
public class App extends Application {

private RequestQueue requestQueue;
private static App instance;

@Override
public void onCreate() {
super.onCreate();

instance = this;
}

/**
* Get Volley request queue
* @return
*/
public RequestQueue getRequestQueue()
{
if(requestQueue==null)
{
// Instantiate the cache
Cache cache = new DiskBasedCache(getCacheDir(), 1024 * 1024); // 1MB cap

// Set up the network to use HttpURLConnection as the HTTP client.
Network network = new BasicNetwork(new HurlStack());

// Instantiate the RequestQueue with the cache and network.
requestQueue = new RequestQueue(cache, network);

requestQueue.start();
}


return requestQueue;

}

public static App getInstance()
{
return instance;
}
}
12 changes: 12 additions & 0 deletions app/src/main/java/in/co/madhur/rabbitmonitor/Constants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package in.co.madhur.rabbitmonitor;

/**
* Created by madhur on 5/17/15.
*/
public class Constants {

public static final String OVERVIEW_API="/api/overview";
public static final String QUEUE_API="/api/queues";

public static final String TAG="mqmonitor";
}
60 changes: 59 additions & 1 deletion app/src/main/java/in/co/madhur/rabbitmonitor/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
package in.co.madhur.rabbitmonitor;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;

import org.json.JSONObject;

import in.co.madhur.rabbitmonitor.request.GsonRequest;

/**
* Created by madhur on 4/26/15.
Expand Down Expand Up @@ -41,8 +50,57 @@ public boolean onOptionsItemSelected(MenuItem item) {
startActivity(i);
break;

case R.id.action_refresh:
refreshStatus();

}

return false;
}

/**
* Refresh status
*/
private void refreshStatus()
{
AppPreferences appPreferences = new AppPreferences(this);
String hostName = appPreferences.getMetadata(AppPreferences.Keys.HOSTNAME);
String port = appPreferences.getMetadata(AppPreferences.Keys.PORT);

if(hostName.length()==0 || port.length()==0)
{
Toast.makeText(this, getString(R.string.incomplete_info), Toast.LENGTH_SHORT).show();
return;
}

String url = "http://"+hostName+":"+port+Constants.OVERVIEW_API;

Log.d(Constants.TAG, url);

GsonRequest jsObjRequest = new GsonRequest
(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {

@Override
public void onResponse(JSONObject response) {
Log.d(Constants.TAG, response.toString());
}
}, new Response.ErrorListener() {

@Override
public void onErrorResponse(VolleyError error) {
// TODO Auto-generated method stub
if(error.networkResponse.statusCode==401)
{
Toast.makeText(MainActivity.this, getString(R.string.invalid_creds), Toast.LENGTH_SHORT).show();
return;
}

}
});

// Access the RequestQueue through your singleton class.
App.getInstance().getRequestQueue().add(jsObjRequest);


}
}
41 changes: 20 additions & 21 deletions app/src/main/java/in/co/madhur/rabbitmonitor/SettingsActivity.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,18 @@
package in.co.madhur.rabbitmonitor;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.Configuration;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceCategory;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.preference.RingtonePreference;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatDelegate;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;


import java.util.List;
import android.widget.LinearLayout;

/**
* A {@link PreferenceActivity} that presents a set of application settings. On
Expand Down Expand Up @@ -62,18 +48,31 @@ protected void onCreate(Bundle savedInstanceState) {
getDelegate().onCreate(savedInstanceState);
super.onCreate(savedInstanceState);

//Finally, let's add the Toolbar
//getDelegate().setContentView(R.layout.settings_toolbar);
// setContentView(R.layout.settings_toolbar);
//Toolbar toolbar= (Toolbar) findViewById(R.id.toolbar);
//getDelegate().setSupportActionBar(toolbar);

}

@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
getDelegate().onPostCreate(savedInstanceState);
setupSimplePreferencesScreen();

LinearLayout root = (LinearLayout)findViewById(android.R.id.list).getParent().getParent().getParent();
Toolbar bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.settings_toolbar, root, false);
root.addView(bar, 0); // insert at top
bar.setTitle(getString(R.string.app_name));

setSupportActionBar(bar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
bar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});



}

/**
Expand Down
29 changes: 29 additions & 0 deletions app/src/main/java/in/co/madhur/rabbitmonitor/api/AckDetails.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

package in.co.madhur.rabbitmonitor.api;

import com.google.gson.annotations.Expose;

public class AckDetails {

@Expose
private Double rate;

/**
*
* @return
* The rate
*/
public Double getRate() {
return rate;
}

/**
*
* @param rate
* The rate
*/
public void setRate(Double rate) {
this.rate = rate;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

package in.co.madhur.rabbitmonitor.api;

import com.google.gson.annotations.Expose;

public class ConfirmDetails {

@Expose
private Double rate;

/**
*
* @return
* The rate
*/
public Double getRate() {
return rate;
}

/**
*
* @param rate
* The rate
*/
public void setRate(Double rate) {
this.rate = rate;
}

}
Loading

0 comments on commit 486114b

Please sign in to comment.