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.ubikod.capptain.android.sdk.reach.CapptainDefaultNotifier.java

@Override
public Boolean handleNotification(CapptainReachInteractiveContent content) throws RuntimeException {
    /* System notification case */
    if (content.isSystemNotification()) {
        /* Big picture handling */
        Bitmap bigPicture = null;//w  w  w  .j  ava  2s.  c o  m
        String bigPictureURL = content.getNotificationBigPicture();
        if (bigPictureURL != null && Build.VERSION.SDK_INT >= 16) {
            /* Schedule picture download if needed, or load picture if download completed. */
            Long downloadId = content.getDownloadId();
            if (downloadId == null) {
                NotificationUtilsV11.downloadBigPicture(mContext, content);
                return null;
            } else
                bigPicture = NotificationUtilsV11.getBigPicture(mContext, downloadId);
        }

        /* Generate notification identifier */
        int notificationId = getNotificationId(content);

        /* Build notification using support lib to manage compatibility with old Android versions */
        NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext);

        /* Icon for ticker and content icon */
        builder.setSmallIcon(mNotificationIcon);

        /*
         * Large icon, handled only since API Level 11 (needs down scaling if too large because it's
         * cropped otherwise by the system).
         */
        Bitmap notificationImage = content.getNotificationImage();
        if (notificationImage != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
            builder.setLargeIcon(scaleBitmapForLargeIcon(mContext, notificationImage));

        /* Texts */
        String notificationTitle = content.getNotificationTitle();
        String notificationMessage = content.getNotificationMessage();
        String notificationBigText = content.getNotificationBigText();
        builder.setContentTitle(notificationTitle);
        builder.setContentText(notificationMessage);

        /*
         * Replay: display original date and don't replay all the tickers (be as quiet as possible
         * when replaying).
         */
        Long notificationFirstDisplayedDate = content.getNotificationFirstDisplayedDate();
        if (notificationFirstDisplayedDate != null)
            builder.setWhen(notificationFirstDisplayedDate);
        else
            builder.setTicker(notificationTitle);

        /* Big picture */
        if (bigPicture != null)
            builder.setStyle(new BigPictureStyle().bigPicture(bigPicture).setBigContentTitle(notificationTitle)
                    .setSummaryText(notificationMessage));

        /* Big text */
        else if (notificationBigText != null)
            builder.setStyle(new BigTextStyle().bigText(notificationBigText));

        /* Vibration/sound if not a replay */
        if (notificationFirstDisplayedDate == null) {
            int defaults = 0;
            if (content.isNotificationSound())
                defaults |= Notification.DEFAULT_SOUND;
            if (content.isNotificationVibrate())
                defaults |= Notification.DEFAULT_VIBRATE;
            builder.setDefaults(defaults);
        }

        /* Launch the receiver on action */
        Intent actionIntent = new Intent(INTENT_ACTION_ACTION_NOTIFICATION);
        CapptainReachAgent.setContentIdExtra(actionIntent, content);
        actionIntent.putExtra(INTENT_EXTRA_NOTIFICATION_ID, notificationId);
        Intent intent = content.getIntent();
        if (intent != null)
            actionIntent.putExtra(INTENT_EXTRA_COMPONENT, intent.getComponent());
        actionIntent.setPackage(mContext.getPackageName());
        PendingIntent contentIntent = PendingIntent.getBroadcast(mContext, (int) content.getLocalId(),
                actionIntent, FLAG_CANCEL_CURRENT);
        builder.setContentIntent(contentIntent);

        /* Also launch receiver if the notification is exited (clear button) */
        Intent exitIntent = new Intent(INTENT_ACTION_EXIT_NOTIFICATION);
        exitIntent.putExtra(INTENT_EXTRA_NOTIFICATION_ID, notificationId);
        CapptainReachAgent.setContentIdExtra(exitIntent, content);
        exitIntent.setPackage(mContext.getPackageName());
        PendingIntent deleteIntent = PendingIntent.getBroadcast(mContext, (int) content.getLocalId(),
                exitIntent, FLAG_CANCEL_CURRENT);
        builder.setDeleteIntent(deleteIntent);

        /* Can be dismissed ? */
        Notification notification = builder.build();
        if (!content.isNotificationCloseable())
            notification.flags |= Notification.FLAG_NO_CLEAR;

        /* Allow overriding */
        if (onNotificationPrepared(notification, content))

            /*
             * Submit notification, replacing the previous one if any (this should happen only if the
             * application process is restarted).
             */
            mNotificationManager.notify(notificationId, notification);
    }

    /* Activity embedded notification case */
    else {
        /* Get activity */
        Activity activity = CapptainActivityManager.getInstance().getCurrentActivity().get();

        /* Cannot notify in app if no activity provided */
        if (activity == null)
            return false;

        /* Get notification area */
        String category = content.getCategory();
        int areaId = getInAppAreaId(category);
        View notificationAreaView = activity.findViewById(areaId);

        /* No notification area, check if we can install overlay */
        if (notificationAreaView == null) {
            /* Check overlay is not disabled in this activity */
            Bundle activityConfig = CapptainUtils.getActivityMetaData(activity);
            if (!activityConfig.getBoolean(METADATA_NOTIFICATION_OVERLAY, true))
                return false;

            /* Inflate overlay layout and get reference to notification area */
            View overlay = LayoutInflater.from(mContext).inflate(getOverlayLayoutId(category), null);
            activity.addContentView(overlay, new LayoutParams(MATCH_PARENT, MATCH_PARENT));
            notificationAreaView = activity.findViewById(areaId);
        }

        /* Otherwise check if there is an overlay containing the area to restore visibility */
        else {
            View overlay = activity.findViewById(getOverlayViewId(category));
            if (overlay != null)
                overlay.setVisibility(View.VISIBLE);
        }

        /* Make the notification area visible */
        notificationAreaView.setVisibility(View.VISIBLE);

        /* Prepare area */
        prepareInAppArea(content, notificationAreaView);
    }

    /* Success */
    return true;
}

