Skip to content

Instantly share code, notes, and snippets.

@dineshmm23
dineshmm23 / drawMultilineTextToBitmap.java
Last active August 22, 2018 11:08
Measure height of multiline text To center text vertically we need to know text height. Instantiate StaticLayout with text width according to your needs, for us it is simple the width of Bitmap/Canvas minus 16dp padding. The getHeight() then returns height of text. Positioning text on Canvas There are four simple steps to position text on Canvas…
public Bitmap drawMultilineTextToBitmap(Context gContext,
int gResId,
String gText) {
// prepare canvas
Resources resources = gContext.getResources();
float scale = resources.getDisplayMetrics().density;
Bitmap bitmap = BitmapFactory.decodeResource(resources, gResId);
android.graphics.Bitmap.Config bitmapConfig = bitmap.getConfig();
public String compressImage(String imageUri) {
String filePath = getRealPathFromURI(imageUri);
Bitmap scaledBitmap = null;
BitmapFactory.Options options = new BitmapFactory.Options();
// by setting this field as true, the actual bitmap pixels are not loaded in the memory. Just the bounds are loaded. If
// you try the use the bitmap here, you will get null.
options.inJustDecodeBounds = true;
public class SomeCode extends AppCompatActivity {
private final static long intervalTime = 3000;
static ArrayList<String> result = new ArrayList<String>();
/**
* The {@link android.support.v4.view.PagerAdapter} that will provide
* fragments for each of the sections. We use a
* {@link FragmentPagerAdapter} derivative, which will keep every
* loaded fragment in memory. If this becomes too memory intensive, it
* may be best to switch to a
@dineshmm23
dineshmm23 / initializeSwipeToRefresh
Created August 8, 2018 08:00
Method for swipe to refresh
private void initializeSwipeToRefresh() {
// Swipe down to force synchronize
//swipeRefreshLayoutUserRole = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout);
swipeRefreshLayoutUserRole.setDistanceToTriggerSync(390);
//swipeRefreshLayoutUserRole.setEnabled(true); //Controlled by fragments!
swipeRefreshLayoutUserRole.setColorSchemeResources(
android.R.color.holo_purple, android.R.color.holo_blue_light,
android.R.color.holo_green_light, android.R.color.holo_orange_light);
swipeRefreshLayoutUserRole.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
@dineshmm23
dineshmm23 / SwipeRefreshLayout, RecyclerView, and EmptyView
Last active August 8, 2018 07:50
A couple of common usage patterns on Android is to use the SwipeRefreshLayout to enable pull-to-refresh, and also to have a custom “empty” view that displays when there are no items in the list. Unfortunately trying to combine these two patterns often results in problems. Reference--> http://innodroid.com/blog/post/recycler-empty-swipe-refresh
<SwipeRefreshLayoutWithEmpty ...>
<FrameLayout ...>
<TextView android:text="List is Empty" ...>
<RecyclerView ...>
</FrameLayout>
</SwipeRefreshLayoutWithEmpty>
--Be aware: this function won't copy attributes of initial foreign key.
--It only takes foreign table name / column name, drops current key and replaces with new one.
CREATE OR REPLACE FUNCTION
replace_foreign_key(f_table VARCHAR, f_column VARCHAR, new_options VARCHAR)
RETURNS VARCHAR
AS $$
DECLARE constraint_name varchar;
DECLARE reftable varchar;
DECLARE refcolumn varchar;
[
{
"communityId": 1,
"communityName": "Ice Hockey Community club",
"communityType": "Leagues",
"description": "Club Membership can have more access on subscription",
"admin": [
"Rohan",
"Raheem"
],