Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 4 commits
  • 7 files changed
  • 0 comments
  • 1 contributor
8  res/layout/firststartdialog.xml
@@ -72,6 +72,14 @@
72 72
 			android:hint="@string/StartupDialog_pwHint"
73 73
 			android:contentDescription="@string/StartupDialog_passwd_title"
74 74
 			/>
  75
+	<CheckBox
  76
+			android:id="@+id/create_account"
  77
+			android:layout_width="fill_parent"
  78
+			android:layout_height="wrap_content"
  79
+			android:text="@string/StartupDialog_create_new"
  80
+			style="?attr/dialogTextColor"
  81
+		/>
  82
+
75 83
 	</LinearLayout>
76 84
 	</ScrollView>
77 85
 </LinearLayout>
2  res/values/strings.xml
@@ -24,6 +24,7 @@
24 24
 	<string name="StartupDialog_Username_title">Jabber ID:</string>
25 25
 	<string name="StartupDialog_passwd_title">Password:</string>
26 26
 	<string name="StartupDialog_advanced">Advanced…</string>
  27
+	<string name="StartupDialog_create_new">Register new account</string>
27 28
 
28 29
 	<!-- Notifications -->
29 30
 	<string name="notification_message">Message from %s</string>
@@ -181,6 +182,7 @@
181 182
 	<string name="AboutDialog_DevelopersTitle">Developers</string>
182 183
 	<string name="AboutDialog_DevelopersText">Contact the developers at http://yaxim.org or on freenode IRC: #yaxim</string>
183 184
 	<string name="AboutDialog_LicenceTitle">Licensing</string>
  185
+	<string name="AboutDialog_Vote">Give Feedback</string>
184 186
 	<string name="AboutDialog_LicenceText">
185 187
 		This program is free software; you can redistribute
186 188
 		it and/or
18  src/org/yaxim/androidclient/MainWindow.java
@@ -645,6 +645,19 @@ private void aboutDialog() {
645 645
 			.setIcon(android.R.drawable.ic_dialog_info)
646 646
 			.setView(about)
647 647
 			.setPositiveButton(android.R.string.ok, null)
  648
+			.setNeutralButton(R.string.AboutDialog_Vote, new DialogInterface.OnClickListener() {
  649
+				public void onClick(DialogInterface dialog, int item) {
  650
+					Intent market = new Intent(Intent.ACTION_VIEW,
  651
+						Uri.parse("market://details?id=" + getPackageName()));
  652
+					market.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
  653
+					try {
  654
+						startActivity(market);
  655
+					} catch (Exception e) {
  656
+						// do not crash
  657
+						Log.e(TAG, "could not go to market: " + e);
  658
+					}
  659
+				}
  660
+			})
648 661
 			.create().show();
649 662
 	}
650 663
 
@@ -733,8 +746,9 @@ private void setConnectingStatus(boolean isConnecting) {
733 746
 			mConnectingText.setVisibility(View.GONE);
734 747
 	}
735 748
 	
736  
-	public void startConnection() {
  749
+	public void startConnection(boolean create_account) {
737 750
 		setConnectingStatus(true);
  751
+		xmppServiceIntent.putExtra("create_account", create_account);
738 752
 		startService(xmppServiceIntent);
739 753
 	}
740 754
 
@@ -755,7 +769,7 @@ public void run() {
755 769
 			}).start();
756 770
 
757 771
 		} else
758  
-			startConnection();
  772
+			startConnection(false);
759 773
 	}
760 774
 
