Project

General

Profile

« Previous | Next » 

Revision f8a21f6b

Added by Leszek Koltunski over 1 year ago

Unify all dialogs.

View differences:

src/main/java/org/distorted/dialogs/RubikDialogPattern.java
10 10
package org.distorted.dialogs;
11 11

  
12 12
import android.app.Dialog;
13
import android.content.Context;
14
import android.content.DialogInterface;
15
import android.os.Bundle;
16
import androidx.annotation.NonNull;
17 13
import androidx.fragment.app.FragmentActivity;
18 14
import androidx.viewpager.widget.ViewPager;
19
import androidx.appcompat.app.AlertDialog;
20
import androidx.appcompat.app.AppCompatDialogFragment;
21 15
import com.google.android.material.tabs.TabLayout;
22
import android.util.DisplayMetrics;
23
import android.util.TypedValue;
24
import android.view.LayoutInflater;
16

  
25 17
import android.view.View;
26 18
import android.view.ViewGroup;
27 19
import android.view.Window;
28 20
import android.view.WindowManager;
29
import android.widget.Button;
30 21
import android.widget.ImageView;
31
import android.widget.TextView;
32 22

  
33 23
import org.distorted.main.R;
34 24
import org.distorted.main.RubikActivity;
......
38 28

  
39 29
///////////////////////////////////////////////////////////////////////////////////////////////////
40 30

  
41
public class RubikDialogPattern extends AppCompatDialogFragment
31
public class RubikDialogPattern extends RubikDialogAbstract
42 32
  {
43 33
  private RubikDialogPatternPagerAdapter mPagerAdapter;
44 34

  
45 35
///////////////////////////////////////////////////////////////////////////////////////////////////
46 36

  
47
  @NonNull
48 37
  @Override
49
  public Dialog onCreateDialog(Bundle savedInstanceState)
38
  public void onResume()
50 39
    {
51
    final FragmentActivity act = getActivity();
52
    AlertDialog.Builder builder = new AlertDialog.Builder(act);
40
    super.onResume();
53 41

  
54
    DisplayMetrics displaymetrics = new DisplayMetrics();
55
    act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
42
    Window window = getDialog().getWindow();
56 43

  
57
    int h = displaymetrics.heightPixels;
58
    final float titleSize= h*RubikActivity.TAB_TEXT_SIZE;
59
    final float okSize   = h*RubikActivity.TAB_BUTTON_SIZE;
60
    final int   tabHeight= (int)(h*RubikActivity.TAB_HEIGHT);
61
    final int   tabWidth = (int)(h*RubikActivity.TAB_WIDTH);
44
    if( window!=null )
45
      {
46
      WindowManager.LayoutParams params = window.getAttributes();
47
      params.width  = (int)Math.min( mHeight*0.65f,mWidth*0.98f );
48
      params.height = (int)Math.min( mHeight*0.85f,mWidth*1.30f );
49
      window.setAttributes(params);
50
      }
51
    }
62 52

  
63
    LayoutInflater layoutInflater = act.getLayoutInflater();
64
    TextView tv = (TextView) layoutInflater.inflate(R.layout.dialog_title, null);
65
    tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
66
    tv.setText(R.string.choose_pattern);
67
    builder.setCustomTitle(tv);
53
///////////////////////////////////////////////////////////////////////////////////////////////////
68 54

  
69
    builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener()
70
      {
71
      @Override
72
      public void onClick(DialogInterface dialog, int which)
73
        {
55
  public int getResource()      { return R.layout.dialog_tabbed; }
56
  public int getTitleResource() { return R.string.choose_pattern; }
57
  public boolean hasArgument()  { return false; }
58
  public int getPositive()      { return R.string.ok; }
59
  public int getNegative()      { return -1; }
60

  
61
///////////////////////////////////////////////////////////////////////////////////////////////////
62

  
63
  public void positiveAction()
64
    {
65

  
66
    }
67

  
68
///////////////////////////////////////////////////////////////////////////////////////////////////
74 69

  
75
        }
76
      });
70
  public void negativeAction()
71
    {
77 72

  
78
    LayoutInflater inflater = act.getLayoutInflater();
79
    final View view = inflater.inflate(R.layout.dialog_tabbed, null);
80
    builder.setView(view);
73
    }
74

  
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76

  
77
  public void prepareBody(Dialog dialog, View view, FragmentActivity act, float size)
78
    {
79
    final int tabHeight= (int)(mHeight*RubikActivity.TAB_HEIGHT);
80
    final int tabWidth = (int)(mHeight*RubikActivity.TAB_WIDTH);
81 81

  
82 82
    ViewPager viewPager = view.findViewById(R.id.viewpager);
83 83
    TabLayout tabLayout = view.findViewById(R.id.sliding_tabs);
84 84
    mPagerAdapter = new RubikDialogPatternPagerAdapter(act, viewPager, this);
85 85
    tabLayout.setupWithViewPager(viewPager);
86
    viewPager.setCurrentItem(getPatternOrdinal());
86

  
87
    int obj = RubikObjectList.getCurrObject();
88
    int ord = RubikPatternList.getOrdinal(obj);
89
    if( ord<0 ) ord = RubikPatternList.getOrdinal(RubikObjectList.DEF_OBJECT);
90
    viewPager.setCurrentItem(ord);
87 91

  
88 92
    ViewGroup.LayoutParams paramsView = new ViewGroup.LayoutParams( tabWidth,tabHeight );
89 93

  
......
97 101
      TabLayout.Tab tab = tabLayout.getTabAt(i);
98 102
      if(tab!=null) tab.setCustomView(imageView);
99 103
      }
100

  
101
    Dialog dialog = builder.create();
102
    dialog.setCanceledOnTouchOutside(false);
103
    Window window = dialog.getWindow();
104

  
105
    if( window!=null )
106
      {
107
      window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS);
108
      }
109

  
110
    dialog.setOnShowListener(new DialogInterface.OnShowListener()
111
      {
112
      @Override
113
      public void onShow(DialogInterface dialog)
114
        {
115
        Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
116
        btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
117
        }
118
      });
119

  
120
    return dialog;
121
    }
122

  
123
///////////////////////////////////////////////////////////////////////////////////////////////////
124

  
125
  private int getPatternOrdinal()
126
    {
127
    int obj = RubikObjectList.getCurrObject();
128
    int ret = RubikPatternList.getOrdinal(obj);
129

  
130
    if( ret<0 )
131
      {
132
      ret = RubikPatternList.getOrdinal(RubikObjectList.DEF_OBJECT);
133
      }
134

  
135
    return ret;
136
    }
137

  
138
///////////////////////////////////////////////////////////////////////////////////////////////////
139

  
140
  @Override
141
  public void onResume()
142
    {
143
    super.onResume();
144

  
145
    Window window = getDialog().getWindow();
146
    Context context = getContext();
147

  
148
    if( window!=null && context!=null )
149
      {
150
      DisplayMetrics metrics = context.getResources().getDisplayMetrics();
151
      WindowManager.LayoutParams params = window.getAttributes();
152
      params.width  = (int)Math.min( 0.65f*metrics.heightPixels,0.98f*metrics.widthPixels );
153
      params.height = (int)Math.min( 0.85f*metrics.heightPixels,1.30f*metrics.widthPixels );
154
      window.setAttributes(params);
155
      }
156 104
    }
157 105

  
158 106
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff