Search in sources :

Example 36 with LayoutInflater

use of android.view.LayoutInflater in project platform_frameworks_base by android.

the class BaseStatusBar method inflateViews.

protected boolean inflateViews(Entry entry, ViewGroup parent) {
    PackageManager pmUser = getPackageManagerForUser(mContext, entry.notification.getUser().getIdentifier());
    final StatusBarNotification sbn = entry.notification;
    try {
        entry.cacheContentViews(mContext, null);
    } catch (RuntimeException e) {
        Log.e(TAG, "Unable to get notification remote views", e);
        return false;
    }
    final RemoteViews contentView = entry.cachedContentView;
    final RemoteViews bigContentView = entry.cachedBigContentView;
    final RemoteViews headsUpContentView = entry.cachedHeadsUpContentView;
    final RemoteViews publicContentView = entry.cachedPublicContentView;
    if (contentView == null) {
        Log.v(TAG, "no contentView for: " + sbn.getNotification());
        return false;
    }
    if (DEBUG) {
        Log.v(TAG, "publicContentView: " + publicContentView);
    }
    ExpandableNotificationRow row;
    // Stash away previous user expansion state so we can restore it at
    // the end.
    boolean hasUserChangedExpansion = false;
    boolean userExpanded = false;
    boolean userLocked = false;
    if (entry.row != null) {
        row = entry.row;
        hasUserChangedExpansion = row.hasUserChangedExpansion();
        userExpanded = row.isUserExpanded();
        userLocked = row.isUserLocked();
        entry.reset();
        if (hasUserChangedExpansion) {
            row.setUserExpanded(userExpanded);
        }
    } else {
        // create the row view
        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        row = (ExpandableNotificationRow) inflater.inflate(R.layout.status_bar_notification_row, parent, false);
        row.setExpansionLogger(this, entry.notification.getKey());
        row.setGroupManager(mGroupManager);
        row.setHeadsUpManager(mHeadsUpManager);
        row.setRemoteInputController(mRemoteInputController);
        row.setOnExpandClickListener(this);
        // Get the app name.
        // Note that Notification.Builder#bindHeaderAppName has similar logic
        // but since this field is used in the guts, it must be accurate.
        // Therefore we will only show the application label, or, failing that, the
        // package name. No substitutions.
        final String pkg = sbn.getPackageName();
        String appname = pkg;
        try {
            final ApplicationInfo info = pmUser.getApplicationInfo(pkg, PackageManager.GET_UNINSTALLED_PACKAGES | PackageManager.GET_DISABLED_COMPONENTS);
            if (info != null) {
                appname = String.valueOf(pmUser.getApplicationLabel(info));
            }
        } catch (NameNotFoundException e) {
        // Do nothing
        }
        row.setAppName(appname);
    }
    workAroundBadLayerDrawableOpacity(row);
    bindDismissListener(row);
    // NB: the large icon is now handled entirely by the template
    // bind the click event to the content area
    NotificationContentView contentContainer = row.getPrivateLayout();
    NotificationContentView contentContainerPublic = row.getPublicLayout();
    row.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
    if (ENABLE_REMOTE_INPUT) {
        row.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
    }
    mNotificationClicker.register(row, sbn);
    // set up the adaptive layout
    View contentViewLocal = null;
    View bigContentViewLocal = null;
    View headsUpContentViewLocal = null;
    View publicViewLocal = null;
    try {
        contentViewLocal = contentView.apply(sbn.getPackageContext(mContext), contentContainer, mOnClickHandler);
        if (bigContentView != null) {
            bigContentViewLocal = bigContentView.apply(sbn.getPackageContext(mContext), contentContainer, mOnClickHandler);
        }
        if (headsUpContentView != null) {
            headsUpContentViewLocal = headsUpContentView.apply(sbn.getPackageContext(mContext), contentContainer, mOnClickHandler);
        }
        if (publicContentView != null) {
            publicViewLocal = publicContentView.apply(sbn.getPackageContext(mContext), contentContainerPublic, mOnClickHandler);
        }
        if (contentViewLocal != null) {
            contentViewLocal.setIsRootNamespace(true);
            contentContainer.setContractedChild(contentViewLocal);
        }
        if (bigContentViewLocal != null) {
            bigContentViewLocal.setIsRootNamespace(true);
            contentContainer.setExpandedChild(bigContentViewLocal);
        }
        if (headsUpContentViewLocal != null) {
            headsUpContentViewLocal.setIsRootNamespace(true);
            contentContainer.setHeadsUpChild(headsUpContentViewLocal);
        }
        if (publicViewLocal != null) {
            publicViewLocal.setIsRootNamespace(true);
            contentContainerPublic.setContractedChild(publicViewLocal);
        }
    } catch (RuntimeException e) {
        final String ident = sbn.getPackageName() + "/0x" + Integer.toHexString(sbn.getId());
        Log.e(TAG, "couldn't inflate view for notification " + ident, e);
        return false;
    }
    // Extract target SDK version.
    try {
        ApplicationInfo info = pmUser.getApplicationInfo(sbn.getPackageName(), 0);
        entry.targetSdk = info.targetSdkVersion;
    } catch (NameNotFoundException ex) {
        Log.e(TAG, "Failed looking up ApplicationInfo for " + sbn.getPackageName(), ex);
    }
    entry.autoRedacted = entry.notification.getNotification().publicVersion == null;
    if (MULTIUSER_DEBUG) {
        TextView debug = (TextView) row.findViewById(R.id.debug_info);
        if (debug != null) {
            debug.setVisibility(View.VISIBLE);
            debug.setText("CU " + mCurrentUserId + " NU " + entry.notification.getUserId());
        }
    }
    entry.row = row;
    entry.row.setOnActivatedListener(this);
    entry.row.setExpandable(bigContentViewLocal != null);
    applyColorsAndBackgrounds(sbn, entry);
    // Restore previous flags.
    if (hasUserChangedExpansion) {
        // Note: setUserExpanded() conveniently ignores calls with
        //       userExpanded=true if !isExpandable().
        row.setUserExpanded(userExpanded);
    }
    row.setUserLocked(userLocked);
    row.onNotificationUpdated(entry);
    return true;
}
Also used : NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) ApplicationInfo(android.content.pm.ApplicationInfo) ImageView(android.widget.ImageView) View(android.view.View) RemoteInputView(com.android.systemui.statusbar.policy.RemoteInputView) TextView(android.widget.TextView) NavigationBarView(com.android.systemui.statusbar.phone.NavigationBarView) RemoteViews(android.widget.RemoteViews) PackageManager(android.content.pm.PackageManager) StatusBarNotification(android.service.notification.StatusBarNotification) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView)

