In android how to performm task one after another - android

In my program, the basic is:-
When the program open it will show an animation then it will show pie chart result.
my code is:---
public class Popup_animation11 extends Activity {
private static int[] COLORS = new int[] { Color.MAGENTA, Color.CYAN };
LinearLayout layout;
private CategorySeries mSeries = new CategorySeries("");
private DefaultRenderer mRenderer = new DefaultRenderer();
private GraphicalView mChartView;
Context ctx;
private TransparentProgressDialog pd;
private Handler h;
private Runnable r;
EditText name1,name2;
private int[] VALUES = { 40, 60 };
String x1,y1;
Button btnOpenPopup;
String[] NAME_LIST ;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.popup_main);
Button btnOpenPopup = (Button)findViewById(R.id.openpopup);
btnOpenPopup.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View arg0) {
pd.show();
}
});
h = new Handler();
pd = new TransparentProgressDialog(this, R.drawable.uktrafficlights);
r =new Runnable() {
#Override
public void run() {
if (pd.isShowing()) {
pd.dismiss();
}
}
};
}
#Override
protected void onDestroy() {
h.removeCallbacks(r);
if (pd.isShowing() ) {
pd.dismiss();
}
super.onDestroy();
}
private class TransparentProgressDialog extends Dialog {
private ImageView iv;
public TransparentProgressDialog(Context context, int resourceIdOfImage) {
super(context, R.style.TransparentProgressDialog);
WindowManager.LayoutParams wlmp = getWindow().getAttributes();
wlmp.gravity = Gravity.CENTER_HORIZONTAL;
getWindow().setAttributes(wlmp);
setTitle(null);
setCancelable(false);
setOnCancelListener(null);
LinearLayout layout = new LinearLayout(context);
layout.setOrientation(LinearLayout.VERTICAL);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
iv = new ImageView(context);
iv.setImageResource(resourceIdOfImage);
layout.addView(iv, params);
addContentView(layout, params);
}
#Override
public void show() {
super.show();
RotateAnimation anim = new RotateAnimation(0.0f, 360.0f , Animation.RELATIVE_TO_SELF, .5f, Animation.RELATIVE_TO_SELF, .5f);
anim.setInterpolator(new LinearInterpolator());
anim.setRepeatCount(Animation.INFINITE);
anim.setDuration(3000);
iv.setAnimation(anim);
iv.startAnimation(anim);
anim.setAnimationListener(new Animation.AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
//here display data
mRenderer.setApplyBackgroundColor(true);
mRenderer.setBackgroundColor(Color.argb(100, 50, 50, 50));
mRenderer.setChartTitleTextSize(20);
mRenderer.setLabelsTextSize(15);
mRenderer.setLegendTextSize(15);
mRenderer.setMargins(new int[] { 20, 30, 15, 0 });
mRenderer.setZoomButtonsVisible(true);
mRenderer.setStartAngle(90);
mChartView = ChartFactory.getPieChartView(ctx, mSeries, mRenderer);
LayoutInflater layoutInflater = (LayoutInflater)getBaseContext() .getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.main_piechart, null);
final PopupWindow popupWindow = new PopupWindow( popupView, LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
layout = (LinearLayout)popupView.findViewById(R.id.chart);
layout.addView(mChartView);
name1=(EditText) findViewById(R.id.ext1);
name2=(EditText) findViewById(R.id.ext2);
x1=name1.getText().toString();
y1=name2.getText().toString();
NAME_LIST = new String[] { x1 , y1 };
for (int i = 0; i < VALUES.length; i++) {
mSeries.add(NAME_LIST[i] + "(" + VALUES[i]+"%)", VALUES[i]);
SimpleSeriesRenderer renderer = new SimpleSeriesRenderer();
renderer.setColor(COLORS[(mSeries.getItemCount() - 1) % COLORS.length]);
mRenderer.addSeriesRenderer(renderer);
}
if (mChartView != null) {
mChartView.repaint();
}
Button btnDismiss = (Button)popupView.findViewById(R.id.dismiss);
btnDismiss.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View v) {
popupWindow.dismiss();
}});
popupWindow.showAsDropDown(btnOpenPopup, 50, -30);
}
#Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
});
}
}
}
But the problem is when I open the program, animation is running and running.the result is not coming.
I requirement was first animation then the result..But only animation is running.. Where is the problem in my code? thanks in advance
my edited code is:---
public class Popup_animation11 extends Activity {
private static int[] COLORS = new int[] { Color.MAGENTA, Color.CYAN };
LinearLayout layout;
private CategorySeries mSeries = new CategorySeries("");
private DefaultRenderer mRenderer = new DefaultRenderer();
private GraphicalView mChartView;
Context ctx;
private TransparentProgressDialog pd;
private Handler h;
private Runnable r;
EditText name1,name2;
private int[] VALUES = { 40,60 };
String x1,y1;
Button btnOpenPopup;
String[] NAME_LIST ;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.popup_main);
Button btnOpenPopup = (Button)findViewById(R.id.openpopup);
btnOpenPopup.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View arg0) {
pd.show();
}
});
h = new Handler();
pd = new TransparentProgressDialog(this, R.drawable.uktrafficlights);
r =new Runnable() {
#Override
public void run() {
if (pd.isShowing()) {
pd.dismiss();
}
}
};
}
#Override
protected void onDestroy() {
h.removeCallbacks(r);
if (pd.isShowing() ) {
pd.dismiss();
}
super.onDestroy();
}
private class TransparentProgressDialog extends Dialog {
private ImageView iv;
public TransparentProgressDialog(Context context, int resourceIdOfImage) {
super(context, R.style.TransparentProgressDialog);
WindowManager.LayoutParams wlmp = getWindow().getAttributes();
wlmp.gravity = Gravity.CENTER_HORIZONTAL;
getWindow().setAttributes(wlmp);
setTitle(null);
setCancelable(false);
setOnCancelListener(null);
LinearLayout layout = new LinearLayout(context);
layout.setOrientation(LinearLayout.VERTICAL);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
iv = new ImageView(context);
iv.setImageResource(resourceIdOfImage);
layout.addView(iv, params);
addContentView(layout, params);
}
#Override
public void show() {
super.show();
RotateAnimation anim = new RotateAnimation(0.0f, 360.0f , Animation.RELATIVE_TO_SELF, .5f, Animation.RELATIVE_TO_SELF, .5f);
anim.setInterpolator(new LinearInterpolator());
anim.setRepeatCount(Animation.INFINITE);
anim.setDuration(3000);
iv.setAnimation(anim);
iv.startAnimation(anim);
anim.setAnimationListener(new Animation.AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
//here display data
h.postDelayed(r, 100);
pd.dismiss();
mRenderer.setApplyBackgroundColor(true);
mRenderer.setBackgroundColor(Color.argb(100, 50, 50, 50));
mRenderer.setChartTitleTextSize(20);
mRenderer.setLabelsTextSize(15);
mRenderer.setLegendTextSize(15);
mRenderer.setMargins(new int[] { 20, 30, 15, 0 });
mRenderer.setZoomButtonsVisible(true);
mRenderer.setStartAngle(90);
mChartView = ChartFactory.getPieChartView(ctx, mSeries, mRenderer);
LayoutInflater layoutInflater = (LayoutInflater)getBaseContext() .getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.main_piechart, null);
final PopupWindow popupWindow = new PopupWindow( popupView, LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
layout = (LinearLayout)popupView.findViewById(R.id.chart);
layout.addView(mChartView);
name1=(EditText) findViewById(R.id.ext1);
name2=(EditText) findViewById(R.id.ext2);
x1=name1.getText().toString();
y1=name2.getText().toString();
NAME_LIST = new String[] { x1 , y1 };
for (int i = 0; i < VALUES.length; i++) {
mSeries.add(NAME_LIST[i] + "(" + VALUES[i]+"%)", VALUES[i]);
SimpleSeriesRenderer renderer = new SimpleSeriesRenderer();
renderer.setColor(COLORS[(mSeries.getItemCount() - 1) % COLORS.length]);
mRenderer.addSeriesRenderer(renderer);
}
if (mChartView != null) {
mChartView.repaint();
}
Button btnDismiss = (Button)popupView.findViewById(R.id.dismiss);
btnDismiss.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View v) {
popupWindow.dismiss();
}});
popupWindow.showAsDropDown(btnOpenPopup, 50, -30);
}
#Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
});
}
}
}

