Exemplo n.º 1
0
 private void onApplicationModePress(View v) {
   final QuickAction mQuickAction = new QuickAction(v);
   mQuickAction.setOnAnchorOnTop(true);
   List<ApplicationMode> vls =
       ApplicationMode.values(mapActivity.getMyApplication().getSettings());
   final ApplicationMode[] modes = vls.toArray(new ApplicationMode[vls.size()]);
   Drawable[] icons = new Drawable[vls.size()];
   int[] values = new int[vls.size()];
   for (int k = 0; k < modes.length; k++) {
     icons[k] = app.getIconsCache().getIcon(modes[k].getSmallIconDark(), R.color.icon_color);
     values[k] = modes[k].getStringResource();
   }
   for (int i = 0; i < modes.length; i++) {
     final ActionItem action = new ActionItem();
     action.setTitle(mapActivity.getResources().getString(values[i]));
     action.setIcon(icons[i]);
     final int j = i;
     action.setOnClickListener(
         new OnClickListener() {
           @Override
           public void onClick(View v) {
             mapActivity.getMyApplication().getSettings().APPLICATION_MODE.set(modes[j]);
             mQuickAction.dismiss();
           }
         });
     mQuickAction.addActionItem(action);
   }
   mQuickAction.setAnimStyle(QuickAction.ANIM_AUTO);
   mQuickAction.show();
 }
Exemplo n.º 2
0
  private QuickAction prepareDirAction(final SeafDirent dirent) {
    final QuickAction mQuickAction = new QuickAction(mActivity);
    Resources resources = mActivity.getResources();
    ActionItem shareAction;
    shareAction =
        new ActionItem(
            ACTION_ID_SHARE,
            resources.getString(R.string.file_action_share),
            resources.getDrawable(R.drawable.action_share));
    mQuickAction.addActionItem(shareAction);

    // setup the action item click listener
    mQuickAction.setOnActionItemClickListener(
        new QuickAction.OnActionItemClickListener() {
          @Override
          public void onItemClick(QuickAction quickAction, int pos, int actionId) {
            NavContext nav = mActivity.getNavContext();
            String repoName = nav.getRepoName();
            String repoID = nav.getRepoID();
            String dir = nav.getDirPath();
            String path = Utils.pathJoin(dir, dirent.name);
            switch (actionId) {
              case ACTION_ID_SHARE:
                mActivity.shareDir(repoID, path);
                break;
            }
          }
        });

    mQuickAction.mAnimateTrack(false);
    return mQuickAction;
  }
