Kaynağa Gözat

app\main\java\com\Intelligent\FamilyU\adapter

生生化息 6 yıl önce
ebeveyn
işleme
d748523fcc

+ 109 - 0
app\main\java\com\Intelligent\FamilyU\adapter/CpuAndMemoryListRecyclerViewAdapter.java

@@ -0,0 +1,109 @@
+package com.Intelligent.FamilyU.adapter;
+
+import android.content.Context;
+import android.support.v7.widget.RecyclerView;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import com.Intelligent.FamilyU.R;
+
+import java.util.HashMap;
+import java.util.List;
+
+public class CpuAndMemoryListRecyclerViewAdapter extends RecyclerView.Adapter<CpuAndMemoryListRecyclerViewAdapter.ViewHolder> {
+    private List<HashMap<String, String>> mlist;
+    private Context context;
+    private OnItemClickListener mOnItemClickListener;
+
+    public static interface OnItemClickListener {
+        void onItemClick(int position);
+
+        void onItemLongClick(int position);
+    }
+
+    public CpuAndMemoryListRecyclerViewAdapter(Context context, List<HashMap<String, String>> list, OnItemClickListener onItemClickListener) {
+        super();
+        mlist = list;
+        this.context = context;
+        mOnItemClickListener = onItemClickListener;
+    }
+
+    public static class ViewHolder extends RecyclerView.ViewHolder {
+        // each data item is just a string in this case
+        public TextView title;
+        public TextView cpuTv;
+        public TextView memoryTv;
+        public LinearLayout ll;
+
+        public ViewHolder(View v) {
+            super(v);
+        }
+    }
+
+    // Create new views (invoked by the layout manager)
+    @Override
+    public CpuAndMemoryListRecyclerViewAdapter.ViewHolder onCreateViewHolder(ViewGroup parent,
+                                                                             int viewType) {
+        // create a new view
+        View convertView = LayoutInflater.from(context)
+                .inflate(R.layout.listview_cpu_memory_listitem, parent, false);
+        ViewHolder viewHolder = new ViewHolder(convertView);
+        viewHolder.title = (TextView) convertView.findViewById(R.id.title);
+        viewHolder.cpuTv = (TextView) convertView.findViewById(R.id.cpu_tv);
+        viewHolder.memoryTv = convertView.findViewById(R.id.memory_tv);
+        viewHolder.ll = (LinearLayout) convertView.findViewById(R.id.ll);
+
+        return viewHolder;
+    }
+
+    // Replace the contents of a view (invoked by the layout manager)
+    @Override
+    public void onBindViewHolder(ViewHolder holder, final int position) {
+        // - get element from your dataset at this position
+        // - replace the contents of the view with that element
+        HashMap<String, String> map = mlist.get(position);
+        holder.title.setText(map.get("title"));
+        String cpuStr = context.getResources().getString(R.string.home_cpu_use);
+        String resultCpu = String.format(cpuStr, map.get("cpu"));
+        holder.cpuTv.setText(resultCpu);
+        String memoryStr = context.getResources().getString(R.string.home_memory_use);
+        String result = String.format(memoryStr, map.get("memory"));
+        holder.memoryTv.setText(result);
+        holder.ll.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                mOnItemClickListener.onItemClick(position);
+            }
+        });
+        holder.ll.setOnLongClickListener(new View.OnLongClickListener() {
+            @Override
+            public boolean onLongClick(View v) {
+                mOnItemClickListener.onItemLongClick(position);
+                return true;
+            }
+        });
+
+    }
+
+    // Return the size of your dataset (invoked by the layout manager)
+    @Override
+    public int getItemCount() {
+        return mlist.size();
+    }
+
+    public void refreshData(List<HashMap<String, String>> list) {
+        if (null != mlist) {
+            mlist.clear();
+        }
+        mlist.addAll(list);
+        notifyDataSetChanged();
+    }
+
+    public List<HashMap<String, String>> getAllList() {
+        return mlist;
+    }
+
+}

+ 106 - 0
app\main\java\com\Intelligent\FamilyU\adapter/DeviceListRecyclerViewAdapter.java

@@ -0,0 +1,106 @@
+package com.Intelligent.FamilyU.adapter;
+
+import android.content.Context;
+import android.support.v7.widget.RecyclerView;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import com.Intelligent.FamilyU.R;
+
+import java.util.HashMap;
+import java.util.List;
+
+public class DeviceListRecyclerViewAdapter extends RecyclerView.Adapter<DeviceListRecyclerViewAdapter.ViewHolder> {
+    private List<HashMap<String, String>> mlist;
+    private Context context;
+    private OnItemClickListener mOnItemClickListener;
+
+    public static interface OnItemClickListener {
+        void onItemClick(int position);
+
+        void onItemLongClick(int position);
+    }
+
+    public DeviceListRecyclerViewAdapter(Context context, List<HashMap<String, String>> list, OnItemClickListener onItemClickListener) {
+        super();
+        mlist = list;
+        this.context = context;
+        mOnItemClickListener = onItemClickListener;
+    }
+
+    public static class ViewHolder extends RecyclerView.ViewHolder {
+        // each data item is just a string in this case
+        public TextView name;
+        public ImageView imv1;
+        public TextView model;
+        public ImageView imv2;
+        public LinearLayout ll;
+
+        public ViewHolder(View v) {
+            super(v);
+        }
+    }
+
+    // Create new views (invoked by the layout manager)
+    @Override
+    public DeviceListRecyclerViewAdapter.ViewHolder onCreateViewHolder(ViewGroup parent,
+                                                                       int viewType) {
+        // create a new view
+        View convertView = LayoutInflater.from(parent.getContext())
+                .inflate(R.layout.listview_add_device_list_item, parent, false);
+        ViewHolder viewHolder = new ViewHolder(convertView);
+        viewHolder.name = (TextView) convertView.findViewById(R.id.name);
+        viewHolder.imv1 = (ImageView) convertView.findViewById(R.id.iv1);
+        viewHolder.model = (TextView) convertView.findViewById(R.id.model);
+        viewHolder.imv2 = (ImageView) convertView.findViewById(R.id.iv2);
+        viewHolder.ll = (LinearLayout) convertView.findViewById(R.id.ll);
+
+        return viewHolder;
+    }
+
+    // Replace the contents of a view (invoked by the layout manager)
+    @Override
+    public void onBindViewHolder(ViewHolder holder, final int position) {
+        // - get element from your dataset at this position
+        // - replace the contents of the view with that element
+        HashMap<String, String> map = mlist.get(position);
+        holder.name.setText(map.get("name"));
+        holder.model.setText(map.get("model"));
+        holder.ll.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                mOnItemClickListener.onItemClick(position);
+            }
+        });
+        holder.ll.setOnLongClickListener(new View.OnLongClickListener() {
+            @Override
+            public boolean onLongClick(View v) {
+                mOnItemClickListener.onItemLongClick(position);
+                return true;
+            }
+        });
+
+    }
+    // Return the size of your dataset (invoked by the layout manager)
+    @Override
+    public int getItemCount() {
+        return mlist.size();
+    }
+
+    public void refreshData(List<HashMap<String, String>> list) {
+        if (null != mlist) {
+            mlist.clear();
+        }
+        mlist.addAll(list);
+        notifyDataSetChanged();
+    }
+
+    public List<HashMap<String, String>> getAllList() {
+        return mlist;
+    }
+
+}

+ 104 - 0
app\main\java\com\Intelligent\FamilyU\adapter/DeviceMessageListRecyclerViewAdapter.java

@@ -0,0 +1,104 @@
+package com.Intelligent.FamilyU.adapter;
+
+import android.content.Context;
+import android.support.v7.widget.RecyclerView;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import com.Intelligent.FamilyU.R;
+
+import java.util.HashMap;
+import java.util.List;
+
+public class DeviceMessageListRecyclerViewAdapter extends RecyclerView.Adapter<DeviceMessageListRecyclerViewAdapter.ViewHolder> {
+    private List<HashMap<String, String>> mlist;
+    private Context context;
+    private OnItemClickListener mOnItemClickListener;
+
+    public static interface OnItemClickListener {
+        void onItemClick(int position);
+
+        void onItemLongClick(int position);
+    }
+
+    public DeviceMessageListRecyclerViewAdapter(Context context, List<HashMap<String, String>> list, OnItemClickListener onItemClickListener) {
+        super();
+        mlist = list;
+        this.context = context;
+        mOnItemClickListener = onItemClickListener;
+    }
+
+    public static class ViewHolder extends RecyclerView.ViewHolder {
+        // each data item is just a string in this case
+        public TextView title;
+        public TextView message;
+        public TextView time;
+        public LinearLayout ll;
+
+        public ViewHolder(View v) {
+            super(v);
+        }
+    }
+
+    // Create new views (invoked by the layout manager)
+    @Override
+    public DeviceMessageListRecyclerViewAdapter.ViewHolder onCreateViewHolder(ViewGroup parent,
+                                                                              int viewType) {
+        // create a new view
+        View convertView = LayoutInflater.from(context)
+                .inflate(R.layout.listview_add_device_message_list_item, parent, false);
+        ViewHolder viewHolder = new ViewHolder(convertView);
+        viewHolder.title = (TextView) convertView.findViewById(R.id.title);
+        viewHolder.message = (TextView) convertView.findViewById(R.id.message);
+        viewHolder.time = (TextView) convertView.findViewById(R.id.time);
+        viewHolder.ll = (LinearLayout) convertView.findViewById(R.id.ll);
+
+        return viewHolder;
+    }
+
+    // Replace the contents of a view (invoked by the layout manager)
+    @Override
+    public void onBindViewHolder(ViewHolder holder, final int position) {
+        // - get element from your dataset at this position
+        // - replace the contents of the view with that element
+        HashMap<String, String> map = mlist.get(position);
+        holder.title.setText(map.get("title"));
+        holder.message.setText(map.get("message"));
+        holder.time.setText(map.get("time"));
+        holder.ll.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                mOnItemClickListener.onItemClick(position);
+            }
+        });
+        holder.ll.setOnLongClickListener(new View.OnLongClickListener() {
+            @Override
+            public boolean onLongClick(View v) {
+                mOnItemClickListener.onItemLongClick(position);
+                return true;
+            }
+        });
+
+    }
+    // Return the size of your dataset (invoked by the layout manager)
+    @Override
+    public int getItemCount() {
+        return mlist.size();
+    }
+
+    public void refreshData(List<HashMap<String, String>> list) {
+        if (null != mlist) {
+            mlist.clear();
+        }
+        mlist.addAll(list);
+        notifyDataSetChanged();
+    }
+
+    public List<HashMap<String, String>> getAllList() {
+        return mlist;
+    }
+
+}

