当前位置: 首页>>代码示例>>Java>>正文


Java ContextCompat类代码示例

本文整理汇总了Java中android.support.v4.content.ContextCompat的典型用法代码示例。如果您正苦于以下问题:Java ContextCompat类的具体用法?Java ContextCompat怎么用?Java ContextCompat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ContextCompat类属于android.support.v4.content包,在下文中一共展示了ContextCompat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initExpandIcon

import android.support.v4.content.ContextCompat; //导入依赖的package包/类
private void initExpandIcon(RelativeLayout headerLayout) {
    expandIcon = new ImageView(getContext());

    int margin = (int) getContext().getResources().getDimension(R.dimen.icon_margin);

    RelativeLayout.LayoutParams expandIconParams = new RelativeLayout.LayoutParams((int) getResources().getDimension(R.dimen.expand_drawable_size), (int) getResources().getDimension(R.dimen.expand_drawable_size));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        expandIconParams.addRule(RelativeLayout.ALIGN_PARENT_END);
    } else {
        expandIconParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    }
    expandIconParams.addRule(RelativeLayout.CENTER_VERTICAL);
    expandIconParams.setMargins(margin, margin, margin, margin);

    expandIcon.setId(ExpandableUtils.ID_EXPAND_ICON);
    expandIcon.setLayoutParams(expandIconParams);
    expandIcon.setImageDrawable(expandIndicator == null ? ContextCompat.getDrawable(getContext(), R.drawable.ic_down) : expandIndicator);

    headerLayout.addView(expandIcon);
}
 
开发者ID:robertlevonyan,项目名称:materialExpansionPanel,代码行数:22,代码来源:Expandable.java

示例2: activateMainIcons

import android.support.v4.content.ContextCompat; //导入依赖的package包/类
private void activateMainIcons(boolean enabled) {
    
    Integer color = R.color.colorPrimary;
    if (!enabled) {
        color = R.color.colorSilver;
    }
    
    ImageView imageViewShowList = (ImageView) findViewById(R.id.imageViewShowList);
    ImageView imageViewShowMap = (ImageView) findViewById(R.id.imageViewShowMap);
    ImageView imageViewCategory = (ImageView) findViewById(R.id.imageViewShowCategories);
    ImageView imageViewAchievements = (ImageView) findViewById(R.id.imageViewAchievements);
    TextView textViewShowList = (TextView) findViewById(R.id.textViewShowList);
    TextView textViewShowMap = (TextView) findViewById(R.id.textViewShowMap);
    TextView textViewCategory = (TextView) findViewById(R.id.textViewShowCategories);
    TextView textViewShowAchievements = (TextView) findViewById(R.id.textViewShowAchievements);
    DrawableCompat.setTint(imageViewShowList.getDrawable(), ContextCompat.getColor(this, color));
    DrawableCompat.setTint(imageViewShowMap.getDrawable(), ContextCompat.getColor(this, color));
    DrawableCompat.setTint(imageViewCategory.getDrawable(), ContextCompat.getColor(this, color));
    DrawableCompat.setTint(imageViewAchievements.getDrawable(), ContextCompat.getColor(this, color));
    textViewShowList.setTextColor(ContextCompat.getColor(this, color));
    textViewShowMap.setTextColor(ContextCompat.getColor(this, color));
    textViewCategory.setTextColor(ContextCompat.getColor(this, color));
    textViewShowAchievements.setTextColor(ContextCompat.getColor(this, color));
}
 
开发者ID:stefanonicolai,项目名称:AstronomyTourPadova,代码行数:25,代码来源:MainActivity.java

示例3: onPostExecute

import android.support.v4.content.ContextCompat; //导入依赖的package包/类
@Override
protected void onPostExecute(Boolean b) {
    if (b) {
        dismiss();
        Toast.makeText(Utils.getContext(), "Umfrage erfolgreich erstellt", Toast.LENGTH_LONG).show();
    } else {
        final Snackbar snackbar = Snackbar.make(findViewById(R.id.wrapper), "Es ist etwas schiefgelaufen, versuche es später erneut", Snackbar.LENGTH_SHORT);
        snackbar.setActionTextColor(ContextCompat.getColor(getContext(), R.color.colorPrimary));
        snackbar.setAction(getContext().getString(R.string.dismiss), new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                snackbar.dismiss();
            }
        });
        snackbar.show();
    }
}
 
开发者ID:LCA311,项目名称:leoapp-sources,代码行数:18,代码来源:NewSurveyDialog.java

示例4: showProgressDialog

import android.support.v4.content.ContextCompat; //导入依赖的package包/类
public TextView showProgressDialog() {

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setCancelable(false);
        View view = View.inflate(this, R.layout.dialog_loading, null);
        builder.setView(view);
        ProgressBar pb_loading = (ProgressBar) view.findViewById(R.id.pb_loading);
        TextView tv_hint = (TextView) view.findViewById(R.id.tv_hint);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            pb_loading.setIndeterminateTintList(ContextCompat.getColorStateList(this, R.color.dialog_pro_color));
        }
        tv_hint.setText("视频编译中");
        progressDialog = builder.create();
        progressDialog.show();

        return tv_hint;
    }
 
开发者ID:Zhaoss,项目名称:WeiXinRecordedDemo,代码行数:18,代码来源:BaseActivity.java

示例5: takePhoto

import android.support.v4.content.ContextCompat; //导入依赖的package包/类
/**
 * 拍照
 */
private void takePhoto() {
    //在每次拍照做权限的判断,防止出现权限不全而获取不到图像
    if (ContextCompat.checkSelfPermission(mActivity,
            Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED
            || ContextCompat.checkSelfPermission(mActivity,
            Manifest.permission.CAMERA)
            != PackageManager.PERMISSION_GRANTED) {
        return;
    }
    Intent takeIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.N){
        mPhotoUri = get24MediaFileUri(TYPE_TAKE_PHOTO);
        takeIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    }else {
        mPhotoUri = getMediaFileUri(TYPE_TAKE_PHOTO);
    }
    takeIntent.putExtra(MediaStore.EXTRA_OUTPUT, mPhotoUri);
    mActivity.startActivityForResult(takeIntent, COOD_TAKE_PHOTO);
}
 
开发者ID:funnyzhaov,项目名称:Tribe,代码行数:23,代码来源:PhotoRequest.java

示例6: BubblePageIndicator

import android.support.v4.content.ContextCompat; //导入依赖的package包/类
public BubblePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode()) return;

    //Load defaults from resources
    final Resources res = getResources();
    final int defaultPageColor = ContextCompat.getColor(context, R.color.default_bubble_indicator_page_color);
    final int defaultFillColor = ContextCompat.getColor(context, R.color.default_bubble_indicator_fill_color);
    final float defaultRadius = res.getDimension(R.dimen.default_bubble_indicator_radius);

    //Retrieve styles attributes
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BubblePageIndicator, defStyle, 0);

    paintPageFill.setStyle(Style.FILL);
    paintPageFill.setColor(a.getColor(R.styleable.BubblePageIndicator_pageColor, defaultPageColor));
    paintFill.setStyle(Style.FILL);
    paintFill.setColor(a.getColor(R.styleable.BubblePageIndicator_fillColor, defaultFillColor));
    radius = a.getDimension(R.styleable.BubblePageIndicator_radius, defaultRadius);
    marginBetweenCircles = a.getDimension(R.styleable.BubblePageIndicator_marginBetweenCircles, radius);

    a.recycle();
}
 
开发者ID:shuhart,项目名称:BubblePagerIndicator,代码行数:23,代码来源:BubblePageIndicator.java

示例7: onBindViewHolder

import android.support.v4.content.ContextCompat; //导入依赖的package包/类
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
    try {
        Pessoa.Contato contato = contatoList.get(position);
        switch (contato.getTipo().toLowerCase()) {
            case "facebook":
                holder.tipo_contato_image.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_facebook));
                break;
            case "twitter":
                holder.tipo_contato_image.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_twitter));
                break;
            case "linkedin":
                holder.tipo_contato_image.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_linkedin));
                break;
            case "github":
                holder.tipo_contato_image.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_github));
                break;
            default:
                holder.tipo_contato_image.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_outro));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:secompufscar,项目名称:app_secompufscar,代码行数:25,代码来源:ContatoAdapter.java

示例8: getView

