@Override
 protected void onScrollChanged(int l, int t, int oldl, int oldt) {
   LayoutParams lp = (LayoutParams) progressbar.getLayoutParams();
   lp.x = l;
   lp.y = t;
   progressbar.setLayoutParams(lp);
   super.onScrollChanged(l, t, oldl, oldt);
 }
Beispiel #2
0
  @Override
  public void onRequestStart(MegaApiJava api, MegaRequest request) {
    log("onRequestStart: " + request.getRequestString());

    if (request.getType() == MegaRequest.TYPE_LOGIN) {
      title.setText(getResources().getString(R.string.logging_in));
    } else if (request.getType() == MegaRequest.TYPE_FETCH_NODES) {
      title.setText(getResources().getString(R.string.fetching_nodes));
      fetchingNodesBar.setVisibility(View.VISIBLE);
      fetchingNodesBar.getLayoutParams().width = 350;
      fetchingNodesBar.setProgress(0);
    }
  }
Beispiel #3
0
  @Override
  public void onRequestUpdate(MegaApiJava api, MegaRequest request) {
    log("onRequestUpdate: " + request.getRequestString());

    if (request.getType() == MegaRequest.TYPE_FETCH_NODES) {
      fetchingNodesBar.setVisibility(View.VISIBLE);
      fetchingNodesBar.getLayoutParams().width = 350;
      if (request.getTotalBytes() > 0) {
        double progressValue = 100.0 * request.getTransferredBytes() / request.getTotalBytes();
        if ((progressValue > 99) || (progressValue < 0)) {
          progressValue = 100;
          title.setText(getResources().getString(R.string.preparing_nodes));
        }
        log("progressValue = " + (int) progressValue);
        fetchingNodesBar.setProgress((int) progressValue);
      }
    }
  }
  @SuppressWarnings("unchecked")
  @Override
  public View createView(Context context) {
    actionBar.setBackgroundColor(0xff333333);
    actionBar.setItemsBackground(R.drawable.bar_selector_picker);
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    if (selectedAlbum != null) {
      actionBar.setTitle(selectedAlbum.bucketName);
    } else if (type == 0) {
      actionBar.setTitle(
          LocaleController.getString("SearchImagesTitle", R.string.SearchImagesTitle));
    } else if (type == 1) {
      actionBar.setTitle(LocaleController.getString("SearchGifsTitle", R.string.SearchGifsTitle));
    }
    actionBar.setActionBarMenuOnItemClick(
        new ActionBar.ActionBarMenuOnItemClick() {
          @Override
          public void onItemClick(int id) {
            if (id == -1) {
              if (Build.VERSION.SDK_INT < 11) {
                listView.setAdapter(null);
                listView = null;
                listAdapter = null;
              }
              finishFragment();
            }
          }
        });

    if (selectedAlbum == null) {
      ActionBarMenu menu = actionBar.createMenu();
      searchItem =
          menu.addItem(0, R.drawable.ic_ab_search)
              .setIsSearchField(true)
              .setActionBarMenuItemSearchListener(
                  new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
                    @Override
                    public void onSearchExpand() {}

                    @Override
                    public boolean canCollapseSearch() {
                      finishFragment();
                      return false;
                    }

                    @Override
                    public void onTextChanged(EditText editText) {
                      if (editText.getText().length() == 0) {
                        searchResult.clear();
                        searchResultKeys.clear();
                        lastSearchString = null;
                        nextSearchBingString = null;
                        giphySearchEndReached = true;
                        searching = false;
                        requestQueue.cancelAll("search");
                        if (type == 0) {
                          emptyView.setText(
                              LocaleController.getString(
                                  "NoRecentPhotos", R.string.NoRecentPhotos));
                        } else if (type == 1) {
                          emptyView.setText(
                              LocaleController.getString("NoRecentGIFs", R.string.NoRecentGIFs));
                        }
                        updateSearchInterface();
                      }
                    }

                    @Override
                    public void onSearchPressed(EditText editText) {
                      if (editText.getText().toString().length() == 0) {
                        return;
                      }
                      searchResult.clear();
                      searchResultKeys.clear();
                      nextSearchBingString = null;
                      giphySearchEndReached = true;
                      if (type == 0) {
                        searchBingImages(editText.getText().toString(), 0, 53);
                      } else if (type == 1) {
                        searchGiphyImages(editText.getText().toString(), 0, 53);
                      }
                      lastSearchString = editText.getText().toString();
                      if (lastSearchString.length() == 0) {
                        lastSearchString = null;
                        if (type == 0) {
                          emptyView.setText(
                              LocaleController.getString(
                                  "NoRecentPhotos", R.string.NoRecentPhotos));
                        } else if (type == 1) {
                          emptyView.setText(
                              LocaleController.getString("NoRecentGIFs", R.string.NoRecentGIFs));
                        }
                      } else {
                        emptyView.setText(
                            LocaleController.getString("NoResult", R.string.NoResult));
                      }
                      updateSearchInterface();
                    }
                  });
    }

    if (selectedAlbum == null) {
      if (type == 0) {
        searchItem
            .getSearchField()
            .setHint(LocaleController.getString("SearchImagesTitle", R.string.SearchImagesTitle));
      } else if (type == 1) {
        searchItem
            .getSearchField()
            .setHint(LocaleController.getString("SearchGifsTitle", R.string.SearchGifsTitle));
      }
    }

    fragmentView = new FrameLayout(context);

    FrameLayout frameLayout = (FrameLayout) fragmentView;
    frameLayout.setBackgroundColor(0xff000000);

    listView = new GridView(context);
    listView.setPadding(
        AndroidUtilities.dp(4),
        AndroidUtilities.dp(4),
        AndroidUtilities.dp(4),
        AndroidUtilities.dp(4));
    listView.setClipToPadding(false);
    listView.setDrawSelectorOnTop(true);
    listView.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
    listView.setHorizontalScrollBarEnabled(false);
    listView.setVerticalScrollBarEnabled(false);
    listView.setNumColumns(GridView.AUTO_FIT);
    listView.setVerticalSpacing(AndroidUtilities.dp(4));
    listView.setHorizontalSpacing(AndroidUtilities.dp(4));
    listView.setSelector(R.drawable.list_selector);
    frameLayout.addView(listView);
    FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    layoutParams.bottomMargin = singlePhoto ? 0 : AndroidUtilities.dp(48);
    listView.setLayoutParams(layoutParams);
    listView.setAdapter(listAdapter = new ListAdapter(context));
    AndroidUtilities.setListViewEdgeEffectColor(listView, 0xff333333);
    listView.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            if (selectedAlbum != null && selectedAlbum.isVideo) {
              if (i < 0 || i >= selectedAlbum.photos.size()) {
                return;
              }
              if (delegate.didSelectVideo(selectedAlbum.photos.get(i).path)) {
                finishFragment();
              }
            } else {
              ArrayList<Object> arrayList;
              if (selectedAlbum != null) {
                arrayList = (ArrayList) selectedAlbum.photos;
              } else {
                if (searchResult.isEmpty() && lastSearchString == null) {
                  arrayList = (ArrayList) recentImages;
                } else {
                  arrayList = (ArrayList) searchResult;
                }
              }
              if (i < 0 || i >= arrayList.size()) {
                return;
              }
              PhotoViewer.getInstance().setParentActivity(getParentActivity());
              PhotoViewer.getInstance()
                  .openPhotoForSelect(
                      arrayList, i, singlePhoto ? 1 : 0, PhotoPickerActivity.this, chatActivity);
            }
          }
        });

    if (selectedAlbum == null) {
      listView.setOnItemLongClickListener(
          new AdapterView.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(
                AdapterView<?> parent, View view, int position, long id) {
              if (searchResult.isEmpty() && lastSearchString == null) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                builder.setMessage(LocaleController.getString("ClearSearch", R.string.ClearSearch));
                builder.setPositiveButton(
                    LocaleController.getString("ClearButton", R.string.ClearButton).toUpperCase(),
                    new DialogInterface.OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialogInterface, int i) {
                        recentImages.clear();
                        if (listAdapter != null) {
                          listAdapter.notifyDataSetChanged();
                        }
                        MessagesStorage.getInstance().clearWebRecent(type);
                      }
                    });
                builder.setNegativeButton(
                    LocaleController.getString("Cancel", R.string.Cancel), null);
                showDialog(builder.create());
                return true;
              }
              return false;
            }
          });
    }

    emptyView = new TextView(context);
    emptyView.setTextColor(0xff808080);
    emptyView.setTextSize(20);
    emptyView.setGravity(Gravity.CENTER);
    emptyView.setVisibility(View.GONE);
    if (selectedAlbum != null) {
      emptyView.setText(LocaleController.getString("NoPhotos", R.string.NoPhotos));
    } else {
      if (type == 0) {
        emptyView.setText(LocaleController.getString("NoRecentPhotos", R.string.NoRecentPhotos));
      } else if (type == 1) {
        emptyView.setText(LocaleController.getString("NoRecentGIFs", R.string.NoRecentGIFs));
      }
    }
    frameLayout.addView(emptyView);
    layoutParams = (FrameLayout.LayoutParams) emptyView.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    layoutParams.bottomMargin = singlePhoto ? 0 : AndroidUtilities.dp(48);
    emptyView.setLayoutParams(layoutParams);
    emptyView.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            return true;
          }
        });

    if (selectedAlbum == null) {
      listView.setOnScrollListener(
          new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView absListView, int i) {
              if (i == SCROLL_STATE_TOUCH_SCROLL) {
                AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
              }
            }

            @Override
            public void onScroll(
                AbsListView absListView,
                int firstVisibleItem,
                int visibleItemCount,
                int totalItemCount) {
              if (visibleItemCount != 0
                  && firstVisibleItem + visibleItemCount > totalItemCount - 2
                  && !searching) {
                if (type == 0 && nextSearchBingString != null) {
                  searchBingImages(lastSearchString, searchResult.size(), 54);
                } else if (type == 1 && !giphySearchEndReached) {
                  searchGiphyImages(
                      searchItem.getSearchField().getText().toString(), searchResult.size(), 54);
                }
              }
            }
          });

      progressView = new FrameLayout(context);
      progressView.setVisibility(View.GONE);
      frameLayout.addView(progressView);
      layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams();
      layoutParams.width = LayoutHelper.MATCH_PARENT;
      layoutParams.height = LayoutHelper.MATCH_PARENT;
      layoutParams.bottomMargin = singlePhoto ? 0 : AndroidUtilities.dp(48);
      progressView.setLayoutParams(layoutParams);

      ProgressBar progressBar = new ProgressBar(context);
      progressView.addView(progressBar);
      layoutParams = (FrameLayout.LayoutParams) progressBar.getLayoutParams();
      layoutParams.width = LayoutHelper.WRAP_CONTENT;
      layoutParams.height = LayoutHelper.WRAP_CONTENT;
      layoutParams.gravity = Gravity.CENTER;
      progressBar.setLayoutParams(layoutParams);

      updateSearchInterface();
    }

    pickerBottomLayout = new PickerBottomLayout(context);
    frameLayout.addView(pickerBottomLayout);
    layoutParams = (FrameLayout.LayoutParams) pickerBottomLayout.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = AndroidUtilities.dp(48);
    layoutParams.gravity = Gravity.BOTTOM;
    pickerBottomLayout.setLayoutParams(layoutParams);
    pickerBottomLayout.cancelButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            delegate.actionButtonPressed(true);
            finishFragment();
          }
        });
    pickerBottomLayout.doneButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            sendSelectedPhotos();
          }
        });
    if (singlePhoto) {
      pickerBottomLayout.setVisibility(View.GONE);
    }

    listView.setEmptyView(emptyView);
    pickerBottomLayout.updateSelectedCount(selectedPhotos.size() + selectedWebPhotos.size(), true);

    return fragmentView;
  }