forked from zengsn/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
Showing
11 changed files
with
553 additions
and
0 deletions.
There are no files selected for viewing
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,40 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.example.jeremy.soft1613071002205"> | ||
|
||
<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=".MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
|
||
<activity | ||
android:name="com.example.jeremy.soft1613071002205.主界面"> | ||
|
||
</activity> | ||
|
||
<activity android:name="com.example.jeremy.soft1613071002205.DownloadActivity"> | ||
|
||
</activity> | ||
|
||
<activity android:name="com.example.jeremy.soft1613071002205.Main2Activity"> | ||
|
||
</activity> | ||
|
||
<activity | ||
android:name="com.example.jeremy.soft1613071002205.User"> | ||
|
||
</activity> | ||
|
||
</application> | ||
|
||
</manifest> |
94 changes: 94 additions & 0 deletions
94
Soft1613071002205/main/java/com/example/jeremy/soft1613071002205/DownloadActivity.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,94 @@ | ||
package com.example.jeremy.soft1613071002205; | ||
|
||
import android.app.Application; | ||
import android.graphics.Bitmap; | ||
import android.graphics.BitmapFactory; | ||
import android.os.Bundle; | ||
import android.os.Environment; | ||
import android.os.Handler; | ||
import android.os.Message; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.view.View; | ||
import android.widget.Button; | ||
import android.widget.ImageView; | ||
|
||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
|
||
public class DownloadActivity extends AppCompatActivity{ | ||
private static final String TAG = "MainActivity"; | ||
private Bitmap bitmap; | ||
Handler handler=new Handler(){ | ||
@Override | ||
public void handleMessage(Message msg) { | ||
if(msg.what==111){ | ||
mShowImage.setImageBitmap(bitmap); | ||
} | ||
} | ||
}; | ||
private ImageView mShowImage; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.download); | ||
mShowImage = findViewById(R.id.show_image); | ||
initButton(); | ||
} | ||
|
||
private void initButton() { | ||
Button startDownLoad = findViewById(R.id.start_btn); | ||
startDownLoad.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
t.start(); | ||
} | ||
}); | ||
} | ||
|
||
//为了下载图片资源,开辟一个新的子线程 | ||
Thread t=new Thread(){ | ||
@Override | ||
public void run() { | ||
//下载图片的路径 | ||
String iPath="https://t" + | ||
"imgsa.baidu.com/timg?" + | ||
"image&quality=80&size=b9999_" + | ||
"10000&sec=1527778386587&di=8be823" + | ||
"0eaebdaeaa949d7b73357c2fa2&imgt" + | ||
"ype=0&src=http%3A%2F%2F5b0988e595225.cdn.so" + | ||
"hucs.com%2Fq_70%2Cc_zoom%2Cw_640%2Fimage" + | ||
"s%2F20180415%2Fb86096a5dac244ddbc8d9060eb68e1b0.jpeg"; | ||
try { | ||
//对资源链接 | ||
URL url=new URL(iPath); | ||
//打开输入流 | ||
InputStream inputStream=url.openStream(); | ||
//对网上资源进行下载转换位图图片 | ||
bitmap= BitmapFactory.decodeStream(inputStream); | ||
handler.sendEmptyMessage(111); | ||
inputStream.close(); | ||
|
||
//再一次打开 | ||
inputStream=url.openStream(); | ||
File file=new File(Environment.getExternalStorageDirectory()+"/haha.jpg"); | ||
FileOutputStream fileOutputStream=new FileOutputStream(file); | ||
int hasRead=0; | ||
while((hasRead=inputStream.read())!=-1){ | ||
fileOutputStream.write(hasRead); | ||
} | ||
fileOutputStream.close(); | ||
inputStream.close(); | ||
} catch (MalformedURLException e) { | ||
e.printStackTrace(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
}; | ||
}; | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
Soft1613071002205/main/java/com/example/jeremy/soft1613071002205/Main2Activity.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,25 @@ | ||
package com.example.jeremy.soft1613071002205; | ||
|
||
import android.os.Bundle; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.widget.TextView; | ||
|
||
public class Main2Activity extends AppCompatActivity { | ||
private TextView mTextViewGetUserName; | ||
private TextView mTextViewGetPassword; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.mynews); | ||
mTextViewGetUserName = (TextView) findViewById(R.id.textView2); | ||
mTextViewGetPassword = (TextView) findViewById(R.id.textView3); | ||
Bundle b = getIntent().getBundleExtra("data"); | ||
String getStringUserName = b.getString("username"); | ||
mTextViewGetUserName.setText(getStringUserName); | ||
String getStringPassword = b.getString("password"); | ||
mTextViewGetPassword.setText(getStringPassword); | ||
|
||
|
||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
Soft1613071002205/main/java/com/example/jeremy/soft1613071002205/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,57 @@ | ||
package com.example.jeremy.soft1613071002205; | ||
|
||
|
||
import android.app.Activity; | ||
import android.content.Intent; | ||
import android.content.SharedPreferences; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
import android.util.Log; | ||
import android.view.View; | ||
import android.widget.Button; | ||
import android.widget.EditText; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
|
||
private Button 登录; | ||
private EditText 用户名; | ||
private EditText 密码; | ||
private SharedPreferences mSharePreferences; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
|
||
mSharePreferences = getSharedPreferences("data", MODE_PRIVATE); | ||
|
||
用户名 = (EditText) findViewById(R.id.editText); | ||
密码 = (EditText) findViewById(R.id.editText2); | ||
//取出数据并渲染 | ||
|
||
登录 = (Button) findViewById(R.id.login); | ||
登录.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
String stringUsername = 用户名.getText().toString(); | ||
String stringPassword = 密码.getText().toString(); | ||
// 2. 调用SharedPreferences.edit()方法,返回SharedPreferences.Editor对象,用于写入数据; | ||
SharedPreferences.Editor editor = mSharePreferences.edit(); | ||
//3. 调用SharedPreferences.Editor.putXxx(String key, xxx Value)方法以键值对的形式保存数据; | ||
editor.putString("user", stringUsername); | ||
editor.putString("password", stringPassword); | ||
// 4. 调用SharedPreferences.Editor.commit()方法提交数据。 | ||
editor.commit(); | ||
|
||
Intent intent = new Intent(MainActivity.this, User.class); | ||
Bundle bundle = new Bundle(); | ||
bundle.putString("username", stringUsername); | ||
bundle.putString("password", stringPassword); | ||
intent.putExtra("data", bundle); | ||
|
||
startActivity(intent); | ||
} | ||
|
||
}); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
Soft1613071002205/main/java/com/example/jeremy/soft1613071002205/User.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,46 @@ | ||
package com.example.jeremy.soft1613071002205; | ||
|
||
import android.content.Intent; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
import android.view.View; | ||
import android.widget.Button; | ||
|
||
import java.util.Map; | ||
|
||
public class User extends AppCompatActivity { | ||
|
||
private Button mReturnButton; | ||
private Button download; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.mynews); | ||
mReturnButton = (Button) findViewById(R.id.returnback); | ||
|
||
Button download = findViewById(R.id.download); | ||
download.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
Intent i = new Intent(User.this, DownloadActivity.class); | ||
startActivity(i); | ||
} | ||
|
||
}); | ||
} | ||
|
||
|
||
|
||
|
||
public void back_to_login(View view) { | ||
Intent intent3 = new Intent(User.this,MainActivity.class) ; | ||
startActivity(intent3); | ||
finish(); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
} |
13 changes: 13 additions & 0 deletions
13
Soft1613071002205/main/java/com/example/jeremy/soft1613071002205/主界面.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,13 @@ | ||
package com.example.jeremy.soft1613071002205; | ||
|
||
import android.os.Bundle; | ||
import android.support.v7.app.AppCompatActivity; | ||
|
||
public class 主界面 extends AppCompatActivity { | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.home); | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
Soft1613071002205/main/java/com/example/jeremy/soft1613071002205/信息发布.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,32 @@ | ||
package com.example.jeremy.soft1613071002205; | ||
|
||
|
||
import android.app.Activity; | ||
import android.content.Intent; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
import android.util.Log; | ||
import android.view.View; | ||
import android.widget.Button; | ||
|
||
public class 信息发布 extends AppCompatActivity { | ||
|
||
private Button 信息发布; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.home); | ||
|
||
|
||
信息发布 = (Button) findViewById(R.id.button); | ||
信息发布.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
Intent intent = new Intent(信息发布.this,主界面.class); | ||
startActivity(intent); | ||
} | ||
|
||
}); | ||
} | ||
} |
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,70 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<android.support.constraint.ConstraintLayout 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:id="@+id/linearLayout" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".MainActivity"> | ||
|
||
<TextView | ||
android:id="@+id/textView" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:background="@drawable/homepage" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
|
||
<TextView | ||
android:id="@+id/textView2" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginEnd="13dp" | ||
android:layout_marginRight="13dp" | ||
android:layout_marginTop="195dp" | ||
android:text="welcome the part-time life!" | ||
android:textSize="30sp" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
|
||
<EditText | ||
android:id="@+id/editText" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginLeft="48dp" | ||
android:layout_marginStart="48dp" | ||
android:hint="用户名" | ||
android:textColorHint="#ff00ff" | ||
android:textSize="20sp" | ||
app:layout_constraintBaseline_toBaselineOf="@+id/editText2" | ||
app:layout_constraintStart_toStartOf="@+id/textView" /> | ||
|
||
<EditText | ||
android:id="@+id/editText2" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginLeft="196dp" | ||
android:layout_marginStart="196dp" | ||
android:layout_marginTop="288dp" | ||
android:hint="密码" | ||
android:inputType="numberPassword" | ||
android:textColorHint="#ff00ff" | ||
android:textSize="20sp" | ||
app:layout_constraintStart_toStartOf="@+id/textView" | ||
app:layout_constraintTop_toTopOf="@+id/textView" /> | ||
|
||
<Button | ||
android:id="@+id/login" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginLeft="216dp" | ||
android:layout_marginStart="216dp" | ||
android:layout_marginTop="356dp" | ||
android:text="登录" | ||
app:layout_constraintStart_toStartOf="@+id/textView" | ||
app:layout_constraintTop_toTopOf="@+id/textView" /> | ||
|
||
|
||
|
||
|
||
</android.support.constraint.ConstraintLayout> |
Oops, something went wrong.