Skip to content

Commit

Permalink
增加调用
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangcaiqi committed Jun 3, 2020
1 parent 1c6cc89 commit 709d57e
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 13 deletions.
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
Expand All @@ -29,5 +33,5 @@ dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

implementation 'com.github.zhangcaiqi:UsbGpsLib:1.0.0'
}
9 changes: 8 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<activity android:name=".MainActivity" android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
</intent-filter>

<meta-data
android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
android:resource="@xml/device_filter" />
</activity>
</application>

Expand Down
44 changes: 44 additions & 0 deletions app/src/main/java/com/zy/usbgpslib/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,53 @@

public class MainActivity extends AppCompatActivity {

private TextView receiveText;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
receiveText = findViewById(R.id.receive_text);
UsbGpsService.getInstance().start(this, new UsbGpsListener() {
@Override
public void onFailed(String msg) {
Toast.makeText(MainActivity.this,msg,Toast.LENGTH_SHORT);
}

@Override
public void onRead(GpsInfo gpsInfo) {
SpannableStringBuilder spn = new SpannableStringBuilder();
spn.append(gpsInfo.getLatitudeDirection()+":");
spn.append(gpsInfo.getLatitude()+"\r\n");
receiveText.append(spn);
}

@Override
public void onUsbAttached() {
SpannableStringBuilder spn = new SpannableStringBuilder();
spn.append("usb设备已插入\r\n");
receiveText.append(spn);
}

@Override
public void onUsbDetached() {
SpannableStringBuilder spn = new SpannableStringBuilder();
spn.append("usb设备已拔出\r\n");
receiveText.append(spn);
}
}
);
}

@Override
protected void onDestroy() {
UsbGpsService.getInstance().onDestroy();
super.onDestroy();
}

@Override
protected void onNewIntent(Intent intent) {

super.onNewIntent(intent);
}
}
20 changes: 9 additions & 11 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
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=".MainActivity">

android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

android:id="@+id/receive_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:freezesText="true"
android:gravity="bottom"
android:scrollbars="vertical"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:typeface="monospace" />
</androidx.constraintlayout.widget.ConstraintLayout>
29 changes: 29 additions & 0 deletions app/src/main/res/xml/device_filter.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- 0x0403 FTDI -->
<usb-device vendor-id="1027" product-id="24577" /> <!-- 0x6001: FT232R -->
<usb-device vendor-id="1027" product-id="24592" /> <!-- 0x6010: FT2232H -->
<usb-device vendor-id="1027" product-id="24593" /> <!-- 0x6011: FT4232H -->
<usb-device vendor-id="1027" product-id="24596" /> <!-- 0x6014: FT232H -->
<usb-device vendor-id="1027" product-id="24597" /> <!-- 0x6015: FT231X -->

<!-- 0x10C4 / 0xEAxx: Silabs CP210x -->
<usb-device vendor-id="4292" product-id="60000" /> <!-- 0xea60: CP2102 -->
<usb-device vendor-id="4292" product-id="60016" /> <!-- 0xea70: CP2105 -->
<usb-device vendor-id="4292" product-id="60017" /> <!-- 0xea71: CP2108 -->
<usb-device vendor-id="4292" product-id="60032" /> <!-- 0xea80: CP2110 -->

<!-- 0x067B / 0x2303: Prolific PL2303 -->
<usb-device vendor-id="1659" product-id="8963" />

<!-- 0x1a86 / 0x7523: Qinheng CH340 -->
<usb-device vendor-id="6790" product-id="29987" />

<!-- CDC driver -->
<usb-device vendor-id="9025" /> <!-- 0x2341 / ......: Arduino -->
<usb-device vendor-id="5824" product-id="1155" /> <!-- 0x16C0 / 0x0483: Teensyduino -->
<usb-device vendor-id="1003" product-id="8260" /> <!-- 0x03EB / 0x2044: Atmel Lufa -->
<usb-device vendor-id="7855" product-id="4" /> <!-- 0x1eaf / 0x0004: Leaflabs Maple -->
<usb-device vendor-id="3368" product-id="516" /> <!-- 0x0d28 / 0x0204: ARM mbed -->
<usb-device vendor-id="5446" product-id="424" />
</resources>
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ allprojects {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
}
}

Expand Down

0 comments on commit 709d57e

Please sign in to comment.