-
Notifications
You must be signed in to change notification settings - Fork 157
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 #197 from zhenglide/master
- Loading branch information
Showing
1 changed file
with
94 additions
and
0 deletions.
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
app/src/main/java/edu/hzuapps/androidworks/homeworks/com1314080901145/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,94 @@ | ||
package com.example.zhenglide.exam; | ||
|
||
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.view.Menu; | ||
import android.view.MenuItem; | ||
import android.widget.Button; | ||
|
||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
String DB_PATH="/data/data/com.example.zhenglide.exam/dataabase/"; | ||
String DB_NAME="question.db"; | ||
if(new File(DB_PATH+DB_NAME).exists()==false) | ||
|
||
{File dir=new File(DB_PATH); | ||
if (!dir.exists()){ | ||
dir.mkdir(); | ||
} | ||
try { | ||
InputStream is=getBaseContext().getAssets().open(DB_NAME); | ||
OutputStream os=new FileOutputStream(DB_PATH+DB_NAME); | ||
byte[] buffer=new byte[1024]; | ||
int length; | ||
while((length=is.read(buffer))>0) | ||
{ | ||
os.write(buffer,0,length); | ||
} | ||
os.flush(); | ||
is.close(); | ||
os.close(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
} | ||
Button btn=(Button)findViewById(R.id.button); | ||
btn.setOnClickListener(new View.OnClickListener() | ||
{ | ||
@Override | ||
public void onClick(View v) { | ||
Intent intent=new Intent(MainActivity.this,ExamActivity.class); | ||
startActivity(intent); | ||
} | ||
}); | ||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); | ||
setSupportActionBar(toolbar); | ||
|
||
FloatingActionButton fab = (FloatingActionButton) 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(); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public boolean onCreateOptionsMenu(Menu menu) { | ||
// Inflate the menu; this adds items to the action bar if it is present. | ||
getMenuInflater().inflate(R.menu.menu_main, menu); | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean onOptionsItemSelected(MenuItem item) { | ||
// Handle action bar item clicks here. The action bar will | ||
// automatically handle clicks on the Home/Up button, so long | ||
// as you specify a parent activity in AndroidManifest.xml. | ||
int id = item.getItemId(); | ||
|
||
//noinspection SimplifiableIfStatement | ||
if (id == R.id.action_settings) { | ||
return true; | ||
} | ||
|
||
return super.onOptionsItemSelected(item); | ||
} | ||
} |