From source file:org.mythtv.client.ui.dvr.EpisodeFragment.java

public void loadEpisode(int channelId, DateTime startTime) {
    Log.v(TAG, "loadEpisode : enter");

    mLocationProfile = mLocationProfileDaoHelper.findConnectedProfile(getActivity());

    Log.v(TAG, "loadEpisode : channelId=" + channelId + ", startTime="
            + DateUtils.dateTimeFormatterPretty.print(startTime));
    program = mRecordedDaoHelper.findOne(getActivity(), mLocationProfile, channelId, startTime);
    if (null != program) {
        Log.v(TAG, "loadEpisode : program found");

        LiveStreamInfo liveStreamInfo = mLiveStreamDaoHelper.findByProgram(getActivity(), mLocationProfile,
                program);//w w  w. ja  v a  2s .  c  o m
        if (null != liveStreamInfo) {
            Log.v(TAG, "loadEpisode : program has livestream");

            if (liveStreamInfo.getPercentComplete() < 100) {
                Log.v(TAG, "loadEpisode : livestream is not complete, start update");

                startUpdateStreamService();
            }

        }

        // get activity to grab views from
        Activity activity = this.getActivity();

        // coverart
        final ImageView iView = (ImageView) activity.findViewById(R.id.imageView_episode_coverart);
        iView.setImageDrawable(null);

        if (null != program.getInetref() && !"".equals(program.getInetref())) {

            String imageUri = mLocationProfile.getUrl() + "Content/GetRecordingArtwork?Type=Coverart&Inetref="
                    + program.getInetref();
            imageLoader.displayImage(imageUri, iView, options, new SimpleImageLoadingListener() {

                /* (non-Javadoc)
                 * @see com.nostra13.universalimageloader.core.assist.SimpleImageLoadingListener#onLoadingComplete(android.graphics.Bitmap)
                 */
                @Override
                public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                    iView.setVisibility(View.VISIBLE);
                }

                /* (non-Javadoc)
                 * @see com.nostra13.universalimageloader.core.assist.SimpleImageLoadingListener#onLoadingFailed(com.nostra13.universalimageloader.core.assist.FailReason)
                 */
                @Override
                public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
                    if (options.shouldShowImageOnFail()) {
                        iView.setImageResource(options.getImageOnFail());
                        iView.setVisibility(View.VISIBLE);
                    } else {
                        iView.setVisibility(View.GONE);
                    }
                }

            });

        } else {

            if (options.shouldShowImageOnFail()) {
                iView.setImageResource(options.getImageOnFail());
                iView.setVisibility(View.VISIBLE);
            } else {
                iView.setVisibility(View.GONE);
            }

        }

        // title
        TextView tView = (TextView) activity.findViewById(R.id.textView_episode_title);
        tView.setText(program.getTitle());

        // subtitle
        tView = (TextView) activity.findViewById(R.id.textView_episode_subtitle);
        tView.setText(program.getSubTitle());

        // description
        tView = (TextView) activity.findViewById(R.id.textView_episode_description);
        tView.setText(program.getDescription());

        // channel number
        tView = (TextView) activity.findViewById(R.id.textView_episode_ch_num);
        tView.setText(program.getChannelInfo().getChannelNumber());

        // airdate
        tView = (TextView) activity.findViewById(R.id.textView_episode_airdate);
        tView.setText(DateUtils.getDateTimeUsingLocaleFormattingPretty(program.getStartTime(),
                getMainApplication().getDateFormat(), getMainApplication().getClockType()));

        if (null == hlsView) {
            hlsView = (TextView) activity.findViewById(R.id.textView_episode_hls);
        }

        updateHlsDetails();
    }

    Log.v(TAG, "loadEpisode : exit");
}

