TextViewEx, (Textjustify) - android

my problem is this, using TextViewEx (https://github.com/bluejamesbond/TextJustify-Android) class texts to justify my android application works fine until the text over a carriage return appear \ n, when this happens the text is cut losing asin several lines of this, I need a solution to justify text without html injection, to change the font size if the application is open from mobile or from a tablet, if know what the problem is and can help me I thank you.
I will put the code in my application:
code xml:
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_marginTop="45dp"
android:layout_below="#+id/view1" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="50dp"
android:background="#drawable/background_border" >
<TextView
android:id="#+id/txt_fecha_promociones"
style="#style/fechaDentroxlarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:text="24/05/2014" />
<TextView
android:id="#+id/txt_titulo_promociones"
style="#style/tituloDentroxlarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_below="#+id/comparte"
android:text="Titulo" />
**<com.xxxxx.tools.TextViewEx
android:id="#+id/txt_noticia_promociones"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/img_promo"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_marginTop="20dp"
android:textSize="30sp"
android:text="noticia"
android:textColor="#color/txtBlanco" />**
<ImageView
android:id="#+id/comparte"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentRight="true"
android:layout_marginRight="15dp"
android:layout_marginTop="15dp"
android:layout_toLeftOf="#+id/txt_fecha_promociones"
android:onClick="compartir"
android:src="#drawable/share_icon_white" />
<ImageView
android:id="#+id/img_promo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/txt_titulo_promociones"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:src="#drawable/promo1" />
</RelativeLayout>
</ScrollView>
code java:
public class xxxxx extends NavegacionActivity {
TextView txt_servicio;
TextViewEx txt_descripcion;
TextView prueba;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_servicios_dentro);
setBehindContentView(R.layout.menu);
getSlidingMenu().setBehindOffset(100);
txt_servicio = (TextView) findViewById(R.id.txt_titulo_servicio);
txt_descripcion = (TextViewEx) findViewById(R.id.txt_descripcion_servicios);
Intent i = getIntent();
txt_servicio.setText(i.getStringExtra("servicio"));
txt_descripcion.setText(i.getStringExtra("descripcion"),true);
}
#Override
public void onBackPressed() {
// TODO Auto-generated method stub
Intent i = new Intent(this, xxxx.class);
startActivity(i);
this.finish();
}
}

Import the classes TextJustifyUtils.java and TextViewEx.java in the root of your project
In your XML Replace TextView --->> com.example.myaplication.TextViewEx

Just go to TextViewEx.java and change to this code:
#Override
public void setPadding(int left, int top, int right, int bottom) {
DisplayMetrics metrics = getContext().getResources()
.getDisplayMetrics();
super.setPadding((int) ((left + (metrics.density * 10))), top,
(int) (right + (metrics.density * 10)),
(int) (bottom + (metrics.heightPixels * 1.5)));
Log.i("Log", "metrics : " + metrics);
}

Related

Adjust the size of a shape based on seekbar progress

