List of usage examples for android.view ViewStub ViewStub
public ViewStub(Context context)
From source file:com.android.settings.PreviewPagerAdapter.java
public PreviewPagerAdapter(Context context, boolean isLayoutRtl, int[] previewSampleResIds, Configuration[] configurations) { mIsLayoutRtl = isLayoutRtl;/* www . j ava 2 s . co m*/ mPreviewFrames = new FrameLayout[previewSampleResIds.length]; mViewStubInflated = new boolean[previewSampleResIds.length][configurations.length]; for (int i = 0; i < previewSampleResIds.length; ++i) { int p = mIsLayoutRtl ? previewSampleResIds.length - 1 - i : i; mPreviewFrames[p] = new FrameLayout(context); mPreviewFrames[p].setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT)); for (int j = 0; j < configurations.length; ++j) { // Create a new configuration for the specified value. It won't // have any theme set, so manually apply the current theme. final Context configContext = context.createConfigurationContext(configurations[j]); configContext.setTheme(context.getThemeResId()); final LayoutInflater configInflater = LayoutInflater.from(configContext); final ViewStub sampleViewStub = new ViewStub(configContext); sampleViewStub.setLayoutResource(previewSampleResIds[i]); final int fi = i, fj = j; sampleViewStub.setOnInflateListener(new OnInflateListener() { @Override public void onInflate(ViewStub stub, View inflated) { inflated.setVisibility(stub.getVisibility()); mViewStubInflated[fi][fj] = true; } }); mPreviewFrames[p].addView(sampleViewStub); } } }
From source file:at.jclehner.rxdroid.DrugListActivity.java
@Override public View makeView(int offset) { if (offset <= -(InfiniteViewPagerAdapter.MAX / 2)) { if (LOGV) Log.d(TAG, "makeView: returning stub for offset=" + offset); return new ViewStub(this); }//from w w w . j a v a2s . c om final View v = getLayoutInflater().inflate(R.layout.drug_list_fragment, null); final AutoDragSortListView listView = (AutoDragSortListView) v.findViewById(android.R.id.list); final TextView emptyView = (TextView) v.findViewById(android.R.id.empty); final Date date = DateTime.add(mOriginalDate, Calendar.DAY_OF_MONTH, offset); if (LOGV) Log.d(TAG, "makeView: date=" + DateTime.toDateString(date)); final List<Drug> drugs = Entries.getAllDrugs(mCurrentPatientId); Collections.sort(drugs, new DrugComparator()); updateListAdapter(listView, date, drugs); final String text; if (drugs.isEmpty()) { if (Settings.getBoolean(Keys.COMPACT_ACTION_BAR, Defaults.COMPACT_ACTION_BAR)) { Log.d(TAG, "COMPACT_ACTION_BAR"); final boolean hasHardwareMenuKey; if (Version.SDK_IS_PRE_HONEYCOMB) hasHardwareMenuKey = true; else { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) { // For Honeycomb, there appears to be no way to find out. As it // targets tablets only, we will assume that none of these have a // hardware menu key... hasHardwareMenuKey = false; } else hasHardwareMenuKey = ViewConfiguration.get(this).hasPermanentMenuKey(); } final StringBuilder sb = new StringBuilder( getString(R.string._msg_no_drugs_compact_ab, getString(R.string._title_add))); if (hasHardwareMenuKey) sb.append(" " + getString(R.string._help_msg_menu_hardware)); else sb.append(" " + getString(R.string._help_msg_menu_ab_overflow)); text = sb.toString(); } else { Log.d(TAG, "EXTENDED_ACTION_BAR"); text = getString(R.string._msg_no_drugs_extended_ab, getString(R.string._title_add)); } } else text = getString(R.string._msg_no_doses_on_this_day, getString(R.string._title_add)); emptyView.setText(text); listView.setEmptyView(emptyView); listView.setDragHandleId(R.id.drug_icon); return v; }