Skip to content

Commit

Permalink
Develop (#29)
Browse files Browse the repository at this point in the history
* fix:color (#23)

Signed-off-by: feaaaaaa <409834725@qq.com>

* docs (#24)

* fix:color

Signed-off-by: feaaaaaa <409834725@qq.com>

* docs

* Owner feax (#28)

* fix:color

Signed-off-by: feaaaaaa <409834725@qq.com>

* docs

* feat:pieChart

Signed-off-by: feaaaaaa <409834725@qq.com>

* feat:barChart

Signed-off-by: feaaaaaa <409834725@qq.com>

* fix: standardise id of textView

Signed-off-by: feaaaaaa <409834725@qq.com>

* feat: switch button for statistic

Signed-off-by: feaaaaaa <409834725@qq.com>

* style: color

Signed-off-by: feaaaaaa <409834725@qq.com>

* feat: setting and about page (#27)

Co-authored-by: feax <48175749+feaaaaaa@users.noreply.github.com>

Co-authored-by: feax <48175749+feaaaaaa@users.noreply.github.com>
Co-authored-by: mark-yyc <61784497+mark-yyc@users.noreply.github.com>
  • Loading branch information
3 people authored Oct 2, 2020
1 parent 512b557 commit dc128ed
Show file tree
Hide file tree
Showing 20 changed files with 886 additions and 63 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ dependencies {
implementation 'androidx.navigation:navigation-fragment:2.3.0'
implementation 'androidx.navigation:navigation-ui:2.3.0'
implementation 'androidx.drawerlayout:drawerlayout:1.1.1'
implementation 'androidx.preference:preference:1.1.1'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'
}
57 changes: 31 additions & 26 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,54 +9,59 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".About"></activity>
<activity
android:name=".SettingsActivity"
android:label="@string/title_activity_settings" />
<activity android:name=".CreditDetailList" />
<activity android:name=".FriendsList" />
<activity android:name=".PersonInfoDetail" />
<activity android:name=".CreditDetailCard" />
<activity android:name=".FriendsListCard" />
<activity android:name=".PersonInfoCard" />
<activity android:name=".PersonInfo" />
<activity android:name=".AlarmList"
<activity
android:name=".AlarmList"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".GameSetting"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".RingSetting"
android:theme="@style/AppTheme.NoActionBar" />
<activity android:name=".TaskListActivity"/>
<activity android:name=".ScreenSaverActivity"/>
<activity android:name=".TaskSuccessActivity"/>
<activity android:name=".WhiteListActivity"/>
<activity android:name=".TaskListActivity" />
<activity android:name=".ScreenSaverActivity" />
<activity android:name=".TaskSuccessActivity" />
<activity android:name=".WhiteListActivity" />
<activity android:name=".RegisterActivity" />
<activity android:name=".LoginActivity2" />
<activity android:name=".StatisticActivity" />
<activity
android:name=".MainActivity"
android:label="111"
android:launchMode="singleInstance"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<activity
android:name=".MainActivity"
android:label="111"
android:launchMode="singleInstance"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ClockSetting"
android:theme="@style/AppTheme.NoActionBar"/>
<activity android:name=".LoginActivity1"/>
<!-- <activity-->
<!-- android:name=".MainActivity"-->
<!-- android:launchMode="standard">-->
<!-- <intent-filter>-->
<!-- <action android:name="android.intent.action.MAIN" />-->

<!-- <category android:name="android.intent.category.DEFAULT" />-->
<!-- </intent-filter>-->
<!-- </activity>-->
android:theme="@style/AppTheme.NoActionBar" />
<activity android:name=".LoginActivity1" /> <!-- <activity -->
<!-- android:name=".MainActivity" -->
<!-- android:launchMode="standard"> -->
<!-- <intent-filter> -->
<!-- <action android:name="android.intent.action.MAIN" /> -->
<!-- <category android:name="android.intent.category.DEFAULT" /> -->
<!-- </intent-filter> -->
<!-- </activity> -->
<activity android:name=".AnotherActivity" />
<activity android:name=".TestActivity" />
<activity android:name=".StatisticWeekActivity"/>
<activity android:name=".StatisticYearActivity"/>
</application>

</manifest>
14 changes: 14 additions & 0 deletions app/src/main/java/com/example/wowtime/About.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.example.wowtime;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class About extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about);
}
}
11 changes: 10 additions & 1 deletion app/src/main/java/com/example/wowtime/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.widget.Button;

import androidx.annotation.Nullable;
Expand All @@ -15,6 +16,14 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
// Button button = findViewById(R.id.button);
// button.setOnClickListener(v -> startActivity(new Intent(MainActivity.this, AnotherActivity.class)));
Button button2 = findViewById(R.id.button3);
button2.setOnClickListener(v -> startActivity(new Intent(MainActivity.this, ClockSetting.class)));
button2.setOnClickListener(v -> startActivity(new Intent(MainActivity.this, StatisticActivity.class)));
}

@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_header, menu);
return true;
}

}
31 changes: 31 additions & 0 deletions app/src/main/java/com/example/wowtime/SettingsActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.example.wowtime;

