Search in sources :

Example 56 with LayoutParams

use of android.support.v7.app.ActionBar.LayoutParams in project AndFrameWorks by scwang90.

the class RecycleViewDivider method drawVertical.

// 绘制纵向 item 分割线
private void drawVertical(Canvas canvas, RecyclerView parent) {
    final int top = parent.getPaddingTop();
    final int bottom = parent.getMeasuredHeight() - parent.getPaddingBottom();
    final int childSize = parent.getChildCount();
    for (int i = 0; i < childSize; i++) {
        final View child = parent.getChildAt(i);
        RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) child.getLayoutParams();
        final int left = child.getRight() + layoutParams.rightMargin;
        final int right = left + mDividerHeight;
        if (mDivider != null) {
            mDivider.setBounds(left, top, right, bottom);
            mDivider.draw(canvas);
        }
        if (mPaint != null) {
            canvas.drawRect(left, top, right, bottom, mPaint);
        }
    }
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) Paint(android.graphics.Paint)

Example 57 with LayoutParams

use of android.support.v7.app.ActionBar.LayoutParams in project AndFrameWorks by scwang90.

the class RecycleViewDivider method drawHorizontal.

// 绘制横向 item 分割线
private void drawHorizontal(Canvas canvas, RecyclerView parent) {
    final int left = parent.getPaddingLeft();
    final int right = parent.getMeasuredWidth() - parent.getPaddingRight();
    final int childSize = parent.getChildCount();
    for (int i = 0; i < childSize; i++) {
        final View child = parent.getChildAt(i);
        RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) child.getLayoutParams();
        final int top = child.getBottom() + layoutParams.bottomMargin;
        final int bottom = top + mDividerHeight;
        if (mDivider != null) {
            mDivider.setBounds(left, top, right, bottom);
            mDivider.draw(canvas);
        }
        if (mPaint != null) {
            canvas.drawRect(left, top, right, bottom, mPaint);
        }
    }
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) Paint(android.graphics.Paint)

Example 58 with LayoutParams

use of android.support.v7.app.ActionBar.LayoutParams in project LibreraReader by foobnix.

the class DragingDialogs method selectTextMenu.

