Skip to content

Instantly share code, notes, and snippets.

View xalexchen's full-sized avatar
🤖

Alex.Chen xalexchen

🤖
View GitHub Profile
private void flipCard() {
if (mShowingBack) {
getFragmentManager().popBackStack();
return;
}
// Flip to the back.
mShowingBack = true;
@xalexchen
xalexchen / DisplayActivity.java
Created March 12, 2014 02:26
Set full screen mode on the device
/**
* Sets full screen mode on the device, by setting parameters in the current
* window and View
* @param fullscreen
*/
public void setFullScreen(boolean fullscreen) {
// If full screen is set, sets the fullscreen flag in the Window manager
getWindow().setFlags(
fullscreen ? WindowManager.LayoutParams.FLAG_FULLSCREEN : 0,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
@xalexchen
xalexchen / Constants.java
Created March 13, 2014 07:25
USER_AGENT
/*
* A user-agent string that's sent to the HTTP site. It includes information about the device
* and the build that the device is running.
*/
public static final String USER_AGENT = "Mozilla/5.0 (Linux; U; Android "
+ android.os.Build.VERSION.RELEASE + ";"
+ Locale.getDefault().toString() + "; " + android.os.Build.DEVICE
+ "/" + android.os.Build.ID + ")";
@xalexchen
xalexchen / PhotoDownloadRunnable.java
Created March 13, 2014 07:26
Download image file into byte array
/*
* Copyright (C) ${year} 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
@xalexchen
xalexchen / PhotoDecodeRunnable.java
Created March 13, 2014 07:54
This runnable decodes a byte array containing an image
/*
* Copyright (C) 2012 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
@xalexchen
xalexchen / PhotoTask.java
Created March 13, 2014 07:58
Class manage PhotoDownloadRunnable and PhotoDownloadRunnable object
/*
* Copyright (C) 2012 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
@xalexchen
xalexchen / ScreenUtils .java
Created March 16, 2014 08:07
Android ScreenUtils
public class ScreenUtils {
public static float dpToPx(Context context, float dp) {
if (context == null) {
return -1;
}
return dp * context.getResources().getDisplayMetrics().density;
}
public static float pxToDp(Context context, float px) {
import android.graphics.Bitmap;
/**
* Created by paveld on 3/6/14.
*/
public class FastBlur {
public static Bitmap doBlur(Bitmap sentBitmap, int radius, boolean canReuseInBitmap) {
// Stack Blur v1.0 from
public class DatabaseManager {
private AtomicInteger mOpenCounter = new AtomicInteger();
private static DatabaseManager instance;
private static SQLiteOpenHelper mDatabaseHelper;
private SQLiteDatabase mDatabase;
public static synchronized void initializeInstance(SQLiteOpenHelper helper) {
if (instance == null) {
private void calculateVideoSize() {
try {
AssetFileDescriptor afd = getAssets().openFd(FILE_NAME);
MediaMetadataRetriever metaRetriever = new MediaMetadataRetriever();
metaRetriever.setDataSource(
afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
String height = metaRetriever
.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT);
String width = metaRetriever
.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH);