forked from dsxkline/dsxkline_android
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
44 changed files
with
1,611 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
plugins { | ||
id 'com.android.application' | ||
} | ||
|
||
android { | ||
compileSdkVersion 31 | ||
buildToolsVersion "30.0.3" | ||
|
||
defaultConfig { | ||
applicationId "com.dsxkline.android" | ||
minSdkVersion 16 | ||
targetSdkVersion 31 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
} | ||
|
||
dependencies { | ||
|
||
implementation 'androidx.appcompat:appcompat:1.2.0' | ||
implementation 'com.google.android.material:material:1.2.1' | ||
implementation 'androidx.constraintlayout:constraintlayout:2.0.1' | ||
testImplementation 'junit:junit:4.+' | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.2' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
Binary file not shown.
26 changes: 26 additions & 0 deletions
26
app/src/androidTest/java/com/dsxkline/android/ExampleInstrumentedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.dsxkline.android; | ||
|
||
import android.content.Context; | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry; | ||
import androidx.test.ext.junit.runners.AndroidJUnit4; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class ExampleInstrumentedTest { | ||
@Test | ||
public void useAppContext() { | ||
// Context of the app under test. | ||
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); | ||
assertEquals("com.dsxkline.android", appContext.getPackageName()); | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.dsxkline.android"> | ||
<uses-permission android:name="android.permission.INTERNET" /> | ||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/Theme.Dsxkline" | ||
android:usesCleartextTraffic="true" | ||
> | ||
<activity android:name=".MainActivity" android:exported="true"> | ||
|
||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<!-- 不允许放大缩小 --> | ||
<meta name="viewport" content = "width=device-width,height=device-height,initial-scale=1.0,user-scalable=no"> | ||
<title>大师兄K线图</title> | ||
<style>*{padding:0;margin:0;-webkit-touch-callout:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;}html{overflow:hidden;}body{position:fixed;top:0;left:0;overflow:hidden;width:100%;height:100%;}</style> | ||
<script src="./dsx.kline.js?v=101"></script> | ||
</head> | ||
<body> | ||
|
||
<div id="kline" style="display: block;"></div> | ||
|
||
</body> | ||
</html> | ||
|
||
<script> | ||
|
||
</script> |
Binary file not shown.
227 changes: 227 additions & 0 deletions
227
app/src/main/java/com/dsxkline/android/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,227 @@ | ||
package com.dsxkline.android; | ||
|
||
import androidx.annotation.RequiresApi; | ||
import androidx.appcompat.app.AppCompatActivity; | ||
|
||
import android.os.Build; | ||
import android.os.Bundle; | ||
import android.view.View; | ||
import android.view.WindowManager; | ||
import android.widget.Button; | ||
import android.widget.LinearLayout; | ||
import android.widget.RelativeLayout; | ||
import android.widget.ScrollView; | ||
|
||
import com.dsxkline.android.dsxkline.DsxKline; | ||
import com.dsxkline.android.dsxkline.HqModel; | ||
import com.dsxkline.android.dsxkline.QQhq; | ||
|
||
import org.json.JSONArray; | ||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.net.HttpURLConnection; | ||
import java.net.MalformedURLException; | ||
import java.net.ProtocolException; | ||
import java.net.URL; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
|
||
private DsxKline kline; | ||
private static String code = "sh000001"; | ||
private static int cycle = 0; | ||
private static int page = 1; | ||
private static JSONArray datas = new JSONArray(); | ||
|
||
@RequiresApi(api = Build.VERSION_CODES.R) | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
WindowManager wm1 = this.getWindowManager(); | ||
int width = wm1.getCurrentWindowMetrics().getBounds().width(); | ||
kline = new DsxKline(this); | ||
|
||
setContentView(R.layout.activity_main); | ||
ScrollView scrollView = findViewById(R.id.scrollView); | ||
LinearLayout linearLayout = findViewById(R.id.scrollViewContent); | ||
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(width,width); | ||
layoutParams.topMargin = 50; | ||
linearLayout.addView(kline,layoutParams); | ||
createTabbar(); | ||
//addContentView(kline,layoutParams); | ||
// 开始请求并加载数据 | ||
kline.onLoading = new DsxKline.ICallback() { | ||
@Override | ||
public void call(Object... args) { | ||
try { | ||
getStockDatas(code); | ||
} catch (JSONException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
}; | ||
// 自动加载下一页数据 | ||
kline.nextPage = new DsxKline.ICallback() { | ||
@Override | ||
public void call(Object... args) { | ||
try { | ||
getStockDatas(code); | ||
} catch (JSONException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
private void createTabbar(){ | ||
Button bt0 = findViewById(R.id.bt0); | ||
Button bt1 = findViewById(R.id.bt1); | ||
Button bt2 = findViewById(R.id.bt2); | ||
Button bt3 = findViewById(R.id.bt3); | ||
Button bt4 = findViewById(R.id.bt4); | ||
Button bt5 = findViewById(R.id.bt5); | ||
bt0.setTag(0); | ||
bt1.setTag(1); | ||
bt2.setTag(2); | ||
bt3.setTag(3); | ||
bt4.setTag(4); | ||
bt5.setTag(5); | ||
View.OnClickListener click = new View.OnClickListener() { | ||
@RequiresApi(api = Build.VERSION_CODES.KITKAT) | ||
@Override | ||
public void onClick(View v) { | ||
cycle = Integer.parseInt(v.getTag().toString()); | ||
page = 1; | ||
datas = new JSONArray(); | ||
kline.chartType = cycle>=2? DsxKline.ChartType.candle:cycle==0? DsxKline.ChartType.timeSharing: DsxKline.ChartType.timeSharing5; | ||
try { | ||
kline.startLoading(); | ||
} catch (JSONException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
}; | ||
bt0.setOnClickListener(click); | ||
bt1.setOnClickListener(click); | ||
bt2.setOnClickListener(click); | ||
bt3.setOnClickListener(click); | ||
bt4.setOnClickListener(click); | ||
bt5.setOnClickListener(click); | ||
} | ||
|
||
@RequiresApi(api = Build.VERSION_CODES.KITKAT) | ||
public void getStockDatas(String code) throws JSONException { | ||
if(kline.chartType == DsxKline.ChartType.candle) getDay(code); | ||
if(kline.chartType.ordinal() <= DsxKline.ChartType.timeSharing5.ordinal())getQuotes(code); | ||
} | ||
|
||
|
||
@RequiresApi(api = Build.VERSION_CODES.KITKAT) | ||
private void getQuotes(String code) throws JSONException { | ||
List<HqModel> result = QQhq.getQuote(code); | ||
if(result!=null){ | ||
HqModel model = result.get(0); | ||
kline.lastClose = Double.parseDouble(model.lastClose); | ||
if(cycle==0)getTimeline(code); | ||
if(cycle==1)getTimeline5(code); | ||
} | ||
|
||
} | ||
|
||
@RequiresApi(api = Build.VERSION_CODES.KITKAT) | ||
private void getTimeline(String code){ | ||
List<String> result = null; | ||
try { | ||
result = QQhq.getTimeLine(code); | ||
JSONArray datas = new JSONArray(result); | ||
runOnUiThread(new Runnable() { | ||
@Override | ||
public void run() { | ||
try { | ||
kline.updateKline(datas); | ||
} catch (JSONException e) { | ||
e.printStackTrace(); | ||
} | ||
kline.finishLoading(); | ||
} | ||
}); | ||
} catch (JSONException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
} | ||
|
||
@RequiresApi(api = Build.VERSION_CODES.KITKAT) | ||
private void getTimeline5(String code) throws JSONException { | ||
Map<String,Object> result = QQhq.getFdayLine(code); | ||
if(result!=null){ | ||
double lastClose = Double.parseDouble(result.get("lastClose").toString()); | ||
kline.lastClose = lastClose; | ||
List<String> data = (List<String>) result.get("data"); | ||
JSONArray datas = new JSONArray(data); | ||
runOnUiThread(new Runnable() { | ||
@RequiresApi(api = Build.VERSION_CODES.KITKAT) | ||
@Override | ||
public void run() { | ||
try { | ||
kline.updateKline(datas); | ||
|
||
} catch (JSONException e) { | ||
e.printStackTrace(); | ||
} | ||
kline.finishLoading(); | ||
} | ||
}); | ||
} | ||
|
||
} | ||
|
||
@RequiresApi(api = Build.VERSION_CODES.KITKAT) | ||
private void getDay(String code) throws JSONException { | ||
String cycleName = "day"; | ||
if(cycle==2) cycleName = "day"; | ||
if(cycle==3) cycleName = "week"; | ||
if(cycle==4) cycleName = "month"; | ||
if(cycle==5) cycleName = "m1"; | ||
List<String> result = QQhq.getkLine(code,cycleName,"","",320,"qfq"); | ||
if(!result.isEmpty()){ | ||
try { | ||
JSONArray data = new JSONArray(result); | ||
if(data.length()>0){ | ||
if(page<=1) datas = new JSONArray(); | ||
String a = data.toString()+(datas.length()>0?datas.toString():""); | ||
a = a.replace("][",","); | ||
datas = new JSONArray(a); | ||
runOnUiThread(new Runnable() { | ||
@Override | ||
public void run() { | ||
try { | ||
kline.page = page; | ||
kline.updateKline(datas); | ||
page ++; | ||
|
||
} catch (JSONException e) { | ||
e.printStackTrace(); | ||
} | ||
kline.finishLoading(); | ||
} | ||
}); | ||
} | ||
|
||
|
||
} catch (JSONException e) { | ||
e.printStackTrace(); | ||
kline.finishLoading(); | ||
} | ||
} | ||
|
||
} | ||
|
||
|
||
} |
Oops, something went wrong.