Search in sources :

Example 1 with MemStat

use of com.spazedog.lib.rootfw3.extenders.MemoryExtender.MemStat in project mounts2sd by SpazeDog.

the class FragmentTabConfigure method onDialogCreateView.

@Override
public View onDialogCreateView(String tag, LayoutInflater inflater, ViewGroup container, final Bundle extra) {
    ViewGroup placeholder = (ViewGroup) inflater.inflate(R.layout.inflate_dialog_placeholder, container, false);
    String selectorType = extra.getString("type");
    String selectorValue = extra.getString("value");
    String[] selectorEnabledValues = getEnabledSelectorValues(extra.getInt("viewId"));
    Integer selectorNamesId = getResources().getIdentifier("selector_" + selectorType + "_names", "array", getActivity().getPackageName());
    Integer selectorValuesId = getResources().getIdentifier("selector_" + selectorType + "_values", "array", getActivity().getPackageName());
    Integer selectorCommentsId = getResources().getIdentifier("selector_" + selectorType + "_comments", "array", getActivity().getPackageName());
    if (selectorNamesId != 0 && selectorValuesId != 0) {
        String[] selectorNames = getResources().getStringArray(selectorNamesId);
        String[] selectorValues = getResources().getStringArray(selectorValuesId);
        String[] selectorComments = selectorCommentsId != 0 ? getResources().getStringArray(selectorCommentsId) : new String[selectorNames.length];
        for (int i = 0; i < selectorNames.length; i++) {
            ViewGroup itemView = (ViewGroup) inflater.inflate(R.layout.inflate_selector_item, (ViewGroup) placeholder, false);
            Boolean enabled = true;
            if (selectorEnabledValues != null) {
                for (int x = 0; x < selectorEnabledValues.length; x++) {
                    if (selectorEnabledValues[x].equals(selectorValues[i])) {
                        enabled = true;
                        break;
                    }
                    enabled = false;
                }
            }
            if (selectorType.equals("threshold")) {
                selectorComments[i] = Common.convertPrifix((mPreferences.deviceConfig.size_storage_data() * (Double.parseDouble(selectorValues[i]) / 100)));
            } else if (selectorType.equals("zram")) {
                if (oMemoryUsage == null) {
                    RootFW rootfw = Root.initiate();
                    MemStat memstat = rootfw.memory().getUsage();
                    oMemoryUsage = memstat != null ? memstat.memTotal().doubleValue() : 0D;
                    Root.release();
                }
                selectorComments[i] = Common.convertPrifix((oMemoryUsage * (Double.parseDouble(selectorValues[i]) / 100)));
            }
            ((TextView) itemView.findViewById(R.id.item_name)).setText(selectorNames[i]);
            if (selectorComments[i] != null && !selectorComments[i].equals("")) {
                ((TextView) itemView.findViewById(R.id.item_description)).setText(selectorComments[i]);
            }
            itemView.setSelected(selectorValues[i].equals(selectorValue));
            itemView.setEnabled(enabled);
            itemView.setTag(selectorValues[i]);
            itemView.setOnTouchListener(new ViewEventHandler(new ViewClickListener() {

                @Override
                public void onViewClick(View v) {
                    extra.putString("value", (String) v.getTag());
                    ViewGroup view = (ViewGroup) v.getParent();
                    for (int i = 0; i < view.getChildCount(); i++) {
                        View child = view.getChildAt(i);
                        if (child == v) {
                            child.setSelected(true);
                        } else {
                            child.setSelected(false);
                        }
                    }
                }
            }));
            if (i > 0) {
                inflater.inflate(R.layout.inflate_dialog_divider, placeholder);
            }
            placeholder.addView(itemView);
        }
    }
    return placeholder;
}
Also used : ViewEventHandler(com.spazedog.mounts2sd.tools.ViewEventHandler) ViewGroup(android.view.ViewGroup) ViewClickListener(com.spazedog.mounts2sd.tools.ViewEventHandler.ViewClickListener) MemStat(com.spazedog.lib.rootfw3.extenders.MemoryExtender.MemStat) TextView(android.widget.TextView) TextView(android.widget.TextView) View(android.view.View) RootFW(com.spazedog.lib.rootfw3.RootFW)

Aggregations

View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 TextView (android.widget.TextView)1 RootFW (com.spazedog.lib.rootfw3.RootFW)1 MemStat (com.spazedog.lib.rootfw3.extenders.MemoryExtender.MemStat)1 ViewEventHandler (com.spazedog.mounts2sd.tools.ViewEventHandler)1 ViewClickListener (com.spazedog.mounts2sd.tools.ViewEventHandler.ViewClickListener)1