@Override public View getChildView( int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); View row = inflater.inflate(R.layout.restrictionchild, parent, false); final CheckedTextView ctvMethodName = (CheckedTextView) row.findViewById(R.id.ctvMethodName); // Get entry final String restrictionName = (String) getGroup(groupPosition); final String methodName = (String) getChild(groupPosition, childPosition); long lastUsage = PrivacyManager.getUsed(row.getContext(), mAppInfo.getUid(), restrictionName, methodName); // Display method name if (lastUsage == 0) ctvMethodName.setText(methodName); else { Date date = new Date(lastUsage); SimpleDateFormat format = new SimpleDateFormat("dd/HH:mm", Locale.US); ctvMethodName.setText(String.format("%s %s", methodName, format.format(date))); } boolean parentRestricted = PrivacyManager.getRestricted( null, row.getContext(), mAppInfo.getUid(), restrictionName, null, false, false); ctvMethodName.setEnabled(parentRestricted); // Display if used if (lastUsage != 0) ctvMethodName.setTypeface(null, Typeface.BOLD_ITALIC); // Display restriction boolean restricted = PrivacyManager.getRestricted( null, row.getContext(), mAppInfo.getUid(), restrictionName, methodName, false, false); ctvMethodName.setChecked(restricted); // Listen for restriction changes ctvMethodName.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { boolean restricted = PrivacyManager.getRestricted( null, view.getContext(), mAppInfo.getUid(), restrictionName, methodName, false, false); restricted = !restricted; ctvMethodName.setChecked(restricted); PrivacyManager.setRestricted( null, view.getContext(), mAppInfo.getUid(), restrictionName, methodName, restricted); } }); return row; }
@Override public View getView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); View row = inflater.inflate(R.layout.xmainentry, parent, false); LinearLayout llIcon = (LinearLayout) row.findViewById(R.id.llIcon); ImageView imgIcon = (ImageView) row.findViewById(R.id.imgIcon); ImageView imgInternet = (ImageView) row.findViewById(R.id.imgInternet); ImageView imgUsed = (ImageView) row.findViewById(R.id.imgUsed); final CheckedTextView ctvApp = (CheckedTextView) row.findViewById(R.id.ctvName); // Get entry final XApplicationInfo xAppInfo = getItem(position); // Set background color if (xAppInfo.getIsSystem()) if (mThemeId == android.R.style.Theme_Holo_Light) row.setBackgroundColor(Color.parseColor("#FFFDD0")); else row.setBackgroundColor(Color.DKGRAY); // Click handler llIcon.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { Intent intentSettings = new Intent(view.getContext(), ActivityApp.class); intentSettings.putExtra(ActivityApp.cPackageName, xAppInfo.getPackageName()); intentSettings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); view.getContext().startActivity(intentSettings); } }); // Set icon imgIcon.setImageDrawable(xAppInfo.getDrawable()); // Set title ctvApp.setText(xAppInfo.toString()); // Check if internet access imgInternet.setVisibility(xAppInfo.hasInternet() ? View.VISIBLE : View.INVISIBLE); // Check if used boolean used = XRestriction.isUsed(row.getContext(), xAppInfo.getUid(), mRestrictionName, null); ctvApp.setTypeface(null, used ? Typeface.BOLD_ITALIC : Typeface.NORMAL); imgUsed.setVisibility(used ? View.VISIBLE : View.INVISIBLE); // Display restriction boolean restricted = XRestriction.getRestricted( null, row.getContext(), xAppInfo.getUid(), mRestrictionName, null, false, false); ctvApp.setChecked(restricted); // Listen for restriction changes ctvApp.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { boolean restricted = XRestriction.getRestricted( null, view.getContext(), xAppInfo.getUid(), mRestrictionName, null, false, false); restricted = !restricted; ctvApp.setChecked(restricted); XRestriction.setRestricted( null, view.getContext(), xAppInfo.getUid(), mRestrictionName, null, restricted); } }); row.refreshDrawableState(); return row; }
@Override public View getGroupView( int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); View row = inflater.inflate(R.layout.restrictionentry, parent, false); ImageView imgIndicator = (ImageView) row.findViewById(R.id.imgIndicator); ImageView imgUsed = (ImageView) row.findViewById(R.id.imgUsed); ImageView imgGranted = (ImageView) row.findViewById(R.id.imgGranted); ImageView imgInfo = (ImageView) row.findViewById(R.id.imgInfo); final CheckedTextView ctvRestriction = (CheckedTextView) row.findViewById(R.id.ctvName); // Indicator state imgIndicator.setImageResource( isExpanded ? R.drawable.expander_ic_maximized : R.drawable.expander_ic_minimized); // Disable indicator for empty groups if (mExpert) { if (getChildrenCount(groupPosition) == 0) imgIndicator.setVisibility(View.INVISIBLE); } else imgIndicator.setVisibility(View.GONE); // Get entry final String restrictionName = (String) getGroup(groupPosition); // Display if restriction granted if (!PrivacyManager.hasPermission( row.getContext(), mAppInfo.getPackageName(), restrictionName)) imgGranted.setVisibility(View.INVISIBLE); // Display if used if (PrivacyManager.getUsed(row.getContext(), mAppInfo.getUid(), restrictionName, null) != 0) ctvRestriction.setTypeface(null, Typeface.BOLD_ITALIC); else imgUsed.setVisibility(View.INVISIBLE); // Handle info imgInfo.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { Intent infoIntent = new Intent(Intent.ACTION_VIEW); infoIntent.setData( Uri.parse( String.format( "http://wiki.faircode.eu/index.php?title=%s", restrictionName))); startActivity(infoIntent); } }); // Display localized name ctvRestriction.setText(PrivacyManager.getLocalizedName(row.getContext(), restrictionName)); // Display restriction boolean restricted = PrivacyManager.getRestricted( null, row.getContext(), mAppInfo.getUid(), restrictionName, null, false, false); ctvRestriction.setChecked(restricted); // Listen for restriction changes ctvRestriction.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { boolean restricted = PrivacyManager.getRestricted( null, view.getContext(), mAppInfo.getUid(), restrictionName, null, false, false); restricted = !restricted; ctvRestriction.setChecked(restricted); PrivacyManager.setRestricted( null, view.getContext(), mAppInfo.getUid(), restrictionName, null, restricted); notifyDataSetChanged(); } }); return row; }