类android.support.v4.content.ContextCompat源码实例Demo

下面列出了怎么用android.support.v4.content.ContextCompat的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: tysq-android   文件: RegisterActivity.java
/**
 * 显示邮箱验证验证
 *
 * @param registerResp
 */
private void showEmailVerifyDialog(RegisterResp registerResp) {

    String content = String.format(getString(R.string.email_verify_tip_content), registerResp.getActivateEmailScore());

    new MaterialDialog.Builder(this)
            .title(getString(R.string.email_verify_tip_title))
            .content(content)
            .negativeColor(ContextCompat.getColor(this, R.color.et_tip_text_color))
            .negativeText(getString(R.string.email_verify_skip))
            .onNegative((dialog, which) -> {
                // 发送登录成功事件,会关闭 "登录"、"注册"、"忘记密码" 页
                EventBus.getDefault().post(new LoginSucEvent());
            })
            .positiveColor(ContextCompat.getColor(this, R.color.main_blue_color))
            .positiveText(getString(R.string.email_verify_verify))
            .onPositive((dialog, which) -> {

                EmailVerifyActivity
                        .startActivity(this, UserCache.getDefault().getEmail());

                // 发送登录成功事件,会关闭 "登录"、"注册"、"忘记密码" 页
                EventBus.getDefault().post(new LoginSucEvent());
            })
            .show();
}
 
源代码2 项目: android   文件: MatchProgressActivity.java
private void appendEvent(@DrawableRes int icon, String text, int gravity) {
  FrameLayout view = (FrameLayout) LayoutInflater.from(this)
      .inflate(R.layout.match_event, eventsLayout, false);
  TextView textView = view.findViewById(R.id.txt_match_events);
  textView.setText(text);
  Drawable drawable = ContextCompat.getDrawable(this, icon);
  drawable.setBounds(0, 0, iconSize, iconSize);
  textView.setCompoundDrawablePadding(iconPadding);
  if (gravity == GravityCompat.START) {
    textView.setCompoundDrawables(null, null, drawable, null);
  } else {
    textView.setCompoundDrawables(drawable, null, null, null);
  }
  LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) view.getLayoutParams();
  layoutParams.gravity = gravity;
  view.setLayoutParams(layoutParams);
  textView.setGravity(gravity);
  eventsLayout.addView(view, 0);
  eventsTimeline.setVisibility(View.VISIBLE);
  eventsScrollView.smoothScrollTo(0, 0);
}
 
源代码3 项目: TextThing   文件: MainActivity.java
void themeDay() {
    themeNr = 1;
    mainView.setBackgroundColor(
            ContextCompat.getColor(getApplicationContext(), R.color.MiddleDay)
    );
    btn.setTextColor(Color.WHITE);
    contentView.setBackgroundColor(
            ContextCompat.getColor(getApplicationContext(), R.color.DarkDay)
    );
    contentView.setTextColor(
            ContextCompat.getColor(getApplicationContext(), R.color.LightDay)
    );
    if (Build.VERSION.SDK_INT >= 21) {
        getWindow().setStatusBarColor(
                ContextCompat.getColor(getApplicationContext(), R.color.LightDay)
        );
    }
    if (isMono) {
        contentView.setTypeface(Typeface.MONOSPACE);
        btn.setTypeface(Typeface.MONOSPACE);
    } else {
        contentView.setTypeface(Typeface.SANS_SERIF);
        btn.setTypeface(Typeface.SANS_SERIF);
    }
}
 
源代码4 项目: MOAAP   文件: MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.i(TAG, "called onCreate");
    super.onCreate(savedInstanceState);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    setContentView(R.layout.activity_main);

    if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CAMERA)
            != PackageManager.PERMISSION_GRANTED) {
        Log.i("permission", "request READ_EXTERNAL_STORAGE");
        ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.CAMERA}, REQUEST_CAMERA);
    }else {
        Log.i("permission", "READ_EXTERNAL_STORAGE already granted");
        camera_granted = true;
    }

    mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.java_surface_view);
    mOpenCvCameraView.setCvCameraViewListener(this);

}
 
源代码5 项目: OpenWeatherPlus-Android   文件: MainActivity.java
@Override
public void onLocationChanged(AMapLocation aMapLocation) {
    if (aMapLocation.getErrorCode() == 0) {
        ContentUtil.NOW_LON = aMapLocation.getLongitude();
        ContentUtil.NOW_LAT = aMapLocation.getLatitude();
        getNowCity(true);
        mLocationClient.onDestroy();
    } else {
        if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_FINE_LOCATION)
                != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE)
                != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_PHONE_STATE)
                != PackageManager.PERMISSION_GRANTED) {
            // 没有权限
            View view = LayoutInflater.from(MainActivity.this).inflate(R.layout.pop_loc_list, null);
            LocListWindow locListWindow = new LocListWindow(view, MATCH_PARENT, MATCH_PARENT, MainActivity.this);
            locListWindow.show();
            locListWindow.showAtLocation(tvLocation, Gravity.CENTER, 0, 0);
            if (ContentUtil.FIRST_OPEN) {
                ContentUtil.FIRST_OPEN = false;
                SpUtils.putBoolean(MainActivity.this, "first_open", false);
            }
        }
        getNowCity(true);
        mLocationClient.onDestroy();
    }
}
 
源代码6 项目: ImageLetterIcon   文件: TintableImageView.java
@Override
protected void drawableStateChanged() {
    super.drawableStateChanged();
    if (mTint != null) {
        if (mTint.isStateful())
            setColorFilter(mTint.getColorForState(getDrawableState(), 0));
        else setColorFilter(mTint);
    }
    Drawable drawable = getBackground();
    if (mBackgroundTint != null && drawable != null) {
        Drawable wrap = DrawableCompat.wrap(drawable);
        wrap = wrap.mutate();

        if (mBackgroundTint.isStateful())
            DrawableCompat.setTint(wrap, ContextCompat.getColor(getContext(), mBackgroundTint.getColorForState(getDrawableState(), 0)));
        else DrawableCompat.setTintList(wrap, mBackgroundTint);

        DrawableCompat.setTintMode(wrap, PorterDuff.Mode.SRC_IN);
    }
}
 
源代码7 项目: SoftwarePilot   文件: MainActivity.java
/**
 * Checks if there is any missing permissions, and
 * requests runtime permission if needed.
 */
private void checkAndRequestPermissions() {
    // Check for permissions
    for (String eachPermission : REQUIRED_PERMISSION_LIST) {
        if (ContextCompat.checkSelfPermission(this, eachPermission) != PackageManager.PERMISSION_GRANTED) {
            missingPermission.add(eachPermission);
        }
    }
    // Request for missing permissions
    if (missingPermission.isEmpty()) {
        startSDKRegistration();
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        showToast("Need to grant the permissions!");
        ActivityCompat.requestPermissions(this,
                missingPermission.toArray(new String[missingPermission.size()]),
                REQUEST_PERMISSION_CODE);
    }

}
 
源代码8 项目: renrenpay-android   文件: MainActivity.java
/**
 * 获取权限。。有些手机很坑,明明是READ_PHONE_STATE权限,却问用户是否允许拨打电话,汗。
 */
private void getPermissions() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        return;
    }
    List<String> sa = new ArrayList<>();
    if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE)
            != PackageManager.PERMISSION_GRANTED) {
        //申请READ_PHONE_STATE权限。。。。
        sa.add(Manifest.permission.READ_PHONE_STATE);
    }
    if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE)
            != PackageManager.PERMISSION_GRANTED) {
        sa.add(Manifest.permission.READ_EXTERNAL_STORAGE);
    }
    if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
            != PackageManager.PERMISSION_GRANTED) {
        sa.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
    }
    if (sa.size() < 1) {
        return;
    }
    ActivityCompat.requestPermissions(this, sa.toArray(new String[]{}), 1);
}
 
源代码9 项目: KUAS-AP-Material   文件: LogoutActivity.java
@Override
public void onClick(View v) {
	if (v.getId() == R.id.button_openUrl) {
		mTracker.send(new HitBuilders.EventBuilder().setCategory("open url").setAction("click")
				.build());
		String shareData = mTitle + "\n" + mURL +
				"\n\n" + getString(R.string.send_from);
		CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
		Bitmap icon =
				BitmapFactory.decodeResource(getResources(), R.drawable.ic_share_white_24dp);
		builder.setActionButton(icon, getString(R.string.share),
				Utils.createSharePendingIntent(this, shareData));
		builder.setToolbarColor(ContextCompat.getColor(this, R.color.main_theme));
		CustomTabsIntent customTabsIntent = builder.build();
		customTabsIntent.launchUrl(this, Uri.parse(mURL));
	} else if (v.getId() == R.id.button_logout) {
		mTracker.send(new HitBuilders.EventBuilder().setCategory("logout").setAction("click")
				.build());
		clearUserData();
		startActivity(new Intent(this, LoginActivity.class));
		finish();
	}
}
 
源代码10 项目: YImagePicker   文件: PBaseLoaderFragment.java
/**
 * 加载媒体文件夹
 */
protected void loadMediaSets() {
    if (getActivity() == null) {
        return;
    }
    if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE)
            != PackageManager.PERMISSION_GRANTED) {
        requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQ_STORAGE);
    } else {
        //从媒体库拿到文件夹列表
        ImagePicker.provideMediaSets(getActivity(), getSelectConfig().getMimeTypes(), new MediaSetsDataSource.MediaSetProvider() {
            @Override
            public void providerMediaSets(ArrayList<ImageSet> imageSets) {
                loadMediaSetsComplete(imageSets);
            }
        });
    }
}
 
源代码11 项目: android-base-mvp   文件: MainActivity.java
@Override
public void showWeather(WeatherPojo weatherPojo) {

    Timber.d("show Weather %s", weatherPojo.toString());

    textview_main_city.setText(weatherPojo.getName());
    textView_main_current_temperature.setText(String.format("%.1f°", weatherPojo.getMain().getTemp()));
    textView_main_min_max.setText(String.format("%.1f°  %.1f°", weatherPojo.getMain().getTempMin(), weatherPojo.getMain().getTempMax()));
    textView_main_conditions.setText(weatherPojo.getWeather().get(0).getDescription());
    textView_main_humidity.setText(getString(R.string.humidity) + " " + weatherPojo.getMain().getHumidity() + "%");

    String wind_suffix = getResources().getString(R.string.wind_suffix_metric);
    if (UnitLocale.getDefault().equals(UnitLocale.Imperial))
        wind_suffix = getResources().getString(R.string.wind_suffix_imperial);
    textView_main_wind.setText(getString(R.string.wind) + " " + String.valueOf(weatherPojo.getWind().getSpeed()) + wind_suffix);

    textView_main_pressure.setText(getString(R.string.pressure) + " " + weatherPojo.getMain().getPressure() + "hPa");
    imageView_main_icon.setImageDrawable(ContextCompat.getDrawable(getContext(), getIcon(weatherPojo.getWeather().get(0).getId())));
}
 
源代码12 项目: AndroidPdfViewerV1   文件: PDFViewActivity.java
@OptionsItem(R.id.pickFile)
void pickFile() {
    int permissionCheck = ContextCompat.checkSelfPermission(this,
            READ_EXTERNAL_STORAGE);

    if (permissionCheck != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(
                this,
                new String[]{READ_EXTERNAL_STORAGE},
                PERMISSION_CODE
        );

        return;
    }

    launchPicker();
}
 
源代码13 项目: Android-Example   文件: MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    tvLatitude = (TextView)findViewById(R.id.latitude);
    tvLongitude = (TextView)findViewById(R.id.longitude);

    try {
        if (ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED ) {
            ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION}, 101);
        }
    } catch (Exception e){
        e.printStackTrace();
    }
}
 
源代码14 项目: Capstone-Project   文件: AuthenticatorActivity.java
private void manageBackgroundColor() {
    switch (PredatorSharedPreferences.getCurrentTheme(getApplicationContext())) {
        case LIGHT:
            relativeLayoutAuthenticator.setBackgroundColor(ContextCompat.getColor(getApplicationContext(),
                    R.color.background_color));
            break;
        case DARK:
            relativeLayoutAuthenticator.setBackgroundColor(ContextCompat.getColor(getApplicationContext(),
                    R.color.background_color_inverse));
            break;
        case AMOLED:
            relativeLayoutAuthenticator.setBackgroundColor(ContextCompat.getColor(getApplicationContext(),
                    R.color.background_color_amoled));
            break;
    }
}
 
源代码15 项目: PainlessMusicPlayer   文件: QueueActivity.java
private void prepareViewsAndExit(@NonNull final Runnable exitAction) {
    if (!TransitionUtils.supportsActivityTransitions() ||
            (fab.getScaleX() == 0f && albumArtDim.getAlpha() == 0f)) {
        exitAction.run();
    } else {
        final boolean isLandscape = getResources().getConfiguration().orientation
                == Configuration.ORIENTATION_LANDSCAPE;
        // Landscape Now Playing has a dim, so dim the ImageView and send it
        if (isLandscape) {
            albumArtDim.setAlpha(0f);
            albumArt.setColorFilter(
                    ContextCompat.getColor(this, R.color.translucentBackground),
                    PorterDuff.Mode.SRC_ATOP);
        } else {
            // Portrait NowPlaying does not have a dim. Fade out the dim before animating.
            albumArtDim.animate().alpha(0f).setDuration(mShortAnimTime).start();
        }
        fab.animate().scaleX(0f).scaleY(0f).setDuration(mShortAnimTime)
                .setListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(final Animator animation) {
                        exitAction.run();
                    }
                }).start();
    }
}
 
源代码16 项目: FaceSlim   文件: DownloadManagerResolver.java
private static AlertDialog createDialog(final Context context) {
    AppCompatTextView messageTextView = new AppCompatTextView(context);
    messageTextView.setTextSize(16f);
    messageTextView.setText(context.getString(R.string.download_manager_disabled));
    messageTextView.setPadding(50, 50, 50, 0);
    messageTextView.setTextColor(ContextCompat.getColor(context, R.color.black));
    return new AlertDialog.Builder(context)
            .setView(messageTextView)
            .setPositiveButton("ok", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    enableDownloadManager(context);
                }
            })
            .setCancelable(false)
            .create();
}
 
源代码17 项目: pocketsphinx-android-demo   文件: WearActivity.java
@Override
public void onCreate(Bundle state) {
    super.onCreate(state);

    // Prepare the data for UI
    captions = new HashMap<String, Integer>();
    captions.put(KWS_SEARCH, R.string.kws_caption);
    captions.put(MENU_SEARCH, R.string.menu_caption);
    captions.put(DIGITS_SEARCH, R.string.digits_caption);
    captions.put(PHONE_SEARCH, R.string.phone_caption);
    captions.put(FORECAST_SEARCH, R.string.forecast_caption);
    setContentView(R.layout.activity_main);
    ((TextView) findViewById(edu.cmu.pocketsphinx.demo.wear.R.id.caption_text))
            .setText("Preparing the recognizer");

    // Check if user has given permission to record audio
    int permissionCheck = ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.RECORD_AUDIO);
    if (permissionCheck != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.RECORD_AUDIO}, PERMISSIONS_REQUEST_RECORD_AUDIO);
        return;
    }
    runRecognizerSetup();
}
 
public void changeBackgroundColor(final View view, int from, int to) {
    int colorFrom = ContextCompat.getColor(this, from);
    int colorTo = ContextCompat.getColor(this, to);
    ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
    colorAnimation.setDuration(250); // milliseconds
    colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animator) {
            view.setBackgroundColor((int) animator.getAnimatedValue());
        }

    });
    colorAnimation.start();
}
 
