public void onEvent(EventsModel eventsModel) {
   if (eventsModel != null && eventsModel.getEventType() == EventType.SETTINGS_CHANGE) {
     setupParams();
     setupFloatingImage(true);
     animateHidden();
     EventTrackerHelper.sendEvent(
         "onEvent", "onLoadCompleteListener", "EventType.SETTINGS_CHANGE");
   } else if (eventsModel != null && eventsModel.getEventType() == EventType.PREVIEW) {
     mParams.height = AppHelper.toPx(context, eventsModel.getPreviewSize());
     mParams.width = AppHelper.toPx(context, eventsModel.getPreviewSize());
     try {
       EventTrackerHelper.sendEvent("onEvent", "onLoadCompleteListener", "EventType.PREVIEW");
       if (windowManager != null) {
         windowManager.updateViewLayout(FloatingHorizontalLayout.this.view, mParams);
         new Handler()
             .postDelayed(
                 new Runnable() {
                   @Override
                   public void run() {
                     setupParams();
                     setupFloatingImage(true);
                   }
                 },
                 1500);
       }
     } catch (Exception e) {
       e.printStackTrace();
     }
   } else if (eventsModel != null && eventsModel.getEventType() == EventType.FA_BACKGROUND) {
     setupBackground();
   } else if (eventsModel != null && eventsModel.getEventType() == EventType.ICON_ALPHA) {
     animateHidden();
   }
 }
 private void setupBackground() {
   Drawable drawable = AppHelper.getColorDrawable(AppHelper.getFABackground(context));
   drawable.setAlpha(AppHelper.getBackgroundAlpha(context));
   if (view != null) {
     view.setBackground(drawable);
     showRecycler();
   }
 }
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
      LayoutInflater layoutInflater = LayoutInflater.from(getActivity());
      View rootView = layoutInflater.inflate(R.layout.dash_dialog_colors, null);

      mColorGrid = (GridView) rootView.findViewById(R.id.color_grid);

      mColorGrid.setNumColumns(mPreference.mNumColumns);

      mColorGrid.setOnItemClickListener(
          new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> listView, View view, int position, long itemId) {
              mPreference.setValue(mAdapter.getItem(position));
              selector.onColorSelected(mAdapter.getItem(position));
              dismiss();
            }
          });

      tryBindLists();

      if (AppHelper.isDarkTheme(getContext())) {
        return new AlertDialog.Builder(getActivity(), R.style.CustomDialogTheme)
            .setView(rootView)
            .create();
      } else {
        return new AlertDialog.Builder(getActivity()).setView(rootView).create();
      }
    }
 public List<AppsModel> getAppList(Context context) {
   if (!AppHelper.isAutoOrder(context)) {
     return new AppsModel().getAll();
   } else {
     return new AppsModel().getAllByUsage();
   }
 }
 private void setupFloatingImage(boolean update) {
   if (AppHelper.getImage(context) != null && new File(AppHelper.getImage(context)).exists()) {
     floatingImage.setImageBitmap(BitmapFactory.decodeFile(AppHelper.getImage(context)));
   } else {
     floatingImage.setImageResource(R.mipmap.ic_launcher);
   }
   if (adapter != null) adapter.notifyDataSetChanged();
   if (update) {
     if (windowManager != null)
       try {
         windowManager.updateViewLayout(FloatingHorizontalLayout.this.floatingImage, mParams);
         windowManager.updateViewLayout(FloatingHorizontalLayout.this.view, rParams);
       } catch (Exception e) {
         e.printStackTrace();
       }
   }
 }
 private void setupParams() {
   int iconSize = AppHelper.getFinalSize(context);
   int pX = AppHelper.getPositionX(context);
   int pY = AppHelper.getPositionY(context);
   rParams.width = MATCH_PARENT;
   rParams.height = iconSize;
   mParams.width = iconSize;
   mParams.height = iconSize;
   if (AppHelper.isSavePositionEnabled(context)) {
     mParams.x = pX;
     mParams.y = pY;
     rParams.y = pY + iconSize;
     rParams.x = pX;
   } else {
     mParams.x = 0;
     mParams.y = 100;
     rParams.x = 0;
     rParams.y = 100 + iconSize;
   }
 }
 private void showRecycler() {
   int iconSize = AppHelper.getFinalSize(context);
   if (paramsF != null) {
     rParams.x = paramsF.x;
     if (paramsF.y + iconSize / 2 > szWindow.y / 2) {
       rParams.y = paramsF.y - iconSize;
     } else if (paramsF.y + iconSize / 2 <= szWindow.y / 2) {
       rParams.y = paramsF.y + iconSize;
     }
     windowManager.updateViewLayout(view, rParams);
   }
   view.setVisibility(View.VISIBLE);
 }
  @Override
  public void onAppClick(AppsModel appsModel) {
    try {
      PackageManager manager = context.getPackageManager();
      Intent intent = manager.getLaunchIntentForPackage(appsModel.getPackageName());
      intent.addCategory(Intent.CATEGORY_LAUNCHER);
      context.startActivity(intent);
      appsModel.updateEntry(appsModel.getPackageName());
      EventTrackerHelper.sendEvent(
          "FloatingHorizontalLayout",
          "onAppClick",
          "onAppClick",
          appsModel.getAppName() == null ? appsModel.getPackageName() : appsModel.getAppName());

    } catch (Exception e) {
      e.printStackTrace();
      EventTrackerHelper.sendEvent(
          "FloatingHorizontalLayout", "onAppClick", "Crash!!!", e.getMessage());
    }
    if (!AppHelper.isAlwaysShowing(context)) {
      hideRecycler();
    }
  }
 @Override
 public boolean onTouch(View v, MotionEvent event) {
   paramsF = mParams;
   switch (event.getAction()) {
     case MotionEvent.ACTION_DOWN:
       initialX = paramsF.x;
       initialY = paramsF.y;
       initialTouchX = event.getRawX();
       initialTouchY = event.getRawY();
       animateShowing();
       break;
     case MotionEvent.ACTION_UP:
       if (AppHelper.isEdged(context)) {
         moveToEdge();
       } else {
         if (AppHelper.isSavePositionEnabled(context)) {
           AppHelper.savePosition(context, paramsF.y, paramsF.x);
         }
       }
       animateHidden();
       break;
     case MotionEvent.ACTION_MOVE:
       if (paramsF.y < 0) {
         paramsF.y = 0;
       }
       if (paramsF.y >= 0 || paramsF.y <= (szWindow.y - AppHelper.getFinalSize(context))) {
         paramsF.x = initialX + (int) (event.getRawX() - initialTouchX);
         paramsF.y = initialY + (int) (event.getRawY() - initialTouchY);
         try {
           windowManager.updateViewLayout(FloatingHorizontalLayout.this.floatingImage, paramsF);
           if (view.isShown()) {
             showRecycler();
           }
         } catch (Exception e) {
           e.printStackTrace();
         }
         animateShowing();
       } else if (paramsF.y > (szWindow.y - AppHelper.getFinalSize(context))) {
         paramsF.y = (szWindow.y - AppHelper.getFinalSize(context));
       }
       break;
   }
   return false;
 }
 private void animateHidden() {
   if (AppHelper.isAutoTransparent(context))
     floatingImage.setImageAlpha(AppHelper.getIconTransparency(context));
 }