From source file:com.breadwallet.BreadWalletApp.java

/**
 * Shows a custom toast using the given string as a paramater,
 *
 * @param message the message to be shown in the custom toast
 *///from  ww  w .j a va2s  .  co m

public void showCustomToast(Activity app, String message, int yOffSet, int duration, int color) {
    if (toast == null)
        toast = new Toast(getApplicationContext());
    if (MainActivity.appInBackground)
        return;

    if (customToastAvailable || !oldMessage.equals(message)) {
        oldMessage = message;
        customToastAvailable = false;
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                customToastAvailable = true;
            }
        }, 1000);
        LayoutInflater inflater = app.getLayoutInflater();
        View layout = inflater.inflate(R.layout.toast, (ViewGroup) app.findViewById(R.id.toast_layout_root));
        if (color == 1) {
            layout.setBackgroundResource(R.drawable.toast_layout_black);
        }
        TextView text = (TextView) layout.findViewById(R.id.toast_text);
        text.setText(message);
        toast.setGravity(Gravity.BOTTOM, 0, yOffSet);
        toast.setDuration(duration);
        toast.setView(layout);
        toast.show();
    }
}

From source file:com.google.zxing.client.android.result.ResultHandler.java

ResultHandler(Activity activity, ParsedResult result, Result rawResult) {
    this.result = result;
    this.activity = activity;
    this.rawResult = rawResult;
    this.customProductSearch = parseCustomSearchURL();

    // Make sure the Shopper button is hidden by default. Without this, scanning a product followed
    // by a QR Code would leave the button on screen among the QR Code actions.
    View shopperButton = activity.findViewById(R.id.shopper_button);
    shopperButton.setVisibility(View.GONE);
}

