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.poguico.palmabici.widgets.SidebarMenu.java

public static void setDrawer(final Activity activity) {
    context = activity.getApplicationContext();
    elements = initElements();/*from   w  w w  .  jav a2 s .c o m*/

    mDrawerLayout = (DrawerLayout) activity.findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) activity.findViewById(R.id.left_drawer);

    mDrawerList.setAdapter(new SidebarElementAdapter(context, elements));
    mDrawerList.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View view, int position, long id) {
            if (position == 0) {
                Intent preferencesActivity = new Intent(activity, PreferencesActivity.class);
                activity.startActivity(preferencesActivity);
            } else if (position == 1) {
                Intent issueIntent = new Intent(Intent.ACTION_VIEW);
                issueIntent.setData(Uri.parse(GPLAY_URL));
                activity.startActivity(issueIntent);
            } else if (position == 2) {
                Intent shareActivity = new Intent(activity, ShareActivity.class);
                activity.startActivity(shareActivity);
            } else if (position == 3) {
                Intent issueIntent = new Intent(Intent.ACTION_VIEW);
                issueIntent.setData(Uri.parse(CONTACT_URL));
                activity.startActivity(issueIntent);
            } else if (position == 4) {
                new CreditsDialog(activity).show();
            }

            new Handler().postDelayed(closeDrawerRunnable(), 200);
        }
    });

    ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeButtonEnabled(true);

    mDrawerToggle = new ActionBarDrawerToggle(activity, /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
            R.string.drawer_open, /* "open drawer" description for accessibility */
            R.string.drawer_close /* "close drawer" description for accessibility */
    ) {

        /** Called when a drawer has settled in a completely closed state. */
        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
        }

        /** Called when a drawer has settled in a completely open state. */
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
        }
    };

    mDrawerLayout.post(new Runnable() {
        @Override
        public void run() {
            mDrawerToggle.syncState();
        }
    });

    mDrawerLayout.setDrawerListener(mDrawerToggle);

}

From source file:ru.strider.simplerecognizer.util.AdMob.java

public static void removeAdView(Activity activity) {
    LinearLayout linearLayout = (LinearLayout) activity.findViewById(R.id.linearLayoutAdView);

    if (linearLayout != null) {
        AdView adView = (AdView) linearLayout.findViewById(R.id.adView);

        if (adView != null) {
            adView.stopLoading();/*from  w  w w .j a  va  2  s  .  c  o  m*/
        }
    }
}

From source file:ru.strider.simplerecognizer.util.AdMob.java

public static void destroyAdView(Activity activity) {
    LinearLayout linearLayout = (LinearLayout) activity.findViewById(R.id.linearLayoutAdView);

    if (linearLayout != null) {
        AdView adView = (AdView) linearLayout.findViewById(R.id.adView);

        if (adView != null) {
            linearLayout.removeView(adView);

            adView.destroy();//from  w w  w. j a  va 2  s  . com
        }
    }
}

From source file:cn.motalks.mtdc.utils.EasyPermissionsEx.java

/**
 *
 * prompt the user to go to the app's settings screen and enable permissions. If the
 * user clicks snackbar's action, they are sent to the settings screen. The result is returned
 * to the Activity via {@link Activity#onActivityResult(int, int, Intent)}.
 *
 * @param object Activity or Fragment requesting permissions.
 * @param rationale a message explaining why the application needs this set of permissions, will
 *                       be displayed on the snackbar.
 * @param snackbarAction text disPlayed on the snackbar's action
 * @param requestCode If >= 0, this code will be returned in onActivityResult() when the activity exits.
 *///from   ww  w  .j a  va  2 s .  co  m
public static void goSettings2Permissions(final Object object, String rationale, String snackbarAction,
        final int requestCode) {
    checkCallingObjectSuitability(object);

    final Activity activity = getActivity(object);
    if (null == activity) {
        return;
    }

    Snackbar.make(activity.findViewById(android.R.id.content), rationale, Snackbar.LENGTH_LONG)
            .setAction(snackbarAction, new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                    Uri uri = Uri.fromParts("package", activity.getPackageName(), null);
                    intent.setData(uri);
                    startForResult(object, intent, requestCode);
                }
            }).show();
}

From source file:cn.motalks.mtdc.utils.EasyPermissionsEx.java

