mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-03 01:39:18 +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:
parent
7e5b6eca26
commit
c3fba9899d
12 changed files with 135 additions and 19 deletions
|
@ -7,6 +7,7 @@ drawable_res_dir = "res/drawable"
|
|||
tree_icons_dir = "icons/tree"
|
||||
menu_icons_dir = "icons/menu"
|
||||
tabs_icons_dir = "icons/tabs"
|
||||
others_icons_dir = "icons/others"
|
||||
text_search_icons_dir = "icons/text_search"
|
||||
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("", menu_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)
|
||||
|
|
8
icons/others/dropdown.xml
Normal file
8
icons/others/dropdown.xml
Normal 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>
|
||||
|
BIN
icons/others/dropdown_normal.png
Normal file
BIN
icons/others/dropdown_normal.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.7 KiB |
BIN
icons/others/dropdown_pressed.png
Normal file
BIN
icons/others/dropdown_pressed.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.3 KiB |
BIN
icons/others/dropdown_selected.png
Normal file
BIN
icons/others/dropdown_selected.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.2 KiB |
|
@ -58,13 +58,28 @@
|
|||
android:singleLine="true"
|
||||
android:layout_marginTop="5dp"
|
||||
/>
|
||||
<EditText
|
||||
android:id="@+id/network_register_email"
|
||||
<RelativeLayout
|
||||
android:layout_width="fill_parent"
|
||||
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
|
||||
android:id="@+id/network_register_error"
|
||||
android:layout_width="fill_parent"
|
||||
|
|
|
@ -126,7 +126,7 @@ class AuthenticationDialog extends NetworkDialog {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void prepareDialog(Dialog dialog) {
|
||||
public void prepareDialogInternal(Dialog dialog) {
|
||||
final NetworkAuthenticationManager mgr = myLink.authenticationManager();
|
||||
|
||||
((TextView) dialog.findViewById(R.id.network_authentication_login)).setText(mgr.UserNameOption.getValue());
|
||||
|
|
|
@ -197,7 +197,7 @@ class CustomCatalogDialog extends NetworkDialog {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void prepareDialog(Dialog dialog) {
|
||||
public void prepareDialogInternal(Dialog dialog) {
|
||||
if (myLink != null) {
|
||||
if (myTitle == null) myTitle = myLink.getTitle();
|
||||
if (myUrl == null) myUrl = myLink.getLink(INetworkLink.URL_MAIN);
|
||||
|
|
|
@ -271,7 +271,7 @@ abstract class NetworkBaseActivity extends ListActivity
|
|||
|
||||
final NetworkDialog dlg = NetworkDialog.getDialog(id);
|
||||
if (dlg != null) {
|
||||
dlg.prepareDialog(dialog);
|
||||
dlg.prepareDialog(this, dialog);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -324,7 +324,7 @@ public class NetworkBookInfoActivity extends Activity implements NetworkView.Eve
|
|||
|
||||
final NetworkDialog dlg = NetworkDialog.getDialog(id);
|
||||
if (dlg != null) {
|
||||
dlg.prepareDialog(dialog);
|
||||
dlg.prepareDialog(this, dialog);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -158,7 +158,6 @@ abstract class NetworkDialog {
|
|||
|
||||
public final Dialog createDialog(final Activity activity) {
|
||||
myActivity = activity;
|
||||
|
||||
final DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (which == DialogInterface.BUTTON_POSITIVE) {
|
||||
|
@ -184,5 +183,10 @@ abstract class NetworkDialog {
|
|||
.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);
|
||||
}
|
||||
|
|
|
@ -19,16 +19,23 @@
|
|||
|
||||
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.AlertDialog;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
|
||||
import org.geometerplus.zlibrary.ui.android.R;
|
||||
|
||||
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.fbreader.network.NetworkErrors;
|
||||
|
@ -39,15 +46,18 @@ class RegisterUserDialog extends NetworkDialog {
|
|||
|
||||
private String myLogin;
|
||||
private String myPassword;
|
||||
private String myConfirmPassword;
|
||||
private String myEmail;
|
||||
|
||||
private ArrayList<String> mySystemEmails = new ArrayList<String>();
|
||||
|
||||
public RegisterUserDialog() {
|
||||
super("RegisterUserDialog");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void clearData() {
|
||||
myLogin = myPassword = myEmail = null;
|
||||
myLogin = myPassword = myConfirmPassword = myEmail = null;
|
||||
}
|
||||
|
||||
@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_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;
|
||||
}
|
||||
|
||||
|
@ -67,7 +117,7 @@ class RegisterUserDialog extends NetworkDialog {
|
|||
AlertDialog alert = (AlertDialog) dialog;
|
||||
myLogin = ((TextView) alert.findViewById(R.id.network_register_login)).getText().toString().trim();
|
||||
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();
|
||||
|
||||
if (myLogin.length() == 0) {
|
||||
|
@ -76,9 +126,10 @@ class RegisterUserDialog extends NetworkDialog {
|
|||
sendError(true, false, err);
|
||||
return;
|
||||
}
|
||||
if (!myPassword.equals(confirmPassword)) {
|
||||
if (!myPassword.equals(myConfirmPassword)) {
|
||||
final String err = myResource.getResource("differentPasswords").getValue();
|
||||
myPassword = null;
|
||||
myConfirmPassword = null;
|
||||
sendError(true, false, err);
|
||||
return;
|
||||
}
|
||||
|
@ -123,11 +174,16 @@ class RegisterUserDialog extends NetworkDialog {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void prepareDialog(Dialog dialog) {
|
||||
((TextView) dialog.findViewById(R.id.network_register_login)).setText((myLogin != null) ? myLogin : "");
|
||||
((TextView) dialog.findViewById(R.id.network_register_password)).setText((myPassword != null) ? myPassword : "");
|
||||
((TextView) dialog.findViewById(R.id.network_register_confirm_password)).setText((myPassword != null) ? myPassword : "");
|
||||
((TextView) dialog.findViewById(R.id.network_register_email)).setText((myEmail != null) ? myEmail : "");
|
||||
public void prepareDialogInternal(Dialog dialog) {
|
||||
dialog.findViewById(R.id.network_register_email_button).setVisibility((mySystemEmails.size() > 1) ? View.VISIBLE : View.GONE);
|
||||
if (mySystemEmails.size() == 1 && (myEmail == null || myEmail.length() == 0)) {
|
||||
myEmail = mySystemEmails.get(0);
|
||||
}
|
||||
|
||||
((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);
|
||||
if (myErrorMessage == null) {
|
||||
|
@ -142,4 +198,35 @@ class RegisterUserDialog extends NetworkDialog {
|
|||
dlgView.invalidate();
|
||||
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) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue