NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

package appcode.in;

import android.content.res.Resources;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.view.ViewTreeObserver;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

// String[] mobileArray = {"Android","IPhone","WindowsMobile","Blackberry",
// "WebOS","Ubuntu","Windows7","Max OS X"};

String[] mobileArray = {"A","IPhone","WindowsMobile","Blackberry",
"WebOS","Ubuntu","Windows7","Max OS X"};

int rowcount=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

//create and initialize recycler view object
final RecyclerView recyclerView = findViewById(R.id.recyclerView);

final GridLayoutManager layoutManager = new GridLayoutManager(this, 3);
recyclerView.setLayoutManager(layoutManager);

MyAdapter adapter = new MyAdapter(mobileArray, this);

recyclerView.setAdapter(adapter);

recyclerView.getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {

int count=recyclerView.getChildCount();
if(rowcount < count)
{
String data=mobileArray[rowcount];
Paint paint = new Paint();
paint.setTextSize(15);
Rect result = new Rect();
paint.getTextBounds(data, 0, data.length(), result);
float width = (result.width());

int viewWidth = recyclerView.getMeasuredWidth();

Resources r = getResources();
float px = TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, width,
r.getDisplayMetrics()
);



// Paint paint = new Paint();
//
// paint.setTypeface(Typeface.create("sans-serif", Typeface.BOLD));
// int spSize = 18;
// float scaledSizeInPixels = TypedValue.applyDimension(
// TypedValue.COMPLEX_UNIT_DIP,
// spSize,
// getResources().getDisplayMetrics());
// paint.setTextSize(scaledSizeInPixels);
//
//// Now compute!
// Rect bounds = new Rect();
//
// paint.getTextBounds(data, 0, data.length(), bounds);
// // Log.d(TAG, "width: " + bounds.width() + " height: " + bounds.height());
// int viewWidth = recyclerView.getMeasuredWidth();

// context.getResources().getDisplayMetrics().density;
int newSpanCount = (int) Math.floor(viewWidth / (px));
layoutManager.setSpanCount(newSpanCount);
layoutManager.requestLayout();
rowcount++;
}
}
});


}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.