Skip to content
This repository has been archived by the owner on Sep 6, 2019. It is now read-only.

Commit

Permalink
Modified tri-state check box implementation
Browse files Browse the repository at this point in the history
Refs #833
  • Loading branch information
M66B committed Nov 27, 2013
1 parent cf43cb3 commit c41158f
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 74 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Changelog

* Caching of application information for better response times
* Restriction of draw over / on top ([issue](https://github.com/M66B/XPrivacy/issues/830))
* Modified tri-state check box implementation ([issue](https://github.com/M66B/XPrivacy/issues/833))
* Updated Arabic translation
* Updated Dutch translation
* Updated Polish translation
Expand Down
32 changes: 12 additions & 20 deletions src/biz/bokhorst/xprivacy/ActivityApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
import android.support.v4.app.NavUtils;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.TaskStackBuilder;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
Expand Down Expand Up @@ -155,7 +154,7 @@ public void onClick(View view) {
// Background color
if (mAppInfo.isSystem()) {
LinearLayout llInfo = (LinearLayout) findViewById(R.id.llInfo);
llInfo.setBackgroundColor(getResources().getColor(getThemed(R.attr.color_dangerous)));
llInfo.setBackgroundColor(getResources().getColor(Util.getThemed(this, R.attr.color_dangerous)));
}

// Display app icon
Expand Down Expand Up @@ -374,7 +373,7 @@ private void optionHelp() {
dialog.requestWindowFeature(Window.FEATURE_LEFT_ICON);
dialog.setTitle(getString(R.string.help_application));
dialog.setContentView(R.layout.help);
dialog.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, getThemed(R.attr.icon_launcher));
dialog.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, Util.getThemed(this, R.attr.icon_launcher));
TextView tvHelpHalf = (TextView) dialog.findViewById(R.id.help_half);
Drawable dHalf = new BitmapDrawable(getResources(), mCheck[1]);
dHalf.setBounds(0, 0, 48, 48);
Expand All @@ -387,7 +386,7 @@ private void optionApply() {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ActivityApp.this);
alertDialogBuilder.setTitle(getString(R.string.app_name));
alertDialogBuilder.setMessage(getString(R.string.msg_sure));
alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher));
alertDialogBuilder.setIcon(Util.getThemed(this, R.attr.icon_launcher));
alertDialogBuilder.setPositiveButton(getString(android.R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Expand Down Expand Up @@ -429,7 +428,7 @@ private void optionClear() {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ActivityApp.this);
alertDialogBuilder.setTitle(getString(R.string.app_name));
alertDialogBuilder.setMessage(getString(R.string.msg_sure));
alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher));
alertDialogBuilder.setIcon(Util.getThemed(this, R.attr.icon_launcher));
alertDialogBuilder.setPositiveButton(getString(android.R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Expand Down Expand Up @@ -458,7 +457,7 @@ private void optionSubmit() {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setTitle(getString(R.string.app_name));
alertDialogBuilder.setMessage(getString(R.string.msg_sure));
alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher));
alertDialogBuilder.setIcon(Util.getThemed(this, R.attr.icon_launcher));
alertDialogBuilder.setPositiveButton(getString(android.R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Expand Down Expand Up @@ -562,7 +561,7 @@ protected void onPostExecute(Object result) {
// Build dialog
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ActivityApp.this);
alertDialogBuilder.setTitle(getString(R.string.menu_accounts));
alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher));
alertDialogBuilder.setIcon(Util.getThemed(ActivityApp.this, R.attr.icon_launcher));
alertDialogBuilder.setMultiChoiceItems(mListAccount.toArray(new CharSequence[0]), mSelection,
new DialogInterface.OnMultiChoiceClickListener() {
public void onClick(DialogInterface dialog, int whichButton, boolean isChecked) {
Expand Down Expand Up @@ -631,7 +630,7 @@ protected void onPostExecute(Object result) {
// Build dialog
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ActivityApp.this);
alertDialogBuilder.setTitle(getString(R.string.menu_applications));
alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher));
alertDialogBuilder.setIcon(Util.getThemed(ActivityApp.this, R.attr.icon_launcher));
alertDialogBuilder.setMultiChoiceItems(mListApp.toArray(new CharSequence[0]), mSelection,
new DialogInterface.OnMultiChoiceClickListener() {
public void onClick(DialogInterface dialog, int whichButton, boolean isChecked) {
Expand Down Expand Up @@ -707,7 +706,7 @@ protected void onPostExecute(Object result) {
// Build dialog
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ActivityApp.this);
alertDialogBuilder.setTitle(getString(R.string.menu_contacts));
alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher));
alertDialogBuilder.setIcon(Util.getThemed(ActivityApp.this, R.attr.icon_launcher));
alertDialogBuilder.setMultiChoiceItems(mListContact.toArray(new CharSequence[0]), mSelection,
new DialogInterface.OnMultiChoiceClickListener() {
public void onClick(DialogInterface dialog, int whichButton, boolean isChecked) {
Expand Down Expand Up @@ -1040,8 +1039,8 @@ public View getGroupView(int groupPosition, boolean isExpanded, View convertView
final String restrictionName = (String) getGroup(groupPosition);

// Indicator state
holder.imgIndicator.setImageResource(getThemed(isExpanded ? R.attr.icon_expander_maximized
: R.attr.icon_expander_minimized));
holder.imgIndicator.setImageResource(Util.getThemed(ActivityApp.this,
isExpanded ? R.attr.icon_expander_maximized : R.attr.icon_expander_minimized));

// Disable indicator for empty groups
if (getChildrenCount(groupPosition) == 0)
Expand Down Expand Up @@ -1223,7 +1222,8 @@ public View getChildView(int groupPosition, int childPosition, boolean isLastChi

// Set background color
if (PrivacyManager.isDangerousMethod(restrictionName, md.getMethodName()))
holder.row.setBackgroundColor(getResources().getColor(getThemed(R.attr.color_dangerous)));
holder.row.setBackgroundColor(getResources().getColor(
Util.getThemed(ActivityApp.this, R.attr.color_dangerous)));
else
holder.row.setBackgroundColor(Color.TRANSPARENT);

Expand Down Expand Up @@ -1254,12 +1254,4 @@ public boolean hasStableIds() {
return true;
}
}

// Helper methods

private int getThemed(int attr) {
TypedValue typedvalueattr = new TypedValue();
getTheme().resolveAttribute(attr, typedvalueattr, true);
return typedvalueattr.resourceId;
}
}
31 changes: 14 additions & 17 deletions src/biz/bokhorst/xprivacy/ActivityMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
Expand Down Expand Up @@ -171,7 +170,8 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {
String text = etFilter.getText().toString();
ImageView imgClear = (ImageView) findViewById(R.id.imgClear);
imgClear.setImageDrawable(getResources().getDrawable(
getThemed(text.equals("") ? R.attr.icon_clear_grayed : R.attr.icon_clear)));
Util.getThemed(ActivityMain.this, text.equals("") ? R.attr.icon_clear_grayed
: R.attr.icon_clear)));
applyFilter();
}

Expand Down Expand Up @@ -564,7 +564,7 @@ private void optionAll() {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setTitle(getString(R.string.app_name));
alertDialogBuilder.setMessage(getString(R.string.msg_sure));
alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher));
alertDialogBuilder.setIcon(Util.getThemed(this, R.attr.icon_launcher));
alertDialogBuilder.setPositiveButton(getString(android.R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Expand Down Expand Up @@ -629,7 +629,7 @@ private void optionTemplate() {
// Build dialog
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setTitle(getString(R.string.menu_template));
alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher));
alertDialogBuilder.setIcon(Util.getThemed(this, R.attr.icon_launcher));
alertDialogBuilder.setMultiChoiceItems(options, selection, new DialogInterface.OnMultiChoiceClickListener() {
public void onClick(DialogInterface dialog, int whichButton, boolean isChecked) {
PrivacyManager.setSetting(null, ActivityMain.this, 0,
Expand Down Expand Up @@ -694,7 +694,7 @@ private void optionFetch() {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setTitle(getString(R.string.app_name));
alertDialogBuilder.setMessage(getString(R.string.msg_sure));
alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher));
alertDialogBuilder.setIcon(Util.getThemed(this, R.attr.icon_launcher));
alertDialogBuilder.setPositiveButton(getString(android.R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Expand Down Expand Up @@ -732,7 +732,7 @@ private void optionAbout() {
dlgAbout.requestWindowFeature(Window.FEATURE_LEFT_ICON);
dlgAbout.setTitle(getString(R.string.app_name));
dlgAbout.setContentView(R.layout.about);
dlgAbout.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, getThemed(R.attr.icon_launcher));
dlgAbout.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, Util.getThemed(this, R.attr.icon_launcher));

// Show version
try {
Expand Down Expand Up @@ -767,7 +767,7 @@ private void optionHelp() {
dialog.requestWindowFeature(Window.FEATURE_LEFT_ICON);
dialog.setTitle(getString(R.string.help_application));
dialog.setContentView(R.layout.help);
dialog.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, getThemed(R.attr.icon_launcher));
dialog.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, Util.getThemed(this, R.attr.icon_launcher));
TextView tvHelpHalf = (TextView) dialog.findViewById(R.id.help_half);
Drawable dHalf = new BitmapDrawable(getResources(), mCheck[1]);
dHalf.setBounds(0, 0, 48, 48);
Expand Down Expand Up @@ -826,7 +826,8 @@ private void toggleFiltersVisibility() {
}

mFiltersHidden = !mFiltersHidden;
vFilterHighlight.setBackgroundResource(mFiltersHidden ? android.R.color.transparent : getThemed(android.R.attr.colorActivatedHighlight));
vFilterHighlight.setBackgroundResource(mFiltersHidden ? android.R.color.transparent : Util.getThemed(this,
android.R.attr.colorActivatedHighlight));
}

private void toggleCategoriesVisibility() {
Expand All @@ -849,7 +850,8 @@ private void toggleCategoriesVisibility() {
}

mCategoriesHidden = !mCategoriesHidden;
vCategoryHighlight.setBackgroundResource(mCategoriesHidden ? android.R.color.transparent : getThemed(android.R.attr.colorActivatedHighlight));
vCategoryHighlight.setBackgroundResource(mCategoriesHidden ? android.R.color.transparent : Util.getThemed(this,
android.R.attr.colorActivatedHighlight));
}

// Tasks
Expand Down Expand Up @@ -1201,7 +1203,7 @@ public void onClick(final View view) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ActivityMain.this);
alertDialogBuilder.setTitle(getString(R.string.app_name));
alertDialogBuilder.setMessage(getString(R.string.msg_sure));
alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher));
alertDialogBuilder.setIcon(Util.getThemed(ActivityMain.this, R.attr.icon_launcher));
alertDialogBuilder.setPositiveButton(getString(android.R.string.ok),
new DialogInterface.OnClickListener() {
@Override
Expand Down Expand Up @@ -1267,7 +1269,8 @@ public View getView(int position, View convertView, ViewGroup parent) {

// Set background color
if (xAppInfo.isSystem())
holder.row.setBackgroundColor(getResources().getColor(getThemed(R.attr.color_dangerous)));
holder.row.setBackgroundColor(getResources().getColor(
Util.getThemed(ActivityMain.this, R.attr.color_dangerous)));
else
holder.row.setBackgroundColor(Color.TRANSPARENT);

Expand Down Expand Up @@ -1365,10 +1368,4 @@ private void checkLicense() {
}
}
}

private int getThemed(int attr) {
TypedValue typedvalueattr = new TypedValue();
getTheme().resolveAttribute(attr, typedvalueattr, true);
return typedvalueattr.resourceId;
}
}
1 change: 0 additions & 1 deletion src/biz/bokhorst/xprivacy/ActivityShare.java
Original file line number Diff line number Diff line change
Expand Up @@ -627,5 +627,4 @@ public static String getFileName(boolean multiple) {
fileName = "XPrivacy.xml";
return new File(folder + File.separator + fileName).getAbsolutePath();
}

}
17 changes: 5 additions & 12 deletions src/biz/bokhorst/xprivacy/Requirements.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import android.net.wifi.WifiInfo;
import android.os.Build;
import android.util.Log;
import android.util.TypedValue;

public class Requirements {

Expand All @@ -30,7 +29,7 @@ public static void check(final Context context) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
alertDialogBuilder.setTitle(context.getString(R.string.app_name));
alertDialogBuilder.setMessage(context.getString(R.string.app_wrongandroid));
alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher, context));
alertDialogBuilder.setIcon(Util.getThemed(context, R.attr.icon_launcher));
alertDialogBuilder.setPositiveButton(context.getString(android.R.string.ok),
new DialogInterface.OnClickListener() {
@Override
Expand All @@ -53,7 +52,7 @@ public void onClick(DialogInterface dialog, int which) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
alertDialogBuilder.setTitle(context.getString(R.string.app_name));
alertDialogBuilder.setMessage(msg);
alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher, context));
alertDialogBuilder.setIcon(Util.getThemed(context, R.attr.icon_launcher));
alertDialogBuilder.setPositiveButton(context.getString(android.R.string.ok),
new DialogInterface.OnClickListener() {
@Override
Expand All @@ -75,7 +74,7 @@ public void onClick(DialogInterface dialog, int which) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
alertDialogBuilder.setTitle(context.getString(R.string.app_name));
alertDialogBuilder.setMessage(msg);
alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher, context));
alertDialogBuilder.setIcon(Util.getThemed(context, R.attr.icon_launcher));
alertDialogBuilder.setPositiveButton(context.getString(android.R.string.ok),
new DialogInterface.OnClickListener() {
@Override
Expand All @@ -99,7 +98,7 @@ public void onClick(DialogInterface dialog, int which) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
alertDialogBuilder.setTitle(context.getString(R.string.app_name));
alertDialogBuilder.setMessage(msg);
alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher, context));
alertDialogBuilder.setIcon(Util.getThemed(context, R.attr.icon_launcher));
alertDialogBuilder.setPositiveButton(context.getString(android.R.string.ok),
new DialogInterface.OnClickListener() {
@Override
Expand Down Expand Up @@ -256,7 +255,7 @@ private static void reportClass(final Class<?> clazz, final Context context) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
alertDialogBuilder.setTitle(context.getString(R.string.app_name));
alertDialogBuilder.setMessage(msg);
alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher, context));
alertDialogBuilder.setIcon(Util.getThemed(context, R.attr.icon_launcher));
alertDialogBuilder.setPositiveButton(context.getString(android.R.string.ok),
new DialogInterface.OnClickListener() {
@Override
Expand Down Expand Up @@ -323,10 +322,4 @@ private static void sendSupportInfo(String text, Context context) {
Util.bug(null, ex);
}
}

private static int getThemed(int attr, Context context) {
TypedValue typedvalueattr = new TypedValue();
context.getTheme().resolveAttribute(attr, typedvalueattr, true);
return typedvalueattr.resourceId;
}
}
9 changes: 1 addition & 8 deletions src/biz/bokhorst/xprivacy/SettingsDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import android.location.Address;
import android.location.Geocoder;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;
import android.view.Window;
import android.widget.Button;
Expand All @@ -29,7 +28,7 @@ public static void edit(final Context context, ApplicationInfoEx appInfo) {
dlgSettings.requestWindowFeature(Window.FEATURE_LEFT_ICON);
dlgSettings.setTitle(context.getString(R.string.app_name));
dlgSettings.setContentView(R.layout.settings);
dlgSettings.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, getThemed(context, R.attr.icon_launcher));
dlgSettings.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, Util.getThemed(context, R.attr.icon_launcher));

// Reference controls
TextView tvAppName = (TextView) dlgSettings.findViewById(R.id.tvAppName);
Expand Down Expand Up @@ -576,10 +575,4 @@ public void onClick(View view) {
dlgSettings.setCancelable(true);
dlgSettings.show();
}

private static int getThemed(Context context, int attr) {
TypedValue typedvalueattr = new TypedValue();
context.getTheme().resolveAttribute(attr, typedvalueattr, true);
return typedvalueattr.resourceId;
}
}
Loading

0 comments on commit c41158f

Please sign in to comment.