Skip to content

Instantly share code, notes, and snippets.

View passiondroid's full-sized avatar
🏠
Working from home

Arif Khan passiondroid

🏠
Working from home
View GitHub Profile
@passiondroid
passiondroid / RuntimePermissionHelper.java
Last active February 26, 2021 05:51
Android Runtime Permission Helper class
import android.Manifest;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.util.Log;
@passiondroid
passiondroid / OpacityHex.markdown
Last active March 1, 2024 21:49
Opacity percentage in a Hex color code

Android uses hexadecimal ARGB values, which are formatted as #AARRGGBB. That first pair of letters, the AA, represent the alpha channel. You must convert your decimal opacity values to a hexadecimal value. Here are the steps:

Alpha Hex Value Process

  • Take your opacity as a decimal value and multiply it by 255. So, if you have a block that is 50% opaque the decimal value would be .5. For example: .5 x 255 = 127.5

  • The fraction won't convert to hexadecimal, so you must round your number up or down to the nearest whole number. For example: 127.5 rounds up to 128; 55.25 rounds down to 55.

  • Enter your decimal value in a decimal-to-hexadecimal converter, like http://www.binaryhexconverter.com/decimal-to-hex-converter, and convert your values.

mDividerItemDecoration = new DividerItemDecoration(recyclerView.getContext(),
mLayoutManager.getOrientation());
recyclerView.addItemDecoration(mDividerItemDecoration);
public boolean canReuseUpdatedViewHolder(@NonNull RecyclerView.ViewHolder viewHolder) {
return true;
}
public ItemHolderInfo recordPreLayoutInformation(@NonNull RecyclerView.State state, @NonNull RecyclerView.ViewHolder viewHolder, int changeFlags, @NonNull List<Object> payloads) {
if (changeFlags == FLAG_CHANGED) {
for (Object payload : payloads) {
if (payload instanceof String) {
return new CharacterItemHolderInfo((String) payload);
}
}
}
return super.recordPreLayoutInformation(state, viewHolder, changeFlags, payloads);
}
@Override
public boolean animateChange(@NonNull RecyclerView.ViewHolder oldHolder,
@NonNull RecyclerView.ViewHolder newHolder,
@NonNull ItemHolderInfo preInfo,
@NonNull ItemHolderInfo postInfo) {
if (preInfo instanceof CharacterItemHolderInfo) {
CharacterItemHolderInfo recipesItemHolderInfo = (CharacterItemHolderInfo) preInfo;
CharacterRVAdapter.CharacterViewHolder holder = (CharacterRVAdapter.CharacterViewHolder) newHolder;
if (CharacterRVAdapter.ACTION_LIKE_IMAGE_DOUBLE_CLICKED.equals(recipesItemHolderInfo.updateAction)) {
android {
 defaultConfig {
 }
 signingConfigs {
 release {
  storeFile file(“app.keystore”) // Your Keystore file path
  storePassword “password” // Your Keystore password
private void getMovies() {
MoviesService service = retrofit.create(MoviesService.class);
Call<List<Movie>> call = service.getMovies();
call.enqueue(new Callback<List<Movie>>() {
@Override
public void onResponse(Response<List<Movie>> response, Retrofit retrofit) {
saveMovies(response.body())
getMovieCasts(response.body())
}
compile 'io.reactivex.rxjava2:rxjava:2.0.1'
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
compile 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'
public interface MoviesService {
@GET("v2/movies/trending")
Observable<List<Movie>> getMovies();
@GET("v2/movies/{movieId}/casts")
Observable<List<Cast>> getCasts(@Path(movieId) String movieId);
}