How to set header layout in video view - android

I'm working in video view that contain title layout. I have attached the header layout in video view. what is my problem is when i touch on video view both title layou and mediacontolls should shown, After some time both(title layou and media controls) should disappear. Simply whenever the media controlls show the title layou should show , then whenever media controlls disapper the title layou should disapper.
XML CODE
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:background="#000">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="match_parent">
<VideoView
android:id="#+id/playerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_centerInParent="true"
android:layout_gravity="center_vertical" />
<LinearLayout
android:id="#+id/share_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:padding="10dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginBottom="80dp"
android:orientation="horizontal">
<ImageButton
android:id="#+id/twitter_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/twitter"
android:paddingTop="20dp"
android:paddingRight="10dp"
android:background="#android:color/transparent" />
<ImageButton
android:id="#+id/facebook_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/facebook"
android:paddingRight="10dp"
android:layout_below="#+id/twitter_button"
android:background="#android:color/transparent"
android:paddingTop="20dp"/>
<ImageButton
android:visibility="gone"
android:id="#+id/share_Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/share_icon"
android:background="#android:color/transparent"
android:paddingTop="20dp"
android:layout_below="#+id/facebook_button"/>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/header_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#BF000000"
android:padding="10dp">
<ImageButton
android:id="#+id/imageBtnclose"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/close_button"
android:background="#android:color/transparent" />
<TextView
android:id="#+id/videoTitletv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical"
android:text="video title"
android:textColor="#ffffff"
android:paddingLeft="10dp"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/imageBtnclose"
android:layout_toEndOf="#+id/imageBtnclose" />
</RelativeLayout>
JAVA CODE
public class VideoAdPlayer extends Activity {
// private boolean vbBackkeyPressed = false;
private VideoView myVideoView;
private RelativeLayout myLinearClose;
LinearLayout shareLayout;
private ProgressDialog progressDialog;
private MediaController mediaControls;
private int adshowTime = 30;
Timer mTimer = new Timer();
boolean MidrollPlayed = false;
YuMeInterface yumeInterface;
ImageButton imgCloseBtn;
boolean isPortrait = true;
ImageButton faceBookButton, twitterButton, shareButton;
public static VideoAdPlayer playerActivity = null;
public static Context playerContext = null;
public static int playedAdType = 1;
public static boolean isActivityrun = false;
boolean isPrerollAds;
boolean isPostrollAds;
boolean isMidrollAds;
boolean isShareClicked = false;
#SuppressLint("ClickableViewAccessibility")
#SuppressWarnings("deprecation")
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String myString = android.os.Build.VERSION.RELEASE;
System.out.println(myString);
setContentView(R.layout.video);
Intent intent = getIntent();
String playVideoUrl = "";
String videoThumb = "";
getActionBar().hide();
playerActivity = this;
playerContext = this.getApplicationContext();
myLinearClose = (RelativeLayout) findViewById(R.id.header_layout);
shareLayout = (LinearLayout) findViewById(R.id.share_layout);
TextView videoTxtview = (TextView)findViewById(R.id.videoTitletv);
faceBookButton = (ImageButton) findViewById(R.id.facebook_button);
twitterButton = (ImageButton) findViewById(R.id.twitter_button);
shareButton = (ImageButton) findViewById(R.id.share_Button);
shareLayout.setOrientation(LinearLayout.HORIZONTAL);
videoTxtview.setText("DEFAULT TITLE");
if (mediaControls == null) {
mediaControls = new MediaController(VideoAdPlayer.this);
}
myVideoView = (VideoView) findViewById(R.id.playerview);
imgCloseBtn = (ImageButton) findViewById(R.id.imageBtnclose);
progressDialog = createProgressDialog(VideoAdPlayer.this);
progressDialog.show();
imgCloseBtn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
JSONObject msgPlayer = new JSONObject();
try {
msgPlayer.put("finished", false);
YumeIntegration.callbackContext.success(msgPlayer);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finish();
}
});
try {
myVideoView.setVideoURI(Uri.parse(playVideoUrl));
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
myVideoView.requestFocus();
myVideoView.setZOrderOnTop(false);
playedAdType = 1;
myVideoView.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
if (!myLinearClose.isShown()) {
if (!isPortrait) {
myLinearClose.setVisibility(View.VISIBLE);
}
myLinearClose.postDelayed(new Runnable() {
#Override
public void run() {
if (!isPortrait) {
myLinearClose.setVisibility(View.INVISIBLE);
}
}
}, 3000);
} else {
if (myLinearClose.isShown()) {
if (!isPortrait) {
myLinearClose.setVisibility(View.INVISIBLE);
}
}
}
return false;
}
});
myVideoView.setMediaController(mediaControls);
myVideoView.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(final MediaPlayer mediaPlayer) {
progressDialog.dismiss();
myLinearClose.setVisibility(View.VISIBLE);
int duration = myVideoView.getDuration();
Log.e("total duration", String.valueOf(duration));
final int totalSeconds = duration / 1000;
final int postrollads = totalSeconds - 25;
final int MidrollAdsShows = totalSeconds / 2;
Log.e("total durationin secods", String.valueOf(totalSeconds));
try {
mTimer.scheduleAtFixedRate(new TimerTask() {
#Override
public void run() {
int currentTime = myVideoView.getCurrentPosition() / 1000;
/*
* if (currentTime > postrollads &&
* !postRolladsInit) { postRolladsInit = true; try {
* yumeInterface.updatesSdkParams(3); } catch
* (YuMeException e) { e.printStackTrace(); }
*
* } */
if (currentTime > MidrollAdsShows && !MidrollPlayed) {
adshowTime += 30;
MidrollPlayed = true;
playedAdType = 2;
if (isMidrollAds) {
if (yumeInterface.sdkIsAdAvailable()) {
myVideoView.pause();
final Intent mainIntent = new Intent(VideoAdPlayer.this, AdView.class);
startActivityForResult(mainIntent, 3);
}
}
}
}
}, 0, 2000);
if (!mediaControls.isShowing()) {
mediaControls.show();
Toast.makeText(VideoAdPlayer.this,"YES",Toast.LENGTH_SHORT).show();
}
myLinearClose.setVisibility(View.VISIBLE);
myLinearClose.postDelayed(new Runnable() {
#Override
public void run() {
// TODO Auto-generated method stub
if (!isPortrait){
myLinearClose.setVisibility(View.INVISIBLE);
}
}
}, 3000);
} catch (Exception ex) {
}
}
});
myVideoView.setOnCompletionListener(new OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer mp) {
mTimer.cancel();
JSONObject msgPlayer = new JSONObject();
try {
msgPlayer.put("finished", true);
YumeIntegration.callbackContext.success(msgPlayer);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
playedAdType = 3;
// finish();
if (isPostrollAds) {
if (yumeInterface.sdkIsAdAvailable()) {
final Intent mainIntent = new Intent(VideoAdPlayer.this, AdView.class);
startActivityForResult(mainIntent, 3);
} else {
finish();
}
} else {
finish();
}
}
});
public static ProgressDialog createProgressDialog(Context mContext) {
ProgressDialog dialog = new ProgressDialog(mContext);
try {
dialog.show();
} catch (BadTokenException e) {
}
dialog.setCancelable(false);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
dialog.setContentView(R.layout.progressdialog);
// dialog.setMessage(Message);
return dialog;
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// check if the request code is same as what is passed here it is 3
if (requestCode == 3) {
myVideoView.requestFocus();
myVideoView.start();
myVideoView.setZOrderOnTop(false);
}
}
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
myLinearClose.setVisibility(View.VISIBLE);
shareLayout.setOrientation(LinearLayout.VERTICAL);
myVideoView.requestFocus();
isPortrait = false;
landscapeMode();
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
shareLayout.setOrientation(LinearLayout.HORIZONTAL);
myVideoView.requestFocus();
isPortrait = true;
myLinearClose.setVisibility(View.VISIBLE);
portraitMode();
}
}
private void portraitMode() {
isPortrait = true;
faceBookButton.setVisibility(View.VISIBLE);
twitterButton.setVisibility(View.VISIBLE);
shareButton.setVisibility(View.VISIBLE);
shareButton.setVisibility(View.GONE);
if (!mediaControls.isShowing()) {
mediaControls.show();
Toast.makeText(VideoAdPlayer.this, "YES", Toast.LENGTH_SHORT).show();
}
myLinearClose.setVisibility(View.VISIBLE);
myLinearClose.postDelayed(new Runnable() {
#Override
public void run() {
// TODO Auto-generated method stub
if (!isPortrait) {
myLinearClose.setVisibility(View.INVISIBLE);
}
}
}, 3000);
}
private void landscapeMode() {
isPortrait = false;
if (!mediaControls.isShowing()) {
mediaControls.show();
Toast.makeText(VideoAdPlayer.this, "YES", Toast.LENGTH_SHORT).show();
}
myLinearClose.setVisibility(View.VISIBLE);
myLinearClose.postDelayed(new Runnable() {
#Override
public void run() {
// TODO Auto-generated method stub
if (!isPortrait) {
myLinearClose.setVisibility(View.INVISIBLE);
}
}
}, 3000);
faceBookButton.setVisibility(View.GONE);
twitterButton.setVisibility(View.GONE);
shareButton.setVisibility(View.VISIBLE);
shareButton.setVisibility(View.VISIBLE);
shareButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if (!isPortrait) {
if (!isShareClicked) {
isShareClicked = true;
faceBookButton.setVisibility(View.GONE);
twitterButton.setVisibility(View.GONE);
} else {
isShareClicked = false;
faceBookButton.setVisibility(View.VISIBLE);
twitterButton.setVisibility(View.VISIBLE);
}
}
}
});
}