From source file:org.schabi.newpipe.VideoItemDetailFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceBundle) {
    super.onActivityCreated(savedInstanceBundle);
    Activity a = getActivity();
    if (android.os.Build.VERSION.SDK_INT < 18) {
        playVideoButton = (FloatingActionButton) a.findViewById(R.id.playVideoButton);
    }/*  www.  ja va  2 s  . c om*/
    thumbnailWindowLayout = a.findViewById(R.id.detailVideoThumbnailWindowLayout);
    Button backgroundButton = (Button) a.findViewById(R.id.detailVideoThumbnailWindowBackgroundButton);

    // Sometimes when this fragment is not visible it still gets initiated
    // then we must not try to access objects of this fragment.
    // Otherwise the applications would crash.
    if (backgroundButton != null) {
        try {
            streamingServiceId = getArguments().getInt(STREAMING_SERVICE);
            StreamingService streamingService = ServiceList.getService(streamingServiceId);
            Thread videoExtractorThread = new Thread(
                    new VideoExtractorRunnable(getArguments().getString(VIDEO_URL), streamingService));

            autoPlayEnabled = getArguments().getBoolean(AUTO_PLAY);
            videoExtractorThread.start();
        } catch (Exception e) {
            e.printStackTrace();
        }

        if (Build.VERSION.SDK_INT >= 18) {
            ImageView thumbnailView = (ImageView) activity.findViewById(R.id.detailThumbnailView);
            thumbnailView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
                // This is used to synchronize the thumbnailWindowButton and the playVideoButton
                // inside the ScrollView with the actual size of the thumbnail.
                //todo: onLayoutChage sometimes not triggered
                // background buttons area seem to overlap the thumbnail view
                // So although you just clicked slightly beneath the thumbnail the action still
                // gets triggered.
                @Override
                public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft,
                        int oldTop, int oldRight, int oldBottom) {
                    RelativeLayout.LayoutParams newWindowLayoutParams = (RelativeLayout.LayoutParams) thumbnailWindowLayout
                            .getLayoutParams();
                    newWindowLayoutParams.height = bottom - top;
                    thumbnailWindowLayout.setLayoutParams(newWindowLayoutParams);

                    //noinspection SuspiciousNameCombination
                    initialThumbnailPos.set(top, left);

                }
            });
        }
    }
}

From source file:nz.ac.auckland.lablet.ExperimentRunViewManager.java

public ExperimentRunViewManager(final Activity activity, final int maxNumberOfRuns,
        final Experiment experiment) {
    this.experiment = experiment;

    // disable the selection layout for now
    View runSelectionLayout = activity.findViewById(R.id.runSelectionLayout);
    runSelectionLayout.setVisibility(View.INVISIBLE);
    addRunButton = (ImageButton) activity.findViewById(R.id.addRunButton);
    nextRunButton = (Button) activity.findViewById(R.id.nextButton);
    prevRunButton = (Button) activity.findViewById(R.id.prevButton);
    runView = (TextView) activity.findViewById(R.id.runGroupView);

    addRunButton.setOnClickListener(new View.OnClickListener() {
        @Override/*  ww w  .  j ava2  s .  c om*/
        public void onClick(View view) {
            ExperimentRun oldGroup = experiment.getCurrentExperimentRun();
            List<String> experimentNamesList = new ArrayList<>();
            for (IExperimentSensor experimentRun : oldGroup.getExperimentSensors())
                experimentNamesList.add(experimentRun.getClass().getSimpleName());
            ExperimentRun experimentRun = ExperimentRun.createExperimentRun(experimentNamesList);

            experiment.addExperimentRun(experimentRun);
            setCurrentExperimentRunGroup(experimentRun);

            if (maxNumberOfRuns > 0) {
                // check if we have the maximal number of runs
                List<ExperimentRun> runGroups = experiment.getExperimentRuns();
                if (runGroups.size() >= maxNumberOfRuns)
                    addRunButton.setEnabled(false);
            }
        }
    });

    nextRunButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            List<ExperimentRun> runGroups = experiment.getExperimentRuns();
            int index = runGroups.indexOf(experiment.getCurrentExperimentRun());
            index++;
            if (index >= runGroups.size())
                return;
            setCurrentExperimentRunGroup(runGroups.get(index));
        }
    });

    prevRunButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            List<ExperimentRun> runGroups = experiment.getExperimentRuns();
            int index = runGroups.indexOf(experiment.getCurrentExperimentRun());
            index--;
            if (index < 0)
                return;
            setCurrentExperimentRunGroup(runGroups.get(index));
        }
    });

    experiment.addListener(experimentListener);

    if (maxNumberOfRuns == 1)
        setVisibility(View.INVISIBLE);

    updateViews();
}