public static DragingPopup selectTextMenu(final FrameLayout anchor, final DocumentController controller, final boolean withAnnotation, final Runnable reloadUI) {
    return new DragingPopup(R.string.text, anchor, 300, 400) {

        @Override
        public View getContentView(LayoutInflater inflater) {
            final View view = inflater.inflate(R.layout.dialog_selected_text, null, false);
            final LinearLayout linearLayoutColor = (LinearLayout) view.findViewById(R.id.colorsLine);
            linearLayoutColor.removeAllViews();
            List<String> colors = new ArrayList<String>(AppState.get().COLORS);
            colors.remove(0);
            colors.remove(0);
            final ImageView underLine = (ImageView) view.findViewById(R.id.onUnderline);
            final ImageView strike = (ImageView) view.findViewById(R.id.onStrike);
            final ImageView selection = (ImageView) view.findViewById(R.id.onSelection);
            final ImageView onAddCustom = (ImageView) view.findViewById(R.id.onAddCustom);
            final LinearLayout customsLayout = (LinearLayout) view.findViewById(R.id.customsLayout);
            final Runnable updateConfigRunnable = new Runnable() {

                @Override
                public void run() {
                    customsLayout.removeAllViews();
                    for (final String line : AppState.get().customConfigColors.split(",")) {
                        if (TxtUtils.isEmpty(line)) {
                            continue;
                        }
                        final ImageView image = new ImageView(controller.getActivity());
                        if (line.startsWith("H")) {
                            image.setImageResource(R.drawable.glyphicons_607_te_background);
                        } else if (line.startsWith("U")) {
                            image.setImageResource(R.drawable.glyphicons_104_te_underline);
                        } else if (line.startsWith("S")) {
                            image.setImageResource(R.drawable.glyphicons_105_te_strike);
                        }
                        String color = line.substring(1);
                        final int colorInt = Color.parseColor(color);
                        TintUtil.setTintImageWithAlpha(image, colorInt);
                        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(Dips.dpToPx(35), Dips.dpToPx(35));
                        int pd = Dips.dpToPx(5);
                        params.leftMargin = pd;
                        image.setPadding(pd, pd, pd, pd);
                        customsLayout.addView(image, params);
                        image.setOnClickListener(new OnClickListener() {

                            @Override
                            public void onClick(View v) {
                                if (line.startsWith("H")) {
                                    controller.underlineText(colorInt, 2.0f, AnnotationType.HIGHLIGHT);
                                } else if (line.startsWith("U")) {
                                    controller.underlineText(colorInt, 2.0f, AnnotationType.UNDERLINE);
                                } else if (line.startsWith("S")) {
                                    controller.underlineText(colorInt, 2.0f, AnnotationType.STRIKEOUT);
                                }
                                closeDialog();
                                controller.saveAnnotationsToFile();
                            }
                        });
                        image.setOnLongClickListener(new OnLongClickListener() {

                            @Override
                            public boolean onLongClick(View v) {
                                AppState.get().customConfigColors = AppState.get().customConfigColors.replace(line, "");
                                customsLayout.removeView(image);
                                return true;
                            }
                        });
                    }
                }
            };
            updateConfigRunnable.run();
            onAddCustom.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    PopupMenu menu = new PopupMenu(v.getContext(), v);
                    Drawable highlight = controller.getActivity().getResources().getDrawable(R.drawable.glyphicons_607_te_background);
                    highlight.setColorFilter(Color.parseColor(AppState.get().annotationTextColor), Mode.SRC_ATOP);
                    Drawable underline = controller.getActivity().getResources().getDrawable(R.drawable.glyphicons_104_te_underline);
                    underline.setColorFilter(Color.parseColor(AppState.get().annotationTextColor), Mode.SRC_ATOP);
                    Drawable strikeout = controller.getActivity().getResources().getDrawable(R.drawable.glyphicons_105_te_strike);
                    strikeout.setColorFilter(Color.parseColor(AppState.get().annotationTextColor), Mode.SRC_ATOP);
                    menu.getMenu().add(R.string.highlight_of_text).setIcon(highlight).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                        @Override
                        public boolean onMenuItemClick(MenuItem item) {
                            AppState.get().customConfigColors += "H" + AppState.get().annotationTextColor + ",";
                            updateConfigRunnable.run();
                            return false;
                        }
                    });
                    menu.getMenu().add(R.string.underline_of_text).setIcon(underline).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                        @Override
                        public boolean onMenuItemClick(MenuItem item) {
                            AppState.get().customConfigColors += "U" + AppState.get().annotationTextColor + ",";
                            updateConfigRunnable.run();
                            return false;
                        }
                    });
                    menu.getMenu().add(R.string.strikethrough_of_text).setIcon(strikeout).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                        @Override
                        public boolean onMenuItemClick(MenuItem item) {
                            AppState.get().customConfigColors += "S" + AppState.get().annotationTextColor + ",";
                            updateConfigRunnable.run();
                            return false;
                        }
                    });
                    menu.show();
                    PopupHelper.initIcons(menu, Color.parseColor(AppState.get().annotationTextColor));
                }
            });
            underLine.setColorFilter(Color.parseColor(AppState.get().annotationTextColor));
            strike.setColorFilter(Color.parseColor(AppState.get().annotationTextColor));
            selection.setColorFilter(Color.parseColor(AppState.get().annotationTextColor));
            for (final String colorName : colors) {
                final View inflate = LayoutInflater.from(linearLayoutColor.getContext()).inflate(R.layout.item_color, linearLayoutColor, false);
                inflate.setBackgroundResource(R.drawable.bg_border_2_lines);
                final View img = inflate.findViewById(R.id.itColor);
                final int colorId = Color.parseColor(colorName);
                img.setBackgroundColor(colorId);
                inflate.setTag(colorName);
                linearLayoutColor.addView(inflate);
                inflate.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        // Views.unselectChilds(linearLayoutColor);
                        // v.setSelected(true);
                        AppState.get().annotationTextColor = colorName;
                        underLine.setColorFilter(Color.parseColor(colorName));
                        strike.setColorFilter(Color.parseColor(colorName));
                        selection.setColorFilter(Color.parseColor(colorName));
                    }
                });
            }
            final EditText editText = (EditText) view.findViewById(R.id.editText);
            final String selectedText = AppState.get().selectedText;
            // AppState.get().selectedText = null;
            editText.setText(selectedText);
            final View onTranslate = view.findViewById(R.id.onTranslate);
            onTranslate.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    anchor.removeAllViews();
                    final PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
                    final Map<String, String> providers = AppState.getDictionaries(editText.getText().toString().trim());
                    for (final String name : providers.keySet()) {
                        popupMenu.getMenu().add(name).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                            @Override
                            public boolean onMenuItemClick(MenuItem item) {
                                Urls.open(anchor.getContext(), providers.get(name).trim());
                                return false;
                            }
                        });
                    }
                    popupMenu.show();
                }
            });
            view.findViewById(R.id.onAddToBookmark).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    closeDialog();
                    ListBoxHelper.showAddDialog(controller, null, null, editText.getText().toString().trim());
                }
            });
            view.findViewById(R.id.readTTS).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    TTSEngine.get().stop();
                    TTSEngine.get().speek(editText.getText().toString().trim());
                }
            });
            view.findViewById(R.id.readTTSNext).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    TTSEngine.get().stop();
                    TTSService.playBookPage(controller.getCurentPageFirst1() - 1, controller.getCurrentBook().getPath(), editText.getText().toString().trim(), controller.getBookWidth(), controller.getBookHeight(), AppState.get().fontSizeSp);
                }
            });
            view.findViewById(R.id.onShare).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    closeDialog();
                    final Intent intent = new Intent(Intent.ACTION_SEND);
                    intent.setType("text/plain");
                    String txt = "\"" + editText.getText().toString().trim() + "\" (" + controller.getBookFileMetaName() + ")";
                    intent.putExtra(Intent.EXTRA_TEXT, txt);
                    controller.getActivity().startActivity(Intent.createChooser(intent, controller.getString(R.string.share)));
                }
            });
            view.findViewById(R.id.onCopy).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    Context c = anchor.getContext();
                    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
                        android.text.ClipboardManager clipboard = (android.text.ClipboardManager) c.getSystemService(Context.CLIPBOARD_SERVICE);
                        clipboard.setText(editText.getText().toString().trim());
                    } else {
                        android.content.ClipboardManager clipboard = (android.content.ClipboardManager) c.getSystemService(Context.CLIPBOARD_SERVICE);
                        android.content.ClipData clip = android.content.ClipData.newPlainText("Copied Text", editText.getText().toString().trim());
                        clipboard.setPrimaryClip(clip);
                    }
                    closeDialog();
                }
            });
            view.findViewById(R.id.onGoogle).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    closeDialog();
                    Urls.open(anchor.getContext(), "http://www.google.com/search?q=" + editText.getText().toString().trim());
                }
            });
            TextView onBookSearch = (TextView) view.findViewById(R.id.onBookSearch);
            // onBookSearch.setText(controller.getString(R.string.search_in_the_book)
            // + " \"" + AppState.get().selectedText + "\"");
            onBookSearch.setVisibility(selectedText.contains(" ") ? View.GONE : View.VISIBLE);
            onBookSearch.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    searchMenu(anchor, controller, selectedText);
                }
            });
            LinearLayout dictLayout = (LinearLayout) view.findViewById(R.id.dictionaryLine);
            dictLayout.removeAllViews();
            final Intent intentProccessText = new Intent();
            if (Build.VERSION.SDK_INT >= 23) {
                intentProccessText.setAction(Intent.ACTION_PROCESS_TEXT);
            }
            intentProccessText.setType("text/plain");
            final Intent intentSearch = new Intent();
            intentSearch.setAction(Intent.ACTION_SEARCH);
            final Intent intentSend = new Intent();
            intentSend.setAction(Intent.ACTION_SEND);
            intentSend.setType("text/plain");
            final Intent intentCustom = new Intent("colordict.intent.action.SEARCH");
            PackageManager pm = anchor.getContext().getPackageManager();
            final List<ResolveInfo> proccessTextList = pm.queryIntentActivities(intentProccessText, 0);
            final List<ResolveInfo> searchList = pm.queryIntentActivities(intentSearch, 0);
            final List<ResolveInfo> sendList = pm.queryIntentActivities(intentSend, 0);
            final List<ResolveInfo> customList = pm.queryIntentActivities(intentCustom, 0);
            final List<ResolveInfo> all = new ArrayList<ResolveInfo>();
            if (Build.VERSION.SDK_INT >= 23) {
                all.addAll(proccessTextList);
            }
            all.addAll(customList);
            all.addAll(searchList);
            all.addAll(sendList);
            final SharedPreferences sp = anchor.getContext().getSharedPreferences("lastDict", Context.MODE_PRIVATE);
            final String lastID = sp.getString("last", "");
            List<String> cache = new ArrayList<String>();
            for (final ResolveInfo app : all) {
                for (final String pkgKey : AppState.appDictionariesKeys) {
                    if (app.activityInfo.packageName.toLowerCase().contains(pkgKey)) {
                        if (cache.contains(app.activityInfo.name)) {
                            continue;
                        }
                        cache.add(app.activityInfo.name);
                        LOG.d("Add APP", app.activityInfo.name);
                        try {
                            ImageView image = new ImageView(anchor.getContext());
                            LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(Dips.dpToPx(44), Dips.dpToPx(44));
                            layoutParams.rightMargin = Dips.dpToPx(8);
                            image.setLayoutParams(layoutParams);
                            Drawable icon = anchor.getContext().getPackageManager().getApplicationIcon(app.activityInfo.packageName);
                            image.setImageDrawable(icon);
                            image.setOnClickListener(new OnClickListener() {

                                @Override
                                public void onClick(View v) {
                                    String selecteText = editText.getText().toString().trim();
                                    closeDialog();
                                    final ActivityInfo activity = app.activityInfo;
                                    final ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name);
                                    if (customList.contains(app)) {
                                        intentCustom.addCategory(Intent.CATEGORY_LAUNCHER);
                                        intentCustom.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
                                        intentCustom.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
                                        intentCustom.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                                        intentCustom.setComponent(name);
                                        intentCustom.putExtra("EXTRA_QUERY", selecteText);
                                        intentCustom.putExtra("EXTRA_HEIGHT", Dips.screenHeight() / 2);
                                        if (AppState.get().isDouble || Dips.screenWidth() > Dips.screenHeight()) {
                                            intentCustom.putExtra("EXTRA_HEIGHT", Dips.screenHeight() * 2 / 3);
                                            if (TempHolder.get().textFromPage == 1) {
                                                intentCustom.putExtra("EXTRA_GRAVITY", Gravity.BOTTOM | Gravity.RIGHT);
                                            } else if (TempHolder.get().textFromPage == 2) {
                                                intentCustom.putExtra("EXTRA_GRAVITY", Gravity.BOTTOM | Gravity.LEFT);
                                            } else {
                                                intentCustom.putExtra("EXTRA_GRAVITY", Gravity.BOTTOM | Gravity.CENTER);
                                            }
                                            intentCustom.putExtra("EXTRA_WIDTH", Dips.screenWidth() / 2);
                                        } else {
                                            intentCustom.putExtra("EXTRA_GRAVITY", Gravity.BOTTOM);
                                        }
                                        controller.getActivity().startActivity(intentCustom);
                                    } else if (proccessTextList.contains(app)) {
                                        intentProccessText.addCategory(Intent.CATEGORY_LAUNCHER);
                                        intentProccessText.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
                                        intentProccessText.setComponent(name);
                                        intentProccessText.putExtra(Intent.EXTRA_TEXT, selecteText);
                                        intentProccessText.putExtra(Intent.EXTRA_PROCESS_TEXT, selecteText);
                                        intentProccessText.putExtra(Intent.EXTRA_PROCESS_TEXT_READONLY, selecteText);
                                        controller.getActivity().startActivity(intentProccessText);
                                    } else if (searchList.contains(app)) {
                                        intentSearch.addCategory(Intent.CATEGORY_LAUNCHER);
                                        intentSearch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
                                        intentSearch.setComponent(name);
                                        intentSearch.putExtra(SearchManager.QUERY, selecteText);
                                        intentSearch.putExtra(Intent.EXTRA_TEXT, selecteText);
                                        controller.getActivity().startActivity(intentSearch);
                                    } else if (sendList.contains(app)) {
                                        intentSend.addCategory(Intent.CATEGORY_LAUNCHER);
                                        intentSend.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
                                        intentSend.setComponent(name);
                                        intentSend.putExtra(Intent.EXTRA_TEXT, selecteText);
                                        controller.getActivity().startActivity(intentSend);
                                    }
                                    sp.edit().putString("last", app.activityInfo.name).commit();
                                }
                            });
                            if (app.activityInfo.name.equals(lastID)) {
                                dictLayout.addView(image, 0);
                            } else {
                                dictLayout.addView(image);
                            }
                        } catch (PackageManager.NameNotFoundException e) {
                            LOG.d(e);
                        }
                    }
                }
            }
            view.findViewById(R.id.onUnderline).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    controller.underlineText(Color.parseColor(AppState.get().annotationTextColor), 2.0f, AnnotationType.UNDERLINE);
                    closeDialog();
                    controller.saveAnnotationsToFile();
                }
            });
            view.findViewById(R.id.onStrike).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    controller.underlineText(Color.parseColor(AppState.get().annotationTextColor), 2.0f, AnnotationType.STRIKEOUT);
                    closeDialog();
                    controller.saveAnnotationsToFile();
                }
            });
            view.findViewById(R.id.onSelection).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    controller.underlineText(Color.parseColor(AppState.get().annotationTextColor), 2.0f, AnnotationType.HIGHLIGHT);
                    closeDialog();
                    controller.saveAnnotationsToFile();
                }
            });
            if (!BookType.PDF.is(controller.getCurrentBook().getPath()) || !withAnnotation || controller.getActivity() instanceof HorizontalViewActivity || controller.isPasswordProtected()) {
                linearLayoutColor.setVisibility(View.GONE);
                view.findViewById(R.id.onUnderline).setVisibility(View.GONE);
                view.findViewById(R.id.onStrike).setVisibility(View.GONE);
                view.findViewById(R.id.onSelection).setVisibility(View.GONE);
                onAddCustom.setVisibility(View.GONE);
                customsLayout.setVisibility(View.GONE);
            }
            return view;
        }
    }.show("text", true).setOnCloseListener(new Runnable() {

        @Override
        public void run() {
            // controller.clearSelectedText();
            AppState.get().selectedText = null;
        }
    });
}
Also used : OnMenuItemClickListener(android.view.MenuItem.OnMenuItemClickListener) ArrayList(java.util.ArrayList) ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) OnLongClickListener(android.view.View.OnLongClickListener) TextView(android.widget.TextView) ComponentName(android.content.ComponentName) ImageView(android.widget.ImageView) Context(android.content.Context) HorizontalViewActivity(com.foobnix.pdf.search.activity.HorizontalViewActivity) EditText(android.widget.EditText) Context(android.content.Context) ActivityInfo(android.content.pm.ActivityInfo) AppSharedPreferences(com.foobnix.pdf.info.AppSharedPreferences) SharedPreferences(android.content.SharedPreferences) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) MenuItem(android.view.MenuItem) OnClickListener(android.view.View.OnClickListener) Intent(android.content.Intent) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) GridView(android.widget.GridView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) SuppressLint(android.annotation.SuppressLint) LayoutInflater(android.view.LayoutInflater) OnClickListener(android.view.View.OnClickListener) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) LinearLayout(android.widget.LinearLayout) PopupMenu(android.widget.PopupMenu)

