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:edu.utexas.cs.bevomaps.MapDrawerVC.java

private void displaceIfNeeded(Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        int id = activity.getResources().getIdentifier("status_bar_height", "dimen", "android");
        if (id > 0) {
            View searchBox = activity.findViewById(R.id.drawer_header);
            ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) searchBox.getLayoutParams();

            params.topMargin = activity.getResources().getDimensionPixelSize(id);
            searchBox.setLayoutParams(params);
        }//from   ww w.j  a v  a 2s  . com
    }
}

From source file:com.brq.wallet.activity.main.BalanceMasterFragment.java

@Override
public void onResume() {
    Activity activity = getActivity();
    // Set beta build
    PackageInfo pInfo;/*w  w w  . j a va  2s .  co  m*/
    try {
        pInfo = activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0);
        ((TextView) activity.findViewById(R.id.tvBuildText))
                .setText(getResources().getString(R.string.build_text, pInfo.versionName));
    } catch (NameNotFoundException e) {
        // Ignore
        //todo insert uncaught error handler
    }

    MbwManager mbwManager = MbwManager.getInstance(activity);
    tvTor = (TextView) activity.findViewById(R.id.tvTorState);
    if (mbwManager.getTorMode() == ServerEndpointType.Types.ONLY_TOR && mbwManager.getTorManager() != null) {
        tvTor.setVisibility(View.VISIBLE);
        showTorState(mbwManager.getTorManager().getInitState());
    } else {
        tvTor.setVisibility(View.GONE);
    }

    MbwManager.getInstance(this.getActivity()).getEventBus().register(this);
    super.onResume();
}

From source file:mobile.client.iot.pzalejko.iothome.mqtt.event.InEventReceiver.java

public InEventReceiver(Activity context, LocalBroadcastManager broadcaster, MqttServiceConnection connection) {
    this.connection = connection;
    this.broadcaster = broadcaster;

    temperatureView = (TextView) context.findViewById(R.id.temperatureTextView);
    connectingTextView = (TextView) context.findViewById(R.id.connectingTextView);
    ledImageView = (ImageView) context.findViewById(R.id.ledImageView);
    temperatureAlertView = (TextView) context.findViewById(R.id.tempAlertValueText);

    if (temperatureAlertView == null) {
        throw new IllegalStateException(context.getString(R.string.temperature_view_missing));
    }//from w ww  . ja v  a  2  s  .  c  o  m

    if (connectingTextView == null) {
        throw new IllegalStateException(context.getString(R.string.connecting_status_view_missing));
    }

    if (ledImageView == null) {
        throw new IllegalStateException(context.getString(R.string.led_status_view_missing));
    }

    if (temperatureAlertView == null) {
        throw new IllegalStateException(context.getString(R.string.temperature_alert_view_missing));
    }

    dateFormat = new SimpleDateFormat(context.getString(R.string.dateFormat));
    isAlertValueObtained = false;
}

From source file:br.com.viniciuscr.notification2android.mediaPlayer.MusicUtils.java

static void processTabClick(Activity a, View v, int current) {
    int id = v.getId();
    if (id == current) {
        return;/* ww w  . ja va 2s. c om*/
    }

    final TabWidget ll = (TabWidget) a.findViewById(R.id.buttonbar);

    activateTab(a, id);
    if (id != R.id.nowplaying) {
        ll.setCurrentTab((Integer) v.getTag());
        setIntPref(a, "activetab", id);
    }
}

From source file:com.nikhilnayak.games.octoshootar.ui.fragments.GameHomeFragment.java

private void notifySignedStateChanged(boolean signedIn, boolean forceRefreshState, View rootView) {
    if (forceRefreshState || signedIn != mSignedIn) {
        final View signIn;
        final View signOut;
        final View signInInfo;
        if (rootView == null) {
            final Activity activity = getActivity();
            signIn = activity.findViewById(R.id.home_sign_in);
            signOut = activity.findViewById(R.id.home_sign_out);
            signInInfo = activity.findViewById(R.id.google_signin_info);
        } else {//from   w  w w .  j  a v a2 s .  c om
            signIn = rootView.findViewById(R.id.home_sign_in);
            signOut = rootView.findViewById(R.id.home_sign_out);
            signInInfo = rootView.findViewById(R.id.google_signin_info);
        }
        if (signedIn) {
            signIn.setVisibility(View.GONE);
            signInInfo.setVisibility(View.GONE);
            signOut.setVisibility(View.VISIBLE);
        } else {
            signOut.setVisibility(View.GONE);
            signIn.findViewById(R.id.home_sign_in).setVisibility(View.VISIBLE);
            signInInfo.setVisibility(View.VISIBLE);
        }
        mSignedIn = signedIn;
    }
}