+ 144 - 0
app\main\java\com\Intelligent\FamilyU\adapter/DeviceModelHomeRecyclerViewAdapter.java

@@ -0,0 +1,144 @@
+package com.Intelligent.FamilyU.adapter;
+
+import android.content.Context;
+import android.support.v7.widget.RecyclerView;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import com.Intelligent.FamilyU.R;
+
+import java.util.HashMap;
+import java.util.List;
+
+public class DeviceModelHomeRecyclerViewAdapter extends RecyclerView.Adapter<DeviceModelHomeRecyclerViewAdapter.ViewHolder> {
+    private List<HashMap<String, String>> mlist;
+    private Context context;
+    private OnItemClickListener mOnItemClickListener;
+
+    public static interface OnItemClickListener {
+        void onItemClick(int position);
+
+        void onItemLongClick(int position);
+    }
+
+    public DeviceModelHomeRecyclerViewAdapter(Context context, List<HashMap<String, String>> list, OnItemClickListener onItemClickListener) {
+        super();
+        mlist = list;
+        this.context = context;
+        mOnItemClickListener = onItemClickListener;
+    }
+
+    public static class ViewHolder extends RecyclerView.ViewHolder {
+        // each data item is just a string in this case
+        public TextView name;
+        public ImageView imv;
+        public ImageView nameIv;
+        public LinearLayout ll;
+
+        public ViewHolder(View v) {
+            super(v);
+        }
+    }
+
+    // Create new views (invoked by the layout manager)
+    @Override
+    public DeviceModelHomeRecyclerViewAdapter.ViewHolder onCreateViewHolder(ViewGroup parent,
+                                                                            int viewType) {
+        // create a new view
+        View convertView = LayoutInflater.from(parent.getContext())
+                .inflate(R.layout.listview_add_device_home_item, parent, false);
+        ViewHolder viewHolder = new ViewHolder(convertView);
+        viewHolder.name = (TextView) convertView.findViewById(R.id.name_tv);
+        viewHolder.imv = (ImageView) convertView.findViewById(R.id.iv);
+        viewHolder.nameIv = (ImageView) convertView.findViewById(R.id.name_iv);
+        viewHolder.ll = (LinearLayout) convertView.findViewById(R.id.ll);
+
+        return viewHolder;
+    }
+
+    // Replace the contents of a view (invoked by the layout manager)
+    @Override
+    public void onBindViewHolder(ViewHolder holder, final int position) {
+        // - get element from your dataset at this position
+        // - replace the contents of the view with that element
+        HashMap<String, String> map = mlist.get(position);
+        String name = map.get("name");
+        holder.name.setText(name);
+        if ("add".equals(name)) {
+            holder.name.setVisibility(View.GONE);
+            holder.nameIv.setVisibility(View.GONE);
+            holder.imv.setImageResource(R.mipmap.dlna_icon_member_add);
+        } else {
+            holder.name.setVisibility(View.VISIBLE);
+            holder.nameIv.setVisibility(View.VISIBLE);
+            holder.imv.setImageResource(R.mipmap.icon_big_study);
+        }
+        holder.ll.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                mOnItemClickListener.onItemClick(position);
+            }
+        });
+        holder.ll.setOnLongClickListener(new View.OnLongClickListener() {
+            @Override
+            public boolean onLongClick(View v) {
+                mOnItemClickListener.onItemLongClick(position);
+                return true;
+            }
+        });
+
+    }
+
+    // Return the size of your dataset (invoked by the layout manager)
+    @Override
+    public int getItemCount() {
+        return mlist.size();
+    }
+
+    public void refreshData(List<HashMap<String, String>> list) {
+        if (null != mlist) {
+            mlist.clear();
+        }
+        mlist.addAll(list);
+        notifyDataSetChanged();
+    }
+
+    public List<HashMap<String, String>> getAllList() {
+        return mlist;
+    }
+
+    // 添加数据
+    public void addData(HashMap<String, String> map, int position) {
+        mlist.add(map);
+        //添加动画
+        notifyItemInserted(position);
+    }
+
+    // 删除数据
+    public void removeData(int position) {
+        mlist.remove(position);
+        //删除动画
+        notifyItemRemoved(position);
+        notifyDataSetChanged();
+    }
+
+    public void addBtn() {
+        if (null == mlist || mlist.size() == 0) {
+            return;
+        }
+//        if ("add".equals(mlist.get(mlist.size() - 1).get("name"))) {
+//            mlist.remove(mlist.size() - 1);
+//        }
+        HashMap<String, String> map = new HashMap<String, String>();
+        map.put("name", "add");
+        mlist.add(map);
+        notifyItemInserted(mlist.size()-1);
+//        List<HashMap<String, String>> list = new ArrayList<>();
+//        list.addAll(mlist);
+//        refreshData(list);
+    }
+}

