This repository has been archived by the owner on Sep 6, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 527
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refs #2116
- Loading branch information
Showing
2 changed files
with
206 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package biz.bokhorst.xprivacy; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Map; | ||
import java.util.TreeMap; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.content.Context; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.view.View.OnClickListener; | ||
import android.widget.ArrayAdapter; | ||
import android.widget.CheckedTextView; | ||
import android.widget.ImageView; | ||
|
||
@SuppressLint("DefaultLocale") | ||
public class WhitelistAdapter extends ArrayAdapter<String> { | ||
private String mSelectedType; | ||
private int mUid; | ||
private Map<String, TreeMap<String, Boolean>> mMapWhitelists; | ||
private LayoutInflater mInflater; | ||
|
||
public WhitelistAdapter(Context context, int resource, int uid, Map<String, TreeMap<String, Boolean>> mapWhitelists) { | ||
super(context, resource, new ArrayList<String>()); | ||
mUid = uid; | ||
mMapWhitelists = mapWhitelists; | ||
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); | ||
} | ||
|
||
public void setType(String selectedType) { | ||
mSelectedType = selectedType; | ||
this.clear(); | ||
if (mMapWhitelists.containsKey(selectedType)) | ||
this.addAll(mMapWhitelists.get(selectedType).keySet()); | ||
} | ||
|
||
private class ViewHolder { | ||
private View row; | ||
public CheckedTextView ctvName; | ||
public ImageView imgDelete; | ||
|
||
public ViewHolder(View theRow, int thePosition) { | ||
row = theRow; | ||
ctvName = (CheckedTextView) row.findViewById(R.id.cbName); | ||
imgDelete = (ImageView) row.findViewById(R.id.imgDelete); | ||
} | ||
} | ||
|
||
@Override | ||
@SuppressLint("InflateParams") | ||
public View getView(int position, View convertView, ViewGroup parent) { | ||
final ViewHolder holder; | ||
if (convertView == null) { | ||
convertView = mInflater.inflate(R.layout.whitelistentry, null); | ||
holder = new ViewHolder(convertView, position); | ||
convertView.setTag(holder); | ||
} else | ||
holder = (ViewHolder) convertView.getTag(); | ||
|
||
// Set data | ||
final String name = this.getItem(position); | ||
holder.ctvName.setText(name); | ||
holder.ctvName.setChecked(mMapWhitelists.get(mSelectedType).get(name)); | ||
|
||
final boolean wnomod = PrivacyManager.getSettingBool(mUid, PrivacyManager.cSettingWhitelistNoModify, false); | ||
|
||
holder.ctvName.setOnClickListener(new OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
// Toggle white/black list entry | ||
holder.ctvName.toggle(); | ||
boolean isChecked = holder.ctvName.isChecked(); | ||
mMapWhitelists.get(mSelectedType).put(name, isChecked); | ||
PrivacyManager.setSetting(mUid, mSelectedType, name, Boolean.toString(isChecked)); | ||
if (!wnomod) | ||
PrivacyManager.updateState(mUid); | ||
} | ||
}); | ||
|
||
holder.imgDelete.setOnClickListener(new OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
// Delete white/black list entry | ||
WhitelistAdapter.this.remove(name); | ||
mMapWhitelists.get(mSelectedType).remove(name); | ||
PrivacyManager.setSetting(mUid, mSelectedType, name, null); | ||
if (!wnomod) | ||
PrivacyManager.updateState(mUid); | ||
} | ||
}); | ||
|
||
return convertView; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package biz.bokhorst.xprivacy; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.TreeMap; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.app.AlertDialog; | ||
import android.content.Context; | ||
import android.content.DialogInterface; | ||
import android.os.AsyncTask; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.widget.AdapterView; | ||
import android.widget.ArrayAdapter; | ||
import android.widget.ListView; | ||
import android.widget.Spinner; | ||
import android.widget.AdapterView.OnItemSelectedListener; | ||
|
||
public class WhitelistTask extends AsyncTask<Object, Object, Object> { | ||
private int mUid; | ||
private String mType; | ||
private ActivityBase mContext; | ||
private WhitelistAdapter mWhitelistAdapter; | ||
private Map<String, TreeMap<String, Boolean>> mListWhitelist; | ||
|
||
public WhitelistTask(int uid, String type, ActivityBase context) { | ||
mUid = uid; | ||
mType = type; | ||
mContext = context; | ||
} | ||
|
||
@Override | ||
protected Object doInBackground(Object... params) { | ||
mListWhitelist = PrivacyManager.listWhitelisted(mUid, null); | ||
mWhitelistAdapter = new WhitelistAdapter(mContext, R.layout.whitelistentry, mUid, mListWhitelist); | ||
return null; | ||
} | ||
|
||
@Override | ||
@SuppressLint({ "DefaultLocale", "InflateParams" }) | ||
protected void onPostExecute(Object result) { | ||
if (!mContext.isFinishing()) { | ||
// Build dialog | ||
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(mContext); | ||
alertDialogBuilder.setTitle(R.string.menu_whitelists); | ||
alertDialogBuilder.setIcon(mContext.getThemed(R.attr.icon_launcher)); | ||
|
||
if (mListWhitelist.keySet().size() > 0) { | ||
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); | ||
View llWhitelists = inflater.inflate(R.layout.whitelists, null); | ||
|
||
int index = 0; | ||
int selected = -1; | ||
final List<String> localizedType = new ArrayList<String>(); | ||
for (String type : mListWhitelist.keySet()) { | ||
String name = "whitelist_" + type.toLowerCase().replace("/", ""); | ||
int id = mContext.getResources().getIdentifier(name, "string", mContext.getPackageName()); | ||
if (id == 0) | ||
localizedType.add(name); | ||
else | ||
localizedType.add(mContext.getResources().getString(id)); | ||
|
||
if (type.equals(mType)) | ||
selected = index; | ||
index++; | ||
} | ||
|
||
Spinner spWhitelistType = (Spinner) llWhitelists.findViewById(R.id.spWhitelistType); | ||
ArrayAdapter<String> whitelistTypeAdapter = new ArrayAdapter<String>(mContext, | ||
android.R.layout.simple_spinner_dropdown_item, localizedType); | ||
spWhitelistType.setAdapter(whitelistTypeAdapter); | ||
spWhitelistType.setOnItemSelectedListener(new OnItemSelectedListener() { | ||
@Override | ||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { | ||
mWhitelistAdapter.setType(mListWhitelist.keySet().toArray(new String[0])[position]); | ||
} | ||
|
||
@Override | ||
public void onNothingSelected(AdapterView<?> view) { | ||
} | ||
}); | ||
if (selected >= 0) | ||
spWhitelistType.setSelection(selected); | ||
|
||
ListView lvWhitelist = (ListView) llWhitelists.findViewById(R.id.lvWhitelist); | ||
lvWhitelist.setAdapter(mWhitelistAdapter); | ||
int position = spWhitelistType.getSelectedItemPosition(); | ||
if (position != AdapterView.INVALID_POSITION) | ||
mWhitelistAdapter.setType(mListWhitelist.keySet().toArray(new String[0])[position]); | ||
|
||
alertDialogBuilder.setView(llWhitelists); | ||
} | ||
|
||
alertDialogBuilder.setPositiveButton(mContext.getString(R.string.msg_done), | ||
new DialogInterface.OnClickListener() { | ||
@Override | ||
public void onClick(DialogInterface dialog, int which) { | ||
// Do nothing | ||
} | ||
}); | ||
|
||
// Show dialog | ||
AlertDialog alertDialog = alertDialogBuilder.create(); | ||
alertDialog.show(); | ||
} | ||
|
||
super.onPostExecute(result); | ||
} | ||
} |