Android Open Source - androiddevice.info Device Information List Adapter






From Project

Back to project page androiddevice.info.

License

The source code is released under:

GNU General Public License

If you think the Android project androiddevice.info listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package info.androiddevice.deviceinventory.submission;
//  w w w .  j  a v  a  2 s  . c o  m
import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class DeviceInformationListAdapter extends BaseAdapter {
    public static final int MAX_LINES = 10;

    private final LayoutInflater mInflater;
    private final int mWhiteColor;
    private final int mGreyColor;
    private List<KeyValuePair> mItems;
    private String mDeviceName;

    public DeviceInformationListAdapter(Context context, JSONObject deviceInformation){
        mInflater = LayoutInflater.from(context);
        mItems = new ArrayList<KeyValuePair>();
        mWhiteColor = context.getResources().getColor(android.R.color.white);
        mGreyColor = context.getResources().getColor(R.color.subtext_grey);
        JSONArray keys = deviceInformation.names();
        for(int ii = 0 ; ii < keys.length(); ++ii) {
            try {
                final String key = keys.getString(ii);
                final Object value = deviceInformation.get(key);
                final String valueString = String.valueOf(value);
                mItems.add(new KeyValuePair(key, value, valueString, key.equals("name")));
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        Collections.sort(mItems, new Comparator<KeyValuePair>() {
            @Override
            public int compare(KeyValuePair lhs, KeyValuePair rhs) {
                if(lhs.isEditable){
                    return -1;
                }
                return lhs.key.compareTo(rhs.key);
            }
        });
    }

    @Override
    public int getCount() {
        return mItems.size();
    }

    @Override
    public KeyValuePair getItem(int position) {
        return mItems.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

//    @Override
//    public boolean isEnabled(int position) {
//        return getItem(position).isEditable;
//    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;
        if(null == view){
            view = mInflater.inflate(R.layout.editable_list_item, parent, false);
        }
        KeyValuePair pair = getItem(position);
        if(null != pair){
            TextView key = ((TextView)view.findViewById(android.R.id.text1));
            key.setText(pair.key);
            key.setTextColor(mWhiteColor);

            final TextView value = ((TextView)view.findViewById(android.R.id.text2));
            final TextView editable  = ((TextView)view.findViewById(R.id.editable));

            if(pair.isEditable){
                value.setVisibility(View.GONE);
                editable.setVisibility(View.VISIBLE);
                if(null != mDeviceName && mDeviceName.length() > 0) {
                    editable.setText(mDeviceName);
                }
            } else {
                value.setVisibility(View.VISIBLE);
                editable.setVisibility(View.GONE);
                value.setText(pair.valueString);
                value.setTextColor(mGreyColor);
                value.setMaxLines(10);
                value.setEllipsize(TextUtils.TruncateAt.END);
            }

            //details.setVisibility(TextView.GONE);

//            ((TextView)view.findViewById(android.R.id.text1)).setOnClickListener(new View.OnClickListener() {
//                private TextView detailsItem = details;
//                @Override
//                public void onClick(View view) {
//                    if(detailsItem.getVisibility() == TextView.VISIBLE) {
//                        detailsItem.setVisibility(TextView.GONE);
//                    } else if(detailsItem.getVisibility() == TextView.GONE) {
//                        detailsItem.setVisibility(TextView.VISIBLE);
//                    }
//                }
//            });
        }
        return view;
    }

    public void setDeviceName(String deviceName) {
        mDeviceName = deviceName;
        notifyDataSetChanged();
    }

    static class KeyValuePair {
        String key;
        Object value;
        String valueString;
        boolean isEditable = false;

        KeyValuePair(String key, Object value, String valueString, boolean isEditable){
            this.key = key;
            this.value = value;
            this.valueString = valueString;
            this.isEditable = isEditable;
        }
    }
}




Java Source Code List

android.system.ErrnoException.java
android.system.Os.java
android.system.StructStat.java
info.androiddevice.deviceinventory.Application.java
info.androiddevice.deviceinventory.DeviceInformation.java
info.androiddevice.deviceinventory.Error.java
info.androiddevice.deviceinventory.info.CpuinfoProperty.java
info.androiddevice.deviceinventory.info.DirProperty.java
info.androiddevice.deviceinventory.info.DisplayProperty.java
info.androiddevice.deviceinventory.info.EnvironmentProperty.java
info.androiddevice.deviceinventory.info.FeaturesProperty.java
info.androiddevice.deviceinventory.info.FileProperty.java
info.androiddevice.deviceinventory.info.GetPropProperty.java
info.androiddevice.deviceinventory.info.JavaSystemProperty.java
info.androiddevice.deviceinventory.info.MeminfoProperty.java
info.androiddevice.deviceinventory.info.MountsProperty.java
info.androiddevice.deviceinventory.info.NameProperty.java
info.androiddevice.deviceinventory.info.OtacertsProperty.java
info.androiddevice.deviceinventory.info.PackageSigProperty.java
info.androiddevice.deviceinventory.info.Property.java
info.androiddevice.deviceinventory.info.SharedLibraryNamesProperty.java
info.androiddevice.deviceinventory.info.UsbProperty.java
info.androiddevice.deviceinventory.info.Utils.java
info.androiddevice.deviceinventory.info.VersionProperty.java
info.androiddevice.deviceinventory.submission.DeviceInformationListAdapter.java
info.androiddevice.deviceinventory.submission.MainActivity.java
libcore.io.ErrnoException.java
libcore.io.Libcore.java
libcore.io.Os.java
libcore.io.StructStat.java
name.unused.android.utils.systemproperties.SystemProperty.java
name.unused.android.utils.systemproperties.exception.NoSuchPropertyException.java