import android.os.Bundle;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.preference.PreferenceFragmentCompat;

public class SettingsActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings_activity);
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.settings, new SettingsFragment())
.commit();
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
}

public static class SettingsFragment extends PreferenceFragmentCompat {
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.root_preferences, rootKey);
}
}
}
151 changes: 141 additions & 10 deletions app/src/main/java/com/example/wowtime/StatisticActivity.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,160 @@
package com.example.wowtime;

import android.graphics.Color;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.PieData;
import com.github.mikephil.charting.data.PieDataSet;
import com.github.mikephil.charting.data.PieEntry;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
import com.github.mikephil.charting.utils.ColorTemplate;

import java.util.ArrayList;
import java.util.List;

public class StatisticActivity extends AppCompatActivity {
// @Override
// protected void onCreate(@Nullable Bundle savedInstanceState) {
//
// super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_statistic);
// PieChartView pieChartView = (PieChartView) findViewById(R.id.chart);
//
// List<PieChartView.PieceDataHolder> pieceDataHolders = new ArrayList<>();
//
// pieceDataHolders.add(new PieChartView.PieceDataHolder(1000, 0xFF8FDCD9, "预习ICS\n15:00-15:25"));
// pieceDataHolders.add(new PieChartView.PieceDataHolder(800, 0xFFCB72D8, "洗衣服\n15:30-15:45"));
// pieceDataHolders.add(new PieChartView.PieceDataHolder(4000, 0xFFFF9800, "App原型UI\n21:00-23:00"));
// pieceDataHolders.add(new PieChartView.PieceDataHolder(5000, 0xFFFFB6C1, "写选修课论文\n19:00-20:20"));
// pieceDataHolders.add(new PieChartView.PieceDataHolder(3000, 0xFF9DDC98, "写CSE-lab1\n12:30-14:00"));
//
// pieChartView.setData(pieceDataHolders);
// }
private PieChart pie;
List<PieEntry> list;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_statistic);
PieChartView pieChartView = (PieChartView) findViewById(R.id.pie_chart);
pie = (PieChart) findViewById(R.id.chart);

list=new ArrayList<>();
list.add(new PieEntry(10,"预习ICS","9:00-9:45"));
list.add(new PieEntry(12,"洗衣服","12:40-13:30"));
list.add(new PieEntry(21,"App原型","14:00-15:30"));
list.add(new PieEntry(27,"CSE-lab1","19:00-21:00"));
list.add(new PieEntry(30,"Android","21:30-23:00"));

PieDataSet pieDataSet=new PieDataSet(list,"");
pieDataSet.setSliceSpace(3f);//设置不同DataSet之间的间距
pieDataSet.setSelectionShift(5f);
// pieDataSet.setHighlightEnabled(true);
//设置各个数据的颜色
// pieDataSet.setColors(0xFF8FDCD9,0xFFCB72D8,0xFFFF9800,0xFFFFB6C1,0xFF9DDC98);
ArrayList<Integer> colors = new ArrayList<Integer>();
for (int c : ColorTemplate.VORDIPLOM_COLORS)
colors.add(c);
for (int c : ColorTemplate.JOYFUL_COLORS)
colors.add(c);
for (int c : ColorTemplate.COLORFUL_COLORS)
colors.add(c);
for (int c : ColorTemplate.LIBERTY_COLORS)
colors.add(c);
for (int c : ColorTemplate.PASTEL_COLORS)
colors.add(c);
colors.add(ColorTemplate.getHoloBlue());
pieDataSet.setColors(colors);
PieData pieData=new PieData(pieDataSet);
pieData.setValueTextColor(Color.WHITE);
pie.setData(pieData);