源代码19 项目: android-material-stepper   文件: StepperLayout.java
private void initDefaultValues() {
    mBackButtonColor = mNextButtonColor = mCompleteButtonColor =
            ContextCompat.getColorStateList(getContext(), R.color.ms_bottomNavigationButtonTextColor);
    mSelectedColor = ContextCompat.getColor(getContext(), R.color.ms_selectedColor);
    mUnselectedColor = ContextCompat.getColor(getContext(), R.color.ms_unselectedColor);
    mErrorColor = ContextCompat.getColor(getContext(), R.color.ms_errorColor);
    mBackButtonText = getContext().getString(R.string.ms_back);
    mNextButtonText = getContext().getString(R.string.ms_next);
    mCompleteButtonText = getContext().getString(R.string.ms_complete);
}
 
源代码20 项目: C9MJ   文件: ExploreFragment.java
@Override
public void onItemSwipeMoving(Canvas canvas, RecyclerView.ViewHolder viewHolder, float dX, float dY, boolean isCurrentlyActive) {
    if (!isCurrentlyActive) {
        BaseViewHolder holder = (BaseViewHolder) viewHolder;
        CardView cardView = holder.getView(R.id.cardview);
        cardView.setCardBackgroundColor(ContextCompat.getColor(context, R.color.color_primary));
    }
}
 
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_friends_search);

    toolbar = (Toolbar) findViewById(R.id.toolbar1);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setTitle("Find friends on Zomato");
    toolbar.setTitleTextColor(ContextCompat.getColor(context, R.color.white));

    recyclerView = (RecyclerView) findViewById(R.id.recyclerView);


    allList = new ArrayList<>();
    allAdapter = new FriendAdapter(context, allList);
    /*allAdapter.setClickListener(new FriendAdapter.ClickListener() {
        @Override
        public void onItemClickListener(View v, int pos) {

        }

        @Override
        public void onFriendListener(int pos, boolean isFollowing) {

        }
    });*/

    recyclerView.setLayoutManager(new LinearLayoutManager(context));
    recyclerView.setNestedScrollingEnabled(false);
    recyclerView.setAdapter(allAdapter);

    setList();
}
 
源代码22 项目: ucar-weex-core   文件: AbsWeexActivity.java
public void runWithPermissionsCheck(int requestCode, String permission, Runnable runnable) {
  if (ContextCompat.checkSelfPermission(this, permission) != PackageManager.PERMISSION_GRANTED) {
    if (ActivityCompat.shouldShowRequestPermissionRationale(this, permission)) {
      Toast.makeText(this, "please give me the permission", Toast.LENGTH_SHORT).show();
    } else {
      ActivityCompat.requestPermissions(this, new String[]{permission}, requestCode);
    }
  } else {
    if (runnable != null) {
      runnable.run();
    }
  }
}
 
源代码23 项目: MangoBloggerAndroidApp   文件: LikeButton.java
/**
 * This drawable is shown when the button is a liked state.
 *
 * @param resId
 */
public void setLikeDrawableRes(@DrawableRes int resId) {
    likeDrawable = ContextCompat.getDrawable(getContext(), resId);

    if (iconSize != 0) {
        likeDrawable = Utils.resizeDrawable(getContext(), likeDrawable, iconSize, iconSize);
    }

    if (isChecked) {
        icon.setImageDrawable(likeDrawable);
    }
}
 
源代码24 项目: AndroidWallet   文件: CaptureActivity.java
/**
 * 获得运行时权限
 */
private void getRuntimeRight() {
    if (ContextCompat.checkSelfPermission(context, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 1);
    } else {
        openAlbum();
    }
}
 
源代码25 项目: BrainPhaser   文件: ChartSettings.java
/**
 * Formats the text which will be shown when no challenges exist
 *
 * @param chart the chart whose no data text will be formatted
 */
public void applyNoDataSettings(Chart chart) {
    chart.setNoDataText(mApplication.getString(R.string.chart_no_data_text));
    Paint p = chart.getPaint(Chart.PAINT_INFO);
    p.setTextSize(NO_DATA_TEXT_SIZE);

    Context appContext = mApplication.getApplicationContext();

    p.setColor(ContextCompat.getColor(appContext, android.R.color.tertiary_text_light));
}
 
