Example usage for android.widget ExpandableListView expandGroup

List of usage examples for android.widget ExpandableListView expandGroup

Introduction

In this page you can find the example usage for android.widget ExpandableListView expandGroup.

Prototype

public boolean expandGroup(int groupPos) 

Source Link

Document

Expand a group in the grouped list view

Usage

From source file:com.androidquery.AbstractAQuery.java

public T expand(boolean expand) {

    if (view instanceof ExpandableListView) {

        ExpandableListView elv = (ExpandableListView) view;
        ExpandableListAdapter ela = elv.getExpandableListAdapter();

        if (ela != null) {

            int count = ela.getGroupCount();

            for (int i = 0; i < count; i++) {
                if (expand) {
                    elv.expandGroup(i);// ww  w  .j av a2  s . c om
                } else {
                    elv.collapseGroup(i);
                }
            }

        }

    }

    return self();
}

From source file:org.thoughtland.xlocation.ActivityApp.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final int userId = Util.getUserId(Process.myUid());

    // Check privacy service client
    if (!PrivacyService.checkClient())
        return;/*w w  w.  j  a va2 s  . co m*/

    // Set layout
    setContentView(R.layout.restrictionlist);

    // 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
    getActionBar().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 = (Switch) 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));
                            }
                        });
                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
    getActionBar().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();
    }
}

From source file:com.android.vending.billing.InAppBillingService.LACK.listAppsFragment.java