From source file:com.ultramegasoft.flavordex2.fragment.CatListFragment.java

/**
 * Set up the list Toolbar./*  w  w  w. ja  va2 s . c om*/
 */
private void setupToolbar() {
    final Activity activity = getActivity();
    if (activity == null) {
        return;
    }

    final Toolbar toolbar = activity.findViewById(R.id.list_toolbar);
    if (toolbar != null) {
        toolbar.getMenu().clear();
        toolbar.inflateMenu(R.menu.cat_list_menu);
        toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                return onOptionsItemSelected(item);
            }
        });
        toolbar.setNavigationIcon(null);
        toolbar.setTitle(R.string.title_categories);
    } else {
        final ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(false);
            actionBar.setSubtitle(R.string.title_categories);
        }
        setHasOptionsMenu(true);
    }
}

From source file:de.wikilab.android.friendica01.Max.java

/**
* Calls the api method <code>verify_credentials</code> with the login data
 * saved in the <code>SharedPreferences</code>. Calls ctx.OnLogin on success,
 * showLoginForm(ctx, "error") on error/*w  ww . j a v a  2s  .  c  o  m*/
* @param ctx     MUST IMPLEMENT LoginListener !!!
*/
public static void tryLogin(final Activity ctx) {

    final ProgressDialog pd = new ProgressDialog(ctx);
    pd.setMessage(ctx.getResources().getString(R.string.logging_in));
    pd.show();

    String server = Max.getServer(ctx);
    Log.i(TAG, "tryLogin on server " + server);

    final TwAjax t = new TwAjax(ctx, true, true);
    t.getUrlContent(server + "/api/account/verify_credentials", new Runnable() {
        @Override
        public void run() {
            pd.dismiss();
            try {
                if (t.isSuccess()) {
                    Log.i(TAG, "... tryLogin - http status: " + t.getHttpCode());
                    if (t.getHttpCode() == 200) {
                        JSONObject r = (JSONObject) t.getJsonResult();
                        String name = r.getString("name");
                        ((TextView) ctx.findViewById(R.id.selected_clipboard)).setText(name);
                        ((LoginListener) ctx).OnLogin();

                        final TwAjax profileImgDl = new TwAjax();
                        final String targetFs = IMG_CACHE_DIR + "/my_profile_pic_" + r.getString("id") + ".jpg";
                        if (new File(targetFs).isFile()) {
                            ((ImageView) ctx.findViewById(R.id.profile_image))
                                    .setImageURI(Uri.parse("file://" + targetFs));
                        } else {
                            profileImgDl.urlDownloadToFile(r.getString("profile_image_url"), targetFs,
                                    new Runnable() {
                                        @Override
                                        public void run() {
                                            ((ImageView) ctx.findViewById(R.id.profile_image))
                                                    .setImageURI(Uri.parse("file://" + targetFs));
                                        }
                                    });
                        }

                    } else {
                        showLoginForm(ctx, "Error: " + t.getResult());
                    }
                } else {
                    Log.w(TAG, "... tryLogin - request failed");
                    showLoginForm(ctx, "ERR: " + t.getError().toString());
                }

            } catch (Exception ex) {
                Log.w(TAG, "... tryLogin - exception:");
                ex.printStackTrace();
                showLoginForm(ctx, "ERR2: " + t.getResult() + ex.toString());

            }
        }
    });
}

From source file:de.tudarmstadt.informatik.secuso.phishedu2.SwipeActivity.java

void updateUI(Activity v) {
    super.updateUI(v);

    final ViewPager mPager = (ViewPager) v.findViewById(R.id.pager);
    mPager.setAdapter(new SwipePageAdapter(getFragmentManager(), this));
    mPager.setOnPageChangeListener(this);

    ImageView imgPrevious = (ImageView) v.findViewById(R.id.game_intro_arrow_back);
    imgPrevious.setOnClickListener(new OnClickListener() {
        @Override/*w  w  w  .  ja va 2 s  . c om*/
        public void onClick(View v) {
            mPager.setCurrentItem(mPager.getCurrentItem() - 1);
        }
    });
    imgPrevious.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            mPager.setCurrentItem(0);
            return true;
        }
    });
    ImageView imgNext = (ImageView) v.findViewById(R.id.game_intro_arrow_forward);
    imgNext.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mPager.setCurrentItem(mPager.getCurrentItem() + 1);
        }
    });
    imgNext.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            mPager.setCurrentItem(getPageCount() - 1);
            return true;
        }
    });

    Button bStartLevel = (Button) v.findViewById(R.id.game_intro_start_button);
    bStartLevel.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            onStartClick();
        }
    });
    bStartLevel.setText(this.startButtonText());

    checkAndHideButtons(0);
}

