Update look for RecipientsPanel.

1) Make the "add contacts" graphic more holo-ific.
2) Adjust the graphic position on holo-themed devices.
This commit is contained in:
Moxie Marlinspike 2012-07-19 15:16:07 -07:00
parent b377fe84df
commit 1ac1cec634
5 changed files with 47 additions and 42 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 909 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@ -10,7 +10,7 @@
android:paddingRight="5dip" android:paddingRight="5dip"
android:background="@drawable/white_background" android:background="@drawable/white_background"
android:orientation="vertical" > android:orientation="vertical" >
<org.thoughtcrime.securesms.contacts.RecipientsEditor android:id="@+id/recipients_text" <org.thoughtcrime.securesms.contacts.RecipientsEditor android:id="@+id/recipients_text"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:capitalize="sentences" android:capitalize="sentences"
@ -18,17 +18,17 @@
android:singleLine="true" android:singleLine="true"
android:hint="To" android:hint="To"
android:paddingRight="45dip" android:paddingRight="45dip"
android:layout_width="fill_parent"/> android:layout_width="fill_parent"/>
<ImageButton android:id="@+id/contacts_button" <ImageButton android:id="@+id/contacts_button"
android:background="#00000000" android:background="#00000000"
android:layout_width="40dip" android:layout_width="40dip"
android:layout_height="35dip" android:layout_height="35dip"
android:layout_marginRight="5dip" android:layout_marginRight="5dip"
android:layout_marginTop="4dip" android:layout_marginTop="4dip"
android:src="@drawable/ic_add" android:src="@drawable/ic_menu_add_field_holo_light"
android:layout_alignRight="@id/recipients_text" android:layout_alignRight="@id/recipients_text"
android:maxWidth="32dip" android:maxWidth="32dip"
android:maxHeight="32dip" /> android:maxHeight="32dip" />
</RelativeLayout> </RelativeLayout>

View File