Example 37 with LayoutInflater

use of android.view.LayoutInflater in project platform_frameworks_base by android.

the class InputMethodManagerService method showInputMethodMenu.

private void showInputMethodMenu(boolean showAuxSubtypes) {
    if (DEBUG)
        Slog.v(TAG, "Show switching menu. showAuxSubtypes=" + showAuxSubtypes);
    final Context context = mContext;
    final boolean isScreenLocked = isScreenLocked();
    final String lastInputMethodId = mSettings.getSelectedInputMethod();
    int lastInputMethodSubtypeId = mSettings.getSelectedInputMethodSubtypeId(lastInputMethodId);
    if (DEBUG)
        Slog.v(TAG, "Current IME: " + lastInputMethodId);
    synchronized (mMethodMap) {
        final HashMap<InputMethodInfo, List<InputMethodSubtype>> immis = mSettings.getExplicitlyOrImplicitlyEnabledInputMethodsAndSubtypeListLocked(mContext);
        if (immis == null || immis.size() == 0) {
            return;
        }
        hideInputMethodMenuLocked();
        final List<ImeSubtypeListItem> imList = mSwitchingController.getSortedInputMethodAndSubtypeListLocked(showAuxSubtypes, isScreenLocked);
        if (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID) {
            final InputMethodSubtype currentSubtype = getCurrentInputMethodSubtypeLocked();
            if (currentSubtype != null) {
                final InputMethodInfo currentImi = mMethodMap.get(mCurMethodId);
                lastInputMethodSubtypeId = InputMethodUtils.getSubtypeIdFromHashCode(currentImi, currentSubtype.hashCode());
            }
        }
        final int N = imList.size();
        mIms = new InputMethodInfo[N];
        mSubtypeIds = new int[N];
        int checkedItem = 0;
        for (int i = 0; i < N; ++i) {
            final ImeSubtypeListItem item = imList.get(i);
            mIms[i] = item.mImi;
            mSubtypeIds[i] = item.mSubtypeId;
            if (mIms[i].getId().equals(lastInputMethodId)) {
                int subtypeId = mSubtypeIds[i];
                if ((subtypeId == NOT_A_SUBTYPE_ID) || (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID && subtypeId == 0) || (subtypeId == lastInputMethodSubtypeId)) {
                    checkedItem = i;
                }
            }
        }
        final Context settingsContext = new ContextThemeWrapper(context, com.android.internal.R.style.Theme_DeviceDefault_Settings);
        mDialogBuilder = new AlertDialog.Builder(settingsContext);
        mDialogBuilder.setOnCancelListener(new OnCancelListener() {

            @Override
            public void onCancel(DialogInterface dialog) {
                hideInputMethodMenu();
            }
        });
        final Context dialogContext = mDialogBuilder.getContext();
        final TypedArray a = dialogContext.obtainStyledAttributes(null, com.android.internal.R.styleable.DialogPreference, com.android.internal.R.attr.alertDialogStyle, 0);
        final Drawable dialogIcon = a.getDrawable(com.android.internal.R.styleable.DialogPreference_dialogIcon);
        a.recycle();
        mDialogBuilder.setIcon(dialogIcon);
        final LayoutInflater inflater = dialogContext.getSystemService(LayoutInflater.class);
        final View tv = inflater.inflate(com.android.internal.R.layout.input_method_switch_dialog_title, null);
        mDialogBuilder.setCustomTitle(tv);
        // Setup layout for a toggle switch of the hardware keyboard
        mSwitchingDialogTitleView = tv;
        mSwitchingDialogTitleView.findViewById(com.android.internal.R.id.hard_keyboard_section).setVisibility(mWindowManagerInternal.isHardKeyboardAvailable() ? View.VISIBLE : View.GONE);
        final Switch hardKeySwitch = (Switch) mSwitchingDialogTitleView.findViewById(com.android.internal.R.id.hard_keyboard_switch);
        hardKeySwitch.setChecked(mShowImeWithHardKeyboard);
        hardKeySwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                mSettings.setShowImeWithHardKeyboard(isChecked);
                // Ensure that the input method dialog is dismissed when changing
                // the hardware keyboard state.
                hideInputMethodMenu();
            }
        });
        final ImeSubtypeListAdapter adapter = new ImeSubtypeListAdapter(dialogContext, com.android.internal.R.layout.input_method_switch_item, imList, checkedItem);
        final OnClickListener choiceListener = new OnClickListener() {

            @Override
            public void onClick(final DialogInterface dialog, final int which) {
                synchronized (mMethodMap) {
                    if (mIms == null || mIms.length <= which || mSubtypeIds == null || mSubtypeIds.length <= which) {
                        return;
                    }
                    final InputMethodInfo im = mIms[which];
                    int subtypeId = mSubtypeIds[which];
                    adapter.mCheckedItem = which;
                    adapter.notifyDataSetChanged();
                    hideInputMethodMenu();
                    if (im != null) {
                        if (subtypeId < 0 || subtypeId >= im.getSubtypeCount()) {
                            subtypeId = NOT_A_SUBTYPE_ID;
                        }
                        setInputMethodLocked(im.getId(), subtypeId);
                    }
                }
            }
        };
        mDialogBuilder.setSingleChoiceItems(adapter, checkedItem, choiceListener);
        mSwitchingDialog = mDialogBuilder.create();
        mSwitchingDialog.setCanceledOnTouchOutside(true);
        mSwitchingDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG);
        mSwitchingDialog.getWindow().getAttributes().privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
        mSwitchingDialog.getWindow().getAttributes().setTitle("Select input method");
        updateSystemUi(mCurToken, mImeWindowVis, mBackDisposition);
        mSwitchingDialog.show();
    }
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) InputMethodInfo(android.view.inputmethod.InputMethodInfo) TypedArray(android.content.res.TypedArray) ArrayList(java.util.ArrayList) List(java.util.List) LocaleList(android.os.LocaleList) OnCancelListener(android.content.DialogInterface.OnCancelListener) IInputContext(com.android.internal.view.IInputContext) Context(android.content.Context) InputMethodSubtype(android.view.inputmethod.InputMethodSubtype) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) Drawable(android.graphics.drawable.Drawable) View(android.view.View) TextView(android.widget.TextView) ImeSubtypeListItem(com.android.internal.inputmethod.InputMethodSubtypeSwitchingController.ImeSubtypeListItem) ContextThemeWrapper(android.view.ContextThemeWrapper) Switch(android.widget.Switch) LayoutInflater(android.view.LayoutInflater) OnClickListener(android.content.DialogInterface.OnClickListener) CompoundButton(android.widget.CompoundButton)

