Example usage for android.view View setClickable

List of usage examples for android.view View setClickable

Introduction

In this page you can find the example usage for android.view View setClickable.

Prototype

public void setClickable(boolean clickable) 

Source Link

Document

Enables or disables click events for this view.

Usage

From source file:cgeo.geocaching.cgeocaches.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setTheme();/*from  w  ww.j  a  v  a 2 s  .  co  m*/
    setContentView(R.layout.cacheslist_activity);

    // get parameters
    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        Object typeObject = extras.get(Intents.EXTRA_LIST_TYPE);
        type = (typeObject instanceof CacheListType) ? (CacheListType) typeObject : CacheListType.OFFLINE;
        coords = extras.getParcelable(Intents.EXTRA_COORDS);
    } else {
        extras = new Bundle();
    }
    if (isInvokedFromAttachment()) {
        type = CacheListType.OFFLINE;
        if (coords == null) {
            coords = new Geopoint(0.0, 0.0);
        }
    }

    // Add the list selection in code. This way we can leave the XML layout of the action bar the same as for other activities.
    final View titleBar = findViewById(R.id.actionbar_title);
    titleBar.setClickable(true);
    titleBar.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            selectList(v);
        }
    });

    setTitle(title);
    setAdapter();

    prepareFilterBar();

    currentLoader = (AbstractSearchLoader) getSupportLoaderManager().initLoader(type.ordinal(), extras, this);

    // init
    if (CollectionUtils.isNotEmpty(cacheList)) {
        // currentLoader can be null if this activity is created from a map, as onCreateLoader() will return null.
        if (currentLoader != null && currentLoader.isStarted()) {
            showFooterLoadingCaches();
        } else {
            showFooterMoreCaches();
        }
    }

    if (isInvokedFromAttachment()) {
        importGpxAttachement();
    }
}

From source file:com.tdispatch.passenger.fragment.ControlCenterFragment.java

protected void hideAimPoint() {
    if (mAimPointVisible) {
        mAimPointVisible = false;/* w w w.jav a 2  s.  c  o m*/

        View v = mFragmentView.findViewById(R.id.map_aim_point_container);
        v.clearAnimation();
        v.startAnimation(AnimationUtils.loadAnimation(mContext, R.anim.fade_out));

        WebnetTools.setVisibility(mFragmentView, R.id.map_aim_point_minimal_container, View.VISIBLE);

        int[] ids = { R.id.button_set_as_pickup, R.id.button_set_as_dropoff };
        for (int id : ids) {
            v = mFragmentView.findViewById(id);
            v.setClickable(false);
            v.setLongClickable(false);
        }
    }
}

From source file:com.tdispatch.passenger.fragment.ControlCenterFragment.java

protected void showAimPoint(Boolean animate) {

    if (mAimPointVisible == false) {
        mAimPointVisible = true;/*from  www.ja  v a  2 s .c  om*/

        View v = mFragmentView.findViewById(R.id.map_aim_point_container);
        v.clearAnimation();

        v.startAnimation(
                AnimationUtils.loadAnimation(mContext, (animate) ? R.anim.fade_in : R.anim.fade_in_instant));

        WebnetTools.setVisibility(mFragmentView, R.id.map_aim_point_minimal_container, View.INVISIBLE);

        int[] ids = { R.id.button_set_as_pickup, R.id.button_set_as_dropoff };
        for (int id : ids) {
            v = mFragmentView.findViewById(id);
            v.setClickable(true);
            v.setLongClickable(true);
        }
    }
}

From source file:com.wewow.MainActivity.java