import android.support.v4.content.ContextCompat; //导入依赖的package包/类
public View getView(final int position, View convertView, ViewGroup parent) {
    ViewHolder viewHolder;
    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.media_item, parent, false);
        viewHolder = new ViewHolder(convertView);
        convertView.setTag(viewHolder);
    } else {
        viewHolder = (ViewHolder) convertView.getTag();
    }
    viewHolder.tvText.setCompoundDrawablesWithIntrinsicBounds(null, ContextCompat.getDrawable(mContext, getItem(position).getDrawableId()), null, null);
    viewHolder.tvText.setText(getItem(position).getText());

    convertView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            getItem(position).getMediaListener().onMediaClick(getItem(position).getId());
        }
    });

    return convertView;
}
 
开发者ID:yangchaojiang,项目名称:ChatKeyboard-master,代码行数:23,代码来源:MediaGridAdapter.java

示例9: initTabs

import android.support.v4.content.ContextCompat; //导入依赖的package包/类
private void initTabs() {
    int normalColor = QMUIResHelper.getAttrColor(getActivity(), R.attr.qmui_config_color_gray_6);
    int selectColor = QMUIResHelper.getAttrColor(getActivity(), R.attr.qmui_config_color_blue);
    mTabSegment.setDefaultNormalColor(normalColor);
    mTabSegment.setDefaultSelectedColor(selectColor);
    QMUITabSegment.Tab component = new QMUITabSegment.Tab(
            ContextCompat.getDrawable(getContext(), R.mipmap.icon_tabbar_component),
            ContextCompat.getDrawable(getContext(), R.mipmap.icon_tabbar_component_selected),
            "Components", false
    );
    QMUITabSegment.Tab util = new QMUITabSegment.Tab(
            ContextCompat.getDrawable(getContext(), R.mipmap.icon_tabbar_util),
            ContextCompat.getDrawable(getContext(), R.mipmap.icon_tabbar_util_selected),
            "Helper", false
    );
    QMUITabSegment.Tab lab = new QMUITabSegment.Tab(
            ContextCompat.getDrawable(getContext(), R.mipmap.icon_tabbar_lab),
            ContextCompat.getDrawable(getContext(), R.mipmap.icon_tabbar_lab_selected),
            "Lab", false
    );
    mTabSegment.addTab(component)
            .addTab(util)
            .addTab(lab);
}
 
开发者ID:coopese,项目名称:qmui,代码行数:25,代码来源:HomeFragment.java

示例10: initToolbar

import android.support.v4.content.ContextCompat; //导入依赖的package包/类
private void initToolbar() {
    Toolbar toolbar = findViewById(R.id.actionBarChat);
    toolbar.setTitleTextColor(ContextCompat.getColor(getApplicationContext(), android.R.color.white));
    toolbar.setTitle(cname);
    setSupportActionBar(toolbar);
    getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_arrow_left);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);
    if (ctype != Chat.ChatType.PRIVATE && Utils.getController().getMessengerDatabase().userInChat(Utils.getUserID(), cid)) {
        toolbar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivityForResult(new Intent(getApplicationContext(), ChatEditActivity.class)
                        .putExtra("cid", cid)
                        .putExtra("cname", cname), 1);
            }
        });
    }
}
 
开发者ID:LCA311,项目名称:leoapp-sources,代码行数:20,代码来源:ChatActivity.java

示例11: shiftSharedElements

import android.support.v4.content.ContextCompat; //导入依赖的package包/类
private void shiftSharedElements(float pageOffsetX, boolean forward){
    final Context context=pager.getContext();
    //since we're clipping the page, we have to adjust the shared elements
    AnimatorSet shiftAnimator=new AnimatorSet();
    for(View view:sharedElements){
        float translationX=forward?pageOffsetX:-pageOffsetX;
        float temp=view.getWidth()/3f;
        translationX-=forward?temp:-temp;
        ObjectAnimator shift=ObjectAnimator.ofFloat(view,View.TRANSLATION_X,0,translationX);
        shiftAnimator.playTogether(shift);
    }

    int color=ContextCompat.getColor(context,forward?R.color.color_logo_sign_up:R.color.color_logo_log_in);
    DrawableCompat.setTint(sharedElements.get(0).getDrawable(),color);
    //scroll the background by x
    int offset=authBackground.getWidth()/2;
    ObjectAnimator scrollAnimator=ObjectAnimator.ofInt(authBackground,"scrollX",forward?offset:-offset);
    shiftAnimator.playTogether(scrollAnimator);
    shiftAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
    shiftAnimator.setDuration(pager.getResources().getInteger(R.integer.duration)/2);
    shiftAnimator.start();
}
 