From source file:com.haofeng.superne.thirdparty.crouton.Manager.java

@TargetApi(19)
private void handleTranslucentActionBar(ViewGroup.MarginLayoutParams params, Activity activity) {
    // Translucent status is only available as of Android 4.4 Kit Kat.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        final int flags = activity.getWindow().getAttributes().flags;
        final int translucentStatusFlag = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
        /* Checks whether translucent status is enabled for this window.
         * If true, sets the top margin to show the crouton just below the action bar. */
        if ((flags & translucentStatusFlag) == translucentStatusFlag) {
            final int actionBarContainerId = Resources.getSystem().getIdentifier("action_bar_container", "id",
                    "android");
            final View actionBarContainer = activity.findViewById(actionBarContainerId);
            // The action bar is present: the app is using a Holo theme.
            if (actionBarContainer != null) {
                final ViewGroup.MarginLayoutParams marginParams = (ViewGroup.MarginLayoutParams) params;
                marginParams.topMargin = actionBarContainer.getBottom();
            }/* w  w  w.j a  v  a 2 s . c om*/
        }
    }
}

From source file:com.arta.lib.widget.crouton.Manager.java

@TargetApi(19)
private void handleTranslucentActionBar(ViewGroup.MarginLayoutParams params, Activity activity) {
    // Translucent status is only available as of Android 4.4 Kit Kat.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        final int flags = activity.getWindow().getAttributes().flags;
        final int translucentStatusFlag = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
        /* Checks whether translucent status is enabled for this window.
        * If true, sets the top margin to show the crouton just below the action bar. */
        if ((flags & translucentStatusFlag) == translucentStatusFlag) {
            final int actionBarContainerId = Resources.getSystem().getIdentifier("action_bar_container", "id",
                    "android");
            final View actionBarContainer = activity.findViewById(actionBarContainerId);
            // The action bar is present: the app is using a Holo theme.
            if (actionBarContainer != null) {
                final ViewGroup.MarginLayoutParams marginParams = (ViewGroup.MarginLayoutParams) params;
                marginParams.topMargin = actionBarContainer.getBottom();
            }//from www  . j ava2s  .  c o  m
        }
    }
}

From source file:com.juick.android.ThreadFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    try {/*from   w  ww.j  a v a 2s  .co  m*/
        parentActivity = (ThreadFragmentListener) activity;
        navMenu = (MyImageView) activity.findViewById(R.id.navmenu);
        if (navMenu != null) {
            navMenu.setVisibility(View.GONE);
            initNavMenuTranslationX = navMenu.initialTranslationX;
            FlyingItem top = new FlyingItem(activity.getWindow().getDecorView(), R.id.navbar_top);
            FlyingItem bottom = new FlyingItem(activity.getWindow().getDecorView(), R.id.navbar_bottom);
            flyingItems = new FlyingItem[] { top, bottom };
        }
    } catch (ClassCastException e) {
        throw new ClassCastException(activity.toString() + " must implement ThreadFragmentListener");
    }
}

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

/**
 * Set the passed Activity background based on user preferences
 *//*from  w  w  w. j a  va2s . c o  m*/
public static void initBackground(int bgResource, Activity a, boolean bright) {
    initBackground(bgResource, a.findViewById(R.id.root), bright);
}