List of usage examples for android.view ViewStub inflate
public View inflate()
From source file:com.hannesdorfmann.home.HomeActivity.java
private void setNoFiltersVisiblity(int visibility) { if (visibility == View.VISIBLE) { if (noFiltersEmptyText == null) { // create the no filters empty text ViewStub stub = (ViewStub) findViewById(R.id.stub_no_filters); noFiltersEmptyText = (TextView) stub.inflate(); String emptyText = getString(R.string.no_filters_selected); int filterPlaceholderStart = emptyText.indexOf('\u08B4'); int altMethodStart = filterPlaceholderStart + 3; SpannableStringBuilder ssb = new SpannableStringBuilder(emptyText); // show an image of the filter icon ssb.setSpan(new ImageSpan(this, R.drawable.ic_filter_small, ImageSpan.ALIGN_BASELINE), filterPlaceholderStart, filterPlaceholderStart + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); // make the alt method (swipe from right) less prominent and italic ssb.setSpan(new ForegroundColorSpan(ContextCompat.getColor(this, R.color.text_secondary_light)), altMethodStart, emptyText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); ssb.setSpan(new StyleSpan(Typeface.ITALIC), altMethodStart, emptyText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); noFiltersEmptyText.setText(ssb); noFiltersEmptyText.setOnClickListener(new View.OnClickListener() { @Override//from w w w . j a v a2s. c o m public void onClick(View v) { drawer.openDrawer(GravityCompat.END); } }); } noFiltersEmptyText.setVisibility(visibility); } else if (noFiltersEmptyText != null) { noFiltersEmptyText.setVisibility(visibility); } }
From source file:net.naonedbus.fragment.CustomListFragment.java
/** * Afficher un message avec une desciption et un symbole. * /*from w w w . j av a2 s . co m*/ * @param title * Le titre. * @param description * La description. * @param drawableRes * L'identifiant du symbole. */ protected void showMessage(final String title, final String description, final int drawableRes) { if (State.MESSAGE == mCurrentState) { return; } if (DBG) Log.d(LOG_TAG + "$" + getClass().getSimpleName(), "showMessage " + title + "\t" + description + "\t" + drawableRes); mCurrentState = State.MESSAGE; mFragmentView.findViewById(android.R.id.list).setVisibility(View.GONE); mFragmentView.findViewById(R.id.fragmentLoading).setVisibility(View.GONE); View message = mFragmentView.findViewById(R.id.fragmentMessage); if (message == null) { final ViewStub messageStrub = (ViewStub) mFragmentView.findViewById(R.id.fragmentMessageStub); message = messageStrub.inflate(); } message.setVisibility(View.VISIBLE); final TextView titleView = (TextView) message.findViewById(android.R.id.title); titleView.setText(title); titleView.setCompoundDrawablesWithIntrinsicBounds(0, drawableRes, 0, 0); final TextView descriptionView = (TextView) message.findViewById(android.R.id.summary); if (description != null) { descriptionView.setText(description); descriptionView.setVisibility(View.VISIBLE); } else { descriptionView.setVisibility(View.GONE); } }
From source file:io.plaidapp.ui.HomeActivity.java
private void checkConnectivity() { ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService( Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); boolean connected = activeNetworkInfo != null && activeNetworkInfo.isConnected(); if (!connected) { loading.setVisibility(View.GONE); ViewStub stub = (ViewStub) findViewById(R.id.stub_no_connection); ImageView iv = (ImageView) stub.inflate(); final AnimatedVectorDrawable avd = (AnimatedVectorDrawable) getDrawable(R.drawable.avd_no_connection); iv.setImageDrawable(avd);/*from w w w. j a va 2 s . c om*/ avd.start(); } }
From source file:jahirfiquitiva.iconshowcase.fragments.DonationsFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); /* Flattr *///from w w w. j a v a 2 s . co m if (mFlattrEnabled) { // inflate flattr view into stub ViewStub flattrViewStub = (ViewStub) getActivity().findViewById(R.id.donations__flattr_stub); flattrViewStub.inflate(); buildFlattrView(); } /* Google */ if (mGoogleEnabled) { // inflate google view into stub ViewStub googleViewStub = (ViewStub) getActivity().findViewById(R.id.donations__google_stub); googleViewStub.inflate(); // choose donation amount mGoogleSpinner = (Spinner) getActivity().findViewById(R.id.donations__google_android_market_spinner); ArrayAdapter<CharSequence> adapter; if (mDebug) { adapter = new ArrayAdapter<CharSequence>(getActivity(), android.R.layout.simple_spinner_item, CATALOG_DEBUG); } else { adapter = new ArrayAdapter<CharSequence>(getActivity(), android.R.layout.simple_spinner_item, mGoogleCatalogValues); } adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mGoogleSpinner.setAdapter(adapter); Button btGoogle = (Button) getActivity() .findViewById(R.id.donations__google_android_market_donate_button); btGoogle.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { donateGoogleOnClick(v); } }); // Create the helper, passing it our context and the public key to verify signatures with if (mDebug) Utils.showLog(context, "Creating IAB helper."); mHelper = new IabHelper(getActivity(), mGooglePubkey); // enable debug logging (for a production application, you should set this to false). mHelper.enableDebugLogging(mDebug); // Start setup. This is asynchronous and the specified listener // will be called once setup completes. if (mDebug) Utils.showLog(context, "Starting setup."); mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() { public void onIabSetupFinished(IabResult result) { if (mDebug) Utils.showLog(context, "Setup finished."); if (!result.isSuccess()) { // Oh noes, there was a problem. openDialog(android.R.drawable.ic_dialog_alert, R.string.donations__google_android_market_not_supported_title, getString(R.string.donations__google_android_market_not_supported)); } } }); } /* PayPal */ if (mPaypalEnabled) { // inflate paypal view into stub ViewStub paypalViewStub = (ViewStub) getActivity().findViewById(R.id.donations__paypal_stub); paypalViewStub.inflate(); Button btPayPal = (Button) getActivity().findViewById(R.id.donations__paypal_donate_button); btPayPal.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { donatePayPalOnClick(v); } }); } /* Bitcoin */ if (mBitcoinEnabled) { // inflate bitcoin view into stub ViewStub bitcoinViewStub = (ViewStub) getActivity().findViewById(R.id.donations__bitcoin_stub); bitcoinViewStub.inflate(); Button btBitcoin = (Button) getActivity().findViewById(R.id.donations__bitcoin_button); btBitcoin.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { donateBitcoinOnClick(v); } }); btBitcoin.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { // http://stackoverflow.com/a/11012443/832776 if (Build.VERSION.SDK_INT >= 11) { ClipboardManager clipboard = (ClipboardManager) getActivity() .getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText(mBitcoinAddress, mBitcoinAddress); clipboard.setPrimaryClip(clip); } else { @SuppressWarnings("deprecation") android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getActivity() .getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setText(mBitcoinAddress); } Toast.makeText(getActivity(), R.string.donations__bitcoin_toast_copy, Toast.LENGTH_SHORT) .show(); return true; } }); } }
From source file:org.sufficientlysecure.donations.DonationsFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); /* Flattr *///w ww . j ava 2 s . com if (mFlattrEnabled) { // inflate flattr view into stub ViewStub flattrViewStub = (ViewStub) getActivity().findViewById(R.id.donations__flattr_stub); flattrViewStub.inflate(); buildFlattrView(); } /* Google */ if (mGoogleEnabled) { // inflate google view into stub ViewStub googleViewStub = (ViewStub) getActivity().findViewById(R.id.donations__google_stub); googleViewStub.inflate(); // choose donation amount mGoogleSpinner = (Spinner) getActivity().findViewById(R.id.donations__google_android_market_spinner); ArrayAdapter<CharSequence> adapter; if (mDebug) { adapter = new ArrayAdapter<CharSequence>(getActivity(), android.R.layout.simple_spinner_item, CATALOG_DEBUG); } else { adapter = new ArrayAdapter<CharSequence>(getActivity(), android.R.layout.simple_spinner_item, mGoogleCatalogValues); } adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mGoogleSpinner.setAdapter(adapter); Button btGoogle = (Button) getActivity() .findViewById(R.id.donations__google_android_market_donate_button); btGoogle.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { donateGoogleOnClick(v); } }); // Create the helper, passing it our context and the public key to verify signatures with if (mDebug) Log.d(TAG, "Creating IAB helper."); mHelper = new IabHelper(getActivity(), mGooglePubkey); // enable debug logging (for a production application, you should set this to false). mHelper.enableDebugLogging(mDebug); // Start setup. This is asynchronous and the specified listener // will be called once setup completes. if (mDebug) Log.d(TAG, "Starting setup."); mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() { public void onIabSetupFinished(IabResult result) { if (mDebug) Log.d(TAG, "Setup finished."); if (!result.isSuccess()) { // Oh noes, there was a problem. openDialog(android.R.drawable.ic_dialog_alert, R.string.donations__google_android_market_not_supported_title, getString(R.string.donations__google_android_market_not_supported)); return; } // Have we been disposed of in the meantime? If so, quit. if (mHelper == null) return; } }); } /* PayPal */ if (mPaypalEnabled) { // inflate paypal view into stub ViewStub paypalViewStub = (ViewStub) getActivity().findViewById(R.id.donations__paypal_stub); paypalViewStub.inflate(); Button btPayPal = (Button) getActivity().findViewById(R.id.donations__paypal_donate_button); btPayPal.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { donatePayPalOnClick(v); } }); } /* Bitcoin */ if (mBitcoinEnabled) { // inflate bitcoin view into stub ViewStub bitcoinViewStub = (ViewStub) getActivity().findViewById(R.id.donations__bitcoin_stub); bitcoinViewStub.inflate(); Button btBitcoin = (Button) getActivity().findViewById(R.id.donations__bitcoin_button); btBitcoin.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { donateBitcoinOnClick(v); } }); btBitcoin.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { Toast.makeText(getActivity(), R.string.donations__bitcoin_toast_copy, Toast.LENGTH_SHORT) .show(); // http://stackoverflow.com/a/11012443/832776 if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) { android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getActivity() .getSystemService(getActivity().CLIPBOARD_SERVICE); clipboard.setText(mBitcoinAddress); } else { android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getActivity() .getSystemService(getActivity().CLIPBOARD_SERVICE); android.content.ClipData clip = android.content.ClipData.newPlainText(mBitcoinAddress, mBitcoinAddress); clipboard.setPrimaryClip(clip); } return true; } }); } }
From source file:com.gh4a.BaseActivity.java
protected void setErrorViewVisibility(boolean visible) { View content = findViewById(R.id.content); View error = findViewById(R.id.error); content.setVisibility(visible ? View.GONE : View.VISIBLE); mSwipeLayout.setEnabled(visible ? false : canSwipeToRefresh()); if (error == null) { if (!visible) { // It's not inflated yet and we don't want it // to be visible, so there's nothing to do return; }// w ww . j a v a 2s .c o m ViewStub errorStub = (ViewStub) findViewById(R.id.error_stub); error = errorStub.inflate(); error.findViewById(R.id.retry_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { setErrorViewVisibility(false); onRefresh(); } }); } error.setVisibility(visible ? View.VISIBLE : View.GONE); }
From source file:org.catnut.ui.ComposeTweetActivity.java
private void initGallery() { ViewStub viewStub = (ViewStub) findViewById(R.id.view_stub); mPhotos = (GridView) viewStub.inflate(); mUris = new LinkedList<Uri>(); mAdapter = new ThumbsAdapter(this, mUris); mPhotos.setAdapter(mAdapter);/*w w w . java 2s .c o m*/ // mPhotos.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { mUris.remove(position); mAdapter.notifyDataSetChanged(); return true; } }); // ? mPhotos.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(mUris.get(0), getString(R.string.mime_image)); startActivity(intent); } }); }
From source file:com.zion.htf.ui.fragment.ArtistSoundcloudFragment.java
private void initMediaController() { ViewStub stub = (ViewStub) this.view.findViewById(R.id.mediaplayer_controller_view_stub); if (null != stub) { ArtistSoundcloudFragment.Listeners listeners = new ArtistSoundcloudFragment.Listeners(); stub.inflate(); ToggleButton playButton = (ToggleButton) this.view.findViewById(R.id.button_play); ToggleButton shuffleButton = (ToggleButton) this.view.findViewById(R.id.button_shuffle); ToggleButton repeatButton = (ToggleButton) this.view.findViewById(R.id.button_repeat); ImageButton prevButton = (ImageButton) this.view.findViewById(R.id.button_prev); ImageButton nextButton = (ImageButton) this.view.findViewById(R.id.button_next); // Set button click listeners playButton.setOnClickListener(listeners); shuffleButton.setOnClickListener(listeners); repeatButton.setOnClickListener(listeners); prevButton.setOnClickListener(listeners); nextButton.setOnClickListener(listeners); // Get a reference to the mediaplayer controls this.seekBar = (SeekBar) this.view.findViewById(R.id.seekbar); this.timeElapsedTextView = (TextView) this.view.findViewById(R.id.elapsed_time); this.durationTextView = (TextView) this.view.findViewById(R.id.duration); this.playButton = playButton; this.shuffleButton = shuffleButton; this.repeatButton = repeatButton; this.seekBar.setOnSeekBarChangeListener(listeners); }/*from w w w .ja va2 s .c o m*/ }
From source file:de.meisterfuu.animexxenger.ui.ContactList.java
/** * Show the groups view.//from w w w . j ava 2 s . com */ private void showGroups() { ViewStub stub = (ViewStub) findViewById(R.id.contactlist_stub); if (stub != null) { View v = stub.inflate(); groupGallery = (Gallery) v.findViewById(R.id.contactlist_banner); groupGallery.setOnItemClickListener(new OnItemClickGroupName()); groupGallery.setAdapter(mAdapterBanner); groupGallery.setSelection(0); } else { ((LinearLayout) findViewById(R.id.contactlist_groupstub)).setVisibility(View.VISIBLE); groupGallery = (Gallery) findViewById(R.id.contactlist_banner); groupGallery.setSelection(0); } GroupHolder.setUniquePrincipal(mListGroup, 0); }
From source file:co.scandy.example.scandycoreandroidexample.MainActivity.java
@SuppressWarnings("StatementWithEmptyBody") @Override/*from ww w. j a v a 2 s .c o m*/ public boolean onNavigationItemSelected(MenuItem item) { // Handle navigation view item clicks here. int id = item.getItemId(); if (id == R.id.initialize_button) { // Setup the scan_controls if (mScanControlsView == null) { // Find the controls_container ViewStub stub = (ViewStub) findViewById(R.id.controls_container); // Set the resource to be the scan_controls stub.setLayoutResource(R.layout.scan_controls); // Store the view inflated as the mScanControlsView mScanControlsView = (LinearLayout) stub.inflate(); // Bind the newly created controls to their callbacks bindScanControls(); } else { // Or just make them visible again mScanControlsView.setVisibility(View.VISIBLE); } // Initialize the scanner with the first file we find in the Download directory File dir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) .getAbsolutePath()); String rrf_path = ""; // NOTE: you could present your users with a list of files to chose from if you felt like it! for (File file : dir.listFiles()) { if (file.getName().contains(".rrf")) { rrf_path = file.getAbsolutePath(); break; } } // check to see if we have a USB sensor attached if (ScandyCore.hasValidSensor()) { ScandyCore.initializeScanner(); } else if (rrf_path != "") { ScandyCore.initializeScanner(rrf_path); } else { // Show an Alert that we didn't find anything to initialize a scanner with AlertDialog alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setTitle("No scanner found"); alertDialog.setMessage("Didn't find a pico flexx or a pre-recorded file."); alertDialog.show(); } } else if (id == R.id.loadmesh_button) { // Make sure to uninitialize the scanner. Scandy Core gracefully handles various states. ScandyCore.uninitializeScanner(); try { // Lets load a test Obj ScandyCore .loadMeshFromURL(new URL("https://s3.amazonaws.com/scandycore-test-assets/scandy-obj.zip")); } catch (MalformedURLException e) { Log.e(TAG, e.getMessage()); } } else if (id == R.id.nav_manage) { } else if (id == R.id.nav_share) { } else if (id == R.id.nav_send) { } DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); return true; }