Try call anim.setAnimationListener() before call iv.startAnimation(anim);

Related

ViewOverlay Code is Removing Last View in Row

I am trying to animate a brick falling, and to create the brick I add rows to a TableLayout and then add buttons to each row. The issue I am having is that when I animate the brick falling, the last button in the row is removed, rather than the brick that was animated. Here is my code:
private void setGameBoard(){
brickWall.setClipChildren(false);
brickWall.setClipToPadding(false);
//Build game board
for(int ii = 0; ii < brickRows;ii++){
final int x = ii;
//Build table rows
row = new TableRow(this.getApplicationContext());
row.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT));
row.setClipChildren(false);
row.setClipToPadding(false);
// row.setBackgroundColor(ResourcesCompat.getColor(getResources(), R.color.colorAccent, null));
//Build table tiles
for(int jj=0; jj < brickColumns; jj++){
final int y = jj;
final Brick tile = new Brick(this);
tile.setBackgroundColor(ResourcesCompat.getColor(getResources(), R.color.colorPrimary, null));
//Set margins to create look of tic-tac-toe
TableRow.LayoutParams lp = new TableRow.LayoutParams(
BRICK_WIDTH, BRICK_HEIGHT);
lp.setMargins(0,0,0,0);
//lp.weight = 1;
tile.setLayoutParams(lp);
if(ii % 2 == 0){
tile.setBackground(ResourcesCompat.getDrawable(getResources(),R.drawable.brick02, null));
}else if(ii % 3 == 0){
tile.setBackground(ResourcesCompat.getDrawable(getResources(),R.drawable.brick03, null));
}else if(ii % 4 == 0){
tile.setBackground(ResourcesCompat.getDrawable(getResources(),R.drawable.brick04, null));
}else{
tile.setBackground(ResourcesCompat.getDrawable(getResources(),R.drawable.brick01, null));
}
tile.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(tile.getHits() == 0){
tile.setBackground(getResources().getDrawable(R.drawable.brick01_broken01));
tile.addHit();
} else if (tile.getHits() == 1){
tile.setBackground(getResources().getDrawable(R.drawable.brick01_broken02));
tile.addHit();
}else if(tile.getHits() == 2){
brokenBricks++;
float bottomOfScreen = getResources().getDisplayMetrics()
.heightPixels;
final ViewGroup vg = (ViewGroup) brickWall.getParent().getParent();
vg.getOverlay().add(tile);
ObjectAnimator anim = ObjectAnimator.ofFloat(tile, "translationY", brickWall.getHeight());
ObjectAnimator rotate = ObjectAnimator.ofFloat(tile, "rotation", 0, 360);
rotate.setRepeatCount(Animation.INFINITE);
rotate.setRepeatMode(ValueAnimator.REVERSE);
rotate.setDuration(350);
anim.setDuration(2000);
tile.setHapticFeedbackEnabled(true);
anim.addListener(new Animator.AnimatorListener() {
#Override
public void onAnimationStart(Animator arg0) {
}
#Override
public void onAnimationRepeat(Animator arg0) {
}
#Override
public void onAnimationEnd(Animator arg0) {
vg.getOverlay().remove(tile);
}
#Override
public void onAnimationCancel(Animator arg0) {
vg.getOverlay().remove(tile);
}
});
anim.setDuration(2000);
AnimatorSet set = new AnimatorSet();
set.playTogether(anim, rotate);
set.start();
//tile.setVisibility(View.INVISIBLE);
if(isRevealComplete()){
brickWall.setVisibility(View.INVISIBLE);
}
}
}
});
row.addView(tile);
}
brickWall.addView(row);
}
}
Any help would be appreciated.

