Skip to content

Instantly share code, notes, and snippets.

@danieldisu
danieldisu / activitystarterbug.java
Created December 19, 2017 13:28
ActivityStarter bug java
public class TestActivity extends AppCompatActivity {
@Arg String arg1;
@Arg String arg2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActivityStarter.fill(this);
@danieldisu
danieldisu / package.json
Created January 29, 2015 16:07
Javascript tooling landscape
{
"name": "test-project",
"version": "1.0.0",
"description": "just a quick test project to show package.json structure",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
@danieldisu
danieldisu / RandomActivity.java
Created June 11, 2014 10:53
Show Android keyboard and focus EditText
@Override
public void onResume() {
super.onResume();
searchEditText.requestFocus();
showKeyboard();
}
private void showKeyboard() {
searchEditText.postDelayed(new Runnable() {
@Override
@danieldisu
danieldisu / BaseActivity.java
Created June 11, 2014 08:44
Android Activity animation transitions
@Override
public void startActivity(Intent intent) {
super.startActivity(intent);
overridePendingTransition(
R.anim.slide_in_right, R.anim.slide_out_left);
// as mentioned in q http://stackoverflow.com/a/13578979/2288146
// The first argument determines the transition animation used by the
// second activity. Also the two animations can be more properly named
// as slide_out_to_right and slide_in_from_left, since in fact they
@danieldisu
danieldisu / aFragment.java
Created June 11, 2014 08:23
Android Fragment Animations
getFragmentManager().beginTransaction()
.setCustomAnimations(R.animator.right_in, R.animator.right_out)
.remove(yourFragment)
.commit();
getFragmentManager().beginTransaction()
.setCustomAnimations(R.animator.right_in, R.animator.right_out)
.add(R.id.fragmentContainer, yourFragment, "yourFragment")
.commit();
@danieldisu
danieldisu / utils.java
Created June 10, 2014 13:02
Create Bitmap/Drawable from View
// Part of this code is taken from http://stackoverflow.com/a/4618030/2288146
// Thanks to http://stackoverflow.com/users/540908/nininho
private static BitmapDrawable loadBitmapFromView(View view, Context context) {
view.setDrawingCacheEnabled(true);
// this is the important code :)
// Without it the view will have a dimension of 0,0 and the bitmap will be null
view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
@danieldisu
danieldisu / stringResourceWithVariables.java
Created June 9, 2014 14:28
Android variable inside strings.xml resource file
String string_resource = getResources().getString(R.string.number_of_results_text);
String formattedString = String.format(string_resource, randomList.size());
searchResultTopText.setText(formattedString);