开发者ID:vpaliyX,项目名称:LoginConcept,代码行数:23,代码来源:AuthAdapter.java

示例12: requestAppPermissions

import android.support.v4.content.ContextCompat; //导入依赖的package包/类
public void requestAppPermissions(final String[]requestedPermissions, final int stringId, final int requestCode) {
    mErrorString.put(requestCode, stringId);

    int permissionCheck = PackageManager.PERMISSION_GRANTED;
    boolean showRequestPermissions = false;
    for(String permission: requestedPermissions) {
        permissionCheck = permissionCheck + ContextCompat.checkSelfPermission(this, permission);
        showRequestPermissions = showRequestPermissions || ActivityCompat.shouldShowRequestPermissionRationale(this, permission);
    }

    if (permissionCheck!=PackageManager.PERMISSION_GRANTED) {
        if(showRequestPermissions) {
            Snackbar.make(findViewById(android.R.id.content), stringId, Snackbar.LENGTH_INDEFINITE).setAction("GRANT", new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    ActivityCompat.requestPermissions(AbsRuntimePermission.this, requestedPermissions, requestCode);
                }
            }).show();
        } else {
            ActivityCompat.requestPermissions(this, requestedPermissions, requestCode);
        }
    } else {
        onPermissionsGranted(requestCode);
    }
}
 
开发者ID:Turing-Circle,项目名称:SmartHealthCare_AmbulanceApp,代码行数:26,代码来源:AbsRuntimePermission.java

示例13: fillViews

import android.support.v4.content.ContextCompat; //导入依赖的package包/类
private void fillViews(Optional<Concert> optional) {
    if (!optional.isPresent()) {
        return;
    }

    Concert concert = optional.getValue();
    String artistName = concert.getArtist().getName();

    collapsingToolbar.setTitle(artistName);
    collapsingToolbar.setExpandedTitleColor(
            ContextCompat.getColor(this, android.R.color.transparent));
    artistTextView.setText(artistName);

    String placeText = String.format("%s, %s",
            concert.getLocation().getName(), concert.getPlace());
    placeTextView.setText(placeText);

    dateTextView.setText(makeDateString(concert));

    imageLoader.loadConcertBackdrop(this, concert, backdropImageView);
}
 
开发者ID:andreybgm,项目名称:gigreminder,代码行数:22,代码来源:ConcertDetailsActivity.java

示例14: hasPermissions

import android.support.v4.content.ContextCompat; //导入依赖的package包/类
/**
 * Check if the calling context has a set of permissions.
 *
 * @param context
 *         the calling context.
 * @param perms
 *         one ore more permissions, such as {@code android.Manifest.permission.CAMERA}.
 * @return true if all permissions are already granted, false if at least one permission is not yet granted.
 */
public static boolean hasPermissions(@NonNull Context context, @NonNull String... perms) {
    // Always return true for SDK < M, let the system deal with the permissions
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        Log.w(TAG, "hasPermissions: API version < M, returning true by default");
        return true;
    }

    for (String perm : perms) {
        boolean hasPerm = (ContextCompat.checkSelfPermission(context, perm) ==
                PackageManager.PERMISSION_GRANTED);
        if (!hasPerm) {
            return false;
        }
    }

    return true;
}
 
开发者ID:42Chapters,项目名称:AdaptationX-android,代码行数:27,代码来源:EasyPermissions.java

示例15: onAttachClick

import android.support.v4.content.ContextCompat; //导入依赖的package包/类
public void onAttachClick() {
    final int permissionStatus = ContextCompat.checkSelfPermission(
            getContext(),
            Manifest.permission.READ_EXTERNAL_STORAGE
    );

    if (permissionStatus != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(
                getActivity(),
                new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
                REQUEST_ATTACH_PERMISSION
        );

        return;
    }

    final Intent attach = new Intent(Intent.ACTION_GET_CONTENT)
            .addCategory(Intent.CATEGORY_OPENABLE)
            .setType("*/*");

    startActivityForResult(attach, REQUEST_ATTACH_FILE);
}
 
开发者ID:PacktPublishing,项目名称:Hands-On-Android-UI-Development,代码行数:23,代码来源:AttachmentPagerFragment.java


注:本文中的android.support.v4.content.ContextCompat类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。