Example 59 with LayoutParams

use of android.support.v7.app.ActionBar.LayoutParams in project LibreraReader by foobnix.

the class FileMetaAdapter method bindFileMetaView.

private FileMeta bindFileMetaView(final FileMetaViewHolder holder, final int position) {
    if (position >= items.size()) {
        return new FileMeta();
    }
    final FileMeta fileMeta = getItem(position);
    if (fileMeta == null) {
        return new FileMeta();
    }
    holder.title.setText(fileMeta.getTitle());
    holder.author.setText(fileMeta.getAuthor());
    if (AppState.get().isUiTextColor) {
        TintUtil.setUITextColor(holder.author, AppState.get().uiTextColor);
        TintUtil.setUITextColor(holder.series, AppState.get().uiTextColor);
    }
    if (TxtUtils.isEmpty(fileMeta.getAuthor())) {
        if (adapterType == ADAPTER_GRID) {
            holder.author.setVisibility(View.INVISIBLE);
        } else {
            holder.author.setVisibility(View.GONE);
        }
    } else {
        holder.author.setVisibility(View.VISIBLE);
    }
    if (holder.series != null && onSeriesClickListener != null) {
        String sequence = fileMeta.getSequence();
        holder.series.setVisibility(TxtUtils.isNotEmpty(sequence) ? View.VISIBLE : View.GONE);
        holder.series.setText(sequence);
        holder.series.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                if (onSeriesClickListener != null) {
                    onSeriesClickListener.onResultRecive(fileMeta.getSequence());
                }
            }
        });
    }
    holder.author.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (onAuthorClickListener != null) {
                onAuthorClickListener.onResultRecive(fileMeta.getAuthor());
            }
        }
    });
    if (holder.tags != null) {
        if (TxtUtils.isNotEmpty(fileMeta.getTag())) {
            holder.tags.setVisibility(View.VISIBLE);
            holder.tags.removeAllViews();
            for (final String tag : StringDB.asList(fileMeta.getTag())) {
                TextView t = new TextView(holder.tags.getContext());
                t.setTextAppearance(holder.tags.getContext(), R.style.textLink);
                TxtUtils.bold(t);
                t.setText(tag + " ");
                t.setTextSize(12);
                t.setGravity(Gravity.CENTER_VERTICAL);
                TypedValue outValue = new TypedValue();
                holder.tags.getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
                t.setBackgroundResource(outValue.resourceId);
                if (AppState.get().isUiTextColor) {
                    TintUtil.setUITextColor(t, AppState.get().uiTextColor);
                }
                t.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        if (onTagClickListner != null) {
                            onTagClickListner.onResultRecive(tag);
                        }
                    }
                });
                t.setOnLongClickListener(new OnLongClickListener() {

                    @Override
                    public boolean onLongClick(View v) {
                        Dialogs.showTagsDialog(v.getContext(), new File(fileMeta.getPath()), new Runnable() {

                            @Override
                            public void run() {
                                notifyDataSetChanged();
                            }
                        });
                        return true;
                    }
                });
                holder.tags.addView(t);
            }
        } else {
            holder.tags.setVisibility(View.GONE);
        }
    }
    holder.path.setText(fileMeta.getPathTxt());
    holder.browserExt.setText(fileMeta.getChild() != null ? fileMeta.getChild() : fileMeta.getExt());
    if (fileMeta.getPages() != null && fileMeta.getPages() != 0) {
        holder.size.setText(fileMeta.getSizeTxt() + " (" + fileMeta.getPages() + ")");
    } else {
        holder.size.setText(fileMeta.getSizeTxt());
    }
    if (holder.date != null) {
        holder.date.setText(fileMeta.getDateTxt());
    }
    double recentProgress = fileMeta.getIsRecentProgress() == null ? 0 : fileMeta.getIsRecentProgress();
    if (holder.idProgressColor != null && recentProgress > 0) {
        holder.progresLayout.setVisibility(View.VISIBLE);
        holder.idPercentText.setVisibility(View.VISIBLE);
        holder.idProgressColor.setBackgroundColor(TintUtil.color);
        int width = adapterType == ADAPTER_LIST_COMPACT ? Dips.dpToPx(100) : Dips.dpToPx(200);
        holder.idProgressBg.getLayoutParams().width = width;
        holder.idProgressColor.getLayoutParams().width = (int) (width * recentProgress);
        holder.idProgressColor.setLayoutParams(holder.idProgressColor.getLayoutParams());
        holder.idPercentText.setText("" + Math.round(100f * recentProgress) + "%");
    } else if (holder.progresLayout != null) {
        holder.progresLayout.setVisibility(View.INVISIBLE);
        holder.idPercentText.setVisibility(View.INVISIBLE);
    }
    if (adapterType == ADAPTER_GRID && recentProgress > 0) {
        holder.idPercentText.setText("" + (int) (100 * recentProgress) + "%");
        if (AppState.get().coverBigSize < IMG.TWO_LINE_COVER_SIZE) {
            holder.browserExt.setVisibility(View.GONE);
        } else {
            holder.browserExt.setVisibility(View.VISIBLE);
        }
    } else if (adapterType == ADAPTER_GRID) {
        holder.idPercentText.setText("");
        holder.browserExt.setVisibility(View.VISIBLE);
    }
    if (fileMeta.getIsStar() == null || fileMeta.getIsStar() == false) {
        holder.star.setImageResource(R.drawable.star_2);
    } else {
        holder.star.setImageResource(R.drawable.star_1);
    }
    TintUtil.setTintImageWithAlpha(holder.star, holder.parent.getContext() instanceof MainTabs2 ? TintUtil.getColorInDayNighth() : TintUtil.getColorInDayNighthBook());
    if (onStarClickListener != null) {
        holder.star.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                onStarClickListener.onResultRecive(fileMeta, FileMetaAdapter.this);
            }
        });
        holder.star.setOnLongClickListener(new OnLongClickListener() {

            @Override
            public boolean onLongClick(View v) {
                Dialogs.showTagsDialog(v.getContext(), new File(fileMeta.getPath()), new Runnable() {

                    @Override
                    public void run() {
                        notifyDataSetChanged();
                    }
                });
                return true;
            }
        });
    } else {
    }
    holder.star.setVisibility(ExtUtils.isExteralSD(fileMeta.getPath()) ? View.GONE : View.VISIBLE);
    if (holder.signIcon != null) {
        holder.signIcon.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Dialogs.showTagsDialog(v.getContext(), new File(fileMeta.getPath()), new Runnable() {

                    @Override
                    public void run() {
                        TintUtil.setTintImageWithAlpha(holder.signIcon, TxtUtils.isEmpty(fileMeta.getTag()) ? TintUtil.COLOR_TINT_GRAY : TintUtil.color);
                    }
                });
            }
        });
        TintUtil.setTintImageWithAlpha(holder.signIcon, TxtUtils.isEmpty(fileMeta.getTag()) ? TintUtil.COLOR_TINT_GRAY : TintUtil.color);
    }
    bindItemClickAndLongClickListeners(holder.parent, fileMeta);
    if (adapterType == ADAPTER_GRID || adapterType == ADAPTER_COVERS) {
        holder.path.setVisibility(View.GONE);
        holder.size.setVisibility(View.GONE);
        int sizeDP = AppState.get().coverBigSize;
        if (tempValue == TEMP_VALUE_STAR_GRID_ITEM) {
            sizeDP = Math.max(80, AppState.get().coverSmallSize);
        }
        IMG.updateImageSizeBig((View) holder.image.getParent().getParent(), sizeDP);
        LayoutParams lp = holder.image.getLayoutParams();
        lp.width = Dips.dpToPx(sizeDP);
        if (AppState.get().isCropBookCovers) {
            lp.height = (int) (lp.width * IMG.WIDTH_DK);
        } else {
            lp.width = LayoutParams.WRAP_CONTENT;
            lp.height = LayoutParams.WRAP_CONTENT;
        }
    } else {
        holder.path.setVisibility(View.VISIBLE);
        holder.size.setVisibility(View.VISIBLE);
        IMG.updateImageSizeSmall((View) holder.image.getParent().getParent());
        LayoutParams lp = holder.image.getLayoutParams();
        lp.width = Dips.dpToPx(AppState.get().coverSmallSize);
        if (AppState.get().isCropBookCovers) {
            lp.height = (int) (lp.width * IMG.WIDTH_DK);
        } else {
            lp.height = LayoutParams.WRAP_CONTENT;
        }
    }
    if (holder.date != null) {
        holder.date.setVisibility(View.VISIBLE);
        holder.size.setVisibility(View.VISIBLE);
        if (adapterType == ADAPTER_LIST_COMPACT) {
            holder.date.setVisibility(View.GONE);
            holder.size.setVisibility(View.GONE);
        }
    }
    if (AppState.get().isBorderAndShadow) {
        View parent = (View) holder.image.getParent();
        parent.setBackgroundColor(Color.TRANSPARENT);
        FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) parent.getLayoutParams();
        layoutParams.setMargins(0, 0, 0, 0);
    }
    if (AppState.get().isCropBookCovers) {
        holder.image.setScaleType(ScaleType.CENTER_CROP);
    } else {
        holder.image.setScaleType(ScaleType.FIT_CENTER);
    }
    if (holder.layoutBootom != null) {
        if (adapterType == ADAPTER_COVERS) {
            holder.layoutBootom.setVisibility(View.GONE);
            holder.infoLayout.setVisibility(View.GONE);
        } else {
            holder.layoutBootom.setVisibility(View.VISIBLE);
            holder.infoLayout.setVisibility(View.VISIBLE);
        }
    }
    holder.authorParent.setVisibility(View.VISIBLE);
    if (adapterType == ADAPTER_LIST || adapterType == ADAPTER_LIST_COMPACT) {
        if (AppState.get().coverSmallSize >= IMG.TWO_LINE_COVER_SIZE) {
            holder.title.setSingleLine(false);
            holder.title.setLines(2);
            holder.path.setVisibility(View.VISIBLE);
            holder.title.setTextSize(16);
        } else {
            holder.title.setSingleLine(false);
            holder.title.setLines(2);
            holder.title.setTextSize(14);
            holder.authorParent.setVisibility(View.GONE);
            holder.path.setVisibility(View.GONE);
            holder.infoLayout.setVisibility(View.VISIBLE);
            holder.title.setText(fileMeta.getPathTxt());
        }
    }
    TintUtil.setTintImageWithAlpha(holder.menu, holder.parent.getContext() instanceof MainTabs2 ? TintUtil.getColorInDayNighth() : TintUtil.getColorInDayNighthBook());
    if (holder.remove != null) {
        holder.remove.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                onDeleteClickListener.onResultRecive(fileMeta);
            }
        });
        if (onDeleteClickListener == null) {
            holder.remove.setVisibility(View.GONE);
        }
    }
    holder.menu.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (onMenuClickListener != null) {
                onMenuClickListener.onResultRecive(fileMeta);
            }
        }
    });
    holder.parent.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            onItemClickListener.onResultRecive(fileMeta);
        }
    });
    holder.parent.setOnLongClickListener(new OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            onItemLongClickListener.onResultRecive(fileMeta);
            return true;
        }
    });
    if (!AppState.get().isBorderAndShadow) {
        holder.parent.setBackgroundColor(Color.TRANSPARENT);
    }
    return fileMeta;
}
Also used : MainTabs2(com.foobnix.ui2.MainTabs2) LayoutParams(android.view.ViewGroup.LayoutParams) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) OnLongClickListener(android.view.View.OnLongClickListener) FrameLayout(android.widget.FrameLayout) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) File(java.io.File) FileMeta(com.foobnix.dao2.FileMeta) TypedValue(android.util.TypedValue)