+ 102 - 0
app\main\java\com\Intelligent\FamilyU\adapter/DeviceModelRecyclerViewAdapter.java

@@ -0,0 +1,102 @@
+package com.Intelligent.FamilyU.adapter;
+
+import android.content.Context;
+import android.support.v7.widget.RecyclerView;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import com.Intelligent.FamilyU.R;
+
+import java.util.HashMap;
+import java.util.List;
+
+public class DeviceModelRecyclerViewAdapter extends RecyclerView.Adapter<DeviceModelRecyclerViewAdapter.ViewHolder> {
+    private List<HashMap<String, String>> mlist;
+    private Context context;
+    private OnItemClickListener mOnItemClickListener;
+
+    public static interface OnItemClickListener {
+        void onItemClick(int position);
+
+        void onItemLongClick(int position);
+    }
+
+    public DeviceModelRecyclerViewAdapter(Context context, List<HashMap<String, String>> list, OnItemClickListener onItemClickListener) {
+        super();
+        mlist = list;
+        this.context = context;
+        mOnItemClickListener = onItemClickListener;
+    }
+
+    public static class ViewHolder extends RecyclerView.ViewHolder {
+        // each data item is just a string in this case
+        public TextView name;
+        public ImageView imv;
+        public LinearLayout ll;
+
+        public ViewHolder(View v) {
+            super(v);
+        }
+    }
+
+    // Create new views (invoked by the layout manager)
+    @Override
+    public DeviceModelRecyclerViewAdapter.ViewHolder onCreateViewHolder(ViewGroup parent,
+                                                                        int viewType) {
+        // create a new view
+        View convertView = LayoutInflater.from(parent.getContext())
+                .inflate(R.layout.listview_add_device_item, parent, false);
+        ViewHolder viewHolder = new ViewHolder(convertView);
+        viewHolder.name = (TextView) convertView.findViewById(R.id.name);
+        viewHolder.imv = (ImageView) convertView.findViewById(R.id.iv);
+        viewHolder.ll = (LinearLayout) convertView.findViewById(R.id.ll);
+
+        return viewHolder;
+    }
+
+    // Replace the contents of a view (invoked by the layout manager)
+    @Override
+    public void onBindViewHolder(ViewHolder holder, final int position) {
+        // - get element from your dataset at this position
+        // - replace the contents of the view with that element
+        HashMap<String, String> map = mlist.get(position);
+        holder.name.setText(map.get("name"));
+        holder.name.setTextColor(context.getResources().getColor(R.color.black));
+        holder.ll.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                mOnItemClickListener.onItemClick(position);
+            }
+        });
+        holder.ll.setOnLongClickListener(new View.OnLongClickListener() {
+            @Override
+            public boolean onLongClick(View v) {
+                mOnItemClickListener.onItemLongClick(position);
+                return true;
+            }
+        });
+
+    }
+    // Return the size of your dataset (invoked by the layout manager)
+    @Override
+    public int getItemCount() {
+        return mlist.size();
+    }
+
+    public void refreshData(List<HashMap<String, String>> list) {
+        if (null != mlist) {
+            mlist.clear();
+        }
+        mlist.addAll(list);
+        notifyDataSetChanged();
+    }
+
+    public List<HashMap<String, String>> getAllList() {
+        return mlist;
+    }
+
+}