/**
 * Request a set of permissions, showing rationale if the system requests it.
 *
 * @param object         Activity or Fragment requesting permissions. Should implement
 *                       {@link ActivityCompat.OnRequestPermissionsResultCallback}
 *                       or {@link android.support.v13.app.FragmentCompat.OnRequestPermissionsResultCallback}
 * @param rationale      a message explaining why the application needs this set of permissions, will
 *                       be displayed if the user rejects the request the first time.
 * @param snackbarActionResId custom text for snackbar action button
 * @param requestCode    request code to track this request, must be < 256.
 * @param perms          a set of permissions to be requested.
 *//*from  w  w w  .j a  v  a 2s .  c  o m*/
public static void requestPermissions(final Object object, String rationale, int snackbarActionResId,
        final int requestCode, final String... perms) {

    checkCallingObjectSuitability(object);

    boolean shouldShowRationale = false;
    for (String perm : perms) {
        shouldShowRationale = shouldShowRationale || shouldShowRequestPermissionRationale(object, perm);
    }

    if (shouldShowRationale) {
        Activity activity = getActivity(object);
        if (null == activity) {
            return;
        }

        Snackbar.make(activity.findViewById(android.R.id.content), rationale, Snackbar.LENGTH_LONG)
                .setAction(snackbarActionResId, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        executePermissionsRequest(object, perms, requestCode);
                    }
                }).show();

    } else {
        executePermissionsRequest(object, perms, requestCode);
    }
}

From source file:com.oliversride.wordryo.Utils.java

public static boolean getChecked(Activity activity, int id) {
    CheckBox cbx = (CheckBox) activity.findViewById(id);
    return cbx.isChecked();
}

From source file:edu.stanford.mobisocial.dungbeetle.ui.MusubiBaseActivity.java

/**
 * Use the activity label to set the text in the activity's title text view.
 * The argument gives the name of the view.
 * <p>//from  w  w w  .  ja  va2s .  c o  m
 * This method is needed because we have a custom title bar rather than the
 * default Android title bar. See the theme definitons in styles.xml.
 * 
 * @param title The text to display, or null to use the activity's label.
 * @return void
 */
public static void doTitleBar(Activity activity, String title) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        View titleBar = activity.findViewById(R.id.dashboardTitleBar);
        if (titleBar != null) {
            titleBar.setVisibility(View.GONE);
        }
    } else {
        // Dashboard title bar
        TextView tv = (TextView) activity.findViewById(R.id.title_text);
        if (tv == null) {
            return;
        }
        if (title == null) {
            tv.setText(activity.getTitle());
        } else {
            tv.setText(title);
        }
    }
}

From source file:com.oliversride.wordryo.Utils.java

public static String getText(Activity activity, int id) {
    EditText editText = (EditText) activity.findViewById(id);
    return editText.getText().toString();
}

From source file:sysnetlab.android.sdc.test.TestHelper.java

public static void startExperiment(ActivityInstrumentationTestCase2<?> testCase, Activity activity) {
    Assert.assertTrue("The activity must be a CreateExperimentActivity.",
            activity instanceof CreateExperimentActivity);

    Button buttonRunExperiment = (Button) activity.findViewById(R.id.button_experiment_run);
    Assert.assertNotNull("The Run-Experiment button should not be null.", buttonRunExperiment);

    TouchUtils.clickView(testCase, buttonRunExperiment);
    testCase.getInstrumentation().waitForIdleSync();
}

From source file:ru.strider.simplerecognizer.util.AdMob.java

@SuppressWarnings("deprecation")
@SuppressLint("InlinedApi")
public static void addAdView(Activity activity) {
    if (!activity.isFinishing()) {
        LinearLayout linearLayout = (LinearLayout) activity.findViewById(R.id.linearLayoutAdView);

        if (linearLayout != null) {
            AdView adView = (AdView) linearLayout.findViewById(R.id.adView);

            if (adView == null) {
                adView = new AdView(activity, AdSize.SMART_BANNER, PUBLISHER_ID);

                adView.setId(R.id.adView);

                linearLayout.addView(adView,
                        (new LinearLayout.LayoutParams(
                                ((Build.VERSION.SDK_INT < Build.VERSION_CODES.FROYO)
                                        ? LinearLayout.LayoutParams.FILL_PARENT
                                        : LinearLayout.LayoutParams.MATCH_PARENT),
                                LinearLayout.LayoutParams.WRAP_CONTENT)));
            }/*w  w w  .j av  a2 s .co  m*/

            adView.loadAd(getAdRequest());
        }
    }
}