1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-03 09:49:19 +02:00

Default emails && NetworkDialog bugfix

git-svn-id: https://only.mawhrin.net/repos/FBReaderJ/trunk@1701 6a642e6f-84f6-412e-ac94-c4a38d5a04b0
This commit is contained in:
Vasiliy Bout 2010-09-06 18:26:32 +00:00
parent 7e5b6eca26
commit c3fba9899d
12 changed files with 135 additions and 19 deletions

View file

@ -7,6 +7,7 @@ drawable_res_dir = "res/drawable"
tree_icons_dir = "icons/tree" tree_icons_dir = "icons/tree"
menu_icons_dir = "icons/menu" menu_icons_dir = "icons/menu"
tabs_icons_dir = "icons/tabs" tabs_icons_dir = "icons/tabs"
others_icons_dir = "icons/others"
text_search_icons_dir = "icons/text_search" text_search_icons_dir = "icons/text_search"
data_dir = "data" data_dir = "data"
@ -35,4 +36,5 @@ shutil.copyfile("icons/fbreader.png", drawable_res_dir + "/fbreader.png")
process_data_dir("", tree_icons_dir, drawable_res_dir, 0) process_data_dir("", tree_icons_dir, drawable_res_dir, 0)
process_data_dir("", menu_icons_dir, drawable_res_dir, 0) process_data_dir("", menu_icons_dir, drawable_res_dir, 0)
process_data_dir("", tabs_icons_dir, drawable_res_dir, 0) process_data_dir("", tabs_icons_dir, drawable_res_dir, 0)
process_data_dir("", others_icons_dir, drawable_res_dir, 0)
process_data_dir("text_search_", text_search_icons_dir, drawable_res_dir, 0) process_data_dir("text_search_", text_search_icons_dir, drawable_res_dir, 0)

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false" android:drawable="@drawable/dropdown_normal" />
<item android:state_pressed="true" android:drawable="@drawable/dropdown_pressed" />
<item android:state_focused="true" android:state_pressed="false" android:drawable="@drawable/dropdown_selected" />
<item android:drawable="@drawable/dropdown_normal" />
</selector>

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

View file

@ -58,13 +58,28 @@
android:singleLine="true" android:singleLine="true"
android:layout_marginTop="5dp" android:layout_marginTop="5dp"
/> />
<EditText <RelativeLayout
android:id="@+id/network_register_email"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:singleLine="true" >
android:inputType="textEmailAddress" <Button
/> android:id="@+id/network_register_email_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/dropdown"
android:layout_alignParentRight="true"
/>
<EditText
android:id="@+id/network_register_email"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:inputType="textEmailAddress"
android:layout_toLeftOf="@id/network_register_email_button"
android:layout_alignWithParentIfMissing="true"
android:layout_alignParentLeft="true"
/>
</RelativeLayout>
<TextView <TextView
android:id="@+id/network_register_error" android:id="@+id/network_register_error"
android:layout_width="fill_parent" android:layout_width="fill_parent"

View file

@ -126,7 +126,7 @@ class AuthenticationDialog extends NetworkDialog {
} }
@Override @Override
public void prepareDialog(Dialog dialog) { public void prepareDialogInternal(Dialog dialog) {
final NetworkAuthenticationManager mgr = myLink.authenticationManager(); final NetworkAuthenticationManager mgr = myLink.authenticationManager();
((TextView) dialog.findViewById(R.id.network_authentication_login)).setText(mgr.UserNameOption.getValue()); ((TextView) dialog.findViewById(R.id.network_authentication_login)).setText(mgr.UserNameOption.getValue());

View file

@ -197,7 +197,7 @@ class CustomCatalogDialog extends NetworkDialog {
} }
@Override @Override
public void prepareDialog(Dialog dialog) { public void prepareDialogInternal(Dialog dialog) {
if (myLink != null) { if (myLink != null) {
if (myTitle == null) myTitle = myLink.getTitle(); if (myTitle == null) myTitle = myLink.getTitle();
if (myUrl == null) myUrl = myLink.getLink(INetworkLink.URL_MAIN); if (myUrl == null) myUrl = myLink.getLink(INetworkLink.URL_MAIN);

View file

@ -271,7 +271,7 @@ abstract class NetworkBaseActivity extends ListActivity
final NetworkDialog dlg = NetworkDialog.getDialog(id); final NetworkDialog dlg = NetworkDialog.getDialog(id);
if (dlg != null) { if (dlg != null) {
dlg.prepareDialog(dialog); dlg.prepareDialog(this, dialog);
} }
} }

View file

@ -324,7 +324,7 @@ public class NetworkBookInfoActivity extends Activity implements NetworkView.Eve
final NetworkDialog dlg = NetworkDialog.getDialog(id); final NetworkDialog dlg = NetworkDialog.getDialog(id);
if (dlg != null) { if (dlg != null) {
dlg.prepareDialog(dialog); dlg.prepareDialog(this, dialog);
} }
} }
} }