android edittext can not fetch data

In my android program I am using achartengine library for showing a pie chart.
The basic of the program is I have an activity,where I have 2 edit text fields and a button.after fill up the edit text field ,when click the button it will show a popup window with piechart..
here,I am using NAME_LIST as a string type array. where value of edit text will store and after we can fetch..
the code is given below:---
public class AndroidPopupWindowActivity111_new extends Activity {
private static int[] COLORS = new int[] { Color.MAGENTA, Color.CYAN };
LinearLayout layout;
private CategorySeries mSeries = new CategorySeries("");
private DefaultRenderer mRenderer = new DefaultRenderer();
private GraphicalView mChartView;
EditText name1,name2;
private int[] VALUES = { 40,60 };
String x1,y1;
String[] NAME_LIST ;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.popup_main);
name1=(EditText) findViewById(R.id.ext1);
name2=(EditText) findViewById(R.id.ext2);
x1=name1.getText().toString();
y1=name2.getText().toString();
NAME_LIST = new String[] { x1 , y1 };
mRenderer.setApplyBackgroundColor(true);
mRenderer.setBackgroundColor(Color.argb(100, 50, 50, 50));
mRenderer.setChartTitleTextSize(20);
mRenderer.setLabelsTextSize(15);
mRenderer.setLegendTextSize(15);
mRenderer.setMargins(new int[] { 20, 30, 15, 0 });
mRenderer.setZoomButtonsVisible(true);
mRenderer.setStartAngle(90);
final Button btnOpenPopup = (Button)findViewById(R.id.openpopup);
mChartView = ChartFactory.getPieChartView(this, mSeries, mRenderer);
btnOpenPopup.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View arg0) {
LayoutInflater layoutInflater = (LayoutInflater)getBaseContext() .getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.main_piechart, null);
final PopupWindow popupWindow = new PopupWindow( popupView, LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
layout = (LinearLayout)popupView.findViewById(R.id.chart);
layout.addView(mChartView);
for (int i = 0; i < VALUES.length; i++) {
mSeries.add(NAME_LIST[i] + "(" + VALUES[i]+"%)", VALUES[i]);
SimpleSeriesRenderer renderer = new SimpleSeriesRenderer();
renderer.setColor(COLORS[(mSeries.getItemCount() - 1) % COLORS.length]);
mRenderer.addSeriesRenderer(renderer);
}
if (mChartView != null) {
mChartView.repaint();
}
Button btnDismiss = (Button)popupView.findViewById(R.id.dismiss);
btnDismiss.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View v) {
popupWindow.dismiss();
}});
popupWindow.showAsDropDown(btnOpenPopup, 50, -30);
}});
}
}
But the problem is the name is not fetching from edittext..I am giving an example what error is occuring.:--
Click the picture to know the problem...in this picture A,B,C,D is the edit text values..in my output A,B,C,D is showing as "null"
where is the problem??????????thanks in advance
When you're initializing
String[] NAME_LIST = new String[] { x1,y1 };
x1 and y1 are null. Changing the values of x1 and y1 later will not change the values in NAME_LIST.
Add the line
NAME_LIST = new String[] { x1,y1 };
just before the for loop in OnCreate(). It will work.
EDIT:
Move these five lines
name1=(EditText) findViewById(R.id.ext1);
name2=(EditText) findViewById(R.id.ext2);
x1=name1.getText().toString();
y1=name2.getText().toString();
NAME_LIST = new String[] { x1 , y1 };
into the onClick() method, just before the for loop begins.

