Browse Source

popups & dioalogs ready for landscape

Julien Clauter 10 years ago
parent
commit
c5d922e722

+ 22 - 0
res/layout-land/date_time_dialog.xml

@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/DateTimePicker"
+    android:layout_width="wrap_content"
+    android:layout_height="fill_parent"
+    android:gravity="center"
+    android:orientation="horizontal"
+    android:padding="5dip" >
+
+    <DatePicker
+        android:id="@+id/DatePicker"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+         />
+
+    <TimePicker
+        android:id="@+id/TimePicker"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+         />
+
+</LinearLayout>

+ 16 - 0
res/layout/simple_popup_table.xml

@@ -23,4 +23,20 @@
 			android:layout_height="2dp"
 			android:background="@android:color/holo_blue_bright"
 			/>
+
+    <ScrollView
+        android:layout_width="fill_parent"
+        android:layout_height="wrap_content"
+        android:id="@+id/item_scrollview">
+
+        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+            android:orientation="vertical"
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:id="@+id/item_scroll_layout"
+            >
+
+        </LinearLayout>
+        </ScrollView>
+
 </LinearLayout>

+ 47 - 7
src/de/tudarmstadt/informatik/hostage/ui2/dialog/DateTimeDialogFragment.java

@@ -7,9 +7,11 @@ import android.app.AlertDialog.Builder;
 import android.app.Dialog;
 import android.app.DialogFragment;
 import android.content.DialogInterface;
+import android.content.res.Configuration;
 import android.os.Bundle;
 import android.view.LayoutInflater;
 import android.view.View;
+import android.view.ViewGroup;
 import android.widget.DatePicker;
 import android.widget.DatePicker.OnDateChangedListener;
 import android.widget.TimePicker;
@@ -53,25 +55,22 @@ public class DateTimeDialogFragment extends DialogFragment implements OnDateChan
     }
 
     public DateTimeDialogFragment(Activity activity, int DialogType) {
+
         this.activity = activity;
         this.DialogType = DialogType;
 
-        // Inflate layout for the view
-        // Pass null as the parent view because its going in the dialog layout
         LayoutInflater inflater = activity.getLayoutInflater();
-        mView = inflater.inflate(R.layout.date_time_dialog, null);  
+        mView = inflater.inflate(R.layout.date_time_dialog, null);
 
-        // Grab a Calendar instance
+        this.setupRootView(mView);
+        /*
         mCalendar = Calendar.getInstance();
 
-        // Init date picker
         datePicker = (DatePicker) mView.findViewById(R.id.DatePicker);
         datePicker.init(mCalendar.get(Calendar.YEAR), mCalendar.get(Calendar.MONTH), mCalendar.get(Calendar.DAY_OF_MONTH), this);
 
-        // Init time picker
         timePicker = (TimePicker) mView.findViewById(R.id.TimePicker);
 
-        // Set default Calendar and Time Style
         setIs24HourView(true);
         setCalendarViewShown(false);
 
@@ -83,6 +82,47 @@ public class DateTimeDialogFragment extends DialogFragment implements OnDateChan
             datePicker.setVisibility(View.GONE);
             break;
         }
+        */
+    }
+
+
+    @Override
+    public void onConfigurationChanged(Configuration newConfig){
+        super.onConfigurationChanged(newConfig);
+        LayoutInflater inflater = LayoutInflater.from(this.activity);
+
+        ViewGroup container = (ViewGroup) this.mView.getParent();
+
+        container.removeView(this.mView);
+
+        mView = inflater.inflate(R.layout.date_time_dialog, null);
+        container.addView(mView);
+        this.setupRootView(mView);
+    }
+
+    private void setupRootView(View mView){
+        // Grab a Calendar instance
+        mCalendar = Calendar.getInstance();
+
+        // Init date picker
+        datePicker = (DatePicker) mView.findViewById(R.id.DatePicker);
+        datePicker.init(mCalendar.get(Calendar.YEAR), mCalendar.get(Calendar.MONTH), mCalendar.get(Calendar.DAY_OF_MONTH), this);
+
+        // Init time picker
+        timePicker = (TimePicker) mView.findViewById(R.id.TimePicker);
+
+        // Set default Calendar and Time Style
+        setIs24HourView(true);
+        setCalendarViewShown(false);
+
+        switch (DialogType) {
+            case DATE_PICKER:
+                timePicker.setVisibility(View.GONE);
+                break;
+            case TIME_PICKER:
+                datePicker.setVisibility(View.GONE);
+                break;
+        }
     }
 
     public void setDate(long timeInMillis){

+ 20 - 6
src/de/tudarmstadt/informatik/hostage/ui2/popup/AbstractPopup.java

@@ -43,6 +43,12 @@ public abstract class AbstractPopup {
 
     }
 
+    public abstract LinearLayout getScrollableItemLayout();
+
+    public View getRootView(){
+        return this.rootView;
+    }
+
     public void addItem(final AbstractPopupItem item)	{
         View view = item.getItemView();
 
@@ -51,7 +57,8 @@ public abstract class AbstractPopup {
             this.configureView(this.rootView);
         }
         if (this.rootView != null){
-            this.rootView.addView(view);
+            this.getScrollableItemLayout().addView(view);
+            //this.rootView.addView(view);
             view.setOnTouchListener(new View.OnTouchListener() {
                 @Override
                 public boolean onTouch(View view, MotionEvent event) {
@@ -90,9 +97,9 @@ public abstract class AbstractPopup {
 
             Window window = this.context.getWindow();
             window.getDecorView().getWindowVisibleDisplayFrame(windowFrame);
-            int orientation = 1; //this.context.getResources().getConfiguration().orientation;
-            int windowWidth = orientation == ORIENTATION_LANDSCAPE ? windowFrame.height() : windowFrame.width();
-            int windowHeight = orientation == ORIENTATION_LANDSCAPE ? windowFrame.width() : windowFrame.height();
+            int orientation = this.context.getResources().getConfiguration().orientation;
+            int windowWidth = windowFrame.width();
+            int windowHeight = windowFrame.height();
 
             final int[] position = new int[2];
             anchorView.getLocationOnScreen(position);
@@ -108,11 +115,18 @@ public abstract class AbstractPopup {
             int x = position[0] + (anchorWidth / 2) - (width / 2);
             int y = position[1] - height;
 
+             int offset = 15;
+            height+=offset;
+
+            width = windowWidth < width ? windowWidth : width;
+
             x = Math.max(0, x);
             x = Math.min(windowWidth - width, x);
 
-            y = Math.min(0,y);
-            y = Math.max(windowHeight - height, y);
+            height = windowHeight < height ? windowHeight : height;
+
+            y = Math.max(0, y);
+            y = Math.min(windowHeight - height, y);
 
             AbstractPopup.this.configureView(this.rootView);
 

+ 6 - 0
src/de/tudarmstadt/informatik/hostage/ui2/popup/SimplePopupTable.java

@@ -2,6 +2,7 @@ package de.tudarmstadt.informatik.hostage.ui2.popup;
 
 import android.content.Context;
 import android.view.View;
+import android.widget.LinearLayout;
 import android.widget.TextView;
 
 import de.tudarmstadt.informatik.hostage.R;
@@ -25,6 +26,11 @@ public class SimplePopupTable extends AbstractPopup {
         super(context, listener);
     }
 
+    @Override
+    public LinearLayout getScrollableItemLayout() {
+        return (LinearLayout) this.getRootView().findViewById(R.id.item_scroll_layout);
+    }
+
     public int getLayoutId(){
         return R.layout.simple_popup_table;
     }