Search in sources :

Example 1 with OnGroupExpandListener

use of android.widget.ExpandableListView.OnGroupExpandListener in project XPrivacy by M66B.

the class ActivityApp method onCreate.

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final int userId = Util.getUserId(Process.myUid());
    // Check privacy service client
    if (!PrivacyService.checkClient())
        return;
    // Set layout
    setContentView(R.layout.restrictionlist);
    setSupportActionBar((Toolbar) findViewById(R.id.widgetToolbar));
    // Annotate
    Meta.annotate(this.getResources());
    // Get arguments
    Bundle extras = getIntent().getExtras();
    if (extras == null) {
        finish();
        return;
    }
    int uid = extras.getInt(cUid);
    String restrictionName = (extras.containsKey(cRestrictionName) ? extras.getString(cRestrictionName) : null);
    String methodName = (extras.containsKey(cMethodName) ? extras.getString(cMethodName) : null);
    // Get app info
    mAppInfo = new ApplicationInfoEx(this, uid);
    if (mAppInfo.getPackageName().size() == 0) {
        finish();
        return;
    }
    // Set sub title
    getSupportActionBar().setSubtitle(TextUtils.join(", ", mAppInfo.getApplicationName()));
    // Handle info click
    ImageView imgInfo = (ImageView) findViewById(R.id.imgInfo);
    imgInfo.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            // Packages can be selected on the web site
            Util.viewUri(ActivityApp.this, Uri.parse(String.format(ActivityShare.getBaseURL() + "?package_name=%s", mAppInfo.getPackageName().get(0))));
        }
    });
    // Display app name
    TextView tvAppName = (TextView) findViewById(R.id.tvApp);
    tvAppName.setText(mAppInfo.toString());
    // Background color
    if (mAppInfo.isSystem()) {
        LinearLayout llInfo = (LinearLayout) findViewById(R.id.llInfo);
        llInfo.setBackgroundColor(getResources().getColor(getThemed(R.attr.color_dangerous)));
    }
    // Display app icon
    final ImageView imgIcon = (ImageView) findViewById(R.id.imgIcon);
    imgIcon.setImageDrawable(mAppInfo.getIcon(this));
    // Handle icon click
    imgIcon.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            openContextMenu(imgIcon);
        }
    });
    // Display on-demand state
    final ImageView imgCbOnDemand = (ImageView) findViewById(R.id.imgCbOnDemand);
    boolean isApp = PrivacyManager.isApplication(mAppInfo.getUid());
    boolean odSystem = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingOnDemandSystem, false);
    boolean gondemand = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingOnDemand, true);
    if ((isApp || odSystem) && gondemand) {
        boolean ondemand = PrivacyManager.getSettingBool(-mAppInfo.getUid(), PrivacyManager.cSettingOnDemand, false);
        imgCbOnDemand.setImageBitmap(ondemand ? getOnDemandCheckBox() : getOffCheckBox());
        imgCbOnDemand.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                boolean ondemand = !PrivacyManager.getSettingBool(-mAppInfo.getUid(), PrivacyManager.cSettingOnDemand, false);
                PrivacyManager.setSetting(mAppInfo.getUid(), PrivacyManager.cSettingOnDemand, Boolean.toString(ondemand));
                imgCbOnDemand.setImageBitmap(ondemand ? getOnDemandCheckBox() : getOffCheckBox());
                if (mPrivacyListAdapter != null)
                    mPrivacyListAdapter.notifyDataSetChanged();
            }
        });
    } else
        imgCbOnDemand.setVisibility(View.GONE);
    // Display restriction state
    swEnabled = (SwitchCompat) findViewById(R.id.swEnable);
    swEnabled.setChecked(PrivacyManager.getSettingBool(mAppInfo.getUid(), PrivacyManager.cSettingRestricted, true));
    swEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            PrivacyManager.setSetting(mAppInfo.getUid(), PrivacyManager.cSettingRestricted, Boolean.toString(isChecked));
            if (mPrivacyListAdapter != null)
                mPrivacyListAdapter.notifyDataSetChanged();
            imgCbOnDemand.setEnabled(isChecked);
        }
    });
    imgCbOnDemand.setEnabled(swEnabled.isChecked());
    // Add context menu to icon
    registerForContextMenu(imgIcon);
    // Check if internet access
    if (!mAppInfo.hasInternet(this)) {
        ImageView imgInternet = (ImageView) findViewById(R.id.imgInternet);
        imgInternet.setVisibility(View.INVISIBLE);
    }
    // Check if frozen
    if (!mAppInfo.isFrozen(this)) {
        ImageView imgFrozen = (ImageView) findViewById(R.id.imgFrozen);
        imgFrozen.setVisibility(View.INVISIBLE);
    }
    // Display version
    TextView tvVersion = (TextView) findViewById(R.id.tvVersion);
    tvVersion.setText(TextUtils.join(", ", mAppInfo.getPackageVersionName(this)));
    // Display package name
    TextView tvPackageName = (TextView) findViewById(R.id.tvPackageName);
    tvPackageName.setText(TextUtils.join(", ", mAppInfo.getPackageName()));
    // Fill privacy expandable list view adapter
    final ExpandableListView elvRestriction = (ExpandableListView) findViewById(R.id.elvRestriction);
    elvRestriction.setGroupIndicator(null);
    mPrivacyListAdapter = new RestrictionAdapter(this, R.layout.restrictionentry, mAppInfo, restrictionName, methodName);
    elvRestriction.setAdapter(mPrivacyListAdapter);
    // Listen for group expand
    elvRestriction.setOnGroupExpandListener(new OnGroupExpandListener() {

        @Override
        public void onGroupExpand(final int groupPosition) {
            if (!PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingMethodExpert, false)) {
                AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ActivityApp.this);
                alertDialogBuilder.setTitle(R.string.app_name);
                alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher));
                alertDialogBuilder.setMessage(R.string.msg_method_expert);
                alertDialogBuilder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        PrivacyManager.setSetting(userId, PrivacyManager.cSettingMethodExpert, Boolean.toString(true));
                        if (mPrivacyListAdapter != null)
                            mPrivacyListAdapter.notifyDataSetChanged();
                    }
                });
                alertDialogBuilder.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        elvRestriction.collapseGroup(groupPosition);
                    }
                });
                alertDialogBuilder.setCancelable(false);
                AlertDialog alertDialog = alertDialogBuilder.create();
                alertDialog.show();
            }
        }
    });
    // Go to method
    if (restrictionName != null) {
        int groupPosition = new ArrayList<String>(PrivacyManager.getRestrictions(this).values()).indexOf(restrictionName);
        elvRestriction.setSelectedGroup(groupPosition);
        elvRestriction.expandGroup(groupPosition);
        if (methodName != null) {
            Version version = new Version(Util.getSelfVersionName(this));
            int childPosition = PrivacyManager.getHooks(restrictionName, version).indexOf(new Hook(restrictionName, methodName));
            elvRestriction.setSelectedChild(groupPosition, childPosition, true);
        }
    }
    // Listen for package add/remove
    IntentFilter iff = new IntentFilter();
    iff.addAction(Intent.ACTION_PACKAGE_REMOVED);
    iff.addDataScheme("package");
    registerReceiver(mPackageChangeReceiver, iff);
    mPackageChangeReceiverRegistered = true;
    // Up navigation
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    // Tutorial
    if (!PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingTutorialDetails, false)) {
        ((ScrollView) findViewById(R.id.svTutorialHeader)).setVisibility(View.VISIBLE);
        ((ScrollView) findViewById(R.id.svTutorialDetails)).setVisibility(View.VISIBLE);
    }
    View.OnClickListener listener = new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            ViewParent parent = view.getParent();
            while (!parent.getClass().equals(ScrollView.class)) parent = parent.getParent();
            ((View) parent).setVisibility(View.GONE);
            PrivacyManager.setSetting(userId, PrivacyManager.cSettingTutorialDetails, Boolean.TRUE.toString());
        }
    };
    ((Button) findViewById(R.id.btnTutorialHeader)).setOnClickListener(listener);
    ((Button) findViewById(R.id.btnTutorialDetails)).setOnClickListener(listener);
    // Process actions
    if (extras.containsKey(cAction)) {
        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.cancel(mAppInfo.getUid());
        if (extras.getInt(cAction) == cActionClear)
            optionClear();
        else if (extras.getInt(cAction) == cActionSettings)
            optionSettings();
    }
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) TaskStackBuilder(android.support.v4.app.TaskStackBuilder) Button(android.widget.Button) CompoundButton(android.widget.CompoundButton) TextView(android.widget.TextView) ImageView(android.widget.ImageView) ExpandableListView(android.widget.ExpandableListView) IntentFilter(android.content.IntentFilter) NotificationManager(android.app.NotificationManager) Bundle(android.os.Bundle) ViewParent(android.view.ViewParent) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) ExpandableListView(android.widget.ExpandableListView) SuppressLint(android.annotation.SuppressLint) ScrollView(android.widget.ScrollView) OnGroupExpandListener(android.widget.ExpandableListView.OnGroupExpandListener) LinearLayout(android.widget.LinearLayout) CompoundButton(android.widget.CompoundButton)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 AlertDialog (android.app.AlertDialog)1 NotificationManager (android.app.NotificationManager)1 DialogInterface (android.content.DialogInterface)1 IntentFilter (android.content.IntentFilter)1 Bundle (android.os.Bundle)1 TaskStackBuilder (android.support.v4.app.TaskStackBuilder)1 View (android.view.View)1 ViewParent (android.view.ViewParent)1 Button (android.widget.Button)1 CompoundButton (android.widget.CompoundButton)1 ExpandableListView (android.widget.ExpandableListView)1 OnGroupExpandListener (android.widget.ExpandableListView.OnGroupExpandListener)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 ScrollView (android.widget.ScrollView)1 TextView (android.widget.TextView)1