private void setUpViewPagerBanner(final List<Banner> banners) {

    group = (ViewGroup) findViewById(R.id.viewGroup);

    LayoutInflater inflater = getLayoutInflater();

    pageview = new ArrayList<View>();
    for (int i = 0; i < banners.size(); i++) {

        View view = inflater.inflate(R.layout.banner_item, null);
        ImageView imageBanner = (ImageView) view.findViewById(R.id.imageViewIcon);
        TextView textViewBannerTitle = (TextView) view.findViewById(R.id.textViewBannerTitle);
        textViewBannerTitle.setText(banners.get(i).getTitle());
        Glide.with(context).load(banners.get(i).getImage()).placeholder(R.drawable.banner_loading_spinner)
                .crossFade(300).into(imageBanner);
        view.setClickable(true);
        view.setFocusable(true);//from w w w  .j av  a2 s. co  m
        view.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                    AppBarLayout.LayoutParams mParams = (AppBarLayout.LayoutParams) mAppBarLayout.getChildAt(0)
                            .getLayoutParams();
                    mParams.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_EXIT_UNTIL_COLLAPSED
                            | AppBarLayout.LayoutParams.SCROLL_FLAG_SNAP);
                } else {

                    AppBarLayout.LayoutParams mParams = (AppBarLayout.LayoutParams) mAppBarLayout.getChildAt(0)
                            .getLayoutParams();
                    mParams.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL
                            | AppBarLayout.LayoutParams.SCROLL_FLAG_EXIT_UNTIL_COLLAPSED
                            | AppBarLayout.LayoutParams.SCROLL_FLAG_SNAP);
                }
            }
        });

        pageview.add(view);
        final int j = i;
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Banner banner = banners.get(j);
                String type = banner.getType();
                if (type.equals(CommonUtilities.BANNER_TYPE_SUBJECT)) {
                    Intent intent = new Intent(MainActivity.this, SubjectActivity.class);
                    intent.putExtra("id", banner.getId());
                    startActivity(intent);

                } else if (type.equals(CommonUtilities.BANNER_TYPE_COLLECTION)) {
                    LabCollection lc = new LabCollection();
                    lc.image = banner.getImage();
                    lc.title = banner.getTitle();
                    lc.id = Long.parseLong(banner.getId());
                    Intent intent = new Intent(MainActivity.this, LifeLabItemActivity.class);
                    intent.putExtra(LifeLabItemActivity.LIFELAB_COLLECTION, lc);

                    startActivity(intent);
                } else if (type.equals(CommonUtilities.BANNER_TYPE_POST)) {
                    Intent intent = new Intent(MainActivity.this, LifePostActivity.class);
                    intent.putExtra(LifePostActivity.POST_ID, Integer.parseInt(banner.getId()));
                    startActivity(intent);
                } else {
                    Intent intent = new Intent(MainActivity.this, WebPageActivity.class);
                    intent.putExtra("url", banner.getUrl());
                    startActivity(intent);

                }
            }
        });
    }

    group.removeAllViews();
    //
    imageViews = new ImageView[pageview.size()];
    for (int i = 0; i < pageview.size(); i++) {
        imageView = new ImageView(MainActivity.this);
        imageView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
        imageView.setPadding(12, 0, 12, 0);
        imageViews[i] = imageView;

        //
        if (i == 0) {
            imageViews[i].setBackgroundResource(R.drawable.dot_b);
        } else {
            imageViews[i].setBackgroundResource(R.drawable.dot);
        }

        group.addView(imageViews[i]);
    }

    PagerAdapter mPagerAdapter = new PagerAdapter() {

        @Override

        public int getCount() {
            // TODO Auto-generated method stub
            return pageview.size();
        }

        @Override

        public boolean isViewFromObject(View arg0, Object arg1) {
            // TODO Auto-generated method stub
            return arg0 == arg1;
        }

        public void destroyItem(View arg0, int arg1, Object arg2) {
            ((ViewPager) arg0).removeView(pageview.get(arg1));
        }

        public Object instantiateItem(View arg0, int arg1) {
            ((ViewPager) arg0).addView(pageview.get(arg1));
            return pageview.get(arg1);
        }

    };

    //set adapter
    viewPager.setAdapter(mPagerAdapter);
    if (Build.VERSION.SDK_INT >= 21) {
        viewPager.setNestedScrollingEnabled(false);
    }

    //set page change listener
    viewPager.setOnPageChangeListener(new GuidePageChangeListener());

}

From source file:com.matthewlogan.reversedrawerlayout.library.ReverseDrawerLayout.java

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    mInLayout = true;//from   w  ww.j av a2s. c om
    final int width = r - l;
    mDrawerOverhangDecimalOffset = mDrawerOverhang / (float) width;
    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);

        if (child.getVisibility() == GONE) {
            continue;
        }

        final LayoutParams lp = (LayoutParams) child.getLayoutParams();

        if (isContentView(child)) {
            child.layout(lp.leftMargin, lp.topMargin, lp.leftMargin + child.getMeasuredWidth(),
                    lp.topMargin + child.getMeasuredHeight());
        } else { // Drawer, if it wasn't onMeasure would have thrown an exception.
            if (mFirstLayout) {
                openDrawer(child);
            }
            child.setClickable(true);

            final int childWidth = child.getMeasuredWidth();
            final int childHeight = child.getMeasuredHeight();
            int childLeft;

            final float newOffset;
            if (checkDrawerViewAbsoluteGravity(child, Gravity.LEFT)) {
                childLeft = -childWidth + (int) (childWidth * lp.onScreen);
                newOffset = (float) (childWidth + childLeft) / childWidth;
            } else { // Right; onMeasure checked for us.
                childLeft = width - (int) (childWidth * lp.onScreen);
                newOffset = (float) (width - childLeft) / childWidth;
            }

            final boolean changeOffset = newOffset != lp.onScreen;

            final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK;

            switch (vgrav) {
            default:
            case Gravity.TOP: {
                child.layout(childLeft, lp.topMargin, childLeft + childWidth, lp.topMargin + childHeight);
                break;
            }

            case Gravity.BOTTOM: {
                final int height = b - t;
                child.layout(childLeft, height - lp.bottomMargin - child.getMeasuredHeight(),
                        childLeft + childWidth, height - lp.bottomMargin);
                break;
            }

            case Gravity.CENTER_VERTICAL: {
                final int height = b - t;
                int childTop = (height - childHeight) / 2;

                // Offset for margins. If things don't fit right because of
                // bad measurement before, oh well.
                if (childTop < lp.topMargin) {
                    childTop = lp.topMargin;
                } else if (childTop + childHeight > height - lp.bottomMargin) {
                    childTop = height - lp.bottomMargin - childHeight;
                }
                child.layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight);
                break;
            }
            }

            if (changeOffset) {
                setDrawerViewOffset(child, newOffset);
            }

            final int newVisibility = lp.onScreen > 0 ? VISIBLE : INVISIBLE;
            if (child.getVisibility() != newVisibility) {
                child.setVisibility(newVisibility);
            }
        }
    }
    mInLayout = false;
    mFirstLayout = false;
}

From source file:de.geeksfactory.opacclient.frontend.AccountFragment.java