Example 60 with LayoutParams

use of android.support.v7.app.ActionBar.LayoutParams in project TicktockMusic by Lauzy.

the class HorizontalPagerScrollListener method onScrollStateChanged.

@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
    super.onScrollStateChanged(recyclerView, newState);
    if (newState != RecyclerView.SCROLL_STATE_IDLE) {
        return;
    }
    RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
    if (mOrientationHelper == null) {
        mOrientationHelper = OrientationHelper.createHorizontalHelper(layoutManager);
    }
    final int rvCenter;
    if (recyclerView.getClipToPadding()) {
        rvCenter = mOrientationHelper.getStartAfterPadding() + mOrientationHelper.getTotalSpace() / 2;
    } else {
        rvCenter = mOrientationHelper.getTotalSpace() / 2;
    }
    int minSpace = Integer.MAX_VALUE;
    View minCloseView = null;
    final int childCount = recyclerView.getChildCount();
    for (int i = 0; i < childCount; i++) {
        View childView = recyclerView.getChildAt(i);
        RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) childView.getLayoutParams();
        final int childStart = mOrientationHelper.getDecoratedStart(childView) + layoutParams.leftMargin;
        final int childWidth = mOrientationHelper.getDecoratedMeasurement(childView) - layoutParams.leftMargin - layoutParams.rightMargin;
        final int childCenter = childStart + childWidth / 2;
        final int space = Math.abs(childCenter - rvCenter);
        if (minSpace > space) {
            minSpace = space;
            minCloseView = childView;
        }
    }
    if (minCloseView != null) {
        int position = recyclerView.getChildViewHolder(minCloseView).getAdapterPosition();
        if (position == RecyclerView.NO_POSITION) {
            return;
        }
        if (mLastPosition != position) {
            onPageChange(position);
            mLastPosition = position;
        }
    }
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Aggregations

View (android.view.View)140 RecyclerView (android.support.v7.widget.RecyclerView)127 TextView (android.widget.TextView)46 ImageView (android.widget.ImageView)38 ViewGroup (android.view.ViewGroup)33 LinearLayout (android.widget.LinearLayout)27 LayoutParams (android.support.v7.widget.RecyclerView.LayoutParams)17 Paint (android.graphics.Paint)15 StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)15 FrameLayout (android.widget.FrameLayout)15 BindView (butterknife.BindView)12 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)11 Toolbar (android.support.v7.widget.Toolbar)11 Rect (android.graphics.Rect)9 EditText (android.widget.EditText)9 OrientationHelperEx (com.alibaba.android.vlayout.OrientationHelperEx)9 AdapterView (android.widget.AdapterView)8 RelativeLayout (android.widget.RelativeLayout)8 VirtualLayoutManager (com.alibaba.android.vlayout.VirtualLayoutManager)8 SuppressLint (android.annotation.SuppressLint)7