Exemplo n.º 3
0
 private void onApplicationModePress() {
   final QuickAction mQuickAction = new QuickAction(backToMenuButton);
   int[] icons =
       new int[] {
         R.drawable.default_mode_small,
         R.drawable.car_small,
         R.drawable.bicycle_small,
         R.drawable.pedestrian_small
       };
   int[] values =
       new int[] {
         R.string.app_mode_default,
         R.string.app_mode_car,
         R.string.app_mode_bicycle,
         R.string.app_mode_pedestrian
       };
   final ApplicationMode[] modes =
       new ApplicationMode[] {
         ApplicationMode.DEFAULT,
         ApplicationMode.CAR,
         ApplicationMode.BICYCLE,
         ApplicationMode.PEDESTRIAN
       };
   for (int i = 0; i < 4; i++) {
     final ActionItem action = new ActionItem();
     action.setTitle(view.getResources().getString(values[i]));
     action.setIcon(view.getResources().getDrawable(icons[i]));
     final int j = i;
     action.setOnClickListener(
         new OnClickListener() {
           @Override
           public void onClick(View v) {
             view.getSettings().APPLICATION_MODE.set(modes[j]);
             activity.updateApplicationModeSettings();
             view.refreshMap(true);
             mQuickAction.dismiss();
           }
         });
     mQuickAction.addActionItem(action);
   }
   mQuickAction.setAnimStyle(QuickAction.ANIM_AUTO);
   mQuickAction.show();
 }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    ActionItem nextItem =
        new ActionItem(ID_DOWN, "Next", getResources().getDrawable(R.drawable.menu_down_arrow));
    ActionItem prevItem =
        new ActionItem(ID_UP, "Prev", getResources().getDrawable(R.drawable.menu_up_arrow));
    ActionItem searchItem =
        new ActionItem(ID_SEARCH, "Find", getResources().getDrawable(R.drawable.menu_search));
    ActionItem infoItem =
        new ActionItem(ID_INFO, "Info", getResources().getDrawable(R.drawable.menu_info));
    ActionItem eraseItem =
        new ActionItem(ID_ERASE, "Clear", getResources().getDrawable(R.drawable.menu_eraser));
    ActionItem okItem = new ActionItem(ID_OK, "OK", getResources().getDrawable(R.drawable.menu_ok));

    // use setSticky(true) to disable QuickAction dialog being dismissed after an item is clicked
    prevItem.setSticky(true);
    nextItem.setSticky(true);

    // create QuickAction. Use QuickAction.VERTICAL or QuickAction.HORIZONTAL param to define layout
    // orientation
    final QuickAction quickAction = new QuickAction(this, QuickAction.VERTICAL);

    // add action items into QuickAction
    quickAction.addActionItem(nextItem);
    quickAction.addActionItem(prevItem);
    quickAction.addActionItem(searchItem);
    quickAction.addActionItem(infoItem);
    quickAction.addActionItem(eraseItem);
    quickAction.addActionItem(okItem);

    // Set listener for action item clicked
    quickAction.setOnActionItemClickListener(
        new QuickAction.OnActionItemClickListener() {
          // @Override
          public void onItemClick(QuickAction source, int pos, int actionId) {
            ActionItem actionItem = quickAction.getActionItem(pos);

            // here we can filter which action item was clicked with pos or actionId parameter
            if (actionId == ID_SEARCH) {
              Toast.makeText(
                      getApplicationContext(), "Let's do some search action", Toast.LENGTH_SHORT)
                  .show();
            } else if (actionId == ID_INFO) {
              Toast.makeText(
                      getApplicationContext(), "I have no info this time", Toast.LENGTH_SHORT)
                  .show();
            } else {
              Toast.makeText(
                      getApplicationContext(),
                      actionItem.getTitle() + " selected",
                      Toast.LENGTH_SHORT)
                  .show();
            }
          }
        });

    // set listnener for on dismiss event, this listener will be called only if QuickAction dialog
    // was dismissed
    // by clicking the area outside the dialog.
    quickAction.setOnDismissListener(
        new QuickAction.OnDismissListener() {
          // @Override
          public void onDismiss() {
            Toast.makeText(getApplicationContext(), "Dismissed", Toast.LENGTH_SHORT).show();
          }
        });

    // show on btn1
    Button btn1 = (Button) this.findViewById(R.id.btn1);
    btn1.setOnClickListener(
        new View.OnClickListener() {
          // @Override
          public void onClick(View v) {
            // quickAction.show(v);
          }
        });

    Button btn2 = (Button) this.findViewById(R.id.btn2);
    btn2.setOnClickListener(
        new OnClickListener() {
          // @Override
          public void onClick(View v) {
            // quickAction.show(v);
          }
        });

    Button btn3 = (Button) this.findViewById(R.id.btn3);
    btn3.setOnClickListener(
        new OnClickListener() {
          // @Override
          public void onClick(View v) {
            // quickAction.show(v);
            quickAction.setAnimStyle(QuickAction.ANIM_REFLECT);
          }
        });
  }
  private void initViews() {
    tvSelect = (TextView) findViewById(R.id.tv_select);
    // ivRecommend = (ImageView)findViewById(R.id.iv_recommend);

    Drawable recommend = getResources().getDrawable(R.drawable.recommend);
    /*Bitmap bitmap = ((BitmapDrawable)tmp).getBitmap();
    Drawable recommend = new BitmapDrawable(getResources(), Bitmap.createScaledBitmap(bitmap, 35, 35, true));*/

    ActionItem commentItem = new ActionItem(FLAG_RECOMMEND, "熱門推薦", recommend);
    ActionItem firstItem = new ActionItem(FLAG_HOT, "依播放次數");
    ActionItem secondItem = new ActionItem(FLAG_NEW, "依上架時間");
    ActionItem thisweekItem = new ActionItem(FLAG_2013, "2013年");
    ActionItem recentItem = new ActionItem(FLAG_2012, "2012年");
    ActionItem topItem = new ActionItem(FLAG_BEFORE, "2011年以前");

    quickAction = new QuickAction(this, QuickAction.VERTICAL);

    // add action items into QuickAction
    quickAction.addActionItem(commentItem);
    quickAction.addActionItem(firstItem);
    quickAction.addActionItem(secondItem);
    quickAction.addActionItem(thisweekItem);
    quickAction.addActionItem(recentItem);
    quickAction.addActionItem(topItem);

    // Set listener for action item clicked
    quickAction.setOnActionItemClickListener(
        new QuickAction.OnActionItemClickListener() {
          public void onItemClick(QuickAction source, int pos, int actionId) {
            quickAction.getActionItem(pos);
            setActionText(actionId);
            sortDataTask = new SortDataTask();
            if (Build.VERSION.SDK_INT < 11) sortDataTask.execute();
            else sortDataTask.executeOnExecutor(LoadDataTask.THREAD_POOL_EXECUTOR, 0);
          }
        });

    // set listnener for on dismiss event, this listener will be called only if QuickAction dialog
    // was dismissed
    // by clicking the area outside the dialog.
    quickAction.setOnDismissListener(
        new QuickAction.OnDismissListener() {
          public void onDismiss() {
            // Toast.makeText(getApplicationContext(), "Dismissed", Toast.LENGTH_SHORT).show();
          }
        });

    llSelect = (LinearLayout) findViewById(R.id.ll_select);
    llSelect.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            quickAction.show(v);
          }
        });

    topbar_text = (TextView) findViewById(R.id.topbar_text);
    topbar_text.setText(getResources().getString(R.string.app_name));

    DisplayMetrics dm = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(dm);
    cursorWidth = dm.widthPixels / listnumber - cursorOffset * 2;

    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(cursorWidth, 15);
    lp.setMargins(cursorOffset, 0, cursorOffset, 0);
    cursor = (ImageView) findViewById(R.id.arrow_1);
    cursor.setLayoutParams(lp);

    buttonTaiwan = (Button) findViewById(R.id.button_drama_taiwan);
    buttonKoera = (Button) findViewById(R.id.button_drama_koera);
    buttonJapan = (Button) findViewById(R.id.button_drama_japan);
    buttonChina = (Button) findViewById(R.id.button_drama_china);

    viewpager = (ViewPager) findViewById(R.id.viewpager_tvchannel);
    viewpager.setOffscreenPageLimit(listnumber);

    imageButtonRefresh = (ImageButton) findViewById(R.id.refresh);
    imageButtonRefresh.setOnClickListener(
        new OnClickListener() {
          public void onClick(View arg0) {
            updatetask = new updateDataTask();
            if (Build.VERSION.SDK_INT < 11) updatetask.execute();
            else updatetask.executeOnExecutor(updateDataTask.THREAD_POOL_EXECUTOR, 0);
          }
        });
  }