Make an ImageView Visible with timer

I know that this question has been answered, but CountdownTimer doesn't work into my method.
So basically I have an animation for a button and a textview, after a button is clicked. But I want also to have an imageview, with a timer. Because imageview is a part of the textview that I want to show it to the user.
Any help?
This is my code:
onCreate method:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView2 = (ImageView)findViewById(R.id.imageView2);
edittext = (EditText)findViewById(R.id.edittext);
leatseatbutton = (Button)findViewById(R.id.letseatbutton);
register=(Button)findViewById(R.id.register);
signin1button=(Button)findViewById(R.id.signin1button);
signinbutton_fb=(Button)findViewById(R.id.signinbutton_fb);
cancel=(Button)findViewById(R.id.cancel);
imageView1 = (ImageView)findViewById(R.id.imageView1);
First onClickListener
leatseatbutton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.width = 175;
params.height = 40;
params.setMargins(75, 240, 0, 0);
leatseatbutton.setLayoutParams(params);
edittext.setVisibility(View.VISIBLE);
TranslateAnimation slide = new TranslateAnimation(0, 0, 100,0 );
slide.setDuration(1000);
slide.setFillAfter(true);
slide.setAnimationListener(new Animation.AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
imageView2.setVisibility(View.VISIBLE);
}
#Override
public void onAnimationRepeat(Animation animation) {
}
});
edittext.startAnimation(slide);
}
});
Second onClickListener
signinbutton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.width = 175;
params.height = 40;
params.setMargins(75, 240, 0, 0);
signinbutton.setLayoutParams(params);
edittext.setVisibility(View.VISIBLE);
TranslateAnimation slide = new TranslateAnimation(0, 0, 100,0 );
slide.setDuration(1000);
slide.setFillAfter(true);
edittext.startAnimation(slide);
}
});
}
Maybe you need use AnimationListener
....
TranslateAnimation slide = new TranslateAnimation(0, 0, 100,0 );
slide.setAnimationListener(new Animation.AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
imageview.setVisible(View.VISIBLE);
}
#Override
public void onAnimationRepeat(Animation animation) {
}
});
slide.setDuration(1000);
slide.setFillAfter(true);
edittext.startAnimation(slide);
....