Related

How to automate Seekbar movement with a song in Android?

I know similar questions have been asked before but none of them could solve my problem. I'm making a music player and wish to automate the Seekbarwhen a song is played. I'm using a RecyclerViewand the following snippet exists in the onBindViewHolder section.
public class ListViewPopulator extends
RecyclerView.Adapter<ListViewPopulator.ViewHolder>{
List<String> musicName;
List<String> musicAdd;
Context context;
MediaPlayer mediaPlayer;
Button media_play;
Button media_stop;
SeekBar seekBar;
final Handler mhandler=new Handler();
TextView timer;
public ListViewPopulator(Activity context, List<String> musicName, List<String> musicAdd)
{
this.context=context;
this.musicName=musicName;
this.musicAdd=musicAdd;
media_play= (Button)context.findViewById(R.id.play);
media_stop=(Button)context.findViewById(R.id.pause);
seekBar= (SeekBar) context.findViewById(R.id.seekbar);
timer=(TextView) context.findViewById(R.id.timer);
}
#Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(context).inflate(R.layout.listview,parent,false);
return new ViewHolder(v);
}
void something(String s)
{
try{mediaPlayer.stop();}catch (NullPointerException e){e.printStackTrace();}
//To fetch the location of audio files on disk
mediaPlayer=MediaPlayer.create(context, Uri.fromFile(new File(s)));
mediaPlayer.start();
//seekBar.setProgress(0);
//seekBar.setMax(mediaPlayer.getDuration());
} int temp=0;
int i=0;
#Override
public void onBindViewHolder(ViewHolder holder, final int position) {
final String s = musicAdd.get(position);
final String v = musicName.get(position);
holder.data.setText(v);
seeker();
cont_seek();
holder.itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
temp = position + 1;
something(s);
seekBar.setProgress(0);
seekBar.setMax(mediaPlayer.getDuration());
// mediaPlayer.reset();
change();
op();
}
});
media_play.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
try {
mediaPlayer.start();
Log.d("click", "Kuch bhi");
} catch (NullPointerException e) {
e.printStackTrace();
}
}
});
media_stop.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
try {
mediaPlayer.pause();
Log.d("click2", "Kuch bhi2");
} catch (NullPointerException e) {
e.printStackTrace();
}
}
});
}
void cont_seek(){
Log.d("auto","seek");
Runnable runnable=new Runnable() {
#Override
public void run() {
String time;
if((mediaPlayer != null) && mediaPlayer.isPlaying()){
int progress = mediaPlayer.getCurrentPosition();
int min = (progress / 1000) / 60;
Log.d("auto","seek");
int sec = (progress / 1000) % 60;
if (sec < 10)
time = "0" + sec;
else
time = "" + sec;
String elapsedTime = min + ":" + time + "";
timer.setText(elapsedTime);
seekBar.setMax(mediaPlayer.getDuration());
seekBar.setProgress(progress);
mhandler.postDelayed(this, 1000);
}
}
};
mhandler.postDelayed(runnable,1000);
}
void seeker(){
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
int seek_progress;
String time_sec;
#Override
public void onProgressChanged(final SeekBar seekBar, int progress, boolean fromUser) {
seek_progress=progress;
//seek_progress=seek_progress*1000;
new Runnable() {
#Override
public void run() {
int min=(seek_progress/1000)/60;
int sec=(seek_progress/1000)%60;
if(sec<10)
time_sec="0"+sec;
else
time_sec=""+sec;
String elapsedTime=min+":"+time_sec+"";
timer.setText(elapsedTime);
//mediaPlayer.seekTo(seek_progress);
new Handler().postDelayed(this,1000);
}
}.run();
if(fromUser) {
Log.d("blah","blah");
new Runnable() {
#Override
public void run() {
int min=(seek_progress/1000)/60;
int sec=(seek_progress/1000)%60;
if(sec<10)
time_sec="0"+sec;
else
time_sec=""+sec;
String elapsedTime=min+":"+time_sec+"";
timer.setText(elapsedTime);
//mediaPlayer.seekTo(seek_progress);
new Handler().postDelayed(this,1000);
}
}.run();
}
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
if(mediaPlayer!=null){mediaPlayer.seekTo(seek_progress);}
}
});
}
int h=0;
void change(){
try{mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer mp) {
if(temp!=musicAdd.size())
something(musicAdd.get(temp));
temp=temp+1;
seekBar.setProgress(0);
seekBar.setMax(mediaPlayer.getDuration());
change();
}
});
}catch(Throwable throwable){throwable.printStackTrace();}}
void op()
{
Sensey.getInstance().startFlipDetection(new FlipDetector.FlipListener() {
#Override
public void onFaceUp() {
if (i == 0) {
try {
mediaPlayer.start();
i = 1;
h=1;
}catch (NullPointerException e){e.printStackTrace();}
}
}
#Override
public void onFaceDown() {
if (i == 1) {
try {
mediaPlayer.pause();
i = 0;
h=0;
}catch (NullPointerException e){e.printStackTrace();}
}
}
});
Sensey.getInstance().startShakeDetection(15, new ShakeDetector.ShakeListener() {
#Override
public void onShakeDetected() {
try {
if(h==1)
something(musicAdd.get(randomG(musicAdd.size()-1,0)));
}catch (Throwable throwable)
{
throwable.printStackTrace();
}
}
});
}
int randomG(int max,int min)
{
Random random=new Random();
return random.nextInt((max-min)+1);
}
#Override
public int getItemCount() {
return musicName.size();
}
public class ViewHolder extends RecyclerView.ViewHolder
{
TextView data;
public ViewHolder(View itemView) {
super(itemView);
data=(TextView)itemView.findViewById(R.id.data);
}
}
}
I am pretty sure the logic is right and have checked the Log, the code doesn't seem to be executing. Can somebody explain why?
In your recycler view adapter you can use something like this:
#Override
public VoiceViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return VoiceViewHolder.createVoiceViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.lecture_voice_item_recycler, parent, false));
}
#Override
public void onBindViewHolder(VoiceViewHolder holder, int position) {
holder.bindHolderToVoice(10000, "your path");
}
public static class VoiceViewHolder extends RecyclerView.ViewHolder {
CardView cardView;
TextView voiceDuration;
ImageView voiceView;
ImageButton mPlayButton;
MediaPlayer mPlayer;
RelativeLayout layoutVoice;
RelativeLayout layoutVoiceNotFound;
boolean isPlaying;
TextView voiceDurationPlayer;
double timeElapsed = 0, finalTime = 0;
Handler durationHandler = new Handler();
Runnable updateSeekBarTime;
SeekBar seekBarDuration;
private VoiceViewHolder(final View itemView) {
super(itemView);
}
public static VoiceViewHolder createVoiceViewHolder(View convertView) {
VoiceViewHolder holder = new VoiceViewHolder(convertView);
holder.voiceDuration = (TextView) convertView.findViewById(R.id.voice_duration);
holder.cardView = (CardView) convertView.findViewById(R.id.card_view);
holder.voiceView = (ImageView) convertView.findViewById(R.id.voiceView);
holder.mPlayButton = (ImageButton) convertView.findViewById(R.id.playButton);
holder.layoutVoice = (RelativeLayout) convertView.findViewById(R.id.layoutVoice);
holder.layoutVoiceNotFound = (RelativeLayout) convertView.findViewById(R.id.layoutVoiceNotFound);
holder.voiceDurationPlayer = (TextView) convertView.findViewById(R.id.voiceDurationPlayer);
holder.seekBarDuration = (SeekBar) convertView.findViewById(R.id.seekBarDuration);
holder.isPlaying = false;
holder.mPlayer = new MediaPlayer();
return holder;
}
public void bindHolderToVoice(final long duration, final String path) {
final Context context = itemView.getContext();
if (duration >= 60000) {
voiceDuration.setText(String.format("%d %s, %d %s", TimeUnit.MILLISECONDS.toMinutes(duration), context.getString(R.string.min),
TimeUnit.MILLISECONDS.toSeconds(duration) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(duration)),
context.getString(R.string.sec)));
} else {
voiceDuration.setText(String.format("%d %s",
TimeUnit.MILLISECONDS.toSeconds(duration) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(duration)),
context.getString(R.string.sec)));
}
finalTime = duration;
seekBarDuration.setMax((int) finalTime);
seekBarDuration.setClickable(false);
seekBarDuration.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
if (mPlayer.isPlaying()) {
SeekBar sb = (SeekBar) v;
mPlayer.seekTo(sb.getProgress());
}
return false;
}
});
updateSeekBarTime = new Runnable() {
public void run() {
if (mPlayer != null) {
if (mPlayer.isPlaying()) {
timeElapsed = mPlayer.getCurrentPosition();
seekBarDuration.setProgress((int) timeElapsed);
voiceDurationPlayer.setText(String.format("%02d:%02d", TimeUnit.MILLISECONDS.toMinutes((long) timeElapsed), TimeUnit.MILLISECONDS.toSeconds((long) timeElapsed) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes((long) timeElapsed))));
durationHandler.postDelayed(this, 100);
} else {
mPlayer.pause();
isPlaying = false;
}
}
}
};
File voiceFile = new File(path);
mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer mp) {
isPlaying = false;
}
});
mPlayButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (!isPlaying) {
isPlaying = true;
try {
mPlayer = new MediaPlayer();
mPlayer.setDataSource(path);
mPlayer.prepare();
} catch (IOException e) {
Log.e("tag", "Start playing prepare() failed");
isPlaying = false;
}
mPlayer.start();
timeElapsed = mPlayer.getCurrentPosition();
seekBarDuration.setProgress((int) timeElapsed);
durationHandler.postDelayed(updateSeekBarTime, 100);
} else {
isPlaying = false;
mPlayer.pause();
}
}
});
}
}
The layout lecture_voice_item_recycler.xml is something like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/lecture_voice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/lecture_voice__margin_card">
<android.support.v7.widget.CardView
android:id="#+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/lecture_voice__margin_card"
android:clickable="true"
android:foreground="?android:attr/selectableItemBackground">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/lecture_voice__margin_card"
android:layout_marginBottom="#dimen/lecture_voice__margin_card">
<LinearLayout
android:id="#+id/layoutVoiceInfo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/grid_annotation_margin"
android:orientation="horizontal">
<TextView
android:id="#+id/voice_duration"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<RelativeLayout
android:id="#+id/layoutVoice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/layoutVoiceInfo"
android:gravity="center_vertical"
android:layout_marginLeft="#dimen/activity_horizontal_margin">
<ImageButton
android:id="#+id/playButton"
android:layout_width="#dimen/lecture_voice_icon"
android:layout_height="#dimen/lecture_voice_icon"
android:background="#android:color/transparent"
android:scaleType="fitXY"
android:src="#drawable/ic_play" />
<LinearLayout
android:id="#+id/layoutVoiceSeekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_toRightOf="#+id/playButton"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginTop="#dimen/activity_horizontal_margin">
<SeekBar
android:id="#+id/seekBarDuration"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin" />
<TextView
android:id="#+id/voiceDurationPlayer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00:00"
android:layout_gravity="right"
android:layout_marginRight="#dimen/lecture_voice_text_duration_margin_right"/>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/layoutVoiceNotFound"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/layoutVoiceInfo"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:visibility="gone">
<ImageView
android:id="#+id/voiceView"
android:layout_width="#dimen/lecture_voice_icon"
android:layout_height="#dimen/lecture_voice_icon"
android:src="#drawable/voice_not_found"
android:scaleType="fitXY" />
<TextView
android:id="#+id/voiceNotFound"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/voiceView"
android:layout_centerInParent="true"
android:text="#string/voice_not_found"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
strings.xml
<string name="min">min</string>
<string name="sec">sec</string>
Note: some dimensions or drawables could be lost in the example. You should use your own dimension if no compile.
You need to use your Handler & Runnable as follows:
final Handler handler = new Handler();
final Runnable r = new Runnable() {
public void run() {
//YOUR CODE GOES HERE
handler.postDelayed(this, 1000);
}
};
handler.postDelayed(r, 0);
Found a solution for this.
Runnable runnable=new Runnable() {
#Override
public void run() {
String time;
Log.d(TAG, "run");
while(mediaPlayer != null && mediaPlayer.isPlaying()){
final int progress = mediaPlayer.getCurrentPosition();
int min = (progress / 1000) / 60;
Log.d("auto","seek");
int sec = (progress / 1000) % 60;
if (sec < 10)
time = "0" + sec;
else
time = "" + sec;
final String elapsedTime = min + ":" + time + "";
context.runOnUiThread(new Runnable() {
#Override
public void run() {
timer.setText(elapsedTime);
seekBar.setMax(mediaPlayer.getDuration());
seekBar.setProgress(progress);
}
});
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
};
new Thread(runnable).start();
The main problem here is that once mediaplayer.start() is called the media file begins loading in the player before that completes the cont_seek function is called which has the condition
if(mediaplayer!=null && mediaplayer.isplaying())
Since the media hasn't started playing yet, the condition fails and the function is never executed.
Fixed it by running the runnable in a different thread.

why display black background between two layouts

I have radio app stream, and when open this app, first its open splash layout like this :
splash.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/loading" />
<ProgressBar
android:id="#+id/progressBar1"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.67" />
</LinearLayout>
and class for it like :
StartPoint.java
public class StartPoint extends Activity{
ProgressBar progressBar;
private int progressBarStatus = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
progressBar = (ProgressBar)findViewById(R.id.progressBar1);
Thread timer = new Thread(){
public void run(){
try{
sleep(5000);
while(progressBarStatus < 5000){
StartPoint.this.runOnUiThread(new Runnable(){
public void run()
{
progressBar.setProgress(progressBarStatus);
progressBarStatus += 1000;
}
});
}
}catch(InterruptedException e){
e.printStackTrace();
}finally{
Intent openMainList = new Intent(StartPoint.this,
com.example.kam.MainActivity.class);
startActivity(openMainList);
}
}
};
timer.start();
}
#Override
protected void onStop(){
super.onStop();
finish();
}
}
this class when finished, its call MainActivity.java class, and its show :
MainActivity.java
public class MainActivity extends Activity implements OnClickListener {
// Define ..............................................................
private static ProgressDialog progressDialog;
public MediaPlayer mp;
boolean isPrepared = false;
Button PlayBtn, ExitBtn, PauseBtn, RefreshBtn;
String MEDIA_PATH;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
progressDialog = ProgressDialog.show(MainActivity.this, "",
"Buffering Radio...", true);
progressDialog.setCancelable(false);
// Declare
// ..............................................................
mp = new MediaPlayer();
PlayBtn = (Button) findViewById(R.id.btnPlay);
PlayBtn.setOnClickListener(this);
PauseBtn = (Button) findViewById(R.id.btnPause);
PauseBtn.setOnClickListener(this);
RefreshBtn = (Button) findViewById(R.id.btnRefresh);
RefreshBtn.setOnClickListener(this);
ExitBtn = (Button) findViewById(R.id.btnExit);
ExitBtn.setOnClickListener(this);
MEDIA_PATH = "http://radio.arabhosters.com:8015/";
// Volume Control
// ..............................................................
final AudioManager leftAm = (AudioManager)
getSystemService(Context.AUDIO_SERVICE);
int maxVolume = leftAm.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
int curVolume = leftAm.getStreamVolume(AudioManager.STREAM_MUSIC);
SeekBar volControl = (SeekBar) findViewById(R.id.volumebar);
volControl.setMax(maxVolume);
volControl.setProgress(curVolume);
volControl.setOnSeekBarChangeListener
(new SeekBar.OnSeekBarChangeListener() {
#Override
public void onStopTrackingTouch(SeekBar arg0) {
// TODO Auto-generated method stub
}
#Override
public void onStartTrackingTouch(SeekBar arg0) {
// TODO Auto-generated method stub
}
#Override
public void onProgressChanged
(SeekBar arg0, int arg1, boolean arg2) {
// TODO Auto-generated method stub
leftAm.setStreamVolume(AudioManager.STREAM_MUSIC, arg1, 0);
}
});
}
#Override
public void onClick(View v) {
if (v == PlayBtn) {
startradio();
}
else if (v == PauseBtn) {
pauseradio();
}
else if (v == ExitBtn) {
exitradio();
}
else if (v == RefreshBtn) {
try {
refreshradio();
}
catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public void onCompletion(MediaPlayer mediaPlayer) {
synchronized (this) {
isPrepared = false;
}
}
protected void onResume() {
super.onResume();
try {
mp.setDataSource(MEDIA_PATH);
}
catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
mp.prepare();
}
catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} // also consider mp.prepareAsync().
// defult start stream when start App.
mp.start();
mp.setVolume(100, 100);
progressDialog.dismiss();
}
// method for play stream after stop it.
public void startradio() {
try {
if (mp.isPlaying()) {
return;
}
mp.start();
progressDialog.dismiss();
}
catch (IllegalStateException ex) {
ex.printStackTrace();
}
}
// method for Refresh stream.
public void refreshradio() throws IllegalArgumentException,
SecurityException, IOException {
try {
if (mp.isPlaying()) {
return;
}
mp.reset();
mp.setDataSource(MEDIA_PATH);
mp.prepare();
mp.start();
progressDialog.dismiss();
}
catch (IllegalStateException ex) {
ex.printStackTrace();
}
}
// method for pause stream.
public void pauseradio() {
mp.pause();
}
// method for check is radio paly or not stream
public boolean isPlaying() {
return mp.isPlaying();
}
// method for Looping audio if your record it - Soon :)
public boolean isLooping() {
return mp.isLooping();
}
// method for Looping audio if your record it - Soon :)
public void setLooping(boolean isLooping) {
mp.setLooping(isLooping);
}
// method for volume
public void setVolume(float volumeLeft, float volumeRight) {
mp.setVolume(volumeLeft, volumeRight);
}
// method for stop stream.
public void stopradio() {
if (mp.isPlaying()) {
mp.stop();
}
mp.release();
}
// method for exit.
public void exitradio() {
finish();
System.exit(0);
}
// method for back to main menu "Home".
public void backtomenu() {
finish();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
and layout for it like :
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/screen"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/bg">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:orientation="vertical"
>
<LinearLayout
android:layout_weight="6"
android:orientation="vertical"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_width="fill_parent"
android:layout_height="0dip" >
</LinearLayout>
<LinearLayout
android:id="#+id/buttons"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_alignParentLeft="true"
android:layout_weight="0.62"
android:background="#drawable/iconbgrepate"
android:gravity="center"
android:orientation="horizontal"
android:tileMode="repeat"
android:weightSum="5"
android:alpha=".75">
<SeekBar
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/volumebar"
android:max="100"
android:paddingBottom="10dip"/>
</LinearLayout>
<LinearLayout
android:id="#+id/buttons"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_alignParentLeft="true"
android:layout_weight="0.62"
android:background="#drawable/iconbgrepate"
android:gravity="center"
android:orientation="horizontal"
android:tileMode="repeat"
android:weightSum="5" >
<Button
android:id="#+id/btnRefresh"
android:layout_width="32dp"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:layout_weight="0.10"
android:background="#drawable/refreshbutton" />
<View android:layout_weight="1"
android:layout_width="0dip"
android:layout_height="0dip" />
<Button
android:id="#+id/btnPause"
android:layout_width="32dp"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:layout_weight="0.05"
android:background="#drawable/pausebutton" />
<View android:layout_weight="1"
android:layout_width="0dip"
android:layout_height="0dip" />
<Button
android:id="#+id/btnPlay"
android:layout_width="32dp"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:layout_weight="0.05"
android:background="#drawable/playbutton" />
<View android:layout_weight="1"
android:layout_width="0dip"
android:layout_height="0dip" />
<Button
android:id="#+id/btnExit"
android:layout_width="32dp"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:layout_weight="0.12"
android:background="#drawable/exitbutton" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
why when trans from splash.xml to activity_main.xml display black background few min and display app.
Since you are changing activity, its gonna show some animation or black screen like you said. Its the default behavior. You can use a custom dialog with your splash layout on top of main activity. you can trigger the dialog to close on progress complete. Using two activities can have other effects. for instance when the user hits the back button, its gonna go back to splash screen instead of exiting the app.
try it
Thread timer = new Thread(){
public void run(){
try{
while(progressBarStatus < 5000){
StartPoint.this.runOnUiThread(new Runnable(){
public void run()
{
progressBar.setProgress(progressBarStatus);
progressBarStatus += 1000;
}
});
sleep(5000);
}

text for marquee dynamically

Is it possible to add text from java coding of a list view to marquee scroll in Android. If yes can you please let me know how?
If needed I shall post the code used.
This was the XML for listview used is as follows
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
</LinearLayout>
<ListView
android:id="#+id/audiolist_listView"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_gravity="bottom"
android:layout_weight="1"
android:background="#drawable/backgroundimg"
android:divider="#drawable/gradient"
android:dividerHeight="1dp"
android:scrollbars="vertical" >
</ListView>
</LinearLayout>
The java class for listview is as follows
public class Audiovediolist extends Activity implements OnItemClickListener {
private ListView audioList;
private Intent frmHome;
private ArrayList<HashMap<String, String>> dataList;
private HashMap<String, String> map;
private HashMap<String, String> data;
private int Screen_Id;
private AdView adView;
String name;
String mSign[] = { "Aries-Mesam", "Taurus-Vrushabham", "Gemini-Midhunam",
"Cancer-Karkatakam", "Leo-Simham", "Virgo-Kanya", "Libra-Tula",
"Scorpio-Vruchikam", "Sagittarius-Dhanussu", "Capricorn-Makaram",
"Aquarius-Kumbham", "Pisces-Meenam" };
Integer mImages[] = { R.drawable.meshamu, R.drawable.vrushabhamu,
R.drawable.medhunam, R.drawable.karkatakam, R.drawable.simham,
R.drawable.kanya, R.drawable.tula, R.drawable.vruchikam,
R.drawable.dhanussu, R.drawable.makaramu, R.drawable.kumbhamu,
R.drawable.meenamu };
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_RIGHT_ICON);
setContentView(R.layout.list);
frmHome = getIntent();
getIntentValues();
initUI();
setUI();
uiListener();
}
private void initUI() {
audioList = (ListView) findViewById(R.id.audiolist_listView);
dataList = new ArrayList<HashMap<String, String>>();
adView = new AdView(this, AdSize.SMART_BANNER, "a150b89c23af3b2");
LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout1);
layout.setGravity(Gravity.TOP);
layout.addView(adView);
adView.loadAd(new AdRequest());
}
private void uiListener() {
audioList.setOnItemClickListener(this);
}
private void getIntentValues() {
String id = frmHome.getStringExtra("Activity_Id");
Screen_Id = Integer.parseInt(id);
if (Screen_Id == 1) {
getWindow().setFeatureDrawableResource(Window.FEATURE_RIGHT_ICON,
R.drawable.audioo);
this.setTitle(getResources().getString(R.string.audio));
this.setTitleColor(getResources().getColor(R.color.Beige));
} else {
this.setTitle(getResources().getString(R.string.video));
this.setTitleColor(getResources().getColor(R.color.Beige));
getWindow().setFeatureDrawableResource(Window.FEATURE_RIGHT_ICON,
R.drawable.videoo);
}
}
private void setAdapter() {
SimpleAdapter adapter = new SimpleAdapter(this, dataList,
R.layout.list_row, new String[] { "Image", "text" }, new int[] {
R.id.audiolist_row_img, R.id.audiolist_row_tv });
audioList.setAdapter(adapter);
}
private void setUI() {
for (int a = 0; a <= 11; a++) {
map = new HashMap<String, String>();
map.put("Image", "" + mImages[a]);
map.put("text", mSign[a]);
dataList.add(map);
map = null;
}
}
#Override
protected void onStart() {
super.onStart();
setAdapter();
}
#Override
public void onBackPressed() {
super.onBackPressed();
System.gc();
}
#Override
protected void onDestroy() {
super.onDestroy();
adView.destroy();
}
/*
* private class NextTask extends AsyncTask<Void,Void,Void> { ProgressDialog
* progressDailog = new ProgressDialog(Audiovediolist.this);
*
* #Override protected void onPreExecute() { super.onPreExecute();
* progressDailog.setTitle("Please Wait");
* progressDailog.setMessage("URL Data Loading ...");
* progressDailog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
* progressDailog.setCancelable(true); progressDailog.show(); }
*
* #SuppressWarnings("static-access")
*
* #Override protected Void doInBackground(Void... params) { return null; }
*
* #Override protected void onPostExecute(Void result) {
* progressDailog.dismiss(); } }
*/
#Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
data = dataList.get(position);
//FinalConstants.AUDIO_VIDEO = "list";
try {
NetWorkCheck netWork = new NetWorkCheck();
if (netWork.isNetWorkConnection(this)) {
if (Screen_Id == 1) {
// new NextTask().execute();
Intent audioInt=new Intent(getApplicationContext(),AudioView.class);
audioInt.setType(data.get("text"));
startActivity(audioInt);
} else if (Screen_Id == 2) {
Intent vedioInt = new Intent(this, VideoPlayActivity.class);
vedioInt.setType(data.get("text"));
startActivity(vedioInt);
}
} else {
netWork.alert();
}
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(this, "Problem while ListItemClick",
Toast.LENGTH_SHORT).show();
}
}
}
The code for audio player where i need the text selected to scroll is as follows
public class AudioView extends Activity implements OnClickListener {
private MediaPlayer mMediaPlayer;
private ImageView mPlay;
private ImageView mPause;
private ImageView mBack;
private ImageView mFar;
private ProgressBar myProgressBar;
private boolean boolFlag = false;
private boolean isPausedInCall = false;
private String url;
private TelephonyManager mTelephoneMgr;
private NotificationManager mNotificationManager;
private int SIMPLE_NOTFICATION_ID;
private TextView tv;
// private boolean serviceRunning;
Notification notifyDetails;
private AdView adView;
#SuppressWarnings("deprecation")
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.marquee);
Toast.makeText(this,"please wait.........",Toast.LENGTH_LONG).show();
url=getIntent().getType();
initUI();
uiListener();
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notifyDetails = new Notification(R.drawable.mulug_icon, url,
System.currentTimeMillis());
mTelephoneMgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
if (mTelephoneMgr != null) {
mTelephoneMgr.listen(phoneStateListener,
PhoneStateListener.LISTEN_CALL_STATE);
}
/*if(FinalConstants.AUDIO_VIDEO=="listitem"){
LoginProgress task = new LoginProgress();
task.applicationContext = AudioView.this;
task.execute();
}*/
}
private void initUI() {
tv = (TextView) findViewById(R.id.text);
mBack = (ImageView) findViewById(R.id.back);
mPlay = (ImageView) findViewById(R.id.play);
mPause = (ImageView) findViewById(R.id.pause);
mFar = (ImageView) findViewById(R.id.fwd);
myProgressBar = (ProgressBar) findViewById(R.id.progressbar_Horizontal);
myProgressBar.setProgressDrawable(getResources().getDrawable(
R.drawable.green_progress));
myProgressBar.setProgress(0);
adView = new AdView(this, AdSize.BANNER, "a150b89c23af3b2");
LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout1);
layout.setGravity(Gravity.TOP);
layout.addView(adView);
adView.loadAd(new AdRequest());
tv.setText(url + "more Deails Click on www.mulugu.com");
tv.setSelected(true);
}
private void uiListener() {
mPlay.setOnClickListener(this);
mPlay.setOnClickListener(this);
mPause.setOnClickListener(this);
mPause.setVisibility(android.view.View.INVISIBLE);
mBack.setOnClickListener(this);
mFar.setOnClickListener(this);
}
private Thread myThread = new Thread() {
public void run() {
while (mMediaPlayer.getCurrentPosition() < mMediaPlayer
.getDuration()) {
try {
myProgressBar
.setProgress(mMediaPlayer.getCurrentPosition());
} catch (Throwable t) {
}
}
}
};
#Override
protected void onStart() {
super.onStart();
this.setProgressBarIndeterminateVisibility(true);
try {
if (boolFlag == false) {
System.out.println(FinalConstants.URL + "mobile-audio/" + url+ ".mp3");
mMediaPlayer = MediaPlayer.create(
this,
Uri.parse(FinalConstants.URL + "mobile-audio/" + url
+ ".mp3"));
}
myProgressBar.setMax(mMediaPlayer.getDuration());
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "Data not available",
Toast.LENGTH_SHORT).show();
Log.e("ERRORS", "Data Not Exist in that Url...");
super.onBackPressed();
e.printStackTrace();
}
}
#SuppressLint("NewApi")
#Override
public void onBackPressed() {
super.onBackPressed();
mMediaPlayer.stop();
// myThread.stop();
mNotificationManager.cancel(SIMPLE_NOTFICATION_ID);
System.gc();
}
#Override
protected void onDestroy() {
adView.destroy();
super.onDestroy();
System.gc();
}
public PhoneStateListener phoneStateListener = new PhoneStateListener() {
#Override
public void onCallStateChanged(int state, String incomingNumber) {
if (state == TelephonyManager.CALL_STATE_RINGING) {
System.out.println("ringing state");
if (mMediaPlayer != null) {
pauseMedia();
isPausedInCall = true;
}
notificationShow();
}
if (state == TelephonyManager.CALL_STATE_IDLE) {
System.out.println("callState Idle");
if (mMediaPlayer != null) {
if (isPausedInCall) {
isPausedInCall = false;
playMedia();
}
}
}
if (state == TelephonyManager.CALL_STATE_OFFHOOK) {
}
super.onCallStateChanged(state, incomingNumber);
}
};
private void pauseMedia() {
mMediaPlayer.pause();
changePlayerIcons(false);
}
private void playMedia() {
mMediaPlayer.start();
changePlayerIcons(true);
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.play:
if (!boolFlag) {
try {
notificationShow();
mMediaPlayer.setLooping(false);
mMediaPlayer.prepareAsync();
} catch (Exception e) {
Toast.makeText(this, "preparing", Toast.LENGTH_SHORT)
.show();
}
boolFlag = true;
mMediaPlayer.start();
myThread.start();
} else {
notificationShow();
mMediaPlayer.getCurrentPosition();
mMediaPlayer.start();
}
changePlayerIcons(true);
myProgressBar.setProgress(mMediaPlayer.getCurrentPosition());
mMediaPlayer.setOnCompletionListener(new OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer arg0) {
changePlayerIcons(false);
myProgressBar.setProgress(0);
onStart();
}
});
mMediaPlayer.setOnPreparedListener(new OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
}
});
break;
case R.id.pause:
mMediaPlayer.pause();
mPlay.setVisibility(android.view.View.VISIBLE);
mPause.setVisibility(android.view.View.INVISIBLE);
break;
case R.id.back:
int dur = mMediaPlayer.getCurrentPosition();
int pos = (dur > 10000 ? dur - 5000 : 0);
mMediaPlayer.seekTo(pos);
break;
case R.id.fwd:
int curpos = mMediaPlayer.getCurrentPosition();
int dur2 = mMediaPlayer.getDuration();
int pos2 = (curpos + 5000 > dur2 ? dur2 : curpos + 5000);
mMediaPlayer.seekTo(pos2);
break;
}
}
#SuppressWarnings("deprecation")
private void notificationShow() {
Context context = getApplicationContext();
CharSequence contentTitle = "Mulugu Running";
CharSequence contentText = url + " Weekly Predictions";
Intent notifyIntent = new Intent(AudioView.this, AudioView.class);
PendingIntent intent = PendingIntent.getActivity(AudioView.this, 0,
notifyIntent, android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP);
notifyDetails.setLatestEventInfo(context, contentTitle, contentText,
intent);
mNotificationManager.notify(SIMPLE_NOTFICATION_ID, notifyDetails);
}
private void changePlayerIcons(boolean b) {
if (b) {
mPlay.setVisibility(android.view.View.INVISIBLE);
mPause.setVisibility(android.view.View.VISIBLE);
} else {
mPlay.setVisibility(android.view.View.VISIBLE);
mPause.setVisibility(android.view.View.INVISIBLE);
}
}
/*public class LoginProgress extends AsyncTask<Void, Void, Void> {
private ProgressDialog dialog;
protected Context applicationContext;
#Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
this.dialog.dismiss();
}
#Override
protected void onPreExecute() {
this.dialog = ProgressDialog.show(applicationContext, "Data Loading",
"Loading .....", true);
}
#Override
protected Void doInBackground(Void... params) {
LoadUrl();
return null;
}
private void LoadUrl() {
mMediaPlayer = new MediaPlayer();
mMediaPlayer.reset();
try {
mMediaPlayer.setDataSource(AudioView.this,Uri.parse(FinalConstants.URL + "mobile-audio/" + getIntent().getType()+ ".mp3"));
mMediaPlayer.setLooping(false); // Set looping
mMediaPlayer.prepare();
myProgressBar.setMax(mMediaPlayer.getDuration());
} catch (Exception e) {
e.printStackTrace();
}
}
}*/
}
If you need to move text around, maybe this will help:
http://developer.android.com/guide/topics/resources/animation-resource.html#translate-element
If you have a TextView with a text that is too big and you want it to move around so people can read the whole thing, try android:ellipsize="marquee" in the .xml file, or in the Java code:
textView.setEllipsize(TextUtils.TruncateAt.MARQUEE);
If the android libraries not enough, you can always use the java via coding. Create a thread class that gets the views and change conditions over time. You can create an intent to call that class.
You can use the TextSwitcher and apply the animation on it.
Try below code:
public class TextSwitcherActivity extends Activity implements ViewSwitcher.ViewFactory,
View.OnClickListener
{
private TextSwitcher m_switcher;
private Button m_nextButton;
private int m_counter = 0;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
m_switcher = (TextSwitcher) findViewById(R.id.tsSwitcher);
m_switcher.setFactory(this);
Animation in = AnimationUtils.loadAnimation(this, android.R.anim.fade_in);
Animation out = AnimationUtils.loadAnimation(this, android.R.anim.fade_out);
m_switcher.setInAnimation(in);
m_switcher.setOutAnimation(out);
m_nextButton = (Button) findViewById(R.id.next);
m_nextButton.setOnClickListener(this);
updateCounter();
}
/**
* Update counter value
*/
public void onClick(View v)
{
m_counter++;
updateCounter();
}
/**
* Set text on textswitcher
*/
private void updateCounter()
{
m_switcher.setText(String.valueOf(m_counter));
}
public View makeView()
{
TextView t = new TextView(this);
t.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
t.setTextSize(36);
return t;
}
You can define your own animations to get the marquee effect.
Here is the example
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/mywidget"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:lines="1"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:textColor="#ff4500"
android:text="Simple application that shows how to use marquee, with a long text" />
In java (If you are using a Listview and binding an adapter, then in getview when u inflate Layout and its view component, set the selected flag to true to your TextView.)
tv = (TextView) this.findViewById(R.id.tv);
tv.setSelected(true);
By using below method you can convert your list of string values into a single string,
String listString = String.join(", ", list);
This will convert list values into string and with that you can achieve this. I know this is very late but I posted because there is no solution provided that's why.

