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:run.ace.IncomingMessages.java

public static Object getInstance(JSONArray message, Activity activity, CordovaWebView webView)
        throws JSONException {
    String fullTypeName = message.getString(2);

    if (fullTypeName.equals("android.content.Context")) {
        return activity.getApplicationContext();
    } else if (fullTypeName.equals("android.app.Activity")) {
        return activity;
    } else if (fullTypeName.equals("android.content.Intent")) {
        return NativeHost.intent;
    } else if (fullTypeName.equals("HostPage")) {
        return activity.findViewById(android.R.id.content);
    } else if (fullTypeName.equals("HostWebView")) {
        return webView.getView();
    } else if (fullTypeName.equals("PluginManager")) {
        return webView.getPluginManager();
    }/*from   ww w .  j  a v a2s  .  c o  m*/

    throw new RuntimeException(fullTypeName + " is not a valid choice for getting an existing instance");
}

From source file:com.breadwallet.tools.animation.BRAnimator.java

public static void hideCopyBubble(final Activity context) {
    try {/*from ww  w .j  av a2s.c  o  m*/
        if (context == null)
            return;
        if (copy == null)
            return;
        final RelativeLayout root = (RelativeLayout) context.findViewById(R.id.main_layout);
        if (copy.getVisibility() == View.VISIBLE) {
            Animation animation = new AlphaAnimation(1f, 0f);
            animation.setDuration(150);
            animation.setAnimationListener(new Animation.AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {

                }

                @Override
                public void onAnimationEnd(Animation animation) {
                    root.removeView(copy);
                }

                @Override
                public void onAnimationRepeat(Animation animation) {

                }
            });
            copy.startAnimation(animation);
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.vuze.android.remote.AndroidUtilsUI.java

public static boolean handleCommonKeyDownEvents(Activity a, int keyCode, KeyEvent event) {
    if (event.getAction() != KeyEvent.ACTION_DOWN) {
        return false;
    }/*from   ww  w . j a va2 s.  co  m*/
    switch (keyCode) {
    case KeyEvent.KEYCODE_MEDIA_NEXT:
    case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: {
        ViewGroup vg = (ViewGroup) a.findViewById(android.R.id.content);
        ArrayList list = AndroidUtilsUI.findByClass(vg, ViewPager.class, new ArrayList<View>(0));

        if (list.size() > 0) {
            ViewPager viewPager = (ViewPager) list.get(0);
            viewPager.arrowScroll(View.FOCUS_RIGHT);
        }
        break;
    }

    case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
    case KeyEvent.KEYCODE_MEDIA_REWIND: {
        ViewGroup vg = (ViewGroup) a.findViewById(android.R.id.content);
        ArrayList list = AndroidUtilsUI.findByClass(vg, ViewPager.class, new ArrayList<View>(0));

        if (list.size() > 0) {
            ViewPager viewPager = (ViewPager) list.get(0);
            viewPager.arrowScroll(View.FOCUS_LEFT);
        }
        break;
    }

    case KeyEvent.KEYCODE_DPAD_LEFT: {
        if (a instanceof DrawerActivity) {
            DrawerActivity da = (DrawerActivity) a;
            DrawerLayout drawerLayout = da.getDrawerLayout();
            View viewFocus = a.getCurrentFocus();
            boolean canOpenDrawer = viewFocus != null && "leftmost".equals(viewFocus.getTag());
            if (canOpenDrawer) {
                drawerLayout.openDrawer(Gravity.LEFT);
                drawerLayout.requestFocus();
                return true;
            }
        }
        break;
    }

    }

    return false;
}

From source file:info.papdt.blacklight.support.Utility.java

public static View addActionViewToCustom(Activity activity, int id, ViewGroup custom) {
    View v = activity.findViewById(id);

    if (v != null) {
        return addActionViewToCustom(v, custom);
    } else {/*from w w  w .jav a 2 s. c  om*/
        return null;
    }
}

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

@TargetApi(Build.VERSION_CODES.KITKAT)
private static void clearPreviousSetting(Activity activity) {
    ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
    int count = decorView.getChildCount();
    if (count > 0 && decorView.getChildAt(count - 1) instanceof StatusBarView) {
        decorView.removeViewAt(count - 1);
        ViewGroup rootView = (ViewGroup) ((ViewGroup) activity.findViewById(android.R.id.content))
                .getChildAt(0);/* w ww.jav  a 2s  . c o  m*/
        rootView.setPadding(0, 0, 0, 0);
    }
}

From source file:info.papdt.blacklight.support.Utility.java

public static void setActionBarTranslation(Activity activity, float y) {
    ViewGroup vg = (ViewGroup) activity.findViewById(android.R.id.content).getParent();
    int count = vg.getChildCount();

    if (DEBUG) {// w  w w . j a v  a  2  s.  com
        Log.d(TAG, "==========================");
    }

    // Get the class of action bar
    Class<?> actionBarContainer = null;
    Field isSplit = null;

    try {
        actionBarContainer = Class.forName("com.android.internal.widget.ActionBarContainer");
        isSplit = actionBarContainer.getDeclaredField("mIsSplit");
        isSplit.setAccessible(true);
    } catch (Exception e) {
        if (DEBUG) {
            Log.e(TAG, Log.getStackTraceString(e));
        }
    }

    for (int i = 0; i < count; i++) {
        View v = vg.getChildAt(i);

        if (v.getId() != android.R.id.content) {
            if (DEBUG) {
                Log.d(TAG, "Found View: " + v.getClass().getName());
            }

            try {
                if (actionBarContainer.isInstance(v)) {
                    if (DEBUG) {
                        Log.d(TAG, "Found ActionBarContainer");
                    }

                    if (isSplit.getBoolean(v)) {
                        if (DEBUG) {
                            Log.d(TAG, "Found Split Action Bar");
                        }

                        continue;
                    }
                }
            } catch (Exception e) {
                if (DEBUG) {
                    Log.e(TAG, Log.getStackTraceString(e));
                }
            }

            v.setTranslationY(y);
        }
    }

    if (DEBUG) {
        Log.d(TAG, "==========================");
    }
}

From source file:org.ttrssreader.utils.Utils.java

/**
 * Alert the user by a short vibration or a flash of the whole screen.
 *///from   w  ww .  j a  va2s  .  c  om
public static void alert(Activity activity, boolean error) {
    Vibrator vib = ((Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE));
    if (vib.hasVibrator()) {
        vib.vibrate(Utils.SHORT_VIBRATE);
    } else if (error) {
        // Only flash when user tried to move forward, flashing when reaching the last article looks just wrong.
        Animation flash = AnimationUtils.loadAnimation(activity, R.anim.flash);
        View main = activity.findViewById(R.id.frame_all);
        main.startAnimation(flash);
    }
}

From source file:com.hybris.mobile.lib.ui.view.Alert.java

/**
 * Hide the alert//  www .j  ava 2 s .  com
 *
 * @param context       application-specific resources
 * @param configuration describes all device configuration information
 */
public static void hide(Activity context, Configuration configuration) {
    if (context == null) {
        throw new IllegalArgumentException("You must provide a configuration and/or context for the alert.");
    }

    ViewGroup mainView = (ViewGroup) context.findViewById(android.R.id.content);
    int viewId = R.id.alert_view_top;

    configuration = setUpConfiguration(context, configuration, null);

    if (configuration.getOrientation().equals(Configuration.Orientation.BOTTOM)) {
        viewId = R.id.alert_view_bottom;
    }

    animOut(configuration, mainView, mainView.findViewById(viewId));
}

From source file:com.hybris.mobile.lib.ui.view.Alert.java

/**
 * Show the alert/*from ww  w.  j  a va2  s  .co m*/
 *
 * @param context                 application-specific resources
 * @param configuration           describes all device configuration information
 * @param text                    message to be displayed
 * @param forceClearPreviousAlert true will clear previous alert else keep it
 */
@SuppressLint("NewApi")
private static void showAlertOnScreen(final Activity context, final Configuration configuration,
        final String text, boolean forceClearPreviousAlert) {

    final ViewGroup mainView = ((ViewGroup) context.findViewById(android.R.id.content));
    boolean currentlyDisplayed = false;
    int viewId = R.id.alert_view_top;
    final TextView textView;
    boolean alertAlreadyExists = false;

    if (configuration.getOrientation().equals(Configuration.Orientation.BOTTOM)) {
        viewId = R.id.alert_view_bottom;
    }

    // Retrieving the view
    RelativeLayout relativeLayout = (RelativeLayout) mainView.findViewById(viewId);

    if (forceClearPreviousAlert) {
        mainView.removeView(relativeLayout);
        relativeLayout = null;
    }

    // Creating the view
    if (relativeLayout == null) {

        // Main layout
        relativeLayout = new RelativeLayout(context);
        relativeLayout.setId(viewId);
        relativeLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, configuration.getHeight()));
        relativeLayout.setGravity(Gravity.CENTER);

        // Textview
        textView = new TextView(context);
        textView.setId(R.id.alert_view_text);
        textView.setGravity(Gravity.CENTER);
        textView.setLayoutParams(
                new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        relativeLayout.addView(textView);

        setIcon(context, configuration, relativeLayout, textView);

        if (configuration.getOrientation().equals(Configuration.Orientation.TOP)) {
            relativeLayout.setY(-configuration.getHeight());
        } else {
            relativeLayout.setY(mainView.getHeight());
        }

        // Adding the view to the global layout
        mainView.addView(relativeLayout, 0);
        relativeLayout.bringToFront();
        relativeLayout.requestLayout();
        relativeLayout.invalidate();
    }
    // View already exists
    else {
        alertAlreadyExists = true;
        textView = (TextView) relativeLayout.findViewById(R.id.alert_view_text);

        if (configuration.getOrientation().equals(Configuration.Orientation.TOP)) {
            if (relativeLayout.getY() == 0) {
                currentlyDisplayed = true;
            }
        } else {
            if (relativeLayout.getY() < mainView.getHeight()) {
                currentlyDisplayed = true;
            }
        }

        // The view is currently shown to the user
        if (currentlyDisplayed) {

            // If the message is not the same, we hide the current message and display the new one
            if (!StringUtils.equals(text, textView.getText())) {
                // Anim out the current message
                ViewPropertyAnimator viewPropertyAnimator = animOut(configuration, mainView, relativeLayout);

                final RelativeLayout relativeLayoutFinal = relativeLayout;

                if (viewPropertyAnimator != null) {
                    // Anim in the new message after the animation out has finished
                    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                        viewPropertyAnimator.setListener(new AnimatorListenerAdapter() {
                            @Override
                            public void onAnimationEnd(Animator animation) {
                                setIcon(context, configuration, relativeLayoutFinal, textView);
                                animIn(configuration, relativeLayoutFinal, textView, mainView, text);
                            }
                        });
                    } else {
                        viewPropertyAnimator.withEndAction(new Runnable() {
                            @Override
                            public void run() {
                                setIcon(context, configuration, relativeLayoutFinal, textView);
                                animIn(configuration, relativeLayoutFinal, textView, mainView, text);
                            }
                        });
                    }
                } else {
                    setIcon(context, configuration, relativeLayoutFinal, textView);
                    animIn(configuration, relativeLayoutFinal, textView, mainView, text);
                }
            }
        }
    }

    final RelativeLayout relativeLayoutFinal = relativeLayout;

    // Close the alert by clicking the layout
    if (configuration.isCloseable()) {
        relativeLayout.setOnTouchListener(new OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                animOut(configuration, mainView, relativeLayoutFinal);
                v.performClick();
                return true;
            }
        });
    }

    if (!currentlyDisplayed) {
        // Set the icon in case the alert already exists but it's not currently displayed
        if (alertAlreadyExists) {
            setIcon(context, configuration, relativeLayoutFinal, textView);
        }

        // We anim in the alert
        animIn(configuration, relativeLayoutFinal, textView, mainView, text);
    }
}

From source file:com.cw.litenote.folder.FolderUi.java

public static void updateFocus_folderPosition() {
    Activity act = MainAct.mAct;
    DB_drawer db_drawer = new DB_drawer(act);

    //update focus position
    int iLastView_folderTableId = Pref.getPref_focusView_folder_tableId(act);
    int count = db_drawer.getFoldersCount(true);
    for (int i = 0; i < count; i++) {
        if (db_drawer.getFolderTableId(i, true) == iLastView_folderTableId) {
            setFocus_folderPos(i);//from   www  . j a v  a2  s.c  om
            DragSortListView listView = (DragSortListView) act.findViewById(R.id.drawer_listview);

            listView.setItemChecked(getFocus_folderPos(), true);
        }
    }

}