111
hxb
2022-11-24 0a3e07f10937484145f33c7560607b4b2353cb81
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
package com.mm.android.deviceaddmodule.views.popwindow;
 
import android.app.Activity;
import android.content.Context;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
 
import com.mm.android.deviceaddmodule.R;
import com.mm.android.deviceaddmodule.event.DeviceAddEvent;
import com.mm.android.deviceaddmodule.mobilecommon.base.adapter.CommonAdapter;
import com.mm.android.deviceaddmodule.mobilecommon.common.ViewHolder;
import com.mm.android.deviceaddmodule.mobilecommon.entity.deviceadd.DeviceAddInfo;
import com.mm.android.deviceaddmodule.model.DeviceAddModel;
 
import org.greenrobot.eventbus.EventBus;
 
import java.util.ArrayList;
import java.util.List;
 
public class ChoseTypePopWindow extends BasePopWindow implements AdapterView.OnItemClickListener {
    ListView mOptionList;
    OptionsAdapter mAdapter;
    PopWindowFactory.PopWindowType mType;
    List<Integer> mData;
    FragmentActivity mParent;
 
    ChoseTypePopWindow(View view, int width, int height) {
        super(view, width, height);
        mData = new ArrayList<>();
    }
 
    public void setType(PopWindowFactory.PopWindowType type) {
        this.mType = type;
        switch (type) {
            case CHOSETYPE:
                mData.add(R.string.add_device_add_by_wired);
                mData.add(R.string.add_device_add_by_sound_wave);
                mData.add(R.string.add_device_add_by_soft_ap);
                mData.add(R.string.common_cancel);
                break;
        }
    }
 
    @Override
    public void drawContent(Activity activity) {
        mParent = (FragmentActivity) activity;
        View view = getContentView();
        mOptionList = view.findViewById(R.id.option_list);
 
        mAdapter = new OptionsAdapter(R.layout.option_item, mData, activity);
        mOptionList.setAdapter(mAdapter);
        mOptionList.setOnItemClickListener(this);
    }
 
    @Override
    public void updateContent(Activity activity, boolean isPort) {
}
 
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        if (position == 0) {
            EventBus.getDefault().post(new DeviceAddEvent(DeviceAddEvent.CHANGE_TO_WIRED_ACTION));
            DeviceAddModel.newInstance().getDeviceInfoCache().setCurDeviceAddType(DeviceAddInfo.DeviceAddType.LAN);
        } else if (position == 1) {
            EventBus.getDefault().post(new DeviceAddEvent(DeviceAddEvent.CHANGE_TO_WIRELESS_ACTION));
            DeviceAddModel.newInstance().getDeviceInfoCache().setCurDeviceAddType(DeviceAddInfo.DeviceAddType.WLAN);
        } else if (position == 2) {
            EventBus.getDefault().post(new DeviceAddEvent(DeviceAddEvent.CHANGE_TO_SOFTAP_ACTION));
            DeviceAddModel.newInstance().getDeviceInfoCache().setCurDeviceAddType(DeviceAddInfo.DeviceAddType.SOFTAP);
        }
        dismiss();
}
 
    class OptionsAdapter extends CommonAdapter<Integer> {
 
        public OptionsAdapter(int layout, List list, Context mContext) {
            super(layout, list, mContext);
        }
 
        @Override
        public void convert(ViewHolder viewHolder, Integer item, int position, ViewGroup parent) {
            TextView optionName = (TextView) viewHolder.findViewById(R.id.option_name);
            optionName.setText(item);
            if (position == getCount() - 1) {
                optionName.setTextColor(mContext.getResources().getColor(R.color.c12));
                LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams)optionName.getLayoutParams();
                layoutParams.topMargin = 15;
                optionName.setLayoutParams(layoutParams);
            } else {
                optionName.setTextColor(mContext.getResources().getColor(R.color.c2));
                LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams)optionName.getLayoutParams();
                layoutParams.topMargin = 0;
                optionName.setLayoutParams(layoutParams);
            }
        }
    }
}