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:sysnetlab.android.sdc.test.TestHelper.java

public static Activity launchCreateExperimentActivity(ActivityInstrumentationTestCase2<?> testCase,
        Activity activity) {

    // click the Create-New-Experiment button
    ActivityMonitor activityMonitor = testCase.getInstrumentation()
            .addMonitor(CreateExperimentActivity.class.getName(), null, false);

    Button buttonCreateExperiment = (Button) activity.findViewById(R.id.button_create_experiment);
    Assert.assertNotNull("The Create-Experiment Button should not be null", buttonCreateExperiment);

    TouchUtils.clickView(testCase, buttonCreateExperiment);

    testCase.getInstrumentation().waitForIdleSync();

    activity = testCase.getInstrumentation().waitForMonitor(activityMonitor);

    testCase.getInstrumentation().removeMonitor(activityMonitor);
    return activity;
}

From source file:com.jamesgiang.aussnowcam.Utils.java

public static void loadWeather(final Activity a, int i) {
    final TextView title;
    final TextView data1;
    final TextView data2;
    final TextView data3;
    final TextView data4;
    final TextView data5;
    final TextView data6;
    title = (TextView) a.findViewById(R.id.weatherTitle);
    data1 = (TextView) a.findViewById(R.id.data1);
    data2 = (TextView) a.findViewById(R.id.data2);
    data3 = (TextView) a.findViewById(R.id.data3);
    data4 = (TextView) a.findViewById(R.id.data4);
    data5 = (TextView) a.findViewById(R.id.data5);
    data6 = (TextView) a.findViewById(R.id.data6);
    String end_point = getEndPoint(i);
    if (end_point != null) {
        BOMClient.get(end_point, null, new JsonHttpResponseHandler() {
            @Override//from  w  ww  .j  a  v  a  2s  . c  o m
            public void onSuccess(JSONObject response) {
                try {
                    JSONObject result = (JSONObject) response.getJSONObject("observations").getJSONArray("data")
                            .get(0);
                    JSONObject header = (JSONObject) response.getJSONObject("observations")
                            .getJSONArray("header").get(0);
                    data1.setVisibility(View.VISIBLE);
                    data2.setVisibility(View.VISIBLE);
                    data3.setVisibility(View.VISIBLE);
                    data4.setVisibility(View.VISIBLE);
                    data5.setVisibility(View.VISIBLE);
                    data6.setVisibility(View.VISIBLE);
                    title.setText("Weather Observations for " + header.getString("name"));
                    if (result.isNull("air_temp")) {
                        data1.setText("Temperature: - ");
                    } else {
                        data1.setText("Temperature: " + result.getString("air_temp"));
                    }
                    if (result.isNull("wind_dir")) {
                        data2.setText("Wind Direction: - ");
                    } else {
                        data2.setText("Wind Direction: " + result.getString("wind_dir"));
                    }
                    if (result.isNull("wind_spd_kmh")) {
                        data3.setText("Wind Speed (km/h): - ");
                    } else {
                        data3.setText("Wind Speed (km/h): " + result.getString("wind_spd_kmh"));
                    }
                    if (result.isNull("gust_kmh")) {
                        data4.setText("Gust Speed (km/h): - ");
                    } else {
                        data4.setText("Gust Speed (km/h): " + result.getString("gust_kmh"));
                    }
                    if (result.isNull("rain_trace")) {
                        data5.setText("Rain since 9am (mm): - ");
                    } else {
                        data5.setText("Rain since 9am (mm): " + result.getString("rain_trace"));
                    }
                    data6.setText(header.getString("refresh_message"));
                } catch (JSONException e) {
                    title.setText("Weather data not available");
                    data1.setVisibility(View.GONE);
                    data2.setVisibility(View.GONE);
                    data3.setVisibility(View.GONE);
                    data4.setVisibility(View.GONE);
                    data5.setVisibility(View.GONE);
                    data6.setVisibility(View.GONE);
                }
            }
        });
    } else {
        title.setText("Weather data not available");
        data1.setVisibility(View.GONE);
        data2.setVisibility(View.GONE);
        data3.setVisibility(View.GONE);
        data4.setVisibility(View.GONE);
        data5.setVisibility(View.GONE);
        data6.setVisibility(View.GONE);
    }
}