@SuppressWarnings("deprecation")
public void displaydata(final AccountData result, boolean fromcache) {
    if (getActivity() == null) {
        return;//www.ja va 2 s.  c  om
    }
    svAccount.setVisibility(View.VISIBLE);
    llLoading.setVisibility(View.GONE);
    unsupportedErrorView.setVisibility(View.GONE);
    answerErrorView.setVisibility(View.GONE);
    errorView.removeAllViews();

    this.fromcache = fromcache;

    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(app.getApplicationContext());
    final int tolerance = Integer.parseInt(sp.getString("notification_warning", "3"));

    tvAccLabel.setText(account.getLabel());
    tvAccUser.setText(account.getName());
    Library lib;
    try {
        lib = app.getLibrary(account.getLibrary());
        tvAccCity.setText(lib.getDisplayName());
    } catch (IOException e) {
        ErrorReporter.handleException(e);
        e.printStackTrace();
    } catch (JSONException e) {
        ErrorReporter.handleException(e);
    }

    /*
    Lent items
     */

    llLent.removeAllViews();

    final boolean notification_on = sp.getBoolean(SyncAccountAlarmListener.PREF_SYNC_SERVICE, false);
    boolean notification_problems = false;

    if (tvWarning != null) {
        if (result.getWarning() != null && result.getWarning().length() > 1) {
            tvWarning.setVisibility(View.VISIBLE);
            tvWarning.setText(result.getWarning());
        } else {
            tvWarning.setVisibility(View.GONE);
        }
    }

    if (result.getLent().size() == 0) {
        TextView t1 = new TextView(getActivity());
        t1.setText(R.string.entl_none);
        llLent.addView(t1);
        tvLentHeader.setText(getActivity().getString(R.string.lent_head) + " (0)");
    } else {
        tvLentHeader
                .setText(getActivity().getString(R.string.lent_head) + " (" + result.getLent().size() + ")");

        lentManager = new ExpandingCardListManager(getActivity(), llLent) {
            @Override
            public View getView(final int position, ViewGroup container) {
                final View v = getLayoutInflater(null).inflate(R.layout.listitem_account_lent, container,
                        false);
                LentViewHolder holder = new LentViewHolder();
                holder.findViews(v);

                final LentItem item = result.getLent().get(position);

                // Expanding and closing details
                v.setClickable(true);
                v.setFocusable(true);
                v.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (getExpandedPosition() != position) {
                            expand(position);
                        } else {
                            collapse();
                        }
                    }
                });

                if (item.getId() != null) {
                    // Connection to detail view
                    holder.ivDetails.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View clicked) {
                            Intent intent = new Intent(getActivity(), SearchResultDetailActivity.class);
                            intent.putExtra(SearchResultDetailFragment.ARG_ITEM_ID, item.getId());
                            ActivityOptionsCompat options = ActivityOptionsCompat.makeScaleUpAnimation(v,
                                    v.getLeft(), v.getTop(), v.getWidth(), v.getHeight());
                            ActivityCompat.startActivity(getActivity(), intent, options.toBundle());
                        }
                    });
                    holder.hasDetailLink = true;
                }

                // Overview (Title/Author, Status/Deadline)
                if (item.getTitle() != null && item.getAuthor() != null) {
                    holder.tvTitleAndAuthor.setText(item.getTitle() + ", " + item.getAuthor());
                } else if (item.getTitle() != null) {
                    holder.tvTitleAndAuthor.setText(item.getTitle());
                } else {
                    setTextOrHide(item.getAuthor(), holder.tvTitleAndAuthor);
                }

                DateTimeFormatter fmt = DateTimeFormat.shortDate();

                if (item.getDeadline() != null && item.getStatus() != null) {
                    holder.tvStatus.setText(
                            fmt.print(item.getDeadline()) + " (" + Html.fromHtml(item.getStatus()) + ")");
                } else if (item.getDeadline() != null) {
                    holder.tvStatus.setText(fmt.print(new LocalDate(item.getDeadline())));
                } else {
                    setHtmlTextOrHide(item.getStatus(), holder.tvStatus);
                }

                // Detail
                setTextOrHide(item.getAuthor(), holder.tvAuthorDetail);
                setHtmlTextOrHide(item.getFormat(), holder.tvFormatDetail);
                if (item.getLendingBranch() != null && item.getHomeBranch() != null) {
                    holder.tvBranchDetail
                            .setText(Html.fromHtml(item.getLendingBranch() + " / " + item.getHomeBranch()));
                } else if (item.getLendingBranch() != null) {
                    holder.tvBranchDetail.setText(Html.fromHtml(item.getLendingBranch()));
                } else {
                    setHtmlTextOrHide(item.getHomeBranch(), holder.tvBranchDetail);
                }

                // Color codes for return dates
                if (item.getDeadline() != null) {
                    if (item.getDeadline().equals(LocalDate.now())
                            || item.getDeadline().isBefore(LocalDate.now())) {
                        holder.vStatusColor.setBackgroundColor(getResources().getColor(R.color.date_overdue));
                    } else if (Days.daysBetween(LocalDate.now(), item.getDeadline()).getDays() <= tolerance) {
                        holder.vStatusColor.setBackgroundColor(getResources().getColor(R.color.date_warning));
                    } else if (item.getDownloadData() != null) {
                        holder.vStatusColor
                                .setBackgroundColor(getResources().getColor(R.color.account_downloadable));
                    }
                } else if (item.getDownloadData() != null) {
                    holder.vStatusColor
                            .setBackgroundColor(getResources().getColor(R.color.account_downloadable));
                }

                if (item.getProlongData() != null) {
                    holder.ivProlong.setTag(item.getProlongData());
                    holder.ivProlong.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View arg0) {
                            prolong((String) arg0.getTag());
                        }
                    });
                    holder.ivProlong.setVisibility(View.VISIBLE);
                    holder.ivProlong.setAlpha(item.isRenewable() ? 255 : 100);
                } else if (item.getDownloadData() != null && app.getApi() instanceof EbookServiceApi) {
                    holder.ivDownload.setTag(item.getDownloadData());
                    holder.ivDownload.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View arg0) {
                            download((String) arg0.getTag());
                        }
                    });
                    holder.ivProlong.setVisibility(View.GONE);
                    holder.ivDownload.setVisibility(View.VISIBLE);
                } else {
                    holder.ivProlong.setVisibility(View.INVISIBLE);
                }
                v.setTag(holder);
                return v;
            }

            @Override
            public void expandView(int position, View view) {
                LentViewHolder holder = (LentViewHolder) view.getTag();
                LentItem item = result.getLent().get(position);

                holder.llDetails.setVisibility(View.VISIBLE);
                setHtmlTextOrHide(item.getTitle(), holder.tvTitleAndAuthor);
                if (holder.hasDetailLink)
                    holder.ivDetails.setVisibility(View.VISIBLE);
            }

            @Override
            public void collapseView(int position, View view) {
                LentViewHolder holder = (LentViewHolder) view.getTag();
                LentItem item = result.getLent().get(position);

                holder.llDetails.setVisibility(View.GONE);
                if (item.getTitle() != null && item.getAuthor() != null) {
                    holder.tvTitleAndAuthor.setText(item.getTitle() + ", " + item.getAuthor());
                } else if (item.getAuthor() != null) {
                    holder.tvTitleAndAuthor.setText(item.getAuthor());
                    holder.tvTitleAndAuthor.setVisibility(View.VISIBLE);
                }
                holder.ivDetails.setVisibility(View.GONE);
            }

            @Override
            public int getCount() {
                return result.getLent().size();
            }
        };
        lentManager.setAnimationInterceptor(new ExpandingCardListManager.AnimationInterceptor() {
            private float llDataY;
            private float llDataTranslationY = 0;

            @Override
            public void beforeExpand(View unexpandedView) {
                LentViewHolder holder = (LentViewHolder) unexpandedView.getTag();
                llDataY = ViewHelper.getY(holder.llData);
            }

            @Override
            public Collection<Animator> getExpandAnimations(int heightDifference, View expandedView) {
                LentViewHolder holder = (LentViewHolder) expandedView.getTag();
                Collection<Animator> anims = getAnimations(-heightDifference, 0);
                // Animate buttons to the side
                int difference = 2 * (getResources().getDimensionPixelSize(R.dimen.card_side_margin_selected)
                        - getResources().getDimensionPixelSize(R.dimen.card_side_margin_default));
                anims.add(ObjectAnimator.ofFloat(holder.llButtons, "translationX", difference, 0));
                // Animate llData to the bottom if required
                if (ViewHelper.getY(holder.llData) != llDataY) {
                    ViewHelper.setY(holder.llData, llDataY);
                    llDataTranslationY = ViewHelper.getTranslationY(holder.llData);
                    anims.add(ObjectAnimator.ofFloat(holder.llData, "translationY", 0));
                } else {
                    llDataTranslationY = 0;
                }
                return anims;
            }

            @Override
            public Collection<Animator> getCollapseAnimations(int heightDifference, View expandedView) {
                LentViewHolder holder = (LentViewHolder) expandedView.getTag();
                Collection<Animator> anims = getAnimations(0, heightDifference);
                // Animate buttons back
                int difference = 2 * (getResources().getDimensionPixelSize(R.dimen.card_side_margin_selected)
                        - getResources().getDimensionPixelSize(R.dimen.card_side_margin_default));
                anims.add(ObjectAnimator.ofFloat(holder.llButtons, "translationX", 0, difference));
                // Animate llData back
                anims.add(ObjectAnimator.ofFloat(holder.llData, "translationY", llDataTranslationY));
                return anims;
            }

            @Override
            public void onCollapseAnimationEnd() {
                if (view.findViewById(R.id.rlMeta) != null) {
                    // tablet
                    ViewHelper.setTranslationY(view.findViewById(R.id.rlMeta), 0);
                } else {
                    // phone
                    ViewHelper.setTranslationY(tvResHeader, 0);
                    ViewHelper.setTranslationY(llRes, 0);
                    ViewHelper.setTranslationY(tvAge, 0);
                    ViewHelper.setTranslationY(view.findViewById(R.id.tvNoWarranty), 0);
                }
            }

            private Collection<Animator> getAnimations(float from, float to) {
                List<Animator> animators = new ArrayList<>();
                if (view.findViewById(R.id.rlMeta) != null) {
                    // tablet
                    if (result.getLent().size() >= result.getReservations().size()) {
                        animators.add(ObjectAnimator.ofFloat(view.findViewById(R.id.rlMeta), "translationY",
                                from, to));
                    }
                } else {
                    // phone
                    animators.add(ObjectAnimator.ofFloat(tvResHeader, "translationY", from, to));
                    animators.add(ObjectAnimator.ofFloat(llRes, "translationY", from, to));
                    animators.add(ObjectAnimator.ofFloat(tvAge, "translationY", from, to));
                    animators.add(ObjectAnimator.ofFloat(view.findViewById(R.id.tvNoWarranty), "translationY",
                            from, to));
                }
                return animators;
            }
        });

        for (final LentItem item : result.getLent()) {
            try {
                if (notification_on && item.getDeadline() == null && !item.isEbook()) {
                    notification_problems = true;
                }
            } catch (Exception e) {
                notification_problems = true;
            }
        }
    }

    if (notification_problems) {
        if (tvError != null) {
            tvError.setVisibility(View.VISIBLE);
            tvError.setText(R.string.notification_problems);
        }
    }

    /*
    Reservations
     */
    llRes.removeAllViews();
    if (result.getReservations().size() == 0) {
        TextView t1 = new TextView(getActivity());
        t1.setText(R.string.reservations_none);
        llRes.addView(t1);
        tvResHeader.setText(getActivity().getString(R.string.reservations_head) + " (0)");
    } else {
        tvResHeader.setText(getActivity().getString(R.string.reservations_head) + " ("
                + result.getReservations().size() + ")");
        resManager = new ExpandingCardListManager(getActivity(), llRes) {
            @Override
            public View getView(final int position, ViewGroup container) {
                final View v = getLayoutInflater(null).inflate(R.layout.listitem_account_reservation, llRes,
                        false);
                ReservationViewHolder holder = new ReservationViewHolder();
                holder.findViews(v);

                final ReservedItem item = result.getReservations().get(position);

                // Expanding and closing details
                v.setClickable(true);
                v.setFocusable(true);
                v.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (getExpandedPosition() != position) {
                            expand(position);
                        } else {
                            collapse();
                        }
                    }
                });

                if (item.getId() != null) {
                    // Connection to detail view
                    holder.ivDetails.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View clicked) {
                            Intent intent = new Intent(getActivity(), SearchResultDetailActivity.class);
                            intent.putExtra(SearchResultDetailFragment.ARG_ITEM_ID, item.getId());
                            ActivityOptionsCompat options = ActivityOptionsCompat.makeScaleUpAnimation(v,
                                    v.getLeft(), v.getTop(), v.getWidth(), v.getHeight());
                            ActivityCompat.startActivity(getActivity(), intent, options.toBundle());
                        }
                    });
                    holder.hasDetailLink = true;
                }

                // Overview (Title/Author, Ready/Expire)
                if (item.getTitle() != null && item.getAuthor() != null) {
                    holder.tvTitleAndAuthor.setText(item.getTitle() + ", " + item.getAuthor());
                } else if (item.getTitle() != null) {
                    holder.tvTitleAndAuthor.setText(item.getTitle());
                } else {
                    setTextOrHide(item.getAuthor(), holder.tvTitleAndAuthor);
                }

                DateTimeFormatter fmt = DateTimeFormat.shortDate();

                StringBuilder status = new StringBuilder();
                if (item.getStatus() != null)
                    status.append(item.getStatus());
                boolean needsBraces = item.getStatus() != null
                        && (item.getReadyDate() != null || item.getExpirationDate() != null);
                if (needsBraces)
                    status.append(" (");
                if (item.getReadyDate() != null) {
                    status.append(getString(R.string.reservation_expire_until)).append(" ")
                            .append(fmt.print(item.getReadyDate()));
                }
                if (item.getExpirationDate() != null) {
                    if (item.getReadyDate() != null)
                        status.append(", ");
                    status.append(fmt.print(item.getExpirationDate()));
                }
                if (needsBraces)
                    status.append(")");
                if (status.length() > 0) {
                    holder.tvStatus.setText(Html.fromHtml(status.toString()));
                } else {
                    holder.tvStatus.setVisibility(View.GONE);
                }

                // Detail
                setTextOrHide(item.getAuthor(), holder.tvAuthorDetail);
                setHtmlTextOrHide(item.getFormat(), holder.tvFormatDetail);
                setHtmlTextOrHide(item.getBranch(), holder.tvBranchDetail);

                if (item.getBookingData() != null) {
                    holder.ivBooking.setTag(item.getBookingData());
                    holder.ivBooking.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View arg0) {
                            bookingStart((String) arg0.getTag());
                        }
                    });
                    holder.ivBooking.setVisibility(View.VISIBLE);
                    holder.ivCancel.setVisibility(View.GONE);
                } else if (item.getCancelData() != null) {
                    holder.ivCancel.setTag(item.getCancelData());
                    holder.ivCancel.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View arg0) {
                            cancel((String) arg0.getTag());
                        }
                    });
                    holder.ivCancel.setVisibility(View.VISIBLE);
                    holder.ivBooking.setVisibility(View.GONE);
                } else {
                    holder.ivCancel.setVisibility(View.INVISIBLE);
                    holder.ivBooking.setVisibility(View.GONE);
                }
                v.setTag(holder);
                return v;
            }

            @Override
            public void expandView(int position, View view) {
                ReservationViewHolder holder = (ReservationViewHolder) view.getTag();
                ReservedItem item = result.getReservations().get(position);

                holder.llDetails.setVisibility(View.VISIBLE);
                setTextOrHide(item.getTitle(), holder.tvTitleAndAuthor);
                if (holder.hasDetailLink)
                    holder.ivDetails.setVisibility(View.VISIBLE);
            }

            @Override
            public void collapseView(int position, View view) {
                ReservationViewHolder holder = (ReservationViewHolder) view.getTag();
                ReservedItem item = result.getReservations().get(position);

                holder.llDetails.setVisibility(View.GONE);
                if (item.getTitle() != null && item.getAuthor() != null) {
                    holder.tvTitleAndAuthor.setText(item.getTitle() + ", " + item.getAuthor());
                } else if (item.getTitle() != null) {
                    holder.tvTitleAndAuthor.setText(item.getAuthor());
                    holder.tvTitleAndAuthor.setVisibility(View.VISIBLE);
                }
                holder.ivDetails.setVisibility(View.GONE);
            }

            @Override
            public int getCount() {
                return result.getReservations().size();
            }
        };
        resManager.setAnimationInterceptor(new ExpandingCardListManager.AnimationInterceptor() {
            private float llDataY;
            private float llDataTranslationY = 0;

            @Override
            public void beforeExpand(View unexpandedView) {
                ReservationViewHolder holder = (ReservationViewHolder) unexpandedView.getTag();
                llDataY = ViewHelper.getY(holder.llData);
            }

            @Override
            public Collection<Animator> getExpandAnimations(int heightDifference, View expandedView) {
                ReservationViewHolder holder = (ReservationViewHolder) expandedView.getTag();
                Collection<Animator> anims = getAnimations(-heightDifference, 0);
                // Animate buttons to the side
                int difference = 2 * (getResources().getDimensionPixelSize(R.dimen.card_side_margin_selected)
                        - getResources().getDimensionPixelSize(R.dimen.card_side_margin_default));
                anims.add(ObjectAnimator.ofFloat(holder.llButtons, "translationX", difference, 0));
                // Animate llData to the bottom if required
                if (ViewHelper.getY(holder.llData) != llDataY) {
                    ViewHelper.setY(holder.llData, llDataY);
                    llDataTranslationY = ViewHelper.getTranslationY(holder.llData);
                    anims.add(ObjectAnimator.ofFloat(holder.llData, "translationY", 0));
                } else {
                    llDataTranslationY = 0;
                }
                return anims;
            }

            @Override
            public Collection<Animator> getCollapseAnimations(int heightDifference, View expandedView) {
                ReservationViewHolder holder = (ReservationViewHolder) expandedView.getTag();
                Collection<Animator> anims = getAnimations(0, heightDifference);
                // Animate buttons back
                int difference = 2 * (getResources().getDimensionPixelSize(R.dimen.card_side_margin_selected)
                        - getResources().getDimensionPixelSize(R.dimen.card_side_margin_default));
                anims.add(ObjectAnimator.ofFloat(holder.llButtons, "translationX", 0, difference));
                // Animate llData back
                anims.add(ObjectAnimator.ofFloat(holder.llData, "translationY", llDataTranslationY));
                return anims;
            }

            @Override
            public void onCollapseAnimationEnd() {
                if (view.findViewById(R.id.rlMeta) != null) {
                    // tablet
                    ViewHelper.setTranslationY(view.findViewById(R.id.rlMeta), 0);
                } else {
                    // phone
                    ViewHelper.setTranslationY(tvAge, 0);
                    ViewHelper.setTranslationY(view.findViewById(R.id.tvNoWarranty), 0);
                }
            }

            private Collection<Animator> getAnimations(float from, float to) {
                List<Animator> animators = new ArrayList<>();
                if (view.findViewById(R.id.rlMeta) != null) {
                    // tablet
                    if (result.getReservations().size() >= result.getLent().size()) {
                        animators.add(ObjectAnimator.ofFloat(view.findViewById(R.id.rlMeta), "translationY",
                                from, to));
                    }
                } else {
                    // phone
                    animators.add(ObjectAnimator.ofFloat(tvAge, "translationY", from, to));
                    animators.add(ObjectAnimator.ofFloat(view.findViewById(R.id.tvNoWarranty), "translationY",
                            from, to));
                }
                return animators;
            }
        });
    }

    if (result.getPendingFees() != null) {
        tvPendingFeesLabel.setVisibility(View.VISIBLE);
        tvPendingFees.setVisibility(View.VISIBLE);
        tvPendingFees.setText(result.getPendingFees());
    } else {
        tvPendingFeesLabel.setVisibility(View.GONE);
        tvPendingFees.setVisibility(View.GONE);
    }
    if (result.getValidUntil() != null) {
        tvValidUntilLabel.setVisibility(View.VISIBLE);
        tvValidUntil.setVisibility(View.VISIBLE);
        tvValidUntil.setText(result.getValidUntil());
    } else {
        tvValidUntilLabel.setVisibility(View.GONE);
        tvValidUntil.setVisibility(View.GONE);
    }
    refreshage();
}

From source file:ca.appvelopers.mcgillmobile.ui.ScheduleActivity.java

/**
 * Fills the schedule based on given data
 *
 * @param timetableContainer Container for the timetable
 * @param scheduleContainer  Container for the schedule
 * @param date               Date to fill the schedule for
 * @param clickable          True if the user can click on the courses (portrait),
 *                           false otherwise (landscape)
 *///  w w  w  . j a v a2 s . c  o  m
private void fillSchedule(LinearLayout timetableContainer, LinearLayout scheduleContainer, LocalDate date,
        boolean clickable) {
    //Go through the list of courses, find which ones are for the given date
    List<Course> courses = new ArrayList<>();
    for (Course course : this.courses) {
        if (course.isForDate(date)) {
            courses.add(course);
        }
    }

    //Set up the DateTimeFormatter we're going to use for the hours
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern(twentyFourHourPref.get() ? "HH:mm" : "hh a");

    //This will be used of an end time of a course when it is added to the schedule container
    LocalTime currentCourseEndTime = null;

    //Cycle through the hours
    for (int hour = 8; hour < 22; hour++) {
        //Start inflating a timetable cell
        View timetableCell = View.inflate(this, R.layout.item_day_timetable, null);

        //Put the correct time
        TextView time = (TextView) timetableCell.findViewById(R.id.cell_time);
        time.setText(LocalTime.MIDNIGHT.withHour(hour).format(formatter));

        //Add it to the right container
        timetableContainer.addView(timetableCell);

        //Cycle through the half hours
        for (int min = 0; min < 31; min += 30) {
            //Initialize the current course to null
            Course currentCourse = null;

            //Get the current time
            LocalTime currentTime = LocalTime.of(hour, min);

            //if currentCourseEndTime = null (no course is being added) or it is equal to
            //the current time in min (end of a course being added) we need to add a new view
            if (currentCourseEndTime == null || currentCourseEndTime.equals(currentTime)) {
                //Reset currentCourseEndTime
                currentCourseEndTime = null;

                //Check if there is a course at this time
                for (Course course : courses) {
                    //If there is, set the current course to that time, and calculate the
                    //ending time of this course
                    if (course.getRoundedStartTime().equals(currentTime)) {
                        currentCourse = course;
                        currentCourseEndTime = course.getRoundedEndTime();
                        break;
                    }
                }

                View scheduleCell;

                //There is a course at this time
                if (currentCourse != null) {
                    //Inflate the right view
                    scheduleCell = View.inflate(this, R.layout.item_day_class, null);

                    //Set up all of the info
                    TextView code = (TextView) scheduleCell.findViewById(R.id.course_code);
                    code.setText(currentCourse.getCode());

                    TextView type = (TextView) scheduleCell.findViewById(R.id.course_type);
                    type.setText(currentCourse.getType());

                    TextView courseTime = (TextView) scheduleCell.findViewById(R.id.course_time);
                    courseTime.setText(currentCourse.getTimeString());

                    TextView location = (TextView) scheduleCell.findViewById(R.id.course_location);
                    location.setText(currentCourse.getLocation());

                    //Find out how long this course is in terms of blocks of 30 min
                    int length = (int) ChronoUnit.MINUTES.between(currentCourse.getRoundedStartTime(),
                            currentCourse.getRoundedEndTime()) / 30;

                    //Set the height of the view depending on this height
                    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
                            LinearLayout.LayoutParams.MATCH_PARENT,
                            (int) getResources().getDimension(R.dimen.cell_30min_height) * length);
                    scheduleCell.setLayoutParams(lp);

                    //Check if we need to make the course clickable
                    if (clickable) {
                        //We need a final variable for the onClick listener
                        final Course course = currentCourse;
                        //OnClick: CourseActivity (for a detailed description of the course)
                        scheduleCell.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                showCourseDialog(course);
                            }
                        });
                    } else {
                        scheduleCell.setClickable(false);
                    }

                } else {
                    //Inflate the empty view
                    scheduleCell = View.inflate(this, R.layout.item_day_empty, null);
                }

                //Add the given view to the schedule container
                scheduleContainer.addView(scheduleCell);
            }
        }
    }
}

From source file:com.breadwallet.tools.adapter.TransactionListAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup viewGroup) {
    View tmpLayout = inflater.inflate(R.layout.transaction_list_item, null);
    if (data.size() == 0 && position == 0) {
        RelativeLayout noTransactions = (RelativeLayout) inflater.inflate(R.layout.button_no_transactions,
                null);// w w w  .j av a 2 s.  co m
        noTransactions.setLayoutParams(new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                Utils.getPixelsFromDps(activity, 70)));
        return noTransactions;
    } else if (position == getCount() - (buyBitcoinEnabled ? 5 : 4)) {
        View separator = new View(activity);
        separator.setLayoutParams(new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                Utils.getPixelsFromDps(activity, 30)));
        separator.setBackgroundResource(android.R.color.transparent);
        return separator;
    } else if (buyBitcoinEnabled && position == getCount() - 4) {
        RelativeLayout buyBitcoinLayout = (RelativeLayout) inflater.inflate(R.layout.button_buy_bitcoin, null);
        buyBitcoinLayout.setLayoutParams(new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                Utils.getPixelsFromDps(activity, 50)));
        buyBitcoinLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (BRAnimator.checkTheMultipressingAvailability()) {
                    FragmentWebView fragmentWebView = new FragmentWebView();
                    fragmentWebView.setMode(1);
                    BRAnimator.animateSlideToLeft((MainActivity) activity, fragmentWebView,
                            FragmentSettingsAll.instantiate(activity, FragmentSettingsAll.class.getName()));
                }
            }
        });
        return buyBitcoinLayout;
    } else if (position == getCount() - 3) {
        RelativeLayout importPrivateKeys = (RelativeLayout) inflater.inflate(R.layout.button_import_privkey,
                null);
        importPrivateKeys.setLayoutParams(new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                Utils.getPixelsFromDps(activity, 50)));
        importPrivateKeys.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (BRAnimator.checkTheMultipressingAvailability()) {
                    BRAnimator.animateDecoderFragment();
                }
            }
        });
        return importPrivateKeys;

    } else if (position == getCount() - 2) {
        RelativeLayout settings = (RelativeLayout) inflater.inflate(R.layout.button_settings, null);
        settings.setLayoutParams(new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                Utils.getPixelsFromDps(activity, 50)));
        settings.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (BRAnimator.checkTheMultipressingAvailability()) {
                    MainActivity app = MainActivity.app;
                    if (app == null)
                        return;
                    FragmentSettingsAll fragmentSettingsAll = (FragmentSettingsAll) activity
                            .getFragmentManager().findFragmentByTag(FragmentSettingsAll.class.getName());
                    BRAnimator.animateSlideToLeft(app, new FragmentSettings(), fragmentSettingsAll);
                }
            }
        });
        return settings;
    } else if (position == getCount() - 1) {
        View separator = new View(activity);
        separator.setLayoutParams(new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                Utils.getPixelsFromDps(activity, 30)));
        separator.setBackgroundResource(android.R.color.transparent);
        separator.setClickable(false);
        return separator;
    }

    if (!BreadWalletApp.unlocked) {
        if (getUnconfirmedCount(data) == 0 && position == 0) {
            RelativeLayout txHistory = (RelativeLayout) inflater.inflate(R.layout.button_transaction_history,
                    null);
            txHistory.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    Utils.getPixelsFromDps(activity, 40)));
            txHistory.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (BRAnimator.checkTheMultipressingAvailability()) {
                        ((BreadWalletApp) activity.getApplicationContext()).promptForAuthentication(activity,
                                BRConstants.AUTH_FOR_GENERAL, null, null, null, null, false);
                    }
                }
            });
            return txHistory;
        } else {
            if (position == getUnconfirmedCount(data)) {
                RelativeLayout moreAuth = (RelativeLayout) inflater.inflate(R.layout.button_more, null);
                moreAuth.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                        Utils.getPixelsFromDps(activity, 40)));
                moreAuth.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (BRAnimator.checkTheMultipressingAvailability()) {
                            ((BreadWalletApp) activity.getApplicationContext()).promptForAuthentication(
                                    activity, BRConstants.AUTH_FOR_GENERAL, null, null, null, null, false);
                        }
                    }
                });
                return moreAuth;
            } else {
                return getTxView(tmpLayout, position);
            }
        }
    } else {
        if (showAllTx)
            return getTxView(tmpLayout, position);
        if (data.size() > 5) {
            if (position < 5) {
                return getTxView(tmpLayout, position);
            } else {
                RelativeLayout more = (RelativeLayout) inflater.inflate(R.layout.button_more, null);
                more.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                        Utils.getPixelsFromDps(activity, 40)));
                more.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        showAllTx = true;
                        notifyDataSetChanged();
                    }
                });
                return more;
            }
        } else {
            return getTxView(tmpLayout, position);
        }
    }
}

