endian11
2020-09-16 cab2ea881e5711d16cf0003e8b00489a2c766365
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
package safeluck.drive.evaluation.customview;
 
import android.app.Dialog;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
 
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
 
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
 
import safeluck.drive.evaluation.DB.route.RouteBean;
import safeluck.drive.evaluation.R;
import safeluck.drive.evaluation.adapter.RouteSelectAdapter;
import safeluck.drive.evaluation.adapter.SysSettingPagerAdapter;
import safeluck.drive.evaluation.bean.SysExamSettingLargeMenu;
import safeluck.drive.evaluation.fragment.BaseSettingFragment;
import safeluck.drive.evaluation.fragment.shop.ShopFragment;
import safeluck.drive.evaluation.listener.OnItemClickListener;
 
/**
 * @ProjectName: DriveJudge
 * @Package: safeluck.drive.evaluation.customview
 * @ClassName: SelectDialog
 * @Description: java类作用描述
 * @Author: 李占伟
 * @CreateDate: 2020-04-23 15:03
 * @UpdateUser: 更新者
 * @UpdateDate: 2020-04-23 15:03
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
 
public class SelectMutliDialog extends DialogFragment implements View.OnClickListener {
 
    private static final String TAG = "SelectDialog";
    private Button button;
    private RadioGroup rgb;
 
    public static final int SELECT_NONE = -1;
    private int result = SELECT_NONE;
 
    private ArrayList<String> stringArrayList;
    private RecyclerView mRecy;
    private RouteSelectAdapter mAdapter;
 
 
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
 
        if (getDialog() != null) {
            Window window = getDialog().getWindow();
 
            if (window != null) {
                window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
                window.addFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
 
                getDialog().setOnShowListener(dialog ->  {
                        window.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
                        hideBottomUIMenu();
                });
            }
        }
        View view = inflater.inflate(R.layout.layout_select_dlg_multi,container,false);
        Bundle bundle = getArguments();
        if (bundle != null){
            stringArrayList = bundle.getStringArrayList("content");
        }
        initView(view);
        return view;
    }
 
    private void initView(View view) {
        mRecy = (RecyclerView) view.findViewById(R.id.recy);
 
        mAdapter = new RouteSelectAdapter(getActivity());
        LinearLayoutManager manager = new LinearLayoutManager(getActivity());
        mRecy.setLayoutManager(manager);
        mRecy.setAdapter(mAdapter);
 
        mAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(int position, View view) {
                Toast.makeText(getActivity(), position+"", Toast.LENGTH_SHORT).show();
                if (onSelectedListener != null){
                    onSelectedListener.makeYourChoice(result);
                }
                dismiss();
            }
        });
 
        mRecy.post(new Runnable() {
            @Override
            public void run() {
                // Init Datas
                ArrayList<String> menues = new ArrayList<>(Arrays.asList(getResources().getStringArray(R.array.array_large_item_menu)));
                List<RouteBean> items = new ArrayList<>();
                for (int i = 0; i < menues.size(); i++) {
                    RouteBean item  = new RouteBean();
                    item.setRouteName(menues.get(i));
                    item.setId(i);
                    items.add(item);
                }
                mAdapter.setDatas(items);
            }
        });
//        button = view.findViewById(R.id.btn_sure_);
 
//        button.setOnClickListener(this);
    }
 
    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_sure_:
                    if (onSelectedListener != null){
                        onSelectedListener.makeYourChoice(result);
                    }
                dismiss();
                break;
        }
    }
 
    public interface OnSelectedListener{
        void makeYourChoice(int res);
    }
 
    private OnSelectedListener onSelectedListener;
 
    public void setSelectedListener(OnSelectedListener onSelectedListener){
        this.onSelectedListener = onSelectedListener;
    }
 
    @Override
    public void onStart() {
        super.onStart();
        Dialog dialog = getDialog();
        if (dialog != null){
            DisplayMetrics dm = new DisplayMetrics();
            getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
            int width = (int)(dm.widthPixels*0.5);
            dialog.getWindow().setLayout(width,ViewGroup.LayoutParams.WRAP_CONTENT);
        }
    }
 
 
 
    public static SelectMutliDialog newInstance(String... args){
 
        SelectMutliDialog sle = new SelectMutliDialog();
        if (args != null && args.length>=2){
            List<String> strs = Arrays.asList(args);
            ArrayList<String> list = new ArrayList<>(strs);
            Bundle bundle = new Bundle();
            bundle.putStringArrayList("content",list);
            sle.setArguments(bundle);
        }
 
 
        return sle;
    }
    /**
     * 隐藏虚拟按键,并且全屏
     */
    protected void hideBottomUIMenu() {
        //隐藏虚拟按键,并且全屏
        if (Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { // lower api
            View v = this.getDialog().getWindow().getDecorView();
            v.setSystemUiVisibility(View.GONE);
        } else if (Build.VERSION.SDK_INT >= 19) {
            //for new api versions.
            View decorView = getDialog().getWindow().getDecorView();
            int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN;
            decorView.setSystemUiVisibility(uiOptions);
        }
    }
 
    @Override
    public void dismiss() {
 
        super.dismiss();
    }
}