I currently am trying to use the SeekBar to change the size of a ring: as the value of the SeekBar increases, I would like the size of the ring to increase. However, when I use the code below, the shape size does not change. Does anyone know how to make this work?
public class MainActivity extends Activity {
TextView textview3;
SeekBar tipSeekBar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tipSeekBar = (SeekBar) findViewById(R.id.seekBar);
tipSeekBar.setOnSeekBarChangeListener(tipSeekBarListener);
}
private OnSeekBarChangeListener tipSeekBarListener = new OnSeekBarChangeListener(){
#Override
public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
TextView textview3 = (TextView) findViewById(R.id.textView3);
textview3.setHeight((int) (tipSeekBar.getProgress()));
textview3.setWidth((int) (tipSeekBar.getProgress()));
}
#Override
public void onStartTrackingTouch(SeekBar arg0) {
TextView textview3 = (TextView) findViewById(R.id.textView3);
textview3.setHeight((int) (tipSeekBar.getProgress()));
textview3.setWidth((int) (tipSeekBar.getProgress()));
}
#Override
public void onStopTrackingTouch(SeekBar arg0) {
TextView textview3 = (TextView) findViewById(R.id.textView3);
textview3.setHeight((int) (tipSeekBar.getProgress()));
textview3.setWidth((int) (tipSeekBar.getProgress()));
}
};
xml file:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView"
android:layout_marginTop="20dp"
android:text="TextView" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="#drawable/circgraya" />
<TextView
android:id="#+id/textView3"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="#drawable/ring_unfilled_gray" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:gravity="center"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<SeekBar
android:id="#+id/seekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textView4"
android:layout_toRightOf="#+id/textView"
android:progressDrawable="#drawable/red_scrubber_progress"
android:thumb="#drawable/red_scrubber_control" />
<TextView
android:id="#+id/textView"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView4"
android:background="#CC0000"
android:gravity="center"
android:text="10"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#ffffff" />
</RelativeLayout>
Your problem is here...
<TextView
android:id="#+id/textView3"
android:layout_width="200dp" <---
android:layout_height="200dp" <---
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="#drawable/ring_unfilled_gray" />
You've set the size explicitly, so it seems it won't override it as it would min, max(s), and wrapping content.
This works for me (changing the size of the text view via the seek bar that is)...
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content" <---
android:layout_height="wrap_content" <---
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="I'll get bigger soon..." /> <-- notice no background!
However, this is a hack. A text view probably isn't what you want. I didn't use an image because the image isn't important to controlling the height and width of the text view. An image would be more appropriate I believe. I think you'll find, once you get it "working", it might not behave as you would like.
Also -
You could be doing some unnecessary things here. My code that handles the progress change is like so (names changed to mine now)...
...
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (fromUser) {
mTextView.setHeight(progress);
mTextView.setWidth(progress);
}
}
...
As you can tell I don't...cast an int to an int, getProgress() - I've already got it, or instantiate a new TextView for each change and gesture. You're actually allocating two new TextViews on a gesture; one at the start, and one at the end. You may want to keep a member TextView to hang on to and refer to the Android Docs to know what API methods you're using are doing, the parameters they provide, and their proper usage.

Android allow multi-touch on an activity