set text to textview in dynamically in android-marquee

How to set TextView Text as dynamically for scrolling marquee.
Please Help me Thanks Advance.
The Listview used for getting the list item to be played in the audio player is as follows.
public class Audiovediolist extends Activity implements OnItemClickListener {
private ListView audioList;
private Intent frmHome;
private ArrayList<HashMap<String, String>> dataList;
private HashMap<String, String> map;
private HashMap<String, String> data;
private int Screen_Id;
String name;
String mSign[] ={"1","2","3","4","5"};
Integer mImages[] = { R.drawable.m, R.drawable.v,
R.drawable.mm, R.drawable.k, R.drawable.s};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_RIGHT_ICON);
setContentView(R.layout.list);
frmHome = getIntent();
getIntentValues();
initUI();
setUI();
uiListener();
}
private void initUI() {
audioList = (ListView) findViewById(R.id.audiolist_listView);
dataList = new ArrayList<HashMap<String, String>>();
}
private void uiListener() {
audioList.setOnItemClickListener(this);
}
private void getIntentValues() {
String id = frmHome.getStringExtra("Activity_Id");
Screen_Id = Integer.parseInt(id);
if (Screen_Id == 1) {
getWindow().setFeatureDrawableResource(Window.FEATURE_RIGHT_ICON,
R.drawable.audioo);
this.setTitle(getResources().getString(R.string.audio));
this.setTitleColor(getResources().getColor(R.color.Beige));
} else {
this.setTitle(getResources().getString(R.string.video));
this.setTitleColor(getResources().getColor(R.color.Beige));
getWindow().setFeatureDrawableResource(Window.FEATURE_RIGHT_ICON,
R.drawable.videoo);
}
}
private void setAdapter() {
SimpleAdapter adapter = new SimpleAdapter(this, dataList,
R.layout.list_row, new String[] { "Image", "text" },
new int[] {
R.id.audiolist_row_img, R.id.audiolist_row_tv });
audioList.setAdapter(adapter);
}
private void setUI() {
for (int a = 0; a <= 11; a++) {
map = new HashMap<String, String>();
map.put("Image", "" + mImages[a]);
map.put("text", mSign[a]);
dataList.add(map);
map = null;
}
}
#Override
protected void onStart() {
super.onStart();
setAdapter();
}
#Override
public void onBackPressed() {
super.onBackPressed();
System.gc();
}
/*private class NextTask extends AsyncTask<Void,Void,Void> {
ProgressDialog progressDailog = new ProgressDialog(Audiovediolist.this);
#Override
protected void onPreExecute() {
super.onPreExecute();
progressDailog.setTitle("Please Wait");
progressDailog.setMessage("URL Data Loading ...");
progressDailog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressDailog.setCancelable(true);
progressDailog.show();
}
#SuppressWarnings("static-access")
#Override
protected Void doInBackground(Void... params) {
return null;
}
#Override
protected void onPostExecute(Void result) {
progressDailog.dismiss();
}
}*/
#Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
data = dataList.get(position);
try {
NetWorkCheck netWork = new NetWorkCheck();
if (netWork.isNetWorkConnection(this)) {
if (Screen_Id == 1) {
// new NextTask().execute();
Intent audioInt=new Intent(getApplicationContext(),AudioView.class);
audioInt.setType(data.get("text"));
startActivity(audioInt);
} else if (Screen_Id == 2) {
Intent vedioInt = new Intent(this, VideoPlayActivity.class);
vedioInt.setType(data.get("text"));
startActivity(vedioInt);
}
} else {
netWork.alert();
}
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(this, "Problem while ListItemClick", Toast.LENGTH_SHORT).show();
}
}
}
The code for audio player used is
public class AudioView extends Activity implements OnClickListener {
private MediaPlayer mMediaPlayer;
private ImageView mPlay;
private ImageView mPause;
private ImageView mBack;
private ImageView mFar;
private ProgressBar myProgressBar;
// private PlayerService mService;
private boolean boolFlag = false;
private boolean isPausedInCall = false;
private String url;
private TelephonyManager mTelephoneMgr;
private NotificationManager mNotificationManager;
private int SIMPLE_NOTFICATION_ID;
private TextView tv;
// private boolean serviceRunning;
Notification notifyDetails;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.audio_main);
getIntentValues();
initUI();
uiListener();
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notifyDetails = new Notification(R.drawable.mulug_icon, url,
System.currentTimeMillis());
mTelephoneMgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
if (mTelephoneMgr != null) {
mTelephoneMgr.listen(phoneStateListener,
PhoneStateListener.LISTEN_CALL_STATE);
}
}
private void getIntentValues() {
url = getIntent().getType();
}
private void uiListener() {
mPlay.setOnClickListener(this);
mPlay.setOnClickListener(this);
mPause.setOnClickListener(this);
mPause.setVisibility(android.view.View.INVISIBLE);
mBack.setOnClickListener(this);
mFar.setOnClickListener(this);
}
private void initUI() {
tv = (TextView) findViewById(R.id.text);
mBack = (ImageView) findViewById(R.id.back);
mPlay = (ImageView) findViewById(R.id.play);
mPause = (ImageView) findViewById(R.id.pause);
mFar = (ImageView) findViewById(R.id.fwd);
myProgressBar = (ProgressBar) findViewById(R.id.progressbar_Horizontal);
myProgressBar.setProgressDrawable(getResources().getDrawable(
R.drawable.green_progress));
myProgressBar.setProgress(0);
tv.setText(url);
tv.setFocusable(true);
}
private Thread myThread = new Thread() {
public void run() {
while (mMediaPlayer.getCurrentPosition() < mMediaPlayer
.getDuration()) {
try {
myProgressBar
.setProgress(mMediaPlayer.getCurrentPosition());
} catch (Throwable t) {
}
}
}
};
#SuppressLint("NewApi")
#Override
public void onBackPressed() {
super.onBackPressed();
mMediaPlayer.stop();
// myThread.stop();
// mMediaPlayer.release();
mNotificationManager.cancel(SIMPLE_NOTFICATION_ID);
System.gc();
}
#Override
protected void onDestroy() {
super.onDestroy();
System.gc();
}
#SuppressLint("NewApi")
#Override
protected void onStart() {
super.onStart();
this.setProgressBarIndeterminateVisibility(true);
try {
if (boolFlag == false) {
System.out.println(FinalConstants.URL + "mobile-audio/" + url
+ ".mp3");
mMediaPlayer = MediaPlayer.create(
this,
Uri.parse(FinalConstants.URL + "mobile-audio/" + url
+ ".mp3"));
}
myProgressBar.setMax(mMediaPlayer.getDuration());
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "Loading Problems",
Toast.LENGTH_SHORT).show();
Log.e("ERRORS", "ServerFailed to Load...");
super.onBackPressed();
e.printStackTrace();
}
}
public PhoneStateListener phoneStateListener = new PhoneStateListener() {
#Override
public void onCallStateChanged(int state, String incomingNumber) {
if (state == TelephonyManager.CALL_STATE_RINGING) {
System.out.println("ringing state");
if (mMediaPlayer != null) {
pauseMedia();
isPausedInCall = true;
}
notificationShow();
}
if (state == TelephonyManager.CALL_STATE_IDLE) {
System.out.println("callState Idle");
if (mMediaPlayer != null) {
if (isPausedInCall) {
isPausedInCall = false;
playMedia();
}
}
}
if (state == TelephonyManager.CALL_STATE_OFFHOOK) {
}
super.onCallStateChanged(state, incomingNumber);
}
};
private void pauseMedia() {
mMediaPlayer.pause();
changePlayerIcons(false);
}
private void playMedia() {
mMediaPlayer.start();
changePlayerIcons(true);
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.play:
if (!boolFlag) {
try {
notificationShow();
mMediaPlayer.setLooping(false);
// mMediaPlayer.prepareAsync();
} catch (Exception e) {
Toast.makeText(this, "preparing", Toast.LENGTH_SHORT)
.show();
}
boolFlag = true;
mMediaPlayer.start();
myThread.start();
} else {
notificationShow();
mMediaPlayer.getCurrentPosition();
mMediaPlayer.start();
}
changePlayerIcons(true);
myProgressBar.setProgress(mMediaPlayer.getCurrentPosition());
mMediaPlayer.setOnCompletionListener(new OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer arg0) {
changePlayerIcons(false);
myProgressBar.setProgress(0);
onStart();
}
});
mMediaPlayer.setOnPreparedListener(new OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
}
});
mMediaPlayer.setOnErrorListener(new OnErrorListener() {
#Override
public boolean onError(MediaPlayer mp, int what, int extra) {
Toast.makeText(getApplicationContext(),
"MediaPlayer Errors", Toast.LENGTH_SHORT).show();
Log.e("ERRORS", "MediaPlayer Errors...");
return false;
}
});
break;
case R.id.pause:
mMediaPlayer.pause();
mPlay.setVisibility(android.view.View.VISIBLE);
mPause.setVisibility(android.view.View.INVISIBLE);
break;
case R.id.back:
int dur = mMediaPlayer.getCurrentPosition();
int pos = (dur > 10000 ? dur - 5000 : 0);
mMediaPlayer.seekTo(pos);
break;
case R.id.fwd:
int curpos = mMediaPlayer.getCurrentPosition();
int dur2 = mMediaPlayer.getDuration();
int pos2 = (curpos + 5000 > dur2 ? dur2 : curpos + 5000);
mMediaPlayer.seekTo(pos2);
break;
}
}
private void notificationShow() {
Context context = getApplicationContext();
CharSequence contentTitle = "Mulugu Running";
CharSequence contentText = url + " Weekly Predictions";
Intent notifyIntent = new Intent(AudioView.this, AudioView.class);
PendingIntent intent = PendingIntent.getActivity(AudioView.this, 0,
notifyIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
notifyDetails.setLatestEventInfo(context, contentTitle, contentText,
intent);
mNotificationManager.notify(SIMPLE_NOTFICATION_ID, notifyDetails);
}
private void changePlayerIcons(boolean b) {
if (b) {
mPlay.setVisibility(android.view.View.INVISIBLE);
mPause.setVisibility(android.view.View.VISIBLE);
} else {
mPlay.setVisibility(android.view.View.VISIBLE);
mPause.setVisibility(android.view.View.INVISIBLE);
}
}
}
The XML used is
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/main_audio"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:gravity="center"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.45"
android:orientation="vertical" >
<TextView
android:id="#+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="center_horizontal"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:text=" for more details check on "
android:textColor="#FF0000"
android:textSize="20dp"
android:textStyle="italic" >
</TextView>
</LinearLayout>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="3dp" >
<ImageView
android:id="#+id/pause"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:src="#drawable/audio_pause" />
<ImageView
android:id="#+id/play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginLeft="2dp"
android:layout_marginTop="10dp"
android:src="#drawable/audio_play" />
<ImageView
android:id="#+id/back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/pause"
android:layout_marginRight="1dp"
android:layout_toLeftOf="#+id/pause"
android:layout_toRightOf="#drawable/audio_play"
android:src="#drawable/audio_bwd" />
<ImageView
android:id="#+id/fwd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/pause"
android:layout_marginLeft="1dp"
android:layout_toRightOf="#+id/pause"
android:src="#drawable/audio_fwd" />
</RelativeLayout>
<ProgressBar
android:id="#+id/progressbar_Horizontal"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
Here is an example:
public class TextViewMarquee extends Activity {
private TextView tv;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv = (TextView) this.findViewById(R.id.tv);
tv.setSelected(true); // Set focus to the textview
}
}
The xml file with the textview:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:lines="1"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:textColor="#ff4500"
android:text="Simple application that shows how to use marquee, with a long text" />
</RelativeLayout>