From source file:com.hughes.android.dictionary.DictionaryManagerActivity.java

private View createDictionaryRow(final DictionaryInfo dictionaryInfo, final ViewGroup parent,
        boolean canLaunch) {

    View row = LayoutInflater.from(parent.getContext()).inflate(R.layout.dictionary_manager_row, parent, false);
    final TextView name = (TextView) row.findViewById(R.id.dictionaryName);
    final TextView details = (TextView) row.findViewById(R.id.dictionaryDetails);
    name.setText(application.getDictionaryName(dictionaryInfo.uncompressedFilename));

    final boolean updateAvailable = application.updateAvailable(dictionaryInfo);
    final Button downloadButton = (Button) row.findViewById(R.id.downloadButton);
    final DictionaryInfo downloadable = application.getDownloadable(dictionaryInfo.uncompressedFilename);
    boolean broken = false;
    if (!dictionaryInfo.isValid()) {
        broken = true;/*from   ww w  . ja  va  2 s.  co m*/
        canLaunch = false;
    }
    if (downloadable != null && (!canLaunch || updateAvailable)) {
        downloadButton.setText(getString(R.string.downloadButton, downloadable.zipBytes / 1024.0 / 1024.0));
        downloadButton.setMinWidth(application.languageButtonPixels * 3 / 2);
        downloadButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                downloadDictionary(downloadable.downloadUrl, downloadable.zipBytes, downloadButton);
            }
        });
    } else {
        downloadButton.setVisibility(View.INVISIBLE);
    }

    LinearLayout buttons = (LinearLayout) row.findViewById(R.id.dictionaryLauncherButtons);
    final List<IndexInfo> sortedIndexInfos = application.sortedIndexInfos(dictionaryInfo.indexInfos);
    final StringBuilder builder = new StringBuilder();
    if (updateAvailable) {
        builder.append(getString(R.string.updateAvailable));
    }
    for (IndexInfo indexInfo : sortedIndexInfos) {
        final View button = application.createButton(buttons.getContext(), dictionaryInfo, indexInfo);
        buttons.addView(button);

        if (canLaunch) {
            button.setOnClickListener(new IntentLauncher(buttons.getContext(),
                    DictionaryActivity.getLaunchIntent(getApplicationContext(),
                            application.getPath(dictionaryInfo.uncompressedFilename), indexInfo.shortName,
                            "")));

        } else {
            button.setEnabled(false);
            button.setFocusable(false);
        }
        if (builder.length() != 0) {
            builder.append("; ");
        }
        builder.append(getString(R.string.indexInfo, indexInfo.shortName, indexInfo.mainTokenCount));
    }
    builder.append("; ");
    builder.append(getString(R.string.downloadButton, dictionaryInfo.uncompressedBytes / 1024.0 / 1024.0));
    if (broken) {
        name.setText("Broken: " + application.getDictionaryName(dictionaryInfo.uncompressedFilename));
        builder.append("; Cannot be used, redownload, check hardware/file system");
        // Allow deleting, but cannot open
        row.setLongClickable(true);
    }
    details.setText(builder.toString());

    if (canLaunch) {
        row.setClickable(true);
        row.setOnClickListener(new IntentLauncher(parent.getContext(),
                DictionaryActivity.getLaunchIntent(getApplicationContext(),
                        application.getPath(dictionaryInfo.uncompressedFilename),
                        dictionaryInfo.indexInfos.get(0).shortName, "")));
        // do not setFocusable, for keyboard navigation
        // offering only the index buttons is better.
        row.setLongClickable(true);
    }
    row.setBackgroundResource(android.R.drawable.menuitem_background);

    return row;
}