I am trying to allow the user to put a ring on the circle on the screen and then press the larger button so that the circle goes to the next ring size.
Everything work fines when no ring is on the screen.
However when a ring it on the screen no other touches are called and the buttons and the seekbar does not work.
I'm new in android and i haven't came across this requirement before. Is there a way I can allow multi-touch gestures on the activity or a way to ignore touches on that specific layout?
XML File
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/White"
android:splitMotionEvents="false"
>
<TextView
android:id="#+id/us"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/uslbl"
android:padding="#dimen/standard_margin"
android:text="size"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/pressed_gemporia" />
<TextView
android:id="#+id/uklbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/uslbl"
android:padding="#dimen/standard_margin"
android:text="UK Size:"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/Black" />
<TextView
android:id="#+id/uk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/uklbl"
android:layout_alignBottom="#+id/uklbl"
android:layout_toRightOf="#+id/uklbl"
android:padding="#dimen/standard_margin"
android:text="size"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/pressed_gemporia" />
<ImageView
android:id="#+id/ci"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
<TextView
android:id="#+id/uslbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/uk"
android:gravity="left"
android:padding="#dimen/standard_margin"
android:text="US Size:"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/Black" />
<SeekBar
android:id="#+id/seekbar"
android:progressDrawable="#drawable/red_scrubber_progress"
android:thumb="#drawable/red_scrubber_control"
android:max="8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/divider" />
<View
android:id="#+id/divider"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_alignParentLeft="true"
android:layout_below="#+id/uklbl"
android:layout_marginTop="18dp"
android:background="#color/pressed_gemporia" />
<TextView
android:id="#+id/sizes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:padding="#dimen/standard_margin"
android:layout_below="#+id/seekbar"
android:text="TextView" android:textColor="#color/pressed_gemporia" />
<Button
android:id="#+id/right"
android:layout_width="100dp"
android:textColor="#color/pressed_gemporia"
android:layout_height="wrap_content"
android:background="#color/White"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/left"
android:text="Larger" />
<Button
android:id="#+id/left"
android:layout_width="100dp"
android:background="#color/White"
android:textColor="#color/pressed_gemporia"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="Smaller" />
<ImageView
android:id="#+id/ring"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/ci"
android:layout_centerHorizontal="true"
android:src="#drawable/j" />
Java Code
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ring_sizes);
left = (Button)findViewById(R.id.left);
right = (Button)findViewById(R.id.right);
us = (TextView) findViewById(R.id.us);
uk = (TextView) findViewById(R.id.uk);
ci = (ImageView)findViewById(R.id.ci);
ring = (ImageView)findViewById(R.id.ring);
sizes.add(R.drawable.j);
sizes.add(R.drawable.l);
sizes.add(R.drawable.n);
sizes.add(R.drawable.p);
sizes.add(R.drawable.r);
sizes.add(R.drawable.t);
sizes.add(R.drawable.v);
sizes.add(R.drawable.x);
sizes.add(R.drawable.z);
USsizes.add("5");
USsizes.add("6");
USsizes.add("7");
USsizes.add("8");
USsizes.add("9");
USsizes.add("10");
USsizes.add("11");
USsizes.add("12");
USsizes.add("13");
UKsizes.add("J-K");
UKsizes.add("L-M");
UKsizes.add("N-O");
UKsizes.add("P-Q");
UKsizes.add("R-S");
UKsizes.add("T-U");
UKsizes.add("V-W");
UKsizes.add("X-Y");
UKsizes.add("Z+");
color = (getBaseContext().getResources().getColor(R.color.pressed_gemporia));
value = (TextView) findViewById(R.id.sizes);
seekbar = (SeekBar) findViewById(R.id.seekbar);
seekbar.getProgressDrawable().setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
value.setText("UK Size : "+UKsizes.get(0) + " - US Size: " + USsizes.get(0));
setUpViews();
seekbar.setOnSeekBarChangeListener( new OnSeekBarChangeListener()
{
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser)
{
ring.setImageResource(sizes.get(progress));
us.setText(USsizes.get(progress));
uk.setText(UKsizes.get(progress));
counter=progress;
value.setText("UK Size : "+UKsizes.get(progress) + " - US Size: " + USsizes.get(progress));
}
public void onStartTrackingTouch(SeekBar seekBar)
{
// TODO Auto-generated method stub
}
public void onStopTrackingTouch(SeekBar seekBar)
{
// TODO Auto-generated method stub
}
});
}
public void setUpViews(){
ring.setImageResource(sizes.get(counter));
us.setText(USsizes.get(counter));
uk.setText(UKsizes.get(counter));
right.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View view)
{
if(UKsizes.size()>counter+1){
ring.setImageResource(sizes.get(counter+1));
seekbar.setProgress(counter+1);
}
}
});
left.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View view)
{
if(counter!=0){
ring.setImageResource(sizes.get(counter));
seekbar.setProgress(counter-1);
} }
});
}
}
There is a way to ignore touches in particular layout,for that you should add
android:splitMotionEvents="false"
in your layout . You can refer answers from thie following link
https://stackoverflow.com/questions/12777435/disable-multi-finger-touch-in-my-app

Android screen resolution issue