Exemplo n.º 6
0
 public void addItem(String s, int i, int j, int k)
 {
     mQuickActions.addActionItem(new ActionItem(j, s));
 }
Exemplo n.º 7
0
  private QuickAction prepareFileAction(final SeafDirent dirent, boolean cacheExists) {
    final QuickAction mQuickAction = new QuickAction(mActivity);
    Resources resources = mActivity.getResources();
    ActionItem shareAction, downloadAction, updateAction, exportAction, renameAction, deleteAction;

    shareAction =
        new ActionItem(
            ACTION_ID_SHARE,
            resources.getString(R.string.file_action_share),
            resources.getDrawable(R.drawable.action_share));
    mQuickAction.addActionItem(shareAction);

    // deleteAction = new ActionItem(ACTION_ID_DELETE,
    //                               resources.getString(R.string.file_action_delete),
    //                               resources.getDrawable(R.drawable.action_delete));
    // mQuickAction.addActionItem(deleteAction);

    renameAction =
        new ActionItem(
            ACTION_ID_RENAME,
            resources.getString(R.string.file_action_rename),
            resources.getDrawable(R.drawable.action_rename));
    mQuickAction.addActionItem(renameAction);

    exportAction =
        new ActionItem(
            ACTION_ID_EXPORT,
            resources.getString(R.string.file_action_export),
            resources.getDrawable(R.drawable.action_export));
    mQuickAction.addActionItem(exportAction);

    if (cacheExists) {
      if (mActivity.hasRepoWritePermission()) {
        updateAction =
            new ActionItem(
                ACTION_ID_UPDATE,
                resources.getString(R.string.file_action_update),
                resources.getDrawable(R.drawable.action_update));
        mQuickAction.addActionItem(updateAction);
      }

    } else {
      downloadAction =
          new ActionItem(
              ACTION_ID_DOWNLOAD,
              resources.getString(R.string.file_action_download),
              resources.getDrawable(R.drawable.action_download));
      mQuickAction.addActionItem(downloadAction);
    }

    // setup the action item click listener
    mQuickAction.setOnActionItemClickListener(
        new QuickAction.OnActionItemClickListener() {
          @Override
          public void onItemClick(QuickAction quickAction, int pos, int actionId) {
            NavContext nav = mActivity.getNavContext();
            String repoName = nav.getRepoName();
            String repoID = nav.getRepoID();
            String dir = nav.getDirPath();
            String path = Utils.pathJoin(dir, dirent.name);
            DataManager dataManager = mActivity.getDataManager();
            String localPath = dataManager.getLocalRepoFile(repoName, repoID, path).getPath();
            switch (actionId) {
              case ACTION_ID_SHARE:
                mActivity.shareFile(repoID, path);
                break;
              case ACTION_ID_EXPORT:
                mActivity.exportFile(dirent.name);
                break;
              case ACTION_ID_DOWNLOAD:
                mActivity.onFileSelected(dirent);
                break;
              case ACTION_ID_UPDATE:
                mActivity.addUpdateTask(repoID, repoName, dir, localPath);
                break;
              case ACTION_ID_RENAME:
                mActivity.renameFile(repoID, repoName, path);
                break;
            }
          }
        });

    mQuickAction.mAnimateTrack(false);
    return mQuickAction;
  }
  /**
   * Shows the context menu using the given region as an anchor point.
   *
   * @param displayRect
   */
  protected void showContextMenu(Rect displayRect) {

    // Don't show this twice
    if (mContextMenuVisible) {
      return;
    }

    // Don't use empty rect
    // if(displayRect.isEmpty()){
    if (displayRect.right <= displayRect.left) {
      return;
    }

    // Copy action item
    ActionItem buttonOne = new ActionItem();

    buttonOne.setTitle("Button 1");
    buttonOne.setActionId(1);
    buttonOne.setIcon(getResources().getDrawable(R.drawable.menu_search));

    // Highlight action item
    ActionItem buttonTwo = new ActionItem();

    buttonTwo.setTitle("Button 2");
    buttonTwo.setActionId(2);
    buttonTwo.setIcon(getResources().getDrawable(R.drawable.menu_info));

    ActionItem buttonThree = new ActionItem();

    buttonThree.setTitle("Button 3");
    buttonThree.setActionId(3);
    buttonThree.setIcon(getResources().getDrawable(R.drawable.menu_eraser));

    // The action menu
    mContextMenu = new QuickAction(getContext());
    mContextMenu.setOnDismissListener(this);

    // Add buttons
    mContextMenu.addActionItem(buttonOne);

    mContextMenu.addActionItem(buttonTwo);

    mContextMenu.addActionItem(buttonThree);

    // setup the action item click listener
    mContextMenu.setOnActionItemClickListener(
        new QuickAction.OnActionItemClickListener() {

          @Override
          public void onItemClick(QuickAction source, int pos, int actionId) {
            // TODO Auto-generated method stub
            if (actionId == 1) {
              // Do Button 1 stuff
              Log.i(TAG, "Hit Button 1");
            } else if (actionId == 2) {
              // Do Button 2 stuff
              Log.i(TAG, "Hit Button 2");
            } else if (actionId == 3) {
              // Do Button 3 stuff
              Log.i(TAG, "Hit Button 3");
            }

            mContextMenuVisible = false;
          }
        });

    mContextMenuVisible = true;
    mContextMenu.show(this, displayRect);
  }