Don't center notes display when notes are long

pull/14/head
Sam Bosley 13 years ago
parent 95826ddab6
commit ad4d1b48a3

@ -21,7 +21,7 @@
android:layout_marginRight="15dip" android:layout_marginRight="15dip"
android:text="@string/TEA_note_label" android:text="@string/TEA_note_label"
style="@style/TextAppearance.GEN_EditLabel" /> style="@style/TextAppearance.GEN_EditLabel" />
<TextView <com.todoroo.astrid.ui.TextViewWithMeasureListener
android:id="@+id/notes_display" android:id="@+id/notes_display"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"

@ -5,31 +5,43 @@ import android.content.Context;
import android.graphics.Color; import android.graphics.Color;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.util.Linkify; import android.text.util.Linkify;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.WindowManager; import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import android.widget.EditText; import android.widget.EditText;
import android.widget.TextView; import android.widget.LinearLayout;
import com.timsu.astrid.R; import com.timsu.astrid.R;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.ui.TextViewWithMeasureListener.OnTextMeasureListener;
public class EditNotesControlSet extends PopupControlSet { public class EditNotesControlSet extends PopupControlSet {
private final EditText editText; private final EditText editText;
private final TextView notesPreview; private final TextViewWithMeasureListener notesPreview;
private final LinearLayout notesBody;
public EditNotesControlSet(Activity activity, int viewLayout, int displayViewLayout) { public EditNotesControlSet(Activity activity, int viewLayout, int displayViewLayout) {
super(activity, viewLayout, displayViewLayout, R.string.TEA_note_label); super(activity, viewLayout, displayViewLayout, R.string.TEA_note_label);
editText = (EditText) getView().findViewById(R.id.notes); editText = (EditText) getView().findViewById(R.id.notes);
notesPreview = (TextView) getDisplayView().findViewById(R.id.notes_display); notesPreview = (TextViewWithMeasureListener) getDisplayView().findViewById(R.id.notes_display);
notesBody = (LinearLayout) getDisplayView().findViewById(R.id.notes_body);
dialog.getWindow() dialog.getWindow()
.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
notesPreview.setOnTextSizeChangedListener(new OnTextMeasureListener() {
@Override
public void onTextSizeChanged() {
setupGravity();
}
});
} }
@Override @Override
protected void refreshDisplayView() { protected void refreshDisplayView() {
notesPreview.setText(""); notesPreview.setText("");
notesPreview.setText(editText.getText()); notesPreview.setText(editText.getText());
setupGravity();
linkifyDisplayView(); linkifyDisplayView();
} }
@ -71,4 +83,15 @@ public class EditNotesControlSet extends PopupControlSet {
return !TextUtils.isEmpty(editText.getText()); return !TextUtils.isEmpty(editText.getText());
} }
private void setupGravity() {
DisplayMetrics metrics = activity.getResources().getDisplayMetrics();
if (hasNotes() && notesPreview.getLineCount() > 2) {
notesBody.setGravity(Gravity.TOP);
notesBody.setPadding(0, (int) (metrics.density * 8), 0, (int) (metrics.density * 8));
} else {
notesBody.setGravity(Gravity.CENTER_VERTICAL);
notesBody.setPadding(0, 0, 0, 0);
}
}
} }

@ -0,0 +1,35 @@
package com.todoroo.astrid.ui;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.TextView;
public class TextViewWithMeasureListener extends TextView {
public interface OnTextMeasureListener {
public void onTextSizeChanged();
}
private OnTextMeasureListener listener;
public TextViewWithMeasureListener(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
if (listener != null) {
listener.onTextSizeChanged();
}
}
public OnTextMeasureListener getOnTextSizeChangedListener() {
return listener;
}
public void setOnTextSizeChangedListener(OnTextMeasureListener listener) {
this.listener = listener;
}
}
Loading…
Cancel
Save