Skip to content

Instantly share code, notes, and snippets.

View Mariuxtheone's full-sized avatar

Mario Viviani Mariuxtheone

View GitHub Profile
@Mariuxtheone
Mariuxtheone / getColorFilterFromColor.java
Last active August 29, 2015 14:11
Android - Custom ColorFilter to apply new solid color to a Drawable.
ColorFilter getColorFilterFromColor(int color){
//Extract the RGB components from color
int red = Color.red(color);
int green = Color.green(color);
int blue = Color.blue(color);
//create a ColorMatrix with the RGB Components
float[] matrix = {
0, 0, 0, 0, red
public Bitmap blurBitmap(Bitmap bitmap){
//Let's create an empty bitmap with the same size of the bitmap we want to blur
Bitmap outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
//Instantiate a new Renderscript
RenderScript rs = RenderScript.create(getApplicationContext());
//Create an Intrinsic Blur Script using the Renderscript
ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
@Mariuxtheone
Mariuxtheone / build.gradle
Last active December 29, 2015 04:59
Android Studio 0.3.6 APK Signing issue. 1) Add the following code to *build.gradle* 2) Add the debug.keystore and your release.keystore file into project root folder 3) Update the "mypassword" and "myalias" strings in code with your keystore password and alias, 4) Select "Release" in *Build Variants* (you can find it in Help->Find Actions->Build…
android {
...
signingConfigs {
debug {
storeFile file("debug.keystore")
}
myConfig {
storeFile file("release.keystore")
@Mariuxtheone
Mariuxtheone / HideMenuItem.java
Last active December 26, 2015 13:09
Hide Menu Item from ActionBar - Menu if the device doesn't support a certain feature.
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getSupportMenuInflater();
inflater.inflate(R.menu.menu, menu);
//Let's say we want to remove a "Share with Bluetooth" item from our Action Bar/Menu
PackageManager pm = getPackageManager();
if (!pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)) {
MenuItem item = menu.findItem(R.id.bluetoothSharing);
item.setVisible(false);
@Mariuxtheone
Mariuxtheone / OnClickListenerActivity.java
Last active December 26, 2015 12:39
Use a ViewSwitcher to put two widgets where only one can fit. This is useful if you want to save space in your UI but don't want to give up multiple features.
public class OnClickListenerActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
commutateViewSwitcherButton.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
final ViewSwitcher viewSwitcher = (ViewSwitcher) findViewById(R.id.viewSwitcher);