View file

@ -158,7 +158,6 @@ abstract class NetworkDialog {
public final Dialog createDialog(final Activity activity) { public final Dialog createDialog(final Activity activity) {
myActivity = activity; myActivity = activity;
final DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() { final DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
if (which == DialogInterface.BUTTON_POSITIVE) { if (which == DialogInterface.BUTTON_POSITIVE) {
@ -184,5 +183,10 @@ abstract class NetworkDialog {
.create(); .create();
} }
public abstract void prepareDialog(Dialog dialog); public final void prepareDialog(final Activity activity, Dialog dialog) {
myActivity = activity;
prepareDialogInternal(dialog);
}
protected abstract void prepareDialogInternal(Dialog dialog);
} }

View file

@ -19,16 +19,23 @@
package org.geometerplus.android.fbreader.network; package org.geometerplus.android.fbreader.network;
import java.lang.reflect.*;
import java.util.ArrayList;
import java.util.List;
import android.app.Dialog; import android.app.Dialog;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.view.View; import android.view.View;
import android.widget.Button;
import android.widget.TextView; import android.widget.TextView;
import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import org.geometerplus.zlibrary.ui.android.R; import org.geometerplus.zlibrary.ui.android.R;
import org.geometerplus.zlibrary.ui.android.dialogs.ZLAndroidDialogManager; import org.geometerplus.zlibrary.ui.android.dialogs.ZLAndroidDialogManager;
import org.geometerplus.zlibrary.core.resources.ZLResource;
import org.geometerplus.zlibrary.core.util.ZLBoolean3; import org.geometerplus.zlibrary.core.util.ZLBoolean3;
import org.geometerplus.fbreader.network.NetworkErrors; import org.geometerplus.fbreader.network.NetworkErrors;
@ -39,15 +46,18 @@ class RegisterUserDialog extends NetworkDialog {
private String myLogin; private String myLogin;
private String myPassword; private String myPassword;
private String myConfirmPassword;
private String myEmail; private String myEmail;
private ArrayList<String> mySystemEmails = new ArrayList<String>();
public RegisterUserDialog() { public RegisterUserDialog() {
super("RegisterUserDialog"); super("RegisterUserDialog");
} }
@Override @Override
protected void clearData() { protected void clearData() {
myLogin = myPassword = myEmail = null; myLogin = myPassword = myConfirmPassword = myEmail = null;
} }
@Override @Override
@ -59,6 +69,46 @@ class RegisterUserDialog extends NetworkDialog {
((TextView) layout.findViewById(R.id.network_register_confirm_password_text)).setText(myResource.getResource("confirmPassword").getValue()); ((TextView) layout.findViewById(R.id.network_register_confirm_password_text)).setText(myResource.getResource("confirmPassword").getValue());
((TextView) layout.findViewById(R.id.network_register_email_text)).setText(myResource.getResource("email").getValue()); ((TextView) layout.findViewById(R.id.network_register_email_text)).setText(myResource.getResource("email").getValue());
mySystemEmails.clear();
collectEMails(myActivity.getApplicationContext(), mySystemEmails);
if (!mySystemEmails.isEmpty()) {
final DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
if (which >= 0 && which < mySystemEmails.size()) {
myEmail = mySystemEmails.get(which);
}
dialog.dismiss();
}
};
((Button) layout.findViewById(R.id.network_register_email_button)).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
myLogin = ((TextView) layout.findViewById(R.id.network_register_login)).getText().toString().trim();
myPassword = ((TextView) layout.findViewById(R.id.network_register_password)).getText().toString();
myConfirmPassword = ((TextView) layout.findViewById(R.id.network_register_confirm_password)).getText().toString();
myEmail = ((TextView) layout.findViewById(R.id.network_register_email)).getText().toString().trim();
final int selected = mySystemEmails.indexOf(myEmail);
final ZLResource buttonResource = ZLResource.resource("dialog").getResource("button");
final AlertDialog dialog = new AlertDialog.Builder(myActivity)
.setSingleChoiceItems(mySystemEmails.toArray(new String[mySystemEmails.size()]), selected, listener)
.setTitle(myResource.getResource("email").getValue())
.setNegativeButton(buttonResource.getResource("cancel").getValue(), null)
.create();
dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
public void onDismiss(DialogInterface dialog) {
myActivity.showDialog(myId);
}
});
myActivity.dismissDialog(myId);
dialog.show();
}
});
}
return layout; return layout;
} }
@ -67,7 +117,7 @@ class RegisterUserDialog extends NetworkDialog {
AlertDialog alert = (AlertDialog) dialog; AlertDialog alert = (AlertDialog) dialog;
myLogin = ((TextView) alert.findViewById(R.id.network_register_login)).getText().toString().trim(); myLogin = ((TextView) alert.findViewById(R.id.network_register_login)).getText().toString().trim();
myPassword = ((TextView) alert.findViewById(R.id.network_register_password)).getText().toString(); myPassword = ((TextView) alert.findViewById(R.id.network_register_password)).getText().toString();
final String confirmPassword = ((TextView) alert.findViewById(R.id.network_register_confirm_password)).getText().toString(); myConfirmPassword = ((TextView) alert.findViewById(R.id.network_register_confirm_password)).getText().toString();
myEmail = ((TextView) alert.findViewById(R.id.network_register_email)).getText().toString().trim(); myEmail = ((TextView) alert.findViewById(R.id.network_register_email)).getText().toString().trim();
if (myLogin.length() == 0) { if (myLogin.length() == 0) {
@ -76,9 +126,10 @@ class RegisterUserDialog extends NetworkDialog {
sendError(true, false, err); sendError(true, false, err);
return; return;
} }
if (!myPassword.equals(confirmPassword)) { if (!myPassword.equals(myConfirmPassword)) {
final String err = myResource.getResource("differentPasswords").getValue(); final String err = myResource.getResource("differentPasswords").getValue();
myPassword = null; myPassword = null;
myConfirmPassword = null;
sendError(true, false, err); sendError(true, false, err);
return; return;
} }
@ -123,11 +174,16 @@ class RegisterUserDialog extends NetworkDialog {
} }
@Override @Override
public void prepareDialog(Dialog dialog) { public void prepareDialogInternal(Dialog dialog) {
((TextView) dialog.findViewById(R.id.network_register_login)).setText((myLogin != null) ? myLogin : ""); dialog.findViewById(R.id.network_register_email_button).setVisibility((mySystemEmails.size() > 1) ? View.VISIBLE : View.GONE);
((TextView) dialog.findViewById(R.id.network_register_password)).setText((myPassword != null) ? myPassword : ""); if (mySystemEmails.size() == 1 && (myEmail == null || myEmail.length() == 0)) {
((TextView) dialog.findViewById(R.id.network_register_confirm_password)).setText((myPassword != null) ? myPassword : ""); myEmail = mySystemEmails.get(0);
((TextView) dialog.findViewById(R.id.network_register_email)).setText((myEmail != null) ? myEmail : ""); }
((TextView) dialog.findViewById(R.id.network_register_login)).setText(myLogin);
((TextView) dialog.findViewById(R.id.network_register_password)).setText(myPassword);
((TextView) dialog.findViewById(R.id.network_register_confirm_password)).setText(myConfirmPassword);
((TextView) dialog.findViewById(R.id.network_register_email)).setText(myEmail);
final TextView error = (TextView) dialog.findViewById(R.id.network_register_error); final TextView error = (TextView) dialog.findViewById(R.id.network_register_error);
if (myErrorMessage == null) { if (myErrorMessage == null) {
@ -142,4 +198,35 @@ class RegisterUserDialog extends NetworkDialog {
dlgView.invalidate(); dlgView.invalidate();
dlgView.requestLayout(); dlgView.requestLayout();
} }
private static void collectEMails(Context context, List<String> emails) {
try {
final Class<?> cls$AccountManager = Class.forName("android.accounts.AccountManager");
final Class<?> cls$Account = Class.forName("android.accounts.Account");
final Method meth$AccountManager$get = cls$AccountManager.getMethod("get", Context.class);
final Method meth$AccountManager$getAccountsByType = cls$AccountManager.getMethod("getAccountsByType", String.class);
final Field fld$Account$name = cls$Account.getField("name");
if (meth$AccountManager$get.getReturnType() == cls$AccountManager
&& meth$AccountManager$getAccountsByType.getReturnType().getComponentType() == cls$Account
&& fld$Account$name.getType() == String.class) {
final Object mgr = meth$AccountManager$get.invoke(null, context);
final Object[] accountsByType = (Object[]) meth$AccountManager$getAccountsByType.invoke(mgr, "com.google");
for (Object a: accountsByType) {
final String value = (String) fld$Account$name.get(a);
if (value != null && value.length() > 0) {
emails.add(value);
}
}
}
} catch (ClassNotFoundException e) {
} catch (NoSuchMethodException e) {
} catch (NoSuchFieldException e) {
} catch (IllegalAccessException e) {
} catch (IllegalArgumentException e) {
} catch (InvocationTargetException e) {
}
}
} }