From source file:org.totschnig.myexpenses.dialog.DialogUtils.java

public static void showPasswordDialog(final Activity ctx, AlertDialog dialog, boolean hideWindow,
        PasswordDialogUnlockedCallback callback) {
    if (hideWindow) {
        ctx.findViewById(android.R.id.content).setVisibility(View.GONE);
        if (ctx instanceof AppCompatActivity) {
            final ActionBar actionBar = ((AppCompatActivity) ctx).getSupportActionBar();
            if (actionBar != null)
                actionBar.hide();//from w w  w  . j  a v  a 2  s . c o  m
        }
    }
    dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
    dialog.show();
    if (callback == null) {
        callback = new PasswordDialogUnlockedCallback() {
            @Override
            public void onPasswordDialogUnlocked() {
                MyApplication.getInstance().setLocked(false);
                ctx.findViewById(android.R.id.content).setVisibility(View.VISIBLE);
                if (ctx instanceof AppCompatActivity) {
                    final ActionBar actionBar = ((AppCompatActivity) ctx).getSupportActionBar();
                    if (actionBar != null)
                        actionBar.show();
                }
            }
        };
    }
    PasswordDialogListener passwordDialogListener = new PasswordDialogListener(ctx, dialog, callback);
    Button b = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
    if (b != null)
        b.setOnClickListener(passwordDialogListener);
    b = dialog.getButton(DialogInterface.BUTTON_NEUTRAL);
    if (b != null)
        b.setOnClickListener(passwordDialogListener);
}

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

private static void updateSafeArea(float progress) {
    // 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();
    Activity activity = IOuyaActivity.GetActivity();
    FrameLayout content = (FrameLayout) activity.findViewById(android.R.id.content);
    LayoutParams layout = content.getLayoutParams();
    layout.width = (int) (maxWidth * ratio);
    layout.height = (int) (maxHeight * ratio);
    content.setLayoutParams(layout);//from  w w  w .  ja  v a 2 s  .  co m
    content.setX(maxWidth - maxWidth * halfRatio);
    content.setY(maxHeight - maxHeight * halfRatio);
}

From source file:com.gosuncn.core.util.view.StatusBarUtils.java

/**
 * ?/* www  .  j a v  a 2  s  .  c o  m*/
 */
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private static void setRootView(Activity activity) {
    ViewGroup rootView = (ViewGroup) ((ViewGroup) activity.findViewById(android.R.id.content)).getChildAt(0);
    rootView.setFitsSystemWindows(true);
    rootView.setClipToPadding(true);
}

From source file:com.project.richard.insightjournal.utils.PermissionsUtils.java

public static void requestLocationPermissions(final Activity c, int viewId) {
    boolean shouldProvideRationale = ActivityCompat.shouldShowRequestPermissionRationale(c,
            Manifest.permission.ACCESS_FINE_LOCATION);

    //         Provide an additional rationale to the user. This would happen if the user denied the
    //         request previously, but didn't check the "Don't ask again" checkbox.
    if (shouldProvideRationale) {
        Log.e("PermissionsUtils", "Displaying permission rationale to provide additional context.");
        Snackbar.make(c.findViewById(viewId),
                "Location permissions requested for recording the city in the meditation log",
                Snackbar.LENGTH_INDEFINITE).setAction("ok", new View.OnClickListener() {
                    @Override/*from  w w w.  j  a  v  a 2 s .  c  o m*/
                    public void onClick(View view) {
                        // Request permission
                        ActivityCompat.requestPermissions(c,
                                new String[] { Manifest.permission.ACCESS_FINE_LOCATION },
                                REQUEST_PERMISSIONS_REQUEST_CODE);
                    }
                }).show();
    } else {
        //         Request permission. It's possible this can be auto answered if device policy
        //         sets the permission in a given state or the user denied the permission
        //         previously and checked "Never ask again".
        ActivityCompat.requestPermissions(c, new String[] { Manifest.permission.ACCESS_FINE_LOCATION },
                REQUEST_PERMISSIONS_REQUEST_CODE);

    }
}

From source file:com.gosuncn.core.util.view.StatusBarUtils.java

