/** Click listener for buttons in dialog */
 @Override
 public void onClick(View v) {
   switch (v.getId()) {
     case TV_MENU_APPLICATIONS_SETTINGS_MANAGE_APPS_FORCE_STOP:
       {
         try {
           appDetails.forceStop();
         } catch (Exception e) {
           e.printStackTrace();
         }
         refreshGUI();
         break;
       }
     case TV_MENU_APPLICATIONS_SETTINGS_MANAGE_APPS_UNINSTALL:
       {
         showAskDialog(TV_MENU_APPLICATIONS_SETTINGS_MANAGE_APPS_UNINSTALL);
         break;
       }
     case TV_MENU_APPLICATIONS_SETTINGS_MANAGE_APPS_STORAGE_CLEAR_DATA:
       {
         showAskDialog(TV_MENU_APPLICATIONS_SETTINGS_MANAGE_APPS_STORAGE_CLEAR_DATA);
         break;
       }
     case TV_MENU_APPLICATIONS_SETTINGS_MANAGE_APPS_CACHE_CLEAR:
       {
         showAskDialog(TV_MENU_APPLICATIONS_SETTINGS_MANAGE_APPS_CACHE_CLEAR);
         break;
       }
     case TV_MENU_APPLICATIONS_SETTINGS_MANAGE_APPS_DEFAULTS_CLEAR:
       {
         try {
           appDetails.clearDefaults();
         } catch (RemoteException e) {
           e.printStackTrace();
         } catch (RuntimeException e) {
           e.printStackTrace();
         }
         refreshGUI();
         break;
       }
     default:
       break;
   }
 }
 /** Set views data from app item */
 public void setViews() {
   if (appItem != null) {
     /** **** TITLE ****** */
     textViewTitle.setText(appItem.getAppname());
     /** **** STRORAGE ****** */
     try {
       appDetails =
           MainActivity.service
               .getSystemControl()
               .getApplicationControl()
               .getApplicationDeatails(appItem.getAppPackage());
     } catch (Exception e) {
       e.printStackTrace();
     }
     if (appDetails != null) {
       try {
         appDetails.getAppSizeInfo();
       } catch (Exception e) {
         e.printStackTrace();
       }
     }
   }
 }
 private void fillPermisions() {
   layoutForInflating.removeAllViews();
   List<AppPermission> permissions = null;
   try {
     permissions = appDetails.getAppPermissions();
   } catch (Exception e) {
     e.printStackTrace();
   }
   if (permissions != null) {
     // list permissions and create views for each
     for (int i = 0; i < permissions.size(); i++) {
       final LinearLayout smallLayoutHorizontal = new LinearLayout(ctx);
       smallLayoutHorizontal.setOrientation(LinearLayout.HORIZONTAL);
       smallLayoutHorizontal.setLayoutParams(
           new LinearLayout.LayoutParams(
               LayoutParams.MATCH_PARENT, MainActivity.dialogListElementHeight));
       smallLayoutHorizontal.setWeightSum(DialogCreatorClass.SMALL_LAYOUT_WEIGHT_SUM);
       smallLayoutHorizontal.setPadding(15, 4, 15, 4);
       /** ***** TEXT VIEW ****** */
       A4TVTextView textView = new A4TVTextView(ctx, null);
       textView.setLayoutParams(
           new LinearLayout.LayoutParams(
               0, LayoutParams.WRAP_CONTENT, DialogCreatorClass.ELEMENTS_WEIGHT_BIG));
       textView.setGravity(Gravity.CENTER_VERTICAL);
       // auto scroll text in text view
       textView.setEllipsize(TruncateAt.MARQUEE);
       textView.setSingleLine(true);
       textView.setTextSize(ctx.getResources().getDimension(R.dimen.a4tvdialog_textview_size));
       // set text to text view
       textView.setText(permissions.get(i).getPermissionGroup());
       // add text view to small layout
       smallLayoutHorizontal.addView(textView);
       /** ********* BUTTON *********** */
       A4TVButton button = new A4TVButton(ctx);
       button.setLayoutParams(
           new LinearLayout.LayoutParams(
               0, LayoutParams.MATCH_PARENT, DialogCreatorClass.ELEMENTS_WEIGHT_SMALL));
       // set text to button
       button.setText(permissions.get(i).getDescription());
       button.setTextSize(ctx.getResources().getDimension(R.dimen.a4tvdialog_button_text_size));
       button.setEllipsize(TruncateAt.MARQUEE);
       button.setSingleLine(true);
       button.setBackgroundColor(Color.TRANSPARENT);
       // add focus listener for button
       button.setOnFocusChangeListener(
           new OnFocusChangeListener() {
             @Override
             public void onFocusChange(View v, boolean hasFocus) {
               // get drawable from theme for small layout
               // background
               TypedArray atts =
                   ctx.getTheme().obtainStyledAttributes(new int[] {R.attr.LayoutFocusDrawable});
               int backgroundID = atts.getResourceId(0, 0);
               if (hasFocus) {
                 smallLayoutHorizontal.getChildAt(0).setSelected(true);
                 smallLayoutHorizontal.setBackgroundResource(backgroundID);
               } else {
                 smallLayoutHorizontal.getChildAt(0).setSelected(false);
                 smallLayoutHorizontal.setBackgroundColor(Color.TRANSPARENT);
               }
               atts.recycle();
             }
           });
       // add button to small layout
       smallLayoutHorizontal.addView(button);
       /** Add view to dialog */
       layoutForInflating.addView(smallLayoutHorizontal);
       if (i < permissions.size() - 1) {
         // create horizontal line
         ImageView horizLin = new ImageView(ctx);
         horizLin.setLayoutParams(
             new LinearLayout.LayoutParams(
                 android.widget.LinearLayout.LayoutParams.MATCH_PARENT,
                 android.widget.LinearLayout.LayoutParams.WRAP_CONTENT));
         // get drawable from theme for image source
         TypedArray att =
             ctx.getTheme().obtainStyledAttributes(new int[] {R.attr.DialogSmallDividerLine});
         int src = att.getResourceId(0, 0);
         horizLin.setBackgroundResource(src);
         att.recycle();
         // add horiz line to main layout
         layoutForInflating.addView(horizLin);
       }
     }
   }
 }
 private void setViewsFromCallBack() {
   Log.d(TAG, "ApplicationsAppControlDialog, SET VIEWS FROM CALLBACK");
   if (appSizeInfo != null) {
     try {
       appDetails =
           MainActivity.service
               .getSystemControl()
               .getApplicationControl()
               .getApplicationDeatails(appItem.getAppPackage());
     } catch (Exception e) {
       e.printStackTrace();
     }
     if (appDetails != null) {
       /** ****** DEFAULTS ************** */
       boolean isDef = true;
       try {
         isDef = appDetails.isDefault();
       } catch (Exception e) {
         e.printStackTrace();
       }
       Log.d(TAG, "APPLICATION IS DEFAULT" + isDef + "");
       btnClearDefaults.setEnabled(isDef);
       /** ***** FORCE STOP *** */
       boolean isStopped = true;
       try {
         isStopped = appDetails.isStopped();
       } catch (RemoteException e) {
         e.printStackTrace();
       } catch (RuntimeException e) {
         e.printStackTrace();
       }
       btnForceStop.setEnabled(!isStopped);
       /** ***** UNINSTALL ******* */
       boolean isSystemApp = true;
       try {
         isSystemApp = appDetails.isSystem();
       } catch (RemoteException e) {
         e.printStackTrace();
       } catch (RuntimeException e) {
         e.printStackTrace();
       }
       if (isSystemApp) {
         boolean isEnabled = false;
         try {
           isEnabled = appDetails.isEnabled();
         } catch (RemoteException e) {
           e.printStackTrace();
         } catch (RuntimeException e) {
           e.printStackTrace();
         }
         if (isEnabled) {
           btnUninstall.setText(
               R.string.tv_menu_applications_settings_manage_applications_disable);
         } else {
           btnUninstall.setText(R.string.tv_menu_applications_settings_manage_applications_enable);
         }
       } else {
         btnUninstall.setText(
             R.string.tv_menu_applications_settings_manage_applications_uninstall_btn);
       }
       /** ****** PERMMISIONS ******** */
       fillPermisions();
     }
     /** **** STRORAGE TOTAL ****** */
     btnStorageTotal.setText(appSizeInfo.getTotalSize());
     /** **** STRORAGE APP ****** */
     btnStorageApp.setText(appSizeInfo.getCodeSize());
     /** **** STRORAGE DATA ****** */
     btnStorageData.setText(appSizeInfo.getDataSize());
     Log.d(TAG, "DATA SIZE: " + appSizeInfo.getDataSize());
     /** **** STRORAGE SD CARD ****** */
     btnStorageExternal.setText(appSizeInfo.getExternalCacheSize());
     /** **** CACHE ****** */
     btnCache.setText(appSizeInfo.getCacheSize());
     /** ****** CLEAR CACHE ******** */
     btnClearCache.setEnabled(!appSizeInfo.isCacheEmpty());
     /** ****** CLEAR DATA ******** */
     btnClearData.setEnabled(!appSizeInfo.isDataEmpty());
   }
 }