Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@talhahasanzia
talhahasanzia / OrderedBroadcast.kt
Created March 22, 2024 10:31
Ordered Broadcast in Android
// Send ordered broadcast
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// Create the intent for the ordered broadcast
val orderedBroadcastIntent = Intent("com.example.ORDERED_BROADCAST")
orderedBroadcastIntent.putExtra("message", "Hello from MainActivity!")
@talhahasanzia
talhahasanzia / script.sql
Created March 24, 2020 10:50
Sql procedures and functions
// -----------------------------------------------------//
// CREATION OF SCHEMA
// -----------------------------------------------------//
CREATE TABLE IF NOT EXISTS user_permissions (
id int NOT NULL,
permission_name varchar(50) NOT NULL,
PRIMARY KEY (id)
);
@talhahasanzia
talhahasanzia / KeystoreHelperFix.java
Last active February 19, 2020 06:53
Fix for EncryptionHelperLibrary for API 28 (Pie)
private PrivateKey getPrivateKey(String alias) throws UnrecoverableEntryException, NoSuchAlgorithmException, KeyStoreException {
//private key
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
return (PrivateKey) keyStore.getKey(alias, null);
} else {
/**
* This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
private File getCompressedFile(String filePath, Context context) {
int compressionRatio = 50;
float scaleDownFactor = 0.5f;
File inputFile = new File(filePath);
// by default it has same file reference as original one
// if create temp file fails it will have some file
File outputFile=new File(filePath);
try {
@talhahasanzia
talhahasanzia / LRUCalculator.java
Created May 21, 2018 06:26
Calculating LRU limit for different devices (as suggested by guide)
public LRUCalculator{
public static int getMemorySize(Context context){
int memClass = ( ( ActivityManager )context.getSystemService( Context.ACTIVITY_SERVICE ) ).getMemoryClass();
int cacheSize = 1024 * 1024 * memClass / 8;
return cacheSize;
}
/*
* Copyright (C) 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@talhahasanzia
talhahasanzia / Enums.java
Last active April 27, 2018 06:55
Enums usage. From Java 7, Strings are also supported.
// declaration
public enum Season {
SPRING("Spring"), SUMMER("Summer"), FALL("Fall"), WINTER("Winter");
private String name;
Season(String name) {
this.name = name;
}
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:fillViewport="true"
android:nestedScrollingEnabled="true">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
@talhahasanzia
talhahasanzia / Play_Expansion_Files_Guide.txt
Last active October 6, 2017 08:07
APK Expansion File Handling Procedure.
-- https://stuff.mit.edu/afs/sipb/project/android/docs/google/play/expansion-files.html
-- http://sapandiwakar.in/how-to-set-up-android-app-to-support-expansion-files/
-- https://stackoverflow.com/questions/18449680/setting-up-the-licensing-verification-library-on-android-studio
-- https://stackoverflow.com/questions/22368251/how-to-make-android-expansion-file-using-android-studio
-- https://stackoverflow.com/questions/18196067/the-import-com-google-android-vending-cannot-be-resolved-in-an-imported-android
-- https://github.com/bolein/better-apk-expansion