Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Allow to externally set host and port.

  • Loading branch information...
commit 2654f453b455a4dbee40b931d38ec5b10a12f925 1 parent 60eaff3
Heiko W. Rupp authored
8 res/menu/main_menu.xml
View
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+
+ <item android:title="Preferences"
+ android:id="@+id/preferences"
+ />
+</menu>
14 res/xml/preferences.xml
View
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
+ <EditTextPreference android:defaultValue="172.31.7.7"
+ android:key="host"
+ android:title="Remote Server"
+ android:summary="Remote server to connect to"
+ />
+ <EditTextPreference android:defaultValue="7080"
+ android:key="port"
+ android:title="Remote Port"
+ android:summary="Remote server port to connect to"
+ />
+</PreferenceScreen>
36 src/org/rhq/pocket/Preferences.java
View
@@ -0,0 +1,36 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2011 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.rhq.pocket;
+
+import android.os.Bundle;
+import android.preference.PreferenceActivity;
+
+/**
+ * Handling of the Preferences
+ * @author Heiko W. Rupp
+ */
+public class Preferences extends PreferenceActivity {
+
+ /** Called when the activity is first created. */
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ addPreferencesFromResource(R.xml.preferences);
+ }
+
+}
25 src/org/rhq/pocket/StartActivity.java
View
@@ -8,6 +8,10 @@
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
+import android.util.Log;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
import android.widget.TabHost;
import android.widget.TextView;
@@ -82,4 +86,25 @@ public void onFailure(Exception e) {
tst.execute();
}
+
+ public boolean onCreateOptionsMenu(Menu menu) {
+ MenuInflater inflater = getMenuInflater();
+
+ inflater.inflate(R.menu.main_menu,menu);
+ return true;
+ }
+
+ public boolean onOptionsItemSelected(MenuItem item) {
+ Intent i;
+ // Handle item selection
+ switch (item.getItemId()) {
+ case R.id.preferences:
+ i = new Intent(this, Preferences.class);
+ startActivity(i);
+ break;
+ default:
+ Log.e(getClass().getName(),"Unknown menu item :"+ item.toString());
+ }
+ return true;
+ }
}
13 src/org/rhq/pocket/TalkToServerTask.java
View
@@ -27,7 +27,9 @@
import android.app.Dialog;
import android.content.Context;
+import android.content.SharedPreferences;
import android.os.AsyncTask;
+import android.preference.PreferenceManager;
import android.util.Log;
import android.widget.TextView;
@@ -61,7 +63,8 @@ protected JsonNode doInBackground(JsonNode... nodes) {
long t1 = System.currentTimeMillis();
try {
// http://localhost:7080/rest/resource/r/10001
- String urlString = "http://172.31.7.7:7080/rest";
+// String urlString = "http://172.31.7.7:7080/rest";
+ String urlString = getHostPort() + "/rest";
urlString =urlString + subUrl;
URL url = new URL(urlString);
@@ -136,4 +139,12 @@ protected void onPostExecute(JsonNode jsonNode) {
callback.onSuccess(inner);
}
+
+ String getHostPort() {
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
+ String host = prefs.getString("host","172.31.7.7");
+ String port = prefs.getString("port","7080");
+
+ return "http://"+host+":"+port; // TODO make https the default
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.