761 775
 	private int getConnectDisconnectIcon() {
242  src/org/yaxim/androidclient/dialogs/FirstStartDialog.java
... ...
@@ -1,125 +1,129 @@
1  
-package org.yaxim.androidclient.dialogs;
2  
-
3  
-import org.yaxim.androidclient.XMPPRosterServiceAdapter;
4  
-import org.yaxim.androidclient.exceptions.YaximXMPPAdressMalformedException;
5  
-import org.yaxim.androidclient.preferences.AccountPrefs;
6  
-import org.yaxim.androidclient.util.PreferenceConstants;
7  
-import org.yaxim.androidclient.util.XMPPHelper;
8  
-
9  
-import android.app.AlertDialog;
10  
-import android.content.Context;
11  
-import android.content.DialogInterface;
12  
-import android.content.Intent;
13  
-import android.content.SharedPreferences;
14  
-import android.content.SharedPreferences.Editor;
15  
-import android.graphics.Color;
16  
-import android.os.Bundle;
17  
-import android.preference.PreferenceManager;
18  
-import android.text.Editable;
19  
-import android.text.TextWatcher;
20  
-import android.util.TypedValue;
21  
-import android.view.LayoutInflater;
22  
-import android.view.View;
23  
-import android.widget.Button;
24  
-import android.widget.EditText;
25  
-import org.yaxim.androidclient.MainWindow;
26  
-import org.yaxim.androidclient.R;
27  
-
28  
-public class FirstStartDialog extends AlertDialog implements DialogInterface.OnClickListener,
29  
-		TextWatcher {
30  
-
31  
-	private MainWindow mainWindow;
32  
-	private Button mOkButton;
33  
-	private EditText mEditJabberID;
34  
-	private EditText mEditPassword;
  1
+package org.yaxim.androidclient.dialogs;
  2
+
  3
+import org.yaxim.androidclient.XMPPRosterServiceAdapter;
  4
+import org.yaxim.androidclient.exceptions.YaximXMPPAdressMalformedException;
  5
+import org.yaxim.androidclient.preferences.AccountPrefs;
  6
+import org.yaxim.androidclient.util.PreferenceConstants;
  7
+import org.yaxim.androidclient.util.XMPPHelper;
  8
+
  9
+import android.app.AlertDialog;
  10
+import android.content.Context;
  11
+import android.content.DialogInterface;
  12
+import android.content.Intent;
  13
+import android.content.SharedPreferences;
  14
+import android.content.SharedPreferences.Editor;
  15
+import android.graphics.Color;
  16
+import android.os.Bundle;
  17
+import android.preference.PreferenceManager;
  18
+import android.text.Editable;
  19
+import android.text.TextWatcher;
  20
+import android.util.TypedValue;
  21
+import android.view.LayoutInflater;
  22
+import android.view.View;
  23
+import android.widget.Button;
  24
+import android.widget.CheckBox;
  25
+import android.widget.EditText;
  26
+import org.yaxim.androidclient.MainWindow;
  27
+import org.yaxim.androidclient.R;
  28
+
  29
+public class FirstStartDialog extends AlertDialog implements DialogInterface.OnClickListener,
  30
+		TextWatcher {
  31
+
  32
+	private MainWindow mainWindow;
  33
+	private Button mOkButton;
  34
+	private EditText mEditJabberID;
  35
+	private EditText mEditPassword;
  36
+	private CheckBox mCreateAccount;
35 37
 	private int themedTextColor;
36  
-
37  
-	public FirstStartDialog(MainWindow mainWindow,
38  
-			XMPPRosterServiceAdapter serviceAdapter) {
39  
-		super(mainWindow);
40  
-		this.mainWindow = mainWindow;
41  
-
42  
-		setTitle(R.string.StartupDialog_Title);
43  
-
44  
-		LayoutInflater inflater = (LayoutInflater) mainWindow
45  
-				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
46  
-		View group = inflater.inflate(R.layout.firststartdialog, null, false);
47  
-		setView(group);
48  
-
49  
-		setButton(BUTTON_POSITIVE, mainWindow.getString(android.R.string.ok), this);
50  
-		setButton(BUTTON_NEUTRAL, mainWindow.getString(R.string.StartupDialog_advanced), this);
51  
-
52  
-		mEditJabberID = (EditText) group.findViewById(R.id.StartupDialog_JID_EditTextField);
53  
-		mEditPassword = (EditText) group.findViewById(R.id.StartupDialog_PASSWD_EditTextField);
  38
+
  39
+	public FirstStartDialog(MainWindow mainWindow,
  40
+			XMPPRosterServiceAdapter serviceAdapter) {
  41
+		super(mainWindow);
  42
+		this.mainWindow = mainWindow;
  43
+
  44
+		setTitle(R.string.StartupDialog_Title);
  45
+
  46
+		LayoutInflater inflater = (LayoutInflater) mainWindow
  47
+				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  48
+		View group = inflater.inflate(R.layout.firststartdialog, null, false);
  49
+		setView(group);
  50
+
  51
+		setButton(BUTTON_POSITIVE, mainWindow.getString(android.R.string.ok), this);
  52
+		setButton(BUTTON_NEUTRAL, mainWindow.getString(R.string.StartupDialog_advanced), this);
  53
+
  54
+		mEditJabberID = (EditText) group.findViewById(R.id.StartupDialog_JID_EditTextField);
  55
+		mEditPassword = (EditText) group.findViewById(R.id.StartupDialog_PASSWD_EditTextField);
  56
+		mCreateAccount = (CheckBox) group.findViewById(R.id.create_account);
54 57
 		mEditJabberID.addTextChangedListener(this);
55 58
 		TypedValue tv = new TypedValue();
56 59
 		boolean found = mainWindow.getTheme().resolveAttribute(android.R.attr.editTextColor, tv, true);
57  
-		if (found) {
58  
-			// SDK 11+
  60
+		if (found) {
  61
+			// SDK 11+
59 62
 			themedTextColor = mainWindow.getResources().getColor(tv.resourceId);
60  
-		} else {
  63
+		} else {
61 64
 			// SDK < 11
62  
-			themedTextColor = mainWindow.getResources().getColor(android.R.color.primary_text_light);
63  
-		}
64  
-	}
65  
-
66  
-	public void onCreate(Bundle savedInstanceState) {
67  
-		super.onCreate(savedInstanceState);
68  
-
69  
-		mOkButton = getButton(BUTTON_POSITIVE);
70  
-		mOkButton.setEnabled(false);
71  
-	}
72  
-
73  
-
74  
-	public void onClick(DialogInterface dialog, int which) {
75  
-		switch (which) {
76  
-		case BUTTON_POSITIVE:
77  
-			verifyAndSavePreferences();
78  
-			mainWindow.startConnection();
79  
-			break;
80  
-		case BUTTON_NEUTRAL:
81  
-			verifyAndSavePreferences();
82  
-			mainWindow.startActivity(new Intent(mainWindow, AccountPrefs.class));
83  
-			break;
84  
-		}
85  
-	}
86  
-
87  
-	private void verifyAndSavePreferences() {
88  
-		String password = mEditPassword.getText().toString();
89  
-		String jabberID = mEditJabberID.getText().toString();
90  
-
91  
-		savePreferences(jabberID, password);
92  
-		cancel();
93  
-	}
94  
-
95  
-	public void afterTextChanged(Editable s) {
96  
-		try {
97  
-			XMPPHelper.verifyJabberID(s);
98  
-			mOkButton.setEnabled(true);
99  
-			//mOkButton.setOnClickListener(this);
100  
-			mEditJabberID.setTextColor(themedTextColor);
101  
-		} catch (YaximXMPPAdressMalformedException e) {
102  
-			mOkButton.setEnabled(false);
103  
-			mEditJabberID.setTextColor(Color.RED);
104  
-		}
105  
-	}
106  
-
107  
-	public void beforeTextChanged(CharSequence s, int start, int count,
108  
-			int after) {
109  
-	}
110  
-
111  
-	public void onTextChanged(CharSequence s, int start, int before, int count) {
112  
-	}
113  
-
114  
-	private void savePreferences(String jabberID, String password) {
115  
-		SharedPreferences sharedPreferences = PreferenceManager
116  
-				.getDefaultSharedPreferences(mainWindow);
117  
-		Editor editor = sharedPreferences.edit();
118  
-
119  
-		editor.putString(PreferenceConstants.JID, jabberID);
120  
-		editor.putString(PreferenceConstants.PASSWORD, password);
121  
-		editor.putString(PreferenceConstants.PORT, PreferenceConstants.DEFAULT_PORT);
122  
-		editor.commit();
123  
-	}
124  
-
125  
-}
  65
+			themedTextColor = mainWindow.getResources().getColor(android.R.color.primary_text_light);
  66
+		}
  67
+	}
  68
+
  69
+	public void onCreate(Bundle savedInstanceState) {
  70
+		super.onCreate(savedInstanceState);
  71
+
  72
+		mOkButton = getButton(BUTTON_POSITIVE);
  73
+		mOkButton.setEnabled(false);
  74
+	}
  75
+
  76
+
  77
+	public void onClick(DialogInterface dialog, int which) {
  78
+		switch (which) {
  79
+		case BUTTON_POSITIVE:
  80
+			verifyAndSavePreferences();
  81
+			boolean create_account = mCreateAccount.isChecked();
  82
+			mainWindow.startConnection(create_account);
  83
+			break;
  84
+		case BUTTON_NEUTRAL:
  85
+			verifyAndSavePreferences();
  86
+			mainWindow.startActivity(new Intent(mainWindow, AccountPrefs.class));
  87
+			break;
  88
+		}
  89
+	}
  90
+
  91
+	private void verifyAndSavePreferences() {
  92
+		String password = mEditPassword.getText().toString();
  93
+		String jabberID = mEditJabberID.getText().toString();
  94
+
  95
+		savePreferences(jabberID, password);
  96
+		cancel();
  97
+	}
  98
+
  99
+	public void afterTextChanged(Editable s) {
  100
+		try {
  101
+			XMPPHelper.verifyJabberID(s);
  102
+			mOkButton.setEnabled(true);
  103
+			//mOkButton.setOnClickListener(this);
  104
+			mEditJabberID.setTextColor(themedTextColor);
  105
+		} catch (YaximXMPPAdressMalformedException e) {
  106
+			mOkButton.setEnabled(false);
  107
+			mEditJabberID.setTextColor(Color.RED);
  108
+		}
  109
+	}
  110
+
  111
+	public void beforeTextChanged(CharSequence s, int start, int count,
  112
+			int after) {
  113
+	}
  114
+
  115
+	public void onTextChanged(CharSequence s, int start, int before, int count) {
  116
+	}
  117
+
  118
+	private void savePreferences(String jabberID, String password) {
  119
+		SharedPreferences sharedPreferences = PreferenceManager
  120
+				.getDefaultSharedPreferences(mainWindow);
  121
+		Editor editor = sharedPreferences.edit();
  122
+
  123
+		editor.putString(PreferenceConstants.JID, jabberID);
  124
+		editor.putString(PreferenceConstants.PASSWORD, password);
  125
+		editor.putString(PreferenceConstants.PORT, PreferenceConstants.DEFAULT_PORT);
  126
+		editor.commit();
  127
+	}
  128
+
  129
+}
2  src/org/yaxim/androidclient/service/Smackable.java
@@ -4,7 +4,7 @@
4 4
 
5 5
 
6 6
 public interface Smackable {
7  
-	boolean doConnect() throws YaximXMPPException;
  7
+	boolean doConnect(boolean create_account) throws YaximXMPPException;
8 8
 	boolean isAuthenticated();
9 9
 
10 10
 	void addRosterItem(String user, String alias, String group) throws YaximXMPPException;
12  src/org/yaxim/androidclient/service/SmackableImp.java
@@ -5,6 +5,7 @@
5 5
 import javax.net.ssl.SSLContext;
6 6
 import javax.net.ssl.X509TrustManager;
7 7
 
  8
+import org.jivesoftware.smack.AccountManager;
8 9
 import org.jivesoftware.smack.ConnectionConfiguration;
9 10
 import org.jivesoftware.smack.ConnectionListener;
10 11
 import org.jivesoftware.smack.PacketListener;
@@ -124,8 +125,8 @@ public SmackableImp(YaximConfiguration config,
124 125
 		this.mContentResolver = contentResolver;
125 126
 	}
126 127
 
127  
-	public boolean doConnect() throws YaximXMPPException {
128  
-		tryToConnect();
  128
+	public boolean doConnect(boolean create_account) throws YaximXMPPException {
  129
+		tryToConnect(create_account);
129 130
 		// actually, authenticated must be true now, or an exception must have
130 131
 		// been thrown.
131 132
 		if (isAuthenticated()) {
@@ -196,7 +197,7 @@ public void requestAuthorizationForRosterItem(String user) {
196 197
 		mXMPPConnection.sendPacket(response);
197 198
 	}
198 199
 
199  
-	private void tryToConnect() throws YaximXMPPException {
  200
+	private void tryToConnect(boolean create_account) throws YaximXMPPException {
200 201
 		try {
201 202
 			if (mXMPPConnection.isConnected()) {
202 203
 				try {
@@ -223,6 +224,11 @@ public void reconnectionSuccessful() { }
223 224
 			initServiceDiscovery();
224 225
 			// SMACK auto-logins if we were authenticated before
225 226
 			if (!mXMPPConnection.isAuthenticated()) {
  227
+				if (create_account) {
  228
+					Log.d(TAG, "creating new server account...");
  229
+					AccountManager am = new AccountManager(mXMPPConnection);
  230
+					am.createAccount(mConfig.userName, mConfig.password);
  231
+				}
226 232
 				mXMPPConnection.login(mConfig.userName, mConfig.password,
227 233
 						mConfig.ressource);
228 234
 			}
6  src/org/yaxim/androidclient/service/XMPPService.java
@@ -42,6 +42,7 @@
42 42
 	private Thread mConnectingThread;
43 43
 
44 44
 	private Smackable mSmackable;
  45
+	private boolean create_account = false;
45 46
 	private IXMPPRosterService.Stub mService2RosterConnection;
46 47
 	private IXMPPChatService.Stub mServiceChatConnection;
47 48
 
@@ -125,6 +126,8 @@ public int onStartCommand(Intent intent, int flags, int startId) {
125 126
 		if (intent != null) {
126 127
 			boolean disconnect = intent.getBooleanExtra("disconnect", false);
127 128
 			boolean reconnect = intent.getBooleanExtra("reconnect", false);
  129
+
  130
+			create_account = intent.getBooleanExtra("create_account", false);
128 131
 			
129 132
 			logInfo("disconnect/reconnect: "+disconnect+ " " + reconnect);
130 133
 			if (disconnect) {
@@ -324,7 +327,7 @@ private void doConnect() {
324 327
 			public void run() {
325 328
 				try {
326 329
 					createAdapter();
327  
-					if (!mSmackable.doConnect()) {
  330
+					if (!mSmackable.doConnect(create_account)) {
328 331
 						postConnectionFailed("Inconsistency in Smackable.doConnect()");
329 332
 					}
330 333
 					postConnectionEstablished();
@@ -339,6 +342,7 @@ public void run() {
339 342
 					if (mConnectingThread != null) synchronized(mConnectingThread) {
340 343
 						mConnectingThread = null;
341 344
 					}
  345
+					create_account = false;
342 346
 				}
343 347
 			}
344 348
 

No commit comments for this range

Something went wrong with that request. Please try again.