Java Code Examples for android.support.v4.content.ContextCompat

The following examples show how to use android.support.v4.content.ContextCompat. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * 显示邮箱验证验证
 *
 * @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();
}
 
Example 2
Source Project: android   Source File: MatchProgressActivity.java    License: Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 3
Source Project: TextThing   Source File: MainActivity.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
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);
    }
}
 
Example 4
Source Project: MOAAP   Source File: MainActivity.java    License: MIT License 6 votes vote down vote up
@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);

}
 
Example 5
Source Project: OpenWeatherPlus-Android   Source File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
@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();
    }
}
 
Example 6
Source Project: ImageLetterIcon   Source File: TintableImageView.java    License: Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example 7
Source Project: SoftwarePilot   Source File: MainActivity.java    License: MIT License 6 votes vote down vote up
/**
 * 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);
    }

}
 
Example 8
Source Project: renrenpay-android   Source File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 获取权限。。有些手机很坑,明明是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);
}
 
Example 9
Source Project: KUAS-AP-Material   Source File: LogoutActivity.java    License: MIT License 6 votes vote down vote up
@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();
	}
}
 
Example 10
Source Project: YImagePicker   Source File: PBaseLoaderFragment.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 加载媒体文件夹
 */
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);
            }
        });
    }
}
 
Example 11
Source Project: android-base-mvp   Source File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
@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())));
}
 
Example 12
Source Project: AndroidPdfViewerV1   Source File: PDFViewActivity.java    License: Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example 13
Source Project: Android-Example   Source File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
@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();
    }
}
 
Example 14
Source Project: Capstone-Project   Source File: AuthenticatorActivity.java    License: MIT License 6 votes vote down vote up
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;
    }
}
 
Example 15
Source Project: PainlessMusicPlayer   Source File: QueueActivity.java    License: Apache License 2.0 6 votes vote down vote up
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();
    }
}
 
Example 16
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();
}
 
Example 17
@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();
}
 
Example 18
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();
}
 
Example 19
Source Project: android-material-stepper   Source File: StepperLayout.java    License: Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 20
Source Project: C9MJ   Source File: ExploreFragment.java    License: Apache License 2.0 5 votes vote down vote up
@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));
    }
}
 
Example 21
Source Project: Expert-Android-Programming   Source File: FriendZomatoActivity.java    License: MIT License 5 votes vote down vote up
@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();
}
 
Example 22
Source Project: ucar-weex-core   Source File: AbsWeexActivity.java    License: Apache License 2.0 5 votes vote down vote up
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();
    }
  }
}
 
Example 23
Source Project: MangoBloggerAndroidApp   Source File: LikeButton.java    License: Mozilla Public License 2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example 24
/**
 * 获得运行时权限
 */
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();
    }
}
 
Example 25
Source Project: BrainPhaser   Source File: ChartSettings.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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));
}
 
Example 26
Source Project: VRPlayer   Source File: VRListActivity.java    License: Apache License 2.0 5 votes vote down vote up
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();
    }
}
 
Example 27
Source Project: FaceT   Source File: ProductDetailActivity.java    License: Mozilla Public License 2.0 5 votes vote down vote up
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);
}
 
Example 28
Source Project: RichEditor   Source File: RichEditorFunctionBar.java    License: MIT License 5 votes vote down vote up
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));
    }
}
 
Example 29
@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;
}
 
Example 30
Source Project: PhotoPicker   Source File: PermissionsUtils.java    License: Apache License 2.0 5 votes vote down vote up
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;
}