forked from hzuapps/android-labs
-
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.
Showing
4 changed files
with
166 additions
and
0 deletions.
There are no files selected for viewing
106 changes: 106 additions & 0 deletions
106
app/src/main/java/edu/hzuapps/androidworks/homeworks/com1314080901140/Com1314080901140.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,106 @@ | ||
package com.hzu.xu.planewar; | ||
|
||
import android.app.Activity; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.view.View; | ||
import android.view.Window; | ||
import android.widget.Button; | ||
import android.widget.TextView; | ||
import java.io.FileInputStream; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.util.Properties; | ||
|
||
public class Com1314080901140 extends Activity { | ||
private TextView mTextView; | ||
private Button Button0; | ||
private Button Button1; | ||
private boolean mChanged = false; | ||
//final Data dd=(Data) getApplication(); | ||
public int Count; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
requestWindowFeature(Window.FEATURE_NO_TITLE);//设置窗口没有标题 | ||
setContentView(R.layout.activity_main); | ||
mTextView = (TextView)findViewById(R.id.show_textview); | ||
Button1=(Button)findViewById(R.id.button1); | ||
Button0=(Button)findViewById(R.id.button0); | ||
|
||
|
||
//read the mChanged is true or false | ||
readLoadFile(); | ||
refreTextView(); | ||
initButton(); | ||
} | ||
public void Btn1OnClick(View view){ | ||
Intent intent = new Intent(); | ||
intent.setClass(Com1314080901140.this, GameActivity.class); | ||
startActivity(intent); | ||
} | ||
private void initButton() | ||
{ | ||
Button1.setOnClickListener(new View.OnClickListener(){ | ||
public void onClick(View arg0) { | ||
readLoadFile(); | ||
mChanged = true; | ||
refreTextView(); | ||
Count=Count+2; | ||
saveFileStorage(); | ||
} | ||
}); | ||
} | ||
public void refreTextView() | ||
{ | ||
mTextView.setText("当前分数为:"+Count+"!"); | ||
} | ||
|
||
private void readLoadFile() | ||
{ | ||
//make the Properties | ||
|
||
Properties properties = new Properties(); | ||
|
||
try{ | ||
FileInputStream istream = this.openFileInput("dmfile.cfg"); | ||
properties.load(istream); | ||
} | ||
catch(FileNotFoundException e){ | ||
return; | ||
} | ||
catch(IOException e){ | ||
return; | ||
} | ||
mChanged = Boolean.valueOf(properties.getProperty("mChanging").toString()); | ||
Count = Integer.valueOf(properties.getProperty("mButton").toString()); | ||
} | ||
|
||
private boolean saveFileStorage() | ||
{ | ||
Properties properties = new Properties(); | ||
properties.put("mChanging", String.valueOf(mChanged)); | ||
properties.put("mButton", String.valueOf(Count)); | ||
try{ | ||
FileOutputStream ostream = this.openFileOutput("dmfile.cfg", Context.MODE_WORLD_WRITEABLE); | ||
properties.store(ostream, ""); | ||
} | ||
catch(FileNotFoundException e) | ||
{ | ||
return false; | ||
} | ||
catch(IOException e) | ||
{ | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
} | ||
|
||
|
||
|
||
|
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,47 @@ | ||
<?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="com.hzu.xu.planewar.Com1314080901140"> | ||
|
||
|
||
<ImageView | ||
android:layout_width="190dp" | ||
android:layout_height="190dp" | ||
android:background="@drawable/xuxu" | ||
android:id="@+id/imageView" | ||
android:layout_alignParentTop="true" | ||
android:layout_centerHorizontal="true" | ||
android:layout_marginTop="72dp" /> | ||
|
||
<Button | ||
android:layout_width="200dp" | ||
android:layout_height="80dp" | ||
android:text="开始游戏" | ||
android:id="@+id/button0" | ||
android:singleLine="true" | ||
android:textSize="30dp" | ||
android:onClick="Btn1OnClick" | ||
android:layout_above="@+id/button1" | ||
android:layout_alignStart="@+id/imageView" /> | ||
|
||
<Button | ||
android:layout_width="200dp" | ||
android:layout_height="80dp" | ||
android:text="更新分数" | ||
android:id="@+id/button1" | ||
android:singleLine="true" | ||
android:textSize="30dp" | ||
android:layout_marginBottom="46dp" | ||
android:layout_alignParentBottom="true" | ||
android:layout_alignStart="@+id/button0" /> | ||
|
||
<TextView | ||
android:id="@+id/show_textview" | ||
android:layout_width="fill_parent" | ||
android:layout_height="wrap_content" | ||
android:gravity="center" | ||
android:layout_above="@+id/button0" | ||
android:layout_below="@+id/imageView" | ||
android:layout_alignParentStart="true" /></RelativeLayout> |
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 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:orientation="vertical" android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:textAppearance="?android:attr/textAppearanceLarge" | ||
android:text="test" | ||
android:id="@+id/textView" | ||
android:layout_gravity="center_horizontal" /> | ||
</LinearLayout> |