Skip to content

Instantly share code, notes, and snippets.

View shikto1's full-sized avatar

Ahidul Islam shikto1

View GitHub Profile
public class SessionManager {
private SharedPreferences sharedPreferences;
private SharedPreferences.Editor editor;
private final String MY_PREF = "my_preferences";
public SessionManager(Context context) {
sharedPreferences = context.getSharedPreferences(MY_PREF, MODE_PRIVATE);
}
public class PermissionManager {
private Context context;
private SessionManager sessionManager;
public PermissionManager(Context context){
this.context = context;
sessionManager = new SessionManager(context);
}
configurations.all {
resolutionStrategy.eachDependency{
DependencyResolveDetails details ->
def requested=details.requested
if(requested.group=="com.android.support"){
if(!requested.name.startsWith("multidex")){
details.useVersion("26.0.1")
}
}
}
public String getInBangla(String string)
{
Character bangla_number[]={'১','২','৩','৪','৫','৬','৭','৮','৯','০'};
Character eng_number[]={'1','2','3','4','5','6','7','8','9','0'};
String values = "";
char[] character = string.toCharArray();
for (int i=0; i<character.length ; i++) {
Character c = ' ';
for (int j = 0; j < eng_number.length; j++) {
if(character[i]==eng_number[j])
public class ApiClient {
public static final String BASE_URL = "http://api.themoviedb.org/3/";
private static Retrofit retrofit = null;
public static Retrofit getClient() {
if (retrofit==null) {
retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) {
case REQUEST_CAMERA: {
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
//Permission was granted. Now you can call your method to open camera, fetch contact or whatever
openCamera();
} else {
public boolean hasPermission(String permission) {
return ContextCompat.checkSelfPermission(getApplicationContext(), permission) == PackageManager.PERMISSION_GRANTED;
}
public void askForMultiplePermissions(){
final int REQUEST_CODE = 13;
String cameraPermissin = Manifest.permission.CAMERA;
String readContactsPermission = Manifest.permission.READ_CONTACTS;
String readExternalStoragePermission = Manifest.permission.READ_EXTERNAL_STORAGE;
if (ContextCompat.checkSelfPermission(thisActivity,Manifest.permission.READ_CONTACTS)!= PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,
Manifest.permission.READ_CONTACTS)) {
// Show an expanation to the user
} else {
if(isFirstTimeAsking(thisActivity, Manifest.permission.READ_CONTACTS){
firstTimeAsking(thisActivity,Manifest.permission.READ_CONTACTS, false);
ActivityCompat.requestPermissions(thisActivity,new String[]{Manifest.permission.CAMERA}, REQUEST_CAMERA);
} else {
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private PermissionManager permissionManager;
private Button openCameraButton;
private ImageView imageView;
private final int REQUEST_CAMERA = 13;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
import io.fabric.sdk.android.Fabric;
import com.crashlytics.android.Crashlytics;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);