I have two tablets. I have run a test resolution app to get screen parameters. Thouse are the results.
1) Coby MID7042 7": low density, scale: 0.75, 120dpi, 480 x 764,
layout for large screen, drawable LDPI.
2) BQ Elcano 7": high density, scale: 1.5, 240dpi, 800 x 1208, layout
for large screen, drawable HDPI.
I have developed an android application that fits good on Coby screen, but in BQ the screen is cut in the right and in the bottom. That is, the screen is bigger than you can see on the screen. I think BQ screen is better and bigger than Coby, but I don't know why it doesn't fit the screen.
In my developed android app, the xml file for the screen is into res/layout folder. I always use sp and dp.
I have read about "supporting multiple screen" and so on, but in this case, I think BQ should show the screen at right fit using the same layout. But it doesn't.
Some one could help me about this issue? I don't know how could I solve this, because two tablets are large for layouts.
Thanks.
Edited. This is a layout that is cut in the right (the latest EditText is cut):
<LinearLayout
style="#style/GroupBox3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:baselineAligned="true" >
<LinearLayout
android:layout_width="130dp"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/TextView08"
style="#style/etstyle1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="#string/Box" />
<EditText
android:id="#+id/eBox"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:layout_weight="1"
android:background="#drawable/roundedittext"
android:ems="10"
android:enabled="true"
android:gravity="right"
android:inputType="number|numberSigned|numberDecimal"
android:selectAllOnFocus="true" >
</EditText>
</LinearLayout>
<LinearLayout
android:layout_width="130dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:orientation="vertical" >
<TextView
android:id="#+id/TextView06"
style="#style/etstyle1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="#string/Uds" />
<EditText
android:id="#+id/euds"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:background="#drawable/roundedittext"
android:ems="10"
android:enabled="true"
android:gravity="right"
android:inputType="number|numberSigned|numberDecimal"
android:selectAllOnFocus="true" />
</LinearLayout>
<LinearLayout
android:layout_width="130dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:orientation="vertical" >
<TextView
android:id="#+id/TextView09"
style="#style/etstyle1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal|left"
android:paddingLeft="10dp"
android:text="#string/Tar" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingBottom="5dp" >
<EditText
android:id="#+id/etar"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="#drawable/roundedittext"
android:ems="10"
android:enabled="true"
android:gravity="center_vertical|right"
android:inputType="number"
android:selectAllOnFocus="true" />
<Button
android:id="#+id/btnTarifa"
style="#style/btnSer"
android:layout_width="50dp"
android:layout_height="40dp"
android:layout_gravity="center_vertical|center_horizontal|center"
android:layout_marginTop="2dp"
android:text="#string/Inter" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="135dp"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:orientation="vertical" >
<TextView
android:id="#+id/etit"
style="#style/etstyle1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="#string/price" />
<EditText
android:id="#+id/eprice"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:background="#drawable/roundedittext"
android:ems="10"
android:enabled="true"
android:gravity="center_vertical|right"
android:inputType="numberDecimal"
android:selectAllOnFocus="true" />
</LinearLayout>
</LinearLayout>
DroidUsers answer is little bit confusing but method is effective...
look for more effective example:
http://www.vanteon.com/downloads/Scaling_Android_Apps_White_Paper.pdf
I have Used one approach where I design the Layout I wanted in a standard device, and store all dynamically apply all the layout dependent values(eg: padding, margin etc) using a seperate class. And by calculating a ratio with current device config to the standard i have stored,
I will give you my sample code. just go through it and find your way accordingly
public class ListViewDimensions
{
private Context _context;
private Configuration config;
private Display display;
private int _width;
private int _height;
private int _portOrLand;
private int _ORIENTATION_LAND=2;
private int _ORIENTATION_PORT=1;
private DisplayMetrics metrics;
private Dimension dimension;
//***************************** PORTRAIT ********************************\\
public int PlistLayoutPaddingLeft=16;
public int PlistLayoutPaddingRight=16;
public int PlistLayoutPaddingTop=16;
public int PlistLayoutPaddingBottom=15;
public int PsuraNoTextsize=10;
public int PsuraNameTextsize=20;
public int PayaNoTextsize=10;
public int PsuraNameWidth=180;
public int PpageNoTextsize=10;
public int PpageNoPadding=2;
public int PmalayalamFontsize;
public int ParabiFontsize;
public int PsuraHeadHeight=40;
//----------------------------------------------------------------------------------------
//***************************** LANDSCAPE IN TABS ********************************\\
public int LTlistLayoutPaddingLeft=35;
public int LTlistLayoutPaddingTop=30;
public int LTlistLayoutPaddingRight=35;
public int LTlistLayoutPaddingRightRightPage=35;
public int LTlistLayoutPaddingBottom=5;
public int LTpageNoTextsize=13;
public int LTpageNoPadding=0;
public int LTsuraNoTextsize=15;
public int LTsuraNameTextsize=25;
public int LTayaNoTextsize=15;
public int LTsuraNameWidth=375;
public int LTmalayalamFontsize;
public int LTarabiFontsize;
public int LTsuraHeadHeight=60;
//----------------------------------------------------------------------------------------
//***************************** LANDSCAPE IN NON-TABS ********************************\\
public int LlistLayoutPaddingLeft=21;
public int LlistLayoutPaddingRight=20;
public int LlistLayoutPaddingTop=16;
public int LlistLayoutPaddingBottom=17;
public int LsuraNoTextsize=10;
public int LsuraNameTextsize=20;
public int LayaNoTextsize=10;
public int LsuraNameWidth=330;
public int LpageNoTextsize=13;
public int LpageNoPadding=3;
public int LmalayalamFontsize;
public int LarabiFontsize;
public int LsuraHeadHeight=40;
//----------------------------------------------------------------------------------------
public float xScale;
private float yScale;
private double diagonalInches;
public class Dimension
{
public int listLayoutPaddingLeft;
public int listLayoutPaddingRight;
public int listLayoutPaddingTop;
public int listLayoutPaddingBottom;
public int pageNoTextsize;
public int pageNoPadding;
public int suraNoTextsize;
public int suraNameTextsize;
public int ayaNoTextsize;
public int suraNameWidth;
public int malayalamFontsize;
public int arabiFontsize;
public int suraHeadHeight;
public String bismi;
}
public ListViewDimensions.Dimension getDimensions(Context c)
{
PmalayalamFontsize=MyApp.appSettings.listMalayalamFontSize;
ParabiFontsize=MyApp.appSettings.listMalayalamFontSize;
LTmalayalamFontsize=MyApp.appSettings.listMalayalamFontSize*2;
LTarabiFontsize=MyApp.appSettings.listMalayalamFontSize*2;
LmalayalamFontsize=MyApp.appSettings.listMalayalamFontSize;
LarabiFontsize=MyApp.appSettings.listMalayalamFontSize;
dimension=new Dimension();
_context=c;
config =c.getResources().getConfiguration();
display=((Activity) c).getWindowManager().getDefaultDisplay();
_width = display.getWidth();
_height =display.getHeight();
if(config.orientation==config.ORIENTATION_LANDSCAPE)
_portOrLand=_ORIENTATION_LAND;
else
_portOrLand=_ORIENTATION_PORT;
metrics = new DisplayMetrics();
((Activity) c).getWindowManager().getDefaultDisplay().getMetrics(metrics);
int widthPixels = metrics.widthPixels;
int heightPixels = metrics.heightPixels;
int density=metrics.densityDpi;
float widthDpi = metrics.xdpi;
float heightDpi = metrics.ydpi;
if(density/widthDpi>1.2)
{
widthDpi=density;
heightDpi=density;
}
float widthInches = widthPixels / widthDpi;
float heightInches = heightPixels / heightDpi;
diagonalInches = Math.sqrt((widthInches * widthInches) + (heightInches * heightInches));
if(diagonalInches>=6.7 && _portOrLand==_ORIENTATION_LAND)
{
//TODO : for landscape in tabs
xScale = (_width/2)/(float)640 ;
yScale = _height/(float)752 ;
dimension.listLayoutPaddingLeft=LTlistLayoutPaddingLeft;
dimension.listLayoutPaddingRight=LTlistLayoutPaddingRight;
dimension.listLayoutPaddingTop=LTlistLayoutPaddingTop;
dimension.listLayoutPaddingBottom=LTlistLayoutPaddingBottom;
dimension.pageNoTextsize=LTpageNoTextsize;
dimension.pageNoPadding=LTpageNoPadding;
dimension.malayalamFontsize=LTmalayalamFontsize;
dimension.arabiFontsize=LTarabiFontsize;
dimension.suraNoTextsize=LTsuraNoTextsize;
dimension.suraNameTextsize=LTsuraNameTextsize;
dimension.ayaNoTextsize=LTayaNoTextsize;
dimension.suraNameWidth=LTsuraNameWidth;
dimension.suraHeadHeight=LTsuraHeadHeight;
dimension.bismi="&%$";
}
else if( _portOrLand==_ORIENTATION_PORT)
{
//TODO : for portrait in non-tab devices and tabs
xScale = _width/(float)320 ;
yScale = _height/(float)480 ;
dimension.listLayoutPaddingLeft=PlistLayoutPaddingLeft;
dimension.listLayoutPaddingRight=PlistLayoutPaddingRight;
dimension.listLayoutPaddingTop=PlistLayoutPaddingTop;
dimension.listLayoutPaddingBottom=PlistLayoutPaddingBottom;
dimension.pageNoTextsize=PpageNoTextsize;
dimension.pageNoPadding=PpageNoPadding; //TODO: check whether it is mandatory
dimension.malayalamFontsize=PmalayalamFontsize;
dimension.arabiFontsize=ParabiFontsize;
dimension.suraHeadHeight=PsuraHeadHeight;
dimension.suraNoTextsize=PsuraNoTextsize;
dimension.suraNameTextsize=PsuraNameTextsize;
dimension.ayaNoTextsize=PayaNoTextsize;
dimension.suraNameWidth=PsuraNameWidth;
if(diagonalInches<4.0)
dimension.bismi="ó";
else
dimension.bismi="&%$";
}
else if(diagonalInches<6.7 && _portOrLand==_ORIENTATION_LAND)
{
//TODO : for land in non-tab devices
xScale = _height/(float)320 ;
yScale = _width/(float)480 ;
dimension.listLayoutPaddingLeft=LlistLayoutPaddingLeft;
dimension.listLayoutPaddingRight=LlistLayoutPaddingRight;
dimension.listLayoutPaddingTop=LlistLayoutPaddingTop;
dimension.listLayoutPaddingBottom=LlistLayoutPaddingBottom;
dimension.suraHeadHeight=LsuraHeadHeight;
dimension.suraNoTextsize=LsuraNoTextsize;
dimension.suraNameTextsize=LsuraNameTextsize;
dimension.ayaNoTextsize=LayaNoTextsize;
dimension.suraNameWidth=LsuraNameWidth;
dimension.pageNoTextsize=LpageNoTextsize;
dimension.pageNoPadding=LpageNoPadding; //TODO: check whether it is mandatory
dimension.malayalamFontsize=LmalayalamFontsize;
dimension.arabiFontsize=LarabiFontsize;
dimension.suraHeadHeight=LsuraHeadHeight;
dimension.bismi="&%$";
}
dimension.listLayoutPaddingLeft=(int) (dimension.listLayoutPaddingLeft*xScale);
dimension.listLayoutPaddingRight=(int) (dimension.listLayoutPaddingRight*xScale);
dimension.listLayoutPaddingTop=(int) (dimension.listLayoutPaddingTop*yScale);
dimension.listLayoutPaddingBottom=(int) (dimension.listLayoutPaddingBottom*yScale);
dimension.pageNoTextsize=(int) (dimension.pageNoTextsize*xScale);
dimension.pageNoPadding=(int) (dimension.pageNoPadding*yScale);
dimension.malayalamFontsize=(int) (dimension.malayalamFontsize*xScale);
dimension.arabiFontsize=(int) (dimension.arabiFontsize*xScale);
dimension.suraHeadHeight=(int) (dimension.suraHeadHeight*yScale);
dimension.suraNoTextsize=(int) (dimension.suraNoTextsize*xScale);
dimension.suraNameTextsize=(int) (dimension.suraNameTextsize*xScale);
dimension.ayaNoTextsize=(int) (dimension.ayaNoTextsize*xScale);
dimension.suraNameWidth=(int) (dimension.suraNameWidth*xScale);
return this.dimension;
}
public ListViewDimensions.Dimension updateFontSize()
{
if(diagonalInches>=6.7 && _portOrLand==_ORIENTATION_LAND)
{
xScale = (_width/2)/(float)640 ;
yScale = _height/(float)752 ;
dimension.malayalamFontsize=LTmalayalamFontsize;
dimension.arabiFontsize=LTarabiFontsize;
}
else if( _portOrLand==_ORIENTATION_PORT)
{
xScale = _width/(float)320 ;
yScale = _height/(float)480 ;
dimension.malayalamFontsize=PmalayalamFontsize;
dimension.arabiFontsize=ParabiFontsize;
}
else if(diagonalInches<6.7 && _portOrLand==_ORIENTATION_LAND)
{
xScale = _height/(float)320 ;
yScale = _width/(float)480 ;
dimension.malayalamFontsize=LmalayalamFontsize;
dimension.arabiFontsize=LarabiFontsize;
}
dimension.malayalamFontsize=(int) (dimension.malayalamFontsize*xScale);
dimension.arabiFontsize=(int) (dimension.arabiFontsize*xScale);
return dimension;
}
}
You should try to work with android:layout_weight instead of specifying your LinearLayout's android:layout_width="130dp". This way, the widths of your textviews and edittexts and what not can be set to fill_parent and Android will scale anything to the size of your screen, whatever the device you're working on might be.
With an exception for the linear layout where you have a new linearlayout for the edittext and a button, there you should use the weight attribute for this edittext and button again instead of their width parameters.
A slightly modified (I couldn't keep the style and text attributes when testing, for obvious reasons) example of how your xml would look:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:baselineAligned="true" >
<LinearLayout
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1" >
<TextView
android:id="#+id/TextView08"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<EditText
android:id="#+id/eBox"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:ems="10"
android:enabled="true"
android:gravity="right"
android:inputType="number|numberSigned|numberDecimal"
android:selectAllOnFocus="true" >
</EditText>
</LinearLayout>
<LinearLayout
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:orientation="vertical"
android:layout_weight="1" >
<TextView
android:id="#+id/TextView06"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" />
<EditText
android:id="#+id/euds"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:ems="10"
android:enabled="true"
android:gravity="right"
android:inputType="number|numberSigned|numberDecimal"
android:selectAllOnFocus="true" />
</LinearLayout>
<LinearLayout
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:orientation="vertical"
android:layout_weight="1" >
<TextView
android:id="#+id/TextView09"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal|left"
android:paddingLeft="10dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingBottom="5dp" >
<EditText
android:id="#+id/etar"
android:layout_weight="0.5"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:ems="10"
android:enabled="true"
android:gravity="center_vertical|right"
android:inputType="number"
android:selectAllOnFocus="true" />
<Button
android:id="#+id/btnTarifa"
android:layout_weight="0.5"
android:layout_height="40dp"
android:layout_gravity="center_vertical|center_horizontal|center"
android:layout_marginTop="2dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_weight="1"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:orientation="vertical" >
<TextView
android:id="#+id/etit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" />
<EditText
android:id="#+id/eprice"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:ems="10"
android:enabled="true"
android:gravity="center_vertical|right"
android:inputType="numberDecimal"
android:selectAllOnFocus="true" />
</LinearLayout>
</LinearLayout>
After lot of sarch I haven't found why it happens, but a very quickly solution. I can scale all the application adding this code to the main activity:
public void changeDensity(float desiredDensity) {
//desiredDensity : ldpi = 0.75 (120dpi) , mdpi = 1 (160dpi), hdpi = 1.5 (240dpi), xhdpi = 2.0 (320dpi)
DisplayMetrics metrics = getResources().getDisplayMetrics();
metrics.density = desiredDensity;
metrics.xdpi = desiredDensity * 160;
metrics.ydpi = desiredDensity * 160;
metrics.densityDpi = (int) (desiredDensity * 160);
getResources().updateConfiguration(null, null);
}
Calling this function on creating main activity, with 1.25f as desiredDensity, the application is scaled to fit the right dimension. I know this isn't the rigth way. I should change all layout, but I can't do it with this device because both use the same layout (large) and then, perhaps, I should use w as parameter in res/layout. Briefly, scaling resolve the problem.
From this: https://stackoverflow.com/a/12077236/1616700

Android Activity as dialog black border

I have activity as a dialogue, all the shows I like. But I have a problem with a frame around them. Just like here.
My Activity:
public class AlarmAlert extends Activity implements Alarms.AlarmSettings {
#Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
AlarmAlertWakeLock.acquire(this);
/*
* FIXME Intentionally verbose: always log this until we've fully
* debugged the app failing to start up
*/
Log.v("AlarmAlert.onCreate()");
DigitalClock dc = (DigitalClock) findViewById(R.id.digitalClock1);
mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
Intent i = getIntent();
mAlarmId = i.getIntExtra(Alarms.ID, -1);
Alarms.getAlarm(getContentResolver(), this, mAlarmId);
mKlaxon = new AlarmKlaxon();
mKlaxon.postPlay(this, mAlarmId);
/* Set the title from the passed in label */
setTitleFromIntent(i);
/*
* allow next alarm to trigger while this activity is active
*/
Alarms.disableSnoozeAlert(AlarmAlert.this);
Alarms.disableAlert(AlarmAlert.this, mAlarmId);
Alarms.setNextAlert(this);
mKlaxon.setKillerCallback(new AlarmKlaxon.KillerCallback() {
public void onKilled() {
if (Log.LOGV)
Log.v("onKilled()");
updateSilencedText();
/* don't allow snooze */
mSnoozeButton.setEnabled(false);
dismiss();
mState = KILLED;
}
});
updateLayout();
SharedPreferences settings = getSharedPreferences(
AlarmClock.PREFERENCES, 0);
if (settings.getBoolean(AlarmClock.PREF_SHAKE_SNOOZE, true)) {
mShakeListener = new ShakeListener(this);
mShakeListener
.setOnShakeListener(new ShakeListener.OnShakeListener() {
public void onShake() {
snooze();
if (mCaptchaSnooze == 0)
finish();
}
});
}
}
private void setTitleFromIntent(Intent i) {
mLabel = i.getStringExtra(Alarms.LABEL);
if (mLabel == null || mLabel.length() == 0) {
mLabel = getString(R.string.default_label);
}
setTitle(mLabel);
}
private void updateSilencedText() {
TextView silenced = (TextView) findViewById(R.id.silencedText);
silenced.setText(getString(R.string.alarm_alert_alert_silenced,
mDuration / 1000 * 60));
silenced.setVisibility(View.VISIBLE);
}
private void updateLayout() {
setContentView(R.layout.alarm_alert);
My alert_alarm.xml (Dialog).
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/root"
android:layout_width="327dp"
android:layout_height="295dp"
android:background="#drawable/alertbg"
android:gravity="center_horizontal"
android:orientation="vertical" >
<TextView
android:id="#+id/silencedText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingBottom="2dp"
android:paddingTop="2dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/ltgrey"
android:visibility="gone" />
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="230dp"
android:gravity="center_horizontal" >
<Button
android:id="#+id/snooze"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="25dp"
android:layout_marginTop="20dp"
android:background="#drawable/teesstt"
android:text="#string/snooze_button"
android:textColor="#fff"
android:textSize="25dp"
android:visibility="visible" />
<Button
android:id="#+id/dismiss"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="25dp"
android:layout_marginTop="20dp"
android:background="#drawable/teesstt"
android:text="#string/dismiss_button"
android:textColor="#fff"
android:textSize="25dp"
android:visibility="visible" />
</RelativeLayout>
<TextView
android:id="#+id/tvDD"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/tvDate"
android:layout_alignLeft="#+id/tvDate"
android:text="Medium Text"
android:textSize="20dp"
android:textColor="#a6a6a6" />
<TextView
android:id="#+id/tvDate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/relativeLayout1"
android:layout_alignParentLeft="true"
android:layout_marginBottom="55dp"
android:layout_marginLeft="30dp"
android:text="Medium Text"
android:textSize="25dp"
android:textColor="#a6a6a6" />
<com.boxclocks.android.alarmclock.dc
android:id="#+id/digitalClock1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="58dp"
android:text="DigitalClock"
android:textColor="#a6a6a6"
android:textSize="70dp" />
</RelativeLayout>
How do I remove the border.
dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
Dialog
You have two options. You can set the theme of your Activity to
Theme_Translucent_NoTitleBar
Or you have to create a new theme and load it with a custom nine patch as specified here
How to remove border from Dialog?

android RelativeLayout how to get smaller size window

I cannot get the Theme.Dialog activity to get smaller.
The problem is that i want half the hight only.
Look at the picture down below.
Here is the manifest:
<activity android:name=".PopUpSettings"
android:label="#string/app_name"
android:theme="#android:style/Theme.Dialog"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation">
here is the xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="15dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingBottom="15dp"
>
<com.hellberg.ptppservice.imageedit.ColorPicker
android:id="#+id/color_picker_popup_settings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
/>
<TextView android:id="#+id/exampeltext_popup_settings"
android:text = "This is the best app in the world"
android:textSize="20sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/color_picker_popup_settings"
/>
<Button android:id="#+id/fontleft_button_popup_settings"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
/>
<Button android:id="#+id/fontright_button_popup_settings"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
/>
<TextView android:id="#+id/textlogo_popup_settings"
android:text = "©2011"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
Here is the screen:
This will do what you want. Be aware that you'll get the full window height so dividing with 2 wont make it exactly half the size. I tried your layout dividing with 3 and it looks good.
public class DialogExampleActivity extends Activity {
private int mWindowHeight;
private static final int DIALOG_OPEN = 0;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Display display = getWindowManager().getDefaultDisplay();
mWindowHeight = display.getHeight();
showDialog(DIALOG_OPEN);
}
#Override
protected Dialog onCreateDialog(int id) {
Dialog myDialog = new Dialog(DialogExampleActivity.this);
switch (id) {
case DIALOG_OPEN:
myDialog.setContentView(R.layout.my_dialog);
myDialog.setCancelable(true);
RelativeLayout rr = (RelativeLayout) myDialog.findViewById(R.id.relative_layout);
LayoutParams params = rr.getLayoutParams();
params.height = mWindowHeight / 3;
rr.setLayoutParams(params);
return myDialog;
}
return null;
}
}

Categories

Resources