natija.setOnClickListener(view -> {
if (calculated == false) {
if (f1 !="" || T1 != "" || wk_1 != "" || wch_1 != "") {
u_a(f, Wk1, Wch1, T);
u_b(f, Wk2, Wch2, T);
u_c(f, Wk3, Wch3, T);
calculated = true;
Toast.makeText(this, "Grafik", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "f , Wk1, Wch1 ,T nitoldiring", Toast.LENGTH_LONG).show();
}
} else {
graphView1.removeAllSeries();
calculated = false;
}
});
}
public void u_a(EditText f1, EditText wk1, EditText wch1, EditText T1) {
com.jjoe64.graphview.GraphView graphView1 = findViewById(R.id.graph_dinamic);
String f = f1.getText().toString();
String T = T1.getText().toString();
String wk_1 = wk1.getText().toString();
String wch_1 = wch1.getText().toString();
for (inti = 0; i<1000; i++) {
double t = i * 0.001;
double k = -t / (Double.parseDouble(T));
//1-graph
double x = 4.44 * Double.parseDouble(f) * Double.parseDouble(wk_1) * Double.parseDouble(wch_1)
* 1 / (R_myu+ R_sigma)*100*(Math.sin(6.28/Double.parseDouble(T)* t));
series_Ua1.appendData(new DataPoint(t, x), true, 1000);
//2-graph
double y= 4.44 * Double.parseDouble(f) * Double.parseDouble(wk_1) * Double.parseDouble(wch_1)
* 1 / (R_myu+ R_sigma)*100*Math.exp(k);
series_Ua2.appendData(new DataPoint(t, y), true, 1000);
//3-graph
double z = 4.44 * Double.parseDouble(f) * Double.parseDouble(wk_1) * Double.parseDouble(wch_1)
* 1 / (R_myu+ R_sigma)*100*(Math.exp(k)+Math.sin(6.28/Double.parseDouble(T)* t));
series_Ua.appendData(new DataPoint(t, z), true, 1000);
}
series_Ua1.setThickness(5);
series_Ua1.setColor(Color.GREEN);
series_Ua2.setThickness(5);
series_Ua2.setColor(Color.BLUE);
series_Ua.setThickness(5);
series_Ua.setColor(Color.RED);
graphView1.getViewport().isScalable();
graphView1.getViewport().computeScroll();
graphView1.getViewport().isScrollable();
graphView1.addSeries(series_Ua1);
graphView1.addSeries(series_Ua2);
graphView1.addSeries(series_Ua);
}
public void u_b(EditText f1, EditText wk2, EditText wch2, EditText T1) {
com.jjoe64.graphview.GraphView graphView1 = findViewById(R.id.graph_dinamic);
String f = f1.getText().toString();
String T = T1.getText().toString();
String wk_2 = wk2.getText().toString();
String wch_2 = wch2.getText().toString();
for (inti = 0; i<1000; i++) {
double t = i * 0.001;
double k = -t / (Double.parseDouble(T));
//1-graph
double x = 4.44 * Double.parseDouble(f) * Double.parseDouble(wk_2) * Double.parseDouble(wch_2)
* 1 / (R_myu+ R_sigma)*100*(Math.sin(6.28/Double.parseDouble(T)* t+2.0943951));
series_Ub1.appendData(new DataPoint(t, x), true, 1000);
//2-graph
double y= 4.44 * Double.parseDouble(f) * Double.parseDouble(wk_2) * Double.parseDouble(wch_2)
* 1 / (R_myu+ R_sigma)*100*Math.exp(k);
series_Ub2.appendData(new DataPoint(t, y), true, 1000);
//3-graph
double z = 4.44 * Double.parseDouble(f) * Double.parseDouble(wk_2) * Double.parseDouble(wch_2)
* 1 / (R_myu+ R_sigma)*100*(Math.exp(k)+Math.sin(6.28/Double.parseDouble(T)* t+2.0943951));
series_Ub.appendData(new DataPoint(t, z), true, 1000);
}
series_Ub1.setThickness(5);
series_Ub1.setColor(Color.BLACK);
series_Ub2.setThickness(5);
series_Ub2.setColor(Color.GRAY);
series_Ub.setThickness(5);
series_Ub.setColor(Color.LTGRAY);
graphView1.getViewport().isScalable();
graphView1.getViewport().computeScroll();
graphView1.getViewport().isScrollable();
graphView1.addSeries(series_Ub1);
graphView1.addSeries(series_Ub2);
graphView1.addSeries(series_Ub);
}
public void u_c(EditText f1, EditText wk3, EditText wch3, EditText T1) {
com.jjoe64.graphview.GraphView graphView1 = findViewById(R.id.graph_dinamic);
String f = f1.getText().toString();
String T = T1.getText().toString();
String wk_3 = wk3.getText().toString();
String wch_3 = wch3.getText().toString();
for (inti = 0; i<1000; i++) {
double t = i * 0.001;
double k = -t / (Double.parseDouble(T));
//1-graph
double x = 4.44 * Double.parseDouble(f) * Double.parseDouble(wk_3) * Double.parseDouble(wch_3)
* 1 / (R_myu+ R_sigma)*100*(Math.sin(6.28/Double.parseDouble(T)* t-2.0943951));
series_Uc1.appendData(new DataPoint(t, x), true, 1000);
//2-graph
double y= 4.44 * Double.parseDouble(f) * Double.parseDouble(wk_3) * Double.parseDouble(wch_3)
* 1 / (R_myu+ R_sigma)*100*Math.exp(k);
series_Uc2.appendData(new DataPoint(t, y), true, 1000);
//3-graph
double z = 4.44 * Double.parseDouble(f) * Double.parseDouble(wk_3) * Double.parseDouble(wch_3)
* 1 / (R_myu+ R_sigma)*100*(Math.exp(k)+Math.sin(6.28/Double.parseDouble(T)* t-2.0943951));
series_Uc.appendData(new DataPoint(t, z), true, 1000);
}
series_Uc1.setThickness(5);
series_Uc1.setColor(Color.CYAN);
series_Uc2.setThickness(5);
series_Uc2.setColor(Color.MAGENTA);
series_Uc.setThickness(5);
series_Uc.setColor(Color.YELLOW);
graphView1.getViewport().isScalable();
graphView1.getViewport().computeScroll();
graphView1.getViewport().isScrollable();
graphView1.addSeries(series_Uc1);
graphView1.addSeries(series_Uc2);
graphView1.addSeries(series_Uc);
}
}
Xml file
xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayoutxmlns: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"
tools:context=".Dinamik">
<com.jjoe64.graphview.GraphView
android:id= "@+id/graph_dinamic"
android:layout_width="match_parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_margin= "10dp"
android:layout_height="300dp"/>
<LinearLayout
android:id="@+id/line1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="20dp"
android:orientation="horizontal"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/graph_dinamic"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:text="Wk1 = "
android:textSize="20sp" />
<EditText
android:id="@+id/Wk1"
android:layout_width="65dp"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:inputType="numberDecimal|numberSigned"
android:textSize="20sp" />
LinearLayout>
<LinearLayout
android:id="@+id/line3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="20dp"
android:orientation="horizontal"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/line2"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:text="Wk3 = "
android:textSize="20sp" />
<EditText
android:id="@+id/Wk3"
android:layout_width="65dp"
android:layout_marginLeft="15dp"
android:layout_height="wrap_content"
android:inputType="numberDecimal|numberSigned"
android:textSize="20sp" />
LinearLayout>
<LinearLayout
android:id="@+id/line4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginRight="20dp"
app:layout_constraintTop_toBottomOf="@id/graph_dinamic"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:text="f = "
android:textSize="20sp" />
<EditText
android:id="@+id/f"
android:layout_width="65dp"
android:layout_marginLeft="15dp"
android:layout_height="wrap_content"
android:inputType="numberDecimal|numberSigned"
android:textSize="20sp" />
LinearLayout>
<LinearLayout
android:id="@+id/line5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginRight="20dp"
android:orientation="horizontal"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/line4"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="T = "
android:textSize="20sp" />
<EditText
android:id="@+id/T"
android:layout_width="65dp"
android:layout_marginLeft="15dp"
android:layout_height="wrap_content"
android:inputType="numberDecimal|numberSigned"
android:textSize="20sp" />
LinearLayout>
<LinearLayout
android:id="@+id/line6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="20dp"
android:orientation="horizontal"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/line3"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:text="Wch1 = "
android:textSize="20sp" />
<EditText
android:id="@+id/Wch1"
android:layout_width="65dp"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:inputType="numberDecimal|numberSigned"
android:textSize="20sp" />
LinearLayout>
<LinearLayout
android:id="@+id/line7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="20dp"
android:orientation="horizontal"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/line6"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:text="Wch2 = "
android:textSize="20sp" />
<EditText
android:id="@+id/Wch2"
android:layout_width="65dp"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:inputType="numberDecimal|numberSigned"
android:textSize="20sp" />
LinearLayout>
<LinearLayout
android:id="@+id/line2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="20dp"
android:orientation="horizontal"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/line1"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:text="Wk2 = "
android:textSize="20sp" />
<EditText
android:id="@+id/Wk2"
android:layout_width="65dp"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:inputType="numberDecimal|numberSigned"
android:textSize="20sp" />
LinearLayout>
<LinearLayout
android:id="@+id/line8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="20dp"
android:orientation="horizontal"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/line7"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:text="Wch3 = "
android:textSize="20sp" />
<EditText
android:id="@+id/Wch3"
android:layout_width="65dp"
android:layout_marginLeft="15dp"
android:layout_height="wrap_content"
android:inputType="numberDecimal|numberSigned"
android:textSize="20sp" />
LinearLayout>
<Button
android:id="@+id/result"
android:layout_width="100dp"
android:layout_height="40dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_margin="30dp"
android:text="Natija"
android:textStyle="bold"
android:background="@drawable/shape"
>Button>
android.support.constraint.ConstraintLayout>
Manifest
xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.linegraph">
<application
android:allowBackup="true"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".Dinamik">activity>
<activity android:name=".Main2Activity" />
<activity
android:name=".Statik"
android:label="@string/title_activity_statik"
android:theme="@style/AppTheme.NoActionBar" />
<activity android:name=".MainActivity" />
<activity android:name=".Kirish">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
intent-filter>
activity>
application>
manifest>
Build gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'
android {
compileSdkVersion28
defaultConfig {
applicationId"com.example.linegraph"
minSdkVersion17
targetSdkVersion28
versionCode1
versionName"1.0"
testInstrumentationRunner"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabledfalse
proguardFilesgetDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
targetCompatibility = '1.8'
sourceCompatibility = '1.8'
}
}
repositories {
maven { url'https://jitpack.io' }
mavenCentral()
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.github.lecho:hellocharts-library:1.5.8@aar'
implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0-alpha'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:design:28.0.0'
implementation 'com.jjoe64:graphview:4.2.2'
testImplementation'junit:junit:4.12'
androidTestImplementation'com.android.support.test:runner:1.0.2'
androidTestImplementation'com.android.support.test.espresso:espresso-core:3.0.2'
implementation files('libs/graphlib.jar')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
Do'stlaringiz bilan baham: |