Android media player with list view and service - java

I have implemented an Android media player that is clicking on songs text view will display the layout. The layout displayed with play pause .. and clicking on play stop works well. Here I am thinking in users perspective to implement the below.
Clicking on songs text view should display the songs in list view and in the bottom of the layout small controls should display with play pause and stop
It should play even when other application is opened.
To achieve the point 2 I used media player service and for point 1, I used a `ListView' but not successfully implemented. Below is the code which play the song and and go till end. From this point can anyone please help me to implement list view songs with service?
public class Songs extends Activity {
private MediaPlayer mediaPlayer;
public TextView songName, duration;
private double timeElapsed = 0, finalTime = 0;
private int forwardTime = 2000, backwardTime = 2000;
private Handler durationHandler = new Handler();
private SeekBar seekbar;
private Context context;
private int getCurrentPos=0;
private int[] songs={R.raw.sample_song,R.raw.sleepaway};
#Override
protected void onCreate(Bundle savedInstanceState) {
context=getApplicationContext();
super.onCreate(savedInstanceState);
setContentView(R.layout.mediaplayer);
initializeViews();
}
public void initializeViews(){
songName = (TextView) findViewById(R.id.songName);
mediaPlayer = MediaPlayer.create(this, songs[getCurrentPos]);
mediaPlayer.setLooping(true);
finalTime = mediaPlayer.getDuration();
duration = (TextView) findViewById(R.id.songDuration);
seekbar = (SeekBar) findViewById(R.id.seekBar);
songName.setText("Sample_Song.mp3");
seekbar.setMax((int) finalTime);
seekbar.setClickable(false);
}
// play mp3 song
public void play(View view) {
mediaPlayer.start();
timeElapsed = mediaPlayer.getCurrentPosition();
seekbar.setProgress((int) timeElapsed);
durationHandler.postDelayed(updateSeekBarTime, 100);
}
private Runnable updateSeekBarTime = new Runnable() {
public void run() {
//get current position
timeElapsed = mediaPlayer.getCurrentPosition();
//set seekbar progress
seekbar.setProgress((int) timeElapsed);
//set time remaing
double timeRemaining = finalTime - timeElapsed;
// duration.setText(String.format("%d min, %d sec", 12, TimeUnit.MILLISECONDS.toSeconds((long) timeRemaining) - 12));
//repeat yourself that again in 100 miliseconds
durationHandler.postDelayed(this, 100);
}
};
// pause mp3 song
public void pause(View view) {
mediaPlayer.pause();
}
// go forward at forwardTime seconds
public void forward(View view) {
//check if we can go forward at forwardTime seconds before song endes
if ((timeElapsed + forwardTime) <= finalTime) {
timeElapsed = timeElapsed + forwardTime;
//seek to the exact second of the track
mediaPlayer.seekTo((int) timeElapsed);
}
}
// go backwards at backwardTime seconds
public void rewind(View view) {
//check if we can go back at backwardTime seconds after song starts
if ((timeElapsed - backwardTime) > 0) {
timeElapsed = timeElapsed - backwardTime;
//seek to the exact second of the track
mediaPlayer.seekTo((int) timeElapsed);
}
}
// Go to next song
public void next(View view) throws IOException{
try {
mediaPlayer.reset();
mediaPlayer = MediaPlayer.create(this, songs[getSongPosition()]);
mediaPlayer.start();
} 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();
}
}
private int getSongPosition(){
if(getCurrentPos==songs.length-1){
getCurrentPos=0;
}else if(getCurrentPos==0){
getCurrentPos=getCurrentPos+1;
}else{
getCurrentPos=getCurrentPos+1;
}
return getCurrentPos;
}
}
Layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#333333"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin" >
<TextView
android:id="#+id/songName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="songName" />
<ImageView
android:id="#+id/mp3Image"
android:layout_width="match_parent"
android:layout_height="200dp"
android:padding="30dp"
android:src="#drawable/music"
android:background="#ffffff"
android:layout_margin="30dp" />
<TextView
android:id="#+id/songDuration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="songDuration" />
<SeekBar
android:id="#+id/seekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="30dp"
android:gravity="center_horizontal"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/media_rew"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="7dp"
android:onClick="rewind"
android:src="#android:drawable/ic_media_rew" />
<ImageButton
android:id="#+id/media_pause"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="7dp"
android:onClick="pause"
android:src="#android:drawable/ic_media_pause" />
<ImageButton
android:id="#+id/media_play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="7dp"
android:onClick="play"
android:src="#android:drawable/ic_media_play" />
<ImageButton
android:id="#+id/media_ff"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="7dp"
android:onClick="forward"
android:src="#android:drawable/ic_media_ff" />
<ImageButton
android:id="#+id/media_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="7dp"
android:onClick="next"
android:src="#android:drawable/ic_media_next" />
</LinearLayout>
</LinearLayout>

Related

Recyclerview is Scrolling when media Player is playing. How can i fix it?

I'm developing a ChatApp with the function of Audio Messages. The Recording and playing of this Audio Messages are working very well, but if i click on Play Button the Recyclerview is scrolling up. Anyone have an idea?
Sorry for my bad english, i'm from Germany ;)
AdapterChat.Java
private static final int MSG_TYPE_LEFT = 0;
private static final int MSG_TYPE_RIGHT = 1;
Context context;
List<ModelChat> chatList;
String imageUrl;
FirebaseUser fUser;
public AdapterChat(Context context, List<ModelChat> chatList, String imageUrl) {
this.context = context;
this.chatList = chatList;
this.imageUrl = imageUrl;
}
#NonNull
#Override
public MyHolder onCreateViewHolder(#NonNull ViewGroup viewGroup, int i) {
//inflate layouts: row_chat_left.xml for receiver, row_chat_right.xml for sender
if (i == MSG_TYPE_RIGHT) {
View view = LayoutInflater.from(context).inflate(R.layout.row_chat_right, viewGroup, false);
return new MyHolder(view);
}
else {
View view = LayoutInflater.from(context).inflate(R.layout.row_chat_left, viewGroup, false);
return new MyHolder(view);
}
}
public void add(ModelChat object) {
chatList.add(object);
add(object);
}
#SuppressLint("ClickableViewAccessibility")
#Override
public void onBindViewHolder(#NonNull final MyHolder myHolder, final int i) {
final String message = chatList.get(i).getMessage();
String timeStamp = chatList.get(i).getTimestamp();
String type = chatList.get(i).getType();
if (type.equals("text") || message.equals(R.string.message_was_deleted)) {
//text message
myHolder.messageTv.setVisibility(View.VISIBLE);
myHolder.messageIv.setVisibility(View.GONE);
myHolder.playAudioBtn.setVisibility(View.GONE);
myHolder.messageVoiceSb.setVisibility(View.GONE);
myHolder.sbCurrentTime.setVisibility(View.GONE);
myHolder.sbTotalDuration.setVisibility(View.GONE);
myHolder.messageTv.setText(message);
}
else if (type.equals("audio")) {
//audio message
myHolder.messageTv.setVisibility(View.GONE);
myHolder.messageIv.setVisibility(View.GONE);
myHolder.playAudioBtn.setVisibility(View.VISIBLE);
myHolder.messageVoiceSb.setVisibility(View.VISIBLE);
myHolder.sbCurrentTime.setVisibility(View.VISIBLE);
myHolder.sbTotalDuration.setVisibility(View.VISIBLE);
myHolder.voiceMessageUrl = message;
myHolder.getAdapterPosition();
myHolder.playAudioBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (myHolder.mediaPlayer.isPlaying()) {
myHolder.handler.removeCallbacks(myHolder.updater);
myHolder.mediaPlayer.pause();
myHolder.playAudioBtn.setImageResource(R.drawable.ic_play_btn);
}
else {
myHolder.mediaPlayer.start();
myHolder.playAudioBtn.setImageResource(R.drawable.ic_pause_btn);
myHolder.updateSeekbar();
}
}
});
myHolder.prepareMediaPlayer();
myHolder.messageVoiceSb.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View view, MotionEvent motionEvent) {
SeekBar seekBar = (SeekBar) view;
int playPosition = (myHolder.mediaPlayer.getDuration() / 100) * seekBar.getProgress();
myHolder.mediaPlayer.seekTo(playPosition);
myHolder.sbCurrentTime.setText(myHolder.milliSecondsToTimer(myHolder.mediaPlayer.getCurrentPosition()));
return false;
}
});
myHolder.mediaPlayer.setOnBufferingUpdateListener(new MediaPlayer.OnBufferingUpdateListener() {
#Override
public void onBufferingUpdate(MediaPlayer mediaPlayer, int i) {
myHolder.messageVoiceSb.setSecondaryProgress(i);
}
});
myHolder.mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer mediaPlayer) {
myHolder.messageVoiceSb.setProgress(0);
myHolder.playAudioBtn.setImageResource(R.drawable.ic_play_btn);
myHolder.mediaPlayer.reset();
myHolder.prepareMediaPlayer();
}
});
}
else {
//image message
myHolder.messageIv.setVisibility(View.VISIBLE);
myHolder.messageTv.setVisibility(View.GONE);
myHolder.playAudioBtn.setVisibility(View.GONE);
myHolder.messageVoiceSb.setVisibility(View.GONE);
myHolder.sbCurrentTime.setVisibility(View.GONE);
myHolder.sbTotalDuration.setVisibility(View.GONE);
Picasso.get().load(message).placeholder(R.drawable.ic_image_black).into(myHolder.messageIv);
}
//set data
myHolder.messageTv.setText(message);
myHolder.timeTv.setText(timeStamp);
try {
Picasso.get().load(imageUrl).into(myHolder.profileIv);
}
catch (Exception e) {
}
myHolder.messageLayout.setOnLongClickListener(new View.OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
//show delete message confirm dialog
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(R.string.delete);
builder.setMessage("Are you sure to delete this message?");
//delete button
builder.setPositiveButton(R.string.delete, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
deleteMessage(i);
}
});
//cancel delete button
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
//dismiss dialog
dialog.dismiss();
}
});
//create and show dialog
builder.create().show();
return false;
}
});
//set seen/delivered status of message
if (i==chatList.size()-1) {
if (chatList.get(i).isSeen()) {
myHolder.isSeenTv.setText("Seen");
}
else {
myHolder.isSeenTv.setText("Delivered");
}
}
else {
myHolder.isSeenTv.setVisibility(View.GONE);
}
}
private void deleteMessage(int position) {
final String myUID = FirebaseAuth.getInstance().getCurrentUser().getUid();
/*Logic:
* Get timeStamp of clicked message
* Compare the timeStamp of the clicked message with all messages in CHats
* Where both values matches, delete that message
* This will allow sender to delete his and receiver's message*/
String msgTimeStamp = chatList.get(position).getTimestamp();
final String type = chatList.get(position).getType();
DatabaseReference dbRef = FirebaseDatabase.getInstance().getReference("Chats");
Query query = dbRef.orderByChild("timestamp").equalTo(msgTimeStamp);
query.addListenerForSingleValueEvent(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot ds: dataSnapshot.getChildren()) {
/*if you want to allow sender to delete only his message then
* compare sender value with current user's uid
* if they match means its the message of sender that is trying to delete*/
if (ds.child("sender").getValue().equals(myUID)) {
if (type.equals("audio")) {
HashMap<String, Object> hashMap = new HashMap<>();
hashMap.put("type", "text");
ds.getRef().updateChildren(hashMap);
} else if (type.equals("image")) {
HashMap<String, Object> hashMap = new HashMap<>();
hashMap.put("type", "text");
ds.getRef().updateChildren(hashMap);
}
/*We can do one of two things here
* 1) Remove the message from chats
* 2) Set the value of message "This messages was deleted..." */
//1) Remove the message from Chats
//ds.getRef().removeValue();
//2) Set the value of message "This message was deleted..."
HashMap<String, Object> hashMap = new HashMap<>();
hashMap.put("message", "This message was deleted...");
ds.getRef().updateChildren(hashMap);
Toast.makeText(context, "message deleted...", Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(context, "You can delete only your messages...", Toast.LENGTH_SHORT).show();
}
}
}
#Override
public void onCancelled(#NonNull DatabaseError error) {
}
});
}
#Override
public int getItemCount() {
return chatList.size();
}
#Override
public long getItemId(int position) {
return 0;
}
#Override
public int getItemViewType(int position) {
//get currently signed in user
fUser = FirebaseAuth.getInstance().getCurrentUser();
if (chatList.get(position).getSender().equals(fUser.getUid())) {
return MSG_TYPE_RIGHT;
}
else {
return MSG_TYPE_LEFT;
}
}
//view holder class
class MyHolder extends RecyclerView.ViewHolder {
//views
ImageView profileIv, messageIv;
ImageButton playAudioBtn;
SeekBar messageVoiceSb;
TextView messageTv, timeTv, isSeenTv, sbCurrentTime, sbTotalDuration;
LinearLayout messageLayout; //for click listener to show delete option
MediaPlayer mediaPlayer;
Handler handler = new Handler();
String voiceMessageUrl = null;
#SuppressLint("ClickableViewAccessibility")
public MyHolder(#NonNull View itemView) {
super(itemView);
//init views
profileIv = itemView.findViewById(R.id.profileIv);
messageIv = itemView.findViewById(R.id.messageIV);
messageTv = itemView.findViewById(R.id.messageTv);
messageVoiceSb = itemView.findViewById(R.id.messageVoiceSb);
playAudioBtn = itemView.findViewById(R.id.playAudioBtn);
sbCurrentTime = itemView.findViewById(R.id.sbCurrentTime);
sbTotalDuration = itemView.findViewById(R.id.sbTotalDuration);
timeTv = itemView.findViewById(R.id.timeTv);
isSeenTv = itemView.findViewById(R.id.isSeenTv);
messageLayout = itemView.findViewById(R.id.messageLayout);
mediaPlayer = new MediaPlayer();
messageVoiceSb.setMax(100);
}
private void prepareMediaPlayer() {
try {
mediaPlayer.setDataSource(voiceMessageUrl); //url of audio file to play
mediaPlayer.prepare();
sbTotalDuration.setText(milliSecondsToTimer(mediaPlayer.getDuration()));
} catch (Exception e) {
Toast.makeText(context, e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
private Runnable updater = new Runnable() {
#Override
public void run() {
updateSeekbar();
long currentDuration = mediaPlayer.getCurrentPosition();
sbCurrentTime.setText(milliSecondsToTimer(currentDuration));
}
};
private void updateSeekbar() {
if (mediaPlayer.isPlaying()) {
messageVoiceSb.setProgress((int) (((float) mediaPlayer.getCurrentPosition() / mediaPlayer.getDuration()) * 100));
handler.postDelayed(updater, 1000);
}
}
private String milliSecondsToTimer(long milliSeconds) {
String timerString = "";
String secondsString;
int hours = (int) (milliSeconds / (1000 * 60 * 60));
int minutes = (int) (milliSeconds % (1000 * 60 * 60)) / (1000 * 60);
int seconds = (int) ((milliSeconds % (1000 * 60 * 60)) % (1000 * 60) / 1000);
if (hours > 0) {
timerString = hours + ":";
}
if (seconds < 10) {
secondsString = "0" + seconds;
} else {
secondsString = "" + seconds;
}
timerString = timerString + minutes + ":" + secondsString;
return timerString;
}
}
chatActivity.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/chatBackground"
tools:context=".ChatActivity">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:background="#color/colorPrimaryDark"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/profileIv"
android:layout_width="35dp"
android:layout_height="35dp"
android:scaleType="centerCrop"
android:src="#drawable/ic_default"
app:civ_circle_background_color="#color/colorPrimaryDark"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:layout_marginStart="20dp">
<!-- Receiver Name-->
<TextView
android:id="#+id/nameTv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="His Name"
android:textColor="#color/colorWhite"
android:textSize="18sp"
android:textStyle="bold" />
<!-- Receiver Status i.e online or offline-->
<TextView
android:id="#+id/userStatusTv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="online"
android:textColor="#color/colorWhite"
android:textSize="12sp"
android:textStyle="bold" />
</LinearLayout>
<ImageView
android:id="#+id/blockIv"
android:layout_gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="5dp"
android:src="#drawable/ic_unblocked_green"
android:visibility="invisible"/>
</LinearLayout>
</androidx.appcompat.widget.Toolbar>
<!-- RecyclerView-->
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/chat_recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/toolbar"
android:layout_above="#id/chatLayout" />
<!-- send message edit text and button in layout-->
<LinearLayout
android:id="#+id/chatLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center"
android:background="#color/textInputBackground"
android:orientation="horizontal">
<!-- ImageButton: to send Image-->
<ImageButton
android:id="#+id/attachBtn"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#null"
android:src="#drawable/ic_attach_black" />
<!-- EditText: input message-->
<EditText
android:id="#+id/messageEt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#null"
android:inputType="textCapSentences|textMultiLine"
android:padding="15dp"
android:hint="Start typing" />
<Chronometer
android:id="#+id/record_timer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:textSize="14sp"
android:textColor="#color/colorPrimary" />
<!-- Button: voice message-->
<ImageButton
android:id="#+id/recordBtn"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="#null"
android:src="#drawable/ic_record_btn_stopped" />
<!-- Button: send message-->
<ImageButton
android:id="#+id/sendBtn"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="#null"
android:src="#drawable/ic_send" />
</LinearLayout>
row_chat_right.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:id="#+id/messageLayout"
android:padding="10dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="end">
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:id="#+id/profileIv"
app:civ_border_color="#null"
android:visibility="gone"
android:src="#drawable/ic_default_img" />
<TextView
android:id="#+id/messageTv"
android:layout_weight="1"
android:textSize="16sp"
android:textColor="#color/textColor"
android:background="#drawable/bg_sender"
android:padding="15dp"
android:text="His Message"
android:visibility="gone"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<ImageView
android:id="#+id/messageIV"
android:layout_width="200dp"
android:layout_height="200dp"
android:adjustViewBounds="true"
android:padding="15dp"
android:src="#drawable/ic_image_black"
android:scaleType="fitCenter"
android:background="#drawable/bg_sender" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/bg_sender"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/playAudioBtn"
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginTop="20dp"
android:background="#null"
android:src="#drawable/ic_play_btn" />
<SeekBar
android:id="#+id/messageVoiceSb"
android:visibility="gone"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/playAudioBtn"
android:padding="10dp"
android:layout_marginTop="10dp"
android:max="100"
android:progress="0" />
<TextView
android:id="#+id/sbCurrentTime"
android:visibility="gone"
android:text="0:00"
android:textStyle="bold"
android:textSize="12sp"
android:layout_marginStart="2dp"
android:layout_below="#id/messageVoiceSb"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/sbTotalDuration"
android:visibility="gone"
android:textStyle="bold"
android:text="0:10"
android:textSize="12sp"
android:layout_below="#id/messageVoiceSb"
android:layout_toEndOf="#id/messageVoiceSb"
android:layout_marginEnd="12dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
</LinearLayout>
<TextView
android:id="#+id/timeTv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:textAlignment="textEnd"
android:text="07/08/2020 23:00PM"
android:textColor="#color/textColor"
android:textSize="12sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/isSeenTv"
android:gravity="end"
android:textAlignment="textEnd"
android:text="delivered" />
Here is the Fix!!
<TextView
android:layout_width="match_parent" <-- This is what I changed
android:layout_height="wrap_content"/>
<SeekBar
android:layout_width="match_parent" <-- Check this as well
android:layout_height="wrap_content"/>

Android Studio: how progress bar can fill up based on user input

I am using a progress bar sample from Github however I noticed that the progress bar fill is set to a fixed value. For example, if the step count goal is 10 (.java class) the man should be "10" in the .XML
My goal: when the user inputs their goal step count, the "10" should be variable and change depending on user input.
java snippet:
ProgressBar progressBar = (ProgressBar) this.findViewById(R.id.progressBar);
ObjectAnimator animation = ObjectAnimator.ofInt(progressBar, "progress", lastStep, stepCounter); //animate only from last known step to current step count
animation.setDuration(5000); // in milliseconds
animation.setInterpolator(new DecelerateInterpolator());
animation.start();
lastStep = stepCounter;
XML snippet
<ProgressBar
android:id="#+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="376dp"
android:layout_height="392dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:max="10"
android:progress="0"
android:progressDrawable="#drawable/circular" />
EDIT********************EDIT
Sorry maybe my question wasn't clear. To provide an example...if the users step goal is 500. I need the progress bar to fill respectively. Therefore, IF step_count = 250 then progress bar should be half full, IF step_count = 750 then should be 3/4 full. I need the progression to be respective to a variable value.
Set android:indeterminate="false". See this fully implemented code
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<ProgressBar
android:id="#+id/pBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:layout_marginTop="200dp"
android:minHeight="50dp"
android:minWidth="200dp"
android:max="100"
android:indeterminate="false"
android:progress="0" />
<TextView
android:id="#+id/tView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/pBar"
android:layout_below="#+id/pBar" />
<Button
android:id="#+id/btnShow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="130dp"
android:layout_marginTop="20dp"
android:text="Start Progress"
android:layout_below="#+id/tView"/>
public class MainActivity extends AppCompatActivity {
private ProgressBar pgsBar;
private int i = 0;
private TextView txtView;
private Handler hdlr = new Handler();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pgsBar = (ProgressBar) findViewById(R.id.pBar);
txtView = (TextView) findViewById(R.id.tView);
Button btn = (Button)findViewById(R.id.btnShow);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
i = pgsBar.getProgress();
new Thread(new Runnable() {
public void run() {
while (i < 100) {
i += 1;
// Update the progress bar and display the current value in text view
hdlr.post(new Runnable() {
public void run() {
pgsBar.setProgress(i);
txtView.setText(i+"/"+pgsBar.getMax());
}
});
try {
// Sleep for 100 milliseconds to show the progress slowly.
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}).start();
}
});
}
}

App Crashes when using setVisibility

As the title says,
When using startLabel.setVisibility(View.GONE);
The app Crashes and I am not sure how to fix
The Java code below.
public class Main extends AppCompatActivity {
private TextView scoreLabel;
private TextView startLabel;
private ImageView box;
private ImageView orange;
private ImageView pink;
private ImageView black;
// Position
private int boxY;
private int boxX;
// Initialize Class
private Handler handler = new Handler();
private Timer timer = new Timer();
//Status Check
private boolean action_flg = false;
private boolean start_flg = false;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
scoreLabel = (TextView) findViewById(R.id.scoreLabel);
scoreLabel = (TextView) findViewById(R.id.startLabel);
box = (ImageView) findViewById(R.id.box);
orange = (ImageView) findViewById(R.id.orange);
pink = (ImageView) findViewById(R.id.pink);
black = (ImageView) findViewById(R.id.black);
//Moves images to out of the screen
//orange.setX(-80.0f);
orange.setY(-80.0f);
// pink.setX(-80.0f);
pink.setY(-80.0f);
//black.setX(-80.0f);
black.setY(-80.0f);
boxY = 200;
}
public void changePos()
{
//Move box
if (action_flg == true)
{
// touching
boxY -= 20;
} else {
//released
boxY += 20;
}
box.setY(boxY);
}
public boolean onTouchEvent(MotionEvent me)
{
if (start_flg == false)
{
start_flg = true;
//Issue here with setting the visibility of the start
// startLabel.setVisibility(View.GONE);
timer.schedule(new TimerTask()
{
#Override
public void run() {
handler.post(new Runnable() {
#Override
public void run() {
changePos();
}
});
}
// Changing these numbers slows down how fast the box moves.
}, 0, 100);
}else {
if(me.getAction() == MotionEvent.ACTION_DOWN)
{
action_flg = true;
}else if (me.getAction() == MotionEvent.ACTION_UP){
action_flg = false;
}
}
return true;
}
}
Here is the XML version of the code.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="me.scott.nathan.catchtheball.Main">
<TextView
android:id="#+id/scoreLabel"
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="Score : 300"
android:textSize="18sp"
android:paddingLeft="10dp"
android:gravity="center_vertical">
</TextView>
<FrameLayout
android:id="#+id/frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/startLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tap to Start"
android:textSize="30sp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="130dp"
/>
<ImageView
android:id="#+id/box"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="#drawable/box"
android:layout_gravity="center_vertical"
/>
<ImageView
android:id="#+id/orange"
android:layout_width="20dp"
android:layout_height="20dp"
android:src="#drawable/orange" />
<ImageView
android:id="#+id/black"
android:layout_width="24dp"
android:layout_height="24dp"
android:src="#drawable/black" />
<ImageView
android:id="#+id/pink"
android:layout_width="16dp"
android:layout_height="16dp"
android:src="#drawable/pink" />
</FrameLayout>
<!--
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.22" />
-->
</LinearLayout>
Anyone help appreciated to fix this issue, Thanks
Your startLabel is null (copy paste problem?^^). Replace this:
scoreLabel = (TextView) findViewById(R.id.startLabel);
with this:
startLabel = (TextView) findViewById(R.id.startLabel);

R cannot resolved to a variable in eclipse android [duplicate]

This question already has answers here:
R cannot be resolved - Android error
(108 answers)
Closed 6 years ago.
This is my xml code R file is not generating please tell me where is the error and why R file is not generating
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#333333"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin" >
<TextView
android:id="#+id/SongName"
android:layout_width="wrap_content"
android:text="#string/songName"
android:layout_height="wrap_content"/>
<ImageView
android:id="#+id/s_mp3Image"
android:layout_width="match_parent"
android:layout_height="200dp"
android:padding="30dp"
android:contentDescription="#string/music"
android:src="#drawable/music"
android:background="#ffffff"
android:layout_margin="30dp" />
<TextView
android:id="#+id/songDuration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/songDuration"
android:layout_gravity="center"/>
<SeekBar
android:id="#+id/s_seekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="30dp"
android:gravity="center_horizontal"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/s_media_rew"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="14dp"
android:onClick="rewind"
android:contentDescription="#string/ic_media_rew"
android:src="#android:drawable/ic_media_rew" />
<ImageButton
android:id="#+id/s_media_pause"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="14dp"
android:onClick="pause"
android:contentDescription="#string/media_pause"
android:src="#android:drawable/ic_media_pause" />
<ImageButton
android:id="#+id/s_media_play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="14dp"
android:onClick="play"
android:contentDescription="#string/ic_media_play"
android:src="#android:drawable/ic_media_play" />
<ImageButton
android:id="#+id/s_media_ff"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="14dp"
android:onClick="forward"
android:contentDescription="#string/ic_media_ff"
android:src="#android:drawable/ic_media_ff" />
</LinearLayout>
and this is my java code
package com.example.androidmediaplayer;
import java.util.concurrent.TimeUnit;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.VideoView;
public class MainActivity extends Activity {
private MediaPlayer mediaPlayer;
public TextView songName, duration;
private double timeElapsed = 0, finalTime = 0;
private int forwardTime = 2000, backwardTime = 2000;
private Handler durationHandler = new Handler();
private SeekBar seekbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//set the layout of the Activity
setContentView(R.layout.activity_list_item); //here R file has problem
//initialize views
initializeViews();
}
public void initializeViews(){
songName=(TextView)findViewById(R.id.SongName); //here R file has problem
mediaPlayer = MediaPlayer.create(this, R.raw.sample); //here
finalTime = mediaPlayer.getDuration();
duration = (TextView) findViewById(R.id.songDuration); //here
seekbar = (SeekBar) findViewById(R.id.s_seekBar); //here
songName.setText("Sample_Song.mp3");
seekbar.setMax((int) finalTime);
seekbar.setClickable(false);
}
// play mp3 song
public void play(View view) {
mediaPlayer = new MediaPlayer();
mediaPlayer.start();
timeElapsed = mediaPlayer.getCurrentPosition();
seekbar.setProgress((int) timeElapsed);
durationHandler.postDelayed(updateSeekBarTime, 100);
}
//handler to change seekBarTime
#SuppressLint("NewApi")
private Runnable updateSeekBarTime = new Runnable() {
#SuppressLint("NewApi")
public void run() {
//get current position
timeElapsed = mediaPlayer.getCurrentPosition();
//set seekBar progress
seekbar.setProgress((int) timeElapsed);
//set time remaining
double timeRemaining = finalTime - timeElapsed;
duration.setText(String.format("%d min, %d sec", TimeUnit.MILLISECONDS.toMinutes((long) timeRemaining), TimeUnit.MILLISECONDS.toSeconds((long) timeRemaining) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes((long) timeRemaining))));
//repeat yourself that again in 100 milliseconds
durationHandler.postDelayed(this, 100);
}
};
// pause mp3 song
public void pause(View view) {
mediaPlayer.pause();
}
// go forward at forwardTime seconds
public void forward(View view) {
//check if we can go forward at forwardTime seconds before song
if ((timeElapsed + forwardTime) <= finalTime) {
timeElapsed = timeElapsed + forwardTime;
//seek to the exact second of the track
mediaPlayer.seekTo((int) timeElapsed);
}
}
// go backwards at backwardTime seconds
public void rewind(View view) {
//check if we can go back at backwardTime seconds after song starts
if ((timeElapsed - backwardTime) > 0) {
timeElapsed = timeElapsed - backwardTime;
//seek to the exact second of the track
mediaPlayer.seekTo((int) timeElapsed);
}
}
}
This is my code R file is not generating please tell me where is the error and why R file is not generating
This is my xml code R file is not generating please tell me where is the error and why R file is not generating This is my xml code R file is not generating please tell me where is the error and why R file is not generating This is my xml code R file is not generating please tell me where is the error and why R file is not generating
You should try cleaning your project !!
Try Clean your Project.
OR
Restart Eclipse.
Or
Check with All XML Resources you have used. Is their any missing things in your XML.
This case mostly happens when you have Something wrong with your XML Resources you are using.

Dynamic Graph of Sensor data with aChartEngine - Android

I have an application which connects to an external sensor via Bluetooth Low Energy. I have the data coming in as a dynamic string which I have split into three strings, then I have the strings converted into doubles.
I have been trying to graph the doubles dynamically for weeks now with various chart libraries such as
aChartEngine
AndroidPlot
and ChartDroid
I decided to go with aChartEngine mainly because I found a dynamic sample app that graphs random data. I have been trying to implement this sample app into mine. Then I am hoping to adapt it to graph my sensor data doubles.
Here is the code I am trying to implement at the moment:
public class XYChartBuilder extends Activity {
public static final String TYPE = "type";
private XYMultipleSeriesDataset mDataset = new XYMultipleSeriesDataset();
private XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer();
private XYSeries mCurrentSeries;
private XYSeriesRenderer mCurrentRenderer;
private String mDateFormat;
private Button mNewSeries;
private Button mAdd;
private GraphicalView mChartView;
private int index = 0;
static double x = 0;
static double y = 0;
protected Update mUpdateTask;
#Override
protected void onRestoreInstanceState(Bundle savedState) {
super.onRestoreInstanceState(savedState);
mDataset = (XYMultipleSeriesDataset) savedState
.getSerializable("dataset");
mRenderer = (XYMultipleSeriesRenderer) savedState
.getSerializable("renderer");
mCurrentSeries = (XYSeries) savedState
.getSerializable("current_series");
mCurrentRenderer = (XYSeriesRenderer) savedState
.getSerializable("current_renderer");
mDateFormat = savedState.getString("date_format");
}
#Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putSerializable("dataset", mDataset);
outState.putSerializable("renderer", mRenderer);
outState.putSerializable("current_series", mCurrentSeries);
outState.putSerializable("current_renderer", mCurrentRenderer);
outState.putString("date_format", mDateFormat);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.demo_opengl_acc);
mRenderer.setApplyBackgroundColor(true);
mRenderer.setBackgroundColor(Color.argb(100, 50, 50, 50));
mRenderer.setAxisTitleTextSize(16);
mRenderer.setChartTitleTextSize(20);
mRenderer.setLabelsTextSize(15);
mRenderer.setLegendTextSize(15);
mRenderer.setMargins(new int[] { 20, 30, 15, 0 });
mRenderer.setZoomButtonsVisible(true);
mRenderer.setPointSize(10);
mRenderer.setXTitle("TIME");
mRenderer.setYTitle("y");
mRenderer.setShowGrid(true);
String seriesTitle = "Series " + (mDataset.getSeriesCount() + 1);
XYSeries series = new XYSeries(seriesTitle);
mDataset.addSeries(series);
mCurrentSeries = series;
XYSeriesRenderer renderer = new XYSeriesRenderer();
mRenderer.addSeriesRenderer(renderer);
renderer.setPointStyle(PointStyle.CIRCLE);
renderer.setFillPoints(true);
mCurrentRenderer = renderer;
mUpdateTask = new Update();
mUpdateTask.execute(this);
}
#Override
protected void onResume() {
super.onResume();
if (mChartView == null) {
LinearLayout layout = (LinearLayout) findViewById(R.id.chart);
mChartView = ChartFactory.getLineChartView(this, mDataset,
mRenderer);
mRenderer.setClickEnabled(true);
mRenderer.setSelectableBuffer(100);
mChartView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
SeriesSelection seriesSelection = mChartView
.getCurrentSeriesAndPoint();
double[] xy = mChartView.toRealPoint(0);
if (seriesSelection == null) {
Toast.makeText(XYChartBuilder.this,
"No chart element was clicked",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(
XYChartBuilder.this,
"Chart element in series index "
+ seriesSelection.getSeriesIndex()
+ " data point index "
+ seriesSelection.getPointIndex()
+ " was clicked"
+ " closest point value X="
+ seriesSelection.getXValue() + ", Y="
+ seriesSelection.getValue()
+ " clicked point value X="
+ (float) xy[0] + ", Y="
+ (float) xy[1], Toast.LENGTH_SHORT)
.show();
}
}
});
mChartView.setOnLongClickListener(new View.OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
SeriesSelection seriesSelection = mChartView
.getCurrentSeriesAndPoint();
if (seriesSelection == null) {
Toast.makeText(XYChartBuilder.this,
"No chart element was long pressed",
Toast.LENGTH_SHORT);
return false; // no chart element was long pressed, so
// let something
// else handle the event
} else {
Toast.makeText(XYChartBuilder.this,
"Chart element in series index "
+ seriesSelection.getSeriesIndex()
+ " data point index "
+ seriesSelection.getPointIndex()
+ " was long pressed",
Toast.LENGTH_SHORT);
return true; // the element was long pressed - the event
// has been
// handled
}
}
});
mChartView.addZoomListener(new ZoomListener() {
public void zoomApplied(ZoomEvent e) {
String type = "out";
if (e.isZoomIn()) {
type = "in";
}
System.out.println("Zoom " + type + " rate "
+ e.getZoomRate());
}
public void zoomReset() {
System.out.println("Reset");
}
}, true, true);
mChartView.addPanListener(new PanListener() {
public void panApplied() {
System.out.println("New X range=["
+ mRenderer.getXAxisMin() + ", "
+ mRenderer.getXAxisMax() + "], Y range=["
+ mRenderer.getYAxisMax() + ", "
+ mRenderer.getYAxisMax() + "]");
}
});
layout.addView(mChartView, new LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
boolean enabled = mDataset.getSeriesCount() > 0;
} else {
mChartView.repaint();
}
}
private int generateRandomNum() {
Random randomGenerator = new Random();
int randomInt = randomGenerator.nextInt(100);
return randomInt;
}
protected class Update extends AsyncTask<Context, Integer, String> {
#Override
protected String doInBackground(Context... params) {
int i = 0;
while (true) {
try {
Thread.sleep(50);
x = x + 5;
y = generateRandomNum();
publishProgress(i);
i++;
} catch (Exception e) {
}
}
// return "COMPLETE!";
}
// -- gets called just before thread begins
#Override
protected void onPreExecute() {
super.onPreExecute();
}
#Override
protected void onProgressUpdate(Integer... values) {
super.onProgressUpdate(values);
mCurrentSeries.add(x, y);
if (mChartView != null) {
mChartView.repaint();
}
Bitmap bitmap = mChartView.toBitmap();
try {
File file = new File(Environment.getExternalStorageDirectory(),
"test" + index++ + ".png");
FileOutputStream output = new FileOutputStream(file);
bitmap.compress(CompressFormat.PNG, 100, output);
} catch (Exception e) {
e.printStackTrace();
}
}
// -- called if the cancel button is pressed
#Override
protected void onCancelled() {
super.onCancelled();
}
#Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
}
}
}
and I have "joined it" to the relevant page on the app in the xml layout:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".demo.DemoAccelerometerSensorActivity" >
<sample.ble.sensortag.demo.DemoGLSurfaceView
android:id="#+id/gl"
android:layout_width="match_parent"
android:layout_height="93dp" />
<requestFocus />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:text="Now Recording Data to file. Press button to add name to file" />
<TextView
android:id="#+id/AccValues"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Accelerometer"
android:textAppearance="?android:textAppearanceLarge" />
<Button
android:id="#+id/baddNametoFile"
android:layout_width="300dp"
android:layout_height="100dp"
android:layout_gravity="left"
android:layout_marginTop="250dp"
android:layout_weight="1"
android:background="#c0c0c0"
android:text="Add Name to File" />
<Button
android:id="#+id/Stop"
android:layout_width="300dp"
android:layout_height="100dp"
android:layout_gravity="right"
android:layout_marginTop="250dp"
android:layout_weight="1"
android:background="#FF0000"
android:text="Stop Recording" />
<EditText
android:id="#+id/ETName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="190dp"
android:ems="10"
android:hint="Name Here"
android:inputType="textCapWords"
android:maxWidth="200dp" />
<TextView
android:id="#+id/text"
android:layout_width="match_parent"
android:layout_height="81dp"
android:layout_margin="10dp"
android:textAppearance="?android:textAppearanceMedium" />
<LinearLayout
android:id="#+id/chart"
android:layout_width="600dp"
android:layout_height="match_parent"
android:layout_marginTop="430dp"
android:orientation="vertical" >
</LinearLayout>
The problem I have implementing the project is that it does not show up in the app at all.
There are no errors. It just doesn't display. I am just wondering if anyone can help. Or if you know any other basic dynamic graph tutorials, maybe for implementing into an existing project. I am 15 (edit - 16 now) and have only started java in the last couple of months. I am still only at the basics. If you post any code could you please explain it.
Thanks in advance,
The problem is with your layout, it is not designed well.
Use something like the following. You may need to adjust few things.
Your layout is not showing properly on small screen devices.I have edited ur layout and now its showing on small devices also.Please adjust height and other things according to ur requirement.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/AccValues"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Accelerometer"
android:textAppearance="?android:textAppearanceLarge" />
<View
android:id="#+id/gl"
android:layout_width="match_parent"
android:layout_height="100dp" />
<requestFocus />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Now Recording Data to file. Press button to add name to file" />
<EditText
android:id="#+id/ETName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Name Here"
android:inputType="textCapWords"
android:maxWidth="200dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="#+id/baddNametoFile"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_gravity="left"
android:layout_weight="1"
android:background="#c0c0c0"
android:text="Add Name to File" />
<Button
android:id="#+id/Stop"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_gravity="right"
android:layout_weight="1"
android:background="#FF0000"
android:text="Stop Recording" />
</LinearLayout>
<TextView
android:id="#+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ABSGS "
android:textAppearance="?android:textAppearanceMedium" />
<LinearLayout
android:id="#+id/chart"
android:layout_width="match_parent"
android:layout_height="164dp"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
</FrameLayout>

Categories