pie.setBackgroundColor(0xFFFFCCBC);
pie.setNoDataText(String.valueOf(R.string.statistic_no_data));//设置当chart为空时显示的描述文字。
pie.setUsePercentValues(true);//使用百分比显示
pie.setExtraOffsets(15, 0, 15, 0);//设置图表上下左右的偏移,类似于外边距
pie.setDragDecelerationFrictionCoef(0.95f);
//实体扇形的空心圆的半径 设置成0时就是一个圆 而不是一个环
pie.setHoleRadius(50f);
//中间半透明白色圆的半径 设置成0时就是隐藏
pie.setTransparentCircleRadius(53f);
//设置中心圆的颜色
pie.setHoleColor(0xFFFFCCBC);
pie.setTransparentCircleColor(Color.WHITE);//?
pie.setTransparentCircleAlpha(110);//?
//设置中心部分的字 (一般中间白色圆不隐藏的情况下才设置)
pie.setCenterText("每日总结");
//设置中心字的字体颜色
pie.setCenterTextColor(Color.WHITE);
//设置中心字的字体大小
pie.setCenterTextSize(22);
//设置描述的字体大小
pie.setEntryLabelTextSize(12);
//设置数据的字体大小 (图中的 44 56)
pieDataSet.setValueTextSize(12);
//设置描述的位置
// pieDataSet.setXValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
// pieDataSet.setValueLinePart1Length(0.2f);//设置描述连接线长度
// //设置数据的位置
// pieDataSet.setYValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
// pieDataSet.setValueLinePart2Length(0.1f);//设置数据连接线长度
// //设置两根连接线的颜色
// pieDataSet.setValueLineColor(Color.WHITE);

//对于右下角一串字母的操作
pie.getDescription().setEnabled(false); //是否显示右下角描述
pie.getDescription().setText("这是修改那串英文的方法"); //修改右下角字母的显示
pie.getDescription().setTextSize(15); //字体大小
pie.getDescription().setTextColor(Color.WHITE); //字体颜色

//图例
Legend legend=pie.getLegend();
legend.setEnabled(true); //是否显示图例
// legend.setTextColor(Color.WHITE);
legend.setPosition(Legend.LegendPosition.BELOW_CHART_RIGHT); //图例的位置

//旋转
pie.setRotationEnabled(true);
pie.setHighlightPerTapEnabled(true);


//数据更新
pie.notifyDataSetChanged();
pie.invalidate();

List<PieChartView.PieceDataHolder> pieceDataHolders = new ArrayList<>();
//动画(如果使用了动画可以则省去更新数据的那一步)
pie.animateY(1000); //在Y轴的动画 参数是动画执行时间 毫秒为单位
// line.animateX(2000); //X轴动画
// line.animateXY(2000,2000);//XY两轴混合动画

pieceDataHolders.add(new PieChartView.PieceDataHolder(1000, 0xFF8FDCD9, "预习ICS\n15:00-15:25"));
pieceDataHolders.add(new PieChartView.PieceDataHolder(800, 0xFFCB72D8, "洗衣服\n15:30-15:45"));
pieceDataHolders.add(new PieChartView.PieceDataHolder(4000, 0xFFFF9800, "App原型UI\n21:00-23:00"));
pieceDataHolders.add(new PieChartView.PieceDataHolder(5000, 0xFFFFB6C1, "写选修课论文\n19:00-20:20"));
pieceDataHolders.add(new PieChartView.PieceDataHolder(3000, 0xFF9DDC98, "写CSE-lab1\n12:30-14:00"));
pie.setOnChartValueSelectedListener(new com.github.mikephil.charting.listener.OnChartValueSelectedListener() {
@Override
public void onValueSelected(Entry e, Highlight h) {
if(e==null)return;
int totalSectors=pieDataSet.getEntryCount();
for(int i=0;i<totalSectors;++i){
if(pieDataSet.getEntryForIndex(i).getY()==e.getY()){//pieDataSet.getEntryForIndex(i).getX()==e.getX()&&
TextView textView=findViewById(R.id.textViewDayBottom);
textView.setText(pieDataSet.getEntryForIndex(i).getLabel()+"\n"+pieDataSet.getEntryForIndex(i).getData());
System.out.println("pie click:"+pieDataSet.getEntryForIndex(i).getLabel());
}
}
}

pieChartView.setData(pieceDataHolders);
@Override
public void onNothingSelected() {
TextView textView=findViewById(R.id.textViewDayBottom);
textView.setText("");
}
});
}
}
Loading

0 comments on commit dc128ed

Please sign in to comment.