Example usage for android.app Activity findViewById

List of usage examples for android.app Activity findViewById

Introduction

In this page you can find the example usage for android.app Activity findViewById.

Prototype

@Nullable
public <T extends View> T findViewById(@IdRes int id) 

Source Link

Document

Finds a view that was identified by the android:id XML attribute that was processed in #onCreate .

Usage

From source file:com.eleybourn.bookcatalogue.utils.Utils.java

/**
 * Set the passed Activity background based on user preferences
 *///  w ww  .ja  v a2  s. co  m
public static void initBackground(int bgResource, Activity a, int rootId, boolean bright) {
    initBackground(bgResource, a.findViewById(rootId), bright);
}

From source file:dev.drsoran.moloko.fragments.TagCloudFragment.java

private void showTagCloudEntries(final List<TagCloudEntry> cloudEntries) {
    final Activity activity = getSherlockActivity();

    // Sort all cloud entries by their name
    Collections.sort(cloudEntries);

    final int size = cloudEntries.size();
    final List<Button> buttons = new ArrayList<Button>(size);

    for (int i = 0; i < size; ++i) {
        final TagCloudEntry cloudEntry = cloudEntries.get(i);

        final Button cloudEntryButton = new Button(activity);
        cloudEntryButton.setId(i);//w ww  .  jav  a2  s. com
        cloudEntryButton.setText(cloudEntry.name);
        cloudEntryButton.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18 * getMagnifyFactor(cloudEntry.count));

        cloudEntry.present(cloudEntryButton);
        cloudEntry.setTagCloudFragmentListener(listener);

        if (cloudEntry.count > 1) {
            cloudEntryButton.setTypeface(Typeface.DEFAULT_BOLD);
        }

        buttons.add(cloudEntryButton);
    }

    final ViewGroup tagContainer = (ViewGroup) activity.findViewById(R.id.tagcloud_container);

    addButtons(buttons, tagContainer);
}

From source file:mobi.cangol.mobile.navigation.DrawerMenuLayout.java

public void attachToActivity(Activity activity, boolean isFloatActionBarEnabled) {
    // get the window background
    TypedArray a = activity.getTheme().obtainStyledAttributes(new int[] { android.R.attr.windowBackground });
    int background = a.getResourceId(0, 0);
    a.recycle();/*from   w w w  . j  ava 2  s. com*/

    this.isFloatActionBarEnabled = isFloatActionBarEnabled;

    if (isFloatActionBarEnabled) {
        ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
        ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
        if (decorChild.getBackground() != null) {
            this.setBackgroundDrawable(decorChild.getBackground());
            decorChild.setBackgroundDrawable(null);
        } else {
            if (this.getBackground() == null)
                this.setBackgroundResource(background);
        }
        decor.removeView(decorChild);
        decor.addView(this, 0);
        getContentView().addView(decorChild);
    } else {
        ViewGroup contentParent = (ViewGroup) activity.findViewById(android.R.id.content);
        ViewGroup content = (ViewGroup) contentParent.getChildAt(0);
        contentParent.removeView(content);
        contentParent.addView(this, 0);
        getContentView().addView(content);
    }
}