源代码26 项目: VRPlayer   文件: VRListActivity.java
private void checkPermission() {
    if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED
            || ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(this,
                permissions,
                REQUEST_PERMISSIONS);
    }else {
        scanVideo();
    }
}
 
源代码27 项目: FaceT   文件: ProductDetailActivity.java
private void setUpEmojiPopup() {
    emojiPopup = EmojiPopup.Builder.fromRootView(activity_product_detail_layout)
            .setOnEmojiBackspaceClickListener(new OnEmojiBackspaceClickListener() {
                @Override public void onEmojiBackspaceClick(final View v) {
                    Log.d(TAG, "Clicked on Backspace");
                }
            })
            .setOnEmojiClickListener(new OnEmojiClickListener() {
                @Override public void onEmojiClick(@NonNull final EmojiImageView imageView, @NonNull final Emoji emoji) {
                    Log.d(TAG, "Clicked on emoji");
                }
            })
            .setOnEmojiPopupShownListener(new OnEmojiPopupShownListener() {
                @Override
                public void onEmojiPopupShown() {
                    emojiButton.setBackground(ContextCompat.getDrawable(ProductDetailActivity.this, R.drawable.ic_keyboard));
                }
            })
            .setOnSoftKeyboardOpenListener(new OnSoftKeyboardOpenListener() {
                @Override
                public void onKeyboardOpen(final int keyBoardHeight) {
                    Log.d(TAG, "Opened soft keyboard");
                }
            })
            .setOnEmojiPopupDismissListener(new OnEmojiPopupDismissListener() {
                @Override
                public void onEmojiPopupDismiss() {
                    emojiButton.setBackground(ContextCompat.getDrawable(ProductDetailActivity.this, R.drawable.emoji_one_category_people));
                }
            })
            .setOnSoftKeyboardCloseListener(new OnSoftKeyboardCloseListener() {
                @Override
                public void onKeyboardClose() {
                    emojiPopup.dismiss();
                    Log.d(TAG, "Closed soft keyboard");
                }
            })
            .build(commentEmojiconEditText);
}
 
源代码28 项目: RichEditor   文件: RichEditorFunctionBar.java
private void initButton(Context context) {
    Drawable normal = ContextCompat.getDrawable(context, R.drawable.bg_normal_shape);
    Drawable select = ContextCompat.getDrawable(context, R.drawable.bg_select_shape);
    Drawable highlight = ContextCompat.getDrawable(context, R.drawable.bg_highlight_shap);

    for (int type : typeSet) {
        final StateListImageButton stateListImageButton = stateListImageButtonSparseArray.get(type);
        stateListImageButton.addState(StyleTypeStateSpec.StyleTypeState.STATE_NONE, normal);
        stateListImageButton.addState(StyleTypeStateSpec.StyleTypeState.STATE_EXIST, select);
        stateListImageButton.addState(StyleTypeStateSpec.StyleTypeState.STATE_ACTIVE, highlight);
        stateListImageButton.setOnClickListener(new StateListImageButtonOnClickListener(type));
    }
}
 
@Override
public View provideHandleView(ViewGroup container) {
    handle = new View(getContext());
    int dimen = getContext().getResources().getDimensionPixelSize(R.dimen.custom_handle_size);
    handle.setLayoutParams(new ViewGroup.LayoutParams(dimen, dimen));
    Utils.setBackground(handle, drawCircle(dimen, dimen, ContextCompat.getColor(getContext(), R.color.custom_handle_color)));
    handle.setVisibility(View.INVISIBLE);
    return handle;
}
 
源代码30 项目: PhotoPicker   文件: PermissionsUtils.java
public static boolean checkCameraPermission(Fragment fragment) {
    int cameraPermissionState = ContextCompat.checkSelfPermission(fragment.getContext(), CAMERA);

    boolean cameraPermissionGranted = cameraPermissionState == PackageManager.PERMISSION_GRANTED;

    if (!cameraPermissionGranted) {
        fragment.requestPermissions(PermissionsConstant.PERMISSIONS_CAMERA,
                PermissionsConstant.REQUEST_CAMERA);
    }
    return cameraPermissionGranted;
}