switch between two surfaceView

I have two surfaceView, only one of them added to the view hierachy at a time, the other one is removed, my problem is, when an surfaceView added, there's a instant black rect cover it, can I avoid this?
here's the testing code:
public class MainActivity extends Activity {
private SurfaceView mSurfaceView;
private SurfaceView mSurfaceView1;
private SurfaceHolder.Callback mSurfaceCallback;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
View rv = this.getWindow().getDecorView();
final FrameLayout frameLayout = (FrameLayout) this.getWindow().getDecorView()
.findViewById(android.R.id.content);
final LinearLayout ll = new LinearLayout(this);
mSurfaceView = new SurfaceView(this);
mSurfaceView1= new SurfaceView(this);
mSurfaceCallback = new SurfaceHolder.Callback() {
#Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {}
#Override
public void surfaceCreated(SurfaceHolder holder) {
Canvas c = null;
try
{
c = holder.lockCanvas();
c.drawColor(Color.GREEN);
Paint p = new Paint();
p.setColor(Color.WHITE);
Rect r = new Rect(100, 50, 300, 250);
c.drawRect(r, p);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (c != null)
{
holder.unlockCanvasAndPost(c);
}
}
}
#Override
public void surfaceDestroyed(SurfaceHolder holder) {}
};
mSurfaceView.getHolder().addCallback(mSurfaceCallback);
mSurfaceView1.getHolder().addCallback(mSurfaceCallback);
Button b = new Button(this);b.setText("view1");
Button c = new Button(this);c.setText("view2");
b.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
try{
ll.addView(mSurfaceView);
ll.removeView(mSurfaceView1);
}catch(Exception e) {}
}
});
c.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
try{
ll.addView(mSurfaceView1);
ll.removeView(mSurfaceView);
}catch(Exception e) {}
}
});
ll.setOrientation(LinearLayout.VERTICAL);
ll.addView(b, new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
ll.addView(c, new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
frameLayout.addView(ll);
}
}
I think you can add the two surfaceviews when you call onCreate, and switch their status in onClick. like this:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
View rv = this.getWindow().getDecorView();
final FrameLayout frameLayout = (FrameLayout) this.getWindow().getDecorView()
.findViewById(android.R.id.content);
final LinearLayout ll = new LinearLayout(this);
mSurfaceView = new SurfaceView(this);
mSurfaceView1= new SurfaceView(this);
mSurfaceCallback = new SurfaceHolder.Callback() {
#Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {}
#Override
public void surfaceCreated(SurfaceHolder holder) {
Canvas c = null;
try
{
c = holder.lockCanvas();
c.drawColor(Color.GREEN);
Paint p = new Paint();
p.setColor(Color.WHITE);
Rect r = new Rect(100, 50, 300, 250);
c.drawRect(r, p);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (c != null)
{
holder.unlockCanvasAndPost(c);
}
}
}
#Override
public void surfaceDestroyed(SurfaceHolder holder) {}
};
mSurfaceView.getHolder().addCallback(mSurfaceCallback);
mSurfaceView1.getHolder().addCallback(mSurfaceCallback);
Button b = new Button(this);b.setText("view1");
Button c = new Button(this);c.setText("view2");
b.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
try{
// ll.addView(mSurfaceView);
// ll.removeView(mSurfaceView1);
mSurfaceView.setVisibility(View.VISIBLE);
mSurfaceView1.setVisibility(View.INVISIBLE);
}catch(Exception e) {}
}
});
c.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
try{
// ll.addView(mSurfaceView1);
// ll.removeView(mSurfaceView);
mSurfaceView1.setVisibility(View.VISIBLE);
mSurfaceView.setVisibility(View.INVISIBLE);
}catch(Exception e) {}
}
});
ll.setOrientation(LinearLayout.VERTICAL);
ll.addView(b, new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
ll.addView(c, new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
// add mSurfaceView & mSurfaceView1
ll.addView(mSurfaceView);
ll.addView(mSurfaceView1);
mSurfaceView.setVisibility(View.INVISIBLE);
mSurfaceView1.setVisibility(View.INVISIBLE);
frameLayout.addView(ll);
}

Several questions to AChartEngine

I am new to AchartEngine. I am using AchartEngine with android to create a Barchart. I have looked at the aChartEngine API and have created a Barchart, its working fine.
When I want to see my actual view I have to decrease the zoom rate by clicking zoom button which is in right bottom. I need to show a compleate Barchart what I exactly declared in my program with out using zoom button.
I need to navigate from one view to another. So, I created one graphical view with ontouchlistner, but it shows error.
Any ideas would be greatly appreciated. Am I missing something here?
public class GraphicViewExample extends Activity {
private String[] mMonth = new String[] { "Jan", "Feb", "Mar", "Apr", "May",
"Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
int[] x = { 0, 1, 2, 3, 4, 5, 6, 7 };
int[] income = { 2000, 2500, 2700, 3000, 2800, 3500, 3700, 3800 };
public static final String TYPE = "type";
private XYMultipleSeriesDataset mDataset = getDemoDataset();
private XYMultipleSeriesRenderer mRenderer = getDemoRenderer();
private GraphicalView mChartView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.graphicviewexample);
if (mChartView == null) {
LinearLayout layout = (LinearLayout) findViewById(R.id.chart);
mChartView = ChartFactory.getBarChartView(this, mDataset,
mRenderer, Type.DEFAULT);
mRenderer.setSelectableBuffer(100);
layout.addView(mChartView, new LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
} else {
mChartView.repaint();
}
mChartView.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
#SuppressWarnings("unused")
/*SeriesSelection seriesSelection = mChartView
.getCurrentSeriesAndPoint();*/
SimpleSeriesRenderer r = new SimpleSeriesRenderer();
mRenderer.removeAllRenderers();
r.setColor(Color.RED);
mChartView.repaint();
return true;
}
});
/*mChartView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
* LinearLayout slayout = (LinearLayout)
* findViewById(R.id.chart); ChartView =
* ChartFactory.getBarChartView( getApplicationContext(),
* sDataset, smRenderer, Type.DEFAULT);
* slayout.addView(ChartView, new LayoutParams(
* LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
*
* ChartView.repaint();
mChartView.repaint();
}
});*/
}
private XYMultipleSeriesDataset getDemoDataset() {
XYSeries incomeSeries = new XYSeries("Income");
for (int i = 0; i < x.length; i++) {
incomeSeries.add(i, income[i]);
}
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
dataset.addSeries(incomeSeries);
return dataset;
}
private XYMultipleSeriesRenderer getDemoRenderer() {
XYSeriesRenderer incomeRenderer = new XYSeriesRenderer();
incomeRenderer.setColor(Color.rgb(130, 130, 230));
incomeRenderer.setFillPoints(true);
incomeRenderer.setLineWidth(2);
incomeRenderer.setDisplayChartValues(true);
XYMultipleSeriesRenderer multiRenderer = new XYMultipleSeriesRenderer();
multiRenderer.setXLabels(0);
multiRenderer.setBarSpacing(0.3f);
multiRenderer.setBarWidth(30);
multiRenderer.setChartTitle("Income Chart");
multiRenderer.setXTitle("Year 2013");
multiRenderer.setYTitle("Amount in Dollars");
//multiRenderer.setZoomLimits(1.0,0.7,1.0,3000.0);
multiRenderer.setZoomButtonsVisible(true);
//multiRenderer.setZoomEnabled(true, true);
//multiRenderer.setPanEnabled(true, true);
multiRenderer.setInScroll(true);
multiRenderer.setXAxisMin(0);
multiRenderer.setXAxisMax(7);
multiRenderer.setYAxisMin(0);
multiRenderer.setYAxisMax(4000);
multiRenderer.setClickEnabled(true);
multiRenderer.setShowGridX(true);
for (int i = 0; i < x.length; i++) {
multiRenderer.addXTextLabel(i, mMonth[i]);
}
multiRenderer.addSeriesRenderer(incomeRenderer);
return multiRenderer;
}
}
Logs:
java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
at org.achartengine.renderer.DefaultRenderer.getSeriesRendererAt(DefaultRenderer.java:189)
at org.achartengine.chart.XYChart.draw(XYChart.java:240)
at org.achartengine.GraphicalView.onDraw(GraphicalView.java:168)
This code works for my line graph,
v.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
SeriesSelection seriesSelection = ((GraphicalView) v)
.getCurrentSeriesAndPoint();
Log.d("sreedhu", String.valueOf(seriesSelection));
if (seriesSelection == null) {
Log.d("sreedhu", "Nothing Selected");
} else {
//your code}
}
}
use this codes to zoom your barchart...!
renderer.setScale((float) 1);

Categories

Resources