Project

General

Profile

« Previous | Next » 

Revision 309a4e6c

Added by Leszek Koltunski 1 day ago

Progress remembering solves.

View differences:

src/main/java/org/distorted/main/MainSolvesPopup.java
10 10
package org.distorted.main;
11 11

  
12 12
import android.content.Context;
13
import android.content.res.Resources;
14
import android.graphics.drawable.ColorDrawable;
15 13
import android.util.TypedValue;
16 14
import android.view.Gravity;
17 15
import android.view.LayoutInflater;
......
26 24
import org.json.JSONException;
27 25
import org.json.JSONObject;
28 26

  
27
import java.text.SimpleDateFormat;
28
import java.util.Date;
29
import java.util.Locale;
30

  
29 31
///////////////////////////////////////////////////////////////////////////////////////////////////
30 32

  
31 33
public class MainSolvesPopup
......
48 50
    mPadding  = (int)(mHeight*0.01f);
49 51

  
50 52
    LayoutInflater layoutInflater = (LayoutInflater)act.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
51
    final View layout = layoutInflater.inflate(R.layout.dialog_scrollable_panes, null);
53
    final View layout = layoutInflater.inflate(R.layout.dialog_scrollable_solves, null);
52 54
    mPopup = new PopupWindow(act);
53 55
    mPopup.setContentView(layout);
54 56
    mPopup.setFocusable(true);
55

  
56
    Resources res = act.getResources();
57
    int l = res.getColor(act.getLightTrans());
58
    mPopup.setBackgroundDrawable(new ColorDrawable(l));
59

  
60 57
    mLayout= layout.findViewById(R.id.dialog_scrollable_main_layout);
61 58

  
62 59
    fillLayout(act,array);
......
74 71
    LinearLayout.LayoutParams pL = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, mSize );
75 72
    pL.setMargins(mMargin, mMargin, mMargin, mMargin);
76 73
    LinearLayout.LayoutParams pT = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, textH );
77
    LinearLayout.LayoutParams pB = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, buttH );
78 74

  
79 75
    int numSolves = array.length();
80 76

  
......
84 80
        {
85 81
        JSONObject object = array.getJSONObject(s);
86 82
        long time = object.getLong("time");
87
        View pane = createOldPane(act, time, pL, pT, pB);
83
        View pane = createOldPane(act, time, pL, pT);
88 84
        mLayout.addView(pane);
89 85
        }
90 86
      }
......
93 89
      android.util.Log.e("D", "fillLayout: JSON error: "+jex.getMessage());
94 90
      }
95 91

  
96
    View pane = createNewPane(act, pL,pT,pB);
92
    View pane = createNewPane(act, pL, pT);
97 93
    mLayout.addView(pane);
98 94
    }
99 95

  
100 96
///////////////////////////////////////////////////////////////////////////////////////////////////
101 97

  
102
  private View createOldPane(MainActivity act, long time, LinearLayout.LayoutParams pView, LinearLayout.LayoutParams pText, LinearLayout.LayoutParams pButt)
98
  private String convertToDate(Date date)
99
    {
100
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MMM-dd", Locale.getDefault());
101
    return sdf.format(date);
102
    }
103

  
104
///////////////////////////////////////////////////////////////////////////////////////////////////
105

  
106
  private String convertToTime(Date date)
107
    {
108
    SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss", Locale.getDefault());
109
    return sdf.format(date);
110
    }
111

  
112
///////////////////////////////////////////////////////////////////////////////////////////////////
113

  
114
  private View createOldPane(MainActivity act, long time, LinearLayout.LayoutParams pView, LinearLayout.LayoutParams pText)
103 115
    {
104 116
    View view = act.getLayoutInflater().inflate(R.layout.dialog_solve_old_pane, null);
105 117
    TextView title = view.findViewById(R.id.solves_pane_title);
118
    TextView dt = view.findViewById(R.id.solves_pane_date);
106 119
    TextView tm = view.findViewById(R.id.solves_pane_time);
107
    tm.setText(Long.toString(time));
120

  
121
    Date date = new Date(time);
122
    dt.setText(convertToDate(date));
123
    tm.setText(convertToTime(date));
108 124

  
109 125
    view.setLayoutParams(pView);
110 126
    view.setPadding(mPadding,mPadding,mPadding,mPadding);
111 127

  
112 128
    title.setTextSize(TypedValue.COMPLEX_UNIT_PX, mFontSize);
129
    dt.setTextSize(TypedValue.COMPLEX_UNIT_PX, mFontSize);
113 130
    tm.setTextSize(TypedValue.COMPLEX_UNIT_PX, mFontSize);
114 131
    title.setLayoutParams(pText);
132
    dt.setLayoutParams(pText);
115 133
    tm.setLayoutParams(pText);
116 134

  
117 135
    Button but1 = view.findViewById(R.id.solves_pane_delete);
136
    but1.setTextSize(TypedValue.COMPLEX_UNIT_PX, mFontSize);
118 137

  
119 138
    but1.setOnClickListener( new View.OnClickListener()
120 139
        {
......
125 144
          }
126 145
        });
127 146

  
128
    but1.setTextSize(TypedValue.COMPLEX_UNIT_PX, mFontSize);
