List of usage examples for android.view ViewStub inflate
public View inflate()
From source file:org.mozilla.gecko.home.BookmarksPanel.java
private void updateUiFromCursor(Cursor c) { if ((c == null || c.getCount() == 0) && mEmptyView == null) { // Set empty page view. We delay this so that the empty view won't flash. final ViewStub emptyViewStub = (ViewStub) getView().findViewById(R.id.home_empty_view_stub); mEmptyView = emptyViewStub.inflate(); final ImageView emptyIcon = (ImageView) mEmptyView.findViewById(R.id.home_empty_image); emptyIcon.setImageResource(R.drawable.icon_bookmarks_empty); final TextView emptyText = (TextView) mEmptyView.findViewById(R.id.home_empty_text); emptyText.setText(R.string.home_bookmarks_empty); mList.setEmptyView(mEmptyView);//from w w w. j a va2 s .c om } }
From source file:org.mozilla.gecko.home.ReadingListPanel.java
private void updateUiFromCursor(Cursor c) { // We delay setting the empty view until the cursor is actually empty. // This avoids image flashing. if ((c == null || c.getCount() == 0) && mEmptyView == null) { final ViewStub emptyViewStub = (ViewStub) mTopView.findViewById(R.id.home_empty_view_stub); mEmptyView = emptyViewStub.inflate(); final TextView emptyHint = (TextView) mEmptyView.findViewById(R.id.home_empty_hint); if (HardwareUtils.isLowMemoryPlatform()) { emptyHint.setVisibility(View.GONE); } else {/*from w w w . j a v a2s. com*/ String readingListHint = emptyHint.getText().toString(); // Use an ImageSpan to include the reader icon in the "Tip". int imageSpanIndex = readingListHint.indexOf(MATCH_STRING); if (imageSpanIndex != -1) { final ImageSpan readingListIcon = new ImageSpan(getActivity(), R.drawable.reader_cropped, ImageSpan.ALIGN_BOTTOM); final SpannableStringBuilder hintBuilder = new SpannableStringBuilder(readingListHint); // Add additional spacing. hintBuilder.insert(imageSpanIndex + MATCH_STRING.length(), " "); hintBuilder.insert(imageSpanIndex, " "); // Add icon. hintBuilder.setSpan(readingListIcon, imageSpanIndex + 1, imageSpanIndex + MATCH_STRING.length() + 1, Spanned.SPAN_INCLUSIVE_INCLUSIVE); emptyHint.setText(hintBuilder, TextView.BufferType.SPANNABLE); } } mList.setEmptyView(mEmptyView); } }
From source file:com.tomeokin.lspush.biz.home.CollectionWebViewActivity.java
@Override protected void onPrepareInflater(ViewStub container) { container.setLayoutResource(R.layout.layout_collection_web_view_bottom_bar); View bottomBarView = container.inflate(); mBottomBar = new BottomBar(bottomBarView); }
From source file:bander.notepad.PrefsActivityAppCompat.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Notepad.setAppCompatThemeFromPreferences(this, "Prefs"); setContentView(R.layout.preferences_toolbar); SharedPreferences mSettings = PreferenceManager.getDefaultSharedPreferences(this); ViewStub stub = (ViewStub) findViewById(R.id.toolbarWrapper); if (mSettings.getBoolean("darkAppCompatTheme", false)) stub.setLayoutResource(R.layout.toolbar_dark); else//from ww w . j a v a2 s . co m stub.setLayoutResource(R.layout.toolbar_light); stub.inflate(); toolbar = (Toolbar) findViewById(R.id.toolbar); Notepad.setToolbarColor(this); setSupportActionBar(toolbar); if (mSettings.getBoolean("darkAppCompatTheme", false)) toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha); else toolbar.setNavigationIcon( IconTintFactory.setDarkMaterialColor(R.drawable.abc_ic_ab_back_mtrl_am_alpha, this)); getSupportActionBar().setDisplayHomeAsUpEnabled(true); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onBackPressed(); } }); // Starting the Fragment Log.i("INFO", "Starting PreferenceFragment..."); FragmentManager manager = getSupportFragmentManager(); FragmentTransaction transaction = manager.beginTransaction(); transaction.replace(R.id.prefContent, myFragment); transaction.commit(); }
From source file:com.keifermiller.inkbar.activities.IBActivity.java
@Override public void setContentView(int layoutResId) { RelativeLayout iBContent = (RelativeLayout) View.inflate(this, R.layout.ib_activity_layout, null); ViewStub stub = (ViewStub) iBContent.findViewById(R.id.view_stub); stub.setLayoutResource(layoutResId); stub.inflate(); super.setContentView(iBContent, new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT)); }
From source file:com.devspacenine.poolpal.fragment.DatePickerDialogFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) { Bundle args = getArguments();//from w w w. java 2s . c o m mRequestCode = args.getInt(REQUEST_CODE); View v; v = inflater.inflate(R.layout.input_dialog, container, false); // Set the layout of the view stub ViewStub stub = (ViewStub) v.findViewById(R.id.stub); stub.setLayoutResource(args.getInt(LAYOUT)); mInputView = (ViewGroup) stub.inflate(); // Set the title mTitleText = (TextView) v.findViewById(R.id.title); mTitleText.setText(args.getString(TITLE)); // Set the prompt mPrompt = (TextView) v.findViewById(R.id.prompt); mPrompt.setVisibility(View.VISIBLE); mPrompt.setText(args.getString(DETAILS)); if (!(mValues.containsKey(PoolDataAdapter.VALUE)) || mValues.getString(PoolDataAdapter.VALUE) == null) { mValues.putString(PoolDataAdapter.VALUE, ""); } mCancelButton = (TextView) v.findViewById(R.id.cancel); mConfirmButton = (TextView) v.findViewById(R.id.confirm); mCancelButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { negativeDecision(); } }); mConfirmButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { positiveDecision(); } }); Calendar initTime = (Calendar) mValues.getSerializable(TaskDataAdapter.VALUE_DATE); Calendar minTime = (Calendar) mValues.getSerializable(TaskDataAdapter.VALUE_DATE_MIN); Calendar maxTime = (Calendar) mValues.getSerializable(TaskDataAdapter.VALUE_DATE_MAX); int interval = mValues.getInt(TaskDataAdapter.VALUE_DATE_INTERVAL); if (interval > 1) { int minutes = initTime.get(Calendar.MINUTE); int diff = ((minutes + interval / 2) / interval) * interval - minutes; initTime.add(Calendar.MINUTE, diff); } mContainer = (SliderContainer) mInputView; mContainer.setOnTimeChangeListener(onTimeChangeListener); mContainer.setMinuteInterval(interval); mContainer.setTime(initTime); if (minTime != null) mContainer.setMinTime(minTime); if (maxTime != null) mContainer.setMaxTime(maxTime); return v; }
From source file:com.lambdasoup.appbarsyncedfabSample.BaseAppBarActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_base); // ViewStub replacement is here to allow DRY with the different activities // that differ only in their AppBarLayout. Usually, you'd just have your AppBarLayout // directly declared in your activity layout xml. ViewStub appBarStub = (ViewStub) findViewById(R.id.app_bar_stub); onBeforeInflateAppBarLayout();/* w w w . j a v a 2s . c o m*/ //noinspection ConstantConditions appBarStub.setLayoutResource(getAppBarLayoutResource()); appBarStub.inflate(); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); if (toolbar != null) { setSupportActionBar(toolbar); //noinspection ConstantConditions getSupportActionBar().setTitle(getTitle()); } final RecyclerView itemsList = (RecyclerView) findViewById(R.id.content_list); itemsAdapter = new ItemsAdapter(new ItemsAdapter.OnItemClickListener() { @Override public void onItemClick(Long item) { //noinspection ConstantConditions Snackbar.make(itemsList, getString(R.string.item_clicked, item), Snackbar.LENGTH_LONG).show(); } }); //noinspection ConstantConditions itemsList.setAdapter(itemsAdapter); ItemTouchHelper swipeDismiss = new ItemTouchHelper( new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.START | ItemTouchHelper.END) { @Override public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) { return false; } @Override public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) { itemsAdapter.removeItem(viewHolder.getItemId()); } }); swipeDismiss.attachToRecyclerView(itemsList); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); //noinspection ConstantConditions fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { itemsAdapter.addItem(); } }); drawer = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.addDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); //noinspection ConstantConditions navigationView.getMenu().findItem(getNavId()).setChecked(true); navigationView.setNavigationItemSelectedListener(this); }
From source file:com.linkedin.android.eventsapp.EventFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final String eventNameArg = getArguments().getString(EXTRA_EVENT_NAME); final long eventDateArg = getArguments().getLong(EXTRA_EVENT_DATE); final String eventLocationArg = getArguments().getString(EXTRA_EVENT_LOCATION); int pictureIdArg = getArguments().getInt(EXTRA_PICTURE_ID); boolean isAttendingArg = getArguments().getBoolean(EXTRA_EVENT_ATTENDING); Person[] attendeesArg = (Person[]) getArguments().getParcelableArray(EXTRA_EVENT_ATTENDEES); SimpleDateFormat dateFormat = new SimpleDateFormat("E dd MMM yyyy 'at' hh:00 a"); final String dateString = dateFormat.format(new Date(eventDateArg)); View v = inflater.inflate(R.layout.layout_event_fragment, container, false); boolean accessTokenValid = LISessionManager.getInstance(getActivity()).getSession().isValid(); if (!accessTokenValid) { ViewStub linkedinLogin = (ViewStub) v.findViewById(R.id.connectWithLinkedInStub); linkedinLogin.inflate(); Button loginButton = (Button) v.findViewById(R.id.connectWithLinkedInButton); loginButton.setOnClickListener(new View.OnClickListener() { @Override//from w ww . j av a2 s.c o m public void onClick(View v) { Log.i(TAG, "clicked login button"); LISessionManager.getInstance(getActivity()).init(getActivity(), Constants.scope, new AuthListener() { @Override public void onAuthSuccess() { Intent intent = new Intent(getActivity(), MainActivity.class); startActivity(intent); getActivity().finish(); } @Override public void onAuthError(LIAuthError error) { } }, false); } }); } TextView eventNameView = (TextView) v.findViewById(R.id.eventName); eventNameView.setText(eventNameArg); TextView eventLocationAndDateView = (TextView) v.findViewById(R.id.eventLocationAndDate); eventLocationAndDateView.setText(eventLocationArg + " " + dateString); TextView eventAttendeeCount = (TextView) v.findViewById(R.id.attendeeCount); eventAttendeeCount.setText("Other Attendees (" + attendeesArg.length + ")"); ImageView eventImageView = (ImageView) v.findViewById(R.id.eventImage); eventImageView.setImageResource(pictureIdArg); final Button attendButton = (Button) v.findViewById(R.id.attendButton); final Button declineButton = (Button) v.findViewById(R.id.declineButton); if (isAttendingArg) { attendButton.setText("Attending"); attendButton.setEnabled(false); declineButton.setText("Decline"); declineButton.setEnabled(true); } attendButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ((Button) v).setText("Attending"); v.setEnabled(false); declineButton.setText("Decline"); declineButton.setEnabled(true); if (LISessionManager.getInstance(getActivity()).getSession().isValid()) { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity()); alertDialogBuilder.setTitle("Share on LinkedIn?"); alertDialogBuilder.setCancelable(true) .setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { JSONObject shareObject = new JSONObject(); try { JSONObject visibilityCode = new JSONObject(); visibilityCode.put("code", "anyone"); shareObject.put("visibility", visibilityCode); shareObject.put("comment", "I am attending " + eventNameArg + " in " + eventLocationArg + " on " + dateString); } catch (JSONException e) { } APIHelper.getInstance(getActivity()).postRequest(getActivity(), Constants.shareBaseUrl, shareObject, new ApiListener() { @Override public void onApiSuccess(ApiResponse apiResponse) { Toast.makeText(getActivity(), "Your share was successful!", Toast.LENGTH_LONG); } @Override public void onApiError(LIApiError apiError) { Log.e(TAG, apiError.toString()); Toast.makeText(getActivity(), "Your share was unsuccessful. Try again later!", Toast.LENGTH_LONG); } }); } }).setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); } } }); declineButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ((Button) v).setText("Declined"); v.setEnabled(false); attendButton.setText("Attend"); attendButton.setEnabled(true); } }); ListView attendeesListView = (ListView) v.findViewById(R.id.attendeesList); AttendeeAdapter adapter = new AttendeeAdapter(getActivity(), R.layout.attendee_list_item, attendeesArg, accessTokenValid); attendeesListView.setAdapter(adapter); attendeesListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { ArrayAdapter adapter = (ArrayAdapter) parent.getAdapter(); Person person = (Person) adapter.getItem(position); Intent intent = new Intent(getActivity(), ProfileActivity.class); Bundle extras = new Bundle(); extras.putParcelable("person", person); intent.putExtras(extras); startActivity(intent); } }); return v; }
From source file:at.maui.cheapcast.fragment.DonationsFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); /* Flattr */// ww w. ja v a2s. c o m if (mFlattrEnabled) { // inflate flattr view into stub ViewStub flattrViewStub = (ViewStub) getActivity().findViewById(R.id.donations__flattr_stub); flattrViewStub.inflate(); buildFlattrView(); } /* 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); } }); } }
From source file:us.phyxsi.gameshelf.ui.HomeActivity.java
private void setNoResultsEmptyTextVisibility(int visibility) { if (visibility == View.VISIBLE) { if (noResultsEmptyText == null) { // create the no results empty text ViewStub stub = (ViewStub) findViewById(R.id.stub_no_results); noResultsEmptyText = (TextView) stub.inflate(); String emptyText = getString(R.string.no_results_found); int addPlaceholderStart = emptyText.indexOf('\u08B4'); int altMethodStart = addPlaceholderStart + 3; SpannableStringBuilder ssb = new SpannableStringBuilder(emptyText); // show an image of the add icon ssb.setSpan(new ImageSpan(this, R.drawable.ic_add_small, ImageSpan.ALIGN_BASELINE), addPlaceholderStart, addPlaceholderStart + 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); noResultsEmptyText.setText(ssb); }//w w w.j ava2s. c o m noResultsEmptyText.setVisibility(visibility); } else if (noResultsEmptyText != null) { noResultsEmptyText.setVisibility(visibility); } }