From source file:org.creativecommons.thelist.fragments.MyListFragment.java

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

    mContext = getActivity();/*from   w  w w  .ja  va 2s  .  c  o m*/
    Activity activity = getActivity();

    //Helpers
    mMessageHelper = new MessageHelper(mContext);
    mRequestMethods = new RequestMethods(mContext);
    mSharedPref = new SharedPreferencesMethods(mContext);
    mCurrentUser = new ListUser(getActivity());

    //Load UI Elements
    snackbarContainer = (ViewGroup) activity.findViewById(R.id.snackbar_container);
    mProgressBar = (ProgressBar) activity.findViewById(R.id.feedProgressBar);
    mUploadProgressBarContainer = (RelativeLayout) activity.findViewById(R.id.photoProgressBar);
    //mUploadProgressBar = (com.gc.materialdesign.views.ProgressBarDeterminate) activity.findViewById(R.id.upload_progress);
    //mUploadText = (TextView) activity.findViewById(R.id.upload_text);

    mEmptyView = (TextView) activity.findViewById(R.id.empty_list_label);

    mFab = (FloatingActionButton) activity.findViewById(R.id.fab);
    //mFab.setEnabled(false);
    mFab.setVisibility(View.GONE);
    mFab.hide();

    mFab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            if (!NetworkUtils.isNetworkAvailable(mContext)) {
                mMessageHelper.toastNeedInternet();
                return;
            }

            Intent hitMeIntent = new Intent(getActivity(), RandomActivity.class);
            startActivity(hitMeIntent);

        } //onClick
    });

    //RecyclerView
    mSwipeRefreshLayout = (SwipeRefreshLayout) activity.findViewById(R.id.feedSwipeRefresh);
    mRecyclerView = (RecyclerView) activity.findViewById(R.id.feedRecyclerView);
    mRecyclerView.setItemAnimator(new DefaultItemAnimator());
    //TODO: Try dividers in layout instead?
    RecyclerView.ItemDecoration itemDecoration = new DividerItemDecoration(activity,
            DividerItemDecoration.VERTICAL_LIST);
    mRecyclerView.addItemDecoration(itemDecoration);
    mLayoutManager = new LinearLayoutManager(mContext);
    mFeedAdapter = new UserListAdapter(mContext, mItemList);
    mRecyclerView.setAdapter(mFeedAdapter);
    mRecyclerView.setLayoutManager(mLayoutManager);
    mRecyclerView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
    initRecyclerView();

    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            displayUserItems();
        }
    });

}

From source file:mobi.cangol.mobile.navigation.SlidingMenuLayout.java

public void attachToActivity(Activity activity, boolean isFloatActionBarEnabled) {
    // get the window background
    TypedArray a = activity.getTheme().obtainStyledAttributes(new int[] { android.R.attr.windowBackground });
    int background = a.getResourceId(0, 0);
    a.recycle();/*  ww w . j a va 2  s.c om*/

    this.isFloatActionBarEnabled = isFloatActionBarEnabled;

    if (isFloatActionBarEnabled) {
        ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
        ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
        if (decorChild.getBackground() != null) {
            this.setBackgroundDrawable(decorChild.getBackground());
            decorChild.setBackgroundDrawable(null);
        } else {
            if (this.getBackground() == null)
                this.setBackgroundResource(background);
        }
        decor.removeView(decorChild);
        decor.addView(this.getRootView(), 0);
        getContentView().addView(decorChild);
    } else {
        ViewGroup contentParent = (ViewGroup) activity.findViewById(android.R.id.content);
        ViewGroup content = (ViewGroup) contentParent.getChildAt(0);
        contentParent.removeView(content);
        contentParent.addView(this, 0);
        getContentView().addView(content);
    }
}

From source file:tv.ouya.sdk.CordovaOuyaPlugin.java

protected void setSafeArea(CallbackContext callback, final float progress) {
    final Activity activity = cordova.getActivity();
    if (null != activity) {
        Runnable runnable = new Runnable() {
            public void run() {
                // bring in by %
                float percent = 0.1f;
                float ratio = 1 - (1 - progress) * percent;
                float halfRatio = 1 - (1 - progress) * percent * 0.5f;
                float maxWidth = getDisplayWidth();
                float maxHeight = getDisplayHeight();
                FrameLayout content = (FrameLayout) activity.findViewById(android.R.id.content);
                ViewGroup.LayoutParams layout = content.getLayoutParams();
                layout.width = (int) (maxWidth * ratio);
                layout.height = (int) (maxHeight * ratio);
                content.setLayoutParams(layout);
                content.setX(maxWidth - maxWidth * halfRatio);
                content.setY(maxHeight - maxHeight * halfRatio);
            }//from ww w .j  a v a 2s. c  o  m
        };
        activity.runOnUiThread(runnable);
    }
    callback.success();
}

From source file:dentex.youtube.downloader.DashboardActivity.java

public static void showEmptyListInfo(Activity activity) {
    TextView info = (TextView) activity.findViewById(R.id.dashboard_activity_info);
    info.setVisibility(View.VISIBLE);
    //Utils.logger("v", "__dashboard is empty__", DEBUG_TAG);
}

