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.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 android.widget.TextView;

import com.google.android.flexbox.FlexboxLayoutManager;

import java.util.ArrayList;
import java.util.Arrays;

public class MainActivity extends AppCompatActivity {
ArrayList personNames = new ArrayList<>(Arrays.asList("Android","IPhone","WindowsMobile","Blackberryregrg", "WebOS","Ubuntu","Windows7","Max OS X"));
int rowcount=0;
private static final int sColumnWidth = 120;
RecyclerView recyclerView;
int current_position=0;
GridLayoutManager layoutManager;
int count=0;
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
recyclerView = findViewById(R.id.recyclerView);

layoutManager = new GridLayoutManager(this, 3);
recyclerView.setLayoutManager(layoutManager);
textView=findViewById(R.id.textview);

CustomAdapter adapter = new CustomAdapter( this,personNames);

recyclerView.setAdapter(adapter);
ViewTreeObserver viewTreeObserver = recyclerView.getViewTreeObserver();
viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
calculateSize();
Log.e("count is nw","");
// layoutManager.setSpanCount(2);
// layoutManager.requestLayout();
}
});



}

@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);
}
private void calculateSize() {


Log.e("Call time ",""+count++);
Log.e("RecylceView widht ",""+recyclerView.getMeasuredWidth());
float width=0;
int spanCount=0;

for (int i=current_position;i<personNames.size();i++)
{


if (width<recyclerView.getMeasuredWidth())
{

// textView.setText("");
// textView.setText(personNames.get(i).toString());
Paint paint = new Paint();
paint.setTextSize(12);
Rect result = new Rect();
paint.getTextBounds(personNames.get(i).toString(), 0, personNames.get(i).toString().length(), result);
Log.e("less width is ",""+convertDPToPixels(result.width()));
width=width+convertDPToPixels(result.width()*2);
// width=width+textView.getMeasuredWidth();
Resources r = getResources();
float px = TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
result.width(),
r.getDisplayMetrics()
);
Log.e("width is ",""+width+"float"+px);
spanCount++;
}

else
{

current_position=i-1;

Log.e("width is else ",""+width+"pos"+i);

// int spanCount = (int) Math.floor(recyclerView.getWidth() / convertDPToPixels((int) width));
if (spanCount==0)
{
spanCount=1;
}
Log.e("span count ",""+width+" span count"+spanCount);
layoutManager.setSpanCount(spanCount-1);
layoutManager.requestLayout();

break;

}


}






}

private float convertDPToPixels(int dp) {
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
float logicalDensity = metrics.density;
return dp * logicalDensity;
}
}
     
 
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.