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:net.olejon.mdapp.MedicationFelleskatalogenFragment.java

@SuppressLint("SetJavaScriptEnabled")
@Override//  w  w w.ja v  a2s .c  om
public View onCreateView(LayoutInflater inflater, ViewGroup container, final Bundle savedInstanceState) {
    ViewGroup viewGroup = (ViewGroup) inflater.inflate(R.layout.fragment_medication_felleskatalogen, container,
            false);

    // Activity
    final Activity activity = getActivity();

    // Context
    final Context context = activity.getApplicationContext();

    // Tools
    final MyTools mTools = new MyTools(context);

    // Arguments
    Bundle bundle = getArguments();

    final String pageUri = bundle.getString("uri");

    // Progress bar
    final ProgressBar progressBar = (ProgressBar) activity
            .findViewById(R.id.medication_toolbar_progressbar_horizontal);

    // Toolbar
    final LinearLayout toolbarSearchLayout = (LinearLayout) activity
            .findViewById(R.id.medication_toolbar_search_layout);
    final EditText toolbarSearchEditText = (EditText) activity.findViewById(R.id.medication_toolbar_search);

    // Web view
    WEBVIEW = (WebView) viewGroup.findViewById(R.id.medication_felleskatalogen_content);

    WebSettings webSettings = WEBVIEW.getSettings();
    webSettings.setJavaScriptEnabled(true);

    WEBVIEW.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (!mTools.isDeviceConnected()) {
                mTools.showToast(getString(R.string.device_not_connected), 0);
                return true;
            } else if (url.matches("^https?://.*?\\.pdf$")) {
                mTools.downloadFile(view.getTitle(), url);
                return true;
            }

            return false;
        }
    });

    WEBVIEW.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            if (newProgress == 100) {
                progressBar.setVisibility(View.INVISIBLE);
            } else {
                progressBar.setVisibility(View.VISIBLE);
                progressBar.setProgress(newProgress);

                toolbarSearchLayout.setVisibility(View.GONE);
                toolbarSearchEditText.setText("");
            }
        }
    });

    if (savedInstanceState == null) {
        WEBVIEW.loadUrl(pageUri);
    } else {
        WEBVIEW.restoreState(savedInstanceState);
    }

    return viewGroup;
}

From source file:net.olejon.mdapp.MedicationNlhFragment.java

@SuppressLint("SetJavaScriptEnabled")
@Override//from   w w  w .java 2  s.c om
public View onCreateView(LayoutInflater inflater, ViewGroup container, final Bundle savedInstanceState) {
    ViewGroup viewGroup = (ViewGroup) inflater.inflate(R.layout.fragment_medication_nlh, container, false);

    // Activity
    final Activity activity = getActivity();

    // Context
    final Context context = activity.getApplicationContext();

    // Tools
    final MyTools mTools = new MyTools(context);

    // Arguments
    Bundle bundle = getArguments();

    final String pageUri = bundle.getString("uri");

    // Progress bar
    final ProgressBar progressBar = (ProgressBar) activity
            .findViewById(R.id.medication_toolbar_progressbar_horizontal);

    // Toolbar
    final LinearLayout toolbarSearchLayout = (LinearLayout) activity
            .findViewById(R.id.medication_toolbar_search_layout);
    final EditText toolbarSearchEditText = (EditText) activity.findViewById(R.id.medication_toolbar_search);

    // Web view
    WEBVIEW = (WebView) viewGroup.findViewById(R.id.medication_nlh_content);

    WebSettings webSettings = WEBVIEW.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setAppCacheEnabled(true);
    webSettings.setDomStorageEnabled(true);
    webSettings.setAppCachePath(context.getCacheDir().getAbsolutePath());
    webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);

    WEBVIEW.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (!mTools.isDeviceConnected()) {
                mTools.showToast(getString(R.string.device_not_connected), 0);
                return true;
            } else if (url.matches(".*/[^#]+#[^/]+$")) {
                WEBVIEW.loadUrl(url.replaceAll("#[^/]+$", ""));
                return true;
            } else if (url.matches("^https?://.*?\\.pdf$")) {
                mTools.downloadFile(view.getTitle(), url);
                return true;
            }

            return false;
        }
    });

    WEBVIEW.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            if (newProgress == 100) {
                progressBar.setVisibility(View.INVISIBLE);
            } else {
                progressBar.setVisibility(View.VISIBLE);
                progressBar.setProgress(newProgress);

                toolbarSearchLayout.setVisibility(View.GONE);
                toolbarSearchEditText.setText("");
            }
        }
    });

    if (savedInstanceState == null) {
        WEBVIEW.loadUrl(pageUri);
    } else {
        WEBVIEW.restoreState(savedInstanceState);
    }

    return viewGroup;
}

From source file:jp.co.rakuten.rakutenvideoplayer.base.BaseActivity.java

protected void initViewCommom(Activity activity, View.OnClickListener clickListener) {
    btnConvention = (Button) activity.findViewById(R.id.common_left_convention);
    btnHelp = (Button) activity.findViewById(R.id.common_left_help);
    btnPersional = (Button) activity.findViewById(R.id.common_left_persional);
    btnTransaction = (Button) activity.findViewById(R.id.common_left_transaction);
    tvInformation = (TextView) activity.findViewById(R.id.common_bottom_information);
    tvLicensecode = (TextView) activity.findViewById(R.id.common_bottom_licensecode);

    btnConvention.setOnClickListener(clickListener);
    btnHelp.setOnClickListener(clickListener);
    btnPersional.setOnClickListener(clickListener);
    btnTransaction.setOnClickListener(clickListener);
    tvInformation.setOnClickListener(clickListener);
    tvLicensecode.setOnClickListener(clickListener);
}

