This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.codeswimmer.android.util; | |
import android.os.Looper; | |
public class ThreadUtil { | |
public static final boolean isRunningOnUiThread() { | |
return Looper.getMainLooper().getThread() == Thread.currentThread(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Bitmap rotateBitmap(Bitmap original, float degrees) { | |
int width = original.getWidth(); | |
int height = original.getHeight(); | |
Matrix matrix = new Matrix(); | |
matrix.preRotate(degrees); | |
Bitmap rotatedBitmap = Bitmap.createBitmap(original, 0, 0, width, height, matrix, true); | |
Canvas canvas = new Canvas(rotatedBitmap); | |
canvas.drawBitmap(original, 5.0f, 0.0f, null); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Use this to make it landscape: | |
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); | |
...and this to make it portrait: | |
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String getDeviceSerialNumber(Context context) { | |
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); | |
return telephonyManager.getDeviceId(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static final int determineCurrentScreenOrientation(Context context) { | |
Display display = ((WindowManager) context.getSystemService(WINDOW_SERVICE)).getDefaultDisplay(); | |
int orientation = display.getOrientation(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Test extends Activity { | |
GridView gv; | |
Gallery g[] = new Gallery[3]; | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.main); | |
gv = (GridView)findViewById(R.id.gridview); | |
gv.setAdapter(new GAdapter()); | |
for (int i = 0; i < g.length; i++) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RetrievedDataFragment extends Fragment implements LoaderManager.LoaderCallbacks<D> { | |
public RetrievedDataFragment() { | |
} | |
@Override | |
public void onActivityCreated(Bundle savedInstanceState) { | |
super.onActivityCreated(savedInstanceState); | |
getLoaderManager().initLoader(0, null, this); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static final boolean hasNetworkConnectivity(Context context) { | |
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); | |
NetworkInfo wifi = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); | |
NetworkInfo mobile = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); | |
return (wifi.isAvailable() || mobile.isAvailable()) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String eventActionToString(int eventAction) { | |
switch (eventAction) { | |
case MotionEvent.ACTION_CANCEL: return "Cancel"; | |
case MotionEvent.ACTION_DOWN: return "Down"; | |
case MotionEvent.ACTION_MOVE: return "Move"; | |
case MotionEvent.ACTION_OUTSIDE: return "Outside"; | |
case MotionEvent.ACTION_UP: return "Up"; | |
case MotionEvent.ACTION_POINTER_DOWN: return "Pointer Down"; | |
case MotionEvent.ACTION_POINTER_UP: return "Pointer Up"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static final float getCurrentSpeed(double location, int formatType) { | |
Location location = Location.convert(location, formatType) | |
return location.getSpeed(); | |
} |
OlderNewer