forked from hzuapps/android-labs-2018
-
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
Im-a-programmer
committed
Jun 2, 2018
1 parent
360cddd
commit 9371420
Showing
8 changed files
with
336 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,31 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="edu.hzuapps.androidlabs.com1614080901140"> | ||
|
||
|
||
<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/AppTheme"> | ||
<activity android:name=".Com1614080901140Activity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
<activity | ||
android:name=".SecondActivity" | ||
android:label="@string/title_activity_second" | ||
android:theme="@style/AppTheme.NoActionBar" /> | ||
<activity | ||
android:name=".ThirdActivity" | ||
android:label="@string/title_activity_third" | ||
android:theme="@style/AppTheme.NoActionBar"></activity> | ||
</application> | ||
|
||
</manifest> |
93 changes: 93 additions & 0 deletions
93
...4080901140/app/src/main/java/edu/hzuapps/androidlabs/Com1614080901140/SecondActivity.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,93 @@ | ||
package edu.hzuapps.androidlabs.com1614080901140; | ||
|
||
import android.os.Bundle; | ||
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.view.View; | ||
|
||
|
||
import android.content.ContextWrapper; | ||
import android.widget.Button; | ||
import android.widget.EditText; | ||
import java.io.BufferedWriter; | ||
import java.io.FileInputStream; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.io.OutputStreamWriter; | ||
import android.content.Intent; | ||
import android.widget.Toast; | ||
|
||
public class SecondActivity extends AppCompatActivity { | ||
|
||
private Button nextbtn; | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_second); | ||
|
||
((Button) findViewById(R.id.btn_save)). | ||
|
||
setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
String text = ((EditText) findViewById(R.id.et_info)).getText().toString(); | ||
save(text); | ||
} | ||
}); | ||
((Button) findViewById(R.id.btn_read)). | ||
|
||
setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
readsy5(); | ||
} | ||
}); | ||
nextbtn=(Button)findViewById(R.id.btn_t); | ||
nextbtn.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
Intent intent=new Intent(SecondActivity.this,ThirdActivity.class); | ||
startActivity(intent); | ||
} | ||
}); | ||
|
||
} | ||
|
||
public void save(String text) { | ||
FileOutputStream out = null; | ||
BufferedWriter writer = null; | ||
try { | ||
out = openFileOutput("sy.txt", ContextWrapper.MODE_APPEND); | ||
writer = new BufferedWriter(new OutputStreamWriter(out)); | ||
writer.write(text); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} finally { | ||
try { | ||
if (writer != null) { | ||
writer.close(); | ||
} | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
Toast.makeText(SecondActivity.this, "订单保存成功", Toast.LENGTH_SHORT).show(); | ||
} | ||
} | ||
|
||
public void readsy5() { | ||
String content = ""; | ||
try { | ||
FileInputStream fis = openFileInput("sy.txt"); | ||
byte[] buffer = new byte[fis.available()]; | ||
fis.read(buffer); | ||
content = new String(buffer); | ||
fis.close(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
Toast.makeText(SecondActivity.this, "您的订单号是" + content, Toast.LENGTH_SHORT).show(); | ||
|
||
} | ||
} |
115 changes: 115 additions & 0 deletions
115
...14080901140/app/src/main/java/edu/hzuapps/androidlabs/Com1614080901140/ThirdActivity.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,115 @@ | ||
package edu.hzuapps.androidlabs.com1614080901140; | ||
|
||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.InputStream; | ||
import java.net.HttpURLConnection; | ||
import java.net.URL; | ||
import android.os.AsyncTask; | ||
import android.os.Environment; | ||
import android.os.Handler; | ||
import android.os.Message; | ||
import android.app.Activity; | ||
import android.graphics.Bitmap; | ||
import android.graphics.BitmapFactory; | ||
import android.view.View; | ||
import android.view.View.OnClickListener; | ||
import android.widget.Button; | ||
import android.widget.ImageView; | ||
import android.widget.Toast; | ||
|
||
|
||
public class ThirdActivity extends AppCompatActivity implements OnClickListener{ | ||
|
||
Button content; | ||
ImageView image; | ||
Bitmap bitmap; | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_third); | ||
content=(Button)findViewById(R.id.content); | ||
image=(ImageView)findViewById(R.id.image); | ||
|
||
content.setOnClickListener(this);; | ||
image.setOnClickListener(this);; | ||
} | ||
|
||
public Bitmap GetImageInputStream(String imageurl){ | ||
URL url; | ||
HttpURLConnection connection=null; | ||
Bitmap bitmap=null; | ||
try { | ||
url = new URL(imageurl); | ||
connection=(HttpURLConnection)url.openConnection(); | ||
connection.setConnectTimeout(6000); | ||
connection.setDoInput(true); | ||
connection.setUseCaches(false); | ||
InputStream inputStream=connection.getInputStream(); | ||
bitmap=BitmapFactory.decodeStream(inputStream); | ||
inputStream.close(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
return bitmap; | ||
} | ||
|
||
public void onClick(View v) { | ||
switch (v.getId()) { | ||
case R.id.content: | ||
|
||
new Task().execute("http://img.szhome.com/images/sznews/2012/07/20120703105442315.JPG"); | ||
break; | ||
|
||
case R.id.image: | ||
|
||
SavaImage(bitmap, Environment.getExternalStorageDirectory().getPath()+"/Test"); | ||
Toast.makeText(getBaseContext(), "图片保存", Toast.LENGTH_SHORT).show(); | ||
break; | ||
|
||
default: | ||
break; | ||
} | ||
} | ||
|
||
Handler handler=new Handler(){ | ||
public void handleMessage(android.os.Message msg) { | ||
if(msg.what==0x123){ | ||
image.setImageBitmap(bitmap); | ||
} | ||
}; | ||
}; | ||
|
||
|
||
class Task extends AsyncTask<String, Integer, Void>{ | ||
|
||
protected Void doInBackground(String... params) { | ||
bitmap=GetImageInputStream((String)params[0]); | ||
return null; | ||
} | ||
|
||
protected void onPostExecute(Void result) { | ||
super.onPostExecute(result); | ||
Message message=new Message(); | ||
message.what=0x123; | ||
handler.sendMessage(message); | ||
} | ||
|
||
} | ||
|
||
public void SavaImage(Bitmap bitmap, String path){ | ||
File file=new File(path); | ||
FileOutputStream fileOutputStream=null; | ||
if(!file.exists()){ | ||
file.mkdir(); | ||
} | ||
try { | ||
fileOutputStream=new FileOutputStream(path+"/"+System.currentTimeMillis()+".png"); | ||
bitmap.compress(Bitmap.CompressFormat.JPEG, 100,fileOutputStream); | ||
fileOutputStream.close(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
com1614080901140/app/src/main/res/layout/activity_second.xml
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,64 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RelativeLayout xmlns: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=".SecondActivity"> | ||
|
||
<EditText | ||
android:id="@+id/et_info" | ||
android:layout_width="wrap_content" | ||
android:layout_height="46dp" | ||
android:layout_centerHorizontal="true" | ||
android:ems="10" | ||
android:hint="请输入您的订单号" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintHorizontal_bias="0.503" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" | ||
app:layout_constraintVertical_bias="0.0" /> | ||
<requestFocus/> | ||
|
||
<Button | ||
android:id="@+id/btn_read" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
|
||
android:layout_alignEnd="@+id/et_info" | ||
android:layout_alignRight="@+id/et_info" | ||
android:layout_below="@+id/et_info" | ||
android:text="查看订单号" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintHorizontal_bias="1.0" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" | ||
app:layout_constraintVertical_bias="0.134" /> | ||
|
||
<Button | ||
android:id="@+id/btn_save" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_alignLeft="@+id/et_info" | ||
android:layout_alignStart="@+id/et_info" | ||
android:layout_below="@+id/et_info" | ||
android:text="保存订单号" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" | ||
app:layout_constraintVertical_bias="0.134" /> | ||
|
||
<Button | ||
android:id="@+id/btn_t" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_alignParentBottom="true" | ||
android:layout_alignParentEnd="true" | ||
android:layout_alignParentRight="true" | ||
android:layout_marginBottom="17dp" | ||
android:layout_marginEnd="30dp" | ||
android:layout_marginRight="30dp" | ||
android:text="铁路路线"/> | ||
</RelativeLayout> |
33 changes: 33 additions & 0 deletions
33
com1614080901140/app/src/main/res/layout/activity_third.xml
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,33 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<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" | ||
tools:context="edu.hzuapps.androidlabs.com1614080901140.ThirdActivity" | ||
android:orientation="vertical" | ||
> | ||
|
||
<ImageView | ||
android:id="@+id/image" | ||
android:layout_width="fill_parent" | ||
android:layout_height="450dp" | ||
android:layout_alignParentLeft="true" | ||
android:layout_alignParentStart="true" | ||
android:layout_alignParentTop="true" | ||
android:layout_marginTop="22dp" /> | ||
|
||
<Button | ||
android:id="@+id/content" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_alignParentBottom="true" | ||
android:layout_alignParentEnd="true" | ||
android:layout_alignParentRight="true" | ||
android:layout_marginBottom="20dp" | ||
android:layout_marginEnd="68dp" | ||
android:layout_marginRight="68dp" | ||
android:background="#ff8c00" | ||
android:text="路线查看" /> | ||
|
||
</RelativeLayout> | ||
|