From source file:ru.valle.btc.MainActivityTest.java

private void performGenerationTest(SharedPreferences preferences, String privateKeyType) {
    preferences.edit().putString(PreferencesActivity.PREF_PRIVATE_KEY, privateKeyType).commit();
    getActivity().finish();//ww w.  j av a 2s . com
    setActivity(null);
    assertFalse(getActivity().isFinishing());
    preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
    assertEquals(privateKeyType, preferences.getString(PreferencesActivity.PREF_PRIVATE_KEY,
            PreferencesActivity.PREF_PRIVATE_KEY_WIF_COMPRESSED));
    checkIfGeneratedKeyIsValid(privateKeyType);
    final Activity activity = getActivity();
    activity.runOnUiThread(new Runnable() {
        public void run() {
            assertTrue(activity.findViewById(R.id.spend_tx_description).getVisibility() == View.GONE);
            assertTrue(activity.findViewById(R.id.spend_tx).getVisibility() == View.GONE);
        }
    });
}

From source file:com.h6ah4i.android.example.openslmediaplayer.app.NavigationDrawerFragment.java

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

    Activity activity = getActivity();
    setUp((DrawerLayout) activity.findViewById(R.id.drawer_layout),
            (ViewGroup) activity.findViewById(R.id.drawer_container));
}

From source file:com.example.ray.firstapp.bottombar.BottomBar.java

/**
 * Bind the BottomBar to your Activity, and inflate your layout here.
 * <p/>/*from w  ww  .jav  a2  s.c om*/
 * Remember to also call {@link #onRestoreInstanceState(Bundle)} inside
 * of your {@link Activity#onSaveInstanceState(Bundle)} to restore the state.
 *
 * @param activity           an Activity to attach to.
 * @param savedInstanceState a Bundle for restoring the state on configuration change.
 * @return a BottomBar at the bottom of the screen.
 */
public static BottomBar attach(Activity activity, Bundle savedInstanceState) {
    BottomBar bottomBar = new BottomBar(activity);
    bottomBar.onRestoreInstanceState(savedInstanceState);

    ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content);
    View oldLayout = contentView.getChildAt(0);
    contentView.removeView(oldLayout);

    bottomBar.setPendingUserContentView(oldLayout);
    contentView.addView(bottomBar, 0);

    return bottomBar;
}

From source file:com.cachirulop.moneybox.fragment.MoneyboxFragment.java

/**
 * Register the event OnGlobalLayoutListener to fill the moneybox when the
 * layout is created./* ww w.  jav  a2 s.  c om*/
 */
private void registerLayoutListener() {
    final View v;
    final ViewTreeObserver vto;
    Activity parent;

    parent = getActivity();

    v = parent.findViewById(R.id.moneyDropLayout);
    vto = v.getViewTreeObserver();
    if (vto.isAlive()) {
        vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            public void onGlobalLayout() {
                initMoneybox();

                v.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            }
        });
    }
}

From source file:com.github.andrewlord1990.snackbarbuilder.SnackbarBuilder.java

/**
 * Create a builder to create a Snackbar. The parent view to attach the Snackbar to is specified through the
 * attribute snackbarBuilder_parentViewId. This attribute is within a style provided through the theme attribute
 * snackbarBuilderStyle. The parent view will be found using this ID and the Snackbar will be attached to it.
 *
 * @param activity Activity to show the Snackbar in, it should contain a view with the ID specified in the style
 *                 attribute snackbarBuilder_parentViewId.
 *///from  ww w  . ja  v  a2 s  .  c o  m
public SnackbarBuilder(Activity activity) {
    setup(activity);
    parentView = activity.findViewById(parentViewId);
}

From source file:org.solovyev.android.calculator.ActivityUi.java

@Override
public void onCreate(@Nonnull Activity activity) {
    super.onCreate(activity);

    if (activity instanceof CalculatorEventListener) {
        Locator.getInstance().getCalculator().addCalculatorEventListener((CalculatorEventListener) activity);
    }/*w  ww .j av a2s.c  o  m*/

    activity.setContentView(layoutId);

    final View root = activity.findViewById(R.id.main_layout);
    if (root != null) {
        processButtons(activity, root);
        fixFonts(root);
        addHelpInfo(activity, root);
    }
}

From source file:com.codinguser.android.contactpicker.ContactDetailsFragment.java

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

    long personId = getArguments().getLong(ContactsPickerActivity.SELECTED_CONTACT_ID);// getIntent().getLongExtra("id", 0);
    Activity activity = getActivity();

    Uri phonesUri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
    String[] projection = new String[] { Phone._ID, Phone.DISPLAY_NAME, Phone.TYPE, Phone.NUMBER, Phone.LABEL };
    String selection = ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?";
    String[] selectionArgs = new String[] { Long.toString(personId) };

    mCursor = activity.getContentResolver().query(phonesUri, projection, selection, selectionArgs, null);

    mDisplayName = (TextView) activity.findViewById(R.id.display_name);
    if (mCursor.moveToFirst()) {
        mDisplayName.setText(mCursor.getString(mCursor.getColumnIndex(Phone.DISPLAY_NAME)));
    }/*  w w w  . j ava 2  s.c  o m*/

    ListAdapter adapter = new PhoneNumbersAdapter(this.getActivity(), R.layout.list_item_phone_number, mCursor,
            new String[] { Phone.TYPE, Phone.NUMBER }, new int[] { R.id.label, R.id.phone_number });
    setListAdapter(adapter);
}