@ -1,6 +1,6 @@
/** /**
* Copyright (C) 2011 Whisper Systems * Copyright (C) 2011 Whisper Systems
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
@ -10,15 +10,18 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.thoughtcrime.securesms.components; package org.thoughtcrime.securesms.components;
import java.util.Iterator; import android.content.Context;
import java.util.LinkedList; import android.os.Build;
import java.util.List; import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;
import org.thoughtcrime.securesms.R; import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.contacts.RecipientsAdapter; import org.thoughtcrime.securesms.contacts.RecipientsAdapter;
@ -28,27 +31,24 @@ import org.thoughtcrime.securesms.recipients.RecipientFactory;
import org.thoughtcrime.securesms.recipients.RecipientFormattingException; import org.thoughtcrime.securesms.recipients.RecipientFormattingException;
import org.thoughtcrime.securesms.recipients.Recipients; import org.thoughtcrime.securesms.recipients.Recipients;
import android.content.Context; import java.util.Iterator;
import android.util.AttributeSet; import java.util.LinkedList;
import android.util.Log; import java.util.List;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;
/** /**
* Panel component combining both an editable field with a button for * Panel component combining both an editable field with a button for
* a list-based contact selector. * a list-based contact selector.
* *
* @author Moxie Marlinspike * @author Moxie Marlinspike
*/ */
public class RecipientsPanel extends RelativeLayout { public class RecipientsPanel extends RelativeLayout {
private RecipientsPanelChangedListener panelChangeListener; private RecipientsPanelChangedListener panelChangeListener;
private RecipientsEditor recipientsText; private RecipientsEditor recipientsText;
private View panel; private View panel;
private static final int RECIPIENTS_MAX_LENGTH = 312; private static final int RECIPIENTS_MAX_LENGTH = 312;
public RecipientsPanel(Context context) { public RecipientsPanel(Context context) {
super(context); super(context);
initialize(); initialize();
@ -63,37 +63,37 @@ public class RecipientsPanel extends RelativeLayout {
super(context, attrs, defStyle); super(context, attrs, defStyle);
initialize(); initialize();
} }
public void addRecipient(String name, String number) { public void addRecipient(String name, String number) {
if (name != null) recipientsText.append(name + "< " + number + ">, "); if (name != null) recipientsText.append(name + "< " + number + ">, ");
else recipientsText.append(number + ", "); else recipientsText.append(number + ", ");
} }
public void addRecipients(Recipients recipients) { public void addRecipients(Recipients recipients) {
List<Recipient> recipientList = recipients.getRecipientsList(); List<Recipient> recipientList = recipients.getRecipientsList();
Iterator<Recipient> iterator = recipientList.iterator(); Iterator<Recipient> iterator = recipientList.iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
Recipient recipient = iterator.next(); Recipient recipient = iterator.next();
addRecipient(recipient.getName(), recipient.getNumber()); addRecipient(recipient.getName(), recipient.getNumber());
} }
} }
public Recipients getRecipients() throws RecipientFormattingException { public Recipients getRecipients() throws RecipientFormattingException {
String rawText = recipientsText.getText().toString(); String rawText = recipientsText.getText().toString();
Recipients recipients = RecipientFactory.getRecipientsFromString(getContext(), rawText); Recipients recipients = RecipientFactory.getRecipientsFromString(getContext(), rawText);
if (recipients.isEmpty()) if (recipients.isEmpty())
throw new RecipientFormattingException("Recipient List Is Empty!"); throw new RecipientFormattingException("Recipient List Is Empty!");
return recipients; return recipients;
} }
public void disable() { public void disable() {
recipientsText.setText(""); recipientsText.setText("");
panel.setVisibility(View.GONE); panel.setVisibility(View.GONE);
} }
public void setPanelChangeListener(RecipientsPanelChangedListener panelChangeListener) { public void setPanelChangeListener(RecipientsPanelChangedListener panelChangeListener) {
this.panelChangeListener = panelChangeListener; this.panelChangeListener = panelChangeListener;
} }
@ -101,15 +101,20 @@ public class RecipientsPanel extends RelativeLayout {
private void initialize() { private void initialize() {
LayoutInflater inflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); LayoutInflater inflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.recipients_panel, this, true); inflater.inflate(R.layout.recipients_panel, this, true);
panel = findViewById(R.id.recipients_panel); View imageButton = findViewById(R.id.contacts_button);
initRecipientsEditor();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)
((MarginLayoutParams) imageButton.getLayoutParams()).topMargin = 0;
panel = findViewById(R.id.recipients_panel);
initRecipientsEditor();
} }
private void initRecipientsEditor() { private void initRecipientsEditor() {
Recipients recipients = null; Recipients recipients = null;
recipientsText = (RecipientsEditor)findViewById(R.id.recipients_text); recipientsText = (RecipientsEditor)findViewById(R.id.recipients_text);
try { try {
recipients = getRecipients(); recipients = getRecipients();
} catch (RecipientFormattingException e) { } catch (RecipientFormattingException e) {
@ -120,7 +125,7 @@ public class RecipientsPanel extends RelativeLayout {
recipientsText.populate(recipients); recipientsText.populate(recipients);
recipientsText.setOnFocusChangeListener(new FocusChangedListener()); recipientsText.setOnFocusChangeListener(new FocusChangedListener());
} }
private class FocusChangedListener implements View.OnFocusChangeListener { private class FocusChangedListener implements View.OnFocusChangeListener {
public void onFocusChange(View v, boolean hasFocus) { public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus && (panelChangeListener != null)) { if (!hasFocus && (panelChangeListener != null)) {
@ -132,7 +137,7 @@ public class RecipientsPanel extends RelativeLayout {
} }
} }
} }
public interface RecipientsPanelChangedListener { public interface RecipientsPanelChangedListener {
public void onRecipientsPanelUpdate(Recipients recipients); public void onRecipientsPanelUpdate(Recipients recipients);
} }