129
    but1.setLayoutParams(pButt);
130

  
131 147
    Button but2 = view.findViewById(R.id.solves_pane_resume);
148
    but2.setTextSize(TypedValue.COMPLEX_UNIT_PX, mFontSize);
132 149

  
133 150
    but2.setOnClickListener( new View.OnClickListener()
134 151
        {
......
139 156
          }
140 157
        });
141 158

  
142
    but2.setTextSize(TypedValue.COMPLEX_UNIT_PX, mFontSize);
143
    but2.setLayoutParams(pButt);
144

  
145 159
    return view;
146 160
    }
147 161

  
148 162
///////////////////////////////////////////////////////////////////////////////////////////////////
149 163

  
150
  private View createNewPane(MainActivity act, LinearLayout.LayoutParams pView, LinearLayout.LayoutParams pText, LinearLayout.LayoutParams pButt)
164
  private View createNewPane(MainActivity act, LinearLayout.LayoutParams pView, LinearLayout.LayoutParams pText)
151 165
    {
152 166
    View view = act.getLayoutInflater().inflate(R.layout.dialog_solve_new_pane, null);
153 167
    TextView title = view.findViewById(R.id.solves_pane_title);
......
159 173
    title.setLayoutParams(pText);
160 174

  
161 175
    Button but = view.findViewById(R.id.solves_pane_play);
176
    but.setTextSize(TypedValue.COMPLEX_UNIT_PX, mFontSize);
162 177

  
163 178
    but.setOnClickListener( new View.OnClickListener()
164 179
        {
......
169 184
          }
170 185
        });
171 186

  
172
    but.setTextSize(TypedValue.COMPLEX_UNIT_PX, mFontSize);
173
    but.setLayoutParams(pButt);
174

  
175 187
    return view;
176 188
    }
177 189

  
src/main/res/layout/dialog_scrollable_solves.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
3
    android:id="@+id/updates_scroll"
4
    android:layout_width="match_parent"
5
    android:layout_height="match_parent"
6
    android:background="?darkC"
7
    android:paddingTop="0dp"
8
    android:paddingBottom="0dp"
9
    android:paddingLeft="0dp"
10
    android:paddingRight="0dp">
11

  
12
    <LinearLayout
13
        android:id="@+id/dialog_scrollable_main_layout"
14
        android:layout_width="match_parent"
15
        android:layout_height="wrap_content"
16
        android:background="?veryDarkC"
17
        android:orientation="vertical">
18
    </LinearLayout>
19

  
20
</ScrollView>
src/main/res/layout/dialog_solve_new_pane.xml
30 30
 		android:layout_height="match_parent"
31 31
 		android:orientation="vertical"
32 32
 		android:layout_marginStart="8dp"
33
 		android:layout_weight="0.5">
33
 		android:layout_weight="1.2">
34 34

  
35 35
		<Button
36 36
             android:id="@+id/solves_pane_play"
src/main/res/layout/dialog_solve_old_pane.xml
11 11
    <LinearLayout
12 12
   		android:layout_width="0dp"
13 13
 		android:layout_height="match_parent"
14
 		android:orientation="horizontal"
14
 		android:orientation="vertical"
15 15
 		android:layout_weight="1.0">
16 16

  
17 17
		<TextView
......
24 24
    		android:textStyle="bold"/>
25 25

  
26 26
        <TextView
27
    		android:id="@+id/solves_pane_date"
28
    		android:gravity="center_vertical|start"
29
    		android:layout_width="match_parent"
30
    		android:layout_height="wrap_content"
31
    		android:singleLine="true"/>
32

  
33
    	<TextView
27 34
    		android:id="@+id/solves_pane_time"
28 35
    		android:gravity="center_vertical|start"
29
    		android:layout_width="wrap_content"
36
    		android:layout_width="match_parent"
30 37
    		android:layout_height="wrap_content"
31 38
    		android:singleLine="true"/>
32 39

  
......
37 44
 		android:layout_height="match_parent"
38 45
 		android:orientation="vertical"
39 46
 		android:layout_marginStart="8dp"
40
 		android:layout_weight="0.5">
47
 		android:layout_weight="1.2">
41 48

  
42 49
    	<Button
43 50
             android:id="@+id/solves_pane_delete"
44 51
             android:layout_width="match_parent"
45
             android:layout_height="wrap_content"
52
             android:layout_height="0dp"
53
             android:layout_weight="1.0"
46 54
             android:backgroundTint="?veryDarkC"
47
             android:minHeight="0dp"
48
             android:minWidth="0dp"
49 55
             android:insetTop="0dp"
50
             android:insetBottom="0dp"
51 56
             android:text="@string/delete"/>
57

  
52 58
		<Button
53 59
             android:id="@+id/solves_pane_resume"
54 60
             android:layout_width="match_parent"
55
             android:layout_height="wrap_content"
61
             android:layout_height="0dp"
62
             android:layout_weight="1.0"
56 63
             android:backgroundTint="?veryDarkC"
57
             android:minHeight="0dp"
58
             android:minWidth="0dp"
59
             android:insetTop="0dp"
60 64
             android:insetBottom="0dp"
61 65
             android:text="@string/resume"/>
62 66

  

Also available in: Unified diff