From source file:jp.mixi.android.sdk.MixiContainerImpl.java

@Override
public void setupAd(Activity activity, AdParameter param) {
    WebView view = (WebView) activity.findViewById(R.id.webview);
    // view ??????????
    if (view == null) {
        Log.w(TAG, "webview not found.");
        return;/* w w w  .jav a2  s  . c  o m*/
    }
    view.setWebViewClient(new MapWebViewClient(activity));
    if (param == null || param.headerPath == null) {
        Log.w(TAG, "path is null.");
        return;
    }
    view.loadUrl(param.headerPath);
    // ?????
    if (mSelector == Config.APPLICATION) {
        setupAppCounter();
    }
}

From source file:com.geecko.QuickLyric.adapter.IntroScreenSlidePagerAdapter.java

public IntroScreenSlidePagerAdapter(FragmentManager fm, final Activity activity) {
    super(fm);/*from   w ww. ja v a2  s.  c om*/
    this.mActivity = activity;
    mPager = ((ViewPager) mActivity.findViewById(R.id.pager));
    mPager.setOnTouchListener(exitTouchListener);
    if (Build.VERSION.SDK_INT >= 17)
        rightToLeft = TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()) == 1;
    if (rightToLeft) {
        List<Integer> list = Arrays.asList(colors);
        Collections.reverse(list);
        colors = (Integer[]) list.toArray();
    }
    ImageButton pagerArrow = ((ImageButton) mActivity.findViewById(R.id.pager_arrow));
    Button okButton = ((Button) mActivity.findViewById(R.id.pager_ok));
    okButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && !Tutorial_5.nlEnabled) {
                final ViewGroup nlFrame = (ViewGroup) activity.findViewById(R.id.NL_frame);
                final ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(),
                        Color.parseColor("#30000000"), Color.parseColor("#80FFFFFF"));
                colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                    @Override
                    public void onAnimationUpdate(ValueAnimator animation) {
                        nlFrame.setBackgroundColor((int) animation.getAnimatedValue());
                    }
                });
                colorAnimation.setInterpolator(new LinearOutSlowInInterpolator());
                colorAnimation.setRepeatCount(3);
                colorAnimation.setRepeatMode(ValueAnimator.REVERSE);
                colorAnimation.setDuration(650L);
                colorAnimation.start();
            } else if (!hasClicked) {
                exitAction();
                hasClicked = true;
            }
        }
    });
    pagerArrow.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            nextAction();
        }
    });
}

From source file:com.av.remusic.fragmentnet.ArtistInfoMusicFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_recyclerview, container, false);

    if (getArguments() != null) {
        mList = getArguments().getParcelableArrayList("list");
    }// w ww  .j  a v a  2s.co m
    Activity parentActivity = getActivity();
    recyclerView = (ObservableRecyclerView) view.findViewById(R.id.scroll);
    recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
    recyclerView.setHasFixedSize(true);
    mAdapter = new PlaylistDetailAdapter(getActivity(), mList);
    recyclerView.setAdapter(mAdapter);

    if (parentActivity instanceof ObservableScrollViewCallbacks) {
        // Scroll to the specified offset after layout
        Bundle args = getArguments();
        if (args != null && args.containsKey(ARG_INITIAL_POSITION)) {
            final int initialPosition = args.getInt(ARG_INITIAL_POSITION, 0);
            ScrollUtils.addOnGlobalLayoutListener(recyclerView, new Runnable() {
                @Override
                public void run() {
                    //  recyclerView.scrollVerticallyToPosition(0);
                }
            });
        }

        // TouchInterceptionViewGroup should be a parent view other than ViewPager.
        // This is a workaround for the issue #117:
        // https://github.com/ksoichiro/Android-ObservableScrollView/issues/117
        recyclerView.setTouchInterceptionViewGroup((ViewGroup) parentActivity.findViewById(R.id.root));

        recyclerView.setScrollViewCallbacks((ObservableScrollViewCallbacks) parentActivity);
    }
    return view;
}