Example 38 with LayoutInflater

use of android.view.LayoutInflater in project platform_frameworks_base by android.

the class DocumentHolderTest method setUp.

public void setUp() throws Exception {
    Context context = getContext();
    LayoutInflater inflater = LayoutInflater.from(context);
    mHolder = new DocumentHolder(getContext(), inflater.inflate(R.layout.item_doc_list, null)) {

        @Override
        public void bind(Cursor cursor, String modelId, State state) {
        }
    };
    mListener = new TestListener();
    mHolder.addEventListener(mListener);
    mHolder.itemView.requestLayout();
    mHolder.itemView.invalidate();
}
Also used : Context(android.content.Context) State(com.android.documentsui.State) LayoutInflater(android.view.LayoutInflater) Cursor(android.database.Cursor)

Example 39 with LayoutInflater

use of android.view.LayoutInflater in project platform_frameworks_base by android.

the class PageAdapter method updatePreviewAreaPageSizeAndEmptyState.

private void updatePreviewAreaPageSizeAndEmptyState() {
    if (mMediaSize == null) {
        return;
    }
    final int availableWidth = mPreviewArea.getWidth();
    final int availableHeight = mPreviewArea.getHeight();
    // Page aspect ratio to keep.
    final float pageAspectRatio = (float) mMediaSize.getWidthMils() / mMediaSize.getHeightMils();
    // Make sure we have no empty columns.
    final int columnCount = Math.min(mSelectedPageCount, mColumnCount);
    mPreviewArea.setColumnCount(columnCount);
    // Compute max page width.
    final int horizontalMargins = 2 * columnCount * mPreviewPageMargin;
    final int horizontalPaddingAndMargins = horizontalMargins + 2 * mPreviewListPadding;
    final int pageContentDesiredWidth = (int) ((((float) availableWidth - horizontalPaddingAndMargins) / columnCount) + 0.5f);
    // Compute max page height.
    final int pageContentDesiredHeight = (int) ((pageContentDesiredWidth / pageAspectRatio) + 0.5f);
    // If the page does not fit entirely in a vertical direction,
    // we shirk it but not less than the minimal page width.
    final int pageContentMinHeight = (int) (mPreviewPageMinWidth / pageAspectRatio + 0.5f);
    final int pageContentMaxHeight = Math.max(pageContentMinHeight, availableHeight - 2 * (mPreviewListPadding + mPreviewPageMargin) - mFooterHeight);
    mPageContentHeight = Math.min(pageContentDesiredHeight, pageContentMaxHeight);
    mPageContentWidth = (int) ((mPageContentHeight * pageAspectRatio) + 0.5f);
    final int totalContentWidth = columnCount * mPageContentWidth + horizontalMargins;
    final int horizontalPadding = (availableWidth - totalContentWidth) / 2;
    final int rowCount = mSelectedPageCount / columnCount + ((mSelectedPageCount % columnCount) > 0 ? 1 : 0);
    final int totalContentHeight = rowCount * (mPageContentHeight + mFooterHeight + 2 * mPreviewPageMargin);
    final int verticalPadding;
    if (mPageContentHeight + mFooterHeight + mPreviewListPadding + 2 * mPreviewPageMargin > availableHeight) {
        verticalPadding = Math.max(0, (availableHeight - mPageContentHeight - mFooterHeight) / 2 - mPreviewPageMargin);
    } else {
        verticalPadding = Math.max(mPreviewListPadding, (availableHeight - totalContentHeight) / 2);
    }
    mPreviewArea.setPadding(horizontalPadding, verticalPadding, horizontalPadding, verticalPadding);
    // Now update the empty state drawable, as it depends on the page
    // size and is reused for all views for better performance.
    LayoutInflater inflater = LayoutInflater.from(mContext);
    View loadingContent = inflater.inflate(R.layout.preview_page_loading, null, false);
    loadingContent.measure(MeasureSpec.makeMeasureSpec(mPageContentWidth, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(mPageContentHeight, MeasureSpec.EXACTLY));
    loadingContent.layout(0, 0, loadingContent.getMeasuredWidth(), loadingContent.getMeasuredHeight());
    Bitmap loadingBitmap = Bitmap.createBitmap(mPageContentWidth, mPageContentHeight, Bitmap.Config.ARGB_8888);
    loadingContent.draw(new Canvas(loadingBitmap));
    // Do not recycle the old bitmap if such as it may be set as an empty
    // state to any of the page views. Just let the GC take care of it.
    mEmptyState = new BitmapDrawable(mContext.getResources(), loadingBitmap);
    // Now update the empty state drawable, as it depends on the page
    // size and is reused for all views for better performance.
    View errorContent = inflater.inflate(R.layout.preview_page_error, null, false);
    errorContent.measure(MeasureSpec.makeMeasureSpec(mPageContentWidth, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(mPageContentHeight, MeasureSpec.EXACTLY));
    errorContent.layout(0, 0, errorContent.getMeasuredWidth(), errorContent.getMeasuredHeight());
    Bitmap errorBitmap = Bitmap.createBitmap(mPageContentWidth, mPageContentHeight, Bitmap.Config.ARGB_8888);
    errorContent.draw(new Canvas(errorBitmap));
    // Do not recycle the old bitmap if such as it may be set as an error
    // state to any of the page views. Just let the GC take care of it.
    mErrorState = new BitmapDrawable(mContext.getResources(), errorBitmap);
}
Also used : Bitmap(android.graphics.Bitmap) LayoutInflater(android.view.LayoutInflater) Canvas(android.graphics.Canvas) BitmapDrawable(android.graphics.drawable.BitmapDrawable) View(android.view.View) PageContentView(com.android.printspooler.widget.PageContentView) TextView(android.widget.TextView)

Example 40 with LayoutInflater

use of android.view.LayoutInflater in project platform_frameworks_base by android.

the class TileAdapter method onCreateViewHolder.

@Override
public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
    final Context context = parent.getContext();
    LayoutInflater inflater = LayoutInflater.from(context);
    if (viewType == TYPE_DIVIDER) {
        return new Holder(inflater.inflate(R.layout.qs_customize_tile_divider, parent, false));
    }
    if (viewType == TYPE_EDIT) {
        return new Holder(inflater.inflate(R.layout.qs_customize_divider, parent, false));
    }
    FrameLayout frame = (FrameLayout) inflater.inflate(R.layout.qs_customize_tile_frame, parent, false);
    frame.addView(new CustomizeTileView(context, new QSIconView(context)));
    return new Holder(frame);
}
Also used : Context(android.content.Context) LayoutInflater(android.view.LayoutInflater) ViewHolder(android.support.v7.widget.RecyclerView.ViewHolder) Holder(com.android.systemui.qs.customize.TileAdapter.Holder) FrameLayout(android.widget.FrameLayout) QSIconView(com.android.systemui.qs.QSIconView)

Aggregations

LayoutInflater (android.view.LayoutInflater)1292 View (android.view.View)803 TextView (android.widget.TextView)615 ImageView (android.widget.ImageView)259 ViewGroup (android.view.ViewGroup)139 Context (android.content.Context)131 ListView (android.widget.ListView)123 LinearLayout (android.widget.LinearLayout)106 RecyclerView (android.support.v7.widget.RecyclerView)104 AdapterView (android.widget.AdapterView)100 Intent (android.content.Intent)92 AlertDialog (android.app.AlertDialog)88 DialogInterface (android.content.DialogInterface)81 Button (android.widget.Button)57 Bundle (android.os.Bundle)54 FrameLayout (android.widget.FrameLayout)49 TypedArray (android.content.res.TypedArray)43 Activity (android.app.Activity)41 AlertDialog (android.support.v7.app.AlertDialog)41 EditText (android.widget.EditText)41