-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1853 from halolol/master
- Loading branch information
Showing
17 changed files
with
940 additions
and
0 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
students/com1714080901118/实验八/app/src/main/AndroidManifest.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,55 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.example.aishop"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET" /> | ||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | ||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> | ||
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /> | ||
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" /> | ||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | ||
|
||
<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=".PersonalActivity" | ||
android:label="@string/title_activity_personal" | ||
android:theme="@style/AppTheme.NoActionBar" /> | ||
<activity | ||
android:name=".DetailActivity" | ||
android:label="@string/title_activity_detail" | ||
android:theme="@style/AppTheme.NoActionBar" /> | ||
<activity | ||
android:name=".BookActivity" | ||
android:label="@string/title_activity_book" | ||
android:theme="@style/AppTheme.NoActionBar" /> | ||
<activity | ||
android:name=".ShowActivity" | ||
android:label="@string/title_activity_show" | ||
android:theme="@style/AppTheme.NoActionBar" /> | ||
<activity android:name=".MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
|
||
<provider | ||
android:name="android.support.v4.content.FileProvider" | ||
android:authorities="com.example.aishop" | ||
android:exported="false" | ||
android:grantUriPermissions="true"> | ||
<meta-data | ||
android:name="android.support.FILE_PROVIDER_PATHS" | ||
android:resource="@xml/file_paths" /> | ||
</provider> | ||
</application> | ||
|
||
</manifest> |
38 changes: 38 additions & 0 deletions
38
...80901118/实验八/app/src/main/java/edu/hzuapps/androidlabs/Com1714080901118/BookActivity.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,38 @@ | ||
package com.example.aishop; | ||
|
||
import android.content.Intent; | ||
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.widget.ImageView; | ||
|
||
public class BookActivity extends AppCompatActivity { | ||
|
||
private ImageView imageView2; | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_book); | ||
Toolbar toolbar = findViewById(R.id.toolbar); | ||
imageView2=(ImageView)findViewById(R.id.book1); | ||
imageView2.setOnClickListener(new View.OnClickListener() { | ||
public void onClick(View v) { | ||
Intent intent3=new Intent(BookActivity.this,DetailActivity.class); | ||
startActivity(intent3); //do something | ||
} | ||
}); | ||
setSupportActionBar(toolbar); | ||
FloatingActionButton fab = findViewById(R.id.fab); | ||
fab.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) | ||
.setAction("Action", null).show(); | ||
} | ||
}); | ||
} | ||
|
||
} |
63 changes: 63 additions & 0 deletions
63
...901118/实验八/app/src/main/java/edu/hzuapps/androidlabs/Com1714080901118/DetailActivity.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,63 @@ | ||
package com.example.aishop; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.content.Context; | ||
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.widget.Button; | ||
import android.widget.EditText; | ||
import android.widget.Toast; | ||
|
||
import java.io.FileOutputStream; | ||
|
||
public class DetailActivity extends AppCompatActivity { | ||
|
||
private EditText et_count; | ||
private Button btn_save; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_detail); | ||
Toolbar toolbar = findViewById(R.id.toolbar); | ||
setSupportActionBar(toolbar); | ||
et_count = (EditText) findViewById(R.id.et_count); | ||
btn_save = (Button) findViewById(R.id.btn_save); | ||
btn_save.setOnClickListener(new ButtonListener()); | ||
FloatingActionButton fab = findViewById(R.id.fab); | ||
fab.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) | ||
.setAction("Action", null).show(); | ||
} | ||
}); | ||
} | ||
|
||
private class ButtonListener implements View.OnClickListener { | ||
@SuppressLint("WrongConstant") | ||
public void onClick(View v) { | ||
switch (v.getId()) { | ||
case R.id.btn_save: | ||
String saveinfo = et_count.getText().toString().trim(); | ||
FileOutputStream fos; | ||
try { | ||
fos = openFileOutput("data.txt", Context.MODE_APPEND); | ||
fos.write(saveinfo.getBytes()); | ||
fos.close(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
Toast.makeText(DetailActivity.this, "添加成功", 0).show(); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
} | ||
|
||
} |
96 changes: 96 additions & 0 deletions
96
...80901118/实验八/app/src/main/java/edu/hzuapps/androidlabs/Com1714080901118/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,96 @@ | ||
package com.example.aishop; | ||
|
||
import android.content.Intent; | ||
import android.graphics.Bitmap; | ||
import android.graphics.BitmapFactory; | ||
import android.graphics.drawable.BitmapDrawable; | ||
import android.os.Build; | ||
import android.os.Handler; | ||
import android.os.Message; | ||
import android.support.annotation.RequiresApi; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
import android.view.View; | ||
import android.widget.Button; | ||
import android.widget.LinearLayout; | ||
|
||
import java.io.InputStream; | ||
import java.net.HttpURLConnection; | ||
import java.net.URL; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
private Button personal; | ||
private Button cbj; | ||
private LinearLayout linear; | ||
private Button btn_shop; | ||
private String url_image="https://img.alicdn.com/imgextra/i3/2257197507/O1CN01usEcgU25KFmTX1RGE_!!2257197507.jpg"; | ||
private Handler handler=new Handler() | ||
{ | ||
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN) | ||
public void handleMessage(Message msg) { | ||
switch (msg.what) { | ||
case 0: | ||
Bitmap bmp=(Bitmap)msg.obj; | ||
linear.setBackground(new BitmapDrawable(bmp)); | ||
break; | ||
} | ||
}; | ||
}; | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
cbj=(Button)findViewById(R.id.cbj); | ||
linear=findViewById(R.id.linear); | ||
personal=(Button)findViewById(R.id.personal); | ||
btn_shop=(Button)findViewById(R.id.btn_shop); | ||
btn_shop .setOnClickListener(new View.OnClickListener() { | ||
public void onClick(View v) { | ||
Intent intent=new Intent(MainActivity.this,ShowActivity.class); | ||
startActivity(intent); //do something | ||
} | ||
}); | ||
personal.setOnClickListener(new View.OnClickListener() { | ||
public void onClick(View v) { | ||
Intent intent4=new Intent(MainActivity.this,PersonalActivity.class); | ||
startActivity(intent4); //do something | ||
} | ||
}); | ||
cbj.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
new Thread(new Runnable() { | ||
@Override | ||
public void run() { | ||
Bitmap bmp = getImage(url_image); | ||
Message msg = new Message(); | ||
msg.what = 0; | ||
msg.obj = bmp; | ||
handler.sendMessage(msg); | ||
} | ||
}).start(); | ||
} | ||
}); | ||
|
||
} | ||
|
||
private Bitmap getImage(String url_image) { | ||
Bitmap bmp = null; | ||
try { | ||
URL Myurl = new URL(url_image); | ||
HttpURLConnection conn = (HttpURLConnection) Myurl.openConnection(); | ||
conn.setConnectTimeout(6000); | ||
conn.setDoInput(true); | ||
conn.setUseCaches(false); | ||
conn.connect(); | ||
InputStream is = conn.getInputStream(); | ||
bmp = BitmapFactory.decodeStream(is); | ||
is.close(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
return bmp; | ||
|
||
} | ||
} | ||
|
87 changes: 87 additions & 0 deletions
87
...1118/实验八/app/src/main/java/edu/hzuapps/androidlabs/Com1714080901118/PersonalActivity.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,87 @@ | ||
package com.example.aishop; | ||
|
||
import android.content.Intent; | ||
import android.graphics.Bitmap; | ||
import android.graphics.BitmapFactory; | ||
import android.net.Uri; | ||
import android.os.Build; | ||
import android.os.Bundle; | ||
import android.provider.MediaStore; | ||
import android.support.design.widget.FloatingActionButton; | ||
import android.support.design.widget.Snackbar; | ||
import android.support.v4.content.FileProvider; | ||
import android.support.v7.app.ActionBar; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.support.v7.widget.Toolbar; | ||
import android.view.View; | ||
import android.widget.Button; | ||
import android.widget.ImageView; | ||
|
||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
|
||
public class PersonalActivity extends AppCompatActivity { | ||
|
||
public static final int TAKE_PHOTO=1; | ||
private ImageView pic; | ||
private Uri imageUrl; | ||
private Button pictureBtn; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_personal); | ||
ActionBar actionBar=getSupportActionBar(); | ||
if(actionBar!=null){ | ||
actionBar.hide(); | ||
} | ||
pictureBtn=(Button) findViewById(R.id.pictureBtn); | ||
pic=(ImageView) findViewById(R.id.picture); | ||
|
||
pictureBtn.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
File outputImage=new File(getExternalCacheDir(),"output_image.jpg"); | ||
try { | ||
if(outputImage.exists()){ | ||
outputImage.delete(); | ||
} | ||
outputImage.createNewFile(); | ||
}catch (IOException e){ | ||
e.printStackTrace(); | ||
} | ||
if(Build.VERSION.SDK_INT>=24){ | ||
imageUrl= FileProvider.getUriForFile(PersonalActivity.this,"com.example.aishop",outputImage); | ||
} | ||
else { | ||
imageUrl=Uri.fromFile(outputImage); | ||
} | ||
//启动相机 | ||
Intent intent=new Intent("android.media.action.IMAGE_CAPTURE"); | ||
intent.putExtra(MediaStore.EXTRA_OUTPUT,imageUrl); | ||
startActivityForResult(intent,TAKE_PHOTO); | ||
} | ||
}); | ||
} | ||
@Override | ||
protected void onActivityResult(int requestCode,int resultCode,Intent data){ | ||
switch (requestCode){ | ||
case TAKE_PHOTO: | ||
if(resultCode==RESULT_OK){ | ||
try{ | ||
//显示图片 | ||
Bitmap bitmap= BitmapFactory.decodeStream(getContentResolver().openInputStream(imageUrl)); | ||
pic.setImageBitmap(bitmap); | ||
} | ||
catch (FileNotFoundException e){ | ||
e.printStackTrace(); | ||
} | ||
} | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
...80901118/实验八/app/src/main/java/edu/hzuapps/androidlabs/Com1714080901118/ShowActivity.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,36 @@ | ||
package com.example.aishop; | ||
|
||
import android.content.Intent; | ||
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.widget.ImageView; | ||
|
||
public class ShowActivity extends AppCompatActivity { | ||
private ImageView imageView; | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_show); | ||
Toolbar toolbar = findViewById(R.id.toolbar); | ||
setSupportActionBar(toolbar); | ||
imageView=(ImageView)findViewById(R.id.book); | ||
imageView .setOnClickListener(new View.OnClickListener() { | ||
public void onClick(View v) { | ||
Intent intent2=new Intent(ShowActivity.this,BookActivity.class); | ||
startActivity(intent2); //do something | ||
} | ||
}); | ||
FloatingActionButton fab = findViewById(R.id.fab); | ||
fab.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) | ||
.setAction("Action", null).show(); | ||
} | ||
}); | ||
} | ||
} |
Oops, something went wrong.