/**
 * ???/*from   w  ww .  j  av a2 s .  c o m*/
 *
 * @param activity       ? activity
 * @param statusBarAlpha ?
 */
private static void addTranslucentView(Activity activity, int statusBarAlpha) {
    ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content);
    if (contentView.getChildCount() > 1) {
        contentView.getChildAt(1).setBackgroundColor(Color.argb(statusBarAlpha, 0, 0, 0));
    } else {
        contentView.addView(createTranslucentStatusBarView(activity, statusBarAlpha));
    }
}

From source file:de.baumann.hhsmoodle.helper.helper_main.java

public static void makeToast(Activity activity, String Text) {
    LayoutInflater inflater = activity.getLayoutInflater();

    View toastLayout = inflater.inflate(R.layout.toast,
            (ViewGroup) activity.findViewById(R.id.toast_root_view));

    TextView header = (TextView) toastLayout.findViewById(R.id.toast_message);
    header.setText(Text);//  w w  w.j a va2  s.co m

    Toast toast = new Toast(activity.getApplicationContext());
    toast.setGravity(Gravity.FILL_HORIZONTAL | Gravity.BOTTOM, 0, 0);
    toast.setDuration(Toast.LENGTH_LONG);
    toast.setView(toastLayout);
    toast.show();
}

From source file:com.marc.marclibs.utils.StatusBarCompat.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static View compat(Activity activity, int statusColor) {
    int color = ContextCompat.getColor(activity, R.color.primary_light);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        if (statusColor != INVALID_VAL) {
            color = statusColor;/*from ww  w.  j  a  v  a 2  s.co m*/
        }
        activity.getWindow().setStatusBarColor(color);
        return null;
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT
            && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content);
        if (statusColor != INVALID_VAL) {
            color = statusColor;
        }
        View statusBarView = contentView.getChildAt(0);
        if (statusBarView != null && statusBarView.getMeasuredHeight() == getStatusBarHeight(activity)) {
            statusBarView.setBackgroundColor(color);
            return statusBarView;
        }
        statusBarView = new View(activity);
        ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                getStatusBarHeight(activity));
        statusBarView.setBackgroundColor(color);
        contentView.addView(statusBarView, lp);
        return statusBarView;
    }
    return null;

}

From source file:com.koushikdutta.superuser.helper.Theme.java

public static void handleTheme(Activity context, String theme, int textToolbarDefault, DrawerLayout drawer,
        AppBarLayout appBar, Toolbar toolbar, TabLayout tabLayout) {

    if (!theme.equals(PREF_BLACK_THEME)) {
        ATH.setStatusbarColor(context, context.getResources().getInteger(R.integer.statusbar_tint));

        if (drawer != null)
            drawer.setStatusBarBackgroundColor(ThemeStore.statusBarColor(context));
        else//from w w  w.  ja  v a2 s . c o  m
            ((CoordinatorLayout) context.findViewById(R.id.coordinator))
                    .setStatusBarBackgroundColor(ThemeStore.statusBarColor(context));

        if (appBar != null)
            appBar.setBackgroundColor(ThemeStore.primaryColor(context));
        else
            toolbar.setBackgroundColor(ThemeStore.primaryColor(context));

        ToolbarContentTintHelper.setToolbarContentColor(context, toolbar, null, textToolbarDefault,
                textToolbarDefault, textToolbarDefault, 0xff424242);

        int tabTextColor = PreferenceManager.getDefaultSharedPreferences(context).getInt("tab_text_selected",
                textToolbarDefault);

        if (tabLayout != null)
            tabLayout.setTabTextColors(
                    //ColorUtil.isColorLight(tabTextColor) ? ColorUtil.shiftColor(tabTextColor, 0.9f) : ColorUtil.shiftColor(tabTextColor, 1.5f),
                    Color.argb(180, Color.red(tabTextColor), Color.green(tabTextColor),
                            Color.blue(tabTextColor)),
                    tabTextColor);

    } else {
        ToolbarContentTintHelper.setToolbarContentColor(context, toolbar, null, 0xffeaeaea, 0xffeaeaea,
                0xffeaeaea, 0xff424242);

        if (tabLayout != null)
            tabLayout.setTabTextColors(ColorUtil.shiftColor(0xffeaeaea, 1.5f), 0xffeaeaea);
    }
}