Activity will run, but not show up (Android)?

I'm just trying to test some stuff with a splash screen. The strangest thing happens when I run the app though. I can see my Log messages in the LogCat, but the activity itself won't show up. Once the loop finishes, it starts the next activity, which does in fact show up. If I comment out the UIThread, it will show up though. I know I'm doing something simple wrong, but I'm not sure what it is. Ideas?
XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:background="#000000">
<ImageView
android:id="#+id/logoIV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="50dp"
android:paddingTop="50dp"
android:src="#drawable/logoa"
/>
Java:
public class Splash extends Activity{
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.splash);
final ImageView logo = (ImageView) findViewById(R.id.logoIV);
final int[] anim = new int[6];
anim[0]=R.drawable.logoa;
anim[1]=R.drawable.logob;
anim[2]=R.drawable.logoc;
anim[3]=R.drawable.logod;
anim[4]=R.drawable.logoe;
anim[5]=R.drawable.logof;
runOnUiThread(new Runnable() {
int img = 0, counter=0;
boolean up = true;
public void run() {
while(counter<21){
logo.setImageResource(anim[img]);
if(up){
img++;
if(img>=5)
up=false;
}else{
img--;
if(img<=0)
up=true;
}
try{
Thread.sleep(150);
}catch (InterruptedException e){
e.printStackTrace();
}
counter++;
Log.e("Tag",Integer.toString(counter));
}
if(counter>=21){
Intent creditsIntent = new Intent(Splash.this, TitlePage.class);
creditsIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Splash.this.startActivity(creditsIntent);
}
}
});
}
#Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
finish();
}
}
change your oncreate method like this
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.splash);
final ImageView logo = (ImageView) findViewById(R.id.logoIV);
final int[] anim = new int[6];
anim[0] = R.drawable.logoa;
anim[1] = R.drawable.logob;
anim[2] = R.drawable.logoc;
anim[3] = R.drawable.logod;
anim[4] = R.drawable.logoe;
anim[5] = R.drawable.logof;
Thread t = new Thread(new Runnable()
{
int img = 0, counter = 0;
boolean up = true;
#Override
public void run()
{
while (counter < 21)
{
runOnUiThread(new Runnable()
{
public void run()
{
logo.setImageResource(anim[img]);
}
});
if (up)
{
img++;
if (img >= 5)
up = false;
}
else
{
img--;
if (img <= 0)
up = true;
}
try
{
Thread.sleep(150);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
counter++;
Log.e("Tag", Integer.toString(counter));
}
if (counter >= 21)
{
runOnUiThread(new Runnable()
{
public void run()
{
Intent creditsIntent = new Intent(Splash.this, TitlePage.class);
creditsIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Splash.this.startActivity(creditsIntent);
}
});
}
}
});
t.start();
}
instead of calling runOnUiThread directly do the following:
new Timer().schedule(new TimerTask()
{
#Override
public void run()
{
runOnUiThread(new Runnable()
{
int img = 0, counter=0;
.....
}
}
}, 1000);
I'm not sure if your animation will work, but surely your activity will show up.

Categories

Resources