public void updateTabs(boolean areTabsShown) {
   if (areTabsShown) {
     mTabs.setImageLevel(TABS_EXPANDED);
     mTabs.getBackground().setLevel(TABS_EXPANDED);
   } else {
     mTabs.setImageLevel(TABS_CONTRACTED);
     mTabs.getBackground().setLevel(TABS_CONTRACTED);
   }
 }
示例#2
0
  private View createButton(Map<Object, Object> hash) {
    Context ctx = RhodesActivity.getContext();

    Object actionObj = hash.get("action");
    if (actionObj == null || !(actionObj instanceof String))
      throw new IllegalArgumentException("'action' should be String");

    String action = (String) actionObj;
    if (action.length() == 0) throw new IllegalArgumentException("'action' should not be empty");

    Drawable icon = null;
    String label = null;
    View.OnClickListener onClick = null;

    if (action.equalsIgnoreCase("back")) {
      icon = ctx.getResources().getDrawable(AndroidR.drawable.back);
      onClick = new ActionBack();
    } else if (action.equalsIgnoreCase("forward")) {
      if (RhodesService.isJQTouch_mode()) {
        return null;
      }
      icon = ctx.getResources().getDrawable(AndroidR.drawable.next);
      onClick = new ActionForward();
    } else if (action.equalsIgnoreCase("home")) {
      icon = ctx.getResources().getDrawable(AndroidR.drawable.home);
      onClick = new ActionHome();
    } else if (action.equalsIgnoreCase("options")) {
      icon = ctx.getResources().getDrawable(AndroidR.drawable.options);
      onClick = new ActionOptions();
    } else if (action.equalsIgnoreCase("refresh")) {
      icon = ctx.getResources().getDrawable(AndroidR.drawable.refresh);
      onClick = new ActionRefresh();
    } else if (action.equalsIgnoreCase("close") || action.equalsIgnoreCase("exit")) {
      icon = ctx.getResources().getDrawable(AndroidR.drawable.exit);
      onClick = new ActionExit();
    } else if (action.equalsIgnoreCase("separator")) return null;

    DisplayMetrics metrics = new DisplayMetrics();
    WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
    wm.getDefaultDisplay().getMetrics(metrics);

    Object iconObj = hash.get("icon");
    if (iconObj != null) {
      if (!(iconObj instanceof String))
        throw new IllegalArgumentException("'icon' should be String");
      String iconPath = "apps/" + (String) iconObj;
      iconPath = RhoFileApi.normalizePath(iconPath);
      Bitmap bitmap = BitmapFactory.decodeStream(RhoFileApi.open(iconPath));
      if (bitmap == null) throw new IllegalArgumentException("Can't find icon: " + iconPath);
      bitmap.setDensity(DisplayMetrics.DENSITY_MEDIUM);
      icon = new BitmapDrawable(bitmap);
    }

    if (icon == null) {
      Object labelObj = hash.get("label");
      if (labelObj == null || !(labelObj instanceof String))
        throw new IllegalArgumentException("'label' should be String");
      label = (String) labelObj;
    }

    if (icon == null && label == null)
      throw new IllegalArgumentException("One of 'icon' or 'label' should be specified");

    if (onClick == null) onClick = new ActionCustom(action);

    View button;
    if (icon != null) {
      ImageButton btn = new ImageButton(ctx);
      btn.setImageDrawable(icon);
      button = btn;
      if (mCustomBackgroundColorEnable) {
        Drawable d = btn.getBackground();
        if (d != null) {
          d.setColorFilter(mCustomBackgroundColor, android.graphics.PorterDuff.Mode.SRC_OVER);
        } else {
          btn.setBackgroundColor(mCustomBackgroundColor);
        }
      }
    } else {
      Button btn = new Button(ctx);
      btn.setText(label);
      if (mCustomBackgroundColorEnable) {
        btn.setBackgroundColor(mCustomBackgroundColor);
        int gray =
            (((mCustomBackgroundColor & 0xFF0000) >> 16)
                    + ((mCustomBackgroundColor & 0xFF00) >> 8)
                    + ((mCustomBackgroundColor & 0xFF)))
                / 3;
        if (gray > 128) {
          btn.setTextColor(0xFF000000);
        } else {
          btn.setTextColor(0xFFFFFFFF);
        }
      }
      button = btn;
    }

    button.setOnClickListener(onClick);

    return button;
  }
示例#3
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_main, container, false);
    mListView = (ListView) rootView.findViewById(android.R.id.list);
    if ((mAdapter = getAdapter(mCategoryId)) == null) {
      mAdapter =
          new MainListAdapter(
              getActivity(),
              AccountManager.getInstance().getAccountsByCategory(mCategoryId),
              Application.getThemedIcons(),
              R.drawable.pb_unknown);
      mListView.postDelayed(
          new Runnable() {
            @Override
            public void run() {
              mAdapter.enableAnimation(false);
            }
          },
          100);
      cacheAdapter(mCategoryId, mAdapter);
    }
    mAdapter.setListener(this);
    mListView.setAdapter(mAdapter);
    mListView.setEmptyView(rootView.findViewById(android.R.id.empty));
    mListView.setOnItemClickListener(this);
    mListView.setOnItemLongClickListener(this);
    mToBeRemoved = new int[mAdapter.getCount()];
    mFab = (ImageButton) rootView.findViewById(R.id.fab);
    mFab.setOnClickListener(this);
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
      LayerDrawable background = (LayerDrawable) mFab.getBackground();
      background
          .getDrawable(1)
          .setColorFilter(C.ThemedColors[C.colorAccent], PorterDuff.Mode.SRC_ATOP);
    }
    if (!getResources().getBoolean(R.bool.snackbar_left_align)) {
      mFabToPush = (int) (getResources().getDimension(R.dimen.snackbar_height_single) + 0.5f);
    } else {
      mFabToPush = 0;
    }
    mCategoryEditView = rootView.findViewById(R.id.category_editor);
    EditText editCategoryName = (EditText) rootView.findViewById(R.id.category_name);
    editCategoryName.addTextChangedListener(
        new TextWatcher() {
          @Override
          public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

          @Override
          public void onTextChanged(CharSequence s, int start, int before, int count) {}

          @Override
          public void afterTextChanged(Editable s) {
            if (mActionMode != null) {
              mCategoryName = s.toString();
              mCategorySavable = mCategoryName.length() > 0;
              mActionMode.invalidate();
            }
          }
        });
    if (mIsEditing) {
      mIsEditing = false;
      editCategory();
    } else if (mSelectionMode) {
      mActionMode = ((MainActivity) getActivity()).startSupportActionMode(mActionModeCallback);
    }
    return rootView;
  }