From source file:org.uab.deic.uabdroid.solutions.unit5.FormFragment.java

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

    final Activity parentActivity = getActivity();

    SharedPreferences activityPreferences = parentActivity.getPreferences(Context.MODE_PRIVATE);

    mEditTextName = (EditText) parentActivity.findViewById(R.id.edittext_form_name);
    mEditTextDeveloper = (EditText) parentActivity.findViewById(R.id.edittext_form_developer);
    mDatePickerDate = (DatePicker) parentActivity.findViewById(R.id.datepicker_form_date);
    mEditTextURL = (EditText) parentActivity.findViewById(R.id.edittext_form_url);

    if (activityPreferences.getBoolean(FormAppActivity.STATE_NOT_SAVED, false)) {
        mEditTextName.setText(activityPreferences.getString(FormAppActivity.FORM_FIELD_NAME, ""));

        mEditTextDeveloper.setText(activityPreferences.getString(FormAppActivity.FORM_FIELD_DEVELOPER, ""));

        Calendar calendar = Calendar.getInstance();
        int day = activityPreferences.getInt(FormAppActivity.FORM_FIELD_DAY,
                calendar.get(Calendar.DAY_OF_MONTH));
        int month = activityPreferences.getInt(FormAppActivity.FORM_FIELD_MONTH,
                calendar.get(Calendar.MONTH) + 1);
        int year = activityPreferences.getInt(FormAppActivity.FORM_FIELD_YEAR, calendar.get(Calendar.YEAR));

        mDatePickerDate.updateDate(year, month, day);

        mEditTextURL.setText(activityPreferences.getString(FormAppActivity.FORM_FIELD_URL, ""));

        SharedPreferences.Editor editor = activityPreferences.edit();
        editor.putBoolean(FormAppActivity.STATE_NOT_SAVED, false);
        editor.commit();/* w w w. ja v a2  s .  c o m*/
    }

    Button cleanButton = (Button) parentActivity.findViewById(R.id.button_form_clean);
    cleanButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mEditTextName.setText("");
            mEditTextDeveloper.setText("");
            Calendar calendar = Calendar.getInstance();
            mDatePickerDate.updateDate(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1,
                    calendar.get(Calendar.DAY_OF_MONTH));
            mEditTextURL.setText("");
        }
    });

    Button acceptButton = (Button) parentActivity.findViewById(R.id.button_form_accept);
    acceptButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Calendar calendar = Calendar.getInstance();
            calendar.set(Calendar.DAY_OF_MONTH, mDatePickerDate.getDayOfMonth());
            calendar.set(Calendar.MONTH, mDatePickerDate.getMonth() - 1);
            calendar.set(Calendar.YEAR, mDatePickerDate.getYear());

            String name = mEditTextName.getText().toString();
            String developer = mEditTextDeveloper.getText().toString();
            String url = mEditTextURL.getText().toString();

            DatabaseAdapter databaseAdapter = new DatabaseAdapter(parentActivity);
            databaseAdapter.open();
            databaseAdapter.insertApp(name, developer, calendar, url);
            databaseAdapter.close();

            ((FormAppActivity) parentActivity).setButtonPressed();

            parentActivity.finish();
        }
    });

    Button cancelButton = (Button) parentActivity.findViewById(R.id.button_form_cancel);
    cancelButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            ((FormAppActivity) parentActivity).setButtonPressed();
            parentActivity.finish();
        }
    });
}

From source file:com.weebly.opus1269.copyeverywhere.ui.clipviewer.ClipViewerFragment.java

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

    if (getArguments().containsKey(ARG_CLIP_ITEM)) {
        final ClipItem clipItem = (ClipItem) getArguments().getSerializable(ARG_CLIP_ITEM);
        setClipItem(clipItem);//  w ww . j ava 2s .c o m
    }

    if (getArguments().containsKey(ARG_HIGHLIGHT)) {
        final String highlightText = getArguments().getString(ARG_HIGHLIGHT);
        setHighlightText(highlightText);
    }

    final Activity activity = getActivity();
    final FloatingActionButton fab = (FloatingActionButton) activity.findViewById(R.id.fab);
    if (fab != null) {
        fab.setOnClickListener(this);
    }
}