private void populateAdapter(ArrayList<PkgListItem> paramArrayList, Comparator<PkgListItem> paramComparator) {
      if ((paramArrayList == null) || (paramArrayList.size() == 0)) {
          lv.invalidate();//from   w w w  .  j a  v a2 s .  c  om
          if (menu_adapter == null) {
              menu_adapter = new MenuItemAdapter(getContext(), getConfig().getInt("viewsize", 0),
                      new ArrayList());
          }
          menu_lv.invalidate();
          menu_lv.setGroupIndicator(null);
          menu_lv.setAdapter(menu_adapter);
          menu_lv.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
              public boolean onGroupClick(ExpandableListView paramAnonymousExpandableListView,
                      View paramAnonymousView, int paramAnonymousInt, long paramAnonymousLong) {
                  paramAnonymousExpandableListView = listAppsFragment.menu_adapter.getGroup(paramAnonymousInt);
                  if ((paramAnonymousExpandableListView.childs.size() == 0)
                          || (paramAnonymousExpandableListView.type == 1)) {
                      switch (paramAnonymousExpandableListView.type) {
                      default:
                          listAppsFragment.this.runId(paramAnonymousExpandableListView.punkt_menu);
                      case 1:
                      case 2:
                          do {
                              return true;
                              switch (paramAnonymousExpandableListView.punkt_menu) {
                              default:
                                  return true;
                              case 2131165190:
                                  listAppsFragment.this.showAbout();
                                  return true;
                              case 2131165509:
                                  listAppsFragment.this.selectLanguage();
                                  return true;
                              case 2131165411:
                                  listAppsFragment.this.changeDefaultDir();
                                  return true;
                              case 2131165483:
                                  paramAnonymousExpandableListView = new Intent(listAppsFragment.patchAct,
                                          HelpActivity.class);
                                  listAppsFragment.this.startActivity(paramAnonymousExpandableListView);
                                  return true;
                              }
                          } while (listAppsFragment.frag == null);
                          listAppsFragment.this.runUpdate();
                          return true;
                          listAppsFragment.this.sendLog();
                          return true;
                          listAppsFragment.this.changeDayOnUp();
                          return true;
                      }
                      listAppsFragment.this.runToMain(paramAnonymousExpandableListView.runCode);
                      return true;
                  }
                  return false;
              }
          });
          menu_lv.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
              public boolean onChildClick(ExpandableListView paramAnonymousExpandableListView,
                      View paramAnonymousView, int paramAnonymousInt1, int paramAnonymousInt2,
                      long paramAnonymousLong) {
                  paramAnonymousInt1 = ((Integer) listAppsFragment.menu_adapter
                          .getGroup(paramAnonymousInt1).childs.get(paramAnonymousInt2)).intValue();
                  listAppsFragment.this.runId(paramAnonymousInt1);
                  return false;
              }
          });
          return;
      }
      Collections.sort(paramArrayList, paramComparator);
      if (getConfig().getBoolean("no_icon", false)) {
      }
      for (int i = 2130968628;; i = 2130968627) {
          plia = new PkgListItemAdapter(getContext(), i, getConfig().getInt("viewsize", 0), paramArrayList);
          adapter_boot = new BootListItemAdapter(getContext(), 2130968593, getConfig().getInt("viewsize", 0),
                  boot_pat);
          plia.sorter = paramComparator;
          removeDialogLP(3);
          lv.invalidate();
          lv.setAdapter(plia);
          lv.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
              public boolean onChildClick(ExpandableListView paramAnonymousExpandableListView,
                      View paramAnonymousView, int paramAnonymousInt1, int paramAnonymousInt2,
                      long paramAnonymousLong) {
                  if (listAppsFragment.getConfig().getBoolean("vibration", false)) {
                      listAppsFragment.this.vib = ((Vibrator) listAppsFragment.this.getContext()
                              .getSystemService("vibrator"));
                      listAppsFragment.this.vib.vibrate(50L);
                  }
                  listAppsFragment.pli = listAppsFragment.plia.getItem(paramAnonymousInt1);
                  switch (listAppsFragment.plia.getChild(paramAnonymousInt1, paramAnonymousInt2).intValue()) {
                  default:
                      return false;
                  case 2131165322:
                      listAppsFragment.this.launch_click();
                      return false;
                  case 2131165197:
                      listAppsFragment.this.contextmenu_click();
                      return false;
                  case 2131165288:
                      listAppsFragment.this.contextmenutools_click();
                      return false;
                  case 2131165731:
                      listAppsFragment.this.uninstall_click();
                      return false;
                  case 2131165253:
                      listAppsFragment.this.cleardata_click();
                      return false;
                  case 2131165556:
                      listAppsFragment.this.move_to_sdcard_click();
                      return false;
                  case 2131165554:
                      listAppsFragment.this.move_to_internal_memory_click();
                      return false;
                  case 2131165206:
                      listAppsFragment.this.show_app_manager_click();
                      return false;
                  }
                  listAppsFragment.plia.updateItem(listAppsFragment.pli.pkgName);
                  listAppsFragment.plia.notifyDataSetChanged(listAppsFragment.plia.getItem(paramAnonymousInt1));
                  listAppsFragment.removeDialogLP(6);
                  listAppsFragment.showDialogLP(6);
                  return false;
              }
          });
          lv.setDividerHeight(2);
          lv.setGroupIndicator(null);
          lv.setClickable(true);
          lv.setLongClickable(true);
          lv.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
              public void onGroupExpand(int paramAnonymousInt) {
              }
          });
          lv.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
              public boolean onGroupClick(ExpandableListView paramAnonymousExpandableListView,
                      View paramAnonymousView, final int paramAnonymousInt, long paramAnonymousLong) {
                  System.out.println(paramAnonymousExpandableListView.getItemAtPosition(paramAnonymousInt));
                  System.out.println(paramAnonymousInt);
                  listAppsFragment.pli = listAppsFragment.plia.getItem(paramAnonymousInt);
                  listAppsFragment.createExpandMenu();
                  if (paramAnonymousExpandableListView.isGroupExpanded(paramAnonymousInt)) {
                      paramAnonymousExpandableListView.collapseGroup(paramAnonymousInt);
                  }
                  for (;;) {
                      return true;
                      paramAnonymousExpandableListView.expandGroup(paramAnonymousInt);
                      if (listAppsFragment.api > 7) {
                          paramAnonymousExpandableListView.smoothScrollToPosition(paramAnonymousInt);
                      } else {
                          listAppsFragment.lv.clearFocus();
                          listAppsFragment.lv.post(new Runnable() {
                              public void run() {
                                  listAppsFragment.lv.setSelection(paramAnonymousInt);
                              }
                          });
                      }
                  }
              }
          });
          lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
              public boolean onItemLongClick(AdapterView<?> paramAnonymousAdapterView, View paramAnonymousView,
                      int paramAnonymousInt, long paramAnonymousLong) {
                  if (listAppsFragment.getConfig().getBoolean("vibration", false)) {
                      listAppsFragment.this.vib = ((Vibrator) listAppsFragment.this.getContext()
                              .getSystemService("vibrator"));
                      listAppsFragment.this.vib.vibrate(50L);
                  }
                  try {
                      listAppsFragment.pli = (PkgListItem) paramAnonymousAdapterView
                              .getItemAtPosition(paramAnonymousInt);
                      listAppsFragment.this.contextlevel0();
                      return false;
                  } catch (Exception paramAnonymousAdapterView) {
                      System.out.println("LuckyPatcher (Context menu long click): " + paramAnonymousAdapterView);
                      paramAnonymousAdapterView.printStackTrace();
                  }
                  return false;
              }
          });
          break;
      }
  }