Break function
The break screen is now working. Bugfixes in BreakReminder
This commit is contained in:
parent
112bc82339
commit
db356b1589
8 changed files with 115 additions and 223 deletions
|
|
@ -26,16 +26,8 @@
|
|||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value="orgprivacy_friendly_apps.secuso.privacyfriendlybreakreminder.BreakReminder" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".BreakActivity"
|
||||
android:label="@string/title_activity_break"
|
||||
android:parentActivityName=".BreakReminder"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value="orgprivacy_friendly_apps.secuso.privacyfriendlybreakreminder.BreakReminder" />
|
||||
</activity>
|
||||
<activity android:name=".BreakDecider"></activity>
|
||||
<activity android:name=".BreakDeciderActivity" />
|
||||
<activity android:name=".BreakActivity"></activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
|
@ -3,171 +3,55 @@ package orgprivacy_friendly_apps.secuso.privacyfriendlybreakreminder;
|
|||
import android.content.SharedPreferences;
|
||||
import android.os.CountDownTimer;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class BreakActivity extends AppCompatActivity implements View.OnClickListener{
|
||||
public class BreakActivity extends AppCompatActivity implements View.OnClickListener {
|
||||
|
||||
/**
|
||||
* The {@link android.support.v4.view.PagerAdapter} that will provide
|
||||
* fragments for each of the sections. We use a
|
||||
* {@link FragmentPagerAdapter} derivative, which will keep every
|
||||
* loaded fragment in memory. If this becomes too memory intensive, it
|
||||
* may be best to switch to a
|
||||
* {@link android.support.v4.app.FragmentStatePagerAdapter}.
|
||||
*/
|
||||
private SectionsPagerAdapter mSectionsPagerAdapter;
|
||||
|
||||
/**
|
||||
* The {@link ViewPager} that will host the section contents.
|
||||
*/
|
||||
private ViewPager mViewPager;
|
||||
private TextView ct_text;
|
||||
private boolean isRunning = false;
|
||||
private CountDownTimer ct;
|
||||
private String stopTime = "";
|
||||
private boolean isRunning = false;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_break);
|
||||
|
||||
|
||||
|
||||
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
int mins = sharedPrefs.getInt("break_value", 10);
|
||||
int mins = sharedPrefs.getInt("break_value", 5);
|
||||
String bufferZeroMinute = "";
|
||||
|
||||
if(mins < 10)
|
||||
bufferZeroMinute = "0";
|
||||
|
||||
System.out.println("Change the view");
|
||||
setContentView(R.layout.fragment_break);
|
||||
|
||||
ct_text =(TextView)findViewById(R.id.textViewBreak);
|
||||
ct_text.setText(bufferZeroMinute+mins+":00");
|
||||
|
||||
Button playStopButton = (Button)findViewById(R.id.button_playStopBreak);
|
||||
playStopButton.setOnClickListener(this);
|
||||
Button resetButton = (Button)findViewById(R.id.button_cancel);
|
||||
resetButton.setOnClickListener(this);
|
||||
ct_text.setOnClickListener(this);
|
||||
|
||||
setContentView(R.layout.activity_break);
|
||||
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
// Create the adapter that will return a fragment for each of the three
|
||||
// primary sections of the activity.
|
||||
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
|
||||
|
||||
// Set up the ViewPager with the sections adapter.
|
||||
mViewPager = (ViewPager) findViewById(R.id.container);
|
||||
mViewPager.setAdapter(mSectionsPagerAdapter);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
getMenuInflater().inflate(R.menu.menu_break, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
// Handle action bar item clicks here. The action bar will
|
||||
// automatically handle clicks on the Home/Up button, so long
|
||||
// as you specify a parent activity in AndroidManifest.xml.
|
||||
int id = item.getItemId();
|
||||
|
||||
//noinspection SimplifiableIfStatement
|
||||
if (id == R.id.action_settings) {
|
||||
return true;
|
||||
LinearLayout ll = (LinearLayout)findViewById(R.id.layout_break);
|
||||
// TODO Do it dynamically
|
||||
for (int i = 0; i < 20; i++){
|
||||
ImageView image = new ImageView(this);
|
||||
image.setLayoutParams(new android.view.ViewGroup.LayoutParams(80,60));
|
||||
image.setImageResource(R.drawable.statistic_logo);
|
||||
ll.addView(image);
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* A placeholder fragment containing a simple view.
|
||||
*/
|
||||
public static class PlaceholderFragment extends Fragment {
|
||||
/**
|
||||
* The fragment argument representing the section number for this
|
||||
* fragment.
|
||||
*/
|
||||
private static final String ARG_SECTION_NUMBER = "section_number";
|
||||
|
||||
public PlaceholderFragment() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new instance of this fragment for the given section
|
||||
* number.
|
||||
*/
|
||||
public static PlaceholderFragment newInstance(int sectionNumber) {
|
||||
PlaceholderFragment fragment = new PlaceholderFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putInt(ARG_SECTION_NUMBER, sectionNumber);
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View rootView = inflater.inflate(R.layout.fragment_break, container, false);
|
||||
TextView textView = (TextView) rootView.findViewById(R.id.section_label);
|
||||
textView.setText(getString(R.string.section_format, getArguments().getInt(ARG_SECTION_NUMBER)));
|
||||
return rootView;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A {@link FragmentPagerAdapter} that returns a fragment corresponding to
|
||||
* one of the sections/tabs/pages.
|
||||
*/
|
||||
public class SectionsPagerAdapter extends FragmentPagerAdapter {
|
||||
|
||||
public SectionsPagerAdapter(FragmentManager fm) {
|
||||
super(fm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
// getItem is called to instantiate the fragment for the given page.
|
||||
// Return a PlaceholderFragment (defined as a static inner class below).
|
||||
return PlaceholderFragment.newInstance(position + 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
//TODO Do it dynamically
|
||||
// Show 4 total pages.
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getPageTitle(int position) {
|
||||
|
||||
if (position > getCount() || position < 0)
|
||||
return null;
|
||||
|
||||
return "Exercise number "+position+1;
|
||||
}
|
||||
}
|
||||
|
||||
public void onClick(View v) {
|
||||
|
|
@ -176,6 +60,7 @@ public class BreakActivity extends AppCompatActivity implements View.OnClickList
|
|||
String bufferZeroMinute = "";
|
||||
String bufferZeroSecond = "";
|
||||
int time = mins * 60 * 1000;
|
||||
int oldTime = time;
|
||||
|
||||
if(stopTime == "" && !isRunning) {
|
||||
if (time / 1000 / 60 < 10)
|
||||
|
|
@ -206,29 +91,30 @@ public class BreakActivity extends AppCompatActivity implements View.OnClickList
|
|||
|
||||
switch (v.getId()) {
|
||||
|
||||
case R.id.textView:
|
||||
case R.id.button_playStop:
|
||||
if (isRunning){
|
||||
case R.id.textViewBreak:
|
||||
case R.id.button_playStopBreak:
|
||||
if (isRunning) {
|
||||
ct.cancel();
|
||||
stopTime = (String)ct_text.getText();
|
||||
stopTime = (String) ct_text.getText();
|
||||
isRunning = false;
|
||||
}else{
|
||||
} else {
|
||||
ct = new CountDownTimer(time, 1000) {
|
||||
|
||||
public void onTick(long millisUntilFinished) {
|
||||
String bufferZeroMinute = "";
|
||||
String bufferZeroSecond = "";
|
||||
|
||||
if ((millisUntilFinished / 1000)/60 < 10)
|
||||
if ((millisUntilFinished / 1000) / 60 < 10)
|
||||
bufferZeroMinute = "0";
|
||||
|
||||
if (millisUntilFinished / 1000 % 60 < 10)
|
||||
bufferZeroSecond = "0";
|
||||
|
||||
ct_text.setText(bufferZeroMinute+(millisUntilFinished / 1000)/60 + ":" + bufferZeroSecond + millisUntilFinished / 1000 % 60);
|
||||
ct_text.setText(bufferZeroMinute + (millisUntilFinished / 1000) / 60 + ":" + bufferZeroSecond + millisUntilFinished / 1000 % 60);
|
||||
}
|
||||
|
||||
public void onFinish() {
|
||||
isRunning = false;
|
||||
ct_text.setText("00:00");
|
||||
//TODO trigger the alarm
|
||||
finish();
|
||||
|
|
@ -238,8 +124,10 @@ public class BreakActivity extends AppCompatActivity implements View.OnClickList
|
|||
isRunning = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case R.id.button_cancel:
|
||||
finish();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,9 @@ import android.support.v7.app.AppCompatActivity;
|
|||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.HorizontalScrollView;
|
||||
|
||||
public class BreakDecider extends AppCompatActivity implements View.OnClickListener {
|
||||
public class BreakDeciderActivity extends AppCompatActivity implements View.OnClickListener {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
|
@ -18,6 +19,7 @@ public class BreakDecider extends AppCompatActivity implements View.OnClickListe
|
|||
Button breakButton = (Button)findViewById(R.id.button_break);
|
||||
breakButton.setOnClickListener(this);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void onClick(View v) {
|
||||
|
|
@ -26,6 +28,7 @@ public class BreakDecider extends AppCompatActivity implements View.OnClickListe
|
|||
finish();
|
||||
break;
|
||||
case R.id.button_break:
|
||||
finish();
|
||||
Intent intent = new Intent(this, BreakActivity.class);
|
||||
this.startActivity(intent);
|
||||
break;
|
||||
|
|
@ -122,6 +122,7 @@ public class BreakReminder extends AppCompatActivity
|
|||
String bufferZeroMinute = "";
|
||||
String bufferZeroSecond = "";
|
||||
int time = mins * 60 * 1000;
|
||||
time = 5000;
|
||||
int oldTime = time;
|
||||
|
||||
if(stopTime == "" && !isRunning) {
|
||||
|
|
@ -176,6 +177,7 @@ public class BreakReminder extends AppCompatActivity
|
|||
}
|
||||
|
||||
public void onFinish() {
|
||||
isRunning = false;
|
||||
ct_text.setText("00:00");
|
||||
//TODO trigger the alarm
|
||||
|
||||
|
|
@ -202,7 +204,7 @@ public class BreakReminder extends AppCompatActivity
|
|||
}
|
||||
|
||||
public void startBreak(){
|
||||
Intent intent = new Intent(this, BreakDecider.class);
|
||||
Intent intent = new Intent(this, BreakDeciderActivity.class);
|
||||
this.startActivity(intent);
|
||||
|
||||
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
|
|
|
|||
|
|
@ -1,36 +1,78 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/main_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
tools:context="orgprivacy_friendly_apps.secuso.privacyfriendlybreakreminder.BreakActivity">
|
||||
|
||||
<android.support.design.widget.AppBarLayout
|
||||
android:id="@+id/appbar"
|
||||
android:layout_width="match_parent"
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="@dimen/appbar_padding_top"
|
||||
android:theme="@style/AppTheme.AppBarOverlay">
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:text="10:00"
|
||||
android:id="@+id/textViewBreak"
|
||||
android:clickable="true"
|
||||
android:enabled="true"
|
||||
android:textStyle="bold"
|
||||
android:textSize="60dp"
|
||||
android:textIsSelectable="false"
|
||||
android:layout_centerHorizontal="true" />
|
||||
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:background="?attr/colorPrimary"
|
||||
app:layout_scrollFlags="scroll|enterAlways"
|
||||
app:popupTheme="@style/AppTheme.PopupOverlay">
|
||||
<Button
|
||||
style="?android:attr/buttonStyleSmall"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Play/Stop"
|
||||
android:id="@+id/button_playStopBreak"
|
||||
android:layout_below="@+id/textViewBreak"
|
||||
android:layout_centerHorizontal="true" />
|
||||
|
||||
</android.support.v7.widget.Toolbar>
|
||||
<Button
|
||||
style="?android:attr/buttonStyleSmall"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Cancel"
|
||||
android:id="@+id/button_cancel"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_centerHorizontal="true" />
|
||||
|
||||
</android.support.design.widget.AppBarLayout>
|
||||
|
||||
<android.support.v4.view.ViewPager
|
||||
android:id="@+id/container"
|
||||
<HorizontalScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
|
||||
android:layout_height="92dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true"
|
||||
android:id="@+id/horizontalScrollView2">
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal"
|
||||
android:id="@+id/layout_break">
|
||||
</LinearLayout>
|
||||
</HorizontalScrollView>
|
||||
|
||||
</android.support.design.widget.CoordinatorLayout>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="name of the Exercise"
|
||||
android:id="@+id/textViewExercise"
|
||||
android:layout_above="@+id/horizontalScrollView2"
|
||||
android:layout_centerHorizontal="true" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="You have to train hard, you little bitch"
|
||||
android:id="@+id/textViewDescription"
|
||||
android:layout_below="@+id/horizontalScrollView2"
|
||||
android:layout_centerHorizontal="true" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
tools:context=".BreakDecider">
|
||||
tools:context=".BreakDeciderActivity">
|
||||
|
||||
<Button
|
||||
style="?android:attr/buttonStyleSmall"
|
||||
|
|
@ -40,4 +40,11 @@
|
|||
android:layout_alignParentTop="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginTop="97dp" />
|
||||
|
||||
<HorizontalScrollView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/horizontalScrollView"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_centerHorizontal="true" />
|
||||
</RelativeLayout>
|
||||
|
|
|
|||
|
|
@ -1,41 +0,0 @@
|
|||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
tools:context="orgprivacy_friendly_apps.secuso.privacyfriendlybreakreminder.BreakActivity$PlaceholderFragment">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/section_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<Button
|
||||
style="?android:attr/buttonStyleSmall"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Play/Stop"
|
||||
android:id="@+id/button_playStopBreak"
|
||||
android:layout_below="@+id/textViewBreak"
|
||||
android:layout_centerHorizontal="true" />
|
||||
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:text="10:00"
|
||||
android:id="@+id/textViewBreak"
|
||||
android:clickable="true"
|
||||
android:enabled="true"
|
||||
android:textStyle="bold"
|
||||
android:textSize="60dp"
|
||||
android:textIsSelectable="false"
|
||||
android:layout_below="@+id/section_label"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginTop="54dp" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
|
@ -38,6 +38,5 @@
|
|||
<string name="pref_title_vibrate">Vibrate</string>
|
||||
|
||||
<!-- settings for BreakActivity -->
|
||||
<string name="title_activity_break">Break</string>
|
||||
<string name="section_format">Please get ready for Exercise %1$d</string>
|
||||
|
||||
</resources>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue